stockcorrection.tpl.php 8.9 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.which);
  61. if ( event.which == 54 ) { /* 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.which == 187 ) { /* char + */
  68. console.log("We set direction to value 0");
  69. jQuery("#mouvement option").removeAttr("selected").change();
  70. jQuery("#mouvement option[value=0]").attr("selected","selected").trigger("change");
  71. jQuery("#mouvement").trigger("change");
  72. }
  73. });
  74. });
  75. </script>';
  76. print load_fiche_titre($langs->trans("StockCorrection"), '', 'generic');
  77. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">'."\n";
  78. print dol_get_fiche_head();
  79. print '<input type="hidden" name="token" value="'.newToken().'">';
  80. print '<input type="hidden" name="action" value="correct_stock">';
  81. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  82. if ($pdluoid) {
  83. print '<input type="hidden" name="pdluoid" value="'.$pdluoid.'">';
  84. }
  85. print '<table class="border centpercent">';
  86. // Warehouse or product
  87. print '<tr>';
  88. if ($object->element == 'product') {
  89. print '<td class="fieldrequired">'.$langs->trans("Warehouse").'</td>';
  90. print '<td>';
  91. $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')));
  92. if (empty($ident) && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE)) {
  93. $ident = $conf->global->MAIN_DEFAULT_WAREHOUSE;
  94. }
  95. print img_picto('', 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($ident, 'id_entrepot', 'warehouseopen,warehouseinternal', 1, 0, 0, '', 0, 0, null, 'minwidth100 maxwidth300 widthcentpercentminusx');
  96. print '</td>';
  97. }
  98. if ($object->element == 'stock') {
  99. print '<td class="fieldrequired">'.$langs->trans("Product").'</td>';
  100. print '<td>';
  101. print img_picto('', 'product');
  102. $form->select_produits(GETPOST('product_id', 'int'), 'product_id', (empty($conf->global->STOCK_SUPPORTS_SERVICES) ? '0' : ''), 0, 0, -1, 2, '', 0, null, 0, 1, 0, 'maxwidth500');
  103. print '</td>';
  104. }
  105. print '<td class="fieldrequired">'.$langs->trans("NumberOfUnit").'</td>';
  106. print '<td>';
  107. if ($object->element == 'product' || $object->element == 'stock') {
  108. print '<select name="mouvement" id="mouvement" class="minwidth100 valignmiddle">';
  109. print '<option value="0">'.$langs->trans("Add").'</option>';
  110. print '<option value="1"'.(GETPOST('mouvement') ? ' selected="selected"' : '').'>'.$langs->trans("Delete").'</option>';
  111. print '</select>';
  112. print ajax_combobox("mouvement");
  113. }
  114. print '<input name="nbpiece" id="nbpiece" class="center valignmiddle maxwidth75" value="'.GETPOST("nbpiece").'">';
  115. print '</td>';
  116. print '</tr>';
  117. // If product is a Kit, we ask if we must disable stock change of subproducts
  118. if (!empty($conf->global->PRODUIT_SOUSPRODUITS) && $object->element == 'product' && $object->hasFatherOrChild(1)) {
  119. print '<tr>';
  120. print '<td></td>';
  121. print '<td colspan="3">';
  122. print '<input type="checkbox" name="disablesubproductstockchange" id="disablesubproductstockchange" value="1"'.(GETPOST('disablesubproductstockchange') ? ' checked="checked"' : '').'">';
  123. print ' <label for="disablesubproductstockchange">'.$langs->trans("DisableStockChangeOfSubProduct").'</label>';
  124. print '</td>';
  125. print '</tr>';
  126. }
  127. // Serial / Eat-by date
  128. if (ismodEnabled('productbatch') &&
  129. (($object->element == 'product' && $object->hasbatch())
  130. || ($object->element == 'stock'))
  131. ) {
  132. print '<tr>';
  133. print '<td'.($object->element == 'stock' ? '' : ' class="fieldrequired"').'>'.$langs->trans("batch_number").'</td><td colspan="3">';
  134. if ($pdluoid > 0) {
  135. // If form was opened for a specific pdluoid, field is disabled
  136. print '<input type="text" name="batch_number_bis" size="40" disabled="disabled" value="'.(GETPOST('batch_number') ?GETPOST('batch_number') : $pdluo->batch).'">';
  137. print '<input type="hidden" name="batch_number" value="'.(GETPOST('batch_number') ?GETPOST('batch_number') : $pdluo->batch).'">';
  138. } else {
  139. print img_picto('', 'barcode', 'class="pictofixedwidth"').'<input type="text" name="batch_number" class="minwidth300" value="'.(GETPOST('batch_number') ? GETPOST('batch_number') : $pdluo->batch).'">';
  140. }
  141. print '</td>';
  142. print '</tr>';
  143. print '<tr>';
  144. if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
  145. print '<td>'.$langs->trans("SellByDate").'</td><td>';
  146. $sellbyselected = dol_mktime(0, 0, 0, GETPOST('sellbymonth'), GETPOST('sellbyday'), GETPOST('sellbyyear'));
  147. // If form was opened for a specific pdluoid, field is disabled
  148. print $form->selectDate(($pdluo->id > 0 ? $pdluo->sellby : $sellbyselected), 'sellby', '', '', 1, "", 1, 0, ($pdluoid > 0 ? 1 : 0));
  149. print '</td>';
  150. }
  151. if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
  152. print '<td>'.$langs->trans("EatByDate").'</td><td>';
  153. $eatbyselected = dol_mktime(0, 0, 0, GETPOST('eatbymonth'), GETPOST('eatbyday'), GETPOST('eatbyyear'));
  154. // If form was opened for a specific pdluoid, field is disabled
  155. print $form->selectDate(($pdluo->id > 0 ? $pdluo->eatby : $eatbyselected), 'eatby', '', '', 1, "", 1, 0, ($pdluoid > 0 ? 1 : 0));
  156. print '</td>';
  157. }
  158. print '</tr>';
  159. }
  160. // Purchase price and project
  161. print '<tr>';
  162. print '<td>'.$langs->trans("UnitPurchaseValue").'</td>';
  163. print '<td colspan="'.(!empty($conf->project->enabled) ? '1' : '3').'"><input name="unitprice" id="unitprice" size="10" value="'.GETPOST("unitprice").'"></td>';
  164. if (!empty($conf->project->enabled)) {
  165. print '<td>'.$langs->trans('Project').'</td>';
  166. print '<td>';
  167. print img_picto('', 'project');
  168. $formproject->select_projects(-1, '', 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, 'maxwidth300 widthcentpercentminusx');
  169. print '</td>';
  170. }
  171. print '</tr>';
  172. // Label of mouvement of id of inventory
  173. $valformovementlabel = ((GETPOST("label") && (GETPOST('label') != $langs->trans("MovementCorrectStock", ''))) ? GETPOST("label") : $langs->trans("MovementCorrectStock", $productref));
  174. print '<tr>';
  175. print '<td>'.$langs->trans("MovementLabel").'</td>';
  176. print '<td>';
  177. print '<input type="text" name="label" class="minwidth400" value="'.dol_escape_htmltag($valformovementlabel).'">';
  178. print '</td>';
  179. print '<td>'.$langs->trans("InventoryCode").'</td>';
  180. print '<td>';
  181. 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')).'">';
  182. print '</td>';
  183. print '</tr>';
  184. print '</table>';
  185. print dol_get_fiche_end();
  186. print '<div class="center">';
  187. print '<input type="submit" class="button button-save" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
  188. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  189. print '<input type="submit" class="button button-cancel" name="cancel" value="'.dol_escape_htmltag($langs->trans("Cancel")).'">';
  190. print '</div>';
  191. print '</form>';
  192. ?>
  193. <!-- END PHP STOCKCORRECTION.TPL.PHP -->