From 9be8c579d0aea997b03701beaedd8975971a5265 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 4 Oct 2018 13:30:37 +0200 Subject: [PATCH 1/2] New massaction to generate PDF --- htdocs/compta/facture/list.php | 1 + htdocs/core/actions_massactions.inc.php | 61 +++++++++++++++++++++++++ htdocs/langs/en_US/main.lang | 2 + 3 files changed, 64 insertions(+) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 78576e4c00d..7a708e412c7 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -587,6 +587,7 @@ if ($resql) $arrayofmassactions=array( 'validate'=>$langs->trans("Validate"), + 'generate_doc'=>$langs->trans("Generate"), 'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), ); diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 2bb55264cf9..91ff96a6b00 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -1130,6 +1130,67 @@ if (! $error && ($massaction == 'delete' || ($action == 'delete' && $confirm == //var_dump($listofobjectthirdparties);exit; } +// Generate document foreach object according to model linked to object +// @TODO : propose model selection +if (! $error && $massaction == 'generate_doc' && $permtoread) +{ + $db->begin(); + + $objecttmp=new $objectclass($db); + $nbok = 0; + foreach($toselect as $toselectid) + { + $result=$objecttmp->fetch($toselectid); + if ($result > 0) + { + $outputlangs = $langs; + $newlang=''; + + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) $newlang=$objecttmp->thirdparty->default_lang; // for proposal, order, invoice, ... + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->default_lang)) $newlang=$objecttmp->default_lang; // for thirdparty + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + // To be sure vars is defined + if (empty($hidedetails)) $hidedetails=0; + if (empty($hidedesc)) $hidedesc=0; + if (empty($hideref)) $hideref=0; + if (empty($moreparams)) $moreparams=null; + + $result= $objecttmp->generateDocument($objecttmp->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); + + if ($result <= 0) + { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + else $nbok++; + } + else + { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + } + + if (! $error) + { + if ($nbok > 1) setEventMessages($langs->trans("RecordsGenerated", $nbok), null, 'mesgs'); + else setEventMessages($langs->trans("RecordGenerated", $nbok), null, 'mesgs'); + $db->commit(); + } + else + { + $db->rollback(); + } +} + $parameters['toselect']=$toselect; $parameters['uploaddir']=$uploaddir; diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index fb2f2a8e9fb..2846434f460 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -86,6 +86,7 @@ GoToWikiHelpPage=Read online help (Internet access needed) GoToHelpPage=Read help RecordSaved=Record saved RecordDeleted=Record deleted +RecordGenerated=Record generated LevelOfFeature=Level of features NotDefined=Not defined DolibarrInHttpAuthenticationSoPasswordUseless=Dolibarr authentication mode is set to %s in configuration file conf.php.
This means that the password database is external to Dolibarr, so changing this field may have no effect. @@ -649,6 +650,7 @@ RecordCreatedSuccessfully=Record created successfully RecordModifiedSuccessfully=Record modified successfully RecordsModified=%s record modified RecordsDeleted=%s record deleted +RecordsGenerated=%s record generated AutomaticCode=Automatic code FeatureDisabled=Feature disabled MoveBox=Move widget From d4d921b1ccc522c1447c240b411e1480d3f513c6 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sun, 7 Oct 2018 20:42:45 +0200 Subject: [PATCH 2/2] Add massaction generate on main lists --- htdocs/comm/propal/list.php | 1 + htdocs/commande/list.php | 1 + htdocs/contrat/list.php | 1 + htdocs/expensereport/list.php | 1 + htdocs/fichinter/list.php | 1 + htdocs/fourn/commande/list.php | 1 + htdocs/fourn/facture/list.php | 1 + htdocs/fourn/product/list.php | 1 + htdocs/product/list.php | 1 + htdocs/projet/list.php | 1 + htdocs/supplier_proposal/list.php | 1 + 11 files changed, 11 insertions(+) diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index dc6e4aff17b..e5995244302 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -453,6 +453,7 @@ if ($resql) // List of mass actions available $arrayofmassactions = array( + 'generate_doc'=>$langs->trans("Generate"), 'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), ); diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 558d8186a86..faba02b511d 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -438,6 +438,7 @@ if ($resql) // List of mass actions available $arrayofmassactions = array( + 'generate_doc'=>$langs->trans("Generate"), 'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), 'cancelorders'=>$langs->trans("Cancel"), diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 96f20fdaf67..815c0f10567 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -364,6 +364,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; // List of mass actions available $arrayofmassactions = array( + 'generate_doc'=>$langs->trans("Generate"), 'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), ); diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index d328cd21de2..f820ca8eea1 100644 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -359,6 +359,7 @@ if ($resql) // List of mass actions available $arrayofmassactions = array( + 'generate_doc'=>$langs->trans("Generate"), 'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), ); diff --git a/htdocs/fichinter/list.php b/htdocs/fichinter/list.php index 96a1199255c..8acf580ac78 100644 --- a/htdocs/fichinter/list.php +++ b/htdocs/fichinter/list.php @@ -269,6 +269,7 @@ if ($resql) // List of mass actions available $arrayofmassactions = array( + 'generate_doc'=>$langs->trans("Generate"), //'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), ); diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index 06857526731..b947840c91c 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -636,6 +636,7 @@ if ($resql) // List of mass actions available $arrayofmassactions = array( + 'generate_doc'=>$langs->trans("Generate"), 'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), ); diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index 3fa525415bb..e8a35e62804 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -466,6 +466,7 @@ if ($resql) // List of mass actions available $arrayofmassactions = array( 'validate'=>$langs->trans("Validate"), + 'generate_doc'=>$langs->trans("Generate"), //'presend'=>$langs->trans("SendByMail"), //'builddoc'=>$langs->trans("PDFMerge"), ); diff --git a/htdocs/fourn/product/list.php b/htdocs/fourn/product/list.php index 9927b6b2b5d..56cb4cc2b01 100644 --- a/htdocs/fourn/product/list.php +++ b/htdocs/fourn/product/list.php @@ -117,6 +117,7 @@ if ($fourn_id) $arrayofmassactions = array( + 'generate_doc'=>$langs->trans("Generate"), 'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), ); diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 28f08035198..3452efddd72 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -403,6 +403,7 @@ if ($resql) // List of mass actions available $arrayofmassactions = array( + 'generate_doc'=>$langs->trans("Generate"), //'presend'=>$langs->trans("SendByMail"), //'builddoc'=>$langs->trans("PDFMerge"), ); diff --git a/htdocs/projet/list.php b/htdocs/projet/list.php index a93fac0edbd..c0bdf351c4d 100644 --- a/htdocs/projet/list.php +++ b/htdocs/projet/list.php @@ -438,6 +438,7 @@ include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; // List of mass actions available $arrayofmassactions = array( + 'generate_doc'=>$langs->trans("Generate"), // 'presend'=>$langs->trans("SendByMail"), // 'builddoc'=>$langs->trans("PDFMerge"), ); diff --git a/htdocs/supplier_proposal/list.php b/htdocs/supplier_proposal/list.php index 2fcb296b433..4a65a3b6b65 100644 --- a/htdocs/supplier_proposal/list.php +++ b/htdocs/supplier_proposal/list.php @@ -381,6 +381,7 @@ if ($resql) // List of mass actions available $arrayofmassactions = array( + 'generate_doc'=>$langs->trans("Generate"), //'presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"), );