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

@ -46,58 +46,58 @@ abstract class CommonObject
* @var DoliDb Database handler (result of a new DoliDB)
*/
public $db;
/**
* @var int The object identifier
*/
public $id;
/**
* @var string Error string
* @see errors
*/
public $error;
/**
* @var string[] Array of error strings
*/
public $errors=array();
/**
* @var string ID to identify managed object
*/
public $element;
/**
* @var string Name of table without prefix where object is stored
*/
public $table_element;
/**
* @var
*/
public $table_element_line;
/**
* @var string Key value used to track if data is coming from import wizard
*/
public $import_key;
/**
* @var mixed Contains data to manage extrafields
*/
public $array_options=array();
/**
* @var int[][] Array of linked objects ids. Loaded by ->fetchObjectLinked
*/
public $linkedObjectsIds;
/**
* @var mixed Array of linked objects. Loaded by ->fetchObjectLinked
*/
public $linkedObjects;
/**
* @var Object To store a cloned copy of object before to edit it and keep track of old properties
*/
@ -127,13 +127,13 @@ abstract class CommonObject
* @see fetch_projet()
*/
public $project;
/**
* @var int The related project ID
* @see setProject(), project
*/
public $fk_project;
/**
* @deprecated
* @see project
@ -145,7 +145,7 @@ abstract class CommonObject
* @see fetch_contact()
*/
public $contact;
/**
* @var int The related contact ID
* @see fetch_contact()
@ -179,17 +179,17 @@ abstract class CommonObject
* @var string The object's reference
*/
public $ref;
/**
* @var string The object's previous reference
*/
public $ref_previous;
/**
* @var string The object's next reference
*/
public $ref_next;
/**
* @var string An external reference for the object
*/
@ -206,43 +206,43 @@ abstract class CommonObject
* @see getFullAddress()
*/
public $country;
/**
* @var int
* @see getFullAddress(), country
*/
public $country_id;
/**
* @var string
* @see getFullAddress(), isInEEC(), country
*/
public $country_code;
/**
* @var string
* @see getFullAddress()
*/
public $state;
/**
* @var int
* @see getFullAddress(), state
*/
public $state_id;
/**
* @var string
* @see getFullAddress(), state
*/
public $state_code;
/**
* @var string
* @see getFullAddress(), region
*/
public $region;
/**
* @var string
* @see getFullAddress(), region
@ -254,19 +254,19 @@ abstract class CommonObject
* @see fetch_barcode()
*/
public $barcode_type;
/**
* @var string
* @see fetch_barcode(), barcode_type
*/
public $barcode_type_code;
/**
* @var string
* @see fetch_barcode(), barcode_type
*/
public $barcode_type_label;
/**
* @var string
* @see fetch_barcode(), barcode_type
@ -284,7 +284,7 @@ abstract class CommonObject
* @see setPaymentTerms()
*/
public $cond_reglement_id;
/**
* @var int Payment terms ID
* @deprecated Kept for compatibility
@ -322,13 +322,13 @@ abstract class CommonObject
* @see update_note()
*/
public $note_public;
/**
* @var string Private note
* @see update_note()
*/
public $note_private;
/**
* @deprecated
* @see note_public
@ -340,25 +340,25 @@ abstract class CommonObject
* @see update_price()
*/
public $total_ht;
/**
* @var float Total VAT amount
* @see update_price()
*/
public $total_tva;
/**
* @var float Total local tax 1 amount
* @see update_price()
*/
public $total_localtax1;
/**
* @var float Total local tax 2 amount
* @see update_price()
*/
public $total_localtax2;
/**
* @var float Total amount with taxes
* @see update_price()
@ -381,13 +381,13 @@ abstract class CommonObject
* @see setIncoterms()
*/
public $fk_incoterms;
/**
* @var string
* @see SetIncoterms()
*/
public $libelle_incoterms;
/**
* @var string
* @see display_incoterms()
@ -3760,7 +3760,7 @@ abstract class CommonObject
$num = count($this->lines);
//Line extrafield
// Line extrafield
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$extrafieldsline = new ExtraFields($this->db);
$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
if (empty($reshook))
{
// Title line
print "<thead>\n";
print '<tr class="liste_titre nodrag nodrop">';
@ -3860,7 +3861,6 @@ abstract class CommonObject
//Line extrafield
$line->fetch_optionals();
//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.
{

View File

@ -45,22 +45,22 @@ class FactureFournisseur extends CommonInvoice
* @var string ID to identify managed object
*/
public $element='invoice_supplier';
/**
* @var string Name of table without prefix where object is stored
*/
public $table_element='facture_fourn';
public $table_element_line='facture_fourn_det';
public $fk_element='fk_facture_fourn';
public $picto='bill';
/**
* 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
* @var int
*/
public $ismultientitymanaged = 1;
/**
* 0=Default, 1=View may be restricted to sales representative only if no permission to see all or to company of external user if external user
* @var integer
@ -110,13 +110,13 @@ class FactureFournisseur extends CommonInvoice
public $total_localtax1=0;
public $total_localtax2=0;
public $total_ttc=0;
/**
* @deprecated
* @see note_private, note_public
*/
public $note;
public $note_private;
public $note_public;
public $propalid;
@ -675,7 +675,9 @@ class FactureFournisseur extends CommonInvoice
*/
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.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';
@ -685,7 +687,6 @@ class FactureFournisseur extends CommonInvoice
$sql.= ' WHERE fk_facture_fourn='.$this->id;
$sql.= ' ORDER BY f.rang, f.rowid';
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
$resql_rows = $this->db->query($sql);
if ($resql_rows)
@ -703,6 +704,9 @@ class FactureFournisseur extends CommonInvoice
$line->id = $obj->rowid;
$line->rowid = $obj->rowid;
$line->description = $obj->description;
$line->date_start = $obj->date_start;
$line->date_end = $obj->date_end;
$line->product_ref = $obj->product_ref;
$line->ref = $obj->product_ref;
$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='')
{
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';
$pu = price2num($pu);
@ -1816,6 +1820,9 @@ class FactureFournisseur extends CommonInvoice
$line->remise_percent = $remise_percent;
$line->ref_supplier = $ref_supplier;
$line->date_start = $date_start;
$line->date_end = $date_end;
$line->vat_src_code=$vat_src_code;
$line->tva_tx = $vatrate;
$line->localtax1_tx = $txlocaltax1;
@ -2572,7 +2579,7 @@ class SupplierInvoiceLine extends CommonObjectLine
* @var string ID to identify managed object
*/
public $element='facture_fourn_det';
/**
* @var string Name of table without prefix where object is stored
*/
@ -2585,7 +2592,7 @@ class SupplierInvoiceLine extends CommonObjectLine
* @see product_ref
*/
public $ref;
/**
* Internal ref
* @var string
@ -2604,7 +2611,7 @@ class SupplierInvoiceLine extends CommonObjectLine
* @see label
*/
public $libelle;
/**
* Product description
* @var string
@ -2618,7 +2625,7 @@ class SupplierInvoiceLine extends CommonObjectLine
* @see subprice
*/
public $pu_ht;
public $subprice;
/**
@ -2634,7 +2641,7 @@ class SupplierInvoiceLine extends CommonObjectLine
* @see total_tva
*/
public $tva;
public $total_tva;
/**
@ -2656,6 +2663,9 @@ class SupplierInvoiceLine extends CommonObjectLine
*/
public $description;
public $date_start;
public $date_end;
public $skip_update_total; // Skip update price total for special lines
/**
@ -2713,7 +2723,7 @@ class SupplierInvoiceLine extends CommonObjectLine
*/
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.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';
@ -2740,6 +2750,8 @@ class SupplierInvoiceLine extends CommonObjectLine
$this->rowid = $obj->rowid;
$this->fk_facture_fourn = $obj->fk_facture_fourn;
$this->description = $obj->description;
$this->date_start = $obj->date_start;
$this->date_end = $obj->date_end;
$this->product_ref = $obj->product_ref;
$this->ref_supplier = $obj->ref_supplier;
$this->libelle = $obj->label;
@ -2871,6 +2883,8 @@ class SupplierInvoiceLine extends CommonObjectLine
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det SET";
$sql.= " description ='".$this->db->escape($this->description)."'";
$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_ttc = ".price2num($this->pu_ttc);
$sql.= ", qty = ".price2num($this->qty);
@ -3045,12 +3059,11 @@ class SupplierInvoiceLine extends CommonObjectLine
$sql.= ", ".price2num($this->multicurrency_total_ttc);
$sql.= ')';
dol_syslog(get_class($this)."::insert", LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$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
{

View File

@ -1097,6 +1097,7 @@ if (empty($reshook))
$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_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');
if ($prod_entry_mode == 'free')
{
@ -1211,7 +1212,7 @@ if (empty($reshook))
if(!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
$desc = $productsupplier->desc_supplier;
} else $desc = $productsupplier->description;
if (trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc);
$type = $productsupplier->type;