PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/modules/commande/pdf_einstein.modules.php

https://github.com/asterix14/dolibarr
PHP | 998 lines | 662 code | 163 blank | 173 comment | 88 complexity | 817315fd3c84569c860a5209f73ab085 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  4. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  5. * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. * or see http://www.gnu.org/
  20. */
  21. /**
  22. * \file htdocs/core/modules/commande/pdf_einstein.modules.php
  23. * \ingroup commande
  24. * \brief Fichier de la classe permettant de generer les commandes au modele Einstein
  25. * \author Laurent Destailleur
  26. */
  27. require_once(DOL_DOCUMENT_ROOT ."/core/modules/commande/modules_commande.php");
  28. require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  29. require_once(DOL_DOCUMENT_ROOT."/core/lib/company.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
  31. require_once(DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php');
  32. /**
  33. * \class pdf_einstein
  34. * \brief Classe permettant de generer les commandes au modele Einstein
  35. */
  36. class pdf_einstein extends ModelePDFCommandes
  37. {
  38. var $db;
  39. var $name;
  40. var $description;
  41. var $type;
  42. var $phpmin = array(4,3,0); // Minimum version of PHP required by module
  43. var $version = 'dolibarr';
  44. var $page_largeur;
  45. var $page_hauteur;
  46. var $format;
  47. var $marge_gauche;
  48. var $marge_droite;
  49. var $marge_haute;
  50. var $marge_basse;
  51. var $emetteur; // Objet societe qui emet
  52. /**
  53. * Constructor
  54. *
  55. * @param DoliDB $DB Database handler
  56. */
  57. function pdf_einstein($db)
  58. {
  59. global $conf,$langs,$mysoc;
  60. $langs->load("main");
  61. $langs->load("bills");
  62. $this->db = $db;
  63. $this->name = "einstein";
  64. $this->description = $langs->trans('PDFEinsteinDescription');
  65. // Dimension page pour format A4
  66. $this->type = 'pdf';
  67. $formatarray=pdf_getFormat();
  68. $this->page_largeur = $formatarray['width'];
  69. $this->page_hauteur = $formatarray['height'];
  70. $this->format = array($this->page_largeur,$this->page_hauteur);
  71. $this->marge_gauche=10;
  72. $this->marge_droite=10;
  73. $this->marge_haute=10;
  74. $this->marge_basse=10;
  75. $this->option_logo = 1; // Affiche logo
  76. $this->option_tva = 1; // Gere option tva FACTURE_TVAOPTION
  77. $this->option_modereg = 1; // Affiche mode reglement
  78. $this->option_condreg = 1; // Affiche conditions reglement
  79. $this->option_codeproduitservice = 1; // Affiche code produit-service
  80. $this->option_multilang = 1; // Dispo en plusieurs langues
  81. $this->option_escompte = 1; // Affiche si il y a eu escompte
  82. $this->option_credit_note = 1; // Support credit notes
  83. $this->option_freetext = 1; // Support add of a personalised text
  84. $this->option_draft_watermark = 1; //Support add of a watermark on drafts
  85. $this->franchise=!$mysoc->tva_assuj;
  86. // Recupere emmetteur
  87. $this->emetteur=$mysoc;
  88. if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // By default, if was not defined
  89. // Defini position des colonnes
  90. $this->posxdesc=$this->marge_gauche+1;
  91. $this->posxtva=111;
  92. $this->posxup=126;
  93. $this->posxqty=145;
  94. $this->posxdiscount=162;
  95. $this->postotalht=174;
  96. $this->tva=array();
  97. $this->localtax1=array();
  98. $this->localtax2=array();
  99. $this->atleastoneratenotnull=0;
  100. $this->atleastonediscount=0;
  101. }
  102. /**
  103. * Function to build pdf onto disk
  104. *
  105. * @param int $object Id of object to generate
  106. * @param object $outputlangs Lang output object
  107. * @param string $srctemplatepath Full path of source filename for generator using a template file
  108. * @param int $hidedetails Do not show line details
  109. * @param int $hidedesc Do not show desc
  110. * @param int $hideref Do not show ref
  111. * @param object $hookmanager Hookmanager object
  112. * @return int 1=OK, 0=KO
  113. */
  114. function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0,$hookmanager=false)
  115. {
  116. global $user,$langs,$conf;
  117. $default_font_size = pdf_getPDFFontSize($outputlangs);
  118. if (! is_object($outputlangs)) $outputlangs=$langs;
  119. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  120. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  121. $outputlangs->load("main");
  122. $outputlangs->load("dict");
  123. $outputlangs->load("companies");
  124. $outputlangs->load("bills");
  125. $outputlangs->load("products");
  126. $outputlangs->load("orders");
  127. if ($conf->commande->dir_output)
  128. {
  129. $object->fetch_thirdparty();
  130. $deja_regle = "";
  131. // Definition de $dir et $file
  132. if ($object->specimen)
  133. {
  134. $dir = $conf->commande->dir_output;
  135. $file = $dir . "/SPECIMEN.pdf";
  136. }
  137. else
  138. {
  139. $objectref = dol_sanitizeFileName($object->ref);
  140. $dir = $conf->commande->dir_output . "/" . $objectref;
  141. $file = $dir . "/" . $objectref . ".pdf";
  142. }
  143. if (! file_exists($dir))
  144. {
  145. if (create_exdir($dir) < 0)
  146. {
  147. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  148. return 0;
  149. }
  150. }
  151. if (file_exists($dir))
  152. {
  153. $nblignes = count($object->lines);
  154. $pdf=pdf_getInstance($this->format);
  155. if (class_exists('TCPDF'))
  156. {
  157. $pdf->setPrintHeader(false);
  158. $pdf->setPrintFooter(false);
  159. }
  160. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  161. $pdf->Open();
  162. $pagenb=0;
  163. $pdf->SetDrawColor(128,128,128);
  164. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  165. $pdf->SetSubject($outputlangs->transnoentities("Order"));
  166. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  167. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  168. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order"));
  169. if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
  170. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  171. $pdf->SetAutoPageBreak(1,0);
  172. // Positionne $this->atleastonediscount si on a au moins une remise
  173. for ($i = 0 ; $i < $nblignes ; $i++)
  174. {
  175. if ($object->lines[$i]->remise_percent)
  176. {
  177. $this->atleastonediscount++;
  178. }
  179. }
  180. // New page
  181. $pdf->AddPage();
  182. $pagenb++;
  183. $this->_pagehead($pdf, $object, 1, $outputlangs);
  184. $pdf->SetFont('','', $default_font_size - 1);
  185. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  186. $pdf->SetTextColor(0,0,0);
  187. $tab_top = 90;
  188. $tab_top_newpage = 50;
  189. $tab_height = 110;
  190. $tab_height_newpage = 150;
  191. // Affiche notes
  192. if (! empty($object->note_public))
  193. {
  194. $tab_top = 88;
  195. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  196. $pdf->SetXY($this->posxdesc-1, $tab_top);
  197. $pdf->MultiCell(190, 3, $outputlangs->convToOutputCharset($object->note_public), 0, 'L');
  198. $nexY = $pdf->GetY();
  199. $height_note=$nexY-$tab_top;
  200. // Rect prend une longueur en 3eme et 4eme param
  201. $pdf->SetDrawColor(192,192,192);
  202. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  203. $tab_height = $tab_height - $height_note;
  204. $tab_top = $nexY+6;
  205. }
  206. else
  207. {
  208. $height_note=0;
  209. }
  210. $iniY = $tab_top + 7;
  211. $curY = $tab_top + 7;
  212. $nexY = $tab_top + 7;
  213. // Loop on each lines
  214. for ($i = 0 ; $i < $nblignes ; $i++)
  215. {
  216. $curY = $nexY;
  217. $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page
  218. // Description of product line
  219. $curX = $this->posxdesc-1;
  220. pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc,0,$hookmanager);
  221. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  222. $nexY = $pdf->GetY();
  223. // TVA
  224. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  225. {
  226. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails, $hookmanager);
  227. $pdf->SetXY($this->posxtva, $curY);
  228. $pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R');
  229. }
  230. // Prix unitaire HT avant remise
  231. $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
  232. $pdf->SetXY($this->posxup, $curY);
  233. $pdf->MultiCell($this->posxqty-$this->posxup-1, 3, $up_excl_tax, 0, 'R', 0);
  234. // Quantity
  235. $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails, $hookmanager);
  236. $pdf->SetXY($this->posxqty, $curY);
  237. $pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 3, $qty, 0, 'R');
  238. // Remise sur ligne
  239. $pdf->SetXY($this->posxdiscount, $curY);
  240. if ($object->lines[$i]->remise_percent)
  241. {
  242. $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails, $hookmanager);
  243. $pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 3, $remise_percent, 0, 'R');
  244. }
  245. // Total HT ligne
  246. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails, $hookmanager);
  247. $pdf->SetXY($this->postotalht, $curY);
  248. $pdf->MultiCell(26, 3, $total_excl_tax, 0, 'R', 0);
  249. // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
  250. $tvaligne=$object->lines[$i]->total_tva;
  251. $localtax1ligne=$object->lines[$i]->total_localtax1;
  252. $localtax2ligne=$object->lines[$i]->total_localtax2;
  253. $vatrate=(string) $object->lines[$i]->tva_tx;
  254. $localtax1rate=(string) $object->lines[$i]->localtax1_tx;
  255. $localtax2rate=(string) $object->lines[$i]->localtax2_tx;
  256. if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
  257. $this->tva[$vatrate] += $tvaligne;
  258. $this->localtax1[$localtax1rate]+=$localtax1ligne;
  259. $this->localtax2[$localtax2rate]+=$localtax2ligne;
  260. $nexY+=2; // Passe espace entre les lignes
  261. // Cherche nombre de lignes a venir pour savoir si place suffisante
  262. if ($i < ($nblignes - 1) && empty($hidedesc)) // If it's not last line
  263. {
  264. //on recupere la description du produit suivant
  265. $follow_descproduitservice = $object->lines[$i+1]->desc;
  266. //on compte le nombre de ligne afin de verifier la place disponible (largeur de ligne 52 caracteres)
  267. $nblineFollowDesc = (dol_nboflines_bis($follow_descproduitservice,52,$outputlangs->charset_output)*4);
  268. // Et si on affiche dates de validite, on ajoute encore une ligne
  269. if ($object->lines[$i]->date_start && $object->lines[$i]->date_end)
  270. {
  271. $nblineFollowDesc += 4;
  272. }
  273. }
  274. else // If it's last line
  275. {
  276. $nblineFollowDesc = 0;
  277. }
  278. // Test if a new page is required
  279. if ($pagenb == 1)
  280. {
  281. $tab_top_in_current_page=$tab_top;
  282. $tab_height_in_current_page=$tab_height;
  283. }
  284. else
  285. {
  286. $tab_top_in_current_page=$tab_top_newpage;
  287. $tab_height_in_current_page=$tab_height_newpage;
  288. }
  289. if (($nexY+$nblineFollowDesc) > ($tab_top_in_current_page+$tab_height_in_current_page) && $i < ($nblignes - 1))
  290. {
  291. if ($pagenb == 1)
  292. {
  293. $this->_tableau($pdf, $tab_top, $tab_height + 20, $nexY, $outputlangs);
  294. }
  295. else
  296. {
  297. $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
  298. }
  299. $this->_pagefoot($pdf,$object,$outputlangs);
  300. // New page
  301. $pdf->AddPage();
  302. $pagenb++;
  303. $this->_pagehead($pdf, $object, 0, $outputlangs);
  304. $pdf->SetFont('','', $default_font_size - 1);
  305. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  306. $pdf->SetTextColor(0,0,0);
  307. $nexY = $tab_top_newpage + 7;
  308. }
  309. }
  310. // Show square
  311. if ($pagenb == 1)
  312. {
  313. $this->_tableau($pdf, $tab_top, $tab_height, $nexY, $outputlangs);
  314. $bottomlasttab=$tab_top + $tab_height + 1;
  315. }
  316. else
  317. {
  318. $this->_tableau($pdf, $tab_top_newpage, $tab_height_newpage, $nexY, $outputlangs);
  319. $bottomlasttab=$tab_top_newpage + $tab_height_newpage + 1;
  320. }
  321. // Affiche zone infos
  322. $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
  323. // Affiche zone totaux
  324. $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
  325. // Affiche zone versements
  326. if ($deja_regle)
  327. {
  328. $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
  329. }
  330. // Pied de page
  331. $this->_pagefoot($pdf,$object,$outputlangs);
  332. $pdf->AliasNbPages();
  333. $pdf->Close();
  334. $pdf->Output($file,'F');
  335. if (! empty($conf->global->MAIN_UMASK))
  336. @chmod($file, octdec($conf->global->MAIN_UMASK));
  337. return 1; // Pas d'erreur
  338. }
  339. else
  340. {
  341. $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
  342. return 0;
  343. }
  344. }
  345. else
  346. {
  347. $this->error=$langs->trans("ErrorConstantNotDefined","COMMANDE_OUTPUTDIR");
  348. return 0;
  349. }
  350. $this->error=$langs->trans("ErrorUnknown");
  351. return 0; // Erreur par defaut
  352. }
  353. /**
  354. * Affiche tableau des versement
  355. *
  356. * @param pdf Object PDF
  357. * @param object Object order
  358. * @param posy Position y in PDF
  359. * @param outputlangs Object langs for output
  360. * @return int <0 if KO, >0 if OK
  361. */
  362. function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
  363. {
  364. }
  365. /**
  366. * Affiche infos divers
  367. *
  368. * @param pdf Object PDF
  369. * @param object Object order
  370. * @param posy Position depart
  371. * @param outputlangs Objet langs
  372. * @return y Position pour suite
  373. */
  374. function _tableau_info(&$pdf, $object, $posy, $outputlangs)
  375. {
  376. global $conf;
  377. $default_font_size = pdf_getPDFFontSize($outputlangs);
  378. $pdf->SetFont('','', $default_font_size - 1);
  379. // If France, show VAT mention if not applicable
  380. if ($this->emetteur->pays_code == 'FR' && $this->franchise == 1)
  381. {
  382. $pdf->SetFont('','B', $default_font_size - 2);
  383. $pdf->SetXY($this->marge_gauche, $posy);
  384. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  385. $posy=$pdf->GetY()+4;
  386. }
  387. // Show payments conditions
  388. if ($object->cond_reglement_code || $object->cond_reglement)
  389. {
  390. $pdf->SetFont('','B', $default_font_size - 2);
  391. $pdf->SetXY($this->marge_gauche, $posy);
  392. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  393. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  394. $pdf->SetFont('','', $default_font_size - 2);
  395. $pdf->SetXY(52, $posy);
  396. $lib_condition_paiement=$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code)!=('PaymentCondition'.$object->cond_reglement_code)?$outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code):$outputlangs->convToOutputCharset($object->cond_reglement_doc);
  397. $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
  398. $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L');
  399. $posy=$pdf->GetY()+3;
  400. }
  401. // Check a payment mode is defined
  402. /* Not used with orders
  403. if (empty($object->mode_reglement_code)
  404. && ! $conf->global->FACTURE_CHQ_NUMBER
  405. && ! $conf->global->FACTURE_RIB_NUMBER)
  406. {
  407. $pdf->SetXY($this->marge_gauche, $posy);
  408. $pdf->SetTextColor(200,0,0);
  409. $pdf->SetFont('','B', $default_font_size - 2);
  410. $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
  411. $pdf->SetTextColor(0,0,0);
  412. $posy=$pdf->GetY()+1;
  413. }
  414. */
  415. // Show payment mode
  416. if ($object->mode_reglement_code
  417. && $object->mode_reglement_code != 'CHQ'
  418. && $object->mode_reglement_code != 'VIR')
  419. {
  420. $pdf->SetFont('','B', $default_font_size - 2);
  421. $pdf->SetXY($this->marge_gauche, $posy);
  422. $titre = $outputlangs->transnoentities("PaymentMode").':';
  423. $pdf->MultiCell(80, 5, $titre, 0, 'L');
  424. $pdf->SetFont('','', $default_font_size - 2);
  425. $pdf->SetXY(50, $posy);
  426. $lib_mode_reg=$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code)!=('PaymentType'.$object->mode_reglement_code)?$outputlangs->transnoentities("PaymentType".$object->mode_reglement_code):$outputlangs->convToOutputCharset($object->mode_reglement);
  427. $pdf->MultiCell(80, 5, $lib_mode_reg,0,'L');
  428. $posy=$pdf->GetY()+2;
  429. }
  430. // Show payment mode CHQ
  431. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
  432. {
  433. // Si mode reglement non force ou si force a CHQ
  434. if ($conf->global->FACTURE_CHQ_NUMBER)
  435. {
  436. if ($conf->global->FACTURE_CHQ_NUMBER > 0)
  437. {
  438. $account = new Account($this->db);
  439. $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
  440. $pdf->SetXY($this->marge_gauche, $posy);
  441. $pdf->SetFont('','B', $default_font_size - 2);
  442. $pdf->MultiCell(90, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio).':',0,'L',0);
  443. $posy=$pdf->GetY()+1;
  444. $pdf->SetXY($this->marge_gauche, $posy);
  445. $pdf->SetFont('','', $default_font_size - 2);
  446. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($account->adresse_proprio), 0, 'L', 0);
  447. $posy=$pdf->GetY()+2;
  448. }
  449. if ($conf->global->FACTURE_CHQ_NUMBER == -1)
  450. {
  451. $pdf->SetXY($this->marge_gauche, $posy);
  452. $pdf->SetFont('','B', $default_font_size - 2);
  453. $pdf->MultiCell(90, 3, $outputlangs->transnoentities('PaymentByChequeOrderedToShort').' '.$outputlangs->convToOutputCharset($this->emetteur->name).' '.$outputlangs->transnoentities('SendTo').':',0,'L',0);
  454. $posy=$pdf->GetY()+1;
  455. $pdf->SetXY($this->marge_gauche, $posy);
  456. $pdf->SetFont('','', $default_font_size - 2);
  457. $pdf->MultiCell(80, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
  458. $posy=$pdf->GetY()+2;
  459. }
  460. }
  461. }
  462. // If payment mode not forced or forced to VIR, show payment with BAN
  463. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
  464. {
  465. if (! empty($conf->global->FACTURE_RIB_NUMBER))
  466. {
  467. $account = new Account($this->db);
  468. $account->fetch($conf->global->FACTURE_RIB_NUMBER);
  469. $curx=$this->marge_gauche;
  470. $cury=$posy;
  471. $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account);
  472. $posy+=2;
  473. }
  474. }
  475. return $posy;
  476. }
  477. /**
  478. * Affiche le total a payer
  479. *
  480. * @param pdf Objet PDF
  481. * @param object Objet commande
  482. * @param deja_regle Montant deja regle
  483. * @param posy Position depart
  484. * @param outputlangs Objet langs
  485. * @return y Position pour suite
  486. */
  487. function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
  488. {
  489. global $conf,$mysoc;
  490. $default_font_size = pdf_getPDFFontSize($outputlangs);
  491. $tab2_top = $posy;
  492. $tab2_hl = 4;
  493. $pdf->SetFont('','', $default_font_size - 1);
  494. // Tableau total
  495. $lltot = 200; $col1x = 120; $col2x = 170; $largcol2 = $lltot - $col2x;
  496. $useborder=0;
  497. $index = 0;
  498. // Total HT
  499. $pdf->SetFillColor(255,255,255);
  500. $pdf->SetXY($col1x, $tab2_top + 0);
  501. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
  502. $pdf->SetXY($col2x, $tab2_top + 0);
  503. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + $object->remise), 0, 'R', 1);
  504. // Show VAT by rates and total
  505. $pdf->SetFillColor(248,248,248);
  506. $this->atleastoneratenotnull=0;
  507. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  508. {
  509. foreach( $this->tva as $tvakey => $tvaval )
  510. {
  511. if ($tvakey > 0) // On affiche pas taux 0
  512. {
  513. $this->atleastoneratenotnull++;
  514. $index++;
  515. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  516. $tvacompl='';
  517. if (preg_match('/\*/',$tvakey))
  518. {
  519. $tvakey=str_replace('*','',$tvakey);
  520. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  521. }
  522. $totalvat =$outputlangs->transnoentities("TotalVAT").' ';
  523. $totalvat.=vatrate($tvakey,1).$tvacompl;
  524. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  525. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  526. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  527. }
  528. }
  529. if (! $this->atleastoneratenotnull) // If not vat at all
  530. {
  531. $index++;
  532. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  533. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
  534. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  535. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
  536. // Total LocalTax1
  537. if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0)
  538. {
  539. $index++;
  540. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  541. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->pays_code), $useborder, 'L', 1);
  542. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  543. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
  544. }
  545. // Total LocalTax2
  546. if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on' && $object->total_localtax2>0)
  547. {
  548. $index++;
  549. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  550. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->pays_code), $useborder, 'L', 1);
  551. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  552. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
  553. }
  554. }
  555. else
  556. {
  557. //Local tax 1
  558. if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  559. {
  560. foreach( $this->localtax1 as $tvakey => $tvaval )
  561. {
  562. if ($tvakey>0) // On affiche pas taux 0
  563. {
  564. //$this->atleastoneratenotnull++;
  565. $index++;
  566. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  567. $tvacompl='';
  568. if (preg_match('/\*/',$tvakey))
  569. {
  570. $tvakey=str_replace('*','',$tvakey);
  571. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  572. }
  573. $totalvat =$outputlangs->transnoentities("TotalLT1".$mysoc->pays_code).' ';
  574. $totalvat.=vatrate($tvakey,1).$tvacompl;
  575. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  576. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  577. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  578. }
  579. }
  580. }
  581. //Local tax 2
  582. if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  583. {
  584. foreach( $this->localtax2 as $tvakey => $tvaval )
  585. {
  586. if ($tvakey>0) // On affiche pas taux 0
  587. {
  588. //$this->atleastoneratenotnull++;
  589. $index++;
  590. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  591. $tvacompl='';
  592. if (preg_match('/\*/',$tvakey))
  593. {
  594. $tvakey=str_replace('*','',$tvakey);
  595. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  596. }
  597. $totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->pays_code).' ';
  598. $totalvat.=vatrate($tvakey,1).$tvacompl;
  599. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  600. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  601. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  602. }
  603. }
  604. }
  605. }
  606. }
  607. // Total TTC
  608. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  609. {
  610. $index++;
  611. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  612. $pdf->SetTextColor(0,0,60);
  613. $pdf->SetFillColor(224,224,224);
  614. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
  615. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  616. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc), $useborder, 'R', 1);
  617. }
  618. $pdf->SetTextColor(0,0,0);
  619. if ($deja_regle > 0)
  620. {
  621. // Already paid + Deposits
  622. $index++;
  623. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  624. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
  625. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  626. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
  627. $resteapayer = $object->total_ttc - $deja_regle;
  628. $index++;
  629. $pdf->SetTextColor(0,0,60);
  630. $pdf->SetFillColor(224,224,224);
  631. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  632. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
  633. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  634. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
  635. // Fin
  636. $pdf->SetFont('','', $default_font_size - 1);
  637. $pdf->SetTextColor(0,0,0);
  638. }
  639. $index++;
  640. return ($tab2_top + ($tab2_hl * $index));
  641. }
  642. /**
  643. * \brief Affiche la grille des lignes de commandes
  644. * \param pdf objet PDF
  645. */
  646. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs)
  647. {
  648. global $conf;
  649. // Amount in (at tab_top - 1)
  650. $default_font_size = pdf_getPDFFontSize($outputlangs);
  651. $pdf->SetTextColor(0,0,0);
  652. $pdf->SetFont('','', $default_font_size - 2);
  653. $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$conf->monnaie));
  654. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
  655. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  656. $pdf->SetDrawColor(128,128,128);
  657. // Rect prend une longueur en 3eme et 4eme param
  658. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height);
  659. // line prend une position y en 3eme et 4eme param
  660. $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5);
  661. $pdf->SetFont('','', $default_font_size - 1);
  662. $pdf->SetXY($this->posxdesc-1, $tab_top+1);
  663. $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
  664. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  665. {
  666. $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
  667. $pdf->SetXY($this->posxtva-3, $tab_top+1);
  668. $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
  669. }
  670. $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
  671. $pdf->SetXY($this->posxup-1, $tab_top+1);
  672. $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
  673. $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
  674. $pdf->SetXY($this->posxqty-1, $tab_top+1);
  675. $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
  676. $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
  677. if ($this->atleastonediscount)
  678. {
  679. $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
  680. $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
  681. }
  682. if ($this->atleastonediscount)
  683. {
  684. $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
  685. }
  686. $pdf->SetXY($this->postotalht-1, $tab_top+1);
  687. $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHT"),'','C');
  688. }
  689. /**
  690. * Show header of page
  691. *
  692. * @param $pdf Object PDF
  693. * @param $object Object order
  694. * @param $showaddress 0=no, 1=yes
  695. * @param $outputlangs Object lang for output
  696. */
  697. function _pagehead(&$pdf, $object, $showaddress=1, $outputlangs)
  698. {
  699. global $conf,$langs;
  700. $outputlangs->load("main");
  701. $outputlangs->load("bills");
  702. $outputlangs->load("propal");
  703. $outputlangs->load("companies");
  704. $default_font_size = pdf_getPDFFontSize($outputlangs);
  705. pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  706. //Affiche le filigrane brouillon - Print Draft Watermark
  707. if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
  708. {
  709. pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
  710. }
  711. //Print content
  712. $pdf->SetTextColor(0,0,60);
  713. $pdf->SetFont('','B', $default_font_size + 3);
  714. $posx=$this->page_largeur-$this->marge_droite-100;
  715. $posy=$this->marge_haute;
  716. $pdf->SetXY($this->marge_gauche,$posy);
  717. // Logo
  718. $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  719. if ($this->emetteur->logo)
  720. {
  721. if (is_readable($logo))
  722. {
  723. $pdf->Image($logo, $this->marge_gauche, $posy, 0, 24); // width=0 (auto), max height=24
  724. }
  725. else
  726. {
  727. $pdf->SetTextColor(200,0,0);
  728. $pdf->SetFont('','B', $default_font_size -2);
  729. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  730. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  731. }
  732. }
  733. else
  734. {
  735. $text=$this->emetteur->name;
  736. $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  737. }
  738. $pdf->SetFont('','B', $default_font_size + 3);
  739. $pdf->SetXY($posx,$posy);
  740. $pdf->SetTextColor(0,0,60);
  741. $title=$outputlangs->transnoentities("Order");
  742. $pdf->MultiCell(100, 4, $title, '', 'R');
  743. $pdf->SetFont('','B', $default_font_size + 2);
  744. $posy+=6;
  745. $pdf->SetXY($posx,$posy);
  746. $pdf->SetTextColor(0,0,60);
  747. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
  748. $posy+=2;
  749. $pdf->SetFont('','', $default_font_size - 1);
  750. $posy+=5;
  751. $pdf->SetXY($posx,$posy);
  752. $pdf->SetTextColor(0,0,60);
  753. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date,"%d %b %Y",false,$outputlangs,true), '', 'R');
  754. if ($showaddress)
  755. {
  756. // Sender properties
  757. $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
  758. // Show sender
  759. $posy=42;
  760. $posx=$this->marge_gauche;
  761. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
  762. $hautcadre=40;
  763. // Show sender frame
  764. $pdf->SetTextColor(0,0,0);
  765. $pdf->SetFont('','', $default_font_size - 2);
  766. $pdf->SetXY($posx,$posy-5);
  767. $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":");
  768. $pdf->SetXY($posx,$posy);
  769. $pdf->SetFillColor(230,230,230);
  770. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  771. $pdf->SetTextColor(0,0,60);
  772. // Show sender name
  773. $pdf->SetXY($posx+2,$posy+3);
  774. $pdf->SetFont('','B', $default_font_size);
  775. $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  776. // Show sender information
  777. $pdf->SetXY($posx+2,$posy+8);
  778. $pdf->SetFont('','', $default_font_size - 1);
  779. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  780. // If CUSTOMER contact defined on order, we use it
  781. $usecontact=false;
  782. $arrayidcontact=$object->getIdContact('external','CUSTOMER');
  783. if (count($arrayidcontact) > 0)
  784. {
  785. $usecontact=true;
  786. $result=$object->fetch_contact($arrayidcontact[0]);
  787. }
  788. // Recipient name
  789. if (! empty($usecontact))
  790. {
  791. // On peut utiliser le nom de la societe du contact
  792. if ($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) $socname = $object->contact->socname;
  793. else $socname = $object->client->nom;
  794. $carac_client_name=$outputlangs->convToOutputCharset($socname);
  795. }
  796. else
  797. {
  798. $carac_client_name=$outputlangs->convToOutputCharset($object->client->nom);
  799. }
  800. $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,$object->contact,$usecontact,'target');
  801. // Show recipient
  802. $posy=42;
  803. $posx=$this->page_largeur-$this->marge_droite-100;
  804. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
  805. // Show recipient frame
  806. $pdf->SetTextColor(0,0,0);
  807. $pdf->SetFont('','', $default_font_size - 2);
  808. $pdf->SetXY($posx+2,$posy-5);
  809. $pdf->MultiCell(80,5, $outputlangs->transnoentities("BillTo").":",0,'L');
  810. $pdf->rect($posx, $posy, 100, $hautcadre);
  811. // Show recipient name
  812. $pdf->SetXY($posx+2,$posy+3);
  813. $pdf->SetFont('','B', $default_font_size);
  814. $pdf->MultiCell(96,4, $carac_client_name, 0, 'L');
  815. // Show recipient information
  816. $pdf->SetFont('','', $default_font_size - 1);
  817. $pdf->SetXY($posx+2,$posy+8);
  818. $pdf->MultiCell(86,4, $carac_client, 0, 'L');
  819. }
  820. }
  821. /**
  822. * Show footer of page
  823. * Need this->emetteur object
  824. *
  825. * @param pdf PDF factory
  826. * @param object Object invoice
  827. * @param outputlangs Object lang for output
  828. */
  829. function _pagefoot(&$pdf,$object,$outputlangs)
  830. {
  831. return pdf_pagefoot($pdf,$outputlangs,'COMMANDE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  832. }
  833. }
  834. ?>