From 17b8de2cdd420a33629c2ee8848e5397a8bcce6d Mon Sep 17 00:00:00 2001 From: Abbes Bahfir Date: Sat, 5 May 2018 12:52:38 +0100 Subject: [PATCH 1/4] New : Option INVOICE_CAN_REMOVE_DRAFT_ONLY to delete draft invoices with precedence over INVOICE_CAN_ALWAYS_BE_REMOVED --- htdocs/compta/facture/list.php | 34 ++++++++++++------------- htdocs/core/actions_massactions.inc.php | 28 +++++++------------- htdocs/core/tpl/massactions_pre.tpl.php | 5 ++++ htdocs/langs/en_US/main.lang | 4 ++- htdocs/langs/fr_FR/main.lang | 2 ++ 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 29a98c0541b..c90ab660c31 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -585,24 +585,22 @@ if ($resql) 'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), ); - if ($conf->prelevement->enabled) - { - $langs->load("withdrawals"); - $arrayofmassactions['withdrawrequest']=$langs->trans("MakeWithdrawRequest"); - } - if ($user->rights->facture->supprimer) - { - //if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) || empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) - if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) - { - // mass deletion never possible on invoices on such situation - } - else - { - $arrayofmassactions['predelete']=$langs->trans("Delete"); - } - } - if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array(); + if ($conf->prelevement->enabled) { + $langs->load("withdrawals"); + $arrayofmassactions['withdrawrequest'] = $langs->trans("MakeWithdrawRequest"); + } + if ($user->rights->facture->supprimer) { + //if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) || empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) + if (!empty($conf->global->INVOICE_CAN_REMOVE_DRAFT_ONLY)) { + $arrayofmassactions['predeletedraft'] = $langs->trans("Deletedraft"); + + } + elseif (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) { + // mass deletion never possible on invoices on such situation + $arrayofmassactions['predelete'] = $langs->trans("Delete"); + } + } + if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); $massactionbutton=$form->selectMassAction('', $arrayofmassactions); $newcardbutton=''; diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index c2c3467e55c..1952bb0c224 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1079,26 +1079,16 @@ if (! $error && ($massaction == 'delete' || ($action == 'delete' && $confirm == $result=$objecttmp->fetch($toselectid); if ($result > 0) { - // Refuse deletion for some status ? - /* - if ($objectclass == 'Facture' && $objecttmp->status == Facture::STATUS_DRAFT) - { - $langs->load("errors"); - $nbignored++; - $resaction.='
'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction',$objecttmp->ref).'

