From e5cd32623c715025219ff9104dd742ffd7e3f9e5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 3 Feb 2014 18:42:24 +0100 Subject: [PATCH] Qual: Uniformize code of payment between customer and supplier payments. New: Add warning if supplier payment is higher that due amount. --- ChangeLog | 1 + htdocs/compta/paiement.php | 83 ++++++++++---------- htdocs/fourn/facture/paiement.php | 125 +++++++++++++++++++++++------- htdocs/langs/en_US/bills.lang | 5 +- htdocs/langs/en_US/errors.lang | 1 + 5 files changed, 146 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3bac0d7f4f3..1f76a3d4351 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,7 @@ For users: public votes - New: The box "balance of bank accounts" show all opened accounts. - New: Add option MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE. +- New: Add warning if supplier payment is higher that due amount. TODO - New: Predefined product and free product use same form. diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 3b9d257314e..ce369effb49 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke @@ -21,8 +21,8 @@ /** * \file htdocs/compta/paiement.php - * \ingroup compta - * \brief Page to create a payment + * \ingroup facture + * \brief Payment page for customers invoices */ require '../main.inc.php'; @@ -34,7 +34,7 @@ $langs->load('companies'); $langs->load('bills'); $langs->load('banks'); -$action = GETPOST('action'); +$action = GETPOST('action','alpha'); $confirm = GETPOST('confirm'); $facid = GETPOST('facid','int'); @@ -66,40 +66,51 @@ if ($facid > 0) } // Initialize technical object to manage hooks of paiements. Note that conf->hooks_modules contains array array -$hookmanager = new HookManager($db); $hookmanager->initHooks(array('paiementcard')); $parameters=array('socid'=>$socid); -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks /* - * Action add_paiement et confirm_paiement + * Actions */ if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes')) { $error = 0; - $datepaye = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $paiement_id = 0; - $totalpaiement = 0; + $totalpayment = 0; $atleastonepaymentnotnull = 0; - // Verifie si des paiements sont superieurs au montant facture + // Generate payment array and check if there is payment higher than invoice and payment date before invoice date + $tmpinvoice=new Facture($db); foreach ($_POST as $key => $value) { if (substr($key,0,7) == 'amount_') { $cursorfacid = substr($key,7); - $amounts[$cursorfacid] = price2num(trim($_POST[$key])); - $totalpaiement = $totalpaiement + $amounts[$cursorfacid]; + $amounts[$cursorfacid] = price2num(trim(GETPOST($key))); + $totalpayment = $totalpayment + $amounts[$cursorfacid]; if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++; - $tmpfacture=new Facture($db); - $tmpfacture->fetch($cursorfacid); - $amountsresttopay[$cursorfacid]=price2num($tmpfacture->total_ttc-$tmpfacture->getSommePaiement()); - if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) + $result=$tmpinvoice->fetch($cursorfacid); + if ($result <= 0) dol_print_error($db); + $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement()); + if ($amounts[$cursorfacid]) { - $addwarning=1; - $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay"); + // Check amount + if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) + { + $addwarning=1; + $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay"); + } + // Check date + if ($datepaye && ($datepaye < $tmpinvoice->date)) + { + $langs->load("errors"); + $error++; + setEventMessage($langs->transnoentities("ErrorPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), 'errors'); + } } $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]); @@ -109,7 +120,7 @@ if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='ye // Check parameters if (! GETPOST('paiementcode')) { - $fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'
'; + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), 'errors'); $error++; } @@ -118,20 +129,20 @@ if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='ye // If bank module is on, account is required to enter a payment if (GETPOST('accountid') <= 0) { - $fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'
'; + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors'); $error++; } } - if (empty($totalpaiement) && empty($atleastonepaymentnotnull)) + if (empty($totalpayment) && empty($atleastonepaymentnotnull)) { - $fiche_erreur_message = '
'.$langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')).'
'; + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), 'errors'); $error++; } if (empty($datepaye)) { - $fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Date')).'
'; + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), 'errors'); $error++; } } @@ -155,7 +166,7 @@ if ($action == 'confirm_paiement' && $confirm == 'yes') { $error=0; - $datepaye = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $db->begin(); @@ -174,7 +185,7 @@ if ($action == 'confirm_paiement' && $confirm == 'yes') // Si module bank actif, un compte est obligatoire lors de la saisie d'un paiement if (GETPOST('accountid') <= 0) { - $fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'
'; + setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors'); $error++; } } @@ -192,7 +203,7 @@ if ($action == 'confirm_paiement' && $confirm == 'yes') $paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices')=='on'?1:0)); if ($paiement_id < 0) { - $errmsg=$paiement->error; + setEventMessage($paiement->error, 'errors'); $error++; } } @@ -204,7 +215,7 @@ if ($action == 'confirm_paiement' && $confirm == 'yes') $result=$paiement->addPaymentToBank($user,'payment',$label,GETPOST('accountid'),GETPOST('chqemetteur'),GETPOST('chqbank')); if ($result < 0) { - $errmsg=$paiement->error; + setEventMessage($paiement->error, 'errors'); $error++; } } @@ -259,8 +270,6 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer"); print_fiche_titre($title); - dol_htmloutput_errors($errmsg); - // Initialize data for confirmation (this is used because data can be change during confirmation) if ($action == 'add_paiement') { @@ -625,7 +634,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $db->free($resql); } else - { + { dol_print_error($db); } @@ -649,21 +658,13 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; } - - - // Message d'erreur - if ($fiche_erreur_message) - { - print $fiche_erreur_message; - } - // Form to confirm payment if ($action == 'add_paiement') { $preselectedchoice=$addwarning?'no':'yes'; print '
'; - $text=$langs->trans('ConfirmCustomerPayment',$totalpaiement,$langs->trans("Currency".$conf->currency)); + $text=$langs->trans('ConfirmCustomerPayment',$totalpayment,$langs->trans("Currency".$conf->currency)); if (GETPOST('closepaidinvoices')) { $text.='
'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed"); @@ -728,10 +729,10 @@ if (! GETPOST('action')) print ''.dol_print_date($db->jdate($objp->dp))."\n"; print ''.$objp->paiement_type.' '.$objp->num_paiement."\n"; print ''.price($objp->amount).' '; - + $parameters=array(); $reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$objp,$action); // Note that $action and $object may have been modified by hook - + print ''; $i++; } diff --git a/htdocs/fourn/facture/paiement.php b/htdocs/fourn/facture/paiement.php index 8f3f2909832..f76aa0aa789 100644 --- a/htdocs/fourn/facture/paiement.php +++ b/htdocs/fourn/facture/paiement.php @@ -1,7 +1,7 @@ * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2004 Christophe Combelles * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin @@ -35,8 +35,10 @@ $langs->load('companies'); $langs->load('bills'); $langs->load('banks'); +$action = GETPOST('action','alpha'); +$confirm = GETPOST('confirm'); + $facid=GETPOST('facid','int'); -$action=GETPOST('action','alpha'); $socid=GETPOST('socid','int'); $sortfield = GETPOST("sortfield",'alpha'); @@ -62,59 +64,107 @@ if ($user->societe_id > 0) // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('paymentsupplier')); +$parameters=array('socid'=>$socid); +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks /* * Actions */ -if ($action == 'add_paiement') +if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes')) { $error = 0; - $datepaye = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $paiement_id = 0; - $total = 0; + $totalpayment = 0; + $atleastonepaymentnotnull = 0; - // Genere tableau des montants amounts + // Generate payment array and check if there is payment higher than invoice and payment date before invoice date + $tmpinvoice=new FactureFournisseur($db); foreach ($_POST as $key => $value) { if (substr($key,0,7) == 'amount_') { - $other_facid = substr($key,7); - $amounts[$other_facid] = price2num(GETPOST($key)); - $total = $total + $amounts[$other_facid]; + $cursorfacid = substr($key,7); + $amounts[$cursorfacid] = price2num(trim(GETPOST($key))); + $totalpayment = $totalpayment + $amounts[$cursorfacid]; + if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++; + $result=$tmpinvoice->fetch($cursorfacid); + if ($result <= 0) dol_print_error($db); + $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement()); + if ($amounts[$cursorfacid]) + { + // Check amount + if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid]))) + { + $addwarning=1; + $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier"); + } + // Check date + if ($datepaye && ($datepaye < $tmpinvoice->date)) + { + $langs->load("errors"); + $error++; + setEventMessage($langs->transnoentities("ErrorPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), 'errors'); + } + } + + $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]); } } - // Effectue les verifications des parametres + // Check parameters if ($_POST['paiementid'] <= 0) { - setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), 'errors'); + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), 'errors'); $error++; } if (! empty($conf->banque->enabled)) { - // Si module bank actif, un compte est obligatoire lors de la saisie - // d'un paiement - if (! $_POST['accountid']) + // If bank module is on, account is required to enter a payment + if (GETPOST('accountid') <= 0) { - setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors'); + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors'); $error++; } } - if ($total == 0) + if (empty($totalpayment) && empty($atleastonepaymentnotnull)) { - setEventMessage($langs->trans('ErrorFieldRequired',$langs->trans('PaymentAmount')), 'errors'); + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), 'errors'); $error++; } if (empty($datepaye)) { - setEventMessage($langs->trans('ErrorFieldRequired',$langs->transnoentities('Date')), 'errors'); + setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), 'errors'); $error++; } +} +/* + * Action add_paiement + */ +if ($action == 'add_paiement') +{ + if ($error) + { + $action = 'create'; + } + // Le reste propre a cette action s'affiche en bas de page. +} + + +/* + * Action confirm_paiement + */ +if ($action == 'confirm_paiement' && $confirm == 'yes') +{ + $error=0; + + $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); + if (! $error) { $db->begin(); @@ -174,6 +224,7 @@ if ($action == 'add_paiement') } + /* * View */ @@ -185,7 +236,7 @@ llxHeader(); $form=new Form($db); -if ($action == 'create' || $action == 'add_paiement') +if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement') { $object = new FactureFournisseur($db); $object->fetch($facid); @@ -212,7 +263,7 @@ if ($action == 'create' || $action == 'add_paiement') print_fiche_titre($langs->trans('DoPayment')); - print '
'; + print ''; print ''; print ''; print ''; @@ -298,13 +349,16 @@ if ($action == 'create' || $action == 'add_paiement') $objp = $db->fetch_object($resql); $var=!$var; print ''; - print ''.img_object($langs->trans('ShowBill'),'bill').' '.$objp->ref; - print ''; + print ''; + $invoicesupplierstatic->ref=$objp->ref; + $invoicesupplierstatic->id=$objp->facid; + print $invoicesupplierstatic->getNomUrl(1); + print ''; print ''.$objp->ref_supplier.''; if ($objp->df > 0 ) { print ''; - print dol_print_date($db->jdate($objp->df)).''; + print dol_print_date($db->jdate($objp->df), 'day').''; } else { @@ -343,10 +397,27 @@ if ($action == 'create' || $action == 'add_paiement') } } - // print ''; - print '

'.$langs->trans("ClosePaidInvoicesAutomatically"); - print '
'; - // print ''; + // Bouton Enregistrer + if ($action != 'add_paiement') + { + print '

'.$langs->trans("ClosePaidInvoicesAutomatically"); + print '
'; + } + + // Form to confirm payment + if ($action == 'add_paiement') + { + $preselectedchoice=$addwarning?'no':'yes'; + + print '
'; + $text=$langs->trans('ConfirmSupplierPayment',$totalpayment,$langs->trans("Currency".$conf->currency)); + if (GETPOST('closepaidinvoices')) + { + $text.='
'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed"); + print ''; + } + $form->form_confirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type,$langs->trans('PayedSuppliersPayments'),$text,'confirm_paiement',$formquestion,$preselectedchoice); + } print '
'; } diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 7b553e0fcb2..4171fa5b675 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -64,6 +64,7 @@ ConfirmConvertToReduc=Do you want to convert this credit note or deposit into an SupplierPayments=Suppliers payments ReceivedPayments=Received payments ReceivedCustomersPayments=Payments received from customers +PayedSuppliersPayments=Payments payed to suppliers ReceivedCustomersPaymentsToValid=Received customers payments to validate PaymentsReportsForYear=Payments reports for %s PaymentsReports=Payments reports @@ -76,7 +77,8 @@ PaymentConditionsShort=Payment term PaymentAmount=Payment amount ValidatePayment=Validate payment PaymentHigherThanReminderToPay=Payment higher than reminder to pay -HelpPaymentHigherThanReminderToPay= Attention, the payment amount of one or more bills is higher than the rest to pay.
Edit your entry, otherwise confirm and think about creating a credit note of the excess received for each overpaid invoices. +HelpPaymentHigherThanReminderToPay=Attention, the payment amount of one or more bills is higher than the rest to pay.
Edit your entry, otherwise confirm and think about creating a credit note of the excess received for each overpaid invoices. +HelpPaymentHigherThanReminderToPaySupplier=Attention, the payment amount of one or more bills is higher than the rest to pay.
Edit your entry, otherwise confirm. ClassifyPaid=Classify 'Paid' ClassifyPaidPartially=Classify 'Paid partially' ClassifyCanceled=Classify 'Abandoned' @@ -166,6 +168,7 @@ ConfirmClassifyPaidPartiallyReasonOtherDesc=Use this choice if all other does no ConfirmClassifyAbandonReasonOther=Other ConfirmClassifyAbandonReasonOtherDesc=This choice will be used in all other cases. For example because you plan to create a replacing invoice. ConfirmCustomerPayment=Do you confirm this payment input for %s %s ? +ConfirmSupplierPayment=Do you confirm this payment input for %s %s ? ConfirmValidatePayment=Are you sure you want to validate this payment ? No change can be made once payment is validated. ValidateBill=Validate invoice UnvalidateBill=Unvalidate invoice diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index c466fa5df1c..5dd292aa10b 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -130,6 +130,7 @@ ErrorPHPNeedModule=Error, your PHP must have module %s installed to use t ErrorOpenIDSetupNotComplete=You setup Dolibarr config file to allow OpenID authentication, but URL of OpenID service is not defined into constant %s ErrorWarehouseMustDiffers=Source and target warehouses must differs ErrorBadFormat=Bad format! +ErrorPaymentDateLowerThanInvoiceDate=Payment date (%s) cant' be before invoice date (%s) for invoice %s. # Warnings WarningMandatorySetupNotComplete=Mandatory setup parameters are not yet defined