dolibarr  7.0.0-beta
commondocgenerator.class.php
Go to the documentation of this file.
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 
34 abstract class CommonDocGenerator
35 {
36  var $error='';
37  protected $db;
38 
39 
45  public function __construct($db) {
46  $this->db = $db;
47  return 1;
48  }
49 
50 
58  function get_substitutionarray_user($user,$outputlangs)
59  {
60  global $conf;
61 
62  $logotouse=$conf->user->dir_output.'/'.get_exdir($user->id, 2, 0, 1, $user, 'user').'/'.$user->photo;
63 
64  return array(
65  'myuser_lastname'=>$user->lastname,
66  'myuser_firstname'=>$user->firstname,
67  'myuser_fullname'=>$user->getFullName($outputlangs,1),
68  'myuser_login'=>$user->login,
69  'myuser_phone'=>$user->office_phone,
70  'myuser_address'=>$user->address,
71  'myuser_zip'=>$user->zip,
72  'myuser_town'=>$user->town,
73  'myuser_country'=>$user->country,
74  'myuser_country_code'=>$user->country_code,
75  'myuser_state'=>$user->state,
76  'myuser_state_code'=>$user->state_code,
77  'myuser_fax'=>$user->office_fax,
78  'myuser_mobile'=>$user->user_mobile,
79  'myuser_email'=>$user->email,
80  'myuser_logo'=>$logotouse,
81  'myuser_job'=>$user->job,
82  'myuser_web'=>'' // url not exist in $user object
83  );
84  }
85 
86 
94  function get_substitutionarray_mysoc($mysoc,$outputlangs)
95  {
96  global $conf;
97 
98  if (empty($mysoc->forme_juridique) && ! empty($mysoc->forme_juridique_code))
99  {
100  $mysoc->forme_juridique=getFormeJuridiqueLabel($mysoc->forme_juridique_code);
101  }
102  if (empty($mysoc->country) && ! empty($mysoc->country_code))
103  {
104  $mysoc->country=$outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code);
105  }
106  if (empty($mysoc->state) && ! empty($mysoc->state_code))
107  {
108  $mysoc->state=getState($mysoc->state_code,0);
109  }
110 
111  $logotouse=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small;
112 
113  return array(
114  'mycompany_logo'=>$logotouse,
115  'mycompany_name'=>$mysoc->name,
116  'mycompany_email'=>$mysoc->email,
117  'mycompany_phone'=>$mysoc->phone,
118  'mycompany_fax'=>$mysoc->fax,
119  'mycompany_address'=>$mysoc->address,
120  'mycompany_zip'=>$mysoc->zip,
121  'mycompany_town'=>$mysoc->town,
122  'mycompany_country'=>$mysoc->country,
123  'mycompany_country_code'=>$mysoc->country_code,
124  'mycompany_state'=>$mysoc->state,
125  'mycompany_state_code'=>$mysoc->state_code,
126  'mycompany_web'=>$mysoc->url,
127  'mycompany_juridicalstatus'=>$mysoc->forme_juridique,
128  'mycompany_managers'=>$mysoc->managers,
129  'mycompany_capital'=>$mysoc->capital,
130  'mycompany_barcode'=>$mysoc->barcode,
131  'mycompany_idprof1'=>$mysoc->idprof1,
132  'mycompany_idprof2'=>$mysoc->idprof2,
133  'mycompany_idprof3'=>$mysoc->idprof3,
134  'mycompany_idprof4'=>$mysoc->idprof4,
135  'mycompany_idprof5'=>$mysoc->idprof5,
136  'mycompany_idprof6'=>$mysoc->idprof6,
137  'mycompany_vatnumber'=>$mysoc->tva_intra,
138  'mycompany_object'=>$mysoc->object,
139  'mycompany_note_private'=>$mysoc->note_private,
140  //'mycompany_note_public'=>$mysoc->note_public, // Only private not exists for "mysoc" but both for thirdparties
141  );
142  }
143 
144 
152  function get_substitutionarray_thirdparty($object,$outputlangs)
153  {
154  global $conf;
155 
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 
165  $array_thirdparty = array(
166  'company_name'=>$object->name,
167  'company_name_alias' => $object->name_alias,
168  'company_email'=>$object->email,
169  'company_phone'=>$object->phone,
170  'company_fax'=>$object->fax,
171  'company_address'=>$object->address,
172  'company_zip'=>$object->zip,
173  'company_town'=>$object->town,
174  'company_country'=>$object->country,
175  'company_country_code'=>$object->country_code,
176  'company_state'=>$object->state,
177  'company_state_code'=>$object->state_code,
178  'company_web'=>$object->url,
179  'company_barcode'=>$object->barcode,
180  'company_vatnumber'=>$object->tva_intra,
181  'company_customercode'=>$object->code_client,
182  'company_suppliercode'=>$object->code_fournisseur,
183  'company_customeraccountancycode'=>$object->code_compta,
184  'company_supplieraccountancycode'=>$object->code_compta_fournisseur,
185  'company_juridicalstatus'=>$object->forme_juridique,
186  'company_outstanding_limit'=>$object->outstanding_limit,
187  'company_capital'=>$object->capital,
188  'company_idprof1'=>$object->idprof1,
189  'company_idprof2'=>$object->idprof2,
190  'company_idprof3'=>$object->idprof3,
191  'company_idprof4'=>$object->idprof4,
192  'company_idprof5'=>$object->idprof5,
193  'company_idprof6'=>$object->idprof6,
194  'company_note_public'=>$object->note_public,
195  'company_note_private'=>$object->note_private,
196  'company_default_bank_iban'=>$object->bank_account->iban,
197  'company_default_bank_bic'=>$object->bank_account->bic
198  );
199 
200  // Retrieve extrafields
201  if(is_array($object->array_options) && count($object->array_options))
202  {
203  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
204  $extrafields = new ExtraFields($this->db);
205  $extralabels = $extrafields->fetch_name_optionals_label('societe',true);
206  $object->fetch_optionals($object->id,$extralabels);
207 
208  foreach($extrafields->attribute_label as $key=>$label)
209  {
210  if($extrafields->attribute_type[$key] == 'price')
211  {
212  $object->array_options['options_'.$key] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency);
213  }
214  else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox')
215  {
216  $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]];
217  }
218  $array_thirdparty = array_merge($array_thirdparty, array ('company_options_'.$key => $object->array_options ['options_' . $key]));
219  }
220  }
221  return $array_thirdparty;
222  }
223 
232  function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object') {
233  global $conf;
234 
235  if(empty($object->country) && ! empty($object->country_code))
236  {
237  $object->country = $outputlangs->transnoentitiesnoconv("Country" . $object->country_code);
238  }
239  if(empty($object->state) && ! empty($object->state_code))
240  {
241  $object->state = getState($object->state_code, 0);
242  }
243 
244  $array_contact = array (
245  $array_key . '_fullname' => $object->getFullName($outputlangs, 1),
246  $array_key . '_lastname' => $object->lastname,
247  $array_key . '_firstname' => $object->firstname,
248  $array_key . '_address' => $object->address,
249  $array_key . '_zip' => $object->zip,
250  $array_key . '_town' => $object->town,
251  $array_key . '_state_id' => $object->state_id,
252  $array_key . '_state_code' => $object->state_code,
253  $array_key . '_state' => $object->state,
254  $array_key . '_country_id' => $object->country_id,
255  $array_key . '_country_code' => $object->country_code,
256  $array_key . '_country' => $object->country,
257  $array_key . '_poste' => $object->poste,
258  $array_key . '_socid' => $object->socid,
259  $array_key . '_statut' => $object->statut,
260  $array_key . '_code' => $object->code,
261  $array_key . '_email' => $object->email,
262  $array_key . '_jabberid' => $object->jabberid,
263  $array_key . '_phone_pro' => $object->phone_pro,
264  $array_key . '_phone_perso' => $object->phone_perso,
265  $array_key . '_phone_mobile' => $object->phone_mobile,
266  $array_key . '_fax' => $object->fax,
267  $array_key . '_birthday' => $object->birthday,
268  $array_key . '_default_lang' => $object->default_lang,
269  $array_key . '_note_public' => $object->note_public,
270  $array_key . '_note_private' => $object->note_private
271  );
272 
273  // Retrieve extrafields
274  require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
275  $extrafields = new ExtraFields($this->db);
276  $extralabels = $extrafields->fetch_name_optionals_label('socpeople', true);
277  $object->fetch_optionals($object->id, $extralabels);
278 
279  foreach($extrafields->attribute_label as $key => $label)
280  {
281  if ($extrafields->attribute_type[$key] == 'price')
282  {
283  $object->array_options['options_' . $key] = price($object->array_options ['options_' . $key], 0, $outputlangs, 0, 0, - 1, $conf->currency);
284  }
285  elseif($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox')
286  {
287  $object->array_options['options_' . $key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_' . $key]];
288  }
289  $array_contact = array_merge($array_contact, array($array_key.'_options_' . $key => $object->array_options['options_'. $key]));
290  }
291  return $array_contact;
292  }
293 
294 
301  function get_substitutionarray_other($outputlangs)
302  {
303  global $conf;
304 
305  $now=dol_now('gmt'); // gmt
306  $array_other = array(
307  // Date in default language
308  'current_date'=>dol_print_date($now,'day','tzuser'),
309  'current_datehour'=>dol_print_date($now,'dayhour','tzuser'),
310  'current_server_date'=>dol_print_date($now,'day','tzserver'),
311  'current_server_datehour'=>dol_print_date($now,'dayhour','tzserver'),
312  // Date in requested output language
313  'current_date_locale'=>dol_print_date($now,'day','tzuser',$outputlangs),
314  'current_datehour_locale'=>dol_print_date($now,'dayhour','tzuser',$outputlangs),
315  'current_server_date_locale'=>dol_print_date($now,'day','tzserver',$outputlangs),
316  'current_server_datehour_locale'=>dol_print_date($now,'dayhour','tzserver',$outputlangs),
317  );
318 
319  return $array_other;
320  }
321 
322 
331  function get_substitutionarray_object($object,$outputlangs,$array_key='object')
332  {
333  global $conf;
334 
335  $sumpayed=$sumdeposit=$sumcreditnote='';
336  if ($object->element == 'facture')
337  {
338  $invoice_source=new Facture($this->db);
339  if ($object->fk_facture_source > 0)
340  {
341  $invoice_source->fetch($object->fk_facture_source);
342  }
343  $sumpayed = $object->getSommePaiement();
344  $sumdeposit = $object->getSumDepositsUsed();
345  $sumcreditnote = $object->getSumCreditNotesUsed();
346  }
347 
348  $resarray=array(
349  $array_key.'_id'=>$object->id,
350  $array_key.'_ref'=>$object->ref,
351  $array_key.'_ref_ext'=>$object->ref_ext,
352  $array_key.'_ref_customer'=>$object->ref_client,
353  $array_key.'_ref_supplier'=>(! empty($object->ref_fournisseur)?$object->ref_fournisseur:''),
354  $array_key.'_source_invoice_ref'=>$invoice_source->ref,
355  // Dates
356  $array_key.'_hour'=>dol_print_date($object->date,'hour'),
357  $array_key.'_date'=>dol_print_date($object->date,'day'),
358  $array_key.'_date_rfc'=>dol_print_date($object->date,'dayrfc'),
359  $array_key.'_date_limit'=>(! empty($object->date_lim_reglement)?dol_print_date($object->date_lim_reglement,'day'):''),
360  $array_key.'_date_end'=>(! empty($object->fin_validite)?dol_print_date($object->fin_validite,'day'):''),
361  $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'),
362  $array_key.'_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''),
363  $array_key.'_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''),
364  $array_key.'_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''),
365  $array_key.'_date_close'=>(! empty($object->date_cloture)?dol_print_date($object->date_cloture,'dayhour'):''),
366 
367  $array_key.'_payment_mode_code'=>$object->mode_reglement_code,
368  $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),
369  $array_key.'_payment_term_code'=>$object->cond_reglement_code,
370  $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),
371 
372  $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs),
373  $array_key.'_total_vat_locale'=>(! empty($object->total_vat)?price($object->total_vat, 0, $outputlangs):price($object->total_tva, 0, $outputlangs)),
374  $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs),
375  $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs),
376  $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs),
377 
378  $array_key.'_total_ht'=>price2num($object->total_ht),
379  $array_key.'_total_vat'=>(! empty($object->total_vat)?price2num($object->total_vat):price2num($object->total_tva)),
380  $array_key.'_total_localtax1'=>price2num($object->total_localtax1),
381  $array_key.'_total_localtax2'=>price2num($object->total_localtax2),
382  $array_key.'_total_ttc'=>price2num($object->total_ttc),
383 
384  $array_key.'_multicurrency_code' => price2num($object->multicurrency_code),
385  $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx),
386  $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht),
387  $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva),
388  $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc),
389  $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs),
390  $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs),
391  $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs),
392 
393  $array_key.'_note_private'=>$object->note,
394  $array_key.'_note_public'=>$object->note_public,
395  $array_key.'_note'=>$object->note_public, // For backward compatibility
396 
397  // Payments
398  $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs),
399  $array_key.'_already_payed'=>price2num($sumpayed),
400  $array_key.'_already_deposit_locale'=>price($sumdeposit, 0, $outputlangs),
401  $array_key.'_already_deposit'=>price2num($sumdeposit),
402  $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs),
403  $array_key.'_already_creditnote'=>price2num($sumcreditnote),
404 
405  $array_key.'_already_payed_all_locale'=>price(price2num($sumpayed + $sumdeposit + $sumcreditnote, 'MT'), 0, $outputlangs),
406  $array_key.'_already_payed_all'=> price2num(($sumpayed + $sumdeposit + $sumcreditnote), 'MT'),
407 
408  // Remain to pay with all know infrmation (except open direct debit requests)
409  $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT'), 0, $outputlangs),
410  $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT')
411  );
412 
413  if (method_exists($object, 'getTotalDiscount')) {
414  $resarray[$array_key.'_total_discount_ht_locale'] = price($object->getTotalDiscount(), 0, $outputlangs);
415  $resarray[$array_key.'_total_discount_ht'] = price2num($object->getTotalDiscount());
416  } else {
417  $resarray[$array_key.'_total_discount_ht_locale'] = '';
418  $resarray[$array_key.'_total_discount_ht'] = '';
419  }
420 
421  // Fetch project information if there is a project assigned to this object
422  if ($object->element != "project" && ! empty($object->fk_project) && $object->fk_project > 0)
423  {
424  if (! is_object($object->project))
425  {
426  $object->fetch_projet();
427  }
428 
429  $resarray[$array_key.'_project_ref'] = $object->project->ref;
430  $resarray[$array_key.'_project_title'] = $object->project->title;
431  $resarray[$array_key.'_project_description'] = $object->project->description;
432  $resarray[$array_key.'_project_date_start'] = dol_print_date($object->project->date_start, 'day');
433  $resarray[$array_key.'_project_date_end'] = dol_print_date($object->project->date_end, 'day');
434  }
435 
436  // Add vat by rates
437  if (is_array($object->lines) && count($object->lines)>0)
438  {
439  foreach ($object->lines as $line)
440  {
441  // $line->tva_tx format depends on database field accuraty, no reliable. This is kept for backward comaptibility
442  if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) $resarray[$array_key.'_total_vat_'.$line->tva_tx]=0;
443  $resarray[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva;
444  $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx]=price($resarray[$array_key.'_total_vat_'.$line->tva_tx]);
445  // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example)
446  $vatformated=vatrate($line->tva_tx);
447  if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated]=0;
448  $resarray[$array_key.'_total_vat_'.$vatformated]+=$line->total_tva;
449  $resarray[$array_key.'_total_vat_locale_'.$vatformated]=price($resarray[$array_key.'_total_vat_'.$vatformated]);
450  }
451  }
452  // Retrieve extrafields
453  if (is_array($object->array_options) && count($object->array_options))
454  {
455  $extrafieldkey=$object->element;
456 
457  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
458  $extrafields = new ExtraFields($this->db);
459  $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true);
460  $object->fetch_optionals($object->id,$extralabels);
461 
462  $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs);
463  }
464  return $resarray;
465  }
466 
474  function get_substitutionarray_lines($line,$outputlangs)
475  {
476  global $conf;
477 
478  $resarray= array(
479  'line_fulldesc'=>doc_getlinedesc($line,$outputlangs),
480  'line_product_ref'=>$line->product_ref,
481  'line_product_label'=>$line->product_label,
482  'line_product_type'=>$line->product_type,
483  'line_desc'=>$line->desc,
484  'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
485  'line_up'=>price2num($line->subprice),
486  'line_up_locale'=>price($line->subprice, 0, $outputlangs),
487  'line_qty'=>$line->qty,
488  'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
489  'line_price_ht'=>price2num($line->total_ht),
490  'line_price_ttc'=>price2num($line->total_ttc),
491  'line_price_vat'=>price2num($line->total_tva),
492  'line_price_ht_locale'=>price($line->total_ht, 0, $outputlangs),
493  'line_price_ttc_locale'=>price($line->total_ttc, 0, $outputlangs),
494  'line_price_vat_locale'=>price($line->total_tva, 0, $outputlangs),
495  // Dates
496  'line_date_start'=>dol_print_date($line->date_start, 'day', 'tzuser'),
497  'line_date_start_locale'=>dol_print_date($line->date_start, 'day', 'tzuser', $outputlangs),
498  'line_date_start_rfc'=>dol_print_date($line->date_start, 'dayrfc', 'tzuser'),
499  'line_date_end'=>dol_print_date($line->date_end, 'day', 'tzuser'),
500  'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzuser', $outputlangs),
501  'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc', 'tzuser'),
502 
503  'line_multicurrency_code' => price2num($line->multicurrency_code),
504  'line_multicurrency_subprice' => price2num($line->multicurrency_subprice),
505  'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht),
506  'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva),
507  'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc),
508  'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs),
509  'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs),
510  'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs),
511  'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs),
512  );
513 
514  // Units
515  if ($conf->global->PRODUCT_USE_UNITS)
516  {
517  $resarray['line_unit']=$outputlangs->trans($line->getLabelOfUnit('long'));
518  $resarray['line_unit_short']=$outputlangs->trans($line->getLabelOfUnit('short'));
519  }
520 
521  // Retrieve extrafields
522  $extrafieldkey=$line->element;
523  $array_key="line";
524  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
525  $extrafields = new ExtraFields($this->db);
526  $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true);
527  $line->fetch_optionals($line->rowid,$extralabels);
528 
529  $resarray = $this->fill_substitutionarray_with_extrafields($line,$resarray,$extrafields,$array_key=$array_key,$outputlangs);
530 
531  return $resarray;
532  }
533 
542  function get_substitutionarray_shipment($object,$outputlangs,$array_key='object')
543  {
544  global $conf;
545  dol_include_once('/core/lib/product.lib.php');
546  $object->list_delivery_methods($object->shipping_method_id);
547  $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth);
548 
549  $array_shipment=array(
550  $array_key.'_id'=>$object->id,
551  $array_key.'_ref'=>$object->ref,
552  $array_key.'_ref_ext'=>$object->ref_ext,
553  $array_key.'_ref_customer'=>$object->ref_customer,
554  $array_key.'_date_delivery'=>dol_print_date($object->date_delivery,'day'),
555  $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery,'hour'),
556  $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'),
557  $array_key.'_total_ht'=>price($object->total_ht),
558  $array_key.'_total_vat'=>price($object->total_tva),
559  $array_key.'_total_ttc'=>price($object->total_ttc),
560  $array_key.'_total_discount_ht' => price($object->getTotalDiscount()),
561  $array_key.'_note_private'=>$object->note_private,
562  $array_key.'_note'=>$object->note_public,
563  $array_key.'_tracking_number'=>$object->tracking_number,
564  $array_key.'_tracking_url'=>$object->tracking_url,
565  $array_key.'_shipping_method'=>$object->listmeths[0]['libelle'],
566  $array_key.'_weight'=>$object->trueWeight.' '.measuring_units_string($object->weight_units, 'weight'),
567  $array_key.'_width'=>$object->trueWidth.' '.measuring_units_string($object->width_units, 'size'),
568  $array_key.'_height'=>$object->trueHeight.' '.measuring_units_string($object->height_units, 'size'),
569  $array_key.'_depth'=>$object->trueDepth.' '.measuring_units_string($object->depth_units, 'size'),
570  $array_key.'_size'=>$calculatedVolume.' '.measuring_units_string(0, 'volume'),
571  );
572 
573  // Add vat by rates
574  foreach ($object->lines as $line)
575  {
576  if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]=0;
577  $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva;
578  }
579 
580  // Retrieve extrafields
581  /*if(is_array($object->array_options) && count($object->array_options))
582  {
583  require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
584  $extrafields = new ExtraFields($this->db);
585  $extralabels = $extrafields->fetch_name_optionals_label('shipment',true);
586  $object->fetch_optionals($object->id,$extralabels);
587 
588  $array_shipment = $this->fill_substitutionarray_with_extrafields($object,$array_shipment,$extrafields,$array_key,$outputlangs);
589  }*/
590  return $array_shipment;
591  }
592 
593 
601  function get_substitutionarray_shipment_lines($line,$outputlangs)
602  {
603  global $conf;
604  dol_include_once('/core/lib/product.lib.php');
605 
606  return array(
607  'line_fulldesc'=>doc_getlinedesc($line,$outputlangs),
608  'line_product_ref'=>$line->product_ref,
609  'line_product_label'=>$line->product_label,
610  'line_desc'=>$line->desc,
611  'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits),
612  'line_up'=>price($line->subprice),
613  'line_qty'=>$line->qty,
614  'line_qty_shipped'=>$line->qty_shipped,
615  'line_qty_asked'=>$line->qty_asked,
616  'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
617  'line_price_ht'=>price($line->total_ht),
618  'line_price_ttc'=>price($line->total_ttc),
619  'line_price_vat'=>price($line->total_tva),
620  'line_weight'=>empty($line->weight) ? '' : $line->weight*$line->qty_shipped.' '.measuring_units_string($line->weight_units, 'weight'),
621  'line_length'=>empty($line->length) ? '' : $line->length*$line->qty_shipped.' '.measuring_units_string($line->length_units, 'size'),
622  'line_surface'=>empty($line->surface) ? '' : $line->surface*$line->qty_shipped.' '.measuring_units_string($line->surface_units, 'surface'),
623  'line_volume'=>empty($line->volume) ? '' : $line->volume*$line->qty_shipped.' '.measuring_units_string($line->volume_units, 'volume'),
624  );
625  }
626 
627 
636  function get_substitutionarray_each_var_object(&$object,$outputlangs,$recursive=true) {
637  $array_other = array();
638  if(!empty($object)) {
639  foreach($object as $key => $value) {
640  if(!empty($value)) {
641  if(!is_array($value) && !is_object($value)) {
642  $array_other['object_'.$key] = $value;
643  }
644  if(is_array($value) && $recursive){
645  $array_other['object_'.$key] = $this->get_substitutionarray_each_var_object($value,$outputlangs,false);
646  }
647  }
648  }
649  }
650  return $array_other;
651  }
652 
653 
664  function fill_substitutionarray_with_extrafields($object,$array_to_fill,$extrafields,$array_key,$outputlangs)
665  {
666  global $conf;
667  foreach($extrafields->attribute_label as $key=>$label)
668  {
669  if($extrafields->attribute_type[$key] == 'price')
670  {
671  $object->array_options['options_'.$key] = price2num($object->array_options['options_'.$key]);
672  $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency);
673  //Add value to store price with currency
674  $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency']));
675  }
676  else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox')
677  {
678  $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]];
679  }
680  else if($extrafields->attribute_type[$key] == 'date')
681  {
682  if (strlen($object->array_options['options_'.$key])>0)
683  {
684  $date = $object->array_options['options_'.$key];
685  $object->array_options['options_'.$key] = dol_print_date($date,'day'); // using company output language
686  $object->array_options['options_'.$key.'_locale'] = dol_print_date($date,'day','tzserver',$outputlangs); // using output language format
687  $object->array_options['options_'.$key.'_rfc'] = dol_print_date($date,'dayrfc'); // international format
688  }
689  else
690  {
691  $object->array_options['options_'.$key] = '';
692  $object->array_options['options_'.$key.'_locale'] = '';
693  $object->array_options['options_'.$key.'_rfc'] = '';
694  }
695  $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale']));
696  $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc']));
697  }
698  else if($extrafields->attribute_type[$key] == 'datetime')
699  {
700  $datetime = $object->array_options['options_'.$key];
701  $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
702  $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
703  $object->array_options['options_'.$key.'_rfc'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhourrfc'):''); // international format
704  $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale']));
705  $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc']));
706  }
707  $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key => $object->array_options['options_'.$key]));
708  }
709 
710  return $array_to_fill;
711 
712  }
713 
714 
727  function printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
728  {
729  if (empty($hidetop) || $hidetop==-1) $pdf->line($x, $y, $x+$l, $y);
730  $pdf->line($x+$l, $y, $x+$l, $y+$h);
731  if (empty($hidebottom)) $pdf->line($x+$l, $y+$h, $x, $y+$h);
732  $pdf->line($x, $y+$h, $x, $y);
733  }
734 }
735 
get_substitutionarray_shipment($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
getState($id, $withcode='', $dbtouse=0)
Return state translated from an id.
get_substitutionarray_lines($line, $outputlangs)
Define array with couple substitution key => substitution value.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart)
Return a path to have a the directory according to object where files are stored. ...
get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive=true)
Define array with couple subtitution key => subtitution value.
get_substitutionarray_object($object, $outputlangs, $array_key='object')
Define array with couple substitution key => substitution value.
__construct($db)
Constructor.
get_substitutionarray_user($user, $outputlangs)
Define array with couple subtitution key => subtitution value.
doc_getlinedesc($line, $outputlangs, $hideref=0, $hidedesc=0, $issupplierline=0)
Return line description translated in outputlangs and encoded into UTF8.
Definition: doc.lib.php:41
get_substitutionarray_shipment_lines($line, $outputlangs)
Define array with couple substitution key => substitution value.
Class to manage standard extra fields.
get_substitutionarray_contact($object, $outputlangs, $array_key= 'object')
Define array with couple subtitution key => subtitution value.
getFormeJuridiqueLabel($code)
Retourne le nom traduit de la forme juridique.
get_substitutionarray_mysoc($mysoc, $outputlangs)
Define array with couple subtitution key => subtitution value.
dol_now($mode='gmt')
Return date for now.
printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0)
Rect pdf.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
get_substitutionarray_thirdparty($object, $outputlangs)
Define array with couple subtitution key => subtitution value.
measuring_units_string($unit, $measuring_style='')
Return translation label of a unit key.
fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs)
Fill array with couple extrafield key => extrafield value.
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Return a prefix to use for this Dolibarr instance, for session/cookie names or email id...
Parent class for documents generators.
get_substitutionarray_other($outputlangs)
Define array with couple subtitution key => subtitution value.
Class to manage invoices.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...