'; - continue; - }*/ + if ($objectclass != 'Facture' || empty($conf->global->INVOICE_CAN_REMOVE_DRAFT_ONLY) || (!empty($conf->global->INVOICE_CAN_REMOVE_DRAFT_ONLY) && $objecttmp->statut == Facture::STATUS_DRAFT) ) { + if (in_array($objecttmp->element, array('societe', 'member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1); + else $result = $objecttmp->delete($user); - if (in_array($objecttmp->element, array('societe','member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1); - else $result = $objecttmp->delete($user); - - if ($result <= 0) - { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } - else $nbok++; + if ($result <= 0) { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } else $nbok++; + } } else { diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index 48989b2daec..d46e27e28af 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -27,6 +27,11 @@ // $trackid='ord'.$object->id; +if ($massaction == 'predeletedraft') +{ + print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDraftDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1); +} + if ($massaction == 'predelete') { print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassDeletion"), $langs->trans("ConfirmMassDeletionQuestion", count($toselect)), "delete", null, '', 0, 200, 500, 1); diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 418042f1da9..60369b80ea5 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -941,4 +941,6 @@ Local=Local Remote=Remote LocalAndRemote=Local and Remote KeyboardShortcut=Keyboard shortcut -AssignedTo=Assigned to \ No newline at end of file +AssignedTo=Assigned to +Deletedraft=Delete draft +ConfirmMassDraftDeletion=Draft Bulk delete confirmation diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index e8681e72e62..6fba224525e 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -941,3 +941,5 @@ Remote=Distant LocalAndRemote=Local et distant KeyboardShortcut=Raccourci clavier AssignedTo=Assigné à +Deletedraft=Supprimer brouillon +ConfirmMassDraftDeletion=Confirmation de suppression brouillons en masse From aba2ef7ad290b239dc87324625c611874bebc0c1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 5 May 2018 14:22:18 +0200 Subject: [PATCH 2/4] Update actions_massactions.inc.php --- htdocs/core/actions_massactions.inc.php | 26 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 1952bb0c224..e1d862b6098 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1079,16 +1079,24 @@ if (! $error && ($massaction == 'delete' || ($action == 'delete' && $confirm == $result=$objecttmp->fetch($toselectid); if ($result > 0) { - if ($objectclass != 'Facture' || empty($conf->global->INVOICE_CAN_REMOVE_DRAFT_ONLY) || (!empty($conf->global->INVOICE_CAN_REMOVE_DRAFT_ONLY) && $objecttmp->statut == Facture::STATUS_DRAFT) ) { - if (in_array($objecttmp->element, array('societe', 'member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1); - else $result = $objecttmp->delete($user); + // Refuse deletion for some objects/status + if ($objectclass == 'Facture' && empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $objecttmp->status != Facture::STATUS_DRAFT)) + { + $langs->load("errors"); + $nbignored++; + $resaction.='
'.$langs->trans('ErrorOnlyDraftStatusCanBeDeletedInMassAction',$objecttmp->ref).'

'; + continue; + } + + if (in_array($objecttmp->element, array('societe', 'member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1); + else $result = $objecttmp->delete($user); + + if ($result <= 0) { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } else $nbok++; - if ($result <= 0) { - setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); - $error++; - break; - } else $nbok++; - } } else { From 8baa529719d2352ed98ffadd896b311a665e0a5f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 5 May 2018 14:22:52 +0200 Subject: [PATCH 3/4] Update actions_massactions.inc.php --- htdocs/core/actions_massactions.inc.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index e1d862b6098..4d2b6145990 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1091,12 +1091,13 @@ if (! $error && ($massaction == 'delete' || ($action == 'delete' && $confirm == if (in_array($objecttmp->element, array('societe', 'member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1); else $result = $objecttmp->delete($user); - if ($result <= 0) { + if ($result <= 0) + { setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); $error++; break; - } else $nbok++; - + } + else $nbok++; } else { From 97f161b2763767ae376760f2e4922a8e65c85150 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 5 May 2018 14:25:44 +0200 Subject: [PATCH 4/4] Update list.php --- htdocs/compta/facture/list.php | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index c90ab660c31..b6bde6605ad 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -585,22 +585,19 @@ if ($resql) 'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), ); - if ($conf->prelevement->enabled) { - $langs->load("withdrawals"); - $arrayofmassactions['withdrawrequest'] = $langs->trans("MakeWithdrawRequest"); - } - if ($user->rights->facture->supprimer) { - //if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) || empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) - if (!empty($conf->global->INVOICE_CAN_REMOVE_DRAFT_ONLY)) { - $arrayofmassactions['predeletedraft'] = $langs->trans("Deletedraft"); - - } - elseif (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) { - // mass deletion never possible on invoices on such situation - $arrayofmassactions['predelete'] = $langs->trans("Delete"); - } - } - if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); + if ($conf->prelevement->enabled) { + $langs->load("withdrawals"); + $arrayofmassactions['withdrawrequest'] = $langs->trans("MakeWithdrawRequest"); + } + if ($user->rights->facture->supprimer) { + if (!empty($conf->global->INVOICE_CAN_REMOVE_DRAFT_ONLY)) { + $arrayofmassactions['predeletedraft'] = $langs->trans("Deletedraft"); + } + elseif (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) { // mass deletion never possible on invoices on such situation + $arrayofmassactions['predelete'] = $langs->trans("Delete"); + } + } + if (in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array(); $massactionbutton=$form->selectMassAction('', $arrayofmassactions); $newcardbutton='';