doc.lib.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. /**
  24. * \file htdocs/core/lib/doc.lib.php
  25. * \brief Set of functions used for ODT generation
  26. * \ingroup core
  27. */
  28. /**
  29. * Return line description translated in outputlangs and encoded into UTF8
  30. *
  31. * @param Object $line Object of line
  32. * @param Translate $outputlangs Object langs for output
  33. * @param int $hideref Hide reference
  34. * @param int $hidedesc Hide description
  35. * @param int $issupplierline Is it a line for a supplier object ?
  36. * @return string String with line
  37. */
  38. function doc_getlinedesc($line, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
  39. {
  40. global $db, $conf, $langs;
  41. $idprod = $line->fk_product;
  42. $label = (!empty($line->label) ? $line->label : (!empty($line->libelle) ? $line->libelle : ''));
  43. $desc = (!empty($line->desc) ? $line->desc : (!empty($line->description) ? $line->description : ''));
  44. $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
  45. $note = (!empty($line->note) ? $line->note : '');
  46. if ($issupplierline) {
  47. $prodser = new ProductFournisseur($db);
  48. } else {
  49. $prodser = new Product($db);
  50. }
  51. if ($idprod) {
  52. $prodser->fetch($idprod);
  53. // If a predefined product and multilang and on other lang, we renamed label with label translated
  54. if (getDolGlobalInt('MAIN_MULTILANGS') && ($outputlangs->defaultlang != $langs->defaultlang)) {
  55. if (!empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label) {
  56. $label = $prodser->multilangs[$outputlangs->defaultlang]["label"];
  57. }
  58. if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) {
  59. $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"];
  60. }
  61. if (!empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note) {
  62. $note = $prodser->multilangs[$outputlangs->defaultlang]["note"];
  63. }
  64. }
  65. }
  66. // Description short of product line
  67. $libelleproduitservice = $label;
  68. // Description long of product line
  69. if ($desc && ($desc != $label)) {
  70. if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except) {
  71. $discount = new DiscountAbsolute($db);
  72. $discount->fetch($line->fk_remise_except);
  73. $sourceref = !empty($discount->discount_type) ? $discount->ref_invoice_supplier_source : $discount->ref_facture_source;
  74. $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $sourceref);
  75. } elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except) {
  76. $discount = new DiscountAbsolute($db);
  77. $discount->fetch($line->fk_remise_except);
  78. $sourceref = !empty($discount->discount_type) ? $discount->ref_invoice_supplier_source : $discount->ref_facture_source;
  79. $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $sourceref);
  80. // Add date of deposit
  81. if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) {
  82. $libelleproduitservice .= ' ('.dol_print_date($discount->datec, 'day', '', $outputlangs).')';
  83. }
  84. } elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except) {
  85. $discount = new DiscountAbsolute($db);
  86. $discount->fetch($line->fk_remise_except);
  87. $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived", $discount->ref_facture_source);
  88. } elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except) {
  89. $discount = new DiscountAbsolute($db);
  90. $discount->fetch($line->fk_remise_except);
  91. $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid", $discount->ref_invoice_supplier_source);
  92. } else {
  93. if ($idprod) {
  94. if (empty($hidedesc)) {
  95. $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc);
  96. }
  97. } else {
  98. $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc);
  99. }
  100. }
  101. }
  102. // If line linked to a product
  103. if ($idprod) {
  104. // On ajoute la ref
  105. if ($prodser->ref) {
  106. $prefix_prodserv = "";
  107. $ref_prodserv = "";
  108. if (!empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) { // In standard mode, we do not show this
  109. if ($prodser->isService()) {
  110. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
  111. } else {
  112. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
  113. }
  114. }
  115. if (empty($hideref)) {
  116. if ($issupplierline) {
  117. $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref
  118. } else {
  119. $ref_prodserv = $prodser->ref; // Show local ref only
  120. }
  121. }
  122. $libelleproduitservice = $prefix_prodserv.$ref_prodserv.($libelleproduitservice ? " - " : "").$libelleproduitservice;
  123. }
  124. }
  125. if (!empty($line->date_start) || !empty($line->date_end)) {
  126. $format = 'day';
  127. // Show duration if exists
  128. if ($line->date_start && $line->date_end) {
  129. $period = '('.$outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($line->date_start, $format, false, $outputlangs), dol_print_date($line->date_end, $format, false, $outputlangs)).')';
  130. }
  131. if ($line->date_start && !$line->date_end) {
  132. $period = '('.$outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($line->date_start, $format, false, $outputlangs)).')';
  133. }
  134. if (!$line->date_start && $line->date_end) {
  135. $period = '('.$outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($line->date_end, $format, false, $outputlangs)).')';
  136. }
  137. //print '>'.$outputlangs->charset_output.','.$period;
  138. $libelleproduitservice = dol_concatdesc($libelleproduitservice, $period);
  139. //print $libelleproduitservice;
  140. }
  141. return $libelleproduitservice;
  142. }