Skip to content

Commit

Permalink
Fix: use MAIN_JS_ON_PAYMENT just for the auto-completion payment
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Jan 15, 2012
1 parent 0ac5c68 commit 71e9e53
Showing 1 changed file with 95 additions and 81 deletions.
176 changes: 95 additions & 81 deletions htdocs/compta/paiement.php
Expand Up @@ -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".'<script type="text/javascript" language="javascript">';
print 'jQuery(document).ready(function () {';
print 'jQuery("#selectpaiementcode").change(function() {
code=jQuery("#selectpaiementcode option:selected").val();
if (code == \'CHQ\')
{
jQuery(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
if (jQuery(\'#fieldchqemetteur\').val() == \'\')
{
jQuery(\'#fieldchqemetteur\').val(jQuery(\'#thirdpartylabel\').val());
}
}
else
{
jQuery(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
}
});
function elemToJson(selector)
{
var subJson = {};
jQuery.map(selector.serializeArray(), function(n,i)
{
subJson[n["name"]] = n["value"];
if ($conf->use_javascript_ajax)
{
print "\n".'<script type="text/javascript" language="javascript">';
print '$(document).ready(function () {
setPaiementCode();
$("#selectpaiementcode").change(function() {
setPaiementCode();
});
return subJson;
}
function callForResult(imgId)
{
var json = {};
var form = jQuery("#payment_form");
json["amountPayment"] = jQuery("#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;
jQuery.post("ajaxpayment.php", json, function(data)
function setPaiementCode()
{
json = jQuery.parseJSON(data);
form.data(json);
for(var key in json)
var code = $("#selectpaiementcode option:selected").val();
if (code == \'CHQ\')
{
if(key == "result") {
if(json["makeRed"]) {
jQuery("#"+key).css("color", "red");
} else {
jQuery("#"+key).removeAttr("style");
}
json[key]=json["label"]+" "+json[key];
jQuery("#"+key).text(json[key]);
} else {
form.find("input[name*=\""+key+"\"]").each(function() {
jQuery(this).attr("value", json[key]);
});
$(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
if ($(\'#fieldchqemetteur\').val() == \'\')
{
$(\'#fieldchqemetteur\').val(jQuery(\'#thirdpartylabel\').val());
}
}
});
}
function callToBreakdown(imgSelector) {
var form = jQuery("#payment_form"), imgId;
imgId = imgSelector.attr("id");
callForResult(imgId);
}
jQuery("#payment_form").find("img").click(function() {
callToBreakdown(jQuery(this));
});
jQuery("#payment_form").find("input[name*=\"amount_\"]").change(function() {
callForResult();
});
jQuery("#amountpayment").change(function() {
callForResult();
});
});
</script>'."\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 '});
</script>'."\n";
}

print '<form id="payment_form" name="add_paiement" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
Expand Down

0 comments on commit 71e9e53

Please sign in to comment.