0
Based on the function below, how can I consider and calculate the value of the entry in the installment, so that the rest is divided in equal parts for the other installments?
function calculo_negociacao($valor_total, $parcelas, $dt_vencimento, $valor_entrada) {
$parcelado = [];
$valor = $valor_total / $parcelas;
$valor = number_format((float)$valor, 2, '.', '');
$parcelado = array_fill(0, $parcelas, ['valor' => $valor]);
$dt_vencimento = explode( '-', $dt_vencimento);
$dia = $dt_vencimento[0];
$mes = $dt_vencimento[1];
$ano = $dt_vencimento[2];
for($x = 0; $x < $parcelas; $x++){
$parcelado[$x]['parcela'] = $x + 1;
$parcelado[$x]['dt_vencimento'] = date("Y-m-d",strtotime("+".$x." month",mktime(0, 0, 0, $mes, $dia, $ano)));
}
return $parcelado;
}
$valor = 150.07;
$valor_entrada= 50.00;
$parcela = 4;
$dt_vencimento = '04-09-2018';
$negociacao = calculo_negociacao($valor, $parcela, $dt_vencimento, $valor_entrada);
var_dump($negociacao);
echo json_encode($negociacao);
All that is left is to subtract the input value from the total value before calculating the plots. I have included your code here.. https://ideone.com/eog1Sa
– Andre Mesquita
@Andremesquita, thank you, but the entry value may or may not be informed, if it is not, will be divided into equal parts.
– Wagner Fillio
How so? At what point is to subtract the input value from the total value? It is to be divided also by each parcel?
– Leite
@Milk, if the value of the input is greater than 0, then I must consider the value of the input, as the first installment, the remainder divides equally for the other installments. an incoming installment plan, example 1(entry) + 3 (installments), if the value of the entry is 0, then divide into 4 equal installments. I am quoting 4 installments, because it is in the example, however, it is a variable
– Wagner Fillio
@Milk, I even got it this way, https://ideone.com/QBpdkE, but I believe there is a simpler way to do it
– Wagner Fillio