diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 86a5cbe07c1..5ee8c502009 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -540,6 +540,17 @@ if (empty($reshook)) } } + if (GETPOST('clone_prices')) { + $result = $object->clone_price($originalId, $id); + + if ($result < 1) { + $db->rollback(); + setEventMessages($langs->trans('ErrorProductClone'), null, 'errors'); + header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $originalId); + exit(); + } + } + // $object->clone_fournisseurs($originalId, $id); $db->commit(); @@ -1997,8 +2008,10 @@ $formquestionclone=array( array('type' => 'text', 'name' => 'clone_ref','label' => $langs->trans("NewRefForClone"), 'value' => empty($tmpcode) ? $langs->trans("CopyOf").' '.$object->ref : $tmpcode, 'size'=>24), array('type' => 'checkbox', 'name' => 'clone_content','label' => $langs->trans("CloneContentProduct"), 'value' => 1), array('type' => 'checkbox', 'name' => 'clone_categories', 'label' => $langs->trans("CloneCategoriesProduct"), 'value' => 1), - array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("FeatureNotYetAvailable").')', 'value' => 0, 'disabled' => true), ); +if (!empty($conf->global->PRODUIT_MULTIPRICES)) { + $formquestionclone[] = array('type' => 'checkbox', 'name' => 'clone_prices', 'label' => $langs->trans("ClonePricesProduct").' ('.$langs->trans("CustomerPrices").')', 'value' => 0); +} if (! empty($conf->global->PRODUIT_SOUSPRODUITS)) { $formquestionclone[]=array('type' => 'checkbox', 'name' => 'clone_composition', 'label' => $langs->trans('CloneCompositionProduct'), 'value' => 1); diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index c55e888e405..5492f760407 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3725,21 +3725,80 @@ class Product extends CommonObject */ public function clone_price($fromId, $toId) { - // phpcs:enable + global $conf, $user; + + $now = dol_now(); + $this->db->begin(); - // les prix - $sql = "INSERT ".MAIN_DB_PREFIX."product_price ("; - $sql.= " fk_product, date_price, price, tva_tx, localtax1_tx, localtax2_tx, fk_user_author, tosell)"; - $sql.= " SELECT ".$toId . ", date_price, price, tva_tx, localtax1_tx, localtax2_tx, fk_user_author, tosell"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_price "; - $sql.= " WHERE fk_product = ". $fromId; + // prices + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_price ("; + $sql .= " entity"; + $sql .= ", fk_product"; + $sql .= ", date_price"; + $sql .= ", price_level"; + $sql .= ", price"; + $sql .= ", price_ttc"; + $sql .= ", price_min"; + $sql .= ", price_min_ttc"; + $sql .= ", price_base_type"; + $sql .= ", default_vat_code"; + $sql .= ", tva_tx"; + $sql .= ", recuperableonly"; + $sql .= ", localtax1_tx"; + $sql .= ", localtax1_type"; + $sql .= ", localtax2_tx"; + $sql .= ", localtax2_type"; + $sql .= ", fk_user_author"; + $sql .= ", tosell"; + $sql .= ", price_by_qty"; + $sql .= ", fk_price_expression"; + $sql .= ", fk_multicurrency"; + $sql .= ", multicurrency_code"; + $sql .= ", multicurrency_tx"; + $sql .= ", multicurrency_price"; + $sql .= ", multicurrency_price_ttc"; + $sql .= ")"; + $sql .= " SELECT"; + $sql .= " entity"; + $sql .= ", " . $toId; + $sql .= ", '" . $this->db->idate($now) . "'"; + $sql .= ", price_level"; + $sql .= ", price"; + $sql .= ", price_ttc"; + $sql .= ", price_min"; + $sql .= ", price_min_ttc"; + $sql .= ", price_base_type"; + $sql .= ", default_vat_code"; + $sql .= ", tva_tx"; + $sql .= ", recuperableonly"; + $sql .= ", localtax1_tx"; + $sql .= ", localtax1_type"; + $sql .= ", localtax2_tx"; + $sql .= ", localtax2_type"; + $sql .= ", " . $user->id; + $sql .= ", tosell"; + $sql .= ", price_by_qty"; + $sql .= ", fk_price_expression"; + $sql .= ", fk_multicurrency"; + $sql .= ", multicurrency_code"; + $sql .= ", multicurrency_tx"; + $sql .= ", multicurrency_price"; + $sql .= ", multicurrency_price_ttc"; + $sql .= " FROM " . MAIN_DB_PREFIX . "product_price"; + $sql .= " WHERE fk_product = ". $fromId; + $sql .= " ORDER BY date_price DESC"; + if ($conf->global->PRODUIT_MULTIPRICES_LIMIT>0) { + $sql .= " LIMIT " . $conf->global->PRODUIT_MULTIPRICES_LIMIT; + } - dol_syslog(get_class($this).'::clone_price', LOG_DEBUG); - if (! $this->db->query($sql)) { + dol_syslog(__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { $this->db->rollback(); return -1; } + $this->db->commit(); return 1; }