accounts and discount updated

This commit is contained in:
Yan
2017-06-23 17:05:08 +06:30
parent 55c8ab80da
commit 3a0e26b2ea
14 changed files with 114 additions and 59 deletions

View File

@@ -34,12 +34,11 @@ class Api::BillController < Api::ApiController
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
# Calculate Food and Beverage Total
food_total, beverage_total = SaleItem.calculate_food_beverage(@sale_items)
# Calculate Price by accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, food_total, beverage_total)
printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts)
end

View File

@@ -83,6 +83,32 @@ class Oqs::HomeController < BaseOqsController
# Query for OQS with delivery status
def queue_items_query(status)
# queue_items = []
# AssignedOrderItem.all.each do |aoi|
# oqs = OrderQueueStation.find(aoi.order_queue_station_id)
# order = Order.find(aoi.order_id)
# order_items = OrderItem.find_by_order_id(aoi.order_id)
# booking_orders = BookingOrder.find_by_order_id(aoi.order_id)
# booking = Booking.find(booking_orders.booking_id)
# dining = DiningFacility.find(booking.dining_facility_id)
# customer = Customer.find_by_customer_id(order.customer_id)
# queue_item = {
# :assigned_order_item_id => aoi.assigned_order_item_id,
# :station_name => oqs.station_name,
# :is_active => oqs.is_active,
# :zone => dining.name,
# :item_code => aoi.item_code,
# :item_name => order_items.item_name,
# :price => order_items.price,
# :qty => order_items.qty,
# :item_order_by => order_items.item_order_by,
# :options => order_items.options,
# :customer_name => customer.name,
# :created_at => order_items.created_at
# }
# queue_items.push(queue_item)
# end
# return queue_items
AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.station_name, oqs.is_active, df.name as zone, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at")
.joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id
left join orders as od ON od.order_id = assigned_order_items.order_id

View File

@@ -19,6 +19,8 @@ class Origami::DiscountsController < BaseOrigamiController
if Sale.exists?(sale_id)
sale = Sale.find(sale_id)
table_id = sale.bookings[0].dining_facility_id
table_type = DiningFacility.find(table_id).type
sale.total_discount = overall_discount.to_f
sale.total_amount = sub_total.to_f
sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax;
@@ -45,6 +47,9 @@ class Origami::DiscountsController < BaseOrigamiController
end
end
end
dining = {:table_id => table_id, :table_type => table_type }
render :json => dining.to_json
end
#discount for selected order

View File

@@ -23,10 +23,10 @@ class Origami::PaymentsController < BaseOrigamiController
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
# Calculate Food and Beverage Total
food_total, beverage_total = SaleItem.calculate_food_beverage(saleObj.sale_items)
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, food_total, beverage_total, member_info,rebate_amount)
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, member_info,rebate_amount)
end
end
@@ -94,11 +94,11 @@ class Origami::PaymentsController < BaseOrigamiController
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
# Calculate Food and Beverage Total
food_total, beverage_total = SaleItem.calculate_food_beverage(saleObj.sale_items)
# Calculate price_by_accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, food_total, beverage_total, member_info,rebate_amount)
printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, member_info,rebate_amount)
end

View File

@@ -31,12 +31,12 @@ class Origami::RequestBillsController < BaseOrigamiController
# find order id by sale id
# sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
# Calculate Food and Beverage Total
food_total, beverage_total = SaleItem.calculate_food_beverage(@sale_items)
# Calculate price_by_accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, food_total, beverage_total,member_info)
printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info)
# redirect_to origami_path(@sale_data.sale_id)
end

View File

@@ -22,6 +22,7 @@ class OrderQueueStation < ApplicationRecord
#Assign OQS id to order Items
oqs_stations.each do |oqs|
is_auto_printed = false
#Get List of items -
pq_items = JSON.parse(oqs.processing_items)
@@ -38,8 +39,10 @@ class OrderQueueStation < ApplicationRecord
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
# end
if oqs.auto_print
# Auto Printing
if oqs.auto_print && is_auto_printed == false
print_slip(oqs, order, order_items)
is_auto_printed = true
end
end
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, food_total, beverage_total, member_info = nil,rebate_amount=nil)
def print_receipt_bill(printer_settings,sale_items,sale_data, customer_name, item_price_by_accounts, member_info = nil,rebate_amount=nil)
#Use CUPS service
#Generate PDF
#Print
pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total, member_info,rebate_amount)
pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, member_info,rebate_amount)
pdf.render_file "tmp/receipt_bill.pdf"
self.print("tmp/receipt_bill.pdf")

View File

