|
|
@@ -17,9 +17,9 @@
|
|
|
</div>
|
|
|
<% end %>
|
|
|
<!-- boton para resetear datos -->
|
|
|
- <div class="col-md-offset-10 col-md-2">
|
|
|
- <button id="reset_pre_sales" type="button" class="btn btn-warning" <%= @disabled_button ? 'disabled' : '' %> onclick="deletePreSales()">Restaurar venta</button>
|
|
|
- </div>
|
|
|
+ <!-- <div class="col-md-offset-10 col-md-2">
|
|
|
+ <button id="reset_pre_sales" type="button" class="btn btn-warning" < %= @disabled_button ? 'disabled' : '' %> onclick="deletePreSales()">Restaurar venta</button>
|
|
|
+ </div> -->
|
|
|
<div class="col-md-8">
|
|
|
<h4 class="form-section"> Datos generales</h4>
|
|
|
<!-- purchase code -->
|
|
|
@@ -169,7 +169,7 @@
|
|
|
<!-- -->
|
|
|
<input class="form-control" type="text" id="typeahead">
|
|
|
</div>
|
|
|
- <button id="products_new" disabled class="btn btn-success" type="button" onclick="addRow()"> Agregar <i class="fa fa-plus"></i> </button>
|
|
|
+ <!-- <button id="products_new" disabled class="btn btn-success" type="button" onclick="addRow()"> Agregar <i class="fa fa-plus"></i> </button> -->
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -186,14 +186,14 @@
|
|
|
<th>Producto</th>
|
|
|
<th>Cantidad</th>
|
|
|
<th>Precio unitario</th>
|
|
|
- <th>IVA</th>
|
|
|
+ <th class="hidden">IVA</th>
|
|
|
<th>Descuento</th>
|
|
|
<th>Importe</th>
|
|
|
<th width="15%">Acciones</th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
<tbody>
|
|
|
- <%= render @pre_sales %>
|
|
|
+ <%= render @pre_sales %>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
</div>
|
|
|
@@ -201,44 +201,44 @@
|
|
|
<!-- totales -->
|
|
|
<div class="row">
|
|
|
<div class="col-md-offset-8 col-md-4">
|
|
|
- <div class="well">
|
|
|
- <div class="row static-info align-reverse">
|
|
|
- <div class="col-md-6 name"> Sub Total: </div>
|
|
|
- <div class="col-md-6 value ">
|
|
|
- <div class="input-group">
|
|
|
- <span class="input-group-addon">$ </span>
|
|
|
- <%= f.text_field :amount, {:class=>"form-control sub_total", :readonly => true, :id => "amount"} %>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ <div class="well">
|
|
|
+ <div class="row static-info align-reverse">
|
|
|
+ <div class="col-md-6 name"> Sub Total: </div>
|
|
|
+ <div class="col-md-6 value ">
|
|
|
+ <div class="input-group">
|
|
|
+ <span class="input-group-addon">$ </span>
|
|
|
+ <%= f.text_field :amount, { class: "form-control sub_total", readonly: true, id: "amount" } %>
|
|
|
</div>
|
|
|
- <div class="row static-info align-reverse">
|
|
|
- <div class="col-md-6 name"> Descuento: </div>
|
|
|
- <div class="col-md-6 value ">
|
|
|
- <div class="input-group">
|
|
|
- <span class="input-group-addon">$ </span>
|
|
|
- <%= f.text_field :discount, {:class=>"form-control sub_total", :readonly => true, :id => "discount"} %>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="row static-info align-reverse">
|
|
|
+ <div class="col-md-6 name"> Descuento: </div>
|
|
|
+ <div class="col-md-6 value ">
|
|
|
+ <div class="input-group">
|
|
|
+ <span class="input-group-addon">$ </span>
|
|
|
+ <%= f.text_field :discount, { class: "form-control sub_total", readonly: true, id: "discount" } %>
|
|
|
</div>
|
|
|
- <div class="row static-info align-reverse">
|
|
|
- <div class="col-md-6 name"> IVA: </div>
|
|
|
- <div class="col-md-6 value ">
|
|
|
- <div class="input-group">
|
|
|
- <span class="input-group-addon">$ </span>
|
|
|
- <%= f.text_field :tax, {:class=>"form-control descto", :readonly => true, :id => "tax"} %>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="row static-info align-reverse">
|
|
|
+ <div class="col-md-6 name"> IVA: </div>
|
|
|
+ <div class="col-md-6 value ">
|
|
|
+ <div class="input-group">
|
|
|
+ <span class="input-group-addon">$ </span>
|
|
|
+ <%= f.text_field :tax, { class: "form-control descto", readonly: true, id: "tax" } %>
|
|
|
</div>
|
|
|
- <div class="row static-info align-reverse">
|
|
|
- <div class="col-md-6 name"> Total: </div>
|
|
|
- <div class="col-md-6 value ">
|
|
|
- <div class="input-group">
|
|
|
- <span class="input-group-addon">$ </span>
|
|
|
- <%= f.text_field :total, {:class=>"form-control descto", :readonly => true, :id => "total"} %>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="row static-info align-reverse">
|
|
|
+ <div class="col-md-6 name"> Total: </div>
|
|
|
+ <div class="col-md-6 value ">
|
|
|
+ <div class="input-group">
|
|
|
+ <span class="input-group-addon">$ </span>
|
|
|
+ <%= f.text_field :total, {:class=>"form-control descto", :readonly => true, :id => "total"} %>
|
|
|
</div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
@@ -247,7 +247,7 @@
|
|
|
<div class="row">
|
|
|
<div class="col-md-9">
|
|
|
<button type="button" class="btn green" onclick="addSale()" id="save_sale">Guardar venta</button>
|
|
|
- <button type="button" class="btn default" onclick="deletePreSales()" id="save_sale">Cancelar</button>
|
|
|
+ <button type="button" class="btn btn-warning" onclick="deletePreSales()" id="save_sale">Cancelar</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -438,7 +438,8 @@
|
|
|
var seller = $('#sale_seller_id').val();
|
|
|
|
|
|
if (openCash && customer && saleType && seller ) {
|
|
|
- $('#products_new').attr('disabled', false);
|
|
|
+ addRow();
|
|
|
+ // $('#products_new').attr('disabled', false);
|
|
|
} else {
|
|
|
toastr["error"]("No ha ingresado toda la información requerida.");
|
|
|
}
|
|
|
@@ -487,22 +488,43 @@
|
|
|
type: "PUT",
|
|
|
url: "/pre_sales/" + preSaleId,
|
|
|
dataType: "json",
|
|
|
- data: { pre_sale: { quantity: input.val() } },
|
|
|
+ data: {
|
|
|
+ pre_sale: { quantity: input.val() }
|
|
|
+ },
|
|
|
success: function(xhr, status, error) {
|
|
|
+ var tax_ = xhr.tax;
|
|
|
+ var discount_ = xhr.discount;
|
|
|
+ var total_ = xhr.total;
|
|
|
|
|
|
- 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);
|
|
|
+ $("#tax_" + preSaleId).val(tax_);
|
|
|
+ $("#discount_" + preSaleId).val(discount_);
|
|
|
+ $("#total_" + preSaleId).val(total_);
|
|
|
|
|
|
- input.closest('tr').find('td:eq(8)').text(Math.round(xhr.amount * 100) / 100);
|
|
|
+ input.closest('tr').find('td:eq(6) label').text("$ " + xhr.tax);
|
|
|
+ input.closest('tr').find('td:eq(7) label').text("$ " + xhr.discount);
|
|
|
+ input.closest('tr').find('td:eq(8) label').text("$ " + xhr.total);
|
|
|
|
|
|
calculateTotals();
|
|
|
|
|
|
$('#save_sale').attr('disabled', false);
|
|
|
},
|
|
|
error: function (xhr, status, errorThrown) {
|
|
|
- input.val(1);
|
|
|
- toastr["error"](xhr.responseText.substr(3, (xhr.responseText.length -6)));
|
|
|
+ var data = JSON.parse(xhr.responseText);
|
|
|
+ input.val(data.quantity);
|
|
|
+ toastr["error"](data.errors);
|
|
|
+ var tax_ = (Math.round(data.presale.tax * 100) / 100).toFixed(2);
|
|
|
+ var discount_ = (Math.round(data.presale.discount * 100) / 100).toFixed(2);
|
|
|
+ var total_ = (Math.round(data.presale.total * 100) / 100).toFixed(2);
|
|
|
+
|
|
|
+ $("#tax_" + preSaleId).val(tax_);
|
|
|
+ $("#discount_" + preSaleId).val(discount_);
|
|
|
+ $("#total_" + preSaleId).val(total_);
|
|
|
+
|
|
|
+ input.closest('tr').find('td:eq(6) label').text("$ " + tax_);
|
|
|
+ input.closest('tr').find('td:eq(7) label').text("$ " + discount_);
|
|
|
+ input.closest('tr').find('td:eq(8) label').text("$ " + total_);
|
|
|
+
|
|
|
+ calculateTotals();
|
|
|
}
|
|
|
});
|
|
|
}, 500);
|
|
|
@@ -515,27 +537,36 @@
|
|
|
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);
|
|
|
- amount += parseFloat($(this).find('td:nth-child(9)').text()); // importe
|
|
|
- });
|
|
|
- }
|
|
|
+ // 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);
|
|
|
+ // amount += parseFloat($(this).find('td:nth-child(9)').text()); // importe
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ $('#products_table').dataTable().fnGetNodes().forEach(function(row) {
|
|
|
+ quantity = parseFloat(($(row).find('td:nth-child(5) input').val()));
|
|
|
+ price = parseFloat($(row).find('td:nth-child(6) input').val());
|
|
|
+ amount += (quantity * price);
|
|
|
+ tax += parseFloat($(row).find('td:nth-child(7) input').val());
|
|
|
+ discount += parseFloat($(row).find('td:nth-child(8) input').val());
|
|
|
+ });
|
|
|
|
|
|
- $('#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());
|
|
|
- });
|
|
|
+ // $('#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());
|
|
|
+ // });
|
|
|
|
|
|
total = amount + 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);
|
|
|
+ total -= discount;
|
|
|
+ $('#tax').val((Math.round(tax * 100) / 100).toFixed(2));
|
|
|
+ $('#discount').val((Math.round(discount * 100) / 100).toFixed(2));
|
|
|
+ $('#amount').val((Math.round(amount * 100) / 100).toFixed(2));
|
|
|
+ $('#total').val((Math.round(total * 100) / 100).toFixed(2));
|
|
|
if(total < parseFloat($("#available_credit").val())) {
|
|
|
$('#types_credit').attr('disabled', false);
|
|
|
$('#types_credit').closest('label').removeClass('disabled');
|