This commit is contained in:
Laurent Destailleur 2020-01-25 14:03:24 +01:00
parent de6b30be8c
commit 09f809f347
10 changed files with 81 additions and 47 deletions

View File

@ -722,6 +722,7 @@ class Propal extends CommonObject
$localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
// Clean vat code
$reg = array();
$vat_src_code = '';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
@ -757,7 +758,7 @@ class Propal extends CommonObject
//Fetch current line from the database and then clone the object and set it in $oldline property
$line = new PropaleLigne($this->db);
$line->fetch($rowid);
$line->fetch_optionals(); // Fetch extrafields for oldcopy
$line->fetch_optionals();
$staticline = clone $line;
@ -808,7 +809,10 @@ class Propal extends CommonObject
$this->line->remise = $remise;
if (is_array($array_options) && count($array_options) > 0) {
$this->line->array_options = $array_options;
// We replace values in this->line->array_options only for entries defined into $array_options
foreach($array_options as $key => $value) {
$this->line->array_options[$key] = $array_options[$key];
}
}
// Multicurrency

View File

@ -3074,6 +3074,7 @@ class Commande extends CommonOrder
//Fetch current line from the database and then clone the object and set it in $oldline property
$line = new OrderLine($this->db);
$line->fetch($rowid);
$line->fetch_optionals();
if (!empty($line->fk_product))
{
@ -3146,7 +3147,10 @@ class Commande extends CommonOrder
$this->line->remise = $remise;
if (is_array($array_options) && count($array_options) > 0) {
$this->line->array_options = $array_options;
// We replace values in this->line->array_options only for entries defined into $array_options
foreach($array_options as $key => $value) {
$this->line->array_options[$key] = $array_options[$key];
}
}
$result = $this->line->update($user, $notrigger);

View File

@ -3105,6 +3105,7 @@ class Facture extends CommonInvoice
//Fetch current line from the database and then clone the object and set it in $oldline property
$line = new FactureLigne($this->db);
$line->fetch($rowid);
$line->fetch_optionals();
if (!empty($line->fk_product))
{
@ -3173,7 +3174,10 @@ class Facture extends CommonInvoice
$this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
if (is_array($array_options) && count($array_options) > 0) {
$this->line->array_options = $array_options;
// We replace values in this->line->array_options only for entries defined into $array_options
foreach($array_options as $key => $value) {
$this->line->array_options[$key] = $array_options[$key];
}
}
$result = $this->line->update($user, $notrigger);

View File

@ -155,23 +155,7 @@ if (empty($reshook))
}
}
// Si ajout champ produit libre
if (GETPOST('mode') == 'libre')
{
$date_start_sl = '';
$date_end_sl = '';
if (GETPOST('date_start_slmonth') && GETPOST('date_start_slday') && GETPOST('date_start_slyear'))
{
$date_start_sl = dol_mktime(GETPOST('date_start_slhour'), GETPOST('date_start_slmin'), 0, GETPOST('date_start_slmonth'), GETPOST('date_start_slday'), GETPOST('date_start_slyear'));
}
if (GETPOST('date_end_slmonth') && GETPOST('date_end_slday') && GETPOST('date_end_slyear'))
{
$date_end_sl = dol_mktime(GETPOST('date_end_slhour'), GETPOST('date_end_slmin'), 0, GETPOST('date_end_slmonth'), GETPOST('date_end_slday'), GETPOST('date_end_slyear'));
}
}
// Param dates
$date_contrat = '';
$date_start_update = '';
$date_end_update = '';
$date_start_real_update = '';
@ -665,11 +649,12 @@ if (empty($reshook))
if (!$error)
{
$objectline = new ContratLigne($db);
if ($objectline->fetch(GETPOST('elrowid')) < 0)
if ($objectline->fetch(GETPOST('elrowid', 'int')) < 0)
{
setEventMessages($objectline->error, $objectline->errors, 'errors');
$error++;
}
$objectline->fetch_optionals();
}
$db->begin();
@ -693,6 +678,7 @@ if (empty($reshook))
$txtva = $vat_rate;
// Clean vat code
$reg = array();
$vat_src_code = '';
if (preg_match('/\((.*)\)/', $txtva, $reg))
{
@ -735,7 +721,13 @@ if (empty($reshook))
// Extrafields
$extralabelsline = $extrafields->fetch_name_optionals_label($objectline->table_element);
$array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
$objectline->array_options = $array_options;
if (is_array($array_options) && count($array_options) > 0) {
// We replace values in this->line->array_options only for entries defined into $array_options
foreach($array_options as $key => $value) {
$objectline->array_options[$key] = $array_options[$key];
}
}
// TODO verifier price_min si fk_product et multiprix

View File

@ -1739,8 +1739,14 @@ class Contrat extends CommonObject
if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used
{
$contractline = new ContratLigne($this->db);
$contractline->array_options = $array_options;
$contractline->id = $rowid;
$contractline->fetch($rowid);
$contractline->fetch_optionals();
// We replace values in $contractline->array_options only for entries defined into $array_options
foreach($array_options as $key => $value) {
$contractline->array_options[$key] = $array_options[$key];
}
$result = $contractline->insertExtraFields();
if ($result < 0)
{

View File

@ -5187,7 +5187,6 @@ abstract class CommonObject
$attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey];
$attrfieldcomputed = $extrafields->attributes[$this->table_element]['computed'][$attributeKey];
if ($attributeRequired)
{
$mandatorypb = false;
@ -5218,7 +5217,6 @@ abstract class CommonObject
}
}
switch ($attributeType)
{
case 'int':

View File

@ -2147,23 +2147,27 @@ class ExtraFields
if (in_array($key_type, array('date', 'datetime')))
{
if (! GETPOSTISSET($keysuffix."options_".$key.$keyprefix)."year") continue; // Value was not provided, we should not set it.
// Clean parameters
$value_key = dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]);
$value_key = dol_mktime(GETPOST($keysuffix."options_".$key.$keyprefix."hour", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."min", 'int'), 0, GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int'));
}
elseif (in_array($key_type, array('checkbox', 'chkbxlst')))
{
if (! GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
$value_arr = GETPOST($keysuffix."options_".$key.$keyprefix);
// Make sure we get an array even if there's only one checkbox
$value_arr = (array) $value_arr;
$value_key = implode(',', $value_arr);
}
elseif (in_array($key_type, array('price', 'double')))
elseif (in_array($key_type, array('price', 'double', 'int')))
{
if (! GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
$value_arr = GETPOST($keysuffix."options_".$key.$keyprefix);
$value_key = price2num($value_arr);
}
else
{
if (! GETPOSTISSET($keysuffix."options_".$key.$keyprefix)) continue; // Value was not provided, we should not set it.
$value_key = GETPOST($keysuffix."options_".$key.$keyprefix);
}

View File

@ -2572,6 +2572,8 @@ class CommandeFournisseur extends CommonOrder
//Fetch current line from the database and then clone the object and set it in $oldline property
$this->line = new CommandeFournisseurLigne($this->db);
$this->line->fetch($rowid);
$this->line->fetch_optionals();
$oldline = clone $this->line;
$this->line->oldline = $oldline;
@ -2620,7 +2622,10 @@ class CommandeFournisseur extends CommonOrder
$this->line->remise_percent = $remise_percent;
if (is_array($array_options) && count($array_options) > 0) {
$this->line->array_options = $array_options;
// We replace values in this->line->array_options only for entries defined into $array_options
foreach($array_options as $key => $value) {
$this->line->array_options[$key] = $array_options[$key];
}
}
$result = $this->line->update($notrigger);

View File

@ -1913,11 +1913,15 @@ class FactureFournisseur extends CommonInvoice
$product_type = $type;
}
//Fetch current line from the database and then clone the object and set it in $oldline property
$line = new SupplierInvoiceLine($this->db);
$line->fetch($id);
$line->fetch_optionals();
if ($line->fetch($id) < 1) {
return -1;
}
$staticline = clone $line;
$line->oldline = $staticline;
$line->context = $this->context;
$line->description = $desc;
$line->subprice = $pu_ht;
@ -1945,9 +1949,15 @@ class FactureFournisseur extends CommonInvoice
$line->product_type = $product_type;
$line->info_bits = $info_bits;
$line->fk_unit = $fk_unit;
$line->array_options = $array_options;
// Multicurrency
if (is_array($array_options) && count($array_options) > 0) {
// We replace values in this->line->array_options only for entries defined into $array_options
foreach($array_options as $key => $value) {
$this->line->array_options[$key] = $array_options[$key];
}
}
// Multicurrency
$line->multicurrency_subprice = $pu_ht_devise;
$line->multicurrency_total_ht = $multicurrency_total_ht;
$line->multicurrency_total_tva = $multicurrency_total_tva;

View File

@ -391,7 +391,7 @@ class SupplierProposal extends CommonObject
* @param int $fk_fournprice Id supplier price. If 0, we will take best price. If -1 we keep it empty.
* @param int $pa_ht Buying price without tax
* @param string $label ???
* @param array $array_option extrafields array
* @param array $array_options extrafields array
* @param string $ref_supplier Supplier price reference
* @param int $fk_unit Id of the unit to use.
* @param string $origin 'order', 'supplier_proposal', ...
@ -403,7 +403,7 @@ class SupplierProposal extends CommonObject
*
* @see add_product()
*/
public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $pu_ttc = 0, $info_bits = 0, $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $array_option = 0, $ref_supplier = '', $fk_unit = '', $origin = '', $origin_id = 0, $pu_ht_devise = 0, $date_start = 0, $date_end = 0)
public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $price_base_type = 'HT', $pu_ttc = 0, $info_bits = 0, $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $array_options = 0, $ref_supplier = '', $fk_unit = '', $origin = '', $origin_id = 0, $pu_ht_devise = 0, $date_start = 0, $date_end = 0)
{
global $mysoc, $conf, $langs;
@ -605,8 +605,8 @@ class SupplierProposal extends CommonObject
// Mise en option de la ligne
if (empty($qty) && empty($special_code)) $this->line->special_code=3;
if (is_array($array_option) && count($array_option)>0) {
$this->line->array_options=$array_option;
if (is_array($array_options) && count($array_options)>0) {
$this->line->array_options=$array_options;
}
$result=$this->line->insert();
@ -664,13 +664,13 @@ class SupplierProposal extends CommonObject
* @param int $pa_ht Price (without tax) of product when it was bought
* @param string $label ???
* @param int $type 0/1=Product/service
* @param array $array_option extrafields array
* @param array $array_options extrafields array
* @param string $ref_supplier Supplier price reference
* @param int $fk_unit Id of the unit to use.
* @param double $pu_ht_devise Unit price in currency
* @return int 0 if OK, <0 if KO
*/
public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $desc = '', $price_base_type = 'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $type = 0, $array_option = 0, $ref_supplier = '', $fk_unit = '', $pu_ht_devise = 0)
public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $desc = '', $price_base_type = 'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $type = 0, $array_options = 0, $ref_supplier = '', $fk_unit = '', $pu_ht_devise = 0)
{
global $conf,$user,$langs, $mysoc;
@ -720,13 +720,17 @@ class SupplierProposal extends CommonObject
$multicurrency_total_tva = $tabprice[17];
$multicurrency_total_ttc = $tabprice[18];
// Update line
$this->line=new SupplierProposalLine($this->db);
//Fetch current line from the database and then clone the object and set it in $oldline property
$line = new SupplierProposalLine($this->db);
$line->fetch($rowid);
$line->fetch_optionals();
// Stock previous line records
$staticline=new SupplierProposalLine($this->db);
$staticline->fetch($rowid);
$this->line->oldline = $staticline;
$staticline = clone $line;
$line->oldline = $staticline;
$this->line = $line;
$this->line->context = $this->context;
// Reorder if fk_parent_line change
if (! empty($fk_parent_line) && ! empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line)
@ -773,8 +777,11 @@ class SupplierProposal extends CommonObject
}
$this->line->pa_ht = $pa_ht;
if (is_array($array_option) && count($array_option)>0) {
$this->line->array_options=$array_option;
if (is_array($array_options) && count($array_options)>0) {
// We replace values in this->line->array_options only for entries defined into $array_options
foreach($array_options as $key => $value) {
$this->line->array_options[$key] = $array_options[$key];
}
}
// Multicurrency