PageRenderTime 34ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php

https://bitbucket.org/speedealing/speedealing
PHP | 1073 lines | 655 code | 166 blank | 252 comment | 85 complexity | 5fc7c558e1900960dbc626a8cf6c89dc MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
  5. * Copyright (C) 2010 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 3 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/supplier_order/pdf/pdf_muscadet.modules.php
  23. * \ingroup fournisseur
  24. * \brief File of class to generate suppliers orders from muscadet model
  25. */
  26. require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
  27. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.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 to generate the supplier orders with the muscadet model
  34. */
  35. class pdf_muscadet extends ModelePDFSuppliersOrders
  36. {
  37. var $db;
  38. var $name;
  39. var $description;
  40. var $type;
  41. var $phpmin = array(4,3,0); // Minimum version of PHP required by module
  42. var $version = 'dolibarr';
  43. var $page_largeur;
  44. var $page_hauteur;
  45. var $format;
  46. var $marge_gauche;
  47. var $marge_droite;
  48. var $marge_haute;
  49. var $marge_basse;
  50. var $emetteur; // Objet societe qui emet
  51. /**
  52. * Constructor
  53. *
  54. * @param DoliDB $db Database handler
  55. * @param Object $object Supplier order
  56. */
  57. function __construct($db,$object)
  58. {
  59. global $conf,$langs,$mysoc;
  60. $langs->load("main");
  61. $langs->load("bills");
  62. $this->db = $db;
  63. $this->name = "muscadet";
  64. $this->description = $langs->trans('SuppliersCommandModel');
  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 = 0; // Affiche si il y a eu escompte
  82. $this->option_credit_note = 0; // 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. // Get source company
  87. //if (! is_object($object->thirdparty)) $object->fetch_thirdparty();
  88. //$this->emetteur=$object->thirdparty;
  89. //if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
  90. $this->emetteur=$mysoc;
  91. if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
  92. // Defini position des colonnes
  93. $this->posxdesc=$this->marge_gauche+1;
  94. $this->posxtva=111;
  95. $this->posxup=126;
  96. $this->posxqty=145;
  97. $this->posxdiscount=162;
  98. $this->postotalht=174;
  99. $this->tva=array();
  100. $this->localtax1=array();
  101. $this->localtax2=array();
  102. $this->atleastoneratenotnull=0;
  103. $this->atleastonediscount=0;
  104. }
  105. /**
  106. * Function to build pdf onto disk
  107. *
  108. * @param int $object Id of object to generate
  109. * @param object $outputlangs Lang output object
  110. * @param string $srctemplatepath Full path of source filename for generator using a template file
  111. * @param int $hidedetails Do not show line details
  112. * @param int $hidedesc Do not show desc
  113. * @param int $hideref Do not show ref
  114. * @return int 1=OK, 0=KO
  115. */
  116. function write_file($object,$outputlangs='',$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0)
  117. {
  118. global $user,$langs,$conf;
  119. if (! is_object($outputlangs)) $outputlangs=$langs;
  120. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  121. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  122. $outputlangs->load("main");
  123. $outputlangs->load("dict");
  124. $outputlangs->load("companies");
  125. $outputlangs->load("bills");
  126. $outputlangs->load("products");
  127. $outputlangs->load("orders");
  128. $default_font_size = pdf_getPDFFontSize($outputlangs);
  129. if ($conf->fournisseur->dir_output.'/commande')
  130. {
  131. $object->fetch_thirdparty();
  132. $deja_regle = "";
  133. $amount_credit_notes_included = 0;
  134. $amount_deposits_included = 0;
  135. //$amount_credit_notes_included = $object->getSumCreditNotesUsed();
  136. //$amount_deposits_included = $object->getSumDepositsUsed();
  137. // Definition of $dir and $file
  138. if ($object->specimen)
  139. {
  140. $dir = $conf->fournisseur->commande->dir_output;
  141. $file = $dir . "/SPECIMEN.pdf";
  142. }
  143. else
  144. {
  145. $objectref = dol_sanitizeFileName($object->ref);
  146. $dir = $conf->fournisseur->commande->dir_output . '/'. $objectref;
  147. $file = $dir . "/" . $objectref . ".pdf";
  148. }
  149. if (! file_exists($dir))
  150. {
  151. if (dol_mkdir($dir) < 0)
  152. {
  153. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  154. return 0;
  155. }
  156. }
  157. if (file_exists($dir))
  158. {
  159. $nblignes = count($object->lines);
  160. $pdf=pdf_getInstance($this->format);
  161. $heightforinfotot = 50; // Height reserved to output the info and total part
  162. $heightforfooter = 25; // Height reserved to output the footer (value include bottom margin)
  163. $pdf->SetAutoPageBreak(1,0);
  164. if (class_exists('TCPDF'))
  165. {
  166. $pdf->setPrintHeader(false);
  167. $pdf->setPrintFooter(false);
  168. }
  169. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  170. // Set path to the background PDF File
  171. if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
  172. {
  173. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  174. $tplidx = $pdf->importPage(1);
  175. }
  176. $pdf->Open();
  177. $pagenb=0;
  178. $pdf->SetDrawColor(128,128,128);
  179. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  180. $pdf->SetSubject($outputlangs->transnoentities("Order"));
  181. $pdf->SetCreator("Speedealing ".DOL_VERSION);
  182. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  183. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Order"));
  184. if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  185. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  186. // Positionne $this->atleastonediscount si on a au moins une remise
  187. for ($i = 0 ; $i < $nblignes ; $i++)
  188. {
  189. if ($object->lines[$i]->remise_percent)
  190. {
  191. $this->atleastonediscount++;
  192. }
  193. }
  194. // New page
  195. $pdf->AddPage();
  196. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  197. $pagenb++;
  198. $this->_pagehead($pdf, $object, 1, $outputlangs);
  199. $pdf->SetFont('','', $default_font_size - 1);
  200. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  201. $pdf->SetTextColor(0,0,0);
  202. $tab_top = 90;
  203. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
  204. $tab_height = 130;
  205. $tab_height_newpage = 150;
  206. // Affiche notes
  207. if (! empty($object->note_public))
  208. {
  209. $tab_top = 88;
  210. $pdf->SetFont('','', $default_font_size - 1);
  211. $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($object->note_public), 0, 1);
  212. $nexY = $pdf->GetY();
  213. $height_note=$nexY-$tab_top;
  214. // Rect prend une longueur en 3eme param
  215. $pdf->SetDrawColor(192,192,192);
  216. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  217. $tab_height = $tab_height - $height_note;
  218. $tab_top = $nexY+6;
  219. }
  220. else
  221. {
  222. $height_note=0;
  223. }
  224. $iniY = $tab_top + 7;
  225. $curY = $tab_top + 7;
  226. $nexY = $tab_top + 7;
  227. // Loop on each lines
  228. for ($i = 0 ; $i < $nblignes ; $i++)
  229. {
  230. $curY = $nexY;
  231. $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
  232. $pdf->SetTextColor(0,0,0);
  233. $pdf->setTopMargin($tab_top_newpage);
  234. $pdf->setPageOrientation('', 1, $this->marge_basse+$heightforfooter+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  235. $pageposbefore=$pdf->getPage();
  236. // Description of product line
  237. $curX = $this->posxdesc-1;
  238. pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,0,0,1);
  239. $nexY = $pdf->GetY();
  240. $pageposafter=$pdf->getPage();
  241. $pdf->setPage($pageposbefore);
  242. $pdf->setTopMargin($this->marge_haute);
  243. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  244. // We suppose that a too long description is moved completely on next page
  245. if ($pageposafter > $pageposbefore) {
  246. $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  247. }
  248. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  249. // VAT Rate
  250. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  251. {
  252. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
  253. $pdf->SetXY($this->posxtva, $curY);
  254. $pdf->MultiCell($this->posxup-$this->posxtva-1, 3, $vat_rate, 0, 'R');
  255. }
  256. // Unit price before discount
  257. $pdf->SetXY($this->posxup, $curY);
  258. $pdf->MultiCell($this->posxqty-$this->posxup-1, 3, price($object->lines[$i]->subprice), 0, 'R', 0);
  259. // Quantity
  260. $pdf->SetXY($this->posxqty, $curY);
  261. $pdf->MultiCell($this->posxdiscount-$this->posxqty-1, 3, $object->lines[$i]->qty, 0, 'R');
  262. // Discount on line
  263. $pdf->SetXY($this->posxdiscount, $curY);
  264. if ($object->lines[$i]->remise_percent)
  265. {
  266. $pdf->MultiCell($this->postotalht-$this->posxdiscount-1, 3, $object->lines[$i]->remise_percent."%", 0, 'R');
  267. }
  268. // Total HT line
  269. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs);
  270. $pdf->SetXY($this->postotalht, $curY);
  271. $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
  272. // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
  273. $tvaligne=$object->lines[$i]->total_tva;
  274. $localtax1ligne=$object->lines[$i]->total_localtax1;
  275. $localtax2ligne=$object->lines[$i]->total_localtax2;
  276. if (! empty($object->remise_percent)) $tvaligne-=($tvaligne*$object->remise_percent)/100;
  277. if (! empty($object->remise_percent)) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
  278. if (! empty($object->remise_percent)) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
  279. $vatrate=(string) $object->lines[$i]->tva_tx;
  280. $localtax1rate=(string) $object->lines[$i]->localtax1_tx;
  281. $localtax2rate=(string) $object->lines[$i]->localtax2_tx;
  282. if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
  283. if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]='';
  284. if (! isset($this->localtax1[$localtax1rate])) $this->localtax1[$localtax1rate]='';
  285. if (! isset($this->localtax2[$localtax2rate])) $this->localtax2[$localtax2rate]='';
  286. $this->tva[$vatrate] += $tvaligne;
  287. $this->localtax1[$localtax1rate]+=$localtax1ligne;
  288. $this->localtax2[$localtax2rate]+=$localtax2ligne;
  289. $nexY+=2; // Passe espace entre les lignes
  290. // Detect if some page were added automatically and output _tableau for past pages
  291. while ($pagenb < $pageposafter)
  292. {
  293. $pdf->setPage($pagenb);
  294. if ($pagenb == 1)
  295. {
  296. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  297. }
  298. else
  299. {
  300. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  301. }
  302. $this->_pagefoot($pdf,$object,$outputlangs);
  303. $pagenb++;
  304. $pdf->setPage($pagenb);
  305. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  306. }
  307. if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
  308. {
  309. if ($pagenb == 1)
  310. {
  311. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1);
  312. }
  313. else
  314. {
  315. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1);
  316. }
  317. $this->_pagefoot($pdf,$object,$outputlangs);
  318. // New page
  319. $pdf->AddPage();
  320. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  321. $pagenb++;
  322. }
  323. }
  324. // Show square
  325. if ($pagenb == 1)
  326. {
  327. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfooter, 0, $outputlangs, 0, 0);
  328. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1;
  329. }
  330. else
  331. {
  332. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfooter, 0, $outputlangs, 1, 0);
  333. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfooter + 1;
  334. }
  335. // Affiche zone infos
  336. $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
  337. // Affiche zone totaux
  338. $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
  339. // Affiche zone versements
  340. if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
  341. {
  342. $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs);
  343. }
  344. // Pied de page
  345. $this->_pagefoot($pdf, $object, $outputlangs);
  346. $pdf->AliasNbPages();
  347. $pdf->Close();
  348. $pdf->Output($file,'F');
  349. // Add pdfgeneration hook
  350. $hookmanager->initHooks(array('pdfgeneration'));
  351. $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  352. global $action;
  353. $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
  354. if (! empty($conf->global->MAIN_UMASK))
  355. @chmod($file, octdec($conf->global->MAIN_UMASK));
  356. return 1; // Pas d'erreur
  357. }
  358. else
  359. {
  360. $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
  361. return 0;
  362. }
  363. }
  364. else
  365. {
  366. $this->error=$langs->trans("ErrorConstantNotDefined","SUPPLIER_OUTPUTDIR");
  367. return 0;
  368. }
  369. $this->error=$langs->trans("ErrorUnknown");
  370. return 0; // Erreur par defaut
  371. }
  372. /**
  373. * Show payments table
  374. *
  375. * @param PDF &$pdf Object PDF
  376. * @param Object $object Object order
  377. * @param int $posy Position y in PDF
  378. * @param Translate $outputlangs Object langs for output
  379. * @return int <0 if KO, >0 if OK
  380. */
  381. function _tableau_versements(&$pdf, $object, $posy, $outputlangs)
  382. {
  383. }
  384. /**
  385. * Show miscellaneous information (payment mode, payment term, ...)
  386. *
  387. * @param PDF &$pdf Object PDF
  388. * @param Object $object Object to show
  389. * @param int $posy Y
  390. * @param Translate $outputlangs Langs object
  391. * @return void
  392. */
  393. function _tableau_info(&$pdf, $object, $posy, $outputlangs)
  394. {
  395. global $conf;
  396. $default_font_size = pdf_getPDFFontSize($outputlangs);
  397. $pdf->SetFont('','', $default_font_size - 1);
  398. // If France, show VAT mention if not applicable
  399. /*if ($this->emetteur->pays_code == 'FR' && $this->franchise == 1)
  400. {
  401. $pdf->SetFont('','B', $default_font_size - 2);
  402. $pdf->SetXY($this->marge_gauche, $posy);
  403. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("VATIsNotUsedForInvoice"), 0, 'L', 0);
  404. $posy=$pdf->GetY()+4;
  405. }*/
  406. // Show payments conditions
  407. if ($object->cond_reglement_code || $object->cond_reglement)
  408. {
  409. $pdf->SetFont('','B', $default_font_size - 2);
  410. $pdf->SetXY($this->marge_gauche, $posy);
  411. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  412. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  413. $pdf->SetFont('','', $default_font_size - 2);
  414. $pdf->SetXY(52, $posy);
  415. $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);
  416. $lib_condition_paiement=str_replace('\n',"\n",$lib_condition_paiement);
  417. $pdf->MultiCell(80, 4, $lib_condition_paiement,0,'L');
  418. $posy=$pdf->GetY()+3;
  419. }
  420. // Check a payment mode is defined
  421. /* Not used with orders
  422. if (empty($object->mode_reglement_code)
  423. && ! $conf->global->FACTURE_CHQ_NUMBER
  424. && ! $conf->global->FACTURE_RIB_NUMBER)
  425. {
  426. $pdf->SetXY($this->marge_gauche, $posy);
  427. $pdf->SetTextColor(200,0,0);
  428. $pdf->SetFont('','B', $default_font_size - 2);
  429. $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
  430. $pdf->SetTextColor(0,0,0);
  431. $posy=$pdf->GetY()+1;
  432. }
  433. */
  434. // Show payment mode
  435. if ($object->mode_reglement_code
  436. // && $object->mode_reglement_code != 'CHQ'
  437. // && $object->mode_reglement_code != 'VIR'
  438. )
  439. {
  440. $pdf->SetFont('','B', $default_font_size - 2);
  441. $pdf->SetXY($this->marge_gauche, $posy);
  442. $titre = $outputlangs->transnoentities("PaymentMode").':';
  443. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  444. $pdf->SetFont('','', $default_font_size - 2);
  445. $pdf->SetXY(52, $posy);
  446. $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);
  447. $pdf->MultiCell(80, 4, $lib_mode_reg,0,'L');
  448. $posy=$pdf->GetY()+2;
  449. }
  450. // Show payment mode CHQ
  451. /*
  452. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ')
  453. {
  454. // Si mode reglement non force ou si force a CHQ
  455. if (! empty($conf->global->FACTURE_CHQ_NUMBER))
  456. {
  457. if ($conf->global->FACTURE_CHQ_NUMBER > 0)
  458. {
  459. $account = new Account($this->db);
  460. $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
  461. $pdf->SetXY($this->marge_gauche, $posy);
  462. $pdf->SetFont('','B', $default_font_size - 3);
  463. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo',$account->proprio).':',0,'L',0);
  464. $posy=$pdf->GetY()+1;
  465. $pdf->SetXY($this->marge_gauche, $posy);
  466. $pdf->SetFont('','', $default_font_size - 3);
  467. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->adresse_proprio), 0, 'L', 0);
  468. $posy=$pdf->GetY()+2;
  469. }
  470. if ($conf->global->FACTURE_CHQ_NUMBER == -1)
  471. {
  472. $pdf->SetXY($this->marge_gauche, $posy);
  473. $pdf->SetFont('','B', $default_font_size - 3);
  474. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedToShort').' '.$outputlangs->convToOutputCharset($this->emetteur->name).' '.$outputlangs->transnoentities('SendTo').':',0,'L',0);
  475. $posy=$pdf->GetY()+1;
  476. $pdf->SetXY($this->marge_gauche, $posy);
  477. $pdf->SetFont('','', $default_font_size - 3);
  478. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
  479. $posy=$pdf->GetY()+2;
  480. }
  481. }
  482. }
  483. // If payment mode not forced or forced to VIR, show payment with BAN
  484. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR')
  485. {
  486. if (! empty($conf->global->FACTURE_RIB_NUMBER))
  487. {
  488. $account = new Account($this->db);
  489. $account->fetch($conf->global->FACTURE_RIB_NUMBER);
  490. $curx=$this->marge_gauche;
  491. $cury=$posy;
  492. $posy=pdf_bank($pdf,$outputlangs,$curx,$cury,$account,0,$default_font_size);
  493. $posy+=2;
  494. }
  495. }
  496. */
  497. return $posy;
  498. }
  499. /**
  500. * Show total to pay
  501. *
  502. * @param PDF &$pdf Object PDF
  503. * @param Facture $object Object invoice
  504. * @param int $deja_regle Montant deja regle
  505. * @param int $posy Position depart
  506. * @param Translate $outputlangs Objet langs
  507. * @return int Position pour suite
  508. */
  509. function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs)
  510. {
  511. global $conf,$mysoc;
  512. $default_font_size = pdf_getPDFFontSize($outputlangs);
  513. $tab2_top = $posy;
  514. $tab2_hl = 4;
  515. $pdf->SetFont('','', $default_font_size - 1);
  516. // Tableau total
  517. $col1x = 120; $col2x = 170; $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
  518. $useborder=0;
  519. $index = 0;
  520. // Total HT
  521. $pdf->SetFillColor(255,255,255);
  522. $pdf->SetXY($col1x, $tab2_top + 0);
  523. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT"), 0, 'L', 1);
  524. $pdf->SetXY($col2x, $tab2_top + 0);
  525. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ht + (! empty($object->remise)?$object->remise:0)), 0, 'R', 1);
  526. // Show VAT by rates and total
  527. $pdf->SetFillColor(248,248,248);
  528. $this->atleastoneratenotnull=0;
  529. foreach( $this->tva as $tvakey => $tvaval )
  530. {
  531. if ($tvakey > 0) // On affiche pas taux 0
  532. {
  533. $this->atleastoneratenotnull++;
  534. $index++;
  535. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  536. $tvacompl='';
  537. if (preg_match('/\*/',$tvakey))
  538. {
  539. $tvakey=str_replace('*','',$tvakey);
  540. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  541. }
  542. $totalvat =$outputlangs->transnoentities("TotalVAT").' ';
  543. $totalvat.=vatrate($tvakey,1).$tvacompl;
  544. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  545. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  546. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  547. }
  548. }
  549. if (! $this->atleastoneratenotnull) // If no vat at all
  550. {
  551. $index++;
  552. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  553. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalVAT"), 0, 'L', 1);
  554. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  555. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_tva), 0, 'R', 1);
  556. // Total LocalTax1
  557. if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on' && $object->total_localtax1>0)
  558. {
  559. $index++;
  560. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  561. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT1".$mysoc->country_code), 0, 'L', 1);
  562. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  563. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax1), $useborder, 'R', 1);
  564. }
  565. // Total LocalTax2
  566. if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on' && $object->total_localtax2>0)
  567. {
  568. $index++;
  569. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  570. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalLT2".$mysoc->country_code), 0, 'L', 1);
  571. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  572. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_localtax2), $useborder, 'R', 1);
  573. }
  574. }
  575. else
  576. {
  577. if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  578. {
  579. //Local tax 1
  580. foreach( $this->localtax1 as $tvakey => $tvaval )
  581. {
  582. if ($tvakey>0) // On affiche pas taux 0
  583. {
  584. //$this->atleastoneratenotnull++;
  585. $index++;
  586. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  587. $tvacompl='';
  588. if (preg_match('/\*/',$tvakey))
  589. {
  590. $tvakey=str_replace('*','',$tvakey);
  591. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  592. }
  593. $totalvat =$outputlangs->transnoentities("TotalLT1".$mysoc->country_code).' ';
  594. $totalvat.=vatrate($tvakey,1).$tvacompl;
  595. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  596. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  597. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  598. }
  599. }
  600. }
  601. if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  602. {
  603. //Local tax 2
  604. foreach( $this->localtax2 as $tvakey => $tvaval )
  605. {
  606. if ($tvakey>0) // On affiche pas taux 0
  607. {
  608. //$this->atleastoneratenotnull++;
  609. $index++;
  610. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  611. $tvacompl='';
  612. if (preg_match('/\*/',$tvakey))
  613. {
  614. $tvakey=str_replace('*','',$tvakey);
  615. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  616. }
  617. $totalvat =$outputlangs->transnoentities("TotalLT2".$mysoc->country_code).' ';
  618. $totalvat.=vatrate($tvakey,1).$tvacompl;
  619. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  620. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  621. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval), 0, 'R', 1);
  622. }
  623. }
  624. }
  625. }
  626. // Total TTC
  627. $index++;
  628. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  629. $pdf->SetTextColor(0,0,60);
  630. $pdf->SetFillColor(224,224,224);
  631. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC"), $useborder, 'L', 1);
  632. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  633. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc), $useborder, 'R', 1);
  634. $pdf->SetFont('','', $default_font_size - 1);
  635. $pdf->SetTextColor(0,0,0);
  636. $creditnoteamount=0;
  637. $depositsamount=0;
  638. //$creditnoteamount=$object->getSumCreditNotesUsed();
  639. //$depositsamount=$object->getSumDepositsUsed();
  640. //print "x".$creditnoteamount."-".$depositsamount;exit;
  641. $resteapayer = price2num($object->total_ttc - $deja_regle - $creditnoteamount - $depositsamount, 'MT');
  642. if (! empty($object->paye)) $resteapayer=0;
  643. if ($deja_regle > 0)
  644. {
  645. // Already paid + Deposits
  646. $index++;
  647. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  648. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid"), 0, 'L', 0);
  649. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  650. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle), 0, 'R', 0);
  651. $index++;
  652. $pdf->SetTextColor(0,0,60);
  653. $pdf->SetFillColor(224,224,224);
  654. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  655. $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay"), $useborder, 'L', 1);
  656. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  657. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer), $useborder, 'R', 1);
  658. $pdf->SetFont('','', $default_font_size - 1);
  659. $pdf->SetTextColor(0,0,0);
  660. }
  661. $index++;
  662. return ($tab2_top + ($tab2_hl * $index));
  663. }
  664. /**
  665. * Show table for lines
  666. *
  667. * @param PDF &$pdf Object PDF
  668. * @param string $tab_top Top position of table
  669. * @param string $tab_height Height of table (rectangle)
  670. * @param int $nexY Y (not used)
  671. * @param Translate $outputlangs Langs object
  672. * @param int $hidetop Hide top bar of array
  673. * @param int $hidebottom Hide bottom bar of array
  674. * @return void
  675. */
  676. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0)
  677. {
  678. global $conf;
  679. // Force to disable hidetop and hidebottom
  680. $hidebottom=0;
  681. if ($hidetop) $hidetop=-1;
  682. $default_font_size = pdf_getPDFFontSize($outputlangs);
  683. // Amount in (at tab_top - 1)
  684. $pdf->SetTextColor(0,0,0);
  685. $pdf->SetFont('','', $default_font_size - 2);
  686. if (empty($hidetop))
  687. {
  688. $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$conf->currency));
  689. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
  690. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  691. }
  692. $pdf->SetDrawColor(128,128,128);
  693. $pdf->SetFont('','', $default_font_size - 1);
  694. // Output Rect
  695. $this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect prend une longueur en 3eme param et 4eme param
  696. if (empty($hidetop))
  697. {
  698. $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); // line prend une position y en 2eme param et 4eme param
  699. $pdf->SetXY($this->posxdesc-1, $tab_top+1);
  700. $pdf->MultiCell(108,2, $outputlangs->transnoentities("Designation"),'','L');
  701. }
  702. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT))
  703. {
  704. $pdf->line($this->posxtva-1, $tab_top, $this->posxtva-1, $tab_top + $tab_height);
  705. if (empty($hidetop))
  706. {
  707. $pdf->SetXY($this->posxtva-3, $tab_top+1);
  708. $pdf->MultiCell($this->posxup-$this->posxtva+3,2, $outputlangs->transnoentities("VAT"),'','C');
  709. }
  710. }
  711. $pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
  712. if (empty($hidetop))
  713. {
  714. $pdf->SetXY($this->posxup-1, $tab_top+1);
  715. $pdf->MultiCell($this->posxqty-$this->posxup-1,2, $outputlangs->transnoentities("PriceUHT"),'','C');
  716. }
  717. $pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
  718. if (empty($hidetop))
  719. {
  720. $pdf->SetXY($this->posxqty-1, $tab_top+1);
  721. $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
  722. }
  723. $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
  724. if (empty($hidetop))
  725. {
  726. if ($this->atleastonediscount)
  727. {
  728. $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
  729. $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("ReductionShort"),'','C');
  730. }
  731. }
  732. if ($this->atleastonediscount)
  733. {
  734. $pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
  735. }
  736. if (empty($hidetop))
  737. {
  738. $pdf->SetXY($this->postotalht-1, $tab_top+1);
  739. $pdf->MultiCell(30,2, $outputlangs->transnoentities("TotalHTShort"),'','C');
  740. }
  741. }
  742. /**
  743. * Show top header of page.
  744. *
  745. * @param PDF &$pdf Object PDF
  746. * @param Object $object Object to show
  747. * @param int $showaddress 0=no, 1=yes
  748. * @param Translate $outputlangs Object lang for output
  749. * @return void
  750. */
  751. function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
  752. {
  753. global $langs,$conf,$mysoc;
  754. $outputlangs->load("main");
  755. $outputlangs->load("bills");
  756. $outputlangs->load("orders");
  757. $outputlangs->load("companies");
  758. $default_font_size = pdf_getPDFFontSize($outputlangs);
  759. // Do not add the BACKGROUND as this is for suppliers
  760. //pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  761. //Affiche le filigrane brouillon - Print Draft Watermark
  762. /*if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
  763. {
  764. pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
  765. }*/
  766. //Print content
  767. $pdf->SetTextColor(0,0,60);
  768. $pdf->SetFont('','B',$default_font_size + 3);
  769. $posx=$this->page_largeur-$this->marge_droite-100;
  770. $posy=$this->marge_haute;
  771. $pdf->SetXY($this->marge_gauche,$posy);
  772. // Logo
  773. $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  774. if ($this->emetteur->logo)
  775. {
  776. if (is_readable($logo))
  777. {
  778. $height=pdf_getHeightForLogo($logo);
  779. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  780. }
  781. else
  782. {
  783. $pdf->SetTextColor(200,0,0);
  784. $pdf->SetFont('','B', $default_font_size - 2);
  785. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  786. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToModuleSetup"), 0, 'L');
  787. }
  788. }
  789. else
  790. {
  791. $text=$this->emetteur->name;
  792. $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  793. }
  794. $pdf->SetFont('', 'B', $default_font_size + 3);
  795. $pdf->SetXY($posx,$posy);
  796. $pdf->SetTextColor(0,0,60);
  797. $title=$outputlangs->transnoentities("SupplierOrder");
  798. $pdf->MultiCell(100, 3, $title, '', 'R');
  799. $pdf->SetFont('','B',$default_font_size);
  800. $posy+=6;
  801. $pdf->SetXY($posx,$posy);
  802. $pdf->SetTextColor(0,0,60);
  803. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
  804. $posy+=2;
  805. $pdf->SetFont('','', $default_font_size -1);
  806. $posy+=5;
  807. $pdf->SetXY($posx,$posy);
  808. if ($object->date_commande)
  809. {
  810. $pdf->SetTextColor(0,0,60);
  811. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date_commande,"day",false,$outputlangs,true), '', 'R');
  812. }
  813. else
  814. {
  815. $pdf->SetTextColor(255,0,0);
  816. $pdf->MultiCell(100, 3, strtolower($outputlangs->transnoentities("OrderToProcess")), '', 'R');
  817. }
  818. $posy+=2;
  819. if ($showaddress)
  820. {
  821. // Sender properties
  822. $carac_emetteur = pdf_build_address($outputlangs,$this->emetteur);
  823. // Show sender
  824. $posy=42;
  825. $posx=$this->marge_gauche;
  826. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
  827. $hautcadre=40;
  828. // Show sender frame
  829. $pdf->SetTextColor(0,0,0);
  830. $pdf->SetFont('','', $default_font_size - 2);
  831. $pdf->SetXY($posx,$posy-5);
  832. $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
  833. $pdf->SetXY($posx,$posy);
  834. $pdf->SetFillColor(230,230,230);
  835. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  836. $pdf->SetTextColor(0,0,60);
  837. // Show sender name
  838. $pdf->SetXY($posx+2,$posy+3);
  839. $pdf->SetFont('','B', $default_font_size);
  840. $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  841. // Show sender information
  842. $pdf->SetXY($posx+2,$posy+4+(dol_nboflines_bis($this->emetteur->name,44)*4));
  843. $pdf->SetFont('','', $default_font_size - 1);
  844. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  845. // If BILLING contact defined on order, we use it
  846. $usecontact=false;
  847. $arrayidcontact=$object->getIdContact('external','BILLING');
  848. if (count($arrayidcontact) > 0)
  849. {
  850. $usecontact=true;
  851. $result=$object->fetch_contact($arrayidcontact[0]);
  852. }
  853. // Recipient name
  854. if (! empty($usecontact))
  855. {
  856. // On peut utiliser le nom de la societe du contact
  857. if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socname = $object->contact->socname;
  858. else $socname = $object->client->name;
  859. $carac_client_name=$outputlangs->convToOutputCharset($socname);
  860. }
  861. else
  862. {
  863. $carac_client_name=$outputlangs->convToOutputCharset($object->client->name);
  864. }
  865. $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->client,($usecontact?$object->contact:''),$usecontact,'target');
  866. // Show recipient
  867. $posy=42;
  868. $posx=$this->page_largeur-$this->marge_droite-100;
  869. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche;
  870. // Show recipient frame
  871. $pdf->SetTextColor(0,0,0);
  872. $pdf->SetFont('','', $default_font_size - 2);
  873. $pdf->SetXY($posx+2,$posy-5);
  874. $pdf->MultiCell(80,5, $outputlangs->transnoentities("BillTo").":",0,'L');
  875. $pdf->Rect($posx, $posy, 100, $hautcadre);
  876. // Show recipient name
  877. $pdf->SetXY($posx+2,$posy+3);
  878. $pdf->SetFont('','B', $default_font_size);
  879. $pdf->MultiCell(96,4, $carac_client_name, 0, 'L');
  880. // Show recipient information
  881. $pdf->SetFont('','', $default_font_size - 1);
  882. $pdf->SetXY($posx+2,$posy+4+(dol_nboflines_bis($carac_client_name,50)*4));
  883. $pdf->MultiCell(86,4, $carac_client, 0, 'L');
  884. }
  885. }
  886. /**
  887. * Show footer of page. Need this->emetteur object
  888. *
  889. * @param PDF &$pdf PDF
  890. * @param Object $object Object to show
  891. * @param Translate $outputlangs Object lang for output
  892. * @return int Return height of bottom margin including footer text
  893. */
  894. function _pagefoot(&$pdf, $object, $outputlangs)
  895. {
  896. return pdf_pagefoot($pdf,$outputlangs,'SUPPLIER_INVOICE_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object);
  897. }
  898. }
  899. ?>