Fix: Pb with recurrent invoice

This commit is contained in:
Laurent Destailleur 2008-07-26 14:48:22 +00:00
parent 4765e6bf91
commit a6c6d19b3f
3 changed files with 60 additions and 53 deletions

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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;
}
}

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 '<tr><td>'.$langs->trans("Customer").' :</td><td>'.$facture->client->nom.'</td>';
print '<td>'.$langs->trans("Comment").'</td></tr>';
print '<tr><td>'.$langs->trans("Title").' :</td><td><input type="text" name="titre" size="16"></td>';
print '<tr><td>'.$langs->trans("Title").' :</td><td><input class="flat" type="text" name="titre" size="16"></td>';
print '<td rowspan="4" valign="top">';
print '<textarea name="note" wrap="soft" cols="60" rows="8"></textarea></td></tr>';
print '<textarea class="flat" name="note" wrap="soft" cols="60" rows="'.ROWS_4.'"></textarea></td></tr>';
print "<tr><td>".$langs->trans("Author")." :</td><td>".$user->fullname."</td></tr>";
@ -264,7 +261,7 @@ if ($_GET["action"] == 'create')
print '</select>';
print '</td></tr>';
}
print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>';
print '<tr><td colspan="3" align="center"><br><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>';
print "</form>\n";
print "</table>\n";
@ -295,7 +292,8 @@ else
$author->fetch();
print_titre($langs->trans("PredefinedInvoices").': '.$fac->titre);
print '<br>';
/*
* Facture
*/
@ -344,7 +342,8 @@ else
print_titre($langs->trans("Products"));
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Product").'</td>';
print '<tr class="liste_titre">';
print '<td colspan="2">'.$langs->trans("Description").'</td>';
print '<td align="right">'.$langs->trans("Price").'</td>';
print '<td align="center">'.$langs->trans("ReductionShort").'</td>';
print '<td align="center">'.$langs->trans("Qty").'</td></tr>';

View File

@ -2012,16 +2012,16 @@ function price($amount, $html=0, $outlangs='', $trunc=1, $nbdecimal=2)
}
/**
\brief Fonction qui retourne un num<EFBFBD>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<EFBFBD>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<EFBFBD>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)