Invoices not paid more than 10 days [duplicate]

1

I have a table of invoices and clients.

In the invoice table, for example, I have the fields client_id, status, and date

In the customer table id, name, etc ...

What I need is to list all invoices, that the status is still Open (in case NP - of unpaid). But I just want to list invoices that have not been paid for more than 10 days.

Listing example

Cliente     Data de Vencimento   Valor
Teste       10/08/2016           R$ 100,00
Teste       09/08/2016           R$ 200,00
Teste       05/08/2016           R$ 100,00
Teste       01/08/2016           R$ 100,00
Teste       10/07/2016           R$ 100,00

I use PHP and MySQL.

    
asked by anonymous 22.08.2016 / 15:19

2 answers

0

Something like this:

SELECT * FROM faturas WHERE status = 'NP' AND vencimento BETWEEN CURRENT_DATE()-10 AND CURRENT_DATE();

As you did not post the table structure, you could not give a more appropriate query to your situation.

Even so, I hope it helps!

    
22.08.2016 / 15:43
0

You can use DATEDIFF() to check how many days passed from a certain date by making INNER JOIN with the clients table.

SELECT 
    clientes.nome, faturas.data, faturas.valor
FROM
    faturas
        INNER JOIN
    clientes ON (faturas.cliente_id = clientes.id)
WHERE
    faturas.status = 'NP'
        AND DATEDIFF(NOW(), faturas.data) >= 10
    
23.08.2016 / 15:37