_transfer_stock.html.erb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <div class="form-horizontal">
  2. <div class="col-md-12">
  3. <div class="note note-success">
  4. <h4>NOTA:</h4>
  5. <p>Aun hay existencia de los siguientes productos, para eliminarlos, es necesario seleccionar un punto de venta ó almacen a donde enviarlos. </p>
  6. </div>
  7. <div class="form-group">
  8. <%= hidden_field_tag 'ids_to_transfer', @ids_array %>
  9. <%= label :destiny, "", {:class=>"col-md-2 control-label"} do %>Destino
  10. <span class="required">*</span>
  11. <% end %>
  12. <div class="col-md-6 select2-bootstrap-prepend">
  13. <%= select_tag "destiny", grouped_options_for_select([
  14. ['Puntos de venta', Pointsale.activos.collect {|p| [ p.name, ('P-' + p.id.to_s) ] }],
  15. ['Almacenes', Warehouse.activos.collect {|w| [ w.name, ('W-' + w.id.to_s)] }]]), class: "pointsale_id form-control select2" %>
  16. </div>
  17. </div>
  18. </div>
  19. <table class="table table-striped table-bordered table-hover" id="products">
  20. <thead>
  21. <tr>
  22. <th>#</th>
  23. <th>Producto</th>
  24. <th>Existencia</th>
  25. </tr>
  26. </thead>
  27. <tbody>
  28. <% @to_delete_with_stock.each_with_index do |to_delete, key| %>
  29. <tr id="available_<%= to_delete.id %>">
  30. <td> <%= key +1 %> </td>
  31. <td>
  32. <label>
  33. <strong> <%= to_delete.product.name %> </strong><br>
  34. <%= to_delete.product.display_attributes %>
  35. </label> <br>
  36. SKU: <%= to_delete.product.sku %><br>
  37. <% if to_delete.product.barcode.present? %>
  38. <i class="fa fa-barcode"></i>: <%= to_delete.product.barcode %><br>
  39. <% end %>
  40. <% if to_delete.product.description.present? %>
  41. Descripción: <%= to_delete.product.description %>
  42. <% end %>
  43. </td>
  44. <td> <%= to_delete.stock %> </td>
  45. </tr>
  46. <% end %>
  47. </tbody>
  48. </table>
  49. </div>
  50. <div class="form-actions">
  51. <div class="row">
  52. <div class="col-md-9">
  53. <button class="btn green" onclick="transferProducts()">Traspasar productos</button>
  54. <button class="btn default" onclick="closeModal()">Cancelar</button>
  55. </div>
  56. </div>
  57. </div>
  58. <script>
  59. function closeModal() {
  60. $('#dialog').modal('toggle');
  61. }
  62. function transferProducts() {
  63. var destiny = $('#destiny').val();
  64. var ids = [];
  65. var all_ids = JSON.parse($('#ids_to_transfer').val());
  66. if(destiny) {
  67. $('#products tbody tr').each(function() {
  68. var idText = $(this).attr('id');
  69. var availableId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
  70. ids.push(availableId);
  71. });
  72. $.ajax({
  73. type: "POST",
  74. url: "/transfer_stock/",
  75. dataType: "json",
  76. data: {ids_to_transfer: ids, destiny: destiny, all_ids: all_ids},
  77. success: function(xhr, status, error) {
  78. $(class_2).DataTable().draw();
  79. $('#dialog').modal('toggle');
  80. toastr["success"]("Se desasignaron " + all_ids.length + " producto(s) del punto de venta.");
  81. }
  82. });
  83. } else {
  84. toastr["error"]("Seleccione destino de los productos.");
  85. }
  86. }
  87. </script>