@@ -30,9 +30,24 @@ class SaleItem < ApplicationRecord
# end
end
# Calculate food total and beverage total
def self.calculate_food_beverage(sale_items)
def self.calculate_price_by_accounts(sale_items)
price_accounts = []
Account.all.each do |a|
account_price = {:name => a.title, :price => 0}
sale_items.each do |si|
if si.account_id == a.id
account_price[:price] = account_price[:price] + si.price
end
end
price_accounts.push(account_price)
end
return price_accounts
end
# Calculate rebate_by_account
def self.calculate_rebate_by_account(sale_items)
rebateacc = Account.where("rebate=?",true)
puts "Account that can rebate"
rebateacc.each do |i|
@@ -40,7 +55,7 @@ class SaleItem < ApplicationRecord
end
prices=0
sale_items.each do |si|
price = self.get_price(si.sale_item_id,rebateacc)
price = self.get_rebate_price(si.sale_item_id,rebateacc)
prices = prices + price
end
@@ -48,7 +63,7 @@ class SaleItem < ApplicationRecord
end
# get food price or beverage price for item
def self.get_price(sale_item_id,rebateacc)
def self.get_rebate_price(sale_item_id,rebateacc)
price=0
item=SaleItem.select("sale_items.price , menu_items.account_id")

View File

@@ -265,7 +265,7 @@ class SalePayment < ApplicationRecord
end
def rebat(sObj)
rebate_prices = SaleItem.calculate_food_beverage(sObj.sale_items)
rebate_prices = SaleItem.calculate_rebate_by_account(sObj.sale_items)
puts "eeeeeeeeeeeeeeeeeeeeeeee"
puts rebate_prices
generic_customer_id = sObj.customer.membership_id

View File

@@ -2,7 +2,7 @@ class OrderItemPdf < Prawn::Document
attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width
def initialize(order_item, print_status, options)
self.page_width = 210
self.page_height = 2500
self.page_height = 1450
self.margin = 5
self.price_width = 40 # No Need for item
self.qty_width = 30

View File

@@ -2,7 +2,7 @@ class OrderSummaryPdf < Prawn::Document
attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width
def initialize(order, print_status)
self.page_width = 210
self.page_height = 2500
self.page_height = 1450
self.margin = 5
self.price_width = 40 # No Need for item
self.qty_width = 30

View File

@@ -2,7 +2,7 @@ class QueueNoPdf < Prawn::Document
attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width
def initialize(printer_settings, queue)
self.page_width = 210
self.page_height = 2500
self.page_height = 1450
self.margin = 5
self.price_width = 35
self.qty_width = 20

View File

@@ -1,6 +1,6 @@
class ReceiptBillPdf < Prawn::Document
attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width
def initialize(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total, member_info = nil,rebate_amount = nil)
def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, member_info = nil,rebate_amount = nil)
self.page_width = 210
self.page_height = 2500
self.margin = 5
@@ -29,7 +29,8 @@ class ReceiptBillPdf < Prawn::Document
stroke_horizontal_rule
cashier_info(sale_data, customer_name)
line_items(sale_items, food_total, beverage_total)
line_items(sale_items)
items_account(item_price_by_accounts)
all_total(sale_data)
@@ -103,7 +104,7 @@ class ReceiptBillPdf < Prawn::Document
move_down 5
end
def line_items(sale_items, food_total, beverage_total)
def line_items(sale_items)
y_position = cursor
pad_top(15) {
@@ -112,17 +113,15 @@ class ReceiptBillPdf < Prawn::Document
text_box "Price", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
text_box "Qty", :at =>[(self.item_width+self.price_width),y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
text_box "Total", :at =>[(self.item_width+self.price_width+4),y_position], :width => self.total_width+3, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
}
move_down 5
stroke_horizontal_rule
add_line_item_row(sale_items, food_total, beverage_total)
add_line_item_row(sale_items)
end
def add_line_item_row(sale_items, food_total, beverage_total)
def add_line_item_row(sale_items)
item_name_width = (self.item_width+self.price_width)
y_position = cursor
move_down 5
@@ -156,24 +155,25 @@ class ReceiptBillPdf < Prawn::Document
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{ sub_total }" , :size => self.item_font_size,:align => :right
end
# Food and Beverage
food_beverage_total = food_total.to_s + "/" + beverage_total.to_s
move_down 5
y_position = cursor
bounding_box([0,y_position], :width => self.item_description_width, :height => self.item_height) do
text "Food/Beverage Total", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width => self.label_width) do
text "#{ food_beverage_total }" , :size => self.item_font_size,:align => :right
def items_account(item_price_by_accounts)
y_position = cursor
item_price_by_accounts.each do |ipa|
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "#{ ipa[:price] }" , :size => self.item_font_size,:align => :right
end
move_down 5
end
end
def all_total(sale_data)
item_name_width = self.item_width
move_down 5
y_position = cursor
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do

View File

@@ -349,7 +349,14 @@ $(document).ready(function(){
data: params,
success:function(result){
alert("Successfully Discount!");
window.history.back();
if(result.table_type == "Table"){
window.location.href = "/origami/table/" + result.table_id
}
else {
window.location.href = "/origami/room/" + result.table_id
}
// window.history.back();
}
});
});