stockcorrection.tpl.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. /* Copyright (C) 2010-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  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. * $object must be defined
  19. * $backtopage
  20. */
  21. // Protection to avoid direct call of template
  22. if (empty($conf) || !is_object($conf)) {
  23. print "Error, template page can't be called as URL";
  24. exit;
  25. }
  26. ?>
  27. <!-- BEGIN PHP TEMPLATE STOCKCORRECTION.TPL.PHP -->
  28. <?php
  29. $productref = '';
  30. if ($object->element == 'product') {
  31. $productref = $object->ref;
  32. }
  33. $langs->load("productbatch");
  34. if (empty($id)) {
  35. $id = $object->id;
  36. }
  37. $pdluoid = GETPOST('pdluoid', 'int');
  38. $pdluo = new Productbatch($db);
  39. if ($pdluoid > 0) {
  40. $result = $pdluo->fetch($pdluoid);
  41. if ($result > 0) {
  42. $pdluoid = $pdluo->id;
  43. } else {
  44. dol_print_error($db, $pdluo->error, $pdluo->errors);
  45. }
  46. }
  47. print '<script type="text/javascript">
  48. jQuery(document).ready(function() {
  49. function init_price()
  50. {
  51. if (jQuery("#mouvement").val() == \'0\') jQuery("#unitprice").removeAttr("disabled");
  52. else jQuery("#unitprice").prop("disabled", true);
  53. }
  54. init_price();
  55. jQuery("#mouvement").change(function() {
  56. console.log("We change the direction of movement");
  57. init_price();
  58. });
  59. jQuery("#nbpiece").keyup(function(event) {
  60. console.log("We enter a qty on "+event.key);
  61. if ( event.key == "-" ) { /* char - */
  62. console.log("We set direction to value 1");
  63. jQuery("#nbpiece").val(jQuery("#nbpiece").val().replace("-", ""));
  64. jQuery("#mouvement option").removeAttr("selected").change();
  65. jQuery("#mouvement option[value=1]").attr("selected","selected").trigger("change");
  66. jQuery("#mouvement").trigger("change");
  67. } else if ( event.key == "+" ) { /* char + */
  68. console.log("We set direction to value 0");
  69. jQuery("#nbpiece").val(jQuery("#nbpiece").val().replace("+", ""));
  70. jQuery("#mouvement option").removeAttr("selected").change();
  71. jQuery("#mouvement option[value=0]").attr("selected","selected").trigger("change");
  72. jQuery("#mouvement").trigger("change");
  73. }
  74. });
  75. });
  76. </script>';
  77. print load_fiche_titre($langs->trans("StockCorrection"), '', 'generic');
  78. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
  79. print dol_get_fiche_head();
  80. print '<input type="hidden" name="token" value="'.newToken().'">';
  81. print '<input type="hidden" name="action" value="correct_stock">';
  82. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  83. if ($pdluoid) {
  84. print '<input type="hidden" name="pdluoid" value="'.$pdluoid.'">';
  85. }
  86. print '<table class="border centpercent">';
  87. // Warehouse or product
  88. print '<tr>';
  89. if ($object->element == 'product') {
  90. print '<td class="fieldrequired">'.$langs->trans("Warehouse").'</td>';
  91. print '<td>';
  92. $ident = (GETPOST("dwid") ? GETPOST("dwid", 'int') : (GETPOST('id_entrepot') ? GETPOST('id_entrepot', 'int') : ($object->element == 'product' && $object->fk_default_warehouse ? $object->fk_default_warehouse : 'ifone')));
  93. if (empty($ident) && getDolGlobalString('MAIN_DEFAULT_WAREHOUSE')) {
  94. $ident = $conf->global->MAIN_DEFAULT_WAREHOUSE;
  95. }
  96. print img_picto('', 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($ident, 'id_entrepot', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'minwidth100 maxwidth300 widthcentpercentminusx');
  97. print '</td>';
  98. }
  99. if ($object->element == 'stock') {
  100. print '<td class="fieldrequired">'.$langs->trans("Product").'</td>';
  101. print '<td>';
  102. print img_picto('', 'product');
  103. $form->select_produits(GETPOST('product_id', 'int'), 'product_id', (!getDolGlobalString('STOCK_SUPPORTS_SERVICES') ? '0' : ''), 0, 0, -1, 2, '', 0, null, 0, 1, 0, 'maxwidth500');
  104. print '</td>';
  105. }
  106. print '<td class="fieldrequired">'.$langs->trans("NumberOfUnit").'</td>';
  107. print '<td>';
  108. if ($object->element == 'product' || $object->element == 'stock') {
  109. print '<select name="mouvement" id="mouvement" class="minwidth100 valignmiddle">';
  110. print '<option value="0">'.$langs->trans("Add").'</option>';
  111. print '<option value="1"'.(GETPOST('mouvement') ? ' selected="selected"' : '').'>'.$langs->trans("Delete").'</option>';
  112. print '</select>';
  113. print ajax_combobox("mouvement");
  114. }
  115. print '<input name="nbpiece" id="nbpiece" class="center valignmiddle maxwidth75" value="'.GETPOST("nbpiece").'">';
  116. print '</td>';
  117. print '</tr>';
  118. // If product is a Kit, we ask if we must disable stock change of subproducts
  119. if (getDolGlobalString('PRODUIT_SOUSPRODUITS') && $object->element == 'product' && $object->hasFatherOrChild(1)) {
  120. print '<tr>';
  121. print '<td></td>';
  122. print '<td colspan="3">';
  123. print '<input type="checkbox" name="disablesubproductstockchange" id="disablesubproductstockchange" value="1"'.(GETPOST('disablesubproductstockchange') ? ' checked="checked"' : '').'">';
  124. print ' <label for="disablesubproductstockchange">'.$langs->trans("DisableStockChangeOfSubProduct").'</label>';
  125. print '</td>';
  126. print '</tr>';
  127. }
  128. // Serial / Eat-by date
  129. if (ismodEnabled('productbatch') &&
  130. (($object->element == 'product' && $object->hasbatch())
  131. || ($object->element == 'stock'))
  132. ) {
  133. print '<tr>';
  134. print '<td'.($object->element == 'stock' ? '' : ' class="fieldrequired"').'>'.$langs->trans("batch_number").'</td><td colspan="3">';
  135. if ($pdluoid > 0) {
  136. // If form was opened for a specific pdluoid, field is disabled
  137. print '<input type="text" name="batch_number_bis" size="40" disabled="disabled" value="'.(GETPOST('batch_number') ? GETPOST('batch_number') : $pdluo->batch).'">';
  138. print '<input type="hidden" name="batch_number" value="'.(GETPOST('batch_number') ? GETPOST('batch_number') : $pdluo->batch).'">';
  139. } else {
  140. print img_picto('', 'barcode', 'class="pictofixedwidth"').'<input type="text" name="batch_number" class="minwidth300" value="'.(GETPOST('batch_number') ? GETPOST('batch_number') : $pdluo->batch).'">';
  141. }
  142. print '</td>';
  143. print '</tr>';
  144. print '<tr>';
  145. if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
  146. print '<td>'.$langs->trans("SellByDate").'</td><td>';
  147. $sellbyselected = dol_mktime(0, 0, 0, GETPOST('sellbymonth'), GETPOST('sellbyday'), GETPOST('sellbyyear'));
  148. // If form was opened for a specific pdluoid, field is disabled
  149. print $form->selectDate(($pdluo->id > 0 ? $pdluo->sellby : $sellbyselected), 'sellby', '', '', 1, "", 1, 0, ($pdluoid > 0 ? 1 : 0));
  150. print '</td>';
  151. }
  152. if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
  153. print '<td>'.$langs->trans("EatByDate").'</td><td>';
  154. $eatbyselected = dol_mktime(0, 0, 0, GETPOST('eatbymonth'), GETPOST('eatbyday'), GETPOST('eatbyyear'));
  155. // If form was opened for a specific pdluoid, field is disabled
  156. print $form->selectDate(($pdluo->id > 0 ? $pdluo->eatby : $eatbyselected), 'eatby', '', '', 1, "", 1, 0, ($pdluoid > 0 ? 1 : 0));
  157. print '</td>';
  158. }
  159. print '</tr>';
  160. }
  161. // Purchase price and project
  162. print '<tr>';
  163. print '<td>'.$langs->trans("UnitPurchaseValue").'</td>';
  164. print '<td colspan="'.(isModEnabled('project') ? '1' : '3').'"><input name="unitprice" id="unitprice" size="10" value="'.GETPOST("unitprice").'"></td>';
  165. if (isModEnabled('project')) {
  166. print '<td>'.$langs->trans('Project').'</td>';
  167. print '<td>';
  168. print img_picto('', 'project');
  169. $formproject->select_projects(-1, '', 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, 'maxwidth300 widthcentpercentminusx');
  170. print '</td>';
  171. }
  172. print '</tr>';
  173. // Label of mouvement of id of inventory
  174. $valformovementlabel = ((GETPOST("label") && (GETPOST('label') != $langs->trans("MovementCorrectStock", ''))) ? GETPOST("label") : $langs->trans("MovementCorrectStock", $productref));
  175. print '<tr>';
  176. print '<td>'.$langs->trans("MovementLabel").'</td>';
  177. print '<td>';
  178. print '<input type="text" name="label" class="minwidth400" value="'.dol_escape_htmltag($valformovementlabel).'">';
  179. print '</td>';
  180. print '<td>'.$langs->trans("InventoryCode").'</td>';
  181. print '<td>';
  182. print '<input class="maxwidth100onsmartphone" name="inventorycode" id="inventorycode" value="'.(GETPOSTISSET("inventorycode") ? GETPOST("inventorycode", 'alpha') : dol_print_date(dol_now(), '%Y%m%d%H%M%S')).'">';
  183. print '</td>';
  184. print '</tr>';
  185. print '</table>';
  186. print dol_get_fiche_end();
  187. print '<div class="center">';
  188. print '<input type="submit" class="button button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  189. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  190. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  191. print '</div>';
  192. print '</form>';
  193. ?>
  194. <!-- END PHP STOCKCORRECTION.TPL.PHP -->