commondocgenerator.class.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. <?php
  2. /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
  8. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. * or see http://www.gnu.org/
  23. */
  24. /**
  25. * \file htdocs/core/class/commondocgenerator.class.php
  26. * \ingroup core
  27. * \brief File of parent class for documents generators
  28. */
  29. /**
  30. * Parent class for documents generators
  31. */
  32. abstract class CommonDocGenerator
  33. {
  34. /**
  35. * @var string Error code (or message)
  36. */
  37. public $error='';
  38. /**
  39. * @var string[] Array of error strings
  40. */
  41. public $errors = array();
  42. /**
  43. * @var DoliDB Database handler.
  44. */
  45. protected $db;
  46. /**
  47. * Constructor
  48. *
  49. * @param DoliDB $db Database handler
  50. */
  51. public function __construct($db)
  52. {
  53. $this->db = $db;
  54. }
  55. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  56. /**
  57. * Define array with couple subtitution key => subtitution value
  58. *
  59. * @param User $user User
  60. * @param Translate $outputlangs Language object for output
  61. * @return array Array of substitution key->code
  62. */
  63. function get_substitutionarray_user($user,$outputlangs)
  64. {
  65. // phpcs:enable
  66. global $conf;
  67. $logotouse=$conf->user->dir_output.'/'.get_exdir($user->id, 2, 0, 1, $user, 'user').'/'.$user->photo;
  68. return array(
  69. 'myuser_lastname'=>$user->lastname,
  70. 'myuser_firstname'=>$user->firstname,
  71. 'myuser_fullname'=>$user->getFullName($outputlangs,1),
  72. 'myuser_login'=>$user->login,
  73. 'myuser_phone'=>$user->office_phone,
  74. 'myuser_address'=>$user->address,
  75. 'myuser_zip'=>$user->zip,
  76. 'myuser_town'=>$user->town,
  77. 'myuser_country'=>$user->country,
  78. 'myuser_country_code'=>$user->country_code,
  79. 'myuser_state'=>$user->state,
  80. 'myuser_state_code'=>$user->state_code,
  81. 'myuser_fax'=>$user->office_fax,
  82. 'myuser_mobile'=>$user->user_mobile,
  83. 'myuser_email'=>$user->email,
  84. 'myuser_logo'=>$logotouse,
  85. 'myuser_job'=>$user->job,
  86. 'myuser_web'=>'' // url not exist in $user object
  87. );
  88. }
  89. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  90. /**
  91. * Define array with couple subtitution key => subtitution value
  92. *
  93. * @param Societe $mysoc Object thirdparty
  94. * @param Translate $outputlangs Language object for output
  95. * @return array Array of substitution key->code
  96. */
  97. function get_substitutionarray_mysoc($mysoc,$outputlangs)
  98. {
  99. // phpcs:enable
  100. global $conf;
  101. if (empty($mysoc->forme_juridique) && ! empty($mysoc->forme_juridique_code))
  102. {
  103. $mysoc->forme_juridique=getFormeJuridiqueLabel($mysoc->forme_juridique_code);
  104. }
  105. if (empty($mysoc->country) && ! empty($mysoc->country_code))
  106. {
  107. $mysoc->country=$outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code);
  108. }
  109. if (empty($mysoc->state) && ! empty($mysoc->state_code))
  110. {
  111. $mysoc->state=getState($mysoc->state_code,0);
  112. }
  113. $logotouse=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
  114. return array(
  115. 'mycompany_logo'=>$logotouse,
  116. 'mycompany_name'=>$mysoc->name,
  117. 'mycompany_email'=>$mysoc->email,
  118. 'mycompany_phone'=>$mysoc->phone,
  119. 'mycompany_fax'=>$mysoc->fax,
  120. 'mycompany_address'=>$mysoc->address,
  121. 'mycompany_zip'=>$mysoc->zip,
  122. 'mycompany_town'=>$mysoc->town,
  123. 'mycompany_country'=>$mysoc->country,
  124. 'mycompany_country_code'=>$mysoc->country_code,
  125. 'mycompany_state'=>$mysoc->state,
  126. 'mycompany_state_code'=>$mysoc->state_code,
  127. 'mycompany_web'=>$mysoc->url,
  128. 'mycompany_juridicalstatus'=>$mysoc->forme_juridique,
  129. 'mycompany_managers'=>$mysoc->managers,
  130. 'mycompany_capital'=>$mysoc->capital,
  131. 'mycompany_barcode'=>$mysoc->barcode,
  132. 'mycompany_idprof1'=>$mysoc->idprof1,
  133. 'mycompany_idprof2'=>$mysoc->idprof2,
  134. 'mycompany_idprof3'=>$mysoc->idprof3,
  135. 'mycompany_idprof4'=>$mysoc->idprof4,
  136. 'mycompany_idprof5'=>$mysoc->idprof5,
  137. 'mycompany_idprof6'=>$mysoc->idprof6,
  138. 'mycompany_vatnumber'=>$mysoc->tva_intra,
  139. 'mycompany_object'=>$mysoc->object,
  140. 'mycompany_note_private'=>$mysoc->note_private,
  141. //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties
  142. );
  143. }
  144. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  145. /**
  146. * Define array with couple subtitution key => subtitution value
  147. *
  148. * @param Object $object Object
  149. * @param Translate $outputlangs Language object for output
  150. * @return array Array of substitution key->code
  151. */
  152. function get_substitutionarray_thirdparty($object,$outputlangs)
  153. {
  154. // phpcs:enable
  155. global $conf;
  156. if (empty($object->country) && ! empty($object->country_code))
  157. {
  158. $object->country=$outputlangs->transnoentitiesnoconv("Country".$object->country_code);
  159. }
  160. if (empty($object->state) && ! empty($object->state_code))
  161. {
  162. $object->state=getState($object->state_code,0);
  163. }
  164. $array_thirdparty = array(
  165. 'company_name'=>$object->name,
  166. 'company_name_alias' => $object->name_alias,
  167. 'company_email'=>$object->email,
  168. 'company_phone'=>$object->phone,
  169. 'company_fax'=>$object->fax,
  170. 'company_address'=>$object->address,
  171. 'company_zip'=>$object->zip,
  172. 'company_town'=>$object->town,
  173. 'company_country'=>$object->country,
  174. 'company_country_code'=>$object->country_code,
  175. 'company_state'=>$object->state,
  176. 'company_state_code'=>$object->state_code,
  177. 'company_web'=>$object->url,
  178. 'company_barcode'=>$object->barcode,
  179. 'company_vatnumber'=>$object->tva_intra,
  180. 'company_customercode'=>$object->code_client,
  181. 'company_suppliercode'=>$object->code_fournisseur,
  182. 'company_customeraccountancycode'=>$object->code_compta,
  183. 'company_supplieraccountancycode'=>$object->code_compta_fournisseur,
  184. 'company_juridicalstatus'=>$object->forme_juridique,
  185. 'company_outstanding_limit'=>$object->outstanding_limit,
  186. 'company_capital'=>$object->capital,
  187. 'company_idprof1'=>$object->idprof1,
  188. 'company_idprof2'=>$object->idprof2,
  189. 'company_idprof3'=>$object->idprof3,
  190. 'company_idprof4'=>$object->idprof4,
  191. 'company_idprof5'=>$object->idprof5,
  192. 'company_idprof6'=>$object->idprof6,
  193. 'company_note_public'=>$object->note_public,
  194. 'company_note_private'=>$object->note_private,
  195. 'company_default_bank_iban'=>$object->bank_account->iban,
  196. 'company_default_bank_bic'=>$object->bank_account->bic
  197. );
  198. // Retrieve extrafields
  199. if(is_array($object->array_options) && count($object->array_options))
  200. {
  201. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  202. $extrafields = new ExtraFields($this->db);
  203. $extralabels = $extrafields->fetch_name_optionals_label('societe',true);
  204. $object->fetch_optionals();
  205. foreach($extrafields->attribute_label as $key=>$label)
  206. {
  207. if($extrafields->attribute_type[$key] == 'price')
  208. {
  209. $object->array_options['options_'.$key] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency);
  210. }
  211. else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox')
  212. {
  213. $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]];
  214. }
  215. $array_thirdparty = array_merge($array_thirdparty, array ('company_options_'.$key => $object->array_options ['options_' . $key]));
  216. }
  217. }
  218. return $array_thirdparty;
  219. }
  220. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  221. /**
  222. * Define array with couple subtitution key => subtitution value
  223. *
  224. * @param Contact $object contact
  225. * @param Translate $outputlangs object for output
  226. * @param array $array_key Name of the key for return array
  227. * @return array Array of substitution key->code
  228. */
  229. function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object')
  230. {
  231. // phpcs:enable
  232. global $conf;
  233. if(empty($object->country) && ! empty($object->country_code))
  234. {
  235. $object->country = $outputlangs->transnoentitiesnoconv("Country" . $object->country_code);
  236. }
  237. if(empty($object->state) && ! empty($object->state_code))
  238. {
  239. $object->state = getState($object->state_code, 0);
  240. }
  241. $array_contact = array (
  242. $array_key . '_fullname' => $object->getFullName($outputlangs, 1),
  243. $array_key . '_lastname' => $object->lastname,
  244. $array_key . '_firstname' => $object->firstname,
  245. $array_key . '_address' => $object->address,
  246. $array_key . '_zip' => $object->zip,
  247. $array_key . '_town' => $object->town,
  248. $array_key . '_state_id' => $object->state_id,
  249. $array_key . '_state_code' => $object->state_code,
  250. $array_key . '_state' => $object->state,
  251. $array_key . '_country_id' => $object->country_id,
  252. $array_key . '_country_code' => $object->country_code,
  253. $array_key . '_country' => $object->country,
  254. $array_key . '_poste' => $object->poste,
  255. $array_key . '_socid' => $object->socid,
  256. $array_key . '_statut' => $object->statut,
  257. $array_key . '_code' => $object->code,
  258. $array_key . '_email' => $object->email,
  259. $array_key . '_jabberid' => $object->jabberid,
  260. $array_key . '_phone_pro' => $object->phone_pro,
  261. $array_key . '_phone_perso' => $object->phone_perso,
  262. $array_key . '_phone_mobile' => $object->phone_mobile,
  263. $array_key . '_fax' => $object->fax,
  264. $array_key . '_birthday' => $object->birthday,
  265. $array_key . '_default_lang' => $object->default_lang,
  266. $array_key . '_note_public' => $object->note_public,
  267. $array_key . '_note_private' => $object->note_private
  268. );
  269. // Retrieve extrafields
  270. require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
  271. $extrafields = new ExtraFields($this->db);
  272. $extralabels = $extrafields->fetch_name_optionals_label('socpeople', true);
  273. $object->fetch_optionals();
  274. foreach($extrafields->attribute_label as $key => $label)
  275. {
  276. if ($extrafields->attribute_type[$key] == 'price')
  277. {
  278. $object->array_options['options_' . $key] = price($object->array_options ['options_' . $key], 0, $outputlangs, 0, 0, - 1, $conf->currency);
  279. }
  280. elseif($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox')
  281. {
  282. $object->array_options['options_' . $key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_' . $key]];
  283. }
  284. $array_contact = array_merge($array_contact, array($array_key.'_options_' . $key => $object->array_options['options_'. $key]));
  285. }
  286. return $array_contact;
  287. }
  288. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  289. /**
  290. * Define array with couple subtitution key => subtitution value
  291. *
  292. * @param Translate $outputlangs Language object for output
  293. * @return array Array of substitution key->code
  294. */
  295. function get_substitutionarray_other($outputlangs)
  296. {
  297. // phpcs:enable
  298. global $conf;
  299. $now=dol_now('gmt'); // gmt
  300. $array_other = array(
  301. // Date in default language
  302. 'current_date'=>dol_print_date($now,'day','tzuser'),
  303. 'current_datehour'=>dol_print_date($now,'dayhour','tzuser'),
  304. 'current_server_date'=>dol_print_date($now,'day','tzserver'),
  305. 'current_server_datehour'=>dol_print_date($now,'dayhour','tzserver'),
  306. // Date in requested output language
  307. 'current_date_locale'=>dol_print_date($now,'day','tzuser',$outputlangs),
  308. 'current_datehour_locale'=>dol_print_date($now,'dayhour','tzuser',$outputlangs),
  309. 'current_server_date_locale'=>dol_print_date($now,'day','tzserver',$outputlangs),
  310. 'current_server_datehour_locale'=>dol_print_date($now,'dayhour','tzserver',$outputlangs),
  311. );
  312. foreach($conf->global as $key => $val)
  313. {
  314. if (preg_match('/(_pass|password|secret|_key|key$)/i', $key)) $newval = '*****forbidden*****';
  315. else $newval = $val;
  316. $array_other['__['.$key.']__'] = $newval;
  317. }
  318. return $array_other;
  319. }
  320. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  321. /**
  322. * Define array with couple substitution key => substitution value
  323. *
  324. * @param Object $object Main object to use as data source
  325. * @param Translate $outputlangs Lang object to use for output
  326. * @param string $array_key Name of the key for return array
  327. * @return array Array of substitution
  328. */
  329. function get_substitutionarray_object($object,$outputlangs,$array_key='object')
  330. {
  331. // phpcs:enable
  332. global $conf;
  333. $sumpayed=$sumdeposit=$sumcreditnote='';
  334. if ($object->element == 'facture')
  335. {
  336. $invoice_source=new Facture($this->db);
  337. if ($object->fk_facture_source > 0)
  338. {
  339. $invoice_source->fetch($object->fk_facture_source);
  340. }
  341. $sumpayed = $object->getSommePaiement();
  342. $sumdeposit = $object->getSumDepositsUsed();
  343. $sumcreditnote = $object->getSumCreditNotesUsed();
  344. }
  345. $date = ($object->element == 'contrat' ? $object->date_contrat : $object->date);
  346. $resarray=array(
  347. $array_key.'_id'=>$object->id,
  348. $array_key.'_ref'=>$object->ref,
  349. $array_key.'_ref_ext'=>$object->ref_ext,
  350. $array_key.'_ref_customer'=>(! empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)),
  351. $array_key.'_ref_supplier'=>(! empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)),
  352. $array_key.'_source_invoice_ref'=>$invoice_source->ref,
  353. // Dates
  354. $array_key.'_hour'=>dol_print_date($date,'hour'),
  355. $array_key.'_date'=>dol_print_date($date,'day'),
  356. $array_key.'_date_rfc'=>dol_print_date($date,'dayrfc'),
  357. $array_key.'_date_limit'=>(! empty($object->date_lim_reglement)?dol_print_date($object->date_lim_reglement,'day'):''),
  358. $array_key.'_date_end'=>(! empty($object->fin_validite)?dol_print_date($object->fin_validite,'day'):''),
  359. $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'),
  360. $array_key.'_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''),
  361. $array_key.'_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''),
  362. $array_key.'_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''),
  363. $array_key.'_date_close'=>(! empty($object->date_cloture)?dol_print_date($object->date_cloture,'dayhour'):''),
  364. $array_key.'_payment_mode_code'=>$object->mode_reglement_code,
  365. $array_key.'_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement),
  366. $array_key.'_payment_term_code'=>$object->cond_reglement_code,
  367. $array_key.'_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):($object->cond_reglement_doc?$object->cond_reglement_doc:$object->cond_reglement)),
  368. $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs),
  369. $array_key.'_total_vat_locale'=>(! empty($object->total_vat)?price($object->total_vat, 0, $outputlangs):price($object->total_tva, 0, $outputlangs)),
  370. $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs),
  371. $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs),
  372. $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs),
  373. $array_key.'_total_ht'=>price2num($object->total_ht),
  374. $array_key.'_total_vat'=>(! empty($object->total_vat)?price2num($object->total_vat):price2num($object->total_tva)),
  375. $array_key.'_total_localtax1'=>price2num($object->total_localtax1),
  376. $array_key.'_total_localtax2'=>price2num($object->total_localtax2),
  377. $array_key.'_total_ttc'=>price2num($object->total_ttc),
  378. $array_key.'_multicurrency_code' => price2num($object->multicurrency_code),
  379. $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
  380. $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
  381. $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
  382. $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
  383. $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
  384. $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
  385. $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
  386. $array_key.'_note_private'=>$object->note,
  387. $array_key.'_note_public'=>$object->note_public,
  388. $array_key.'_note'=>$object->note_public, // For backward compatibility
  389. // Payments
  390. $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs),
  391. $array_key.'_already_payed'=>price2num($sumpayed),
  392. $array_key.'_already_deposit_locale'=>price($sumdeposit, 0, $outputlangs),
  393. $array_key.'_already_deposit'=>price2num($sumdeposit),
  394. $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs),
  395. $array_key.'_already_creditnote'=>price2num($sumcreditnote),
  396. $array_key.'_already_payed_all_locale'=>price(price2num($sumpayed + $sumdeposit + $sumcreditnote, 'MT'), 0, $outputlangs),
  397. $array_key.'_already_payed_all'=> price2num(($sumpayed + $sumdeposit + $sumcreditnote), 'MT'),
  398. // Remain to pay with all know infrmation (except open direct debit requests)
  399. $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT'), 0, $outputlangs),
  400. $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT')
  401. );
  402. if (method_exists($object, 'getTotalDiscount')) {
  403. $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
  404. $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
  405. } else {
  406. $resarray[$array_key.'_total_discount_ht_locale'] = '';
  407. $resarray[$array_key.'_total_discount_ht'] = '';
  408. }
  409. // Fetch project information if there is a project assigned to this object
  410. if ($object->element != "project" && ! empty($object->fk_project) && $object->fk_project > 0)
  411. {
  412. if (! is_object($object->project))
  413. {
  414. $object->fetch_projet();
  415. }
  416. $resarray[$array_key.'_project_ref'] = $object->project->ref;
  417. $resarray[$array_key.'_project_title'] = $object->project->title;
  418. $resarray[$array_key.'_project_description'] = $object->project->description;
  419. $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
  420. $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
  421. }
  422. // Add vat by rates
  423. if (is_array($object->lines) && count($object->lines)>0)
  424. {
  425. foreach ($object->lines as $line)
  426. {
  427. // $line->tva_tx format depends on database field accuraty, no reliable. This is kept for backward comaptibility
  428. if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) $resarray[$array_key.'_total_vat_'.$line->tva_tx]=0;
  429. $resarray[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva;
  430. $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx]=price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
  431. // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
  432. $vatformated=vatrate($line->tva_tx);
  433. if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated]=0;
  434. $resarray[$array_key.'_total_vat_'.$vatformated]+=$line->total_tva;
  435. $resarray[$array_key.'_total_vat_locale_'.$vatformated]=price($resarray[$array_key.'_total_vat_'.$vatformated]);
  436. }
  437. }
  438. // Retrieve extrafields
  439. if (is_array($object->array_options) && count($object->array_options))
  440. {
  441. $extrafieldkey=$object->element;
  442. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  443. $extrafields = new ExtraFields($this->db);
  444. $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true);
  445. $object->fetch_optionals();
  446. $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs);
  447. }
  448. return $resarray;
  449. }
  450. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  451. /**
  452. * Define array with couple substitution key => substitution value
  453. *
  454. * @param Object $line Object line
  455. * @param Translate $outputlangs Lang object to use for output
  456. * @return array Return a substitution array
  457. */
  458. function get_substitutionarray_lines($line, $outputlangs)
  459. {
  460. // phpcs:enable
  461. global $conf;
  462. $resarray= array(
  463. 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs),
  464. 'line_product_ref'=>$line->product_ref,
  465. 'line_product_ref_fourn'=>$line->ref_fourn, // for supplier doc lines
  466. 'line_product_label'=>$line->product_label,
  467. 'line_product_type'=>$line->product_type,
  468. 'line_desc'=>$line->desc,
  469. 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
  470. 'line_up'=>price2num($line->subprice),
  471. 'line_up_locale'=>price($line->subprice, 0, $outputlangs),
  472. 'line_qty'=>$line->qty,
  473. 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
  474. 'line_price_ht'=>price2num($line->total_ht),
  475. 'line_price_ttc'=>price2num($line->total_ttc),
  476. 'line_price_vat'=>price2num($line->total_tva),
  477. 'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs),
  478. 'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs),
  479. 'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs),
  480. // Dates
  481. 'line_date_start'=>dol_print_date($line->date_start, 'day', 'tzuser'),
  482. 'line_date_start_locale'=>dol_print_date($line->date_start, 'day', 'tzuser', $outputlangs),
  483. 'line_date_start_rfc'=>dol_print_date($line->date_start, 'dayrfc', 'tzuser'),
  484. 'line_date_end'=>dol_print_date($line->date_end, 'day', 'tzuser'),
  485. 'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzuser', $outputlangs),
  486. 'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc', 'tzuser'),
  487. 'line_multicurrency_code' => price2num($line->multicurrency_code),
  488. 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
  489. 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
  490. 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
  491. 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
  492. 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
  493. 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
  494. 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
  495. 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
  496. );
  497. // Units
  498. if ($conf->global->PRODUCT_USE_UNITS)
  499. {
  500. $resarray['line_unit']=$outputlangs->trans($line->getLabelOfUnit('long'));
  501. $resarray['line_unit_short']=$outputlangs->trans($line->getLabelOfUnit('short'));
  502. }
  503. // Retrieve extrafields
  504. $extrafieldkey=$line->element;
  505. $array_key="line";
  506. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  507. $extrafields = new ExtraFields($this->db);
  508. $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true);
  509. $line->fetch_optionals();
  510. $resarray = $this->fill_substitutionarray_with_extrafields($line,$resarray,$extrafields,$array_key=$array_key,$outputlangs);
  511. // Load product data optional fields to the line -> enables to use "line_options_{extrafield}"
  512. if (isset($line->fk_product) && $line->fk_product > 0)
  513. {
  514. $tmpproduct = new Product($this->db);
  515. $result = $tmpproduct->fetch($line->fk_product);
  516. foreach($tmpproduct->array_options as $key=>$label)
  517. $resarray["line_product_".$key] = $label;
  518. }
  519. return $resarray;
  520. }
  521. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  522. /**
  523. * Define array with couple substitution key => substitution value
  524. *
  525. * @param Expedition $object Main object to use as data source
  526. * @param Translate $outputlangs Lang object to use for output
  527. * @param array $array_key Name of the key for return array
  528. * @return array Array of substitution
  529. */
  530. function get_substitutionarray_shipment($object,$outputlangs,$array_key='object')
  531. {
  532. // phpcs:enable
  533. global $conf;
  534. dol_include_once('/core/lib/product.lib.php');
  535. $object->list_delivery_methods($object->shipping_method_id);
  536. $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth);
  537. $array_shipment=array(
  538. $array_key.'_id'=>$object->id,
  539. $array_key.'_ref'=>$object->ref,
  540. $array_key.'_ref_ext'=>$object->ref_ext,
  541. $array_key.'_ref_customer'=>$object->ref_customer,
  542. $array_key.'_date_delivery'=>dol_print_date($object->date_delivery,'day'),
  543. $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery,'hour'),
  544. $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'),
  545. $array_key.'_total_ht'=>price($object->total_ht),
  546. $array_key.'_total_vat'=>price($object->total_tva),
  547. $array_key.'_total_ttc'=>price($object->total_ttc),
  548. $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
  549. $array_key.'_note_private'=>$object->note_private,
  550. $array_key.'_note'=>$object->note_public,
  551. $array_key.'_tracking_number'=>$object->tracking_number,
  552. $array_key.'_tracking_url'=>$object->tracking_url,
  553. $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'],
  554. $array_key.'_weight'=>$object->trueWeight.' '.measuring_units_string($object->weight_units, 'weight'),
  555. $array_key.'_width'=>$object->trueWidth.' '.measuring_units_string($object->width_units, 'size'),
  556. $array_key.'_height'=>$object->trueHeight.' '.measuring_units_string($object->height_units, 'size'),
  557. $array_key.'_depth'=>$object->trueDepth.' '.measuring_units_string($object->depth_units, 'size'),
  558. $array_key.'_size'=>$calculatedVolume.' '.measuring_units_string(0, 'volume'),
  559. );
  560. // Add vat by rates
  561. foreach ($object->lines as $line)
  562. {
  563. if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]=0;
  564. $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva;
  565. }
  566. // Retrieve extrafields
  567. if (is_array($object->array_options) && count($object->array_options))
  568. {
  569. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  570. $extrafields = new ExtraFields($this->db);
  571. $extralabels = $extrafields->fetch_name_optionals_label('expedition',true);
  572. $object->fetch_optionals();
  573. $array_shipment = $this->fill_substitutionarray_with_extrafields($object,$array_shipment,$extrafields,$array_key,$outputlangs);
  574. }
  575. return $array_shipment;
  576. }
  577. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  578. /**
  579. * Define array with couple substitution key => substitution value
  580. *
  581. * @param ExpeditionLigne $line Object line
  582. * @param Translate $outputlangs Lang object to use for output
  583. * @return array Substitution array
  584. */
  585. function get_substitutionarray_shipment_lines($line, $outputlangs)
  586. {
  587. // phpcs:enable
  588. global $conf;
  589. dol_include_once('/core/lib/product.lib.php');
  590. $resarray = array(
  591. 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs),
  592. 'line_product_ref'=>$line->product_ref,
  593. 'line_product_label'=>$line->product_label,
  594. 'line_desc'=>$line->desc,
  595. 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
  596. 'line_up'=>price($line->subprice),
  597. 'line_qty'=>$line->qty,
  598. 'line_qty_shipped'=>$line->qty_shipped,
  599. 'line_qty_asked'=>$line->qty_asked,
  600. 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
  601. 'line_price_ht'=>price($line->total_ht),
  602. 'line_price_ttc'=>price($line->total_ttc),
  603. 'line_price_vat'=>price($line->total_tva),
  604. 'line_weight'=>empty($line->weight) ? '' : $line->weight*$line->qty_shipped.' '.measuring_units_string($line->weight_units, 'weight'),
  605. 'line_length'=>empty($line->length) ? '' : $line->length*$line->qty_shipped.' '.measuring_units_string($line->length_units, 'size'),
  606. 'line_surface'=>empty($line->surface) ? '' : $line->surface*$line->qty_shipped.' '.measuring_units_string($line->surface_units, 'surface'),
  607. 'line_volume'=>empty($line->volume) ? '' : $line->volume*$line->qty_shipped.' '.measuring_units_string($line->volume_units, 'volume'),
  608. );
  609. // Retrieve extrafields
  610. $extrafieldkey = $line->element;
  611. $array_key = "line";
  612. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  613. $extrafields = new ExtraFields($this->db);
  614. $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey, true);
  615. $line->fetch_optionals();
  616. $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key, $outputlangs);
  617. return $resarray;
  618. }
  619. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  620. /**
  621. * Define array with couple subtitution key => subtitution value
  622. *
  623. * @param Object $object Dolibarr Object
  624. * @param Translate $outputlangs Language object for output
  625. * @param boolean $recursive Want to fetch child array or child object
  626. * @return array Array of substitution key->code
  627. */
  628. function get_substitutionarray_each_var_object(&$object,$outputlangs,$recursive=true)
  629. {
  630. // phpcs:enable
  631. $array_other = array();
  632. if (!empty($object)) {
  633. foreach($object as $key => $value) {
  634. if (!empty($value)) {
  635. if (!is_array($value) && !is_object($value)) {
  636. $array_other['object_'.$key] = $value;
  637. }
  638. if (is_array($value) && $recursive) {
  639. $array_other['object_'.$key] = $this->get_substitutionarray_each_var_object($value,$outputlangs,false);
  640. }
  641. }
  642. }
  643. }
  644. return $array_other;
  645. }
  646. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  647. /**
  648. * Fill array with couple extrafield key => extrafield value
  649. *
  650. * @param Object $object Object with extrafields (must have $object->array_options filled)
  651. * @param array $array_to_fill Substitution array
  652. * @param Extrafields $extrafields Extrafields object
  653. * @param string $array_key Prefix for name of the keys into returned array
  654. * @param Translate $outputlangs Lang object to use for output
  655. * @return array Substitution array
  656. */
  657. function fill_substitutionarray_with_extrafields($object,$array_to_fill,$extrafields,$array_key,$outputlangs)
  658. {
  659. // phpcs:enable
  660. global $conf;
  661. foreach($extrafields->attribute_label as $key=>$label)
  662. {
  663. if($extrafields->attribute_type[$key] == 'price')
  664. {
  665. $object->array_options['options_'.$key] = price2num($object->array_options['options_'.$key]);
  666. $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency);
  667. //Add value to store price with currency
  668. $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency']));
  669. }
  670. else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox')
  671. {
  672. $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]];
  673. }
  674. else if($extrafields->attribute_type[$key] == 'date')
  675. {
  676. if (strlen($object->array_options['options_'.$key])>0)
  677. {
  678. $date = $object->array_options['options_'.$key];
  679. $object->array_options['options_'.$key] = dol_print_date($date,'day'); // using company output language
  680. $object->array_options['options_'.$key.'_locale'] = dol_print_date($date,'day','tzserver',$outputlangs); // using output language format
  681. $object->array_options['options_'.$key.'_rfc'] = dol_print_date($date,'dayrfc'); // international format
  682. }
  683. else
  684. {
  685. $object->array_options['options_'.$key] = '';
  686. $object->array_options['options_'.$key.'_locale'] = '';
  687. $object->array_options['options_'.$key.'_rfc'] = '';
  688. }
  689. $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale']));
  690. $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc']));
  691. }
  692. else if($extrafields->attribute_type[$key] == 'datetime')
  693. {
  694. $datetime = $object->array_options['options_'.$key];
  695. $object->array_options['options_'.$key] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour'):''); // using company output language
  696. $object->array_options['options_'.$key.'_locale'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour','tzserver',$outputlangs):''); // using output language format
  697. $object->array_options['options_'.$key.'_rfc'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhourrfc'):''); // international format
  698. $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale']));
  699. $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc']));
  700. }
  701. else if($extrafields->attribute_type[$key] == 'link')
  702. {
  703. $id = $object->array_options['options_'.$key];
  704. if ($id != "")
  705. {
  706. $param = $extrafields->attribute_param[$key];
  707. $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath'
  708. $InfoFieldList = explode(":", $param_list[0]);
  709. $classname=$InfoFieldList[0];
  710. $classpath=$InfoFieldList[1];
  711. if (! empty($classpath))
  712. {
  713. dol_include_once($InfoFieldList[1]);
  714. if ($classname && class_exists($classname))
  715. {
  716. $tmpobject = new $classname($this->db);
  717. $tmpobject->fetch($id);
  718. // completely replace the id with the linked object name
  719. $object->array_options['options_'.$key] = $tmpobject->name;
  720. }
  721. }
  722. }
  723. }
  724. $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key => $object->array_options['options_'.$key]));
  725. }
  726. return $array_to_fill;
  727. }
  728. /**
  729. * Rect pdf
  730. *
  731. * @param TCPDF $pdf Object PDF
  732. * @param float $x Abscissa of first point
  733. * @param float $y Ordinate of first point
  734. * @param float $l ??
  735. * @param float $h ??
  736. * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
  737. * @param int $hidebottom Hide bottom
  738. * @return void
  739. */
  740. function printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
  741. {
  742. if (empty($hidetop) || $hidetop==-1) $pdf->line($x, $y, $x+$l, $y);
  743. $pdf->line($x+$l, $y, $x+$l, $y+$h);
  744. if (empty($hidebottom)) $pdf->line($x+$l, $y+$h, $x, $y+$h);
  745. $pdf->line($x, $y+$h, $x, $y);
  746. }
  747. /**
  748. * uasort callback function to Sort colums fields
  749. *
  750. * @param array $a PDF lines array fields configs
  751. * @param array $b PDF lines array fields configs
  752. * @return int Return compare result
  753. */
  754. function columnSort($a, $b)
  755. {
  756. if(empty($a['rank'])){ $a['rank'] = 0; }
  757. if(empty($b['rank'])){ $b['rank'] = 0; }
  758. if ($a['rank'] == $b['rank']) {
  759. return 0;
  760. }
  761. return ($a['rank'] > $b['rank']) ? -1 : 1;
  762. }
  763. /**
  764. * Prepare Array Column Field
  765. *
  766. * @param object $object common object
  767. * @param Translate $outputlangs langs
  768. * @param int $hidedetails Do not show line details
  769. * @param int $hidedesc Do not show desc
  770. * @param int $hideref Do not show ref
  771. * @return null
  772. */
  773. function prepareArrayColumnField($object,$outputlangs,$hidedetails=0,$hidedesc=0,$hideref=0)
  774. {
  775. global $conf;
  776. $this->defineColumnField($object,$outputlangs,$hidedetails,$hidedesc,$hideref);
  777. // Sorting
  778. uasort ( $this->cols, array( $this, 'columnSort' ) );
  779. // Positionning
  780. $curX = $this->page_largeur-$this->marge_droite; // start from right
  781. // Array witdh
  782. $arrayWidth = $this->page_largeur-$this->marge_droite-$this->marge_gauche;
  783. // Count flexible column
  784. $totalDefinedColWidth = 0;
  785. $countFlexCol = 0;
  786. foreach ($this->cols as $colKey =>& $colDef)
  787. {
  788. if(!$this->getColumnStatus($colKey)) continue; // continue if desable
  789. if(!empty($colDef['scale'])){
  790. // In case of column widht is defined by percentage
  791. $colDef['width'] = abs($arrayWidth * $colDef['scale'] / 100 );
  792. }
  793. if(empty($colDef['width'])){
  794. $countFlexCol++;
  795. }
  796. else{
  797. $totalDefinedColWidth += $colDef['width'];
  798. }
  799. }
  800. foreach ($this->cols as $colKey =>& $colDef)
  801. {
  802. // setting empty conf with default
  803. if(!empty($colDef['title'])){
  804. $colDef['title'] = array_replace($this->defaultTitlesFieldsStyle, $colDef['title']);
  805. }
  806. else{
  807. $colDef['title'] = $this->defaultTitlesFieldsStyle;
  808. }
  809. // setting empty conf with default
  810. if(!empty($colDef['content'])){
  811. $colDef['content'] = array_replace($this->defaultContentsFieldsStyle, $colDef['content']);
  812. }
  813. else{
  814. $colDef['content'] = $this->defaultContentsFieldsStyle;
  815. }
  816. if($this->getColumnStatus($colKey))
  817. {
  818. // In case of flexible column
  819. if(empty($colDef['width'])){
  820. $colDef['width'] = abs(($arrayWidth - $totalDefinedColWidth)) / $countFlexCol;
  821. }
  822. // Set positions
  823. $lastX = $curX;
  824. $curX = $lastX - $colDef['width'];
  825. $colDef['xStartPos'] = $curX;
  826. $colDef['xEndPos'] = $lastX;
  827. }
  828. }
  829. }
  830. /**
  831. * get column content width from column key
  832. *
  833. * @param string $colKey the column key
  834. * @return float width in mm
  835. */
  836. function getColumnContentWidth($colKey)
  837. {
  838. $colDef = $this->cols[$colKey];
  839. return $colDef['width'] - $colDef['content']['padding'][3] - $colDef['content']['padding'][1];
  840. }
  841. /**
  842. * get column content X (abscissa) left position from column key
  843. *
  844. * @param string $colKey the column key
  845. * @return float X position in mm
  846. */
  847. function getColumnContentXStart($colKey)
  848. {
  849. $colDef = $this->cols[$colKey];
  850. return $colDef['xStartPos'] + $colDef['content']['padding'][3];
  851. }
  852. /**
  853. * get column position rank from column key
  854. *
  855. * @param string $colKey the column key
  856. * @return int rank on success and -1 on error
  857. */
  858. function getColumnRank($colKey)
  859. {
  860. if(!isset($this->cols[$colKey]['rank'])) return -1;
  861. return $this->cols[$colKey]['rank'];
  862. }
  863. /**
  864. * get column position rank from column key
  865. *
  866. * @param string $newColKey the new column key
  867. * @param array $defArray a single column definition array
  868. * @param string $targetCol target column used to place the new column beside
  869. * @param bool $insertAfterTarget insert before or after target column ?
  870. * @return int new rank on success and -1 on error
  871. */
  872. function insertNewColumnDef($newColKey, $defArray, $targetCol = false, $insertAfterTarget = false)
  873. {
  874. // prepare wanted rank
  875. $rank = -1;
  876. // try to get rank from target column
  877. if(!empty($targetCol)){
  878. $rank = $this->getColumnRank($targetCol);
  879. if($rank>=0 && $insertAfterTarget){ $rank++; }
  880. }
  881. // get rank from new column definition
  882. if($rank<0 && !empty($defArray['rank'])){
  883. $rank = $defArray['rank'];
  884. }
  885. // error: no rank
  886. if($rank<0){ return -1; }
  887. foreach ($this->cols as $colKey =>& $colDef)
  888. {
  889. if( $rank <= $colDef['rank'])
  890. {
  891. $colDef['rank'] = $colDef['rank'] + 1;
  892. }
  893. }
  894. $defArray['rank'] = $rank;
  895. $this->cols[$newColKey] = $defArray; // array_replace is used to preserve keys
  896. return $rank;
  897. }
  898. /**
  899. * print standard column content
  900. *
  901. * @param PDF $pdf pdf object
  902. * @param float $curY curent Y position
  903. * @param string $colKey the column key
  904. * @param string $columnText column text
  905. * @return int new rank on success and -1 on error
  906. */
  907. function printStdColumnContent($pdf, &$curY, $colKey, $columnText = '')
  908. {
  909. global $hookmanager;
  910. $parameters=array(
  911. 'curY' => &$curY,
  912. 'columnText' => $columnText,
  913. 'colKey' => $colKey
  914. );
  915. $reshook=$hookmanager->executeHooks('printStdColumnContent',$parameters,$this); // Note that $action and $object may have been modified by hook
  916. if ($reshook < 0) setEventMessages($hookmanager->error,$hookmanager->errors,'errors');
  917. if (!$reshook)
  918. {
  919. if(empty($columnText)) return;
  920. $pdf->SetXY($this->getColumnContentXStart($colKey),$curY); // Set curent position
  921. $colDef = $this->cols[$colKey];
  922. $pdf->MultiCell( $this->getColumnContentWidth($colKey),2, $columnText,'',$colDef['content']['align']);
  923. }
  924. }
  925. /**
  926. * get column status from column key
  927. *
  928. * @param string $colKey the column key
  929. * @return float width in mm
  930. */
  931. function getColumnStatus($colKey)
  932. {
  933. if( !empty($this->cols[$colKey]['status'])){
  934. return true;
  935. }
  936. else return false;
  937. }
  938. }