originproductline.tpl.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
  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. // Protection to avoid direct call of template
  19. if (empty($conf) || !is_object($conf)) {
  20. print "Error, template page can't be called as URL";
  21. exit;
  22. }
  23. global $db;
  24. if (!empty($form) && !is_object($form)) {
  25. $form = new Form($db);
  26. }
  27. $qtytoconsumeforline = $this->tpl['qty'] / ( !empty($this->tpl['efficiency']) ? $this->tpl['efficiency'] : 1 );
  28. /*if ((empty($this->tpl['qty_frozen']) && $this->tpl['qty_bom'] > 1)) {
  29. $qtytoconsumeforline = $qtytoconsumeforline / $this->tpl['qty_bom'];
  30. }*/
  31. $qtytoconsumeforline = price2num($qtytoconsumeforline, 'MS');
  32. $tmpproduct = new Product($db);
  33. $tmpproduct->fetch($line->fk_product);
  34. $tmpbom = new BOM($db);
  35. $res = $tmpbom->fetch($line->fk_bom_child);
  36. ?>
  37. <!-- BEGIN PHP TEMPLATE originproductline.tpl.php -->
  38. <?php
  39. print '<tr class="oddeven'.(empty($this->tpl['strike']) ? '' : ' strikefordisabled').'">';
  40. // Ref or label
  41. print '<td>';
  42. if ($res) {
  43. print $tmpproduct->getNomUrl(1);
  44. if ($tmpbom->id) {
  45. print ' ' . $langs->trans("or") . ' ';
  46. print $tmpbom->getNomUrl(1);
  47. print ' <a class="collapse_bom" id="collapse-' . $line->id . '" href="#">';
  48. print (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT) ? img_picto('', 'folder') : img_picto('', 'folder-open'));
  49. }
  50. print '</a>';
  51. } else {
  52. print $this->tpl['label'];
  53. }
  54. print '</td>';
  55. // Qty
  56. print '<td class="right">'.$this->tpl['qty'].(($this->tpl['efficiency'] > 0 && $this->tpl['efficiency'] < 1) ? ' / '.$form->textwithpicto($this->tpl['efficiency'], $langs->trans("ValueOfMeansLoss")).' = '.$qtytoconsumeforline : '').'</td>';
  57. print '<td class="center">'.(empty($this->tpl['stock']) ? 0 : price2num($this->tpl['stock'], 'MS'));
  58. if ($this->tpl['seuil_stock_alerte'] != '' && ($this->tpl['stock'] < $this->tpl['seuil_stock_alerte'])) {
  59. print ' '.img_warning($langs->trans("StockLowerThanLimit", $this->tpl['seuil_stock_alerte']));
  60. }
  61. print '</td>';
  62. print '<td class="center">'.((empty($this->tpl['virtual_stock']) ? 0 : price2num($this->tpl['virtual_stock'], 'MS')));
  63. if ($this->tpl['seuil_stock_alerte'] != '' && ($this->tpl['virtual_stock'] < $this->tpl['seuil_stock_alerte'])) {
  64. print ' '.img_warning($langs->trans("StockLowerThanLimit", $this->tpl['seuil_stock_alerte']));
  65. }
  66. print '</td>';
  67. print '<td class="center">'.($this->tpl['qty_frozen'] ? yn($this->tpl['qty_frozen']) : '').'</td>';
  68. print '<td class="center">'.($this->tpl['disable_stock_change'] ? yn($this->tpl['disable_stock_change']) : '').'</td>';
  69. //print '<td class="right">'.$this->tpl['efficiency'].'</td>';
  70. $selected = 1;
  71. if (!empty($selectedLines) && !in_array($this->tpl['id'], $selectedLines)) {
  72. $selected = 0;
  73. }
  74. if ($tmpbom->id > 0) {
  75. print '<td class="center">';
  76. print '<input type="checkbox" name="bomlineid[]" value="' . $line->id . '">';
  77. print '</td>';
  78. } else {
  79. print '<td class="center"></td>';
  80. }
  81. //print '<td class="center">';
  82. //print '<input id="cb'.$this->tpl['id'].'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$this->tpl['id'].'"'.($selected?' checked="checked"':'').'>';
  83. //print '</td>';
  84. print '</tr>'."\n";
  85. // Select of all the sub-BOM lines
  86. $sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
  87. $sql.= ' WHERE fk_bom ='. (int) $tmpbom->id;
  88. $resql = $db->query($sql);
  89. if ($resql) {
  90. // Loop on all the sub-BOM lines if they exist
  91. while ($obj = $db->fetch_object($resql)) {
  92. $sub_bom_product = new Product($db);
  93. $sub_bom_product->fetch($obj->fk_product);
  94. $sub_bom_product->load_stock();
  95. $sub_bom = new BOM($db);
  96. $sub_bom->fetch($obj->fk_bom_child);
  97. $sub_bom_line = new BOMLine($db);
  98. $sub_bom_line->fetch($obj->rowid);
  99. //If hidden conf is set, we show directly all the sub-BOM lines
  100. if (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT)) {
  101. print '<tr style="display:none" class="sub_bom_lines" parentid="'.$line->id.'">';
  102. } else {
  103. print '<tr class="sub_bom_lines" parentid="'.$line->id.'">';
  104. }
  105. // Product OR BOM
  106. print '<td style="padding-left: 5%" id="sub_bom_product_'.$sub_bom_line->id.'">';
  107. if (!empty($obj->fk_bom_child)) {
  108. print $sub_bom_product->getNomUrl(1);
  109. print ' '.$langs->trans('or').' ';
  110. print $sub_bom->getNomUrl(1);
  111. } else {
  112. print $sub_bom_product->getNomUrl(1);
  113. print '</td>';
  114. }
  115. // Qty
  116. if ($sub_bom_line->qty_frozen > 0) {
  117. print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty, 0, '', 0, 0).'</td>';
  118. } else {
  119. 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>';
  120. }
  121. // Stock réel
  122. if ($sub_bom_product->stock_reel > 0) {
  123. print '<td class="linecolstockreel nowrap center" id="sub_bom_stock_reel_'.$sub_bom_product->stock_reel.'">'.$sub_bom_product->stock_reel.'</td>';
  124. } else {
  125. print '<td class="linecolstockreel nowrap center" id="sub_bom_stock_reel_'.$sub_bom_product->stock_reel.'">&nbsp;</td>';
  126. }
  127. // Stock virtuel
  128. if ($sub_bom_product->stock_theorique > 0) {
  129. print '<td class="linecolstocktheorique nowrap center" id="sub_bom_stock_theorique_'.$sub_bom_product->stock_theorique.'">'.$sub_bom_product->stock_theorique.'</td>';
  130. } else {
  131. print '<td class="linecolstocktheorique nowrap center" id="sub_bom_stock_theorique_'.$sub_bom_product->stock_theorique.'">&nbsp;</td>';
  132. }
  133. // Frozen qty
  134. if ($sub_bom_line->qty_frozen > 0) {
  135. print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->qty_frozen.'">'.$langs->trans('Yes').'</td>';
  136. } else {
  137. print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->qty_frozen.'">&nbsp;</td>';
  138. }
  139. // Disable stock change
  140. if ($sub_bom_line->disable_stock_change > 0) {
  141. print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">'.yn($sub_bom_line->disable_stock_change).'</td>';
  142. } else {
  143. print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">&nbsp;</td>';
  144. }
  145. print '<td></td>';
  146. print '<td></td>';
  147. }
  148. }
  149. ?>
  150. <!-- END PHP TEMPLATE originproductline.tpl.php -->