Merge branch 'master' into license

This commit is contained in:
Yan
2017-11-24 10:15:37 +06:30
143 changed files with 23874 additions and 3746 deletions

View File

@@ -122,7 +122,7 @@ class Ability
can :index, :credit_payment
can :index, :void_sale
elsif user.role == "supervisour"
elsif user.role == "supervisor"
can :edit, :sale_edit
can :item_void, :sale_edit

View File

@@ -35,7 +35,7 @@ class AssignedOrderItem < ApplicationRecord
left join booking_orders as bo on bo.order_id = assigned_order_items.order_id
left join bookings as bk on bk.booking_id = bo.booking_id
left join dining_facilities as df on df.id = bk.dining_facility_id")
.where("assigned_order_items.order_id = '#{order_id}' AND assigned_order_items.delivery_status = false AND odt.price <> 0 AND assigned_order_items.created_at >= '#{Time.now.beginning_of_day.utc}' ")
.where("assigned_order_items.order_id = '#{order_id}' AND assigned_order_items.delivery_status = false AND assigned_order_items.created_at >= '#{Time.now.beginning_of_day.utc}' ")
.order("assigned_order_items.assigned_order_item_id desc")
.group("assigned_order_items.assigned_order_item_id")
return order_item

View File

@@ -4,16 +4,16 @@ class DiningCharge < ApplicationRecord
def self.amount_calculate(dining_charges_obj, checkin , checkout)
# note :: the first Charge Block will cost all, the Time rounding block will included in 2nd Charge Block
if !checkin.nil? && !checkout.nil? && !dining_charges_obj.nil?
if !checkin.nil? && !checkout.nil? && !dining_charges_obj.nil?
block_count = 0
price = 0
minutes = DiningCharge.time_diff(checkout, checkin)
free_time = DiningCharge.convert_to_minutes(dining_charges_obj.minimum_free_time.utc.localtime.strftime('%H:%M'))
free_time = DiningCharge.convert_to_minutes(dining_charges_obj.minimum_free_time.utc.strftime('%H:%M'))
dining_minutes = minutes #- free_time # stayminutes - free minutes
if dining_minutes <= free_time
price = 0
else
charge_type = dining_charges_obj.charge_type
charge_type = dining_charges_obj.charge_type
if charge_type == 'hr'
block_count, price = DiningCharge.charges(dining_charges_obj, dining_minutes, 'hr')
elsif charge_type == 'day'
@@ -30,7 +30,7 @@ class DiningCharge < ApplicationRecord
# dining charges calculate
def self.charges(chargesObj, dining_minutes, type)
solid_price = 0
charge_block = DiningCharge.convert_to_minutes(chargesObj.charge_block.utc.localtime.strftime('%H:%M'))
charge_block = DiningCharge.convert_to_minutes(chargesObj.charge_block.utc.strftime('%H:%M'))
result = dining_minutes / charge_block
if result.to_i < 1
@@ -40,7 +40,7 @@ class DiningCharge < ApplicationRecord
solid_price = result * chargesObj.unit_price
remain_value = dining_minutes % charge_block
rounding_time = DiningCharge.convert_to_minutes(chargesObj.time_rounding_block.utc.localtime.strftime('%H:%M'))
rounding_time = DiningCharge.convert_to_minutes(chargesObj.time_rounding_block.utc.strftime('%H:%M'))
roundingblock = remain_value / rounding_time
if roundingblock.to_i < 1
# no time rounding block

View File

@@ -77,7 +77,7 @@ class License
has_license = true # verify_license()
if has_license
puts "VERIFIED"
# puts "VERIFIED"
end
end

View File

@@ -6,7 +6,8 @@ class MenuCategory < ApplicationRecord
belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true
has_many :menu_items
validates_presence_of :name, :menu, :order_by
validates_presence_of :code, :name, :menu, :order_by
validates_uniqueness_of :code
default_scope { order('order_by asc') }
scope :active, -> {where("is_available = 1")}

View File

@@ -13,8 +13,9 @@ class MenuItem < ApplicationRecord
has_many :menu_item_sets
has_many :item_sets, through: :menu_item_sets
validates_presence_of :name, :type, :min_qty, :taxable,:account_id
validates_presence_of :item_code, :name, :type, :min_qty, :taxable,:account_id
validates_uniqueness_of :item_code
default_scope { order('item_code asc') }
scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') }
@@ -39,7 +40,7 @@ class MenuItem < ApplicationRecord
menu_item_hash[:item_code] = menu_item.item_code
menu_item_hash[:item_instance_code] = mt_instance.item_instance_code
menu_item_hash[:name] = menu_item.name.to_s + " - " + mt_instance.item_instance_name.to_s
menu_item_hash[:alt_name] = menu_item.alt_name.to_s + " - " + mt_instance.item_instance_name.to_s
menu_item_hash[:alt_name] = menu_item.alt_name.to_s # + " - " + mt_instance.item_instance_name.to_s
menu_item_hash[:price] = mt_instance.price
menu_item_hash[:promotion_price] = mt_instance.promotion_price
menu_item_hash[:is_on_promotion] = mt_instance.is_on_promotion

