From d15493e50dbfc8040a6f6cd18aa9413176ced637 Mon Sep 17 00:00:00 2001 From: Faustin Date: Sun, 30 Oct 2022 02:59:11 +0200 Subject: [PATCH 1/2] massacrtion for updating product prices --- htdocs/core/actions_massactions.inc.php | 44 +++++++++++++++++++++++++ htdocs/core/tpl/massactions_pre.tpl.php | 18 ++++++++++ htdocs/langs/en_US/main.lang | 3 ++ htdocs/langs/en_US/products.lang | 1 + htdocs/langs/fr_FR/main.lang | 5 ++- htdocs/langs/fr_FR/products.lang | 1 + htdocs/product/list.php | 4 +-- 7 files changed, 73 insertions(+), 3 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 49cc6fa873c..7539bb028a4 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1240,6 +1240,50 @@ if (!$error && ($action == 'affecttag' && $confirm == 'yes') && $permissiontoadd } } +if (!$error && ($action == 'updateprice' && $confirm == 'yes') && $permissiontoadd) { + $db->begin(); + if (GETPOSTISSET('pricevariation')) { + $pricepercentage=GETPOST('pricevariation', 'int'); + if ($pricepercentage == 0) { + setEventMessages($langs->trans("RecordsModified", 0), null); + } else { + foreach ($toselect as $toselectid) { + $result = $object->fetch($toselectid); + //var_dump($contcats);exit; + if ($result > 0) { + if ($obj->price_base_type == 'TTC') { + $newprice = $object->price_ttc * (100 + $pricepercentage) / 100; + $minprice = $object->price_min_ttc; + } else { + $newprice = $object->price * (100 + $pricepercentage) / 100; + $minprice = $object->price_min; + } + $res = $object->updatePrice($newprice, $obj->price_base_type, $user, $object->tva_tx, $minprice, 0, $object->tva_npr, 0, 0, array(), $object->default_vat_code); + if ($res > 0) { + $nbok++; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } else { + setEventMessages($object->error, $object->errors, 'errors'); + $error++; + break; + } + } + } + } + + if (!$error) { + if ($nbok > 0) { + setEventMessages($langs->trans("RecordsModified", $nbok), null); + } + $db->commit(); + $toselect=array(); + } else { + $db->rollback(); + } +} + if (!$error && ($action == 'setsupervisor' && $confirm == 'yes') && $permissiontoadd) { $db->begin(); $supervisortoset=GETPOST('supervisortoset'); diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index f09d7defeb1..74ae317d938 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -78,6 +78,23 @@ if ($massaction == 'preaffecttag' && isModEnabled('category')) { } } +if ($massaction == 'preupdateprice' && isModEnabled('category')) { + $formquestion = array(); + + $valuefield = '
'; + $valuefield .= '%'; + $valuefield .= '
'; + + $formquestion[] = array( + 'type' => 'other', + 'name' => 'pricevariation', + 'label' => $langs->trans("PriceVariation"), + 'value' => $valuefield + ); + + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmUpdatePrice"), $langs->trans("ConfirmUpdatePriceQuestion", count($toselect)), "updateprice", $formquestion, 1, 0, 200, 500, 1); +} + if ($massaction == 'presetsupervisor') { $formquestion = array(); @@ -96,6 +113,7 @@ if ($massaction == 'presetsupervisor') { print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmSetSupervisor"), $langs->trans("ConfirmSetSupervisorQuestion", count($toselect)), "setsupervisor", $formquestion, 1, 0, 200, 500, 1); } + if ($massaction == 'presend') { $langs->load("mails"); diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 325e27b6606..a21d6633718 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1150,9 +1150,12 @@ SetSupervisor=Set Supervisor CreateExternalUser=Create external user ConfirmAffectTag=Bulk Tag Affect ConfirmSetSupervisor=Bulk Supervisor Set +ConfirmUpdatePrice=Choose a price update percentage ConfirmAffectTagQuestion=Are you sure you want to affect tags to the %s selected record(s)? ConfirmSetSupervisorQuestion=Are you sure you want to set supervisor to the %s selected record(s)? +ConfirmUpdatePriceQuestion=Are you sure you want to update the price of the %s selected record(s)? CategTypeNotFound=No tag type found for type of records +PriceVariation=Price variation SupervisorNotFound=Supervisor not found CopiedToClipboard=Copied to clipboard InformationOnLinkToContract=This amount is only the total of all the lines of the contract. No notion of time is taken into consideration. diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index fa2ed9669d9..39f09917d99 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -416,6 +416,7 @@ ProductsMergeSuccess=Products have been merged ErrorsProductsMerge=Errors in products merge SwitchOnSaleStatus=Switch on sale status SwitchOnPurchaseStatus=Switch on purchase status +UpdatePrice=Update price StockMouvementExtraFields= Extra Fields (stock mouvement) InventoryExtraFields= Extra Fields (inventory) ScanOrTypeOrCopyPasteYourBarCodes=Scan or type or copy/paste your barcodes diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 2c376c887bf..c51ee2b09fa 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -566,7 +566,7 @@ None=Aucun NoneF=Aucune NoneOrSeveral=Aucun ou plusieurs Late=Retard -LateDesc=Le délai qui définit si un enregistrement est en retard ou non dépend de votre configuration. Demandez à votre administrateur pour changer ce délai depuis Accueil - Configuration - Alertes +LateDesc=Le délai qui définit si un enregistrement est en retard ou non dépend de votre configuration. Demandez à votre administrateur pour changer ce délai depuis Accueil - Configuration - Alertes NoItemLate=Aucun élément en retard Photo=Photo Photos=Photos @@ -1150,9 +1150,12 @@ SetSupervisor=Choisir un superviseur CreateExternalUser=Créer utilisateur externe ConfirmAffectTag=Affecter les tags en masse ConfirmSetSupervisor=Choisir un superviseur en masse +ConfirmUpdatePrice=Choisir un pourcentage de hausse/baisse des prix ConfirmAffectTagQuestion=Êtes-vous sur de vouloir affecter ces catégories aux %s lignes sélectionnées ? ConfirmSetSupervisorQuestion=Êtes-vous sur de vouloir affecter ce superviseur aux %s lignes sélectionnées ? +ConfirmUpdatePriceQuestion=Êtes-vous sur de vouloir mettre à jour les prix des %s lignes sélectionnées ? CategTypeNotFound=Aucun type de tag trouvé pour ce type d'enregistrements +PriceVariation=Variation de prix SupervisorNotFound=Supervisuer non trouvé CopiedToClipboard=Copié dans le presse-papier InformationOnLinkToContract=Ce montant n’est que le total de toutes les lignes du contrat. Aucune notion de temps n’est prise en considération. diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index 9061f0498fc..4a679dc4bd6 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -416,6 +416,7 @@ ProductsMergeSuccess=Produits fusionnés ErrorsProductsMerge=Erreur lors de la fusion des produits SwitchOnSaleStatus=Basculer le statut En vente SwitchOnPurchaseStatus=Basculer le statut En achat +UpdatePrice=Mettre à jour le prix StockMouvementExtraFields= Champs supplémentaires (mouvement de stock) InventoryExtraFields= Attributs supplémentaires (inventaire) ScanOrTypeOrCopyPasteYourBarCodes=Scannez ou tapez ou copiez/collez vos codes-barres diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 26f6a3a410c..76fba05b5a7 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -310,7 +310,6 @@ if (GETPOST('cancel', 'alpha')) { if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } - $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { @@ -737,11 +736,12 @@ if ($resql) { if ($user->rights->{$rightskey}->creer) { $arrayofmassactions['switchonsalestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnSaleStatus"); $arrayofmassactions['switchonpurchasestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnPurchaseStatus"); + $arrayofmassactions['preupdateprice'] = img_picto('', 'edit', 'class="pictofixedwidth"').$langs->trans("UpdatePrice"); } if (isModEnabled('category') && $user->rights->{$rightskey}->creer) { $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag"); } - if (in_array($massaction, array('presend', 'predelete','preaffecttag', 'edit_extrafields'))) { + if (in_array($massaction, array('presend', 'predelete','preaffecttag', 'edit_extrafields', 'preupdateprice'))) { $arrayofmassactions = array(); } $massactionbutton = $form->selectMassAction('', $arrayofmassactions); From 71e55ab7097dcc3df3ab4f5a1724a3497b02442d Mon Sep 17 00:00:00 2001 From: Faustin Date: Sun, 30 Oct 2022 02:37:56 +0100 Subject: [PATCH 2/2] Translation update --- htdocs/core/actions_massactions.inc.php | 4 ++-- htdocs/core/tpl/massactions_pre.tpl.php | 6 +++--- htdocs/langs/en_US/main.lang | 4 ++-- htdocs/langs/en_US/products.lang | 2 +- htdocs/langs/fr_FR/main.lang | 2 +- htdocs/langs/fr_FR/products.lang | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 7539bb028a4..02d4215b963 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1242,8 +1242,8 @@ if (!$error && ($action == 'affecttag' && $confirm == 'yes') && $permissiontoadd if (!$error && ($action == 'updateprice' && $confirm == 'yes') && $permissiontoadd) { $db->begin(); - if (GETPOSTISSET('pricevariation')) { - $pricepercentage=GETPOST('pricevariation', 'int'); + if (GETPOSTISSET('pricerate')) { + $pricepercentage=GETPOST('pricerate', 'int'); if ($pricepercentage == 0) { setEventMessages($langs->trans("RecordsModified", 0), null); } else { diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index 74ae317d938..1e48fc4d5a0 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -82,13 +82,13 @@ if ($massaction == 'preupdateprice' && isModEnabled('category')) { $formquestion = array(); $valuefield = '
'; - $valuefield .= '%'; + $valuefield .= '%'; $valuefield .= '
'; $formquestion[] = array( 'type' => 'other', - 'name' => 'pricevariation', - 'label' => $langs->trans("PriceVariation"), + 'name' => 'pricerate', + 'label' => $langs->trans("Rate"), 'value' => $valuefield ); diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index a21d6633718..6f849e39be1 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -1150,12 +1150,12 @@ SetSupervisor=Set Supervisor CreateExternalUser=Create external user ConfirmAffectTag=Bulk Tag Affect ConfirmSetSupervisor=Bulk Supervisor Set -ConfirmUpdatePrice=Choose a price update percentage +ConfirmUpdatePrice=Choose a increase/decrease price rate ConfirmAffectTagQuestion=Are you sure you want to affect tags to the %s selected record(s)? ConfirmSetSupervisorQuestion=Are you sure you want to set supervisor to the %s selected record(s)? ConfirmUpdatePriceQuestion=Are you sure you want to update the price of the %s selected record(s)? CategTypeNotFound=No tag type found for type of records -PriceVariation=Price variation +Rate=Rate SupervisorNotFound=Supervisor not found CopiedToClipboard=Copied to clipboard InformationOnLinkToContract=This amount is only the total of all the lines of the contract. No notion of time is taken into consideration. diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 39f09917d99..3d5048d99a9 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -416,7 +416,7 @@ ProductsMergeSuccess=Products have been merged ErrorsProductsMerge=Errors in products merge SwitchOnSaleStatus=Switch on sale status SwitchOnPurchaseStatus=Switch on purchase status -UpdatePrice=Update price +UpdatePrice=Increase/decrease customer price StockMouvementExtraFields= Extra Fields (stock mouvement) InventoryExtraFields= Extra Fields (inventory) ScanOrTypeOrCopyPasteYourBarCodes=Scan or type or copy/paste your barcodes diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index c51ee2b09fa..39d857ae0e8 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -1155,7 +1155,7 @@ ConfirmAffectTagQuestion=Êtes-vous sur de vouloir affecter ces catégories aux ConfirmSetSupervisorQuestion=Êtes-vous sur de vouloir affecter ce superviseur aux %s lignes sélectionnées ? ConfirmUpdatePriceQuestion=Êtes-vous sur de vouloir mettre à jour les prix des %s lignes sélectionnées ? CategTypeNotFound=Aucun type de tag trouvé pour ce type d'enregistrements -PriceVariation=Variation de prix +Rate=Taux SupervisorNotFound=Supervisuer non trouvé CopiedToClipboard=Copié dans le presse-papier InformationOnLinkToContract=Ce montant n’est que le total de toutes les lignes du contrat. Aucune notion de temps n’est prise en considération. diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index 4a679dc4bd6..2592548059c 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -416,7 +416,7 @@ ProductsMergeSuccess=Produits fusionnés ErrorsProductsMerge=Erreur lors de la fusion des produits SwitchOnSaleStatus=Basculer le statut En vente SwitchOnPurchaseStatus=Basculer le statut En achat -UpdatePrice=Mettre à jour le prix +UpdatePrice=Augmenter/baisser le prix de vente StockMouvementExtraFields= Champs supplémentaires (mouvement de stock) InventoryExtraFields= Attributs supplémentaires (inventaire) ScanOrTypeOrCopyPasteYourBarCodes=Scannez ou tapez ou copiez/collez vos codes-barres