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

@@ -1,4 +1,4 @@
class ApplicationController < ActionController::Base
JSONclass ApplicationController < ActionController::Base
#before_action :check_installation
protect_from_forgery with: :exception

View File

@@ -5,10 +5,12 @@ class OrderQueueProcessorJob < ApplicationJob
# Do something later
#Order ID
order = Order.find(order_id)
#Loop through the order stations and process the items
#Execute orders and send to order stations
if order
oqs = OrderQueueStation.new
oqs.process_order(order)
end
end
end

View File

@@ -0,0 +1,13 @@
class AssignedOrderItem < ApplicationRecord
belongs_to :order_queue_station
def self.assigned_order_item (order, item_code, order_queue_station )
assigned_order_item = AssignedOrderItem.new()
assigned_order_item.order = order
assigned_order_item.item_code = item_code
assigned_order_item.order_queue_station = order_queue_station
assigned_order_item.print_status = false
assigned_order_item.delivery_status = false
assigned_order_item.save
end
end

View File

@@ -4,17 +4,19 @@ class Lookup < ApplicationRecord
{'Employee Roles' => 'employee_roles',
'Dining Facilities Status' => 'dining_facilities_status',
'Menu Item Type' => 'menu_item_type',
'Menu Item Attribute Type' => 'menu_item_attribute_type',
'Order Type' => 'order_type',
'Order Source' => 'order_source',
'Order Status' => 'order_status',
'Order Item Status' => 'order_item_status',
'Sale Status' => 'sales_status',
'Payment Status' => 'payment_status',
'Payment Methods' => 'payment_methods'}
'Payment Methods' => 'payment_methods',
"Gateway Communication Type" => "gateway_communication_type"}
end
def self.collection_of(type)
Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] }
Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] }
end
end

View File

@@ -0,0 +1,2 @@
class MembershipSetting < ApplicationRecord
end

View File

@@ -4,6 +4,7 @@ class Order < ApplicationRecord
belongs_to :customer
has_many :order_items, autosave: true , inverse_of: :order
has_many :assigned_order_items
#internal references attributes for business logic control
attr_accessor :items, :guest, :table_id, :new_booking, :booking_type, :employee_name

View File

@@ -1,3 +1,4 @@
class OrderQueueProcessByZone < ApplicationRecord
belongs_to :zone
belongs_to :order_queue_station
end

View File

@@ -1,3 +0,0 @@
class OrderQueueProcessLog < ApplicationRecord
belongs_to :order
end

View File

@@ -1,2 +1,47 @@
# Order Queue station is where order are submitted to
# Order can send from tablet | table
# Source of order will determin where it will appear
class OrderQueueStation < ApplicationRecord
has_many :assigned_order_items
has_many :order_items
scope :active, -> {where(is_active: true)}
def process_order (order)
oqs_stations = OrderQueueStation.active
order_items = order.order_items
#Assign OQS id to order Items
oqs_stations.each do |oqs|
#Get List of items -
pq_items = JSON.parse(oqs.processing_items)
#Loop through the processing items
pq_items.each do |pq_item|
#Processing through the looping items
order_items.each do |order_item|
if (pq_item == order_item.item_code)
#Same Order_items can appear in two location.
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
end
end
end
end
#Print OQS where printing is require
end
private
#Print order_items in 1 slip
def print_slip
end
#Print order_items in 1 slip per item
def print_slip_item
end
end

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

View File

@@ -1,2 +1,41 @@
class SaleAudit < ApplicationRecord
belongs_to :sale
def record_audit_void(sale_id, void_by, approved_by, reason)
#sale_audit
sale_audit = SaleAudit.new()
sale_audit.sale_id = sale_id
sale_audit.action = "SALEVOID"
sale_audit.action_at = DateTime.now.utc
sale_audit.action_by = void_by
sale_audit.approved_by = approved_by
sale_audit.remark = reason
sale_audit.save!
#sale_audit.
end
def record_audit_discount(sale_id, discount_by, approved_by, reason)
#sale_audit
sale_audit = SaleAudit.new()
sale_audit.sale_id = sale_id
sale_audit.action = "SALEDISCOUNT"
sale_audit.action_at = DateTime.now.utc
sale_audit.action_by = discount_by
sale_audit.approved_by = approved_by
sale_audit.remark = reason
sale_audit.save!
#sale_audit.
end
def record_audit_foc(sale_id, cashier_id, approved_by, reason)
#sale_audit
sale_audit = SaleAudit.new()
sale_audit.sale_id = sale_id
sale_audit.action = "SALEFOC"
sale_audit.action_at = DateTime.now.utc
sale_audit.action_by = cashier_id
sale_audit.approved_by = approved_by
sale_audit.remark = reason
sale_audit.save!
end
end

View File

@@ -6,7 +6,7 @@
<meta name="description" content=""/>
<meta name="author" content=""/>
<title>Film Buff</title>
<title>SmartSales : Restaurant</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>

View File

@@ -6,7 +6,7 @@
<meta name="description" content=""/>
<meta name="author" content=""/>
<title>Film Buff</title>
<title>SmartSales : Restaurant</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>