Merge branch 'august_spring' of bitbucket.org:code2lab/sxrestaurant into august_spring
* 'august_spring' of bitbucket.org:code2lab/sxrestaurant: (71 commits) Update Coupon / Voucher data change update menu_sync update addorder update addorder view add fields for Menu Sync update add oreder add menu api update add order and calculate subtotal update seed menu ui update update ability for setmenu fixed update show for foc add bootstrap file input and menu item img implemented update foc and pdf update menu item update receipt bill pdf for foc and credit add CarrierWave gems for menu image upload add CarrierWave gems for menu image upload ...
This commit is contained in:
@@ -4,137 +4,131 @@ class Ability
|
||||
def initialize(user)
|
||||
user ||= Employee.new
|
||||
|
||||
if user.role == 'administrator'
|
||||
if user.role == "administrator"
|
||||
can :manage, :all
|
||||
elsif user.role == "manager"
|
||||
can :manage, Menu
|
||||
can :manage, MenuCategory
|
||||
can :manage, MenuItemAttribute
|
||||
can :manage, MenuItemInstance
|
||||
can :manage, MenuItemOption
|
||||
can :manage, SetMenuItem
|
||||
can :manage, ItemSet
|
||||
can :manage, MenuItemSet
|
||||
can :manage, OrderQueueStation
|
||||
can :manage, Zone
|
||||
can :manage, CashierTerminal
|
||||
can :manage, Employee
|
||||
# can :manage, MembershipSetting
|
||||
# can :manage, MembershipAction
|
||||
# can :manage, PaymentMethodSetting
|
||||
can :manage, TaxProfile
|
||||
can :manage, PrintSetting
|
||||
can :manage, Account
|
||||
|
||||
can :manage, :all
|
||||
can :manage, Order
|
||||
can :manage, Sale
|
||||
|
||||
elsif user.role == 'manager'
|
||||
can :manage, Customer
|
||||
can :manage, DiningQueue
|
||||
|
||||
can :manage, Menu
|
||||
can :manage, MenuCategory
|
||||
can :manage, MenuItemAttribute
|
||||
can :manage, MenuItemInstance
|
||||
can :manage, MenuItemOption
|
||||
can :manage, SetMenuItem
|
||||
can :manage, OrderQueueStation
|
||||
can :manage, Zone
|
||||
can :manage, CashierTerminal
|
||||
can :manage, Employee
|
||||
# can :manage, MembershipSetting
|
||||
# can :manage, MembershipAction
|
||||
# can :manage, PaymentMethodSetting
|
||||
can :manage, TaxProfile
|
||||
can :manage, PrintSetting
|
||||
can :manage, Account
|
||||
can :index, :dailysale
|
||||
can :index, :saleitem
|
||||
can :index, :receipt_no
|
||||
can :index, :shiftsale
|
||||
can :index, :credit_payment
|
||||
can :index, :void_sale
|
||||
|
||||
can :manage, Order
|
||||
can :manage, Sale
|
||||
can :get_customer, Customer
|
||||
can :add_customer, Customer
|
||||
can :update_sale_by_customer, Customer
|
||||
|
||||
can :manage, Customer
|
||||
can :manage, DiningQueue
|
||||
can :index, :other_charge
|
||||
can :create, :other_charge
|
||||
can :index, :discount
|
||||
can :create, :discount
|
||||
can :remove_discount_items, :discount
|
||||
can :remove_all_discount, :discount
|
||||
|
||||
can :index, :dailysale
|
||||
can :index, :saleitem
|
||||
can :index, :receipt_no
|
||||
can :index, :shiftsale
|
||||
can :index, :credit_payment
|
||||
can :index, :void_sale
|
||||
can :first_bill, :payment
|
||||
can :show, :payment
|
||||
can :create, :payment
|
||||
can :reprint, :payment
|
||||
can :rounding_adj, :payment
|
||||
can :foc, :payment
|
||||
|
||||
can :get_customer, Customer
|
||||
can :add_customer, Customer
|
||||
can :update_sale_by_customer, Customer
|
||||
|
||||
can :index, :other_charge
|
||||
can :create, :other_charge
|
||||
can :index, :discount
|
||||
can :create, :discount
|
||||
can :remove_discount_items, :discount
|
||||
can :remove_all_discount, :discount
|
||||
can :move_dining, :movetable
|
||||
can :moving, :movetable
|
||||
|
||||
can :first_bill, :payment
|
||||
can :show, :payment
|
||||
can :create, :payment
|
||||
can :reprint, :payment
|
||||
can :rounding_adj, :payment
|
||||
can :move_dining, :moveroom
|
||||
|
||||
can :move_dining, :movetable
|
||||
can :moving, :movetable
|
||||
can :edit, :sale_edit
|
||||
can :item_void, :sale_edit
|
||||
can :item_void_cancel, :sale_edit
|
||||
can :cancel_all_void, :sale_edit
|
||||
can :apply_void, :sale_edit
|
||||
|
||||
can :move_dining, :moveroom
|
||||
can :overall_void, :void
|
||||
|
||||
can :edit, :sale_edit
|
||||
can :item_void, :sale_edit
|
||||
can :item_void_cancel, :sale_edit
|
||||
can :cancel_all_void, :sale_edit
|
||||
can :apply_void, :sale_edit
|
||||
elsif user.role == "cashier"
|
||||
|
||||
# can :overall_void, :void
|
||||
|
||||
can :overall_void, :void
|
||||
can :read, Order
|
||||
can :update, Order
|
||||
|
||||
can :read, Sale
|
||||
can :update, Sale
|
||||
can :get_customer, Customer
|
||||
can :add_customer, Customer
|
||||
can :update_sale_by_customer, Customer
|
||||
|
||||
elsif user.role == 'cashier'
|
||||
can :index, :other_charge
|
||||
can :create, :other_charge
|
||||
can :index, :discount
|
||||
can :create, :discount
|
||||
can :remove_discount_items, :discount
|
||||
can :remove_all_discount, :discount
|
||||
can :member_discount, :discount
|
||||
|
||||
# can :overall_void, :void
|
||||
can :first_bill, :payment
|
||||
can :show, :payment
|
||||
can :create, :payment
|
||||
can :reprint, :payment
|
||||
can :rounding_adj, :payment
|
||||
|
||||
can :read, Order
|
||||
can :update, Order
|
||||
can :move_dining, :movetable
|
||||
can :moving, :movetable
|
||||
|
||||
can :read, Sale
|
||||
can :update, Sale
|
||||
can :get_customer, Customer
|
||||
can :add_customer, Customer
|
||||
can :update_sale_by_customer, Customer
|
||||
can :move_dining, :moveroom
|
||||
|
||||
can :index, :other_charge
|
||||
can :create, :other_charge
|
||||
can :index, :discount
|
||||
can :create, :discount
|
||||
can :remove_discount_items, :discount
|
||||
can :remove_all_discount, :discount
|
||||
can :member_discount, :discount
|
||||
can :manage, DiningQueue
|
||||
|
||||
elsif user.role == "account"
|
||||
|
||||
can :first_bill, :payment
|
||||
can :show, :payment
|
||||
can :create, :payment
|
||||
can :reprint, :payment
|
||||
can :rounding_adj, :payment
|
||||
can :index, :dailysale
|
||||
can :index, :saleitem
|
||||
can :index, :receipt_no
|
||||
can :index, :shiftsale
|
||||
can :index, :credit_payment
|
||||
can :index, :void_sale
|
||||
|
||||
can :move_dining, :movetable
|
||||
can :moving, :movetable
|
||||
elsif user.role == "supervisour"
|
||||
|
||||
can :move_dining, :moveroom
|
||||
can :edit, :sale_edit
|
||||
can :item_void, :sale_edit
|
||||
can :item_edit, :sale_edit
|
||||
can :item_void_cancel, :sale_edit
|
||||
can :cancel_all_void, :sale_edit
|
||||
can :apply_void, :sale_edit
|
||||
can :overall_void, :void
|
||||
|
||||
can :first_bill, :payment
|
||||
can :show, :payment
|
||||
can :create, :payment
|
||||
can :reprint, :payment
|
||||
|
||||
can :manage, DiningQueue
|
||||
|
||||
elsif user.role == 'account'
|
||||
|
||||
can :index, :dailysale
|
||||
can :index, :saleitem
|
||||
can :index, :receipt_no
|
||||
can :index, :shiftsale
|
||||
can :index, :credit_payment
|
||||
can :index, :void_sale
|
||||
|
||||
elsif user.role == 'supervisour'
|
||||
|
||||
can :edit, :sale_edit
|
||||
can :item_void, :sale_edit
|
||||
can :item_edit, :sale_edit
|
||||
can :item_void_cancel, :sale_edit
|
||||
can :cancel_all_void, :sale_edit
|
||||
can :apply_void, :sale_edit
|
||||
can :overall_void, :void
|
||||
|
||||
can :first_bill, :payment
|
||||
can :create, :payment
|
||||
can :show, :payment
|
||||
can :reprint, :payment
|
||||
can :rounding_adj, :payment
|
||||
can :first_bill, :payment
|
||||
can :create, :payment
|
||||
can :show, :payment
|
||||
can :reprint, :payment
|
||||
can :rounding_adj, :payment
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -35,7 +35,6 @@ class Employee < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.authenticate_by_token(session_token)
|
||||
|
||||
if (session_token)
|
||||
user = Employee.find_by_token_session(session_token)
|
||||
if user && user.session_expiry.utc > DateTime.now.utc
|
||||
|
||||
9
app/models/item_set.rb
Normal file
9
app/models/item_set.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class ItemSet < ApplicationRecord
|
||||
has_many :menu_item_sets
|
||||
has_many :menu_items, through: :menu_item_sets
|
||||
|
||||
has_many :menu_instance_item_sets
|
||||
has_many :menu_item_instances, through: :menu_instance_item_sets
|
||||
|
||||
validates_presence_of :name
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
class MenuCategory < ApplicationRecord
|
||||
before_create :generate_menu_category_code
|
||||
# before_create :generate_menu_category_code
|
||||
|
||||
belongs_to :menu
|
||||
has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id"
|
||||
@@ -37,7 +37,7 @@ class MenuCategory < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def generate_menu_category_code
|
||||
self.code = SeedGenerator.generate_code(self.class.name, "C")
|
||||
end
|
||||
# def generate_menu_category_code
|
||||
# self.code = SeedGenerator.generate_code(self.class.name, "C")
|
||||
# end
|
||||
end
|
||||
|
||||
4
app/models/menu_instance_item_set.rb
Normal file
4
app/models/menu_instance_item_set.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class MenuInstanceItemSet < ApplicationRecord
|
||||
belongs_to :item_set
|
||||
belongs_to :menu_item_instance
|
||||
end
|
||||
@@ -1,20 +1,25 @@
|
||||
class MenuItem < ApplicationRecord
|
||||
|
||||
before_create :generate_menu_item_code
|
||||
# before_create :generate_menu_item_code
|
||||
|
||||
belongs_to :menu_category, :optional => true
|
||||
has_many :menu_item_instances
|
||||
belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true
|
||||
has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
|
||||
# belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true
|
||||
# has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
|
||||
belongs_to :account
|
||||
|
||||
validates_presence_of :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item
|
||||
has_many :menu_item_sets
|
||||
has_many :item_sets, through: :menu_item_sets
|
||||
|
||||
validates_presence_of :name, :type, :min_qty, :taxable
|
||||
|
||||
default_scope { order('item_code asc') }
|
||||
|
||||
scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') }
|
||||
scope :set_menu_item, -> { where(type: 'SetMenuItem') }
|
||||
|
||||
# Item Image Uploader
|
||||
mount_uploader :image_path, MenuItemImageUploader
|
||||
|
||||
def self.collection
|
||||
MenuItem.select("id, name").map { |e| [e.name, e.id] }
|
||||
end
|
||||
@@ -70,10 +75,10 @@ class MenuItem < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
# private
|
||||
|
||||
def generate_menu_item_code
|
||||
self.item_code = SeedGenerator.generate_code(self.class.name, "I")
|
||||
end
|
||||
# def generate_menu_item_code
|
||||
# self.item_code = SeedGenerator.generate_code(self.class.name, "I")
|
||||
# end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class MenuItemAttribute < ApplicationRecord
|
||||
validates_presence_of :attribute_type, :name, :value
|
||||
def self.collection
|
||||
MenuItemAttribute.select("id, name").map { |e| [e.name, e.id] }
|
||||
MenuItemAttribute.select("name, value").map { |e| [e.name, e.value] }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
class MenuItemInstance < ApplicationRecord
|
||||
belongs_to :menu_item
|
||||
before_create :generate_menu_item_instance_code
|
||||
|
||||
has_many :menu_instance_item_sets
|
||||
has_many :item_sets, through: :menu_instance_item_sets
|
||||
# before_create :generate_menu_item_instance_code
|
||||
|
||||
def self.findParentCategory(item)
|
||||
if item.menu_category_id
|
||||
@@ -11,9 +14,9 @@ class MenuItemInstance < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# private
|
||||
|
||||
def generate_menu_item_instance_code
|
||||
self.item_instance_code = SeedGenerator.generate_code(self.class.name, "II")
|
||||
end
|
||||
# def generate_menu_item_instance_code
|
||||
# self.item_instance_code = SeedGenerator.generate_code(self.class.name, "II")
|
||||
# end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
class MenuItemOption < ApplicationRecord
|
||||
validates_presence_of :name, :value
|
||||
|
||||
end
|
||||
|
||||
9
app/models/menu_item_set.rb
Normal file
9
app/models/menu_item_set.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class MenuItemSet < ApplicationRecord
|
||||
belongs_to :item_set
|
||||
belongs_to :menu_item
|
||||
end
|
||||
|
||||
# class Settings::MenuItemSet < ApplicationRecord
|
||||
# belongs_to :item_set_id
|
||||
# belongs_to :menu_item_id
|
||||
# end
|
||||
@@ -65,7 +65,6 @@ class Order < ApplicationRecord
|
||||
end
|
||||
|
||||
def adding_line_items
|
||||
|
||||
if self.items
|
||||
#re-order to
|
||||
ordered_list = re_order_items(self.items)
|
||||
@@ -320,12 +319,18 @@ class Order < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
def self.search(filter,from,to)
|
||||
if !from.nil? && !to.nil?
|
||||
Order.where("DATE_FORMAT(date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(date,'%d-%m-%Y') <= ?", from,to)
|
||||
def self.search(filter,from,to,count)
|
||||
if count.to_i > 0
|
||||
item_count = "and item_count = '#{count}'"
|
||||
else
|
||||
# find(:all)
|
||||
where("order_id LIKE ? OR item_count ='#{filter}'","%#{filter}%",)
|
||||
item_count = ''
|
||||
end
|
||||
if from.present? && to.present?
|
||||
Order.where("DATE_FORMAT(date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(date,'%d-%m-%Y') <= ? #{item_count}", from,to)
|
||||
elsif !from.present? && !to.present? && count.present?
|
||||
Order.where("item_count = '#{count}'")
|
||||
else
|
||||
Order.where("order_id LIKE ? OR status LIKE ? OR order_type LIKE ? OR source='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%",)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -22,14 +22,14 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
|
||||
# end
|
||||
|
||||
#Bill Receipt Print
|
||||
def print_close_cashier(printer_settings,shift_sale,shop_details,sale_taxes)
|
||||
def print_close_cashier(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount)
|
||||
#Use CUPS service
|
||||
#Generate PDF
|
||||
#Print
|
||||
cashier = shift_sale.employee.name
|
||||
shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p")
|
||||
|
||||
pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes)
|
||||
pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount)
|
||||
filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf"
|
||||
pdf.render_file filename
|
||||
self.print(filename)
|
||||
|
||||
@@ -91,7 +91,7 @@ class Sale < ApplicationRecord
|
||||
add_item(item)
|
||||
end
|
||||
|
||||
# link_order_sale(order.id)
|
||||
link_order_sale(order.id)
|
||||
|
||||
end
|
||||
self.save!
|
||||
@@ -295,25 +295,33 @@ class Sale < ApplicationRecord
|
||||
total_tax_amount = 0
|
||||
#tax_profile - list by order_by
|
||||
tax_profiles = TaxProfile.all.order("order_by asc")
|
||||
|
||||
customer = Customer.find(sale.customer_id)
|
||||
# #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
|
||||
customer.tax_profiles.each do |cus_tax|
|
||||
if cus_tax.to_i == tax.id
|
||||
sale_tax = SaleTax.new(:sale => sale)
|
||||
sale_tax.tax_name = tax.name
|
||||
sale_tax.tax_rate = tax.rate
|
||||
|
||||
# substract , to give after discount
|
||||
total_tax = total_taxable - total_discount
|
||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||
#new taxable amount is standard rule for step by step
|
||||
# total_taxable = total_taxable + sale_tax.tax_payable_amount
|
||||
# substract , to give after discount
|
||||
total_tax = total_taxable - total_discount
|
||||
#include or execulive
|
||||
if tax.inclusive
|
||||
rate = tax.rate
|
||||
divided_value = (100 + rate)/rate
|
||||
sale_tax.tax_payable_amount = total_tax / divided_value
|
||||
else
|
||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
||||
end
|
||||
#new taxable amount is standard rule for step by step
|
||||
# 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
|
||||
sale_tax.inclusive = tax.inclusive
|
||||
sale_tax.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
sale.total_tax = total_tax_amount
|
||||
@@ -321,12 +329,6 @@ class Sale < ApplicationRecord
|
||||
|
||||
# Tax Calculate
|
||||
def apply_tax(total_taxable)
|
||||
#if tax is not apply create new record
|
||||
# self.sale_taxes.each do |existing_tax|
|
||||
# #delete existing and create new
|
||||
# existing_tax.delete
|
||||
# end
|
||||
|
||||
#if tax is not apply create new record
|
||||
SaleTax.where("sale_id='#{self.sale_id}'").find_each do |existing_tax|
|
||||
#delete existing and create new
|
||||
@@ -336,27 +338,38 @@ class Sale < ApplicationRecord
|
||||
total_tax_amount = 0
|
||||
#tax_profile - list by order_by
|
||||
tax_profiles = TaxProfile.all.order("order_by asc")
|
||||
|
||||
customer = Customer.find(self.customer_id)
|
||||
|
||||
# #Creat new tax records
|
||||
#Create 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 = total_taxable * tax.rate
|
||||
total_tax = total_taxable - self.total_discount
|
||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||
#new taxable amount is standard rule for step by step
|
||||
# total_taxable = total_taxable + sale_tax.tax_payable_amount
|
||||
customer.tax_profiles.each do |cus_tax|
|
||||
if cus_tax.to_i == tax.id
|
||||
sale_tax = SaleTax.new(:sale => self)
|
||||
sale_tax.tax_name = tax.name
|
||||
sale_tax.tax_rate = tax.rate
|
||||
|
||||
sale_tax.inclusive = tax.inclusive
|
||||
sale_tax.save
|
||||
# substract , to give after discount
|
||||
total_tax = total_taxable - self.total_discount
|
||||
#include or execulive
|
||||
if tax.inclusive
|
||||
rate = tax.rate
|
||||
divided_value = (100 + rate)/rate
|
||||
sale_tax.tax_payable_amount = total_tax / divided_value
|
||||
else
|
||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
||||
end
|
||||
|
||||
#new taxable amount is standard rule for step by step
|
||||
# total_taxable = total_taxable + sale_tax.tax_payable_amount
|
||||
|
||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
||||
sale_tax.inclusive = tax.inclusive
|
||||
sale_tax.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.total_tax = total_tax_amount
|
||||
|
||||
end
|
||||
|
||||
def product_get_unit_price(item_code)
|
||||
@@ -401,7 +414,6 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.search(filter,from,to)
|
||||
|
||||
if filter.blank?
|
||||
keyword = ''
|
||||
else
|
||||
@@ -418,7 +430,6 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.search_credit_sales(customer,filter,from,to)
|
||||
|
||||
if filter.blank?
|
||||
keyword = ''
|
||||
else
|
||||
@@ -436,7 +447,7 @@ class Sale < ApplicationRecord
|
||||
.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and sp.payment_method = 'creditnote' #{keyword} #{custo}", from,to)
|
||||
else
|
||||
sale = Sale.all.joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id")
|
||||
.where("sp.payment_method =? #{keyword} #{custo}",'creditnote')
|
||||
.where("sp.payment_method ='creditnote' #{keyword} #{custo}")
|
||||
|
||||
end
|
||||
|
||||
@@ -537,31 +548,25 @@ class Sale < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.get_by_range_by_saleitems(from,to,status,report_type)
|
||||
query = Sale.select("
|
||||
mi.item_code as code,(SUM(i.qty) * i.unit_price) as grand_total,
|
||||
SUM(i.qty) as total_item," +
|
||||
" i.unit_price as unit_price,
|
||||
mi.name as product_name,
|
||||
mc.name as menu_category_name,
|
||||
mc.id as menu_category_id ")
|
||||
.group('mi.id')
|
||||
.order("mi.menu_category_id")
|
||||
|
||||
query = Sale.select("
|
||||
mi.item_code as code,(SUM(i.qty) * i.unit_price) as grand_total,
|
||||
SUM(i.qty) as total_item," +
|
||||
" i.unit_price as unit_price,
|
||||
mi.name as product_name,
|
||||
mc.name as menu_category_name,
|
||||
mc.id as menu_category_id ")
|
||||
.group('mi.id')
|
||||
.order("mi.menu_category_id")
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
|
||||
JOIN menu_items mi ON i.product_code = mi.item_code" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id
|
||||
JOIN employees ea ON ea.id = sales.cashier_id")
|
||||
|
||||
|
||||
query = query.where("(receipt_date between ? and ? and sale_status=?) AND i.unit_price <> 0",from,to,status)
|
||||
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
|
||||
JOIN menu_items mi ON i.product_code = mi.item_code" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id
|
||||
JOIN employees ea ON ea.id = sales.cashier_id")
|
||||
|
||||
|
||||
query = query.where("(receipt_date between ? and ? and sale_status=?) AND i.unit_price <> 0",from,to,status)
|
||||
end
|
||||
|
||||
|
||||
def self.get_by_shiftsales(from,to,shift)
|
||||
if !shift.blank?
|
||||
ShiftSale.where("id =?",shift.id)
|
||||
@@ -591,79 +596,77 @@ def self.get_item_query()
|
||||
|
||||
query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id")
|
||||
query = query.group('i.product_code ').order("mi.account_id, mi.menu_category_id")
|
||||
end
|
||||
|
||||
def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
||||
# date_type_selection = get_sql_function_for_report_type(report_type)
|
||||
|
||||
query = self.get_item_query()
|
||||
discount_query = 0
|
||||
total_card_amount = 0
|
||||
total_cash_amount = 0
|
||||
total_credit_amount = 0
|
||||
total_foc_amount = 0
|
||||
total_grand_total = 0
|
||||
|
||||
if shift.present?
|
||||
query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
|
||||
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
|
||||
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
|
||||
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
|
||||
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
|
||||
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
|
||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a)
|
||||
sale_cash.each do |s_c|
|
||||
total_cash_amount += s_c.cash_amount.to_f
|
||||
total_card_amount += s_c.card_amount.to_f
|
||||
total_credit_amount += s_c.credit_amount.to_f
|
||||
total_foc_amount += s_c.foc_amount.to_f
|
||||
end
|
||||
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
|
||||
### => get all sales range in shift_sales
|
||||
elsif shift_sale_range.present?
|
||||
query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
|
||||
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
|
||||
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
|
||||
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
|
||||
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
|
||||
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
|
||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a)
|
||||
sale_cash.each do |s_c|
|
||||
total_cash_amount += s_c.cash_amount.to_f
|
||||
total_card_amount += s_c.card_amount.to_f
|
||||
total_credit_amount += s_c.credit_amount.to_f
|
||||
total_foc_amount += s_c.foc_amount.to_f
|
||||
end
|
||||
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
|
||||
else
|
||||
query = query.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
|
||||
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
|
||||
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
|
||||
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
|
||||
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
|
||||
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
|
||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||
.where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to)
|
||||
sale_cash.each do |s_c|
|
||||
total_cash_amount += s_c.cash_amount.to_f
|
||||
total_card_amount += s_c.card_amount.to_f
|
||||
total_credit_amount += s_c.credit_amount.to_f
|
||||
total_foc_amount += s_c.foc_amount.to_f
|
||||
end
|
||||
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
|
||||
end
|
||||
|
||||
|
||||
def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
|
||||
|
||||
# date_type_selection = get_sql_function_for_report_type(report_type)
|
||||
|
||||
query = self.get_item_query()
|
||||
discount_query = 0
|
||||
total_card_amount = 0
|
||||
total_cash_amount = 0
|
||||
total_credit_amount = 0
|
||||
total_foc_amount = 0
|
||||
total_grand_total = 0
|
||||
|
||||
if shift.present?
|
||||
query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
|
||||
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
|
||||
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
|
||||
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
|
||||
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
|
||||
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
|
||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a)
|
||||
sale_cash.each do |s_c|
|
||||
total_cash_amount += s_c.cash_amount.to_f
|
||||
total_card_amount += s_c.card_amount.to_f
|
||||
total_credit_amount += s_c.credit_amount.to_f
|
||||
total_foc_amount += s_c.foc_amount.to_f
|
||||
end
|
||||
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
|
||||
### => get all sales range in shift_sales
|
||||
elsif shift_sale_range.present?
|
||||
query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
|
||||
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
|
||||
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
|
||||
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
|
||||
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
|
||||
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
|
||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||
.where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a)
|
||||
sale_cash.each do |s_c|
|
||||
total_cash_amount += s_c.cash_amount.to_f
|
||||
total_card_amount += s_c.card_amount.to_f
|
||||
total_credit_amount += s_c.credit_amount.to_f
|
||||
total_foc_amount += s_c.foc_amount.to_f
|
||||
end
|
||||
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
|
||||
else
|
||||
query = query.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
|
||||
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
|
||||
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
|
||||
sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
|
||||
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
|
||||
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
|
||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||
.where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to)
|
||||
sale_cash.each do |s_c|
|
||||
total_cash_amount += s_c.cash_amount.to_f
|
||||
total_card_amount += s_c.card_amount.to_f
|
||||
total_credit_amount += s_c.credit_amount.to_f
|
||||
total_foc_amount += s_c.foc_amount.to_f
|
||||
end
|
||||
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
|
||||
|
||||
end
|
||||
|
||||
return query, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
|
||||
return query, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
|
||||
end
|
||||
|
||||
def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_type)
|
||||
|
||||
@@ -46,6 +46,8 @@ class SalePayment < ApplicationRecord
|
||||
payment_status = giftcard_payment
|
||||
when "paypar"
|
||||
payment_status = paypar_payment
|
||||
when "foc"
|
||||
payment_status = foc_payment
|
||||
else
|
||||
puts "it was something else"
|
||||
end
|
||||
@@ -164,6 +166,17 @@ class SalePayment < ApplicationRecord
|
||||
return payment_status
|
||||
end
|
||||
|
||||
def foc_payment
|
||||
payment_status = false
|
||||
self.payment_method = "foc"
|
||||
self.payment_amount = self.received_amount
|
||||
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
|
||||
self.payment_status = "paid"
|
||||
payment_method = self.save!
|
||||
sale_update_payment_status(self.received_amount)
|
||||
return payment_status
|
||||
end
|
||||
|
||||
def creditnote_payment(customer_id)
|
||||
payment_status = false
|
||||
|
||||
@@ -257,11 +270,15 @@ class SalePayment < ApplicationRecord
|
||||
all_received_amount = 0.0
|
||||
sObj = Sale.find(self.sale_id)
|
||||
is_credit = 0
|
||||
is_foc = 0
|
||||
sObj.sale_payments.each do |spay|
|
||||
all_received_amount += spay.payment_amount.to_f
|
||||
if spay.payment_method == "creditnote"
|
||||
is_credit = 1
|
||||
end
|
||||
if spay.payment_method == "foc"
|
||||
is_foc = 1
|
||||
end
|
||||
end
|
||||
if (self.sale.grand_total <= all_received_amount)
|
||||
if is_credit == 0
|
||||
@@ -269,9 +286,16 @@ class SalePayment < ApplicationRecord
|
||||
else
|
||||
self.sale.payment_status = "outstanding"
|
||||
end
|
||||
|
||||
if is_foc == 0
|
||||
self.sale.payment_status = "paid"
|
||||
else
|
||||
self.sale.payment_status = "foc"
|
||||
end
|
||||
|
||||
self.sale.sale_status = "completed"
|
||||
|
||||
if MembershipSetting.find_by_rebate(1)
|
||||
if MembershipSetting.find_by_rebate(1) && is_foc == 0
|
||||
response = rebat(sObj)
|
||||
|
||||
if !response.nil?
|
||||
|
||||
@@ -57,6 +57,11 @@ class ShiftSale < ApplicationRecord
|
||||
self.commercial_taxes = self.commercial_taxes.to_i + tax.to_f
|
||||
self.total_rounding = self.total_rounding + saleobj.rounding_adjustment
|
||||
self.total_receipt = self.total_receipt + 1
|
||||
if saleobj.customer.customer_type == "Dinein"
|
||||
self.dining_count = self.dining_count + 1
|
||||
else
|
||||
self.takeaway_count = self.takeaway_count + 1
|
||||
end
|
||||
self.save
|
||||
end
|
||||
|
||||
@@ -79,6 +84,11 @@ class ShiftSale < ApplicationRecord
|
||||
self.commercial_taxes = self.commercial_taxes.to_i - tax.to_f
|
||||
self.total_rounding = self.total_rounding - saleobj.rounding_adjustment
|
||||
self.total_void = self.total_void + saleobj.grand_total
|
||||
if saleobj.customer.customer_type == "Dinein"
|
||||
self.dining_count = self.dining_count - 1
|
||||
else
|
||||
self.takeaway_count = self.takeaway_count - 1
|
||||
end
|
||||
self.save
|
||||
end
|
||||
end
|
||||
@@ -88,4 +98,40 @@ class ShiftSale < ApplicationRecord
|
||||
closing_balance = shiftobj.grand_total + shiftobj.cash_in - shiftobj.cash_out + shiftobj.total_cash
|
||||
return closing_balance
|
||||
end
|
||||
|
||||
def self.get_by_shift_other_payment(shift)
|
||||
|
||||
other_payment = Sale.select("sale_payments.payment_method as name,
|
||||
SUM(case when (sale_payments.payment_method='mpu') then (sale_payments.payment_amount) else 0 end) as mpu_amount,
|
||||
SUM(case when (sale_payments.payment_method='visa') then (sale_payments.payment_amount) else 0 end) as visa_amount,
|
||||
SUM(case when (sale_payments.payment_method='master') then (sale_payments.payment_amount) else 0 end) as master_amount,
|
||||
SUM(case when (sale_payments.payment_method='jcb') then (sale_payments.payment_amount) else 0 end) as jcb_amount,
|
||||
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount,
|
||||
SUM(case when (sale_payments.payment_method='paypar') then (sale_payments.payment_amount) else 0 end) as paypar_amount")
|
||||
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
|
||||
.where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id)
|
||||
end
|
||||
|
||||
def self.calculate_total_price_by_accounts(shift,type)
|
||||
query = Sale.select("acc.title as account_name," +
|
||||
"SUM(case when (acc.id=i.account_id) then (i.price) else 0 end) as total_price")
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id "+
|
||||
"JOIN accounts acc ON acc.id = i.account_id" +
|
||||
" JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id")
|
||||
if type == 'discount'
|
||||
query = query.where("sales.shift_sale_id =? and sale_status = 'completed' and i.is_taxable = false and i.remark = 'Discount'", shift.id)
|
||||
.group("acc.title").order("acc.id")
|
||||
else
|
||||
query = query.where("sales.shift_sale_id =? and sale_status = 'completed'", shift.id)
|
||||
.group("acc.title").order("acc.id")
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_total_member_discount(shift)
|
||||
query = Sale.select("SUM(sales.total_discount) as member_discount")
|
||||
.where("shift_sale_id =? and sale_status = 'completed' and discount_type = 'member_discount'", shift.id)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user