View File

@@ -4,6 +4,8 @@ class MenuItemInstance < ApplicationRecord
has_many :menu_instance_item_sets
has_many :item_sets, through: :menu_instance_item_sets
# before_create :generate_menu_item_instance_code
validates_presence_of :item_instance_code
# validates_uniqueness_of :item_instance_code
def self.findParentCategory(item)
if item.menu_category_id

View File

@@ -69,10 +69,10 @@ class OrderQueueStation < ApplicationRecord
# AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
# else
if (order_item.price != 0)
# if (order_item.price != 0)
AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs)
oqs_order_items.push(order_item)
end
# end
# end
end
end

View File

@@ -9,7 +9,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
filename = "tmp/order_item.pdf"
# check for item not to show
if order_item[0].price != 0
# if order_item[0].price != 0
pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name)
pdf.render_file filename
@@ -22,7 +22,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
else
self.print(filename, oqs.printer_name)
end
end
# end
end
# Query for per order
@@ -40,7 +40,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
options = odi.options == "[]"? "" : odi.options
# check for item not to show
if odi.price != 0
#if odi.price != 0
pdf = OrderItemPdf.new(print_settings,odi, print_status, options, oqs.use_alternate_name)
# pdf.render_file "tmp/order_item.pdf"
pdf.render_file filename
@@ -51,7 +51,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
else
self.print(filename, oqs.printer_name)
end
end
#end
end
# For Print Order Summary
else
@@ -81,7 +81,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
options = odi.options == "[]"? "" : odi.options
# check for item not to show
if odi.price != 0
#if odi.price != 0
pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name)
pdf.render_file filename
@@ -94,11 +94,11 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
else
self.print(filename, oqs.printer_name)
end
end
#end
end
# For Print Order Summary
else
filename = "tmp/booking_summary.pdf"
filename = "tmp/booking_summary.pdf"
pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name)
pdf.render_file filename
if oqs.print_copy
@@ -123,7 +123,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
left join dining_facilities AS df ON df.id = b.dining_facility_id
left join customers as cus ON cus.customer_id = orders.customer_id
left join menu_items as item ON item.item_code = order_items.item_code")
.where("order_items.item_code = '#{ id }' AND order_items.price != 0")
.where("order_items.item_instance_code = '#{ id }'")
.group("order_items.item_code")
elsif type == "order_summary"
OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
@@ -133,7 +133,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
left join dining_facilities AS df ON df.id = b.dining_facility_id
left join customers as cus ON cus.customer_id = orders.customer_id
left join menu_items as item ON item.item_code = order_items.item_code")
.where("orders.order_id = '#{ id }' AND order_items.price != 0")
.where("orders.order_id = '#{ id }'")
.group("order_items.order_items_id")
else
# order summary for booking
@@ -144,7 +144,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
left join dining_facilities AS df ON df.id = b.dining_facility_id
left join customers as cus ON cus.customer_id = orders.customer_id
left join menu_items as item ON item.item_code = order_items.item_code")
.where("b.booking_id = '#{ id }' AND order_items.price != 0")
.where("b.booking_id = '#{ id }'")
end
end

View File

@@ -153,7 +153,7 @@ class Promotion < ApplicationRecord
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price)
end
def self.update_existing_item(foc_qty, item, sale_id, type, item_price)
def self.update_existing_item(qty, item, sale_id, type, item_price)
sale_item = SaleItem.new
sale_item.product_code = item.item_code
@@ -161,13 +161,13 @@ class Promotion < ApplicationRecord
sale_item.product_alt_name = item.alt_name
sale_item.account_id = item.account_id
sale_item.remark = type
sale_item.qty = foc_qty * (-1)
sale_item.qty = qty * (-1)
sale_item.unit_price = item_price # * (-1)
sale_item.taxable_price = item_price # * (-1)
sale_item.price = foc_qty * item_price * (-1)
sale_item.taxable_price = (qty * item_price) * (-1)
sale_item.price = qty * item_price * (-1)
sale_item.is_taxable = false
sale_item.is_taxable = 1
sale_item.sale_id = sale_id
sale_item.save
sale = Sale.find(sale_id)

