diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 467448830a7..358e73d4f85 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -2,7 +2,7 @@ /* Copyright (C) 2001-2006 Rodolphe Quiedeville * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2010 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke * * 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') { - $facture = new Facture($db); - $result=$facture->fetch($facid); - - if ($result >= 0) - { - $facture->fetch_thirdparty(); - - $title=''; - if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer"); - if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer"); - print_fiche_titre($title); - - dol_htmloutput_errors($errmsg); - - // Bouchon - if ($facture->type == 2) - { - print $langs->trans("FeatureNotYetAvailable"); - llxFooter(); - exit; - } - - // Initialize data for confirmation (this is used because data can be change during confirmation) - if ($action == 'add_paiement') - { - $i=0; - - $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' => 'type', 'value' => $facture->type); - } - - // Invoice with Paypal transaction - 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 ($conf->use_javascript_ajax && !empty($conf->global->MAIN_JS_ON_PAYMENT)) - { - print "\n".''."\n"; - } - - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; + 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 ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print '
'; // Third party print '\n";
'.$langs->trans('Company').''.$facture->client->getNomUrl(4)."