NEW option update prices on proposal cloning

This commit is contained in:
lvessiller 2022-03-03 11:58:29 +01:00
parent 72965fdb2e
commit 6c172d6441
4 changed files with 57 additions and 5 deletions

View File

@ -220,7 +220,7 @@ if (empty($reshook)) {
}
}
$result = $object->createFromClone($user, $socid, (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : null));
$result = $object->createFromClone($user, $socid, (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : null), GETPOSTISSET('update_prices'));
if ($result > 0) {
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
exit();
@ -1914,8 +1914,8 @@ if ($action == 'create') {
$formquestion = array(
// 'text' => $langs->trans("ConfirmClone"),
// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
// array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=2 OR s.client=3)'))
array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '(s.client=1 OR s.client=2 OR s.client=3)')),
array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans('PuttingPricesUpToDate'), 'value' => 1),
);
if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY) && !empty($object->delivery_date)) {
$formquestion[] = array('type' => 'date', 'name' => 'date_delivery', 'label' => $langs->trans("DeliveryDate"), 'value' => $object->delivery_date);

View File

@ -1324,11 +1324,12 @@ class Propal extends CommonObject
* @param User $user User making the clone
* @param int $socid Id of thirdparty
* @param int $forceentity Entity id to force
* @param bool $update_prices [=false] Update prices if true
* @return int New id of clone
*/
public function createFromClone(User $user, $socid = 0, $forceentity = null)
public function createFromClone(User $user, $socid = 0, $forceentity = null, $update_prices = false)
{
global $conf, $hookmanager;
global $conf, $hookmanager, $mysoc;
dol_include_once('/projet/class/project.class.php');
@ -1375,6 +1376,55 @@ class Propal extends CommonObject
$objsoc->fetch($object->socid);
}
// update prices
if ($update_prices === true) {
if ($objsoc->id > 0 && !empty($object->lines)) {
if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
// If price per customer
require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
}
foreach ($object->lines as $line) {
if ($line->fk_product > 0) {
$prod = new Product($this->db);
$res = $prod->fetch($line->fk_product);
if ($res > 0) {
$pu_ht = $prod->price;
$tva_tx = get_default_tva($mysoc, $objsoc, $prod->id);
$remise_percent = $objsoc->remise_percent;
if (!empty($conf->global->PRODUIT_MULTIPRICES) && $objsoc->price_level > 0) {
$pu_ht = $prod->multiprices[$objsoc->price_level];
if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { // using this option is a bug. kept for backward compatibility
if (isset($prod->multiprices_tva_tx[$objsoc->price_level])) {
$tva_tx = $prod->multiprices_tva_tx[$objsoc->price_level];
}
}
} elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
$prodcustprice = new Productcustomerprice($this->db);
$filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $objsoc->id);
$result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
if ($result) {
// If there is some prices specific to the customer
if (count($prodcustprice->lines) > 0) {
$pu_ht = price($prodcustprice->lines[0]->price);
$tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx);
if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) {
$tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')';
}
}
}
}
$line->subprice = $pu_ht;
$line->tva_tx = $tva_tx;
$line->remise_percent = $remise_percent;
}
}
}
}
}
$object->id = 0;
$object->ref = '';
$object->entity = (!empty($forceentity) ? $forceentity : $object->entity);

View File

@ -412,3 +412,4 @@ SwitchOnSaleStatus=Switch on sale status
SwitchOnPurchaseStatus=Switch on purchase status
StockMouvementExtraFields= Extra Fields (stock mouvement)
InventoryExtraFields= Extra Fields (inventory)
PuttingPricesUpToDate=Update prices

View File

@ -411,3 +411,4 @@ Rank=Classement
SwitchOnSaleStatus=Basculer le statut En vente
SwitchOnPurchaseStatus=Basculer le statut En achat
StockMouvementExtraFields= Champs supplémentaires (mouvement de stock)
PuttingPricesUpToDate=Mettre à jour les tarifs