Merge branch 'discount' of bitbucket.org:code2lab/sxrestaurant

This commit is contained in:
Yan
2017-06-23 17:51:46 +06:30
16 changed files with 183 additions and 69 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

@@ -82,7 +82,33 @@ class Oqs::HomeController < BaseOqsController
end
# Query for OQS with delivery status
def queue_items_query(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;
@@ -44,7 +46,10 @@ class Origami::DiscountsController < BaseOrigamiController
sale_item.save
end
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

@@ -24,19 +24,19 @@ class Origami::RequestBillsController < BaseOrigamiController
customer= Customer.find(@sale_data.customer_id)
# get member information
member_info = Customer.get_member_account(customer)
member_info = Customer.get_member_account(customer)
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
# 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

@@ -18,14 +18,15 @@ class OrderQueueStation < ApplicationRecord
order_items = order.order_items
# get dining
booking = Booking.find_by_dining_facility_id(dining.id)
booking = Booking.find_by_dining_facility_id(dining.id)
#Assign OQS id to order Items
oqs_stations.each do |oqs|
oqs_stations.each do |oqs|
is_auto_printed = false
#Get List of items -
pq_items = JSON.parse(oqs.processing_items)
#Loop through the processing items
#Loop through the processing items
pq_items.each do |pq_item|
#Processing through the looping items
order_items.each do |order_item|
@@ -36,11 +37,13 @@ class OrderQueueStation < ApplicationRecord
# else
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
# end
if oqs.auto_print
# end
# Auto Printing
if oqs.auto_print && is_auto_printed == false
print_slip(oqs, order, order_items)
end
is_auto_printed = true
end
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,26 +104,24 @@ 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) {
# @item_width.to_i + @half_qty.to_i
text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
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
}
# @item_width.to_i + @half_qty.to_i
text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
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
@@ -155,25 +154,26 @@ class ReceiptBillPdf < Prawn::Document
end
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
end
move_down 5
end
def items_account(item_price_by_accounts)
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
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

@@ -80,7 +80,7 @@
<!-- Column One -->
<!-- Column Two -->
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="col-lg-5 col-md-5 col-sm-5">
<!-- Discount Amount -->
<div class="card">
<div class="card-header">
@@ -167,14 +167,23 @@
<div class="col-md-3">
<div class="form-group">
<button id="net" class="btn btn-warning fluid action-btn">Net</button>
<button id="percentage" class="btn btn-primary fluid action-btn">Percentage</button>
<button id="pay-discount" class="btn btn-danger fluid action-btn">Enter</button>
<button id="percentage" class="btn btn-primary fluid action-btn">Percentage</button>
<button id="remove-item" class="btn btn-default fluid action-btn">Remove</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Column Three -->
<div class="col-lg-1 col-md-1 col-sm-1">
<!-- Action Panel -->
<div>
<button type="button" class="btn btn-primary btn-block" onclick="window.location.href = '/origami';"><i class="fa fa-arrow-left"></i> Back </button>
<button id="pay-discount" class="btn btn-danger btn-block action-btn">Enter</button>
</div>
</div>
</div>
<script type="text/javascript">
@@ -233,6 +242,16 @@ $(document).ready(function(){
}
});
// Select discount-item
$('#order-items-table tbody').on('click', '.discount-item-row',function(){
if($(this).hasClass('selected-item') == true){
$(this).removeClass('selected-item');
}
else {
$(this).addClass('selected-item');
}
});
// Select for account types
$(".accounts-type").on('click', function(e){
if($(this).hasClass('selected-account') == true){
@@ -241,6 +260,13 @@ $(document).ready(function(){
else {
$(this).addClass('selected-account');
}
var account_id = $(this).attr('id').substr(8);
$(".item-row").each(function(i){
if($(this).children().find("#item-account-type").text() == account_id){
$(this).addClass("selected-item");
}
});
});
// Calculate Net Discount for Payment
@@ -261,7 +287,10 @@ $(document).ready(function(){
}
else {
calculate_item_discount(0, discount_value, sale_items, account_types);
}
}
// Remove Selection
selection_remove();
});
// Calculate Percentage Discount for Payment
@@ -282,10 +311,21 @@ $(document).ready(function(){
}
else {
calculate_item_discount(1, discount_value, sale_items, account_types);
}
}
// Remove Selection
selection_remove();
});
// Remove selected discount items
$("#remove-item").on('click', function(e){
e.preventDefault();
$('.discount-item-row.selected-item').each(function(i){
$(this).remove();
});
});
// Pay Discount
// Pay Discount for Payment
$("#pay-discount").on('click', function(e){
e.preventDefault();
@@ -307,9 +347,16 @@ $(document).ready(function(){
type: "POST",
url: ajax_url,
data: params,
success:function(result){
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();
}
});
});
@@ -331,6 +378,13 @@ function update_balance(){
$('#order-grand-total').text(total);
}
/* Remove Selection */
function selection_remove(){
$(".item-row").removeClass("selected-item");
$(".discount_item_row").removeClass("selected-item");
$(".accounts-type").removeClass("selected-account");
}
/* Get Item rows but not discount*/
function get_item_rows(){
var sale_items = [];
@@ -359,11 +413,24 @@ function get_discount_item_rows(){
return sale_items;
}
/* Get discount Item rows */
// function get_selected_discount_items(){
// var sale_items = [];
// $('.discount-item-row').hasClass('.selected-item').each(function(i){
// var sale_item = {};
// sale_item.id = $(this).attr('id');
// sale_item.name = $(this).find('#item-name-price').text();
// sale_item.account_id = $(this).find('#item_account_type').text();
// sale_item.price = $(this).find('#item-total-price').text();
// sale_items.push(sale_item);
// });
// return sale_items;
// }
/* Get Selected Sale Item's ID and Price */
function get_selected_sale_items(){
var sale_items = [];
$('.selected-item').each(function(i){
$('.item-row.selected-item').each(function(i){
var sale_item = {};
sale_item.id = $(this).attr('id').substr(0,16);
sale_item.name = $(this).find('#item-name-price').text().split('@')[0];
@@ -526,7 +593,7 @@ function item_row_template(type, item, discount_amount, amount){
if(type == 1){
dis_str = dis_str + "(" + amount + "%)"
}
var discount_item_row = "<tr class='item-row discount-item-row' id='" + item.id + "'>" +
var discount_item_row = "<tr class='discount-item-row' id='" + item.id + "'>" +
"<td style='width: 60%; text-align: left;'>" +
"<span id='item_account_type' class='hidden'>" +
item.account_id +

View File

@@ -243,7 +243,6 @@
<!-- Waiter Buttons -->
<button type="button" class="btn btn-primary btn-block" onclick="localStorage.removeItem('cash');window.location.href = '/origami';"> Back </button>
<button type="button" class="btn btn-primary btn-block"> FOC </button>
</div>
</div>

View File

@@ -190,7 +190,7 @@
</tr>
<tr>
<td class="charges-name"><strong>Discount:</strong></td>
<td class="item-attr"><strong id="order-discount">(<%=@selected_item.total_discount rescue 0%>)</strong></td>
<td class="item-attr"><strong id="order-discount">(<%=@obj.total_discount rescue 0%>)</strong></td>
</tr>
<% if @status == "sale" %>
<tr>