_form.html.erb 12 KB

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