Merge pull request #22710 from fboitel/NEW#22676-massaction-product-list

NEW #22676 : massaction for updating product prices
This commit is contained in:
Laurent Destailleur 2022-11-01 21:05:21 +01:00 committed by GitHub
commit 30375fc769
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 3 deletions

View File

@ -1240,6 +1240,50 @@ if (!$error && ($action == 'affecttag' && $confirm == 'yes') && $permissiontoadd
}
}
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');

View File

@ -78,6 +78,23 @@ if ($massaction == 'preaffecttag' && isModEnabled('category')) {
}
}
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();
@ -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");

View File

@ -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.

View File

@ -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

View File

@ -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
Rate=Taux
SupervisorNotFound=Supervisuer non trouvé
CopiedToClipboard=Copié dans le presse-papier
InformationOnLinkToContract=Ce montant nest que le total de toutes les lignes du contrat. Aucune notion de temps nest prise en considération.

View File

@ -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

View File

@ -311,7 +311,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) {
@ -741,11 +740,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);