2
0
forked from Wavyzz/dolibarr

FIX Can use odx templates that does not include lines tags

This commit is contained in:
Laurent Destailleur
2018-02-24 12:32:48 +01:00
parent e68612fa09
commit cbfe241c1b
7 changed files with 287 additions and 198 deletions

View File

@@ -392,7 +392,18 @@ class doc_generic_order_odt extends ModelePDFCommandes
// Replace tags of lines
try
{
$foundtagforlines = 1;
try {
$listlines = $odfHandler->setSegment('lines');
}
catch(OdfException $e)
{
// We may arrive here if tags for lines not present into template
$foundtagforlines = 0;
dol_syslog($e->getMessage(), LOG_INFO);
}
if ($foundtagforlines)
{
foreach ($object->lines as $line)
{
$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
@@ -417,6 +428,7 @@ class doc_generic_order_odt extends ModelePDFCommandes
}
$odfHandler->mergeSegment($listlines);
}
}
catch(OdfException $e)
{
$this->error=$e->getMessage();

View File

@@ -290,17 +290,38 @@ class doc_generic_contract_odt extends ModelePDFContract
{
$socobject=$object->thirdparty;
}
// Make substitution
$substitutionarray=array(
'__FROM_NAME__' => $this->emetteur->name,
'__FROM_EMAIL__' => $this->emetteur->email,
'__TOTAL_TTC__' => $object->total_ttc,
'__TOTAL_HT__' => $object->total_ht,
'__TOTAL_VAT__' => $object->total_vat
);
complete_substitutions_array($substitutionarray, $langs, $object);
$object->fetch_optionals();
// Define substitution array
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
/* deprecated
$substitutionarray['__FROM_NAME__'] = $this->emetteur->name;
$substitutionarray['__FROM_EMAIL__'] = $this->emetteur->email;
$substitutionarray['__TOTAL_TTC__'] = $object->total_ttc;
$substitutionarray['__TOTAL_HT__'] = $object->total_ht;
$substitutionarray['__TOTAL_VAT__'] = $object->total_vat;
*/
// Make substitutions into ODT
$array_contract=$this->get_substitutionarray_each_var_object($object, $outputlangs);
$array_user=$this->get_substitutionarray_user($user,$outputlangs);
$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
$array_objet=$this->get_substitutionarray_object($object,$outputlangs);
$array_other=$this->get_substitutionarray_other($outputlangs);
// retrieve contact information for use in contract as contact_xxx tags
$array_thirdparty_contact = array();
if ($usecontact) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
$substitutionarray = array_merge($substitutionarray,$array_contract,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact);
complete_substitutions_array($substitutionarray, $outputlangs, $object);
$tmparray = $substitutionarray;
// Call the ODTSubstitution hook
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray);
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
// Line of free text
@@ -311,6 +332,7 @@ class doc_generic_contract_odt extends ModelePDFContract
$newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray);
}
// Open and load template
require_once ODTPHP_PATH.'odf.php';
try {
@@ -344,24 +366,6 @@ class doc_generic_contract_odt extends ModelePDFContract
{
}
// Make substitutions into odt
$array_contract=$this->get_substitutionarray_each_var_object($object, $outputlangs);
$array_user=$this->get_substitutionarray_user($user,$outputlangs);
$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
$array_objet=$this->get_substitutionarray_object($object,$outputlangs);
$array_other=$this->get_substitutionarray_other($outputlangs);
// retrieve contact information for use in contract as contact_xxx tags
$array_thirdparty_contact = array();
if ($usecontact)
$array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
$tmparray = array_merge($array_contract,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact);
complete_substitutions_array($tmparray, $outputlangs, $object);
$object->fetch_optionals();
// Call the ODTSubstitution hook
$parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);
$reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
foreach($tmparray as $key=>$value)
{
try {
@@ -379,10 +383,22 @@ class doc_generic_contract_odt extends ModelePDFContract
{
}
}
// Replace tags of lines
try
{
$foundtagforlines = 1;
try {
$listlines = $odfHandler->setSegment('lines');
}
catch(OdfException $e)
{
// We may arrive here if tags for lines not present into template
$foundtagforlines = 0;
dol_syslog($e->getMessage(), LOG_INFO);
}
if ($foundtagforlines)
{
foreach ($object->lines as $line)
{
$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
@@ -407,6 +423,7 @@ class doc_generic_contract_odt extends ModelePDFContract
}
$odfHandler->mergeSegment($listlines);
}
}
catch(OdfException $e)
{
$this->error=$e->getMessage();

View File

@@ -437,7 +437,18 @@ class doc_generic_shipment_odt extends ModelePdfExpedition
// Replace tags of lines
try
{
$foundtagforlines = 1;
try {
$listlines = $odfHandler->setSegment('lines');
}
catch(OdfException $e)
{
// We may arrive here if tags for lines not present into template
$foundtagforlines = 0;
dol_syslog($e->getMessage(), LOG_INFO);
}
if ($foundtagforlines)
{
foreach ($object->lines as $line)
{
$tmparray=$this->get_substitutionarray_shipment_lines($line,$outputlangs);
@@ -462,6 +473,7 @@ class doc_generic_shipment_odt extends ModelePdfExpedition
}
$odfHandler->mergeSegment($listlines);
}
}
catch(OdfException $e)
{
$this->error=$e->getMessage();

View File

@@ -401,7 +401,18 @@ class doc_generic_invoice_odt extends ModelePDFFactures
// Replace tags of lines
try
{
$foundtagforlines = 1;
try {
$listlines = $odfHandler->setSegment('lines');
}
catch(OdfException $e)
{
// We may arrive here if tags for lines not present into template
$foundtagforlines = 0;
dol_syslog($e->getMessage(), LOG_INFO);
}
if ($foundtagforlines)
{
foreach ($object->lines as $line)
{
$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
@@ -426,6 +437,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
}
$odfHandler->mergeSegment($listlines);
}
}
catch(OdfException $e)
{
$this->error=$e->getMessage();

View File

@@ -421,7 +421,18 @@ class doc_generic_proposal_odt extends ModelePDFPropales
// Replace tags of lines
try
{
$foundtagforlines = 1;
try {
$listlines = $odfHandler->setSegment('lines');
}
catch(OdfException $e)
{
// We may arrive here if tags for lines not present into template
$foundtagforlines = 0;
dol_syslog($e->getMessage(), LOG_INFO);
}
if ($foundtagforlines)
{
foreach ($object->lines as $line)
{
$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
@@ -446,6 +457,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales
}
$odfHandler->mergeSegment($listlines);
}
}
catch(OdfException $e)
{
$this->error=$e->getMessage();

View File

@@ -413,7 +413,18 @@ class doc_generic_supplier_proposal_odt extends ModelePDFSupplierProposal
// Replace tags of lines
try
{
$foundtagforlines = 1;
try {
$listlines = $odfHandler->setSegment('lines');
}
catch(OdfException $e)
{
// We may arrive here if tags for lines not present into template
$foundtagforlines = 0;
dol_syslog($e->getMessage(), LOG_INFO);
}
if ($foundtagforlines)
{
foreach ($object->lines as $line)
{
$tmparray=$this->get_substitutionarray_lines($line,$outputlangs);
@@ -438,6 +449,7 @@ class doc_generic_supplier_proposal_odt extends ModelePDFSupplierProposal
}
$odfHandler->mergeSegment($listlines);
}
}
catch(OdfException $e)
{
$this->error=$e->getMessage();

View File

@@ -408,7 +408,18 @@ class doc_generic_usergroup_odt extends ModelePDFUserGroup
// Replace tags of lines
try
{
$foundtagforlines = 1;
try {
$listlines = $odfHandler->setSegment('lines');
}
catch(OdfException $e)
{
// We may arrive here if tags for lines not present into template
$foundtagforlines = 0;
dol_syslog($e->getMessage(), LOG_INFO);
}
if ($foundtagforlines)
{
foreach ($object->members as $u)
{
$tmparray=$this->get_substitutionarray_each_var_object($u,$outputlangs);
@@ -437,6 +448,7 @@ class doc_generic_usergroup_odt extends ModelePDFUserGroup
}
$odfHandler->mergeSegment($listlines);
}
}
catch(OdfException $e)
{
$this->error=$e->getMessage();