Suite gestion des arrondis. C'est fait sur les contrats
This commit is contained in:
parent
5cb9588518
commit
d827dd626b
@ -555,7 +555,8 @@ if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST
|
|||||||
$_POST['qty'],
|
$_POST['qty'],
|
||||||
$_POST['remise_percent'],
|
$_POST['remise_percent'],
|
||||||
$_POST['tva_tx'],
|
$_POST['tva_tx'],
|
||||||
$_POST['desc']);
|
$_POST['desc'],
|
||||||
|
'HT');
|
||||||
|
|
||||||
if ($_REQUEST['lang_id'])
|
if ($_REQUEST['lang_id'])
|
||||||
{
|
{
|
||||||
@ -1020,8 +1021,9 @@ if ($_GET['propalid'] > 0)
|
|||||||
*/
|
*/
|
||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
|
|
||||||
$sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.fk_remise_except,';
|
$sql = 'SELECT pt.rowid, pt.description, pt.fk_product, pt.fk_remise_except,';
|
||||||
$sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
|
$sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
|
||||||
|
$sql.= ' pt.total_ht, pt.total_tva, pt.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.'propaldet as pt';
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt';
|
||||||
@ -1032,7 +1034,7 @@ if ($_GET['propalid'] > 0)
|
|||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
$i = 0; $total = 0;
|
$i = 0;
|
||||||
|
|
||||||
if ($num)
|
if ($num)
|
||||||
{
|
{
|
||||||
@ -1148,7 +1150,7 @@ if ($_GET['propalid'] > 0)
|
|||||||
{
|
{
|
||||||
print '<td> </td>';
|
print '<td> </td>';
|
||||||
}
|
}
|
||||||
print '<td align="right">'.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."</td>\n";
|
print '<td align="right">'.price($objp->total_ht)."</td>\n";
|
||||||
|
|
||||||
// Icone d'edition et suppression
|
// Icone d'edition et suppression
|
||||||
if ($propal->statut == 0 && $user->rights->propale->creer)
|
if ($propal->statut == 0 && $user->rights->propale->creer)
|
||||||
@ -1268,7 +1270,6 @@ if ($_GET['propalid'] > 0)
|
|||||||
print "</form>\n";
|
print "</form>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = $total + ($objp->qty * $objp->price);
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,8 +27,9 @@
|
|||||||
\version $Revision$
|
\version $Revision$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php");
|
require_once(DOL_DOCUMENT_ROOT."/commonobject.class.php");
|
||||||
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
|
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
|
||||||
|
require_once(DOL_DOCUMENT_ROOT."/lib/price.lib.php");
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -641,30 +642,33 @@ class Contrat extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* \brief Ajoute une ligne de contrat en base
|
* \brief Ajoute une ligne de contrat en base
|
||||||
* \param desc Description de la ligne
|
* \param desc Description de la ligne
|
||||||
* \param pu Prix unitaire
|
* \param pu Prix unitaire (HT ou TTC selon price_base_type
|
||||||
* \param qty Quantité
|
* \param qty Quantité
|
||||||
* \param txtva Taux tva
|
* \param txtva Taux tva
|
||||||
* \param fk_product Id produit
|
* \param fk_product Id produit
|
||||||
* \param remise_percent Pourcentage de remise de la ligne
|
* \param remise_percent Pourcentage de remise de la ligne
|
||||||
* \param date_start Date de debut prévue
|
* \param date_start Date de debut prévue
|
||||||
* \param date_end Date de fin prévue
|
* \param date_end Date de fin prévue
|
||||||
|
* \param price_base_type HT ou TTC
|
||||||
* \return int <0 si erreur, >0 si ok
|
* \return int <0 si erreur, >0 si ok
|
||||||
*/
|
*/
|
||||||
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $date_start, $date_end)
|
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $date_start, $date_end, $price_base_type='HT')
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
// Nettoyage parametres
|
// Nettoyage parametres
|
||||||
if (! $txtva) $txtva=0;
|
if (! $txtva) $txtva=0;
|
||||||
|
$remise_percent=price2num($remise_percent);
|
||||||
|
$qty=price2num($qty);
|
||||||
|
if (! $qty) $qty=1;
|
||||||
|
$pu = price2num($pu,'MU');
|
||||||
|
$txtva = price2num($txtva,'MU');
|
||||||
|
|
||||||
dolibarr_syslog("Contrat::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent, $date_start, $date_end");
|
dolibarr_syslog("Contrat::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type");
|
||||||
|
|
||||||
if ($this->statut == 0)
|
if ($this->statut == 0)
|
||||||
{
|
{
|
||||||
$qty = price2num($qty);
|
|
||||||
$pu = price2num($pu);
|
|
||||||
|
|
||||||
if ($fk_product > 0)
|
if ($fk_product > 0)
|
||||||
{
|
{
|
||||||
$prod = new Product($this->db, $fk_product);
|
$prod = new Product($this->db, $fk_product);
|
||||||
@ -680,9 +684,19 @@ class Contrat extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calcul du total TTC et de la TVA pour la ligne a partir de
|
||||||
|
// qty, pu, remise_percent et txtva
|
||||||
|
// 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.
|
||||||
|
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, $price_base_type);
|
||||||
|
$total_ht = $tabprice[0];
|
||||||
|
$total_tva = $tabprice[1];
|
||||||
|
$total_ttc = $tabprice[2];
|
||||||
|
|
||||||
|
// \TODO A virer
|
||||||
|
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
|
||||||
$remise = 0;
|
$remise = 0;
|
||||||
$price = price2num(round($pu, 2));
|
$price = price2num(round($pu, 2));
|
||||||
$subprice = $price;
|
|
||||||
if (strlen($remise_percent) > 0)
|
if (strlen($remise_percent) > 0)
|
||||||
{
|
{
|
||||||
$remise = round(($pu * $remise_percent / 100), 2);
|
$remise = round(($pu * $remise_percent / 100), 2);
|
||||||
@ -691,18 +705,22 @@ class Contrat extends CommonObject
|
|||||||
|
|
||||||
// Insertion dans la base
|
// Insertion dans la base
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet";
|
||||||
$sql.= " (fk_contrat, label, description, fk_product, price_ht, qty, tva_tx,";
|
$sql.= " (fk_contrat, label, description, fk_product, qty, tva_tx,";
|
||||||
$sql.= " remise_percent, subprice, remise";
|
$sql.= " remise_percent, subprice,";
|
||||||
|
$sql.= " total_ht, total_tva, total_ttc,";
|
||||||
|
$sql.= " price_ht, remise"; // \TODO A virer
|
||||||
if ($date_start > 0) { $sql.= ",date_ouverture_prevue"; }
|
if ($date_start > 0) { $sql.= ",date_ouverture_prevue"; }
|
||||||
if ($date_end > 0) { $sql.= ",date_fin_validite"; }
|
if ($date_end > 0) { $sql.= ",date_fin_validite"; }
|
||||||
$sql.= ") VALUES ($this->id, '" . addslashes($label) . "','" . addslashes($desc) . "',";
|
$sql.= ") VALUES ($this->id, '" . addslashes($label) . "','" . addslashes($desc) . "',";
|
||||||
$sql.= ($fk_product>0 ? $fk_product : "null");
|
$sql.= ($fk_product>0 ? $fk_product : "null").",";
|
||||||
$sql.= ",".price2num($price).", '$qty', ";
|
$sql.= " '$qty',";
|
||||||
$sql.= $txtva.",";
|
$sql.= " ".$txtva.",";
|
||||||
$sql.= $remise_percent.",'".price2num($subprice)."','".price2num( $remise)."'";
|
$sql.= " ".price2num($remise_percent).",".price2num($pu).",";
|
||||||
|
$sql.= " ".price2num($total_ht).",".price2num($total_tva).",".price2num($total_ttc).",";
|
||||||
|
$sql.= " ".price2num($price).",".price2num( $remise); // \TODO A virer
|
||||||
if ($date_start > 0) { $sql.= ",".$this->db->idate($date_start); }
|
if ($date_start > 0) { $sql.= ",".$this->db->idate($date_start); }
|
||||||
if ($date_end > 0) { $sql.= ",".$this->db->idate($date_end); }
|
if ($date_end > 0) { $sql.= ",".$this->db->idate($date_end); }
|
||||||
$sql.= ");";
|
$sql.= ")";
|
||||||
|
|
||||||
if ( $this->db->query($sql) )
|
if ( $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
@ -831,6 +849,7 @@ class Contrat extends CommonObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Mets à jour le prix total du contrat
|
* \brief Mets à jour le prix total du contrat
|
||||||
|
* \return int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function update_price()
|
function update_price()
|
||||||
{
|
{
|
||||||
@ -839,7 +858,7 @@ class Contrat extends CommonObject
|
|||||||
/*
|
/*
|
||||||
* Liste des produits a ajouter
|
* Liste des produits a ajouter
|
||||||
*/
|
*/
|
||||||
$sql = "SELECT price_ht, qty, tva_tx";
|
$sql = "SELECT total_ht, total_tva, total_ttc";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet";
|
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet";
|
||||||
$sql.= " WHERE fk_contrat = ".$this->id;
|
$sql.= " WHERE fk_contrat = ".$this->id;
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
@ -851,23 +870,35 @@ class Contrat extends CommonObject
|
|||||||
while ($i < $num)
|
while ($i < $num)
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
$products[$i][0] = $obj->price_ht;
|
$this->total_ht += $obj->total_ht;
|
||||||
$products[$i][1] = $obj->qty;
|
$this->total_tva += $obj->total_tva;
|
||||||
$products[$i][2] = $obj->tva_tx;
|
$this->total_ttc += $obj->total_ttc;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Met a jour en base
|
||||||
|
/*
|
||||||
|
$sql = "UPDATE ".MAIN_DB_PREFIX."contrat SET";
|
||||||
|
$sql .= " total_ht=". price2num($this->total_ht).",";
|
||||||
|
$sql .= " total_tva=". price2num($this->total_tva).",";
|
||||||
|
$sql .= " total_ttc='".price2num($this->total_ttc);
|
||||||
|
$sql .=" WHERE rowid = ".$this->id;
|
||||||
|
if ( $this->db->query($sql) )
|
||||||
|
{
|
||||||
|
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 -1;
|
||||||
}
|
}
|
||||||
$calculs = calcul_price($products, $this->remise_percent);
|
|
||||||
|
|
||||||
$this->remise = $calculs[3];
|
|
||||||
$this->total_ht = $calculs[0];
|
|
||||||
$this->total_tva = $calculs[1];
|
|
||||||
$this->total_ttc = $calculs[2];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -353,16 +353,17 @@ class Propal extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* \brief Mise à jour d'une ligne de produit
|
* \brief Mise à jour d'une ligne de produit
|
||||||
* \param id Id de la ligne
|
* \param id Id de la ligne
|
||||||
* \param subprice Prix unitaire
|
* \param pu Prix unitaire (HT ou TTC selon price_base_type)
|
||||||
* \param qty Quantité
|
* \param qty Quantité
|
||||||
* \param remise_percent Remise effectuée sur le produit
|
* \param remise_percent Remise effectuée sur le produit
|
||||||
* \param tva_tx Taux de TVA
|
* \param tva_tx Taux de TVA
|
||||||
* \param desc Description
|
* \param desc Description
|
||||||
|
* \param price_base_type HT ou TTC
|
||||||
* \return int 0 en cas de succès
|
* \return int 0 en cas de succès
|
||||||
*/
|
*/
|
||||||
function updateline($rowid, $pu, $qty, $remise_percent=0, $txtva, $desc='', $price_base_type='HT')
|
function updateline($rowid, $pu, $qty, $remise_percent=0, $txtva, $desc='', $price_base_type='HT')
|
||||||
{
|
{
|
||||||
dolibarr_syslog("propal.class.php::UpdateLine $rowid, $pu, $qty, $remise_percent, $txtva, $desc");
|
dolibarr_syslog("Propal::UpdateLine $rowid, $pu, $qty, $remise_percent, $txtva, $desc, $price_base_type");
|
||||||
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)
|
||||||
@ -385,9 +386,8 @@ class Propal extends CommonObject
|
|||||||
$total_tva = $tabprice[1];
|
$total_tva = $tabprice[1];
|
||||||
$total_ttc = $tabprice[2];
|
$total_ttc = $tabprice[2];
|
||||||
|
|
||||||
// Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser)
|
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
|
||||||
$price = $pu;
|
$price = $pu;
|
||||||
$subprice = $pu;
|
|
||||||
if ($remise_percent > 0)
|
if ($remise_percent > 0)
|
||||||
{
|
{
|
||||||
$remise = round(($pu * $remise_percent / 100), 2);
|
$remise = round(($pu * $remise_percent / 100), 2);
|
||||||
@ -396,14 +396,14 @@ class Propal extends CommonObject
|
|||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propaldet ";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propaldet ";
|
||||||
$sql.= " SET qty='".$qty."'";
|
$sql.= " SET qty='".$qty."'";
|
||||||
$sql.= " , price='". price2num($price)."'";
|
$sql.= " , price='". price2num($price)."'"; // \TODO A virer
|
||||||
$sql.= " , remise_percent='".$remise_percent."'";
|
$sql.= " , remise_percent='".$remise_percent."'"; // \TODO A virer
|
||||||
$sql.= " , subprice='".$subprice."'";
|
$sql.= " , subprice=".price2num($pu);
|
||||||
$sql.= " , tva_tx='".$txtva."'";
|
$sql.= " , tva_tx=".price2num($txtva);
|
||||||
$sql.= " , description='".addslashes($desc)."'";
|
$sql.= " , description='".addslashes($desc)."'";
|
||||||
$sql.= " , total_ht='".price2num($total_ht)."'";
|
$sql.= " , total_ht=".price2num($total_ht);
|
||||||
$sql.= " , total_tva='".price2num($total_tva)."'";
|
$sql.= " , total_tva=".price2num($total_tva);
|
||||||
$sql.= " , total_ttc='".price2num($total_ttc)."'";
|
$sql.= " , total_ttc=".price2num($total_ttc);
|
||||||
$sql.= " WHERE rowid = '".$rowid."';";
|
$sql.= " WHERE rowid = '".$rowid."';";
|
||||||
|
|
||||||
$result=$this->db->query($sql);
|
$result=$this->db->query($sql);
|
||||||
@ -588,6 +588,8 @@ class Propal extends CommonObject
|
|||||||
$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."propaldet";
|
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet";
|
||||||
$sql.= " WHERE fk_propal = ".$this->id;
|
$sql.= " WHERE fk_propal = ".$this->id;
|
||||||
|
|
||||||
|
dolibarr_syslog("Propal::update_price sql=".$sql);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if ($result)
|
if ($result)
|
||||||
{
|
{
|
||||||
@ -602,11 +604,11 @@ class Propal extends CommonObject
|
|||||||
$obj = $this->db->fetch_object($result);
|
$obj = $this->db->fetch_object($result);
|
||||||
|
|
||||||
$this->total_ht += $obj->total_ht;
|
$this->total_ht += $obj->total_ht;
|
||||||
$this->total_tva += ($obj->total_ttc - $obj->total_ht);
|
$this->total_tva += $obj->total_tva;
|
||||||
$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; // \TODO A virer
|
||||||
$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)
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
@ -616,12 +618,14 @@ class Propal extends CommonObject
|
|||||||
|
|
||||||
// Met a jour en base
|
// Met a jour en base
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET";
|
||||||
$sql .= " price='". 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='". price2num($this->total_ttc)."'";
|
$sql .= " total=". price2num($this->total_ttc).",";
|
||||||
$sql .= ", remise='".price2num($this->total_remise)."'";
|
$sql .= " remise=". price2num($this->total_remise).","; // \TODO A virer
|
||||||
|
$sql .= " price=". price2num($this->total_ht); // \TODO A virer
|
||||||
$sql .=" WHERE rowid = ".$this->id;
|
$sql .=" WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
|
dolibarr_syslog("Propal::update_price sql=".$sql);
|
||||||
if ( $this->db->query($sql) )
|
if ( $this->db->query($sql) )
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
@ -629,6 +633,7 @@ class Propal extends CommonObject
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
$this->error=$this->db->error();
|
||||||
|
dolibarr_syslog("Propal::update_price error=".$this->error);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user