objectline_create.tpl.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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)) $filtertype = 0;
  42. if (!empty($object->element) && $object->element == 'contrat' && empty($conf->global->STOCK_SUPPORT_SERVICES)) {
  43. $filtertype = -1;
  44. }
  45. $formproduct = new FormProduct($object->db);
  46. // Define colspan for the button 'Add'
  47. $colspan = 3; // Columns: total ht + col edit + col delete
  48. //print $object->element;
  49. // Lines for extrafield
  50. $objectline = new BOMLine($this->db);
  51. print "<!-- BEGIN PHP TEMPLATE objectline_create.tpl.php -->\n";
  52. $nolinesbefore = (count($this->lines) == 0 || $forcetoshowtitlelines);
  53. if ($nolinesbefore) {
  54. print '<tr class="liste_titre nodrag nodrop">';
  55. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  56. print '<td class="linecolnum center"></td>';
  57. }
  58. print '<td class="linecoldescription minwidth500imp">';
  59. print '<div id="add"></div><span class="hideonsmartphone">'.$langs->trans('AddNewLine').'</span>';
  60. print '</td>';
  61. print '<td class="linecolqty right">'.$langs->trans('Qty').'</td>';
  62. if ($filtertype != 1) {
  63. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  64. print '<td class="linecoluseunit left">';
  65. print '<span id="title_units">';
  66. print $langs->trans('Unit');
  67. print '</span></td>';
  68. }
  69. print '<td class="linecolqtyfrozen right">' . $form->textwithpicto($langs->trans('QtyFrozen'), $langs->trans("QuantityConsumedInvariable")) . '</td>';
  70. print '<td class="linecoldisablestockchange right">' . $form->textwithpicto($langs->trans('DisableStockChange'), $langs->trans('DisableStockChangeHelp')) . '</td>';
  71. print '<td class="linecollost right">' . $form->textwithpicto($langs->trans('ManufacturingEfficiency'), $langs->trans('ValueOfMeansLoss')) . '</td>';
  72. } else {
  73. print '<td class="linecolunit right">' . $form->textwithpicto($langs->trans('Unit'), '').'</td>';
  74. if (isModEnabled('workstation')) print '<td class="linecolworkstation right">' . $form->textwithpicto($langs->trans('Workstation'), '') . '</td>';
  75. print '<td class="linecoltotalcost right">' . $form->textwithpicto($langs->trans('TotalCost'), '') . '</td>';
  76. }
  77. print '<td class="linecoledit" colspan="' . $colspan . '">&nbsp;</td>';
  78. print '</tr>';
  79. }
  80. print '<tr class="pair nodrag nodrop nohoverpair'.(($nolinesbefore || $object->element == 'contrat') ? '' : ' liste_titre_create').'">';
  81. $coldisplay = 0;
  82. // Adds a line numbering column
  83. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  84. $coldisplay++;
  85. echo '<td class="bordertop nobottom linecolnum center"></td>';
  86. }
  87. $coldisplay++;
  88. print '<td class="bordertop nobottom linecoldescription minwidth500imp">';
  89. // Predefined product/service
  90. if (isModEnabled("product") || isModEnabled("service")) {
  91. if ($filtertype == 1) {
  92. print $langs->trans("Service");
  93. } else {
  94. print $langs->trans("Product");
  95. }
  96. echo '<span class="prod_entry_mode_predef">';
  97. $statustoshow = -1;
  98. if (!empty($conf->global->ENTREPOT_EXTRA_STATUS)) {
  99. // hide products in closed warehouse, but show products for internal transfer
  100. $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'));
  101. } else {
  102. $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'));
  103. }
  104. echo '</span>';
  105. }
  106. if (!empty($conf->global->BOM_SUB_BOM) && $filtertype!=1) {
  107. print '<br><span class="opacitymedium">'.$langs->trans("or").'</span><br>'.$langs->trans("BOM");
  108. // TODO Add component to select a BOM
  109. $form->select_bom();
  110. }
  111. if (is_object($objectline)) {
  112. $temps = $objectline->showOptionals($extrafields, 'create', array(), '', '', 1, 'line');
  113. if (!empty($temps)) {
  114. print '<div style="padding-top: 10px" id="extrafield_lines_area_create" name="extrafield_lines_area_create">';
  115. print $temps;
  116. print '</div>';
  117. }
  118. }
  119. print '</td>';
  120. $coldisplay++;
  121. 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).'">';
  122. print '</td>';
  123. if ($filtertype != 1) {
  124. if (!empty($conf->global->PRODUCT_USE_UNITS)) {
  125. $coldisplay++;
  126. print '<td class="nobottom linecoluseunit left">';
  127. print '</td>';
  128. }
  129. $coldisplay++;
  130. 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"' : '') . '>';
  131. print '</td>';
  132. $coldisplay++;
  133. 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"' : '') . '">';
  134. print '</td>';
  135. $coldisplay++;
  136. print '<td class="bordertop nobottom nowrap linecollost right">';
  137. print '<input type="text" size="2" name="efficiency" id="efficiency" class="flat right" value="' . ((GETPOSTISSET("efficiency") && $action == 'addline') ? GETPOST("efficiency", 'alpha') : 1) . '">';
  138. print '</td>';
  139. $coldisplay++;
  140. print '<td class="bordertop nobottom nowrap linecolcost right">';
  141. print '&nbsp;';
  142. print '</td>';
  143. } else {
  144. $coldisplay++;
  145. require_once DOL_DOCUMENT_ROOT.'/core/class/cunits.class.php';
  146. $cUnit = new CUnits($this->db);
  147. $fk_unit_default = $cUnit->getUnitFromCode('h', 'short_label', 'time');
  148. print '<td class="bordertop nobottom nowrap linecolunit right">';
  149. print $formproduct->selectMeasuringUnits("fk_unit", "time", $fk_unit_default, 0, 0);
  150. print '</td>';
  151. $coldisplay++;
  152. print '<td class="bordertop nobottom nowrap linecolworkstation right">';
  153. print '&nbsp;';
  154. print '</td>';
  155. $coldisplay++;
  156. print '<td class="bordertop nobottom nowrap linecolcost right">';
  157. print '&nbsp;';
  158. print '</td>';
  159. }
  160. $coldisplay += $colspan;
  161. print '<td class="bordertop nobottom linecoledit center valignmiddle" colspan="' . $colspan . '">';
  162. print '<input type="submit" class="button button-add" name="addline" id="addline" value="' . $langs->trans('Add') . '">';
  163. print '</td>';
  164. print '</tr>';
  165. if (is_object($objectline)) {
  166. print $objectline->showOptionals($extrafields, 'edit', array('style'=>$bcnd[$var], 'colspan'=>$coldisplay), '', '', 1, 'line');
  167. }
  168. ?>
  169. <script>
  170. /* JQuery for product free or predefined select */
  171. jQuery(document).ready(function() {
  172. /* When changing predefined product, we reload list of supplier prices required for margin combo */
  173. $("#idprod").change(function()
  174. {
  175. console.log("#idprod change triggered");
  176. /* To set focus */
  177. if (jQuery('#idprod').val() > 0)
  178. {
  179. /* focus work on a standard textarea but not if field was replaced with CKEDITOR */
  180. jQuery('#dp_desc').focus();
  181. /* focus if CKEDITOR */
  182. if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
  183. {
  184. var editor = CKEDITOR.instances['dp_desc'];
  185. if (editor) { editor.focus(); }
  186. }
  187. }
  188. });
  189. //change unit selected if we change service selected
  190. <?php if ($filtertype == 1) { ?>
  191. $('#idprodservice').change(function(){
  192. var idproduct = $(this).val();
  193. $.ajax({
  194. url : "<?php echo dol_buildpath('/bom/ajax/ajax.php', 1); ?>"
  195. ,type: 'POST'
  196. ,data: {
  197. 'action': 'getDurationUnitByProduct'
  198. ,'idproduct' : idproduct
  199. }
  200. }).done(function(data) {
  201. console.log(data);
  202. var data = JSON.parse(data);
  203. $("#fk_unit").val(data).change();
  204. });
  205. });
  206. <?php } ?>
  207. });
  208. </script>
  209. <!-- END PHP TEMPLATE objectline_create.tpl.php -->