Work on ODT generation
This commit is contained in:
parent
0ebe9c6f01
commit
5be8bdbd27
@ -91,7 +91,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
*
|
*
|
||||||
* @param $object
|
* @param $object
|
||||||
*/
|
*/
|
||||||
function get_substitutionarray_object($object)
|
function get_substitutionarray_thirdparty($object)
|
||||||
{
|
{
|
||||||
global $conf;
|
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
|
/** \brief Return description of a module
|
||||||
* \return string Description
|
* \return string Description
|
||||||
*/
|
*/
|
||||||
@ -178,7 +204,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
$nb++;
|
$nb++;
|
||||||
if ($nb >= 5) { $texthelp.='...<br>'; break; }
|
if ($nb >= 5) { $texthelp.='...<br>'; break; }
|
||||||
}
|
}
|
||||||
$tmparray=$this->get_substitutionarray_object($dummy);
|
$tmparray=$this->get_substitutionarray_thirdparty($dummy);
|
||||||
$nb=0;
|
$nb=0;
|
||||||
foreach($tmparray as $key => $val)
|
foreach($tmparray as $key => $val)
|
||||||
{
|
{
|
||||||
@ -287,7 +313,29 @@ class doc_generic_invoice_odt extends ModelePDFFactures
|
|||||||
|
|
||||||
create_exdir($conf->facture->dir_temp);
|
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');
|
require_once(DOL_DOCUMENT_ROOT.'/includes/odtphp/odf.php');
|
||||||
$odfHandler = new odf($srctemplatepath, array(
|
$odfHandler = new odf($srctemplatepath, array(
|
||||||
'PATH_TO_TMP' => $conf->facture->dir_temp,
|
'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)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
try {
|
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
|
// Write new file
|
||||||
//$result=$odfHandler->exportAsAttachedFile('toto');
|
//$result=$odfHandler->exportAsAttachedFile('toto');
|
||||||
$odfHandler->saveToDisk($file);
|
$odfHandler->saveToDisk($file);
|
||||||
|
|||||||
@ -81,7 +81,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc
|
|||||||
*
|
*
|
||||||
* @param $object
|
* @param $object
|
||||||
*/
|
*/
|
||||||
function get_substitutionarray_object($object)
|
function get_substitutionarray_thirdparty($object)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc
|
|||||||
$nb++;
|
$nb++;
|
||||||
if ($nb >= 5) { $texthelp.='...<br>'; break; }
|
if ($nb >= 5) { $texthelp.='...<br>'; break; }
|
||||||
}
|
}
|
||||||
$tmparray=$this->get_substitutionarray_object($dummy);
|
$tmparray=$this->get_substitutionarray_thirdparty($dummy);
|
||||||
$nb=0;
|
$nb=0;
|
||||||
foreach($tmparray as $key => $val)
|
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.
|
* Function to build a document on disk using the generic odt module.
|
||||||
* \param object Object source to build document
|
* @param object Object source to build document
|
||||||
* \param outputlangs Lang output object
|
* @param outputlangs Lang output object
|
||||||
* \param $srctemplatepath Full path of source filename for generator using a template file
|
* @param srctemplatepath Full path of source filename for generator using a template file
|
||||||
* \return int 1 if OK, <=0 if KO
|
* @return int 1 if OK, <=0 if KO
|
||||||
*/
|
*/
|
||||||
function write_file($object,$outputlangs,$srctemplatepath)
|
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)
|
foreach($tmparray as $key=>$value)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user