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['remise_percent'],
|
||||
$_POST['tva_tx'],
|
||||
$_POST['desc']);
|
||||
$_POST['desc'],
|
||||
'HT');
|
||||
|
||||
if ($_REQUEST['lang_id'])
|
||||
{
|
||||
@ -1020,8 +1021,9 @@ if ($_GET['propalid'] > 0)
|
||||
*/
|
||||
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.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.description as product_desc';
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt';
|
||||
@ -1032,7 +1034,7 @@ if ($_GET['propalid'] > 0)
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0; $total = 0;
|
||||
$i = 0;
|
||||
|
||||
if ($num)
|
||||
{
|
||||
@ -1148,7 +1150,7 @@ if ($_GET['propalid'] > 0)
|
||||
{
|
||||
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
|
||||
if ($propal->statut == 0 && $user->rights->propale->creer)
|
||||
@ -1268,7 +1270,6 @@ if ($_GET['propalid'] > 0)
|
||||
print "</form>\n";
|
||||
}
|
||||
|
||||
$total = $total + ($objp->qty * $objp->price);
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
@ -27,8 +27,9 @@
|
||||
\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."/lib/price.lib.php");
|
||||
|
||||
|
||||
/**
|
||||
@ -640,31 +641,34 @@ class Contrat extends CommonObject
|
||||
|
||||
/**
|
||||
* \brief Ajoute une ligne de contrat en base
|
||||
* \param desc Description de la ligne
|
||||
* \param pu Prix unitaire
|
||||
* \param qty Quantité
|
||||
* \param txtva Taux tva
|
||||
* \param fk_product Id produit
|
||||
* \param remise_percent Pourcentage de remise de la ligne
|
||||
* \param date_start Date de debut prévue
|
||||
* \param date_end Date de fin prévue
|
||||
* \return int <0 si erreur, >0 si ok
|
||||
* \param desc Description de la ligne
|
||||
* \param pu Prix unitaire (HT ou TTC selon price_base_type
|
||||
* \param qty Quantité
|
||||
* \param txtva Taux tva
|
||||
* \param fk_product Id produit
|
||||
* \param remise_percent Pourcentage de remise de la ligne
|
||||
* \param date_start Date de debut 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
|
||||
*/
|
||||
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 $conf;
|
||||
|
||||
// Nettoyage parametres
|
||||
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)
|
||||
{
|
||||
$qty = price2num($qty);
|
||||
$pu = price2num($pu);
|
||||
|
||||
if ($fk_product > 0)
|
||||
{
|
||||
$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;
|
||||
$price = price2num(round($pu, 2));
|
||||
$subprice = $price;
|
||||
if (strlen($remise_percent) > 0)
|
||||
{
|
||||
$remise = round(($pu * $remise_percent / 100), 2);
|
||||
@ -691,18 +705,22 @@ class Contrat extends CommonObject
|
||||
|
||||
// Insertion dans la base
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet";
|
||||
$sql.= " (fk_contrat, label, description, fk_product, price_ht, qty, tva_tx,";
|
||||
$sql.= " remise_percent, subprice, remise";
|
||||
$sql.= " (fk_contrat, label, description, fk_product, qty, tva_tx,";
|
||||
$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_end > 0) { $sql.= ",date_fin_validite"; }
|
||||
$sql.= ") VALUES ($this->id, '" . addslashes($label) . "','" . addslashes($desc) . "',";
|
||||
$sql.= ($fk_product>0 ? $fk_product : "null");
|
||||
$sql.= ",".price2num($price).", '$qty', ";
|
||||
$sql.= $txtva.",";
|
||||
$sql.= $remise_percent.",'".price2num($subprice)."','".price2num( $remise)."'";
|
||||
$sql.= ($fk_product>0 ? $fk_product : "null").",";
|
||||
$sql.= " '$qty',";
|
||||
$sql.= " ".$txtva.",";
|
||||
$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_end > 0) { $sql.= ",".$this->db->idate($date_end); }
|
||||
$sql.= ");";
|
||||
$sql.= ")";
|
||||
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
@ -831,6 +849,7 @@ class Contrat extends CommonObject
|
||||
|
||||
/**
|
||||
* \brief Mets à jour le prix total du contrat
|
||||
* \return int <0 si ko, >0 si ok
|
||||
*/
|
||||
function update_price()
|
||||
{
|
||||
@ -839,7 +858,7 @@ class Contrat extends CommonObject
|
||||
/*
|
||||
* 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.= " WHERE fk_contrat = ".$this->id;
|
||||
$resql=$this->db->query($sql);
|
||||
@ -851,23 +870,35 @@ class Contrat extends CommonObject
|
||||
while ($i < $num)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
$products[$i][0] = $obj->price_ht;
|
||||
$products[$i][1] = $obj->qty;
|
||||
$products[$i][2] = $obj->tva_tx;
|
||||
$this->total_ht += $obj->total_ht;
|
||||
$this->total_tva += $obj->total_tva;
|
||||
$this->total_ttc += $obj->total_ttc;
|
||||
$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
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -48,46 +48,46 @@ class Propal extends CommonObject
|
||||
var $db;
|
||||
var $element='propal';
|
||||
|
||||
var $id;
|
||||
var $id;
|
||||
|
||||
var $socid; // Id client
|
||||
var $client; // Objet societe client (à charger par fetch_client)
|
||||
|
||||
var $contactid;
|
||||
var $projetidp;
|
||||
var $author;
|
||||
var $ref;
|
||||
var $ref_client;
|
||||
var $statut; // 0, 1, 2, 3, 4
|
||||
var $datep;
|
||||
var $fin_validite;
|
||||
var $price; // Total HT
|
||||
var $tva; // Total TVA
|
||||
var $total; // Total TTC
|
||||
var $cond_reglement_id;
|
||||
var $cond_reglement_code;
|
||||
var $mode_reglement_id;
|
||||
var $mode_reglement_code;
|
||||
var $remise;
|
||||
var $remise_percent;
|
||||
var $remise_absolue;
|
||||
var $note;
|
||||
var $note_public;
|
||||
var $contactid;
|
||||
var $projetidp;
|
||||
var $author;
|
||||
var $ref;
|
||||
var $ref_client;
|
||||
var $statut; // 0, 1, 2, 3, 4
|
||||
var $datep;
|
||||
var $fin_validite;
|
||||
var $price; // Total HT
|
||||
var $tva; // Total TVA
|
||||
var $total; // Total TTC
|
||||
var $cond_reglement_id;
|
||||
var $cond_reglement_code;
|
||||
var $mode_reglement_id;
|
||||
var $mode_reglement_code;
|
||||
var $remise;
|
||||
var $remise_percent;
|
||||
var $remise_absolue;
|
||||
var $note;
|
||||
var $note_public;
|
||||
var $date_livraison;
|
||||
var $adresse_livraison_id;
|
||||
var $adresse;
|
||||
var $adresse_livraison_id;
|
||||
var $adresse;
|
||||
|
||||
var $products=array();
|
||||
var $products=array();
|
||||
|
||||
var $labelstatut=array();
|
||||
var $labelstatut_short=array();
|
||||
|
||||
// Pour board
|
||||
var $nbtodo;
|
||||
var $nbtodolate;
|
||||
var $labelstatut=array();
|
||||
var $labelstatut_short=array();
|
||||
|
||||
var $specimen;
|
||||
var $error;
|
||||
// Pour board
|
||||
var $nbtodo;
|
||||
var $nbtodolate;
|
||||
|
||||
var $specimen;
|
||||
var $error;
|
||||
|
||||
|
||||
/**
|
||||
@ -352,17 +352,18 @@ class Propal extends CommonObject
|
||||
|
||||
/**
|
||||
* \brief Mise à jour d'une ligne de produit
|
||||
* \param id Id de la ligne
|
||||
* \param subprice Prix unitaire
|
||||
* \param qty Quantité
|
||||
* \param remise_percent Remise effectuée sur le produit
|
||||
* \param tva_tx Taux de TVA
|
||||
* \param desc Description
|
||||
* \return int 0 en cas de succès
|
||||
* \param id Id de la ligne
|
||||
* \param pu Prix unitaire (HT ou TTC selon price_base_type)
|
||||
* \param qty Quantité
|
||||
* \param remise_percent Remise effectuée sur le produit
|
||||
* \param tva_tx Taux de TVA
|
||||
* \param desc Description
|
||||
* \param price_base_type HT ou TTC
|
||||
* \return int 0 en cas de succès
|
||||
*/
|
||||
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');
|
||||
|
||||
if ($this->statut == 0)
|
||||
@ -385,9 +386,8 @@ class Propal extends CommonObject
|
||||
$total_tva = $tabprice[1];
|
||||
$total_ttc = $tabprice[2];
|
||||
|
||||
// Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser)
|
||||
// Anciens indicateurs: $price, $remise (a ne plus utiliser)
|
||||
$price = $pu;
|
||||
$subprice = $pu;
|
||||
if ($remise_percent > 0)
|
||||
{
|
||||
$remise = round(($pu * $remise_percent / 100), 2);
|
||||
@ -396,14 +396,14 @@ class Propal extends CommonObject
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propaldet ";
|
||||
$sql.= " SET qty='".$qty."'";
|
||||
$sql.= " , price='". price2num($price)."'";
|
||||
$sql.= " , remise_percent='".$remise_percent."'";
|
||||
$sql.= " , subprice='".$subprice."'";
|
||||
$sql.= " , tva_tx='".$txtva."'";
|
||||
$sql.= " , price='". price2num($price)."'"; // \TODO A virer
|
||||
$sql.= " , remise_percent='".$remise_percent."'"; // \TODO A virer
|
||||
$sql.= " , subprice=".price2num($pu);
|
||||
$sql.= " , tva_tx=".price2num($txtva);
|
||||
$sql.= " , description='".addslashes($desc)."'";
|
||||
$sql.= " , total_ht='".price2num($total_ht)."'";
|
||||
$sql.= " , total_tva='".price2num($total_tva)."'";
|
||||
$sql.= " , total_ttc='".price2num($total_ttc)."'";
|
||||
$sql.= " , total_ht=".price2num($total_ht);
|
||||
$sql.= " , total_tva=".price2num($total_tva);
|
||||
$sql.= " , total_ttc=".price2num($total_ttc);
|
||||
$sql.= " WHERE rowid = '".$rowid."';";
|
||||
|
||||
$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.= " FROM ".MAIN_DB_PREFIX."propaldet";
|
||||
$sql.= " WHERE fk_propal = ".$this->id;
|
||||
|
||||
dolibarr_syslog("Propal::update_price sql=".$sql);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@ -602,11 +604,11 @@ class Propal extends CommonObject
|
||||
$obj = $this->db->fetch_object($result);
|
||||
|
||||
$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;
|
||||
|
||||
// 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)
|
||||
$i++;
|
||||
}
|
||||
@ -616,12 +618,14 @@ class Propal extends CommonObject
|
||||
|
||||
// Met a jour en base
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET";
|
||||
$sql .= " price='". price2num($this->total_ht)."'";
|
||||
$sql .= ", tva='". price2num($this->total_tva)."'";
|
||||
$sql .= ", total='". price2num($this->total_ttc)."'";
|
||||
$sql .= ", remise='".price2num($this->total_remise)."'";
|
||||
$sql .= " total_ht=".price2num($this->total_ht).",";
|
||||
$sql .= " tva=". price2num($this->total_tva).",";
|
||||
$sql .= " total=". price2num($this->total_ttc).",";
|
||||
$sql .= " remise=". price2num($this->total_remise).","; // \TODO A virer
|
||||
$sql .= " price=". price2num($this->total_ht); // \TODO A virer
|
||||
$sql .=" WHERE rowid = ".$this->id;
|
||||
|
||||
dolibarr_syslog("Propal::update_price sql=".$sql);
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
return 1;
|
||||
@ -629,6 +633,7 @@ class Propal extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dolibarr_syslog("Propal::update_price error=".$this->error);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user