order queue processing

This commit is contained in:
Min Zeya Phyo
2017-04-14 15:50:17 +06:30
parent 5b1bb6f6cd
commit 7cc2ac395d
22 changed files with 246 additions and 33 deletions

View File

@@ -3,27 +3,60 @@ class Sale < ApplicationRecord
belongs_to :cashier
belongs_to :customer
has_many :sale_items
has_many :sale_discount_items
has_many :sale_discounts
has_many :sale_taxes
has_many :sale_payments
has_many :sale_orders
def generate_invoice_from_order (order_no)
def generate_invoice_from_order (order_no, sale_id)
#if sale_id is exsit and validate
#add order to that invoice
if (sale_id)
self = Sale.find(sale_id)
end
if self.sale_status == "void"
return false, "Invoice is void. Cannot be edited"
else
order = Order.find(order_no)
if order
order.order_items.each do |item|
self.sale_items.add(add_item(item))
end
end
link_order_sale(order.id)
return self.save!
end
end
def generate_invoice_by_items (items)
end
def add_item (item)
#check if the item is on promotion
#save sale_audit
sale_item = SaleItem.new
sale_item.sale = self
sale_item.product_code = item.item_code
sale_item.product_name = item.item_name
sale_item.qty = item.qty
return sale_item
end
def remove_item (item)
def update_item (item)
#save sale_audit
end
def apply_discount_item (promotion_id, item)
def apply_item_discount (promotion_id, item)
end
def apply_discount (discount_type, discount_code)
@@ -33,8 +66,13 @@ class Sale < ApplicationRecord
def accept_payment (payment_method, amount, payment_ref, payment_external_result)
end
def void_sales (void_by, reason, approval_code)
def void_sales (void_by, reason, approval_code, request_by)
#save sale_audit
self.sale_status = "void"
self.
end
#compute - invoice total
@@ -64,14 +102,17 @@ class Sale < ApplicationRecord
#tax_profile - list by order_by
tax_profiles = TaxProfile.all.order("order_by asc")
total_amount = self.total_amount
#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.tax_payable_amount = total_amount * tax.rate
#new taxable amount
total_amount = total_amount + sale_tax.tax_payable_amount
sale_tax.inclusive = tax.inclusive
sale_tax.save
end
@@ -82,12 +123,22 @@ class Sale < ApplicationRecord
private
def product_get_unit_price(item.item_code)
menu_instance_code = MenuInstanceCode.find_by_item_instance_code(item.item_code)
if (menu_instance_code)
end
def link_order_sale(order.id)
end
#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
self.receipt_date = prefix
end
end
end