Update description of products on cloning

This commit is contained in:
Sylvain Legrand 2023-03-30 22:14:04 +02:00
parent 1be9364971
commit a8d4ea406b
4 changed files with 37 additions and 28 deletions

View File

@ -221,7 +221,7 @@ if (empty($reshook)) {
}
}
$result = $object->createFromClone($user, $socid, (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : null), (GETPOST('update_prices', 'aZ') ? true : false));
$result = $object->createFromClone($user, $socid, (GETPOSTISSET('entity') ? GETPOST('entity', 'int') : null), (GETPOST('update_prices', 'aZ') ? true : false), (GETPOST('update_desc', 'aZ') ? true : false));
if ($result > 0) {
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
exit();
@ -2137,7 +2137,8 @@ if ($action == 'create') {
// 'text' => $langs->trans("ConfirmClone"),
// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), '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)', '', 0, 0, null, 0, 'maxwidth300')),
array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans('PuttingPricesUpToDate'), 'value' => (!empty($conf->global->PROPOSAL_CLONE_UPDATE_PRICES) ? 1 : 0)),
array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans('PuttingPricesUpToDate'), 'value' => 0),
array('type' => 'checkbox', 'name' => 'update_desc', 'label' => $langs->trans('PuttingDescUpToDate'), 'value' => 0),
);
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

@ -1360,9 +1360,10 @@ class Propal extends CommonObject
* @param int $socid Id of thirdparty
* @param int $forceentity Entity id to force
* @param bool $update_prices [=false] Update prices if true
* @param bool $update_desc [=false] Update description if true
* @return int New id of clone
*/
public function createFromClone(User $user, $socid = 0, $forceentity = null, $update_prices = false)
public function createFromClone(User $user, $socid = 0, $forceentity = null, $update_prices = false, $update_desc = false)
{
global $conf, $hookmanager, $mysoc;
@ -1413,7 +1414,7 @@ class Propal extends CommonObject
}
// update prices
if ($update_prices === true) {
if ($update_prices === true || $update_desc === true) {
if ($objsoc->id > 0 && !empty($object->lines)) {
if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
// If price per customer
@ -1425,36 +1426,41 @@ class Propal extends CommonObject
$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 ($update_prices === true) {
$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];
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->fetchAll('', '', 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.')';
} 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->fetchAll('', '', 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;
$line->subprice = $pu_ht;
$line->tva_tx = $tva_tx;
$line->remise_percent = $remise_percent;
}
if ($update_desc === true) {
$line->desc = $prod->description;
}
}
}
}

View File

@ -55,6 +55,7 @@ CopyPropalFrom=Create commercial proposal by copying existing proposal
CreateEmptyPropal=Create empty commercial proposal or from list of products/services
DefaultProposalDurationValidity=Default commercial proposal validity duration (in days)
DefaultPuttingPricesUpToDate=By default update prices with current known prices on cloning a proposal
DefaultPuttingDescUpToDate=By default update descriptions with current known descriptions on cloning a proposal
UseCustomerContactAsPropalRecipientIfExist=Use contact/address with type 'Contact following-up proposal' if defined instead of third party address as proposal recipient address
ConfirmClonePropal=Are you sure you want to clone the commercial proposal <b>%s</b>?
ConfirmReOpenProp=Are you sure you want to open back the commercial proposal <b>%s</b>?

View File

@ -55,6 +55,7 @@ CopyPropalFrom=Créer proposition/devis par recopie d'un proposition existante
CreateEmptyPropal=Créer proposition/devis vierge ou avec la liste des produits/services
DefaultProposalDurationValidity=Délai de validité par défaut (en jours)
DefaultPuttingPricesUpToDate=Par défaut, mettre à jour les prix avec les prix connus actuels lors du clonage d'une proposition
DefaultPuttingDescUpToDate=Par défaut, mettre à jour les descriptions lors de clonage d'une proposition commerciale
UseCustomerContactAsPropalRecipientIfExist=Utiliser l'adresse de 'contact suivi client' si définie plutôt que l'adresse du tiers comme destinataire des propositions
ConfirmClonePropal=Êtes-vous sûr de vouloir cloner la proposition commerciale <b>%s</b> ?
ConfirmReOpenProp=Êtes-vous sûr de vouloir réouvrir la proposition commerciale <b>%s</b> ?