Merge pull request #20255 from Easya-Solutions/new-proposal-clone-update-prices
NEW option update prices on proposal cloning
This commit is contained in:
commit
94224e9275
@ -198,6 +198,37 @@ if ($action == 'updateMask') {
|
|||||||
// par appel methode canBeActivated
|
// par appel methode canBeActivated
|
||||||
|
|
||||||
dolibarr_set_const($db, "PROPALE_ADDON", $value, 'chaine', 0, '', $conf->entity);
|
dolibarr_set_const($db, "PROPALE_ADDON", $value, 'chaine', 0, '', $conf->entity);
|
||||||
|
} elseif (preg_match('/set_(.*)/', $action, $reg)) {
|
||||||
|
$code = $reg[1];
|
||||||
|
$value = (GETPOST($code) ? GETPOST($code) : 1);
|
||||||
|
|
||||||
|
$res = dolibarr_set_const($db, $code, $value, 'chaine', 0, '', $conf->entity);
|
||||||
|
if (!($res > 0)) {
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
|
setEventMessages($langs->trans('Error'), null, 'errors');
|
||||||
|
} else {
|
||||||
|
setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
|
||||||
|
header("Location: " . $_SERVER["PHP_SELF"]);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
} elseif (preg_match('/del_(.*)/', $action, $reg)) {
|
||||||
|
$code = $reg[1];
|
||||||
|
$res = dolibarr_del_const($db, $code, $conf->entity);
|
||||||
|
|
||||||
|
if (!($res > 0)) {
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($error) {
|
||||||
|
setEventMessages($langs->trans('Error'), null, 'errors');
|
||||||
|
} else {
|
||||||
|
setEventMessages($langs->trans('SetupSaved'), null, 'mesgs');
|
||||||
|
header("Location: " . $_SERVER["PHP_SELF"]);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -593,6 +624,26 @@ print '<td class="right"><input type="submit" class="button button-edit" value="
|
|||||||
print '</tr>';
|
print '</tr>';
|
||||||
print '</form>';
|
print '</form>';
|
||||||
|
|
||||||
|
// default update prices on cloning a proposal
|
||||||
|
print '<form method="post" action="' . $_SERVER["PHP_SELF"] . '">';
|
||||||
|
print '<input type="hidden" name="token" value="' . newToken() .'">';
|
||||||
|
print '<tr class="oddeven">';
|
||||||
|
print '<td>' . $langs->trans('DefaultPuttingPricesUpToDate').'</td>';
|
||||||
|
print '<td></td>';
|
||||||
|
print '<td class="right">';
|
||||||
|
if (!empty($conf->use_javascript_ajax)) {
|
||||||
|
print ajax_constantonoff('PROPOSAL_CLONE_UPDATE_PRICES', array(), $conf->entity, 0, 0, 1, 0);
|
||||||
|
} else {
|
||||||
|
if (empty($conf->global->PROPOSAL_CLONE_UPDATE_PRICES)) {
|
||||||
|
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=set_PROPOSAL_CLONE_UPDATE_PRICES">' . img_picto($langs->trans('Disabled'), 'switch_off') . '</a>';
|
||||||
|
} else {
|
||||||
|
print '<a href="' . $_SERVER['PHP_SELF'] . '?action=del_PROPOSAL_CLONE_UPDATE_PRICES">' . img_picto($langs->trans('Enabled'), 'switch_on') . '</a>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print '</td>';
|
||||||
|
print '</tr>';
|
||||||
|
print '</form>';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
|
||||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||||
|
|||||||
@ -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), (GETPOST('update_prices', 'aZ') ? true : false));
|
||||||
if ($result > 0) {
|
if ($result > 0) {
|
||||||
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
|
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
|
||||||
exit();
|
exit();
|
||||||
@ -1917,8 +1917,8 @@ if ($action == 'create') {
|
|||||||
$formquestion = array(
|
$formquestion = array(
|
||||||
// 'text' => $langs->trans("ConfirmClone"),
|
// 'text' => $langs->trans("ConfirmClone"),
|
||||||
// array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
|
// 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' => (!empty($conf->global->PROPOSAL_CLONE_UPDATE_PRICES) ? 1 : 0)),
|
||||||
);
|
);
|
||||||
if (!empty($conf->global->PROPAL_CLONE_DATE_DELIVERY) && !empty($object->delivery_date)) {
|
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);
|
$formquestion[] = array('type' => 'date', 'name' => 'date_delivery', 'label' => $langs->trans("DeliveryDate"), 'value' => $object->delivery_date);
|
||||||
|
|||||||
@ -1326,11 +1326,12 @@ class Propal extends CommonObject
|
|||||||
* @param User $user User making the clone
|
* @param User $user User making the clone
|
||||||
* @param int $socid Id of thirdparty
|
* @param int $socid Id of thirdparty
|
||||||
* @param int $forceentity Entity id to force
|
* @param int $forceentity Entity id to force
|
||||||
|
* @param bool $update_prices [=false] Update prices if true
|
||||||
* @return int New id of clone
|
* @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');
|
dol_include_once('/projet/class/project.class.php');
|
||||||
|
|
||||||
@ -1377,6 +1378,55 @@ class Propal extends CommonObject
|
|||||||
$objsoc->fetch($object->socid);
|
$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->id = 0;
|
||||||
$object->ref = '';
|
$object->ref = '';
|
||||||
$object->entity = (!empty($forceentity) ? $forceentity : $object->entity);
|
$object->entity = (!empty($forceentity) ? $forceentity : $object->entity);
|
||||||
|
|||||||
@ -414,3 +414,4 @@ SwitchOnPurchaseStatus=Switch on purchase status
|
|||||||
StockMouvementExtraFields= Extra Fields (stock mouvement)
|
StockMouvementExtraFields= Extra Fields (stock mouvement)
|
||||||
InventoryExtraFields= Extra Fields (inventory)
|
InventoryExtraFields= Extra Fields (inventory)
|
||||||
ScanOrTypeOrCopyPasteYourBarCodes=Scan or type or copy/paste your barcodes
|
ScanOrTypeOrCopyPasteYourBarCodes=Scan or type or copy/paste your barcodes
|
||||||
|
PuttingPricesUpToDate=Update prices with current known prices
|
||||||
|
|||||||
@ -54,6 +54,7 @@ NoDraftProposals=No draft proposals
|
|||||||
CopyPropalFrom=Create commercial proposal by copying existing proposal
|
CopyPropalFrom=Create commercial proposal by copying existing proposal
|
||||||
CreateEmptyPropal=Create empty commercial proposal or from list of products/services
|
CreateEmptyPropal=Create empty commercial proposal or from list of products/services
|
||||||
DefaultProposalDurationValidity=Default commercial proposal validity duration (in days)
|
DefaultProposalDurationValidity=Default commercial proposal validity duration (in days)
|
||||||
|
DefaultPuttingPricesUpToDate=By default update prices with current known prices 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
|
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>?
|
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>?
|
ConfirmReOpenProp=Are you sure you want to open back the commercial proposal <b>%s</b>?
|
||||||
|
|||||||
@ -411,3 +411,4 @@ Rank=Classement
|
|||||||
SwitchOnSaleStatus=Basculer le statut En vente
|
SwitchOnSaleStatus=Basculer le statut En vente
|
||||||
SwitchOnPurchaseStatus=Basculer le statut En achat
|
SwitchOnPurchaseStatus=Basculer le statut En achat
|
||||||
StockMouvementExtraFields= Champs supplémentaires (mouvement de stock)
|
StockMouvementExtraFields= Champs supplémentaires (mouvement de stock)
|
||||||
|
PuttingPricesUpToDate=Mettre à jour les prix
|
||||||
|
|||||||
@ -54,6 +54,7 @@ NoDraftProposals=Pas de propositions brouillons
|
|||||||
CopyPropalFrom=Créer proposition/devis par recopie d'un proposition existante
|
CopyPropalFrom=Créer proposition/devis par recopie d'un proposition existante
|
||||||
CreateEmptyPropal=Créer proposition/devis vierge ou avec la liste des produits/services
|
CreateEmptyPropal=Créer proposition/devis vierge ou avec la liste des produits/services
|
||||||
DefaultProposalDurationValidity=Délai de validité par défaut (en jours)
|
DefaultProposalDurationValidity=Délai de validité par défaut (en jours)
|
||||||
|
DefaultPuttingPricesUpToDate=Par défaut, mettre à jour les prix 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
|
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> ?
|
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> ?
|
ConfirmReOpenProp=Êtes-vous sûr de vouloir réouvrir la proposition commerciale <b>%s</b> ?
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user