pdf_standard.modules.php 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  1. <?php
  2. /* Copyright (C) 2017 Laurent Destailleur <eldy@stocks.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/modules/stock/doc/pdf_standard.modules.php
  20. * \ingroup societe
  21. * \brief File of class to build PDF documents for stocks/services
  22. */
  23. require_once DOL_DOCUMENT_ROOT.'/core/modules/stock/modules_stock.php';
  24. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  30. /**
  31. * Class to build documents using ODF templates generator
  32. */
  33. class pdf_standard extends ModelePDFStock
  34. {
  35. /**
  36. * @var DoliDb Database handler
  37. */
  38. public $db;
  39. /**
  40. * @var string model name
  41. */
  42. public $name;
  43. /**
  44. * @var string model description (short text)
  45. */
  46. public $description;
  47. /**
  48. * @var string document type
  49. */
  50. public $type;
  51. /**
  52. * @var array() Minimum version of PHP required by module.
  53. * e.g.: PHP ≥ 5.4 = array(5, 4)
  54. */
  55. public $phpmin = array(5, 4);
  56. /**
  57. * Dolibarr version of the loaded document
  58. * @public string
  59. */
  60. public $version = 'dolibarr';
  61. /**
  62. * @var int page_largeur
  63. */
  64. public $page_largeur;
  65. /**
  66. * @var int page_hauteur
  67. */
  68. public $page_hauteur;
  69. /**
  70. * @var array format
  71. */
  72. public $format;
  73. /**
  74. * @var int marge_gauche
  75. */
  76. public $marge_gauche;
  77. /**
  78. * @var int marge_droite
  79. */
  80. public $marge_droite;
  81. /**
  82. * @var int marge_haute
  83. */
  84. public $marge_haute;
  85. /**
  86. * @var int marge_basse
  87. */
  88. public $marge_basse;
  89. /**
  90. * Issuer
  91. * @var Societe
  92. */
  93. public $emetteur;
  94. /**
  95. * Constructor
  96. *
  97. * @param DoliDB $db Database handler
  98. */
  99. public function __construct($db)
  100. {
  101. global $conf,$langs,$mysoc;
  102. // Load traductions files requiredby by page
  103. $langs->loadLangs(array("main", "companies"));
  104. $this->db = $db;
  105. $this->name = "standard";
  106. $this->description = $langs->trans("DocumentModelStandardPDF");
  107. // Dimension page pour format A4
  108. $this->type = 'pdf';
  109. $formatarray=pdf_getFormat();
  110. $this->page_largeur = $formatarray['width'];
  111. $this->page_hauteur = $formatarray['height'];
  112. $this->format = array($this->page_largeur,$this->page_hauteur);
  113. $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10;
  114. $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10;
  115. $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10;
  116. $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10;
  117. $this->option_logo = 1; // Affiche logo
  118. $this->option_codestockservice = 0; // Affiche code stock-service
  119. $this->option_multilang = 1; // Dispo en plusieurs langues
  120. $this->option_freetext = 0; // Support add of a personalised text
  121. // Recupere emetteur
  122. $this->emetteur=$mysoc;
  123. if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined
  124. // Define position of columns
  125. $this->wref = 15;
  126. $this->posxdesc=$this->marge_gauche+1;
  127. $this->posxlabel=$this->posxdesc+$this->wref;
  128. $this->posxtva=80;
  129. $this->posxqty=95;
  130. $this->posxup=115;
  131. $this->posxunit=135;
  132. $this->posxdiscount=155;
  133. $this->postotalht=175;
  134. if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup;
  135. $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
  136. if ($this->page_largeur < 210) // To work with US executive format
  137. {
  138. $this->posxpicture-=20;
  139. $this->posxtva-=20;
  140. $this->posxup-=20;
  141. $this->posxqty-=20;
  142. $this->posxunit-=20;
  143. $this->posxdiscount-=20;
  144. $this->postotalht-=20;
  145. }
  146. $this->tva=array();
  147. $this->localtax1=array();
  148. $this->localtax2=array();
  149. $this->atleastoneratenotnull=0;
  150. $this->atleastonediscount=0;
  151. }
  152. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  153. /**
  154. * Function to build a document on disk using the generic odt module.
  155. *
  156. * @param Stock $object Object source to build document
  157. * @param Translate $outputlangs Lang output object
  158. * @param string $srctemplatepath Full path of source filename for generator using a template file
  159. * @param int $hidedetails Do not show line details
  160. * @param int $hidedesc Do not show desc
  161. * @param int $hideref Do not show ref
  162. * @return int 1 if OK, <=0 if KO
  163. */
  164. function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0)
  165. {
  166. // phpcs:enable
  167. global $user,$langs,$conf,$mysoc,$db,$hookmanager;
  168. if (! is_object($outputlangs)) $outputlangs=$langs;
  169. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  170. if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';
  171. // Load traductions files requiredby by page
  172. $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "stocks", "orders", "deliveries"));
  173. $nblignes = count($object->lines);
  174. if ($conf->stock->dir_output)
  175. {
  176. // Definition of $dir and $file
  177. if ($object->specimen)
  178. {
  179. $dir = $conf->stock->dir_output;
  180. $file = $dir . "/SPECIMEN.pdf";
  181. }
  182. else
  183. {
  184. $objectref = dol_sanitizeFileName($object->ref);
  185. $dir = $conf->stock->dir_output . "/" . $objectref;
  186. $file = $dir . "/" . $objectref . ".pdf";
  187. }
  188. $stockFournisseur = new ProductFournisseur($this->db);
  189. $supplierprices = $stockFournisseur->list_product_fournisseur_price($object->id);
  190. $object->supplierprices = $supplierprices;
  191. $productstatic=new Product($db);
  192. if (! file_exists($dir))
  193. {
  194. if (dol_mkdir($dir) < 0)
  195. {
  196. $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir);
  197. return -1;
  198. }
  199. }
  200. if (file_exists($dir))
  201. {
  202. // Add pdfgeneration hook
  203. if (! is_object($hookmanager))
  204. {
  205. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  206. $hookmanager=new HookManager($this->db);
  207. }
  208. $hookmanager->initHooks(array('pdfgeneration'));
  209. $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  210. global $action;
  211. $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  212. // Create pdf instance
  213. $pdf=pdf_getInstance($this->format);
  214. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  215. $pdf->SetAutoPageBreak(1,0);
  216. $heightforinfotot = 40; // Height reserved to output the info and total part
  217. $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page
  218. $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin)
  219. if (class_exists('TCPDF'))
  220. {
  221. $pdf->setPrintHeader(false);
  222. $pdf->setPrintFooter(false);
  223. }
  224. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  225. // Set path to the background PDF File
  226. if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND))
  227. {
  228. $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  229. $tplidx = $pdf->importPage(1);
  230. }
  231. $pdf->Open();
  232. $pagenb=0;
  233. $pdf->SetDrawColor(128,128,128);
  234. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  235. $pdf->SetSubject($outputlangs->transnoentities("Stock"));
  236. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  237. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  238. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Stock")." ".$outputlangs->convToOutputCharset($object->libelle));
  239. if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  240. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  241. // New page
  242. $pdf->AddPage();
  243. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  244. $pagenb++;
  245. $this->_pagehead($pdf, $object, 1, $outputlangs);
  246. $pdf->SetFont('','', $default_font_size - 1);
  247. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  248. $pdf->SetTextColor(0,0,0);
  249. $tab_top = 42;
  250. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10);
  251. $tab_height = 130;
  252. $tab_height_newpage = 150;
  253. /* ************************************************************************** */
  254. /* */
  255. /* Affichage de la liste des produits de l'entrepot */
  256. /* */
  257. /* ************************************************************************** */
  258. $nexY+=5;
  259. $nexY = $pdf->GetY();
  260. $nexY+=10;
  261. $totalunit=0;
  262. $totalvalue=$totalvaluesell=0;
  263. $sql = "SELECT p.rowid as rowid, p.ref, p.label as produit, p.tobatch, p.fk_product_type as type, p.pmp as ppmp, p.price, p.price_ttc, p.entity,";
  264. $sql.= " ps.reel as value";
  265. $sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p";
  266. $sql.= " WHERE ps.fk_product = p.rowid";
  267. $sql.= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse)
  268. $sql.= " AND ps.fk_entrepot = ".$object->id;
  269. $sql.= $db->order($sortfield,$sortorder);
  270. //dol_syslog('List products', LOG_DEBUG);
  271. $resql = $db->query($sql);
  272. if ($resql)
  273. {
  274. $num = $db->num_rows($resql);
  275. $i = 0;
  276. $nblignes = $num;
  277. for ($i = 0 ; $i < $nblignes ; $i++)
  278. {
  279. $objp = $db->fetch_object($resql);
  280. // Multilangs
  281. if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
  282. {
  283. $sql = "SELECT label";
  284. $sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
  285. $sql.= " WHERE fk_product=".$objp->rowid;
  286. $sql.= " AND lang='". $langs->getDefaultLang() ."'";
  287. $sql.= " LIMIT 1";
  288. $result = $db->query($sql);
  289. if ($result)
  290. {
  291. $objtp = $db->fetch_object($result);
  292. if ($objtp->label != '') $objp->produit = $objtp->label;
  293. }
  294. }
  295. $curY = $nexY;
  296. $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
  297. $pdf->SetTextColor(0,0,0);
  298. $pdf->setTopMargin($tab_top_newpage);
  299. $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  300. $pageposbefore=$pdf->getPage();
  301. // Description of product line
  302. $curX = $this->posxdesc-1;
  303. $showpricebeforepagebreak=1;
  304. $pdf->startTransaction();
  305. pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
  306. $pageposafter=$pdf->getPage();
  307. if ($pageposafter > $pageposbefore) // There is a pagebreak
  308. {
  309. $pdf->rollbackTransaction(true);
  310. $pageposafter=$pageposbefore;
  311. //print $pageposafter.'-'.$pageposbefore;exit;
  312. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  313. pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
  314. $pageposafter=$pdf->getPage();
  315. $posyafter=$pdf->GetY();
  316. if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
  317. {
  318. if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page
  319. {
  320. $pdf->AddPage('','',true);
  321. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  322. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  323. $pdf->setPage($pageposafter+1);
  324. }
  325. }
  326. else
  327. {
  328. // We found a page break
  329. $showpricebeforepagebreak=0;
  330. }
  331. }
  332. else // No pagebreak
  333. {
  334. $pdf->commitTransaction();
  335. }
  336. $posYAfterDescription=$pdf->GetY();
  337. $nexY = $pdf->GetY();
  338. $pageposafter=$pdf->getPage();
  339. $pdf->setPage($pageposbefore);
  340. $pdf->setTopMargin($this->marge_haute);
  341. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  342. // We suppose that a too long description is moved completely on next page
  343. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  344. $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  345. }
  346. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  347. $productstatic->id=$objp->rowid;
  348. $productstatic->ref = $objp->ref;
  349. $productstatic->label = $objp->produit;
  350. $productstatic->type=$objp->type;
  351. $productstatic->entity=$objp->entity;
  352. $productstatic->status_batch=$objp->tobatch;
  353. // Ref.
  354. $pdf->SetXY($this->posxdesc, $curY);
  355. $pdf->MultiCell($this->wref, 3, $productstatic->ref, 0, 'L');
  356. // Label
  357. $pdf->SetXY($this->posxlabel+0.8, $curY);
  358. $pdf->MultiCell($this->posxqty-$this->posxlabel-0.8, 3, $objp->produit, 0, 'L');
  359. // Quantity
  360. $valtoshow=price2num($objp->value, 'MS');
  361. $towrite = (empty($valtoshow)?'0':$valtoshow);
  362. $pdf->SetXY($this->posxqty, $curY);
  363. $pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $towrite, 0, 'R');
  364. $totalunit+=$objp->value;
  365. $pdf->SetXY($this->posxup, $curY);
  366. $pdf->MultiCell($this->posxunit-$this->posxup-0.8, 3, price(price2num($objp->ppmp,'MU'), 0, $outputlangs), 0, 'R');
  367. // Total PMP
  368. $pdf->SetXY($this->posxunit, $curY);
  369. $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 3, price(price2num($objp->ppmp*$objp->value,'MT'), 0, $outputlangs), 0, 'R');
  370. $totalvalue+=price2num($objp->ppmp*$objp->value,'MT');
  371. // Price sell min
  372. if (empty($conf->global->PRODUIT_MULTIPRICES))
  373. {
  374. $pricemin=$objp->price;
  375. $pdf->SetXY($this->posxdiscount, $curY);
  376. $pdf->MultiCell($this->postotalht-$this->posxdiscount, 3, price(price2num($pricemin,'MU'), 0, $outputlangs), 0, 'R', 0);
  377. // Total sell min
  378. $pdf->SetXY($this->postotalht, $curY);
  379. $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, price(price2num($pricemin*$objp->value,'MT'), 0, $outputlangs), 0, 'R', 0);
  380. }
  381. $totalvaluesell+=price2num($pricemin*$objp->value,'MT');
  382. // Add line
  383. if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
  384. {
  385. $pdf->setPage($pageposafter);
  386. $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
  387. //$pdf->SetDrawColor(190,190,200);
  388. $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
  389. $pdf->SetLineStyle(array('dash'=>0));
  390. }
  391. $nexY+=2; // Passe espace entre les lignes
  392. // Detect if some page were added automatically and output _tableau for past pages
  393. while ($pagenb < $pageposafter)
  394. {
  395. $pdf->setPage($pagenb);
  396. if ($pagenb == 1)
  397. {
  398. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
  399. }
  400. else
  401. {
  402. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
  403. }
  404. $this->_pagefoot($pdf,$object,$outputlangs,1);
  405. $pagenb++;
  406. $pdf->setPage($pagenb);
  407. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  408. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  409. }
  410. if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
  411. {
  412. if ($pagenb == 1)
  413. {
  414. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
  415. }
  416. else
  417. {
  418. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
  419. }
  420. $this->_pagefoot($pdf,$object,$outputlangs,1);
  421. // New page
  422. $pdf->AddPage();
  423. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  424. $pagenb++;
  425. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  426. }
  427. }
  428. $db->free($resql);
  429. /**
  430. * footer table
  431. */
  432. $nexY = $pdf->GetY();
  433. $nexY+=2;
  434. $curY = $nexY;
  435. $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
  436. $pdf->line($this->marge_gauche, $curY-1, $this->page_largeur-$this->marge_droite, $curY-1);
  437. $pdf->SetLineStyle(array('dash'=>0));
  438. $pdf->SetFont('','B',$default_font_size-1);
  439. $pdf->SetTextColor(0,0,120);
  440. // Ref.
  441. $pdf->SetXY($this->posxdesc, $curY);
  442. $pdf->MultiCell($this->wref, 3, $langs->trans("Total"), 0, 'L');
  443. // Quantity
  444. $valtoshow=price2num($totalunit, 'MS');
  445. $towrite = empty($valtoshow)?'0':$valtoshow;
  446. $pdf->SetXY($this->posxqty, $curY);
  447. $pdf->MultiCell($this->posxup-$this->posxqty-0.8, 3, $towrite, 0, 'R');
  448. // Total PMP
  449. $pdf->SetXY($this->posxunit, $curY);
  450. $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 3, price(price2num($totalvalue,'MT'), 0, $outputlangs), 0, 'R');
  451. // Price sell min
  452. if (empty($conf->global->PRODUIT_MULTIPRICES))
  453. {
  454. // Total sell min
  455. $pdf->SetXY($this->postotalht, $curY);
  456. $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, price(price2num($totalvaluesell,'MT'), 0, $outputlangs), 0, 'R', 0);
  457. }
  458. }
  459. else
  460. {
  461. dol_print_error($db);
  462. }
  463. if ($notetoshow)
  464. {
  465. $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object);
  466. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  467. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  468. $tab_top = 88;
  469. $pdf->SetFont('','', $default_font_size - 1);
  470. $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  471. $nexY = $pdf->GetY();
  472. $height_note=$nexY-$tab_top;
  473. // Rect prend une longueur en 3eme param
  474. $pdf->SetDrawColor(192,192,192);
  475. $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1);
  476. $tab_height = $tab_height - $height_note;
  477. $tab_top = $nexY+6;
  478. }
  479. else
  480. {
  481. $height_note=0;
  482. }
  483. $iniY = $tab_top + 7;
  484. $curY = $tab_top + 7;
  485. $nexY = $tab_top + 7;
  486. // Loop on each lines
  487. /*
  488. for ($i = 0 ; $i < $nblignes ; $i++)
  489. {
  490. $curY = $nexY;
  491. $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage
  492. $pdf->SetTextColor(0,0,0);
  493. $pdf->setTopMargin($tab_top_newpage);
  494. $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  495. $pageposbefore=$pdf->getPage();
  496. // Description of stock line
  497. $curX = $this->posxdesc-1;
  498. $showpricebeforepagebreak=1;
  499. $pdf->startTransaction();
  500. pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,3,$curX,$curY,$hideref,$hidedesc);
  501. $pageposafter=$pdf->getPage();
  502. if ($pageposafter > $pageposbefore) // There is a pagebreak
  503. {
  504. $pdf->rollbackTransaction(true);
  505. $pageposafter=$pageposbefore;
  506. //print $pageposafter.'-'.$pageposbefore;exit;
  507. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  508. pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxtva-$curX,4,$curX,$curY,$hideref,$hidedesc);
  509. $pageposafter=$pdf->getPage();
  510. $posyafter=$pdf->GetY();
  511. if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text
  512. {
  513. if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page
  514. {
  515. $pdf->AddPage('','',true);
  516. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  517. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  518. $pdf->setPage($pageposafter+1);
  519. }
  520. }
  521. else
  522. {
  523. // We found a page break
  524. $showpricebeforepagebreak=0;
  525. }
  526. }
  527. else // No pagebreak
  528. {
  529. $pdf->commitTransaction();
  530. }
  531. $nexY = $pdf->GetY();
  532. $pageposafter=$pdf->getPage();
  533. $pdf->setPage($pageposbefore);
  534. $pdf->setTopMargin($this->marge_haute);
  535. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  536. // We suppose that a too long description is moved completely on next page
  537. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  538. $pdf->setPage($pageposafter); $curY = $tab_top_newpage;
  539. }
  540. $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut
  541. // VAT Rate
  542. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN))
  543. {
  544. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
  545. $pdf->SetXY($this->posxtva, $curY);
  546. $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R');
  547. }
  548. // Unit price before discount
  549. $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
  550. $pdf->SetXY($this->posxup, $curY);
  551. $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
  552. // Quantity
  553. $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
  554. $pdf->SetXY($this->posxqty, $curY);
  555. // Enough for 6 chars
  556. if($conf->global->PRODUCT_USE_UNITS)
  557. {
  558. $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
  559. }
  560. else
  561. {
  562. $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
  563. }
  564. // Unit
  565. if($conf->global->PRODUCT_USE_UNITS)
  566. {
  567. $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
  568. $pdf->SetXY($this->posxunit, $curY);
  569. $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
  570. }
  571. // Discount on line
  572. $pdf->SetXY($this->posxdiscount, $curY);
  573. if ($object->lines[$i]->remise_percent)
  574. {
  575. $pdf->SetXY($this->posxdiscount-2, $curY);
  576. $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
  577. $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R');
  578. }
  579. // Total HT line
  580. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
  581. $pdf->SetXY($this->postotalht, $curY);
  582. $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0);
  583. // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva
  584. if ($conf->multicurrency->enabled && $object->multicurrency_tx != 1) $tvaligne=$object->lines[$i]->multicurrency_total_tva;
  585. else $tvaligne=$object->lines[$i]->total_tva;
  586. $localtax1ligne=$object->lines[$i]->total_localtax1;
  587. $localtax2ligne=$object->lines[$i]->total_localtax2;
  588. $localtax1_rate=$object->lines[$i]->localtax1_tx;
  589. $localtax2_rate=$object->lines[$i]->localtax2_tx;
  590. $localtax1_type=$object->lines[$i]->localtax1_type;
  591. $localtax2_type=$object->lines[$i]->localtax2_type;
  592. if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100;
  593. if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100;
  594. if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100;
  595. $vatrate=(string) $object->lines[$i]->tva_tx;
  596. // Retrieve type from database for backward compatibility with old records
  597. if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined
  598. && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax
  599. {
  600. $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc);
  601. $localtax1_type = $localtaxtmp_array[0];
  602. $localtax2_type = $localtaxtmp_array[2];
  603. }
  604. // retrieve global local tax
  605. if ($localtax1_type && $localtax1ligne != 0)
  606. $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne;
  607. if ($localtax2_type && $localtax2ligne != 0)
  608. $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne;
  609. if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*';
  610. if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0;
  611. $this->tva[$vatrate] += $tvaligne;
  612. // Add line
  613. if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1))
  614. {
  615. $pdf->setPage($pageposafter);
  616. $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80)));
  617. //$pdf->SetDrawColor(190,190,200);
  618. $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1);
  619. $pdf->SetLineStyle(array('dash'=>0));
  620. }
  621. $nexY+=2; // Passe espace entre les lignes
  622. // Detect if some page were added automatically and output _tableau for past pages
  623. while ($pagenb < $pageposafter)
  624. {
  625. $pdf->setPage($pagenb);
  626. if ($pagenb == 1)
  627. {
  628. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
  629. }
  630. else
  631. {
  632. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
  633. }
  634. $this->_pagefoot($pdf,$object,$outputlangs,1);
  635. $pagenb++;
  636. $pdf->setPage($pagenb);
  637. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  638. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  639. }
  640. if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak)
  641. {
  642. if ($pagenb == 1)
  643. {
  644. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1, $object->multicurrency_code);
  645. }
  646. else
  647. {
  648. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code);
  649. }
  650. $this->_pagefoot($pdf,$object,$outputlangs,1);
  651. // New page
  652. $pdf->AddPage();
  653. if (! empty($tplidx)) $pdf->useTemplate($tplidx);
  654. $pagenb++;
  655. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs);
  656. }
  657. }
  658. */
  659. $tab_top = $tab_top_newpage+21;
  660. // Show square
  661. if ($pagenb == 1)
  662. {
  663. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0, $object->multicurrency_code);
  664. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  665. }
  666. else
  667. {
  668. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code);
  669. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  670. }
  671. $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
  672. // Affiche zone infos
  673. //$posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs);
  674. // Affiche zone totaux
  675. //$posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs);
  676. // Pied de page
  677. $this->_pagefoot($pdf,$object,$outputlangs);
  678. if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages();
  679. $pdf->Close();
  680. $pdf->Output($file,'F');
  681. // Add pdfgeneration hook
  682. $hookmanager->initHooks(array('pdfgeneration'));
  683. $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs);
  684. global $action;
  685. $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
  686. if (! empty($conf->global->MAIN_UMASK))
  687. @chmod($file, octdec($conf->global->MAIN_UMASK));
  688. $this->result = array('fullpath'=>$file);
  689. return 1; // Pas d'erreur
  690. }
  691. else
  692. {
  693. $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
  694. return 0;
  695. }
  696. }
  697. else
  698. {
  699. $this->error=$langs->trans("ErrorConstantNotDefined","PRODUCT_OUTPUTDIR");
  700. return 0;
  701. }
  702. }
  703. /**
  704. * Show table for lines
  705. *
  706. * @param TCPDF $pdf Object PDF
  707. * @param string $tab_top Top position of table
  708. * @param string $tab_height Height of table (rectangle)
  709. * @param int $nexY Y (not used)
  710. * @param Translate $outputlangs Langs object
  711. * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
  712. * @param int $hidebottom Hide bottom bar of array
  713. * @param string $currency Currency code
  714. * @return void
  715. */
  716. function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0, $currency='')
  717. {
  718. global $conf;
  719. // Force to disable hidetop and hidebottom
  720. $hidebottom=0;
  721. if ($hidetop) $hidetop=-1;
  722. $currency = !empty($currency) ? $currency : $conf->currency;
  723. $default_font_size = pdf_getPDFFontSize($outputlangs);
  724. // Amount in (at tab_top - 1)
  725. $pdf->SetTextColor(0,0,0);
  726. $pdf->SetFont('','', $default_font_size - 2);
  727. if (empty($hidetop))
  728. {
  729. $titre = $outputlangs->transnoentities("AmountInCurrency",$outputlangs->transnoentitiesnoconv("Currency".$currency));
  730. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top-4);
  731. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  732. //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
  733. if (! empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite-$this->marge_gauche, 5, 'F', null, explode(',',$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
  734. }
  735. $pdf->SetDrawColor(128,128,128);
  736. $pdf->SetFont('','B', $default_font_size - 3);
  737. // Output Rect
  738. //$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
  739. $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
  740. $pdf->SetDrawColor(220,26,26);
  741. $pdf->line($this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_droite, $tab_top);
  742. $pdf->SetLineStyle(array('dash'=>0));
  743. $pdf->SetDrawColor(128,128,128);
  744. $pdf->SetTextColor(0,0,120);
  745. if (empty($hidetop))
  746. {
  747. //$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
  748. $pdf->SetXY($this->posxdesc-1, $tab_top+1);
  749. $pdf->MultiCell($this->wref,3, $outputlangs->transnoentities("Ref"),'','L');
  750. }
  751. //$pdf->line($this->posxlabel-1, $tab_top, $this->posxlabel-1, $tab_top + $tab_height);
  752. if (empty($hidetop))
  753. {
  754. $pdf->SetXY($this->posxlabel-3, $tab_top+1);
  755. $pdf->MultiCell($this->posxqty-$this->posxlabel+3,2, $outputlangs->transnoentities("Label"),'','C');
  756. }
  757. //$pdf->line($this->posxqty-1, $tab_top, $this->posxqty-1, $tab_top + $tab_height);
  758. if (empty($hidetop))
  759. {
  760. $pdf->SetXY($this->posxqty-1, $tab_top+1);
  761. $pdf->MultiCell($this->posxup-$this->posxqty-1,2, $outputlangs->transnoentities("Units"),'','C');
  762. }
  763. //$pdf->line($this->posxup-1, $tab_top, $this->posxup-1, $tab_top + $tab_height);
  764. if (empty($hidetop))
  765. {
  766. $pdf->SetXY($this->posxup-1, $tab_top+1);
  767. $pdf->MultiCell($this->posxunit-$this->posxup-1,2, $outputlangs->transnoentities("AverageUnitPricePMPShort"),'','C');
  768. }
  769. //$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
  770. if (empty($hidetop))
  771. {
  772. $pdf->SetXY($this->posxunit - 1, $tab_top + 1);
  773. $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("EstimatedStockValueShort"), '',
  774. 'C');
  775. }
  776. //$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
  777. if (empty($hidetop))
  778. {
  779. $pdf->SetXY($this->posxdiscount-1, $tab_top+1);
  780. $pdf->MultiCell($this->postotalht-$this->posxdiscount+1,2, $outputlangs->transnoentities("SellPriceMin"),'','C');
  781. }
  782. //$pdf->line($this->postotalht, $tab_top, $this->postotalht, $tab_top + $tab_height);
  783. if (empty($hidetop))
  784. {
  785. $pdf->SetXY($this->postotalht-1, $tab_top+1);
  786. $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht,2, $outputlangs->transnoentities("EstimatedStockValueSellShort"),'','C');
  787. }
  788. $pdf->SetDrawColor(220,26,26);
  789. $pdf->SetLineStyle(array('dash'=>'0','color'=>array(220,26,26)));
  790. $pdf->line($this->marge_gauche, $tab_top+11, $this->page_largeur-$this->marge_droite, $tab_top+11);
  791. $pdf->SetLineStyle(array('dash'=>0));
  792. }
  793. /**
  794. * Show top header of page.
  795. *
  796. * @param TCPDF $pdf Object PDF
  797. * @param Object $object Object to show
  798. * @param int $showaddress 0=no, 1=yes
  799. * @param Translate $outputlangs Object lang for output
  800. * @param string $titlekey Translation key to show as title of document
  801. * @return void
  802. */
  803. function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey="")
  804. {
  805. global $conf,$langs,$db,$hookmanager;
  806. // Load traductions files requiredby by page
  807. $outputlangs->loadLangs(array("main", "propal", "companies", "bills", "orders", "stocks"));
  808. $default_font_size = pdf_getPDFFontSize($outputlangs);
  809. if ($object->type == 1) $titlekey='ServiceSheet';
  810. else $titlekey='StockSheet';
  811. pdf_pagehead($pdf,$outputlangs,$this->page_hauteur);
  812. // Show Draft Watermark
  813. if($object->statut==0 && (! empty($conf->global->COMMANDE_DRAFT_WATERMARK)) )
  814. {
  815. pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->COMMANDE_DRAFT_WATERMARK);
  816. }
  817. $pdf->SetTextColor(0,0,60);
  818. $pdf->SetFont('','B', $default_font_size + 3);
  819. $posy=$this->marge_haute;
  820. $posx=$this->page_largeur-$this->marge_droite-100;
  821. $pdf->SetXY($this->marge_gauche,$posy);
  822. // Logo
  823. $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo;
  824. if ($this->emetteur->logo)
  825. {
  826. if (is_readable($logo))
  827. {
  828. $height=pdf_getHeightForLogo($logo);
  829. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  830. }
  831. else
  832. {
  833. $pdf->SetTextColor(200,0,0);
  834. $pdf->SetFont('','B', $default_font_size -2);
  835. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L');
  836. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  837. }
  838. }
  839. else
  840. {
  841. $text=$this->emetteur->name;
  842. $pdf->MultiCell(100, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
  843. }
  844. $pdf->SetFont('','B', $default_font_size + 3);
  845. $pdf->SetXY($posx,$posy);
  846. $pdf->SetTextColor(0,0,60);
  847. $title=$outputlangs->transnoentities("Warehouse");
  848. $pdf->MultiCell(100, 3, $title, '', 'R');
  849. $pdf->SetFont('','B',$default_font_size);
  850. $posy+=5;
  851. $pdf->SetXY($posx,$posy);
  852. $pdf->SetTextColor(0,0,60);
  853. $pdf->MultiCell(100, 4, $outputlangs->transnoentities("Ref")." : " . $outputlangs->convToOutputCharset($object->libelle), '', 'R');
  854. $posy+=5;
  855. $pdf->SetFont('','', $default_font_size - 1);
  856. $pdf->SetXY($posx,$posy);
  857. $pdf->SetTextColor(0,0,60);
  858. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("LocationSummary").' :', '', 'R');
  859. $posy+=4;
  860. $pdf->SetXY($posx-50,$posy);
  861. $pdf->MultiCell(150, 3, $object->lieu, '', 'R');
  862. // Parent entrepot
  863. $posy+=4;
  864. $pdf->SetXY($posx,$posy);
  865. $pdf->SetTextColor(0,0,60);
  866. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("ParentWarehouse").' :', '', 'R');
  867. $posy+=4;
  868. $pdf->SetXY($posx-50,$posy);
  869. $e = new Entrepot($db);
  870. if(!empty($object->fk_parent) && $e->fetch($object->fk_parent) > 0)
  871. {
  872. $pdf->MultiCell(150, 3, $e->libelle, '', 'R');
  873. }
  874. else
  875. {
  876. $pdf->MultiCell(150, 3, $outputlangs->transnoentities("None"), '', 'R');
  877. }
  878. // Description
  879. $nexY = $pdf->GetY();
  880. $nexY+=5;
  881. $pdf->SetXY($posx,$posy);
  882. $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("Description").' : </b>'.nl2br($object->description), 0, 1);
  883. $nexY = $pdf->GetY();
  884. $calcproductsunique=$object->nb_different_products();
  885. $calcproducts=$object->nb_products();
  886. // Total nb of different products
  887. $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfDifferentProducts").' : </b>'.(empty($calcproductsunique['nb'])?'0':$calcproductsunique['nb']), 0, 1);
  888. $nexY = $pdf->GetY();
  889. // Nb of products
  890. $valtoshow=price2num($calcproducts['nb'], 'MS');
  891. $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("NumberOfProducts").' : </b>'.(empty($valtoshow)?'0':$valtoshow), 0, 1);
  892. $nexY = $pdf->GetY();
  893. // Value
  894. $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("EstimatedStockValueShort").' : </b>'. price((empty($calcproducts['value'])?'0':price2num($calcproducts['value'],'MT')), 0, $langs, 0, -1, -1, $conf->currency), 0, 1);
  895. $nexY = $pdf->GetY();
  896. // Last movement
  897. $sql = "SELECT max(m.datem) as datem";
  898. $sql .= " FROM ".MAIN_DB_PREFIX."stock_mouvement as m";
  899. $sql .= " WHERE m.fk_entrepot = '".$object->id."'";
  900. $resqlbis = $db->query($sql);
  901. if ($resqlbis)
  902. {
  903. $obj = $db->fetch_object($resqlbis);
  904. $lastmovementdate=$db->jdate($obj->datem);
  905. }
  906. else
  907. {
  908. dol_print_error($db);
  909. }
  910. if ($lastmovementdate)
  911. {
  912. $toWrite = dol_print_date($lastmovementdate,'dayhour').' ';
  913. }
  914. else
  915. {
  916. $toWrite = $outputlangs->transnoentities("None");
  917. }
  918. $pdf->writeHTMLCell(190, 2, $this->marge_gauche, $nexY, '<b>'.$outputlangs->transnoentities("LastMovement").' : </b>'.$toWrite, 0, 1);
  919. $nexY = $pdf->GetY();
  920. /*if ($object->ref_client)
  921. {
  922. $posy+=5;
  923. $pdf->SetXY($posx,$posy);
  924. $pdf->SetTextColor(0,0,60);
  925. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("RefCustomer")." : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
  926. }*/
  927. /*$posy+=4;
  928. $pdf->SetXY($posx,$posy);
  929. $pdf->SetTextColor(0,0,60);
  930. $pdf->MultiCell(100, 3, $outputlangs->transnoentities("OrderDate")." : " . dol_print_date($object->date,"%d %b %Y",false,$outputlangs,true), '', 'R');
  931. */
  932. // Get contact
  933. /*
  934. if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP))
  935. {
  936. $arrayidcontact=$object->getIdContact('internal','SALESREPFOLL');
  937. if (count($arrayidcontact) > 0)
  938. {
  939. $usertmp=new User($this->db);
  940. $usertmp->fetch($arrayidcontact[0]);
  941. $posy+=4;
  942. $pdf->SetXY($posx,$posy);
  943. $pdf->SetTextColor(0,0,60);
  944. $pdf->MultiCell(100, 3, $langs->trans("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
  945. }
  946. }*/
  947. $posy+=2;
  948. // Show list of linked objects
  949. $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);
  950. if ($showaddress)
  951. {
  952. /*
  953. // Sender properties
  954. $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty);
  955. // Show sender
  956. $posy=42;
  957. $posx=$this->marge_gauche;
  958. if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80;
  959. $hautcadre=40;
  960. // Show sender frame
  961. $pdf->SetTextColor(0,0,0);
  962. $pdf->SetFont('','', $default_font_size - 2);
  963. $pdf->SetXY($posx,$posy-5);
  964. $pdf->MultiCell(66,5, $outputlangs->transnoentities("BillFrom").":", 0, 'L');
  965. $pdf->SetXY($posx,$posy);
  966. $pdf->SetFillColor(230,230,230);
  967. $pdf->MultiCell(82, $hautcadre, "", 0, 'R', 1);
  968. $pdf->SetTextColor(0,0,60);
  969. // Show sender name
  970. $pdf->SetXY($posx+2,$posy+3);
  971. $pdf->SetFont('','B', $default_font_size);
  972. $pdf->MultiCell(80, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
  973. $posy=$pdf->getY();
  974. // Show sender information
  975. $pdf->SetXY($posx+2,$posy);
  976. $pdf->SetFont('','', $default_font_size - 1);
  977. $pdf->MultiCell(80, 4, $carac_emetteur, 0, 'L');
  978. */
  979. }
  980. $pdf->SetTextColor(0,0,0);
  981. }
  982. /**
  983. * Show footer of page. Need this->emetteur object
  984. *
  985. * @param TCPDF $pdf PDF
  986. * @param Object $object Object to show
  987. * @param Translate $outputlangs Object lang for output
  988. * @param int $hidefreetext 1=Hide free text
  989. * @return int Return height of bottom margin including footer text
  990. */
  991. function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0)
  992. {
  993. global $conf;
  994. $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  995. return pdf_pagefoot($pdf,$outputlangs,'PRODUCT_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext);
  996. }
  997. }