Skip to content

Commit

Permalink
Start to introduce common substitution rules for odt substitutions
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Feb 24, 2018
1 parent c8078b5 commit 38d1fc2
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 65 deletions.
4 changes: 2 additions & 2 deletions htdocs/core/class/commondocgenerator.class.php
Expand Up @@ -349,8 +349,8 @@ function get_substitutionarray_object($object,$outputlangs,$array_key='object')
$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'),
Expand Down
Expand Up @@ -354,21 +354,22 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
{
}

// 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

Expand Down
Expand Up @@ -296,26 +296,17 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede

// 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;
Expand Down
Expand Up @@ -361,20 +361,22 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
{
}

// 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
Expand Down
24 changes: 13 additions & 11 deletions htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php
Expand Up @@ -95,7 +95,7 @@ function __construct($db)
function info($langs)
{
global $conf,$langs;

$langs->load("companies");
$langs->load("errors");

Expand Down Expand Up @@ -361,6 +361,7 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
//print html_entity_decode($odfHandler->__toString());
//print exit;

$object->fetch_optionals();

// Make substitutions into odt of freetext
try {
Expand All @@ -369,25 +370,26 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
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 {
Expand Down
Expand Up @@ -569,24 +569,25 @@ function write_file($object,$outputlangs,$srctemplatepath)
//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 {
Expand Down
Expand Up @@ -507,17 +507,18 @@ function write_file($object,$outputlangs,$srctemplatepath)
//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 {
Expand Down
Expand Up @@ -375,6 +375,7 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
//print html_entity_decode($odfHandler->__toString());
//print exit;

$object->fetch_optionals();

// Make substitutions into odt of freetext
try {
Expand All @@ -384,23 +385,25 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
{
}

// 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 {
Expand Down
Expand Up @@ -381,18 +381,21 @@ function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidede
{
}

// 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 {
Expand Down

0 comments on commit 38d1fc2

Please sign in to comment.