diff --git a/ChangeLog b/ChangeLog index b0a6fb9eab2..dc680f5a3f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ $Id$ ***** ChangeLog for 3.1 compared to 3.0 ***** For users: +- New: task #10969 : Add checkbox to close automatically invoice to "payed" - New: Can edit note of payment. - New: Login is not mandatory in member module. - New: Reduce a step into supplier order workflow to save time (if user diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index fe87efa7684..8ab2a9c35c2 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -419,10 +419,10 @@ class Facture extends CommonObject /** - * \brief Create a new invoice in database from current invoice - * \param user Object user that ask creation - * \param invertdetail Reverse sign of amounts for lines - * \return int <0 si ko, >0 si ok + * Create a new invoice in database from current invoice + * @param user Object user that ask creation + * @param invertdetail Reverse sign of amounts for lines + * @return int <0 if KO, >0 if OK */ function createFromCurrent($user,$invertdetail=0) { @@ -476,10 +476,10 @@ class Facture extends CommonObject /** - * \brief Load an object from its id and create a new one in database - * \param fromid Id of object to clone - * \param invertdetail Reverse sign of amounts for lines - * \return int New id of clone + * Load an object from its id and create a new one in database + * @param fromid Id of object to clone + * @param invertdetail Reverse sign of amounts for lines + * @return int New id of clone */ function createFromClone($fromid,$invertdetail=0) { @@ -741,8 +741,8 @@ class Facture extends CommonObject /** - * \brief Recupere les lignes de factures dans this->lines - * \return int 1 if OK, < 0 if KO + * Recupere les lignes de factures dans this->lines + * @return int 1 if OK, < 0 if KO */ function fetch_lines() { @@ -1203,11 +1203,11 @@ class Facture extends CommonObject } /** - * \brief Tag la facture comme paye completement (close_code non renseigne) ou partiellement (close_code renseigne) + appel trigger BILL_PAYED - * \param user Objet utilisateur qui modifie - * \param close_code Code renseigne si on classe a payee completement alors que paiement incomplet (cas ecompte par exemple) - * \param close_note Commentaire renseigne si on classe a payee alors que paiement incomplet (cas ecompte par exemple) - * \return int <0 si ok, >0 si ok + * Tag la facture comme paye completement (close_code non renseigne) ou partiellement (close_code renseigne) + appel trigger BILL_PAYED + * @param user Objet utilisateur qui modifie + * @param close_code Code renseigne si on classe a payee completement alors que paiement incomplet (cas escompte par exemple) + * @param close_note Commentaire renseigne si on classe a payee alors que paiement incomplet (cas escompte par exemple) + * @return int <0 si ok, >0 si ok */ function set_paid($user,$close_code='',$close_note='') { @@ -1686,7 +1686,7 @@ class Facture extends CommonObject if (empty($txtva)) $txtva=0; if (empty($txlocaltax1)) $txlocaltax1=0; if (empty($txlocaltax2)) $txlocaltax2=0; - + $remise_percent=price2num($remise_percent); $qty=price2num($qty); $pu_ht=price2num($pu_ht); @@ -2227,7 +2227,7 @@ class Facture extends CommonObject * \param paye Etat paye * \param statut Id statut * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto - * \param alreadypaid Montant deja paye + * \param alreadypaid Montant deja paye * \param type Type facture * \return string Libelle du statut */ diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index b825f1dfed7..1bf1b0ec69b 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -143,49 +143,59 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes') $datepaye = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); + $db->begin(); + + // Creation of payment line + $paiement = new Paiement($db); + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; // Array with all payments dispatching + $paiement->paiementid = dol_getIdFromCode($db,$_POST['paiementcode'],'c_paiement'); + $paiement->num_paiement = $_POST['num_paiement']; + $paiement->note = $_POST['comment']; + if (! $error) { - $db->begin(); - - // Creation de la ligne paiement - $paiement = new Paiement($db); - $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Tableau de montant - $paiement->paiementid = dol_getIdFromCode($db,$_POST['paiementcode'],'c_paiement'); - $paiement->num_paiement = $_POST['num_paiement']; - $paiement->note = $_POST['comment']; - - if (! $error) + $paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0)); + if ($paiement_id < 0) { - $paiement_id = $paiement->create($user); - if ($paiement_id < 0) - { - $errmsg=$paiement->error; - $error++; - } + $errmsg=$paiement->error; + $error++; } + } - if (! $error) - { - $result=$paiement->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']); - if ($result < 0) + if (! $error) + { + $result=$paiement->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']); + if ($result < 0) + { + $errmsg=$paiement->error; + $error++; + } + } + + if (! $error) + { + $db->commit(); + + // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card + $invoiceid=0; + foreach ($paiement->amounts as $key => $amount) + { + $facid = $key; + if (is_numeric($amount) && $amount <> 0) { - $errmsg=$paiement->error; - $error++; + if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment + else $invoiceid=$facid; } - } - - if (! $error) - { - $db->commit(); - $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id; - Header('Location: '.$loc); - exit; - } - else - { - $db->rollback(); - } + } + if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture.php?facid='.$invoiceid; + else $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id; + Header('Location: '.$loc); + exit; + } + else + { + $db->rollback(); } } @@ -197,7 +207,6 @@ if ($_POST['action'] == 'confirm_paiement' && $_POST['confirm'] == 'yes') llxHeader(); $html=new Form($db); -$facturestatic=new Facture($db); if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_POST['action'] == 'add_paiement') @@ -256,7 +265,7 @@ if ($_GET['action'] == 'create' || $_POST['action'] == 'confirm_paiement' || $_P print '});'; print ''."\n"; } - + print '