dolibarr  17.0.4
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) {
52  $prodser = new ProductFournisseur($db);
53  } else {
54  $prodser = new Product($db);
55  }
56 
57  if ($idprod) {
58  $prodser->fetch($idprod);
59  // If a predefined product and multilang and on other lang, we renamed label with label translated
60  if (getDolGlobalInt('MAIN_MULTILANGS') && ($outputlangs->defaultlang != $langs->defaultlang)) {
61  if (!empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label) {
62  $label = $prodser->multilangs[$outputlangs->defaultlang]["label"];
63  }
64  if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) {
65  $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"];
66  }
67  if (!empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note) {
68  $note = $prodser->multilangs[$outputlangs->defaultlang]["note"];
69  }
70  }
71  }
72 
73  // Description short of product line
74  $libelleproduitservice = $label;
75 
76  // Description long of product line
77  if ($desc && ($desc != $label)) {
78  if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except) {
79  $discount = new DiscountAbsolute($db);
80  $discount->fetch($line->fk_remise_except);
81  $sourceref = !empty($discount->discount_type) ? $discount->ref_invoice_supplier_source : $discount->ref_facture_source;
82  $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $sourceref);
83  } elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except) {
84  $discount = new DiscountAbsolute($db);
85  $discount->fetch($line->fk_remise_except);
86  $sourceref = !empty($discount->discount_type) ? $discount->ref_invoice_supplier_source : $discount->ref_facture_source;
87  $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $sourceref);
88  // Add date of deposit
89  if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) {
90  $libelleproduitservice .= ' ('.dol_print_date($discount->datec, 'day', '', $outputlangs).')';
91  }
92  } elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except) {
93  $discount = new DiscountAbsolute($db);
94  $discount->fetch($line->fk_remise_except);
95  $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived", $discount->ref_facture_source);
96  } elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except) {
97  $discount = new DiscountAbsolute($db);
98  $discount->fetch($line->fk_remise_except);
99  $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid", $discount->ref_invoice_supplier_source);
100  } else {
101  if ($idprod) {
102  if (empty($hidedesc)) {
103  $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc);
104  }
105  } else {
106  $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc);
107  }
108  }
109  }
110 
111  // If line linked to a product
112  if ($idprod) {
113  // On ajoute la ref
114  if ($prodser->ref) {
115  $prefix_prodserv = "";
116  $ref_prodserv = "";
117  if (!empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) { // In standard mode, we do not show this
118  if ($prodser->isService()) {
119  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
120  } else {
121  $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
122  }
123  }
124 
125  if (empty($hideref)) {
126  if ($issupplierline) {
127  $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref
128  } else {
129  $ref_prodserv = $prodser->ref; // Show local ref only
130  }
131  }
132 
133  $libelleproduitservice = $prefix_prodserv.$ref_prodserv.($libelleproduitservice ? " - " : "").$libelleproduitservice;
134  }
135  }
136 
137  if (!empty($line->date_start) || !empty($line->date_end)) {
138  $format = 'day';
139  // Show duration if exists
140  if ($line->date_start && $line->date_end) {
141  $period = '('.$outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($line->date_start, $format, false, $outputlangs), dol_print_date($line->date_end, $format, false, $outputlangs)).')';
142  }
143  if ($line->date_start && !$line->date_end) {
144  $period = '('.$outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($line->date_start, $format, false, $outputlangs)).')';
145  }
146  if (!$line->date_start && $line->date_end) {
147  $period = '('.$outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($line->date_end, $format, false, $outputlangs)).')';
148  }
149  //print '>'.$outputlangs->charset_output.','.$period;
150  $libelleproduitservice = dol_concatdesc($libelleproduitservice, $period);
151  //print $libelleproduitservice;
152  }
153 
154  return $libelleproduitservice;
155 }
Class to manage absolute discounts.
Class to manage predefined suppliers products.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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...