PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/bom/tpl/objectline_view.tpl.php

http://github.com/Dolibarr/dolibarr
PHP | 270 lines | 196 code | 27 blank | 47 comment | 44 complexity | cbf09e780456ef11dd82c6c00e5f13fa MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, MIT
  1. <?php
  2. /* Copyright (C) 2010-2013 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2010-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
  5. * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
  6. * Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  7. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  8. * Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. *
  23. * Need to have following variables defined:
  24. * $object (invoice, order, ...)
  25. * $conf
  26. * $langs
  27. * $forceall (0 by default, 1 for supplier invoices/orders)
  28. * $element (used to test $user->rights->$element->creer)
  29. * $permtoedit (used to replace test $user->rights->$element->creer)
  30. * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax)
  31. * $object_rights->creer initialized from = $object->getRights()
  32. * $disableedit, $disablemove, $disableremove
  33. *
  34. * $type, $text, $description, $line
  35. */
  36. // Protection to avoid direct call of template
  37. if (empty($object) || !is_object($object)) {
  38. print "Error, template page can't be called as URL";
  39. exit;
  40. }
  41. global $forceall, $senderissupplier, $inputalsopricewithtax, $outputalsopricetotalwithtax;
  42. if (empty($dateSelector)) {
  43. $dateSelector = 0;
  44. }
  45. if (empty($forceall)) {
  46. $forceall = 0;
  47. }
  48. if (empty($senderissupplier)) {
  49. $senderissupplier = 0;
  50. }
  51. if (empty($inputalsopricewithtax)) {
  52. $inputalsopricewithtax = 0;
  53. }
  54. if (empty($outputalsopricetotalwithtax)) {
  55. $outputalsopricetotalwithtax = 0;
  56. }
  57. // add html5 elements
  58. $domData = ' data-element="'.$line->element.'"';
  59. $domData .= ' data-id="'.$line->id.'"';
  60. $domData .= ' data-qty="'.$line->qty.'"';
  61. $domData .= ' data-product_type="'.$line->product_type.'"';
  62. // Lines for extrafield
  63. $objectline = new BOMLine($object->db);
  64. $coldisplay = 0;
  65. print "<!-- BEGIN PHP TEMPLATE objectline_view.tpl.php -->\n";
  66. print '<tr id="row-'.$line->id.'" class="drag drop oddeven" '.$domData.' >';
  67. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  68. print '<td class="linecolnum center">'.($i + 1).'</td>';
  69. $coldisplay++;
  70. }
  71. print '<td class="linecoldescription minwidth300imp">';
  72. print '<div id="line_'.$line->id.'"></div>';
  73. $coldisplay++;
  74. $tmpproduct = new Product($object->db);
  75. $tmpproduct->fetch($line->fk_product);
  76. $tmpbom = new BOM($object->db);
  77. $res = $tmpbom->fetch($line->fk_bom_child);
  78. if ($tmpbom->id > 0) {
  79. print $tmpbom->getNomUrl(1);
  80. print '<a class="collapse_bom" id="collapse-'.$line->id.'" href="#">' . (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT) ? '(+)' : '(-)') . '&nbsp;</a>';
  81. } else {
  82. print $tmpproduct->getNomUrl(1);
  83. print ' - '.$tmpproduct->label;
  84. }
  85. print '</td>';
  86. print '<td class="linecolqty nowrap right">';
  87. $coldisplay++;
  88. echo price($line->qty, 0, '', 0, 0); // Yes, it is a quantity, not a price, but we just want the formating role of function price
  89. print '</td>';
  90. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  91. print '<td class="linecoluseunit nowrap left">';
  92. $label = $tmpproduct->getLabelOfUnit('long');
  93. if ($label !== '') {
  94. print $langs->trans($label);
  95. }
  96. print '</td>';
  97. }
  98. print '<td class="linecolqtyfrozen nowrap right">';
  99. $coldisplay++;
  100. echo $line->qty_frozen ? yn($line->qty_frozen) : '';
  101. print '</td>';
  102. print '<td class="linecoldisablestockchange nowrap right">';
  103. $coldisplay++;
  104. echo $line->disable_stock_change ? yn($line->disable_stock_change) : ''; // Yes, it is a quantity, not a price, but we just want the formating role of function price
  105. print '</td>';
  106. print '<td class="linecolefficiency nowrap right">';
  107. $coldisplay++;
  108. echo $line->efficiency;
  109. print '</td>';
  110. $total_cost = 0;
  111. print '<td id="costline_'.$line->id.'" class="linecolcost nowrap right">';
  112. $coldisplay++;
  113. echo price($line->total_cost);
  114. print '</td>';
  115. if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines') {
  116. print '<td class="linecoledit center">';
  117. $coldisplay++;
  118. if (($line->info_bits & 2) == 2 || !empty($disableedit)) {
  119. } else {
  120. print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=editline&token='.newToken().'&lineid='.$line->id.'">'.img_edit().'</a>';
  121. }
  122. print '</td>';
  123. print '<td class="linecoldelete center">';
  124. $coldisplay++;
  125. if (($line->fk_prev_id == null) && empty($disableremove)) {
  126. //La suppression n'est autorisée que si il n'y a pas de ligne dans une précédente situation
  127. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=deleteline&token='.newToken().'&lineid='.$line->id.'">';
  128. print img_delete();
  129. print '</a>';
  130. }
  131. print '</td>';
  132. if ($num > 1 && $conf->browser->layout != 'phone' && empty($disablemove)) {
  133. print '<td class="linecolmove tdlineupdown center">';
  134. $coldisplay++;
  135. if ($i > 0) {
  136. print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=up&amp;rowid='.$line->id.'">';
  137. echo img_up('default', 0, 'imgupforline');
  138. print '</a>';
  139. }
  140. if ($i < $num - 1) {
  141. print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&amp;action=down&amp;rowid='.$line->id.'">';
  142. echo img_down('default', 0, 'imgdownforline');
  143. print '</a>';
  144. }
  145. print '</td>';
  146. } else {
  147. print '<td '.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'></td>';
  148. $coldisplay++;
  149. }
  150. } else {
  151. print '<td colspan="3"></td>';
  152. $coldisplay = $coldisplay + 3;
  153. }
  154. if ($action == 'selectlines') {
  155. print '<td class="linecolcheck center">';
  156. print '<input type="checkbox" class="linecheckbox" name="line_checkbox['.($i + 1).']" value="'.$line->id.'" >';
  157. print '</td>';
  158. }
  159. print '</tr>';
  160. // Select of all the sub-BOM lines
  161. $sql = 'SELECT rowid, fk_bom_child, fk_product FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
  162. $sql.= ' WHERE fk_bom ='. (int) $tmpbom->id;
  163. $resql = $object->db->query($sql);
  164. if ($resql) {
  165. // Loop on all the sub-BOM lines if they exist
  166. while ($obj = $object->db->fetch_object($resql)) {
  167. $sub_bom_product = new Product($object->db);
  168. $sub_bom_product->fetch($obj->fk_product);
  169. $sub_bom = new BOM($object->db);
  170. $sub_bom->fetch($obj->fk_bom_child);
  171. $sub_bom_line = new BOMLine($object->db);
  172. $sub_bom_line->fetch($obj->rowid);
  173. //If hidden conf is set, we show directly all the sub-BOM lines
  174. if (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT)) {
  175. print '<tr style="display:none" class="sub_bom_lines" parentid="'.$line->id.'">';
  176. } else {
  177. print '<tr class="sub_bom_lines" parentid="'.$line->id.'">';
  178. }
  179. // Product
  180. print '<td style="padding-left: 5%" id="sub_bom_product_'.$sub_bom_line->id.'">'.$sub_bom_product->getNomUrl(1).'</td>';
  181. // Sub-BOM
  182. if ($sub_bom_line->fk_bom_child > 0) {
  183. print '<td id="sub_bom_bom_'.$sub_bom_line->id.'">'.$sub_bom->getNomUrl(1).'</td>';
  184. } else {
  185. print '<td id="sub_bom_bom_'.$sub_bom_line->id.'">&nbsp;</td>';
  186. }
  187. // Qty
  188. print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty * $line->qty, 0, '', 0, 0).'</td>';
  189. if ($sub_bom_line->qty_frozen > 0) {
  190. print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">'.$sub_bom_line->qty_frozen.'</td>';
  191. } else {
  192. print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">&nbsp;</td>';
  193. }
  194. // Disable stock change
  195. if ($sub_bom_line->disable_stock_change > 0) {
  196. print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">'.$sub_bom_line->disable_stock_change.'</td>';
  197. } else {
  198. print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">&nbsp;</td>';
  199. }
  200. // Efficiency
  201. print '<td class="linecolefficiency nowrap right" id="sub_bom_efficiency_'.$sub_bom_line->id.'">'.$sub_bom_line->efficiency.'</td>';
  202. // Cost price if it's defined
  203. if ($sub_bom_product->cost_price > 0) {
  204. print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($sub_bom_product->cost_price * $line->qty).'</td>';
  205. $total_cost.= $sub_bom_product->cost_price * $line->qty;
  206. } elseif ($sub_bom_product->pmp > 0) { // PMP if cost price isn't defined
  207. print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($sub_bom_product->pmp * $line->qty).'</td>';
  208. $total_cost.= $sub_bom_product->pmp * $line->qty;
  209. } else { // Minimum purchase price if cost price and PMP aren't defined
  210. $sql_supplier_price = 'SELECT MIN(price) AS min_price FROM '.MAIN_DB_PREFIX.'product_fournisseur_price';
  211. $sql_supplier_price.= ' WHERE fk_product = '. (int) $sub_bom_product->id;
  212. $resql_supplier_price = $object->db->query($sql_supplier_price);
  213. if ($resql_supplier_price) {
  214. $obj = $object->db->fetch_object($resql_supplier_price);
  215. print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'">'.price($obj->min_price * $line->qty).'</td>';
  216. $total_cost+= $obj->min_price * $line->qty;
  217. }
  218. }
  219. print '<td></td>';
  220. print '<td></td>';
  221. print '<td></td>';
  222. }
  223. }
  224. // Replace of the total_cost value by the sum of all sub-BOM lines total_cost
  225. if ($total_cost > 0) {
  226. $line->total_cost = price($total_cost);
  227. ?>
  228. <script>
  229. $('#costline_<?php echo $line->id?>').html("<?php echo "".price($total_cost)?>");
  230. </script>
  231. <?php
  232. }
  233. //Line extrafield
  234. if (!empty($extrafields)) {
  235. print $line->showOptionals($extrafields, 'view', array('style'=>'class="drag drop oddeven"', 'colspan'=>$coldisplay), '', '', 1, 'line');
  236. }
  237. print "<!-- END PHP TEMPLATE objectline_view.tpl.php -->\n";