23if (!defined(
'NOREQUIRESOC')) {
24 define(
'NOREQUIRESOC',
'1');
26if (!defined(
'NOTOKENRENEWAL')) {
27 define(
'NOTOKENRENEWAL',
'1');
29if (!defined(
'NOREQUIREMENU')) {
30 define(
'NOREQUIREMENU',
'1');
32if (!defined(
'NOREQUIREHTML')) {
33 define(
'NOREQUIREHTML',
'1');
37require
'../main.inc.php';
39$langs->load(
'compta');
49$invoice_type =
GETPOST(
'invoice_type',
'int');
50$amountPayment =
GETPOST(
'amountPayment');
53$currentInvId =
GETPOST(
'imgClicked');
56$amountPayment = $amountPayment !=
'' ? (is_numeric(
price2num($amountPayment)) ?
price2num($amountPayment) :
'') :
'';
59if (is_array($amounts)) {
60 foreach ($amounts as $key => $value) {
62 $amounts[$key] = $value;
64 unset($amounts[$key]);
69if (is_array($remains)) {
70 foreach ($remains as $key => $value) {
72 $remains[$key] = (($invoice_type) == 2 ?-1 : 1) * $value;
74 unset($remains[$key]);
84$result = ($amountPayment !=
'') ? ($amountPayment - array_sum($amounts)) : array_sum($amounts);
85$toJsonArray = array();
86$totalRemaining =
price2num(array_sum($remains));
87$toJsonArray[
'label'] = $amountPayment ==
'' ?
'' : $langs->transnoentities(
'RemainingAmountPayment');
90 $currentAmount = $amounts[
'amount_'.$currentInvId];
91 $currentRemain = $remains[
'remain_'.$currentInvId];
94 if ($amountPayment ==
'') {
96 $amountExists = array_key_exists(
'amount_'.$currentInvId, $amounts);
98 $remainAmount = $currentRemain - $currentAmount;
99 $result += $remainAmount;
100 $currentAmount += $remainAmount;
102 $currentAmount = $currentRemain;
103 $result += $currentRemain;
111 $amountToBreakdown = ($result - $currentRemain >= 0 ?
113 $currentRemain + ($result - $currentRemain));
114 $currentAmount = $amountToBreakdown;
115 $result -= $amountToBreakdown;
118 $toJsonArray[
'amount_'.$currentInvId] =
price2num($currentAmount);
121$toJsonArray[
'makeRed'] = ($totalRemaining <
price2num($result) ||
price2num($result) < 0) ?
true : false;
122$toJsonArray[
'result'] =
price($result);
123$toJsonArray[
'resultnum'] =
price2num($result);
126echo 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.