Thinking about it seems to me that I will not even need it.
A Customer has a plan and agrees to pay every day '15' for example. Then on day '7' $ for example I want to take the list of the month.
As only those who have not paid and who have a grace period of 5 days after the date, would soon have to do (DiaHoje - DiaVencimento) which will give (7-15 = -8) that is less than the 5 days grace period.
In fact it's the following
The function I am using is:
function diferencaDatas ($dataInicio, $dataFim) {
$dataInicio = new DateTime($dataInicio);
$dataFim = new DateTime($dataFim);
$diferencas = $dataInicio->diff($dataFim);
return $diferencas;
}
Call:
$dataHoje = date('Y-m-d');
$dataVencimento = date('Y-m')."-dataVencimento ";
$diasDiferenca = diferencaDatas ($dataHoje , $dataVencimento ) ->days;
Know how many days apart they are.
But since the listing will always be done within the same month, both $diaHoje
and $diaVencimento
will occur in the same month, so I will not need the function just by making the simple difference between them.
Am I right in my thinking?
Well, if I'm going to take the listing for example on the 25th, the month is 09. So I'll take the date of the listing (25) and take the day of the due date (if it has not yet been paid) , this in time, otherwise it is in debt.
Corrected class.
<?php
class Relatorios {
private $conexao;
public function __construct ($_conexao) {
$this->conexao = $_conexao;
}
/*
//COMENTÁRIO DA FUNÇÃO ABAIXO
//SELECIONAR OS ID'S E OS NOMES DOS CLIENTES
$string = "SELECT idClientes, nome FROM clientes WHERE idClientes IN (
//SELECIONAR ID'S DOS CLIENTES QUE TEM PLANOS E QUE A DIA DE VENCIMENTO É MENOR QUE A O DIA ATUAL
SELECT idClientes FROM planosclientes WHERE idPlanosClientes IN (
//MAS NÃO PAGARAM A PARCELA DO MES CORRENTE
SELECT distinct(idPlanoClientes) FROM pagamentos WHERE mesReferencia NOT IN ('".$mesReferencia."')
) and DATEDIFF (curdate(), CONCAT('".date('Y-m')."','-', diaVencimento)) > ".$dias."
//UNIÃO COM
UNION
//SELECIONAR ID'S DOS CLIENTES QUE TEM PLANOS E QUE NÃO PAGARAM NENHUMA PARCELA
SELECT idPlanosClientes FROM planosclientes WHERE idPlanosClientes NOT IN (SELECT distinct(idPlanoClientes) FROM pagamentos)
) ";
*/
function retornaClientesDevedores ($mesReferencia, $dias) {
$retorno = array();
$string = "SELECT DISTINCT(idClientes), nome FROM clientes WHERE idClientes IN (
SELECT idClientes FROM planosclientes WHERE idPlanosClientes IN (
SELECT distinct(idPlanoClientes) FROM pagamentos WHERE mesReferencia NOT IN ('".$mesReferencia."')
) and DATEDIFF (curdate(), CONCAT('".date('Y-m')."','-', diaVencimento)) > ".$dias."
UNION
SELECT idPlanosClientes FROM planosclientes WHERE idPlanosClientes NOT IN (SELECT distinct(idPlanoClientes) FROM pagamentos)
) ORDER BY nome";
$dados = $this->conexao->query($string);
if($dados->num_rows == 0) {
$retorno = null;
}
else {
$contador = 0;
while ( list ($idClientes, $nomeClientes) = $dados->fetch_row()) {
$retorno[$contador][0] = $idClientes;
$retorno[$contador][1] = $nomeClientes;
$contador++;
}
}
return $retorno;
}
}
?>