commonobjectline.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/core/class/commonobjectline.class.php
  20. * \ingroup core
  21. * \brief File of the superclass of classes of lines of business objects (invoice, contract, proposal, orders, etc. ...)
  22. */
  23. /**
  24. * Parent class for class inheritance lines of business objects
  25. * This class is useless for the moment so no inherit are done on it
  26. *
  27. * TODO For the moment we use the extends on CommonObject until PHP min is 5.4 so we can use Traits.
  28. */
  29. abstract class CommonObjectLine extends CommonObject
  30. {
  31. /**
  32. * Id of the line
  33. * @var int
  34. */
  35. public $id;
  36. /**
  37. * Id of the line
  38. * @var int
  39. * @deprecated Try to use id property as possible (even if field into database is still rowid)
  40. * @see $id
  41. */
  42. public $rowid;
  43. /**
  44. * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
  45. */
  46. public $picto = 'line';
  47. /**
  48. * Product/service unit code ('km', 'm', 'p', ...)
  49. * @var string
  50. */
  51. public $fk_unit;
  52. public $date_debut_prevue;
  53. public $date_debut_reel;
  54. public $date_fin_prevue;
  55. public $date_fin_reel;
  56. public $weight;
  57. public $weight_units;
  58. public $width;
  59. public $width_units;
  60. public $height;
  61. public $height_units;
  62. public $length;
  63. public $length_units;
  64. public $surface;
  65. public $surface_units;
  66. public $volume;
  67. public $volume_units;
  68. public $multilangs;
  69. public $product_type; // type in line
  70. public $fk_product; // product id in line (when line is linked to a product)
  71. public $desc;
  72. public $product; // To store full product object after a fetch_product() on a line
  73. public $product_ref; // ref in product table
  74. public $product_label; // label in product table
  75. public $product_barcode; // barcode in product table
  76. public $product_desc; // desc in product table
  77. public $fk_product_type; // type in product table
  78. public $qty;
  79. public $duree;
  80. public $remise_percent;
  81. public $info_bits;
  82. public $special_code;
  83. /**
  84. * Constructor
  85. *
  86. * @param DoliDB $db Database handler
  87. */
  88. public function __construct($db)
  89. {
  90. $this->db = $db;
  91. }
  92. /**
  93. * Returns the label, short_label or code found in units dictionary from ->fk_unit.
  94. * A langs->trans() must be called on result to get translated value.
  95. *
  96. * @param string $type Label type ('long', 'short' or 'code'). This can be a translation key.
  97. * @return string|int <0 if KO, label if OK (Example: 'long', 'short' or 'unitCODE')
  98. */
  99. public function getLabelOfUnit($type = 'long')
  100. {
  101. global $langs;
  102. if (empty($this->fk_unit)) {
  103. return '';
  104. }
  105. $langs->load('products');
  106. $label_type = 'label';
  107. $label_type = 'label';
  108. if ($type == 'short') {
  109. $label_type = 'short_label';
  110. } elseif ($type == 'code') {
  111. $label_type = 'code';
  112. }
  113. $sql = "SELECT ".$label_type.", code from ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit);
  114. $resql = $this->db->query($sql);
  115. if ($resql && $this->db->num_rows($resql) > 0) {
  116. $res = $this->db->fetch_array($resql);
  117. if ($label_type == 'code') {
  118. $label = 'unit'.$res['code'];
  119. } else {
  120. $label = $res[$label_type];
  121. }
  122. $this->db->free($resql);
  123. return $label;
  124. } else {
  125. $this->error = $this->db->lasterror();
  126. dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR);
  127. return -1;
  128. }
  129. }
  130. /**
  131. * Empty function to prevent errors on call of this function must be overload if usefull
  132. *
  133. * @param string $sortorder Sort Order
  134. * @param string $sortfield Sort field
  135. * @param int $limit offset limit
  136. * @param int $offset offset limit
  137. * @param array $filter filter array
  138. * @param string $filtermode filter mode (AND or OR)
  139. * @return int <0 if KO, >0 if OK
  140. */
  141. public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
  142. {
  143. return 0;
  144. }
  145. }