|
@@ -1,30 +1,30 @@
|
|
|
-<%= form_for(@purchase, :html => {:class=>"form-horizontal", :id=> "purchase_form"}) do |f| %>
|
|
|
|
|
|
|
+<%= form_for(@purchase, html: { class: "form-horizontal", id: "purchase_form" }) do |f| %>
|
|
|
<div class="portlet-body form">
|
|
<div class="portlet-body form">
|
|
|
<%= hidden_field_tag :tax_percent, @pos_config.tax_percent %>
|
|
<%= hidden_field_tag :tax_percent, @pos_config.tax_percent %>
|
|
|
<div id="error_explanation"></div>
|
|
<div id="error_explanation"></div>
|
|
|
<!-- purchase code -->
|
|
<!-- purchase code -->
|
|
|
<div class="form-group">
|
|
<div class="form-group">
|
|
|
- <%= f.label :purchase_code, {:class=>"col-md-2 control-label"} do %> Codigo de compra
|
|
|
|
|
|
|
+ <%= f.label :purchase_code, { class: "col-md-2 control-label" } do %> Código de compra
|
|
|
<span class="required">*</span>
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
<% end %>
|
|
|
<div class="col-md-3 input-group">
|
|
<div class="col-md-3 input-group">
|
|
|
<span class="input-group-addon"><i class="fa fa-barcode"></i></span>
|
|
<span class="input-group-addon"><i class="fa fa-barcode"></i></span>
|
|
|
- <%= f.text_field :purchase_code, {:class=>"form-control", :readonly => true} %>
|
|
|
|
|
|
|
+ <%= f.text_field :purchase_code, { class: "form-control", readonly: true } %>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<!-- fecha -->
|
|
<!-- fecha -->
|
|
|
<div class="form-group">
|
|
<div class="form-group">
|
|
|
- <%= f.label :purchase_date, {:class=>"col-md-2 control-label"} do %> Fecha
|
|
|
|
|
|
|
+ <%= f.label :purchase_date, { class: "col-md-2 control-label" } do %> Fecha
|
|
|
<span class="required">*</span>
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
<% end %>
|
|
|
<div class="col-md-3 input-group date date-picker">
|
|
<div class="col-md-3 input-group date date-picker">
|
|
|
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
|
|
<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} %>
|
|
|
|
|
|
|
+ <%= f.date_field :purchase_date, { value: Date.today, class: "form-control", readonly: true } %>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<!-- tipo de destino -->
|
|
<!-- tipo de destino -->
|
|
|
<div class="form-group">
|
|
<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>
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
<% end %>
|
|
|
<div class="col-md-3" style="padding-left:0px;padding-right:0px">
|
|
<div class="col-md-3" style="padding-left:0px;padding-right:0px">
|
|
@@ -42,40 +42,40 @@
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<!-- punto de venta -->
|
|
<!-- 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
|
|
|
|
|
|
|
+ <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
|
|
|
<span class="required">*</span>
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
<% end %>
|
|
|
<div class="input-group col-md-3 select2-bootstrap-prepend">
|
|
<div class="input-group col-md-3 select2-bootstrap-prepend">
|
|
|
- <%= 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'} %>
|
|
|
|
|
|
|
+ <%= 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>
|
|
</div>
|
|
|
<!-- almacen -->
|
|
<!-- 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
|
|
|
|
|
|
|
+ <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
|
|
|
<span class="required">*</span>
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
<% end %>
|
|
|
<div class="input-group col-md-3 select2-bootstrap-prepend">
|
|
<div class="input-group col-md-3 select2-bootstrap-prepend">
|
|
|
- <%= 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'} %>
|
|
|
|
|
|
|
+ <%= 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>
|
|
</div>
|
|
|
<!-- proveedor -->
|
|
<!-- proveedor -->
|
|
|
<div class="form-group">
|
|
<div class="form-group">
|
|
|
- <%= f.label :supplier_id, "Proveedor", {:class=>"col-md-2 control-label"} do %> Proveedor
|
|
|
|
|
|
|
+ <%= f.label :supplier_id, "Proveedor", { class: "col-md-2 control-label" } do %> Proveedor
|
|
|
<span class="required">*</span>
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
<% end %>
|
|
|
<div class="input-group col-md-3 select2-bootstrap-prepend">
|
|
<div class="input-group col-md-3 select2-bootstrap-prepend">
|
|
|
- <%= 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'} %>
|
|
|
|
|
|
|
+ <%= 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>
|
|
|
<div class="form-group">
|
|
<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>
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
<% end %>
|
|
|
- <div class="col-md-3" style="padding-left:0px;padding-right:0px">
|
|
|
|
|
|
|
+ <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",
|
|
class: "make-switch",
|
|
@@ -90,15 +90,15 @@
|
|
|
"true", "false"
|
|
"true", "false"
|
|
|
) %>
|
|
) %>
|
|
|
</div>
|
|
</div>
|
|
|
- <%= f.hidden_field :is_in_dollars, {:id => 'is_in_dollars'} %>
|
|
|
|
|
|
|
+ <%= f.hidden_field :is_in_dollars, { id: 'is_in_dollars' } %>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="form-group hidden" id="exchange_div">
|
|
<div class="form-group hidden" id="exchange_div">
|
|
|
- <%= f.label :exchange, {:class=>"col-md-2 control-label"} do %> Tipo de cambio
|
|
|
|
|
|
|
+ <%= f.label :exchange, { class: "col-md-2 control-label" } do %> Tipo de cambio
|
|
|
<span class="required">*</span>
|
|
<span class="required">*</span>
|
|
|
<% end %>
|
|
<% end %>
|
|
|
<div class="col-md-3 input-group">
|
|
<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"} %>
|
|
|
|
|
|
|
+ <%= f.number_field :exchange, { class: "form-control", step: "any" } %>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<!-- boton para resetear datos -->
|
|
<!-- boton para resetear datos -->
|
|
@@ -121,7 +121,7 @@
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="col-md-2">
|
|
<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>
|
|
|
</div>
|
|
</div>
|
|
@@ -143,7 +143,7 @@
|
|
|
</tr>
|
|
</tr>
|
|
|
</thead>
|
|
</thead>
|
|
|
<tbody>
|
|
<tbody>
|
|
|
- <%= render @pre_purchases %>
|
|
|
|
|
|
|
+ <%= render @pre_purchases %>
|
|
|
</tbody>
|
|
</tbody>
|
|
|
</table>
|
|
</table>
|
|
|
</div>
|
|
</div>
|
|
@@ -152,67 +152,67 @@
|
|
|
<div class="row">
|
|
<div class="row">
|
|
|
<div class="col-md-6">
|
|
<div class="col-md-6">
|
|
|
<div class="form-group">
|
|
<div class="form-group">
|
|
|
- <%= f.label :observations, "Observaciones", {:class=>"col-md-3 control-label"} %>
|
|
|
|
|
|
|
+ <%= f.label :observations, "Observaciones", { class: "col-md-3 control-label" } %>
|
|
|
<div class="col-md-8">
|
|
<div class="col-md-8">
|
|
|
- <%= f.text_area :observations, {:class=>"form-control", :rows=>5} %>
|
|
|
|
|
|
|
+ <%= f.text_area :observations, { class: "form-control", rows: 5 } %>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="col-md-offset-1 col-md-5">
|
|
<div class="col-md-offset-1 col-md-5">
|
|
|
- <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">
|
|
|
|
|
- <div class="input-group">
|
|
|
|
|
- <span class="input-group-addon">$ </span>
|
|
|
|
|
- <%= f.text_field :amount, {:class=>"form-control sub_total", :readonly => true, :id => "amount"} %>
|
|
|
|
|
- <span class="input-group-addon"></span>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <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">
|
|
|
|
|
+ <div class="input-group">
|
|
|
|
|
+ <span class="input-group-addon">$ </span>
|
|
|
|
|
+ <%= f.text_field :amount, { class: "form-control sub_total", readonly: true, id: "amount" } %>
|
|
|
|
|
+ <span class="input-group-addon"></span>
|
|
|
</div>
|
|
</div>
|
|
|
- <div class="row static-info align-reverse">
|
|
|
|
|
- <div class="col-md-4 name"> IVA: </div>
|
|
|
|
|
- <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"} %>
|
|
|
|
|
- <span class="input-group-addon"></span>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="row static-info align-reverse">
|
|
|
|
|
+ <div class="col-md-4 name"> IVA: </div>
|
|
|
|
|
+ <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" } %>
|
|
|
|
|
+ <span class="input-group-addon"></span>
|
|
|
</div>
|
|
</div>
|
|
|
- <div class="row static-info align-reverse">
|
|
|
|
|
- <div class="col-md-4 name"> Total: </div>
|
|
|
|
|
- <div class="col-md-8 value " id="total_div">
|
|
|
|
|
- <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>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="row static-info align-reverse">
|
|
|
|
|
+ <div class="col-md-4 name"> Total: </div>
|
|
|
|
|
+ <div class="col-md-8 value " id="total_div">
|
|
|
|
|
+ <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>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="col-md-offset-7 col-md-5 hidden" id="total_in_mxn_div">
|
|
<div class="col-md-offset-7 col-md-5 hidden" id="total_in_mxn_div">
|
|
|
- <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>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <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>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
<!-- acciones del form -->
|
|
<!-- acciones del form -->
|
|
|
<div class="form-actions">
|
|
<div class="form-actions">
|
|
|
<div class="row">
|
|
<div class="row">
|
|
|
<div class="col-md-offset-2 col-md-9">
|
|
<div class="col-md-offset-2 col-md-9">
|
|
|
- <%= f.submit 'Guardar', {:class=>"btn green"} %>
|
|
|
|
|
- <%= link_to 'Cancelar', purchases_path(:filter => @filter, :current_page => @current_page), {:class=>"btn default"} %>
|
|
|
|
|
|
|
+ <%= f.submit 'Guardar', { class: "btn green" } %>
|
|
|
|
|
+ <%= link_to 'Cancelar', purchases_path(filter: @filter, current_page: @current_page), { class: "btn default" } %>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
@@ -272,354 +272,350 @@
|
|
|
generatePurchaseCode();
|
|
generatePurchaseCode();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- $('body').barcodeListener().on('barcode.valid', function(e, code) {
|
|
|
|
|
- findProductByBarcode(code);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- var bloodhound = new Bloodhound({
|
|
|
|
|
- datumTokenizer: function (d) {
|
|
|
|
|
- return Bloodhound.tokenizers.whitespace(d.value);
|
|
|
|
|
- },
|
|
|
|
|
- queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
|
- remote: {
|
|
|
|
|
- url: '/find_products?query=%QUERY',
|
|
|
|
|
- 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;
|
|
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- var supplier = $('#purchase_supplier_id').val();
|
|
|
|
|
- var pointsale = $('#purchase_pointsale_id').val();
|
|
|
|
|
- var warehouse = $('#purchase_warehouse_id').val();
|
|
|
|
|
|
|
+ $('body').barcodeListener().on('barcode.valid', function(e, code) {
|
|
|
|
|
+ findProductByBarcode(code);
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- if( (supplier && pointsale) || (supplier && warehouse) ) {
|
|
|
|
|
- $('#products_new').attr('disabled', false);
|
|
|
|
|
- } else {
|
|
|
|
|
- toastr["error"]("Se debe seleccionar proveedor y destino de la compra.");
|
|
|
|
|
|
|
+ var bloodhound = new Bloodhound({
|
|
|
|
|
+ datumTokenizer: function (d) {
|
|
|
|
|
+ return Bloodhound.tokenizers.whitespace(d.value);
|
|
|
|
|
+ },
|
|
|
|
|
+ queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
|
+ remote: {
|
|
|
|
|
+ url: '/find_products?query=%QUERY',
|
|
|
|
|
+ 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 addNewProduct() {
|
|
|
|
|
- var pointsale = $('#purchase_pointsale_id').val();
|
|
|
|
|
- var supplier = $('#purchase_supplier_id').val();
|
|
|
|
|
- var warehouse = $('#purchase_warehouse_id').val();
|
|
|
|
|
- var exchange = $('#purchase_exchange').val();
|
|
|
|
|
- if( (supplier && pointsale) || (supplier && warehouse) ) {
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "GET",
|
|
|
|
|
- url: "/products/new",
|
|
|
|
|
- dataType: "script",
|
|
|
|
|
- data: {
|
|
|
|
|
- remoto: true,
|
|
|
|
|
- pointsale: pointsale,
|
|
|
|
|
- warehouse: warehouse,
|
|
|
|
|
- supplier: supplier,
|
|
|
|
|
- exchange: exchange
|
|
|
|
|
- },
|
|
|
|
|
- success: function(xhr, status, error) {}
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- toastr["error"]("Se debe seleccionar proveedor y destino de la compra.");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ var supplier = $('#purchase_supplier_id').val();
|
|
|
|
|
+ var pointsale = $('#purchase_pointsale_id').val();
|
|
|
|
|
+ var warehouse = $('#purchase_warehouse_id').val();
|
|
|
|
|
|
|
|
- function addRow() {
|
|
|
|
|
- if(selectedProduct) {
|
|
|
|
|
- $('#pre_purchase_supplier_id').val($('#supplier').val());
|
|
|
|
|
- $('#pre_purchase_pointsale_id').val($('#pointsale').val());
|
|
|
|
|
- $('#pre_purchase_warehouse_id').val($('#warehouse').val());
|
|
|
|
|
- $('#pre_purchase_exchange').val($('#purchase_exchange').val());
|
|
|
|
|
- $('#pre_purchase_price_base').val();
|
|
|
|
|
- $('#pre_purchase_product_id').val(selectedProduct.id);
|
|
|
|
|
- $('#pre_purchase_quantity').val(1);
|
|
|
|
|
- $('#pre_purchase_amount').val(selectedProduct.price_sale);
|
|
|
|
|
- $('#pre_purchase_tax').val(0);
|
|
|
|
|
- $('#pre_purchase_total').val(0);
|
|
|
|
|
-
|
|
|
|
|
- $('#new_pre_purchase').submit();
|
|
|
|
|
- $('#typeahead').typeahead('val','');
|
|
|
|
|
- $('#products_new').attr('disabled', true);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if( (supplier && pointsale) || (supplier && warehouse) ) {
|
|
|
|
|
+ $('#products_new').attr('disabled', false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ toastr["error"]("Se debe seleccionar proveedor y destino de la compra.");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- function deleteRow(input) {
|
|
|
|
|
- var table = $('#products_table').DataTable();
|
|
|
|
|
- var idText = input.closest('tr').attr('id');
|
|
|
|
|
- var prePurchaseId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ function addNewProduct() {
|
|
|
|
|
+ var pointsale = $('#purchase_pointsale_id').val();
|
|
|
|
|
+ var supplier = $('#purchase_supplier_id').val();
|
|
|
|
|
+ var warehouse = $('#purchase_warehouse_id').val();
|
|
|
|
|
+ var exchange = $('#purchase_exchange').val();
|
|
|
|
|
+ if( (supplier && pointsale) || (supplier && warehouse) ) {
|
|
|
$.ajax({
|
|
$.ajax({
|
|
|
- type: "DELETE",
|
|
|
|
|
- url: "/pre_purchases/" + prePurchaseId,
|
|
|
|
|
- dataType: "json",
|
|
|
|
|
- data: "",
|
|
|
|
|
- success: function(xhr, status, error) {
|
|
|
|
|
- table.row(input.closest('tr')).remove().draw();
|
|
|
|
|
- calculateTotals();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ type: "GET",
|
|
|
|
|
+ url: "/products/new",
|
|
|
|
|
+ dataType: "script",
|
|
|
|
|
+ data: {
|
|
|
|
|
+ remoto: true,
|
|
|
|
|
+ pointsale: pointsale,
|
|
|
|
|
+ warehouse: warehouse,
|
|
|
|
|
+ supplier: supplier,
|
|
|
|
|
+ exchange: exchange
|
|
|
|
|
+ },
|
|
|
|
|
+ success: function(xhr, status, error) {}
|
|
|
});
|
|
});
|
|
|
|
|
+ } else {
|
|
|
|
|
+ toastr["error"]("Se debe seleccionar proveedor y destino de la compra.");
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function addRow() {
|
|
|
|
|
+ if(selectedProduct) {
|
|
|
|
|
+ $('#pre_purchase_supplier_id').val($('#supplier').val());
|
|
|
|
|
+ $('#pre_purchase_pointsale_id').val($('#pointsale').val());
|
|
|
|
|
+ $('#pre_purchase_warehouse_id').val($('#warehouse').val());
|
|
|
|
|
+ $('#pre_purchase_exchange').val($('#purchase_exchange').val());
|
|
|
|
|
+ $('#pre_purchase_price_base').val();
|
|
|
|
|
+ $('#pre_purchase_product_id').val(selectedProduct.id);
|
|
|
|
|
+ $('#pre_purchase_quantity').val(1);
|
|
|
|
|
+ $('#pre_purchase_amount').val(selectedProduct.price_sale);
|
|
|
|
|
+ $('#pre_purchase_tax').val(0);
|
|
|
|
|
+ $('#pre_purchase_total').val(0);
|
|
|
|
|
+
|
|
|
|
|
+ $('#new_pre_purchase').submit();
|
|
|
|
|
+ $('#typeahead').typeahead('val','');
|
|
|
|
|
+ $('#products_new').attr('disabled', true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function deleteRow(input) {
|
|
|
|
|
+ var table = $('#products_table').DataTable();
|
|
|
|
|
+ var idText = input.closest('tr').attr('id');
|
|
|
|
|
+ var prePurchaseId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "DELETE",
|
|
|
|
|
+ url: "/pre_purchases/" + prePurchaseId,
|
|
|
|
|
+ dataType: "json",
|
|
|
|
|
+ data: "",
|
|
|
|
|
+ success: function(xhr, status, error) {
|
|
|
|
|
+ table.row(input.closest('tr')).remove().draw();
|
|
|
|
|
+ calculateTotals();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function updateQuantity(input) {
|
|
|
|
|
+ if(input.val()) {
|
|
|
|
|
+ clearTimeout(timeout);
|
|
|
|
|
+ timeout = setTimeout(function () {
|
|
|
|
|
+ tax = 0;
|
|
|
|
|
+ quantity = parseInt(input.val());
|
|
|
|
|
+ // sacar el precio del producto
|
|
|
|
|
+ if (input.closest('tr').find('td:eq(5) input').val()) {
|
|
|
|
|
+ price = parseFloat(input.closest('tr').find('td:eq(5) input').val());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ price = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ amount = price * quantity;
|
|
|
|
|
+ if(input.closest('tr').find('td:eq(0) input').val() == '1') {
|
|
|
|
|
+ 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();
|
|
|
|
|
|
|
|
- function updateQuantity(input) {
|
|
|
|
|
- if(input.val()) {
|
|
|
|
|
- clearTimeout(timeout);
|
|
|
|
|
- timeout = setTimeout(function () {
|
|
|
|
|
- tax = 0;
|
|
|
|
|
- quantity = parseInt(input.val());
|
|
|
|
|
- // sacar el precio del producto
|
|
|
|
|
- if (input.closest('tr').find('td:eq(5) input').val()) {
|
|
|
|
|
- price = parseFloat(input.closest('tr').find('td:eq(5) input').val());
|
|
|
|
|
- } else {
|
|
|
|
|
- price = 0;
|
|
|
|
|
- }
|
|
|
|
|
- amount = price * quantity;
|
|
|
|
|
- if(input.closest('tr').find('td:eq(0) input').val() == '1') {
|
|
|
|
|
- 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();
|
|
|
|
|
-
|
|
|
|
|
- var idText = input.closest('tr').attr('id');
|
|
|
|
|
- var prePurchaseId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
|
|
|
|
|
|
|
+ var idText = input.closest('tr').attr('id');
|
|
|
|
|
+ var prePurchaseId = idText.substring(idText.lastIndexOf('_') + 1, idText.length);
|
|
|
|
|
|
|
|
- $.ajax({
|
|
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "PUT",
|
|
|
|
|
+ url: "/pre_purchases/" + prePurchaseId,
|
|
|
|
|
+ dataType: "json",
|
|
|
|
|
+ data: {pre_purchase: {quantity: quantity }},
|
|
|
|
|
+ success: function(xhr, status, error) {
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }, 700);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function updateProductPrice(input) {
|
|
|
|
|
+ if(input.val()) {
|
|
|
|
|
+ clearTimeout(timeout);
|
|
|
|
|
+ timeout = setTimeout(function () {
|
|
|
|
|
+ price = parseFloat(input.val());
|
|
|
|
|
+ var is_in_dollars = $('#purchase_is_in_dollars').bootstrapSwitch('state');
|
|
|
|
|
+ var exchange = $('#purchase_exchange').val() ? parseFloat($('#purchase_exchange').val()) : '';
|
|
|
|
|
+ var productId = input.closest('td').find('span').text();
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "POST",
|
|
|
|
|
+ url: "/products/" + productId + "/edit_from_purchase",
|
|
|
|
|
+ dataType: "script",
|
|
|
|
|
+ data: {product: {price_base: price }, is_in_dollars: is_in_dollars, exchange: exchange},
|
|
|
|
|
+ success: function(xhr, status, error) {
|
|
|
|
|
+ //actualizar datos en la tabla
|
|
|
|
|
+ tax = 0;
|
|
|
|
|
+ hasTax = input.closest('tr').find('td:eq(0) input').val();
|
|
|
|
|
+ quantity = parseFloat(input.closest('tr').find('td:eq(4) input').val());
|
|
|
|
|
+ price = parseFloat(input.closest('tr').find('td:eq(5) input').val());
|
|
|
|
|
+ amount = price * quantity;
|
|
|
|
|
+ if(hasTax == '1') {
|
|
|
|
|
+ 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);
|
|
|
|
|
+ var preIdText = input.closest('tr').attr('id');
|
|
|
|
|
+ var prePurchaseId = preIdText.substring(preIdText.lastIndexOf('_') + 1, preIdText.length);
|
|
|
|
|
+ $.ajax({
|
|
|
type: "PUT",
|
|
type: "PUT",
|
|
|
url: "/pre_purchases/" + prePurchaseId,
|
|
url: "/pre_purchases/" + prePurchaseId,
|
|
|
dataType: "json",
|
|
dataType: "json",
|
|
|
data: {pre_purchase: {quantity: quantity }},
|
|
data: {pre_purchase: {quantity: quantity }},
|
|
|
success: function(xhr, status, error) {
|
|
success: function(xhr, status, error) {
|
|
|
|
|
+ calculateTotals();
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
- }, 700);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }, 600);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- function updateProductPrice(input) {
|
|
|
|
|
- if(input.val()) {
|
|
|
|
|
- clearTimeout(timeout);
|
|
|
|
|
- timeout = setTimeout(function () {
|
|
|
|
|
- price = parseFloat(input.val());
|
|
|
|
|
- var is_in_dollars = $('#purchase_is_in_dollars').bootstrapSwitch('state');
|
|
|
|
|
- var exchange = $('#purchase_exchange').val() ? parseFloat($('#purchase_exchange').val()) : '';
|
|
|
|
|
- var productId = input.closest('td').find('span').text();
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "POST",
|
|
|
|
|
- url: "/products/" + productId + "/edit_from_purchase",
|
|
|
|
|
- dataType: "script",
|
|
|
|
|
- data: {product: {price_base: price }, is_in_dollars: is_in_dollars, exchange: exchange},
|
|
|
|
|
- success: function(xhr, status, error) {
|
|
|
|
|
- //actualizar datos en la tabla
|
|
|
|
|
- tax = 0;
|
|
|
|
|
- hasTax = input.closest('tr').find('td:eq(0) input').val();
|
|
|
|
|
- quantity = parseFloat(input.closest('tr').find('td:eq(4) input').val());
|
|
|
|
|
- price = parseFloat(input.closest('tr').find('td:eq(5) input').val());
|
|
|
|
|
- amount = price * quantity;
|
|
|
|
|
- if(hasTax == '1') {
|
|
|
|
|
- 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);
|
|
|
|
|
- var preIdText = input.closest('tr').attr('id');
|
|
|
|
|
- var prePurchaseId = preIdText.substring(preIdText.lastIndexOf('_') + 1, preIdText.length);
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "PUT",
|
|
|
|
|
- url: "/pre_purchases/" + prePurchaseId,
|
|
|
|
|
- dataType: "json",
|
|
|
|
|
- data: {pre_purchase: {quantity: quantity }},
|
|
|
|
|
- success: function(xhr, status, error) {
|
|
|
|
|
- calculateTotals();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }, 600);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function calculateTotals() {
|
|
|
|
|
+ var amount = 0;
|
|
|
|
|
+ var tax = 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);
|
|
|
|
|
+ $('#amount').val(Math.round(amount * 100) / 100);
|
|
|
|
|
+ $('#total').val(Math.round(total * 100) / 100);
|
|
|
|
|
+
|
|
|
|
|
+ // mostrar el total en pesos cuando es en dolares
|
|
|
|
|
+ var is_in_dollars = $('#purchase_is_in_dollars').bootstrapSwitch('state');
|
|
|
|
|
+ if (is_in_dollars) {
|
|
|
|
|
+ $('#total_in_mxn').val(Math.round((total * $('#purchase_exchange').val()) * 100) / 100);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- function calculateTotals() {
|
|
|
|
|
- var amount = 0;
|
|
|
|
|
- var tax = 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);
|
|
|
|
|
- $('#amount').val(Math.round(amount * 100) / 100);
|
|
|
|
|
- $('#total').val(Math.round(total * 100) / 100);
|
|
|
|
|
-
|
|
|
|
|
- // mostrar el total en pesos cuando es en dolares
|
|
|
|
|
- var is_in_dollars = $('#purchase_is_in_dollars').bootstrapSwitch('state');
|
|
|
|
|
- if (is_in_dollars) {
|
|
|
|
|
- $('#total_in_mxn').val(Math.round((total * $('#purchase_exchange').val()) * 100) / 100);
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function deletePrePurchases() {
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "get",
|
|
|
|
|
+ url: '/delete_pre_purchases',
|
|
|
|
|
+ dataType: 'json',
|
|
|
|
|
+ success: function(xhr, status, error){
|
|
|
|
|
+ $('#products_table').dataTable().fnClearTable();
|
|
|
|
|
+ $('#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);
|
|
|
|
|
+ $("#reset_pre_purchases").attr('disabled',true);
|
|
|
|
|
+ $('#destiny').bootstrapSwitch('disabled',false);
|
|
|
|
|
+ $('#purchase_is_in_dollars').bootstrapSwitch('disabled', false);
|
|
|
|
|
+ $('#purchase_is_in_dollars').bootstrapSwitch('state', false);
|
|
|
|
|
+ calculateTotals();
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function addPurchase() {
|
|
|
|
|
+ $('#purchase_form').submit();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- function deletePrePurchases() {
|
|
|
|
|
|
|
+ function generatePurchaseCode() {
|
|
|
|
|
+ if($('#purchase_pointsale_id').val()) {
|
|
|
$.ajax({
|
|
$.ajax({
|
|
|
type: "get",
|
|
type: "get",
|
|
|
- url: '/delete_pre_purchases',
|
|
|
|
|
- dataType: 'json',
|
|
|
|
|
- success: function(xhr, status, error){
|
|
|
|
|
- $('#products_table').dataTable().fnClearTable();
|
|
|
|
|
- $('#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);
|
|
|
|
|
- $("#reset_pre_purchases").attr('disabled',true);
|
|
|
|
|
- $('#destiny').bootstrapSwitch('disabled',false);
|
|
|
|
|
- $('#purchase_is_in_dollars').bootstrapSwitch('disabled', false);
|
|
|
|
|
- $('#purchase_is_in_dollars').bootstrapSwitch('state', false);
|
|
|
|
|
- calculateTotals();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ url: '/get_max_purchaseid_by_pointsale/' + $('#purchase_pointsale_id').val(),
|
|
|
|
|
+ dataType: 'text',
|
|
|
|
|
+ success: function(data) {
|
|
|
|
|
+ $('#purchase_purchase_code').val(data);
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ } else if($('#purchase_warehouse_id').val()) {
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "get",
|
|
|
|
|
+ url: '/get_max_purchaseid_by_warehouse/' + $('#purchase_warehouse_id').val(),
|
|
|
|
|
+ dataType: 'text',
|
|
|
|
|
+ success: function(data) {
|
|
|
|
|
+ $('#purchase_purchase_code').val(data);
|
|
|
|
|
+ },
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- function addPurchase() {
|
|
|
|
|
- $('#purchase_form').submit();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ function findProductByBarcode(barcode) {
|
|
|
|
|
+ var supplier = $('#purchase_supplier_id').val();
|
|
|
|
|
+ var pointsale = $('#purchase_pointsale_id').val();
|
|
|
|
|
+ var warehouse = $('#purchase_warehouse_id').val();
|
|
|
|
|
|
|
|
- function generatePurchaseCode() {
|
|
|
|
|
- if($('#purchase_pointsale_id').val()) {
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "get",
|
|
|
|
|
- url: '/get_max_purchaseid_by_pointsale/' + $('#purchase_pointsale_id').val(),
|
|
|
|
|
- dataType: 'text',
|
|
|
|
|
- success: function(data) {
|
|
|
|
|
- $('#purchase_purchase_code').val(data);
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- } else if($('#purchase_warehouse_id').val()) {
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "get",
|
|
|
|
|
- url: '/get_max_purchaseid_by_warehouse/' + $('#purchase_warehouse_id').val(),
|
|
|
|
|
- dataType: 'text',
|
|
|
|
|
- success: function(data) {
|
|
|
|
|
- $('#purchase_purchase_code').val(data);
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (pointsale) {
|
|
|
|
|
+ url = '/add_pre_purchase_by_barcode_pointsale/' + barcode + "/" + supplier + "/" + pointsale;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ url = '/add_pre_purchase_by_barcode_warehouse/' + barcode + "/" + supplier + "/" + warehouse;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- function findProductByBarcode(barcode) {
|
|
|
|
|
- var supplier = $('#purchase_supplier_id').val();
|
|
|
|
|
- var pointsale = $('#purchase_pointsale_id').val();
|
|
|
|
|
- var warehouse = $('#purchase_warehouse_id').val();
|
|
|
|
|
-
|
|
|
|
|
- if (pointsale) {
|
|
|
|
|
- url = '/add_pre_purchase_by_barcode_pointsale/' + barcode + "/" + supplier + "/" + pointsale;
|
|
|
|
|
- } else {
|
|
|
|
|
- url = '/add_pre_purchase_by_barcode_warehouse/' + barcode + "/" + supplier + "/" + warehouse;
|
|
|
|
|
- }
|
|
|
|
|
- if((supplier && pointsale) || (supplier && warehouse)) {
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: "get",
|
|
|
|
|
- url: url,
|
|
|
|
|
- dataType: 'script',
|
|
|
|
|
- success: function(data) {
|
|
|
|
|
- calculateTotals();
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- toastr["error"]("Se debe seleccionar proveedor y destino de la compra.");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if((supplier && pointsale) || (supplier && warehouse)) {
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: "get",
|
|
|
|
|
+ url: url,
|
|
|
|
|
+ dataType: 'script',
|
|
|
|
|
+ success: function(data) {
|
|
|
|
|
+ calculateTotals();
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ toastr["error"]("Se debe seleccionar proveedor y destino de la compra.");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- function enumeratePrePurchases() {
|
|
|
|
|
- if($('#reset_pre_purchases').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 enumeratePrePurchases() {
|
|
|
|
|
+ if($('#reset_pre_purchases').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 setDestiny(state) {
|
|
|
|
|
- // true es almacen| false es punto de venta
|
|
|
|
|
- $('#purchase_purchase_code').val('');
|
|
|
|
|
- if (state) {
|
|
|
|
|
- $('#warehouse_div').removeClass('hidden');
|
|
|
|
|
- $("#purchase_warehouse_id").select2();
|
|
|
|
|
- $('#pointsale_div').addClass('hidden');
|
|
|
|
|
- <% if current_user.usertype == 'A' %>
|
|
|
|
|
- $('#purchase_pointsale_id').select2('val', null);
|
|
|
|
|
- <% end %>
|
|
|
|
|
- } else {
|
|
|
|
|
- $('#pointsale_div').removeClass('hidden');
|
|
|
|
|
- $("#purchase_pointsale_id").select2();
|
|
|
|
|
- $('#warehouse_div').addClass('hidden');
|
|
|
|
|
- <% if current_user.usertype == 'A' %>
|
|
|
|
|
- $('#purchase_warehouse_id').select2('val', null);
|
|
|
|
|
- <% end %>
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function setDestiny(state) {
|
|
|
|
|
+ // true es almacen| false es punto de venta
|
|
|
|
|
+ $('#purchase_purchase_code').val('');
|
|
|
|
|
+ if (state) {
|
|
|
|
|
+ $('#warehouse_div').removeClass('hidden');
|
|
|
|
|
+ $("#purchase_warehouse_id").select2();
|
|
|
|
|
+ $('#pointsale_div').addClass('hidden');
|
|
|
|
|
+ <% if current_user.usertype == "A" || current_user.usertype == "SS" %>
|
|
|
|
|
+ $('#purchase_pointsale_id').select2('val', null);
|
|
|
|
|
+ <% end %>
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $('#pointsale_div').removeClass('hidden');
|
|
|
|
|
+ $("#purchase_pointsale_id").select2();
|
|
|
|
|
+ $('#warehouse_div').addClass('hidden');
|
|
|
|
|
+ <% if current_user.usertype == "A" || current_user.usertype == "SS" %>
|
|
|
|
|
+ $('#purchase_warehouse_id').select2('val', null);
|
|
|
|
|
+ <% end %>
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- function showExchangeField(state) {
|
|
|
|
|
- // true es dolares | false es pesos
|
|
|
|
|
- if (state) {
|
|
|
|
|
- $('#exchange_div').removeClass('hidden');
|
|
|
|
|
- $('#amount_div div span:last-child').html('USD');
|
|
|
|
|
- $('#tax_div div span:last-child').html('USD');
|
|
|
|
|
- $('#total_div div span:last-child').html('USD');
|
|
|
|
|
- $("#total_in_mxn_div").removeClass('hidden');
|
|
|
|
|
- } else {
|
|
|
|
|
- $('#exchange_div').addClass('hidden');
|
|
|
|
|
- $('#purchase_exchange').val('');
|
|
|
|
|
- $('#amount_div div span:last-child').html('MXN');
|
|
|
|
|
- $('#tax_div div span:last-child').html('MXN');
|
|
|
|
|
- $('#total_div div span:last-child').html('MXN');
|
|
|
|
|
- $("#total_in_mxn_div").addClass('hidden');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function showExchangeField(state) {
|
|
|
|
|
+ // true es dolares | false es pesos
|
|
|
|
|
+ if (state) {
|
|
|
|
|
+ $('#exchange_div').removeClass('hidden');
|
|
|
|
|
+ $('#amount_div div span:last-child').html('USD');
|
|
|
|
|
+ $('#tax_div div span:last-child').html('USD');
|
|
|
|
|
+ $('#total_div div span:last-child').html('USD');
|
|
|
|
|
+ $("#total_in_mxn_div").removeClass('hidden');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $('#exchange_div').addClass('hidden');
|
|
|
|
|
+ $('#purchase_exchange').val('');
|
|
|
|
|
+ $('#amount_div div span:last-child').html('MXN');
|
|
|
|
|
+ $('#tax_div div span:last-child').html('MXN');
|
|
|
|
|
+ $('#total_div div span:last-child').html('MXN');
|
|
|
|
|
+ $("#total_in_mxn_div").addClass('hidden');
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
</script>
|
|
</script>
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|