dolibarr  9.0.0
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@inodbox.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  $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
77  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
78  }
79  elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
80  {
81  $discount=new DiscountAbsolute($db);
82  $discount->fetch($line->fk_remise_except);
83  $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
84  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref);
85  // Add date of deposit
86  if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
87  }
88  elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except)
89  {
90  $discount=new DiscountAbsolute($db);
91  $discount->fetch($line->fk_remise_except);
92  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
93  }
94  elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except)
95  {
96  $discount=new DiscountAbsolute($db);
97  $discount->fetch($line->fk_remise_except);
98  $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
99  }
100  else
101  {
102  if ($idprod)
103  {
104  if (empty($hidedesc)) $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
105  }
106  else
107  {
108  $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
109  }
110  }
111  }
112 
113  // If line linked to a product
114  if ($idprod)
115  {
116  // On ajoute la ref
117  if ($prodser->ref)
118  {
119  $prefix_prodserv = "";
120  $ref_prodserv = "";
121  if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this
122  {
123  if ($prodser->isService())
124  {
125  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
126  }
127  else
128  {
129  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
130  }
131  }
132 
133  if (empty($hideref))
134  {
135  if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref
136  else $ref_prodserv = $prodser->ref; // Show local ref only
137 
138  $ref_prodserv .= " - ";
139  }
140 
141  $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
142  }
143  }
144 
145  if (! empty($line->date_start) || ! empty($line->date_end))
146  {
147  $format='day';
148  // Show duration if exists
149  if ($line->date_start && $line->date_end)
150  {
151  $period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($line->date_start, $format, false, $outputlangs),dol_print_date($line->date_end, $format, false, $outputlangs)).')';
152  }
153  if ($line->date_start && ! $line->date_end)
154  {
155  $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($line->date_start, $format, false, $outputlangs)).')';
156  }
157  if (! $line->date_start && $line->date_end)
158  {
159  $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($line->date_end, $format, false, $outputlangs)).')';
160  }
161  //print '>'.$outputlangs->charset_output.','.$period;
162  $libelleproduitservice=dol_concatdesc($libelleproduitservice, $period);
163  //print $libelleproduitservice;
164  }
165 
166  return $libelleproduitservice;
167 }
168 
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.