pdf_cyan.modules.php 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325
  1. <?php
  2. /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
  5. * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  7. * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
  10. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. * or see https://www.gnu.org/
  25. */
  26. /**
  27. * \file htdocs/core/modules/propale/doc/pdf_cyan.modules.php
  28. * \ingroup propale
  29. * \brief File of Class to generate PDF proposal with Cyan template
  30. */
  31. require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
  32. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  36. /**
  37. * Class to generate PDF proposal Cyan
  38. */
  39. class pdf_cyan extends ModelePDFPropales
  40. {
  41. /**
  42. * @var DoliDb Database handler
  43. */
  44. public $db;
  45. /**
  46. * @var string model name
  47. */
  48. public $name;
  49. /**
  50. * @var string model description (short text)
  51. */
  52. public $description;
  53. /**
  54. * @var int Save the name of generated file as the main doc when generating a doc with this template
  55. */
  56. public $update_main_doc_field;
  57. /**
  58. * @var string document type
  59. */
  60. public $type;
  61. /**
  62. * @var array Minimum version of PHP required by module.
  63. * e.g.: PHP ≥ 5.6 = array(5, 6)
  64. */
  65. public $phpmin = array(5, 6);
  66. /**
  67. * Dolibarr version of the loaded document
  68. * @var string
  69. */
  70. public $version = 'dolibarr';
  71. /**
  72. * @var int page_largeur
  73. */
  74. public $page_largeur;
  75. /**
  76. * @var int page_hauteur
  77. */
  78. public $page_hauteur;
  79. /**
  80. * @var array format
  81. */
  82. public $format;
  83. /**
  84. * @var int marge_gauche
  85. */
  86. public $marge_gauche;
  87. /**
  88. * @var int marge_droite
  89. */
  90. public $marge_droite;
  91. /**
  92. * @var int marge_haute
  93. */
  94. public $marge_haute;
  95. /**
  96. * @var int marge_basse
  97. */
  98. public $marge_basse;
  99. /**
  100. * Issuer
  101. * @var Societe Object that emits
  102. */
  103. public $emetteur;
  104. /**
  105. * @var array of document table columns
  106. */
  107. public $cols;
  108. /**
  109. * Constructor
  110. *
  111. * @param DoliDB $db Database handler
  112. */
  113. public function __construct($db)
  114. {
  115. global $conf, $langs, $mysoc;
  116. // Translations
  117. $langs->loadLangs(array("main", "bills"));
  118. $this->db = $db;
  119. $this->name = "cyan";
  120. $this->description = $langs->trans('DocModelCyanDescription');
  121. $this->update_main_doc_field = 1; // Save the name of generated file as the main doc when generating a doc with this template
  122. // Dimension page
  123. $this->type = 'pdf';
  124. $formatarray = pdf_getFormat();
  125. $this->page_largeur = $formatarray['width'];
  126. $this->page_hauteur = $formatarray['height'];
  127. $this->format = array($this->page_largeur, $this->page_hauteur);
  128. $this->marge_gauche = isset($conf->global->MAIN_PDF_MARGIN_LEFT) ? $conf->global->MAIN_PDF_MARGIN_LEFT : 10;
  129. $this->marge_droite = isset($conf->global->MAIN_PDF_MARGIN_RIGHT) ? $conf->global->MAIN_PDF_MARGIN_RIGHT : 10;
  130. $this->marge_haute = isset($conf->global->MAIN_PDF_MARGIN_TOP) ? $conf->global->MAIN_PDF_MARGIN_TOP : 10;
  131. $this->marge_basse = isset($conf->global->MAIN_PDF_MARGIN_BOTTOM) ? $conf->global->MAIN_PDF_MARGIN_BOTTOM : 10;
  132. $this->option_logo = 1; // Display logo
  133. $this->option_tva = 1; // Manage the vat option FACTURE_TVAOPTION
  134. $this->option_modereg = 1; // Display payment mode
  135. $this->option_condreg = 1; // Display payment terms
  136. $this->option_multilang = 1; // Available in several languages
  137. $this->option_escompte = 0; // Displays if there has been a discount
  138. $this->option_credit_note = 0; // Support credit notes
  139. $this->option_freetext = 1; // Support add of a personalised text
  140. $this->option_draft_watermark = 1; // Support add of a watermark on drafts
  141. $this->watermark = '';
  142. // Get source company
  143. $this->emetteur = $mysoc;
  144. if (empty($this->emetteur->country_code)) {
  145. $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default, if was not defined
  146. }
  147. // Define position of columns
  148. $this->posxdesc = $this->marge_gauche + 1; // used for notes ans other stuff
  149. $this->tabTitleHeight = 5; // default height
  150. // Use new system for position of columns, view $this->defineColumnField()
  151. $this->tva = array();
  152. $this->tva_array = array();
  153. $this->localtax1 = array();
  154. $this->localtax2 = array();
  155. $this->atleastoneratenotnull = 0;
  156. $this->atleastonediscount = 0;
  157. }
  158. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  159. /**
  160. * Function to build pdf onto disk
  161. *
  162. * @param Propal $object Object to generate
  163. * @param Translate $outputlangs Lang output object
  164. * @param string $srctemplatepath Full path of source filename for generator using a template file
  165. * @param int $hidedetails Do not show line details
  166. * @param int $hidedesc Do not show desc
  167. * @param int $hideref Do not show ref
  168. * @return int 1=OK, 0=KO
  169. */
  170. public function write_file($object, $outputlangs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  171. {
  172. // phpcs:enable
  173. global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
  174. dol_syslog("write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 'null'));
  175. if (!is_object($outputlangs)) {
  176. $outputlangs = $langs;
  177. }
  178. // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
  179. if (!empty($conf->global->MAIN_USE_FPDF)) {
  180. $outputlangs->charset_output = 'ISO-8859-1';
  181. }
  182. // Load translation files required by page
  183. $outputlangs->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
  184. // Show Draft Watermark
  185. if ($object->statut == $object::STATUS_DRAFT && (!empty($conf->global->PROPALE_DRAFT_WATERMARK))) {
  186. $this->watermark = $conf->global->PROPALE_DRAFT_WATERMARK;
  187. }
  188. global $outputlangsbis;
  189. $outputlangsbis = null;
  190. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  191. $outputlangsbis = new Translate('', $conf);
  192. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  193. $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
  194. }
  195. $nblines = count($object->lines);
  196. $hidetop = 0;
  197. if (!empty($conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE)) {
  198. $hidetop = $conf->global->MAIN_PDF_DISABLE_COL_HEAD_TITLE;
  199. }
  200. // Loop on each lines to detect if there is at least one image to show
  201. $realpatharray = array();
  202. $this->atleastonephoto = false;
  203. if (!empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE)) {
  204. $objphoto = new Product($this->db);
  205. for ($i = 0; $i < $nblines; $i++) {
  206. if (empty($object->lines[$i]->fk_product)) {
  207. continue;
  208. }
  209. $objphoto->fetch($object->lines[$i]->fk_product);
  210. //var_dump($objphoto->ref);exit;
  211. if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
  212. $pdir[0] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/";
  213. $pdir[1] = get_exdir(0, 0, 0, 0, $objphoto, 'product').dol_sanitizeFileName($objphoto->ref).'/';
  214. } else {
  215. $pdir[0] = get_exdir(0, 0, 0, 0, $objphoto, 'product'); // default
  216. $pdir[1] = get_exdir($objphoto->id, 2, 0, 0, $objphoto, 'product').$objphoto->id."/photos/"; // alternative
  217. }
  218. $arephoto = false;
  219. foreach ($pdir as $midir) {
  220. if (!$arephoto) {
  221. if ($conf->entity != $objphoto->entity) {
  222. $dir = $conf->product->multidir_output[$objphoto->entity].'/'.$midir; //Check repertories of current entities
  223. } else {
  224. $dir = $conf->product->dir_output.'/'.$midir; //Check repertory of the current product
  225. }
  226. foreach ($objphoto->liste_photos($dir, 1) as $key => $obj) {
  227. if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) { // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo
  228. if ($obj['photo_vignette']) {
  229. $filename = $obj['photo_vignette'];
  230. } else {
  231. $filename = $obj['photo'];
  232. }
  233. } else {
  234. $filename = $obj['photo'];
  235. }
  236. $realpath = $dir.$filename;
  237. $arephoto = true;
  238. $this->atleastonephoto = true;
  239. }
  240. }
  241. }
  242. if ($realpath && $arephoto) {
  243. $realpatharray[$i] = $realpath;
  244. }
  245. }
  246. }
  247. if (count($realpatharray) == 0) {
  248. $this->posxpicture = $this->posxtva;
  249. }
  250. if ($conf->propal->multidir_output[$conf->entity]) {
  251. $object->fetch_thirdparty();
  252. $deja_regle = 0;
  253. // Definition of $dir and $file
  254. if ($object->specimen) {
  255. $dir = $conf->propal->multidir_output[$conf->entity];
  256. $file = $dir."/SPECIMEN.pdf";
  257. } else {
  258. $objectref = dol_sanitizeFileName($object->ref);
  259. $dir = $conf->propal->multidir_output[$object->entity]."/".$objectref;
  260. $file = $dir."/".$objectref.".pdf";
  261. }
  262. if (!file_exists($dir)) {
  263. if (dol_mkdir($dir) < 0) {
  264. $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir);
  265. return 0;
  266. }
  267. }
  268. if (file_exists($dir)) {
  269. // Add pdfgeneration hook
  270. if (!is_object($hookmanager)) {
  271. include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
  272. $hookmanager = new HookManager($this->db);
  273. }
  274. $hookmanager->initHooks(array('pdfgeneration'));
  275. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  276. global $action;
  277. $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  278. // Set nblines with the new content of lines after hook
  279. $nblines = count($object->lines);
  280. //$nbpayments = count($object->getListOfPayments());
  281. // Create pdf instance
  282. $pdf = pdf_getInstance($this->format);
  283. $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance
  284. $pdf->SetAutoPageBreak(1, 0);
  285. if (class_exists('TCPDF')) {
  286. $pdf->setPrintHeader(false);
  287. $pdf->setPrintFooter(false);
  288. }
  289. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  290. // Set path to the background PDF File
  291. if (!empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) {
  292. $logodir = $conf->mycompany->dir_output;
  293. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  294. $logodir = $conf->mycompany->multidir_output[$object->entity];
  295. }
  296. $pagecount = $pdf->setSourceFile($logodir.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND);
  297. $tplidx = $pdf->importPage(1);
  298. }
  299. $pdf->Open();
  300. $pagenb = 0;
  301. $pdf->SetDrawColor(128, 128, 128);
  302. $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
  303. $pdf->SetSubject($outputlangs->transnoentities("PdfCommercialProposalTitle"));
  304. $pdf->SetCreator("Dolibarr ".DOL_VERSION);
  305. $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
  306. $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("PdfCommercialProposalTitle")." ".$outputlangs->convToOutputCharset($object->thirdparty->name));
  307. if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) {
  308. $pdf->SetCompression(false);
  309. }
  310. $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
  311. // Set $this->atleastonediscount if you have at least one discount
  312. for ($i = 0; $i < $nblines; $i++) {
  313. if ($object->lines[$i]->remise_percent) {
  314. $this->atleastonediscount++;
  315. }
  316. }
  317. // New page
  318. $pdf->AddPage();
  319. if (!empty($tplidx)) {
  320. $pdf->useTemplate($tplidx);
  321. }
  322. $pagenb++;
  323. $heightforinfotot = 40; // Height reserved to output the info and total part
  324. $heightforsignature = empty($conf->global->PROPAL_DISABLE_SIGNATURE) ? (pdfGetHeightForHtmlContent($pdf, $outputlangs->transnoentities("ProposalCustomerSignature")) + 10) : 0;
  325. // Added by MMI Mathieu Moulin iProspective
  326. $heightfocomplement = 0;
  327. if (!empty($conf->global->DOCUMENT_SHOW_COMPLEMENT)) {
  328. $textComplement = $this->textComplement($object, $outputlangs);
  329. $heightfocomplement = $this->heightComplementArea($pdf, $textComplement, $default_font_size);
  330. //var_dump($heightfocomplement); die();
  331. $heightforsignature += $heightfocomplement;
  332. }
  333. $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
  334. $heightforfooter = $this->marge_basse + (empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 12 : 22); // Height reserved to output the footer (value include bottom margin)
  335. //print $heightforinfotot + $heightforsignature + $heightforfreetext + $heightforfooter;exit;
  336. $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
  337. $pdf->SetFont('', '', $default_font_size - 1);
  338. $pdf->MultiCell(0, 3, ''); // Set interline to 3
  339. $pdf->SetTextColor(0, 0, 0);
  340. $tab_top = 90 + $top_shift;
  341. $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD) ? 42 + $top_shift : 10);
  342. // Incoterm
  343. $height_incoterms = 0;
  344. if (!empty($conf->incoterm->enabled)) {
  345. $desc_incoterms = $object->getIncotermsForPDF();
  346. if ($desc_incoterms) {
  347. $tab_top -= 2;
  348. $pdf->SetFont('', '', $default_font_size - 1);
  349. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top - 1, dol_htmlentitiesbr($desc_incoterms), 0, 1);
  350. $nexY = max($pdf->GetY(), $nexY);
  351. $height_incoterms = $nexY - $tab_top;
  352. // Rect takes a length in 3rd parameter
  353. $pdf->SetDrawColor(192, 192, 192);
  354. $pdf->Rect($this->marge_gauche, $tab_top - 1, $this->page_largeur - $this->marge_gauche - $this->marge_droite, $height_incoterms + 1);
  355. $tab_top = $nexY + 6;
  356. $height_incoterms += 4;
  357. }
  358. }
  359. // Displays notes
  360. $notetoshow = empty($object->note_public) ? '' : $object->note_public;
  361. if (!empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) {
  362. // Get first sale rep
  363. if (is_object($object->thirdparty)) {
  364. $salereparray = $object->thirdparty->getSalesRepresentatives($user);
  365. $salerepobj = new User($this->db);
  366. $salerepobj->fetch($salereparray[0]['id']);
  367. if (!empty($salerepobj->signature)) {
  368. $notetoshow = dol_concatdesc($notetoshow, $salerepobj->signature);
  369. }
  370. }
  371. }
  372. // Extrafields in note
  373. $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
  374. if (!empty($extranote)) {
  375. $notetoshow = dol_concatdesc($notetoshow, $extranote);
  376. }
  377. if (!empty($conf->global->MAIN_ADD_CREATOR_IN_NOTE) && $object->user_author_id > 0) {
  378. $tmpuser = new User($this->db);
  379. $tmpuser->fetch($object->user_author_id);
  380. $creator_info = $langs->trans("CaseFollowedBy").' '.$tmpuser->getFullName($langs);
  381. if ($tmpuser->email) $creator_info .= ', '.$langs->trans("EMail").': '.$tmpuser->email;
  382. if ($tmpuser->office_phone) $creator_info .= ', '.$langs->trans("Phone").': '.$tmpuser->office_phone;
  383. $notetoshow = dol_concatdesc($notetoshow, $creator_info);
  384. }
  385. $tab_height = $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter;
  386. $pagenb = $pdf->getPage();
  387. if ($notetoshow) {
  388. $tab_top -= 2;
  389. $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
  390. $pageposbeforenote = $pagenb;
  391. $substitutionarray = pdf_getSubstitutionArray($outputlangs, null, $object);
  392. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  393. $notetoshow = make_substitutions($notetoshow, $substitutionarray, $outputlangs);
  394. $notetoshow = convertBackOfficeMediasLinksToPublicLinks($notetoshow);
  395. $pdf->startTransaction();
  396. $pdf->SetFont('', '', $default_font_size - 1);
  397. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  398. // Description
  399. $pageposafternote = $pdf->getPage();
  400. $posyafter = $pdf->GetY();
  401. if ($pageposafternote > $pageposbeforenote) {
  402. $pdf->rollbackTransaction(true);
  403. // prepare pages to receive notes
  404. while ($pagenb < $pageposafternote) {
  405. $pdf->AddPage();
  406. $pagenb++;
  407. if (!empty($tplidx)) {
  408. $pdf->useTemplate($tplidx);
  409. }
  410. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  411. $this->_pagehead($pdf, $object, 0, $outputlangs);
  412. }
  413. // $this->_pagefoot($pdf,$object,$outputlangs,1);
  414. $pdf->setTopMargin($tab_top_newpage);
  415. // The only function to edit the bottom margin of current page to set it.
  416. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  417. }
  418. // back to start
  419. $pdf->setPage($pageposbeforenote);
  420. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  421. $pdf->SetFont('', '', $default_font_size - 1);
  422. $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1);
  423. $pageposafternote = $pdf->getPage();
  424. $posyafter = $pdf->GetY();
  425. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) { // There is no space left for total+free text
  426. $pdf->AddPage('', '', true);
  427. $pagenb++;
  428. $pageposafternote++;
  429. $pdf->setPage($pageposafternote);
  430. $pdf->setTopMargin($tab_top_newpage);
  431. // The only function to edit the bottom margin of current page to set it.
  432. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext);
  433. //$posyafter = $tab_top_newpage;
  434. }
  435. // apply note frame to previous pages
  436. $i = $pageposbeforenote;
  437. while ($i < $pageposafternote) {
  438. $pdf->setPage($i);
  439. $pdf->SetDrawColor(128, 128, 128);
  440. // Draw note frame
  441. if ($i > $pageposbeforenote) {
  442. $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
  443. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
  444. } else {
  445. $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
  446. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
  447. }
  448. // Add footer
  449. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  450. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  451. $i++;
  452. }
  453. // apply note frame to last page
  454. $pdf->setPage($pageposafternote);
  455. if (!empty($tplidx)) {
  456. $pdf->useTemplate($tplidx);
  457. }
  458. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  459. $this->_pagehead($pdf, $object, 0, $outputlangs);
  460. }
  461. $height_note = $posyafter - $tab_top_newpage;
  462. $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
  463. } else {
  464. // No pagebreak
  465. $pdf->commitTransaction();
  466. $posyafter = $pdf->GetY();
  467. $height_note = $posyafter - $tab_top;
  468. $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
  469. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
  470. // not enough space, need to add page
  471. $pdf->AddPage('', '', true);
  472. $pagenb++;
  473. $pageposafternote++;
  474. $pdf->setPage($pageposafternote);
  475. if (!empty($tplidx)) {
  476. $pdf->useTemplate($tplidx);
  477. }
  478. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  479. $this->_pagehead($pdf, $object, 0, $outputlangs);
  480. }
  481. $posyafter = $tab_top_newpage;
  482. }
  483. }
  484. $tab_height = $tab_height - $height_note;
  485. $tab_top = $posyafter + 6;
  486. } else {
  487. $height_note = 0;
  488. }
  489. // Use new auto column system
  490. $this->prepareArrayColumnField($object, $outputlangs, $hidedetails, $hidedesc, $hideref);
  491. // Table simulation to know the height of the title line
  492. $pdf->startTransaction();
  493. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  494. $pdf->rollbackTransaction(true);
  495. $nexY = $tab_top + $this->tabTitleHeight;
  496. // Loop on each lines
  497. $pageposbeforeprintlines = $pdf->getPage();
  498. $pagenb = $pageposbeforeprintlines;
  499. for ($i = 0; $i < $nblines; $i++) {
  500. $curY = $nexY;
  501. $pdf->SetFont('', '', $default_font_size - 1); // Into loop to work with multipage
  502. $pdf->SetTextColor(0, 0, 0);
  503. // Define size of image if we need it
  504. $imglinesize = array();
  505. if (!empty($realpatharray[$i])) {
  506. $imglinesize = pdf_getSizeForImage($realpatharray[$i]);
  507. }
  508. $pdf->setTopMargin($tab_top_newpage);
  509. $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot); // The only function to edit the bottom margin of current page to set it.
  510. $pageposbefore = $pdf->getPage();
  511. $showpricebeforepagebreak = 1;
  512. $posYAfterImage = 0;
  513. $posYAfterDescription = 0;
  514. if ($this->getColumnStatus('photo')) {
  515. // We start with Photo of product line
  516. if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) { // If photo too high, we moved completely on new page
  517. $pdf->AddPage('', '', true);
  518. if (!empty($tplidx)) {
  519. $pdf->useTemplate($tplidx);
  520. }
  521. $pdf->setPage($pageposbefore + 1);
  522. $curY = $tab_top_newpage;
  523. // Allows data in the first page if description is long enough to break in multiples pages
  524. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  525. $showpricebeforepagebreak = 1;
  526. } else {
  527. $showpricebeforepagebreak = 0;
  528. }
  529. }
  530. if (!empty($this->cols['photo']) && isset($imglinesize['width']) && isset($imglinesize['height'])) {
  531. $pdf->Image($realpatharray[$i], $this->getColumnContentXStart('photo'), $curY + 1, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi
  532. // $pdf->Image does not increase value return by getY, so we save it manually
  533. $posYAfterImage = $curY + $imglinesize['height'];
  534. }
  535. }
  536. // Description of product line
  537. if ($this->getColumnStatus('desc')) {
  538. $pdf->startTransaction();
  539. $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
  540. $pageposafter = $pdf->getPage();
  541. if ($pageposafter > $pageposbefore) { // There is a pagebreak
  542. $pdf->rollbackTransaction(true);
  543. $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it.
  544. $this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
  545. $pageposafter = $pdf->getPage();
  546. $posyafter = $pdf->GetY();
  547. //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit;
  548. if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforsignature + $heightforinfotot))) { // There is no space left for total+free text
  549. if ($i == ($nblines - 1)) { // No more lines, and no space left to show total, so we create a new page
  550. $pdf->AddPage('', '', true);
  551. if (!empty($tplidx)) {
  552. $pdf->useTemplate($tplidx);
  553. }
  554. $pdf->setPage($pageposafter + 1);
  555. }
  556. } else {
  557. // We found a page break
  558. // Allows data in the first page if description is long enough to break in multiples pages
  559. if (!empty($conf->global->MAIN_PDF_DATA_ON_FIRST_PAGE)) {
  560. $showpricebeforepagebreak = 1;
  561. } else {
  562. $showpricebeforepagebreak = 0;
  563. }
  564. }
  565. } else // No pagebreak
  566. {
  567. $pdf->commitTransaction();
  568. }
  569. $posYAfterDescription = $pdf->GetY();
  570. }
  571. $nexY = $pdf->GetY();
  572. $pageposafter = $pdf->getPage();
  573. $pdf->setPage($pageposbefore);
  574. $pdf->setTopMargin($this->marge_haute);
  575. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  576. // We suppose that a too long description or photo were moved completely on next page
  577. if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
  578. $pdf->setPage($pageposafter);
  579. $curY = $tab_top_newpage;
  580. }
  581. $pdf->SetFont('', '', $default_font_size - 1); // We reposition the default font
  582. // VAT Rate
  583. if ($this->getColumnStatus('vat')) {
  584. $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails);
  585. $this->printStdColumnContent($pdf, $curY, 'vat', $vat_rate);
  586. $nexY = max($pdf->GetY(), $nexY);
  587. }
  588. // Unit price before discount
  589. if ($this->getColumnStatus('subprice')) {
  590. $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
  591. $this->printStdColumnContent($pdf, $curY, 'subprice', $up_excl_tax);
  592. $nexY = max($pdf->GetY(), $nexY);
  593. }
  594. // Quantity
  595. // Enough for 6 chars
  596. if ($this->getColumnStatus('qty')) {
  597. $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
  598. $this->printStdColumnContent($pdf, $curY, 'qty', $qty);
  599. $nexY = max($pdf->GetY(), $nexY);
  600. }
  601. // Unit
  602. if ($this->getColumnStatus('unit')) {
  603. $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
  604. $this->printStdColumnContent($pdf, $curY, 'unit', $unit);
  605. $nexY = max($pdf->GetY(), $nexY);
  606. }
  607. // Discount on line
  608. if ($this->getColumnStatus('discount') && $object->lines[$i]->remise_percent) {
  609. $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails);
  610. $this->printStdColumnContent($pdf, $curY, 'discount', $remise_percent);
  611. $nexY = max($pdf->GetY(), $nexY);
  612. }
  613. // Total excl tax line (HT)
  614. if ($this->getColumnStatus('totalexcltax')) {
  615. $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails);
  616. $this->printStdColumnContent($pdf, $curY, 'totalexcltax', $total_excl_tax);
  617. $nexY = max($pdf->GetY(), $nexY);
  618. }
  619. // Total with tax line (TTC)
  620. if ($this->getColumnStatus('totalincltax')) {
  621. $total_incl_tax = pdf_getlinetotalwithtax($object, $i, $outputlangs, $hidedetails);
  622. $this->printStdColumnContent($pdf, $curY, 'totalincltax', $total_incl_tax);
  623. $nexY = max($pdf->GetY(), $nexY);
  624. }
  625. // Extrafields
  626. if (!empty($object->lines[$i]->array_options)) {
  627. foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
  628. if ($this->getColumnStatus($extrafieldColKey)) {
  629. $extrafieldValue = $this->getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
  630. $this->printStdColumnContent($pdf, $curY, $extrafieldColKey, $extrafieldValue);
  631. $nexY = max($pdf->GetY(), $nexY);
  632. }
  633. }
  634. }
  635. $parameters = array(
  636. 'object' => $object,
  637. 'i' => $i,
  638. 'pdf' =>& $pdf,
  639. 'curY' =>& $curY,
  640. 'nexY' =>& $nexY,
  641. 'outputlangs' => $outputlangs,
  642. 'hidedetails' => $hidedetails
  643. );
  644. $reshook = $hookmanager->executeHooks('printPDFline', $parameters, $this); // Note that $object may have been modified by hook
  645. // Collection of totals by value of vat in $this->tva["rate"] = total_tva
  646. if (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) {
  647. $tvaligne = $object->lines[$i]->multicurrency_total_tva;
  648. } else {
  649. $tvaligne = $object->lines[$i]->total_tva;
  650. }
  651. $localtax1ligne = $object->lines[$i]->total_localtax1;
  652. $localtax2ligne = $object->lines[$i]->total_localtax2;
  653. $localtax1_rate = $object->lines[$i]->localtax1_tx;
  654. $localtax2_rate = $object->lines[$i]->localtax2_tx;
  655. $localtax1_type = $object->lines[$i]->localtax1_type;
  656. $localtax2_type = $object->lines[$i]->localtax2_type;
  657. if ($object->remise_percent) {
  658. $tvaligne -= ($tvaligne * $object->remise_percent) / 100;
  659. }
  660. if ($object->remise_percent) {
  661. $localtax1ligne -= ($localtax1ligne * $object->remise_percent) / 100;
  662. }
  663. if ($object->remise_percent) {
  664. $localtax2ligne -= ($localtax2ligne * $object->remise_percent) / 100;
  665. }
  666. $vatrate = (string) $object->lines[$i]->tva_tx;
  667. // Retrieve type from database for backward compatibility with old records
  668. if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined
  669. && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax
  670. $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc);
  671. $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : '';
  672. $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : '';
  673. }
  674. // retrieve global local tax
  675. if ($localtax1_type && $localtax1ligne != 0) {
  676. $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
  677. }
  678. if ($localtax2_type && $localtax2ligne != 0) {
  679. $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
  680. }
  681. if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
  682. $vatrate .= '*';
  683. }
  684. // Fill $this->tva and $this->tva_array
  685. if (!isset($this->tva[$vatrate])) {
  686. $this->tva[$vatrate] = 0;
  687. }
  688. $this->tva[$vatrate] += $tvaligne;
  689. $vatcode = $object->lines[$i]->vat_src_code;
  690. if (empty($this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'])) {
  691. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] = 0;
  692. }
  693. $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')] = array('vatrate'=>$vatrate, 'vatcode'=>$vatcode, 'amount'=> $this->tva_array[$vatrate.($vatcode ? ' ('.$vatcode.')' : '')]['amount'] + $tvaligne);
  694. if ($posYAfterImage > $posYAfterDescription) {
  695. $nexY = max($nexY, $posYAfterImage);
  696. }
  697. // Add line
  698. if (!empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblines - 1)) {
  699. $pdf->setPage($pageposafter);
  700. $pdf->SetLineStyle(array('dash'=>'1,1', 'color'=>array(80, 80, 80)));
  701. //$pdf->SetDrawColor(190,190,200);
  702. $pdf->line($this->marge_gauche, $nexY + 1, $this->page_largeur - $this->marge_droite, $nexY + 1);
  703. $pdf->SetLineStyle(array('dash'=>0));
  704. }
  705. $nexY += 2; // Add space between lines
  706. // Detect if some page were added automatically and output _tableau for past pages
  707. while ($pagenb < $pageposafter) {
  708. $pdf->setPage($pagenb);
  709. if ($pagenb == $pageposbeforeprintlines) {
  710. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
  711. } else {
  712. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
  713. }
  714. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  715. $pagenb++;
  716. $pdf->setPage($pagenb);
  717. $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it.
  718. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  719. $this->_pagehead($pdf, $object, 0, $outputlangs);
  720. }
  721. if (!empty($tplidx)) {
  722. $pdf->useTemplate($tplidx);
  723. }
  724. }
  725. if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
  726. if ($pagenb == $pageposafter) {
  727. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
  728. } else {
  729. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
  730. }
  731. $this->_pagefoot($pdf, $object, $outputlangs, 1);
  732. // New page
  733. $pdf->AddPage();
  734. if (!empty($tplidx)) {
  735. $pdf->useTemplate($tplidx);
  736. }
  737. $pagenb++;
  738. if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) {
  739. $this->_pagehead($pdf, $object, 0, $outputlangs);
  740. }
  741. }
  742. }
  743. // Show square
  744. if ($pagenb == $pageposbeforeprintlines) {
  745. $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
  746. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
  747. } else {
  748. $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
  749. $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforsignature - $heightforfooter + 1;
  750. }
  751. // Display infos area
  752. $posy = $this->drawInfoTable($pdf, $object, $bottomlasttab, $outputlangs);
  753. // Display total zone
  754. $posy = $this->drawTotalTable($pdf, $object, 0, $bottomlasttab, $outputlangs);
  755. // Display payment area
  756. /*
  757. if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included)
  758. {
  759. $posy=$this->drawPaymentsTable($pdf, $object, $posy, $outputlangs);
  760. }
  761. */
  762. // Customer signature area
  763. if (empty($conf->global->PROPAL_DISABLE_SIGNATURE)) {
  764. $posy = $this->drawSignatureArea($pdf, $object, $posy, $outputlangs);
  765. }
  766. // Added by MMI Mathieu Moulin iProspective
  767. if (!empty($textComplement)) {
  768. $posy = $this->drawComplementArea($pdf, $textComplement, $posy, $outputlangs);
  769. }
  770. // Pagefoot
  771. $this->_pagefoot($pdf, $object, $outputlangs);
  772. if (method_exists($pdf, 'AliasNbPages')) {
  773. $pdf->AliasNbPages();
  774. }
  775. //If propal merge product PDF is active
  776. if (!empty($conf->global->PRODUIT_PDF_MERGE_PROPAL)) {
  777. require_once DOL_DOCUMENT_ROOT.'/product/class/propalmergepdfproduct.class.php';
  778. $already_merged = array();
  779. foreach ($object->lines as $line) {
  780. if (!empty($line->fk_product) && !(in_array($line->fk_product, $already_merged))) {
  781. // Find the desire PDF
  782. $filetomerge = new Propalmergepdfproduct($this->db);
  783. if ($conf->global->MAIN_MULTILANGS) {
  784. $filetomerge->fetch_by_product($line->fk_product, $outputlangs->defaultlang);
  785. } else {
  786. $filetomerge->fetch_by_product($line->fk_product);
  787. }
  788. $already_merged[] = $line->fk_product;
  789. $product = new Product($this->db);
  790. $product->fetch($line->fk_product);
  791. if ($product->entity != $conf->entity) {
  792. $entity_product_file = $product->entity;
  793. } else {
  794. $entity_product_file = $conf->entity;
  795. }
  796. // If PDF is selected and file is not empty
  797. if (count($filetomerge->lines) > 0) {
  798. foreach ($filetomerge->lines as $linefile) {
  799. if (!empty($linefile->id) && !empty($linefile->file_name)) {
  800. if (!empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
  801. if (!empty($conf->product->enabled)) {
  802. $filetomerge_dir = $conf->product->multidir_output[$entity_product_file].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos";
  803. } elseif (!empty($conf->service->enabled)) {
  804. $filetomerge_dir = $conf->service->multidir_output[$entity_product_file].'/'.get_exdir($product->id, 2, 0, 0, $product, 'product').$product->id."/photos";
  805. }
  806. } else {
  807. if (!empty($conf->product->enabled)) {
  808. $filetomerge_dir = $conf->product->multidir_output[$entity_product_file].'/'.get_exdir(0, 0, 0, 0, $product, 'product');
  809. } elseif (!empty($conf->service->enabled)) {
  810. $filetomerge_dir = $conf->service->multidir_output[$entity_product_file].'/'.get_exdir(0, 0, 0, 0, $product, 'product');
  811. }
  812. }
  813. dol_syslog(get_class($this).':: upload_dir='.$filetomerge_dir, LOG_DEBUG);
  814. $infile = $filetomerge_dir.'/'.$linefile->file_name;
  815. if (file_exists($infile) && is_readable($infile)) {
  816. $pagecount = $pdf->setSourceFile($infile);
  817. for ($i = 1; $i <= $pagecount; $i++) {
  818. $tplIdx = $pdf->importPage($i);
  819. if ($tplIdx !== false) {
  820. $s = $pdf->getTemplatesize($tplIdx);
  821. $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
  822. $pdf->useTemplate($tplIdx);
  823. } else {
  824. setEventMessages(null, array($infile.' cannot be added, probably protected PDF'), 'warnings');
  825. }
  826. }
  827. }
  828. }
  829. }
  830. }
  831. }
  832. }
  833. }
  834. $pdf->Close();
  835. $pdf->Output($file, 'F');
  836. //Add pdfgeneration hook
  837. $hookmanager->initHooks(array('pdfgeneration'));
  838. $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs);
  839. global $action;
  840. $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
  841. if ($reshook < 0) {
  842. $this->error = $hookmanager->error;
  843. $this->errors = $hookmanager->errors;
  844. }
  845. if (!empty($conf->global->MAIN_UMASK)) {
  846. @chmod($file, octdec($conf->global->MAIN_UMASK));
  847. }
  848. $this->result = array('fullpath'=>$file);
  849. return 1; // No error
  850. } else {
  851. $this->error = $langs->trans("ErrorCanNotCreateDir", $dir);
  852. return 0;
  853. }
  854. } else {
  855. $this->error = $langs->trans("ErrorConstantNotDefined", "PROP_OUTPUTDIR");
  856. return 0;
  857. }
  858. }
  859. /**
  860. * Show payments table
  861. *
  862. * @param TCPDF $pdf Object PDF
  863. * @param Propal $object Object proposal
  864. * @param int $posy Position y in PDF
  865. * @param Translate $outputlangs Object langs for output
  866. * @return int <0 if KO, >0 if OK
  867. */
  868. protected function drawPaymentsTable(&$pdf, $object, $posy, $outputlangs)
  869. {
  870. }
  871. /**
  872. * Show miscellaneous information (payment mode, payment term, ...)
  873. *
  874. * @param TCPDF $pdf Object PDF
  875. * @param Propal $object Object to show
  876. * @param int $posy Y
  877. * @param Translate $outputlangs Langs object
  878. * @return int Pos y
  879. */
  880. public function drawInfoTable(&$pdf, $object, $posy, $outputlangs)
  881. {
  882. global $conf, $mysoc;
  883. $default_font_size = pdf_getPDFFontSize($outputlangs);
  884. $pdf->SetFont('', '', $default_font_size - 1);
  885. // MMI Mathieu Moulin iProspective
  886. // Replacement for VAT exempt notice
  887. global $hookmanager;
  888. $parameters = array(
  889. 'object' => $object,
  890. 'outputlangs' => $outputlangs,
  891. 'mysoc' => $mysoc,
  892. 'emetteur' => $this->emetteur,
  893. );
  894. $reshook = $hookmanager->executeHooks('VATNotificationOnPDF', $parameters, $this); // Note that $object may have been modified by hook
  895. //var_dump($hookmanager); die();
  896. //var_dump($reshook); die();
  897. if ($reshook < 0) {
  898. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  899. } elseif (empty($reshook)) {
  900. // If France, show VAT mention if not applicable
  901. if ($this->emetteur->country_code == 'FR' && empty($mysoc->tva_assuj))
  902. $vat_info = $outputlangs->transnoentities("VATIsNotUsedForInvoice");
  903. } else {
  904. $vat_info = $hookmanager->resPrint;
  905. }
  906. if (!empty($vat_info)) {
  907. $pdf->SetFont('', 'B', $default_font_size - 2);
  908. $pdf->SetXY($this->marge_gauche, $posy);
  909. $pdf->MultiCell(100, 3, $vat_info, 0, 'L', 0);
  910. $posy = $pdf->GetY() + 4;
  911. }
  912. $posxval = 52;
  913. if (!empty($conf->global->MAIN_PDF_DATE_TEXT)) {
  914. $displaydate = "daytext";
  915. } else {
  916. $displaydate = "day";
  917. }
  918. // Show shipping date
  919. if (!empty($object->delivery_date)) {
  920. $outputlangs->load("sendings");
  921. $pdf->SetFont('', 'B', $default_font_size - 2);
  922. $pdf->SetXY($this->marge_gauche, $posy);
  923. $titre = $outputlangs->transnoentities("DateDeliveryPlanned").':';
  924. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  925. $pdf->SetFont('', '', $default_font_size - 2);
  926. $pdf->SetXY($posxval, $posy);
  927. $dlp = dol_print_date($object->delivery_date, $displaydate, false, $outputlangs, true);
  928. $pdf->MultiCell(80, 4, $dlp, 0, 'L');
  929. $posy = $pdf->GetY() + 1;
  930. } elseif ($object->availability_code || $object->availability) { // Show availability conditions
  931. $pdf->SetFont('', 'B', $default_font_size - 2);
  932. $pdf->SetXY($this->marge_gauche, $posy);
  933. $titre = $outputlangs->transnoentities("AvailabilityPeriod").':';
  934. $pdf->MultiCell(80, 4, $titre, 0, 'L');
  935. $pdf->SetTextColor(0, 0, 0);
  936. $pdf->SetFont('', '', $default_font_size - 2);
  937. $pdf->SetXY($posxval, $posy);
  938. $lib_availability = $outputlangs->transnoentities("AvailabilityType".$object->availability_code) != ('AvailabilityType'.$object->availability_code) ? $outputlangs->transnoentities("AvailabilityType".$object->availability_code) : $outputlangs->convToOutputCharset($object->availability);
  939. $lib_availability = str_replace('\n', "\n", $lib_availability);
  940. $pdf->MultiCell(80, 4, $lib_availability, 0, 'L');
  941. $posy = $pdf->GetY() + 1;
  942. }
  943. // Show payments conditions
  944. if (empty($conf->global->PROPOSAL_PDF_HIDE_PAYMENTTERM) && ($object->cond_reglement_code || $object->cond_reglement)) {
  945. $pdf->SetFont('', 'B', $default_font_size - 2);
  946. $pdf->SetXY($this->marge_gauche, $posy);
  947. $titre = $outputlangs->transnoentities("PaymentConditions").':';
  948. $pdf->MultiCell(43, 4, $titre, 0, 'L');
  949. $pdf->SetFont('', '', $default_font_size - 2);
  950. $pdf->SetXY($posxval, $posy);
  951. $lib_condition_paiement = $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) != ('PaymentCondition'.$object->cond_reglement_code) ? $outputlangs->transnoentities("PaymentCondition".$object->cond_reglement_code) : $outputlangs->convToOutputCharset($object->cond_reglement_doc ? $object->cond_reglement_doc : $object->cond_reglement_label);
  952. $lib_condition_paiement = str_replace('\n', "\n", $lib_condition_paiement);
  953. if ($object->deposit_percent > 0) {
  954. $lib_condition_paiement = str_replace('__DEPOSIT_PERCENT__', $object->deposit_percent, $lib_condition_paiement);
  955. }
  956. $pdf->MultiCell(67, 4, $lib_condition_paiement, 0, 'L');
  957. $posy = $pdf->GetY() + 3;
  958. }
  959. if (empty($conf->global->PROPOSAL_PDF_HIDE_PAYMENTMODE)) {
  960. // Check a payment mode is defined
  961. /* Not required on a proposal
  962. if (empty($object->mode_reglement_code)
  963. && ! $conf->global->FACTURE_CHQ_NUMBER
  964. && ! $conf->global->FACTURE_RIB_NUMBER)
  965. {
  966. $pdf->SetXY($this->marge_gauche, $posy);
  967. $pdf->SetTextColor(200,0,0);
  968. $pdf->SetFont('','B', $default_font_size - 2);
  969. $pdf->MultiCell(90, 3, $outputlangs->transnoentities("ErrorNoPaiementModeConfigured"),0,'L',0);
  970. $pdf->SetTextColor(0,0,0);
  971. $posy=$pdf->GetY()+1;
  972. }
  973. */
  974. // Show payment mode
  975. if ($object->mode_reglement_code
  976. && $object->mode_reglement_code != 'CHQ'
  977. && $object->mode_reglement_code != 'VIR') {
  978. $pdf->SetFont('', 'B', $default_font_size - 2);
  979. $pdf->SetXY($this->marge_gauche, $posy);
  980. $titre = $outputlangs->transnoentities("PaymentMode").':';
  981. $pdf->MultiCell(80, 5, $titre, 0, 'L');
  982. $pdf->SetFont('', '', $default_font_size - 2);
  983. $pdf->SetXY($posxval, $posy);
  984. $lib_mode_reg = $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) != ('PaymentType'.$object->mode_reglement_code) ? $outputlangs->transnoentities("PaymentType".$object->mode_reglement_code) : $outputlangs->convToOutputCharset($object->mode_reglement);
  985. $pdf->MultiCell(80, 5, $lib_mode_reg, 0, 'L');
  986. $posy = $pdf->GetY() + 2;
  987. }
  988. // Show payment mode CHQ
  989. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'CHQ') {
  990. // Si mode reglement non force ou si force a CHQ
  991. if (!empty($conf->global->FACTURE_CHQ_NUMBER)) {
  992. $diffsizetitle = (empty($conf->global->PDF_DIFFSIZE_TITLE) ? 3 : $conf->global->PDF_DIFFSIZE_TITLE);
  993. if ($conf->global->FACTURE_CHQ_NUMBER > 0) {
  994. $account = new Account($this->db);
  995. $account->fetch($conf->global->FACTURE_CHQ_NUMBER);
  996. $pdf->SetXY($this->marge_gauche, $posy);
  997. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  998. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $account->proprio), 0, 'L', 0);
  999. $posy = $pdf->GetY() + 1;
  1000. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  1001. $pdf->SetXY($this->marge_gauche, $posy);
  1002. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  1003. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($account->owner_address), 0, 'L', 0);
  1004. $posy = $pdf->GetY() + 2;
  1005. }
  1006. }
  1007. if ($conf->global->FACTURE_CHQ_NUMBER == -1) {
  1008. $pdf->SetXY($this->marge_gauche, $posy);
  1009. $pdf->SetFont('', 'B', $default_font_size - $diffsizetitle);
  1010. $pdf->MultiCell(100, 3, $outputlangs->transnoentities('PaymentByChequeOrderedTo', $this->emetteur->name), 0, 'L', 0);
  1011. $posy = $pdf->GetY() + 1;
  1012. if (empty($conf->global->MAIN_PDF_HIDE_CHQ_ADDRESS)) {
  1013. $pdf->SetXY($this->marge_gauche, $posy);
  1014. $pdf->SetFont('', '', $default_font_size - $diffsizetitle);
  1015. $pdf->MultiCell(100, 3, $outputlangs->convToOutputCharset($this->emetteur->getFullAddress()), 0, 'L', 0);
  1016. $posy = $pdf->GetY() + 2;
  1017. }
  1018. }
  1019. }
  1020. }
  1021. // If payment mode not forced or forced to VIR, show payment with BAN
  1022. if (empty($object->mode_reglement_code) || $object->mode_reglement_code == 'VIR') {
  1023. if ($object->fk_account > 0 || $object->fk_bank > 0 || !empty($conf->global->FACTURE_RIB_NUMBER)) {
  1024. $bankid = ($object->fk_account <= 0 ? $conf->global->FACTURE_RIB_NUMBER : $object->fk_account);
  1025. if ($object->fk_bank > 0) {
  1026. $bankid = $object->fk_bank; // For backward compatibility when object->fk_account is forced with object->fk_bank
  1027. }
  1028. $account = new Account($this->db);
  1029. $account->fetch($bankid);
  1030. $curx = $this->marge_gauche;
  1031. $cury = $posy;
  1032. $posy = pdf_bank($pdf, $outputlangs, $curx, $cury, $account, 0, $default_font_size);
  1033. $posy += 2;
  1034. }
  1035. }
  1036. }
  1037. return $posy;
  1038. }
  1039. /**
  1040. * Show total to pay
  1041. *
  1042. * @param TCPDF $pdf Object PDF
  1043. * @param Propal $object Object proposal
  1044. * @param int $deja_regle Amount already paid (in the currency of invoice)
  1045. * @param int $posy Position depart
  1046. * @param Translate $outputlangs Objet langs
  1047. * @param Translate $outputlangsbis Object lang for output bis
  1048. * @return int Position pour suite
  1049. */
  1050. protected function drawTotalTable(&$pdf, $object, $deja_regle, $posy, $outputlangs, $outputlangsbis = null)
  1051. {
  1052. global $conf, $mysoc, $hookmanager;
  1053. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1054. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && $outputlangs->defaultlang != $conf->global->PDF_USE_ALSO_LANGUAGE_CODE) {
  1055. $outputlangsbis = new Translate('', $conf);
  1056. $outputlangsbis->setDefaultLang($conf->global->PDF_USE_ALSO_LANGUAGE_CODE);
  1057. $outputlangsbis->loadLangs(array("main", "dict", "companies", "bills", "products", "propal"));
  1058. $default_font_size--;
  1059. }
  1060. $tab2_top = $posy;
  1061. $tab2_hl = 4;
  1062. $pdf->SetFont('', '', $default_font_size - 1);
  1063. // Total table
  1064. $col1x = 120;
  1065. $col2x = 170;
  1066. if ($this->page_largeur < 210) { // To work with US executive format
  1067. $col2x -= 20;
  1068. }
  1069. $largcol2 = ($this->page_largeur - $this->marge_droite - $col2x);
  1070. $useborder = 0;
  1071. $index = 0;
  1072. // Total HT
  1073. $pdf->SetFillColor(255, 255, 255);
  1074. $pdf->SetXY($col1x, $tab2_top + 0);
  1075. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalHT").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalHT") : ''), 0, 'L', 1);
  1076. $total_ht = ((!empty($conf->multicurrency->enabled) && isset($object->multicurrency_tx) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ht : $object->total_ht);
  1077. $pdf->SetXY($col2x, $tab2_top + 0);
  1078. $pdf->MultiCell($largcol2, $tab2_hl, price($total_ht + (!empty($object->remise) ? $object->remise : 0), 0, $outputlangs), 0, 'R', 1);
  1079. // Show VAT by rates and total
  1080. $pdf->SetFillColor(248, 248, 248);
  1081. $total_ttc = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $object->multicurrency_total_ttc : $object->total_ttc;
  1082. $this->atleastoneratenotnull = 0;
  1083. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) {
  1084. $tvaisnull = ((!empty($this->tva) && count($this->tva) == 1 && isset($this->tva['0.000']) && is_float($this->tva['0.000'])) ? true : false);
  1085. if (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_IFNULL) && $tvaisnull) {
  1086. // Nothing to do
  1087. } else {
  1088. //Local tax 1 before VAT
  1089. //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  1090. //{
  1091. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  1092. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  1093. continue;
  1094. }
  1095. foreach ($localtax_rate as $tvakey => $tvaval) {
  1096. if ($tvakey != 0) { // On affiche pas taux 0
  1097. //$this->atleastoneratenotnull++;
  1098. $index++;
  1099. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1100. $tvacompl = '';
  1101. if (preg_match('/\*/', $tvakey)) {
  1102. $tvakey = str_replace('*', '', $tvakey);
  1103. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1104. }
  1105. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  1106. $totalvat .= ' ';
  1107. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1108. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1109. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1110. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1111. }
  1112. }
  1113. }
  1114. //}
  1115. //Local tax 2 before VAT
  1116. //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1117. //{
  1118. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1119. if (in_array((string) $localtax_type, array('1', '3', '5'))) {
  1120. continue;
  1121. }
  1122. foreach ($localtax_rate as $tvakey => $tvaval) {
  1123. if ($tvakey != 0) { // On affiche pas taux 0
  1124. //$this->atleastoneratenotnull++;
  1125. $index++;
  1126. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1127. $tvacompl = '';
  1128. if (preg_match('/\*/', $tvakey)) {
  1129. $tvakey = str_replace('*', '', $tvakey);
  1130. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1131. }
  1132. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  1133. $totalvat .= ' ';
  1134. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1135. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1136. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1137. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1138. }
  1139. }
  1140. }
  1141. //}
  1142. // VAT
  1143. foreach ($this->tva as $tvakey => $tvaval) {
  1144. if ($tvakey != 0) { // On affiche pas taux 0
  1145. $this->atleastoneratenotnull++;
  1146. $index++;
  1147. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1148. $tvacompl = '';
  1149. if (preg_match('/\*/', $tvakey)) {
  1150. $tvakey = str_replace('*', '', $tvakey);
  1151. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1152. }
  1153. $totalvat = $outputlangs->transcountrynoentities("TotalVAT", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalVAT", $mysoc->country_code) : '');
  1154. $totalvat .= ' ';
  1155. $totalvat .= vatrate($tvakey, 1).$tvacompl;
  1156. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1157. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1158. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1159. }
  1160. }
  1161. //Local tax 1 after VAT
  1162. //if (! empty($conf->global->FACTURE_LOCAL_TAX1_OPTION) && $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on')
  1163. //{
  1164. foreach ($this->localtax1 as $localtax_type => $localtax_rate) {
  1165. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1166. continue;
  1167. }
  1168. foreach ($localtax_rate as $tvakey => $tvaval) {
  1169. if ($tvakey != 0) { // On affiche pas taux 0
  1170. //$this->atleastoneratenotnull++;
  1171. $index++;
  1172. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1173. $tvacompl = '';
  1174. if (preg_match('/\*/', $tvakey)) {
  1175. $tvakey = str_replace('*', '', $tvakey);
  1176. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1177. }
  1178. $totalvat = $outputlangs->transcountrynoentities("TotalLT1", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT1", $mysoc->country_code) : '');
  1179. $totalvat .= ' ';
  1180. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1181. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1182. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1183. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1184. }
  1185. }
  1186. }
  1187. //}
  1188. //Local tax 2 after VAT
  1189. //if (! empty($conf->global->FACTURE_LOCAL_TAX2_OPTION) && $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on')
  1190. //{
  1191. foreach ($this->localtax2 as $localtax_type => $localtax_rate) {
  1192. if (in_array((string) $localtax_type, array('2', '4', '6'))) {
  1193. continue;
  1194. }
  1195. foreach ($localtax_rate as $tvakey => $tvaval) {
  1196. // retrieve global local tax
  1197. if ($tvakey != 0) { // On affiche pas taux 0
  1198. //$this->atleastoneratenotnull++;
  1199. $index++;
  1200. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1201. $tvacompl = '';
  1202. if (preg_match('/\*/', $tvakey)) {
  1203. $tvakey = str_replace('*', '', $tvakey);
  1204. $tvacompl = " (".$outputlangs->transnoentities("NonPercuRecuperable").")";
  1205. }
  1206. $totalvat = $outputlangs->transcountrynoentities("TotalLT2", $mysoc->country_code).(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transcountrynoentities("TotalLT2", $mysoc->country_code) : '');
  1207. $totalvat .= ' ';
  1208. $totalvat .= vatrate(abs($tvakey), 1).$tvacompl;
  1209. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $totalvat, 0, 'L', 1);
  1210. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1211. $pdf->MultiCell($largcol2, $tab2_hl, price($tvaval, 0, $outputlangs), 0, 'R', 1);
  1212. }
  1213. }
  1214. }
  1215. //}
  1216. // Total TTC
  1217. $index++;
  1218. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1219. $pdf->SetTextColor(0, 0, 60);
  1220. $pdf->SetFillColor(224, 224, 224);
  1221. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("TotalTTC").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("TotalTTC") : ''), $useborder, 'L', 1);
  1222. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1223. $pdf->MultiCell($largcol2, $tab2_hl, price($total_ttc, 0, $outputlangs), $useborder, 'R', 1);
  1224. }
  1225. }
  1226. $pdf->SetTextColor(0, 0, 0);
  1227. $resteapayer = 0;
  1228. /*
  1229. $resteapayer = $object->total_ttc - $deja_regle;
  1230. if (! empty($object->paye)) $resteapayer=0;
  1231. */
  1232. if ($deja_regle > 0) {
  1233. // Already paid + Deposits
  1234. $index++;
  1235. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1236. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("AlreadyPaid").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("AlreadyPaid") : ''), 0, 'L', 0);
  1237. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1238. $pdf->MultiCell($largcol2, $tab2_hl, price($deja_regle, 0, $outputlangs), 0, 'R', 0);
  1239. /*
  1240. if ($object->close_code == 'discount_vat')
  1241. {
  1242. $index++;
  1243. $pdf->SetFillColor(255,255,255);
  1244. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1245. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("EscompteOfferedShort"), $useborder, 'L', 1);
  1246. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1247. $pdf->MultiCell($largcol2, $tab2_hl, price($object->total_ttc - $deja_regle, 0, $outputlangs), $useborder, 'R', 1);
  1248. $resteapayer=0;
  1249. }
  1250. */
  1251. $index++;
  1252. $pdf->SetTextColor(0, 0, 60);
  1253. $pdf->SetFillColor(224, 224, 224);
  1254. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1255. $pdf->MultiCell($col2x - $col1x, $tab2_hl, $outputlangs->transnoentities("RemainderToPay").(is_object($outputlangsbis) ? ' / '.$outputlangsbis->transnoentities("RemainderToPay") : ''), $useborder, 'L', 1);
  1256. $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index);
  1257. $pdf->MultiCell($largcol2, $tab2_hl, price($resteapayer, 0, $outputlangs), $useborder, 'R', 1);
  1258. $pdf->SetFont('', '', $default_font_size - 1);
  1259. $pdf->SetTextColor(0, 0, 0);
  1260. }
  1261. // Added by MMI Mathieu Moulin iProspective
  1262. // @todo Hook
  1263. $acompte_p = (!empty($object->array_options['options_acompte']) && $object->array_options['options_acompte']>0) ?$object->array_options['options_acompte'] :0;
  1264. if (!$acompte_p)
  1265. $acompte_val = (!empty($object->array_options['options_acompte_val']) && $object->array_options['options_acompte_val']>0) ?round($object->array_options['options_acompte_val'], 2) :0;
  1266. if (!empty($object->array_options['options_acompte_aff']) && ($acompte_p || $acompte_val)) {
  1267. $index++;
  1268. $outputlangs->load('mmidocuments@mmidocuments');
  1269. if ($acompte_p)
  1270. $acompte_val = round($object->total_ttc*$acompte_p/100, 2);
  1271. $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index);
  1272. $pdf->SetFont('', 'B', $default_font_size - 1);
  1273. if ($acompte_p)
  1274. $pdf->MultiCell($col2x, $tab2_hl, $outputlangs->transnoentities('PaymentAcomptePourcent', str_replace('.', ',', $acompte_p).' %', price($acompte_val)), 0, 'L', 0);
  1275. else
  1276. $pdf->MultiCell($col2x, $tab2_hl, $outputlangs->transnoentities('PaymentAcompte', price($acompte_val)), 0, 'L', 0);
  1277. $posy = $pdf->GetY() + 1;
  1278. }
  1279. $index++;
  1280. return ($tab2_top + ($tab2_hl * $index));
  1281. }
  1282. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1283. /**
  1284. * Show table for lines
  1285. *
  1286. * @param TCPDF $pdf Object PDF
  1287. * @param string $tab_top Top position of table
  1288. * @param string $tab_height Height of table (rectangle)
  1289. * @param int $nexY Y (not used)
  1290. * @param Translate $outputlangs Langs object
  1291. * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
  1292. * @param int $hidebottom Hide bottom bar of array
  1293. * @param string $currency Currency code
  1294. * @param Translate $outputlangsbis Langs object bis
  1295. * @return void
  1296. */
  1297. protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
  1298. {
  1299. global $conf;
  1300. // Force to disable hidetop and hidebottom
  1301. $hidebottom = 0;
  1302. if ($hidetop) {
  1303. $hidetop = -1;
  1304. }
  1305. $currency = !empty($currency) ? $currency : $conf->currency;
  1306. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1307. // Amount in (at tab_top - 1)
  1308. $pdf->SetTextColor(0, 0, 0);
  1309. $pdf->SetFont('', '', $default_font_size - 2);
  1310. if (empty($hidetop)) {
  1311. $titre = $outputlangs->transnoentities("AmountInCurrency", $outputlangs->transnoentitiesnoconv("Currency".$currency));
  1312. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1313. $titre .= ' - '.$outputlangsbis->transnoentities("AmountInCurrency", $outputlangsbis->transnoentitiesnoconv("Currency".$currency));
  1314. }
  1315. $pdf->SetXY($this->page_largeur - $this->marge_droite - ($pdf->GetStringWidth($titre) + 3), $tab_top - 4);
  1316. $pdf->MultiCell(($pdf->GetStringWidth($titre) + 3), 2, $titre);
  1317. //$conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR='230,230,230';
  1318. if (!empty($conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR)) {
  1319. $pdf->Rect($this->marge_gauche, $tab_top, $this->page_largeur - $this->marge_droite - $this->marge_gauche, $this->tabTitleHeight, 'F', null, explode(',', $conf->global->MAIN_PDF_TITLE_BACKGROUND_COLOR));
  1320. }
  1321. }
  1322. $pdf->SetDrawColor(128, 128, 128);
  1323. $pdf->SetFont('', '', $default_font_size - 1);
  1324. // Output Rect
  1325. $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
  1326. $this->pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
  1327. if (empty($hidetop)) {
  1328. $pdf->line($this->marge_gauche, $tab_top + $this->tabTitleHeight, $this->page_largeur - $this->marge_droite, $tab_top + $this->tabTitleHeight); // line takes a position y in 2nd parameter and 4th parameter
  1329. }
  1330. }
  1331. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1332. /**
  1333. * Show top header of page.
  1334. *
  1335. * @param TCPDF $pdf Object PDF
  1336. * @param Propal $object Object to show
  1337. * @param int $showaddress 0=no, 1=yes
  1338. * @param Translate $outputlangs Object lang for output
  1339. * @param Translate $outputlangsbis Object lang for output bis
  1340. * @return void
  1341. */
  1342. protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
  1343. {
  1344. global $conf, $langs;
  1345. $ltrdirection = 'L';
  1346. if ($outputlangs->trans("DIRECTION") == 'rtl') $ltrdirection = 'R';
  1347. // Load traductions files required by page
  1348. $outputlangs->loadLangs(array("main", "propal", "companies", "bills"));
  1349. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1350. pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
  1351. $pdf->SetTextColor(0, 0, 60);
  1352. $pdf->SetFont('', 'B', $default_font_size + 3);
  1353. $w = 100;
  1354. $posy = $this->marge_haute;
  1355. $posx = $this->page_largeur - $this->marge_droite - $w;
  1356. $pdf->SetXY($this->marge_gauche, $posy);
  1357. // Logo
  1358. if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) {
  1359. if ($this->emetteur->logo) {
  1360. $logodir = $conf->mycompany->dir_output;
  1361. if (!empty($conf->mycompany->multidir_output[$object->entity])) {
  1362. $logodir = $conf->mycompany->multidir_output[$object->entity];
  1363. }
  1364. if (empty($conf->global->MAIN_PDF_USE_LARGE_LOGO)) {
  1365. $logo = $logodir.'/logos/thumbs/'.$this->emetteur->logo_small;
  1366. } else {
  1367. $logo = $logodir.'/logos/'.$this->emetteur->logo;
  1368. }
  1369. if (is_readable($logo)) {
  1370. $height = pdf_getHeightForLogo($logo);
  1371. $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto)
  1372. } else {
  1373. $pdf->SetTextColor(200, 0, 0);
  1374. $pdf->SetFont('', 'B', $default_font_size - 2);
  1375. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
  1376. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
  1377. }
  1378. } else {
  1379. $text = $this->emetteur->name;
  1380. $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, $ltrdirection);
  1381. }
  1382. }
  1383. $pdf->SetFont('', 'B', $default_font_size + 3);
  1384. $pdf->SetXY($posx, $posy);
  1385. $pdf->SetTextColor(0, 0, 60);
  1386. $title = $outputlangs->transnoentities("PdfCommercialProposalTitle");
  1387. $title .= ' '.$outputlangs->convToOutputCharset($object->ref);
  1388. if ($object->statut == $object::STATUS_DRAFT) {
  1389. $pdf->SetTextColor(128, 0, 0);
  1390. $title .= ' - '.$outputlangs->transnoentities("NotValidated");
  1391. }
  1392. $pdf->MultiCell($w, 4, $title, '', 'R');
  1393. $pdf->SetFont('', 'B', $default_font_size);
  1394. /*
  1395. $posy += 5;
  1396. $pdf->SetXY($posx, $posy);
  1397. $pdf->SetTextColor(0, 0, 60);
  1398. $textref = $outputlangs->transnoentities("Ref")." : ".$outputlangs->convToOutputCharset($object->ref);
  1399. if ($object->statut == $object::STATUS_DRAFT) {
  1400. $pdf->SetTextColor(128, 0, 0);
  1401. $textref .= ' - '.$outputlangs->transnoentities("NotValidated");
  1402. }
  1403. $pdf->MultiCell($w, 4, $textref, '', 'R');
  1404. */
  1405. $posy += 3;
  1406. $pdf->SetFont('', '', $default_font_size - 2);
  1407. if ($object->ref_client) {
  1408. $posy += 4;
  1409. $pdf->SetXY($posx, $posy);
  1410. $pdf->SetTextColor(0, 0, 60);
  1411. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer")." : ".dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65), '', 'R');
  1412. }
  1413. if (!empty($conf->global->PDF_SHOW_PROJECT_TITLE)) {
  1414. $object->fetch_projet();
  1415. if (!empty($object->project->ref)) {
  1416. $posy += 3;
  1417. $pdf->SetXY($posx, $posy);
  1418. $pdf->SetTextColor(0, 0, 60);
  1419. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Project")." : ".(empty($object->project->title) ? '' : $object->project->title), '', 'R');
  1420. }
  1421. }
  1422. if (!empty($conf->global->PDF_SHOW_PROJECT)) {
  1423. $object->fetch_projet();
  1424. if (!empty($object->project->ref)) {
  1425. $outputlangs->load("projects");
  1426. $posy += 3;
  1427. $pdf->SetXY($posx, $posy);
  1428. $pdf->SetTextColor(0, 0, 60);
  1429. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefProject")." : ".(empty($object->project->ref) ? '' : $object->project->ref), '', 'R');
  1430. }
  1431. }
  1432. if (!empty($conf->global->MAIN_PDF_DATE_TEXT)) {
  1433. $displaydate = "daytext";
  1434. } else {
  1435. $displaydate = "day";
  1436. }
  1437. $posy += 4;
  1438. $pdf->SetXY($posx, $posy);
  1439. $pdf->SetTextColor(0, 0, 60);
  1440. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("Date")." : ".dol_print_date($object->date, $displaydate, false, $outputlangs, true), '', 'R');
  1441. $posy += 4;
  1442. $pdf->SetXY($posx, $posy);
  1443. $pdf->SetTextColor(0, 0, 60);
  1444. $title = $outputlangs->transnoentities("DateEndPropal");
  1445. if (!empty($conf->global->PDF_USE_ALSO_LANGUAGE_CODE) && is_object($outputlangsbis)) {
  1446. $title .= ' - '.$outputlangsbis->transnoentities("DateEndPropal");
  1447. }
  1448. $pdf->MultiCell($w, 3, $title." : ".dol_print_date($object->fin_validite, $displaydate, false, $outputlangs, true), '', 'R');
  1449. if (empty($conf->global->MAIN_PDF_HIDE_CUSTOMER_CODE) && $object->thirdparty->code_client) {
  1450. $posy += 4;
  1451. $pdf->SetXY($posx, $posy);
  1452. $pdf->SetTextColor(0, 0, 60);
  1453. $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : ".$outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
  1454. }
  1455. // Get contact
  1456. if (!empty($conf->global->DOC_SHOW_FIRST_SALES_REP)) {
  1457. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1458. if (count($arrayidcontact) > 0) {
  1459. $usertmp = new User($this->db);
  1460. $usertmp->fetch($arrayidcontact[0]);
  1461. $posy += 4;
  1462. $pdf->SetXY($posx, $posy);
  1463. $pdf->SetTextColor(0, 0, 60);
  1464. $pdf->MultiCell($w, 3, $langs->transnoentities("SalesRepresentative")." : ".$usertmp->getFullName($langs), '', 'R');
  1465. }
  1466. }
  1467. $posy += 2;
  1468. $top_shift = 0;
  1469. // Show list of linked objects
  1470. $current_y = $pdf->getY();
  1471. $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
  1472. if ($current_y < $pdf->getY()) {
  1473. $top_shift = $pdf->getY() - $current_y;
  1474. }
  1475. if ($showaddress) {
  1476. // Sender properties
  1477. $carac_emetteur = '';
  1478. // Add internal contact of proposal if defined
  1479. $arrayidcontact = $object->getIdContact('internal', 'SALESREPFOLL');
  1480. if (count($arrayidcontact) > 0) {
  1481. $object->fetch_user($arrayidcontact[0]);
  1482. $labelbeforecontactname = ($outputlangs->transnoentities("FromContactName") != 'FromContactName' ? $outputlangs->transnoentities("FromContactName") : $outputlangs->transnoentities("Name"));
  1483. $carac_emetteur .= ($carac_emetteur ? "\n" : '').$labelbeforecontactname." ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n";
  1484. }
  1485. $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, '', 0, 'source', $object);
  1486. // Show sender
  1487. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1488. $posy += $top_shift;
  1489. $posx = $this->marge_gauche;
  1490. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1491. $posx = $this->page_largeur - $this->marge_droite - 80;
  1492. }
  1493. $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
  1494. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  1495. // Added by MMI Mathieu Moulin iProspective
  1496. // If CUSTOMER/SHIPPING contact defined, we use it
  1497. $useshippingcontact = false;
  1498. $arrayidcontact = $object->getIdContact('external', 'SHIPPING');
  1499. if (count($arrayidcontact) > 0) {
  1500. $useshippingcontact = true;
  1501. $result = $object->fetch_contact($arrayidcontact[0]);
  1502. }
  1503. // If CUSTOMER/BILLING contact defined, we use it
  1504. $usebillingcontact = false;
  1505. $arrayidcontact = $object->getIdContact('external', 'BILLING');
  1506. if (count($arrayidcontact) > 0) {
  1507. $usebillingcontact = true;
  1508. $result = $object->fetch_contact($arrayidcontact[0]);
  1509. }
  1510. if ($twocontacts = !empty($conf->global->MMI_DOCUMENT_PDF_SEPARATE_CONTACTS) && $useshippingcontact)
  1511. $widthrecbox = 60;
  1512. // Show sender frame
  1513. if (empty($conf->global->MAIN_PDF_NO_SENDER_FRAME)) {
  1514. $pdf->SetTextColor(0, 0, 0);
  1515. $pdf->SetFont('', '', $default_font_size - 2);
  1516. $pdf->SetXY($posx, $posy - 5);
  1517. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillFrom"), 0, $ltrdirection);
  1518. $pdf->SetXY($posx, $posy);
  1519. $pdf->SetFillColor(230, 230, 230);
  1520. $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
  1521. $pdf->SetTextColor(0, 0, 60);
  1522. }
  1523. // Show sender name
  1524. if (empty($conf->global->MAIN_PDF_HIDE_SENDER_NAME)) {
  1525. $pdf->SetXY($posx + 2, $posy + 3);
  1526. $pdf->SetFont('', 'B', $default_font_size);
  1527. $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
  1528. $posy = $pdf->getY();
  1529. }
  1530. // Show sender information
  1531. $pdf->SetXY($posx + 2, $posy);
  1532. $pdf->SetFont('', '', $default_font_size - 1);
  1533. $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
  1534. // Added by MMI Mathieu Moulin iProspective
  1535. // Adresses livraison & facturation
  1536. if ($twocontacts) {
  1537. // ---- RECIPIENT SHIPPING
  1538. // If CUSTOMER/SHIPPING contact defined, we use it
  1539. $usecontact = false;
  1540. $arrayidcontact = $object->getIdContact('external', 'SHIPPING');
  1541. if (count($arrayidcontact) > 0) {
  1542. $usecontact = true;
  1543. $result = $object->fetch_contact($arrayidcontact[0]);
  1544. }
  1545. // Recipient name
  1546. if ($usecontact && ($object->contact->socid == $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
  1547. $thirdparty = $object->contact;
  1548. } else {
  1549. $thirdparty = $object->thirdparty;
  1550. }
  1551. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  1552. $mode = 'target';
  1553. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
  1554. // Show recipient
  1555. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  1556. if ($this->page_largeur < 210) {
  1557. $widthrecbox = 84; // To work with US executive format
  1558. }
  1559. $widthrecbox = 60;
  1560. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1561. $posy += $top_shift;
  1562. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  1563. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1564. $posx = $this->marge_gauche;
  1565. }
  1566. // Show recipient frame
  1567. $pdf->SetTextColor(0, 0, 0);
  1568. $pdf->SetFont('', '', $default_font_size - 2);
  1569. $pdf->SetXY($posx + 2, $posy - 5);
  1570. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("DeliveryAddress"), 0, $ltrdirection);
  1571. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  1572. // Show recipient name
  1573. $pdf->SetXY($posx + 2, $posy + 3);
  1574. $pdf->SetFont('', 'B', $default_font_size);
  1575. $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
  1576. $posy = $pdf->getY();
  1577. // Show recipient information
  1578. $pdf->SetFont('', '', $default_font_size - 1);
  1579. $pdf->SetXY($posx + 2, $posy);
  1580. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
  1581. // ---- RECIPIENT INVOICE
  1582. // If CUSTOMER contact defined, we use it
  1583. $usecontact = false;
  1584. $arrayidcontact = $object->getIdContact('external', 'BILLING');
  1585. if (count($arrayidcontact) > 0) {
  1586. $usecontact = true;
  1587. $result = $object->fetch_contact($arrayidcontact[0]);
  1588. }
  1589. // Recipient name
  1590. if ($usecontact && ($object->contact->socid == $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
  1591. $thirdparty = $object->contact;
  1592. } else {
  1593. $thirdparty = $object->thirdparty;
  1594. }
  1595. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  1596. $mode = 'target';
  1597. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
  1598. // Show recipient
  1599. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
  1600. if ($this->page_largeur < 210) {
  1601. $widthrecbox = 84; // To work with US executive format
  1602. }
  1603. $widthrecbox = 60;
  1604. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1605. $posy += $top_shift;
  1606. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  1607. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1608. $posx = $this->marge_gauche;
  1609. }
  1610. $posx -= $widthrecbox +5;
  1611. // Show recipient frame
  1612. $pdf->SetTextColor(0, 0, 0);
  1613. $pdf->SetFont('', '', $default_font_size - 2);
  1614. $pdf->SetXY($posx + 2, $posy - 5);
  1615. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillAddress"), 0, $ltrdirection);
  1616. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  1617. // Show recipient name
  1618. $pdf->SetXY($posx + 2, $posy + 3);
  1619. $pdf->SetFont('', 'B', $default_font_size);
  1620. $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
  1621. $posy = $pdf->getY();
  1622. // Show recipient information
  1623. $pdf->SetFont('', '', $default_font_size - 1);
  1624. $pdf->SetXY($posx + 2, $posy);
  1625. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
  1626. }
  1627. // 1 seule adresse
  1628. else {
  1629. // If CUSTOMER contact defined, we use it
  1630. $usecontact = false;
  1631. $arrayidcontact = $object->getIdContact('external', 'CUSTOMER');
  1632. if (count($arrayidcontact) > 0) {
  1633. $usecontact = true;
  1634. $result = $object->fetch_contact($arrayidcontact[0]);
  1635. }
  1636. // Recipient name
  1637. if ($usecontact && ($object->contact->socid == $object->thirdparty->id && (!isset($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT) || !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)))) {
  1638. $thirdparty = $object->contact;
  1639. } else {
  1640. $thirdparty = $object->thirdparty;
  1641. }
  1642. $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
  1643. $mode = 'target';
  1644. $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : ''), $usecontact, $mode, $object);
  1645. // Show recipient
  1646. $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
  1647. if ($this->page_largeur < 210) {
  1648. $widthrecbox = 84; // To work with US executive format
  1649. }
  1650. $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
  1651. $posy += $top_shift;
  1652. $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
  1653. if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
  1654. $posx = $this->marge_gauche;
  1655. }
  1656. // Show recipient frame
  1657. if (empty($conf->global->MAIN_PDF_NO_RECIPENT_FRAME)) {
  1658. $pdf->SetTextColor(0, 0, 0);
  1659. $pdf->SetFont('', '', $default_font_size - 2);
  1660. $pdf->SetXY($posx + 2, $posy - 5);
  1661. $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo"), 0, $ltrdirection);
  1662. $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
  1663. }
  1664. // Show recipient name
  1665. $pdf->SetXY($posx + 2, $posy + 3);
  1666. $pdf->SetFont('', 'B', $default_font_size);
  1667. $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
  1668. $posy = $pdf->getY();
  1669. // Show recipient information
  1670. $pdf->SetFont('', '', $default_font_size - 1);
  1671. $pdf->SetXY($posx + 2, $posy);
  1672. $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
  1673. }
  1674. }
  1675. $pdf->SetTextColor(0, 0, 0);
  1676. return $top_shift;
  1677. }
  1678. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
  1679. /**
  1680. * Show footer of page. Need this->emetteur object
  1681. *
  1682. * @param TCPDF $pdf PDF
  1683. * @param Propal $object Object to show
  1684. * @param Translate $outputlangs Object lang for output
  1685. * @param int $hidefreetext 1=Hide free text
  1686. * @return int Return height of bottom margin including footer text
  1687. */
  1688. protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
  1689. {
  1690. global $conf;
  1691. $showdetails = empty($conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS) ? 0 : $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS;
  1692. return pdf_pagefoot($pdf, $outputlangs, 'PROPOSAL_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext, $this->page_largeur, $this->watermark);
  1693. }
  1694. /**
  1695. * Show area for the customer to sign
  1696. *
  1697. * @param TCPDF $pdf Object PDF
  1698. * @param Propal $object Object proposal
  1699. * @param int $posy Position depart
  1700. * @param Translate $outputlangs Objet langs
  1701. * @return int Position pour suite
  1702. */
  1703. protected function drawSignatureArea(&$pdf, $object, $posy, $outputlangs)
  1704. {
  1705. global $conf;
  1706. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1707. $tab_top = $posy + 4;
  1708. $tab_hl = 4;
  1709. $posx = 120;
  1710. $largcol = ($this->page_largeur - $this->marge_droite - $posx);
  1711. $useborder = 0;
  1712. $index = 0;
  1713. // Total HT
  1714. $pdf->SetFillColor(255, 255, 255);
  1715. $pdf->SetXY($posx, $tab_top + 0);
  1716. $pdf->SetFont('', '', $default_font_size - 2);
  1717. $pdf->MultiCell($largcol, $tab_hl, $outputlangs->transnoentities("ProposalCustomerSignature"), 0, 'L', 1);
  1718. $pdf->SetXY($posx, $tab_top + $tab_hl);
  1719. $pdf->MultiCell($largcol, $tab_hl * 3, '', 1, 'R');
  1720. if (!empty($conf->global->MAIN_PDF_PROPAL_USE_ELECTRONIC_SIGNING)) {
  1721. $pdf->addEmptySignatureAppearance($posx, $tab_top + $tab_hl, $largcol, $tab_hl * 3);
  1722. }
  1723. return $posy+($tab_hl * 7);
  1724. }
  1725. /**
  1726. * Added by MMI Mathieu Moulin iProspective
  1727. */
  1728. protected function textComplement(&$object, $outputlangs)
  1729. {
  1730. global $conf;
  1731. $outputlangs->load('mmidocuments@mmidocuments');
  1732. //var_dump($object); die();
  1733. //var_dump($object->array_options['options_cgv_cpv']); die();
  1734. $complement = [];
  1735. if (!empty($object->array_options['options_cgv_cpv'])) {
  1736. if (!empty($conf->global->MMIDOCUMENT_CGP_TITLE))
  1737. $complement[] = '<h3>'.$outputlangs->transnoentities("DocumentMoreInfoCGP")."</h3>";
  1738. $complement[] = $object->array_options['options_cgv_cpv'];
  1739. }
  1740. if (!empty($object->array_options['options_propal_decennale'])) {
  1741. if (!empty($conf->global->MMIPROJECT_DECENNALE_TITLE))
  1742. $complement[] = '<h3>'.$outputlangs->transnoentities("DocumentMoreInfoDecennale")."</h3>";
  1743. $complement[] = $conf->global->MMIPROJECT_DECENNALE_TEXT;
  1744. }
  1745. return !empty($complement) ?implode("\r\n", $complement) :'';
  1746. }
  1747. protected function heightComplement(&$pdf, $text, $default_font_size)
  1748. {
  1749. $pdf->SetFont('', '', $default_font_size - 2);
  1750. $useborder = 0;
  1751. $cellpadding = 0;
  1752. $reseth = false;
  1753. $autopadding = true;
  1754. $largcol = ($this->page_largeur - $this->marge_droite - $this->marge_gauche);
  1755. return $pdf->getStringHeight($largcol, strip_tags($text), $reseth, $autopadding, $cellpadding, $useborder);
  1756. }
  1757. protected function heightComplementArea(&$pdf, $text, $default_font_size)
  1758. {
  1759. $marg_top = 8;
  1760. $tab_titre = 4;
  1761. $tab_text = $this->heightComplement($pdf, $text, $default_font_size);
  1762. //var_dump($tab_text);
  1763. return $marg_top + $tab_titre + $tab_text;
  1764. }
  1765. protected function drawComplementArea(&$pdf, $text, $posy, $outputlangs)
  1766. {
  1767. global $conf;
  1768. $default_font_size = pdf_getPDFFontSize($outputlangs);
  1769. $marg_top = 8;
  1770. $tab_top = $posy + $marg_top;
  1771. $posx = $this->marge_gauche;
  1772. $largcol = ($this->page_largeur - $this->marge_droite - $posx);
  1773. $pdf->SetFillColor(255, 255, 255);
  1774. $pdf->SetFont('', '', $default_font_size - 2);
  1775. // Titre
  1776. if (!empty($conf->global->DOCUMENT_COMPLEMENT_TITLE)) {
  1777. $pdf->SetXY($posx, $tab_top);
  1778. $tab_titre = 4;
  1779. $pdf->WriteHTMLCell($largcol, $tab_titre, $posx, $posy+$marg_top, '<b>'.$outputlangs->transnoentities("DocumentMoreInfo").'</b>', 0);
  1780. }
  1781. // Texte
  1782. $pdf->SetXY($posx, $tab_top + $tab_titre);
  1783. $tab_text = $this->heightComplement($pdf, $text, $default_font_size);
  1784. //var_dump($tab_text); die();
  1785. $pdf->WriteHTMLCell($largcol, $tab_text, $posx,$tab_top+$tab_titre, $text, 1, 'L');
  1786. //var_dump($tab_top + $tab_titre + $tab_text); die();
  1787. return $tab_top + $tab_titre + $tab_text;
  1788. }
  1789. /**
  1790. * Define Array Column Field
  1791. *
  1792. * @param Propal $object object proposal
  1793. * @param Translate $outputlangs langs
  1794. * @param int $hidedetails Do not show line details
  1795. * @param int $hidedesc Do not show desc
  1796. * @param int $hideref Do not show ref
  1797. * @return null
  1798. */
  1799. public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
  1800. {
  1801. global $conf, $hookmanager;
  1802. // Default field style for content
  1803. $this->defaultContentsFieldsStyle = array(
  1804. 'align' => 'R', // R,C,L
  1805. 'padding' => array(1, 0.5, 1, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1806. );
  1807. // Default field style for content
  1808. $this->defaultTitlesFieldsStyle = array(
  1809. 'align' => 'C', // R,C,L
  1810. 'padding' => array(0.5, 0, 0.5, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1811. );
  1812. /*
  1813. * For exemple
  1814. $this->cols['theColKey'] = array(
  1815. 'rank' => $rank, // int : use for ordering columns
  1816. 'width' => 20, // the column width in mm
  1817. 'title' => array(
  1818. 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1819. 'label' => ' ', // the final label : used fore final generated text
  1820. 'align' => 'L', // text alignement : R,C,L
  1821. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1822. ),
  1823. 'content' => array(
  1824. 'align' => 'L', // text alignement : R,C,L
  1825. 'padding' => array(0.5,0.5,0.5,0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1826. ),
  1827. );
  1828. */
  1829. $rank = 0; // do not use negative rank
  1830. $this->cols['desc'] = array(
  1831. 'rank' => $rank,
  1832. 'width' => false, // only for desc
  1833. 'status' => true,
  1834. 'title' => array(
  1835. 'textkey' => 'Designation', // use lang key is usefull in somme case with module
  1836. 'align' => 'L',
  1837. // 'textkey' => 'yourLangKey', // if there is no label, yourLangKey will be translated to replace label
  1838. // 'label' => ' ', // the final label
  1839. 'padding' => array(0.5, 0.5, 0.5, 0.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1840. ),
  1841. 'content' => array(
  1842. 'align' => 'L',
  1843. 'padding' => array(1, 0.5, 1, 1.5), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1844. ),
  1845. );
  1846. // Image of product
  1847. $rank = $rank + 10;
  1848. $this->cols['photo'] = array(
  1849. 'rank' => $rank,
  1850. 'width' => (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH) ? 20 : $conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH), // in mm
  1851. 'status' => false,
  1852. 'title' => array(
  1853. 'textkey' => 'Photo',
  1854. 'label' => ' '
  1855. ),
  1856. 'content' => array(
  1857. 'padding' => array(0, 0, 0, 0), // Like css 0 => top , 1 => right, 2 => bottom, 3 => left
  1858. ),
  1859. 'border-left' => false, // remove left line separator
  1860. );
  1861. if (!empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE) && !empty($this->atleastonephoto)) {
  1862. $this->cols['photo']['status'] = true;
  1863. $this->cols['photo']['border-left'] = true;
  1864. }
  1865. $rank = $rank + 10;
  1866. $this->cols['vat'] = array(
  1867. 'rank' => $rank,
  1868. 'status' => false,
  1869. 'width' => 16, // in mm
  1870. 'title' => array(
  1871. 'textkey' => 'VAT'
  1872. ),
  1873. 'border-left' => true, // add left line separator
  1874. );
  1875. if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) && empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) {
  1876. $this->cols['vat']['status'] = true;
  1877. }
  1878. $rank = $rank + 10;
  1879. $this->cols['subprice'] = array(
  1880. 'rank' => $rank,
  1881. 'width' => 19, // in mm
  1882. 'status' => true,
  1883. 'title' => array(
  1884. 'textkey' => 'PriceUHT'
  1885. ),
  1886. 'border-left' => true, // add left line separator
  1887. );
  1888. // Adapt dynamically the width of subprice, if text is too long.
  1889. $tmpwidth = 0;
  1890. $nblines = count($object->lines);
  1891. for ($i = 0; $i < $nblines; $i++) {
  1892. $tmpwidth2 = dol_strlen(dol_string_nohtmltag(pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails)));
  1893. $tmpwidth = max($tmpwidth, $tmpwidth2);
  1894. }
  1895. if ($tmpwidth > 10) {
  1896. $this->cols['subprice']['width'] += (2 * ($tmpwidth - 10));
  1897. }
  1898. $rank = $rank + 10;
  1899. $this->cols['qty'] = array(
  1900. 'rank' => $rank,
  1901. 'width' => 16, // in mm
  1902. 'status' => true,
  1903. 'title' => array(
  1904. 'textkey' => 'Qty'
  1905. ),
  1906. 'border-left' => true, // add left line separator
  1907. );
  1908. $rank = $rank + 10;
  1909. $this->cols['unit'] = array(
  1910. 'rank' => $rank,
  1911. 'width' => 11, // in mm
  1912. 'status' => false,
  1913. 'title' => array(
  1914. 'textkey' => 'Unit'
  1915. ),
  1916. 'border-left' => true, // add left line separator
  1917. );
  1918. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  1919. $this->cols['unit']['status'] = true;
  1920. }
  1921. $rank = $rank + 10;
  1922. $this->cols['discount'] = array(
  1923. 'rank' => $rank,
  1924. 'width' => 13, // in mm
  1925. 'status' => false,
  1926. 'title' => array(
  1927. 'textkey' => 'ReductionShort'
  1928. ),
  1929. 'border-left' => true, // add left line separator
  1930. );
  1931. if ($this->atleastonediscount) {
  1932. $this->cols['discount']['status'] = true;
  1933. }
  1934. $rank = $rank + 1000; // add a big offset to be sure is the last col because default extrafield rank is 100
  1935. $this->cols['totalexcltax'] = array(
  1936. 'rank' => $rank,
  1937. 'width' => 26, // in mm
  1938. 'status' => empty($conf->global->PDF_PROPAL_HIDE_PRICE_EXCL_TAX) ? true : false,
  1939. 'title' => array(
  1940. 'textkey' => 'TotalHT'
  1941. ),
  1942. 'border-left' => true, // add left line separator
  1943. );
  1944. $rank = $rank + 1010; // add a big offset to be sure is the last col because default extrafield rank is 100
  1945. $this->cols['totalincltax'] = array(
  1946. 'rank' => $rank,
  1947. 'width' => 26, // in mm
  1948. 'status' => empty($conf->global->PDF_PROPAL_SHOW_PRICE_INCL_TAX) ? false : true,
  1949. 'title' => array(
  1950. 'textkey' => 'TotalTTC'
  1951. ),
  1952. 'border-left' => true, // add left line separator
  1953. );
  1954. // Add extrafields cols
  1955. if (!empty($object->lines)) {
  1956. $line = reset($object->lines);
  1957. $this->defineColumnExtrafield($line, $outputlangs, $hidedetails);
  1958. }
  1959. $parameters = array(
  1960. 'object' => $object,
  1961. 'outputlangs' => $outputlangs,
  1962. 'hidedetails' => $hidedetails,
  1963. 'hidedesc' => $hidedesc,
  1964. 'hideref' => $hideref
  1965. );
  1966. $reshook = $hookmanager->executeHooks('defineColumnField', $parameters, $this); // Note that $object may have been modified by hook
  1967. if ($reshook < 0) {
  1968. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  1969. } elseif (empty($reshook)) {
  1970. $this->cols = array_replace($this->cols, $hookmanager->resArray); // array_replace is used to preserve keys
  1971. } else {
  1972. $this->cols = $hookmanager->resArray;
  1973. }
  1974. }
  1975. }