add Re-compute all amoute for sale
This commit is contained in:
@@ -22,10 +22,10 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
sale = Sale.find(sale_id)
|
sale = Sale.find(sale_id)
|
||||||
table_id = sale.bookings[0].dining_facility_id
|
table_id = sale.bookings[0].dining_facility_id
|
||||||
table_type = DiningFacility.find(table_id).type
|
table_type = DiningFacility.find(table_id).type
|
||||||
sale.total_discount = overall_discount.to_f
|
# sale.total_discount = overall_discount.to_f
|
||||||
sale.total_amount = sub_total.to_f
|
# sale.total_amount = sub_total.to_f
|
||||||
sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax;
|
# sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax;
|
||||||
sale.save
|
# sale.save
|
||||||
if discount_items.length > 0
|
if discount_items.length > 0
|
||||||
#save sale item for discount
|
#save sale item for discount
|
||||||
discount_items.each do |di|
|
discount_items.each do |di|
|
||||||
@@ -35,6 +35,7 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
sale_item.sale_id = sale_id
|
sale_item.sale_id = sale_id
|
||||||
sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id
|
sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id
|
||||||
sale_item.product_name = di["name"]
|
sale_item.product_name = di["name"]
|
||||||
|
sale_item.product_alt_name = ""
|
||||||
sale_item.remark = "Discount"
|
sale_item.remark = "Discount"
|
||||||
|
|
||||||
sale_item.qty = 1
|
sale_item.qty = 1
|
||||||
@@ -45,7 +46,10 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
sale_item.price = di["price"]
|
sale_item.price = di["price"]
|
||||||
sale_item.save
|
sale_item.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Re-calc All Amount in Sale
|
||||||
|
sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f)
|
||||||
end
|
end
|
||||||
|
|
||||||
dining = {:table_id => table_id, :table_type => table_type }
|
dining = {:table_id => table_id, :table_type => table_type }
|
||||||
|
|||||||
@@ -16,10 +16,11 @@ class Origami::OtherChargesController < BaseOrigamiController
|
|||||||
if Sale.exists?(sale_id)
|
if Sale.exists?(sale_id)
|
||||||
sale = Sale.find(sale_id)
|
sale = Sale.find(sale_id)
|
||||||
table_id = sale.bookings[0].dining_facility_id
|
table_id = sale.bookings[0].dining_facility_id
|
||||||
table_type = DiningFacility.find(table_id).type
|
table_type = DiningFacility.find(table_id).type
|
||||||
sale.total_amount = sub_total.to_f
|
|
||||||
sale.grand_total = sub_total.to_f + sale.total_tax;
|
# sale.total_amount = sub_total.to_f
|
||||||
sale.save
|
# sale.grand_total = sub_total.to_f + sale.total_tax;
|
||||||
|
# sale.save
|
||||||
if other_charges_items.length > 0
|
if other_charges_items.length > 0
|
||||||
#save sale item for discount
|
#save sale item for discount
|
||||||
other_charges_items.each do |di|
|
other_charges_items.each do |di|
|
||||||
@@ -34,14 +35,17 @@ class Origami::OtherChargesController < BaseOrigamiController
|
|||||||
|
|
||||||
sale_item.qty = 1
|
sale_item.qty = 1
|
||||||
sale_item.unit_price = di["price"]
|
sale_item.unit_price = di["price"]
|
||||||
sale_item.taxable_price = di["price"]
|
sale_item.taxable_price = 0
|
||||||
sale_item.is_taxable = 0
|
sale_item.is_taxable = 0
|
||||||
|
|
||||||
sale_item.price = di["price"]
|
sale_item.price = di["price"]
|
||||||
sale_item.save
|
sale_item.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
# Re-calc All Amount in Sale
|
||||||
|
sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount)
|
||||||
|
end
|
||||||
|
|
||||||
dining = {:table_id => table_id, :table_type => table_type }
|
dining = {:table_id => table_id, :table_type => table_type }
|
||||||
render :json => dining.to_json
|
render :json => dining.to_json
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ class Origami::SalesController < BaseOrigamiController
|
|||||||
order.order_items.each do |orer_item|
|
order.order_items.each do |orer_item|
|
||||||
saleobj.add_item (orer_item)
|
saleobj.add_item (orer_item)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Re-compute for add
|
||||||
|
saleobj.compute
|
||||||
saleobj.save
|
saleobj.save
|
||||||
order.save
|
order.save
|
||||||
booking.save
|
booking.save
|
||||||
|
|||||||
@@ -41,8 +41,10 @@ class Sale < ApplicationRecord
|
|||||||
end
|
end
|
||||||
booking.sale_id = sale_id
|
booking.sale_id = sale_id
|
||||||
end
|
end
|
||||||
|
|
||||||
order = booking.booking_orders.take.order
|
order = booking.booking_orders.take.order
|
||||||
link_order_sale(order.id)
|
link_order_sale(order.id)
|
||||||
|
|
||||||
return status, sale_id
|
return status, sale_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -207,6 +209,33 @@ class Sale < ApplicationRecord
|
|||||||
|
|
||||||
end
|
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
|
def compute_without_void
|
||||||
sales_items = self.sale_items
|
sales_items = self.sale_items
|
||||||
|
|
||||||
@@ -232,6 +261,39 @@ class Sale < ApplicationRecord
|
|||||||
|
|
||||||
self.save!
|
self.save!
|
||||||
end
|
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
|
# Tax Calculate
|
||||||
def apply_tax(total_taxable)
|
def apply_tax(total_taxable)
|
||||||
#if tax is not apply create new record
|
#if tax is not apply create new record
|
||||||
|
|||||||
@@ -54,6 +54,14 @@ class SalePayment < ApplicationRecord
|
|||||||
remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}"
|
remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}"
|
||||||
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
|
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
|
||||||
|
|
||||||
|
# update complete order items in oqs
|
||||||
|
SaleOrder.where("sale_id = '#{ invoice.sale_id }'").find_each do |sodr|
|
||||||
|
AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi|
|
||||||
|
aoi.delivery_status = 1
|
||||||
|
aoi.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return true, self.save
|
return true, self.save
|
||||||
else
|
else
|
||||||
#record an payment in sale-audit
|
#record an payment in sale-audit
|
||||||
|
|||||||
Reference in New Issue
Block a user