From a6c6d19b3f4d04b3b75e84b1b375f01301085dad Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 26 Jul 2008 14:48:22 +0000 Subject: [PATCH] Fix: Pb with recurrent invoice --- htdocs/compta/facture/facture-rec.class.php | 71 +++++++++++---------- htdocs/compta/facture/fiche-rec.php | 21 +++--- htdocs/lib/functions.lib.php | 21 +++--- 3 files changed, 60 insertions(+), 53 deletions(-) diff --git a/htdocs/compta/facture/facture-rec.class.php b/htdocs/compta/facture/facture-rec.class.php index c1c996838d5..90254be65e7 100644 --- a/htdocs/compta/facture/facture-rec.class.php +++ b/htdocs/compta/facture/facture-rec.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,16 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ */ /** \file htdocs/compta/facture/facture-rec.class.php \ingroup facture \brief Fichier de la classe des factures recurentes - \version $Revision$ + \version $Id$ */ require_once(DOL_DOCUMENT_ROOT."/notify.class.php"); @@ -81,6 +78,8 @@ class FactureRec extends Facture { global $langs; + $error=0; + // Nettoyage parametere $this->titre=trim($this->titre); @@ -91,6 +90,8 @@ class FactureRec extends Facture return -3; } + $this->db->begin(); + // Charge facture modele $facsrc=new Facture($this->db); $result=$facsrc->fetch($this->facid); @@ -99,8 +100,8 @@ class FactureRec extends Facture // On positionne en mode brouillon la facture $this->brouillon = 1; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (titre, fk_soc, datec, amount, remise, remise_percent, note, fk_user_author,fk_projet, fk_cond_reglement, fk_mode_reglement) "; - $sql.= " VALUES ('$this->titre', '$facsrc->socid', now(), '$facsrc->amount', '$facsrc->remise', '$facsrc->remise_percent', '".addslashes($this->note)."','$user->id',"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (titre, fk_soc, datec, amount, remise, note, fk_user_author,fk_projet, fk_cond_reglement, fk_mode_reglement) "; + $sql.= " VALUES ('$this->titre', '$facsrc->socid', now(), '$facsrc->amount', '$facsrc->remise', '".addslashes($this->note)."','$user->id',"; $sql.= " ".($facsrc->projetid?"'".$facsrc->projetid."'":"null").", "; $sql.= " '".$facsrc->cond_reglement_id."',"; $sql.= " '".$facsrc->mode_reglement_id."')"; @@ -113,38 +114,41 @@ class FactureRec extends Facture */ for ($i = 0 ; $i < sizeof($facsrc->lignes) ; $i++) { - if ($facsrc->lignes[$i]->produit_id > 0) - { - $prod = new Product($this->db); - $prod->fetch($facsrc->lignes[$i]->produit_id); - } - $result_insert = $this->addline($this->id, - addslashes($facsrc->lignes[$i]->desc), - $facsrc->lignes[$i]->subprice, - $facsrc->lignes[$i]->qty, - $facsrc->lignes[$i]->tva_tx, - $facsrc->lignes[$i]->produit_id, - $facsrc->lignes[$i]->remise_percent); + $facsrc->lignes[$i]->desc, + $facsrc->lignes[$i]->subprice, + $facsrc->lignes[$i]->qty, + $facsrc->lignes[$i]->tva_tx, + $facsrc->lignes[$i]->fk_product, + $facsrc->lignes[$i]->remise_percent); - - if ( $result_insert < 0) + if ($result_insert < 0) { - $this->error=$this->db->error().' sql='.$sql; + $error++; } } - - return $this->id; + + if ($error) + { + $this->db->rollback(); + } + else + { + $this->db->commit(); + return $this->id; + } } else { $this->error=$this->db->error().' sql='.$sql; + $this->db->rollback(); return -2; } } else { - return -1; + $this->db->rollback(); + return -1; } } @@ -159,7 +163,7 @@ class FactureRec extends Facture { dolibarr_syslog("Facture::Fetch rowid=".$rowid.", societe_id=".$societe_id, LOG_DEBUG); - $sql = 'SELECT f.fk_soc,f.amount,f.tva,f.total,f.total_ttc,f.remise_percent,f.remise_absolue,f.remise'; + $sql = 'SELECT f.titre,f.fk_soc,f.amount,f.tva,f.total,f.total_ttc,f.remise_percent,f.remise_absolue,f.remise'; $sql.= ','.$this->db->pdate('f.date_lim_reglement').' as dlr'; $sql.= ', f.note, f.note_public, f.fk_user_author'; $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement'; @@ -184,6 +188,7 @@ class FactureRec extends Facture $obj = $this->db->fetch_object($result); $this->id = $rowid; + $this->titre = $obj->titre; $this->ref = $obj->facnumber; $this->ref_client = $obj->ref_client; $this->type = $obj->type; @@ -361,7 +366,7 @@ class FactureRec extends Facture /** * \brief Ajoute une ligne de facture */ - function addline($facid, $desc, $pu, $qty, $txtva, $fk_product='NULL', $remise_percent=0, $price_base_type='HT', $info_bits=0) + function addline($facid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0) { include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); @@ -372,7 +377,7 @@ class FactureRec extends Facture $qty=1; } $remise = 0; - $price = round(price2num($pu), 2); + $price = $pu; $subprice = $price; // Calcul du total TTC et de la TVA pour la ligne a partir de @@ -391,11 +396,11 @@ class FactureRec extends Facture } $sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (fk_facture,description,price,qty,tva_taux, fk_product, remise_percent, subprice, remise, total_ht, total_tva, total_ttc)"; - $sql .= " VALUES ('$facid', '$desc'"; + $sql .= " VALUES ('".$facid."', '".addslashes($desc)."'"; $sql .= ",".price2num($price); $sql .= ",".price2num($qty); $sql .= ",".price2num($txtva); - $sql .= ",'".$fk_product."'"; + $sql .= ",".($fk_product?"'".$fk_product."'":"null"); $sql .= ",'".price2num($remise_percent)."'"; $sql .= ",'".price2num($subprice)."'"; $sql .= ",'".price2num($remise)."'"; @@ -403,7 +408,8 @@ class FactureRec extends Facture $sql .= ",'".price2num($total_tva)."'"; $sql .= ",'".price2num($total_ttc)."') ;"; - if ( $this->db->query( $sql) ) + dolibarr_syslog("Facture-rec::addline sql=".$sql, LOG_DEBUG); + if ($this->db->query( $sql)) { $this->id=$facid; // \TODO A virer $this->update_price(); @@ -411,7 +417,8 @@ class FactureRec extends Facture } else { - print "$sql"; + $this->error=$this->db->lasterror(); + dolibarr_syslog("Facture-rec::addline sql=".$this->error, LOG_ERR); return -1; } } diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index d66e00b25e5..556cac31575 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2006 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,16 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ */ /** \file htdocs/compta/facture/fiche-rec.php \ingroup facture \brief Page d'affichage d'une facture récurrent - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); @@ -94,7 +91,7 @@ if ($_REQUEST["action"] == 'delete' && $user->rights->facture->supprimer) /* - * Affichage page + * View */ llxHeader('',$langs->trans("RepeatableInvoices"),'ch-facture.html#s-fac-facture-rec'); @@ -127,10 +124,10 @@ if ($_GET["action"] == 'create') print ''.$langs->trans("Customer").' :'.$facture->client->nom.''; print ''.$langs->trans("Comment").''; - print ''.$langs->trans("Title").' :'; + print ''.$langs->trans("Title").' :'; print ''; - print ''; + print ''; print "".$langs->trans("Author")." :".$user->fullname.""; @@ -264,7 +261,7 @@ if ($_GET["action"] == 'create') print ''; print ''; } - print ''; + print '
'; print "\n"; print "\n"; @@ -295,7 +292,8 @@ else $author->fetch(); print_titre($langs->trans("PredefinedInvoices").': '.$fac->titre); - + print '
'; + /* * Facture */ @@ -344,7 +342,8 @@ else print_titre($langs->trans("Products")); print ''; - print ''; + print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 8706b2f6186..5d6ab57fc6f 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -2012,16 +2012,16 @@ function price($amount, $html=0, $outlangs='', $trunc=1, $nbdecimal=2) } /** - \brief Fonction qui retourne un num�rique conforme PHP et SQL, depuis un montant au - format utilisateur. - \remarks Fonction a appeler sur montants saisis avant un insert en base - \param amount Montant a formater - \param rounding 'MU'=Round to Max unit price (MAIN_MAX_DECIMALS_UNIT) - 'MT'=Round to Max with Tax (MAIN_MAX_DECIMALS_TOT) - 'MS'=Round to Max Shown (MAIN_MAX_DECIMALS_SHOWN) - ''=No rounding - \return string Montant au format num�rique PHP et SQL (Exemple: '99.99999') - \seealso price Fonction inverse de price2num + * \brief Fonction qui retourne un numerique conforme PHP et SQL, depuis un montant au + * format utilisateur. + * \remarks Fonction a appeler sur montants saisis avant un insert en base + * \param amount Montant a formater + * \param rounding 'MU'=Round to Max unit price (MAIN_MAX_DECIMALS_UNIT) + * 'MT'=Round to Max with Tax (MAIN_MAX_DECIMALS_TOT) + * 'MS'=Round to Max Shown (MAIN_MAX_DECIMALS_SHOWN) + * ''=No rounding + * \return string Montant au format num�rique PHP et SQL (Exemple: '99.99999') + * \seealso price Fonction inverse de price2num */ function price2num($amount,$rounding='') { @@ -2029,6 +2029,7 @@ function price2num($amount,$rounding='') // Round PHP function does not allow number like '1,234.5'. // Numbers must be '1234.5' + // \TODO If there is already a ".", we remove ",", otherwise replace by "." $amount=ereg_replace(',','.',$amount); $amount=ereg_replace(' ','',$amount); if ($rounding)
'.$langs->trans("Ref").''.$langs->trans("Product").'
'.$langs->trans("Description").''.$langs->trans("Price").''.$langs->trans("ReductionShort").''.$langs->trans("Qty").'