objectline_view.tpl.php 13 KB

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