NEW add clone customers prices in clone product or service

This commit is contained in:
VESSILLER 2019-10-18 15:10:22 +02:00
parent e8104a50ac
commit 801092d848
2 changed files with 82 additions and 10 deletions

View File

@ -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);

View File

@ -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;
}