calc tax by user taxes
This commit is contained in:
@@ -273,28 +273,33 @@ class Sale < ApplicationRecord
|
||||
total_tax_amount = 0
|
||||
#tax_profile - list by order_by
|
||||
tax_profiles = TaxProfile.all.order("order_by asc")
|
||||
customer = Customer.find(sale.customer_id)
|
||||
|
||||
# #Creat new tax records
|
||||
tax_profiles.each do |tax|
|
||||
sale_tax = SaleTax.new(:sale => sale)
|
||||
sale_tax.tax_name = tax.name
|
||||
sale_tax.tax_rate = tax.rate
|
||||
customer.tax_profiles.each do |cus_tax|
|
||||
if cus_tax == tax.id
|
||||
sale_tax = SaleTax.new(:sale => sale)
|
||||
sale_tax.tax_name = tax.name
|
||||
sale_tax.tax_rate = tax.rate
|
||||
|
||||
# substract , to give after discount
|
||||
total_tax = total_taxable - total_discount
|
||||
#include or execulive
|
||||
if tax.inclusive
|
||||
sale_tax.tax_payable_amount = total_tax / 21
|
||||
else
|
||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||
# substract , to give after discount
|
||||
total_tax = total_taxable - total_discount
|
||||
#include or execulive
|
||||
if tax.inclusive
|
||||
sale_tax.tax_payable_amount = total_tax / 21
|
||||
else
|
||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||
end
|
||||
#new taxable amount is standard rule for step by step
|
||||
# total_taxable = total_taxable + sale_tax.tax_payable_amount
|
||||
|
||||
sale_tax.inclusive = tax.inclusive
|
||||
sale_tax.save
|
||||
|
||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
||||
end
|
||||
end
|
||||
#new taxable amount is standard rule for step by step
|
||||
# total_taxable = total_taxable + sale_tax.tax_payable_amount
|
||||
|
||||
sale_tax.inclusive = tax.inclusive
|
||||
sale_tax.save
|
||||
|
||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
||||
end
|
||||
|
||||
sale.total_tax = total_tax_amount
|
||||
@@ -312,32 +317,35 @@ class Sale < ApplicationRecord
|
||||
#tax_profile - list by order_by
|
||||
tax_profiles = TaxProfile.all.order("order_by asc")
|
||||
|
||||
# #Creat new tax records
|
||||
customer = Customer.find(self.customer_id)
|
||||
# #Create new tax records
|
||||
tax_profiles.each do |tax|
|
||||
sale_tax = SaleTax.new(:sale => self)
|
||||
sale_tax.tax_name = tax.name
|
||||
sale_tax.tax_rate = tax.rate
|
||||
customer.tax_profiles.each do |cus_tax|
|
||||
if cus_tax == tax.id
|
||||
sale_tax = SaleTax.new(:sale => self)
|
||||
sale_tax.tax_name = tax.name
|
||||
sale_tax.tax_rate = tax.rate
|
||||
|
||||
# substract , to give after discount
|
||||
total_tax = total_taxable - self.total_discount
|
||||
#include or execulive
|
||||
if tax.inclusive
|
||||
sale_tax.tax_payable_amount = total_tax / 21
|
||||
else
|
||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||
# substract , to give after discount
|
||||
total_tax = total_taxable - self.total_discount
|
||||
#include or execulive
|
||||
if tax.inclusive
|
||||
sale_tax.tax_payable_amount = total_tax / 21
|
||||
else
|
||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||
end
|
||||
|
||||
#new taxable amount is standard rule for step by step
|
||||
# total_taxable = total_taxable + sale_tax.tax_payable_amount
|
||||
|
||||
sale_tax.inclusive = tax.inclusive
|
||||
sale_tax.save
|
||||
|
||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
||||
end
|
||||
end
|
||||
|
||||
#new taxable amount is standard rule for step by step
|
||||
# total_taxable = total_taxable + sale_tax.tax_payable_amount
|
||||
|
||||
sale_tax.inclusive = tax.inclusive
|
||||
sale_tax.save
|
||||
|
||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
||||
end
|
||||
|
||||
self.total_tax = total_tax_amount
|
||||
|
||||
end
|
||||
|
||||
def product_get_unit_price(item_code)
|
||||
@@ -382,7 +390,6 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.search(filter,from,to)
|
||||
|
||||
if filter.blank?
|
||||
keyword = ''
|
||||
else
|
||||
@@ -399,7 +406,6 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.search_credit_sales(customer,filter,from,to)
|
||||
|
||||
if filter.blank?
|
||||
keyword = ''
|
||||
else
|
||||
@@ -518,31 +524,25 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.get_by_range_by_saleitems(from,to,status,report_type)
|
||||
query = Sale.select("
|
||||
mi.item_code as code,(SUM(i.qty) * i.unit_price) as grand_total,
|
||||
SUM(i.qty) as total_item," +
|
||||
" i.unit_price as unit_price,
|
||||
mi.name as product_name,
|
||||
mc.name as menu_category_name,
|
||||
mc.id as menu_category_id ")
|
||||
.group('mi.id')
|
||||
.order("mi.menu_category_id")
|
||||
|
||||
query = Sale.select("
|
||||
mi.item_code as code,(SUM(i.qty) * i.unit_price) as grand_total,
|
||||
SUM(i.qty) as total_item," +
|
||||
" i.unit_price as unit_price,
|
||||
mi.name as product_name,
|
||||
mc.name as menu_category_name,
|
||||
mc.id as menu_category_id ")
|
||||
.group('mi.id')
|
||||
.order("mi.menu_category_id")
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
|
||||
JOIN menu_items mi ON i.product_code = mi.item_code" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id
|
||||
JOIN employees ea ON ea.id = sales.cashier_id")
|
||||
|
||||
|
||||
query = query.where("(receipt_date between ? and ? and sale_status=?) AND i.unit_price <> 0",from,to,status)
|
||||
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
|
||||
JOIN menu_items mi ON i.product_code = mi.item_code" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id
|
||||
JOIN employees ea ON ea.id = sales.cashier_id")
|
||||
|
||||
|
||||
query = query.where("(receipt_date between ? and ? and sale_status=?) AND i.unit_price <> 0",from,to,status)
|
||||
end
|
||||
|
||||
|
||||
def self.get_by_shiftsales(from,to,shift)
|
||||
if !shift.blank?
|
||||
ShiftSale.where("id =?",shift.id)
|
||||
|
||||
@@ -99,9 +99,8 @@ customer_type = Lookup.create([{lookup_type:'customer_type', name: 'Dinein', val
|
||||
{lookup_type:'customer_type', name: 'Delivery', value: 'Delivery'}])
|
||||
|
||||
#WALK CUSTOMER - Default CUSTOMER (take key 1)
|
||||
customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000",card_no:"000"})
|
||||
customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contact_no:"111111111",card_no:"111"})
|
||||
|
||||
customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000",card_no:"000", customer_type:"Dinein", tax_profiles:"[2,1]"})
|
||||
customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contact_no:"111111111",card_no:"111", customer_type:"Takeaway", tax_profiles:"[1]"})
|
||||
|
||||
#Default ZOne
|
||||
# zone = Zone.create({id:1, name: "Normal Zone", is_active:true, created_by: "SYSTEM DEFAULT"})
|
||||
|
||||
Reference in New Issue
Block a user