View File

@@ -48,7 +48,7 @@ class Sale < ApplicationRecord
# dining charges
charges = DiningCharge.where('dining_facility_id=?',booking.dining_facility_id).take
if !charges.nil?
if !charges.nil?
block_count, diningprice = DiningCharge.amount_calculate(charges, booking.checkin_at, booking.checkout_at)
dining_time = booking.checkin_at.strftime('%H:%M %p').to_s + " - " + booking.checkout_at.strftime('%H:%M %p').to_s
create_saleitem_diningcharges(charges, block_count, diningprice, booking.dining_facility.name, dining_time)
@@ -166,7 +166,7 @@ class Sale < ApplicationRecord
sale_item.qty = item.qty
sale_item.unit_price = item.price
sale_item.taxable_price = item.price
sale_item.taxable_price = sale_item.qty * sale_item.unit_price
sale_item.is_taxable = item.taxable
sale_item.price = sale_item.qty * sale_item.unit_price
@@ -225,7 +225,8 @@ class Sale < ApplicationRecord
puts "item.sales_item_id ddd"
puts item.sale_item_id
subtotal_price = subtotal_price + item.price
total_taxable = total_taxable + (item.taxable_price * item.qty)
total_taxable = total_taxable + item.taxable_price
# total_taxable = total_taxable + (item.taxable_price * item.qty)
end
apply_tax (total_taxable)
@@ -253,7 +254,11 @@ class Sale < ApplicationRecord
sales_items.each do |item|
#compute each item and added to total
subtotal_price = subtotal_price + item.price
total_taxable = total_taxable + (item.taxable_price * item.qty)
# check for item is taxable and calculate
if item.is_taxable
total_taxable = total_taxable + item.taxable_price
end
end
compute_tax(sale, total_taxable, total_discount)
@@ -269,6 +274,7 @@ class Sale < ApplicationRecord
end
# No Use too many wrong
def compute_without_void
sales_items = self.sale_items
@@ -467,9 +473,7 @@ class Sale < ApplicationRecord
else
sale = Sale.all.joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id")
.where("sp.payment_method ='creditnote' #{keyword} #{custo}")
end
end
def self.get_rounding_adjustment(num)
@@ -604,19 +608,33 @@ def self.get_by_shift_sale(from,to,status)
end
def self.get_item_query()
# query = SaleItem.select("acc.title as account_name,account_id, item_instance_code as item_code, " +
# "SUM(qty * unit_price) as grand_total,SUM(qty) as total_item," +
# " unit_price as unit_price,product_name as product_name, 'cat' as" +
# " menu_category_name,'test' as menu_category_id ")
# query = query.joins("JOIN sales s ON s.sale_id = sale_items.sale_id" +
# " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id")
# # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ")
# query = query.joins(" JOIN accounts acc ON acc.id = account_id")
# query = query.where("item_instance_code is not NULL")
# query = query.group("item_instance_code").order("account_id")
query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code, " +
"(i.qty * i.unit_price) as grand_total,(i.qty) as total_item," +
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," +
" i.unit_price as unit_price,i.product_name as product_name, mc.name as" +
" menu_category_name,mc.id as 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_item_instances mii ON i.item_instance_code = mii.item_instance_code" +
" JOIN menu_items mi ON mi.id = mii.menu_item_id" +
" JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id" +
" JOIN menu_categories mc ON mc.id = mi.menu_category_id ")
# "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ")
query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id")
query = query.where("i.unit_price > 0")
query = query.where("i.item_instance_code IS NOT NULL")
query = query.group("i.item_instance_code").order("mi.account_id, mi.menu_category_id")
end
@@ -759,35 +777,34 @@ end
def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type)
if payment_type.blank?
payment_type = ''
else
if payment_type == 'card'
payment_type = " and 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'"
else
payment_type = " and sale_payments.payment_method = '#{payment_type}'"
end
end
# wrong amount tax for service and commercial tax
# if payment_type.blank?
# payment_type = ''
# else
# if payment_type == 'card'
# payment_type = " and 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'"
# else
# payment_type = " and sale_payments.payment_method = '#{payment_type}'"
# end
# end
if shift.present?
query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
.joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a)
.where("sales.shift_sale_id in (?) and sale_status= 'completed'", shift.to_a)
.group("sale_taxes.tax_name")
.order("sale_taxes.sale_tax_id asc")
elsif shift_sale_range.present?
query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
.joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift_sale_range.to_a)
.where("sales.shift_sale_id in (?) and sale_status= 'completed'", shift_sale_range.to_a)
.group("sale_taxes.tax_name")
.order("sale_taxes.sale_tax_id asc")
else
query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
.joins("LEFT JOIN sales ON sales.sale_id = sale_taxes.sale_id")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.receipt_date between ? and ? #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", from,to)
.where("sales.receipt_date between ? and ? and sale_status= 'completed'", from,to)
.group("sale_taxes.tax_name")
.order("sale_taxes.sale_tax_id asc")
end
@@ -951,7 +968,7 @@ end
# .joins("join sale_payments on sale_id = sales.sale_id")
# .group("sales.sale_id")
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb"',today)
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb")',today)
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount")
@@ -970,7 +987,7 @@ end
end
def self.total_payment_methods(today)
query = Sale.select("sp.payment_method")
query = Sale.select("distinct sp.payment_method")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
end
@@ -978,7 +995,7 @@ end
def self.payment_sale(payment_method, today)
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if payment_method == 'card'
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb"',today)
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb")',today)
else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
end

