From e3377b1e29179546a3a005c33978070cf9180b82 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 4 Jul 2008 10:44:54 +0000 Subject: [PATCH] Fix: Error management. Payment date is not preselected to avoid errors. --- htdocs/compta/paiement.php | 342 +++++++++++++++++++------------------ 1 file changed, 172 insertions(+), 170 deletions(-) diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 61b1ec54562..da6e8c872f2 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -20,11 +20,11 @@ */ /** - \file htdocs/compta/paiement.php - \ingroup compta - \brief Page to create a payment - \version $Id$ -*/ + \file htdocs/compta/paiement.php + \ingroup compta + \brief Page to create a payment + \version $Id$ + */ include_once('./pre.inc.php'); require_once(DOL_DOCUMENT_ROOT.'/paiement.class.php'); @@ -47,162 +47,168 @@ $amountsresttopay=array(); $addwarning=0; /* -* Action add_paiement et confirm_paiement -*/ + * Action add_paiement et confirm_paiement + */ if ($_POST['action'] == 'add_paiement' || $_POST['action'] == 'confirm_paiement') { - $error = 0; + $error = 0; - $datepaye = dolibarr_mktime(12, 0 , 0, - $_POST['remonth'], - $_POST['reday'], - $_POST['reyear']); - $paiement_id = 0; - - // Verifie si des paiements sont sup�rieurs au montant facture - foreach ($_POST as $key => $value) - { - if (substr($key,0,7) == 'amount_') - { - $cursorfacid = substr($key,7); - $amounts[$cursorfacid] = price2num($_POST[$key]); - $totalpaiement = $totalpaiement + $amounts[$cursorfacid]; - $tmpfacture=new Facture($db); - $tmpfacture->fetch($cursorfacid); - $amountsresttopay[$cursorfacid]=price2num($tmpfacture->total_ttc-$tmpfacture->getSommePaiement()); - if ($amounts[$cursorfacid] && $amounts[$cursorfacid] > $amountsresttopay[$cursorfacid]) - { - $addwarning=1; - $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' Attention, le montant de paiement pour une ou plusieurs facture est superieur au reste a payer.'; - $formquestion['text'].='
Corriger votre saisie, sinon, confirmer et penser a creer un avoir du trop percu lors de la fermeture de chacune des factures surpayees.'; - } - - $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]); - } - } - - // Effectue les verifications des parametres - if ($_POST['paiementid'] <= 0) - { - $fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'
'; - $error++; - } - - if ($conf->banque->enabled) - { - // Si module bank actif, un compte est obligatoire lors de la saisie - // d'un paiement - if (! $_POST['accountid']) + $datepaye = dolibarr_mktime(12, 0 , 0, + $_POST['remonth'], + $_POST['reday'], + $_POST['reyear']); + $paiement_id = 0; + + // Verifie si des paiements sont sup�rieurs au montant facture + foreach ($_POST as $key => $value) { + if (substr($key,0,7) == 'amount_') + { + $cursorfacid = substr($key,7); + $amounts[$cursorfacid] = price2num($_POST[$key]); + $totalpaiement = $totalpaiement + $amounts[$cursorfacid]; + $tmpfacture=new Facture($db); + $tmpfacture->fetch($cursorfacid); + $amountsresttopay[$cursorfacid]=price2num($tmpfacture->total_ttc-$tmpfacture->getSommePaiement()); + if ($amounts[$cursorfacid] && $amounts[$cursorfacid] > $amountsresttopay[$cursorfacid]) + { + $addwarning=1; + $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' Attention, le montant de paiement pour une ou plusieurs facture est superieur au reste a payer.'; + $formquestion['text'].='
Corriger votre saisie, sinon, confirmer et penser a creer un avoir du trop percu lors de la fermeture de chacune des factures surpayees.'; + } + + $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]); + } + } + + // Effectue les verifications des parametres + if ($_POST['paiementid'] <= 0) + { + $fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'
'; + $error++; + } + + if ($conf->banque->enabled) + { + // Si module bank actif, un compte est obligatoire lors de la saisie + // d'un paiement + if (! $_POST['accountid']) + { $fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'
'; $error++; + } + } + + if ($totalpaiement == 0) + { + $fiche_erreur_message = '
'.$langs->transnoentities('ErrorFieldRequired',$langs->trans('Amount')).'
'; + $error++; + } + + if (empty($datepaye)) + { + $fiche_erreur_message = '
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Date')).'
'; + $error++; } - } - - if ($totalpaiement == 0) - { - $fiche_erreur_message = '
'.$langs->transnoentities('ErrorFieldRequired',$langs->trans('Amount')).'
'; - $error++; - } } /* -* Action add_paiement -*/ + * Action add_paiement + */ if ($_POST['action'] == 'add_paiement') { - if ($error) - { - $_POST['action']=''; - $_GET['action'] = 'create'; - } - // Le reste propre a cette action s'affiche en bas de page. + if ($error) + { + $_POST['action']=''; + $_GET['action'] = 'create'; + } + // Le reste propre a cette action s'affiche en bas de page. } /* -* Action confirm_paiement -*/ + * Action confirm_paiement + */ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes') { - if (! $error) - { - $db->begin(); - - // Creation de la ligne paiement - $paiement = new Paiement($db); - $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Tableau de montant - $paiement->paiementid = $_POST['paiementid']; - $paiement->num_paiement = $_POST['num_paiement']; - $paiement->note = $_POST['comment']; - - $paiement_id = $paiement->create($user); - - if ($paiement_id > 0) - { - if ($conf->banque->enabled) - { - // Insertion dans llx_bank - $label = "(CustomerInvoicePayment)"; - $acc = new Account($db, $_POST['accountid']); - //paiementid contient "CHQ ou VIR par exemple" - $bank_line_id = $acc->addline($paiement->datepaye, - $paiement->paiementid, - $label, - $totalpaiement, - $paiement->num_paiement, + if (! $error) + { + $db->begin(); + + // Creation de la ligne paiement + $paiement = new Paiement($db); + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; // Tableau de montant + $paiement->paiementid = $_POST['paiementid']; + $paiement->num_paiement = $_POST['num_paiement']; + $paiement->note = $_POST['comment']; + + $paiement_id = $paiement->create($user); + + if ($paiement_id > 0) + { + if ($conf->banque->enabled) + { + // Insertion dans llx_bank + $label = "(CustomerInvoicePayment)"; + $acc = new Account($db, $_POST['accountid']); + //paiementid contient "CHQ ou VIR par exemple" + $bank_line_id = $acc->addline($paiement->datepaye, + $paiement->paiementid, + $label, + $totalpaiement, + $paiement->num_paiement, '', - $user, - $_POST['chqemetteur'], - $_POST['chqbank']); - - // Mise a jour fk_bank dans llx_paiement. - // On connait ainsi le paiement qui a g�n�r� l'�criture bancaire - if ($bank_line_id > 0) - { - $paiement->update_fk_bank($bank_line_id); - // Mise a jour liens (pour chaque facture concern�es par le paiement) - foreach ($paiement->amounts as $key => $value) - { - $facid = $key; - $fac = new Facture($db); - $fac->fetch($facid); - $fac->fetch_client(); - $acc->add_url_line($bank_line_id, - $paiement_id, - DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', + $user, + $_POST['chqemetteur'], + $_POST['chqbank']); + + // Mise a jour fk_bank dans llx_paiement. + // On connait ainsi le paiement qui a g�n�r� l'�criture bancaire + if ($bank_line_id > 0) + { + $paiement->update_fk_bank($bank_line_id); + // Mise a jour liens (pour chaque facture concern�es par le paiement) + foreach ($paiement->amounts as $key => $value) + { + $facid = $key; + $fac = new Facture($db); + $fac->fetch($facid); + $fac->fetch_client(); + $acc->add_url_line($bank_line_id, + $paiement_id, + DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', '(paiement)', 'payment'); - $acc->add_url_line($bank_line_id, - $fac->client->id, - DOL_URL_ROOT.'/compta/fiche.php?socid=', - $fac->client->nom, + $acc->add_url_line($bank_line_id, + $fac->client->id, + DOL_URL_ROOT.'/compta/fiche.php?socid=', + $fac->client->nom, 'company'); - } - } - else - { - $error++; - } - } - } - else - { - $error++; - } - - if ($error == 0) - { - $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id; - $db->commit(); - Header('Location: '.$loc); - exit; - } - else - { - $db->rollback(); - } - } + } + } + else + { + $error++; + } + } + } + else + { + $error++; + } + + if ($error == 0) + { + $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id; + $db->commit(); + Header('Location: '.$loc); + exit; + } + else + { + $db->rollback(); + } + } } // S�curit� acc�s client @@ -214,7 +220,7 @@ if ($user->societe_id > 0) /* - * Affichage + * View */ llxHeader(); @@ -227,11 +233,11 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P { $facture = new Facture($db); $result=$facture->fetch($facid); - + if ($result >= 0) { $facture->fetch_client(); - + $title=''; if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer"); if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer"); @@ -244,12 +250,12 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P llxFooter(); exit; } - + // Initialise donnees pour page de confirmation if ($_POST["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); @@ -268,11 +274,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P print ''.$langs->trans('Company').''.$facture->client->getNomUrl(4)."\n"; print ''.$langs->trans('Date').''; - if (!empty($_POST['remonth']) && !empty($_POST['reday']) && !empty($_POST['reyear'])) - $sel_date=mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); - else - $sel_date=''; - $html->select_date($sel_date,'','','','',"add_paiement"); + $html->select_date(-1,'','','',0,"add_paiement"); print ''; print ''.$langs->trans('Comments').''; @@ -286,15 +288,15 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P print ''; if ($conf->banque->enabled) { - if ($facture->type != 2) print ''.$langs->trans('AccountToCredit').''; - if ($facture->type == 2) print ''.$langs->trans('AccountToDebit').''; - print ''; - $html->select_comptes(empty($_POST['accountid'])?'':$_POST['accountid'],'accountid',0,'',1); - print ''; + if ($facture->type != 2) print ''.$langs->trans('AccountToCredit').''; + if ($facture->type == 2) print ''.$langs->trans('AccountToDebit').''; + print ''; + $html->select_comptes(empty($_POST['accountid'])?'':$_POST['accountid'],'accountid',0,'',1); + print ''; } else { - print ' '; + print ' '; } print "\n"; @@ -330,7 +332,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P } else { - $sql .= ' AND type = 2'; + $sql .= ' AND type = 2'; } $sql .= ' GROUP BY f.facnumber'; $resql = $db->query($sql); @@ -365,10 +367,10 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P print ''; print ''; - $facturestatic->ref=$objp->facnumber; - $facturestatic->id=$objp->facid; - $facturestatic->type=$objp->type; - print $facturestatic->getNomUrl(1,''); + $facturestatic->ref=$objp->facnumber; + $facturestatic->id=$objp->facid; + $facturestatic->type=$objp->type; + print $facturestatic->getNomUrl(1,''); print "\n"; // Date @@ -376,10 +378,10 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P // Prix print ''.price($objp->total_ttc).''; - + // Recu print ''.price($objp->am).''; - + // Reste a payer print ''.price($objp->total_ttc - $objp->am).''; @@ -393,11 +395,11 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P print ''; if ($amounts[$facturestatic->id] && $amounts[$facturestatic->id] > $amountsresttopay[$facturestatic->id]) { - print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay")); + print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay")); } print ''; - - + + print "\n"; $total+=$objp->total; @@ -431,24 +433,24 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P { print ''; } - + print ''; // Message d'erreur if ($fiche_erreur_message) { - print ''.$fiche_erreur_message.''; + print $fiche_erreur_message; } // Formulaire confirmation if ($_POST["action"] == 'add_paiement') { -// print ''; + // print ''; print '
'; $text=$langs->trans('ConfirmCustomerPayment',$totalpaiement,$langs->trans("Currency".$conf->monnaie)); $html->form_confirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type,$langs->trans('ReceivedCustomersPayments'),$text,'confirm_paiement',$formquestion); -// print ''; + // print ''; } print "\n";