Fix: Correction bug divers sur ajout ligne pour un produit avec prix fixé en TTC.
This commit is contained in:
parent
9acbd9d490
commit
4a9e8c7769
@ -1066,6 +1066,8 @@ if ($_GET['propalid'] > 0)
|
|||||||
if ($_GET['action'] != 'editline' || $_GET['ligne'] != $objp->rowid)
|
if ($_GET['action'] != 'editline' || $_GET['ligne'] != $objp->rowid)
|
||||||
{
|
{
|
||||||
print '<tr '.$bc[$var].'>';
|
print '<tr '.$bc[$var].'>';
|
||||||
|
|
||||||
|
// Produit
|
||||||
if ($objp->fk_product > 0)
|
if ($objp->fk_product > 0)
|
||||||
{
|
{
|
||||||
print '<td>';
|
print '<td>';
|
||||||
@ -1129,9 +1131,12 @@ if ($_GET['propalid'] > 0)
|
|||||||
}
|
}
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
}
|
}
|
||||||
if ($objp->fk_product_type==0 && $conf->global->PRODUIT_USE_MARKUP && $conf->use_ajax)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
if ($conf->global->PRODUIT_USE_MARKUP)
|
||||||
|
{
|
||||||
|
// Champ ???
|
||||||
|
if ($objp->fk_product_type==0 && $conf->use_ajax)
|
||||||
|
{
|
||||||
$formMarkup = '<form id="formMarkup" action="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'" method="post">'."\n";
|
$formMarkup = '<form id="formMarkup" action="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'" method="post">'."\n";
|
||||||
$formMarkup.= '<table class="border" width="100%">'."\n";
|
$formMarkup.= '<table class="border" width="100%">'."\n";
|
||||||
if ($objp->fk_product > 0)
|
if ($objp->fk_product > 0)
|
||||||
@ -1186,8 +1191,12 @@ if ($_GET['propalid'] > 0)
|
|||||||
{
|
{
|
||||||
print '<td> </td>';
|
print '<td> </td>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// VAT Rate
|
||||||
print '<td align="right">'.vatrate($objp->tva_tx).'%</td>';
|
print '<td align="right">'.vatrate($objp->tva_tx).'%</td>';
|
||||||
|
|
||||||
|
// U.P HT
|
||||||
print '<td align="right">'.price($objp->subprice)."</td>\n";
|
print '<td align="right">'.price($objp->subprice)."</td>\n";
|
||||||
|
|
||||||
// Qty
|
// Qty
|
||||||
@ -1198,6 +1207,8 @@ if ($_GET['propalid'] > 0)
|
|||||||
}
|
}
|
||||||
else print ' ';
|
else print ' ';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
|
// Remise %
|
||||||
if ($objp->remise_percent > 0)
|
if ($objp->remise_percent > 0)
|
||||||
{
|
{
|
||||||
print '<td align="right">'.$objp->remise_percent."%</td>\n";
|
print '<td align="right">'.$objp->remise_percent."%</td>\n";
|
||||||
|
|||||||
@ -605,14 +605,18 @@ class Commande extends CommonObject
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Ajout d'un produit dans la commande, en base
|
* \brief Ajoute une ligne de produit (associé à un produit/service prédéfini ou non)
|
||||||
* \param commandeid id de la commande
|
* \param commandeid Id de la commande
|
||||||
* \param desc description de la ligne
|
* \param desc Description de la ligne
|
||||||
* \param pu prix unitaire
|
* \param pu_ht Prix unitaire HT
|
||||||
* \param qty quantité
|
* \param qty Quantité
|
||||||
* \param txtva taux de tva forcé, sinon -1
|
* \param txtva Taux de tva forcé, sinon -1
|
||||||
* \param fk_product id du produit/service predéfini
|
* \param fk_product Id du produit/service predéfini
|
||||||
* \param remise_percent pourcentage de remise de la ligne
|
* \param remise_percent Pourcentage de remise de la ligne
|
||||||
|
* \param info_bits Bits de type de lignes
|
||||||
|
* \param fk_remise_exscept Id remise
|
||||||
|
* \param price_base_type HT or TTC
|
||||||
|
* \param pu_ttc Prix unitaire TTC
|
||||||
* \return int >0 si ok, <0 si ko
|
* \return int >0 si ok, <0 si ko
|
||||||
* \see add_product
|
* \see add_product
|
||||||
* \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel
|
* \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel
|
||||||
@ -620,9 +624,9 @@ class Commande extends CommonObject
|
|||||||
* par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit)
|
* par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit)
|
||||||
* et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
|
* et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
|
||||||
*/
|
*/
|
||||||
function addline($commandeid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $fk_remise_except=0, $info_bits=0, $price_base_type='HT')
|
function addline($commandeid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0)
|
||||||
{
|
{
|
||||||
dolibarr_syslog("Commande.class.php::addline this->id=$this->id, $commandeid, $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
|
dolibarr_syslog("Commande::addline $commandeid, $desc, $pu, $qty, $txtva, $fk_product, $remise_percent, $info_bits, $fk_remise_except, $price_base_type, $pu_ttc");
|
||||||
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
|
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
|
||||||
|
|
||||||
if ($this->statut == 0)
|
if ($this->statut == 0)
|
||||||
@ -633,20 +637,26 @@ class Commande extends CommonObject
|
|||||||
$remise_percent=price2num($remise_percent);
|
$remise_percent=price2num($remise_percent);
|
||||||
$qty=price2num($qty);
|
$qty=price2num($qty);
|
||||||
if (! $qty) $qty=1;
|
if (! $qty) $qty=1;
|
||||||
$pu = price2num($pu);
|
if (! $info_bits) $info_bits=0;
|
||||||
|
$pu_ht=price2num($pu_ht);
|
||||||
|
$pu_ttc=price2num($pu_ttc);
|
||||||
$txtva = price2num($txtva);
|
$txtva = price2num($txtva);
|
||||||
|
|
||||||
|
if ($price_base_type=='HT') $pu=$pu;
|
||||||
|
else $pu=$pu_ttc;
|
||||||
|
|
||||||
// Calcul du total TTC et de la TVA pour la ligne a partir de
|
// Calcul du total TTC et de la TVA pour la ligne a partir de
|
||||||
// qty, pu, remise_percent et txtva
|
// qty, pu, remise_percent et txtva
|
||||||
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
|
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
|
||||||
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
|
// la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
|
||||||
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, $price_base_type);
|
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, $price_base_type);
|
||||||
$total_ht = $tabprice[0];
|
$total_ht = $tabprice[0];
|
||||||
$total_tva = $tabprice[1];
|
$total_tva = $tabprice[1];
|
||||||
$total_ttc = $tabprice[2];
|
$total_ttc = $tabprice[2];
|
||||||
|
|
||||||
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
|
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
|
||||||
$price = $pu;
|
$price = $pu;
|
||||||
|
$remise = 0;
|
||||||
if ($remise_percent > 0)
|
if ($remise_percent > 0)
|
||||||
{
|
{
|
||||||
$remise = round(($pu * $remise_percent / 100), 2);
|
$remise = round(($pu * $remise_percent / 100), 2);
|
||||||
@ -663,7 +673,7 @@ class Commande extends CommonObject
|
|||||||
$ligne->fk_product=$fk_product;
|
$ligne->fk_product=$fk_product;
|
||||||
$ligne->fk_remise_except=$fk_remise_except;
|
$ligne->fk_remise_except=$fk_remise_except;
|
||||||
$ligne->remise_percent=$remise_percent;
|
$ligne->remise_percent=$remise_percent;
|
||||||
$ligne->subprice=$pu;
|
$ligne->subprice=$pu_ht;
|
||||||
$ligne->rang=-1;
|
$ligne->rang=-1;
|
||||||
$ligne->info_bits=$info_bits;
|
$ligne->info_bits=$info_bits;
|
||||||
$ligne->total_ht=$total_ht;
|
$ligne->total_ht=$total_ht;
|
||||||
@ -679,7 +689,6 @@ class Commande extends CommonObject
|
|||||||
{
|
{
|
||||||
// Mise a jour informations denormalisees au niveau de la commande meme
|
// Mise a jour informations denormalisees au niveau de la commande meme
|
||||||
$result=$this->update_price($this->id);
|
$result=$this->update_price($this->id);
|
||||||
|
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
@ -1442,20 +1451,21 @@ class Commande extends CommonObject
|
|||||||
{
|
{
|
||||||
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
|
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
|
||||||
|
|
||||||
|
$tvas=array();
|
||||||
|
$err=0;
|
||||||
|
|
||||||
// Liste des lignes factures a sommer
|
// Liste des lignes factures a sommer
|
||||||
$sql = "SELECT price, qty, tva_tx, total_ht, total_tva, total_ttc";
|
$sql = "SELECT price, qty, tva_tx, total_ht, total_tva, total_ttc";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet";
|
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet";
|
||||||
$sql.= " WHERE fk_commande = ".$this->id;
|
$sql.= " WHERE fk_commande = ".$this->id;
|
||||||
|
|
||||||
dolibarr_syslog("Commande.class.php::update_price this->id=".$this->id);
|
dolibarr_syslog("Commande::update_price sql=".$sql);
|
||||||
|
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
$this->total_ht = 0;
|
$this->total_ht = 0;
|
||||||
$this->total_tva = 0;
|
$this->total_tva = 0;
|
||||||
$this->total_ttc = 0;
|
$this->total_ttc = 0;
|
||||||
|
|
||||||
$num = $this->db->num_rows($result);
|
$num = $this->db->num_rows($result);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
@ -1467,43 +1477,39 @@ class Commande extends CommonObject
|
|||||||
$this->total_ttc += $obj->total_ttc;
|
$this->total_ttc += $obj->total_ttc;
|
||||||
|
|
||||||
// Anciens indicateurs
|
// Anciens indicateurs
|
||||||
$this->amount_ht += $obj->price * $obj->qty;
|
$this->amount_ht += ($obj->price * $obj->qty);
|
||||||
$this->total_remise += 0; // Plus de remise globale (toute remise est sur une ligne)
|
$this->total_remise += 0; // Plus de remise globale (toute remise est sur une ligne)
|
||||||
/* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes
|
$tvas[$obj->tva_taux] += ($obj->total_ttc - $obj->total_ht);
|
||||||
$products[$i][0] = $obj->price;
|
|
||||||
$products[$i][1] = $obj->qty;
|
|
||||||
$products[$i][2] = $obj->tva_tx;
|
|
||||||
*/
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->free($result);
|
$this->db->free($result);
|
||||||
}
|
|
||||||
/* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes
|
// Met a jour indicateurs
|
||||||
$calculs = calcul_price($products, $this->remise_percent, $this->remise_absolue);
|
|
||||||
$this->total_remise = $calculs[3];
|
|
||||||
$this->amount_ht = $calculs[4];
|
|
||||||
$this->total_ht = $calculs[0];
|
|
||||||
$this->total_tva = $calculs[1];
|
|
||||||
$this->total_ttc = $calculs[2];
|
|
||||||
$tvas = $calculs[5];
|
|
||||||
*/
|
|
||||||
// Met a jour en base
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."commande SET";
|
||||||
$sql .= " amount_ht='".price2num($this->total_ht)."'";
|
$sql .= " amount_ht='".price2num($this->amount_ht)."'";
|
||||||
$sql .= ", total_ht='". price2num($this->total_ht)."'";
|
$sql .= ", total_ht='". price2num($this->total_ht)."'";
|
||||||
$sql .= ", tva='". price2num($this->total_tva)."'";
|
$sql .= ", tva='". price2num($this->total_tva)."'";
|
||||||
$sql .= ", total_ttc='".price2num($this->total_ttc)."'";
|
$sql .= ", total_ttc='".price2num($this->total_ttc)."'";
|
||||||
$sql .= ", remise='".price2num($this->total_remise)."'";
|
$sql .= ", remise='".price2num($this->total_remise)."'";
|
||||||
$sql .=" WHERE rowid = ".$this->id;
|
$sql .=" WHERE rowid = ".$this->id;
|
||||||
if ( $this->db->query($sql) )
|
$resql=$this->db->query($sql);
|
||||||
|
|
||||||
|
if ($resql)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
$this->error=$this->db->error();
|
||||||
dolibarr_syslog("Commande::update_price error=".$this->error);
|
dolibarr_syslog("Commande::update_price error=".$this->error,LOG_ERR);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->error=$this->db->error();
|
||||||
|
dolibarr_syslog("Commande::update_price error=".$this->error,LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2322,10 +2328,10 @@ class CommandeLigne
|
|||||||
var $desc; // Description ligne
|
var $desc; // Description ligne
|
||||||
var $fk_product; // Id produit prédéfini
|
var $fk_product; // Id produit prédéfini
|
||||||
|
|
||||||
var $qty;
|
var $qty; // Quantité (exemple 2)
|
||||||
var $tva_tx;
|
var $tva_tx; // Taux tva produit/service (exemple 19.6)
|
||||||
var $subprice;
|
var $subprice; // P.U. HT (exemple 100)
|
||||||
var $remise_percent;
|
var $remise_percent; // % de la remise ligne (exemple 20%)
|
||||||
var $rang = 0;
|
var $rang = 0;
|
||||||
var $marge_tx;
|
var $marge_tx;
|
||||||
var $marque_tx;
|
var $marque_tx;
|
||||||
@ -2441,7 +2447,7 @@ class CommandeLigne
|
|||||||
{
|
{
|
||||||
global $langs, $conf, $user;
|
global $langs, $conf, $user;
|
||||||
|
|
||||||
dolibarr_syslog("CommandeLigne.class::insert rang=".$this->rang);
|
dolibarr_syslog("CommandeLigne::insert rang=".$this->rang);
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
$rangtouse=$this->rang;
|
$rangtouse=$this->rang;
|
||||||
@ -2466,19 +2472,19 @@ class CommandeLigne
|
|||||||
|
|
||||||
// Insertion dans base de la ligne
|
// Insertion dans base de la ligne
|
||||||
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet';
|
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet';
|
||||||
$sql.= ' (fk_commande, description, price, qty, tva_tx,';
|
$sql.= ' (fk_commande, description, qty, tva_tx,';
|
||||||
$sql.= ' fk_product, remise_percent, subprice, remise, fk_remise_except, ';
|
$sql.= ' fk_product, remise_percent, subprice, price, remise, fk_remise_except,';
|
||||||
$sql.= ' rang, marge_tx, marque_tx,';
|
$sql.= ' rang, marge_tx, marque_tx,';
|
||||||
$sql.= ' info_bits, total_ht, total_tva, total_ttc)';
|
$sql.= ' info_bits, total_ht, total_tva, total_ttc)';
|
||||||
$sql.= " VALUES (".$this->fk_commande.",";
|
$sql.= " VALUES (".$this->fk_commande.",";
|
||||||
$sql.= " '".addslashes($this->desc)."',";
|
$sql.= " '".addslashes($this->desc)."',";
|
||||||
$sql.= " '".price2num($this->price)."',";
|
|
||||||
$sql.= " '".price2num($this->qty)."',";
|
$sql.= " '".price2num($this->qty)."',";
|
||||||
$sql.= " '".price2num($this->tva_tx)."',";
|
$sql.= " '".price2num($this->tva_tx)."',";
|
||||||
if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; }
|
if ($this->fk_product) { $sql.= "'".$this->fk_product."',"; }
|
||||||
else { $sql.='null,'; }
|
else { $sql.='null,'; }
|
||||||
$sql.= " '".price2num($this->remise_percent)."',";
|
$sql.= " '".price2num($this->remise_percent)."',";
|
||||||
$sql.= " '".price2num($this->subprice)."',";
|
$sql.= " '".price2num($this->subprice)."',";
|
||||||
|
$sql.= " '".price2num($this->price)."',";
|
||||||
$sql.= " '".price2num($this->remise)."',";
|
$sql.= " '".price2num($this->remise)."',";
|
||||||
if ($this->fk_remise_except) $sql.= $this->fk_remise_except.",";
|
if ($this->fk_remise_except) $sql.= $this->fk_remise_except.",";
|
||||||
else $sql.= 'null,';
|
else $sql.= 'null,';
|
||||||
@ -2493,8 +2499,6 @@ class CommandeLigne
|
|||||||
$sql.= " '".price2num($this->total_ttc)."'";
|
$sql.= " '".price2num($this->total_ttc)."'";
|
||||||
$sql.= ')';
|
$sql.= ')';
|
||||||
|
|
||||||
dolibarr_syslog("CommandeLigne.class.php::insert sql=$sql");
|
|
||||||
|
|
||||||
if ($this->fk_product)
|
if ($this->fk_product)
|
||||||
{
|
{
|
||||||
$product = new Product($this->db);
|
$product = new Product($this->db);
|
||||||
@ -2502,9 +2506,12 @@ class CommandeLigne
|
|||||||
$product->ajust_stock_commande($this->qty, 0);
|
$product->ajust_stock_commande($this->qty, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dolibarr_syslog("CommandeLigne::insert sql=$sql");
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
|
$this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'commandedet');
|
||||||
|
|
||||||
if (! $notrigger)
|
if (! $notrigger)
|
||||||
{
|
{
|
||||||
// Appel des triggers
|
// Appel des triggers
|
||||||
@ -2515,7 +2522,7 @@ class CommandeLigne
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
return $this->rowid;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -256,37 +256,43 @@ if ($_REQUEST['action'] == 'setremiseabsolue' && $user->rights->facture->creer)
|
|||||||
*/
|
*/
|
||||||
if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
|
if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
|
||||||
{
|
{
|
||||||
if ($_POST['qty'] && (($_POST['pu'] && $_POST['np_desc']) || $_POST['idprod']))
|
if ($_POST['qty'] && (($_POST['pu'] != '' && $_POST['np_desc']) || $_POST['idprod']))
|
||||||
{
|
{
|
||||||
$commande = new Commande($db);
|
$commande = new Commande($db);
|
||||||
$ret=$commande->fetch($_POST['id']);
|
$ret=$commande->fetch($_POST['id']);
|
||||||
$soc = new Societe($db, $commande->socid);
|
$ret=$commande->fetch_client();
|
||||||
$soc->fetch($commande->socid);
|
|
||||||
|
|
||||||
if ($ret < 0)
|
if ($ret < 0)
|
||||||
{
|
{
|
||||||
dolibarr_print_error($db,$commande->error);
|
dolibarr_print_error($db,$commande->error);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$price_base_type = 'HT';
|
||||||
|
|
||||||
// Ecrase $pu par celui du produit
|
// Ecrase $pu par celui du produit
|
||||||
// Ecrase $desc par celui du produit
|
// Ecrase $desc par celui du produit
|
||||||
// Ecrase $txtva par celui du produit
|
// Ecrase $txtva par celui du produit
|
||||||
|
// Ecrase $base_price_type par celui du produit
|
||||||
if ($_POST['idprod'])
|
if ($_POST['idprod'])
|
||||||
{
|
{
|
||||||
$prod = new Product($db, $_POST['idprod']);
|
$prod = new Product($db, $_POST['idprod']);
|
||||||
$prod->fetch($_POST['idprod']);
|
$prod->fetch($_POST['idprod']);
|
||||||
|
|
||||||
|
$price_base_type = $prod->price_base_type;
|
||||||
|
|
||||||
$libelle = $prod->libelle;
|
$libelle = $prod->libelle;
|
||||||
|
|
||||||
// multiprix
|
// multiprix
|
||||||
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
if ($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||||
{
|
{
|
||||||
$pu = $prod->multiprices[$soc->price_level];
|
$pu = $prod->multiprices[$commande->client->price_level];
|
||||||
|
$pu_ttc = $prod->multiprices_ttc[$commande->client->price_level];
|
||||||
|
$price_base_type = $prod->multiprices_base_type[$commande->client->price_level];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$pu=$prod->price;
|
$pu = $prod->price;
|
||||||
|
$pu_ttc = $prod->price_ttc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// La description de la ligne est celle saisie ou
|
// La description de la ligne est celle saisie ou
|
||||||
@ -300,7 +306,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
|
|||||||
$desc=$_POST['np_desc'];
|
$desc=$_POST['np_desc'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
|
$tva_tx = get_default_tva($mysoc,$commande->client,$prod->tva_tx);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -316,7 +322,11 @@ if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
|
|||||||
$_POST['qty'],
|
$_POST['qty'],
|
||||||
$tva_tx,
|
$tva_tx,
|
||||||
$_POST['idprod'],
|
$_POST['idprod'],
|
||||||
$_POST['remise_percent']
|
$_POST['remise_percent'],
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
$price_base_type,
|
||||||
|
$pu_ttc
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($_REQUEST['lang_id'])
|
if ($_REQUEST['lang_id'])
|
||||||
@ -1268,6 +1278,7 @@ else
|
|||||||
*/
|
*/
|
||||||
$sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, ';
|
$sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, ';
|
||||||
$sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits,';
|
$sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits,';
|
||||||
|
$sql.= ' l.total_ht, l.total_tva, l.total_ttc,';
|
||||||
$sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid, ';
|
$sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid, ';
|
||||||
$sql.= ' p.description as product_desc';
|
$sql.= ' p.description as product_desc';
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
|
||||||
@ -1386,7 +1397,7 @@ else
|
|||||||
{
|
{
|
||||||
print '<td> </td>';
|
print '<td> </td>';
|
||||||
}
|
}
|
||||||
print '<td align="right">'.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100).'</td>';
|
print '<td align="right">'.price($objp->total_ht).'</td>';
|
||||||
|
|
||||||
// Icone d'edition et suppression
|
// Icone d'edition et suppression
|
||||||
if ($commande->statut == 0 && $user->rights->commande->creer)
|
if ($commande->statut == 0 && $user->rights->commande->creer)
|
||||||
|
|||||||
@ -806,7 +806,8 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') &&
|
|||||||
0,
|
0,
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
$price_base_type, $pu_ttc
|
$price_base_type,
|
||||||
|
$pu_ttc
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1300,7 +1300,7 @@ class Facture extends CommonObject
|
|||||||
* \brief Ajoute une ligne de facture (associé à un produit/service prédéfini ou non)
|
* \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_ht Prix unitaire HT
|
||||||
* \param qty Quantité
|
* \param qty Quantité
|
||||||
* \param txtva Taux de tva forcé, sinon -1
|
* \param txtva Taux de tva forcé, sinon -1
|
||||||
* \param fk_product Id du produit/service predéfini
|
* \param fk_product Id du produit/service predéfini
|
||||||
@ -1309,14 +1309,18 @@ class Facture extends CommonObject
|
|||||||
* \param date_end Date de fin de validité du service
|
* \param date_end Date de fin de validité du service
|
||||||
* \param ventil Code de ventilation comptable
|
* \param ventil Code de ventilation comptable
|
||||||
* \param info_bits Bits de type de lignes
|
* \param info_bits Bits de type de lignes
|
||||||
|
* \param fk_remise_exscept Id remise
|
||||||
|
* \param price_base_type HT or TTC
|
||||||
|
* \param pu_ttc Prix unitaire TTC
|
||||||
|
* \return int >0 si ok, <0 si ko
|
||||||
* \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel
|
* \remarks Les parametres sont deja censé etre juste et avec valeurs finales a l'appel
|
||||||
* de cette methode. Aussi, pour le taux tva, il doit deja avoir ete défini
|
* de cette methode. Aussi, pour le taux tva, il doit deja avoir ete défini
|
||||||
* par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit)
|
* par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit)
|
||||||
* et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
|
* et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
|
||||||
*/
|
*/
|
||||||
function addline($facid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $fk_remise_except='', $price_base_type='HT', $pu_ttc=0)
|
function addline($facid, $desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $fk_remise_except='', $price_base_type='HT', $pu_ttc=0)
|
||||||
{
|
{
|
||||||
dolibarr_syslog("Facture::Addline $facid,$desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$fk_remise_except", LOG_DEBUG);
|
dolibarr_syslog("Facture::Addline $facid,$desc,$pu_ht,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$fk_remise_except,$price_base_type,$pu_ttc", LOG_DEBUG);
|
||||||
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
|
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
|
||||||
|
|
||||||
if ($this->brouillon)
|
if ($this->brouillon)
|
||||||
@ -1329,9 +1333,11 @@ class Facture extends CommonObject
|
|||||||
if (! $qty) $qty=1;
|
if (! $qty) $qty=1;
|
||||||
if (! $ventil) $ventil=0;
|
if (! $ventil) $ventil=0;
|
||||||
if (! $info_bits) $info_bits=0;
|
if (! $info_bits) $info_bits=0;
|
||||||
$pu = price2num($pu);
|
$pu_ht=price2num($pu_ht);
|
||||||
|
$pu_ttc=price2num($pu_ttc);
|
||||||
$txtva=price2num($txtva);
|
$txtva=price2num($txtva);
|
||||||
if ($price_base_type=='HT') $pu=$pu;
|
|
||||||
|
if ($price_base_type=='HT') $pu=$pu_ht;
|
||||||
else $pu=$pu_ttc;
|
else $pu=$pu_ttc;
|
||||||
|
|
||||||
// Calcul du total TTC et de la TVA pour la ligne a partir de
|
// Calcul du total TTC et de la TVA pour la ligne a partir de
|
||||||
@ -1361,7 +1367,7 @@ class Facture extends CommonObject
|
|||||||
$ligne->tva_tx=$txtva;
|
$ligne->tva_tx=$txtva;
|
||||||
$ligne->fk_product=$fk_product;
|
$ligne->fk_product=$fk_product;
|
||||||
$ligne->remise_percent=$remise_percent;
|
$ligne->remise_percent=$remise_percent;
|
||||||
$ligne->subprice=$pu;
|
$ligne->subprice=$pu_ht;
|
||||||
$ligne->date_start=$date_start;
|
$ligne->date_start=$date_start;
|
||||||
$ligne->date_end=$date_end;
|
$ligne->date_end=$date_end;
|
||||||
$ligne->ventil=$ventil;
|
$ligne->ventil=$ventil;
|
||||||
@ -1562,6 +1568,7 @@ class Facture extends CommonObject
|
|||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet';
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet';
|
||||||
$sql.= ' WHERE fk_facture = '.$facid;
|
$sql.= ' WHERE fk_facture = '.$facid;
|
||||||
|
|
||||||
|
dolibarr_syslog("Facture::update_price sql=".$sql);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
@ -1587,7 +1594,7 @@ class Facture extends CommonObject
|
|||||||
|
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
|
|
||||||
// Met a jour indicateurs sur facture
|
// Met a jour indicateurs
|
||||||
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture ';
|
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture ';
|
||||||
$sql .= "SET amount ='".price2num($this->amount_ht)."'";
|
$sql .= "SET amount ='".price2num($this->amount_ht)."'";
|
||||||
$sql .= ", remise='". price2num($this->total_remise)."'";
|
$sql .= ", remise='". price2num($this->total_remise)."'";
|
||||||
@ -1632,12 +1639,16 @@ class Facture extends CommonObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
$this->error=$this->db->error();
|
||||||
|
dolibarr_syslog("Facture::update_price error=".$this->error,LOG_ERR);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dolibarr_print_error($this->db);
|
$this->error=$this->db->error();
|
||||||
|
dolibarr_syslog("Facture::update_price error=".$this->error,LOG_ERR);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2832,9 +2843,10 @@ class FactureLigne
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Insère l'objet ligne de facture en base
|
* \brief Insère l'objet ligne de facture en base
|
||||||
|
* \param notrigger 1 ne declenche pas les triggers, 0 sinon
|
||||||
* \return int <0 si ko, >0 si ok
|
* \return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function insert()
|
function insert($notrigger=0)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
@ -2945,11 +2957,14 @@ class FactureLigne
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! $notrigger)
|
||||||
|
{
|
||||||
// Appel des triggers
|
// Appel des triggers
|
||||||
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
|
||||||
$interface=new Interfaces($this->db);
|
$interface=new Interfaces($this->db);
|
||||||
$result = $interface->run_triggers('LINEBILL_INSERT',$this,$user,$langs,$conf);
|
$result = $interface->run_triggers('LINEBILL_INSERT',$this,$user,$langs,$conf);
|
||||||
// Fin appel triggers
|
// Fin appel triggers
|
||||||
|
}
|
||||||
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $this->rowid;
|
return $this->rowid;
|
||||||
|
|||||||
@ -197,7 +197,7 @@ class User
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error="USERNOTFOUND";
|
$this->error="USERNOTFOUND";
|
||||||
dolibarr_syslog("User::fetch Error 0, fails to get user - ".$this->error." - sql=".$sql);
|
dolibarr_syslog("User::fetch user not found", LOG_DEBUG);
|
||||||
|
|
||||||
$this->db->free($result);
|
$this->db->free($result);
|
||||||
return 0;
|
return 0;
|
||||||
@ -206,7 +206,7 @@ class User
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
$this->error=$this->db->error();
|
||||||
dolibarr_syslog("User::fetch Error -1, fails to get user - ".$this->error." - sql=".$sql);
|
dolibarr_syslog("User::fetch Error -1, fails to get user - ".$this->error." - sql=".$sql, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ class User
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
$this->error=$this->db->error();
|
||||||
dolibarr_syslog("User::fetch Error -2, fails to get setup user - ".$this->error." - sql=".$sql);
|
dolibarr_syslog("User::fetch Error -2, fails to get setup user - ".$this->error." - sql=".$sql, LOG_ERR);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user