|
@@ -1,12 +1,12 @@
|
|
|
<%= form_for(@sale, :remote => true, :html => {:class=>"form-horizontal", :id=> "sale_form"}) do |f| %>
|
|
<%= form_for(@sale, :remote => true, :html => {:class=>"form-horizontal", :id=> "sale_form"}) do |f| %>
|
|
|
<div class="portlet-body form">
|
|
<div class="portlet-body form">
|
|
|
<!-- este error explanation se usa para mostrar errores de presales e inventarios -->
|
|
<!-- este error explanation se usa para mostrar errores de presales e inventarios -->
|
|
|
- <div id="error_explanation"></div>
|
|
|
|
|
|
|
+ <!-- <div id="error_explanation"></div> -->
|
|
|
<!-- este error explanation es cuando falla alguna validacion de la venta en sí -->
|
|
<!-- este error explanation es cuando falla alguna validacion de la venta en sí -->
|
|
|
<div class="alert alert-danger hidden" id="error_explanation_for_sale"></div>
|
|
<div class="alert alert-danger hidden" id="error_explanation_for_sale"></div>
|
|
|
<div class="row">
|
|
<div class="row">
|
|
|
<!-- cuando no hay caja abierta -->
|
|
<!-- cuando no hay caja abierta -->
|
|
|
- <% if @opened_cash_registers.blank?%>
|
|
|
|
|
|
|
+ <% if @opened_cash_registers.blank? %>
|
|
|
<div class="alert alert-block alert-danger fade in">
|
|
<div class="alert alert-block alert-danger fade in">
|
|
|
<h4 class="alert-heading">¡AVISO! no hay caja abierta</h4>
|
|
<h4 class="alert-heading">¡AVISO! no hay caja abierta</h4>
|
|
|
<p> Para realizar una venta es necesario abrir una caja registradora. </p>
|
|
<p> Para realizar una venta es necesario abrir una caja registradora. </p>
|
|
@@ -57,11 +57,11 @@
|
|
|
<% end %>
|
|
<% end %>
|
|
|
<div class="input-group col-md-6 select2-bootstrap-prepend">
|
|
<div class="input-group col-md-6 select2-bootstrap-prepend">
|
|
|
<% if @sale.open_cash_register.nil? %>
|
|
<% if @sale.open_cash_register.nil? %>
|
|
|
- <%= 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 } %>
|
|
|
|
|
|
|
+ <%= 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 } %>
|
|
|
<% else %>
|
|
<% else %>
|
|
|
- <%= 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 } %>
|
|
|
|
|
|
|
+ <%= 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 } %>
|
|
|
<% end %>
|
|
<% end %>
|
|
|
- <%= f.hidden_field :open_cash_register_id, {:id => 'open_cash'} %>
|
|
|
|
|
|
|
+ <%= f.hidden_field :open_cash_register_id, { :id => 'open_cash' } %>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<!-- cliente -->
|
|
<!-- cliente -->
|
|
@@ -69,14 +69,13 @@
|
|
|
<%= f.label :customer_id, "Cliente", {:class=>"col-md-3 control-label"} do %> Cliente
|
|
<%= f.label :customer_id, "Cliente", {:class=>"col-md-3 control-label"} do %> Cliente
|
|
|
<span class="required">*</span>
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
<% end %>
|
|
|
-
|
|
|
|
|
<div class="input-group col-md-6 select2-bootstrap-prepend" style="float:left">
|
|
<div class="input-group col-md-6 select2-bootstrap-prepend" style="float:left">
|
|
|
- <%= 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} %>
|
|
|
|
|
|
|
+ <%= 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" } %>
|
|
|
<%= f.hidden_field :customer_id, :value => @sale.customer_id.present? ? @sale.customer_id : @general_public_id, :id => 'customer' %>
|
|
<%= f.hidden_field :customer_id, :value => @sale.customer_id.present? ? @sale.customer_id : @general_public_id, :id => 'customer' %>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="col-md-2">
|
|
<div class="col-md-2">
|
|
|
<% if @pre_sales.count == 0 %>
|
|
<% if @pre_sales.count == 0 %>
|
|
|
- <%= link_to new_customer_path, :remote => true, :class=>"btn btn-success", :id => :customer_remote do %>
|
|
|
|
|
|
|
+ <%= link_to new_customer_path, remote: true, class: "btn btn-success", id: :customer_remote do %>
|
|
|
<i class="fa fa-plus"></i>
|
|
<i class="fa fa-plus"></i>
|
|
|
<% end %>
|
|
<% end %>
|
|
|
<% end %>
|
|
<% end %>
|
|
@@ -123,24 +122,28 @@
|
|
|
<div class="panel panel-info">
|
|
<div class="panel panel-info">
|
|
|
<!-- Default panel contents -->
|
|
<!-- Default panel contents -->
|
|
|
<div class="panel-heading">
|
|
<div class="panel-heading">
|
|
|
- <h3 class="panel-title" id="customer_name"></h3>
|
|
|
|
|
|
|
+ <h3 class="panel-title" id="customer_name"></h3>
|
|
|
</div>
|
|
</div>
|
|
|
<!-- List group -->
|
|
<!-- List group -->
|
|
|
<ul class="list-group">
|
|
<ul class="list-group">
|
|
|
- <li class="list-group-item"> ¿Tiene crédito?
|
|
|
|
|
- <span class="badge badge-info badge-roundless" id="has_credit"></span>
|
|
|
|
|
- </li>
|
|
|
|
|
- <li class="list-group-item"> Adeudo del cliente
|
|
|
|
|
- <span class="badge badge-info badge-roundless" id="customer_debiting"></span>
|
|
|
|
|
- </li>
|
|
|
|
|
- <li class="list-group-item"> Límite de crédito
|
|
|
|
|
- <span class="badge badge-info badge-roundless" id="credit_limit"></span>
|
|
|
|
|
- </li>
|
|
|
|
|
- <li class="list-group-item"> Fecha de último abono
|
|
|
|
|
- <span class="badge badge-info badge-roundless" id="last_credit_payment"></span>
|
|
|
|
|
- </li>
|
|
|
|
|
|
|
+ <li class="list-group-item"> ¿Tiene crédito?
|
|
|
|
|
+ <span class="badge badge-info badge-roundless" id="has_credit"></span>
|
|
|
|
|
+ </li>
|
|
|
|
|
+ <li class="list-group-item"> Adeudo del cliente
|
|
|
|
|
+ <span class="badge badge-info badge-roundless" id="customer_debiting"></span>
|
|
|
|
|
+ </li>
|
|
|
|
|
+ <%= hidden_field_tag :available_credit, 0 %>
|
|
|
|
|
+ <li class="list-group-item"> Límite de crédito
|
|
|
|
|
+ <span class="badge badge-info badge-roundless" id="credit_limit"></span>
|
|
|
|
|
+ </li>
|
|
|
|
|
+ <li class="list-group-item"> Fecha de último abono
|
|
|
|
|
+ <span class="badge badge-info badge-roundless" id="last_credit_payment"></span>
|
|
|
|
|
+ </li>
|
|
|
</ul>
|
|
</ul>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ <div class="from-group">
|
|
|
|
|
+ <div id="error_explanation"></div>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
@@ -149,10 +152,8 @@
|
|
|
<div class="row">
|
|
<div class="row">
|
|
|
<div class="col-md-12">
|
|
<div class="col-md-12">
|
|
|
<div class="note note-info">
|
|
<div class="note note-info">
|
|
|
- <h4 class="block">¡Nota!</h4>
|
|
|
|
|
- <p> Para hacer una busqueda avanzada utiliza el siguiente formato, nombre del producto :atributo a buscar<br>
|
|
|
|
|
- ejemplo. <strong>blusa :verde</strong> (Solo se puede buscar un atributo, ya sea estilo, talla ó color).</p>
|
|
|
|
|
-
|
|
|
|
|
|
|
+ <h4 class="block">¡Nota!</h4>
|
|
|
|
|
+ <p> Para hacer una búsqueda avanzada utiliza el siguiente formato, nombre del producto :atributo a buscar<br> ejemplo. <strong>blusa :verde</strong> (Sólo se puede buscar un atributo, ya sea estilo, talla o color).</p>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<div class='col-md-12'>
|
|
<div class='col-md-12'>
|
|
@@ -283,23 +284,6 @@
|
|
|
$('#save_sale').attr('disabled', false);
|
|
$('#save_sale').attr('disabled', false);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- $('#sale_customer_id').on('change', function() {
|
|
|
|
|
- $(this).attr('disabled', true);
|
|
|
|
|
- $('#customer').val($(this).val());
|
|
|
|
|
-
|
|
|
|
|
- //bloquear boton para agregar nuevo cliente ya que se selecciono o agrego uno
|
|
|
|
|
- $('#customer_remote').removeAttr("href");
|
|
|
|
|
- $('#customer_remote').attr("disabled", true);
|
|
|
|
|
-
|
|
|
|
|
- // activar apartado y el credito se activa dependiendo si tiene o no,
|
|
|
|
|
- // en la funcion fillCustomer
|
|
|
|
|
- if ($('#sale_customer_id').val() != '<%= @general_public_id %>') {
|
|
|
|
|
- $('#types_reserved').attr('disabled', false);
|
|
|
|
|
- $('#types_reserved').closest('label').removeClass('disabled');
|
|
|
|
|
- }
|
|
|
|
|
- fillCustomerInfo();
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
$('#sale_open_cash_register_id').on('change', function() {
|
|
$('#sale_open_cash_register_id').on('change', function() {
|
|
|
$(this).attr('disabled', true);
|
|
$(this).attr('disabled', true);
|
|
|
$('#open_cash').val($(this).val());
|
|
$('#open_cash').val($(this).val());
|
|
@@ -338,270 +322,323 @@
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- $('body').barcodeListener().on('barcode.valid', function(e, code) {
|
|
|
|
|
- findProductByBarcode(code);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // initialize bloodhound engine
|
|
|
|
|
- var bloodhound = new Bloodhound({
|
|
|
|
|
- datumTokenizer: function (d) {
|
|
|
|
|
- return Bloodhound.tokenizers.whitespace(d.value);
|
|
|
|
|
- },
|
|
|
|
|
- queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
|
- remote: {
|
|
|
|
|
- url: $('#typeahead').data('option-url'),
|
|
|
|
|
- wildcard: '%QUERY'
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- bloodhound.initialize();
|
|
|
|
|
|
|
+ $('#sale_customer_id').on('change', function() {
|
|
|
|
|
+ // $(this).attr('disabled', true);
|
|
|
|
|
+ $('#customer').val($(this).val());
|
|
|
|
|
|
|
|
|
|
+ //bloquear boton para agregar nuevo cliente ya que se selecciono o agrego uno
|
|
|
|
|
+ $('#customer_remote').remove();
|
|
|
|
|
+ // $('#customer_remote').attr("disabled", true);
|
|
|
|
|
|
|
|
- $('#typeahead').typeahead(
|
|
|
|
|
- {
|
|
|
|
|
- minLength: 3
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- displayKey: 'name',
|
|
|
|
|
- source: bloodhound.ttAdapter(),
|
|
|
|
|
- limit: Infinity,
|
|
|
|
|
- templates: {
|
|
|
|
|
- empty: [
|
|
|
|
|
- '<div class="empty-message">',
|
|
|
|
|
- 'No se encontró ningun producto. Favor de verificar',
|
|
|
|
|
- '</div>'
|
|
|
|
|
- ].join('\n'),
|
|
|
|
|
- suggestion: Handlebars.compile(
|
|
|
|
|
- '<div class="media">' +
|
|
|
|
|
- '<div class="pull-left">' +
|
|
|
|
|
- '<div class="media-object">' +
|
|
|
|
|
- '<img src="{{small_img}}" width="50" height="50"/>' +
|
|
|
|
|
- '</div>' +
|
|
|
|
|
- '</div>' +
|
|
|
|
|
- '<div class="media-body">' +
|
|
|
|
|
- '<h4 class="media-heading"><strong>{{sku}}</strong> | {{name}}</h4>' +
|
|
|
|
|
- '<p>{{barcode}}</p>' +
|
|
|
|
|
- '<p>{{description}}</p>' +
|
|
|
|
|
- '<p>{{display_attributes}}</p>' +
|
|
|
|
|
- '</div>' +
|
|
|
|
|
- '</div>')
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // activar apartado y el credito se activa dependiendo si tiene o no,
|
|
|
|
|
+ // en la funcion fillCustomer
|
|
|
|
|
+ if ($('#sale_customer_id').val() != '<%= @general_public_id %>') {
|
|
|
|
|
+ $('#types_reserved').attr('disabled', false);
|
|
|
|
|
+ $('#types_reserved').closest('label').removeClass('disabled');
|
|
|
|
|
+ }
|
|
|
|
|
+ updatePreSale($(this).val());
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- // this is the event that is fired when a user clicks on a suggestion
|
|
|
|
|
- $('#typeahead').bind('typeahead:selected', function(event, datum, name) {
|
|
|
|
|
- selectedProduct = datum;
|
|
|
|
|
|
|
+ $('#types_cash, #types_credit, #types_reserved').on('change', function() {
|
|
|
|
|
+ $("#sale_saletype").val($(this).val());
|
|
|
|
|
+ if($(this).val() == "cash"){
|
|
|
|
|
+ $("#save_sale").attr("disabled", false);
|
|
|
|
|
+ }
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "PUT",
|
|
|
|
|
+ url: "/update_saletype/" + $(this).val(),
|
|
|
|
|
+ dataType: "json",
|
|
|
|
|
+ success: function(xhr, status, error) {
|
|
|
|
|
+ toastr["warning"]("Se actualizó el tipo de venta");
|
|
|
|
|
+ },
|
|
|
|
|
+ error: function (xhr, status, errorThrown) {
|
|
|
|
|
+ toastr["error"](xhr.responseText.substr(3, (xhr.responseText.length -6)));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- var openCash = $('#sale_open_cash_register_id').val();
|
|
|
|
|
- var customer = $('#sale_customer_id').val();
|
|
|
|
|
- var saleType = $('#sale_saletype').val();
|
|
|
|
|
- var seller = $('#sale_seller_id').val();
|
|
|
|
|
|
|
+ function updatePreSale(customer_id) {
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "PUT",
|
|
|
|
|
+ url: "/update_presale_customer/" + customer_id,
|
|
|
|
|
+ dataType: "json",
|
|
|
|
|
+ success: function(xhr, status, error) {
|
|
|
|
|
+ toastr["warning"]("Se actualizó el cliente de venta");
|
|
|
|
|
+ fillCustomerInfo();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $('body').barcodeListener().on('barcode.valid', function(e, code) {
|
|
|
|
|
+ findProductByBarcode(code);
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- if (openCash && customer && saleType && seller ) {
|
|
|
|
|
- $('#products_new').attr('disabled', false);
|
|
|
|
|
- } else {
|
|
|
|
|
- toastr["error"]("No ha ingresado toda la informacion requerida.");
|
|
|
|
|
|
|
+ // initialize bloodhound engine
|
|
|
|
|
+ var bloodhound = new Bloodhound({
|
|
|
|
|
+ datumTokenizer: function (d) {
|
|
|
|
|
+ return Bloodhound.tokenizers.whitespace(d.value);
|
|
|
|
|
+ },
|
|
|
|
|
+ queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
|
+ remote: {
|
|
|
|
|
+ url: $('#typeahead').data('option-url'),
|
|
|
|
|
+ wildcard: '%QUERY'
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ bloodhound.initialize();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ $('#typeahead').typeahead(
|
|
|
|
|
+ {
|
|
|
|
|
+ minLength: 3
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ displayKey: 'name',
|
|
|
|
|
+ source: bloodhound.ttAdapter(),
|
|
|
|
|
+ limit: Infinity,
|
|
|
|
|
+ templates: {
|
|
|
|
|
+ empty: [
|
|
|
|
|
+ '<div class="empty-message">',
|
|
|
|
|
+ 'No se encontró ningun producto. Favor de verificar',
|
|
|
|
|
+ '</div>'
|
|
|
|
|
+ ].join('\n'),
|
|
|
|
|
+ suggestion: Handlebars.compile(
|
|
|
|
|
+ '<div class="media">' +
|
|
|
|
|
+ '<div class="pull-left">' +
|
|
|
|
|
+ '<div class="media-object">' +
|
|
|
|
|
+ '<img src="{{small_img}}" width="50" height="50"/>' +
|
|
|
|
|
+ '</div>' +
|
|
|
|
|
+ '</div>' +
|
|
|
|
|
+ '<div class="media-body">' +
|
|
|
|
|
+ '<h4 class="media-heading"><strong>{{sku}}</strong> | {{name}}</h4>' +
|
|
|
|
|
+ '<p>{{barcode}}</p>' +
|
|
|
|
|
+ '<p>{{description}}</p>' +
|
|
|
|
|
+ '<p>{{display_attributes}}</p>' +
|
|
|
|
|
+ '</div>' +
|
|
|
|
|
+ '</div>')
|
|
|
}
|
|
}
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // this is the event that is fired when a user clicks on a suggestion
|
|
|
|
|
+ $('#typeahead').bind('typeahead:selected', function(event, datum, name) {
|
|
|
|
|
+ selectedProduct = datum;
|
|
|
|
|
|
|
|
- function addRow() {
|
|
|
|
|
- if(selectedProduct) {
|
|
|
|
|
- $('#pre_sale_customer_id').val($('#sale_customer_id').val());
|
|
|
|
|
- $('#pre_sale_open_cash_register_id').val($('#sale_open_cash_register_id').val());
|
|
|
|
|
- $('#pre_sale_sale_type').val($('#sale_saletype').val());
|
|
|
|
|
- $('#pre_sale_product_id').val(selectedProduct.id);
|
|
|
|
|
- $('#pre_sale_quantity').val(1);
|
|
|
|
|
- $('#new_pre_sale').submit();
|
|
|
|
|
- $('#typeahead').typeahead('val','');
|
|
|
|
|
- $('#products_new').attr('disabled', true);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ var openCash = $('#sale_open_cash_register_id').val();
|
|
|
|
|
+ var customer = $('#sale_customer_id').val();
|
|
|
|
|
+ var saleType = $('#sale_saletype').val();
|
|
|
|
|
+ var seller = $('#sale_seller_id').val();
|
|
|
|
|
|
|
|
- function deleteRow(input) {
|
|
|
|
|
- var table = $('#products_table').DataTable();
|
|
|
|
|
- var idText = input.closest('tr').attr('id');
|
|
|
|
|
- var preSaleId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "DELETE",
|
|
|
|
|
- url: "/pre_sales/" + preSaleId,
|
|
|
|
|
- dataType: "json",
|
|
|
|
|
- data: "",
|
|
|
|
|
- success: function(xhr, status, error) {
|
|
|
|
|
- table.row(input.closest('tr')).remove().draw();
|
|
|
|
|
- calculateTotals();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (openCash && customer && saleType && seller ) {
|
|
|
|
|
+ $('#products_new').attr('disabled', false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ toastr["error"]("No ha ingresado toda la información requerida.");
|
|
|
}
|
|
}
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- function calculatePrice(input) {
|
|
|
|
|
- if(input.val()) {
|
|
|
|
|
- clearTimeout(timeout);
|
|
|
|
|
- timeout = setTimeout(function () {
|
|
|
|
|
- tax = 0;
|
|
|
|
|
- quantity = parseInt(input.val());
|
|
|
|
|
-
|
|
|
|
|
- var idText = input.closest('tr').attr('id');
|
|
|
|
|
- var preSaleId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
|
|
|
|
|
- $('#save_sale').attr('disabled', true);
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "PUT",
|
|
|
|
|
- url: "/pre_sales/" + preSaleId,
|
|
|
|
|
- dataType: "json",
|
|
|
|
|
- data: {pre_sale: {quantity: input.val()}},
|
|
|
|
|
- success: function(xhr, status, error) {
|
|
|
|
|
-
|
|
|
|
|
- input.closest('tr').find('td:eq(6)').text(Math.round(xhr.tax * 100) / 100);
|
|
|
|
|
-
|
|
|
|
|
- input.closest('tr').find('td:eq(7)').text(Math.round(xhr.discount * 100) / 100);
|
|
|
|
|
-
|
|
|
|
|
- input.closest('tr').find('td:eq(8)').text(Math.round(xhr.total * 100) / 100);
|
|
|
|
|
-
|
|
|
|
|
- calculateTotals();
|
|
|
|
|
-
|
|
|
|
|
- $('#save_sale').attr('disabled', false);
|
|
|
|
|
- },
|
|
|
|
|
- error: function (xhr, status, errorThrown) {
|
|
|
|
|
- toastr["error"](xhr.responseText.substr(3, (xhr.responseText.length -6)));
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }, 500);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ function addRow() {
|
|
|
|
|
+ if(selectedProduct) {
|
|
|
|
|
+ $('#pre_sale_customer_id').val($('#sale_customer_id').val());
|
|
|
|
|
+ $('#pre_sale_open_cash_register_id').val($('#sale_open_cash_register_id').val());
|
|
|
|
|
+ $('#pre_sale_sale_type').val($('#sale_saletype').val());
|
|
|
|
|
+ $('#pre_sale_product_id').val(selectedProduct.id);
|
|
|
|
|
+ $('#pre_sale_quantity').val(1);
|
|
|
|
|
+ $('#new_pre_sale').submit();
|
|
|
|
|
+ $('#typeahead').typeahead('val','');
|
|
|
|
|
+ $('#products_new').attr('disabled', true);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- function calculateTotals() {
|
|
|
|
|
- var amount = 0;
|
|
|
|
|
- var discount = 0;
|
|
|
|
|
- var tax = 0;
|
|
|
|
|
- var total = 0;
|
|
|
|
|
-
|
|
|
|
|
- if($('#products_table').dataTable().fnGetData().length > 0) {
|
|
|
|
|
- $('#products_table tbody tr').each(function() {
|
|
|
|
|
- quantity = parseFloat(($(this).find('td:nth-child(5) input').val()));
|
|
|
|
|
- price = parseFloat($(this).find('td:nth-child(6)').text());
|
|
|
|
|
- amount+= (quantity * price);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function deleteRow(input) {
|
|
|
|
|
+ var table = $('#products_table').DataTable();
|
|
|
|
|
+ var idText = input.closest('tr').attr('id');
|
|
|
|
|
+ var preSaleId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "DELETE",
|
|
|
|
|
+ url: "/pre_sales/" + preSaleId,
|
|
|
|
|
+ dataType: "json",
|
|
|
|
|
+ data: "",
|
|
|
|
|
+ success: function(xhr, status, error) {
|
|
|
|
|
+ table.row(input.closest('tr')).remove().draw();
|
|
|
|
|
+ calculateTotals();
|
|
|
}
|
|
}
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function calculatePrice(input) {
|
|
|
|
|
+ if(input.val()) {
|
|
|
|
|
+ clearTimeout(timeout);
|
|
|
|
|
+ timeout = setTimeout(function () {
|
|
|
|
|
+ tax = 0;
|
|
|
|
|
+ quantity = parseInt(input.val());
|
|
|
|
|
+
|
|
|
|
|
+ var idText = input.closest('tr').attr('id');
|
|
|
|
|
+ var preSaleId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
|
|
|
|
|
+ $('#save_sale').attr('disabled', true);
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "PUT",
|
|
|
|
|
+ url: "/pre_sales/" + preSaleId,
|
|
|
|
|
+ dataType: "json",
|
|
|
|
|
+ data: { pre_sale: { quantity: input.val() } },
|
|
|
|
|
+ success: function(xhr, status, error) {
|
|
|
|
|
|
|
|
- $('#products_table tbody tr td:nth-child(7)').each(function() {
|
|
|
|
|
- tax+= parseFloat($(this).text());
|
|
|
|
|
- });
|
|
|
|
|
- $('#products_table tbody tr td:nth-child(8)').each(function() {
|
|
|
|
|
- discount+= parseFloat($(this).text());
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ input.closest('tr').find('td:eq(6)').text(Math.round(xhr.tax * 100) / 100);
|
|
|
|
|
|
|
|
- total = (amount - discount) + tax;
|
|
|
|
|
- $('#tax').val(Math.round(tax * 100) / 100);
|
|
|
|
|
- $('#discount').val(Math.round(discount * 100) / 100);
|
|
|
|
|
- $('#amount').val(Math.round(amount * 100) / 100);
|
|
|
|
|
- $('#total').val(Math.round(total * 100) / 100);
|
|
|
|
|
|
|
+ input.closest('tr').find('td:eq(7)').text(Math.round(xhr.discount * 100) / 100);
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ input.closest('tr').find('td:eq(8)').text(Math.round(xhr.total * 100) / 100);
|
|
|
|
|
|
|
|
- function deletePreSales() {
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "get",
|
|
|
|
|
- url: '/delete_pre_sales',
|
|
|
|
|
- dataType: 'json',
|
|
|
|
|
- success: function(xhr, status, error) {
|
|
|
|
|
- location.reload();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ calculateTotals();
|
|
|
|
|
+
|
|
|
|
|
+ $('#save_sale').attr('disabled', false);
|
|
|
|
|
+ },
|
|
|
|
|
+ error: function (xhr, status, errorThrown) {
|
|
|
|
|
+ input.val(1);
|
|
|
|
|
+ toastr["error"](xhr.responseText.substr(3, (xhr.responseText.length -6)));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }, 500);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function calculateTotals() {
|
|
|
|
|
+ var amount = 0;
|
|
|
|
|
+ var discount = 0;
|
|
|
|
|
+ var tax = 0;
|
|
|
|
|
+ var total = 0;
|
|
|
|
|
+
|
|
|
|
|
+ if($('#products_table').dataTable().fnGetData().length > 0) {
|
|
|
|
|
+ $('#products_table tbody tr').each(function() {
|
|
|
|
|
+ quantity = parseFloat(($(this).find('td:nth-child(5) input').val()));
|
|
|
|
|
+ price = parseFloat($(this).find('td:nth-child(6)').text());
|
|
|
|
|
+ amount += (quantity * price);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function addSale() {
|
|
|
|
|
- var $form = $('#sale_form');
|
|
|
|
|
- var table = $('#products_table').dataTable();
|
|
|
|
|
|
|
+ $('#products_table tbody tr td:nth-child(7)').each(function() {
|
|
|
|
|
+ tax += parseFloat($(this).text());
|
|
|
|
|
+ });
|
|
|
|
|
+ $('#products_table tbody tr td:nth-child(8)').each(function() {
|
|
|
|
|
+ discount += parseFloat($(this).text());
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- if ($form[0].checkValidity()) {
|
|
|
|
|
- if(table.fnGetData().length > 0) {
|
|
|
|
|
- $('#sale_form').submit();
|
|
|
|
|
- $('#save_sale').attr('disabled', true);
|
|
|
|
|
- } else {
|
|
|
|
|
- toastr["error"]("Error, Se debe agregar al menos un producto.");
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- toastr["error"]("La cantidad de los productos debe de ser mayor o igual a 1.");
|
|
|
|
|
|
|
+ total = (amount - discount) + tax;
|
|
|
|
|
+ $('#tax').val(Math.round(tax * 100) / 100);
|
|
|
|
|
+ $('#discount').val(Math.round(discount * 100) / 100);
|
|
|
|
|
+ $('#amount').val(Math.round(amount * 100) / 100);
|
|
|
|
|
+ $('#total').val(Math.round(total * 100) / 100);
|
|
|
|
|
+ if(total < parseFloat($("#available_credit").val())) {
|
|
|
|
|
+ $('#types_credit').attr('disabled', false);
|
|
|
|
|
+ $('#types_credit').closest('label').removeClass('disabled');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function deletePreSales() {
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "get",
|
|
|
|
|
+ url: '/delete_pre_sales',
|
|
|
|
|
+ dataType: 'json',
|
|
|
|
|
+ success: function(xhr, status, error) {
|
|
|
|
|
+ location.reload();
|
|
|
}
|
|
}
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function addSale() {
|
|
|
|
|
+ var $form = $('#sale_form');
|
|
|
|
|
+ var table = $('#products_table').dataTable();
|
|
|
|
|
|
|
|
|
|
+ if ($form[0].checkValidity()) {
|
|
|
|
|
+ if(table.fnGetData().length > 0) {
|
|
|
|
|
+ $('#sale_form').submit();
|
|
|
|
|
+ $('#save_sale').attr('disabled', true);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ toastr["error"]("Error, Se debe agregar al menos un producto.");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ toastr["error"]("La cantidad de los productos debe de ser mayor o igual a 1.");
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- function fillCustomerInfo() {
|
|
|
|
|
- var customerId = $('#customer').val();
|
|
|
|
|
- var public_customer = "<%= @general_public_id %>";
|
|
|
|
|
- if(customerId && customerId != public_customer) {
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "get",
|
|
|
|
|
- url: '/customers/' + customerId + ".json",
|
|
|
|
|
- dataType: 'json',
|
|
|
|
|
- success: function(data) {
|
|
|
|
|
- if(data.credit) {
|
|
|
|
|
- $('#customer_name').text(data.nick_name);
|
|
|
|
|
- $('#has_credit').text(data.credit ? 'SI' : 'NO');
|
|
|
|
|
- // $('#customer_debiting').text(formatter.format(data.customer_debiting.customer_debiting));
|
|
|
|
|
- // $('#credit_limit').text(formatter.format(data.credit_limit));
|
|
|
|
|
- $('#customer_debiting').text(accounting.formatMoney(data.customer_debiting.customer_debiting));
|
|
|
|
|
- $('#credit_limit').text(accounting.formatMoney(data.credit_limit));
|
|
|
|
|
- if(data.customer_payment) {
|
|
|
|
|
- $('#last_credit_payment').text(data.customer_payment.customer_payment);
|
|
|
|
|
- }
|
|
|
|
|
- $('#customer_info').removeClass('hidden');
|
|
|
|
|
- <% if @pre_sales.count == 0 %>
|
|
|
|
|
- $('#types_credit').attr('disabled', false);
|
|
|
|
|
- $('#types_credit').closest('label').removeClass('disabled');
|
|
|
|
|
- <% end %>
|
|
|
|
|
- } else {
|
|
|
|
|
- // DISABLEAR EL DE CREDITO
|
|
|
|
|
|
|
+ function fillCustomerInfo() {
|
|
|
|
|
+ var customerId = $('#customer').val();
|
|
|
|
|
+ var public_customer = "<%= @general_public_id %>";
|
|
|
|
|
+ if(customerId) {
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "get",
|
|
|
|
|
+ url: '/customers/' + customerId + ".json",
|
|
|
|
|
+ dataType: 'json',
|
|
|
|
|
+ success: function(data) {
|
|
|
|
|
+ if(data.credit) {
|
|
|
|
|
+ $('#customer_name').text(data.nick_name);
|
|
|
|
|
+ $('#has_credit').text(data.credit ? 'SI' : 'NO');
|
|
|
|
|
+ // $('#customer_debiting').text(formatter.format(data.customer_debiting.customer_debiting));
|
|
|
|
|
+ // $('#credit_limit').text(formatter.format(data.credit_limit));
|
|
|
|
|
+ $('#customer_debiting').text(accounting.formatMoney(data.customer_debiting.customer_debiting));
|
|
|
|
|
+ $('#credit_limit').text(accounting.formatMoney(data.credit_limit));
|
|
|
|
|
+ if(data.customer_payment) {
|
|
|
|
|
+ $('#last_credit_payment').text(data.customer_payment.customer_payment);
|
|
|
|
|
+ }
|
|
|
|
|
+ $('#customer_info').removeClass('hidden');
|
|
|
|
|
+ $("#available_credit").val(data.available_credit.available_credit)
|
|
|
|
|
+ if(parseInt($("#total").val()) > parseInt(data.available_credit.available_credit)) {
|
|
|
|
|
+ $('#types_cash').click();
|
|
|
$('#types_credit').attr('disabled', true);
|
|
$('#types_credit').attr('disabled', true);
|
|
|
$('#types_credit').closest('label').addClass('disabled');
|
|
$('#types_credit').closest('label').addClass('disabled');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $('#types_credit').attr('disabled', false);
|
|
|
|
|
+ $('#types_credit').closest('label').removeClass('disabled');
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // DISABLEAR EL DE CREDITO
|
|
|
|
|
+ $("#customer_info").addClass("hidden");
|
|
|
|
|
+ $('#types_cash').click();
|
|
|
|
|
+ $('#types_credit').attr('disabled', true);
|
|
|
|
|
+ $('#types_credit').closest('label').addClass('disabled');
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- function enumeratePreSales() {
|
|
|
|
|
- if($('#reset_pre_sales').prop("disabled") == false) {
|
|
|
|
|
- var table = $('#products_table').dataTable();
|
|
|
|
|
- var counter = 1;
|
|
|
|
|
- $('#products_table tbody tr').each(function() {
|
|
|
|
|
- $(this).find('td:eq(0)').html($(this).find('td:eq(0)').html().replace('#', counter));
|
|
|
|
|
- counter++;
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ function enumeratePreSales() {
|
|
|
|
|
+ if($('#reset_pre_sales').prop("disabled") == false) {
|
|
|
|
|
+ var table = $('#products_table').dataTable();
|
|
|
|
|
+ var counter = 1;
|
|
|
|
|
+ $('#products_table tbody tr').each(function() {
|
|
|
|
|
+ $(this).find('td:eq(0)').html($(this).find('td:eq(0)').html().replace('#', counter));
|
|
|
|
|
+ counter++;
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- function generateSaleCode() {
|
|
|
|
|
- if($('#sale_open_cash_register_id').val()) {
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "get",
|
|
|
|
|
- url: '/get_next_sale_code/' + $('#sale_open_cash_register_id').val(),
|
|
|
|
|
- dataType: 'text',
|
|
|
|
|
- success: function(data) {
|
|
|
|
|
- $('#sale_sale_code').val(data);
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ function generateSaleCode() {
|
|
|
|
|
+ if($('#sale_open_cash_register_id').val()) {
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "get",
|
|
|
|
|
+ url: '/get_next_sale_code/' + $('#sale_open_cash_register_id').val(),
|
|
|
|
|
+ dataType: 'text',
|
|
|
|
|
+ success: function(data) {
|
|
|
|
|
+ $('#sale_sale_code').val(data);
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- function findProductByBarcode(barcode) {
|
|
|
|
|
- var customer = $('#sale_customer_id').val();
|
|
|
|
|
- var openCash = $('#sale_open_cash_register_id').val();
|
|
|
|
|
- var saleType = $('form input[type=radio]:checked').val();
|
|
|
|
|
- var seller = $('#sale_seller_id').val();
|
|
|
|
|
- if(customer && openCash && saleType && seller) {
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "get",
|
|
|
|
|
- url: '/add_pre_sale_by_barcode/' + barcode + "/" + customer + "/" + openCash + "/" + saleType,
|
|
|
|
|
- dataType: 'script',
|
|
|
|
|
- success: function(data) {
|
|
|
|
|
- calculateTotals();
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- toastr["error"]("Falta seleccionar datos del formulario.");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function findProductByBarcode(barcode) {
|
|
|
|
|
+ var customer = $('#sale_customer_id').val();
|
|
|
|
|
+ var openCash = $('#sale_open_cash_register_id').val();
|
|
|
|
|
+ var saleType = $('form input[type=radio]:checked').val();
|
|
|
|
|
+ var seller = $('#sale_seller_id').val();
|
|
|
|
|
+ if(customer && openCash && saleType && seller) {
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "get",
|
|
|
|
|
+ url: '/add_pre_sale_by_barcode/' + barcode + "/" + customer + "/" + openCash + "/" + saleType,
|
|
|
|
|
+ dataType: 'script',
|
|
|
|
|
+ success: function(data) {
|
|
|
|
|
+ calculateTotals();
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ toastr["error"]("Falta seleccionar datos del formulario.");
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
</script>
|
|
</script>
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|