Qual: Uniformize code of payment between customer and supplier payments.

New: Add warning if supplier payment is higher that due amount.
This commit is contained in:
Laurent Destailleur 2014-02-03 18:42:24 +01:00
parent 6896ce0daa
commit e5cd32623c
5 changed files with 146 additions and 69 deletions

View File

@ -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.

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
@ -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 = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'</div>';
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 = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), 'errors');
$error++;
}
}
if (empty($totalpaiement) && empty($atleastonepaymentnotnull))
if (empty($totalpayment) && empty($atleastonepaymentnotnull))
{
$fiche_erreur_message = '<div class="error">'.$langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')).'</div>';
setEventMessage($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), 'errors');
$error++;
}
if (empty($datepaye))
{
$fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Date')).'</div>';
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 = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
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 '</center>';
}
// Message d'erreur
if ($fiche_erreur_message)
{
print $fiche_erreur_message;
}
// Form to confirm payment
if ($action == 'add_paiement')
{
$preselectedchoice=$addwarning?'no':'yes';
print '<br>';
$text=$langs->trans('ConfirmCustomerPayment',$totalpaiement,$langs->trans("Currency".$conf->currency));
$text=$langs->trans('ConfirmCustomerPayment',$totalpayment,$langs->trans("Currency".$conf->currency));
if (GETPOST('closepaidinvoices'))
{
$text.='<br>'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
@ -728,10 +729,10 @@ if (! GETPOST('action'))
print '<td>'.dol_print_date($db->jdate($objp->dp))."</td>\n";
print '<td>'.$objp->paiement_type.' '.$objp->num_paiement."</td>\n";
print '<td align="right">'.price($objp->amount).'</td><td>&nbsp;</td>';
$parameters=array();
$reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$objp,$action); // Note that $action and $object may have been modified by hook
print '</tr>';
$i++;
}

View File

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
@ -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 '<form name="addpaiement" action="paiement.php" method="post">';
print '<form id="payment_form" name="addpaiement" 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="'.$facid.'">';
@ -298,13 +349,16 @@ if ($action == 'create' || $action == 'add_paiement')
$objp = $db->fetch_object($resql);
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td><a href="fiche.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').' '.$objp->ref;
print '</a></td>';
print '<td>';
$invoicesupplierstatic->ref=$objp->ref;
$invoicesupplierstatic->id=$objp->facid;
print $invoicesupplierstatic->getNomUrl(1);
print '</td>';
print '<td>'.$objp->ref_supplier.'</td>';
if ($objp->df > 0 )
{
print '<td align="center">';
print dol_print_date($db->jdate($objp->df)).'</td>';
print dol_print_date($db->jdate($objp->df), 'day').'</td>';
}
else
{
@ -343,10 +397,27 @@ if ($action == 'create' || $action == 'add_paiement')
}
}
// print '<tr><td colspan="3" align="center">';
print '<center><br><input type="checkbox" checked="checked" name="closepaidinvoices"> '.$langs->trans("ClosePaidInvoicesAutomatically");
print '<br><input type="submit" class="button" value="'.$langs->trans('Save').'"></center>';
// print '</td></tr>';
// Bouton Enregistrer
if ($action != 'add_paiement')
{
print '<center><br><input type="checkbox" checked="checked" name="closepaidinvoices"> '.$langs->trans("ClosePaidInvoicesAutomatically");
print '<br><input type="submit" class="button" value="'.$langs->trans('Save').'"></center>';
}
// Form to confirm payment
if ($action == 'add_paiement')
{
$preselectedchoice=$addwarning?'no':'yes';
print '<br>';
$text=$langs->trans('ConfirmSupplierPayment',$totalpayment,$langs->trans("Currency".$conf->currency));
if (GETPOST('closepaidinvoices'))
{
$text.='<br>'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
print '<input type="hidden" name="closepaidinvoices" value="'.GETPOST('closepaidinvoices').'">';
}
$form->form_confirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type,$langs->trans('PayedSuppliersPayments'),$text,'confirm_paiement',$formquestion,$preselectedchoice);
}
print '</form>';
}

View File

@ -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. <br> 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. <br> 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. <br> 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 <b>%s</b> %s ?
ConfirmSupplierPayment=Do you confirm this payment input for <b>%s</b> %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

View File

@ -130,6 +130,7 @@ ErrorPHPNeedModule=Error, your PHP must have module <b>%s</b> 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