PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/lib/doc.lib.php

https://bitbucket.org/speedealing/speedealing
PHP | 158 lines | 97 code | 16 blank | 45 comment | 43 complexity | 1c4c4e116cfc2fbbcce817bce5dc75e7 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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 ( $libelleproduitservice && empty($hidedesc) ) $libelleproduitservice.="\n";
  65. if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except)
  66. {
  67. $discount=new DiscountAbsolute($db);
  68. $discount->fetch($line->fk_remise_except);
  69. $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
  70. }
  71. elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
  72. {
  73. $discount=new DiscountAbsolute($db);
  74. $discount->fetch($line->fk_remise_except);
  75. $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$discount->ref_facture_source);
  76. // Add date of deposit
  77. if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
  78. }
  79. else
  80. {
  81. if ($idprod)
  82. {
  83. if (empty($hidedesc))
  84. $libelleproduitservice.=$desc;
  85. }
  86. else
  87. {
  88. $libelleproduitservice.=$desc;
  89. }
  90. }
  91. }
  92. // If line linked to a product
  93. if ($idprod)
  94. {
  95. // On ajoute la ref
  96. if ($prodser->ref)
  97. {
  98. $prefix_prodserv = "";
  99. $ref_prodserv = "";
  100. if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this
  101. {
  102. if ($prodser->isservice())
  103. {
  104. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
  105. }
  106. else
  107. {
  108. $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
  109. }
  110. }
  111. if (empty($hideref))
  112. {
  113. if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref
  114. else $ref_prodserv = $prodser->ref; // Show local ref only
  115. $ref_prodserv .= " - ";
  116. }
  117. $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
  118. }
  119. }
  120. if (! empty($line->date_start) || ! empty($line->date_end))
  121. {
  122. $format='day';
  123. // Show duration if exists
  124. if ($line->date_start && $line->date_end)
  125. {
  126. $period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($line->date_start, $format, false, $outputlangs),dol_print_date($line->date_end, $format, false, $outputlangs)).')';
  127. }
  128. if ($line->date_start && ! $line->date_end)
  129. {
  130. $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($line->date_start, $format, false, $outputlangs)).')';
  131. }
  132. if (! $line->date_start && $line->date_end)
  133. {
  134. $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($line->date_end, $format, false, $outputlangs)).')';
  135. }
  136. //print '>'.$outputlangs->charset_output.','.$period;
  137. $libelleproduitservice.="\n".$period;
  138. //print $libelleproduitservice;
  139. }
  140. return $libelleproduitservice;
  141. }
  142. ?>