_form.html.erb 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <%= form_for(OpenCashRegister.new, remote: true, :html => {:class=>"form-horizontal", :id=> "open_cash_register_form"}) do |f| %>
  2. <div class="portlet-body form">
  3. <div id="error_explanation"></div>
  4. <div class="row">
  5. <div class="col-md-12">
  6. <!-- caja registradora -->
  7. <div class="form-group">
  8. <%= f.label :cash_register_id, "Caja registradora", {:class=>"col-md-offset-1 col-md-3 control-label"} do %> Caja registradora
  9. <span class="required">*</span>
  10. <% end %>
  11. <div class="input-group col-md-4 select2-bootstrap-prepend">
  12. <%
  13. available_cash = Array.new
  14. CashRegister.where(:pointsale_id => current_user.pointsale_id, :status => '1').find_each do |cash|
  15. is_opened = OpenCashRegister.where(:cash_register_id => cash.id, :status => '0').any?
  16. available_cash << cash if is_opened == false
  17. end
  18. %>
  19. <%= f.collection_select :cash_register_id, available_cash, :id, :name, {:prompt => "Seleccione"}, {:class => "form-control select2" } %>
  20. </div>
  21. </div>
  22. <!-- initial cash -->
  23. <div class="form-group">
  24. <%= f.label :initial_cash, "Efectivo inicial", {:class=>"col-md-offset-1 col-md-3 control-label"} do %> Efectivo inicial <span class="required">*</span>
  25. <% end %>
  26. <div class="col-md-4" style="padding-left: 0px;padding-right:0px">
  27. <%= f.number_field :initial_cash, {:class=>"form-control"} %>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. <h4 class="form-section" style="margin:20px 0px 10px 0px"></h4>
  33. <div class="actions">
  34. <%= f.submit 'guardar', {:class=>"hidden"} %>
  35. <button type="button" class="btn btn-success" onclick="submitForm()" id="openCashButton" disabled>Abrir caja</button>
  36. </div>
  37. </div>
  38. <% end %>
  39. <script type="text/javascript">
  40. toastr.options = {
  41. "closeButton": false,
  42. "debug": false,
  43. "positionClass": "toast-top-center",
  44. "onclick": null,
  45. "showDuration": "1000",
  46. "hideDuration": "1000",
  47. "timeOut": "5000",
  48. "extendedTimeOut": "1000",
  49. "showEasing": "swing",
  50. "hideEasing": "linear",
  51. "showMethod": "fadeIn",
  52. "hideMethod": "fadeOut"
  53. }
  54. $('#open_cash_register_cash_register_id').on('change', function() {
  55. if ($(this).val() != "") {
  56. getCashFund( $(this).val() );
  57. $('#openCashButton').attr('disabled', false);
  58. } else {
  59. $('#openCashButton').attr('disabled', true);
  60. }
  61. });
  62. function submitForm() {
  63. var cash = parseInt($('#open_cash_register_initial_cash').val());
  64. if ($('#open_cash_register_cash_register_id').val() != "") {
  65. $('#open_cash_register_form').submit();
  66. } else {
  67. toastr["warning"]("Se debe indicar efectivo inicial.");
  68. }
  69. }
  70. function getCashFund(id) {
  71. $.ajax({
  72. type: "get",
  73. url: '/cash_registers/' + id +'/get_cash_fund',
  74. dataType: 'json',
  75. success: function(data) {
  76. $('#open_cash_register_initial_cash').val(data);
  77. },
  78. });
  79. }
  80. </script>