Fix: use MAIN_JS_ON_PAYMENT just for the auto-completion payment
This commit is contained in:
parent
244af052cc
commit
196bb42636
@ -2,7 +2,7 @@
|
|||||||
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||||
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||||
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
|
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
|
||||||
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
|
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -210,140 +210,155 @@ $form=new Form($db);
|
|||||||
|
|
||||||
if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement')
|
if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement')
|
||||||
{
|
{
|
||||||
$facture = new Facture($db);
|
$facture = new Facture($db);
|
||||||
$result=$facture->fetch($facid);
|
$result=$facture->fetch($facid);
|
||||||
|
|
||||||
if ($result >= 0)
|
if ($result >= 0)
|
||||||
{
|
{
|
||||||
$facture->fetch_thirdparty();
|
$facture->fetch_thirdparty();
|
||||||
|
|
||||||
$title='';
|
$title='';
|
||||||
if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
|
if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
|
||||||
if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
|
if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
|
||||||
print_fiche_titre($title);
|
print_fiche_titre($title);
|
||||||
|
|
||||||
dol_htmloutput_errors($errmsg);
|
dol_htmloutput_errors($errmsg);
|
||||||
|
|
||||||
// Bouchon
|
// Bouchon
|
||||||
if ($facture->type == 2)
|
if ($facture->type == 2)
|
||||||
{
|
{
|
||||||
print $langs->trans("FeatureNotYetAvailable");
|
print $langs->trans("FeatureNotYetAvailable");
|
||||||
llxFooter();
|
llxFooter();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize data for confirmation (this is used because data can be change during confirmation)
|
// Initialize data for confirmation (this is used because data can be change during confirmation)
|
||||||
if ($action == 'add_paiement')
|
if ($action == 'add_paiement')
|
||||||
{
|
{
|
||||||
$i=0;
|
$i=0;
|
||||||
|
|
||||||
$formquestion[$i++]=array('type' => 'hidden','name' => 'facid', 'value' => $facture->id);
|
$formquestion[$i++]=array('type' => 'hidden','name' => 'facid', 'value' => $facture->id);
|
||||||
$formquestion[$i++]=array('type' => 'hidden','name' => 'socid', 'value' => $facture->socid);
|
$formquestion[$i++]=array('type' => 'hidden','name' => 'socid', 'value' => $facture->socid);
|
||||||
$formquestion[$i++]=array('type' => 'hidden','name' => 'type', 'value' => $facture->type);
|
$formquestion[$i++]=array('type' => 'hidden','name' => 'type', 'value' => $facture->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoice with Paypal transaction
|
// Invoice with Paypal transaction
|
||||||
if ($conf->paypalplus->enabled && $conf->global->PAYPAL_ENABLE_TRANSACTION_MANAGEMENT && ! empty($facture->ref_int))
|
// TODO add hook possibility (regis)
|
||||||
{
|
if ($conf->paypalplus->enabled && $conf->global->PAYPAL_ENABLE_TRANSACTION_MANAGEMENT && ! empty($facture->ref_int))
|
||||||
if (! empty($conf->global->PAYPAL_BANK_ACCOUNT)) $accountid=$conf->global->PAYPAL_BANK_ACCOUNT;
|
{
|
||||||
$paymentnum=$facture->ref_int;
|
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))
|
}
|
||||||
{
|
if ($conf->use_javascript_ajax)
|
||||||
print "\n".'<script type="text/javascript" language="javascript">';
|
{
|
||||||
print 'jQuery(document).ready(function () {';
|
print "\n".'<script type="text/javascript" language="javascript">';
|
||||||
print 'jQuery("#selectpaiementcode").change(function() {
|
print '$(document).ready(function () {
|
||||||
code=jQuery("#selectpaiementcode option:selected").val();
|
setPaiementCode();
|
||||||
if (code == \'CHQ\')
|
|
||||||
{
|
$("#selectpaiementcode").change(function() {
|
||||||
jQuery(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
|
setPaiementCode();
|
||||||
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"];
|
|
||||||
});
|
});
|
||||||
return subJson;
|
|
||||||
}
|
function setPaiementCode()
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
json = jQuery.parseJSON(data);
|
var code = $("#selectpaiementcode option:selected").val();
|
||||||
|
|
||||||
form.data(json);
|
if (code == \'CHQ\')
|
||||||
|
|
||||||
for(var key in json)
|
|
||||||
{
|
{
|
||||||
if(key == "result") {
|
$(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
|
||||||
if(json["makeRed"]) {
|
if ($(\'#fieldchqemetteur\').val() == \'\')
|
||||||
jQuery("#"+key).css("color", "red");
|
{
|
||||||
} else {
|
$(\'#fieldchqemetteur\').val(jQuery(\'#thirdpartylabel\').val());
|
||||||
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]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
else
|
||||||
|
{
|
||||||
}
|
$(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
|
||||||
function callToBreakdown(imgSelector) {
|
$(\'#fieldchqemetteur\').val(\'\');
|
||||||
var form = jQuery("#payment_form"), imgId;
|
}
|
||||||
|
}';
|
||||||
imgId = imgSelector.attr("id");
|
// For paiement auto-completion
|
||||||
callForResult(imgId);
|
if (! empty($conf->global->MAIN_JS_ON_PAYMENT))
|
||||||
}
|
{
|
||||||
|
print "\n".'
|
||||||
jQuery("#payment_form").find("img").click(function() {
|
function elemToJson(selector)
|
||||||
callToBreakdown(jQuery(this));
|
{
|
||||||
});
|
var subJson = {};
|
||||||
|
$.map(selector.serializeArray(), function(n,i)
|
||||||
jQuery("#payment_form").find("input[name*=\"amount_\"]").change(function() {
|
{
|
||||||
callForResult();
|
subJson[n["name"]] = n["value"];
|
||||||
});
|
});
|
||||||
|
return subJson;
|
||||||
jQuery("#amountpayment").change(function() {
|
}
|
||||||
callForResult();
|
function callForResult(imgId)
|
||||||
});
|
{
|
||||||
});
|
var json = {};
|
||||||
</script>'."\n";
|
var form = $("#payment_form");
|
||||||
}
|
|
||||||
|
json["amountPayment"] = $("#amountpayment").attr("value");
|
||||||
print '<form id="payment_form" name="add_paiement" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
|
json["amounts"] = elemToJson(form.find("input[name*=\"amount_\"]"));
|
||||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
json["remains"] = elemToJson(form.find("input[name*=\"remain_\"]"));
|
||||||
print '<input type="hidden" name="action" value="add_paiement">';
|
|
||||||
print '<input type="hidden" name="facid" value="'.$facture->id.'">';
|
if (imgId != null) {
|
||||||
print '<input type="hidden" name="socid" value="'.$facture->socid.'">';
|
json["imgClicked"] = imgId;
|
||||||
print '<input type="hidden" name="type" value="'.$facture->type.'">';
|
}
|
||||||
print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($facture->client->name).'">';
|
|
||||||
|
$.post("ajaxpayment.php", json, function(data)
|
||||||
print '<table class="border" width="100%">';
|
{
|
||||||
|
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'].'">';
|
||||||
|
print '<input type="hidden" name="action" value="add_paiement">';
|
||||||
|
print '<input type="hidden" name="facid" value="'.$facture->id.'">';
|
||||||
|
print '<input type="hidden" name="socid" value="'.$facture->socid.'">';
|
||||||
|
print '<input type="hidden" name="type" value="'.$facture->type.'">';
|
||||||
|
print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($facture->client->name).'">';
|
||||||
|
|
||||||
|
print '<table class="border" width="100%">';
|
||||||
|
|
||||||
// Third party
|
// Third party
|
||||||
print '<tr><td><span class="fieldrequired">'.$langs->trans('Company').'</span></td><td colspan="2">'.$facture->client->getNomUrl(4)."</td></tr>\n";
|
print '<tr><td><span class="fieldrequired">'.$langs->trans('Company').'</span></td><td colspan="2">'.$facture->client->getNomUrl(4)."</td></tr>\n";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user