View File

@@ -11,6 +11,44 @@ class SaleItem < ApplicationRecord
def compute_item
end
# Add Sale Items
def self.add_sale_items(sale_items)
sale_items.each do|saleitemObj|
@newsaleitem = SaleItem.new
@newsaleitem = saleitemObj.dup
@newsaleitem.save
@newsaleitem.qty = saleitemObj.qty * (-1)
@newsaleitem.unit_price = saleitemObj.unit_price * (-1)
@newsaleitem.taxable_price = (saleitemObj.unit_price * saleitemObj.qty) * (-1)
@newsaleitem.price = (saleitemObj.unit_price * saleitemObj.qty) * (-1)
@newsaleitem.product_name = saleitemObj.product_name + ' (FOC)'
@newsaleitem.save
end
end
def self.update_existing_item(qty, item, sale_id, type, item_price, price)
sale_item = SaleItem.new
sale_item.product_code = item.product_code
sale_item.product_name = item.product_name + "(#{type})"
sale_item.product_alt_name = item.product_alt_name
sale_item.account_id = item.account_id
sale_item.remark = type
if type == "foc" || type == "promotion" || type == "void"
sale_item.qty = qty * (-1)
else
sale_item.qty = qty
end
sale_item.unit_price = item_price # * (-1)
sale_item.taxable_price = (price) * (-1)
sale_item.price = (price) * (-1)
sale_item.is_taxable = 1
sale_item.sale_id = sale_id
sale_item.save
sale = Sale.find(sale_id)
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount)
end
def self.get_order_items_details(sale_id)
order_details = SaleItem.select("sales.total_tax as tax_amount, sales.grand_total as grand_total_amount , sales.total_discount as discount_amount,sales.receipt_date as receipt_date,
@@ -58,7 +96,7 @@ class SaleItem < ApplicationRecord
# Check for actual sale items
sale_items.where("is_taxable = false AND remark = 'Discount'").find_each do |si|
if si.account_id == a.id
discount_account[:price] = (discount_account[:price].abs + si.price.abs) * -1
discount_account[:price] = (discount_account[:price].abs + si.price.abs) * (-1)
end
end
discount_accounts.push(discount_account)

View File

@@ -169,12 +169,21 @@ class SalePayment < ApplicationRecord
def foc_payment
payment_status = false
# add to sale item with foc
sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }'")
sale_items.each do|item|
SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price)
end
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)
sale_update_payment_status(self.received_amount)
return payment_status
end

View File

@@ -54,7 +54,7 @@ class ShiftSale < ApplicationRecord
self.cash_sales = self.cash_sales.to_f + cash.to_f
self.credit_sales = self.credit_sales.to_i + credit.to_f
self.other_sales = self.other_sales.to_i + other_sales.to_f
self.nett_sales = self.nett_sales + saleobj.total_amount.to_f #self.grand_total.to_i - self.commercial_taxes
self.nett_sales = self.nett_sales + (saleobj.total_amount.to_f - self.total_discounts) #self.grand_total.to_i - self.commercial_taxes
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
@@ -81,7 +81,7 @@ class ShiftSale < ApplicationRecord
self.cash_sales = self.cash_sales.to_f - cash.to_f
self.credit_sales = self.credit_sales.to_i - credit.to_f
self.other_sales = self.other_sales.to_i - other_sales.to_f
self.nett_sales = self.nett_sales - saleobj.total_amount.to_f #self.grand_total.to_i - self.commercial_taxes
self.nett_sales = self.nett_sales - (saleobj.total_amount.to_f - self.total_discounts) #self.grand_total.to_i - self.commercial_taxes
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