Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW #22676 : massaction for updating product prices #22710

Merged
merged 2 commits into from Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 44 additions & 0 deletions htdocs/core/actions_massactions.inc.php
Expand Up @@ -1240,6 +1240,50 @@
}
}

if (!$error && ($action == 'updateprice' && $confirm == 'yes') && $permissiontoadd) {
$db->begin();
if (GETPOSTISSET('pricerate')) {
$pricepercentage=GETPOST('pricerate', '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');
Expand Down
18 changes: 18 additions & 0 deletions htdocs/core/tpl/massactions_pre.tpl.php
Expand Up @@ -78,6 +78,23 @@
}
}

if ($massaction == 'preupdateprice' && isModEnabled('category')) {
$formquestion = array();

$valuefield = '<div style="display: flex; align-items: center; justify-content: flex-end; padding-right: 150px">';
$valuefield .= '<input type="number" name="pricerate" id="pricerate" min="-100" value="0" style="width: 100px; text-align: right; margin-right: 10px" />%';
$valuefield .= '</div>';

$formquestion[] = array(
'type' => 'other',
'name' => 'pricerate',
'label' => $langs->trans("Rate"),
'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();

Expand All @@ -96,6 +113,7 @@
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");

Expand Down
3 changes: 3 additions & 0 deletions htdocs/langs/en_US/main.lang
Expand Up @@ -1150,9 +1150,12 @@ SetSupervisor=Set Supervisor
CreateExternalUser=Create external user
ConfirmAffectTag=Bulk Tag Affect
ConfirmSetSupervisor=Bulk Supervisor Set
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
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.
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/products.lang
Expand Up @@ -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=Increase/decrease customer price
StockMouvementExtraFields= Extra Fields (stock mouvement)
InventoryExtraFields= Extra Fields (inventory)
ScanOrTypeOrCopyPasteYourBarCodes=Scan or type or copy/paste your barcodes
Expand Down
5 changes: 4 additions & 1 deletion htdocs/langs/fr_FR/main.lang
Expand Up @@ -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
Expand Down Expand Up @@ -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
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.
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/fr_FR/products.lang
Expand Up @@ -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=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
Expand Down
4 changes: 2 additions & 2 deletions htdocs/product/list.php
Expand Up @@ -310,7 +310,6 @@
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) {
Expand Down Expand Up @@ -737,11 +736,12 @@
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);
Expand Down