From 5be8bdbd274648099bcff0e0f4188817eecceb39 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 20 Feb 2011 21:52:04 +0000 Subject: [PATCH] Work on ODT generation --- .../doc/doc_generic_invoice_odt.modules.php | 75 ++++++++++++++++++- .../societe/doc/doc_generic_odt.modules.php | 16 ++-- 2 files changed, 79 insertions(+), 12 deletions(-) diff --git a/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php index ba97b03ee0c..947eabb9ef3 100644 --- a/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -91,7 +91,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures * * @param $object */ - function get_substitutionarray_object($object) + function get_substitutionarray_thirdparty($object) { global $conf; @@ -121,6 +121,32 @@ class doc_generic_invoice_odt extends ModelePDFFactures ); } + /** + * Define array with couple subtitution key => subtitution value + * + * @param $object + */ + function get_substitutionarray_object($object) + { + global $conf; + + return array( + 'object_id'=>$object->id, + 'object_ref'=>$object->ref, + 'object_ref_customer'=>$object->ref_client, + 'object_ref_supplier'=>$object->ref_fournisseur, + 'object_date'=>$object->date, + 'object_date_creation'=>$object->date_creation, + 'object_date_validation'=>$object->date_validation, + 'object_total_ht'=>$object->total_ht, + 'object_total_vat'=>$object->total_tva, + 'object_total_ttc'=>$object->total_ttc, + 'object_vatrate'=>$object->tva, + 'object_note_private'=>$object->note, + 'object_note'=>$object->note_public + ); + } + /** \brief Return description of a module * \return string Description */ @@ -178,7 +204,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures $nb++; if ($nb >= 5) { $texthelp.='...
'; break; } } - $tmparray=$this->get_substitutionarray_object($dummy); + $tmparray=$this->get_substitutionarray_thirdparty($dummy); $nb=0; foreach($tmparray as $key => $val) { @@ -287,7 +313,29 @@ class doc_generic_invoice_odt extends ModelePDFFactures create_exdir($conf->facture->dir_temp); - // Open and load template + + // If BILLING contact defined on invoice, we use it + $usecontact=false; + $arrayidcontact=$object->getIdContact('external','BILLING'); + if (sizeof($arrayidcontact) > 0) + { + $usecontact=true; + $result=$object->fetch_contact($arrayidcontact[0]); + } + + // Recipient name + if (! empty($usecontact)) + { + // On peut utiliser le nom de la societe du contact + if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socobject = $object->contact; + else $socobject = $object->client; + } + else + { + $socobject=$object->client; + } + + // Open and load template require_once(DOL_DOCUMENT_ROOT.'/includes/odtphp/odf.php'); $odfHandler = new odf($srctemplatepath, array( 'PATH_TO_TMP' => $conf->facture->dir_temp, @@ -337,7 +385,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures { } } - $tmparray=$this->get_substitutionarray_object($object); + $tmparray=$this->get_substitutionarray_thirdparty($socobject); foreach($tmparray as $key=>$value) { try { @@ -356,6 +404,25 @@ class doc_generic_invoice_odt extends ModelePDFFactures } } + $tmparray=$this->get_substitutionarray_object($object); + foreach($tmparray as $key=>$value) + { + try { + if (preg_match('/logo$/',$key)) // Image + { + if (file_exists($value)) $odfHandler->setImage($key, $value); + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); + } + else // Text + { + $odfHandler->setVars($key, $value, true, 'UTF-8'); + } + } + catch(OdfException $e) + { + } + } + // Write new file //$result=$odfHandler->exportAsAttachedFile('toto'); $odfHandler->saveToDisk($file); diff --git a/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php index 3d5741e1211..38d1879187b 100644 --- a/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/includes/modules/societe/doc/doc_generic_odt.modules.php @@ -81,7 +81,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc * * @param $object */ - function get_substitutionarray_object($object) + function get_substitutionarray_thirdparty($object) { global $conf; @@ -168,7 +168,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc $nb++; if ($nb >= 5) { $texthelp.='...
'; break; } } - $tmparray=$this->get_substitutionarray_object($dummy); + $tmparray=$this->get_substitutionarray_thirdparty($dummy); $nb=0; foreach($tmparray as $key => $val) { @@ -209,11 +209,11 @@ class doc_generic_odt extends ModeleThirdPartyDoc } /** - * \brief Function to build a document on disk using the generic odt module. - * \param object Object source to build document - * \param outputlangs Lang output object - * \param $srctemplatepath Full path of source filename for generator using a template file - * \return int 1 if OK, <=0 if KO + * Function to build a document on disk using the generic odt module. + * @param object Object source to build document + * @param outputlangs Lang output object + * @param srctemplatepath Full path of source filename for generator using a template file + * @return int 1 if OK, <=0 if KO */ function write_file($object,$outputlangs,$srctemplatepath) { @@ -330,7 +330,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc { } } - $tmparray=$this->get_substitutionarray_object($object); + $tmparray=$this->get_substitutionarray_thirdparty($object); foreach($tmparray as $key=>$value) { try {