diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 4498c265786a8..54670e67a3f2f 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -252,92 +252,106 @@ if (! empty($conf->global->PAYPAL_BANK_ACCOUNT)) $accountid=$conf->global->PAYPAL_BANK_ACCOUNT; $paymentnum=$facture->ref_int; } - if ($conf->use_javascript_ajax && !empty($conf->global->MAIN_JS_ON_PAYMENT)) - { - print "\n".''."\n"; - } + else + { + $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\'); + $(\'#fieldchqemetteur\').val(\'\'); + } + }'; + // For paiement auto-completion + if (! empty($conf->global->MAIN_JS_ON_PAYMENT)) + { + print "\n".' + function elemToJson(selector) + { + var subJson = {}; + $.map(selector.serializeArray(), function(n,i) + { + subJson[n["name"]] = n["value"]; + }); + return subJson; + } + function callForResult(imgId) + { + var json = {}; + 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_\"]")); + + if (imgId != null) { + json["imgClicked"] = imgId; + } + + $.post("ajaxpayment.php", json, function(data) + { + json = $.parseJSON(data); + + form.data(json); + + for (var key in json) + { + if (key == "result") { + if (json["makeRed"]) { + $("#"+key).css("color", "red"); + } else { + $("#"+key).removeAttr("style"); + } + json[key]=json["label"]+" "+json[key]; + $("#"+key).text(json[key]); + } else { + form.find("input[name*=\""+key+"\"]").each(function() { + $(this).attr("value", json[key]); + }); + } + } + }); + } + 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(); + }); + + $("#amountpayment").change(function() { + callForResult(); + });'; + } + print '}); + '."\n"; + } print '
'; print '';