objectline_view.tpl.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. require_once DOL_DOCUMENT_ROOT.'/workstation/class/workstation.class.php';
  37. // Protection to avoid direct call of template
  38. if (empty($object) || !is_object($object)) {
  39. print "Error, template page can't be called as URL";
  40. exit;
  41. }
  42. global $filtertype;
  43. if (empty($filtertype)) $filtertype = 0;
  44. global $forceall, $senderissupplier, $inputalsopricewithtax, $outputalsopricetotalwithtax, $langs;
  45. if (empty($dateSelector)) {
  46. $dateSelector = 0;
  47. }
  48. if (empty($forceall)) {
  49. $forceall = 0;
  50. }
  51. if (empty($senderissupplier)) {
  52. $senderissupplier = 0;
  53. }
  54. if (empty($inputalsopricewithtax)) {
  55. $inputalsopricewithtax = 0;
  56. }
  57. if (empty($outputalsopricetotalwithtax)) {
  58. $outputalsopricetotalwithtax = 0;
  59. }
  60. // add html5 elements
  61. if ($filtertype == 1) $domData = ' data-element="'.$line->element.'service"';
  62. else $domData = ' data-element="'.$line->element.'"';
  63. $domData .= ' data-id="'.$line->id.'"';
  64. $domData .= ' data-qty="'.$line->qty.'"';
  65. $domData .= ' data-product_type="'.$line->product_type.'"';
  66. // Lines for extrafield
  67. $objectline = new BOMLine($object->db);
  68. $coldisplay = 0;
  69. print "<!-- BEGIN PHP TEMPLATE objectline_view.tpl.php -->\n";
  70. print '<tr id="row-'.$line->id.'" class="drag drop oddeven" '.$domData.' >';
  71. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  72. print '<td class="linecolnum center">'.($i + 1).'</td>';
  73. $coldisplay++;
  74. }
  75. print '<td class="linecoldescription minwidth300imp">';
  76. print '<div id="line_'.$line->id.'"></div>';
  77. $coldisplay++;
  78. $tmpproduct = new Product($object->db);
  79. $tmpproduct->fetch($line->fk_product);
  80. $tmpbom = new BOM($object->db);
  81. $res = $tmpbom->fetch($line->fk_bom_child);
  82. if ($tmpbom->id > 0) {
  83. print $tmpproduct->getNomUrl(1);
  84. print ' '.$langs->trans("or").' ';
  85. print $tmpbom->getNomUrl(1);
  86. print ' <a class="collapse_bom" id="collapse-'.$line->id.'" href="#">';
  87. print (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT) ? img_picto('', 'folder') : img_picto('', 'folder-open'));
  88. print '</a>';
  89. } else {
  90. print $tmpproduct->getNomUrl(1);
  91. print ' - '.$tmpproduct->label;
  92. }
  93. // Line extrafield
  94. if (!empty($extrafields)) {
  95. $temps = $line->showOptionals($extrafields, 'view', array(), '', '', 1, 'line');
  96. if (!empty($temps)) {
  97. print '<div style="padding-top: 10px" id="extrafield_lines_area_'.$line->id.'" name="extrafield_lines_area_'.$line->id.'">';
  98. print $temps;
  99. print '</div>';
  100. }
  101. }
  102. print '</td>';
  103. print '<td class="linecolqty nowrap right">';
  104. $coldisplay++;
  105. 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
  106. print '</td>';
  107. if ($filtertype != 1) {
  108. if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
  109. print '<td class="linecoluseunit nowrap left">';
  110. $label = $tmpproduct->getLabelOfUnit('long');
  111. if ($label !== '') {
  112. print $langs->trans($label);
  113. }
  114. print '</td>';
  115. }
  116. print '<td class="linecolqtyfrozen nowrap right">';
  117. $coldisplay++;
  118. echo $line->qty_frozen ? yn($line->qty_frozen) : '';
  119. print '</td>';
  120. print '<td class="linecoldisablestockchange nowrap right">';
  121. $coldisplay++;
  122. 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
  123. print '</td>';
  124. print '<td class="linecolefficiency nowrap right">';
  125. $coldisplay++;
  126. echo $line->efficiency;
  127. print '</td>';
  128. } else {
  129. //Unité
  130. print '<td class="linecolunit nowrap right">';
  131. $coldisplay++;
  132. if (!empty($line->fk_unit)) {
  133. require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
  134. $unit = new CUnits($this->db);
  135. $unit->fetch($line->fk_unit);
  136. print (isset($unit->label) ? "&nbsp;".$langs->trans(ucwords($unit->label))."&nbsp;" : '');
  137. }
  138. print '</td>';
  139. // Work station
  140. if (isModEnabled('workstation')) {
  141. $workstation = new Workstation($object->db);
  142. $res = $workstation->fetch($tmpproduct->fk_default_workstation);
  143. print '<td class="linecolunit nowrap right">';
  144. $coldisplay++;
  145. if ($res > 0) echo $workstation->getNomUrl();
  146. print '</td>';
  147. }
  148. }
  149. $total_cost = 0;
  150. $tmpbom->calculateCosts();
  151. print '<td id="costline_'.$line->id.'" class="linecolcost nowrap right">';
  152. $coldisplay++;
  153. if (!empty($line->fk_bom_child)) {
  154. echo '<span class="amount">'.price($tmpbom->total_cost * $line->qty).'</span>';
  155. } else {
  156. echo '<span class="amount">'.price($line->total_cost).'</span>';
  157. }
  158. print '</td>';
  159. if ($this->status == 0 && ($object_rights->write) && $action != 'selectlines') {
  160. print '<td class="linecoledit center">';
  161. $coldisplay++;
  162. if (($line->info_bits & 2) == 2 || !empty($disableedit)) {
  163. } else {
  164. print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=editline&token='.newToken().'&lineid='.$line->id.'">'.img_edit().'</a>';
  165. }
  166. print '</td>';
  167. print '<td class="linecoldelete center">';
  168. $coldisplay++;
  169. if (($line->fk_prev_id == null) && empty($disableremove)) {
  170. //La suppression n'est autorisée que si il n'y a pas de ligne dans une précédente situation
  171. print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=deleteline&token='.newToken().'&lineid='.$line->id.'">';
  172. print img_delete();
  173. print '</a>';
  174. }
  175. print '</td>';
  176. if ($num > 1 && $conf->browser->layout != 'phone' && empty($disablemove)) {
  177. print '<td class="linecolmove tdlineupdown center">';
  178. $coldisplay++;
  179. if ($i > 0) {
  180. print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=up&token='.newToken().'&rowid='.$line->id.'">';
  181. echo img_up('default', 0, 'imgupforline');
  182. print '</a>';
  183. }
  184. if ($i < $num - 1) {
  185. print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=down&token='.newToken().'&rowid='.$line->id.'">';
  186. echo img_down('default', 0, 'imgdownforline');
  187. print '</a>';
  188. }
  189. print '</td>';
  190. } else {
  191. print '<td '.(($conf->browser->layout != 'phone' && empty($disablemove)) ? ' class="linecolmove tdlineupdown center"' : ' class="linecolmove center"').'></td>';
  192. $coldisplay++;
  193. }
  194. } else {
  195. print '<td colspan="3"></td>';
  196. $coldisplay = $coldisplay + 3;
  197. }
  198. if ($action == 'selectlines') {
  199. print '<td class="linecolcheck center">';
  200. print '<input type="checkbox" class="linecheckbox" name="line_checkbox['.($i + 1).']" value="'.$line->id.'" >';
  201. print '</td>';
  202. }
  203. print '</tr>';
  204. // Select of all the sub-BOM lines
  205. // From this pont to the end of the file, we only take care of sub-BOM lines
  206. $sql = 'SELECT rowid, fk_bom_child, fk_product, qty FROM '.MAIN_DB_PREFIX.'bom_bomline AS bl';
  207. $sql.= ' WHERE fk_bom ='. (int) $tmpbom->id;
  208. $resql = $object->db->query($sql);
  209. if ($resql) {
  210. // Loop on all the sub-BOM lines if they exist
  211. while ($obj = $object->db->fetch_object($resql)) {
  212. $sub_bom_product = new Product($object->db);
  213. $sub_bom_product->fetch($obj->fk_product);
  214. $sub_bom = new BOM($object->db);
  215. if (!empty($obj->fk_bom_child)) {
  216. $sub_bom->fetch($obj->fk_bom_child);
  217. }
  218. $sub_bom_line = new BOMLine($object->db);
  219. $sub_bom_line->fetch($obj->rowid);
  220. //If hidden conf is set, we show directly all the sub-BOM lines
  221. if (empty($conf->global->BOM_SHOW_ALL_BOM_BY_DEFAULT)) {
  222. print '<tr style="display:none" class="sub_bom_lines" parentid="'.$line->id.'">';
  223. } else {
  224. print '<tr class="sub_bom_lines" parentid="'.$line->id.'">';
  225. }
  226. // Product OR BOM
  227. print '<td style="padding-left: 5%" id="sub_bom_product_'.$sub_bom_line->id.'">';
  228. if (!empty($obj->fk_bom_child)) {
  229. print $sub_bom_product->getNomUrl(1);
  230. print ' '.$langs->trans('or').' ';
  231. print $sub_bom->getNomUrl(1);
  232. } else {
  233. print $sub_bom_product->getNomUrl(1);
  234. print '</td>';
  235. }
  236. // Qty
  237. $label = $sub_bom_product->getLabelOfUnit('long');
  238. if ($sub_bom_line->qty_frozen > 0) {
  239. print '<td class="linecolqty nowrap right" id="sub_bom_qty_'.$sub_bom_line->id.'">'.price($sub_bom_line->qty, 0, '', 0, 0).'</td>';
  240. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  241. print '<td class="linecoluseunit nowrap left">';
  242. if ($label !== '') print $langs->trans($label);
  243. print '</td>';
  244. }
  245. print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">'.$langs->trans('Yes').'</td>';
  246. } else {
  247. 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>';
  248. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  249. print '<td class="linecoluseunit nowrap left">';
  250. if ($label !== '') print $langs->trans($label);
  251. print '</td>';
  252. }
  253. print '<td class="linecolqtyfrozen nowrap right" id="sub_bom_qty_frozen_'.$sub_bom_line->id.'">&nbsp;</td>';
  254. }
  255. // Disable stock change
  256. if ($sub_bom_line->disable_stock_change > 0) {
  257. print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">'.$sub_bom_line->disable_stock_change.'</td>';
  258. } else {
  259. print '<td class="linecoldisablestockchange nowrap right" id="sub_bom_stock_change_'.$sub_bom_line->id.'">&nbsp;</td>';
  260. }
  261. // Efficiency
  262. print '<td class="linecolefficiency nowrap right" id="sub_bom_efficiency_'.$sub_bom_line->id.'">'.$sub_bom_line->efficiency.'</td>';
  263. // Cost
  264. if (!empty($sub_bom->id)) {
  265. $sub_bom->calculateCosts();
  266. print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price(price2num($sub_bom->total_cost * $sub_bom_line->qty * $line->qty, 'MT')).'</span></td>';
  267. $total_cost+= $sub_bom->total_cost * $sub_bom_line->qty * $line->qty;
  268. } elseif ($sub_bom_product->cost_price > 0) {
  269. print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price(price2num($sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty, 'MT')).'</span></td>';
  270. $total_cost+= $sub_bom_product->cost_price * $sub_bom_line->qty * $line->qty;
  271. } elseif ($sub_bom_product->pmp > 0) { // PMP if cost price isn't defined
  272. print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price(price2num($sub_bom_product->pmp * $sub_bom_line->qty * $line->qty, 'MT')).'</span></td>';
  273. $total_cost.= $sub_bom_product->pmp * $sub_bom_line->qty * $line->qty;
  274. } else { // Minimum purchase price if cost price and PMP aren't defined
  275. $sql_supplier_price = 'SELECT MIN(price) AS min_price, quantity AS qty FROM '.MAIN_DB_PREFIX.'product_fournisseur_price';
  276. $sql_supplier_price.= ' WHERE fk_product = '. (int) $sub_bom_product->id;
  277. $resql_supplier_price = $object->db->query($sql_supplier_price);
  278. if ($resql_supplier_price) {
  279. $obj = $object->db->fetch_object($resql_supplier_price);
  280. $line_cost = $obj->min_price/$obj->qty * $sub_bom_line->qty * $line->qty;
  281. print '<td class="linecolcost nowrap right" id="sub_bom_cost_'.$sub_bom_line->id.'"><span class="amount">'.price2num($line_cost, 'MT').'</span></td>';
  282. $total_cost+= $line_cost;
  283. }
  284. }
  285. print '<td></td>';
  286. print '<td></td>';
  287. print '<td></td>';
  288. }
  289. }
  290. print "<!-- END PHP TEMPLATE objectline_view.tpl.php -->\n";