Qual: Uniformisation du code php pour grer les lignes de propal, facture et commande.

This commit is contained in:
Laurent Destailleur 2006-06-16 23:55:20 +00:00
parent 4a814b6b81
commit 9666db6cb7
20 changed files with 743 additions and 819 deletions

View File

@ -115,35 +115,34 @@ if (defined("PROPALE_ADDON") && is_readable(DOL_DOCUMENT_ROOT ."/includes/module
$i=0;
while ($i < GEN_NUMBER_PROPAL)
{
$i++;
$socid = rand(1, $num_socs);
$soc = new Societe($db);
$obj = PROPALE_ADDON;
$modPropale = new $obj;
$numpr = $modPropale->propale_get_num($soc);
$propal = new Propal($db, $socids[$socid]);
$propal->ref = $numpr;
$propal->contactid = $contids[$socids[$socid]][0];
$propal->datep = time();
$propal->author = $user->id;
$propal->create($user);
$nbp = rand(1, 9);
$xnbp = 0;
while ($xnbp < $nbp)
{
$prodid = rand(1, $num_prods);
$propal->insert_product($prodids[$prodid], rand(1,5));
$xnbp++;
}
$i++;
$socid = rand(1, $num_socs);
$soc = new Societe($db);
$obj = $conf->global->PROPALE_ADDON;
$modPropale = new $obj;
$numpr = $modPropale->propale_get_num($soc);
$propal = new Propal($db, $socids[$socid]);
$propal->ref = $numpr;
$propal->contactid = $contids[$socids[$socid]][0];
$propal->datep = time();
$propal->author = $user->id;
$propal->create($user);
$nbp = rand(1, 9);
$xnbp = 0;
while ($xnbp < $nbp)
{
$prodid = rand(1, $num_prods);
$propal->addline($propa->id, 'Description '.$xnbp, '100', rand(1,5), '19.6', $prodids[$prodid], 0);
$xnbp++;
}
}

View File

@ -96,7 +96,9 @@ if ($_POST['action'] == 'confirm_deleteproductline' && $_POST['confirm'] == 'yes
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
$propal->delete_product($_GET['ligne']);
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
}
Header('Location: '.$_SERVER["PHP_SELF"].'?propalid='.$_GET['propalid']);
exit;
@ -109,7 +111,9 @@ if ($_POST['action'] == 'confirm_validate' && $_POST['confirm'] == 'yes')
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
$result=$propal->update_price($_GET['propalid']);
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
$result=$propal->valid($user);
}
Header ('Location: '.$_SERVER["PHP_SELF"].'?propalid='.$_GET['propalid']);
@ -147,13 +151,14 @@ if ($_POST['action'] == 'set_ref_client' && $user->rights->propale->creer)
$propal->set_ref_client($user, $_POST['ref_client']);
}
/*
* Creation propale
*/
if ($_POST['action'] == 'add')
{
$propal = new Propal($db, $_POST['socidp']);
/*
* Si on a selectionné une propal à copier, on réalise la copie
*/
// Si on a selectionné une propal à copier, on réalise la copie
if($_POST['createmode']=='copy' && $_POST['copie_propal'])
{
if($propal->load_from($_POST['copie_propal']) == -1)
@ -216,7 +221,9 @@ if ($_POST['action'] == 'add')
*/
if ($id > 0)
{
propale_pdf_create($db, $id, $_POST['model']);
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
propale_pdf_create($db, $id, $_POST['model'], $outputlangs);
Header ('Location: '.$_SERVER["PHP_SELF"].'?propalid='.$id);
exit;
@ -398,36 +405,75 @@ if ($_POST['action'] == "addligne" && $user->rights->propale->creer)
$propal = new Propal($db);
$ret=$propal->fetch($_POST['propalid']);
if (isset($_POST['np_tva_tx']))
{
$propal->insert_product_generic(
$_POST['np_desc'],
$_POST['np_price'],
$_POST['qty'],
$_POST['np_tva_tx'],
$_POST['np_remise']);
}
else
{
$propal->insert_product(
$_POST['idprod'],
$_POST['qty'],
$_POST['remise'],
$_POST['np_desc']);
}
propale_pdf_create($db, $_POST['propalid'], $propal->modelpdf);
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
if ($_POST['idprod'])
{
$prod = new Product($db, $_POST['idprod']);
$prod->fetch($_POST['idprod']);
// multiprix
if ($conf->global->PRODUIT_MULTIPRICES == 1)
{
$pu = $prod->multiprices[$soc->price_level];
}
else
{
$pu=$prod->price;
}
// La description de la ligne est celle saisie ou
// celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini)
$desc=$_POST['np_desc'];
if (! $desc && $conf->global->PRODUIT_CHANGE_PROD_DESC)
{
$desc = $prod->description;
}
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
}
else
{
$pu=$_POST['np_price'];
$tva_tx=$_POST['np_tva_tx'];
$desc=$_POST['np_desc'];
}
$propal->addline(
$_POST['propalid'],
$desc,
$pu,
$_POST['qty'],
$tva_tx,
$_POST['idprod'],
$_POST['remise_percent']
);
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
}
}
/*
* Mise à jour d'une ligne dans la propale
*/
if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST["save"] == $langs->trans("Save"))
{
/*
* Mise à jour d'une ligne dans la propale
*/
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
$propal->UpdateLigne($_POST['ligne'], $_POST['subprice'], $_POST['qty'], $_POST['remise_percent'], $_POST['tva_tx'], $_POST['desc']);
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
if (! $propal->fetch($_POST['propalid']) > 0) dolibarr_print_error($db);
$result = $propal->updateline($_POST['ligne'],
$_POST['subprice'],
$_POST['qty'],
$_POST['remise_percent'],
$_POST['tva_tx'],
$_POST['desc']);
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
}
/*
@ -435,24 +481,26 @@ if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer && $_POST
*/
if ($_REQUEST['action'] == 'builddoc' && $user->rights->propale->creer)
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
if ($_POST['model']) $propal->set_pdf_model($user, $_POST['model']);
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf, $outputlangs);
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
}
if ($_GET['action'] == 'del_ligne' && $user->rights->propale->creer && !$conf->global->PRODUIT_CONFIRM_DELETE_LINE)
{
/*
* Supprime une ligne produit dans la propale
*/
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
$propal->delete_product($_GET['ligne']);
propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
/*
* Supprime une ligne produit dans la propale
*/
$propal = new Propal($db);
$propal->fetch($_GET['propalid']);
$propal->delete_product($_GET['ligne']);
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
propale_pdf_create($db, $propal->id, $propal->modelpdf, $outputlangs);
}
if ($_POST['action'] == 'set_project')
@ -1197,7 +1245,7 @@ if ($_GET['propalid'] > 0)
print "</td>\n";
print '<td align="right"><input type="text" size="5" name="np_price"></td>';
print '<td align="right"><input type="text" size="2" value="1" name="qty"></td>';
print '<td align="right" nowrap><input type="text" size="1" value="'.$societe->remise_client.'" name="np_remise">%</td>';
print '<td align="right" nowrap><input type="text" size="1" value="'.$societe->remise_client.'" name="remise_percent">%</td>';
print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="'.$langs->trans('Add').'" name="addligne"></td>';
print '</tr>';
@ -1228,7 +1276,7 @@ if ($_GET['propalid'] > 0)
print '</td>';
print '<td>&nbsp;</td>';
print '<td align="right"><input type="text" size="2" name="qty" value="1"></td>';
print '<td align="right" nowrap><input type="text" size="1" name="remise" value="'.$societe->remise_client.'">%</td>';
print '<td align="right" nowrap><input type="text" size="1" name="remise_percent" value="'.$societe->remise_client.'">%</td>';
print '<td align="center" valign="middle" colspan="4"><input type="submit" class="button" value="'.$langs->trans("Add").'" name="addligne">';
print '</td></tr>'."\n";

View File

