New massaction to generate PDF

This commit is contained in:
Maxime Kohlhaas 2018-10-04 13:30:37 +02:00
parent 278910b66b
commit 9be8c579d0
3 changed files with 64 additions and 0 deletions

View File

@ -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"),
);

View File

@ -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;

View File

@ -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 <b>%s</b> in configuration file <b>conf.php</b>.<br>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