doc.lib.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. /**
  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 Line $line Current line number (0 = first line, 1 = second 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) $prodser = new ProductFournisseur($db);
  47. else $prodser = new Product($db);
  48. if ($idprod)
  49. {
  50. $prodser->fetch($idprod);
  51. // If a predefined product and multilang and on other lang, we renamed label with label translated
  52. if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
  53. {
  54. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label) $label=$prodser->multilangs[$outputlangs->defaultlang]["label"];
  55. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
  56. if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note) $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
  57. }
  58. }
  59. // Description short of product line
  60. $libelleproduitservice=$label;
  61. // Description long of product line
  62. if ($desc && ($desc != $label))
  63. {
  64. if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except)
  65. {
  66. $discount=new DiscountAbsolute($db);
  67. $discount->fetch($line->fk_remise_except);
  68. $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
  69. }
  70. elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
  71. {
  72. $discount=new DiscountAbsolute($db);
  73. $discount->fetch($line->fk_remise_except);
  74. $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$discount->ref_facture_source);
  75. // Add date of deposit
  76. if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
  77. }
  78. elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except)
  79. {
  80. $discount=new DiscountAbsolute($db);
  81. $discount->fetch($line->fk_remise_except);
  82. $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
  83. }
  84. else
  85. {
  86. if ($idprod)
  87. {
  88. if (empty($hidedesc)) $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
  89. }
  90. else
  91. {
  92. $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
  93. }
  94. }
  95. }
  96. // If line linked to a product
  97. if ($idprod)
  98. {
  99. // On ajoute la ref
  100. if ($prodser->ref)
  101. {
  102. $prefix_prodserv = "";
  103. $ref_prodserv = "";
  104. if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this
  105. {
  106. if ($prodser->isService())
  107. {
  108. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
  109. }
  110. else
  111. {
  112. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
  113. }
  114. }
  115. if (empty($hideref))
  116. {
  117. if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref
  118. else $ref_prodserv = $prodser->ref; // Show local ref only
  119. $ref_prodserv .= " - ";
  120. }
  121. $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
  122. }
  123. }
  124. if (! empty($line->date_start) || ! empty($line->date_end))
  125. {
  126. $format='day';
  127. // Show duration if exists
  128. if ($line->date_start && $line->date_end)
  129. {
  130. $period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($line->date_start, $format, false, $outputlangs),dol_print_date($line->date_end, $format, false, $outputlangs)).')';
  131. }
  132. if ($line->date_start && ! $line->date_end)
  133. {
  134. $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($line->date_start, $format, false, $outputlangs)).')';
  135. }
  136. if (! $line->date_start && $line->date_end)
  137. {
  138. $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($line->date_end, $format, false, $outputlangs)).')';
  139. }
  140. //print '>'.$outputlangs->charset_output.','.$period;
  141. $libelleproduitservice=dol_concatdesc($libelleproduitservice, $period);
  142. //print $libelleproduitservice;
  143. }
  144. return $libelleproduitservice;
  145. }