customer_sales.html.erb 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 <%= @custom.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' : (sale.paid? ? 'success' : '')) %>>
  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. <% credito = Credit.where(:sale_id => sale.id).first %>
  138. <% if credito.present? %>
  139. <% abonos = CreditPayment.where(:credit_id => credito.id, :status => 0).sum(:quantity) %>
  140. <% if abonos.present? %>
  141. <td><%= number_to_currency(abonos, precision: 2) %></td>
  142. <% end %>
  143. <td><%= number_to_currency(credito.rest, precision: 2) %></td>
  144. <% else %>
  145. <td></td>
  146. <td></td>
  147. <% end %>
  148. <td class="text-center">
  149. <%= link_to sale, {:class=>"btn btn-icon-only default", :title=>"Ver venta"} do %>
  150. <i class="fa fa-search"></i>
  151. <% end %>
  152. <% if can? :destroy, Sale %>
  153. <% daysToCancel = @pos_config.days_cancel_sale %>
  154. <% if (sale.date_sale + daysToCancel.days >= Date.today) && !sale.cancelled? %>
  155. <%= 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>
  156. <% end %>
  157. <% end %>
  158. <% end %>
  159. </td>
  160. </tr>
  161. <% end %>
  162. </tbody>
  163. </table>
  164. </div>
  165. </div>
  166. <!-- fin contenido customer sales -->
  167. <!-- contenido abono -->
  168. <div class="tab-pane" id="abonos">
  169. <table class="table table-striped table-bordered table-hover tableadvancedprintable" id="sales_table">
  170. <thead>
  171. <tr>
  172. <th>Folio</th>
  173. <th>Fecha</th>
  174. <th>Deuda</th>
  175. <th>Abono</th>
  176. <th>Restante</th>
  177. <td>Status</td>
  178. <th width="15%">Acciones</th>
  179. </tr>
  180. </thead>
  181. <tbody id="abonos">
  182. <% @credit.each_with_index do |credit, key| %>
  183. <% abonos = CreditPayment.where(:credit_id => credit.id).order('id') %>
  184. <% total = credit.total %>
  185. <% abonos.each_with_index do |abono, key| %>
  186. <% rest = total - abono.quantity %>
  187. <tr class=<%= (credit.cancelled? ? 'danger' : (credit.active? ? 'success' : '')) %>>
  188. <td><%= credit.sale.sale_code %> </td>
  189. <td><%= l(abono.date_payment, :format => '%d/%m/%Y') %></td>
  190. <td><%= number_to_currency(total, precision: 2) %></td>
  191. <td><%= number_to_currency(abono.quantity, precision: 2) %></td>
  192. <td><%= number_to_currency(rest, precision: 2) %></td>
  193. <td>
  194. <% case abono.status %>
  195. <% when "cancelled"%>
  196. <span class="label label-danger"> CANCELADO </span>
  197. <% when "active"%>
  198. <span class="label label-success"> ACTIVO </span>
  199. <% end %>
  200. </td>
  201. <td class="text-center">
  202. <% if !abono.cancelled? && abono.cash_registers_move.present? && abono.cash_registers_move.open_cash_register.open?%>
  203. <%= 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>
  204. <% end %>
  205. <% end %>
  206. </td>
  207. <% total -= abono.quantity %>
  208. </tr>
  209. <% end %>
  210. <% end %>
  211. </tbody>
  212. </table>
  213. </div>
  214. <!-- fin contenido abono -->
  215. </div>
  216. </div>
  217. </div>
  218. </div>
  219. </div>
  220. </div>
  221. <!-- END PAGE CONTENT INNER -->
  222. </div>
  223. </div>
  224. <!-- END PAGE CONTENT BODY -->
  225. <!-- END CONTENT BODY -->
  226. </div>
  227. <!-- END CONTENT -->
  228. </div>
  229. <script>
  230. $(document).on("page:change", function() {
  231. App.init();
  232. $('#begin_date').datetimepicker({
  233. icons: {
  234. date: "fa fa-calendar"
  235. },
  236. format: "DD/MM/YYYY",
  237. defaultDate: moment().startOf('month').toDate()
  238. });
  239. $('#end_date').datetimepicker({
  240. icons: {
  241. date: "fa fa-calendar"
  242. },
  243. format: "DD/MM/YYYY",
  244. defaultDate: moment().endOf('month').toDate()
  245. });
  246. var startDate = moment($("#begin_date").data("date"), "DD-MM-YYYY").format('DD/MM/YYYY')
  247. var endDate = moment($("#end_date").data("date"), "DD-MM-YYYY").format('DD/MM/YYYY');
  248. $('#title_for_print').val('Ventas del ' + startDate + ' al ' + endDate);
  249. });
  250. function salesByDate() {
  251. var start = moment($("#begin_date").data("date"), "DD-MM-YYYY").format('YYYY-MM-DD HH:mm:ss');
  252. var end = moment($("#end_date").data("date"), "DD-MM-YYYY").format('YYYY-MM-DD HH:mm:ss');
  253. var cliente = '<%= @custom.id %>'
  254. App.blockUI({
  255. target: $("#sales_table"),
  256. animate: true
  257. });
  258. $.ajax({
  259. type: "get",
  260. url: '/find_customer_sales_by_date/' + start + '/' + end + '/' + cliente,
  261. dataType: 'script',
  262. success: function(data) {
  263. window.setTimeout(function() {
  264. App.unblockUI($("#sales_table"));
  265. var startDate = moment($("#begin_date").data("date"), "DD-MM-YYYY").format('DD/MM/YYYY')
  266. var endDate = moment($("#end_date").data("date"), "DD-MM-YYYY").format('DD/MM/YYYY');
  267. $('#title_for_print').val('Ventas del ' + startDate + ' al ' + endDate);
  268. }, 100);
  269. }
  270. });
  271. }
  272. </script>