diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 006c8710770..3ea695504da 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -500,52 +500,6 @@ if (empty($reshook)) { // If price has changed, we update it if (!array_key_exists($key, $object->multiprices) || $object->multiprices[$key] != $newprice || $object->multiprices_min[$key] != $newprice_min || $object->multiprices_base_type[$key] != $val['price_base_type'] || $object->multiprices_tva_tx[$key] != $newvattx) { $res = $object->updatePrice($newprice, $val['price_base_type'], $user, $val['vat_tx'], $newprice_min, $key, $val['npr'], $psq, 0, $val['localtaxes_array'], $val['default_vat_code'], $val['price_label']); - if ($res > 0) { - $extralabels = $extrafields->fetch_name_optionals_label("product"); - if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES') && !empty($extralabels)) { - // Default price - $extrafield_values = $extrafields->getOptionalsFromPost("product"); - foreach ($extrafield_values as $efkey => $value) { - $object->array_options[$efkey] = $value; - } - $result = $object->insertExtraFields(); - if ($result < 0) { - $error++; - } - } elseif ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($extralabels)) { - $price_extralabels = $extrafields->fetch_name_optionals_label("product_price"); - $sql = "SELECT rowid"; - $sql .= " FROM ".$object->db->prefix()."product_price"; - $sql .= " WHERE entity IN (".getEntity('productprice').")"; - $sql .= " AND price_level=".((int) $key); // $i - $sql .= " AND fk_product = ".((int) $object->id); - $sql .= " ORDER BY date_price DESC, rowid DESC"; - $sql .= " LIMIT 1"; - $resql = $object->db->query($sql); - if ($resql) { - $lineid = $object->db->fetch_object($resql); - $db->free($resql); - } - if (!empty($lineid->rowid)) { - if (!empty($price_extralabels) && is_array($price_extralabels)) { - foreach ($price_extralabels as $code => $label) { - $code_array = GETPOST($code, 'array'); - $object->array_options['options_'.$code] = $code_array[$key]; - } - // We need to force table to update product_price and not product extrafields - $object->id = $lineid->rowid; - $object->table_element = 'product_price'; - $result = $object->insertExtraFields(); - } - // Back to product table - $object->id = $id; - $object->table_element = 'product'; - if ($result < 0) { - $error++; - } - } - } - } } else { $res = 0; } @@ -555,6 +509,41 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); break; } + + // Update level price extrafields + $price_extralabels = $extrafields->fetch_name_optionals_label("product_price"); + if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) && !empty($price_extralabels)) { + $sql = "SELECT rowid"; + $sql .= " FROM ".$object->db->prefix()."product_price"; + $sql .= " WHERE entity IN (".getEntity('productprice').")"; + $sql .= " AND price_level=".((int) $key); // $i + $sql .= " AND fk_product = ".((int) $object->id); + $sql .= " ORDER BY date_price DESC, rowid DESC"; + $sql .= " LIMIT 1"; + $resql = $object->db->query($sql); + if ($resql) { + $lineid = $object->db->fetch_object($resql); + $db->free($resql); + } + if (!empty($lineid->rowid)) { + if (!empty($price_extralabels) && is_array($price_extralabels)) { + foreach ($price_extralabels as $code => $label) { + $code_array = GETPOST($code, 'array'); + $object->array_options['options_'.$code] = $code_array[$key]; + } + // We need to force table to update product_price and not product extrafields + $object->id = $lineid->rowid; + $object->table_element = 'product_price'; + $result = $object->insertExtraFields(); + } + // Back to product table + $object->id = $id; + $object->table_element = 'product'; + if ($result < 0) { + $error++; + } + } + } } } @@ -1515,39 +1504,6 @@ if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUS } print ''; } - - // Extrafields - $extrafields->fetch_name_optionals_label("product"); - $extralabels = !empty($extrafields->attributes["product"]['label']) ? $extrafields->attributes["product"]['label'] : []; - $extrafield_values = $extrafields->getOptionalsFromPost("product"); - $sql = "SELECT"; - $sql .= " fk_object"; - foreach ($extralabels as $key => $value) { - $sql .= ", ".$key; - } - $sql .= " FROM ".MAIN_DB_PREFIX."product_extrafields"; - $sql .= " WHERE fk_object = ".((int) $object->id); - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - foreach ($extralabels as $key => $value) { - if (!empty($extrafields->attributes["product"]['list'][$key]) && ($extrafields->attributes["product"]['list'][$key] == 1 || $extrafields->attributes["product"]['list'][$key] == 3 || ($action == "edit_price" && $extrafields->attributes["product"]['list'][$key] == 4))) { - if (!empty($extrafields->attributes["product"]['langfile'][$key])) { - $langs->load($extrafields->attributes["product"]['langfile'][$key]); - } - - print 'attributes["product"]['required'][$key] ? ' class="fieldrequired"' : '').'>'; - if (!empty($extrafields->attributes["product"]['help'][$key])) { - print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product"]['help'][$key])); - } else { - print $langs->trans($value); - } - - print ''.$extrafields->showOutputField($key, $obj->{$key}, '', 'product').""; - } - } - $db->free($resql); - } } print "\n"; @@ -1751,59 +1707,6 @@ if (($action == 'edit_price' || $action == 'edit_level_price') && $object->getRi print ''; print ''; - // Extrafields - $extrafields->fetch_name_optionals_label("product"); - $extralabels = !empty($extrafields->attributes["product"]['label']) ? $extrafields->attributes["product"]['label'] : ''; - $extrafield_values = $extrafields->getOptionalsFromPost("product"); - if (!empty($extralabels)) { - if (empty($object->id)) { - foreach ($extralabels as $key => $value) { - if (!empty($extrafields->attributes["product"]['list'][$key]) && ($extrafields->attributes["product"]['list'][$key] == 1 || $extrafields->attributes["product"]['list'][$key] == 3 || ($action == "edit_price" && $extrafields->attributes["product"]['list'][$key] == 4))) { - if (!empty($extrafields->attributes["product"]['langfile'][$key])) { - $langs->load($extrafields->attributes["product"]['langfile'][$key]); - } - - print 'attributes["product"]['required'][$key] ? ' class="fieldrequired"' : '').'>'; - if (!empty($extrafields->attributes["product"]['help'][$key])) { - print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product"]['help'][$key])); - } else { - print $langs->trans($value); - } - print ''.$extrafields->showInputField($key, GETPOSTISSET('options_'.$key) ? $extrafield_values['options_'.$key] : '', '', '', '', '', 0, 'product').''; - } - } - } else { - $sql = "SELECT"; - $sql .= " fk_object"; - foreach ($extralabels as $key => $value) { - $sql .= ", ".$key; - } - $sql .= " FROM ".MAIN_DB_PREFIX."product_extrafields"; - $sql .= " WHERE fk_object = ".((int) $object->id); - $resql = $db->query($sql); - if ($resql) { - $obj = $db->fetch_object($resql); - foreach ($extralabels as $key => $value) { - if (!empty($extrafields->attributes["product"]['list'][$key]) && ($extrafields->attributes["product"]['list'][$key] == 1 || $extrafields->attributes["product"]['list'][$key] == 3 || ($action == "edit_price" && $extrafields->attributes["product"]['list'][$key] == 4))) { - if (!empty($extrafields->attributes["product"]['langfile'][$key])) { - $langs->load($extrafields->attributes["product"]['langfile'][$key]); - } - - print 'attributes["product"]['required'][$key] ? ' class="fieldrequired"' : '').'>'; - if (!empty($extrafields->attributes["product"]['help'][$key])) { - print $form->textwithpicto($langs->trans($value), $langs->trans($extrafields->attributes["product"]['help'][$key])); - } else { - print $langs->trans($value); - } - print ''.$extrafields->showInputField($key, GETPOSTISSET('options_'.$key) ? $extrafield_values['options_'.$key] : $obj->{$key}, '', '', '', '', 0, 'product'); - - print ''; - } - } - $db->free($resql); - } - } - } $parameters = array(); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook @@ -2458,6 +2361,8 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT print ''."\n"; if (count($prodcustprice->lines) > 0 || $search_soc) { + $extrafields->fetch_name_optionals_label("product_customer_price"); + $custom_price_extralabels = !empty($extrafields->attributes["product_customer_price"]['label']) ? $extrafields->attributes["product_customer_price"]['label'] : ''; if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_AND_MULTIPRICES')) { $colspan = 10; } else { @@ -2466,8 +2371,8 @@ if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") { $colspan++; } - if (!empty($price_extralabels) && is_array($price_extralabels)) { - $colspan += count($price_extralabels); + if (!empty($custom_price_extralabels) && is_array($custom_price_extralabels)) { + $colspan += count($custom_price_extralabels); } print '';