Explorar o código

fixed error on add by barcode in sales and added missing feature in products return get totals

chemi ledon %!s(int64=6) %!d(string=hai) anos
pai
achega
042bf4851b

+ 7 - 2
app/controllers/products_returns_controller.rb

@@ -219,8 +219,13 @@ class ProductsReturnsController < ApplicationController
 
       obj['tax'] = 0.0
 
-      if @product_for_return.include_sale_tax == 1
-        obj['tax'] = ((PosConfig.first.tax_percent / 100) * obj['amount']).round(2)
+      if @product_for_return.include_sale_tax?
+        if @pos_config.add_iva_to_pre_sales?
+          obj['tax'] = ((@pos_config.tax_percent.to_f / 100) * obj['amount']).round(2)
+        else
+          obj['amount'] = ((obj['amount'] * 100) / (100 + @pos_config.tax_percent.to_f)).round(2)
+          obj['tax'] = ((@pos_config.tax_percent.to_f / 100) * obj['amount']).round(2)
+        end
       end
 
       obj['total'] = (obj['amount'] - obj['discount']) + obj['tax']

+ 2 - 1
app/views/pre_sales/create.js.erb

@@ -19,12 +19,13 @@
   $('#customer_remote').remove();
 <% elsif @pre_sale.quantity > 1 %>
   $("#quantity_<%= @pre_sale.id %>").val(<%= @pre_sale.quantity.to_i %>);
+  $("#amount_<%= @pre_sale.id %>").val(<%= @pre_sale.amount.round(2) %>);
   $("#unit_price_<%= @pre_sale.id.to_s %>").val(<%= @pre_sale.unit_price.round(2) %>);
   $("#tax_<%= @pre_sale.id.to_s %>").val(<%= @pre_sale.tax.round(2) %>);
   $("#discount_<%= @pre_sale.id.to_s %>").val(<%= @pre_sale.discount.round(2) %>);
   $("#total_<%= @pre_sale.id.to_s %>").val(<%= @pre_sale.total.round(2) %>);
 
-  tr = $("#pre_sale_<%= @pre_sale.id %>")
+  tr = $("#pre_sale_<%= @pre_sale.id %>");
   tr.find('td:eq(5) label').text("$ " + <%= @pre_sale.unit_price.round(2) %>);
   tr.find('td:eq(6) label').text("$ " + <%= @pre_sale.tax.round(2) %>);
   tr.find('td:eq(7) label').text("$ " + <%= @pre_sale.discount.round(2) %>);