94 lines
1.9 KiB
Ruby
94 lines
1.9 KiB
Ruby
class Sale < ApplicationRecord
|
|
before_create :generate_receipt_no
|
|
belongs_to :cashier
|
|
belongs_to :customer
|
|
has_many :sale_items
|
|
has_many :sale_discounts
|
|
has_many :sale_taxes
|
|
has_many :sale_payments
|
|
has_many :sale_orders
|
|
|
|
def generate_invoice_from_order (order_no)
|
|
end
|
|
|
|
def generate_invoice_by_items (items)
|
|
end
|
|
|
|
def add_item (item)
|
|
#save sale_audit
|
|
end
|
|
|
|
def remove_item (item)
|
|
#save sale_audit
|
|
|
|
end
|
|
|
|
def apply_discount_item (promotion_id, item)
|
|
end
|
|
|
|
def apply_discount (discount_type, discount_code)
|
|
#save action to sale_audit
|
|
end
|
|
|
|
def accept_payment (payment_method, amount, payment_ref, payment_external_result)
|
|
end
|
|
|
|
def void_sales (void_by, reason, approval_code)
|
|
#save sale_audit
|
|
end
|
|
|
|
#compute - invoice total
|
|
def compute
|
|
sales_items = self.sale_items
|
|
|
|
#Computation Fields
|
|
total_items_price = 0
|
|
total_discounts = 0
|
|
total_taxable = 0
|
|
rounding_adjustment = 0
|
|
|
|
sales_items.each do |item|
|
|
#compute each item and added to total
|
|
end
|
|
|
|
apply_tax
|
|
end
|
|
|
|
def apply_tax
|
|
#if tax is not apply create new record
|
|
self.sale_taxes.each |existing_tax|
|
|
#delete existing and create new
|
|
existing_tax.delete
|
|
end
|
|
|
|
#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 => self)
|
|
sale_tax.tax_name = tax.name
|
|
sale_tax.tax_rate = tax.rate
|
|
#include or execulive
|
|
sale_tax.tax_payable_amount = self.total_amount * tax.rate
|
|
sale_tax.inclusive = tax.inclusive
|
|
sale_tax.save
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
private
|
|
#Generate new Receipt No when it is not assigned
|
|
def generate_receipt_no
|
|
#Date-Shift-
|
|
if !self.receipt_no.nil?
|
|
prefix = Date.now()
|
|
self.receipt_no = prefix.to_s + "/" + self.shit_id.to_s + "/" + SeedGenerator.new_receipt_no().to_s
|
|
end
|
|
end
|
|
end
|