Fix PHPunit

This commit is contained in:
Laurent Destailleur 2017-08-27 13:38:42 +02:00
parent 64bbf35812
commit 6c93c6f6cc

View File

@ -43,7 +43,7 @@ class FactureRec extends CommonInvoice
public $table_element_line='facturedet_rec'; public $table_element_line='facturedet_rec';
public $fk_element='fk_facture'; public $fk_element='fk_facture';
public $picto='bill'; public $picto='bill';
var $entity; var $entity;
var $number; var $number;
var $date; var $date;
@ -58,7 +58,7 @@ class FactureRec extends CommonInvoice
var $date_when; var $date_when;
var $nb_gen_done; var $nb_gen_done;
var $nb_gen_max; var $nb_gen_max;
var $rang; var $rang;
var $special_code; var $special_code;
@ -91,20 +91,20 @@ class FactureRec extends CommonInvoice
// Clean parameters // Clean parameters
$this->titre=trim($this->titre); $this->titre=trim($this->titre);
$this->usenewprice=empty($this->usenewprice)?0:$this->usenewprice; $this->usenewprice=empty($this->usenewprice)?0:$this->usenewprice;
// No frequency defined then no next date to execution // No frequency defined then no next date to execution
if (empty($this->frequency)) if (empty($this->frequency))
{ {
$this->frequency=0; $this->frequency=0;
$this->date_when=NULL; $this->date_when=NULL;
} }
$this->frequency=abs($this->frequency); $this->frequency=abs($this->frequency);
$this->nb_gen_done=0; $this->nb_gen_done=0;
$this->nb_gen_max=empty($this->nb_gen_max)?0:$this->nb_gen_max; $this->nb_gen_max=empty($this->nb_gen_max)?0:$this->nb_gen_max;
$this->auto_validate=empty($this->auto_validate)?0:$this->auto_validate; $this->auto_validate=empty($this->auto_validate)?0:$this->auto_validate;
$this->db->begin(); $this->db->begin();
// Charge facture modele // Charge facture modele
@ -197,7 +197,7 @@ class FactureRec extends CommonInvoice
$error++; $error++;
} }
} }
// Add object linked // Add object linked
if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects))
{ {
@ -210,7 +210,7 @@ class FactureRec extends CommonInvoice
$error++; $error++;
} }
} }
} }
if ($error) if ($error)
{ {
@ -268,7 +268,7 @@ class FactureRec extends CommonInvoice
if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'"; if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'";
if ($ref_int) $sql.= " AND f.ref_int='".$this->db->escape($ref_int)."'"; if ($ref_int) $sql.= " AND f.ref_int='".$this->db->escape($ref_int)."'";
*/ */
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
@ -326,14 +326,14 @@ class FactureRec extends CommonInvoice
if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1;
// Retreive all extrafield for thirdparty // Retreive all extrafield for thirdparty
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
$extrafields=new ExtraFields($this->db); $extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels); $this->fetch_optionals($this->id,$extralabels);
/* /*
* Lines * Lines
*/ */
@ -369,8 +369,8 @@ class FactureRec extends CommonInvoice
{ {
return $this->fetch_lines(); return $this->fetch_lines();
} }
/** /**
* Recupere les lignes de factures predefinies dans this->lines * Recupere les lignes de factures predefinies dans this->lines
* *
@ -394,7 +394,7 @@ class FactureRec extends CommonInvoice
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
$sql.= ' WHERE l.fk_facture = '.$this->id; $sql.= ' WHERE l.fk_facture = '.$this->id;
$sql.= ' ORDER BY l.rang'; $sql.= ' ORDER BY l.rang';
dol_syslog('FactureRec::fetch_lines', LOG_DEBUG); dol_syslog('FactureRec::fetch_lines', LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
@ -439,20 +439,20 @@ class FactureRec extends CommonInvoice
$line->special_code = $objp->special_code; $line->special_code = $objp->special_code;
$line->fk_unit = $objp->fk_unit; $line->fk_unit = $objp->fk_unit;
$line->fk_contract_line = $objp->fk_contract_line; $line->fk_contract_line = $objp->fk_contract_line;
// Ne plus utiliser // Ne plus utiliser
$line->price = $objp->price; $line->price = $objp->price;
$line->remise = $objp->remise; $line->remise = $objp->remise;
// Retreive all extrafield for thirdparty // Retreive all extrafield for thirdparty
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
$extrafieldsline=new ExtraFields($line->db); $extrafieldsline=new ExtraFields($line->db);
$extrafieldsline=$extrafieldsline->fetch_name_optionals_label($line->table_element,true); $extrafieldsline=$extrafieldsline->fetch_name_optionals_label($line->table_element,true);
$extralabelsline = $line->fetch_optionals($line->id,$extrafieldsline); $extralabelsline = $line->fetch_optionals($line->id,$extrafieldsline);
$this->lines[$i] = $line; $this->lines[$i] = $line;
$i++; $i++;
@ -480,12 +480,12 @@ class FactureRec extends CommonInvoice
function delete($user, $notrigger=0, $idwarehouse=-1) function delete($user, $notrigger=0, $idwarehouse=-1)
{ {
$rowid=$this->id; $rowid=$this->id;
dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG); dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
$error=0; $error=0;
$this->db->begin(); $this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".$rowid; $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".$rowid;
dol_syslog($sql); dol_syslog($sql);
if ($this->db->query($sql)) if ($this->db->query($sql))
@ -498,7 +498,7 @@ class FactureRec extends CommonInvoice
$res = $this->deleteObjectLinked(); $res = $this->deleteObjectLinked();
if ($res < 0) $error=-3; if ($res < 0) $error=-3;
} }
else else
{ {
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
$error=-1; $error=-1;
@ -509,7 +509,7 @@ class FactureRec extends CommonInvoice
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
$error=-2; $error=-2;
} }
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();
@ -548,7 +548,7 @@ class FactureRec extends CommonInvoice
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null) function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null)
{ {
global $mysoc; global $mysoc;
$facid=$this->id; $facid=$this->id;
dol_syslog(get_class($this)."::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,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit", LOG_DEBUG); dol_syslog(get_class($this)."::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,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit", LOG_DEBUG);
@ -601,7 +601,7 @@ class FactureRec extends CommonInvoice
$total_ttc = $tabprice[2]; $total_ttc = $tabprice[2];
$total_localtax1=$tabprice[9]; $total_localtax1=$tabprice[9];
$total_localtax2=$tabprice[10]; $total_localtax2=$tabprice[10];
$product_type=$type; $product_type=$type;
if ($fk_product) if ($fk_product)
{ {
@ -703,12 +703,12 @@ class FactureRec extends CommonInvoice
function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null) function updateline($rowid, $desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit=null)
{ {
global $mysoc; global $mysoc;
$facid=$this->id; $facid=$this->id;
dol_syslog(get_class($this)."::updateline facid=".$facid." rowid=$rowid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit", LOG_DEBUG); dol_syslog(get_class($this)."::updateline facid=".$facid." rowid=$rowid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,txlocaltax1=$txlocaltax1,txlocaltax2=$txlocaltax2,fk_product=$fk_product,remise_percent=$remise_percent,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Check parameters // Check parameters
if ($type < 0) return -1; if ($type < 0) return -1;
@ -733,7 +733,7 @@ class FactureRec extends CommonInvoice
$txtva=price2num($txtva); $txtva=price2num($txtva);
$txlocaltax1 = price2num($txlocaltax1); $txlocaltax1 = price2num($txlocaltax1);
$txlocaltax2 = price2num($txlocaltax2); $txlocaltax2 = price2num($txlocaltax2);
if ($price_base_type=='HT') if ($price_base_type=='HT')
{ {
$pu=$pu_ht; $pu=$pu_ht;
@ -742,7 +742,7 @@ class FactureRec extends CommonInvoice
{ {
$pu=$pu_ttc; $pu=$pu_ttc;
} }
// Calcul du total TTC et de la TVA pour la ligne a partir de // Calcul du total TTC et de la TVA pour la ligne a partir de
// qty, pu, remise_percent et txtva // qty, pu, remise_percent et txtva
// TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
@ -754,7 +754,7 @@ class FactureRec extends CommonInvoice
$total_ttc = $tabprice[2]; $total_ttc = $tabprice[2];
$total_localtax1=$tabprice[9]; $total_localtax1=$tabprice[9];
$total_localtax2=$tabprice[10]; $total_localtax2=$tabprice[10];
$product_type=$type; $product_type=$type;
if ($fk_product) if ($fk_product)
{ {
@ -762,7 +762,7 @@ class FactureRec extends CommonInvoice
$result=$product->fetch($fk_product); $result=$product->fetch($fk_product);
$product_type=$product->type; $product_type=$product->type;
} }
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET "; $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET ";
$sql.= "fk_facture = '".$facid."'"; $sql.= "fk_facture = '".$facid."'";
$sql.= ", label=".(! empty($label)?"'".$this->db->escape($label)."'":"null"); $sql.= ", label=".(! empty($label)?"'".$this->db->escape($label)."'":"null");
@ -802,12 +802,12 @@ class FactureRec extends CommonInvoice
return -1; return -1;
} }
} }
} }
/** /**
* Return the next date of * Return the next date of
* *
* @return timestamp false if KO, timestamp if OK * @return timestamp false if KO, timestamp if OK
*/ */
function getNextDate() function getNextDate()
@ -815,27 +815,27 @@ class FactureRec extends CommonInvoice
if (empty($this->date_when)) return false; if (empty($this->date_when)) return false;
return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency); return dol_time_plus_duree($this->date_when, $this->frequency, $this->unit_frequency);
} }
/** /**
* Create all recurrents invoices (for all entities if multicompany is used). * Create all recurrents invoices (for all entities if multicompany is used).
* A result may also be provided into this->output. * A result may also be provided into this->output.
* *
* WARNING: This method change context $conf->entity to be in correct context for each recurring invoice found. * WARNING: This method change context $conf->entity to be in correct context for each recurring invoice found.
* *
* @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK) * @return int 0 if OK, < 0 if KO (this function is used also by cron so only 0 is OK)
*/ */
function createRecurringInvoices() function createRecurringInvoices()
{ {
global $conf, $langs, $db, $user; global $conf, $langs, $db, $user;
$langs->load("bills"); $langs->load("bills");
$nb_create=0; $nb_create=0;
$now = dol_now(); $now = dol_now();
$tmparray=dol_getdate($now); $tmparray=dol_getdate($now);
$today = dol_mktime(23,59,59,$tmparray['mon'],$tmparray['mday'],$tmparray['year']); // Today is last second of current day $today = dol_mktime(23,59,59,$tmparray['mon'],$tmparray['mday'],$tmparray['year']); // Today is last second of current day
dol_syslog("createRecurringInvoices"); dol_syslog("createRecurringInvoices");
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec'; $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec';
$sql.= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency $sql.= ' WHERE frequency > 0'; // A recurring invoice is an invoice with a frequency
@ -843,30 +843,30 @@ class FactureRec extends CommonInvoice
$sql.= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)'; $sql.= ' AND (nb_gen_done < nb_gen_max OR nb_gen_max = 0)';
$sql.= $db->order('entity', 'ASC'); $sql.= $db->order('entity', 'ASC');
//print $sql;exit; //print $sql;exit;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
$i=0; $i=0;
$num = $db->num_rows($resql); $num = $db->num_rows($resql);
if ($num) $this->output.=$langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n"; if ($num) $this->output.=$langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
else $this->output.=$langs->trans("NoQualifiedRecurringInvoiceTemplateFound"); else $this->output.=$langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
$saventity = $conf->entity; $saventity = $conf->entity;
while ($i < $num) // Loop on each template invoice while ($i < $num) // Loop on each template invoice
{ {
$line = $db->fetch_object($resql); $line = $db->fetch_object($resql);
$db->begin(); $db->begin();
$facturerec = new FactureRec($db); $facturerec = new FactureRec($db);
$facturerec->fetch($line->rowid); $facturerec->fetch($line->rowid);
// Set entity context // Set entity context
$conf->entity = $facturerec->entity; $conf->entity = $facturerec->entity;
dol_syslog("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref.", entity=".$facturerec->entity); dol_syslog("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref.", entity=".$facturerec->entity);
$error=0; $error=0;
@ -874,12 +874,12 @@ class FactureRec extends CommonInvoice
$facture = new Facture($db); $facture = new Facture($db);
$facture->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice $facture->fac_rec = $facturerec->id; // We will create $facture from this recurring invoice
$facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice $facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice
$facture->type = self::TYPE_STANDARD; $facture->type = self::TYPE_STANDARD;
$facture->brouillon = 1; $facture->brouillon = 1;
$facture->date = $facturerec->date_when; // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later. $facture->date = $facturerec->date_when; // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later.
$facture->socid = $facturerec->socid; $facture->socid = $facturerec->socid;
$invoiceidgenerated = $facture->create($user); $invoiceidgenerated = $facture->create($user);
if ($invoiceidgenerated <= 0) if ($invoiceidgenerated <= 0)
{ {
@ -912,16 +912,16 @@ class FactureRec extends CommonInvoice
$i++; $i++;
} }
$conf->entity = $saventity; // Restore entity context $conf->entity = $saventity; // Restore entity context
} }
else dol_print_error($db); else dol_print_error($db);
$this->output=trim($this->output); $this->output=trim($this->output);
return $error?$error:0; return $error?$error:0;
} }
/** /**
* Return clicable name (with picto eventually) * Return clicable name (with picto eventually)
* *
@ -938,13 +938,13 @@ class FactureRec extends CommonInvoice
$result=''; $result='';
$label=$langs->trans("ShowInvoice").': '.$this->ref; $label=$langs->trans("ShowInvoice").': '.$this->ref;
$url = DOL_URL_ROOT.'/compta/facture/fiche-rec.php?facid='.$this->id; $url = DOL_URL_ROOT.'/compta/facture/fiche-rec.php?facid='.$this->id;
if ($short) return $url; if ($short) return $url;
$picto='bill'; $picto='bill';
$link = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; $link = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend='</a>'; $linkend='</a>';
@ -976,7 +976,7 @@ class FactureRec extends CommonInvoice
// Load array of products prodids // Load array of products prodids
$num_prods = 0; $num_prods = 0;
$prodids = array(); $prodids = array();
$sql = "SELECT rowid"; $sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."product"; $sql.= " FROM ".MAIN_DB_PREFIX."product";
$sql.= " WHERE entity IN (".getEntity('product').")"; $sql.= " WHERE entity IN (".getEntity('product').")";
@ -1089,7 +1089,7 @@ class FactureRec extends CommonInvoice
$this->lines[$xnbp]=$line; $this->lines[$xnbp]=$line;
$xnbp++; $xnbp++;
} }
$this->usenewprice = 1; $this->usenewprice = 1;
} }
@ -1109,7 +1109,7 @@ class FactureRec extends CommonInvoice
return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
} }
/** /**
* Update frequency and unit * Update frequency and unit
* *
@ -1133,12 +1133,12 @@ class FactureRec extends CommonInvoice
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= ' SET frequency = '.($frequency?$this->db->escape($frequency):'null'); $sql.= ' SET frequency = '.($frequency?$this->db->escape($frequency):'null');
if (!empty($unit)) if (!empty($unit))
{ {
$sql.= ', unit_frequency = \''.$this->db->escape($unit).'\''; $sql.= ', unit_frequency = \''.$this->db->escape($unit).'\'';
} }
$sql.= ' WHERE rowid = '.$this->id; $sql.= ' WHERE rowid = '.$this->id;
dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG); dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
if ($this->db->query($sql)) if ($this->db->query($sql))
{ {
@ -1152,7 +1152,7 @@ class FactureRec extends CommonInvoice
return -1; return -1;
} }
} }
/** /**
* Update the next date of execution * Update the next date of execution
* *
@ -1185,7 +1185,7 @@ class FactureRec extends CommonInvoice
return -1; return -1;
} }
} }
/** /**
* Update the maximum period * Update the maximum period
* *
@ -1199,9 +1199,9 @@ class FactureRec extends CommonInvoice
dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined",LOG_ERR); dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined",LOG_ERR);
return -1; return -1;
} }
if (empty($nb)) $nb=0; if (empty($nb)) $nb=0;
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= ' SET nb_gen_max = '.$nb; $sql.= ' SET nb_gen_max = '.$nb;
$sql.= ' WHERE rowid = '.$this->id; $sql.= ' WHERE rowid = '.$this->id;
@ -1218,7 +1218,7 @@ class FactureRec extends CommonInvoice
return -1; return -1;
} }
} }
/** /**
* Update the auto validate invoice * Update the auto validate invoice
* *
@ -1232,7 +1232,7 @@ class FactureRec extends CommonInvoice
dol_syslog(get_class($this)."::setAutoValidate was called on objet with property table_element not defined",LOG_ERR); dol_syslog(get_class($this)."::setAutoValidate was called on objet with property table_element not defined",LOG_ERR);
return -1; return -1;
} }
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= ' SET auto_validate = '.$validate; $sql.= ' SET auto_validate = '.$validate;
$sql.= ' WHERE rowid = '.$this->id; $sql.= ' WHERE rowid = '.$this->id;
@ -1259,10 +1259,10 @@ class FactureRec extends CommonInvoice
*/ */
class FactureLigneRec extends CommonInvoiceLine class FactureLigneRec extends CommonInvoiceLine
{ {
public $element='facturedetrec'; public $element='facturedetrec';
public $table_element='facturedet_rec'; public $table_element='facturedet_rec';
/** /**
* Delete line in database * Delete line in database
* *
@ -1271,12 +1271,12 @@ class FactureLigneRec extends CommonInvoiceLine
function delete() function delete()
{ {
global $conf,$langs,$user; global $conf,$langs,$user;
$error=0; $error=0;
$this->db->begin(); $this->db->begin();
$sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element." WHERE rowid = ".($this->rowid > 0 ? $this->rowid : $this->id); $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element." WHERE rowid = ".($this->rowid > 0 ? $this->rowid : $this->id);
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
if ($this->db->query($sql) ) if ($this->db->query($sql) )
@ -1289,7 +1289,7 @@ class FactureLigneRec extends CommonInvoiceLine
return -1; return -1;
} }
// End call triggers // End call triggers
$this->db->commit(); $this->db->commit();
return 1; return 1;
} }
@ -1300,17 +1300,17 @@ class FactureLigneRec extends CommonInvoiceLine
return -1; return -1;
} }
} }
/** /**
* Recupere les lignes de factures predefinies dans this->lines * Recupere les lignes de factures predefinies dans this->lines
* @param int $rowid * @param int $rowid
* @return int 1 if OK, < 0 if KO * @return int 1 if OK, < 0 if KO
*/ */
function fetch($rowid) function fetch($rowid)
{ {
$sql = 'SELECT l.rowid, l.fk_facture ,l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, '; $sql = 'SELECT l.rowid, l.fk_facture ,l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, ';
$sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,'; $sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,';
$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,'; $sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,';
@ -1321,14 +1321,14 @@ class FactureLigneRec extends CommonInvoiceLine
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
$sql.= ' WHERE l.rowid = '.$rowid; $sql.= ' WHERE l.rowid = '.$rowid;
$sql.= ' ORDER BY l.rang'; $sql.= ' ORDER BY l.rang';
dol_syslog('FactureRec::fetch_lines', LOG_DEBUG); dol_syslog('FactureRec::fetch_lines', LOG_DEBUG);
$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->id = $objp->rowid; $this->id = $objp->rowid;
$this->label = $objp->custom_label; // Label line $this->label = $objp->custom_label; // Label line
$this->desc = $objp->description; // Description line $this->desc = $objp->description; // Description line
@ -1363,7 +1363,7 @@ class FactureLigneRec extends CommonInvoiceLine
$this->fk_unit = $objp->fk_unit; $this->fk_unit = $objp->fk_unit;
$this->fk_contract_line = $objp->fk_contract_line; $this->fk_contract_line = $objp->fk_contract_line;
$this->db->free($result); $this->db->free($result);
return 1; return 1;
} }
@ -1373,8 +1373,8 @@ class FactureLigneRec extends CommonInvoiceLine
return -3; return -3;
} }
} }
/** /**
* Update a line to invoice_rec * Update a line to invoice_rec
* @return int <0 if KO, Id of line if OK * @return int <0 if KO, Id of line if OK
@ -1382,16 +1382,16 @@ class FactureLigneRec extends CommonInvoiceLine
function update() function update()
{ {
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
if ($fk_product) if ($fk_product)
{ {
$product=new Product($this->db); $product=new Product($this->db);
$result=$product->fetch($fk_product); $result=$product->fetch($fk_product);
$product_type=$product->type; $product_type=$product->type;
} }
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET "; $sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET ";
$sql.= " fk_facture = '".$this->fk_facture."'"; $sql.= " fk_facture = ".$this->fk_facture;
$sql.= ", label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null"); $sql.= ", label=".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null");
$sql.= ", description='".$this->db->escape($this->desc)."'"; $sql.= ", description='".$this->db->escape($this->desc)."'";
$sql.= ", price=".price2num($this->price); $sql.= ", price=".price2num($this->price);
@ -1415,9 +1415,9 @@ class FactureLigneRec extends CommonInvoiceLine
$sql.= ", special_code=".$this->special_code; $sql.= ", special_code=".$this->special_code;
$sql.= ", fk_unit=".($this->fk_unit ?"'".$this->db->escape($this->fk_unit )."'":"null"); $sql.= ", fk_unit=".($this->fk_unit ?"'".$this->db->escape($this->fk_unit )."'":"null");
$sql.= ", fk_contract_line=".($this->fk_contract_line?$this->fk_contract_line:"null"); $sql.= ", fk_contract_line=".($this->fk_contract_line?$this->fk_contract_line:"null");
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::updateline", LOG_DEBUG); dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -1430,7 +1430,7 @@ class FactureLigneRec extends CommonInvoiceLine
$error++; $error++;
} }
} }
if (! $notrigger) if (! $notrigger)
{ {
// Call trigger // Call trigger
@ -1451,9 +1451,9 @@ class FactureLigneRec extends CommonInvoiceLine
$this->db->rollback(); $this->db->rollback();
return -2; return -2;
} }
} }
} }