_form.html.erb 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <%= form_for(@cash_out, :remote => true, :html => {:class=>"form-horizontal", :id=> "cash_out_form"}) do |f| %>
  2. <div class="portlet-body form">
  3. <div id="error_explanation"></div>
  4. <div class="col-md-12">
  5. <%= hidden_field_tag 'open_cash_register_id', @opened_cash_register.id %>
  6. <%= hidden_field_tag 'cash_payment_id', @cash_payment_method_id %>
  7. <div class="form-group">
  8. <%= f.label :received_by_id, "Recibe", {:class=>"col-md-3 control-label"} do %> Recibe
  9. <span class="required">*</span>
  10. <% end %>
  11. <div class="input-group col-md-6 select2-bootstrap-prepend">
  12. <%= f.collection_select :received_by_id, User.where(:pointsale_id => current_user.pointsale_id), :id, :userid, {:prompt => "Seleccione" },
  13. {:class => "form-control select2"} %>
  14. </div>
  15. </div>
  16. <h4 class="form-section" style="margin:0px 0px 30px 0px"> Resumen</h4>
  17. <div class="col-md-4" style="padding-left: 0px">
  18. <ul class="list-group">
  19. <li class="list-group-item list-group-item"> Efectivo inicial
  20. <span class="pull-right label label-info"><%= number_to_currency(@initial_cash, precision: 2) %></span>
  21. </li>
  22. <li class="list-group-item list-group-item"> Total de ventas
  23. <span class="pull-right label label-info"><%= number_to_currency(@sales_total, precision: 2) %></span>
  24. </li>
  25. <li class="list-group-item list-group-item"> Total de gastos
  26. <span class="pull-right label label-info"><%= number_to_currency(@expenses_total, precision: 2) %></span>
  27. </li>
  28. </ul>
  29. </div>
  30. <div class="col-md-offset-2 col-md-6" style="padding-right:0px">
  31. <div class="form-group credit_limits">
  32. <%= f.label :physical_cash, {:class=>"col-md-4 control-label"} do %>Efectivo en caja<span class="required">*</span> <% end %>
  33. <div class="col-md-8">
  34. <div class="input-group">
  35. <span class="input-group-addon"> $ </span>
  36. <%= f.text_field :physical_cash, {:class=>"form-control mask_decimal"} %>
  37. </div>
  38. <span class="help-block">Es el dinero que se tiene fisicamente en caja. </span>
  39. </div>
  40. </div>
  41. <div class="form-group credit_limits">
  42. <%= f.label :received_cash, {:class=>"col-md-4 control-label"} do %>Retiro de efectivo<span class="required">*</span> <% end %>
  43. <div class="col-md-8">
  44. <div class="input-group">
  45. <span class="input-group-addon"> $ </span>
  46. <%= f.text_field :received_cash, {:class=>"form-control mask_decimal", :oninput => "receivedAndFundCash()", :disabled => true} %>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="form-group credit_limits">
  51. <%= f.label :cash_fund, {:class=>"col-md-4 control-label"} do %>Fondo de caja<span class="required">*</span> <% end %>
  52. <div class="col-md-8">
  53. <div class="input-group">
  54. <span class="input-group-addon"> $ </span>
  55. <%= text_field_tag :cash_fund_display, '', class: "form-control mask_decimal", disabled: true %>
  56. <!-- < %= f.hidden_field(:cash_fund) %> -->
  57. <%= f.hidden_field :cash_fund, {:class=>"form-control mask_decimal"} %>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="form-group credit_limits">
  62. <%= f.label :observations, {:class=>"col-md-4 control-label"} do %>Observaciones<span class="required" id="required_observations"></span> <% end %>
  63. <div class="col-md-8">
  64. <div class="input-group">
  65. <span class="input-group-addon"> <i class="fa fa-comment-o"></i> </span>
  66. <%= f.text_area :observations, {:class=>"form-control", :rows=>5 } %>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="row">
  72. <div class="col-md-12">
  73. <div class="table-scrollable">
  74. <table class="table table-hover table-striped table-bordered" id="payment_methods_table">
  75. <thead>
  76. <tr class="uppercase">
  77. <th> # </th>
  78. <th> Método de pago </th>
  79. <th> Total de ingresos </th>
  80. <th> Total de gastos </th>
  81. <th>Total</th>
  82. </tr>
  83. </thead>
  84. <tbody>
  85. <% @payments.each_with_index do |payment, key| %>
  86. <tr id="payment_<%= payment['payment_method_id']%>">
  87. <td> <%= key +1 %> </td>
  88. <td> <%= payment["method"] %> </td>
  89. <td> <%= number_to_currency(payment["incoming"], precision: 2) %> </td>
  90. <td class="danger"> <%= number_to_currency(payment["outgoing"], precision: 2) %> </td>
  91. <td>
  92. <%= number_to_currency(payment["total"], precision: 2) %>
  93. <input class="hidden" value="<%= payment["total"] %>" id="<%=key + 1%>">
  94. </td>
  95. </tr>
  96. <%= f.fields_for :cash_out_details do |ff| %>
  97. <%= ff.hidden_field :payment_method_id, :value => payment["payment_method_id"] %>
  98. <%= ff.hidden_field :incoming, :value => payment["incoming"] %>
  99. <%= ff.hidden_field :outgoing, :value => payment["outgoing"] %>
  100. <%= ff.hidden_field :total, :value => payment["total"] %>
  101. <% end %>
  102. <% end %>
  103. </tbody>
  104. </table>
  105. </div>
  106. </div>
  107. </div>
  108. <h4 class="form-section"> Ingresos del día</h4>
  109. <table class="table table-striped table-bordered table-hover tableadvanced">
  110. <thead>
  111. <tr>
  112. <th>#</th>
  113. <th>Folio</th>
  114. <th>Caja registradora</th>
  115. <th>Método de pago</th>
  116. <th>Cantidad</th>
  117. <th>Concepto</th>
  118. <th>Hora</th>
  119. </tr>
  120. </thead>
  121. <tbody>
  122. <% @incomings.each_with_index do |move, key| %>
  123. <tr>
  124. <td><%= key + 1 %></td>
  125. <td>
  126. <% case move.concept %>
  127. <% when "sale", "reserved_payment" %>
  128. <%= move.sale.sale_code %>
  129. <% when "purchase"%>
  130. <%= move.purchase.purchase_code %>
  131. <% when "expense"%>
  132. <%= move.expense.expense_code %>
  133. <% when "credit_payment"%>
  134. <%= move.credit_payment.id %>
  135. <% end %>
  136. </td>
  137. <td><%= move.open_cash_register.cash_register.name%></td>
  138. <td><%= move.payment_method.method %></td>
  139. <td><%= number_to_currency(move.quantity, precision: 2) %></td>
  140. <td>
  141. <% case move.concept %>
  142. <% when "sale"%>
  143. VENTA
  144. <% when "purchase"%>
  145. COMPRA CANCELADA
  146. <% when "expense"%>
  147. GASTO CANCELADO
  148. <% when "credit_payment"%>
  149. ABONO A CRÉDITO
  150. <% when "reserved_payment"%>
  151. ABONO A APARTADO
  152. <% end %>
  153. </td>
  154. <td><%= l(move.created_at, :format => '%I:%M %p') %> </td>
  155. </tr>
  156. <% end %>
  157. </tbody>
  158. </table>
  159. <h4 class="form-section"> Gastos del día</h4>
  160. <table class="table table-striped table-bordered table-hover tableadvanced">
  161. <thead>
  162. <tr>
  163. <th>#</th>
  164. <th>Folio</th>
  165. <th>Caja registradora</th>
  166. <th>Método de pago</th>
  167. <th>Cantidad</th>
  168. <th>Concepto</th>
  169. <th>Hora</th>
  170. </tr>
  171. </thead>
  172. <tbody>
  173. <% @outgoings.each_with_index do |move, key| %>
  174. <tr>
  175. <td><%= key + 1 %></td>
  176. <td>
  177. <% case move.concept %>
  178. <% when "sale", "reserved_payment" %>
  179. <%= move.sale.sale_code %>
  180. <% when "purchase"%>
  181. <%= move.purchase.purchase_code %>
  182. <% when "expense"%>
  183. <%= move.expense.expense_code %>
  184. <% when "credit_payment"%>
  185. <%= move.credit_payment.id %>
  186. <% end %>
  187. </td>
  188. <td><%= move.open_cash_register.cash_register.name%></td>
  189. <td><%= move.payment_method.method %></td>
  190. <td><%= number_to_currency(move.quantity, precision: 2) %></td>
  191. <td>
  192. <% case move.concept %>
  193. <% when "sale" %>
  194. <% if move.sale.cash? %>
  195. VENTA CANCELADA
  196. <% elsif move.sale.reserved? %>
  197. APARTADO CANCELADO
  198. <% end %>
  199. <% when "purchase"%>
  200. COMPRA
  201. <% when "expense"%>
  202. <strong> <%= move.expense.expensesconcept.name %></strong> <br>
  203. <%= move.expense.observations %>
  204. <% when "credit_payment"%>
  205. ABONO CANCELADO
  206. <% end %>
  207. </td>
  208. <td><%= l(move.created_at, :format => '%I:%M %p') %> </td>
  209. </tr>
  210. <% end %>
  211. </tbody>
  212. </table>
  213. </div>
  214. <!-- acciones del form -->
  215. <div style="margin-top: 30px">
  216. <div class="row">
  217. <div class="col-md-9">
  218. <button type="button" class="btn green disabled" onclick="addCashOut()" id="submit_cash_out">Guardar</button>
  219. <%= link_to 'Cancelar', root_path, {:class=>"btn default"} %>
  220. </div>
  221. </div>
  222. </div>
  223. </div>
  224. <% end %>
  225. <script type="text/javascript">
  226. var timeout = null;
  227. var cashOutValid = false;
  228. $(document).on("page:change", function() {
  229. $('.dataTables_filter').hide();
  230. $('#cash_out_physical_cash').keyup(function() {
  231. var physicalCash = $('#cash_out_physical_cash').val();
  232. if(physicalCash) {
  233. $('#cash_out_received_cash').attr('disabled', false);
  234. } else {
  235. $('#cash_out_received_cash').attr('disabled', true);
  236. $('#cash_out_received_cash').val('');
  237. }
  238. });
  239. $('#cash_out_physical_cash').keyup(function() {
  240. receivedAndFundCash();
  241. });
  242. });
  243. function addCashOut() {
  244. if ( !$('#submit_cash_out').hasClass('disabled') ) {
  245. if ($('#cash_out_received_by_id').val()) {
  246. $('#cash_out_form').submit();
  247. } else {
  248. toastr["error"]("Seleccione quien va a recibir el corte de caja.");
  249. }
  250. }
  251. }
  252. function receivedAndFundCash() {
  253. clearTimeout(timeout);
  254. timeout = setTimeout(function () {
  255. var physicalCash = parseFloat($('#cash_out_physical_cash').val());
  256. var receivedCash = parseFloat($('#cash_out_received_cash').val());
  257. if(physicalCash && receivedCash) {
  258. var cashFund = physicalCash - receivedCash;
  259. $('#cash_out_cash_fund').val(cashFund);
  260. $('#cash_fund_display').val(cashFund);
  261. if( receivedCash > physicalCash) {
  262. toastr["error"]("El retiro de efectivo no puede ser mayor al efectivo disponible en caja.");
  263. $('#submit_cash_out').addClass('disabled');
  264. $('#cash_out_cash_fund').val('');
  265. $('#cash_fund_display').val('');
  266. } else {
  267. $('#submit_cash_out').removeClass('disabled');
  268. }
  269. } else {
  270. $('#submit_cash_out').addClass('disabled');
  271. }
  272. }, 300);
  273. }
  274. </script>