objectline_create.tpl.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. /* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
  3. * Copyright (C) 2010-2014 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) 2014 Florian Henry <florian.henry@open-concept.pro>
  7. * Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  8. * Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
  10. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. *
  25. * Need to have following variables defined:
  26. * $object (invoice, order, ...)
  27. * $conf
  28. * $langs
  29. * $forceall (0 by default, 1 for supplier invoices/orders)
  30. */
  31. require_once DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php";
  32. // Protection to avoid direct call of template
  33. if (empty($object) || !is_object($object)) {
  34. print "Error: this template page cannot be called directly as an URL";
  35. exit;
  36. }
  37. global $forceall, $forcetoshowtitlelines, $filtertype;
  38. if (empty($forceall)) {
  39. $forceall = 0;
  40. }
  41. if (empty($filtertype)) {
  42. $filtertype = 0;
  43. }
  44. if (!empty($object->element) && $object->element == 'contrat' && !getDolGlobalString('STOCK_SUPPORT_SERVICES')) {
  45. $filtertype = -1;
  46. }
  47. $formproduct = new FormProduct($object->db);
  48. // Define colspan for the button 'Add'
  49. $colspan = 3; // Columns: total ht + col edit + col delete
  50. //print $object->element;
  51. // Lines for extrafield
  52. $objectline = new BOMLine($this->db);
  53. print "<!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->\n";
  54. $nolinesbefore = (count($this->lines) == 0 || $forcetoshowtitlelines);
  55. if ($nolinesbefore) {
  56. print '<tr class="liste_titre nodrag nodrop">';
  57. if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
  58. print '<td class="linecolnum center"></td>';
  59. }
  60. print '<td class="linecoldescription minwidth500imp">';
  61. print '<div id="add"></div><span class="hideonsmartphone">'.$langs->trans('AddNewLine').'</span>';
  62. print '</td>';
  63. print '<td class="linecolqty right">'.$langs->trans('Qty').'</td>';
  64. if ($filtertype != 1) {
  65. if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
  66. print '<td class="linecoluseunit left">';
  67. print '<span id="title_units">';
  68. print $langs->trans('Unit');
  69. print '</span></td>';
  70. }
  71. print '<td class="linecolqtyfrozen right">' . $form->textwithpicto($langs->trans('QtyFrozen'), $langs->trans("QuantityConsumedInvariable")) . '</td>';
  72. print '<td class="linecoldisablestockchange right">' . $form->textwithpicto($langs->trans('DisableStockChange'), $langs->trans('DisableStockChangeHelp')) . '</td>';
  73. print '<td class="linecollost right">' . $form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('ValueOfMeansLoss')) . '</td>';
  74. } else {
  75. print '<td class="linecolunit right">' . $form->textwithpicto($langs->trans('Unit'), '').'</td>';
  76. if (isModEnabled('workstation')) {
  77. print '<td class="linecolworkstation right">' . $form->textwithpicto($langs->trans('Workstation'), '') . '</td>';
  78. }
  79. print '<td class="linecoltotalcost right">' . $form->textwithpicto($langs->trans('TotalCost'), '') . '</td>';
  80. }
  81. print '<td class="linecoledit" colspan="' . $colspan . '">&nbsp;</td>';
  82. print '</tr>';
  83. }
  84. print '<tr class="pair nodrag nodrop nohoverpair'.(($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_create').'">';
  85. $coldisplay = 0;
  86. // Adds a line numbering column
  87. if (getDolGlobalString('MAIN_VIEW_LINE_NUMBER')) {
  88. $coldisplay++;
  89. echo '<td class="bordertop nobottom linecolnum center"></td>';
  90. }
  91. $coldisplay++;
  92. print '<td class="bordertop nobottom linecoldescription minwidth500imp">';
  93. // Predefined product/service
  94. if (isModEnabled("product") || isModEnabled("service")) {
  95. if ($filtertype == 1) {
  96. print $langs->trans("Service");
  97. } else {
  98. print $langs->trans("Product");
  99. }
  100. echo '<span class="prod_entry_mode_predef">';
  101. $statustoshow = -1;
  102. if (getDolGlobalString('ENTREPOT_EXTRA_STATUS')) {
  103. // hide products in closed warehouse, but show products for internal transfer
  104. print $form->select_produits(GETPOST('idprod', 'int'), (($filtertype == 1) ? 'idprodservice' : 'idprod'), $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, 'warehouseopen,warehouseinternal', GETPOST('combinations', 'array'), 1);
  105. } else {
  106. print $form->select_produits(GETPOST('idprod', 'int'), (($filtertype == 1) ? 'idprodservice' : 'idprod'), $filtertype, $conf->product->limit_size, $buyer->price_level, $statustoshow, 2, '', 1, array(), $buyer->id, '1', 0, 'maxwidth500', 0, '', GETPOST('combinations', 'array'), 1);
  107. }
  108. $urltocreateproduct = DOL_URL_ROOT.'/product/card.php?action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id);
  109. print '<a href="'.$urltocreateproduct.'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProduct").'"></span></a>';
  110. echo '</span>';
  111. }
  112. if (getDolGlobalString('BOM_SUB_BOM') && $filtertype != 1) {
  113. print '<br><span class="opacitymedium">'.$langs->trans("or").'</span><br>'.$langs->trans("BOM");
  114. print $form->select_bom('', 'bom_id', 0, 1, 0, '1', '', 1);
  115. }
  116. if (is_object($objectline)) {
  117. $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
  118. if (!empty($temps)) {
  119. print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
  120. print $temps;
  121. print '</div>';
  122. }
  123. }
  124. print '</td>';
  125. $coldisplay++;
  126. print '<td class="bordertop nobottom linecolqty right"><input type="text" size="2" name="qty" id="qty" class="flat right" value="'.(GETPOSTISSET("qty") ? GETPOST("qty", 'alpha', 2) : 1).'">';
  127. print '</td>';
  128. if ($filtertype != 1) {
  129. if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
  130. $coldisplay++;
  131. print '<td class="nobottom linecoluseunit left">';
  132. print '</td>';
  133. }
  134. $coldisplay++;
  135. print '<td class="bordertop nobottom linecolqtyfrozen right"><input type="checkbox" name="qty_frozen" id="qty_frozen" class="flat right" value="1"' . (GETPOST("qty_frozen", 'alpha') ? ' checked="checked"' : '') . '>';
  136. print '</td>';
  137. $coldisplay++;
  138. print '<td class="bordertop nobottom linecoldisablestockchange right"><input type="checkbox" name="disable_stock_change" id="disable_stock_change" class="flat right" value="1"' . (GETPOST("disable_stock_change", 'alpha') ? ' checked="checked"' : '') . '">';
  139. print '</td>';
  140. $coldisplay++;
  141. print '<td class="bordertop nobottom nowrap linecollost right">';
  142. print '<input type="text" size="2" name="efficiency" id="efficiency" class="flat right" value="' . ((GETPOSTISSET("efficiency") && $action == 'addline') ? GETPOST("efficiency", 'alpha') : 1) . '">';
  143. print '</td>';
  144. $coldisplay++;
  145. print '<td class="bordertop nobottom nowrap linecolcost right">';
  146. print '&nbsp;';
  147. print '</td>';
  148. } else {
  149. $coldisplay++;
  150. require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
  151. $cUnit = new CUnits($this->db);
  152. $fk_unit_default = $cUnit->getUnitFromCode('h', 'short_label', 'time');
  153. print '<td class="bordertop nobottom nowrap linecolunit right">';
  154. print $formproduct->selectMeasuringUnits("fk_unit", "time", $fk_unit_default, 0, 0);
  155. print '</td>';
  156. $coldisplay++;
  157. print '<td class="bordertop nobottom nowrap linecolworkstation right">';
  158. print '&nbsp;';
  159. print '</td>';
  160. $coldisplay++;
  161. print '<td class="bordertop nobottom nowrap linecolcost right">';
  162. print '&nbsp;';
  163. print '</td>';
  164. }
  165. $coldisplay += $colspan;
  166. print '<td class="bordertop nobottom linecoledit center valignmiddle" colspan="' . $colspan . '">';
  167. print '<input type="submit" class="button button-add" name="addline" id="addline" value="' . $langs->trans('Add') . '">';
  168. print '</td>';
  169. print '</tr>';
  170. ?>
  171. <script>
  172. /* JQuery for product free or predefined select */
  173. jQuery(document).ready(function() {
  174. /* When changing predefined product, we reload list of supplier prices required for margin combo */
  175. $("#idprod").change(function()
  176. {
  177. console.log("#idprod change triggered");
  178. /* To set focus */
  179. if (jQuery('#idprod').val() > 0)
  180. {
  181. /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
  182. jQuery('#dp_desc').focus();
  183. /* focus if CKEDITOR */
  184. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  185. {
  186. var editor = CKEDITOR.instances['dp_desc'];
  187. if (editor) { editor.focus(); }
  188. }
  189. }
  190. });
  191. //change unit selected if we change service selected
  192. <?php if ($filtertype == 1) { ?>
  193. $('#idprodservice').change(function(){
  194. var idproduct = $(this).val();
  195. $.ajax({
  196. url : "<?php echo dol_buildpath('/bom/ajax/ajax.php', 1); ?>"
  197. ,type: 'POST'
  198. ,data: {
  199. 'action': 'getDurationUnitByProduct'
  200. ,'idproduct' : idproduct
  201. }
  202. }).done(function(data) {
  203. console.log(data);
  204. var data = JSON.parse(data);
  205. $("#fk_unit").val(data).change();
  206. });
  207. });
  208. <?php } ?>
  209. });
  210. </script>
  211. <!-- END PHP TEMPLATE objectline_create.tpl.php -->