dolibarr  7.0.0-beta
doc.lib.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
4  * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
5  * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
6  * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
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 
41 function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0)
42 {
43  global $db, $conf, $langs;
44 
45  $idprod=$line->fk_product;
46  $label=(! empty($line->label)?$line->label:(! empty($line->libelle)?$line->libelle:''));
47  $desc=(! empty($line->desc)?$line->desc:(! empty($line->description)?$line->description:''));
48  $ref_supplier=(! empty($line->ref_supplier)?$line->ref_supplier:(! empty($line->ref_fourn)?$line->ref_fourn:'')); // TODO Not yet saved for supplier invoices, only supplier orders
49  $note=(! empty($line->note)?$line->note:'');
50 
51  if ($issupplierline) $prodser = new ProductFournisseur($db);
52  else $prodser = new Product($db);
53 
54  if ($idprod)
55  {
56  $prodser->fetch($idprod);
57  // If a predefined product and multilang and on other lang, we renamed label with label translated
58  if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
59  {
60  if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label) $label=$prodser->multilangs[$outputlangs->defaultlang]["label"];
61  if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
62  if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note) $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
63  }
64  }
65 
66  // Description short of product line
67  $libelleproduitservice=$label;
68 
69  // Description long of product line
70  if ($desc && ($desc != $label))
71  {
72  if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except)
73  {
74  $discount=new DiscountAbsolute($db);
75  $discount->fetch($line->fk_remise_except);
76  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
77  }
78  elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
79  {
80  $discount=new DiscountAbsolute($db);
81  $discount->fetch($line->fk_remise_except);
82  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$discount->ref_facture_source);
83  // Add date of deposit
84  if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
85  }
86  elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except)
87  {
88  $discount=new DiscountAbsolute($db);
89  $discount->fetch($line->fk_remise_except);
90  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
91  }
92  else
93  {
94  if ($idprod)
95  {
96  if (empty($hidedesc)) $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
97  }
98  else
99  {
100  $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
101  }
102  }
103  }
104 
105  // If line linked to a product
106  if ($idprod)
107  {
108  // On ajoute la ref
109  if ($prodser->ref)
110  {
111  $prefix_prodserv = "";
112  $ref_prodserv = "";
113  if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this
114  {
115  if ($prodser->isService())
116  {
117  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
118  }
119  else
120  {
121  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
122  }
123  }
124 
125  if (empty($hideref))
126  {
127  if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref
128  else $ref_prodserv = $prodser->ref; // Show local ref only
129 
130  $ref_prodserv .= " - ";
131  }
132 
133  $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
134  }
135  }
136 
137  if (! empty($line->date_start) || ! empty($line->date_end))
138  {
139  $format='day';
140  // Show duration if exists
141  if ($line->date_start && $line->date_end)
142  {
143  $period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($line->date_start, $format, false, $outputlangs),dol_print_date($line->date_end, $format, false, $outputlangs)).')';
144  }
145  if ($line->date_start && ! $line->date_end)
146  {
147  $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($line->date_start, $format, false, $outputlangs)).')';
148  }
149  if (! $line->date_start && $line->date_end)
150  {
151  $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($line->date_end, $format, false, $outputlangs)).')';
152  }
153  //print '>'.$outputlangs->charset_output.','.$period;
154  $libelleproduitservice=dol_concatdesc($libelleproduitservice, $period);
155  //print $libelleproduitservice;
156  }
157 
158  return $libelleproduitservice;
159 }
160 
Class to manage products or services.
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
dol_concatdesc($text1, $text2, $forxml=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage absolute discounts.
Class to manage predefined suppliers products.