Fix: hook is already instantiate

Fix: add fk_parent_line in customer bill
This commit is contained in:
Regis Houssin 2011-04-10 07:52:30 +00:00
parent 84a5469693
commit b163b0c73c
3 changed files with 73 additions and 46 deletions

View File

@ -242,12 +242,6 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer)
$lines = $srcobject->lines; $lines = $srcobject->lines;
if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks('objectcard');
}
$fk_parent_line=0; $fk_parent_line=0;
$num=sizeof($lines); $num=sizeof($lines);

View File

@ -700,7 +700,10 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
$lines = $srcobject->lines; $lines = $srcobject->lines;
if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
for ($i = 0 ; $i < sizeof($lines) ; $i++) $fk_parent_line=0;
$num=sizeof($lines);
for ($i=0;$i<$num;$i++)
{ {
$desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
$product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
@ -714,6 +717,11 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
// Reset fk_parent_line for no child products and special product
if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
$fk_parent_line = 0;
}
$result = $object->addline( $result = $object->addline(
$facid, $facid,
$desc, $desc,
@ -735,7 +743,8 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
$lines[$i]->rang, $lines[$i]->rang,
$lines[$i]->special_code, $lines[$i]->special_code,
$object->origin, $object->origin,
$lines[$i]->rowid $lines[$i]->rowid,
$fk_parent_line
); );
if ($result < 0) if ($result < 0)
@ -743,6 +752,21 @@ if ($_POST['action'] == 'add' && $user->rights->facture->creer)
$error++; $error++;
break; break;
} }
// Defined the new fk_parent_line
if ($result > 0 && $lines[$i]->product_type == 9) {
$fk_parent_line = $result;
}
}
// Hooks
if (! empty($object->hooks))
{
foreach($object->hooks as $module)
{
$res = $module->createfrom($srcobject,$facid,$object->element);
if ($res < 0) $error++;
}
} }
} }
else else

View File

