customer_sales.html.erb 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <div class="page-container">
  2. <!-- BEGIN CONTENT -->
  3. <div class="page-content-wrapper">
  4. <!-- BEGIN CONTENT BODY -->
  5. <!-- BEGIN PAGE HEAD-->
  6. <div class="page-head">
  7. <div class="container-fluid">
  8. <!-- BEGIN PAGE TITLE -->
  9. <div class="page-title">
  10. <h1>Clientes deudores</h1>
  11. </div>
  12. <!-- END PAGE TITLE -->
  13. </div>
  14. </div>
  15. <!-- END PAGE HEAD-->
  16. <!-- BEGIN PAGE CONTENT BODY -->
  17. <div class="page-content">
  18. <div class="container-fluid">
  19. <%= link_to debtors_path(filter: @filter, current_page: @current_page), { class: "btn blue-hoki pull-right margin-bottom-10" } do %> <i class="fa fa-angle-left "></i> Regresar
  20. <% end %>
  21. <!-- BEGIN PAGE BREADCRUMBS -->
  22. <ul class="page-breadcrumb breadcrumb">
  23. <%= render_breadcrumbs :tag => :li, :separator => ' <i class="fa fa-circle"></i> ' %>
  24. </ul>
  25. <!-- END PAGE BREADCRUMBS -->
  26. <!-- BEGIN PAGE CONTENT INNER -->
  27. <div class="page-content-inner">
  28. <div id="notice">
  29. <% if success %>
  30. <div class="alert alert-success">
  31. <p><%= success %></p>
  32. </div>
  33. <% elsif warning %>
  34. <div class="alert alert-warning">
  35. <p><%= warning %></p>
  36. </div>
  37. <% end %>
  38. </div>
  39. <div class="row">
  40. <div class="col-md-12">
  41. <div class="portlet light ">
  42. <div class="portlet-title">
  43. <div class="caption">
  44. <i class="fa fa-list "></i>
  45. <span class="caption-subject bold uppercase">Ventas al cliente <%= @customer.nick_name %></span>
  46. <span class="caption-helper"></span>
  47. </div>
  48. </div>
  49. <div class="portlet-body">
  50. <!-- tabs? -->
  51. <div class="tabbable-custom ">
  52. <ul class="nav nav-tabs ">
  53. <li class="active">
  54. <a href="#customer_sales" data-toggle="tab" aria-expanded="true"> Ventas </a>
  55. </li>
  56. <li class="">
  57. <a href="#abonos" data-toggle="tab" aria-expanded="false"> Abonos </a>
  58. </li>
  59. </ul>
  60. <div class="tab-content">
  61. <div class="tab-pane active" id="customer_sales">
  62. <div class="pull-right-margin-bottom-10">
  63. <!-- búsqueda por fecha-->
  64. <div class="row">
  65. <div class="col-md-11">
  66. <%= hidden_field_tag 'title_for_print' %>
  67. <div class="form-group">
  68. <%= label_tag :begin_date, "Fecha", {:class=>"col-md-1 control-label"} do %> Desde
  69. <% end %>
  70. <div class="col-sm-2" style="padding-left:0px;padding-right:0px;">
  71. <div class='input-group date' id='begin_date'>
  72. <input id="start" type='text' class="form-control"/>
  73. <span class="input-group-addon">
  74. <span class="glyphicon glyphicon-calendar"></span>
  75. </span>
  76. </div>
  77. </div>
  78. <%= label_tag :end_date, "Fecha", {:class=>"col-md-1 control-label"} do %> Hasta
  79. <% end %>
  80. <div class="col-sm-2" style="padding-left:0px;padding-right:0px;">
  81. <div class='input-group date' id='end_date'>
  82. <input id="end" type='text' class="form-control"/>
  83. <span class="input-group-addon">
  84. <span class="glyphicon glyphicon-calendar"></span>
  85. </span>
  86. </div>
  87. </div>
  88. <button class="btn btn-icon-only blue" style="margin-left:25px" onclick="salesByDate()">
  89. <i class="fa fa-search"></i>
  90. </button>
  91. </div>
  92. </div>
  93. </div>
  94. <!-- fin búsqueda por fecha-->
  95. <!-- contenido customer sales -->
  96. <table class="table table-striped table-bordered table-hover tableadvancedprintable" id="sales_table">
  97. <thead>
  98. <tr>
  99. <th>#</th>
  100. <th>Código de venta</th>
  101. <% if current_user.usertype == "A" || current_user.usertype == "SS" %>
  102. <th>Punto de venta</th>
  103. <% end %>
  104. <th>Vendedor</th>
  105. <th>Fecha</th>
  106. <th>Tipo</th>
  107. <th>Productos</th>
  108. <th>Status</th>
  109. <th>Total</th>
  110. <th>Abonado</th>
  111. <th>Restante</th>
  112. <th width="15%">Acciones</th>
  113. </tr>
  114. </thead>
  115. <tbody id="customer_sales">
  116. <% @sales.each_with_index do |sale, key| %>
  117. <tr class=<%= sale.cancelled? ? 'danger' : '' %>>
  118. <td><%= sale.id %></td>
  119. <td><%= sale.sale_code %> </td>
  120. <% if current_user.usertype == "A" || current_user.usertype == "SS" %>
  121. <td> <%= sale.get_pointsale.name %> </td>
  122. <% end %>
  123. <td><%= sale.user.first_name %> </td>
  124. <td><%= l(sale.date_sale, :format => '%d/%m/%Y') %></td>
  125. <td>
  126. <% if sale.saletype == "credit" && sale.credit_note.blank? %>
  127. Crédito
  128. <% elsif sale.saletype == "credit" && sale.credit_note.present? %>
  129. Crédito/vale
  130. <% else %>
  131. Contado
  132. <% end %>
  133. </td>
  134. <td><%= sale.products.count %></td>
  135. <td><%= sale_status(sale) %></td>
  136. <td><%= number_to_currency(sale.total, precision: 2) %></td>
  137. <% if sale.credit.present? %>
  138. <td><%= number_to_currency(sale.credit.credit_payments.activos.sum(:quantity), precision: 2) %></td>
  139. <td><%= number_to_currency(sale.credit.rest, precision: 2) %></td>
  140. <% else %>
  141. <td></td>
  142. <td></td>
  143. <% end %>
  144. <td class="text-center">
  145. <%= link_to sale, { class: "btn btn-icon-only default", title: "Ver venta" } do %>
  146. <i class="fa fa-search"></i>
  147. <% end %>
  148. <% if can? :destroy, Sale %>
  149. <% daysToCancel = @pos_config.days_cancel_sale %>
  150. <% if (sale.date_sale + daysToCancel.days >= Date.today) && !sale.cancelled? %>
  151. <%= link_to sale , method: :delete, :class => "btn btn-icon-only btn-danger", :title=>"Cancelar venta", data: { confirm: '¿Está seguro que desea cancelar la venta?' } do %> <i class="fa fa-ban"></i>
  152. <% end %>
  153. <% end %>
  154. <% end %>
  155. </td>
  156. </tr>
  157. <% end %>
  158. </tbody>
  159. </table>
  160. </div>
  161. </div>
  162. <!-- fin contenido customer sales -->
  163. <!-- contenido abono -->
  164. <div class="tab-pane" id="abonos">
  165. <table class="table table-striped table-bordered table-hover tableadvancedprintable" id="sales_table">
  166. <thead>
  167. <tr>
  168. <th>Folio</th>
  169. <th>Fecha</th>
  170. <th>Deuda</th>
  171. <th>Abono</th>
  172. <th>Restante</th>
  173. <td>Status</td>
  174. <th width="15%">Acciones</th>
  175. </tr>
  176. </thead>
  177. <tbody id="abonos">
  178. <% @credits.each_with_index do |credit, key| %>
  179. <% abonos = credit.credit_payments.activos.order(:id) %>
  180. <% abonos.each_with_index do |abono, key| %>
  181. <tr class=<%= credit.cancelled? ? 'danger' : '' %>>
  182. <td><%= credit.sale.sale_code %> </td>
  183. <td><%= l(abono.date_payment, :format => '%d/%m/%Y') %></td>
  184. <td><%= number_to_currency(credit.total, precision: 2) %></td>
  185. <td><%= number_to_currency(abono.quantity, precision: 2) %></td>
  186. <td><%= number_to_currency(credit.rest, precision: 2) %></td>
  187. <td>
  188. <% case abono.status %>
  189. <% when "cancelled"%>
  190. <span class="label label-danger"> CANCELADO </span>
  191. <% when "active"%>
  192. <span class="label label-success"> ACTIVO </span>
  193. <% end %>
  194. </td>
  195. <td class="text-center">
  196. <% if !abono.cancelled? && abono.cash_registers_move.present? && abono.cash_registers_move.open_cash_register.open? %>
  197. <%= link_to cash_move_delete_payment_path(:credit_payment_id => abono.id, :credit => credit.id) , method: :delete_credit_payment, :class => "btn btn-icon-only btn-danger", :title=>"Cancelar abono", data: { confirm: '¿Está seguro que desea cancelar el abono?' } do %> <i class="fa fa-ban"></i>
  198. <% end %>
  199. <% end %>
  200. </td>
  201. <% credit.total -= abono.quantity %>
  202. </tr>
  203. <% end %>
  204. <% end %>
  205. </tbody>
  206. </table>
  207. </div>
  208. <!-- fin contenido abono -->
  209. </div>
  210. </div>
  211. </div>
  212. </div>
  213. </div>
  214. </div>
  215. <!-- END PAGE CONTENT INNER -->
  216. </div>
  217. </div>
  218. <!-- END PAGE CONTENT BODY -->
  219. <!-- END CONTENT BODY -->
  220. </div>
  221. <!-- END CONTENT -->
  222. </div>
  223. <script>
  224. $(document).on("page:change", function() {
  225. App.init();
  226. $('#begin_date').datetimepicker({
  227. icons: {
  228. date: "fa fa-calendar"
  229. },
  230. format: "DD/MM/YYYY",
  231. defaultDate: moment().startOf('month').toDate()
  232. });
  233. $('#end_date').datetimepicker({
  234. icons: {
  235. date: "fa fa-calendar"
  236. },
  237. format: "DD/MM/YYYY",
  238. defaultDate: moment().endOf('month').toDate()
  239. });
  240. var startDate = moment($("#begin_date").data("date"), "DD-MM-YYYY").format('DD/MM/YYYY')
  241. var endDate = moment($("#end_date").data("date"), "DD-MM-YYYY").format('DD/MM/YYYY');
  242. $('#title_for_print').val('Ventas del ' + startDate + ' al ' + endDate);
  243. });
  244. function salesByDate() {
  245. var start = moment($("#begin_date").data("date"), "DD-MM-YYYY").format('YYYY-MM-DD HH:mm:ss');
  246. var end = moment($("#end_date").data("date"), "DD-MM-YYYY").format('YYYY-MM-DD HH:mm:ss');
  247. var cliente = '<%= @customer.id %>'
  248. App.blockUI({
  249. target: $("#sales_table"),
  250. animate: true
  251. });
  252. $.ajax({
  253. type: "get",
  254. url: '/find_customer_sales_by_date/' + start + '/' + end + '/' + cliente,
  255. dataType: 'script',
  256. success: function(data) {
  257. window.setTimeout(function() {
  258. App.unblockUI($("#sales_table"));
  259. var startDate = moment($("#begin_date").data("date"), "DD-MM-YYYY").format('DD/MM/YYYY')
  260. var endDate = moment($("#end_date").data("date"), "DD-MM-YYYY").format('DD/MM/YYYY');
  261. $('#title_for_print').val('Ventas del ' + startDate + ' al ' + endDate);
  262. }, 100);
  263. }
  264. });
  265. }
  266. </script>