optimize for dashboards
This commit is contained in:
@@ -104,7 +104,9 @@ class Origami::DashboardController < BaseOrigamiController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_all_menu
|
def get_all_menu
|
||||||
@menus = Menu.active.all
|
@menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).active.all
|
||||||
|
@item_attributes = MenuItemAttribute.all.load
|
||||||
|
@item_options = MenuItemOption.all.load
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_credit_sales
|
def get_credit_sales
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ class MenuCategory < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def valid_time
|
def valid_time
|
||||||
|
menu = self.menu
|
||||||
menu_category = MenuCategory.find(self.id)
|
|
||||||
menu = Menu.find(menu_category.menu_id)
|
|
||||||
|
|
||||||
from_t = Time.parse(menu.valid_time_from.strftime("%H:%M:%S"))
|
from_t = Time.parse(menu.valid_time_from.strftime("%H:%M:%S"))
|
||||||
to_t = Time.parse(menu.valid_time_to.strftime("%H:%M:%S"))
|
to_t = Time.parse(menu.valid_time_to.strftime("%H:%M:%S"))
|
||||||
@@ -123,7 +121,3 @@ class MenuCategory < ApplicationRecord
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class MenuItem < ApplicationRecord
|
|||||||
belongs_to :account
|
belongs_to :account
|
||||||
|
|
||||||
has_many :menu_item_sets
|
has_many :menu_item_sets
|
||||||
has_many :item_sets, through: :menu_item_sets
|
has_and_belongs_to_many :item_sets, join_table: "menu_item_sets"
|
||||||
|
|
||||||
validates_presence_of :item_code, :name, :type, :min_qty,:account_id
|
validates_presence_of :item_code, :name, :type, :min_qty,:account_id
|
||||||
validates_uniqueness_of :item_code
|
validates_uniqueness_of :item_code
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,8 @@ class SaleAudit < ApplicationRecord
|
|||||||
|
|
||||||
belongs_to :sale
|
belongs_to :sale
|
||||||
|
|
||||||
|
belongs_to :credit_payment, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment"
|
||||||
|
|
||||||
def self.sync_sale_audit_records(sale_audits)
|
def self.sync_sale_audit_records(sale_audits)
|
||||||
if !sale_audits.nil?
|
if !sale_audits.nil?
|
||||||
sale_audits.each do |sa|
|
sale_audits.each do |sa|
|
||||||
|
|||||||
@@ -6,8 +6,13 @@ class SalePayment < ApplicationRecord
|
|||||||
|
|
||||||
belongs_to :sale
|
belongs_to :sale
|
||||||
|
|
||||||
|
has_one :sale_audit, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id"
|
||||||
|
|
||||||
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status,:action_by
|
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status,:action_by
|
||||||
|
|
||||||
|
scope :credits, -> { where(payment_method: 'creditnote') }
|
||||||
|
scope :cards, -> { where(payment_method: ['mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher']) }
|
||||||
|
|
||||||
def self.sync_sale_payment_records(sale_payments)
|
def self.sync_sale_payment_records(sale_payments)
|
||||||
if !sale_payments.nil?
|
if !sale_payments.nil?
|
||||||
sale_payments.each do |sp|
|
sale_payments.each do |sp|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
class ShiftSale < ApplicationRecord
|
class ShiftSale < ApplicationRecord
|
||||||
belongs_to :cashier_terminal
|
belongs_to :cashier_terminal
|
||||||
belongs_to :employee, :foreign_key => 'employee_id'
|
belongs_to :employee, :foreign_key => 'employee_id'
|
||||||
|
has_many :sales
|
||||||
|
|
||||||
def self.current_shift
|
def self.current_shift
|
||||||
# today_date = DateTime.now.strftime("%Y-%m-%d")
|
# today_date = DateTime.now.strftime("%Y-%m-%d")
|
||||||
|
|||||||
@@ -2,52 +2,19 @@
|
|||||||
attr_format = []
|
attr_format = []
|
||||||
# Format for attributes json
|
# Format for attributes json
|
||||||
if item.item_attributes.count > 0
|
if item.item_attributes.count > 0
|
||||||
item.item_attributes.each do|attr_id|
|
item_attributes = MenuItemAttribute.where(id: item.item_attributes)
|
||||||
menu_attr = MenuItemAttribute.find(attr_id)
|
attr_format = item_attributes.group_by {|att| att.attribute_type }.map { |type, values| {type: type, values: values.map(&:name)} }
|
||||||
if attr_format.count == 0
|
|
||||||
attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] })
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
attr_format.each do |af|
|
|
||||||
if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]}
|
|
||||||
if menu_attr.attribute_type == af[:type]
|
|
||||||
af[:values].push(menu_attr.name)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] }
|
|
||||||
attr_format.push(new_attr)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Format for option json
|
# Format for option json
|
||||||
opt_format = []
|
opt_format = []
|
||||||
# Format for attributes json
|
# Format for attributes json
|
||||||
if item.item_options.count > 0
|
if item.item_options.count > 0
|
||||||
item.item_options.each do|opt|
|
item_options = MenuItemOption.where(id: item.item_options)
|
||||||
menu_opt = MenuItemOption.find(opt)
|
opt_format = item_options.group_by {|opt| opt.option_type }.map { |type, values| {type: type, values: values.map(&:name)} }
|
||||||
if opt_format.count == 0
|
|
||||||
opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] })
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
opt_format.each do |of|
|
|
||||||
if menu_opt.option_type.in? opt_format.map {|k| k[:type]}
|
|
||||||
if menu_opt.option_type == of[:type]
|
|
||||||
of[:values].push(menu_opt.name)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] }
|
|
||||||
opt_format.push(new_opt)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
#Menu Item Information
|
#Menu Item Information
|
||||||
json.id item.id
|
json.id item.id
|
||||||
json.code item.item_code
|
json.code item.item_code
|
||||||
@@ -64,7 +31,7 @@ json.is_sub_item item.is_sub_item
|
|||||||
json.unit item.unit
|
json.unit item.unit
|
||||||
|
|
||||||
# Item Sets of Menu Item
|
# Item Sets of Menu Item
|
||||||
json.item_sets item.item_sets do |its|
|
json.item_sets item.item_sets.includes(:menu_item_instances) do |its|
|
||||||
json.id its.id
|
json.id its.id
|
||||||
json.name its.name
|
json.name its.name
|
||||||
json.alt_name its.alt_name
|
json.alt_name its.alt_name
|
||||||
@@ -92,22 +59,17 @@ json.options opt_format
|
|||||||
json.instances item.menu_item_instances do |is|
|
json.instances item.menu_item_instances do |is|
|
||||||
if is.is_available
|
if is.is_available
|
||||||
# Convert id to name for attributes
|
# Convert id to name for attributes
|
||||||
instance_attr = []
|
instance_attr = MenuItemAttribute.where(id: item.item_attributes).pluck(:name)
|
||||||
is.item_attributes.each do |ia|
|
|
||||||
mItemAttr = MenuItemAttribute.find(ia).name
|
|
||||||
instance_attr.push(mItemAttr)
|
|
||||||
end
|
|
||||||
|
|
||||||
json.id is.id
|
json.id is.id
|
||||||
json.code is.item_instance_code
|
json.code is.item_instance_code
|
||||||
json.name is.item_instance_name
|
json.name is.item_instance_name
|
||||||
json.price is.price
|
json.price is.price
|
||||||
json.is_available is.is_available
|
json.is_available is.is_available
|
||||||
json.is_default is.is_default
|
json.is_default is.is_default
|
||||||
json.is_on_promotion is.is_on_promotion
|
json.is_on_promotion is.is_on_promotion
|
||||||
json.promotion_price is.promotion_price
|
json.promotion_price is.promotion_price
|
||||||
json.values instance_attr
|
json.values instance_attr
|
||||||
# json.item_sets is.item_sets
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ if (menu.menu_categories)
|
|||||||
# else
|
# else
|
||||||
# categories = menu.menu_categories
|
# categories = menu.menu_categories
|
||||||
# end
|
# end
|
||||||
categories = menu.menu_categories
|
categories = menu.menu_categories
|
||||||
json.categories categories do |category|
|
json.categories categories do |category|
|
||||||
if category.is_available
|
if category.is_available
|
||||||
menu_category = MenuCategory.find_by_menu_category_id(category.id)
|
parent_category = category.parent
|
||||||
if !menu_category.nil?
|
if !parent_category.nil?
|
||||||
json.sub_category "true"
|
json.sub_category "true"
|
||||||
else
|
else
|
||||||
json.sub_category "false"
|
json.sub_category "false"
|
||||||
@@ -34,7 +34,7 @@ if (menu.menu_categories)
|
|||||||
json.is_available category.is_available
|
json.is_available category.is_available
|
||||||
|
|
||||||
if !order_by.nil? && order_by.value == "name"
|
if !order_by.nil? && order_by.value == "name"
|
||||||
menu_items = MenuItem.unscoped.where("menu_category_id = ?",category.id).order("name asc")
|
menu_items = category.menu_items.sort_by(&:name)
|
||||||
else
|
else
|
||||||
menu_items = category.menu_items
|
menu_items = category.menu_items
|
||||||
end
|
end
|
||||||
@@ -42,7 +42,68 @@ if (menu.menu_categories)
|
|||||||
if category.menu_items
|
if category.menu_items
|
||||||
json.items menu_items do |item|
|
json.items menu_items do |item|
|
||||||
if item.is_available
|
if item.is_available
|
||||||
json.partial! 'origami/addorders/menu_item', item: item
|
# Format for attributes json
|
||||||
|
attr_format = []
|
||||||
|
# Format for attributes json
|
||||||
|
if item.item_attributes.count > 0
|
||||||
|
item_attributes = @item_attributes.select{ |x| item.item_attributes.include?(x.id.to_s) }
|
||||||
|
attr_format = item_attributes.group_by {|att| att.attribute_type }.map { |type, values| {type: type, values: values.map(&:name)} }
|
||||||
|
end
|
||||||
|
|
||||||
|
# Format for option json
|
||||||
|
opt_format = []
|
||||||
|
# Format for attributes json
|
||||||
|
if item.item_options.count > 0
|
||||||
|
item_options = @item_options.select{ |x| item.item_options.include?(x.id.to_s) }
|
||||||
|
opt_format = item_options.group_by {|opt| opt.option_type }.map { |type, values| {type: type, values: values.map(&:name)} }
|
||||||
|
end
|
||||||
|
|
||||||
|
#Menu Item Information
|
||||||
|
json.id item.id
|
||||||
|
json.code item.item_code
|
||||||
|
json.name item.name
|
||||||
|
json.alt_name item.alt_name
|
||||||
|
json.image item.image_path.url
|
||||||
|
json.description item.description
|
||||||
|
json.information item.information
|
||||||
|
json.type item.type
|
||||||
|
json.account_id item.account_id
|
||||||
|
json.min_qty item.min_qty
|
||||||
|
json.is_available item.is_available
|
||||||
|
json.is_sub_item item.is_sub_item
|
||||||
|
json.unit item.unit
|
||||||
|
|
||||||
|
# Item Sets of Menu Item
|
||||||
|
json.item_sets item.item_sets.map { |its|
|
||||||
|
{ id: its.id,
|
||||||
|
name: its.name,
|
||||||
|
alt_name: its.alt_name,
|
||||||
|
min_selectable_qty: its.min_selectable_qty,
|
||||||
|
max_selectable_qty: its.max_selectable_qty,
|
||||||
|
instances: its.menu_item_instances.pluck(:id).map { |id| {id: id}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
json.attributes attr_format
|
||||||
|
json.options opt_format
|
||||||
|
|
||||||
|
json.instances item.menu_item_instances do |is|
|
||||||
|
if is.is_available
|
||||||
|
# Convert id to name for attributes
|
||||||
|
instance_attr = @item_attributes.select{ |x| item.item_attributes.include?(x.id) }.pluck(:name)
|
||||||
|
|
||||||
|
json.id is.id
|
||||||
|
json.code is.item_instance_code
|
||||||
|
json.name is.item_instance_name
|
||||||
|
json.price is.price
|
||||||
|
json.is_available is.is_available
|
||||||
|
json.is_default is.is_default
|
||||||
|
json.is_on_promotion is.is_on_promotion
|
||||||
|
json.promotion_price is.promotion_price
|
||||||
|
json.values instance_attr
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user