Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2023-08-02 16:19:24 +02:00
commit e7c2dcead6
2 changed files with 65 additions and 1 deletions

View file

@ -72,8 +72,10 @@ $bon = new BonPrelevement($db);
$hookmanager->initHooks(array('withdrawalsreceiptslist'));
$usercancreate = $user->rights->prelevement->bons->creer;
$permissiontodelete = $user->hasRight('prelevement', 'creer');
if ($type == 'bank-transfer') {
$usercancreate = $user->rights->paymentbybanktransfer->create;
$permissiontodelete = $user->hasRight('paymentbybanktransfer', 'create');
}
// Security check
@ -97,6 +99,61 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
$search_amount = "";
}
// Mass actions
// Delete draft
if (($massaction == "delete" || ($action == 'delete' && $confirm == 'yes')) && $permissiontodelete) {
$db->begin();
$objecttmp = new BonPrelevement($db);
foreach ($toselect as $toselectid) {
$result = $objecttmp->fetch($toselectid);
if ($result > 0) {
if ($objecttmp->status != $objecttmp::STATUS_DRAFT || $objecttmp->credite > 0 || $objecttmp->date_creation != null) {
$langs->load("errors");
$nbignored++;
$TMsg[] = '<div class="error">'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).'</div><br>';
continue;
}
$result = $objecttmp->delete($user);
if ($result < 0) { // if delete returns is < 0, there is an error, we break and rollback later
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
} else {
$nbok++;
}
} else {
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
}
}
if (empty($error)) {
// Message for elements well deleted
if ($nbok > 1) {
setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
} elseif ($nbok > 0) {
setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
} else {
setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
}
// Message for elements which can't be deleted
if (!empty($TMsg)) {
sort($TMsg);
setEventMessages('', array_unique($TMsg), 'warnings');
}
$db->commit();
} else {
$db->rollback();
}
$massaction = '';
}
$objectclass = 'BonPrelevement';
$objectlabel = 'BonPrelevement';
$uploaddir = $conf->prelevement->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
/*
* View
@ -194,6 +251,9 @@ $arrayofmassactions = array(
//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
);
if (!empty($permissiontodelete)) {
$arrayofmassactions['predeletedraft'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
@ -221,7 +281,10 @@ if ($usercancreate) {
$newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type='.urlencode($type));
}
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1);
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'generic', 0, $newcardbutton, '', $limit, 0, 0, 1);
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
$moreforfilter = '';
/*$moreforfilter.='<div class="divsearchfield">';

View file

@ -164,3 +164,4 @@ TaxUndefinedForThisCategory = Taxe undefined for this category
ErrorRecordNotFound=Record not found
errorComputeTtcOnMileageExpense=Error on computing mileage expense
ErrorBadValueForParameter=Error bad value for parameter %s
ErrorOnlyDraftStatusCanBeDeletedInMassAction=Error only draft status can be deleted in mass action