@ -321,7 +321,10 @@ class Commande
*/
function create($user)
{
global $conf,$langs;
global $conf,$langs,$mysoc;
// Nettoyage parametres
$this->brouillon = 1; // On positionne en mode brouillon la commande
// Vérification paramètres
if ($this->source < 0)
@ -329,20 +332,16 @@ class Commande
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Source"));
return -1;
}
if (! $remise) $remise=0;
if (! $this->projetid) $this->projetid = 0;
// On positionne en mode brouillon la commande
$this->brouillon = 1;
if (! $remise)
{
$remise = 0 ;
}
if (! $this->projetid)
{
$this->projetid = 0;
}
dolibarr_syslog("Commande.class.php::create");
$soc = new Societe($this->db);
$soc->fetch($this->socidp);
$this->db->begin();
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commande (';
$sql.= 'fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note, ref_client,';
$sql.= ' model_pdf, fk_cond_reglement, fk_mode_reglement, date_livraison, fk_adresse_livraison,';
@ -357,82 +356,63 @@ class Commande
$sql.= " '".$this->remise_absolue."',";
$sql.= " '".$this->remise_percent."')";
dolibarr_syslog("Commande.class.php::create sql=$sql");
if ( $this->db->query($sql) )
$resql=$this->db->query($sql);
if ($resql)
{
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'commande');
/*
* Insertion des produits dans la base
*/
for ($i = 0 ; $i < sizeof($this->products) ; $i++)
{
$prod = new Product($this->db, $this->products[$i]);
if ($prod->fetch($this->products[$i]))
{
$this->soc_id;
$client = new Societe($this->db);
$client->fetch($this->soc_id);
if($client->tva_assuj == "0")
$tva_tx ="0";
else
$tva_tx=$prod->tva_tx;
// multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
//$prod->multiprices[$client->price_level]
$this->insert_product_generic($prod->libelle,
$prod->description,
$prod->multiprices[$client->price_level],
$this->products_qty[$i],
$tva_tx,
$this->products[$i],
$this->products_remise_percent[$i]);
}
else
{
$this->insert_product_generic($prod->libelle,
$prod->description,
$prod->price,
$this->products_qty[$i],
$tva_tx,
$this->products[$i],
$this->products_remise_percent[$i]);
}
}
}
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
if ($this->db->query($sql))
{
if ($this->id && $this->propale_id)
{
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_pr (fk_commande, fk_propale) VALUES ('.$this->id.','.$this->propale_id.')';
$this->db->query($sql);
}
if ($this->id)
{
/*
* Produits
*
*/
for ($i = 0 ; $i < sizeof($this->lines) ; $i++)
* Insertion des produits dans la base
*/
for ($i = 0 ; $i < sizeof($this->products) ; $i++)
{
$result_insert = $this->insert_product_generic(
$this->lines[$i]->libelle,
$this->lines[$i]->description,
$this->lines[$i]->price,
$this->lines[$i]->qty,
$this->lines[$i]->tva_tx,
$this->lines[$i]->product_id,
$this->lines[$i]->remise_percent);
if ( $result_insert < 0)
$prod = new Product($this->db, $this->products[$i]);
if ($prod->fetch($this->products[$i]))
{
dolibarr_print_error($this->db);
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
// multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1)
$price = $prod->multiprices[$soc->price_level];
else
$price = $prod->price;
$resql = $this->addline(
$this->id,
$prod->description,
$price,
$this->products_qty[$i],
$tva_tx,
$this->products[$i],
$this->products_remise_percent[$i]
);
if ($resql < 0)
{
$this->error=$this->db->error;
dolibarr_print_error($this->db);
break;
}
}
}
return $this->id;
}
else
{
return -1;
// Mise a jour ref
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande SET ref='(PROV".$this->id.")' WHERE rowid=".$this->id;
if ($this->db->query($sql))
{
if ($this->id && $this->propale_id)
{
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'co_pr (fk_commande, fk_propale) VALUES ('.$this->id.','.$this->propale_id.')';
$this->db->query($sql);
}
return $this->id;
}
else
{
return -1;
}
}
}
else
@ -441,197 +421,102 @@ class Commande
return 0;
}
}
/**
* Ajoute un produit
*
*/
function insert_product_generic($p_desc, $p_product_desc, $p_price, $p_qty, $p_tva_tx=19.6, $p_product_id=0, $remise_percent=0)
{
global $conf;
if ($this->statut == 0)
{
if (strlen(trim($p_qty)) == 0)
{
$p_qty = 1;
}
$p_price = ereg_replace(',','.',$p_price);
$price = $p_price;
$subprice = $p_price;
if ($remise_percent > 0)
{
$remise = round(($p_price * $remise_percent / 100), 2);
$price = $p_price - $remise;
}
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet (fk_commande, fk_product, qty, price, tva_tx, label, description, remise_percent, subprice) VALUES ';
$sql .= " ('".$this->id."', '$p_product_id','". $p_qty."','".price2num($price)."','".$p_tva_tx."','".addslashes($p_desc)."','".addslashes($p_product_desc)."', '$remise_percent', '$subprice') ; ";
// Bugfix
/*
if ($conf->global->PRODUIT_CHANGE_PROD_DESC)
{
$sql .= " ('".$this->id."', '$p_product_id','". $p_qty."','".price2num($price)."','".$p_tva_tx."','".addslashes($p_desc)."','".addslashes($p_product_desc)."', '$remise_percent', '$subprice') ; ";
}
else
{
$sql .= " ('".$this->id."', '$p_product_id','". $p_qty."','".price2num($price)."','".$p_tva_tx."','".addslashes($p_desc)."','".addslashes($p_product_desc)."', '$remise_percent', '$subprice') ; ";
}
*/
if ($this->db->query($sql) )
{
if ($this->update_price() > 0)
{
/**
* \brief Ajout d'un produit dans la commande, en base
* \param commandeid id de la commande
* \param desc description de la ligne
* \param pu prix unitaire
* \param qty quantité
* \param txtva taux de tva forcé, sinon -1
* \param fk_product id du produit/service predéfini
* \param remise_percent pourcentage de remise de la ligne
* \return int >0 si ok, <0 si ko
* \see add_product
* \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
* 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)
*/
function addline($commandeid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
{
dolibarr_syslog("commande.class.php::addline $commandeid, $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
if ($this->statut == 0)
{
$this->db->begin();
// Nettoyage paramètres
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
if (! $qty) $qty=1;
$pu = price2num($pu);
$txtva = price2num($txtva);
// 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);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
$total_ttc = $tabprice[2];
// Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser)
$price = $pu;
$subprice = $pu;
if ($remise_percent > 0)
{
$remise = round(($pu * $remise_percent / 100), 2);
$price = $pu - $remise;
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commandedet (fk_commande, fk_product, qty, price, tva_tx, description, remise_percent, subprice, total_ht, total_tva, total_ttc)";
$sql.= " VALUES ";
$sql.= " (".$this->id.", ";
if ($fk_product) { $sql.= "'$fk_product',"; }
else { $sql.='0,'; }
$sql.= " '". $qty."','". price2num($price)."','".$txtva."','".addslashes($desc)."','".price2num($remise_percent)."', '".price2num($subprice)."',";
$sql.= " '".price2num($total_ht) ."',";
$sql.= " '".price2num($total_tva)."',";
$sql.= " '".price2num($total_ttc)."'";
$sql.= ")";
if ($this->db->query($sql))
{
// Mise a jour informations denormalisees au niveau de la facture meme
$result=$this->update_price($this->id);
if ($result > 0)
{
$this->db->commit();
return 1;
}
else
{
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Error sql=$sql, error=".$this->error);
$this->db->rollback();
return -1;
}
}
else
{
dolibarr_print_error($this->db);
return -2;
}
}
}
}
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Error sql=$sql, error=".$this->error);
$this->db->rollback();
return -2;
}
}
}
/**
* Ajoute une ligne de commande
* Ajoute un produit dans la commande
*
*/
function addline($desc, $product_desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
{
global $conf;
// Nettoyage parametres
$qty = price2num($qty);
$pu = price2num($pu);
$desc=trim($desc);
$product_desc=trim($product_desc);
if (strlen(trim($qty))==0)
{
$qty=1;
}
// Verifs
if (! $this->brouillon) return -1;
$this->db->begin();
if ($fk_product > 0)
{
$prod = new Product($this->db, $fk_product);
if ($prod->fetch($fk_product) > 0)
{
$desc = $desc?$desc:$prod->libelle;
$product_desc = $prod->description;
$client = new Societe($this->db);
$client->fetch($this->soc_id);
if($client->tva_assuj == "0")
$txtva ="0";
else
$txtva=$prod->tva_tx;
// multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1)
{
$pu = $prod->multiprices[$client->price_level];
}
else
$pu = $prod->price;
}
}
$remise = 0;
$price = round(price2num($pu), 2);
$subprice = $price;
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet (fk_commande,label,description,fk_product, price,qty,tva_tx, remise_percent, subprice, remise)';
if ($conf->global->PRODUIT_CHANGE_PROD_DESC)
{
$sql .= " VALUES ($this->id, '" . addslashes($desc) . "','" . addslashes($product_desc) . "',$fk_product,".price2num($price).", '$qty', $txtva, $remise_percent,'".price2num($subprice)."','".price2num( $remise)."') ;";
}
else
{
$sql .= " VALUES ($this->id, '" . addslashes($desc) . "','" . addslashes($desc) . "',$fk_product,".price2num($price).", '$qty', $txtva, $remise_percent,'".price2num($subprice)."','".price2num( $remise)."') ;";
}
if ( $this->db->query( $sql) )
{
$this->update_price();
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
}
/**
* Ajoute une ligne de commande libre
*
*/
function addline_libre($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
{
global $conf;
// Nettoyage parametres
$qty = ereg_replace(',','.',$qty);
$pu = ereg_replace(',','.',$pu);
$desc=trim($desc);
if (strlen(trim($qty))==0)
{
$qty=1;
}
// Verifs
if (! $this->brouillon) return -1;
$this->db->begin();
$remise = 0;
$price = round(ereg_replace(',','.',$pu), 2);
$subprice = $price;
// appliquait la remise 2 fois : sur la ligne et le HT
/*
if (trim(strlen($remise_percent)) > 0)
{
$remise = round(($pu * $remise_percent / 100), 2);
$price = $pu - $remise;
}
*/
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet (fk_commande,label,description,fk_product, price,qty,tva_tx, remise_percent, subprice, remise)';
$sql .= " VALUES ($this->id, '" . addslashes($desc) . "','" . addslashes($desc) . "','$fk_product',".price2num($price).", '$qty', '$txtva', $remise_percent,'".price2num($subprice)."','".price2num( $remise)."') ;";
if ( $this->db->query( $sql) )
{
$this->update_price();
$this->db->commit();
return 1;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
return -1;
}
}
/**
* Ajoute un produit dans la commande
*
*/
function add_product($idproduct, $qty, $remise_percent=0)
{
global $conf;
@ -806,7 +691,7 @@ class Commande
$result = $this->db->query($sql) ;
if ( $result )
{
$obj = $this->db->fetch_object();
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
$this->ref = $obj->ref;
$this->ref_client = $obj->ref_client;
@ -886,7 +771,7 @@ class Commande
{
$objp = $this->db->fetch_object($result);
$ligne = new CommandeLigne();
$ligne = new CommandeLigne($this->db);
$ligne->desc = $objp->description; // Description ligne
$ligne->qty = $objp->qty;
@ -1227,49 +1112,64 @@ class Commande
}
/**
* \brief Mets à jour le prix total de la proposition
* \brief Mets à jour le prix total de la commnde
* \return int <0 si ko, >0 si ok
*/
function update_price()
{
include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
/*
* Liste des produits a ajouter
*/
$sql = "SELECT price, qty, tva_tx FROM ".MAIN_DB_PREFIX."commandedet";
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
// Liste des lignes factures a sommer
$sql = "SELECT price, qty, tva_tx, total_ht, total_tva, total_ttc";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet";
$sql.= " WHERE fk_commande = ".$this->id;
if ( $this->db->query($sql) )
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows();
$this->total_ht = 0;
$this->total_tva = 0;
$this->total_ttc = 0;
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object();
$obj = $this->db->fetch_object($result);
$this->total_ht += $obj->total_ht;
$this->total_tva += ($obj->total_ttc - $obj->total_ht);
$this->total_ttc += $obj->total_ttc;
// Anciens indicateurs
$this->amount_ht += $obj->price * $obj->qty;
$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
$products[$i][0] = $obj->price;
$products[$i][1] = $obj->qty;
$products[$i][2] = $obj->tva_tx;
*/
$i++;
}
$this->db->free($result);
}
/* \deprecated car simplifie par les 3 indicateurs total_ht, total_tva et total_ttc sur lignes
$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 .= " total_ht='". price2num($this->total_ht)."'";
$sql .= ", tva='". price2num($this->total_tva)."'";
$sql .= ", total_ttc='".price2num($this->total_ttc)."'";
$sql .= " amount_ht='".price2num($this->total_ht)."'";
$sql .= ", total_ht='". price2num($this->total_ht)."'";
$sql .= ", tva='". price2num($this->total_tva)."'";
$sql .= ", total_ttc='".price2num($this->total_ttc)."'";
$sql .= ", remise='".price2num($this->total_remise)."'";
$sql .=" WHERE rowid = ".$this->id;
if ( $this->db->query($sql) )
{
return 1;
@ -1277,6 +1177,7 @@ class Commande
else
{
$this->error=$this->db->error();
dolibarr_syslog("Commande::update_price error=".$this->error);
return -1;
}
}
@ -1579,51 +1480,80 @@ class Commande
* \param tva_tx Taux TVA
* \return int < 0 si erreur, > 0 si ok
*/
function update_line($rowid, $desc, $pu, $qty, $remise_percent=0, $tva_tx)
function update_line($rowid, $desc, $pu, $qty, $remise_percent=0, $txtva)
{
dolibarr_syslog("Commande::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent=0, $tva_tx");
dolibarr_syslog("Commande::UpdateLine $rowid, $desc, $pu, $qty, $remise_percent, $txtva");
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
if ($this->brouillon)
{
$this->db->begin();
// Nettoyage paramètres
$pu=price2num($pu);
if (strlen(trim($qty))==0) $qty=1;
$remise = 0;
// Nettoyage paramètres
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
if (! $qty) $qty=1;
$pu = price2num($pu);
$txtva=price2num($txtva);
// 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);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
$total_ttc = $tabprice[2];
// Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser)
$price = $pu;
$subprice = $price;
$remise_percent=trim($remise_percent);
$subprice = $pu;
$remise = 0;
if ($remise_percent > 0)
{
$remise = round(($pu * $remise_percent / 100), 2);
$price = $pu - $remise;
}
else
{
$remise_percent=0;
$remise = round(($pu * $remise_percent / 100),2);
$price = ($pu - $remise);
}
$price = price2num($price);
$subprice = price2num($subprice);
$sql = 'UPDATE '.MAIN_DB_PREFIX.'commandedet';
$sql.= " SET description='".addslashes($desc)."',price='".price2num($price)."',subprice='".$subprice."',";
$sql.= " remise='".$remise."',remise_percent='".$remise_percent."',qty='".$qty."',tva_tx='".$tva_tx."'";
$sql.= " WHERE rowid = '".$rowid."'";
// Mise a jour ligne en base
$sql = "UPDATE ".MAIN_DB_PREFIX."commandedet SET";
$sql.= " description='".addslashes($desc)."'";
$sql.= ",price='".price2num($price)."'";
$sql.= ",subprice='".price2num($subprice)."'";
$sql.= ",remise='".price2num($remise)."'";
$sql.= ",remise_percent='".price2num($remise_percent)."'";
$sql.= ",tva_tx='".price2num($txtva)."'";
$sql.= ",qty='".price2num($qty)."'";
//if ($datestart) { $sql.= ",date_start='$datestart'"; }
//else { $sql.=',date_start=null'; }
//if ($dateend) { $sql.= ",date_end='$dateend'"; }
//else { $sql.=',date_end=null'; }
//$sql.= " info_bits=".$info_bits.",";
$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);
if ( $result )
$result = $this->db->query( $sql);
if ($result > 0)
{
// Mise a jour info denormalisees au niveau facture
$this->update_price($this->id);
$this->db->commit();
return $result;
return $result;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
dolibarr_print_error($this->db);
return -1;
}
}
else
{
$this->error="Commande::updateline Order status makes operation forbidden";
return -2;
}
}

View File

@ -193,40 +193,70 @@ if ($_REQUEST['action'] == 'setremiseabsolue' && $user->rights->facture->creer)
$_GET['id']=$_REQUEST['id'];
}
/*
* Ajout d'une ligne produit dans la commande
*/
if ($_POST['action'] == 'addligne' && $user->rights->commande->creer)
{
/*
* Ajout d'une ligne produit dans la commande
*/
if ($_POST['qty'] && (($_POST['pu'] && $_POST['desc']) || $_POST['p_idprod']))
if ($_POST['qty'] && (($_POST['pu'] && $_POST['desc']) || $_POST['idprod']))
{
$commande = new Commande($db);
$ret=$commande->fetch($_POST['id']);
if (isset($_POST['p_idprod']))
{
$result = $commande->addline(
$_POST['np_desc'],
$_POST['product_desc'],
$_POST['pu'],
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
if ($_POST['idprod'])
{
$prod = new Product($db, $_POST['idprod']);
$prod->fetch($_POST['idprod']);
// multiprix
if ($conf->global->PRODUIT_MULTIPRICES == 1)
{
$pu = $prod->multiprices[$soc->price_level];
}
else
{
$pu=$prod->price;
}
// La description de la ligne est celle saisie ou
// celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini)
$desc=$_POST['np_desc'];
if (! $desc && $conf->global->PRODUIT_CHANGE_PROD_DESC)
{
$desc = $prod->description;
}
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
}
else
{
$pu=$_POST['pu'];
$tva_tx=$_POST['tva_tx'];
$desc=$_POST['desc'];
}
$commande->addline(
$_POST['id'],
$desc,
$pu,
$_POST['qty'],
$_POST['tva_tx'],
$_POST['p_idprod'],
$_POST['remise_percent']);
}
else
{
$result = $commande->addline_libre(
$_POST['desc'],
$_POST['pu'],
$_POST['qty'],
$_POST['tva_tx'],
0,
$_POST['remise_percent']);
}
$tva_tx,
$_POST['idprod'],
$_POST['remise_percent']
);
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
}
}
/*
* Mise à jour d'une ligne dans la propale
*/
if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POST['save'] == $langs->trans('Save'))
{
$commande = new Commande($db,'',$_POST['id']);
@ -234,12 +264,24 @@ if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POS
$result = $commande->update_line($_POST['elrowid'],
$_POST['eldesc'],
$_POST['elprice'],
$_POST['elqty'],
$_POST['pu'],
$_POST['qty'],
$_POST['elremise_percent'],
$_POST['eltva_tx']
$_POST['tva_tx']
);
if ($result >= 0)
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs);
}
else
{
dolibarr_print_error($db,$commande->error);
exit;
}
$_GET['id']=$_POST['id']; // Pour réaffichage de la fiche en cours d'édition
}
@ -1190,12 +1232,12 @@ else
print '<textarea name="eldesc" cols="50" rows="1">'.stripslashes($objp->description).'</textarea></td>';
print '<td align="right">';
if($soc->tva_assuj == "0")
print '<input type="hidden" name="eltva_tx" value="0">0';
print '<input type="hidden" name="tva_tx" value="0">0';
else
print $html->select_tva('eltva_tx',$objp->tva_tx,$mysoc,$soc);
print $html->select_tva('tva_tx',$objp->tva_tx,$mysoc,$soc);
print '</td>';
print '<td align="right"><input size="5" type="text" class="flat" name="elprice" value="'.price($objp->subprice).'"></td>';
print '<td align="right"><input size="2" type="text" class="flat" name="elqty" value="'.$objp->qty.'"></td>';
print '<td align="right"><input size="5" type="text" class="flat" name="pu" value="'.price($objp->subprice).'"></td>';
print '<td align="right"><input size="2" type="text" class="flat" name="qty" value="'.$objp->qty.'"></td>';
print '<td align="right" nowrap="nowrap"><input size="1" type="text" class="flat" name="elremise_percent" value="'.$objp->remise_percent.'">%</td>';
print '<td align="center" colspan="4"><input type="submit" class="button" name="save" value="'.$langs->trans('Save').'">';
print '<br /><input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'"></td>';
@ -1378,9 +1420,9 @@ else
print '<td colspan="2">';
// multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1)
$html->select_produits('','p_idprod','',$conf->produit->limit_size,$soc->price_level);
$html->select_produits('','idprod','',$conf->produit->limit_size,$soc->price_level);
else
$html->select_produits('','p_idprod','',$conf->produit->limit_size);
$html->select_produits('','idprod','',$conf->produit->limit_size);
if (! $conf->use_ajax) print '<br>';
print '<textarea cols="50" name="np_desc" rows="1"></textarea>';
print '</td>';
@ -1557,9 +1599,9 @@ else
print '<table class="border" width="100%">';
print '<tr '.$bc[$var].'><td>'.$langs->trans('Sendings').'</td>';
if ($conf->livraison->enabled)
{
print '<td>'.$langs->trans("DeliveryOrder").'</td>';
}
{
print '<td>'.$langs->trans("DeliveryOrder").'</td>';
}
print '<td>'.$langs->trans('Date').'</td></tr>';
$var=True;

View File

@ -142,7 +142,9 @@ if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->
$result = $fac->set_valid($fac->id, $user, $soc);
if ($result)
{
facture_pdf_create($db, $fac->id);
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
facture_pdf_create($db, $fac->id, '', $_REQUEST['model'], $outputlangs);
}
}
@ -360,14 +362,17 @@ if ($_POST['action'] == 'add')
}
}
/*
* Ajout d'une ligne produit dans la facture
*/
if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') && $user->rights->facture->creer)
{
if ($_POST['qty'] && ( $_POST['desc'] || $_POST['idprod']))
if ($_POST['qty'] && (($_POST['pu']!=0 && $_POST['desc']) || $_POST['idprod']))
{
$fac = new Facture($db);
$fac->fetch($_POST['facid']);
$ret=$fac->fetch($_POST['facid']);
$soc = new Societe($db);
$soc->fetch($fac->socidp);
$ret=$soc->fetch($fac->socidp);
$datestart='';
$dateend='';
@ -414,16 +419,10 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') &&
$pu=$prod->price;
}
// La description de la ligne est celle saisie ou
// celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini)
$desc=$_POST['desc'];
if (! $desc)
{
$desc = $prod->description;
}
// ceci n'a plus d'intérêt si on rajoute la description produit
// à chaque fois ???
if ($conf->global->PRODUIT_CHANGE_PROD_DESC)
if (! $desc && $conf->global->PRODUIT_CHANGE_PROD_DESC)
{
$desc = $prod->description;
}
@ -457,7 +456,7 @@ if (($_POST['action'] == 'addligne' || $_POST['action'] == 'addligne_predef') &&
if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST['save'] == $langs->trans('Save'))
{
$fac = new Facture($db,'',$_POST['facid']);
$fac->fetch($_POST['facid']);
if (! $fac->fetch($_POST['facid']) > 0) dolibarr_print_error($db);
$datestart='';
$dateend='';
@ -478,6 +477,10 @@ if ($_POST['action'] == 'updateligne' && $user->rights->facture->creer && $_POST
$_POST['tva_tx']
);
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
facture_pdf_create($db, $fac->id, '', $fac->modelpdf, $outputlangs);
$_GET['facid']=$_POST['facid']; // Pour réaffichage de la fiche en cours d'édition
}
@ -676,12 +679,12 @@ if ($_POST['action'] == 'send' || $_POST['action'] == 'relance')
*/
if ($_REQUEST['action'] == 'builddoc') // En get ou en post
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
$facture = new Facture($db, 0, $_GET['facid']);
$facture->fetch($_GET['facid']);
if ($_REQUEST['model']) $facture->set_pdf_model($user, $_REQUEST['model']);
$result=facture_pdf_create($db, $_REQUEST['facid'], '', $facture->modelpdf, $outputlangs);
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
$result=facture_pdf_create($db, $facture->id, '', $facture->modelpdf, $outputlangs);
if ($result <= 0)
{
dolibarr_print_error($db,$result);
@ -2174,7 +2177,7 @@ else
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Ref').'</td>';
print '<td>'.$langs->trans('RefCdeClientShort').'</td>';
print '<td>'.$langs->trans('RefCdeClientShort').'</td>';
print '<td align="center">'.$langs->trans('Date').'</td>';
print '<td align="right">'.$langs->trans('AmountHT').'</td>';
print '</tr>';
@ -2185,7 +2188,7 @@ else
$var=!$var;
print '<tr '.$bc[$var].'><td>';
print '<a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$objp->id.'">'.img_object($langs->trans('ShowOrder'), 'order').' '.$objp->ref."</a></td>\n";
print '<td>'.$objp->ref_client.'</td>';
print '<td>'.$objp->ref_client.'</td>';
print '<td align="center">'.dolibarr_print_date($objp->date_commande).'</td>';
print '<td align="right">'.price($objp->total_ht).'</td>';
print "</tr>\n";
@ -2268,8 +2271,8 @@ else
if (! is_readable($file))
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
$result=facture_pdf_create($db, $_REQUEST['facid'], '', $_REQUEST['model'], $outputlangs);
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
$result=facture_pdf_create($db, $fac->id, '', $_REQUEST['model'], $outputlangs);
if ($result <= 0)
{
dolibarr_print_error($db,$result);
@ -2319,8 +2322,8 @@ else
if (! is_readable($file))
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs");
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
$result=facture_pdf_create($db, $_REQUEST['facid'], '', $_REQUEST['model'], $outputlangs);
if ($_REQUEST['lang_id']) $outputlangs->setDefaultLang($_REQUEST['lang_id']);
$result=facture_pdf_create($db, $fac->id, '', $_REQUEST['model'], $outputlangs);
if ($result <= 0)
{
dolibarr_print_error($db,$result);

View File

@ -447,7 +447,7 @@ class FactureRec extends Facture
if ( $this->db->query( $sql) )
{
$this->updateprice($facid);
$this->update_price($facid);
return 1;
}
else
@ -492,7 +492,7 @@ class FactureRec extends Facture
$result = $this->db->query( $sql);
$this->updateprice($this->id);
$this->update_price($this->id);
}
}
@ -506,14 +506,14 @@ class FactureRec extends Facture
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = $rowid;";
$result = $this->db->query( $sql);
$this->updateprice($this->id);
$this->update_price($this->id);
}
}
/**
* Mise à jour des sommes de la facture
*/
function updateprice($facid)
function update_price($facid)
{
include_once DOL_DOCUMENT_ROOT . "/lib/price.lib.php";
$err=0;
@ -595,7 +595,7 @@ class FactureRec extends Facture
if ($this->db->query($sql) )
{
$this->updateprice($this->id);
$this->update_price($this->id);
return 1;
}
else

View File

@ -83,26 +83,26 @@ if ($_GET["action"] == 'setstatut')
if ( $action == 'delete' )
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = $propalid;";
if ( $db->query($sql) )
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = $propalid ;";
if ( $db->query($sql) )
{
print '<div class="ok">'.$langs->trans("Deleted").'</div>';
}
else
{
dolibarr_print_error($db);
}
}
else
{
dolibarr_print_error($db);
}
$propalid = 0;
$brouillon = 1;
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = $propalid;";
if ( $db->query($sql) )
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = $propalid ;";
if ( $db->query($sql) )
{
print '<div class="ok">'.$langs->trans("Deleted").'</div>';
}
else
{
dolibarr_print_error($db);
}
}
else
{
dolibarr_print_error($db);
}
$propalid = 0;
$brouillon = 1;
}
@ -151,7 +151,7 @@ if ($_GET["propalid"] > 0)
print '</td>';
print '</tr>';
$rowspan=9;
$rowspan=8;
// Société
print '<tr><td>'.$langs->trans('Company').'</td><td colspan="5">'.$societe->getNomUrl(1).'</td></tr>';
@ -231,6 +231,7 @@ if ($_GET["propalid"] > 0)
print '</td></tr>';
// Destinataire
/* Remplacé par contacts de propal
$langs->load('mails');
print '<tr>';
print '<td>'.$langs->trans('MailTo').'</td>';
@ -253,6 +254,7 @@ if ($_GET["propalid"] > 0)
print '<td colspan="3">&nbsp;</td>';
}
}
*/
// Projet
if ($conf->projet->enabled)

