0
I have a system for registering debt negotiations.
Suppose I register a negotiation with 3 installments.
Being:
Parcela || Valor || Vencimento || Situação
1 || 100,00 || 01/09/2017 || Pago
2 || 100,00 || 01/10/2017 || Pago
3 || 100,00 || 01/11/2017 || Aguardando Pagamento
So in the listing, I want to display the status of this negotiation on:
Acordo em dia
Acordo Quitado
Acordo Quebrado
Following the following rules, if all plots are in situation pago
, then the situation will be Acordo Quitado
, if there is at least one plot with situation quebrado
, then the situation will be Acordo Quebrado
and if there is at least one plot with situation Aguardando Pagamento
and none Quebrado
, then the situation will be Acordo em dia
.
I did the following test with the code below and it works, but I believe this is gambiarra,
so I want to know if there’s any other way to create the information I want,
using the above rules.
$this->db->select('situacao');
$aguardando = $this->db->where('situacao', 0);
$retorno_aguardando = $this->db->get('tbl_planilha_parcela')->num_rows();
$quitado = $this->db->where('situacao', 1);
$retorno_quitado = $this->db->get('tbl_planilha_parcela')->num_rows();
$quebrado = $this->db->where('situacao', 2);
$retorno_quebrado = $this->db->get('tbl_planilha_parcela')->num_rows();
if($retorno_aguardando > 0 && $retorno_quebrado == 0)
{
$situacao = 'Aguardando Pagamento';
}
else if($retorno_quebrado > 0)
{
$situacao = 'Acordo Quebrado';
}
else if($retorno_aguardando == 0 && $retorno_quitado > 0 && $retorno_quebrado == 0)
{
$situacao = 'Quitado';
}
Maybe the method
verificaSituacao
would send to themodel
also, but as I am not an expert in architecture, let’s wait for the comments ofninjas
– Samuel Fontebasso
Reviewing my code, I could see that it is not correct, because it is taking all registered negotiations and if one of them has any part that is within any condition, then all negotiations are with the same situation
– Wagner Fillio
Each installment must have an agreement_id and you must have a table of agreements with data of who is the client the date that the agreement was closed the total amount of debt. And, if you have answered your question, vote in favor and be sure to indicate that she answered your question :)
– Samuel Fontebasso
I’m testing the code and I’ll vote.
– Wagner Fillio