* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/includes/modules/facture/doc/doc_generic_invoice_odt.modules.php
* \ingroup societe
* \brief File of class to build ODT documents for third parties
* \author Laurent Destailleur
* \version $Id: doc_generic_invoice_odt.modules.php,v 1.19 2011/07/21 22:54:36 eldy Exp $
*/
require_once(DOL_DOCUMENT_ROOT."/includes/modules/facture/modules_facture.php");
require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
/**
* \class doc_generic_invoice_odt
* \brief Class to build documents using ODF templates generator
*/
class doc_generic_invoice_odt extends ModelePDFFactures
{
var $emetteur; // Objet societe qui emet
var $phpmin = array(5,2,0); // Minimum version of PHP required by module
var $version = 'dolibarr';
/**
* \brief Constructor
* \param db Database handler
*/
function doc_generic_invoice_odt($db)
{
global $conf,$langs,$mysoc;
$langs->load("main");
$langs->load("companies");
$this->db = $db;
$this->name = "ODT templates";
$this->description = $langs->trans("DocumentModelOdt");
$this->scandir = 'FACTURE_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan
// Dimension page pour format A4
$this->type = 'odt';
$this->page_largeur = 0;
$this->page_hauteur = 0;
$this->format = array($this->page_largeur,$this->page_hauteur);
$this->marge_gauche=0;
$this->marge_droite=0;
$this->marge_haute=0;
$this->marge_basse=0;
$this->option_logo = 1; // Affiche logo
$this->option_tva = 0; // Gere option tva FACTURE_TVAOPTION
$this->option_modereg = 0; // Affiche mode reglement
$this->option_condreg = 0; // Affiche conditions reglement
$this->option_codeproduitservice = 0; // Affiche code produit-service
$this->option_multilang = 0; // Dispo en plusieurs langues
$this->option_escompte = 0; // Affiche si il y a eu escompte
$this->option_credit_note = 0; // Support credit notes
$this->option_freetext = 1; // Support add of a personalised text
$this->option_draft_watermark = 0; // Support add of a watermark on drafts
// Recupere emetteur
$this->emetteur=$mysoc;
if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'etait pas defini
}
/**
* Define array with couple substitution key => substitution value
*
* @param $object Main object to use as data source
* @param $outputlangs Lang object to use for output
*/
function get_substitutionarray_object($object,$outputlangs)
{
global $conf;
$invoice_source=new Facture($this->db);
if ($object->fk_facture_source > 0)
{
$invoice_source->fetch($object->fk_facture_source);
}
$alreadypayed=price($object->getSommePaiement(),'MT');
return array(
'object_id'=>$object->id,
'object_ref'=>$object->ref,
'object_ref_ext'=>$object->ref_ext,
'object_ref_customer'=>$object->ref_client,
'object_ref_supplier'=>$object->ref_fournisseur,
'object_source_invoice_ref'=>$invoice_source->ref,
'object_date'=>dol_print_date($object->date,'day'),
'object_date_limit'=>dol_print_date($object->date_lim_reglement,'dayhour'),
'object_date_creation'=>dol_print_date($object->date_creation,'day'),
'object_date_modification'=>dol_print_date($object->date_modification,'day'),
'object_date_validation'=>dol_print_date($object->date_validation,'dayhour'),
'object_payment_mode'=>$object->mode_reglement,
'object_payment_term'=>$object->cond_reglement,
'object_total_ht'=>price($object->total_ht),
'object_total_vat'=>price($object->total_tva),
'object_total_ttc'=>price($object->total_ttc),
'object_vatrate'=>vatrate($object->tva),
'object_note_private'=>$object->note,
'object_note'=>$object->note_public,
// Payments
'object_already_payed'=>$alreadypayed,
'object_remain_to_pay'=>price($object->total_ttc - $alreadypayed,'MT')
);
}
/**
* Define array with couple substitution key => substitution value
*
* @param $line
* @param $outputlangs Lang object to use for output
*/
function get_substitutionarray_lines($line,$outputlangs)
{
global $conf;
return array(
'line_fulldesc'=>$line->product_ref.(($line->product_ref && $line->desc)?' - ':'').$line->desc,
'line_product_ref'=>$line->product_ref,
'line_desc'=>$line->desc,
'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
'line_up'=>price($line->subprice, 0, $outputlangs),
'line_qty'=>$line->qty,
'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
'line_price_ht'=>price($line->total_ht, 0, $outputlangs),
'line_price_ttc'=>price($line->total_ttc, 0, $outputlangs),
'line_price_vat'=>price($line->total_tva, 0, $outputlangs),
'line_date_start'=>$line->date_start,
'line_date_end'=>$line->date_end
);
}
/** Return description of a module
* @param langs Lang object to use for output
* @return string Description
*/
function info($langs)
{
global $conf,$langs;
$langs->load("companies");
$langs->load("errors");
$form = new Form($db);
$texte = $this->description.".
\n";
$texte.= '