New: Possibilité de modifier la date de fin de validité

This commit is contained in:
Laurent Destailleur 2005-11-04 20:24:40 +00:00
parent d761bc6a2b
commit 6559c4fbc2
2 changed files with 105 additions and 68 deletions

View File

@ -955,7 +955,7 @@ class Facture
} }
/** /**
* \brief Ajoute une ligne de facture (associé à aucun produit/service prédéfini) * \brief Ajoute une ligne de facture (associé à un produit/service prédéfini ou non)
* \param facid id de la facture * \param facid id de la facture
* \param desc description de la ligne * \param desc description de la ligne
* \param pu prix unitaire * \param pu prix unitaire
@ -973,6 +973,8 @@ class Facture
if ($this->brouillon) if ($this->brouillon)
{ {
// Nettoyage paramètres // Nettoyage paramètres
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
if (strlen(trim($qty))==0) $qty=1; if (strlen(trim($qty))==0) $qty=1;
if ($fk_product && ! $pu) if ($fk_product && ! $pu)
@ -982,12 +984,11 @@ class Facture
$pu=$prod->price; $pu=$prod->price;
$txtva=$prod->tva_tx; $txtva=$prod->tva_tx;
} }
$_price = $pu; $price = $pu;
$subprice = $pu; $subprice = $pu;
// Calcul remise et nouveau prix
$remise = 0; $remise = 0;
$remise_percent = trim($remise_percent);
if ($this->socidp) if ($this->socidp)
{ {
$soc = new Societe($this->db); $soc = new Societe($this->db);
@ -1001,11 +1002,11 @@ class Facture
if ($remise_percent > 0) if ($remise_percent > 0)
{ {
$remise = ($pu * $remise_percent / 100); $remise = round(($pu * $remise_percent / 100),2);
$_price = ($pu - $remise); $price = ($pu - $remise);
} }
// Lecture du rang max de la facture // Stockage du rang max de la facture dans rangmax
$sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.'facturedet'; $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.'facturedet';
$sql .= ' WHERE fk_facture ='.$facid; $sql .= ' WHERE fk_facture ='.$facid;
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -1016,12 +1017,12 @@ class Facture
} }
// Formatage des prix // Formatage des prix
$_price = price2num($_price); $price = price2num($price);
$subprice = price2num($subprice); $subprice = price2num($subprice);
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet '; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet ';
$sql.= ' (fk_facture, description, price, qty, tva_taux, fk_product, remise_percent, subprice, remise, date_start, date_end, fk_code_ventilation, rang)'; $sql.= ' (fk_facture, description, price, qty, tva_taux, fk_product, remise_percent, subprice, remise, date_start, date_end, fk_code_ventilation, rang)';
$sql.= " VALUES ($facid, '".addslashes($desc)."','$_price','$qty','$txtva',"; $sql.= " VALUES ($facid, '".addslashes($desc)."','$price','$qty','$txtva',";
if ($fk_product) { $sql.= "'$fk_product',"; } if ($fk_product) { $sql.= "'$fk_product',"; }
else { $sql.='0,'; } else { $sql.='0,'; }
$sql.= " '$remise_percent','$subprice','$remise',"; $sql.= " '$remise_percent','$subprice','$remise',";

View File

@ -55,6 +55,7 @@ class Propal
var $note; var $note;
var $price; var $price;
var $status; var $status;
var $fin_validite;
var $labelstatut=array(); var $labelstatut=array();
var $labelstatut_short=array(); var $labelstatut_short=array();
@ -138,37 +139,43 @@ class Propal
$remise_percent=price2num($remise_percent); $remise_percent=price2num($remise_percent);
$qty=price2num($qty); $qty=price2num($qty);
$prod = new Product($this->db, $idproduct); if ($idproduct)
if ($prod->fetch($idproduct) > 0)
{ {
$price = price2num($prod->price); $prod = new Product($this->db, $idproduct);
$subprice = price2num($prod->price); if ($prod->fetch($idproduct) > 0)
if ($remise_percent > 0)
{ {
$remise = round(($prod->price * $remise_percent / 100), 2); $txtva = $prod->tva_tx;
$price = $prod->price - $remise; $price = price2num($prod->price);
} $subprice = price2num($prod->price);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES "; // Calcul remise et nouveau prix
$sql .= " (".$this->id.",". $idproduct.",'". $qty."','". $price."','".$prod->tva_tx."','".addslashes($p_desc?$p_desc:$prod->label)."','".ereg_replace(",",".",$remise_percent)."','".ereg_replace(",",".",$subprice)."')"; $remise = 0;
if ($remise_percent > 0)
{
$remise = round(($prod->price * $remise_percent / 100), 2);
$price = $prod->price - $remise;
}
if ($this->db->query($sql) ) $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
{ $sql .= " (".$this->id.",". $idproduct.",'". $qty."','". $price."','".$txtva."','".addslashes($p_desc?$p_desc:$prod->label)."','".ereg_replace(",",".",$remise_percent)."','".ereg_replace(",",".",$subprice)."')";
$this->update_price();
return 1; if ($this->db->query($sql) )
{
$this->update_price();
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
} }
else else
{ {
$this->error=$this->db->error(); $this->error=$this->db->error();
return -1; return -2;
} }
} }
else
{
$this->error=$this->db->error();
return -2;
}
} }
else else
{ {
@ -192,12 +199,11 @@ class Propal
dolibarr_syslog("propal.class.php::insert_product_generic $p_desc, $p_price, $p_qty, $p_tva_tx, $remise_percent"); dolibarr_syslog("propal.class.php::insert_product_generic $p_desc, $p_price, $p_qty, $p_tva_tx, $remise_percent");
if ($this->statut == 0) if ($this->statut == 0)
{ {
if (strlen(trim($p_qty)) == 0) // Nettoyage paramètres
{ $remise_percent=price2num($remise_percent);
$p_qty = 1; $p_qty=price2num($p_qty);
} if (strlen(trim($p_qty))==0) $p_qty=1;
$p_price = price2num($p_price);
$p_price = ereg_replace(",",".",$p_price);
$price = $p_price; $price = $p_price;
$subprice = $p_price; $subprice = $p_price;
@ -211,7 +217,6 @@ class Propal
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
$sql .= " (".$this->id.", 0,'". $p_qty."','". ereg_replace(",",".",$price)."','".$p_tva_tx."','".addslashes($p_desc)."','$remise_percent', '".ereg_replace(",",".",$subprice)."') ; "; $sql .= " (".$this->id.", 0,'". $p_qty."','". ereg_replace(",",".",$price)."','".$p_tva_tx."','".addslashes($p_desc)."','$remise_percent', '".ereg_replace(",",".",$subprice)."') ; ";
if ($this->db->query($sql) ) if ($this->db->query($sql) )
{ {
@ -629,40 +634,71 @@ class Propal
} }
} }
/**
* \brief Définit une remise globale sur la proposition
*
*
*/
function set_remise($user, $remise) /**
{ * \brief Définit une remise globale sur la proposition
if ($user->rights->propale->creer) * \param user Objet utilisateur qui modifie
{ * \param remise Montant remise
$remise = ereg_replace(",",".",$remise); * \return int <0 si ko, >0 si ok
*/
function set_echeance($user, $date_fin_validite)
{
if ($user->rights->propale->creer)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".$this->db->idate($date_fin_validite);
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise; if ($this->db->query($sql) )
$sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; {
$this->fin_validite = $date_fin_validite;
return 1;
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Propal::set_echeance Erreur SQL");
return -1;
}
}
}
/**
* \brief Définit une remise globale sur la proposition
* \param user Objet utilisateur qui modifie
* \param remise Montant remise
* \return int <0 si ko, >0 si ok
*/
function set_remise($user, $remise)
{
if ($user->rights->propale->creer)
{
$remise = price2num($remise);
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise;
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
if ($this->db->query($sql) )
{
$this->remise_percent = $remise;
$this->update_price();
return 1;
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Propal::set_remise Erreur SQL");
return -1;
}
}
}
if ($this->db->query($sql) )
{
$this->remise_percent = $remise;
$this->update_price();
return 1;
}
else
{
dolibarr_syslog("Propal::set_remise Erreur SQL");
}
}
}
/* /*
* *
* *
* *
*/ */
function set_project($user, $project_id) function set_project($user, $project_id)
{ {
if ($user->rights->propale->creer) if ($user->rights->propale->creer)