24if (!defined(
'NOREQUIRESOC')) {
25 define(
'NOREQUIRESOC',
'1');
27if (!defined(
'NOTOKENRENEWAL')) {
28 define(
'NOTOKENRENEWAL',
'1');
30if (!defined(
'NOREQUIREMENU')) {
31 define(
'NOREQUIREMENU',
'1');
33if (!defined(
'NOREQUIREHTML')) {
34 define(
'NOREQUIREHTML',
'1');
38require
'../main.inc.php';
40$langs->load(
'compta');
51$amountPayment =
GETPOST(
'amountPayment');
54$currentInvId =
GETPOST(
'imgClicked');
57$amountPayment = $amountPayment !=
'' ? (is_numeric(
price2num($amountPayment)) ?
price2num($amountPayment) :
'') :
'';
60if (is_array($amounts)) {
61 foreach ($amounts as $key => $value) {
63 $amounts[$key] = $value;
65 unset($amounts[$key]);
70if (is_array($remains)) {
71 foreach ($remains as $key => $value) {
73 $remains[$key] = ($invoice_type == 2 ? -1 : 1) * (
float) $value;
75 unset($remains[$key]);
85$result = ($amountPayment !=
'') ? ((
float) $amountPayment - array_sum($amounts)) : array_sum($amounts);
86$toJsonArray = array();
87$totalRemaining =
price2num(array_sum($remains));
88$toJsonArray[
'label'] = $amountPayment ==
'' ?
'' : $langs->transnoentities(
'RemainingAmountPayment');
91 $currentAmount = $amounts[
'amount_'.$currentInvId];
92 $currentRemain = $remains[
'remain_'.$currentInvId];
95 if ($amountPayment ==
'') {
97 $amountExists = array_key_exists(
'amount_'.$currentInvId, $amounts);
99 $remainAmount = $currentRemain - $currentAmount;
100 $result += $remainAmount;
101 $currentAmount += $remainAmount;
103 $currentAmount = $currentRemain;
104 $result += $currentRemain;
112 $amountToBreakdown = ($result - $currentRemain >= 0 ?
114 $currentRemain + ($result - $currentRemain));
115 $currentAmount = $amountToBreakdown;
116 $result -= $amountToBreakdown;
119 $toJsonArray[
'amount_'.$currentInvId] =
price2num($currentAmount);
122$toJsonArray[
'makeRed'] = ($totalRemaining <
price2num($result) ||
price2num($result) < 0);
123$toJsonArray[
'result'] =
price($result);
124$toJsonArray[
'resultnum'] =
price2num($result);
127echo json_encode($toJsonArray);
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.