在巴西,我们可以购买和平分付款。
如果购买总额为100美元,我们可以在购买时支付30美元,其余的在接下来的几个月中分成等额。
示例:
购买时支付30美元。
2018年工资35美元-10-04
2018年35美元工资-11-04
基于下面的函数,我如何考虑和计算$value_entry资金条目的值,以便将其余部分平分到其他部分?
我需要平分一笔债,但要报告一份付款收据。
function calculo_negociacao($amount, $plots, $date, $value_entry) {
$split = [];
$value = $amount / $plots;
$value = number_format((float)$value, 2, '.', '');
$split = array_fill(0, $plots, ['value ' => $value ]);
$date = explode( '-', $date);
$day = $date[0];
$month = $date[1];
$year = $date[2];
for($x = 0; $x < $plots; $x++){
$split[$x]['portion'] = $x + 1;
$split[$x]['date'] = date("Y-m-d",strtotime("+".$x." month",mktime(0, 0, 0, $month, $day, $year)));
}
return $split;
}
$value = 150.07;
$value_entry= 50.00;
$portion = 4;
$date = '04-09-2018';
$negotiation = calculo_negociacao($value, $portion, $date, $value_entry);
var_dump($negotiation);
echo json_encode($negotiation);发布于 2018-09-04 20:02:15
我想你想要这个:
function calculo_negociacao($amount, $plots, $date, $value_entry) {
$plots--; // the first will be the entry
$split = [];
// each plot value
$value = ($amount - $value_entry) / $plots;
$value = number_format((float)$value, 2, '.', '');
// entry + number of plots
$split = array_fill(0, $plots + 1, ['value' => $value ]);
$date = explode( '-', $date);
$day = $date[0];
$month = $date[1];
$year = $date[2];
// position 0 will be the entry
$split[0]['portion'] = 1;
$split[0]['value'] = $value_entry;
$split[0]['date'] = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year));
// plots
for($x = 0; $x < $plots; $x++){
$split[$x + 1]['portion'] = $x + 2;
$split[$x + 1]['date'] = date("Y-m-d",strtotime("+". ($x+1) ." month",mktime(0, 0, 0, $month, $day, $year))); // I changed to ($x+1) here
}
return $split;
}
$value = 150.07;
$value_entry= 50.00;
$portion = 4;
$date = '04-09-2018';
$negotiation = calculo_negociacao($value, $portion, $date, $value_entry);
var_dump($negotiation);
echo json_encode($negotiation);其结果将是:
[
{
"value":50,
"portion":1,
"date":"2018-09-04"
},
{
"value":"33.36",
"portion":2,
"date":"2018-10-04"
},
{
"value":"33.36",
"portion":3,
"date":"2018-11-04"
},
{
"value":"33.36",
"portion":4,
"date":"2018-12-04"
}
]https://stackoverflow.com/questions/52172891
复制相似问题