merge with discount

This commit is contained in:
Yan
2017-06-29 11:41:29 +06:30
13 changed files with 374 additions and 126 deletions

View File

@@ -25,9 +25,8 @@ class Order < ApplicationRecord
booking = nil
if self.new_booking
booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking",
:checkin_at => Time.now.utc.getlocal, :checkin_by => self.employee_name,
:checkin_at => Time.now.utc, :checkin_by => self.employee_name,
:booking_status => "assign" })
table = DiningFacility.find(self.table_id)
table.status = "occupied"
@@ -55,7 +54,7 @@ class Order < ApplicationRecord
end
return false
return false, @message = "booking fail"
end

View File

@@ -65,11 +65,11 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
end
#Bill Receipt Print
def print_receipt_bill(printer_settings,sale_items,sale_data, customer_name, item_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details)
def print_receipt_bill(printer_settings,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details)
#Use CUPS service
#Generate PDF
#Print
pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, member_info,rebate_amount,shop_details)
pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details)
# print as print copies in printer setting
count = printer_settings.print_copies

View File

@@ -30,11 +30,13 @@ class SaleItem < ApplicationRecord
# end
end
# Get Prices for each accounts (eg: food, beverage)
def self.calculate_price_by_accounts(sale_items)
price_accounts = []
Account.all.each do |a|
account_price = {:name => a.title, :price => 0}
# Check for actual sale items
sale_items.each do |si|
if si.account_id == a.id
account_price[:price] = account_price[:price] + si.price
@@ -46,6 +48,24 @@ class SaleItem < ApplicationRecord
return price_accounts
end
# Get discount Prices for each accounts (eg: food, beverage)
def self.get_discount_price_by_accounts(sale_items)
discount_accounts = []
Account.all.each do |a|
discount_account = {:name => a.title, :price => 0}
# Check for actual sale items
sale_items.where("is_taxable = 0 AND remark = 'Discount'").find_each do |si|
if si.account_id == a.id
discount_account[:price] = (discount_account[:price] + si.price) * -1
end
end
discount_accounts.push(discount_account)
end
return discount_accounts
end
# Calculate rebate_by_account
def self.calculate_rebate_by_account(sale_items)
rebateacc = Account.where("rebate=?",true)