dolibarr  13.0.2
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 <https://www.gnu.org/licenses/>.
21  * or see https://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  } elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
79  {
80  $discount = new DiscountAbsolute($db);
81  $discount->fetch($line->fk_remise_except);
82  $sourceref = !empty($discount->discount_type) ? $discount->ref_invoive_supplier_source : $discount->ref_facture_source;
83  $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $sourceref);
84  // Add date of deposit
85  if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice .= ' ('.dol_print_date($discount->datec, 'day', '', $outputlangs).')';
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  } elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except)
92  {
93  $discount = new DiscountAbsolute($db);
94  $discount->fetch($line->fk_remise_except);
95  $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid", $discount->ref_invoice_supplier_source);
96  } else {
97  if ($idprod)
98  {
99  if (empty($hidedesc)) $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc);
100  } else {
101  $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc);
102  }
103  }
104  }
105 
106  // If line linked to a product
107  if ($idprod)
108  {
109  // On ajoute la ref
110  if ($prodser->ref)
111  {
112  $prefix_prodserv = "";
113  $ref_prodserv = "";
114  if (!empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this
115  {
116  if ($prodser->isService())
117  {
118  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
119  } else {
120  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
121  }
122  }
123 
124  if (empty($hideref))
125  {
126  if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref
127  else $ref_prodserv = $prodser->ref; // Show local ref only
128 
129  $ref_prodserv .= " - ";
130  }
131 
132  $libelleproduitservice = $prefix_prodserv.$ref_prodserv.$libelleproduitservice;
133  }
134  }
135 
136  if (!empty($line->date_start) || !empty($line->date_end))
137  {
138  $format = 'day';
139  // Show duration if exists
140  if ($line->date_start && $line->date_end)
141  {
142  $period = '('.$outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($line->date_start, $format, false, $outputlangs), dol_print_date($line->date_end, $format, false, $outputlangs)).')';
143  }
144  if ($line->date_start && !$line->date_end)
145  {
146  $period = '('.$outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($line->date_start, $format, false, $outputlangs)).')';
147  }
148  if (!$line->date_start && $line->date_end)
149  {
150  $period = '('.$outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($line->date_end, $format, false, $outputlangs)).')';
151  }
152  //print '>'.$outputlangs->charset_output.','.$period;
153  $libelleproduitservice = dol_concatdesc($libelleproduitservice, $period);
154  //print $libelleproduitservice;
155  }
156 
157  return $libelleproduitservice;
158 }
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, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
dol_print_date($time, $format= '', $tzoutput= 'auto', $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.