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