new.html.erb 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <!-- BEGIN CONTAINER -->
  2. <div class="page-container">
  3. <!-- BEGIN CONTENT -->
  4. <div class="page-content-wrapper">
  5. <!-- BEGIN CONTENT BODY -->
  6. <!-- BEGIN PAGE HEAD-->
  7. <div class="page-head">
  8. <div class="container-fluid">
  9. <!-- BEGIN PAGE TITLE -->
  10. <div class="page-title">
  11. <h1>Merma de productos</h1>
  12. </div>
  13. <!-- END PAGE TITLE -->
  14. </div>
  15. </div>
  16. <!-- END PAGE HEAD-->
  17. <!-- BEGIN PAGE CONTENT BODY -->
  18. <div class="page-content">
  19. <div class="container-fluid">
  20. <%= link_to product_wastes_path, {:class=>"btn blue-hoki pull-right margin-bottom-10"} do %> <i class="fa fa-angle-left "></i> Regresar
  21. <% end %>
  22. <!-- BEGIN PAGE BREADCRUMBS -->
  23. <ul class="page-breadcrumb breadcrumb">
  24. <%= render_breadcrumbs :tag => :li, :separator => ' <i class="fa fa-circle"></i> ' %>
  25. </ul>
  26. <!-- END PAGE BREADCRUMBS -->
  27. <!-- BEGIN PAGE CONTENT INNER -->
  28. <div class="page-content-inner">
  29. <div id="notice"><%= notice %></div>
  30. <div class="row">
  31. <div class="col-md-12">
  32. <div class="portlet light">
  33. <div class="portlet-title">
  34. <div class="caption">
  35. <i class="fa fa-plus font-green"></i>
  36. <span class="caption-subject font-green bold uppercase">Resgistro de merma de productos</span>
  37. <span class="caption-helper"></span>
  38. </div>
  39. </div>
  40. <div class="portlet-body form form-horizontal">
  41. <div id="error_explanation"></div>
  42. <div class="form-body">
  43. <h4 class="form-section"> Agregar producto</h4>
  44. <div class="row">
  45. <div class="col-md-12">
  46. <div class="form-group">
  47. <%= label_tag "product", {:class=>"col-md-3 control-label"} do %>Producto <span class="required">*</span>
  48. <% end %>
  49. <div class="col-md-6">
  50. <input class="form-control" type="text" id="typeahead">
  51. </div>
  52. </div>
  53. <div class="form-group">
  54. <%= label_tag "quantity", {:class=>"col-md-3 control-label"} do %>Cantidad mermada <span class="required">*</span>
  55. <% end %>
  56. <div class="col-md-9">
  57. <%= number_field_tag "quantity", "", class: 'form-control input-small' %>
  58. </div>
  59. </div>
  60. <div class="form-group">
  61. <%= label_tag "reason", {:class=>"col-md-3 control-label"} do %> Motivo <span class="required">*</span>
  62. <% end %>
  63. <div class="col-md-6">
  64. <%= text_area_tag "reason", "", class: 'form-control', rows: 5 %>
  65. </div>
  66. </div>
  67. <div class="form-group">
  68. <div class="col-md-offset-3 col-md-9">
  69. <button id="products_new" disabled class="btn btn-success" type="button" onclick="addRow()"> Agregar <i class="fa fa-plus"></i> </button>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. <!-- lista de productos -->
  75. <div class='row'>
  76. <div class="col-md-12">
  77. <h4 class="form-section"> Lista de productos a mermar</h4>
  78. <table class="table table-striped table-bordered table-hover tableadvanced" id="products_table">
  79. <thead>
  80. <tr>
  81. <th>#</th>
  82. <th>SKU</th>
  83. <th>Producto</th>
  84. <th>Stock anterior</th>
  85. <th>Merma</th>
  86. <th>Stock actual</th>
  87. <th>Motivo</th>
  88. <th>Acciones</th>
  89. </tr>
  90. </thead>
  91. <tbody>
  92. </tbody>
  93. </table>
  94. <%= render 'form' %>
  95. </div>
  96. </div>
  97. </div>
  98. <div class="form-actions">
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. <script type="text/javascript">
  111. var timeout = null;
  112. var selectedProduct;
  113. // initialize bloodhound engine
  114. var bloodhound = new Bloodhound({
  115. datumTokenizer: function (d) {
  116. return Bloodhound.tokenizers.whitespace(d.value);
  117. },
  118. queryTokenizer: Bloodhound.tokenizers.whitespace,
  119. remote: {
  120. url: '/find_products_from_stock?query=%QUERY',
  121. wildcard: '%QUERY'
  122. }
  123. });
  124. bloodhound.initialize();
  125. $('#typeahead').typeahead(
  126. {
  127. minLength: 3
  128. },
  129. {
  130. displayKey: 'name',
  131. source: bloodhound.ttAdapter(),
  132. limit: Infinity,
  133. templates: {
  134. empty: [
  135. '<div class="empty-message">',
  136. 'No se encontró ningun producto. Favor de verificar',
  137. '</div>'
  138. ].join('\n'),
  139. suggestion: Handlebars.compile(
  140. '<div class="media">' +
  141. '<div class="pull-left">' +
  142. '<div class="media-object">' +
  143. '<img src="{{small_img}}" width="50" height="50"/>' +
  144. '</div>' +
  145. '</div>' +
  146. '<div class="media-body">' +
  147. '<h4 class="media-heading"><strong>{{name}}</strong> | {{sku}}</h4>' +
  148. '<p>{{barcode}}</p>' +
  149. '<p>{{description}}</p>' +
  150. '<p>{{display_attributes}}</p>' +
  151. '</div>' +
  152. '</div>')
  153. }
  154. });
  155. // this is the event that is fired when a user clicks on a suggestion
  156. $('#typeahead').bind('typeahead:selected', function(event, datum, name) {
  157. selectedProduct = datum;
  158. $('#products_new').attr('disabled', false);
  159. });
  160. function addRow() {
  161. if(selectedProduct && $('#quantity').val()) {
  162. $('#product_waste_product_id').val(selectedProduct.id);
  163. $('#product_waste_quantity').val($('#quantity').val());
  164. $('#product_waste_reason').val($('#reason').val());
  165. $('#new_product_waste').submit();
  166. $('#typeahead').typeahead('val','');
  167. $('#products_new').attr('disabled', true);
  168. $('#quantity').val("");
  169. $('#reason').val("");
  170. } else {
  171. toastr["error"]("Error, Se debe indicar la cantidad.");
  172. }
  173. }
  174. function deleteRow(input) {
  175. var table = $('#products_table').DataTable();
  176. var idText = input.closest('tr').attr('id');
  177. var productWasteId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
  178. $.ajax({
  179. type: "DELETE",
  180. url: "/product_wastes/" + productWasteId,
  181. dataType: "json",
  182. data: "",
  183. success: function(xhr, status, error) {
  184. table.row(input.closest('tr')).remove().draw();
  185. }
  186. });
  187. }
  188. </script>