From 38d1fc27e0edfccebfff6e02649f761f5490a34f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Feb 2018 13:41:01 +0100 Subject: [PATCH] Start to introduce common substitution rules for odt substitutions --- .../core/class/commondocgenerator.class.php | 4 ++-- .../doc/doc_generic_order_odt.modules.php | 17 ++++++------- .../doc/doc_generic_contract_odt.modules.php | 15 +++--------- .../doc/doc_generic_invoice_odt.modules.php | 16 +++++++------ .../doc/doc_generic_product_odt.modules.php | 24 ++++++++++--------- .../doc/doc_generic_project_odt.modules.php | 19 ++++++++------- .../task/doc/doc_generic_task_odt.modules.php | 11 +++++---- .../doc/doc_generic_proposal_odt.modules.php | 19 ++++++++------- ..._generic_supplier_proposal_odt.modules.php | 9 ++++--- 9 files changed, 69 insertions(+), 65 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index c9c250ee1fa..dd296429d58 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -349,8 +349,8 @@ abstract class CommonDocGenerator $array_key.'_id'=>$object->id, $array_key.'_ref'=>$object->ref, $array_key.'_ref_ext'=>$object->ref_ext, - $array_key.'_ref_customer'=>$object->ref_client, - $array_key.'_ref_supplier'=>(! empty($object->ref_fournisseur)?$object->ref_fournisseur:''), + $array_key.'_ref_customer'=>(! empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)), + $array_key.'_ref_supplier'=>(! empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)), $array_key.'_source_invoice_ref'=>$invoice_source->ref, // Dates $array_key.'_hour'=>dol_print_date($object->date,'hour'), diff --git a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php index 0fb5dbabc03..8178af40c37 100644 --- a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php +++ b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php @@ -354,21 +354,22 @@ class doc_generic_order_odt extends ModelePDFCommandes { } - // Make substitutions into odt + // Define substitution array + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + $array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs); + $array_objet=$this->get_substitutionarray_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 order as contact_xxx tags - $array_thirdparty_contact = array(); - if ($usecontact) - $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); + // retrieve contact information for use in order as contact_xxx tags + $array_thirdparty_contact = array(); + if ($usecontact) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); - $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact); + $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact); complete_substitutions_array($tmparray, $outputlangs, $object); - // Call the ODTSubstitution hook + // Call the ODTSubstitution hook $parameters=array('odfHandler'=>&$odfHandler,'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 diff --git a/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php b/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php index 8eca65f62ec..ff7abbca53a 100644 --- a/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php +++ b/htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php @@ -296,26 +296,17 @@ class doc_generic_contract_odt extends ModelePDFContract // 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_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs); + $array_objet=$this->get_substitutionarray_object($object,$outputlangs); // complete with vars not set as properties by get_substitutionarray_each_var_object $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); + $substitutionarray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact); complete_substitutions_array($substitutionarray, $outputlangs, $object); $tmparray = $substitutionarray; diff --git a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php index c9f18218d9a..6d9d5172a7f 100644 --- a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -361,20 +361,22 @@ class doc_generic_invoice_odt extends ModelePDFFactures { } - // Make substitutions into odt + // Define substitution array + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + $array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs); + $array_objet=$this->get_substitutionarray_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_propal=is_object($propal_object)?$this->get_substitutionarray_object($propal_object,$outputlangs,'propal'):array(); $array_other=$this->get_substitutionarray_other($outputlangs); - // retrieve contact information for use in invoice as contact_xxx tags - $array_thirdparty_contact = array(); - if ($usecontact) - $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); + // retrieve contact information for use in invoice as contact_xxx tags + $array_thirdparty_contact = array(); + if ($usecontact) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); - $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_propal,$array_other,$array_thirdparty_contact); + $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_propal,$array_other,$array_thirdparty_contact); complete_substitutions_array($tmparray, $outputlangs, $object); + // Call the ODTSubstitution hook $parameters=array('odfHandler'=>&$odfHandler,'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 diff --git a/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php b/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php index 8af397d15c1..6c5fa8652f9 100644 --- a/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php +++ b/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php @@ -95,7 +95,7 @@ class doc_generic_product_odt extends ModelePDFProduct function info($langs) { global $conf,$langs; - + $langs->load("companies"); $langs->load("errors"); @@ -361,6 +361,7 @@ class doc_generic_product_odt extends ModelePDFProduct //print html_entity_decode($odfHandler->__toString()); //print exit; + $object->fetch_optionals(); // Make substitutions into odt of freetext try { @@ -369,25 +370,26 @@ class doc_generic_product_odt extends ModelePDFProduct catch(OdfException $e) { } - - // Make substitutions into odt - $array_global = $this->get_substitutionarray_each_var_object($object, $outputlangs); + + // Define substitution array + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); + //$array_objet=$this->get_substitutionarray_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 product as contact_xxx tags - $array_thirdparty_contact = array(); - if ($usecontact) - $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); + // retrieve contact information for use in product as contact_xxx tags + $array_thirdparty_contact = array(); + if ($usecontact) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); - $tmparray = array_merge($array_global,$array_user,$array_soc,$array_thirdparty,$array_other,$array_thirdparty_contact); + $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$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 { diff --git a/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php b/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php index 35e8ace270e..5c0d025252e 100644 --- a/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php +++ b/htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php @@ -569,24 +569,25 @@ class doc_generic_project_odt extends ModelePDFProjects //print exit; - - - // Make substitutions into odt of user info + // Define substitution array + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); + $array_objet=$this->get_substitutionarray_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 project as contact_xxx tags - $array_project_contact = array(); - if ($usecontact) - $array_project_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); + // retrieve contact information for use in project as contact_xxx tags + $array_project_contact = array(); + if ($usecontact) $array_project_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); - $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_project_contact); + $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_project_contact); complete_substitutions_array($tmparray, $outputlangs, $object); + // Call the ODTSubstitution hook $parameters=array('odfHandler'=>&$odfHandler,'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 { diff --git a/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php b/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php index c846d7f6a23..5f7ff754a65 100644 --- a/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php +++ b/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php @@ -507,17 +507,18 @@ class doc_generic_task_odt extends ModelePDFTask //print exit; - - - // Make substitutions into odt of user info + // Define substitution array + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); + $array_objet=$this->get_substitutionarray_object($project,$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($project,$outputlangs); $array_other=$this->get_substitutionarray_other($outputlangs); - $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_other); + $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other); complete_substitutions_array($tmparray, $outputlangs, $object); + foreach($tmparray as $key=>$value) { try { diff --git a/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php b/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php index e8af7d87cae..bc34d5b5691 100644 --- a/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php +++ b/htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php @@ -375,6 +375,7 @@ class doc_generic_proposal_odt extends ModelePDFPropales //print html_entity_decode($odfHandler->__toString()); //print exit; + $object->fetch_optionals(); // Make substitutions into odt of freetext try { @@ -384,23 +385,25 @@ class doc_generic_proposal_odt extends ModelePDFPropales { } - // Make substitutions into odt + // Define substitution array + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + $array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs); + $array_objet=$this->get_substitutionarray_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 proposal as contact_xxx tags - $array_thirdparty_contact = array(); - if ($usecontact) - $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); + // retrieve contact information for use in proposal as contact_xxx tags + $array_thirdparty_contact = array(); + if ($usecontact) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); - $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact); + $tmparray = array_merge($substitutionarray,$array_object_from_properties,$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('odfHandler'=>&$odfHandler,'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 { diff --git a/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php b/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php index 0e2a932ce3b..a8497416501 100644 --- a/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php +++ b/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php @@ -381,18 +381,21 @@ class doc_generic_supplier_proposal_odt extends ModelePDFSupplierProposal { } - // Make substitutions into odt + // Define substitution array + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + $array_objet=$this->get_substitutionarray_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); - $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_other); + $tmparray = array_merge($substitutionarray,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other); complete_substitutions_array($tmparray, $outputlangs, $object); + // Call the ODTSubstitution hook $parameters=array('odfHandler'=>&$odfHandler,'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 {