View File

@ -396,53 +396,6 @@ class Expedition
return 1;
}
/**
* Ajoute un produit
*
*/
function insert_product_generic($p_desc, $p_price, $p_qty, $p_tva_tx=19.6, $p_product_id=0, $remise_percent=0)
{
if ($this->statut == 0)
{
if (strlen(trim($p_qty)) == 0)
{
$p_qty = 1;
}
$p_price = price2num($p_price);
$price = $p_price;
$subprice = $p_price;
if ($remise_percent > 0)
{
$remise = round(($p_price * $remise_percent / 100), 2);
$price = $p_price - $remise;
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commandedet (fk_commande, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
$sql .= " (".$this->id.", $p_product_id,". $p_qty.",". $price.",".$p_tva_tx.",'". addslashes($p_desc) ."',$remise_percent, $subprice) ; ";
if ($this->db->query($sql) )
{
if ($this->update_price() > 0)
{
return 1;
}
else
{
return -1;
}
}
else
{
print $this->db->error();
print "<br>".$sql;
return -2;
}
}
}
/**
* \brief Crée un bon de livraison à partir de l'expédition

View File

@ -109,8 +109,6 @@ class Facture
{
global $langs,$conf,$mysoc;
$this->db->begin();
// Nettoyage paramètres
$this->note=trim($this->note);
$this->note_public=trim($this->note_public);
@ -122,6 +120,11 @@ class Facture
dolibarr_syslog("Facture::create");
$soc = new Societe($this->db);
$soc->fetch($this->socidp);
$this->db->begin();
// Facture récurrente
if ($this->fac_rec > 0)
{
@ -196,8 +199,7 @@ class Facture
{
$prod = new Product($this->db, $this->products[$i]);
$res=$prod->fetch($this->products[$i]);
$soc = new Societe($this->db);
$soc->fetch($this->socidp);
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
// multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1)
@ -258,7 +260,7 @@ class Facture
if ($resql)
{
$resql=$this->updateprice($this->id);
$resql=$this->update_price($this->id);
if ($resql)
{
// Appel des triggers
@ -789,7 +791,7 @@ class Facture
$numfa = $this->getNextNumRef($soc);
}
$this->updateprice($this->id);
$this->update_price($this->id);
// Validation de la facture
$sql = 'UPDATE '.MAIN_DB_PREFIX.'facture ';
@ -970,13 +972,13 @@ class Facture
}
/**
* \brief Ajoute un produit dans les tableaux products, products_qty, products_date_start|end
* \param idproduct
* \param qty
* \param remise_percent
* \param datestart
* \param dateend
*/
* \brief Ajoute un produit dans les tableaux products, products_qty, products_date_start|end
* \param idproduct
* \param qty
* \param remise_percent
* \param datestart
* \param dateend
*/
function add_product($idproduct, $qty, $remise_percent, $datestart='', $dateend='')
{
if ($idproduct > 0)
@ -1014,7 +1016,7 @@ class Facture
function addline($facid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $datestart='', $dateend='', $ventil = 0)
{
global $conf;
dolibarr_syslog("facture.class.php::addline($facid,$desc,$product_desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$datestart,$dateend,$ventil)");
dolibarr_syslog("facture.class.php::addline($facid,$desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$datestart,$dateend,$ventil)");
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
if ($this->brouillon)
@ -1048,8 +1050,6 @@ class Facture
$remise = round(($pu * $remise_percent / 100),2);
$price = ($pu - $remise);
}
$price = price2num($price);
$subprice = price2num($subprice);
// Récupère rang max de la facture dans $rangmax
$sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.'facturedet';
@ -1096,7 +1096,7 @@ class Facture
if ( $this->db->query($sql) )
{
// Mise a jour informations denormalisees au niveau de la facture meme
$result=$this->updateprice($facid);
$result=$this->update_price($facid);
if ($result > 0)
{
@ -1105,14 +1105,18 @@ class Facture
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Error sql=$sql, error=".$this->error);
$this->db->rollback();
return -1;
}
}
else
{
dolibarr_print_error($this->db);
$this->db->commit();
$this->error=$this->db->error();
dolibarr_syslog("Error sql=$sql, error=".$this->error);
$this->db->rollback();
return -2;
}
}
}
@ -1167,8 +1171,8 @@ class Facture
$subprice = price2num($subprice);
// Mise a jour ligne en base
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet";
$sql.= " set description='".addslashes($desc)."'";
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet SET";
$sql.= " description='".addslashes($desc)."'";
$sql.= ",price='".price2num($price)."'";
$sql.= ",subprice='".price2num($subprice)."'";
$sql.= ",remise='".price2num($remise)."'";
@ -1186,10 +1190,10 @@ class Facture
$sql.= " WHERE rowid = ".$rowid;
$result = $this->db->query( $sql);
if ($result)
if ($result > 0)
{
// Mise a jour info denormalisees au niveau facture
$this->updateprice($this->id);
$this->update_price($this->id);
$this->db->commit();
return $result;
}
@ -1202,7 +1206,7 @@ class Facture
}
else
{
$this->error="Invoice statut makes operation forbidden";
$this->error="Facture::UpdateLine Invoice statut makes operation forbidden";
return -2;
}
}
@ -1217,7 +1221,7 @@ class Facture
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE rowid = '.$rowid;
$result = $this->db->query( $sql);
$this->updateprice($this->id);
$this->update_price($this->id);
}
}
@ -1226,12 +1230,12 @@ class Facture
* \param facid id de la facture a modifier
* \return int <0 si ko, >0 si ok
*/
function updateprice($facid)
function update_price($facid)
{
$tvas=array();
$err=0;
// Lit les lignes detail
// Liste des lignes factures a sommer
$sql = 'SELECT qty, tva_taux, subprice, remise_percent, price, total_ht, total_tva, total_ttc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet';
$sql.= ' WHERE fk_facture = '.$facid;
@ -1350,7 +1354,7 @@ class Facture
if ($this->db->query($sql))
{
$this->remise_percent = $remise;
$this->updateprice($this->id);
$this->update_price($this->id);
return 1;
}
else
@ -1385,7 +1389,7 @@ class Facture
if ($this->db->query($sql))
{
$this->remise_absolue = $remise;
$this->updateprice($this->id);
$this->update_price($this->id);
return 1;
}
else

View File

@ -662,51 +662,6 @@ class CommandeFournisseur extends Commande
}
}
/**
* Ajoute un produit
*
*/
function insert_product_generic($p_desc, $p_price, $p_qty, $p_tva_tx=19.6, $p_product_id=0, $remise_percent=0)
{
if ($this->statut == 0)
{
if (strlen(trim($p_qty)) == 0)
{
$p_qty = 1;
}
$p_price = price2num($p_price);
$price = $p_price;
$subprice = $p_price;
if ($remise_percent > 0)
{
$remise = round(($p_price * $remise_percent / 100), 2);
$price = $p_price - $remise;
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commandedet (fk_commande, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
$sql .= " ('".$this->id."', '$p_product_id','". $p_qty."','". $price."','".$p_tva_tx."','".addslashes($p_desc)."','$remise_percent', '$subprice') ; ";
if ($this->db->query($sql) )
{
if ($this->update_price() > 0)
{
return 1;
}
else
{
return -1;
}
}
else
{
dolibarr_print_error($this->db);
return -2;
}
}
}
/**
* Supprime une ligne de la commande
*

View File

@ -125,7 +125,7 @@ class FactureFournisseur extends Facture
}
}
// Mise à jour prix
if ($this->updateprice($this->id) > 0)
if ($this->update_price($this->id) > 0)
{
$this->db->commit();
return $this->id;
@ -340,7 +340,7 @@ class FactureFournisseur extends Facture
dolibarr_print_error($this->db);
}
// Mise a jour prix facture
$this->updateprice($this->id);
$this->update_price($this->id);
}
/**
@ -378,7 +378,7 @@ class FactureFournisseur extends Facture
if ($resql)
{
// Mise a jour prix facture
return $this->updateprice($this->id);
return $this->update_price($this->id);
}
else
{
@ -403,7 +403,7 @@ class FactureFournisseur extends Facture
dolibarr_print_error($this->db);
}
// Mise a jour prix facture
$this->updateprice($this->id);
$this->update_price($this->id);
return 1;
}
@ -412,7 +412,7 @@ class FactureFournisseur extends Facture
* \param facid id de la facture a modifier
* \return int <0 si ko, >0 si ok
*/
function updateprice($facid)
function update_price($facid)
{
$total_ht = 0;
$total_tva = 0;

View File

@ -163,6 +163,8 @@ if (isset($_POST['action']) && $_POST['action'] == 'upgrade')
migrate_modeles($db,$langs,$conf);
migrate_price_facture($db,$langs,$conf);
// On commit dans tous les cas.
// La procédure etant conçue pour pouvoir passer plusieurs fois quelquesoit la situation.
@ -583,6 +585,52 @@ function migrate_paiementfourn_facturefourn($db,$langs,$conf)
}
/*
* Mise a jour des totaux facture
*/
function migrate_price_facture($db,$langs,$conf)
{
if ($conf->facture->enabled)
{
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture";
if ($db->query($sql))
{
$num = $db->num_rows();
$i = 0;
while ($i < $num)
{
$row = $db->fetch_row($i);
$facture = new Facture($db);
if ( $facture->fetch($row[0]) )
{
if ( $facture->update_price($row[0]) > 0 )
{
print "(ok $row[0]) ";
}
else
{
print "Erreur #2";
$err++;
}
}
else
{
print "Erreur #3";
$err++;
}
$i++;
}
$db->free();
}
else
{
print "Erreur #1";
$err++;
}
}
}
/*
* Mise a jour des modeles selectionnes
*/

View File

@ -439,52 +439,7 @@ class Livraison
return $this->create($user);
}
/**
* Ajoute un produit
*
*/
function insert_product_generic($p_desc, $p_price, $p_qty, $p_tva_tx=19.6, $p_product_id=0, $remise_percent=0)
{
if ($this->statut == 0)
{
if (strlen(trim($p_qty)) == 0)
{
$p_qty = 1;
}
$p_price = price2num($p_price);
$price = $p_price;
$subprice = $p_price;
if ($remise_percent > 0)
{
$remise = round(($p_price * $remise_percent / 100), 2);
$price = $p_price - $remise;
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commandedet (fk_commande, fk_product, qty, price, tva_tx, description, remise_percent, subprice) VALUES ";
$sql .= " (".$this->id.", $p_product_id,". $p_qty.",". $price.",".$p_tva_tx.",'". addslashes($p_desc) ."',$remise_percent, $subprice) ; ";
if ($this->db->query($sql) )
{
if ($this->update_price() > 0)
{
return 1;
}
else
{
return -1;
}
}
else
{
print $this->db->error();
print "<br>".$sql;
return -2;
}
}
}
/**
* Ajoute une ligne
*

View File

@ -780,7 +780,7 @@ class Product
if (! $id && ! $ref)
{
$this->error=$langs->trans('ErrorWrongParameters');
dolibarr_error("Product::fetch ".$this->error);
dolibarr_print_error("Product::fetch ".$this->error);
return -1;
}

View File

@ -228,16 +228,41 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user-
if ($_POST["action"] == 'addinpropal')
{
$propal = New Propal($db);
$propal->fetch($_POST["propalid"]);
$result = $propal->insert_product($_GET["id"], $_POST["qty"], $_POST["remise_percent"]);
if ( $result < 0)
$result=$propal->fetch($_POST["propalid"]);
if ($result <= 0)
{
dolibarr_print_error($db,$propal->error);
exit;
}
$prod = new Product($db, $_GET['id']);
$result=$prod->fetch($_GET['id']);
if ($result <= 0)
{
dolibarr_print_error($db,$prod->error);
exit;
}
// multiprix
if ($conf->global->PRODUIT_MULTIPRICES == 1)
{
$mesg = $langs->trans("ErrorUnknown").": $result";
$pu = $prod->multiprices[$soc->price_level];
}
else
{
$pu=$prod->price;
}
$desc = $prod->desc;
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
Header("Location: ../comm/propal.php?propalid=".$propal->id);
exit;
$result = $propal->addline($propal->id, $desc, $pu, $_POST["qty"], $tva_tx, $prod->id, $_POST["remise_percent"]);
if ($result > 0)
{
Header("Location: ../comm/propal.php?propalid=".$propal->id);
return;
}
$mesg = $langs->trans("ErrorUnknown").": $result";
}
/*

View File

@ -117,14 +117,13 @@ class Propal
}
/**
* \brief Ajout d'un produit dans la proposition, en memoire dans l'objet
* \param idproduct Id du produit à ajouter
* \param qty Quantité
* \param remise_percent Remise relative effectuée sur le produit
* \return void
* \see insert_product
*/
/**
* \brief Ajout d'un produit dans la proposition, en memoire dans l'objet
* \param idproduct Id du produit à ajouter
* \param qty Quantité
* \param remise_percent Remise relative effectuée sur le produit
* \return void
*/
function add_product($idproduct, $qty, $remise_percent=0)
{
if ($idproduct > 0)
@ -157,137 +156,41 @@ class Propal
/**
* \brief Ajout d'un produit dans la proposition, en base
* \param idproduct Id du produit à ajouter
* \param qty Quantité
* \param remise_percent Remise relative effectuée sur le produit
* \param desc Descriptif optionnel
* \return int >0 si ok, <0 si ko
* \param propalid id de la propale
* \param desc description de la ligne
* \param pu prix unitaire
* \param qty quantité
* \param txtva taux de tva forcé, sinon -1
* \param fk_product id du produit/service predéfini
* \param remise_percent pourcentage de remise de la ligne
* \return int >0 si ok, <0 si ko
* \see add_product
* \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
* 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)
*/
function insert_product($idproduct, $qty, $remise_percent=0, $desc='')
function addline($propalid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
{
global $conf,$mysoc;
dolibarr_syslog("propal.class.php::insert_product $idproduct, $qty, $remise_percent, $desc");
dolibarr_syslog("propal.class.php::addline $propalid, $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
if ($this->statut == 0)
{
// Nettoyage parametres
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
$this->db->begin();
if ($idproduct)
{
$prod = new Product($this->db, $idproduct);
if ($prod->fetch($idproduct) > 0)
{
$this->fetch_client();
// multiprix
if ($conf->global->PRODUIT_MULTIPRICES == 1)
{
$pu = price2num($prod->multiprices[$this->client->price_level]);
}
else
{
$pu = price2num($prod->price);
}
$txtva = get_default_tva($mysoc,$this->client,$prod->tva_tx);
if (! $desc) $desc = $prod->description;
if ($conf->global->PRODUIT_CHANGE_PROD_DESC) $desc=$prod->description;
// 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);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
$total_ttc = $tabprice[2];
// Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser)
$price = $pu;
$subprice = $pu;
$remise = 0;
if ($remise_percent > 0)
{
$remise = round(($prod->price * $remise_percent / 100), 2);
$price = $prod->price - $remise;
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice,";
$sql.= " total_ht, total_tva, total_ttc)";
$sql.= " VALUES ";
$sql.= " (".$this->id.",". $idproduct.",'". $qty."','". price2num($price) ."','".$txtva."','".addslashes($desc?$desc:$prod->label)."','".price2num($remise_percent)."','".price2num($subprice)."',";
$sql.= " '".price2num($total_ht) ."',";
$sql.= " '".price2num($total_tva)."',";
$sql.= " '".price2num($total_ttc)."'";
$sql.= ")";
if ($this->db->query($sql))
{
$this->update_price();
return 1;
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Error sql=$sql, error=".$this->error);
return -1;
}
}
else
{
$this->error=$this->db->error();
return -2;
}
}
}
else
{
return -3;
}
}
/**
* \brief Ajout d'un produit dans la proposition, en base
* \param desc Descriptif optionnel
* \param pu Prix
* \param qty Quantité
* \param tva_tx Taux tva
* \param remise_percent Remise effectuée sur le produit
* \return int >0 si ok, <0 si ko
* \see add_product
* \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
* 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)
*/
function insert_product_generic($desc, $pu, $qty, $tva_tx, $remise_percent=0)
{
global $conf,$mysoc;
dolibarr_syslog("propal.class.php::insert_product_generic $desc, $pu, $qty, $tva_tx, $remise_percent");
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
if ($this->statut == 0)
{
// Nettoyage paramètres
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
if (! $qty) $qty=1;
$pu = price2num($pu);
$tva_tx = price2num($tva_tx);
$txtva = price2num($txtva);
// 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, $tva_tx);
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
$total_ttc = $tabprice[2];
@ -303,7 +206,10 @@ class Propal
$sql = "INSERT INTO ".MAIN_DB_PREFIX."propaldet (fk_propal, fk_product, qty, price, tva_tx, description, remise_percent, subprice, total_ht, total_tva, total_ttc)";
$sql.= " VALUES ";
$sql.= " (".$this->id.", 0,'". $qty."','". price2num($price)."','".$tva_tx."','".addslashes($desc)."','$remise_percent', '".price2num($subprice)."',";
$sql.= " (".$this->id.", ";
if ($fk_product) { $sql.= "'$fk_product',"; }
else { $sql.='0,'; }
$sql.= " '". $qty."','". price2num($price)."','".$txtva."','".addslashes($desc)."','".price2num($remise_percent)."', '".price2num($subprice)."',";
$sql.= " '".price2num($total_ht) ."',";
$sql.= " '".price2num($total_tva)."',";
$sql.= " '".price2num($total_ttc)."'";
@ -311,20 +217,27 @@ class Propal
if ($this->db->query($sql))
{
// Mise a jour informations denormalisees au niveau de la facture meme
$result=$this->update_price($facid);
if ($this->update_price() > 0)
if ($result > 0)
{
return 1;
$this->db->commit();
return 1;
}
else
{
return -1;
$this->error=$this->db->error();
dolibarr_syslog("Error sql=$sql, error=".$this->error);
$this->db->rollback();
return -1;
}
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Error sql=$sql, error=".$this->error);
$this->db->rollback();
return -2;
}
}
@ -341,26 +254,27 @@ class Propal
* \param desc Description
* \return int 0 en cas de succès
*/
function UpdateLigne($id, $pu, $qty, $remise_percent=0, $tva_tx, $desc='')
function updateline($rowid, $pu, $qty, $remise_percent=0, $txtva, $desc='')
{
global $conf,$mysoc;
dolibarr_syslog("propal.class.php::updateligne $id, $pu, $qty, $remise_percent, $tva_tx, $desc");
dolibarr_syslog("propal.class.php::updateligne $rowid, $pu, $qty, $remise_percent, $txtva, $desc");
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
if ($this->statut == 0)
{
$this->db->begin();
// Nettoyage paramètres
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
if (! $qty) $qty=1;
$pu = price2num($pu);
$tva_tx = price2num($tva_tx);
$txtva = price2num($txtva);
// 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, $tva_tx);
$tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva);
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
$total_ttc = $tabprice[2];
@ -379,21 +293,24 @@ class Propal
$sql.= " , price='". price2num($price)."'";
$sql.= " , remise_percent='".$remise_percent."'";
$sql.= " , subprice='".$subprice."'";
$sql.= " , tva_tx='".$tva_tx."'";
$sql.= " , tva_tx='".$txtva."'";
$sql.= " , description='".addslashes($desc)."'";
$sql.= " , total_ht='".price2num($total_ht)."'";
$sql.= " , total_tva='".price2num($total_tva)."'";
$sql.= " , total_ttc='".price2num($total_ttc)."'";
$sql.= " WHERE rowid = '".$id."';";
$sql.= " WHERE rowid = '".$rowid."';";
if ($this->db->query($sql))
$result=$this->db->query($sql);
if ($result > 0)
{
$this->update_price();
$this->db->commit();
return 0;
}
else
{
$this->error=$this->db->error();
$this->db->rollback();
dolibarr_syslog("Propal::UpdateLigne Erreur sql=$sql, error=".$this->error);
return -1;
}
@ -744,15 +661,18 @@ class Propal
* \brief Crée une propal
* \return int <0 si ko, >=0 si ok
*/
function create()
function create($user='')
{
global $langs,$conf;
global $langs,$conf,$mysoc;
// Nettoyage/définition paramètres
$this->fin_validite = $this->datep + ($this->duree_validite * 24 * 3600);
dolibarr_syslog("Propal::create ref=".$this->ref);
$soc = new Societe($this->db);
$soc->fetch($this->socidp);
$this->db->begin();
// Insertion dans la base
@ -760,7 +680,7 @@ class Propal
$sql.= " tva, total, datep, datec, ref, fk_user_author, note, note_public, model_pdf, fin_validite,";
$sql.= " fk_cond_reglement, fk_mode_reglement, date_livraison, ref_client) ";
$sql.= " VALUES ($this->socidp, $this->contactid, 0, $this->remise, $this->remise_percent, $this->remise_absolue,";
$sql.= " 0,0,".$this->db->idate($this->datep).", now(), '$this->ref', $this->author,";
$sql.= " 0,0,".$this->db->idate($this->datep).", now(), '".$this->ref."', ".$this->author.",";
$sql.= "'".addslashes($this->note)."',";
$sql.= "'".addslashes($this->note_public)."',";
$sql.= "'$this->modelpdf',".$this->db->idate($this->fin_validite).",";
@ -779,48 +699,75 @@ class Propal
*/
for ($i = 0 ; $i < sizeof($this->products) ; $i++)
{
$prod = new Product($this->db, $this->products[$i]);
$result=$prod->fetch($this->products[$i]);
$result=$this->insert_product($this->products[$i],
$this->products_qty[$i],
$this->products_remise_percent[$i]);
$prod = new Product($this->db, $this->products[$i]);
if ($prod->fetch($this->products[$i]))
{
$tva_tx = get_default_tva($mysoc,$soc,$prod->tva_tx);
// multiprix
if($conf->global->PRODUIT_MULTIPRICES == 1)
$price = $prod->multiprices[$soc->price_level];
else
$price = $prod->price;
$resql = $this->addline(
$this->id,
$prod->libelle,
$prod->description,
$price,
$this->products_qty[$i],
$tva_tx,
$this->products[$i],
$this->products_remise_percent[$i],
$this->products_date_start[$i],
$this->products_date_end[$i]
);
if ($resql < 0)
{
$this->error=$this->db->error;
dolibarr_print_error($this->db);
break;
}
}
}
// Affectation au projet
if ($this->projetidp)
if ($resql && $this->projetidp)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_projet=$this->projetidp WHERE ref='$this->ref'";
$result=$this->db->query($sql);
}
// Affectation de l'adresse de livraison
if ($this->adresse_livraison_id)
if ($resql && $this->adresse_livraison_id)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_adresse_livraison=$this->adresse_livraison_id WHERE ref='$this->ref'";
$result=$this->db->query($sql);
}
// Mise a journ infos dénormalisés
$resql=$this->update_price();
if ($resql)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('PROPAL_CREATE',$this,$user,$langs,$conf);
// Fin appel triggers
$this->db->commit();
return $this->id;
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Propal::Create -2 ".$this->error);
$this->db->rollback();
return -2;
}
if ($resql)
{
// Mise a jour infos dénormalisés
$resql=$this->update_price();
if ($resql)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('PROPAL_CREATE',$this,$user,$langs,$conf);
// Fin appel triggers
$this->db->commit();
return $this->id;
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Propal::Create -2 ".$this->error);
$this->db->rollback();
return -2;
}
}
}
}
else
@ -842,9 +789,7 @@ class Propal
{
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
/*
* Liste des produits a ajouter
*/
// Liste des lignes factures a sommer
$sql = "SELECT price, qty, tva_tx, total_ht, total_tva, total_ttc";
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet";
$sql.= " WHERE fk_propal = ".$this->id;
@ -2221,17 +2166,23 @@ class Propal
*/
foreach($this->lignes as $ligne)
{
if($ligne->product_id != 0)
{
$result=$this->insert_product($ligne->product_id,
$ligne->qty,
$ligne->remise_percent, $ligne->product_desc);
}
else
{
$this->insert_product_generic($ligne->desc, $ligne->price,
$ligne->qty, $ligne->tva_tx, $ligne->remise_percent);
}
$resql = $this->addline(
$this->id,
$prod->libelle,
$prod->description,
$price,
$ligne->qty,
$tva_tx,
$ligne->product_id,
$ligne->remise_percent
);
if ($resql < 0)
{
$this->error=$this->db->error;
dolibarr_print_error($this->db);
break;
}
}
// Affectation au projet

View File

@ -120,6 +120,11 @@ ALTER TABLE llx_propaldet ADD COLUMN total_tva real AFTER total_ht;
ALTER TABLE llx_propaldet ADD COLUMN total_ttc real AFTER total_tva;
ALTER TABLE llx_propaldet ADD COLUMN info_bits integer DEFAULT 0 AFTER total_ttc;
ALTER TABLE llx_commandedet ADD COLUMN total_ht real AFTER price;
ALTER TABLE llx_commandedet ADD COLUMN total_tva real AFTER total_ht;
ALTER TABLE llx_commandedet ADD COLUMN total_ttc real AFTER total_tva;
ALTER TABLE llx_commandedet ADD COLUMN info_bits integer DEFAULT 0 AFTER total_ttc;
ALTER TABLE llx_commande ADD INDEX idx_commande_fk_soc (fk_soc);
ALTER TABLE llx_commande ADD CONSTRAINT fk_commande_societe FOREIGN KEY (fk_soc) REFERENCES llx_societe (idp);

View File

@ -26,13 +26,17 @@ create table llx_commandedet
fk_product integer,
label varchar(255),
description text,
tva_tx real DEFAULT 19.6, -- taux tva
tva_tx real, -- taux tva
qty real, -- quantité
remise_percent real DEFAULT 0, -- pourcentage de remise
remise real DEFAULT 0, -- montant de la remise
fk_remise_except integer NULL, -- Lien vers table des remises fixes
subprice real, -- prix avant remise
price real, -- prix final
total_ht real, -- Total HT de la ligne toute quantité et incluant remise ligne et globale
total_tva real, -- Total TVA de la ligne toute quantité et incluant remise ligne et globale
total_ttc real, -- Total TTC de la ligne toute quantité et incluant remise ligne et globale
info_bits integer DEFAULT 0, -- TVA NPR ou non
coef real, -- coefficient de marge
rang integer DEFAULT 0
)type=innodb;

View File

@ -26,7 +26,7 @@ create table llx_facturedet
fk_facture integer NOT NULL,
fk_product integer NULL, -- Doit pouvoir etre nul pour ligne detail sans produits
description text,
tva_taux real DEFAULT 19.6, -- Taux tva produit/service (exemple 19.6)
tva_taux real, -- Taux tva produit/service (exemple 19.6)
qty real, -- Quantité (exemple 2)
remise_percent real DEFAULT 0, -- % de la remise ligne (exemple 20%)
remise real DEFAULT 0, -- Montant calculé de la remise % sur PU HT (exemple 20)

View File

@ -25,7 +25,7 @@ create table llx_propaldet
fk_propal integer,
fk_product integer,
description text,
tva_tx real DEFAULT 19.6, -- taux tva
tva_tx real, -- taux tva
qty real, -- quantité
remise_percent real DEFAULT 0, -- pourcentage de remise
remise real DEFAULT 0, -- montant de la remise