25if (!defined(
'NOREQUIRESOC')) {
26 define(
'NOREQUIRESOC',
'1');
28if (!defined(
'NOTOKENRENEWAL')) {
29 define(
'NOTOKENRENEWAL',
'1');
31if (!defined(
'NOREQUIREMENU')) {
32 define(
'NOREQUIREMENU',
'1');
34if (!defined(
'NOREQUIREHTML')) {
35 define(
'NOREQUIREHTML',
'1');
39require
'../main.inc.php';
49$langs->load(
'compta');
60$amountPayment =
GETPOST(
'amountPayment');
63$currentInvId =
GETPOST(
'imgClicked');
66$amountPayment = $amountPayment !=
'' ? (is_numeric(
price2num($amountPayment)) ?
price2num($amountPayment) :
'') :
'';
69if (is_array($amounts)) {
70 foreach ($amounts as $key => $value) {
72 $amounts[$key] = $value;
74 unset($amounts[$key]);
79if (is_array($remains)) {
80 foreach ($remains as $key => $value) {
82 $remains[$key] = ($invoice_type == 2 ? -1 : 1) * (
float) $value;
84 unset($remains[$key]);
94$result = ($amountPayment !=
'') ? ((
float) $amountPayment - array_sum($amounts)) : array_sum($amounts);
95$toJsonArray = array();
96$totalRemaining =
price2num(array_sum($remains));
97$toJsonArray[
'label'] = $amountPayment ==
'' ?
'' : $langs->transnoentities(
'RemainingAmountPayment');
100 $currentAmount = $amounts[
'amount_'.$currentInvId];
101 $currentRemain = $remains[
'remain_'.$currentInvId];
104 if ($amountPayment ==
'') {
106 $amountExists = array_key_exists(
'amount_'.$currentInvId, $amounts);
108 $remainAmount = $currentRemain - $currentAmount;
109 $result += $remainAmount;
110 $currentAmount += $remainAmount;
112 $currentAmount = $currentRemain;
113 $result += $currentRemain;
121 $amountToBreakdown = ($result - $currentRemain >= 0 ?
123 $currentRemain + ($result - $currentRemain));
124 $currentAmount = $amountToBreakdown;
125 $result -= $amountToBreakdown;
128 $toJsonArray[
'amount_'.$currentInvId] =
price2num($currentAmount);
131$toJsonArray[
'makeRed'] = ($totalRemaining <
price2num($result) ||
price2num($result) < 0);
132$toJsonArray[
'result'] =
price($result);
133$toJsonArray[
'resultnum'] =
price2num($result);
136echo 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.