@ -746,7 +746,7 @@ class Facture extends CommonObject
*/ */
function fetch_lines() function fetch_lines()
{ {
$sql = 'SELECT l.rowid, l.fk_product, l.description, l.product_type, l.price, l.qty, l.tva_tx, '; $sql = 'SELECT l.rowid, l.fk_product, l.fk_parent_line, l.description, l.product_type, l.price, l.qty, l.tva_tx, ';
$sql.= ' l.localtax1_tx, l.localtax2_tx, l.remise, l.remise_percent, l.fk_remise_except, l.subprice,'; $sql.= ' l.localtax1_tx, l.localtax2_tx, l.remise, l.remise_percent, l.fk_remise_except, l.subprice,';
$sql.= ' l.rang, l.special_code,'; $sql.= ' l.rang, l.special_code,';
$sql.= ' l.date_start as date_start, l.date_end as date_end,'; $sql.= ' l.date_start as date_start, l.date_end as date_end,';
@ -797,6 +797,7 @@ class Facture extends CommonObject
$line->code_ventilation = $objp->fk_code_ventilation; $line->code_ventilation = $objp->fk_code_ventilation;
$line->rang = $objp->rang; $line->rang = $objp->rang;
$line->special_code = $objp->special_code; $line->special_code = $objp->special_code;
$line->fk_parent_line = $objp->fk_parent_line;
// Ne plus utiliser // Ne plus utiliser
$line->price = $objp->price; $line->price = $objp->price;
@ -1672,7 +1673,7 @@ class Facture extends CommonObject
* par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,produit) * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,produit)
* et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue) * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
*/ */
function addline($facid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $origin='', $origin_id=0) function addline($facid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0)
{ {
dol_syslog("Facture::Addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type", LOG_DEBUG); dol_syslog("Facture::Addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type", LOG_DEBUG);
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
@ -1773,6 +1774,7 @@ class Facture extends CommonObject
$this->line->total_localtax2=($this->type==2?-1:1)*abs($total_localtax2); $this->line->total_localtax2=($this->type==2?-1:1)*abs($total_localtax2);
$this->line->total_ttc= ($this->type==2?-1:1)*abs($total_ttc); $this->line->total_ttc= ($this->type==2?-1:1)*abs($total_ttc);
$this->line->special_code=$special_code; $this->line->special_code=$special_code;
$this->line->fk_parent_line=$fk_parent_line;
$this->line->origin=$origin; $this->line->origin=$origin;
$this->line->origin_id=$origin_id; $this->line->origin_id=$origin_id;
@ -1789,7 +1791,7 @@ class Facture extends CommonObject
if ($result > 0) if ($result > 0)
{ {
$this->db->commit(); $this->db->commit();
return 1; return $this->line->rowid;
} }
else else
{ {
@ -1825,7 +1827,7 @@ class Facture extends CommonObject
* @param type Type of line (0=product, 1=service) * @param type Type of line (0=product, 1=service)
* @return int < 0 if KO, > 0 if OK * @return int < 0 if KO, > 0 if OK
*/ */
function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0,$price_base_type='HT', $info_bits=0, $type=0) function updateline($rowid, $desc, $pu, $qty, $remise_percent=0, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0,$price_base_type='HT', $info_bits=0, $type=0, $fk_parent_line=0)
{ {
include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php');
@ -1890,6 +1892,7 @@ class Facture extends CommonObject
$this->line->total_ttc = ($this->type==2?-1:1)*abs($total_ttc); $this->line->total_ttc = ($this->type==2?-1:1)*abs($total_ttc);
$this->line->info_bits = $info_bits; $this->line->info_bits = $info_bits;
$this->line->product_type = $type; $this->line->product_type = $type;
$this->line->fk_parent_line = $fk_parent_line;
// A ne plus utiliser // A ne plus utiliser
$this->line->price=$price; $this->line->price=$price;
@ -3120,7 +3123,7 @@ class FactureLigne
*/ */
function fetch($rowid) function fetch($rowid)
{ {
$sql = 'SELECT fd.rowid, fd.fk_facture, fd.fk_product, fd.product_type, fd.description, fd.price, fd.qty, fd.tva_tx,'; $sql = 'SELECT fd.rowid, fd.fk_facture, fd.fk_parent_line, fd.fk_product, fd.product_type, fd.description, fd.price, fd.qty, fd.tva_tx,';
$sql.= ' fd.localtax1_tx, fd. localtax2_tx, fd.remise, fd.remise_percent, fd.fk_remise_except, fd.subprice,'; $sql.= ' fd.localtax1_tx, fd. localtax2_tx, fd.remise, fd.remise_percent, fd.fk_remise_except, fd.subprice,';
$sql.= ' fd.date_start as date_start, fd.date_end as date_end,'; $sql.= ' fd.date_start as date_start, fd.date_end as date_end,';
$sql.= ' fd.info_bits, fd.total_ht, fd.total_tva, fd.total_ttc, fd.rang,'; $sql.= ' fd.info_bits, fd.total_ht, fd.total_tva, fd.total_ttc, fd.rang,';
@ -3129,12 +3132,15 @@ class FactureLigne
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as fd'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as fd';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON fd.fk_product = p.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON fd.fk_product = p.rowid';
$sql.= ' WHERE fd.rowid = '.$rowid; $sql.= ' WHERE fd.rowid = '.$rowid;
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$objp = $this->db->fetch_object($result); $objp = $this->db->fetch_object($result);
$this->rowid = $objp->rowid; $this->rowid = $objp->rowid;
$this->fk_facture = $objp->fk_facture; $this->fk_facture = $objp->fk_facture;
$this->fk_parent_line = $objp->fk_parent_line;
$this->desc = $objp->description; $this->desc = $objp->description;
$this->qty = $objp->qty; $this->qty = $objp->qty;
$this->subprice = $objp->subprice; $this->subprice = $objp->subprice;
@ -3201,6 +3207,7 @@ class FactureLigne
if (empty($this->subprice)) $this->subprice=0; if (empty($this->subprice)) $this->subprice=0;
if (empty($this->price)) $this->price=0; if (empty($this->price)) $this->price=0;
if (empty($this->special_code)) $this->special_code=0; if (empty($this->special_code)) $this->special_code=0;
if (empty($this->fk_parent_line)) $this->fk_parent_line=0;
// Check parameters // Check parameters
if ($this->product_type < 0) return -1; if ($this->product_type < 0) return -1;
@ -3209,12 +3216,13 @@ class FactureLigne
// Insertion dans base de la ligne // Insertion dans base de la ligne
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet'; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facturedet';
$sql.= ' (fk_facture, description, qty, tva_tx, localtax1_tx, localtax2_tx,'; $sql.= ' (fk_facture, fk_parent_line, description, qty, tva_tx, localtax1_tx, localtax2_tx,';
$sql.= ' fk_product, product_type, remise_percent, subprice, price, remise, fk_remise_except,'; $sql.= ' fk_product, product_type, remise_percent, subprice, price, remise, fk_remise_except,';
$sql.= ' date_start, date_end, fk_code_ventilation, fk_export_compta, '; $sql.= ' date_start, date_end, fk_code_ventilation, fk_export_compta, ';
$sql.= ' rang, special_code,'; $sql.= ' rang, special_code,';
$sql.= ' info_bits, total_ht, total_tva, total_localtax1, total_localtax2, total_ttc)'; $sql.= ' info_bits, total_ht, total_tva, total_localtax1, total_localtax2, total_ttc)';
$sql.= " VALUES (".$this->fk_facture.","; $sql.= " VALUES (".$this->fk_facture.",";
$sql.= " ".$this->fk_parent_line.",";
$sql.= " '".$this->db->escape($this->desc)."',"; $sql.= " '".$this->db->escape($this->desc)."',";
$sql.= " ".price2num($this->qty).","; $sql.= " ".price2num($this->qty).",";
$sql.= " ".price2num($this->tva_tx).","; $sql.= " ".price2num($this->tva_tx).",";
@ -3365,6 +3373,7 @@ class FactureLigne
$sql.= ",total_localtax1=".price2num($this->total_localtax1).""; $sql.= ",total_localtax1=".price2num($this->total_localtax1)."";
$sql.= ",total_localtax2=".price2num($this->total_localtax2).""; $sql.= ",total_localtax2=".price2num($this->total_localtax2)."";
$sql.= ",total_ttc=".price2num($this->total_ttc).""; $sql.= ",total_ttc=".price2num($this->total_ttc)."";
$sql.= ",fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
$sql.= " WHERE rowid = ".$this->rowid; $sql.= " WHERE rowid = ".$this->rowid;
dol_syslog("FactureLigne::update sql=".$sql); dol_syslog("FactureLigne::update sql=".$sql);