|
|
@@ -11,7 +11,7 @@
|
|
|
<span class="input-group-addon"><i class="fa fa-barcode"></i></span>
|
|
|
<%= f.text_field :purchase_code, {:class=>"form-control", :readonly => true} %>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
<!-- fecha -->
|
|
|
<div class="form-group">
|
|
|
<%= f.label :purchase_date, {:class=>"col-md-2 control-label"} do %> Fecha
|
|
|
@@ -21,26 +21,26 @@
|
|
|
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
|
|
|
<%= f.date_field :purchase_date, {:value=>Date.today, :class=>"form-control", :readonly => true} %>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
<!-- tipo de destino -->
|
|
|
<div class="form-group">
|
|
|
- <%= label_tag 'destiny', {:class=>"col-md-2 control-label"} do %> Destino del producto
|
|
|
+ <%= label_tag 'destiny', {:class=>"col-md-2 control-label"} do %> Destino del producto
|
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
|
<div class="col-md-3" style="padding-left:0px;padding-right:0px">
|
|
|
<%= check_box_tag('destiny', 'warehouse', (@destiny == 'warehouse' ? true : false),
|
|
|
- {
|
|
|
+ {
|
|
|
class: "make-switch",
|
|
|
disabled: @disable_destiny,
|
|
|
data: {
|
|
|
on_color: "success",
|
|
|
off_color: "warning",
|
|
|
- on_text: "Almacén",
|
|
|
+ on_text: "Almacén",
|
|
|
off_text: "Punto de venta"
|
|
|
}
|
|
|
}) %>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
<!-- punto de venta -->
|
|
|
<div class= "form-group <%=(@destiny == 'pointsale' ? '' : 'hidden')%>" id='pointsale_div'>
|
|
|
<%= f.label :pointsale_id, "Punto de venta", {:class=>"col-md-2 control-label"} do %> Punto de venta
|
|
|
@@ -50,7 +50,7 @@
|
|
|
<%= f.collection_select :pointsale_id, Pointsale.activos, :id, :name, {:prompt => "Seleccione"}, {:class => "form-control select2", :disabled => @disable_pointsale} %>
|
|
|
<%= f.hidden_field :pointsale_id, {:id => 'pointsale'} %>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
<!-- almacen -->
|
|
|
<div class= "form-group <%=(@destiny == 'warehouse' ? '' : 'hidden')%>" id='warehouse_div'>
|
|
|
<%= f.label :warehouse_id, "Almacén", {:class=>"col-md-2 control-label"} do %> Almacén
|
|
|
@@ -60,7 +60,7 @@
|
|
|
<%= f.collection_select :warehouse_id, Warehouse.activos, :id, :name, {:prompt => "Seleccione"}, {:class => "form-control select2", :disabled => @disable_warehouse} %>
|
|
|
<%= f.hidden_field :warehouse_id, {:id => 'warehouse'} %>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
<!-- proveedor -->
|
|
|
<div class="form-group">
|
|
|
<%= f.label :supplier_id, "Proveedor", {:class=>"col-md-2 control-label"} do %> Proveedor
|
|
|
@@ -70,24 +70,24 @@
|
|
|
<%= f.collection_select :supplier_id, Supplier.activos, :id, :nick_name, {:prompt => "Seleccione"}, {:class => "form-control select2", :disabled => @disable_supplier} %>
|
|
|
<%= f.hidden_field :supplier_id, {:id => 'supplier'} %>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
<div class="form-group">
|
|
|
- <%= f.label :is_in_dollars, {:class=>"col-md-2 control-label"} do %> tipo de Moneda
|
|
|
+ <%= f.label :is_in_dollars, {:class=>"col-md-2 control-label"} do %> tipo de Moneda
|
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
|
<div class="col-md-3" style="padding-left:0px;padding-right:0px">
|
|
|
- <%= f.check_box(:is_in_dollars,
|
|
|
+ <%= f.check_box(:is_in_dollars,
|
|
|
{
|
|
|
class: "make-switch",
|
|
|
disabled: @disable_is_in_dollars,
|
|
|
data: {
|
|
|
on_color: "success",
|
|
|
off_color: "warning",
|
|
|
- on_text: "Dolares",
|
|
|
+ on_text: "Dolares",
|
|
|
off_text: "Pesos"
|
|
|
}
|
|
|
},
|
|
|
- "true", "false"
|
|
|
+ "true", "false"
|
|
|
) %>
|
|
|
</div>
|
|
|
<%= f.hidden_field :is_in_dollars, {:id => 'is_in_dollars'} %>
|
|
|
@@ -97,34 +97,34 @@
|
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
|
<div class="col-md-3 input-group">
|
|
|
- <span class="input-group-addon"><i class="fa fa-usd"></i></span>
|
|
|
+ <span class="input-group-addon"><i class="fa fa-usd"></i></span>
|
|
|
<%= f.number_field :exchange, {:class=>"form-control", :step=>"any"} %>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
<!-- boton para resetear datos -->
|
|
|
<div class="col-md-offset-10 col-md-2">
|
|
|
<button id="reset_pre_purchases" type="button" class="btn btn-warning" <%= @disabled_button ? 'disabled' : '' %> onclick="deletePrePurchases()">Restaurar compra</button>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
<!-- agregar productos -->
|
|
|
<h4 class="form-section"> Agregar producto</h4>
|
|
|
<div class="row">
|
|
|
- <div class='col-md-12'>
|
|
|
+ <div class='col-md-12'>
|
|
|
<div class="col-md-10">
|
|
|
<div class="form-group">
|
|
|
<label class="col-md-2 control-label" for="typeahead"> Producto
|
|
|
<span class="required">*</span>
|
|
|
</label>
|
|
|
- <div class="col-md-4">
|
|
|
- <input class="form-control" type="text" id="typeahead" data-option-url="/find_products/%QUERY">
|
|
|
+ <div class="col-md-4">
|
|
|
+ <input class="form-control" type="text" id="typeahead">
|
|
|
</div>
|
|
|
- <button id="products_new" disabled class="btn btn-success" type="button" onclick="addRow()"> <i class="fa fa-plus"></i> Agregar </button>
|
|
|
- </div>
|
|
|
+ <button id="products_new" disabled class="btn btn-success" type="button" onclick="addRow()"> <i class="fa fa-plus"></i> Agregar </button>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
<div class="col-md-2">
|
|
|
- <button id="products_add_new" class="btn btn-success" type="button" onclick="addNewProduct()"> <i class="fa fa-plus"></i> Nuevo Producto </button>
|
|
|
+ <button id="products_add_new" class="btn btn-success" type="button" onclick="addNewProduct()"> <i class="fa fa-plus"></i> Nuevo Producto </button>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
<!-- lista de productos -->
|
|
|
<h4 class="form-section"> Lista de productos</h4>
|
|
|
<div class="portlet-body">
|
|
|
@@ -159,7 +159,7 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="col-md-offset-1 col-md-5">
|
|
|
- <div class="well">
|
|
|
+ <div class="well">
|
|
|
<div class="row static-info align-reverse">
|
|
|
<div class="col-md-4 name"> Sub Total: </div>
|
|
|
<div class="col-md-8 value " id="amount_div">
|
|
|
@@ -175,7 +175,7 @@
|
|
|
<div class="col-md-8 value " id="tax_div">
|
|
|
<div class="input-group">
|
|
|
<span class="input-group-addon">$ </span>
|
|
|
- <%= f.text_field :tax, {:class=>"form-control descto", :readonly => true, :id => "tax"} %>
|
|
|
+ <%= f.text_field :tax, {:class=>"form-control descto", :readonly => true, :id => "tax"} %>
|
|
|
<span class="input-group-addon"></span>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -186,32 +186,32 @@
|
|
|
<div class="input-group">
|
|
|
<span class="input-group-addon">$ </span>
|
|
|
<%= f.text_field :total, {:class=>"form-control descto", :readonly => true, :id => "total"} %>
|
|
|
- <span class="input-group-addon"></span>
|
|
|
+ <span class="input-group-addon"></span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="col-md-offset-7 col-md-5 hidden" id="total_in_mxn_div">
|
|
|
- <div class="well">
|
|
|
+ <div class="well">
|
|
|
<div class="row static-info align-reverse">
|
|
|
<div class="col-md-4 name"> Total en pesos: </div>
|
|
|
<div class="col-md-8 value ">
|
|
|
<div class="input-group">
|
|
|
<span class="input-group-addon">$ </span>
|
|
|
<%= text_field_tag :total_in_mxn, '' , :class=>"form-control", :readonly => true %>
|
|
|
- <span class="input-group-addon">MXN</span>
|
|
|
+ <span class="input-group-addon">MXN</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
<!-- acciones del form -->
|
|
|
<div class="form-actions">
|
|
|
<div class="row">
|
|
|
<div class="col-md-offset-2 col-md-9">
|
|
|
- <%= f.submit 'Guardar', {:class=>"btn green"} %>
|
|
|
+ <%= f.submit 'Guardar', {:class=>"btn green"} %>
|
|
|
<%= link_to 'Cancelar', purchases_path(:filter => @filter, :current_page => @current_page), {:class=>"btn default"} %>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -239,12 +239,12 @@
|
|
|
$('#purchase_is_in_dollars').on('switchChange.bootstrapSwitch', function(event, state) {
|
|
|
showExchangeField(state);
|
|
|
$('#is_in_dollars').val(state);
|
|
|
- });
|
|
|
+ });
|
|
|
|
|
|
$("#new_pre_purchase").bind('ajax:complete', function() {
|
|
|
calculateTotals();
|
|
|
- $('#purchase_is_in_dollars').bootstrapSwitch('disabled', true);
|
|
|
- $('#destiny').bootstrapSwitch('disabled', true);
|
|
|
+ $('#purchase_is_in_dollars').bootstrapSwitch('disabled', true);
|
|
|
+ $('#destiny').bootstrapSwitch('disabled', true);
|
|
|
});
|
|
|
|
|
|
$('#purchase_supplier_id').on('change', function() {
|
|
|
@@ -276,7 +276,7 @@
|
|
|
|
|
|
$('body').barcodeListener().on('barcode.valid', function(e, code) {
|
|
|
findProductByBarcode(code);
|
|
|
- });
|
|
|
+ });
|
|
|
|
|
|
var bloodhound = new Bloodhound({
|
|
|
datumTokenizer: function (d) {
|
|
|
@@ -284,7 +284,7 @@
|
|
|
},
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
remote: {
|
|
|
- url: "/find_products/" +"%QUERY",
|
|
|
+ url: '/find_products?query=%QUERY',
|
|
|
wildcard: '%QUERY'
|
|
|
}
|
|
|
});
|
|
|
@@ -293,7 +293,7 @@
|
|
|
$('#typeahead').typeahead(
|
|
|
{
|
|
|
minLength: 3
|
|
|
- },
|
|
|
+ },
|
|
|
{
|
|
|
displayKey: 'name',
|
|
|
source: bloodhound.ttAdapter(),
|
|
|
@@ -313,9 +313,9 @@
|
|
|
'</div>' +
|
|
|
'<div class="media-body">' +
|
|
|
'<h4 class="media-heading"><strong>{{sku}}</strong> | {{name}}</h4>' +
|
|
|
- '<p>{{barcode}}</p>' +
|
|
|
+ '<p>{{barcode}}</p>' +
|
|
|
'<p>{{description}}</p>' +
|
|
|
- '<p>{{display_attributes}}</p>' +
|
|
|
+ '<p>{{display_attributes}}</p>' +
|
|
|
'</div>' +
|
|
|
'</div>')
|
|
|
}
|
|
|
@@ -330,7 +330,7 @@
|
|
|
var warehouse = $('#purchase_warehouse_id').val();
|
|
|
|
|
|
if( (supplier && pointsale) || (supplier && warehouse) ) {
|
|
|
- $('#products_new').attr('disabled', false);
|
|
|
+ $('#products_new').attr('disabled', false);
|
|
|
} else {
|
|
|
toastr["error"]("Se debe seleccionar proveedor y destino de la compra.");
|
|
|
}
|
|
|
@@ -345,7 +345,7 @@
|
|
|
if( (supplier && pointsale) || (supplier && warehouse) ) {
|
|
|
$.ajax({
|
|
|
type: "GET",
|
|
|
- url: "/products/new",
|
|
|
+ url: "/products/new",
|
|
|
dataType: "script",
|
|
|
data: {
|
|
|
remoto: true,
|
|
|
@@ -355,7 +355,7 @@
|
|
|
exchange: exchange
|
|
|
},
|
|
|
success: function(xhr, status, error) {}
|
|
|
- });
|
|
|
+ });
|
|
|
} else {
|
|
|
toastr["error"]("Se debe seleccionar proveedor y destino de la compra.");
|
|
|
}
|
|
|
@@ -375,7 +375,7 @@
|
|
|
$('#pre_purchase_total').val(0);
|
|
|
|
|
|
$('#new_pre_purchase').submit();
|
|
|
- $('#typeahead').typeahead('val','');
|
|
|
+ $('#typeahead').typeahead('val','');
|
|
|
$('#products_new').attr('disabled', true);
|
|
|
}
|
|
|
}
|
|
|
@@ -393,11 +393,11 @@
|
|
|
table.row(input.closest('tr')).remove().draw();
|
|
|
calculateTotals();
|
|
|
}
|
|
|
- });
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
function updateQuantity(input) {
|
|
|
- if(input.val()) {
|
|
|
+ if(input.val()) {
|
|
|
clearTimeout(timeout);
|
|
|
timeout = setTimeout(function () {
|
|
|
tax = 0;
|
|
|
@@ -413,9 +413,9 @@
|
|
|
taxPercent = parseFloat($('#tax_percent').val()) / 100
|
|
|
tax = (taxPercent * amount) / (1 + taxPercent);
|
|
|
}
|
|
|
- input.closest('tr').find('td:eq(6)').text(Math.round(tax * 100) / 100);
|
|
|
- input.closest('tr').find('td:eq(7)').text(Math.round(amount * 100) / 100);
|
|
|
- calculateTotals();
|
|
|
+ input.closest('tr').find('td:eq(6)').text(Math.round(tax * 100) / 100);
|
|
|
+ input.closest('tr').find('td:eq(7)').text(Math.round(amount * 100) / 100);
|
|
|
+ calculateTotals();
|
|
|
|
|
|
var idText = input.closest('tr').attr('id');
|
|
|
var prePurchaseId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
|
|
|
@@ -427,8 +427,8 @@
|
|
|
data: {pre_purchase: {quantity: quantity }},
|
|
|
success: function(xhr, status, error) {
|
|
|
}
|
|
|
- });
|
|
|
- }, 700);
|
|
|
+ });
|
|
|
+ }, 700);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -456,8 +456,8 @@
|
|
|
taxPercent = parseFloat($('#tax_percent').val()) / 100
|
|
|
tax = (taxPercent * amount) / (1 + taxPercent);
|
|
|
}
|
|
|
- input.closest('tr').find('td:eq(6)').text(Math.round(tax * 100) / 100);
|
|
|
- input.closest('tr').find('td:eq(7)').text(Math.round(amount * 100) / 100);
|
|
|
+ input.closest('tr').find('td:eq(6)').text(Math.round(tax * 100) / 100);
|
|
|
+ input.closest('tr').find('td:eq(7)').text(Math.round(amount * 100) / 100);
|
|
|
var preIdText = input.closest('tr').attr('id');
|
|
|
var prePurchaseId = preIdText.substring(preIdText.lastIndexOf('_') + 1, preIdText.length);
|
|
|
$.ajax({
|
|
|
@@ -466,25 +466,25 @@
|
|
|
dataType: "json",
|
|
|
data: {pre_purchase: {quantity: quantity }},
|
|
|
success: function(xhr, status, error) {
|
|
|
- calculateTotals();
|
|
|
+ calculateTotals();
|
|
|
}
|
|
|
- });
|
|
|
+ });
|
|
|
}
|
|
|
- });
|
|
|
- }, 600);
|
|
|
+ });
|
|
|
+ }, 600);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function calculateTotals() {
|
|
|
var amount = 0;
|
|
|
var tax = 0;
|
|
|
- var total = 0;
|
|
|
+ var total = 0;
|
|
|
$('#products_table tbody tr td:nth-child(7)').each(function() {
|
|
|
tax+= parseFloat($(this).text());
|
|
|
- });
|
|
|
+ });
|
|
|
$('#products_table tbody tr td:nth-child(8)').each(function() {
|
|
|
amount+= parseFloat($(this).text());
|
|
|
- });
|
|
|
+ });
|
|
|
amount = amount - tax;
|
|
|
total = amount + tax;
|
|
|
$('#tax').val(Math.round(tax * 100) / 100);
|
|
|
@@ -508,20 +508,20 @@
|
|
|
$('#purchase_purchase_code').val('');
|
|
|
$("#purchase_supplier_id").select2().select2("val", null);
|
|
|
$("#purchase_supplier_id").attr('disabled',false);
|
|
|
- $("#purchase_pointsale_id").select2().select2("val", null);
|
|
|
- $("#purchase_pointsale_id").attr('disabled',false);
|
|
|
- $("#purchase_warehouse_id").select2().select2("val", null);
|
|
|
- $("#purchase_warehouse_id").attr('disabled',false);
|
|
|
+ $("#purchase_pointsale_id").select2().select2("val", null);
|
|
|
+ $("#purchase_pointsale_id").attr('disabled',false);
|
|
|
+ $("#purchase_warehouse_id").select2().select2("val", null);
|
|
|
+ $("#purchase_warehouse_id").attr('disabled',false);
|
|
|
$("#reset_pre_purchases").attr('disabled',true);
|
|
|
- $('#destiny').bootstrapSwitch('disabled',false);
|
|
|
+ $('#destiny').bootstrapSwitch('disabled',false);
|
|
|
$('#purchase_is_in_dollars').bootstrapSwitch('disabled', false);
|
|
|
- $('#purchase_is_in_dollars').bootstrapSwitch('state', false);
|
|
|
+ $('#purchase_is_in_dollars').bootstrapSwitch('state', false);
|
|
|
calculateTotals();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- function addPurchase() {
|
|
|
+ function addPurchase() {
|
|
|
$('#purchase_form').submit();
|
|
|
}
|
|
|
|
|
|
@@ -533,8 +533,8 @@
|
|
|
dataType: 'text',
|
|
|
success: function(data) {
|
|
|
$('#purchase_purchase_code').val(data);
|
|
|
- },
|
|
|
- });
|
|
|
+ },
|
|
|
+ });
|
|
|
} else if($('#purchase_warehouse_id').val()) {
|
|
|
$.ajax({
|
|
|
type: "get",
|
|
|
@@ -542,8 +542,8 @@
|
|
|
dataType: 'text',
|
|
|
success: function(data) {
|
|
|
$('#purchase_purchase_code').val(data);
|
|
|
- },
|
|
|
- });
|
|
|
+ },
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -564,8 +564,8 @@
|
|
|
dataType: 'script',
|
|
|
success: function(data) {
|
|
|
calculateTotals();
|
|
|
- },
|
|
|
- });
|
|
|
+ },
|
|
|
+ });
|
|
|
} else {
|
|
|
toastr["error"]("Se debe seleccionar proveedor y destino de la compra.");
|
|
|
}
|
|
|
@@ -578,7 +578,7 @@
|
|
|
$('#products_table tbody tr').each(function() {
|
|
|
$(this).find('td:eq(0)').html($(this).find('td:eq(0)').html().replace('#', counter));
|
|
|
counter++;
|
|
|
- });
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -588,18 +588,18 @@
|
|
|
if (state) {
|
|
|
$('#warehouse_div').removeClass('hidden');
|
|
|
$("#purchase_warehouse_id").select2();
|
|
|
- $('#pointsale_div').addClass('hidden');
|
|
|
+ $('#pointsale_div').addClass('hidden');
|
|
|
<% if current_user.usertype == 'A' %>
|
|
|
$('#purchase_pointsale_id').select2('val', null);
|
|
|
- <% end %>
|
|
|
+ <% end %>
|
|
|
} else {
|
|
|
$('#pointsale_div').removeClass('hidden');
|
|
|
- $("#purchase_pointsale_id").select2();
|
|
|
+ $("#purchase_pointsale_id").select2();
|
|
|
$('#warehouse_div').addClass('hidden');
|
|
|
<% if current_user.usertype == 'A' %>
|
|
|
$('#purchase_warehouse_id').select2('val', null);
|
|
|
<% end %>
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function showExchangeField(state) {
|
|
|
@@ -617,7 +617,7 @@
|
|
|
$('#tax_div div span:last-child').html('MXN');
|
|
|
$('#total_div div span:last-child').html('MXN');
|
|
|
$("#total_in_mxn_div").addClass('hidden');
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
</script>
|
|
|
|