commondocgenerator.class.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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@capnetworks.com>
  6. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. * or see http://www.gnu.org/
  22. */
  23. /**
  24. * \file htdocs/core/class/commondocgenerator.class.php
  25. * \ingroup core
  26. * \brief File of parent class for documents generators
  27. */
  28. /**
  29. * Parent class for documents generators
  30. */
  31. abstract class CommonDocGenerator
  32. {
  33. var $error='';
  34. protected $db;
  35. /**
  36. * Constructor
  37. *
  38. * @param DoliDB $db Database handler
  39. */
  40. public function __construct($db) {
  41. $this->db = $db;
  42. return 1;
  43. }
  44. /**
  45. * Define array with couple subtitution key => subtitution value
  46. *
  47. * @param User $user User
  48. * @param Translate $outputlangs Language object for output
  49. * @return array Array of substitution key->code
  50. */
  51. function get_substitutionarray_user($user,$outputlangs)
  52. {
  53. global $conf;
  54. return array(
  55. 'myuser_lastname'=>$user->lastname,
  56. 'myuser_firstname'=>$user->firstname,
  57. 'myuser_fullname'=>$user->getFullName($outputlangs,1),
  58. 'myuser_login'=>$user->login,
  59. 'myuser_phone'=>$user->office_phone,
  60. 'myuser_address'=>$user->address,
  61. 'myuser_zip'=>$user->zip,
  62. 'myuser_town'=>$user->town,
  63. 'myuser_country'=>$user->country,
  64. 'myuser_country_code'=>$user->country_code,
  65. 'myuser_state'=>$user->state,
  66. 'myuser_state_code'=>$user->state_code,
  67. 'myuser_fax'=>$user->office_fax,
  68. 'myuser_mobile'=>$user->user_mobile,
  69. 'myuser_email'=>$user->email,
  70. 'myuser_logo'=>$user->photo,
  71. 'myuser_job'=>$user->job,
  72. 'myuser_web'=>'' // url not exist in $user object
  73. );
  74. }
  75. /**
  76. * Define array with couple subtitution key => subtitution value
  77. *
  78. * @param Societe $mysoc Object thirdparty
  79. * @param Translate $outputlangs Language object for output
  80. * @return array Array of substitution key->code
  81. */
  82. function get_substitutionarray_mysoc($mysoc,$outputlangs)
  83. {
  84. global $conf;
  85. if (empty($mysoc->forme_juridique) && ! empty($mysoc->forme_juridique_code))
  86. {
  87. $mysoc->forme_juridique=getFormeJuridiqueLabel($mysoc->forme_juridique_code);
  88. }
  89. if (empty($mysoc->country) && ! empty($mysoc->country_code))
  90. {
  91. $mysoc->country=$outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code);
  92. }
  93. if (empty($mysoc->state) && ! empty($mysoc->state_code))
  94. {
  95. $mysoc->state=getState($mysoc->state_code,0);
  96. }
  97. $logotouse=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
  98. return array(
  99. 'mycompany_logo'=>$logotouse,
  100. 'mycompany_name'=>$mysoc->name,
  101. 'mycompany_email'=>$mysoc->email,
  102. 'mycompany_phone'=>$mysoc->phone,
  103. 'mycompany_fax'=>$mysoc->fax,
  104. 'mycompany_address'=>$mysoc->address,
  105. 'mycompany_zip'=>$mysoc->zip,
  106. 'mycompany_town'=>$mysoc->town,
  107. 'mycompany_country'=>$mysoc->country,
  108. 'mycompany_country_code'=>$mysoc->country_code,
  109. 'mycompany_state'=>$mysoc->state,
  110. 'mycompany_state_code'=>$mysoc->state_code,
  111. 'mycompany_web'=>$mysoc->url,
  112. 'mycompany_juridicalstatus'=>$mysoc->forme_juridique,
  113. 'mycompany_managers'=>$mysoc->managers,
  114. 'mycompany_capital'=>$mysoc->capital,
  115. 'mycompany_barcode'=>$mysoc->barcode,
  116. 'mycompany_idprof1'=>$mysoc->idprof1,
  117. 'mycompany_idprof2'=>$mysoc->idprof2,
  118. 'mycompany_idprof3'=>$mysoc->idprof3,
  119. 'mycompany_idprof4'=>$mysoc->idprof4,
  120. 'mycompany_idprof5'=>$mysoc->idprof5,
  121. 'mycompany_idprof6'=>$mysoc->idprof6,
  122. 'mycompany_vatnumber'=>$mysoc->tva_intra,
  123. 'mycompany_object'=>$mysoc->object,
  124. 'mycompany_note_private'=>$mysoc->note_private,
  125. //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties
  126. );
  127. }
  128. /**
  129. * Define array with couple subtitution key => subtitution value
  130. *
  131. * @param Object $object Object
  132. * @param Translate $outputlangs Language object for output
  133. * @return array Array of substitution key->code
  134. */
  135. function get_substitutionarray_thirdparty($object,$outputlangs)
  136. {
  137. global $conf;
  138. if (empty($object->country) && ! empty($object->country_code))
  139. {
  140. $object->country=$outputlangs->transnoentitiesnoconv("Country".$object->country_code);
  141. }
  142. if (empty($object->state) && ! empty($object->state_code))
  143. {
  144. $object->state=getState($object->state_code,0);
  145. }
  146. $array_thirdparty = array(
  147. 'company_name'=>$object->name,
  148. 'company_name_alias' => $object->name_alias,
  149. 'company_email'=>$object->email,
  150. 'company_phone'=>$object->phone,
  151. 'company_fax'=>$object->fax,
  152. 'company_address'=>$object->address,
  153. 'company_zip'=>$object->zip,
  154. 'company_town'=>$object->town,
  155. 'company_country'=>$object->country,
  156. 'company_country_code'=>$object->country_code,
  157. 'company_state'=>$object->state,
  158. 'company_state_code'=>$object->state_code,
  159. 'company_web'=>$object->url,
  160. 'company_barcode'=>$object->barcode,
  161. 'company_vatnumber'=>$object->tva_intra,
  162. 'company_customercode'=>$object->code_client,
  163. 'company_suppliercode'=>$object->code_fournisseur,
  164. 'company_customeraccountancycode'=>$object->code_compta,
  165. 'company_supplieraccountancycode'=>$object->code_compta_fournisseur,
  166. 'company_juridicalstatus'=>$object->forme_juridique,
  167. 'company_outstanding_limit'=>$object->outstanding_limit,
  168. 'company_capital'=>$object->capital,
  169. 'company_idprof1'=>$object->idprof1,
  170. 'company_idprof2'=>$object->idprof2,
  171. 'company_idprof3'=>$object->idprof3,
  172. 'company_idprof4'=>$object->idprof4,
  173. 'company_idprof5'=>$object->idprof5,
  174. 'company_idprof6'=>$object->idprof6,
  175. 'company_note_public'=>$object->note_public,
  176. 'company_note_private'=>$object->note_private,
  177. 'company_default_bank_iban'=>$object->bank_account->iban,
  178. 'company_default_bank_bic'=>$object->bank_account->bic
  179. );
  180. // Retrieve extrafields
  181. if(is_array($object->array_options) && count($object->array_options))
  182. {
  183. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  184. $extrafields = new ExtraFields($this->db);
  185. $extralabels = $extrafields->fetch_name_optionals_label('societe',true);
  186. $object->fetch_optionals($object->id,$extralabels);
  187. foreach($extrafields->attribute_label as $key=>$label)
  188. {
  189. if($extrafields->attribute_type[$key] == 'price')
  190. {
  191. $object->array_options['options_'.$key] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency);
  192. }
  193. else if($extrafields->attribute_type[$key] == 'select')
  194. {
  195. $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]];
  196. }
  197. $array_thirdparty = array_merge($array_thirdparty, array ('company_options_'.$key => $object->array_options ['options_' . $key]));
  198. }
  199. }
  200. return $array_thirdparty;
  201. }
  202. /**
  203. * Define array with couple subtitution key => subtitution value
  204. *
  205. * @param Contact $object contact
  206. * @param Translate $outputlangs object for output
  207. * @param array_key $array_key Name of the key for return array
  208. * @return array of substitution key->code
  209. */
  210. function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object') {
  211. global $conf;
  212. if(empty($object->country) && ! empty($object->country_code))
  213. {
  214. $object->country = $outputlangs->transnoentitiesnoconv("Country" . $object->country_code);
  215. }
  216. if(empty($object->state) && ! empty($object->state_code))
  217. {
  218. $object->state = getState($object->state_code, 0);
  219. }
  220. $array_contact = array (
  221. $array_key . '_fullname' => $object->getFullName($outputlangs, 1),
  222. $array_key . '_lastname' => $object->lastname,
  223. $array_key . '_firstname' => $object->firstname,
  224. $array_key . '_address' => $object->address,
  225. $array_key . '_zip' => $object->zip,
  226. $array_key . '_town' => $object->town,
  227. $array_key . '_state_id' => $object->state_id,
  228. $array_key . '_state_code' => $object->state_code,
  229. $array_key . '_state' => $object->state,
  230. $array_key . '_country_id' => $object->country_id,
  231. $array_key . '_country_code' => $object->country_code,
  232. $array_key . '_country' => $object->country,
  233. $array_key . '_poste' => $object->poste,
  234. $array_key . '_socid' => $object->socid,
  235. $array_key . '_statut' => $object->statut,
  236. $array_key . '_code' => $object->code,
  237. $array_key . '_email' => $object->email,
  238. $array_key . '_jabberid' => $object->jabberid,
  239. $array_key . '_phone_pro' => $object->phone_pro,
  240. $array_key . '_phone_perso' => $object->phone_perso,
  241. $array_key . '_phone_mobile' => $object->phone_mobile,
  242. $array_key . '_fax' => $object->fax,
  243. $array_key . '_birthday' => $object->birthday,
  244. $array_key . '_default_lang' => $object->default_lang,
  245. $array_key . '_note_public' => $object->note_public,
  246. $array_key . '_note_private' => $object->note_private
  247. );
  248. // Retrieve extrafields
  249. require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
  250. $extrafields = new ExtraFields($this->db);
  251. $extralabels = $extrafields->fetch_name_optionals_label('socpeople', true);
  252. $object->fetch_optionals($object->id, $extralabels);
  253. foreach($extrafields->attribute_label as $key => $label)
  254. {
  255. if ($extrafields->attribute_type[$key] == 'price')
  256. {
  257. $object->array_options['options_' . $key] = price($object->array_options ['options_' . $key], 0, $outputlangs, 0, 0, - 1, $conf->currency);
  258. }
  259. elseif($extrafields->attribute_type[$key] == 'select')
  260. {
  261. $object->array_options['options_' . $key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_' . $key]];
  262. }
  263. $array_contact = array_merge($array_contact, array($array_key.'_options_' . $key => $object->array_options['options_'. $key]));
  264. }
  265. return $array_contact;
  266. }
  267. /**
  268. * Define array with couple subtitution key => subtitution value
  269. *
  270. * @param Translate $outputlangs Language object for output
  271. * @return array Array of substitution key->code
  272. */
  273. function get_substitutionarray_other($outputlangs)
  274. {
  275. global $conf;
  276. $now=dol_now('gmt'); // gmt
  277. $array_other = array(
  278. 'current_date'=>dol_print_date($now,'day','tzuser'),
  279. 'current_datehour'=>dol_print_date($now,'dayhour','tzuser'),
  280. 'current_server_date'=>dol_print_date($now,'day','tzserver'),
  281. 'current_server_datehour'=>dol_print_date($now,'dayhour','tzserver'),
  282. 'current_date_locale'=>dol_print_date($now,'day','tzuser',$outputlangs),
  283. 'current_datehour_locale'=>dol_print_date($now,'dayhour','tzuser',$outputlangs),
  284. 'current_server_date_locale'=>dol_print_date($now,'day','tzserver',$outputlangs),
  285. 'current_server_datehour_locale'=>dol_print_date($now,'dayhour','tzserver',$outputlangs),
  286. );
  287. return $array_other;
  288. }
  289. /**
  290. * Define array with couple substitution key => substitution value
  291. *
  292. * @param Object $object Main object to use as data source
  293. * @param Translate $outputlangs Lang object to use for output
  294. * @param string $array_key Name of the key for return array
  295. * @return array Array of substitution
  296. */
  297. function get_substitutionarray_object($object,$outputlangs,$array_key='object')
  298. {
  299. global $conf;
  300. $sumpayed=''; $alreadypayed='';
  301. if ($object->element == 'facture')
  302. {
  303. $invoice_source=new Facture($this->db);
  304. if ($object->fk_facture_source > 0)
  305. {
  306. $invoice_source->fetch($object->fk_facture_source);
  307. }
  308. $sumpayed = $object->getSommePaiement();
  309. $alreadypayed=price($sumpayed,0,$outputlangs);
  310. }
  311. $resarray=array(
  312. $array_key.'_id'=>$object->id,
  313. $array_key.'_ref'=>$object->ref,
  314. $array_key.'_ref_ext'=>$object->ref_ext,
  315. $array_key.'_ref_customer'=>$object->ref_client,
  316. $array_key.'_ref_supplier'=>(! empty($object->ref_fournisseur)?$object->ref_fournisseur:''),
  317. $array_key.'_source_invoice_ref'=>$invoice_source->ref,
  318. $array_key.'_hour'=>dol_print_date($object->date,'hour'),
  319. $array_key.'_date'=>dol_print_date($object->date,'day'),
  320. $array_key.'_date_rfc'=>dol_print_date($object->date,'dayrfc'),
  321. $array_key.'_date_limit'=>(! empty($object->date_lim_reglement)?dol_print_date($object->date_lim_reglement,'day'):''),
  322. $array_key.'_date_end'=>(! empty($object->fin_validite)?dol_print_date($object->fin_validite,'day'):''),
  323. $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'),
  324. $array_key.'_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''),
  325. $array_key.'_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''),
  326. $array_key.'_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''),
  327. $array_key.'_date_close'=>(! empty($object->date_cloture)?dol_print_date($object->date_cloture,'dayhour'):''),
  328. $array_key.'_payment_mode_code'=>$object->mode_reglement_code,
  329. $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),
  330. $array_key.'_payment_term_code'=>$object->cond_reglement_code,
  331. $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),
  332. $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs),
  333. $array_key.'_total_vat_locale'=>price($object->total_tva, 0, $outputlangs),
  334. $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs),
  335. $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs),
  336. $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs),
  337. $array_key.'_total_discount_ht_locale' => price($object->getTotalDiscount(), 0, $outputlangs),
  338. $array_key.'_total_ht'=>price2num($object->total_ht),
  339. $array_key.'_total_vat'=>price2num($object->total_tva),
  340. $array_key.'_total_localtax1'=>price2num($object->total_localtax1),
  341. $array_key.'_total_localtax2'=>price2num($object->total_localtax2),
  342. $array_key.'_total_ttc'=>price2num($object->total_ttc),
  343. $array_key.'_total_discount_ht' => price2num($object->getTotalDiscount()),
  344. $array_key.'_note_private'=>$object->note,
  345. $array_key.'_note_public'=>$object->note_public,
  346. $array_key.'_note'=>$object->note_public, // For backward compatibility
  347. // Payments
  348. $array_key.'_already_payed_locale'=>price($alreadypayed, 0, $outputlangs),
  349. $array_key.'_remain_to_pay_locale'=>price($object->total_ttc - $sumpayed, 0, $outputlangs),
  350. $array_key.'_already_payed'=>$alreadypayed,
  351. $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $sumpayed)
  352. );
  353. // Add vat by rates
  354. foreach ($object->lines as $line)
  355. {
  356. // $line->tva_tx format depends on database field accuraty, no reliable. This is kept for backward comaptibility
  357. if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) $resarray[$array_key.'_total_vat_'.$line->tva_tx]=0;
  358. $resarray[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva;
  359. $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx]=price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
  360. // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
  361. $vatformated=vatrate($line->tva_tx);
  362. if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated]=0;
  363. $resarray[$array_key.'_total_vat_'.$vatformated]+=$line->total_tva;
  364. $resarray[$array_key.'_total_vat_locale_'.$vatformated]=price($resarray[$array_key.'_total_vat_'.$vatformated]);
  365. }
  366. // Retrieve extrafields
  367. if (is_array($object->array_options) && count($object->array_options))
  368. {
  369. $extrafieldkey=$object->element;
  370. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  371. $extrafields = new ExtraFields($this->db);
  372. $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true);
  373. $object->fetch_optionals($object->id,$extralabels);
  374. $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs);
  375. }
  376. return $resarray;
  377. }
  378. /**
  379. * Define array with couple substitution key => substitution value
  380. *
  381. * @param array $line Array of lines
  382. * @param Translate $outputlangs Lang object to use for output
  383. * @return array Return a substitution array
  384. */
  385. function get_substitutionarray_lines($line,$outputlangs)
  386. {
  387. global $conf;
  388. $resarray= array(
  389. 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs),
  390. 'line_product_ref'=>$line->product_ref,
  391. 'line_product_label'=>$line->product_label,
  392. 'line_product_type'=>$line->product_type,
  393. 'line_desc'=>$line->desc,
  394. 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
  395. 'line_up'=>price2num($line->subprice),
  396. 'line_up_locale'=>price($line->subprice, 0, $outputlangs),
  397. 'line_qty'=>$line->qty,
  398. 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
  399. 'line_price_ht'=>price2num($line->total_ht),
  400. 'line_price_ttc'=>price2num($line->total_ttc),
  401. 'line_price_vat'=>price2num($line->total_tva),
  402. 'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs),
  403. 'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs),
  404. 'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs),
  405. 'line_date_start'=>$line->date_start,
  406. 'line_date_start_rfc'=>dol_print_date($line->date_start,'rfc'),
  407. 'line_date_end'=>$line->date_end,
  408. 'line_date_end_rfc'=>dol_print_date($line->date_end,'rfc')
  409. );
  410. // Retrieve extrafields
  411. $extrafieldkey=$line->element;
  412. $array_key="line";
  413. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  414. $extrafields = new ExtraFields($this->db);
  415. $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true);
  416. $line->fetch_optionals($line->rowid,$extralabels);
  417. $resarray = $this->fill_substitutionarray_with_extrafields($line,$resarray,$extrafields,$array_key=$array_key,$outputlangs);
  418. return $resarray;
  419. }
  420. /**
  421. * Define array with couple substitution key => substitution value
  422. *
  423. * @param Expedition $object Main object to use as data source
  424. * @param Translate $outputlangs Lang object to use for output
  425. * @param array_key $array_key Name of the key for return array
  426. * @return array Array of substitution
  427. */
  428. function get_substitutionarray_shipment($object,$outputlangs,$array_key='object')
  429. {
  430. global $conf;
  431. dol_include_once('/core/lib/product.lib.php');
  432. $object->list_delivery_methods($object->shipping_method_id);
  433. $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth);
  434. $array_shipment=array(
  435. $array_key.'_id'=>$object->id,
  436. $array_key.'_ref'=>$object->ref,
  437. $array_key.'_ref_ext'=>$object->ref_ext,
  438. $array_key.'_ref_customer'=>$object->ref_customer,
  439. $array_key.'_date_delivery'=>dol_print_date($object->date_delivery,'day'),
  440. $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery,'hour'),
  441. $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'),
  442. $array_key.'_total_ht'=>price($object->total_ht),
  443. $array_key.'_total_vat'=>price($object->total_tva),
  444. $array_key.'_total_ttc'=>price($object->total_ttc),
  445. $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
  446. $array_key.'_note_private'=>$object->note_private,
  447. $array_key.'_note'=>$object->note_public,
  448. $array_key.'_tracking_number'=>$object->tracking_number,
  449. $array_key.'_tracking_url'=>$object->tracking_url,
  450. $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'],
  451. $array_key.'_weight'=>$object->trueWeight.' '.measuring_units_string($object->weight_units, 'weight'),
  452. $array_key.'_width'=>$object->trueWidth.' '.measuring_units_string($object->width_units, 'size'),
  453. $array_key.'_height'=>$object->trueHeight.' '.measuring_units_string($object->height_units, 'size'),
  454. $array_key.'_depth'=>$object->trueDepth.' '.measuring_units_string($object->depth_units, 'size'),
  455. $array_key.'_size'=>$calculatedVolume.' '.measuring_units_string(0, 'volume'),
  456. );
  457. // Add vat by rates
  458. foreach ($object->lines as $line)
  459. {
  460. if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]=0;
  461. $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva;
  462. }
  463. // Retrieve extrafields
  464. /*if(is_array($object->array_options) && count($object->array_options))
  465. {
  466. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  467. $extrafields = new ExtraFields($this->db);
  468. $extralabels = $extrafields->fetch_name_optionals_label('shipment',true);
  469. $object->fetch_optionals($object->id,$extralabels);
  470. $array_shipment = $this->fill_substitutionarray_with_extrafields($object,$array_shipment,$extrafields,$array_key,$outputlangs);
  471. }*/
  472. return $array_shipment;
  473. }
  474. /**
  475. * Define array with couple substitution key => substitution value
  476. *
  477. * @param array $line Array of lines
  478. * @param Translate $outputlangs Lang object to use for output
  479. * @return array Substitution array
  480. */
  481. function get_substitutionarray_shipment_lines($line,$outputlangs)
  482. {
  483. global $conf;
  484. dol_include_once('/core/lib/product.lib.php');
  485. return array(
  486. 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs),
  487. 'line_product_ref'=>$line->product_ref,
  488. 'line_product_label'=>$line->product_label,
  489. 'line_desc'=>$line->desc,
  490. 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
  491. 'line_up'=>price($line->subprice),
  492. 'line_qty'=>$line->qty,
  493. 'line_qty_shipped'=>$line->qty_shipped,
  494. 'line_qty_asked'=>$line->qty_asked,
  495. 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
  496. 'line_price_ht'=>price($line->total_ht),
  497. 'line_price_ttc'=>price($line->total_ttc),
  498. 'line_price_vat'=>price($line->total_tva),
  499. 'line_weight'=>empty($line->weight) ? '' : $line->weight*$line->qty_shipped.' '.measuring_units_string($line->weight_units, 'weight'),
  500. 'line_length'=>empty($line->length) ? '' : $line->length*$line->qty_shipped.' '.measuring_units_string($line->length_units, 'size'),
  501. 'line_surface'=>empty($line->surface) ? '' : $line->surface*$line->qty_shipped.' '.measuring_units_string($line->surface_units, 'surface'),
  502. 'line_volume'=>empty($line->volume) ? '' : $line->volume*$line->qty_shipped.' '.measuring_units_string($line->volume_units, 'volume'),
  503. );
  504. }
  505. /**
  506. * Fill array with couple extrafield key => extrafield value
  507. *
  508. * @param Object $object Object with extrafields (must have $object->array_options filled)
  509. * @param array $array_to_fill Substitution array
  510. * @param Extrafields $extrafields Extrafields object
  511. * @param string $array_key Prefix for name of the keys into returned array
  512. * @param Translate $outputlangs Lang object to use for output
  513. * @return array Substitution array
  514. */
  515. function fill_substitutionarray_with_extrafields($object,$array_to_fill,$extrafields,$array_key,$outputlangs)
  516. {
  517. global $conf;
  518. foreach($extrafields->attribute_label as $key=>$label)
  519. {
  520. if($extrafields->attribute_type[$key] == 'price')
  521. {
  522. $object->array_options['options_'.$key] = price2num($object->array_options['options_'.$key]);
  523. $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency);
  524. //Add value to store price with currency
  525. $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency']));
  526. }
  527. else if($extrafields->attribute_type[$key] == 'select')
  528. {
  529. $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]];
  530. }
  531. else if($extrafields->attribute_type[$key] == 'date')
  532. {
  533. if (strlen($object->array_options['options_'.$key])>0)
  534. {
  535. $object->array_options['options_'.$key] = dol_print_date($object->array_options['options_'.$key],'day'); // using company output language
  536. $object->array_options['options_'.$key.'_locale'] = dol_print_date($object->array_options['options_'.$key],'day','tzserver',$outputlangs); // using output language format
  537. $object->array_options['options_'.$key.'_rfc'] = dol_print_date($object->array_options['options_'.$key],'dayrfc'); // international format
  538. }
  539. else
  540. {
  541. $object->array_options['options_'.$key] = '';
  542. $object->array_options['options_'.$key.'_locale'] = '';
  543. $object->array_options['options_'.$key.'_rfc'] = '';
  544. }
  545. }
  546. else if($extrafields->attribute_type[$key] == 'datetime')
  547. {
  548. $object->array_options['options_'.$key] = ($object->array_options['options_'.$key]!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour'):''); // using company output language
  549. $object->array_options['options_'.$key.'_locale'] = ($object->array_options['options_'.$key]!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour','tzserver',$outputlangs):''); // using output language format
  550. $object->array_options['options_'.$key.'_rfc'] = ($object->array_options['options_'.$key]!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhourrfc'):''); // international format
  551. }
  552. $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key => $object->array_options['options_'.$key]));
  553. }
  554. return $array_to_fill;
  555. }
  556. /**
  557. * Rect pdf
  558. *
  559. * @param PDF $pdf Object PDF
  560. * @param float $x Abscissa of first point
  561. * @param float $y Ordinate of first point
  562. * @param float $l ??
  563. * @param float $h ??
  564. * @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
  565. * @param int $hidebottom Hide bottom
  566. * @return void
  567. */
  568. function printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
  569. {
  570. if (empty($hidetop) || $hidetop==-1) $pdf->line($x, $y, $x+$l, $y);
  571. $pdf->line($x+$l, $y, $x+$l, $y+$h);
  572. if (empty($hidebottom)) $pdf->line($x+$l, $y+$h, $x, $y+$h);
  573. $pdf->line($x, $y+$h, $x, $y);
  574. }
  575. }