_form.html.erb 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. <%= form_for(@sale, :remote => true, :html => {:class=>"form-horizontal", :id=> "sale_form"}) do |f| %>
  2. <div class="portlet-body form">
  3. <!-- este error explanation se usa para mostrar errores de presales e inventarios -->
  4. <div id="error_explanation"></div>
  5. <!-- este error explanation es cuando falla alguna validacion de la venta en sí -->
  6. <div class="alert alert-danger hidden" id="error_explanation_for_sale"></div>
  7. <div class="row">
  8. <!-- cuando no hay caja abierta -->
  9. <% if @opened_cash_registers.blank?%>
  10. <div class="alert alert-block alert-danger fade in">
  11. <h4 class="alert-heading">¡AVISO! no hay caja abierta</h4>
  12. <p> Para realizar una venta es necesario abrir una caja registradora. </p>
  13. <p>
  14. <%= link_to "Abrir caja", new_open_cash_register_path, :remote => true, :class => 'btn btn-primary' %>
  15. </p>
  16. </div>
  17. <% end %>
  18. <!-- boton para resetear datos -->
  19. <div class="col-md-offset-10 col-md-2">
  20. <button id="reset_pre_sales" type="button" class="btn btn-warning" <%= @disabled_button ? 'disabled' : '' %> onclick="deletePreSales()">Restaurar venta</button>
  21. </div>
  22. <div class="col-md-8">
  23. <h4 class="form-section"> Datos generales</h4>
  24. <!-- purchase code -->
  25. <div class="form-group">
  26. <%= f.label :sale_code, {:class=>"col-md-3 control-label"} do %> Código de compra
  27. <span class="required">*</span>
  28. <% end %>
  29. <div class="col-md-6 input-group">
  30. <span class="input-group-addon"><i class="fa fa-barcode"></i></span>
  31. <%= f.text_field :sale_code, {:class=>"form-control", :readonly => true} %>
  32. </div>
  33. </div>
  34. <!-- fecha -->
  35. <div class="form-group">
  36. <%= hidden_field_tag :tax_percent, @pos_config.tax_percent %>
  37. <%= f.label :date_sale, "Fecha", {:class=>"col-md-3 control-label"} do %> Fecha
  38. <span class="required">*</span>
  39. <% end %>
  40. <%= f.hidden_field :date_sale, {:value=>Date.today} %>
  41. <div class="col-sm-6" style="padding-left:0px;padding-right:0px;">
  42. <div class='input-group date' id='datetimepicker1'>
  43. <span class="input-group-addon">
  44. <span class="glyphicon glyphicon-calendar"></span>
  45. </span>
  46. <input type='text' class="form-control" disabled/>
  47. </div>
  48. </div>
  49. </div>
  50. <!-- open cash register -->
  51. <!-- < % if current_user.usertype == 'C' %>
  52. < %= f.hidden_field :open_cash_register_id, :value => @open_cash_register.id %>
  53. < % end %> -->
  54. <div class="form-group">
  55. <%= f.label :open_cash_register_id, "Caja registradora", {:class=>"col-md-3 control-label"} do %> Caja registradora
  56. <span class="required">*</span>
  57. <% end %>
  58. <div class="input-group col-md-6 select2-bootstrap-prepend">
  59. <% if @sale.open_cash_register.nil? %>
  60. <%= f.select :open_cash_register_id, Pointsale.find(current_user.pointsale_id).open_cash_registers.abiertas.map{|o| [o.cash_register.name, o.id]}, {:prompt => "Seleccione"}, { :class => 'form-control select2', :disabled => @disabled_select } %>
  61. <% else %>
  62. <%= f.select :open_cash_register_id, @opened_cash_registers.map{|o| [o.cash_register.name, o.id]}, {:include_blank => "Seleccione", :selected => @sale.open_cash_register.id}, {:class => "form-control", :disabled => true } %>
  63. <% end %>
  64. <%= f.hidden_field :open_cash_register_id, {:id => 'open_cash'} %>
  65. </div>
  66. </div>
  67. <!-- cliente -->
  68. <div class="form-group">
  69. <%= f.label :customer_id, "Cliente", {:class=>"col-md-3 control-label"} do %> Cliente
  70. <span class="required">*</span>
  71. <% end %>
  72. <div class="input-group col-md-6 select2-bootstrap-prepend" style="float:left">
  73. <%= f.collection_select :customer_id, Customer.vigentes, :id, :nick_name, {:prompt => "Seleccione", :selected => @sale.customer_id.present? ? @sale.customer_id : @general_public_id}, {:class => "form-control select2", :disabled => @disabled_select} %>
  74. <%= f.hidden_field :customer_id, :value => @sale.customer_id.present? ? @sale.customer_id : @general_public_id, :id => 'customer' %>
  75. </div>
  76. <div class="col-md-2">
  77. <% if @pre_sales.count == 0 %>
  78. <%= link_to new_customer_path, :remote => true, :class=>"btn btn-success", :id => :customer_remote do %>
  79. <i class="fa fa-plus"></i>
  80. <% end %>
  81. <% end %>
  82. </div>
  83. </div>
  84. <!-- tipo de venta -->
  85. <div class="form-group">
  86. <%= f.label :saletype, {:class=>"col-md-3 control-label"} do %> ¿Tipo de venta?
  87. <span class="required">*</span><% end %>
  88. <div class="btn-group col-md-6" data-toggle="buttons" style="padding-left:0px;padding-right:0px">
  89. <label class="col-md-4 btn default <%= @sale.saletype == 'cash' ? 'active' : (@enable_radios ? '' : 'disabled') %>">
  90. <%= radio_button_tag 'types', "cash", (@sale.saletype == 'cash'), class: "toggle" %> Contado
  91. </label>
  92. <label class="col-md-4 btn default <%= @sale.saletype == 'credit' ? 'active' : (@enable_radios ? '' : 'disabled') %>">
  93. <%= radio_button_tag 'types', "credit", (@sale.saletype == 'credit'), class: "toggle" %> Crédito
  94. </label>
  95. <label class="col-md-4 btn default <%= @sale.saletype == 'reserved' ? 'active' : (@enable_radios ? '' : 'disabled') %>">
  96. <%= radio_button_tag 'types', "reserved", (@sale.saletype == 'reserved'), class: "toggle" %> Apartado
  97. </label>
  98. <%= f.hidden_field :saletype %>
  99. </div>
  100. </div>
  101. <!-- vale -->
  102. <div class="form-group hidden" id="credit_note_div">
  103. <%= f.label :credit_note, {:class=>"col-md-3 control-label"} do %> Folio de vale <% end %>
  104. <div class="col-md-6 input-group">
  105. <span class="input-group-addon"><i class="fa fa-ticket"></i></span>
  106. <%= f.text_field :credit_note, {:class=>"form-control"} %>
  107. </div>
  108. </div>
  109. <!-- vendedor -->
  110. <div class="form-group">
  111. <%= f.label :seller_id, "Vendedor", {:class=>"col-md-3 control-label"} do %> Vendedor
  112. <span class="required">*</span>
  113. <% end %>
  114. <div class="input-group col-md-6 select2-bootstrap-prepend">
  115. <%= f.collection_select :seller_id, Seller.where(:pointsale_id => current_user.pointsale_id, :status => '1'), :id, :full_name, {:prompt => "Seleccione",
  116. :selected => @seller.blank? ? '' : @seller_id.to_i}, {:class => "form-control select2"} %>
  117. </div>
  118. </div>
  119. </div>
  120. <div class="col-md-4 hidden" id="customer_info">
  121. <h4 class="form-section"> Datos del cliente</h4>
  122. <div class="panel panel-info">
  123. <!-- Default panel contents -->
  124. <div class="panel-heading">
  125. <h3 class="panel-title" id="customer_name"></h3>
  126. </div>
  127. <!-- List group -->
  128. <ul class="list-group">
  129. <li class="list-group-item"> ¿Tiene crédito?
  130. <span class="badge badge-info badge-roundless" id="has_credit"></span>
  131. </li>
  132. <li class="list-group-item"> Adeudo del cliente
  133. <span class="badge badge-info badge-roundless" id="customer_debiting"></span>
  134. </li>
  135. <li class="list-group-item"> Límite de crédito
  136. <span class="badge badge-info badge-roundless" id="credit_limit"></span>
  137. </li>
  138. <li class="list-group-item"> Fecha de último abono
  139. <span class="badge badge-info badge-roundless" id="last_credit_payment"></span>
  140. </li>
  141. </ul>
  142. </div>
  143. </div>
  144. </div>
  145. <!-- agregar productos -->
  146. <h4 class="form-section"> Agregar producto</h4>
  147. <div class="row">
  148. <div class="col-md-12">
  149. <div class="note note-info">
  150. <h4 class="block">¡Nota!</h4>
  151. <p> Para hacer una busqueda avanzada utiliza el siguiente formato, nombre del producto :atributo a buscar<br>
  152. ejemplo. <strong>blusa :verde</strong> (Solo se puede buscar un atributo, ya sea estilo, talla ó color).</p>
  153. </div>
  154. </div>
  155. <div class='col-md-12'>
  156. <div class="form-group">
  157. <label class="col-md-2 control-label" for="typeahead"> Producto
  158. <span class="required">*</span>
  159. </label>
  160. <div class="col-md-4">
  161. <input class="form-control" type="text" id="typeahead" data-option-url="/find_products_from_stock/%QUERY">
  162. </div>
  163. <button id="products_new" disabled class="btn btn-success" type="button" onclick="addRow()"> Agregar <i class="fa fa-plus"></i> </button>
  164. </div>
  165. </div>
  166. </div>
  167. <!-- lista de productos -->
  168. <h4 class="form-section"> Lista de productos</h4>
  169. <div class="portlet-body">
  170. <table class="table table-striped table-bordered table-hover tableadvanced" id="products_table">
  171. <thead>
  172. <tr>
  173. <th>#</th>
  174. <th>SKU</th>
  175. <th>Imagen</th>
  176. <th>Producto</th>
  177. <th>Cantidad</th>
  178. <th>Precio unitario</th>
  179. <th>IVA</th>
  180. <th>Descuento</th>
  181. <th>Importe</th>
  182. <th width="15%">Acciones</th>
  183. </tr>
  184. </thead>
  185. <tbody>
  186. <%= render @pre_sales %>
  187. </tbody>
  188. </table>
  189. </div>
  190. <!-- totales -->
  191. <div class="row">
  192. <div class="col-md-offset-8 col-md-4">
  193. <div class="well">
  194. <div class="row static-info align-reverse">
  195. <div class="col-md-6 name"> Sub Total: </div>
  196. <div class="col-md-6 value ">
  197. <div class="input-group">
  198. <span class="input-group-addon">$ </span>
  199. <%= f.text_field :amount, {:class=>"form-control sub_total", :readonly => true, :id => "amount"} %>
  200. </div>
  201. </div>
  202. </div>
  203. <div class="row static-info align-reverse">
  204. <div class="col-md-6 name"> Descuento: </div>
  205. <div class="col-md-6 value ">
  206. <div class="input-group">
  207. <span class="input-group-addon">$ </span>
  208. <%= f.text_field :discount, {:class=>"form-control sub_total", :readonly => true, :id => "discount"} %>
  209. </div>
  210. </div>
  211. </div>
  212. <div class="row static-info align-reverse">
  213. <div class="col-md-6 name"> IVA: </div>
  214. <div class="col-md-6 value ">
  215. <div class="input-group">
  216. <span class="input-group-addon">$ </span>
  217. <%= f.text_field :tax, {:class=>"form-control descto", :readonly => true, :id => "tax"} %>
  218. </div>
  219. </div>
  220. </div>
  221. <div class="row static-info align-reverse">
  222. <div class="col-md-6 name"> Total: </div>
  223. <div class="col-md-6 value ">
  224. <div class="input-group">
  225. <span class="input-group-addon">$ </span>
  226. <%= f.text_field :total, {:class=>"form-control descto", :readonly => true, :id => "total"} %>
  227. </div>
  228. </div>
  229. </div>
  230. </div>
  231. </div>
  232. </div>
  233. <!-- acciones del form -->
  234. <div class="form-actions">
  235. <div class="row">
  236. <div class="col-md-9">
  237. <button type="button" class="btn green" onclick="addSale()" id="save_sale">Guardar venta</button>
  238. <%= link_to 'Cancelar', sales_path(:filter => @filter, :current_page => @current_page), {:class=>"btn default"} %>
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. <% end %>
  244. <script type="text/javascript">
  245. var selectedProduct;
  246. var timeout = null;
  247. $(document).on("page:change", function() {
  248. App.init();
  249. calculateTotals();
  250. fillCustomerInfo();
  251. enumeratePreSales();
  252. generateSaleCode();
  253. // si es publico en general, desactivar venta a credito y apartado
  254. if ($('#sale_customer_id').val() == '<%= @general_public_id %>') {
  255. $('#types_credit').attr('disabled', true);
  256. $('#types_credit').closest('label').addClass('disabled');
  257. $('#types_reserved').attr('disabled', true);
  258. $('#types_reserved').closest('label').addClass('disabled');
  259. }
  260. $('#datetimepicker1').datetimepicker({
  261. icons: {
  262. date: "fa fa-calendar"
  263. },
  264. format: "DD/MM/YYYY",
  265. defaultDate: new Date()
  266. });
  267. $("#new_pre_sale").bind('ajax:complete', function() {
  268. calculateTotals();
  269. });
  270. $('#sale_customer_id').on('change', function() {
  271. $(this).attr('disabled', true);
  272. $('#customer').val($(this).val());
  273. //bloquear boton para agregar nuevo cliente ya que se selecciono o agrego uno
  274. $('#customer_remote').removeAttr("href");
  275. $('#customer_remote').attr("disabled", true);
  276. // activar apartado y el credito se activa dependiendo si tiene o no,
  277. // en la funcion fillCustomer
  278. if ($('#sale_customer_id').val() != '<%= @general_public_id %>') {
  279. $('#types_reserved').attr('disabled', false);
  280. $('#types_reserved').closest('label').removeClass('disabled');
  281. }
  282. fillCustomerInfo();
  283. });
  284. $('#sale_open_cash_register_id').on('change', function() {
  285. $(this).attr('disabled', true);
  286. $('#open_cash').val($(this).val());
  287. generateSaleCode();
  288. });
  289. $('input:radio[name=types]').change(function() {
  290. if (!$(this).closest('label').hasClass('disabled')) {
  291. <% if @pre_sales.count == 0 %>
  292. if (!$(this).closest('label').hasClass('disabled')) {
  293. $('#sale_saletype').val($(this).val());
  294. } else {
  295. var type = $('#sale_saletype').val();
  296. $(":radio[value=" + type + "]").closest('label').addClass('active');
  297. }
  298. <% else %>
  299. var type = '<%= @sale.saletype %>';
  300. $(":radio[value=" + type + "]").closest('label').addClass('active');
  301. <% end %>
  302. //Si es tipo crédito, aparecer input de vale
  303. if ($(this).val() == 'credit') {
  304. $('#credit_note_div').removeClass('hidden');
  305. } else {
  306. $('#credit_note_div').addClass('hidden');
  307. $('#sale_credit_note').val('');
  308. }
  309. }
  310. });
  311. $(document).on("keydown", function (e) {
  312. if (window.location.pathname == "/sales/new") {
  313. if (e.which === 8 && !$(e.target).is("input, textarea")) {
  314. e.preventDefault();
  315. }
  316. }
  317. });
  318. });
  319. $('body').barcodeListener().on('barcode.valid', function(e, code) {
  320. findProductByBarcode(code);
  321. });
  322. // initialize bloodhound engine
  323. var bloodhound = new Bloodhound({
  324. datumTokenizer: function (d) {
  325. return Bloodhound.tokenizers.whitespace(d.value);
  326. },
  327. queryTokenizer: Bloodhound.tokenizers.whitespace,
  328. remote: {
  329. url: $('#typeahead').data('option-url'),
  330. wildcard: '%QUERY'
  331. }
  332. });
  333. bloodhound.initialize();
  334. $('#typeahead').typeahead(
  335. {
  336. minLength: 3
  337. },
  338. {
  339. displayKey: 'name',
  340. source: bloodhound.ttAdapter(),
  341. limit: Infinity,
  342. templates: {
  343. empty: [
  344. '<div class="empty-message">',
  345. 'No se encontró ningun producto. Favor de verificar',
  346. '</div>'
  347. ].join('\n'),
  348. suggestion: Handlebars.compile(
  349. '<div class="media">' +
  350. '<div class="pull-left">' +
  351. '<div class="media-object">' +
  352. '<img src="{{small_img}}" width="50" height="50"/>' +
  353. '</div>' +
  354. '</div>' +
  355. '<div class="media-body">' +
  356. '<h4 class="media-heading"><strong>{{sku}}</strong> | {{name}}</h4>' +
  357. '<p>{{barcode}}</p>' +
  358. '<p>{{description}}</p>' +
  359. '<p>{{display_attributes}}</p>' +
  360. '</div>' +
  361. '</div>')
  362. }
  363. });
  364. // this is the event that is fired when a user clicks on a suggestion
  365. $('#typeahead').bind('typeahead:selected', function(event, datum, name) {
  366. selectedProduct = datum;
  367. var openCash = $('#sale_open_cash_register_id').val();
  368. var customer = $('#sale_customer_id').val();
  369. var saleType = $('#sale_saletype').val();
  370. var seller = $('#sale_seller_id').val();
  371. if (openCash && customer && saleType && seller ) {
  372. $('#products_new').attr('disabled', false);
  373. } else {
  374. toastr["error"]("No ha ingresado toda la informacion requerida.");
  375. }
  376. });
  377. function addRow() {
  378. if(selectedProduct) {
  379. $('#pre_sale_customer_id').val($('#sale_customer_id').val());
  380. $('#pre_sale_open_cash_register_id').val($('#sale_open_cash_register_id').val());
  381. $('#pre_sale_sale_type').val($('#sale_saletype').val());
  382. $('#pre_sale_product_id').val(selectedProduct.id);
  383. $('#pre_sale_quantity').val(1);
  384. $('#new_pre_sale').submit();
  385. $('#typeahead').typeahead('val','');
  386. $('#products_new').attr('disabled', true);
  387. }
  388. }
  389. function deleteRow(input) {
  390. var table = $('#products_table').DataTable();
  391. var idText = input.closest('tr').attr('id');
  392. var preSaleId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
  393. $.ajax({
  394. type: "DELETE",
  395. url: "/pre_sales/" + preSaleId,
  396. dataType: "json",
  397. data: "",
  398. success: function(xhr, status, error) {
  399. table.row(input.closest('tr')).remove().draw();
  400. calculateTotals();
  401. }
  402. });
  403. }
  404. function calculatePrice(input) {
  405. if(input.val()) {
  406. clearTimeout(timeout);
  407. timeout = setTimeout(function () {
  408. tax = 0;
  409. quantity = parseInt(input.val());
  410. var idText = input.closest('tr').attr('id');
  411. var preSaleId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
  412. $('#save_sale').attr('disabled', true);
  413. $.ajax({
  414. type: "PUT",
  415. url: "/pre_sales/" + preSaleId,
  416. dataType: "json",
  417. data: {pre_sale: {quantity: input.val()}},
  418. success: function(xhr, status, error) {
  419. input.closest('tr').find('td:eq(6)').text(Math.round(xhr.tax * 100) / 100);
  420. input.closest('tr').find('td:eq(7)').text(Math.round(xhr.discount * 100) / 100);
  421. input.closest('tr').find('td:eq(8)').text(Math.round(xhr.total * 100) / 100);
  422. calculateTotals();
  423. $('#save_sale').attr('disabled', false);
  424. },
  425. error: function (xhr, status, errorThrown) {
  426. toastr["error"](xhr.responseText.substr(3, (xhr.responseText.length -6)));
  427. }
  428. });
  429. }, 500);
  430. }
  431. }
  432. function calculateTotals() {
  433. var amount = 0;
  434. var discount = 0;
  435. var tax = 0;
  436. var total = 0;
  437. if($('#products_table').dataTable().fnGetData().length > 0) {
  438. $('#products_table tbody tr').each(function() {
  439. quantity = parseFloat(($(this).find('td:nth-child(5) input').val()));
  440. price = parseFloat($(this).find('td:nth-child(6)').text());
  441. amount+= (quantity * price);
  442. });
  443. }
  444. $('#products_table tbody tr td:nth-child(7)').each(function() {
  445. tax+= parseFloat($(this).text());
  446. });
  447. $('#products_table tbody tr td:nth-child(8)').each(function() {
  448. discount+= parseFloat($(this).text());
  449. });
  450. total = (amount - discount) + tax;
  451. $('#tax').val(Math.round(tax * 100) / 100);
  452. $('#discount').val(Math.round(discount * 100) / 100);
  453. $('#amount').val(Math.round(amount * 100) / 100);
  454. $('#total').val(Math.round(total * 100) / 100);
  455. }
  456. function deletePreSales() {
  457. $.ajax({
  458. type: "get",
  459. url: '/delete_pre_sales',
  460. dataType: 'json',
  461. success: function(xhr, status, error) {
  462. location.reload();
  463. }
  464. });
  465. }
  466. function addSale() {
  467. var $form = $('#sale_form');
  468. var table = $('#products_table').dataTable();
  469. if ($form[0].checkValidity()) {
  470. if(table.fnGetData().length > 0) {
  471. $('#sale_form').submit();
  472. } else {
  473. toastr["error"]("Error, Se debe agregar al menos un producto.");
  474. }
  475. } else {
  476. toastr["error"]("La cantidad de los productos debe de ser mayor o igual a 1.");
  477. }
  478. }
  479. function fillCustomerInfo() {
  480. var customerId = $('#customer').val();
  481. var public_customer = "<%= @general_public_id %>";
  482. if(customerId && customerId != public_customer) {
  483. $.ajax({
  484. type: "get",
  485. url: '/customers/' + customerId + ".json",
  486. dataType: 'json',
  487. success: function(data) {
  488. if(data.credit) {
  489. $('#customer_name').text(data.nick_name);
  490. $('#has_credit').text(data.credit ? 'SI' : 'NO');
  491. // $('#customer_debiting').text(formatter.format(data.customer_debiting.customer_debiting));
  492. // $('#credit_limit').text(formatter.format(data.credit_limit));
  493. $('#customer_debiting').text(accounting.formatMoney(data.customer_debiting.customer_debiting));
  494. $('#credit_limit').text(accounting.formatMoney(data.credit_limit));
  495. if(data.customer_payment) {
  496. $('#last_credit_payment').text(data.customer_payment.customer_payment);
  497. }
  498. $('#customer_info').removeClass('hidden');
  499. <% if @pre_sales.count == 0 %>
  500. $('#types_credit').attr('disabled', false);
  501. $('#types_credit').closest('label').removeClass('disabled');
  502. <% end %>
  503. } else {
  504. // DISABLEAR EL DE CREDITO
  505. $('#types_credit').attr('disabled', true);
  506. $('#types_credit').closest('label').addClass('disabled');
  507. }
  508. }
  509. });
  510. }
  511. }
  512. function enumeratePreSales() {
  513. if($('#reset_pre_sales').prop("disabled") == false) {
  514. var table = $('#products_table').dataTable();
  515. var counter = 1;
  516. $('#products_table tbody tr').each(function() {
  517. $(this).find('td:eq(0)').html($(this).find('td:eq(0)').html().replace('#', counter));
  518. counter++;
  519. });
  520. }
  521. }
  522. function generateSaleCode() {
  523. if($('#sale_open_cash_register_id').val()) {
  524. $.ajax({
  525. type: "get",
  526. url: '/get_next_sale_code/' + $('#sale_open_cash_register_id').val(),
  527. dataType: 'text',
  528. success: function(data) {
  529. $('#sale_sale_code').val(data);
  530. },
  531. });
  532. }
  533. }
  534. function findProductByBarcode(barcode) {
  535. var customer = $('#sale_customer_id').val();
  536. var openCash = $('#sale_open_cash_register_id').val();
  537. var saleType = $('form input[type=radio]:checked').val();
  538. var seller = $('#sale_seller_id').val();
  539. if(customer && openCash && saleType && seller) {
  540. $.ajax({
  541. type: "get",
  542. url: '/add_pre_sale_by_barcode/' + barcode + "/" + customer + "/" + openCash + "/" + saleType,
  543. dataType: 'script',
  544. success: function(data) {
  545. calculateTotals();
  546. },
  547. });
  548. } else {
  549. toastr["error"]("Falta seleccionar datos del formulario.");
  550. }
  551. }
  552. </script>