diff --git a/htdocs/compta/ajaxpayment.php b/htdocs/compta/ajaxpayment.php index e9ceafdaf52..d0b49b78762 100644 --- a/htdocs/compta/ajaxpayment.php +++ b/htdocs/compta/ajaxpayment.php @@ -18,7 +18,6 @@ /** * \file htdocs/compta/ajaxpayment.php * \brief File to return Ajax response on payment breakdown process - * \version ajaxpayment.php,v 1.0 */ //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); @@ -45,10 +44,7 @@ $currentInvId = $_POST['imgClicked']; // from DOM elements : imgId (equals invo // Getting the posted keys=>values, sanitize the ones who are from text inputs // from text inputs : total amount -$amountPayment = $amountPayment!='' ? ( is_numeric(price2num($amountPayment)) ? price2num($amountPayment) - : '' - ) - : ''; // keep void if not a valid entry +$amountPayment = $amountPayment!='' ? ( is_numeric(price2num($amountPayment)) ? price2num($amountPayment) : '' ) : ''; // keep void if not a valid entry // Checkamounts foreach ($amounts as $key => $value) { @@ -60,7 +56,7 @@ foreach ($amounts as $key => $value) $result = $amountPayment != '' ? $amountPayment - array_sum($amounts) : $amountPayment + array_sum($amounts); // Remaining amountPayment $toJsonArray = array(); $totalRemaining = price2num(array_sum($remains)); -$toJsonArray['label'] = $amountPayment == '' ? $langs->transnoentities('AmountToBeCharged') : $langs->transnoentities('RemainingAmountPayment'); +$toJsonArray['label'] = $amountPayment == '' ? '' : $langs->transnoentities('RemainingAmountPayment'); if($currentInvId) // Here to breakdown { // Get the current amount (from form) and the corresponding remainToPay (from invoice) diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index b1896db302a..04a4af7e09d 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -280,12 +280,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\'); $(\'#fieldchqemetteur\').val(\'\'); } - }'; - // For paiement auto-completion - if (! empty($conf->global->MAIN_JS_ON_PAYMENT)) - { - print "\n".' - function elemToJson(selector) + } + + function _elemToJson(selector) { var subJson = {}; $.map(selector.serializeArray(), function(n,i) @@ -300,14 +297,14 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie var form = $("#payment_form"); json["amountPayment"] = $("#amountpayment").attr("value"); - json["amounts"] = elemToJson(form.find("input[name*=\"amount_\"]")); - json["remains"] = elemToJson(form.find("input[name*=\"remain_\"]")); + json["amounts"] = _elemToJson(form.find("input[name*=\"amount_\"]")); + json["remains"] = _elemToJson(form.find("input[name*=\"remain_\"]")); if (imgId != null) { json["imgClicked"] = imgId; } - $.post("ajaxpayment.php", json, function(data) + $.post("'.DOL_URL_ROOT.'/compta/ajaxpayment.php", json, function(data) { json = $.parseJSON(data); @@ -317,9 +314,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie { if (key == "result") { if (json["makeRed"]) { - $("#"+key).css("color", "red"); + $("#"+key).addClass("error"); } else { - $("#"+key).removeAttr("style"); + $("#"+key).removeClass("error"); } json[key]=json["label"]+" "+json[key]; $("#"+key).text(json[key]); @@ -331,27 +328,27 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie } }); } - function callToBreakdown(imgSelector) { - var form = $("#payment_form"), imgId; - - imgId = imgSelector.attr("id"); - callForResult(imgId); - } - - $("#payment_form").find("img").click(function() { - callToBreakdown(jQuery(this)); - }); - $("#payment_form").find("input[name*=\"amount_\"]").change(function() { callForResult(); }); + $("#payment_form").find("input[name*=\"amount_\"]").keyup(function() { + callForResult(); + }); + '; + + if (! empty($conf->global->MAIN_JS_ON_PAYMENT)) + { + print ' $("#payment_form").find("img").click(function() { + callForResult(jQuery(this).attr("id")); + }); $("#amountpayment").change(function() { callForResult(); });'; } - print '}); - '."\n"; + + print ' });'."\n"; + print ' '."\n"; } print '