update shift close print
This commit is contained in:
@@ -41,8 +41,10 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
booking.sale_id = sale_id
|
||||
end
|
||||
|
||||
order = booking.booking_orders.take.order
|
||||
link_order_sale(order.id)
|
||||
|
||||
return status, sale_id
|
||||
end
|
||||
end
|
||||
@@ -205,6 +207,33 @@ class Sale < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
#compute - invoice total
|
||||
def compute_by_sale_items(sale_id, sale_itemss, total_discount)
|
||||
sale = Sale.find(sale_id)
|
||||
sales_items = sale_itemss
|
||||
|
||||
#Computation Fields
|
||||
subtotal_price = 0
|
||||
total_taxable = 0
|
||||
rounding_adjustment = 0
|
||||
|
||||
sales_items.each do |item|
|
||||
#compute each item and added to total
|
||||
subtotal_price = subtotal_price + item.price
|
||||
total_taxable = total_taxable + (item.taxable_price * item.qty)
|
||||
end
|
||||
|
||||
compute_tax(sale, total_taxable)
|
||||
sale.total_amount = subtotal_price
|
||||
sale.total_discount = total_discount
|
||||
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax
|
||||
#compute rounding adjustment
|
||||
# adjust_rounding
|
||||
|
||||
sale.save!
|
||||
|
||||
end
|
||||
|
||||
def compute_without_void
|
||||
sales_items = self.sale_items
|
||||
|
||||
@@ -230,6 +259,39 @@ class Sale < ApplicationRecord
|
||||
|
||||
self.save!
|
||||
end
|
||||
|
||||
# Tax Re-Calculte
|
||||
def compute_tax(sale, total_taxable)
|
||||
#if tax is not apply create new record
|
||||
SaleTax.where("sale_id='#{sale.sale_id}'").find_each do |existing_tax|
|
||||
#delete existing and create new
|
||||
existing_tax.delete
|
||||
end
|
||||
|
||||
total_tax_amount = 0
|
||||
#tax_profile - list by order_by
|
||||
tax_profiles = TaxProfile.all.order("order_by asc")
|
||||
|
||||
# #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
|
||||
#include or execulive
|
||||
# sale_tax.tax_payable_amount = total_taxable * tax.rate
|
||||
sale_tax.tax_payable_amount = total_taxable * tax.rate / 100
|
||||
#new taxable amount
|
||||
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
|
||||
end
|
||||
|
||||
# Tax Calculate
|
||||
def apply_tax(total_taxable)
|
||||
#if tax is not apply create new record
|
||||
@@ -344,8 +406,8 @@ class Sale < ApplicationRecord
|
||||
else
|
||||
## up to 100
|
||||
value = 100 - get_last_no.to_f
|
||||
num += value
|
||||
puts 'up to 100'
|
||||
num += value
|
||||
puts 'up to 100'
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -538,11 +600,12 @@ end
|
||||
|
||||
def get_commerical_tax
|
||||
tax = 0.0
|
||||
self.sale_taxes.each do |tax|
|
||||
if tax.tax_name == "Commerical Tax"
|
||||
tax += tax.tax_payable_amount
|
||||
self.sale_taxes.each do |taxobj|
|
||||
if taxobj.tax_name == "Commerical Tax"
|
||||
tax += taxobj.tax_payable_amount
|
||||
end
|
||||
end
|
||||
return tax
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user