diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php
index 98ff1c45194..e6cd028b036 100644
--- a/htdocs/comm/propal/list.php
+++ b/htdocs/comm/propal/list.php
@@ -462,6 +462,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 f26d7b86b44..428c4745e8a 100644
--- a/htdocs/commande/list.php
+++ b/htdocs/commande/list.php
@@ -449,6 +449,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/compta/facture/list.php b/htdocs/compta/facture/list.php
index 2a50103e062..70e2120590a 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -595,6 +595,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/contrat/list.php b/htdocs/contrat/list.php
index 056362bb2d2..07c18ad42f9 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/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php
index b56f40c269d..a71629e947d 100644
--- a/htdocs/core/actions_massactions.inc.php
+++ b/htdocs/core/actions_massactions.inc.php
@@ -1169,6 +1169,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/expensereport/list.php b/htdocs/expensereport/list.php
index b2b8e46d668..317614afc4c 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 c26e642a651..85f92f55f85 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 729899a8ff2..6eec51fa809 100644
--- a/htdocs/fourn/commande/list.php
+++ b/htdocs/fourn/commande/list.php
@@ -647,6 +647,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 9a53b31c8a1..153054f8e95 100644
--- a/htdocs/fourn/facture/list.php
+++ b/htdocs/fourn/facture/list.php
@@ -477,6 +477,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 16ed559814d..7a623e2cba2 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/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang
index 47cdb28693d..b696ee5ba5f 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.
@@ -650,8 +651,9 @@ ValueIsValid=Value is valid
ValueIsNotValid=Value is not valid
RecordCreatedSuccessfully=Record created successfully
RecordModifiedSuccessfully=Record modified successfully
-RecordsModified=%s record(s) modified
-RecordsDeleted=%s record(s) deleted
+RecordsModified=%s record modified
+RecordsDeleted=%s record deleted
+RecordsGenerated=%s record generated
AutomaticCode=Automatic code
FeatureDisabled=Feature disabled
MoveBox=Move widget
diff --git a/htdocs/product/list.php b/htdocs/product/list.php
index dda8cf267c9..323d21e5629 100644
--- a/htdocs/product/list.php
+++ b/htdocs/product/list.php
@@ -417,6 +417,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 b220af0d96a..e36a000674b 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 795564984d4..5986ac65f14 100644
--- a/htdocs/supplier_proposal/list.php
+++ b/htdocs/supplier_proposal/list.php
@@ -396,6 +396,7 @@ if ($resql)
// List of mass actions available
$arrayofmassactions = array(
+ 'generate_doc'=>$langs->trans("Generate"),
//'presend'=>$langs->trans("SendByMail"),
'builddoc'=>$langs->trans("PDFMerge"),
);