From b89b5f8a316999bcbfdc45f26b2c53335db4dc32 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 11 Jun 2006 00:36:17 +0000 Subject: [PATCH] =?UTF-8?q?New:=20Sur=20page=20config=20choix=20module=20g?= =?UTF-8?q?=E9n=E9ration=20facture,=20un=20clic=20sur=20info=20affiche=20u?= =?UTF-8?q?n=20aper=E7u=20d'un=20specimen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/admin/facture.php | 36 +- htdocs/facture.class.php | 82 ++- .../modules/facture/pdf_bernique.modules.php | 294 +++++----- .../modules/facture/pdf_bulot.modules.php | 307 ++++++----- .../modules/facture/pdf_crabe.modules.php | 34 +- .../modules/facture/pdf_huitre.modules.php | 393 +++++++------- .../modules/facture/pdf_oursin.modules.php | 503 +++++++++--------- htdocs/langs/en_US/bills.lang | 2 +- htdocs/langs/fr_FR/bills.lang | 2 +- htdocs/lib/functions.inc.php | 11 +- 10 files changed, 930 insertions(+), 734 deletions(-) diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index be653d43965..efe2a43834a 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2006 Laurent Destailleur * Copyright (C) 2005 Eric Seigne * Copyright (C) 2005-2006 Regis Houssin * @@ -30,6 +30,7 @@ */ require("./pre.inc.php"); +require_once(DOL_DOCUMENT_ROOT.'/facture.class.php'); $langs->load("admin"); $langs->load("companies"); @@ -40,11 +41,36 @@ if (!$user->admin) accessforbidden(); $typeconst=array('yesno','texte','chaine'); +$dir = DOL_DOCUMENT_ROOT."/includes/modules/facture/"; /* * Actions */ +if ($_GET["action"] == 'specimen') +{ + $modele=$_GET["module"]; + + $facture = new Facture($db); + $facture->initAsSpecimen(); + + // Charge le modele + $dir = DOL_DOCUMENT_ROOT . "/includes/modules/facture/"; + $file = "pdf_".$modele.".modules.php"; + if (file_exists($dir.$file)) + { + $classname = "pdf_".$modele; + require_once($dir.$file); + + $obj = new $classname($db); + + if ($obj->write_pdf_file($facture) > 0) + { + header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture&file=SPECIMEN.pdf"); + return; + } + } +} if ($_GET["action"] == 'set') { @@ -81,7 +107,7 @@ if ($_GET["action"] == 'setdoc') // On active le modele $type='invoice'; $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model"; - $sql_del .= " WHERE nom = '".$_GET["value"]."' AND type = '".$type."'"; + $sql_del.= " WHERE nom = '".$_GET["value"]."' AND type = '".$type."'"; $result1=$db->query($sql_del); $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom,type) VALUES ('".$_GET["value"]."','".$type."')"; $result2=$db->query($sql); @@ -142,7 +168,6 @@ if ($_GET["action"] == 'delete') llxHeader("",""); -$dir = "../includes/modules/facture/"; $html=new Form($db); $h = 0; @@ -285,6 +310,7 @@ while (($file = readdir($handle))!==false) print ''; echo "$name"; print "\n"; + require_once($dir.$file); $module = new $classname($db); print $module->description; @@ -333,7 +359,9 @@ while (($file = readdir($handle))!==false) $htmltooltip.='
'.$langs->trans("Logo").': '.yn($module->option_logo); $htmltooltip.='
'.$langs->trans("PaymentMode").': '.yn($module->option_modereg); $htmltooltip.='
'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg); - print 'tooltip_properties($htmltooltip).'>'.img_help(0).''; + print 'tooltip_properties($htmltooltip).'>'; + print ''.img_help(0,0).''; + print ''; print "\n"; } diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index fbe662b1380..ed315fef0ef 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -954,7 +954,7 @@ class Facture } /** - * \brief Ajoute un produit dans l'objet facture + * \brief Ajoute un produit dans les tableaux products, products_qty, products_date_start|end * \param idproduct * \param qty * \param remise_percent @@ -1235,6 +1235,8 @@ class Facture $sql .= ' WHERE rowid = '.$facid; if ( $this->db->query($sql) ) { + // \TODO Supprimer l'utilisation de facture_tva_sum non utilisable + // dans un context compta propre. $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_tva_sum WHERE fk_facture='.$this->id; if ( $this->db->query($sql) ) { @@ -1351,6 +1353,8 @@ class Facture */ function getSumTva() { + $tvs=array(); + $sql = 'SELECT amount, tva_tx FROM '.MAIN_DB_PREFIX.'facture_tva_sum WHERE fk_facture = '.$this->id; if ($this->db->query($sql)) { @@ -1366,6 +1370,7 @@ class Facture } else { + dolibarr_print_error($this->db); return -1; } } @@ -2228,6 +2233,81 @@ class Facture return $this->getIdContact('external','SHIPPING'); } + + /** + * \brief Initialise la facture avec valeurs fictives aléatoire + * Sert à générer une facture pour l'aperu des modèles ou demo + */ + function initAsSpecimen() + { + global $user,$langs; + + // Charge tableau des id de société socids + $socids = array(); + $sql = "SELECT idp FROM ".MAIN_DB_PREFIX."societe WHERE client=1 LIMIT 10"; + $resql = $this->db->query($sql); + if ($resql) + { + $num_socs = $this->db->num_rows($resql); + $i = 0; + while ($i < $num_socs) + { + $i++; + + $row = $this->db->fetch_row($resql); + $socids[$i] = $row[0]; + } + } + + // Charge tableau des produits prodids + $prodids = array(); + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product WHERE envente=1"; + $resql = $this->db->query($sql); + if ($resql) + { + $num_prods = $this->db->num_rows($resql); + $i = 0; + while ($i < $num_prods) + { + $i++; + $row = $this->db->fetch_row($resql); + $prodids[$i] = $row[0]; + } + } + + // Initialise paramètres + $this->id=0; + $this->ref = 'SPECIMEN'; + $this->specimen=1; + $socid = rand(1, $num_socs); + $this->socidp = $socids[$socid]; + $this->date = time(); + $this->date_lim_reglement=$this->date+3600*24*30; + $this->cond_reglement_id = 3; + $this->mode_reglement_id = 3; + $this->note_public='SPECIMEN'; + $nbp = rand(1, 9); + $xnbp = 0; + while ($xnbp < $nbp) + { + $ligne=new FactureLigne($this->db); + $ligne->desc=$langs->trans("Description")." ".$xnbp; + $ligne->qty=1; + $ligne->subprice=100; + $ligne->price=100; + $ligne->tva_taux=19.6; + $prodid = rand(1, $num_prods); + $ligne->produit_id=$prodids[$prodid]; + $this->lignes[$xnbp]=$ligne; + $xnbp++; + } + + $this->amount_ht = $xnbp*100; + $this->total_ht = $xnbp*100; + $this->total_tva = $xnbp*19.6; + $this->total_ttc = $xnbp*119.6; + } + } diff --git a/htdocs/includes/modules/facture/pdf_bernique.modules.php b/htdocs/includes/modules/facture/pdf_bernique.modules.php index 5259c613661..53789920c31 100644 --- a/htdocs/includes/modules/facture/pdf_bernique.modules.php +++ b/htdocs/includes/modules/facture/pdf_bernique.modules.php @@ -56,151 +56,170 @@ class pdf_bernique extends ModelePDFFactures { $this->format = array($this->page_largeur,$this->page_hauteur); } - function write_pdf_file($facid) - { - global $user,$langs,$conf; - - $fac = new Facture($this->db,"",$facid); - $fac->fetch($facid); - if ($conf->facture->dir_output) + /** + * \brief Fonction générant la facture sur le disque + * \param fac Objet facture à générer (ou id si ancienne methode) + * \return int 1=ok, 0=ko + */ + function write_pdf_file($fac,$outputlangs='') { - - $facref = sanitize_string($fac->ref); - $dir = $conf->facture->dir_output . "/" . $facref . "/" ; - $file = $dir . $facref . ".pdf"; - - if (! file_exists($dir)) - { - if (create_exdir($dir) < 0) - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } - } - - if (file_exists($dir)) - { - // Initialisation facture vierge - $pdf=new FPDF('P','mm','A4'); - $pdf->Open(); - $pdf->AddPage(); - - $this->_pagehead($pdf, $fac); - - $pdf->SetTitle($fac->ref); - $pdf->SetSubject($langs->trans("Bill")); - $pdf->SetCreator("Dolibarr ".DOL_VERSION); - $pdf->SetAuthor($user->fullname); - - $tab_top = 100; - $tab_height = 110; - - /* - * - */ - - $pdf->SetFillColor(220,220,220); - - $pdf->SetFont('Arial','', 9); - - $pdf->SetXY (10, $tab_top + 10 ); - - $iniY = $pdf->GetY(); - $curY = $pdf->GetY(); - $nexY = $pdf->GetY(); - $nblignes = sizeof($fac->lignes); - - for ($i = 0 ; $i < $nblignes ; $i++) + global $user,$langs,$conf,$mysoc; + + if ($conf->facture->dir_output) { - $curY = $nexY; + // Définition de l'objet $fac (pour compatibilite ascendante) + if (! is_object($fac)) + { + $fac = new Facture($this->db,"",$fac); + $ret=$fac->fetch($fac); + } - $pdf->SetXY (11, $curY ); - $pdf->MultiCell(118, 5, $fac->lignes[$i]->desc, 0, 'J'); + // Définition de $dir et $file + if ($fac->specimen) + { + $dir = $conf->facture->dir_output; + $file = $dir . "/SPECIMEN.pdf"; + } + else + { + $facref = sanitize_string($fac->ref); + $dir = $conf->facture->dir_output . "/" . $facref; + $file = $dir . "/" . $facref . ".pdf"; + } + + if (! file_exists($dir)) + { + if (create_exdir($dir) < 0) + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } + + if (file_exists($dir)) + { + // Initialisation facture vierge + $pdf=new FPDF('P','mm','A4'); + $pdf->Open(); + $pdf->AddPage(); + + $this->_pagehead($pdf, $fac); + + $pdf->SetTitle($fac->ref); + $pdf->SetSubject($langs->trans("Bill")); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); + $pdf->SetAuthor($user->fullname); + + $tab_top = 100; + $tab_height = 110; + + /* + * + */ + + $pdf->SetFillColor(220,220,220); + + $pdf->SetFont('Arial','', 9); + + $pdf->SetXY (10, $tab_top + 10 ); + + $iniY = $pdf->GetY(); + $curY = $pdf->GetY(); + $nexY = $pdf->GetY(); + $nblignes = sizeof($fac->lignes); + + for ($i = 0 ; $i < $nblignes ; $i++) + { + $curY = $nexY; + + $pdf->SetXY (11, $curY ); + $pdf->MultiCell(118, 5, $fac->lignes[$i]->desc, 0, 'J'); + + $nexY = $pdf->GetY(); + + $pdf->SetXY (133, $curY); + $pdf->MultiCell(10, 5, $fac->lignes[$i]->tva_taux, 0, 'C'); + + $pdf->SetXY (145, $curY); + $pdf->MultiCell(10, 5, $fac->lignes[$i]->qty, 0, 'C'); + + $pdf->SetXY (156, $curY); + $pdf->MultiCell(18, 5, price($fac->lignes[$i]->price), 0, 'R', 0); + + $pdf->SetXY (174, $curY); + $total = price($fac->lignes[$i]->price * $fac->lignes[$i]->qty); + $pdf->MultiCell(26, 5, $total, 0, 'R', 0); + + if ($nexY > 200 && $i < $nblignes - 1) + { + $this->_tableau($pdf, $tab_top, $tab_height, $nexY); + $pdf->AddPage(); + $nexY = $iniY; + $this->_pagehead($pdf, $fac); + $pdf->SetTextColor(0,0,0); + $pdf->SetFont('Arial','', 10); + } + + } + $this->_tableau($pdf, $tab_top, $tab_height, $nexY); - $nexY = $pdf->GetY(); - - $pdf->SetXY (133, $curY); - $pdf->MultiCell(10, 5, $fac->lignes[$i]->tva_taux, 0, 'C'); - - $pdf->SetXY (145, $curY); - $pdf->MultiCell(10, 5, $fac->lignes[$i]->qty, 0, 'C'); - - $pdf->SetXY (156, $curY); - $pdf->MultiCell(18, 5, price($fac->lignes[$i]->price), 0, 'R', 0); - - $pdf->SetXY (174, $curY); - $total = price($fac->lignes[$i]->price * $fac->lignes[$i]->qty); - $pdf->MultiCell(26, 5, $total, 0, 'R', 0); - - if ($nexY > 200 && $i < $nblignes - 1) - { - $this->_tableau($pdf, $tab_top, $tab_height, $nexY); - $pdf->AddPage(); - $nexY = $iniY; - $this->_pagehead($pdf, $fac); - $pdf->SetTextColor(0,0,0); - $pdf->SetFont('Arial','', 10); - } - + $this->_tableau_tot($pdf, $fac, $tab_top, $tab_height); + + $this->_tableau_compl($pdf, $fac); + + /* + * + */ + if (defined("FACTURE_RIB_NUMBER")) + { + if (FACTURE_RIB_NUMBER > 0) + { + $account = new Account($this->db); + $account->fetch(FACTURE_RIB_NUMBER); + + $pdf->SetXY (10, 49); + $pdf->SetFont('Arial','U',8); + $pdf->MultiCell(40, 4, $langs->trans("BankDetails"), 0, 'L', 0); + $pdf->SetFont('Arial','',8); + $pdf->MultiCell(40, 4, $langs->trans("BankCode").' : ' . $account->code_banque, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("DeskCode").' : ' . $account->code_guichet, 0, 'L', 0); + $pdf->MultiCell(50, 4, $langs->trans("BankAccountNumber").' : ' . $account->number, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("BankAccountNumberKey").' : ' . $account->cle_rib, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("Residence").' : ' . $account->domiciliation, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("IbanPrefix").' : ' . $account->iban_prefix, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("BIC").' : ' . $account->bic, 0, 'L', 0); + } + } + + /* + * + * + */ + + $pdf->SetFont('Arial','',9); + $pdf->SetXY(10, 260); + $pdf->MultiCell(190, 5, $langs->trans("IntracommunityVATNumber").' : '.MAIN_INFO_TVAINTRA, 0, 'J'); + $pdf->MultiCell(190, 5, $langs->trans("PrettyLittleSentence"), 0, 'J'); + + $pdf->Close(); + + $pdf->Output($file); + + return 1; + } + else + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } } - $this->_tableau($pdf, $tab_top, $tab_height, $nexY); - - $this->_tableau_tot($pdf, $fac, $tab_top, $tab_height); - - $this->_tableau_compl($pdf, $fac); - - /* - * - */ - if (defined("FACTURE_RIB_NUMBER")) + else { - if (FACTURE_RIB_NUMBER > 0) - { - $account = new Account($this->db); - $account->fetch(FACTURE_RIB_NUMBER); - - $pdf->SetXY (10, 49); - $pdf->SetFont('Arial','U',8); - $pdf->MultiCell(40, 4, $langs->trans("BankDetails"), 0, 'L', 0); - $pdf->SetFont('Arial','',8); - $pdf->MultiCell(40, 4, $langs->trans("BankCode").' : ' . $account->code_banque, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("DeskCode").' : ' . $account->code_guichet, 0, 'L', 0); - $pdf->MultiCell(50, 4, $langs->trans("BankAccountNumber").' : ' . $account->number, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("BankAccountNumberKey").' : ' . $account->cle_rib, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("Residence").' : ' . $account->domiciliation, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("IbanPrefix").' : ' . $account->iban_prefix, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("BIC").' : ' . $account->bic, 0, 'L', 0); - } + $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); + return 0; } - - /* - * - * - */ - - $pdf->SetFont('Arial','',9); - $pdf->SetXY(10, 260); - $pdf->MultiCell(190, 5, $langs->trans("IntracommunityVATNumber").' : '.MAIN_INFO_TVAINTRA, 0, 'J'); - $pdf->MultiCell(190, 5, $langs->trans("PrettyLittleSentence"), 0, 'J'); - - $pdf->Close(); - - $pdf->Output($file); - - return 1; - } - else - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } } - else - { - $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); - return 0; - } - } + /* * * @@ -252,6 +271,7 @@ class pdf_bernique extends ModelePDFFactures { $pdf->SetFont('Arial','', 9); $tvas = $fac->getSumTva(); + $i = 0; $tab4_top = $tab2_top + 2 + ($tab2_hl * 2); diff --git a/htdocs/includes/modules/facture/pdf_bulot.modules.php b/htdocs/includes/modules/facture/pdf_bulot.modules.php index 3bddf269a19..5c3dfff9ab7 100644 --- a/htdocs/includes/modules/facture/pdf_bulot.modules.php +++ b/htdocs/includes/modules/facture/pdf_bulot.modules.php @@ -57,158 +57,175 @@ class pdf_bulot extends ModelePDFFactures { $this->format = array($this->page_largeur,$this->page_hauteur); } - - function write_pdf_file($facid) - { - global $user,$langs,$conf; - - if ($conf->facture->dir_output) + /** + * \brief Fonction générant la facture sur le disque + * \param fac Objet facture à générer (ou id si ancienne methode) + * \return int 1=ok, 0=ko + */ + function write_pdf_file($fac,$outputlangs='') { - $fac = new Facture($this->db,"",$facid); - $fac->fetch($facid); - - $facref = sanitize_string($fac->ref); - $dir = $conf->facture->dir_output . "/" . $facref; - $file = $dir . "/" . $facref . ".pdf"; - - if (! file_exists($dir)) - { - if (create_exdir($dir) < 0) - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } - } - - if (file_exists($dir)) - { - // Initialisation facture vierge - $pdf=new FPDF('P','mm','A4'); - $pdf->Open(); - $pdf->AddPage(); - - $this->_pagehead($pdf, $fac); - - $pdf->SetTitle($fac->ref); - $pdf->SetSubject($langs->trans("Bill")); - $pdf->SetCreator("Dolibarr ".DOL_VERSION); - $pdf->SetAuthor($user->fullname); - - $tab_top = 100; - $tab_height = 110; - - /* - * - */ - - $pdf->SetFillColor(220,220,220); - - $pdf->SetFont('Arial','', 9); - - $pdf->SetXY (10, $tab_top + 10 ); - - $iniY = $pdf->GetY(); - $curY = $pdf->GetY(); - $nexY = $pdf->GetY(); - $nblignes = sizeof($fac->lignes); - - for ($i = 0 ; $i < $nblignes ; $i++) + global $user,$langs,$conf,$mysoc; + + if ($conf->facture->dir_output) { - $curY = $nexY; + // Définition de l'objet $fac (pour compatibilite ascendante) + if (! is_object($fac)) + { + $fac = new Facture($this->db,"",$fac); + $ret=$fac->fetch($fac); + } - $pdf->SetXY (11, $curY ); - $pdf->MultiCell(118, 5, $fac->lignes[$i]->desc, 0, 'J'); - - $nexY = $pdf->GetY(); - - $pdf->SetXY (133, $curY); - $pdf->MultiCell(10, 5, $fac->lignes[$i]->tva_taux, 0, 'C'); - - $pdf->SetXY (145, $curY); - $pdf->MultiCell(10, 5, $fac->lignes[$i]->qty, 0, 'C'); - - $pdf->SetXY (156, $curY); - $pdf->MultiCell(18, 5, price($fac->lignes[$i]->price), 0, 'R', 0); - - $pdf->SetXY (174, $curY); - $total = price($fac->lignes[$i]->price * $fac->lignes[$i]->qty); - $pdf->MultiCell(26, 5, $total, 0, 'R', 0); - - if ($nexY > 200 && $i < $nblignes - 1) - { - $this->_tableau($pdf, $tab_top, $tab_height, $nexY); - $pdf->AddPage(); - $nexY = $iniY; - $this->_pagehead($pdf, $fac); - $pdf->SetTextColor(0,0,0); - $pdf->SetFont('Arial','', 10); - } - + // Définition de $dir et $file + if ($fac->specimen) + { + $dir = $conf->facture->dir_output; + $file = $dir . "/SPECIMEN.pdf"; + } + else + { + $facref = sanitize_string($fac->ref); + $dir = $conf->facture->dir_output . "/" . $facref; + $file = $dir . "/" . $facref . ".pdf"; + } + + if (! file_exists($dir)) + { + if (create_exdir($dir) < 0) + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } + + if (file_exists($dir)) + { + // Initialisation facture vierge + $pdf=new FPDF('P','mm','A4'); + $pdf->Open(); + $pdf->AddPage(); + + $this->_pagehead($pdf, $fac); + + $pdf->SetTitle($fac->ref); + $pdf->SetSubject($langs->trans("Bill")); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); + $pdf->SetAuthor($user->fullname); + + $tab_top = 100; + $tab_height = 110; + + /* + * + */ + + $pdf->SetFillColor(220,220,220); + + $pdf->SetFont('Arial','', 9); + + $pdf->SetXY (10, $tab_top + 10 ); + + $iniY = $pdf->GetY(); + $curY = $pdf->GetY(); + $nexY = $pdf->GetY(); + $nblignes = sizeof($fac->lignes); + + for ($i = 0 ; $i < $nblignes ; $i++) + { + $curY = $nexY; + + $pdf->SetXY (11, $curY ); + $pdf->MultiCell(118, 5, $fac->lignes[$i]->desc, 0, 'J'); + + $nexY = $pdf->GetY(); + + $pdf->SetXY (133, $curY); + $pdf->MultiCell(10, 5, $fac->lignes[$i]->tva_taux, 0, 'C'); + + $pdf->SetXY (145, $curY); + $pdf->MultiCell(10, 5, $fac->lignes[$i]->qty, 0, 'C'); + + $pdf->SetXY (156, $curY); + $pdf->MultiCell(18, 5, price($fac->lignes[$i]->price), 0, 'R', 0); + + $pdf->SetXY (174, $curY); + $total = price($fac->lignes[$i]->price * $fac->lignes[$i]->qty); + $pdf->MultiCell(26, 5, $total, 0, 'R', 0); + + if ($nexY > 200 && $i < $nblignes - 1) + { + $this->_tableau($pdf, $tab_top, $tab_height, $nexY); + $pdf->AddPage(); + $nexY = $iniY; + $this->_pagehead($pdf, $fac); + $pdf->SetTextColor(0,0,0); + $pdf->SetFont('Arial','', 10); + } + + } + $this->_tableau($pdf, $tab_top, $tab_height, $nexY); + + $this->_tableau_tot($pdf, $fac); + + $this->_tableau_compl($pdf, $fac); + + /* + * + */ + if (defined("FACTURE_RIB_NUMBER")) + { + if (FACTURE_RIB_NUMBER > 0) + { + $account = new Account($this->db); + $account->fetch(FACTURE_RIB_NUMBER); + + $pdf->SetXY (10, 40); + $pdf->SetFont('Arial','U',8); + $pdf->MultiCell(40, 4, $langs->trans("BankDetails"), 0, 'L', 0); + $pdf->SetFont('Arial','',8); + $pdf->MultiCell(40, 4, $langs->trans("BankCode").' : '. $account->code_banque, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("DeskCode").' : ' . $account->code_guichet, 0, 'L', 0); + $pdf->MultiCell(50, 4, $langs->trans("BankAccountNumber").' : ' . $account->number, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("BankAccountNumberKey").' : ' . $account->cle_rib, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("Residence").' : ' . $account->domiciliation, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("IbanPrefix").' : ' . $account->iban_prefix, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("BIC").' : ' . $account->bic, 0, 'L', 0); + } + } + + /* + * + * + */ + + $pdf->SetFont('Arial','U',12); + $pdf->SetXY(10, 220); + $titre = $langs->trans("PaymentConditions").' : '.$fac->cond_reglement_facture; + $pdf->MultiCell(190, 5, $titre, 0, 'J'); + + $pdf->SetFont('Arial','',9); + $pdf->SetXY(10, 265); + $pdf->MultiCell(190, 5, $langs->trans("PrettyLittleSentence"), 0, 'J'); + + $pdf->Close(); + + $pdf->Output($file); + + return 1; + } + else + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } } - $this->_tableau($pdf, $tab_top, $tab_height, $nexY); - - $this->_tableau_tot($pdf, $fac); - - $this->_tableau_compl($pdf, $fac); - - /* - * - */ - if (defined("FACTURE_RIB_NUMBER")) + else { - if (FACTURE_RIB_NUMBER > 0) - { - $account = new Account($this->db); - $account->fetch(FACTURE_RIB_NUMBER); - - $pdf->SetXY (10, 40); - $pdf->SetFont('Arial','U',8); - $pdf->MultiCell(40, 4, $langs->trans("BankDetails"), 0, 'L', 0); - $pdf->SetFont('Arial','',8); - $pdf->MultiCell(40, 4, $langs->trans("BankCode").' : '. $account->code_banque, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("DeskCode").' : ' . $account->code_guichet, 0, 'L', 0); - $pdf->MultiCell(50, 4, $langs->trans("BankAccountNumber").' : ' . $account->number, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("BankAccountNumberKey").' : ' . $account->cle_rib, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("Residence").' : ' . $account->domiciliation, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("IbanPrefix").' : ' . $account->iban_prefix, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("BIC").' : ' . $account->bic, 0, 'L', 0); - } + $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); + return 0; } - - /* - * - * - */ - - $pdf->SetFont('Arial','U',12); - $pdf->SetXY(10, 220); - $titre = $langs->trans("PaymentConditions").' : '.$fac->cond_reglement_facture; - $pdf->MultiCell(190, 5, $titre, 0, 'J'); - - $pdf->SetFont('Arial','',9); - $pdf->SetXY(10, 265); - $pdf->MultiCell(190, 5, $langs->trans("PrettyLittleSentence"), 0, 'J'); - - $pdf->Close(); - - $pdf->Output($file); - - return 1; - } - else - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } + $this->error=$langs->trans("ErrorUnknown"); + return 0; // Erreur par defaut } - else - { - $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); - return 0; - } - $this->error=$langs->trans("ErrorUnknown"); - return 0; // Erreur par defaut - } /** * \brief Affiche tableau des versement diff --git a/htdocs/includes/modules/facture/pdf_crabe.modules.php b/htdocs/includes/modules/facture/pdf_crabe.modules.php index b28e6b576a5..06647e91145 100644 --- a/htdocs/includes/modules/facture/pdf_crabe.modules.php +++ b/htdocs/includes/modules/facture/pdf_crabe.modules.php @@ -48,7 +48,7 @@ class pdf_crabe extends ModelePDFFactures { global $conf,$langs; - $langs->load("main"); + $langs->load("main"); $langs->load("bills"); $langs->load("products"); @@ -105,7 +105,7 @@ class pdf_crabe extends ModelePDFFactures /** * \brief Fonction générant la facture sur le disque - * \param id Id de la facture à générer + * \param fac Objet facture à générer (ou id si ancienne methode) * \return int 1=ok, 0=ko * \remarks Variables utilisées * \remarks MAIN_INFO_SOCIETE_NOM @@ -124,19 +124,31 @@ class pdf_crabe extends ModelePDFFactures * \remarks FACTURE_CHQ_NUMBER * \remarks FACTURE_RIB_NUMBER */ - function write_pdf_file($id) + function write_pdf_file($fac,$outputlangs='') { global $user,$langs,$conf,$mysoc; if ($conf->facture->dir_output) { - $fac = new Facture($this->db,"",$id); - $ret=$fac->fetch($id); - $nblignes = sizeof($fac->lignes); + // Définition de l'objet $fac (pour compatibilite ascendante) + if (! is_object($fac)) + { + $fac = new Facture($this->db,"",$fac); + $ret=$fac->fetch($fac); + } - $facref = sanitize_string($fac->ref); - $dir = $conf->facture->dir_output . "/" . $facref; - $file = $dir . "/" . $facref . ".pdf"; + // Définition de $dir et $file + if ($fac->specimen) + { + $dir = $conf->facture->dir_output; + $file = $dir . "/SPECIMEN.pdf"; + } + else + { + $facref = sanitize_string($fac->ref); + $dir = $conf->facture->dir_output . "/" . $facref; + $file = $dir . "/" . $facref . ".pdf"; + } if (! file_exists($dir)) { @@ -149,6 +161,8 @@ class pdf_crabe extends ModelePDFFactures if (file_exists($dir)) { + $nblignes = sizeof($fac->lignes); + // Initialisation document vierge $pdf=new FPDF('P','mm',$this->format); $pdf->Open(); @@ -574,7 +588,7 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetXY($this->marge_gauche, $tab2_top + 0); if ($this->franchise==1) { - $pdf->MultiCell(100, $tab2_hl, $langs->trans("VATIsNotUsed"), 0, 'L', 0); + $pdf->MultiCell(100, $tab2_hl, $langs->trans("VATIsNotUsedForInvoice"), 0, 'L', 0); } // Tableau total diff --git a/htdocs/includes/modules/facture/pdf_huitre.modules.php b/htdocs/includes/modules/facture/pdf_huitre.modules.php index 790e861ec93..d7bc4d6edf9 100644 --- a/htdocs/includes/modules/facture/pdf_huitre.modules.php +++ b/htdocs/includes/modules/facture/pdf_huitre.modules.php @@ -56,191 +56,212 @@ class pdf_huitre extends ModelePDFFactures { $this->description = $langs->trans('PDFHuitreDescription'); // Dimension page pour format A4 - $this->type = 'pdf'; + $this->type = 'pdf'; $this->page_largeur = 210; $this->page_hauteur = 297; $this->format = array($this->page_largeur,$this->page_hauteur); } - function write_pdf_file($facid) - { - global $user,$langs,$conf; - - if ($conf->facture->dir_output) - { - $fac = new Facture($this->db,"",$facid); - $fac->fetch($facid); - $facref = sanitize_string($fac->ref); - $dir = $conf->facture->dir_output . "/" . $facref; - $file = $dir . "/" . $facref . ".pdf"; - - if (! file_exists($dir)) - { - if (create_exdir($dir) < 0) - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } - } - - if (file_exists($dir)) - { - // Initialisation facture vierge - $pdf=new FPDF('P','mm','A4'); - $pdf->Open(); - $pdf->AddPage(); - - $this->_pagehead($pdf, $fac); - - $pdf->SetTitle($fac->ref); - $pdf->SetSubject($langs->trans("Bill")); - $pdf->SetCreator("Dolibarr (By ADYTEK)".DOL_VERSION); - $pdf->SetAuthor($user->fullname); - $pdf->SetMargins(10, 10, 10); - $pdf->SetAutoPageBreak(1,0); - $tab_top = 100; - $tab_height = 110; - - $pdf->SetFillColor(242,239,119); - - $pdf->SetFont('Arial','', 9); - - $pdf->SetXY (10, $tab_top + 10 ); - - $iniY = $pdf->GetY(); - $curY = $pdf->GetY(); - $nexY = $pdf->GetY(); - $nblignes = sizeof($fac->lignes); - - // Boucle sur les lignes de factures - for ($i = 0 ; $i < $nblignes ; $i++) - { - $curY = $nexY; - - $pdf->SetXY (11, $curY ); - $pdf->MultiCell(118, 5, $fac->lignes[$i]->desc, 0, 'J'); - - $nexY = $pdf->GetY(); - - $pdf->SetXY (133, $curY); - $pdf->MultiCell(10, 5, $fac->lignes[$i]->tva_taux, 0, 'C'); - - $pdf->SetXY (145, $curY); - $pdf->MultiCell(10, 5, $fac->lignes[$i]->qty, 0, 'C'); - - $pdf->SetXY (156, $curY); - $pdf->MultiCell(18, 5, price($fac->lignes[$i]->price), 0, 'R', 0); - - $pdf->SetXY (174, $curY); - $total = price($fac->lignes[$i]->price * $fac->lignes[$i]->qty); - $pdf->MultiCell(26, 5, $total, 0, 'R', 0); - - if ($nexY > 200 && $i < $nblignes - 1) - { - $this->_tableau($pdf, $tab_top, $tab_height, $nexY); - $pdf->AddPage(); - $nexY = $iniY; - $this->_pagehead($pdf, $fac); - $pdf->SetTextColor(0,0,0); - $pdf->SetFont('Arial','', 10); - } - - } - $this->_tableau($pdf, $tab_top, $tab_height, $nexY); - - $this->_tableau_tot($pdf, $fac); - - $this->_tableau_compl($pdf, $fac); - - /* - * - */ - if (defined("FACTURE_RIB_NUMBER")) - { - if (FACTURE_RIB_NUMBER > 0) - { - $account = new Account($this->db); - $account->fetch(FACTURE_RIB_NUMBER); - - $pdf->SetXY (10, 40); - $pdf->SetFont('Arial','U',8); - $pdf->MultiCell(40, 4, $langs->trans("BankDetails"), 0, 'L', 0); - $pdf->SetFont('Arial','',8); - $pdf->MultiCell(40, 4, $langs->trans("BankCode").' : ' . $account->code_banque, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("DeskCode").' : ' . $account->code_guichet, 0, 'L', 0); - $pdf->MultiCell(50, 4, $langs->trans("BankAccountNumber").' : ' . $account->number, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("BankAccountNumberKey").' : ' . $account->cle_rib, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("Residence").' : ' . $account->domiciliation, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("IbanPrefix").' : ' . $account->iban_prefix, 0, 'L', 0); - $pdf->MultiCell(40, 4, $langs->trans("BIC").' : ' . $account->bic, 0, 'L', 0); - } - } - - /* - * - * - */ - -// if ( $fac->note >0 ) -// { - $pdf->SetFont('Arial','',7); - $pdf->SetXY(10, 211); - $note = "Note : ".$fac->note; - $pdf->MultiCell(110, 3, $note, 0, 'J'); -// } - - $pdf->SetFont('Arial','U',11); - $pdf->SetXY(10, 225); - $titre = $langs->trans("PaymentConditions").' : '.$fac->cond_reglement_facture; - $pdf->MultiCell(190, 5, $titre, 0, 'J'); - - $pdf->SetFont('Arial','',6); - $pdf->SetXY(10, 265); - $pdf->MultiCell(90, 2, $langs->trans('LawApplicationPart1'), 0, 'J'); - $pdf->SetXY(10, 267); - $pdf->MultiCell(90, 2, $langs->trans('LawApplicationPart2'), 0, 'J'); - $pdf->SetXY(10, 269); - $pdf->MultiCell(90, 2, $langs->trans('LawApplicationPart3'), 0, 'J'); - $pdf->SetXY(10, 271); - $pdf->MultiCell(90, 2, $langs->trans('LawApplicationPart4'), 0, 'J'); - - $pdf->SetFont('Arial','',7); - $pdf->SetXY(85, 271); - $pdf->MultiCell(90, 3, $langs->trans('VATDischarged'), 0, 'J'); - - $this->_pagefoot($pdf, $fac); - $pdf->AliasNbPages(); - //---- - $pdf->SetTextColor(0,0,0); - $pdf->SetFillColor(242,239,119); - - $pdf->SetLineWidth(0.5); - - - - - - $pdf->Close(); - - $pdf->Output($file); - - return 1; // Pas d'erreur - } - else - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } - } - else + /** + * \brief Fonction générant la facture sur le disque + * \param fac Objet facture à générer (ou id si ancienne methode) + * \return int 1=ok, 0=ko + */ + function write_pdf_file($fac,$outputlangs='') { - $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); - return 0; + global $user,$langs,$conf,$mysoc; + + if ($conf->facture->dir_output) + { + // Définition de l'objet $fac (pour compatibilite ascendante) + if (! is_object($fac)) + { + $fac = new Facture($this->db,"",$fac); + $ret=$fac->fetch($fac); + } + + // Définition de $dir et $file + if ($fac->specimen) + { + $dir = $conf->facture->dir_output; + $file = $dir . "/SPECIMEN.pdf"; + } + else + { + $facref = sanitize_string($fac->ref); + $dir = $conf->facture->dir_output . "/" . $facref; + $file = $dir . "/" . $facref . ".pdf"; + } + + if (! file_exists($dir)) + { + if (create_exdir($dir) < 0) + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } + + if (file_exists($dir)) + { + // Initialisation facture vierge + $pdf=new FPDF('P','mm','A4'); + $pdf->Open(); + $pdf->AddPage(); + + $this->_pagehead($pdf, $fac); + + $pdf->SetTitle($fac->ref); + $pdf->SetSubject($langs->trans("Bill")); + $pdf->SetCreator("Dolibarr (By ADYTEK)".DOL_VERSION); + $pdf->SetAuthor($user->fullname); + $pdf->SetMargins(10, 10, 10); + $pdf->SetAutoPageBreak(1,0); + $tab_top = 100; + $tab_height = 110; + + $pdf->SetFillColor(242,239,119); + + $pdf->SetFont('Arial','', 9); + + $pdf->SetXY (10, $tab_top + 10 ); + + $iniY = $pdf->GetY(); + $curY = $pdf->GetY(); + $nexY = $pdf->GetY(); + $nblignes = sizeof($fac->lignes); + + // Boucle sur les lignes de factures + for ($i = 0 ; $i < $nblignes ; $i++) + { + $curY = $nexY; + + $pdf->SetXY (11, $curY ); + $pdf->MultiCell(118, 5, $fac->lignes[$i]->desc, 0, 'J'); + + $nexY = $pdf->GetY(); + + $pdf->SetXY (133, $curY); + $pdf->MultiCell(10, 5, $fac->lignes[$i]->tva_taux, 0, 'C'); + + $pdf->SetXY (145, $curY); + $pdf->MultiCell(10, 5, $fac->lignes[$i]->qty, 0, 'C'); + + $pdf->SetXY (156, $curY); + $pdf->MultiCell(18, 5, price($fac->lignes[$i]->price), 0, 'R', 0); + + $pdf->SetXY (174, $curY); + $total = price($fac->lignes[$i]->price * $fac->lignes[$i]->qty); + $pdf->MultiCell(26, 5, $total, 0, 'R', 0); + + if ($nexY > 200 && $i < $nblignes - 1) + { + $this->_tableau($pdf, $tab_top, $tab_height, $nexY); + $pdf->AddPage(); + $nexY = $iniY; + $this->_pagehead($pdf, $fac); + $pdf->SetTextColor(0,0,0); + $pdf->SetFont('Arial','', 10); + } + + } + $this->_tableau($pdf, $tab_top, $tab_height, $nexY); + + $this->_tableau_tot($pdf, $fac); + + $this->_tableau_compl($pdf, $fac); + + /* + * + */ + if (defined("FACTURE_RIB_NUMBER")) + { + if (FACTURE_RIB_NUMBER > 0) + { + $account = new Account($this->db); + $account->fetch(FACTURE_RIB_NUMBER); + + $pdf->SetXY (10, 40); + $pdf->SetFont('Arial','U',8); + $pdf->MultiCell(40, 4, $langs->trans("BankDetails"), 0, 'L', 0); + $pdf->SetFont('Arial','',8); + $pdf->MultiCell(40, 4, $langs->trans("BankCode").' : ' . $account->code_banque, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("DeskCode").' : ' . $account->code_guichet, 0, 'L', 0); + $pdf->MultiCell(50, 4, $langs->trans("BankAccountNumber").' : ' . $account->number, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("BankAccountNumberKey").' : ' . $account->cle_rib, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("Residence").' : ' . $account->domiciliation, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("IbanPrefix").' : ' . $account->iban_prefix, 0, 'L', 0); + $pdf->MultiCell(40, 4, $langs->trans("BIC").' : ' . $account->bic, 0, 'L', 0); + } + } + + /* + * + * + */ + + if ( $fac->note_public) + { + $pdf->SetFont('Arial','',7); + $pdf->SetXY(10, 211); + $note = $langs->trans("Note").' : '.$fac->note_public; + $pdf->MultiCell(110, 3, $note, 0, 'J'); + } + + $pdf->SetFont('Arial','U',11); + $pdf->SetXY(10, 225); + $titre = $langs->trans("PaymentConditions").' : '.$fac->cond_reglement_facture; + $pdf->MultiCell(190, 5, $titre, 0, 'J'); + + $pdf->SetFont('Arial','',6); + $pdf->SetXY(10, 265); + $pdf->MultiCell(90, 2, $langs->trans('LawApplicationPart1'), 0, 'J'); + $pdf->SetXY(10, 267); + $pdf->MultiCell(90, 2, $langs->trans('LawApplicationPart2'), 0, 'J'); + $pdf->SetXY(10, 269); + $pdf->MultiCell(90, 2, $langs->trans('LawApplicationPart3'), 0, 'J'); + $pdf->SetXY(10, 271); + $pdf->MultiCell(90, 2, $langs->trans('LawApplicationPart4'), 0, 'J'); + + $pdf->SetFont('Arial','',7); + $pdf->SetXY(85, 271); + $pdf->MultiCell(90, 3, $langs->trans('VATDischarged'), 0, 'J'); + + $this->_pagefoot($pdf, $fac); + $pdf->AliasNbPages(); + //---- + $pdf->SetTextColor(0,0,0); + $pdf->SetFillColor(242,239,119); + + $pdf->SetLineWidth(0.5); + + + + + + $pdf->Close(); + + $pdf->Output($file); + + return 1; // Pas d'erreur + } + else + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } + else + { + $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); + return 0; + } + $this->error=$langs->trans("ErrorUnknown"); + return 0; // Erreur par defaut } - $this->error=$langs->trans("ErrorUnknown"); - return 0; // Erreur par defaut - } + + /* * * @@ -499,11 +520,12 @@ class pdf_huitre extends ModelePDFFactures { /* * Definition du document */ - $pdf->SetXY(10,50); + $pdf->SetXY(10,16); $pdf->SetFont('Arial','B',16); $pdf->SetTextColor(0,0,200); - $pdf->MultiCell(50, 8, "FACTURE", '' , 'C'); - /* + $pdf->MultiCell(50, 2, "FACTURE", '' , 'C'); + + /* * Adresse Client */ $pdf->SetTextColor(0,0,0); @@ -528,15 +550,12 @@ class pdf_huitre extends ModelePDFFactures { $pdf->Text(35, 88, ": " . strftime("%d %b %Y", $fac->date)); $pdf->Text(11, 94, $langs->trans('Invoice')); $pdf->Text(35, 94, ": ".$fac->ref); - /* - */ - $pdf->line(200, 94, 205, 94 ); + + // Montants exprimes en euros $pdf->SetTextColor(0,0,0); $pdf->SetFont('Arial','',10); - $titre = $langs->trans("AmountInCurrency",$langs->trans("Currency".$conf->monnaie)); - $pdf->Text(200 - $pdf->GetStringWidth($titre), 94, $titre); - /* - */ + $titre = $langs->trans("AmountInCurrency",$langs->trans("Currency".$conf->monnaie)); + $pdf->Text(200 - $pdf->GetStringWidth($titre), 94, $titre); } diff --git a/htdocs/includes/modules/facture/pdf_oursin.modules.php b/htdocs/includes/modules/facture/pdf_oursin.modules.php index 6e85b000516..d22c6e8c32a 100644 --- a/htdocs/includes/modules/facture/pdf_oursin.modules.php +++ b/htdocs/includes/modules/facture/pdf_oursin.modules.php @@ -108,254 +108,267 @@ class pdf_oursin extends ModelePDFFactures * \remarks MAIN_INFO_CAPITAL * \remarks MAIN_INFO_TVAINTRA */ - function write_pdf_file($facid) + function write_pdf_file($fac,$outputlangs='') { - global $user,$langs,$conf,$mysoc; + global $user,$langs,$conf,$mysoc; + + $langs->load("main"); + $langs->load("bills"); + $langs->load("products"); + + if ($conf->facture->dir_output) + { + // Définition de l'objet $fac (pour compatibilite ascendante) + if (! is_object($fac)) + { + $fac = new Facture($this->db,"",$fac); + $ret=$fac->fetch($fac); + } - $langs->load("main"); - $langs->load("bills"); - $langs->load("products"); - - if ($conf->facture->dir_output) - { - $fac = new Facture($this->db,"",$facid); - $fac->fetch($facid); - - $facref = sanitize_string($fac->ref); - $dir = $conf->facture->dir_output . "/" . $facref; - $file = $dir . "/" . $facref . ".pdf"; - - if (! file_exists($dir)) - { - if (create_exdir($dir) < 0) - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } - } - - if (file_exists($dir)) - { - // Initialisation facture vierge - $pdf=new FPDF('P','mm',$this->format); - $pdf->Open(); - $pdf->AddPage(); - - $this->_pagehead($pdf, $fac); - - $pdf->SetTitle($fac->ref); - $pdf->SetSubject($langs->trans("Bill")); - $pdf->SetCreator("Dolibarr ".DOL_VERSION); - $pdf->SetAuthor($user->fullname); - - $pdf->SetMargins(10, 10, 10); - $pdf->SetAutoPageBreak(1,0); - - $tab_top = $this->marges['h']+90; - $tab_height = 110; - - $pdf->SetFillColor(220,220,220); - $pdf->SetFont('Arial','', 9); - $pdf->SetXY ($this->marges['g'], $tab_top + $this->marges['g'] ); - - $iniY = $pdf->GetY(); - $curY = $pdf->GetY(); - $nexY = $pdf->GetY(); - $nblignes = sizeof($fac->lignes); - - // Boucle sur les lignes de factures - for ($i = 0 ; $i < $nblignes ; $i++) - { - $curY = $nexY; - - // Description produit - $codeproduitservice=""; - $pdf->SetXY ($this->marges['g']+ 1, $curY ); - if (defined("FACTURE_CODEPRODUITSERVICE") && FACTURE_CODEPRODUITSERVICE) { - // Affiche code produit si ligne associée à un code produit - - $prodser = new Product($this->db); - - $prodser->fetch($fac->lignes[$i]->produit_id); - if ($prodser->ref) { - $codeproduitservice=" - ".$langs->trans("ProductCode")." ".$prodser->ref; - } + // Définition de $dir et $file + if ($fac->specimen) + { + $dir = $conf->facture->dir_output; + $file = $dir . "/SPECIMEN.pdf"; + } + else + { + $facref = sanitize_string($fac->ref); + $dir = $conf->facture->dir_output . "/" . $facref; + $file = $dir . "/" . $facref . ".pdf"; + } + + if (! file_exists($dir)) + { + if (create_exdir($dir) < 0) + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } + + if (file_exists($dir)) + { + // Initialisation facture vierge + $pdf=new FPDF('P','mm',$this->format); + $pdf->Open(); + $pdf->AddPage(); + + $this->_pagehead($pdf, $fac); + + $pdf->SetTitle($fac->ref); + $pdf->SetSubject($langs->trans("Invoice")); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); + $pdf->SetAuthor($user->fullname); + + $pdf->SetMargins(10, 10, 10); + $pdf->SetAutoPageBreak(1,0); + + $tab_top = $this->marges['h']+90; + $tab_height = 110; + + $pdf->SetFillColor(220,220,220); + $pdf->SetFont('Arial','', 9); + $pdf->SetXY ($this->marges['g'], $tab_top + $this->marges['g'] ); + + $iniY = $pdf->GetY(); + $curY = $pdf->GetY(); + $nexY = $pdf->GetY(); + $nblignes = sizeof($fac->lignes); + + // Boucle sur les lignes de factures + for ($i = 0 ; $i < $nblignes ; $i++) + { + $curY = $nexY; + + // Description produit + $codeproduitservice=""; + $pdf->SetXY ($this->marges['g']+ 1, $curY ); + if (defined("FACTURE_CODEPRODUITSERVICE") && FACTURE_CODEPRODUITSERVICE) { + // Affiche code produit si ligne associée à un code produit + + $prodser = new Product($this->db); + + $prodser->fetch($fac->lignes[$i]->produit_id); + if ($prodser->ref) { + $codeproduitservice=" - ".$langs->trans("ProductCode")." ".$prodser->ref; + } + } + if ($fac->lignes[$i]->date_start && $fac->lignes[$i]->date_end) { + // Affichage durée si il y en a une + $codeproduitservice.=" (".$langs->trans("From")." ".dolibarr_print_date($fac->lignes[$i]->date_start)." ".$langs->trans("to")." ".dolibarr_print_date($fac->lignes[$i]->date_end).")"; + } + $pdf->MultiCell(108, 5, $fac->lignes[$i]->desc."$codeproduitservice", 0, 'J'); + + $nexY = $pdf->GetY(); + + // TVA + if ($this->franchise!=1) + { + $pdf->SetXY ($this->marges['g']+119, $curY); + $pdf->MultiCell(10, 5, $fac->lignes[$i]->tva_taux, 0, 'C'); + } + // Prix unitaire HT avant remise + $pdf->SetXY ($this->marges['g']+132, $curY); + $pdf->MultiCell(16, 5, price($fac->lignes[$i]->subprice), 0, 'R', 0); + + // Quantit + $pdf->SetXY ($this->marges['g']+150, $curY); + $pdf->MultiCell(10, 5, $fac->lignes[$i]->qty, 0, 'R'); + + // Remise sur ligne + $pdf->SetXY ($this->marges['g']+160, $curY); + if ($fac->lignes[$i]->remise_percent) { + $pdf->MultiCell(14, 5, $fac->lignes[$i]->remise_percent."%", 0, 'R'); + } + + // Total HT + $pdf->SetXY ($this->marges['g']+168, $curY); + $total = price($fac->lignes[$i]->price * $fac->lignes[$i]->qty); + $pdf->MultiCell(21, 5, $total, 0, 'R', 0); + + + if ($nexY > 200 && $i < $nblignes - 1) + { + $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $fac); + $pdf->AddPage(); + $nexY = $iniY; + $this->_pagehead($pdf, $fac); + $pdf->SetTextColor(0,0,0); + $pdf->SetFont('Arial','', 10); + } + + } + $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $fac); + + $deja_regle = $fac->getSommePaiement(); + + $this->_tableau_tot($pdf, $fac, $deja_regle); + + if ($deja_regle) { + $this->_tableau_versements($pdf, $fac); + } + + /* + * Mode de règlement + */ + if ((! defined("FACTURE_CHQ_NUMBER") || ! FACTURE_CHQ_NUMBER) && (! defined("FACTURE_RIB_NUMBER") || ! FACTURE_RIB_NUMBER)) { + $pdf->SetXY ($this->marges['g'], 228); + $pdf->SetTextColor(200,0,0); + $pdf->SetFont('Arial','B',8); + $pdf->MultiCell(90, 3, $langs->trans("ErrorNoPaiementModeConfigured"),0,'L',0); + $pdf->MultiCell(90, 3, $langs->trans("ErrorCreateBankAccount"),0,'L',0); + $pdf->SetTextColor(0,0,0); + } + + /* + * Propose mode règlement par CHQ + */ + if (defined("FACTURE_CHQ_NUMBER")) + { + if (FACTURE_CHQ_NUMBER > 0) + { + $account = new Account($this->db); + $account->fetch(FACTURE_CHQ_NUMBER); + + $pdf->SetXY ($this->marges['g'], 225); + $pdf->SetFont('Arial','B',8); + $pdf->MultiCell(90, 3, $langs->trans('PaymentByChequeOrderedTo').' '.$account->proprio.' '.$langs->trans('SendTo').':',0,'L',0); + $pdf->SetXY ($this->marges['g'], 230); + $pdf->SetFont('Arial','',8); + $pdf->MultiCell(80, 3, $account->adresse_proprio, 0, 'L', 0); + } + } + + /* + * Propose mode règlement par RIB + */ + if (defined("FACTURE_RIB_NUMBER")) + { + if (FACTURE_RIB_NUMBER > 0) + { + $account = new Account($this->db); + $account->fetch(FACTURE_RIB_NUMBER); + + $cury=240; + $pdf->SetXY ($this->marges['g'], $cury); + $pdf->SetFont('Arial','B',8); + $pdf->MultiCell(90, 3, $langs->trans('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0); + $cury=245; + $pdf->SetFont('Arial','B',6); + $pdf->line($this->marges['g'], $cury, $this->marges['g'], $cury+10 ); + $pdf->SetXY ($this->marges['g'], $cury); + $pdf->MultiCell(18, 3, $langs->trans("BankCode"), 0, 'C', 0); + $pdf->line($this->marges['g']+18, $cury, $this->marges['g']+18, $cury+10 ); + $pdf->SetXY ($this->marges['g']+18, $cury); + $pdf->MultiCell(18, 3, $langs->trans("DeskCode"), 0, 'C', 0); + $pdf->line($this->marges['g']+36, $cury, $this->marges['g']+36, $cury+10 ); + $pdf->SetXY ($this->marges['g']+36, $cury); + $pdf->MultiCell(24, 3, $langs->trans("BankAccountNumber"), 0, 'C', 0); + $pdf->line($this->marges['g']+60, $cury, $this->marges['g']+60, $cury+10 ); + $pdf->SetXY ($this->marges['g']+60, $cury); + $pdf->MultiCell(13, 3, $langs->trans("BankAccountNumberKey"), 0, 'C', 0); + $pdf->line($this->marges['g']+73, $cury, $this->marges['g']+73, $cury+10 ); + + $pdf->SetFont('Arial','',8); + $pdf->SetXY ($this->marges['g'], $cury+5); + $pdf->MultiCell(18, 3, $account->code_banque, 0, 'C', 0); + $pdf->SetXY ($this->marges['g']+18, $cury+5); + $pdf->MultiCell(18, 3, $account->code_guichet, 0, 'C', 0); + $pdf->SetXY ($this->marges['g']+36, $cury+5); + $pdf->MultiCell(24, 3, $account->number, 0, 'C', 0); + $pdf->SetXY ($this->marges['g']+60, $cury+5); + $pdf->MultiCell(13, 3, $account->cle_rib, 0, 'C', 0); + + $pdf->SetXY ($this->marges['g'], $cury+15); + $pdf->MultiCell(90, 3, $langs->trans("Residence").' : ' . $account->domiciliation, 0, 'L', 0); + $pdf->SetXY ($this->marges['g'], $cury+25); + $pdf->MultiCell(90, 3, $langs->trans("IbanPrefix").' : ' . $account->iban_prefix, 0, 'L', 0); + $pdf->SetXY ($this->marges['g'], $cury+30); + $pdf->MultiCell(90, 3, $langs->trans("BIC").' : ' . $account->bic, 0, 'L', 0); + } + } + + /* + * Conditions de règlements + */ + if ($fac->cond_reglement_code) + { + $pdf->SetFont('Arial','B',10); + $pdf->SetXY($this->marges['g'], 217); + $titre = $langs->trans("PaymentConditions").':'; + $pdf->MultiCell(80, 5, $titre, 0, 'L'); + $pdf->SetFont('Arial','',10); + $pdf->SetXY($this->marges['g']+44, 217); + $pdf->MultiCell(80, 5, $fac->cond_reglement_facture,0,'L'); + } + + /* + * Pied de page + */ + $this->_pagefoot($pdf, $fac); + $pdf->AliasNbPages(); + + $pdf->Close(); + + $pdf->Output($file); + + return 1; // Pas d'erreur + } + else + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } } - if ($fac->lignes[$i]->date_start && $fac->lignes[$i]->date_end) { - // Affichage durée si il y en a une - $codeproduitservice.=" (".$langs->trans("From")." ".dolibarr_print_date($fac->lignes[$i]->date_start)." ".$langs->trans("to")." ".dolibarr_print_date($fac->lignes[$i]->date_end).")"; + else + { + $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); + return 0; } - $pdf->MultiCell(108, 5, $fac->lignes[$i]->desc."$codeproduitservice", 0, 'J'); - - $nexY = $pdf->GetY(); - - // TVA - if ($this->franchise!=1) - { - $pdf->SetXY ($this->marges['g']+119, $curY); - $pdf->MultiCell(10, 5, $fac->lignes[$i]->tva_taux, 0, 'C'); - } - // Prix unitaire HT avant remise - $pdf->SetXY ($this->marges['g']+132, $curY); - $pdf->MultiCell(16, 5, price($fac->lignes[$i]->subprice), 0, 'R', 0); - - // Quantité - $pdf->SetXY ($this->marges['g']+150, $curY); - $pdf->MultiCell(10, 5, $fac->lignes[$i]->qty, 0, 'R'); - - // Remise sur ligne - $pdf->SetXY ($this->marges['g']+160, $curY); - if ($fac->lignes[$i]->remise_percent) { - $pdf->MultiCell(14, 5, $fac->lignes[$i]->remise_percent."%", 0, 'R'); - } - - // Total HT - $pdf->SetXY ($this->marges['g']+168, $curY); - $total = price($fac->lignes[$i]->price * $fac->lignes[$i]->qty); - $pdf->MultiCell(21, 5, $total, 0, 'R', 0); - - - if ($nexY > 200 && $i < $nblignes - 1) - { - $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $fac); - $pdf->AddPage(); - $nexY = $iniY; - $this->_pagehead($pdf, $fac); - $pdf->SetTextColor(0,0,0); - $pdf->SetFont('Arial','', 10); - } - - } - $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $fac); - - $deja_regle = $fac->getSommePaiement(); - - $this->_tableau_tot($pdf, $fac, $deja_regle); - - if ($deja_regle) { - $this->_tableau_versements($pdf, $fac); - } - - /* - * Mode de règlement - */ - if ((! defined("FACTURE_CHQ_NUMBER") || ! FACTURE_CHQ_NUMBER) && (! defined("FACTURE_RIB_NUMBER") || ! FACTURE_RIB_NUMBER)) { - $pdf->SetXY ($this->marges['g'], 228); - $pdf->SetTextColor(200,0,0); - $pdf->SetFont('Arial','B',8); - $pdf->MultiCell(90, 3, $langs->trans("ErrorNoPaiementModeConfigured"),0,'L',0); - $pdf->MultiCell(90, 3, $langs->trans("ErrorCreateBankAccount"),0,'L',0); - $pdf->SetTextColor(0,0,0); - } - - /* - * Propose mode règlement par CHQ - */ - if (defined("FACTURE_CHQ_NUMBER")) - { - if (FACTURE_CHQ_NUMBER > 0) - { - $account = new Account($this->db); - $account->fetch(FACTURE_CHQ_NUMBER); - - $pdf->SetXY ($this->marges['g'], 225); - $pdf->SetFont('Arial','B',8); - $pdf->MultiCell(90, 3, $langs->trans('PaymentByChequeOrderedTo').' '.$account->proprio.' '.$langs->trans('SendTo').':',0,'L',0); - $pdf->SetXY ($this->marges['g'], 230); - $pdf->SetFont('Arial','',8); - $pdf->MultiCell(80, 3, $account->adresse_proprio, 0, 'L', 0); - } - } - - /* - * Propose mode règlement par RIB - */ - if (defined("FACTURE_RIB_NUMBER")) - { - if (FACTURE_RIB_NUMBER > 0) - { - $account = new Account($this->db); - $account->fetch(FACTURE_RIB_NUMBER); - - $cury=240; - $pdf->SetXY ($this->marges['g'], $cury); - $pdf->SetFont('Arial','B',8); - $pdf->MultiCell(90, 3, $langs->trans('PaymentByTransferOnThisBankAccount').':', 0, 'L', 0); - $cury=245; - $pdf->SetFont('Arial','B',6); - $pdf->line($this->marges['g'], $cury, $this->marges['g'], $cury+10 ); - $pdf->SetXY ($this->marges['g'], $cury); - $pdf->MultiCell(18, 3, $langs->trans("BankCode"), 0, 'C', 0); - $pdf->line($this->marges['g']+18, $cury, $this->marges['g']+18, $cury+10 ); - $pdf->SetXY ($this->marges['g']+18, $cury); - $pdf->MultiCell(18, 3, $langs->trans("DeskCode"), 0, 'C', 0); - $pdf->line($this->marges['g']+36, $cury, $this->marges['g']+36, $cury+10 ); - $pdf->SetXY ($this->marges['g']+36, $cury); - $pdf->MultiCell(24, 3, $langs->trans("BankAccountNumber"), 0, 'C', 0); - $pdf->line($this->marges['g']+60, $cury, $this->marges['g']+60, $cury+10 ); - $pdf->SetXY ($this->marges['g']+60, $cury); - $pdf->MultiCell(13, 3, $langs->trans("BankAccountNumberKey"), 0, 'C', 0); - $pdf->line($this->marges['g']+73, $cury, $this->marges['g']+73, $cury+10 ); - - $pdf->SetFont('Arial','',8); - $pdf->SetXY ($this->marges['g'], $cury+5); - $pdf->MultiCell(18, 3, $account->code_banque, 0, 'C', 0); - $pdf->SetXY ($this->marges['g']+18, $cury+5); - $pdf->MultiCell(18, 3, $account->code_guichet, 0, 'C', 0); - $pdf->SetXY ($this->marges['g']+36, $cury+5); - $pdf->MultiCell(24, 3, $account->number, 0, 'C', 0); - $pdf->SetXY ($this->marges['g']+60, $cury+5); - $pdf->MultiCell(13, 3, $account->cle_rib, 0, 'C', 0); - - $pdf->SetXY ($this->marges['g'], $cury+15); - $pdf->MultiCell(90, 3, $langs->trans("Residence").' : ' . $account->domiciliation, 0, 'L', 0); - $pdf->SetXY ($this->marges['g'], $cury+25); - $pdf->MultiCell(90, 3, $langs->trans("IbanPrefix").' : ' . $account->iban_prefix, 0, 'L', 0); - $pdf->SetXY ($this->marges['g'], $cury+30); - $pdf->MultiCell(90, 3, $langs->trans("BIC").' : ' . $account->bic, 0, 'L', 0); - } - } - - /* - * Conditions de règlements - */ - if ($fac->cond_reglement_code) - { - $pdf->SetFont('Arial','B',10); - $pdf->SetXY($this->marges['g'], 217); - $titre = $langs->trans("PaymentConditions").':'; - $pdf->MultiCell(80, 5, $titre, 0, 'L'); - $pdf->SetFont('Arial','',10); - $pdf->SetXY($this->marges['g']+44, 217); - $pdf->MultiCell(80, 5, $fac->cond_reglement_facture,0,'L'); - } - - /* - * Pied de page - */ - $this->_pagefoot($pdf, $fac); - $pdf->AliasNbPages(); - - $pdf->Close(); - - $pdf->Output($file); - - return 1; // Pas d'erreur - } - else - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } - } - else - { - $this->error=$langs->trans("ErrorConstantNotDefined","FAC_OUTPUTDIR"); - return 0; - } - $this->error=$langs->trans("ErrorUnknown"); - return 0; // Erreur par defaut - } + $this->error=$langs->trans("ErrorUnknown"); + return 0; // Erreur par defaut + } /* @@ -469,7 +482,7 @@ class pdf_oursin extends ModelePDFFactures $pdf->SetXY ($this->marges['g'], $tab2_top + 0); if ($this->franchise==1) { - $pdf->MultiCell(100, $tab2_hl, $langs->trans("VATIsNotUsed"), 0, 'L', 0); + $pdf->MultiCell(100, $tab2_hl, $langs->trans("VATIsNotUsedForInvoice"), 0, 'L', 0); } // Tableau total diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 6208dbcdca5..59536883853 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -175,7 +175,7 @@ IntracommunityVATNumber=Intracommunity number of VAT PaymentByChequeOrderedTo=Règlement par chèque à l'ordre de SendTo=envoyé à PaymentByTransferOnThisBankAccount=Payment by transfer on the following bank account -VATIsNotUsed=* TVA non applicable art-293B du CGI +VATIsNotUsedForInvoice=* TVA non applicable art-293B du CGI LawApplicationPart1=Par application de la loi 80.335 du 12/05/80 LawApplicationPart2=les marchandises demeurent la propriété du LawApplicationPart3=vendeur jusqu'à complet encaissement de diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index a7c26996227..5ca3abaf85f 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -175,7 +175,7 @@ IntracommunityVATNumber=Num PaymentByChequeOrderedTo=Règlement par chèque à l'ordre de SendTo=envoyé à PaymentByTransferOnThisBankAccount=Règlement par virement sur le compte bancaire suivant -VATIsNotUsed=* TVA non applicable art-293B du CGI +VATIsNotUsedForInvoice=* TVA non applicable art-293B du CGI LawApplicationPart1=Par application de la loi 80.335 du 12/05/80 LawApplicationPart2=les marchandises demeurent la propriété du LawApplicationPart3=vendeur jusqu'à complet encaissement de diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php index 19a1237f453..121daaa996b 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.inc.php @@ -731,10 +731,15 @@ function img_disable($alt = "default") \brief Affiche logo help avec curseur "?" \return string Retourne tag img */ -function img_help($usehelpcursor=1) +function img_help($usehelpcursor=1,$usealttitle=1) { - global $conf,$langs; - return ''.$langs->trans('; + global $conf,$langs; + $s ='theme.'/img/help.png" border="0"'; + if ($usealttitle) $s.=' alt="'.$langs->trans("Info").'" title="'.$langs->trans("Info"); + $s.='">'; + return $s; } /**