FIX Clean bad parameters when inserting line of template invoice
Conflicts: htdocs/compta/facture/class/facture-rec.class.php
This commit is contained in:
parent
d13c4b7b84
commit
26385fa10d
@ -34,7 +34,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe de gestion des factures recurrentes/Modeles
|
* Class to manage invoice templates
|
||||||
*/
|
*/
|
||||||
class FactureRec extends CommonInvoice
|
class FactureRec extends CommonInvoice
|
||||||
{
|
{
|
||||||
@ -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,10 @@ 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 $frequency;
|
||||||
|
var $unit_frequency;
|
||||||
|
|
||||||
var $rang;
|
var $rang;
|
||||||
var $special_code;
|
var $special_code;
|
||||||
|
|
||||||
@ -91,20 +94,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 +200,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 +213,7 @@ class FactureRec extends CommonInvoice
|
|||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($error)
|
if ($error)
|
||||||
{
|
{
|
||||||
@ -268,7 +271,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)
|
||||||
{
|
{
|
||||||
@ -361,8 +364,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
|
||||||
*
|
*
|
||||||
@ -386,7 +389,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)
|
||||||
@ -431,7 +434,7 @@ 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;
|
||||||
@ -463,12 +466,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))
|
||||||
@ -481,7 +484,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;
|
||||||
@ -492,7 +495,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();
|
||||||
@ -531,7 +534,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);
|
||||||
@ -557,11 +560,14 @@ class FactureRec extends CommonInvoice
|
|||||||
if (empty($remise_percent)) $remise_percent=0;
|
if (empty($remise_percent)) $remise_percent=0;
|
||||||
$qty=price2num($qty);
|
$qty=price2num($qty);
|
||||||
if (! $info_bits) $info_bits=0;
|
if (! $info_bits) $info_bits=0;
|
||||||
$pu_ht=price2num($pu_ht);
|
$pu_ht = price2num($pu_ht);
|
||||||
$pu_ttc=price2num($pu_ttc);
|
$pu_ttc = price2num($pu_ttc);
|
||||||
$txtva=price2num($txtva);
|
$txtva = price2num($txtva);
|
||||||
$txlocaltax1 = price2num($txlocaltax1);
|
$txlocaltax1 = price2num($txlocaltax1);
|
||||||
$txlocaltax2 = price2num($txlocaltax2);
|
$txlocaltax2 = price2num($txlocaltax2);
|
||||||
|
if (empty($txtva)) $txtva=0;
|
||||||
|
if (empty($txlocaltax1)) $txlocaltax1=0;
|
||||||
|
if (empty($txlocaltax2)) $txlocaltax2=0;
|
||||||
|
|
||||||
if ($price_base_type=='HT')
|
if ($price_base_type=='HT')
|
||||||
{
|
{
|
||||||
@ -584,7 +590,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)
|
||||||
{
|
{
|
||||||
@ -685,12 +691,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;
|
||||||
|
|
||||||
@ -715,7 +721,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;
|
||||||
@ -724,7 +730,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
|
||||||
@ -736,7 +742,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)
|
||||||
{
|
{
|
||||||
@ -744,7 +750,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");
|
||||||
@ -784,12 +790,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()
|
||||||
@ -797,27 +803,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
|
||||||
@ -825,30 +831,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;
|
||||||
@ -856,12 +862,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)
|
||||||
{
|
{
|
||||||
@ -894,16 +900,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)
|
||||||
*
|
*
|
||||||
@ -920,13 +926,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>';
|
||||||
|
|
||||||
@ -958,7 +964,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').")";
|
||||||
@ -1071,7 +1077,7 @@ class FactureRec extends CommonInvoice
|
|||||||
$this->lines[$xnbp]=$line;
|
$this->lines[$xnbp]=$line;
|
||||||
$xnbp++;
|
$xnbp++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->usenewprice = 1;
|
$this->usenewprice = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1091,7 +1097,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
|
||||||
*
|
*
|
||||||
@ -1115,12 +1121,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))
|
||||||
{
|
{
|
||||||
@ -1134,7 +1140,7 @@ class FactureRec extends CommonInvoice
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the next date of execution
|
* Update the next date of execution
|
||||||
*
|
*
|
||||||
@ -1167,7 +1173,7 @@ class FactureRec extends CommonInvoice
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the maximum period
|
* Update the maximum period
|
||||||
*
|
*
|
||||||
@ -1181,9 +1187,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;
|
||||||
@ -1200,7 +1206,7 @@ class FactureRec extends CommonInvoice
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the auto validate invoice
|
* Update the auto validate invoice
|
||||||
*
|
*
|
||||||
@ -1214,7 +1220,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;
|
||||||
@ -1241,7 +1247,7 @@ class FactureRec extends CommonInvoice
|
|||||||
*/
|
*/
|
||||||
class FactureLigneRec extends CommonInvoiceLine
|
class FactureLigneRec extends CommonInvoiceLine
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete line in database
|
* Delete line in database
|
||||||
*
|
*
|
||||||
@ -1250,11 +1256,11 @@ 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();
|
||||||
|
|
||||||
// Call trigger
|
// Call trigger
|
||||||
/*$result=$this->call_trigger('LINEBILLREC_DELETE',$user);
|
/*$result=$this->call_trigger('LINEBILLREC_DELETE',$user);
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
@ -1263,8 +1269,8 @@ class FactureLigneRec extends CommonInvoiceLine
|
|||||||
return -1;
|
return -1;
|
||||||
}*/
|
}*/
|
||||||
// End call triggers
|
// End call triggers
|
||||||
|
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE rowid = ".($this->rowid > 0 ? $this->rowid : $this->id);
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec 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) )
|
||||||
@ -1279,5 +1285,5 @@ class FactureLigneRec extends CommonInvoiceLine
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user