Fix date_start and date_end not saved on supplier invoice

This commit is contained in:
Laurent Destailleur 2018-08-29 17:03:18 +02:00
parent ee204e2e64
commit 98356c6ed0
3 changed files with 70 additions and 56 deletions

View File

@ -3760,7 +3760,7 @@ abstract class CommonObject
$num = count($this->lines); $num = count($this->lines);
//Line extrafield // Line extrafield
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafieldsline = new ExtraFields($this->db); $extrafieldsline = new ExtraFields($this->db);
$extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line);
@ -3769,6 +3769,7 @@ abstract class CommonObject
$reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if (empty($reshook)) if (empty($reshook))
{ {
// Title line
print "<thead>\n"; print "<thead>\n";
print '<tr class="liste_titre nodrag nodrop">'; print '<tr class="liste_titre nodrag nodrop">';
@ -3860,7 +3861,6 @@ abstract class CommonObject
//Line extrafield //Line extrafield
$line->fetch_optionals(); $line->fetch_optionals();
//if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line)))
if (is_object($hookmanager)) // Old code is commented on preceding line. if (is_object($hookmanager)) // Old code is commented on preceding line.
{ {

View File

@ -675,7 +675,9 @@ class FactureFournisseur extends CommonInvoice
*/ */
function fetch_lines() function fetch_lines()
{ {
$sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.vat_src_code, f.tva_tx'; $this->lines = array();
$sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.date_start, f.date_end, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.vat_src_code, f.tva_tx';
$sql.= ', f.localtax1_tx, f.localtax2_tx, f.localtax1_type, f.localtax2_type, f.total_localtax1, f.total_localtax2, f.fk_facture_fourn '; $sql.= ', f.localtax1_tx, f.localtax2_tx, f.localtax1_type, f.localtax2_type, f.total_localtax1, f.total_localtax2, f.fk_facture_fourn ';
$sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit'; $sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit';
$sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc'; $sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc';
@ -685,7 +687,6 @@ class FactureFournisseur extends CommonInvoice
$sql.= ' WHERE fk_facture_fourn='.$this->id; $sql.= ' WHERE fk_facture_fourn='.$this->id;
$sql.= ' ORDER BY f.rang, f.rowid'; $sql.= ' ORDER BY f.rang, f.rowid';
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
$resql_rows = $this->db->query($sql); $resql_rows = $this->db->query($sql);
if ($resql_rows) if ($resql_rows)
@ -703,6 +704,9 @@ class FactureFournisseur extends CommonInvoice
$line->id = $obj->rowid; $line->id = $obj->rowid;
$line->rowid = $obj->rowid; $line->rowid = $obj->rowid;
$line->description = $obj->description; $line->description = $obj->description;
$line->date_start = $obj->date_start;
$line->date_end = $obj->date_end;
$line->product_ref = $obj->product_ref; $line->product_ref = $obj->product_ref;
$line->ref = $obj->product_ref; $line->ref = $obj->product_ref;
$line->ref_supplier = $obj->ref_supplier; $line->ref_supplier = $obj->ref_supplier;
@ -1736,7 +1740,7 @@ class FactureFournisseur extends CommonInvoice
public function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit = null, $pu_ht_devise=0, $ref_supplier='') public function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit = null, $pu_ht_devise=0, $ref_supplier='')
{ {
global $mysoc; global $mysoc;
dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent,$fk_unit,$pu_ht_devise,$ref_supplier", LOG_DEBUG); dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent,$notrigger,$date_start,$date_end,$fk_unit,$pu_ht_devise,$ref_supplier", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
$pu = price2num($pu); $pu = price2num($pu);
@ -1816,6 +1820,9 @@ class FactureFournisseur extends CommonInvoice
$line->remise_percent = $remise_percent; $line->remise_percent = $remise_percent;
$line->ref_supplier = $ref_supplier; $line->ref_supplier = $ref_supplier;
$line->date_start = $date_start;
$line->date_end = $date_end;
$line->vat_src_code=$vat_src_code; $line->vat_src_code=$vat_src_code;
$line->tva_tx = $vatrate; $line->tva_tx = $vatrate;
$line->localtax1_tx = $txlocaltax1; $line->localtax1_tx = $txlocaltax1;
@ -2656,6 +2663,9 @@ class SupplierInvoiceLine extends CommonObjectLine
*/ */
public $description; public $description;
public $date_start;
public $date_end;
public $skip_update_total; // Skip update price total for special lines public $skip_update_total; // Skip update price total for special lines
/** /**
@ -2713,7 +2723,7 @@ class SupplierInvoiceLine extends CommonObjectLine
*/ */
public function fetch($rowid) public function fetch($rowid)
{ {
$sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx'; $sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.date_start, f.date_end, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx';
$sql.= ', f.localtax1_type, f.localtax2_type, f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 '; $sql.= ', f.localtax1_type, f.localtax2_type, f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 ';
$sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_facture_fourn, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit'; $sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_facture_fourn, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit';
$sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc'; $sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc';
@ -2740,6 +2750,8 @@ class SupplierInvoiceLine extends CommonObjectLine
$this->rowid = $obj->rowid; $this->rowid = $obj->rowid;
$this->fk_facture_fourn = $obj->fk_facture_fourn; $this->fk_facture_fourn = $obj->fk_facture_fourn;
$this->description = $obj->description; $this->description = $obj->description;
$this->date_start = $obj->date_start;
$this->date_end = $obj->date_end;
$this->product_ref = $obj->product_ref; $this->product_ref = $obj->product_ref;
$this->ref_supplier = $obj->ref_supplier; $this->ref_supplier = $obj->ref_supplier;
$this->libelle = $obj->label; $this->libelle = $obj->label;
@ -2871,6 +2883,8 @@ class SupplierInvoiceLine extends CommonObjectLine
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det SET";
$sql.= " description ='".$this->db->escape($this->description)."'"; $sql.= " description ='".$this->db->escape($this->description)."'";
$sql.= ", ref ='".$this->db->escape($this->ref_supplier ? $this->ref_supplier : $this->ref)."'"; $sql.= ", ref ='".$this->db->escape($this->ref_supplier ? $this->ref_supplier : $this->ref)."'";
$sql.= ", date_start = ".($this->date_start != '' ? "'".$this->db->idate($this->date_start)."'" : "null");
$sql.= ", date_end = ".($this->date_end != '' ? "'".$this->db->idate($this->date_end)."'" : "null");
$sql.= ", pu_ht = ".price2num($this->pu_ht); $sql.= ", pu_ht = ".price2num($this->pu_ht);
$sql.= ", pu_ttc = ".price2num($this->pu_ttc); $sql.= ", pu_ttc = ".price2num($this->pu_ttc);
$sql.= ", qty = ".price2num($this->qty); $sql.= ", qty = ".price2num($this->qty);
@ -3045,12 +3059,11 @@ class SupplierInvoiceLine extends CommonObjectLine
$sql.= ", ".price2num($this->multicurrency_total_ttc); $sql.= ", ".price2num($this->multicurrency_total_ttc);
$sql.= ')'; $sql.= ')';
dol_syslog(get_class($this)."::insert", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
$this->rowid=$this->id; $this->rowid=$this->id; // backward compatibility
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
{ {

View File

@ -1097,6 +1097,7 @@ if (empty($reshook))
$product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):''); $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
$date_start=dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_start=dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
$date_end=dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); $date_end=dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
$prod_entry_mode = GETPOST('prod_entry_mode'); $prod_entry_mode = GETPOST('prod_entry_mode');
if ($prod_entry_mode == 'free') if ($prod_entry_mode == 'free')
{ {