From 2c6d11e040d1dee27e8c40889dc0835eb934a3e1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Jan 2021 10:42:43 +0100 Subject: [PATCH] When creating invoice by mass action, message has link to invoice --- htdocs/core/actions_massactions.inc.php | 25 +++++++++++++++++++----- htdocs/fourn/commande/list.php | 26 +++++++++++++++++++------ htdocs/langs/en_US/bills.lang | 3 ++- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 81cc4d81bd4..403c8c52a42 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -590,7 +590,8 @@ if (!$error && $massaction == 'confirm_presend') } } -if ($massaction == 'confirm_createbills') // Create bills from orders +// TODO Move this action into commande/list.php if called only by this page. +if ($massaction == 'confirm_createbills') // Create bills from orders. { $orders = GETPOST('toselect', 'array'); $createbills_onebythird = GETPOST('createbills_onebythird', 'int'); @@ -600,6 +601,8 @@ if ($massaction == 'confirm_createbills') // Create bills from orders $TFactThird = array(); $nb_bills_created = 0; + $lastid= 0; + $lastref = ''; $db->begin(); @@ -609,8 +612,9 @@ if ($massaction == 'confirm_createbills') // Create bills from orders if ($cmd->fetch($id_order) <= 0) continue; $objecttmp = new Facture($db); - if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. - else { + if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) { + $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. + } else { // Load extrafields of order $cmd->fetch_optionals(); @@ -636,7 +640,11 @@ if ($massaction == 'confirm_createbills') // Create bills from orders $res = $objecttmp->create($user); - if ($res > 0) $nb_bills_created++; + if ($res > 0) { + $nb_bills_created++; + $lastref = $objecttmp->ref; + $lastid = $objecttmp->id; + } } if ($objecttmp->id > 0) @@ -818,7 +826,14 @@ if ($massaction == 'confirm_createbills') // Create bills from orders if (!$error) { $db->commit(); - setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs'); + + if ($nb_bills_created == 1) { + $texttoshow = $langs->trans('BillXCreated', '{s1}'); + $texttoshow = str_replace('{s1}', ''.$lastref.'', $texttoshow); + setEventMessages($texttoshow, null, 'mesgs'); + } else { + setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs'); + } // Make a redirect to avoid to bill twice if we make a refresh or back $param = ''; diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index 2b77801fee3..14a9a9e6f19 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -244,7 +244,7 @@ if (empty($reshook)) $uploaddir = $conf->fournisseur->commande->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; - // TODO Move this into mass action include + // Mass action to generate vendor bills if ($massaction == 'confirm_createsupplierbills') { $orders = GETPOST('toselect', 'array'); @@ -255,6 +255,8 @@ if (empty($reshook)) $TFactThird = array(); $nb_bills_created = 0; + $lastid = 0; + $lastref = ''; $db->begin(); @@ -263,8 +265,9 @@ if (empty($reshook)) if ($cmd->fetch($id_order) <= 0) continue; $objecttmp = new FactureFournisseur($db); - if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. - else { + if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) { + $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. + } else { $objecttmp->socid = $cmd->socid; $objecttmp->type = $objecttmp::TYPE_STANDARD; $objecttmp->cond_reglement_id = $cmd->cond_reglement_id; @@ -285,7 +288,11 @@ if (empty($reshook)) $res = $objecttmp->create($user); - if ($res > 0) $nb_bills_created++; + if ($res > 0) { + $nb_bills_created++; + $lastref = $objecttmp->ref; + $lastid = $objecttmp->id; + } } if ($objecttmp->id > 0) @@ -442,7 +449,14 @@ if (empty($reshook)) if (!$error) { $db->commit(); - setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs'); + + if ($nb_bills_created == 1) { + $texttoshow = $langs->trans('BillXCreated', '{s1}'); + $texttoshow = str_replace('{s1}', ''.$lastref.'', $texttoshow); + setEventMessages($texttoshow, null, 'mesgs'); + } else { + setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs'); + } // Make a redirect to avoid to bill twice if we make a refresh or back $param = ''; @@ -459,7 +473,7 @@ if (empty($reshook)) if ($search_deliveryyear) $param .= '&search_deliveryyear='.urlencode($search_deliveryyear); if ($search_ref) $param .= '&search_ref='.urlencode($search_ref); if ($search_company) $param .= '&search_company='.urlencode($search_company); - if ($search_ref_customer) $param .= '&search_ref_customer='.urlencode($search_ref_customer); + //if ($search_ref_customer) $param .= '&search_ref_customer='.urlencode($search_ref_customer); if ($search_user > 0) $param .= '&search_user='.urlencode($search_user); if ($search_sale > 0) $param .= '&search_sale='.urlencode($search_sale); if ($search_total_ht != '') $param .= '&search_total_ht='.urlencode($search_total_ht); diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 76ea80b53c8..88f4c59a28d 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -562,7 +562,8 @@ ToCreateARecurringInvoiceGeneAuto=If you need to have such invoices generated au DeleteRepeatableInvoice=Delete template invoice ConfirmDeleteRepeatableInvoice=Are your sure you want to delete the template invoice? CreateOneBillByThird=Create one invoice per third party (otherwise, one invoice per order) -BillCreated=%s bill(s) created +BillCreated=%s invoice(s) generated +BillXCreated=Invoice %s generated StatusOfGeneratedDocuments=Status of document generation DoNotGenerateDoc=Do not generate document file AutogenerateDoc=Auto generate document file