pdf_standard.modules.php 43 KB

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