23 if (!defined(
'NOREQUIRESOC')) {
24 define(
'NOREQUIRESOC',
'1');
26 if (!defined(
'NOTOKENRENEWAL')) {
27 define(
'NOTOKENRENEWAL',
'1');
29 if (!defined(
'NOREQUIREMENU')) {
30 define(
'NOREQUIREMENU',
'1');
32 if (!defined(
'NOREQUIREHTML')) {
33 define(
'NOREQUIREHTML',
'1');
37 require
'../main.inc.php';
39 $langs->load(
'compta');
47 $invoice_type =
GETPOST(
'invoice_type',
'int');
48 $amountPayment =
GETPOST(
'amountPayment');
51 $currentInvId =
GETPOST(
'imgClicked');
54 $amountPayment = $amountPayment !=
'' ? (is_numeric(
price2num($amountPayment)) ?
price2num($amountPayment) :
'') :
'';
57 if (is_array($amounts)) {
58 foreach ($amounts as $key => $value) {
60 $amounts[$key] = $value;
62 unset($amounts[$key]);
67 if (is_array($remains)) {
68 foreach ($remains as $key => $value) {
70 $remains[$key] = (($invoice_type) == 2 ?-1 : 1) * $value;
72 unset($remains[$key]);
78 $result = ($amountPayment !=
'') ? ($amountPayment - array_sum($amounts)) : array_sum($amounts);
79 $toJsonArray = array();
80 $totalRemaining =
price2num(array_sum($remains));
81 $toJsonArray[
'label'] = $amountPayment ==
'' ?
'' : $langs->transnoentities(
'RemainingAmountPayment');
84 $currentAmount = $amounts[
'amount_'.$currentInvId];
85 $currentRemain = $remains[
'remain_'.$currentInvId];
88 if ($amountPayment ==
'') {
90 $amountExists = array_key_exists(
'amount_'.$currentInvId, $amounts);
92 $remainAmount = $currentRemain - $currentAmount;
93 $result += $remainAmount;
94 $currentAmount += $remainAmount;
96 $currentAmount = $currentRemain;
97 $result += $currentRemain;
105 $amountToBreakdown = ($result - $currentRemain >= 0 ?
107 $currentRemain + ($result - $currentRemain));
108 $currentAmount = $amountToBreakdown;
109 $result -= $amountToBreakdown;
112 $toJsonArray[
'amount_'.$currentInvId] =
price2num($currentAmount);
115 $toJsonArray[
'makeRed'] = ($totalRemaining <
price2num($result) ||
price2num($result) < 0) ?
true :
false;
116 $toJsonArray[
'result'] =
price($result);
117 $toJsonArray[
'resultnum'] =
price2num($result);
120 echo json_encode($toJsonArray);
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.