merge with r-19

This commit is contained in:
NyanLinHtut
2020-01-11 11:08:33 +06:30
106 changed files with 2722 additions and 3024 deletions

View File

@@ -1,7 +1,6 @@
source 'https://rubygems.org' source 'https://rubygems.org'
#ruby '2.4.1'
#ruby '2.5.0'
#ruby '2.5.7' #ruby '2.5.7'

View File

@@ -288,6 +288,10 @@ For Number Formats
=> settings/lookups => { lookup_type: number_format, name: strip_insignificant_zeros, => settings/lookups => { lookup_type: number_format, name: strip_insignificant_zeros,
value: {true: => ['1', 't', 'true', 'on', 'y', 'yes'], false: => ['0', 'f', 'false', 'off', 'n', 'no', ...] } value: {true: => ['1', 't', 'true', 'on', 'y', 'yes'], false: => ['0', 'f', 'false', 'off', 'n', 'no', ...] }
For Booking checkin time limit
settings/lookups =>
{ lookup_type: checkin_time_limit, name: CheckinTimeLimit, value: total hours before checkout (e.g., '48')) }
/* Customer Types in lookups */ /* Customer Types in lookups */
1) settings/lookups => { type:customer_type, name: Dinein, value:Dinein } 1) settings/lookups => { type:customer_type, name: Dinein, value:Dinein }
2) settings/lookups => { type:customer_type, name: Takeaway, value: Takeaway } 2) settings/lookups => { type:customer_type, name: Takeaway, value: Takeaway }

View File

@@ -629,7 +629,7 @@ $(function() {
status = "selected-attribute"; status = "selected-attribute";
} }
if(parseInt(jQuery.inArray(value[i], instance_attributes)) == -1){ if(parseInt(jQuery.inArray(value[i], instance_attributes)) == -1){
disabled = "disabled"; // disabled = "disabled";
} }
row +="<button id='selected-attribute' data-instances='"+JSON.stringify(instances)+"' data-type='" row +="<button id='selected-attribute' data-instances='"+JSON.stringify(instances)+"' data-type='"
+type+"' data-value='"+value[i]+"' class='btn btn- waves-effect attribute_btn " +type+"' data-value='"+value[i]+"' class='btn btn- waves-effect attribute_btn "
@@ -1102,16 +1102,30 @@ $(function() {
var total_price = 0; var total_price = 0;
var total_qty = 0; var total_qty = 0;
var taxable_amount = 0; var taxable_amount = 0;
var exclusive_total =0;
var inclusive_total =0;
var inclusive_tax =$('#inclusive_tax').val();
var exclusive_tax =$('#exclusive_tax').val();
var item_row = $('.summary-items tbody tr'); var item_row = $('.summary-items tbody tr');
$(item_row).each(function(i){ $(item_row).each(function(i){
var unit_price = parseFloat($(item_row[i]).attr('data-price')); var unit_price = parseFloat($(item_row[i]).attr('data-price'));
var qty = parseFloat($(item_row[i]).children('#item_qty').text()); var qty = parseFloat($(item_row[i]).children('#item_qty').text());
total_qty += qty; total_qty += qty;
total_price += qty*unit_price; total_price += qty*unit_price;
}); });
if (inclusive_tax >0){
inclusive_total = total_price / inclusive_tax;
total_price = total_price;
}
if (exclusive_tax >0){
exclusive_total = total_price * exclusive_tax;
total_price = total_price + exclusive_total;
}
var fixed_total_price = parseFloat(total_price).toFixed(2); var fixed_total_price = parseFloat(total_price).toFixed(2);
var fixed_taxable_amount = parseFloat(taxable_amount).toFixed(2); var fixed_taxable_amount = parseFloat(taxable_amount).toFixed(2);
$('#total_tax').empty();
$('#total_tax').append(parseInt(exclusive_total) + parseInt(inclusive_total));
$('#sub_total').empty(); $('#sub_total').empty();
$('#sub_total').append(fixed_total_price); $('#sub_total').append(fixed_total_price);

View File

@@ -1,16 +1,16 @@
App.checkin = App.cable.subscriptions.create('SecondDisplayChannel', { App.checkin = App.cable.subscriptions.create('SecondDisplayChannel', {
// App.messages = App.cable.subscriptions.create('MessagesChannel', { // App.messages = App.cable.subscriptions.create('MessagesChannel', {
connected: function() {}, connected: function() {},
disconnected: function() {}, disconnected: function() {},
received: function(data) { received: function(data) {
var hostname = location.hostname.trim(); var hostname = location.hostname.trim();
if(data.from == "" || hostname == data.from){ if(data.from == "" || hostname == data.from){
var data_obj = data.data; var data_obj = data.data;
var status = data.status; var status = data.status;
var count = 0 var count = 0
var sub_total = 0 var sub_total = 0
if (data.status == "order") { if (data.status == "order") {
for(var i in data_obj) { for(var i in data_obj) {
@@ -26,16 +26,15 @@ App.checkin = App.cable.subscriptions.create('SecondDisplayChannel', {
$(".second_display_items").append(row); $(".second_display_items").append(row);
}//end looping }//end looping
}else{ }else{
$('#s_sub_total').empty(); $('#s_sub_total').empty();
$('#s_sub_total').append(data_obj.total_amount); $('#s_sub_total').append(data_obj.total_amount);
$('#s_total_discount').empty(); $('#s_total_discount').empty();
$('#s_total_discount').append(data_obj.total_discount); $('#s_total_discount').append(data_obj.total_discount);
$('#s_tatal_tax').empty(); $('#s_tatal_tax').empty();
$('#s_tatal_tax').append(data_obj.total_tax); $('#s_tatal_tax').append(data_obj.total_tax);
$('#s_grand_total').empty(); $('#s_grand_total').empty();
$('#s_grand_total').append(data_obj.grand_total); $('#s_grand_total').append(data_obj.grand_total);
} }
} }
} }
}); });

View File

@@ -261,9 +261,9 @@ function checkReceiptNoInFirstBillData(receipt_no,payment) {
if (payment) { if (payment) {
if (json_data.length>0) { if (json_data.length>0) {
return json_data[0]["payment"]; return json_data[0]["payment"];
}else{ }else{
return false; return false;
} }
}else{ }else{
return status; return status;
} }

View File

@@ -69,11 +69,11 @@ $(document).ready(function(){
type: "POST", type: "POST",
url: "/origami/" + unique_id, url: "/origami/" + unique_id,
data: { 'booking_id' : unique_id }, data: { 'booking_id' : unique_id },
success:function(result){ success:function(result){
for (i = 0; i < result.length; i++) { for (i = 0; i < result.length; i++) {
var data = JSON.stringify(result[i]); var data = JSON.stringify(result[i]);
var parse_data = JSON.parse(data); var parse_data = JSON.parse(data);
var show_date = ""; var show_date = "";
// Receipt Header // Receipt Header
receipt_no = result[i].receipt_no; receipt_no = result[i].receipt_no;
@@ -81,14 +81,14 @@ $(document).ready(function(){
if(result[i].receipt_date != null){ if(result[i].receipt_date != null){
receipt_date = new Date(result[i].receipt_date); receipt_date = new Date(result[i].receipt_date);
show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes() show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes()
} }
//Receipt Charges //Receipt Charges
sub_total += parseFloat(parse_data.price); sub_total += parseFloat(parse_data.price);
discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount; discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount;
tax_amount = parse_data.tax_amount; tax_amount = parse_data.tax_amount;
grand_total_amount = parse_data.grand_total_amount; grand_total_amount = parse_data.grand_total_amount;
// Ordered Items // Ordered Items
var order_items_rows = "<tr>" + var order_items_rows = "<tr>" +
@@ -135,7 +135,7 @@ $(document).ready(function(){
// Discount for Payment // Discount for Payment
$('#discount').click(function() { $('#discount').click(function() {
var order_id=$(".selected-item").find(".orders-id").text().substr(0,16); var order_id=$(".selected-item").find(".orders-id").text().substr(0,16);
if(order_id!=""){ if(order_id!=""){
window.location.href = '/origami/' + order_id + '/discount' window.location.href = '/origami/' + order_id + '/discount'
} }
@@ -164,7 +164,7 @@ $(document).ready(function(){
} }
// For Percentage Discount // For Percentage Discount
if(discount_type == 1){ if(discount_type == 1){
discount_amount=(sub_total*discount_value)/100; discount_amount=(sub_total*discount_value)/100;
} }
@@ -193,7 +193,7 @@ $(document).ready(function(){
$('#customer').click(function() { $('#customer').click(function() {
var sale = $(".selected-item").find(".orders-id").text().substr(0,16); var sale = $(".selected-item").find(".orders-id").text().substr(0,16);
if (sale.substring(0, 3)=="SAL") { if (sale.includes("SAL")) {
var sale_id = sale var sale_id = sale
}else{ }else{
var sale_id = $(".selected-item").find(".order-cid").text(); var sale_id = $(".selected-item").find(".order-cid").text();
@@ -205,7 +205,7 @@ $(document).ready(function(){
$('#re-print').click(function() { $('#re-print').click(function() {
var sale_id = $(".selected-item").find(".orders-id").text().substr(0,16); var sale_id = $(".selected-item").find(".orders-id").text().substr(0,16);
window.location.href = '/origami/'+ sale_id + "/reprint" window.location.href = '/origami/'+ sale_id + "/reprint"
return false; return false;

View File

@@ -225,3 +225,14 @@ i.logout_icon{
width: 100% !important; width: 100% !important;
} }
} }
.report-table-header {
font-size: .95rem;
font-weight: 500;
color: rgba(0, 0, 0, 0.54);
padding: 10px;
}
.input-group-addon {
margin-bottom: 20px;
}

View File

@@ -29,7 +29,6 @@
} }
.bmd-form-group { .bmd-form-group {
position: relative; position: relative;
padding-top: 0 !important;
} }
.btn_create_induty{ .btn_create_induty{
display: inline; display: inline;
@@ -93,4 +92,4 @@
.add_to_charges{ .add_to_charges{
width:100%; width:100%;
padding:1rem; padding:1rem;
} }

View File

@@ -1,10 +1,9 @@
class Api::ApiController < ActionController::API class Api::ApiController < ActionController::API
include MultiTenancy include MultiTenancy
include TokenVerification include TokenVerification
include ActionController::MimeResponds include ActionController::MimeResponds
include ActionView::Rendering include ActionView::Rendering
include Customers
before_action :core_allow before_action :core_allow
helper_method :current_token, :current_login_employee, :get_cashier helper_method :current_token, :current_login_employee, :get_cashier

View File

@@ -10,7 +10,7 @@ class Api::BillController < Api::ApiController
if !ShiftSale.current_shift.nil? if !ShiftSale.current_shift.nil?
#create Bill by Booking ID #create Bill by Booking ID
table = 0 table = 0
if (params[:booking_id]) if params[:booking_id].present?
booking = Booking.find(params[:booking_id]) booking = Booking.find(params[:booking_id])
if booking.booking_orders.count > 0 if booking.booking_orders.count > 0
if booking.checkin_at.utc.strftime("%Y-%m-%d %H:%M") > Time.now.utc.strftime("%Y-%m-%d %H:%M") && booking.checkout_at.nil? if booking.checkin_at.utc.strftime("%Y-%m-%d %H:%M") > Time.now.utc.strftime("%Y-%m-%d %H:%M") && booking.checkout_at.nil?
@@ -52,13 +52,6 @@ class Api::BillController < Api::ApiController
@status = false @status = false
@error_message = "There is no order for '#{params[:booking_id]}'" @error_message = "There is no order for '#{params[:booking_id]}'"
end end
# elsif (params[:order_id])
# order = Order.find(params[:order_id])
# @status, @sale_id = Sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier, order.source)
#
# # for Job
# booking = Booking.find_by_sale_id(@sale_id)
# table = DiningFacility.find(booking.dining_facility_id)
end end
# Bind shift sale id to sale # Bind shift sale id to sale
@@ -148,7 +141,7 @@ class Api::BillController < Api::ApiController
@order = Order.new @order = Order.new
@order.source = "cashier" @order.source = "cashier"
@order.order_type = "Takeaway" @order.order_type = "Takeaway"
@order.customer_id = "CUS-000000000002" # for no customer id from mobile @order.customer_id = takeaway.customer_id # for no customer id from mobile
@order.items = params[:order_items] @order.items = params[:order_items]
@order.guest = params[:guest_info] @order.guest = params[:guest_info]
@order.table_id = params[:table_id] # this is dining facilities's id @order.table_id = params[:table_id] # this is dining facilities's id

View File

@@ -1,8 +1,8 @@
class Api::CheckInProcessController < Api::ApiController class Api::CheckInProcessController < Api::ApiController
# before_action :authenticate # before_action :authenticate
def check_in_time def check_in_time
if params[:dining_id] if params[:dining_id]
dining_facility = DiningFacility.find(params[:dining_id]) dining_facility = DiningFacility.find(params[:dining_id])
if params[:booking_id] if params[:booking_id]
data = Booking.where("dining_facility_id = #{params[:dining_id]} AND booking_id = '#{params[:booking_id]}'") data = Booking.where("dining_facility_id = #{params[:dining_id]} AND booking_id = '#{params[:booking_id]}'")
if data.count > 0 if data.count > 0
@@ -10,7 +10,7 @@ class Api::CheckInProcessController < Api::ApiController
else else
booking = nil booking = nil
end end
else else
booking = dining_facility.get_current_booking booking = dining_facility.get_current_booking
end end
if !booking.nil? if !booking.nil?
@@ -21,7 +21,7 @@ class Api::CheckInProcessController < Api::ApiController
#Send to background job for processing #Send to background job for processing
if ENV["SERVER_MODE"] == 'cloud' if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain from = request.subdomain + "." + request.domain
else else
from = "" from = ""
end end
ActionCable.server.broadcast "check_in_booking_channel",table: table,from:from ActionCable.server.broadcast "check_in_booking_channel",table: table,from:from
@@ -37,7 +37,7 @@ class Api::CheckInProcessController < Api::ApiController
end end
lookup_checkout_time = Lookup.collection_of("checkout_alert_time") lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
if !lookup_checkout_time.empty? if !lookup_checkout_time.empty?
now = Time.now.utc now = Time.now.utc
lookup_checkout_time.each do |checkout_time| lookup_checkout_time.each do |checkout_time|
@@ -52,16 +52,18 @@ class Api::CheckInProcessController < Api::ApiController
else else
render :json => { :status => true } render :json => { :status => true }
end end
else else
render :json => { :status => false, :error_message => "No current booking!" } render :json => { :status => false, :error_message => "No current booking!" }
end end
else
render :json => { :status => false }
end end
end end
def check_in_process def check_in_process
if params[:dining_id] if params[:dining_id]
dining_facility = DiningFacility.find(params[:dining_id]) dining_facility = DiningFacility.find(params[:dining_id])
if dining_facility.is_active && dining_facility.status == "available" if dining_facility.is_active && dining_facility.status == "available"
if params[:checkin_time] if params[:checkin_time]
checkin_at = nil checkin_at = nil
@@ -75,7 +77,7 @@ class Api::CheckInProcessController < Api::ApiController
if dining_facility.check_time(checkin_at, "checkin") if dining_facility.check_time(checkin_at, "checkin")
booking = dining_facility.get_current_booking booking = dining_facility.get_current_booking
if booking.nil? if booking.nil?
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking", booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
:checkin_by=>current_login_employee.name,:checkin_at => checkin_at,:checkout_at =>nil, :booking_status => "assign", :reserved_at => nil, :reserved_by => nil }) :checkin_by=>current_login_employee.name,:checkin_at => checkin_at,:checkout_at =>nil, :booking_status => "assign", :reserved_at => nil, :reserved_by => nil })
if booking.save! if booking.save!
@@ -95,10 +97,10 @@ class Api::CheckInProcessController < Api::ApiController
render :json => { :status => false, :error_message => "Operation failed!" } render :json => { :status => false, :error_message => "Operation failed!" }
end end
else else
booking = dining_facility.get_current_checkout_booking booking = dining_facility.current_checkout_booking
if booking.nil? if booking.nil?
lookup_checkout_time = Lookup.collection_of("checkout_time") lookup_checkout_time = Lookup.collection_of("checkout_time")
if !lookup_checkout_time.empty? if !lookup_checkout_time.empty?
today = Time.now.utc.getlocal today = Time.now.utc.getlocal
checkout_at = Time.now.utc.getlocal checkout_at = Time.now.utc.getlocal
@@ -118,7 +120,7 @@ class Api::CheckInProcessController < Api::ApiController
# else # else
# type = "RoomBooking" # type = "RoomBooking"
# end # end
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking", booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
:checkin_by=>current_login_employee.name,:checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign", :reserved_at => checkout_at, :reserved_by => current_login_employee.name }) :checkin_by=>current_login_employee.name,:checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign", :reserved_at => checkout_at, :reserved_by => current_login_employee.name })
if booking.save! if booking.save!
@@ -133,13 +135,13 @@ class Api::CheckInProcessController < Api::ApiController
unique_code = "CheckInOutPdf" unique_code = "CheckInOutPdf"
printer = PrintSetting.find_by_unique_code(unique_code) printer = PrintSetting.find_by_unique_code(unique_code)
# print when complete click # print when complete click
order_queue_printer = Printer::OrderQueuePrinter.new(printer) order_queue_printer = Printer::OrderQueuePrinter.new(printer)
if !printer.nil? if !printer.nil?
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, dining_facility) order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, dining_facility)
end end
end end
render :json => { :status => true, :booking_id => booking.booking_id, :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") } render :json => { :status => true, :booking_id => booking.booking_id, :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") }
else else
render :json => { :status => true } render :json => { :status => true }
@@ -176,7 +178,7 @@ class Api::CheckInProcessController < Api::ApiController
booking.save! booking.save!
render :json => { :status => true, :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") } render :json => { :status => true, :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") }
elsif !params[:booking_id].nil? && params[:time].nil? elsif !params[:booking_id].nil? && params[:time].nil?
error_message = "time is required!" error_message = "time is required!"
render :json => { :status => false, :error_message => error_message } render :json => { :status => false, :error_message => error_message }
elsif params[:booking_id].nil? && !params[:time].nil? elsif params[:booking_id].nil? && !params[:time].nil?

View File

@@ -71,15 +71,10 @@ class Api::OrdersController < Api::ApiController
current_user =Employee.find(current_shift.employee_id) current_user =Employee.find(current_shift.employee_id)
if checkin_checkout_time(params[:booking_id]) if checkin_checkout_time(params[:booking_id])
if params[:booking_id].present? table = DiningFacility.find(params[:table_id]) if params[:table_id].present?
booking = Booking.find(params[:booking_id])
end booking = table.current_checkin_booking if table
if params[:table_id].present? booking ||= Booking.find(params[:booking_id]) if params[:booking_id].present?
if booking.nil? || booking.dining_facility_id.to_i != params[:table_id].to_i
table = DiningFacility.find(params[:table_id])
booking = table.get_current_booking
end
end
#for extratime #for extratime
is_extra_time = false is_extra_time = false
@@ -102,14 +97,14 @@ class Api::OrdersController < Api::ApiController
@order = Order.new @order = Order.new
@order.source = params[:order_source] @order.source = params[:order_source]
@order.order_type = params[:order_type] @order.order_type = params[:order_type]
@order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile @order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
@order.items = params[:order_items] @order.items = params[:order_items]
@order.guest = params[:guest_info] @order.guest = params[:guest_info]
@order.table_id = params[:table_id] # this is dining facilities's id @order.table_id = params[:table_id] # this is dining facilities's id
@order.new_booking = true @order.new_booking = true
@order.waiters = current_login_employee.name @order.waiters = current_login_employee.name
@order.employee_name = current_login_employee.name @order.employee_name = current_login_employee.name
@order.shop_code = @shop.shop_code
@order.is_extra_time = is_extra_time @order.is_extra_time = is_extra_time
@order.extra_time = extra_time @order.extra_time = extra_time
@@ -122,8 +117,9 @@ class Api::OrdersController < Api::ApiController
end end
@status, @booking = @order.generate @status, @booking = @order.generate
if params[:order_source] != "app"
@order.process_order_queue(@order.order_id,@order.table_id,@order.source) if @status && @booking
Order.process_order_queue(@order.order_id,@order.table_id,@order.source)
end end
if @order.table_id.to_i > 0 if @order.table_id.to_i > 0
table = DiningFacility.find(@booking.dining_facility_id) table = DiningFacility.find(@booking.dining_facility_id)
@@ -131,11 +127,12 @@ class Api::OrdersController < Api::ApiController
from = getCloudDomain #get sub domain in cloud mode from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
end end
if current_user.role != "waiter" && params[:create_type] == "create_pay" # # for parallel order
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court') || (@order.source == 'app') # remoteIP = ""
@status, @sale = Sale.request_bill(@order,current_user,current_user) # begin
end # @status, @booking = @order.generate
end # remoteIP = request.remote_ip
# end while request.remote_ip != remoteIP
else else
return return_json_status_with_code(406, "Checkout time is over!") return return_json_status_with_code(406, "Checkout time is over!")
end end
@@ -198,7 +195,7 @@ class Api::OrdersController < Api::ApiController
#checked checkin and checkout time #checked checkin and checkout time
def checkin_checkout_time(booking_id) def checkin_checkout_time(booking_id)
status = true status = true
if !booking_id.nil? if booking_id.present?
if booking = Booking.find(booking_id) if booking = Booking.find(booking_id)
if booking.checkout_at.present? if booking.checkout_at.present?
if booking.checkout_at.utc <= Time.now.utc if booking.checkout_at.utc <= Time.now.utc

View File

@@ -8,8 +8,8 @@ class Api::Restaurant::MenuController < Api::ApiController
param_checksum = params[:checksum] param_checksum = params[:checksum]
# checksum = File.readlines("public/checksums/menu_json.txt").pop.chomp # checksum = File.readlines("public/checksums/menu_json.txt").pop.chomp
shop_code = params[:shop_code] all_menu = Menu.includes(:menu_categories => [:children, :menu_items => [:menu_item_instances => :menu_instance_item_sets, :item_sets => :menu_item_instances]]).active.all
all_menu = Menu.where('shop_code=?',shop_code).active.all
@request_url = '' @request_url = ''
if ENV["SERVER_MODE"] == "cloud" if ENV["SERVER_MODE"] == "cloud"
@request_url = request.base_url @request_url = request.base_url
@@ -17,10 +17,7 @@ class Api::Restaurant::MenuController < Api::ApiController
# to hash # to hash
menu_array = [] menu_array = []
all_menu.each do |m| all_menu.each do |m|
menu_array.push(m.to_json(:include => {:menu_categories => menu_array.push(m.to_json(:include => { :menu_categories => { :include => { :menu_items => { :include => [ :item_sets, :menu_item_instances => { :include => :menu_instance_item_sets } ] } } } } ))
{ :include => { :menu_items =>
{ :include => [:menu_item_sets, :menu_item_instances =>
{ :include => :menu_instance_item_sets}]} } }}))
end end
#export Checksum file generate by md5 #export Checksum file generate by md5
@@ -29,6 +26,10 @@ class Api::Restaurant::MenuController < Api::ApiController
if menu_checksum != param_checksum if menu_checksum != param_checksum
response.headers['CHECKSUM'] = menu_checksum response.headers['CHECKSUM'] = menu_checksum
@menus = all_menu @menus = all_menu
@item_attributes = MenuItemAttribute.all.load
@item_options = MenuItemOption.all.load
else
render :json => nil
end end
# @current_menu = Menu.current_menu # @current_menu = Menu.current_menu
end end

View File

@@ -2,8 +2,8 @@ class Api::Restaurant::ZonesController < Api::ApiController
def index def index
if (params[:filter] && params[:filter] = "all" ) if (params[:filter] && params[:filter] = "all" )
@all_tables = Table.active @all_tables = Table.includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).active
@all_rooms = Room.active @all_rooms = Room.includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).active
else else
@zones = Zone.includes([:tables, :rooms]).where("is_active = true") @zones = Zone.includes([:tables, :rooms]).where("is_active = true")
end end

View File

@@ -1,6 +1,7 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
include MultiTenancy include MultiTenancy
include LoginVerification include LoginVerification
include Customers
#before_action :check_installation #before_action :check_installation
protect_from_forgery with: :exception protect_from_forgery with: :exception

View File

@@ -1,6 +1,4 @@
class BaseCrmController < ActionController::Base class BaseCrmController < ActionController::Base
include MultiTenancy include MultiTenancy
include LoginVerification include LoginVerification
layout "CRM" layout "CRM"

View File

@@ -1,5 +1,4 @@
class BaseInventoryController < ActionController::Base class BaseInventoryController < ActionController::Base
include MultiTenancy include MultiTenancy
include LoginVerification include LoginVerification
layout "inventory" layout "inventory"

View File

@@ -1,8 +1,7 @@
class BaseOqsController < ActionController::Base class BaseOqsController < ActionController::Base
include MultiTenancy include MultiTenancy
include LoginVerification include LoginVerification
layout "OQS" layout "OQS"
before_action :check_user before_action :check_user

View File

@@ -1,7 +1,8 @@
class BaseOrigamiController < ActionController::Base class BaseOrigamiController < ActionController::Base
include MultiTenancy include MultiTenancy
include LoginVerification include LoginVerification
include Customers
layout "origami" layout "origami"
before_action :check_user before_action :check_user

View File

@@ -1,5 +1,4 @@
class BaseReportController < ActionController::Base class BaseReportController < ActionController::Base
include MultiTenancy include MultiTenancy
include LoginVerification include LoginVerification
layout "application" layout "application"
@@ -34,6 +33,7 @@ class BaseReportController < ActionController::Base
if params[:from].present? && params[:to].present? if params[:from].present? && params[:to].present?
from = Time.parse(params[:from]) from = Time.parse(params[:from])
to = Time.parse(params[:to]) to = Time.parse(params[:to])
else else
case period.to_i case period.to_i
when PERIOD["today"] when PERIOD["today"]

View File

@@ -1,5 +1,4 @@
class BaseWaiterController < ActionController::Base class BaseWaiterController < ActionController::Base
include MultiTenancy include MultiTenancy
include LoginVerification include LoginVerification
layout "waiter" layout "waiter"

View File

@@ -0,0 +1,18 @@
module Customers
extend ActiveSupport::Concern
included do
helper_method :walkin, :takeaway if respond_to? :helper_method
end
def walkin
return @walkin if defined? @walkin
@walkin = Customer.walkin
end
def takeaway
return @takeaway if defined? @takeaway
@takeaway = Customer.takeaway
end
end

View File

@@ -4,7 +4,6 @@ module MultiTenancy
included do included do
set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter
before_action :find_shop_by_subdomain_or_frist if respond_to? :before_action before_action :find_shop_by_subdomain_or_frist if respond_to? :before_action
helper_method :current_shop if respond_to? :helper_method
end end
private private

View File

@@ -8,7 +8,7 @@ module NumberFormattable
@precision = @number_formats.find? { |x| x.name.parameterize.underscore == 'precision'}.value.to_i rescue nil @precision = @number_formats.find? { |x| x.name.parameterize.underscore == 'precision'}.value.to_i rescue nil
end end
if @precision.nil? if @precision.nil?
@print_settings = PrintSetting.get_precision_delimiter if !defined? @number_formats @print_settings = PrintSetting.get_precision_delimiter if !defined? @print_settings
if @print_settings if @print_settings
@precision = @print_settings.precision.to_i @precision = @print_settings.precision.to_i
else else
@@ -24,7 +24,7 @@ module NumberFormattable
@delimiter = @number_formats.find { |f| f.name.parameterize.underscore == 'delimiter'}.value.gsub(/\\u(\h{4})/) { |m| [$1].pack("H*").unpack("n*").pack("U*") } rescue nil @delimiter = @number_formats.find { |f| f.name.parameterize.underscore == 'delimiter'}.value.gsub(/\\u(\h{4})/) { |m| [$1].pack("H*").unpack("n*").pack("U*") } rescue nil
end end
if @delimiter.nil? if @delimiter.nil?
@print_settings = PrintSetting.get_precision_delimiter if !defined? @number_formats @print_settings = PrintSetting.get_precision_delimiter if !defined? @print_settings
if @print_settings && @print_settings.delimiter if @print_settings && @print_settings.delimiter
@delimiter = "," @delimiter = ","
else else
@@ -42,10 +42,10 @@ module NumberFormattable
end end
def number_format(number, options = {}) def number_format(number, options = {})
options[:precision] = options[:precision] || precision options[:precision] = options[:precision] || precision
# options[:delimiter] = options[:delimiter] || delimiter # options[:delimiter] = options[:delimiter] || delimiter
options[:strip_insignificant_zeros] = options[:strip_insignificant_zeros] || strip_insignificant_zeros options[:strip_insignificant_zeros] = options[:strip_insignificant_zeros] || strip_insignificant_zeros
number = number.to_f.round(options[:precision]) number = number.to_f.round(options[:precision])
if options[:precision] > 0 if options[:precision] > 0

View File

@@ -83,8 +83,9 @@ class Crm::CustomersController < BaseCrmController
@membership_types = Lookup.collection_of("member_group_type") @membership_types = Lookup.collection_of("member_group_type")
# @taxes = TaxProfile.where(:group_type => 'cashier') # @taxes = TaxProfile.where(:group_type => 'cashier')
@taxes = TaxProfile.unscope(:order).select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name") @taxes = TaxProfile.unscope(:order).select("tax_profiles.id, CONCAT(tax_profiles.name, '(', lookups.name, ')') as name")
.order("group_type ASC,order_by ASC") .joins(:lookup)
.order("group_type ASC, order_by ASC")
@filter = filter @filter = filter
@@ -147,104 +148,101 @@ class Crm::CustomersController < BaseCrmController
def new def new
@crm_customer = Customer.new @crm_customer = Customer.new
@membership = Customer.get_member_group() @membership = Customer.get_member_group()
end end
# GET /crm/customers/1/edit # GET /crm/customers/1/edit
def edit def edit
@customer = Customer.find(params[:id]) @customer = Customer.find(params[:id])
end end
def sync def sync
@customer = Customer.find(params[:id]) @customer = Customer.find(params[:id])
respond_to do |format| respond_to do |format|
name = @customer.name name = @customer.name
phone = @customer.contact_no phone = @customer.contact_no
email = @customer.email email = @customer.email
dob = @customer.date_of_birth dob = @customer.date_of_birth
address = @customer.address address = @customer.address
nrc = @customer.nrc_no nrc = @customer.nrc_no
card_no = @customer.card_no card_no = @customer.card_no
paypar_account_no = @customer.paypar_account_no paypar_account_no = @customer.paypar_account_no
id = @crm_customer.membership_id id = @customer.membership_id
member_group_id = @customer.membership_type member_group_id = @customer.membership_type
if !id.present? && !member_group_id.nil? membership = MembershipSetting.find_by_membership_type("paypar_url")
membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("create_membership_customer")
memberaction = MembershipAction.find_by_membership_type("create_membership_customer") merchant_uid = memberaction.merchant_account_id.to_s
merchant_uid = memberaction.merchant_account_id.to_s auth_token = memberaction.auth_token.to_s
auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email,
dob: dob,address: address,nrc:nrc,card_no:card_no,
member_group_id: member_group_id,
id:id,
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
member_params = { name: name,phone: phone,email: email, # Check for paypar account exists
dob: dob,address: address,nrc:nrc,card_no:card_no, # if paypar_account_no != nil || paypar_account_no != ''
member_group_id: member_group_id, if paypar_account_no.present?
id:id, member_params = { name: name,phone: phone,email: email,
merchant_uid:merchant_uid,auth_token:auth_token}.to_json dob: dob,address: address,nrc:nrc,card_no:card_no,
paypar_account_no: paypar_account_no,
member_group_id: member_group_id,
id:id,
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
# Check for paypar account exists begin
# if paypar_account_no != nil || paypar_account_no != '' response = HTTParty.post(url,
if paypar_account_no.present? :body => member_params,
member_params = { name: name,phone: phone,email: email, :headers => {
dob: dob,address: address,nrc:nrc,card_no:card_no, 'Content-Type' => 'application/json',
paypar_account_no: paypar_account_no, 'Accept' => 'application/json; version=3'
member_group_id: member_group_id, },
id:id, :timeout => 10
merchant_uid:merchant_uid,auth_token:auth_token}.to_json )
end
begin rescue HTTParty::Error
response = HTTParty.post(url, response = {"status" => false, "message" => "No internet connection "}
:body => member_params,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
},
:timeout => 10
)
rescue HTTParty::Error rescue Net::OpenTimeout
response = {"status" => false, "message" => "No internet connection "} response = {"status" => false, "message" => "No internet connection "}
rescue Net::OpenTimeout rescue OpenURI::HTTPError
response = {"status" => false, "message" => "No internet connection "} response = {"status" => false, "message" => "No internet connection "}
rescue OpenURI::HTTPError rescue SocketError
response = {"status" => false, "message" => "No internet connection "} response = {"status" => false, "message" => "No internet connection "}
rescue SocketError
response = {"status" => false, "message" => "No internet connection "}
end
customer = Customer.find(@crm_customer.customer_id)
Rails.logger.debug "--------Sync Member response -------"
Rails.logger.debug response.to_json
if response["status"] == true
status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id )
format.html { redirect_to crm_customers_path }
flash[:member_notice] ='Member was successfully synced'
else
# Check membership id and bind to user
if response["membership_id"] != nil
status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id )
format.html { redirect_to crm_customers_path }
flash[:member_notice] ='Member was successfully synced'
else
status = customer.update_attributes(membership_type:member_group_id)
end
# When paypar account no not exist in paypar
if response["message"] == "Account does not exist."
customer.destroy
format.html { redirect_to crm_customers_path }
flash[:member_error] ='Member cannot created.Invalid Account.'
else
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
end
end end
customer = Customer.find(@crm_customer.customer_id)
Rails.logger.debug "--------Sync Member response -------"
Rails.logger.debug response.to_json
if response["status"] == true
status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id )
format.html { redirect_to crm_customers_path }
flash[:member_notice] ='Member was successfully synced'
else
# Check membership id and bind to user
if response["membership_id"] != nil
status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id )
format.html { redirect_to crm_customers_path }
flash[:member_notice] ='Member was successfully synced'
else
status = customer.update_attributes(membership_type:member_group_id)
end
# When paypar account no not exist in paypar
if response["message"] == "Account does not exist."
customer.destroy
format.html { redirect_to crm_customers_path }
flash[:member_error] ='Member cannot created.Invalid Account.'
else
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
format.html { redirect_to crm_customers_path }
flash[:member_error] =response["message"]
end
end
end
end end
# POST /crm/customers # POST /crm/customers
# POST /crm/customers.json # POST /crm/customers.json

View File

@@ -30,7 +30,7 @@ class Foodcourt::FoodCourtController < ApplicationController
else else
@display_type = nil @display_type = nil
end end
@quick_service_only = true @quick_service_only = true
lookup_dine_in = Lookup.collection_of('dinein_cashier') lookup_dine_in = Lookup.collection_of('dinein_cashier')
if !lookup_dine_in.empty? if !lookup_dine_in.empty?
@@ -47,7 +47,7 @@ class Foodcourt::FoodCourtController < ApplicationController
.joins("JOIN orders ON orders.order_id=booking_orders.order_id") .joins("JOIN orders ON orders.order_id=booking_orders.order_id")
.joins("JOIN order_items ON orders.order_id=order_items.order_id") .joins("JOIN order_items ON orders.order_id=order_items.order_id")
.joins("JOIN customers ON orders.customer_id=customers.customer_id") .joins("JOIN customers ON orders.customer_id=customers.customer_id")
.where("orders.source='app' and bookings.shop_code='#{@shop.shop_code}' and DATE(bookings.created_at) = '#{Date.today}' and bookings.booking_status='assign'").uniq.length .where("orders.source='app' and DATE(bookings.created_at) = '#{Date.today}' and bookings.booking_status='assign'").uniq.length
render "foodcourt/addorders/detail" render "foodcourt/addorders/detail"
end end

View File

@@ -71,7 +71,7 @@ class Foodcourt::OrdersController < BaseFoodcourtController
.joins("JOIN orders ON orders.order_id=booking_orders.order_id") .joins("JOIN orders ON orders.order_id=booking_orders.order_id")
.joins("JOIN order_items ON orders.order_id=order_items.order_id") .joins("JOIN order_items ON orders.order_id=order_items.order_id")
.joins("JOIN customers ON orders.customer_id=customers.customer_id") .joins("JOIN customers ON orders.customer_id=customers.customer_id")
.where("sales.sale_status !=? and orders.source='app' and bookings.shop_code=? and DATE(bookings.created_at)=?",'void',@shop.shop_code,Date.today).order("bookings.created_at desc").uniq .where("sales.sale_status !=? and orders.source='app' and DATE(bookings.created_at)=?",'void',@shop.shop_code,Date.today).order("bookings.created_at desc").uniq
end end
def completed def completed
customer =Customer.find_by_customer_id(params[:customer_id]) customer =Customer.find_by_customer_id(params[:customer_id])

View File

@@ -86,10 +86,10 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController
def destroy def destroy
inventory = InventoryDefinition.find_by_id_and_shop_code(params[:id],@shop.shop_code) inventory = InventoryDefinition.find_by_id_and_shop_code(params[:id],@shop.shop_code)
@inventory_definition.destroy @inventory_definition.destroy
# respond_to do |format| respond_to do |format|
# format.html { redirect_to inventory_inventory_definitions_url, notice: 'Inventory definition was successfully destroyed.' } format.html { redirect_to inventory_inventory_definitions_url, notice: 'Inventory definition was successfully destroyed.' }
# format.json { head :no_content } format.json { head :no_content }
# end end
# inventory = InventoryDefinition.find_by_id_and_shop_code(params[:id],@shop.shop_code) # inventory = InventoryDefinition.find_by_id_and_shop_code(params[:id],@shop.shop_code)
StockJournal.delete_stock_journal(inventory.item_code,@shop) StockJournal.delete_stock_journal(inventory.item_code,@shop)

View File

@@ -21,7 +21,7 @@ class Oqs::HomeController < BaseOqsController
zone_id = qid.zone_id zone_id = qid.zone_id
i=i+1 i=i+1
end end
end end
end end
@queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i }) @queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i })
end end
@@ -57,14 +57,6 @@ class Oqs::HomeController < BaseOqsController
end end
end end
# booking_id = dining.get_new_booking
# BookingOrder.where("booking_id='#{ booking_id }'").find_each do |bo|
# order=Order.find(bo.order_id);
# order.order_items.each do |oi|
# items.push(oi)
# end
# end
render :json => items.to_json render :json => items.to_json
end end
@@ -88,7 +80,7 @@ class Oqs::HomeController < BaseOqsController
end end
# Query for OQS with delivery status # Query for OQS with delivery status
def queue_items_query(status) def queue_items_query(status)
AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type as type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type as type, odt.order_id, 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 .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id
left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id

View File

@@ -6,10 +6,11 @@ class Origami::AddordersController < BaseOrigamiController
if check_mobile if check_mobile
@webview = true @webview = true
end end
@tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id")
@rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('zone_id asc').group("zone_id") @tables = Table.active.order('zone_id asc').group("zone_id")
@all_table = Table.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc') @rooms = Room.active.order('zone_id asc').group("zone_id")
@all_room = Room.all.where("shop_code='#{@shop.shop_code}'").active.order('status desc') @all_table = Table.active.order('status desc')
@all_room = Room.active.order('status desc')
end end
def detail def detail
@@ -33,10 +34,11 @@ class Origami::AddordersController < BaseOrigamiController
@booking = @table.get_booking @booking = @table.get_booking
if @booking if @booking
@booking_id = @booking.booking_id @booking_id = @booking.booking_id
@obj_order = @booking.orders.first if @obj_order = @booking.orders.first
@customer = @obj_order.customer @customer = @obj_order.customer
@date = @obj_order.created_at @date = @obj_order.created_at
@order_items = @booking.order_items @order_items = @booking.order_items
end
end end
end end
@@ -98,87 +100,85 @@ class Origami::AddordersController < BaseOrigamiController
items_arr = [] items_arr = []
JSON.parse(params[:order_items]).each { |i| JSON.parse(params[:order_items]).each { |i|
i["item_instance_code"] = i["item_instance_code"].downcase.to_s i["item_instance_code"] = i["item_instance_code"].downcase.to_s
if i["item_instance_code"].include? "ext" if i["item_instance_code"].include? "ext"
is_extra_time = true is_extra_time = true
arr_exts = i["item_instance_code"].split("_") arr_exts = i["item_instance_code"].split("_")
if arr_exts[1].match(/^(\d)+$/) if arr_exts[1].match(/^(\d)+$/)
time = arr_exts[1].to_i*60*i["quantity"].to_i time = arr_exts[1].to_i*60*i["quantity"].to_i
extra_time = Time.at(time) extra_time = Time.at(time)
end end
end end
if i["parent_order_item_id"]; if i["parent_order_item_id"]
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])} items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])}
else else
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])} items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])}
end end
items_arr.push(items) items_arr.push(items)
} }
# begin # begin
if params[:order_source] == "quick_service" && params[:table_id].to_i == 0 if params[:order_source] == "quick_service" && params[:table_id].to_i == 0
customer_id = "CUS-000000000002" # for no customer id from mobile customer_id = takeaway.customer_id # for no customer id from mobile
else else
customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
end end
@order = Order.new Order.transaction do
@order.source = params[:order_source] @order = Order.new
@order.order_type = params[:order_type] @order.source = params[:order_source]
@order.customer_id = customer_id @order.order_type = params[:order_type]
@order.items = items_arr @order.customer_id = customer_id
@order.guest = params[:guest_info] @order.items = items_arr
@order.table_id = params[:table_id] # this is dining facilities's id @order.guest = params[:guest_info]
@order.new_booking = true @order.table_id = params[:table_id] # this is dining facilities's id
@order.waiters = current_login_employee.name
@order.employee_name = current_login_employee.name
@order.shop_code = @shop.shop_code
@order.is_extra_time = is_extra_time
@order.extra_time = extra_time
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
@order.new_booking = true @order.new_booking = true
else @order.waiters = current_login_employee.name
@order.new_booking = false @order.employee_name = current_login_employee.name
@order.booking_id = booking.booking_id
end
@status, @booking = @order.generate @order.is_extra_time = is_extra_time
@order.extra_time = extra_time
if @status && @booking
#send order broadcast to order_channel
if @order.table_id.to_i > 0
table = DiningFacility.find(@booking.dining_facility_id)
type = 'order'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
if booking.nil? || booking.sale_id.present? || booking.booking_status == 'moved'
@order.new_booking = true
else
@order.new_booking = false
@order.booking_id = booking.booking_id
end end
if params[:order_source] != "quick_service" && params[:order_source] != "food_court" @status, @booking = @order.generate
process_order_queue(@order.order_id,@order.table_id,@order.source)
end
end
if @status && @booking
#send order broadcast to order_channel
if @order.table_id.to_i > 0
table = DiningFacility.find(@booking.dining_facility_id)
type = 'order'
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel", table: table,type:type,from:from
end
if params[:order_source] != "quick_service" && params[:order_source] != "food_court"
process_order_queue(@order.order_id,@order.table_id,@order.source)
end
end
# Order.send_customer_view(@booking) # Order.send_customer_view(@booking)
if current_user.role != "waiter" && params[:create_type] == "create_pay" if current_user.role != "waiter" && params[:create_type] == "create_pay"
if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court') if @status && @booking && (@order.source == 'quick_service') || (@order.source == 'food_court')
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee) @status, @sale = Sale.request_bill(@order,current_user,current_login_employee)
# for second display # for second display
if @order.source == 'quick_service' if @order.source == 'quick_service'
from = getCloudDomain #get sub domain in cloud mode from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from ActionCable.server.broadcast "second_display_channel",data: @sale,status:"sale",from:from
end
#end
result = {:status=> @status, :data => @sale }
render :json => result.to_json
end end
#end else
result = {:status=> @status, :data => @sale } result = {:status=> @status, :data => 0 }
render :json => result.to_json render :json => result.to_json
end end
else
result = {:status=> @status, :data => 0 }
render :json => result.to_json
end end
end end
# render json for http status code # render json for http status code
@@ -220,66 +220,29 @@ class Origami::AddordersController < BaseOrigamiController
end end
end end
def process_order_queue(order_id,table_id,order_source) def process_order_queue(order_id, table_id, order_source)
print_status = nil #Send to background job for processing
cup_status = nil order = Order.find(order_id)
#Send to background job for processing sidekiq = Lookup.find_by_lookup_type("sidekiq")
order = Order.find(order_id)
sidekiq = Lookup.find_by_lookup_type_and_shop_code("sidekiq",@shop.shop_code) if ENV["SERVER_MODE"] != 'cloud'
if ENV["SERVER_MODE"] != 'cloud' if Printer::PrinterWorker.printers.blank?
cup_status = `#{"sudo service cups status"}` msg = 'Print Error ! Please contact to service'
print_status = check_cup_status(cup_status) ActionCable.server.broadcast "call_waiter_channel", table: msg, time:'print_error', from: ''
end end
end
if print_status if !sidekiq.nil?
if !sidekiq.nil? OrderQueueProcessorJob.perform_later(order_id, table_id)
OrderQueueProcessorJob.perform_later(order_id, table_id) else
else if order
if order oqs = OrderQueueStation.new
oqs = OrderQueueStation.new oqs.process_order(order, table_id, order_source)
oqs.process_order(order, table_id, order_source)
end
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
else
if ENV["SERVER_MODE"] != 'cloud'
cup_start = `#{"sudo service cups start"}`
cup_status = `#{"sudo service cups status"}`
print_status = check_cup_status(cup_status)
end
if print_status
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(order_id, table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, order_source)
end
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
else
if ENV["SERVER_MODE"] != 'cloud'
from = ""
msg = ' Print Error ! Please contact to service'
ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error',from:from
end
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(order_id, table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, order_source)
end
from = getCloudDomain #get sub domain in cloud mode
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
end
end
end end
from = getCloudDomain #get sub domain in cloud mode
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
ActionCable.server.broadcast "order_queue_station_channel", order: assign_order, from: from
end
end end
def check_cup_status(status) def check_cup_status(status)

View File

@@ -55,7 +55,7 @@ class Origami::CustomersController < BaseOrigamiController
@cashier_type = params[:type] @cashier_type = params[:type]
@page = params[:dir_page] @page = params[:dir_page]
if(@sale_id[0,3] == "SAL") if @sale_id.include? "SAL"
@booking = Booking.find_by_sale_id(@sale_id) @booking = Booking.find_by_sale_id(@sale_id)
if @booking.dining_facility_id.to_i > 0 if @booking.dining_facility_id.to_i > 0
@dining_facility = DiningFacility.find(@booking.dining_facility_id) @dining_facility = DiningFacility.find(@booking.dining_facility_id)
@@ -117,7 +117,7 @@ class Origami::CustomersController < BaseOrigamiController
def update_sale_by_customer def update_sale_by_customer
id = params[:sale_id][0,3] id = params[:sale_id]
customer_id = params[:customer_id] customer_id = params[:customer_id]
customer = Customer.find(customer_id) customer = Customer.find(customer_id)
order_source = params[:type] order_source = params[:type]
@@ -129,7 +129,7 @@ class Origami::CustomersController < BaseOrigamiController
# end # end
# end # end
if(id == "SAL") if id.include? "SAL"
sale = Sale.find(params[:sale_id]) sale = Sale.find(params[:sale_id])
status = sale.update_attributes(customer_id: customer_id) status = sale.update_attributes(customer_id: customer_id)
sale.sale_orders.each do |sale_order| sale.sale_orders.each do |sale_order|
@@ -153,7 +153,7 @@ class Origami::CustomersController < BaseOrigamiController
if status == true if status == true
render json: JSON.generate({:status => true}) render json: JSON.generate({:status => true})
if(id == "SAL") if id.include? "SAL"
sale.compute_by_sale_items(sale.total_discount, nil, order_source) sale.compute_by_sale_items(sale.total_discount, nil, order_source)
end end
else else

View File

@@ -104,9 +104,7 @@ class Origami::DashboardController < BaseOrigamiController
end end
def get_all_menu def get_all_menu
@menus = Menu.includes(:menu_categories => [:children, :menu_items => [:menu_item_instances => :menu_instance_item_sets, :item_sets => :menu_item_instances]]).active.all
@menus = Menu.includes(:menu_categories => :children).includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).includes(:menu_categories => {:menu_items => {:item_sets => :menu_item_instances}}).active.shop
@item_attributes = MenuItemAttribute.all.load @item_attributes = MenuItemAttribute.all.load
@item_options = MenuItemOption.all.load @item_options = MenuItemOption.all.load
end end

View File

@@ -22,7 +22,6 @@ class Origami::FoodCourtController < ApplicationController
@tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') @tables = Table.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc') @rooms = Room.all.active.where("shop_code='#{@shop.shop_code}'").order('status desc')
@cashier_type = "food_court" @cashier_type = "food_court"
display_type = Lookup.find_by_lookup_type("display_type") display_type = Lookup.find_by_lookup_type("display_type")
if !display_type.nil? && display_type.value.to_i ==2 if !display_type.nil? && display_type.value.to_i ==2
@display_type = display_type.value @display_type = display_type.value
@@ -57,7 +56,7 @@ class Origami::FoodCourtController < ApplicationController
# @menus = Menu.all # @menus = Menu.all
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
# end # end
if(params[:id][0,3] == "BKI") if params[:id].include? "BKI"
@table_id = nil @table_id = nil
@table = nil @table = nil
@booking = Booking.find(params[:id]) @booking = Booking.find(params[:id])
@@ -114,7 +113,7 @@ class Origami::FoodCourtController < ApplicationController
order = Order.new order = Order.new
order.source = params[:order_source] order.source = params[:order_source]
order.order_type = params[:order_type] order.order_type = params[:order_type]
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
order.items = items_arr order.items = items_arr
order.guest = params[:guest_info] order.guest = params[:guest_info]
order.table_id = params[:table_id] # this is dining facilities's id order.table_id = params[:table_id] # this is dining facilities's id

View File

@@ -4,10 +4,8 @@ class Origami::HomeController < BaseOrigamiController
def index def index
@webview = check_mobile @webview = check_mobile
@tables = Table.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).active.order('status desc')
@rooms = Room.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).active.order('status desc')
@tables = Table.unscope(:order).includes(:zone).shop.active.order('status desc')
@rooms = Room.unscope(:order).includes(:zone).shop.active.order('status desc')
@complete = Sale.completed_sale("cashier") @complete = Sale.completed_sale("cashier")
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@@ -23,9 +21,8 @@ class Origami::HomeController < BaseOrigamiController
@print_settings = PrintSetting.get_precision_delimiter() @print_settings = PrintSetting.get_precision_delimiter()
@webview = check_mobile @webview = check_mobile
@tables = Table.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).all.active.order('status desc')
@tables = Table.unscope(:order).includes(:zone).shop.active.order('status desc') @rooms = Room.unscope(:order).includes(:zone, :current_checkin_booking, :current_checkout_booking, :current_reserved_booking).all.active.order('status desc')
@rooms = Room.unscope(:order).includes(:zone).shop.active.order('status desc')
@complete = Sale.completed_sale("cashier") @complete = Sale.completed_sale("cashier")
@orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc')
@@ -36,77 +33,44 @@ class Origami::HomeController < BaseOrigamiController
@status_sale = "" @status_sale = ""
@sale_array = Array.new @sale_array = Array.new
@membership = MembershipSetting.find_by_shop_code(@shop.shop_code) @shop = shop_detail
@payment_methods = PaymentMethodSetting.where("shop_code='#{@shop.shop_code}'") @membership = MembershipSetting::MembershipSetting
@dining_booking = @dining.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ") @payment_methods = PaymentMethodSetting.all
#@dining_booking = @dining.bookings.active.where("created_at between '#{DateTime.now.utc - 12.hours}' and '#{DateTime.now.utc}'") @dining_booking = @dining.current_bookings
@order_items = Array.new
@order_items = Array.new
@dining_booking.each do |booking| @dining_booking.each do |booking|
if booking.sale_id.nil? && booking.booking_status != 'moved' if @obj_sale || @booking.blank?
@order_items = Array.new @booking = booking
# @assigned_order_items = Array.new end
if booking.booking_orders.empty?
@booking = booking if booking.sale_id
else @obj_sale = booking.sale
booking.booking_orders.each do |booking_order| @sale_array.push(@obj_sale)
order = Order.find(booking_order.order_id) @sale_taxes = @obj_sale.sale_taxes
if (order.status == "new") @status_sale = 'sale'
@obj_order = order else
@customer = order.customer @order_items += booking.order_items
@date = order.created_at @obj_order = booking.orders.first
@booking= booking end
order.order_items.each do |item|
@order_items.push(item) if @obj_sale || @customer.blank?
# assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id) if obj = @obj_sale || @obj_order
# if !assigned_order_items.nil? @customer = obj.customer
# @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id}) @date = obj.created_at
# end
end
@account_arr = Array.new
if @customer.tax_profiles
accounts = @customer.tax_profiles
@account_arr =[]
accounts.each do |acc|
account = TaxProfile.find_by_id(acc)
if !account.nil?
@account_arr.push(account)
end
end
end
end
end
end
@status_order = 'order'
else
sale = Sale.find(booking.sale_id)
if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != 'spoile' && sale.sale_status != 'waste'
@sale_array.push(sale)
if @status_order == 'order'
@status_order = 'sale'
end
@booking= booking
@date = sale.created_at
@status_sale = 'sale'
@obj_sale = sale
@customer = sale.customer
accounts = @customer.tax_profiles
@account_arr =[]
accounts.each do |acc|
account = TaxProfile.find_by_id(acc)
if !account.nil?
@account_arr.push(account)
end
end
end
@sale_taxes = []
sale_taxes = SaleTax.where("sale_id = ?", sale.sale_id)
if !sale_taxes.empty?
sale_taxes.each do |sale_tax|
@sale_taxes.push(sale_tax)
end
end
end end
end end
if @obj_sale
@status_order = 'sale'
else
@status_order = 'order'
end
if (@obj_sale || @account_arr.blank?) && @customer
@account_arr = TaxProfile.find_by(id: @customer.tax_profiles)
end
end
#for bank integration #for bank integration
@checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time') @checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time')

View File

@@ -1,9 +1,8 @@
class Origami::HomeController < ApplicationController class Origami::HomeController < ApplicationController
def index def index
if params[:booking_id] != nil if params[:booking_id] != nil
type=params[:booking_id].split('-')[0];
# Sale # Sale
if type == "SAL" if params[:booking_id].include? "SAL"
@selected_item = Sale.find(params[:booking_id]) @selected_item = Sale.find(params[:booking_id])
@selected_item_type="Sale" @selected_item_type="Sale"
# Booking # Booking
@@ -25,9 +24,8 @@ class Origami::HomeController < ApplicationController
def selection(selected_id, is_ajax) def selection(selected_id, is_ajax)
str = [] str = []
type=selected_id.split('-')[0];
# Sale # Sale
if type == "SAL" if selected_id.include? "SAL"
@order_details = SaleItem.get_order_items_details(params[:booking_id]) @order_details = SaleItem.get_order_items_details(params[:booking_id])
@order_details.each do |ord_detail| @order_details.each do |ord_detail|
str.push(ord_detail) str.push(ord_detail)
@@ -48,9 +46,7 @@ class Origami::HomeController < ApplicationController
end end
def update_sale_by_customer def update_sale_by_customer
if id.inlude? "SAL"
id = params[:sale_id][0,3]
if(id == "SAL")
sale = Sale.find(params[:sale_id]) sale = Sale.find(params[:sale_id])
else else
sale = Order.find(params[:sale_id]) sale = Order.find(params[:sale_id])

View File

@@ -10,121 +10,73 @@ class Origami::PaymentsController < BaseOrigamiController
member_info = nil member_info = nil
# For Cashier by Zone # For Cashier by Zone
booking = Booking.find_by_sale_id(sale_id) booking = sale_data.booking
# if bookings.count > 1
# # for Multiple Booking if current_user.role == 'cashier'
# table = DiningFacility.find(bookings[0].dining_facility_id) cashier_terminal = current_user.cashier_terminal
# else elsif booking.dining_facility
# table = DiningFacility.find(bookings[0].dining_facility_id) cashier_terminal = booking.cashier_terminal_by_dining_facility
# end end
shift = ShiftSale.current_open_shift(current_user)
if !shift.nil? cashier_terminal ||= sale_data.cashier_terminal_by_shift_sale
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else customer = sale_data.customer
if booking.dining_facility_id.to_i > 0
table = DiningFacility.find(booking.dining_facility_id) #record for sale audit
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) action_by = current_user.name
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id) type = "FIRST_BILL"
else
shift = ShiftSale.find(sale_data.shift_sale_id) remark = "#{action_by} print out first bill for Receipt No #{sale_data.receipt_no}"
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type )
# get member information
rebate = MembershipSetting.find_by_rebate(1)
if customer.membership_id != nil && rebate
# member_info = Customer.get_member_account(customer)
# current_balance = SaleAudit.paymal_search(sale_id)
current_balance = 0
end
# find order id by sale id
# sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
# Calculate price_by_accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items)
other_amount = SaleItem.calculate_other_charges(sale_items)
print_settings = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first
printer = Printer::ReceiptPrinter.new(print_settings)
#TODO :: KBZPAY ( QR )
# On/Off setting ( show or not qr )
# qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD"
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
status = false
qr = nil
if !kbz_pay_method.nil?
if kbz_pay_method.is_active == true
sale_payment = SalePayment.new
sale_payment.process_kbz_payment(sale_id, sale_data.grand_total, 0, 'pending')
status, qr = KbzPay.pay(sale_data.grand_total.to_i, sale_payment.sale_payment_id, kbz_pay_method.gateway_url, kbz_pay_method.auth_token, kbz_pay_method.merchant_account_id, kbz_pay_method.additional_parameters)
end end
end end
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount,nil,nil,nil)
receipt_bill_a5_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
# Print for First Bill to Customer
unique_code = "ReceiptBillPdf"
print_settings = PrintSetting.all
if !print_settings.nil?
print_settings.each do |setting|
if setting.unique_code == 'ReceiptBillPdf'
unique_code = "ReceiptBillPdf"
elsif setting.unique_code == 'ReceiptBillStarPdf'
unique_code = "ReceiptBillStarPdf"
end
end
end
if !receipt_bill_a5_pdf.empty? result = {
receipt_bill_a5_pdf.each do |receipt_bilA5| :filepath => filename,
if receipt_bilA5[0] == 'ReceiptBillA5Pdf' :printer_model => print_settings.brand_name,
if receipt_bilA5[1] == '1' :printer_url => print_settings.api_settings
unique_code = "ReceiptBillA5Pdf" }
else
unique_code = unique_code#{}"ReceiptBillPdf"
end
end
end
end
#shop detail # status, qr = KbzPay.query(sale_payment.sale_payment_id)
## shop_detail = @shop
# customer= Customer.where('customer_id=' +.customer_id)
customer = Customer.find(sale_data.customer_id)
# rounding adjustment
if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
rounding_adj = new_total - sale_data.grand_total
sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
end
#end rounding adjustment
#record for sale audit
action_by = current_user.name
type = "FIRST_BILL"
remark = "#{action_by} print out first bill for Receipt No #{sale_data.receipt_no}" # Mobile Print
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type ) render :json => result.to_json
# get member information
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code)
if customer.membership_id != nil && rebate
# member_info = Customer.get_member_account(customer)
# current_balance = SaleAudit.paymal_search(sale_id)
current_balance = 0
end
# get printer info
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
# find order id by sale id
# sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
# Calculate price_by_accounts
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items)
other_amount = SaleItem.calculate_other_charges(sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
#TODO :: KBZPAY ( QR )
# On/Off setting ( show or not qr )
# qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD"
kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY,:shop_code => @shop.shop_code).last
status = false
qr = nil
if !kbz_pay_method.nil?
if kbz_pay_method.is_active == true
sale_payment = SalePayment.new
sale_payment.process_kbz_payment(sale_id, sale_data.grand_total, 0, 'pending')
status, qr = KbzPay.pay(sale_data.grand_total.to_i, sale_payment.sale_payment_id, kbz_pay_method.gateway_url, kbz_pay_method.auth_token, kbz_pay_method.merchant_account_id, kbz_pay_method.additional_parameters)
end
end
filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, @shop, "Frt",current_balance,nil,other_amount,nil,nil,nil,nil)
result = {
:filepath => filename,
:printer_model => print_settings.brand_name,
:printer_url => print_settings.api_settings
}
# status, qr = KbzPay.query(sale_payment.sale_payment_id)
# Mobile Print
render :json => result.to_json
# end # end
end end
@@ -138,25 +90,9 @@ class Origami::PaymentsController < BaseOrigamiController
latest_order_no = nil latest_order_no = nil
is_kbz = params[:is_kbz] is_kbz = params[:is_kbz]
if(Sale.exists?(sale_id)) if saleObj = Sale.find(sale_id)
saleObj = Sale.find(sale_id)
sale_items = SaleItem.get_all_sale_items(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id)
#shop_detail = @shop
# rounding adjustment
if !path.include? ("credit_payment")
if @shop.is_rounding_adj
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
rounding_adj = new_total - saleObj.grand_total
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
end
end
#end rounding adjustment
# if pay_from = 'kbzpay'
# salePayment = SalePayment.find(sale_payment_id)
# salePayment.process_kbz_payment(salePayment.sale_id, sale_data.grand_total, cash, 'paid')
# else
sp = SalePayment.where('sale_id=? and payment_method=? and payment_status=?', sale_id, 'kbzpay', 'paid').last
if is_kbz == 'false' if is_kbz == 'false'
Rails.logger.info '################ CASH PAYMENT #################' Rails.logger.info '################ CASH PAYMENT #################'
sale_payment = SalePayment.new sale_payment = SalePayment.new
@@ -166,134 +102,110 @@ class Origami::PaymentsController < BaseOrigamiController
sale_payment.process_payment(saleObj, current_user, cash, "cash") sale_payment.process_payment(saleObj, current_user, cash, "cash")
end end
else else
sp = SalePayment.where('sale_id=? and payment_method=? and payment_status=?', sale_id, 'kbzpay', 'paid').last
sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user) sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user)
end end
# end
if !path.include? ("credit_payment") if !path.include? ("credit_payment")
rebate_amount = nil rebate_amount = nil
# For Cashier by Zone # For Cashier by Zone
# bookings = Booking.where("sale_id='#{sale_id}'") # bookings = Booking.where("sale_id='#{sale_id}'")
bookings = saleObj.bookings[0] booking = saleObj.booking
shift = ShiftSale.current_open_shift(current_user) if current_user.role == 'cashier'
if !shift.nil? cashier_terminal = current_user.cashier_terminal
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) elsif booking.dining_facility
else cashier_terminal = booking.cashier_terminal_by_dining_facility
if bookings.dining_facility_id.to_i > 0 end
table = bookings.dining_facility
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
type = 'payment' cashier_terminal ||= saleObj.cashier_terminal_by_shift_sale
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from if booking.dining_facility
else ActionCable.server.broadcast(
shift = ShiftSale.find(saleObj.shift_sale_id) "order_channel",
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) table: booking.dining_facility,
end type: 'payment',
from: getCloudDomain
)
end end
# For Print # For Print
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
receipt_bill_a5_pdf = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf
unique_code = "ReceiptBillPdf" unique_code = "ReceiptBillA5Pdf"
print_settings = PrintSetting.all else
if !print_settings.nil? unique_code = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code
print_settings.each do |setting| end
if setting.unique_code == 'ReceiptBillPdf'
unique_code = "ReceiptBillPdf" customer = saleObj.customer
elsif setting.unique_code == 'ReceiptBillStarPdf'
unique_code = "ReceiptBillStarPdf" # get member information
end rebate = MembershipSetting.find_by_rebate(1)
end credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote')
if customer.membership_id != nil && rebate && credit_data.nil?
member_info = Customer.get_member_account(customer)
if member_info["status"] == true
rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
current_balance = SaleAudit.paymal_search(sale_id)
end
end
#orders print out
if type == "quick_service"
if booking.dining_facility_id.present?
table_id = booking.dining_facility_id
else
table_id = 0
end end
if !receipt_bill_a5_pdf.empty? latest_order = booking.booking_orders.order("order_id DESC").limit(1).first()
receipt_bill_a5_pdf.each do |receipt_bilA5| if !latest_order.nil?
if receipt_bilA5[0] == 'ReceiptBillA5Pdf' latest_order_no = latest_order.order_id
if receipt_bilA5[1] == '1'
unique_code = "ReceiptBillA5Pdf"
# else
end
end
end
end end
customer= Customer.find(saleObj.customer_id) booking.booking_orders.each do |order|
# Order.pay_process_order_queue(order.order_id, table_id)
oqs = OrderQueueStation.new
oqs.pay_process_order_queue(order.order_id, table_id)
# get member information assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id)
rebate = MembershipSetting.find_by_rebate_and_shop_code(1,@shop.shop_code) from = getCloudDomain #get sub domain in cloud mode
credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote') ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
if customer.membership_id != nil && rebate && credit_data.nil?
member_info = Customer.get_member_account(customer)
if member_info["status"] == true
rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
current_balance = SaleAudit.paymal_search(sale_id)
end
end end
#orders print out end
if type == "quick_service"
booking = Booking.find_by_sale_id(sale_id)
if booking.dining_facility_id.to_i>0
table_id = booking.dining_facility_id
else
table_id = 0
end
latest_order = booking.booking_orders.order("order_id DESC").limit(1).first()
if !latest_order.nil?
latest_order_no = latest_order.order_id
end
booking.booking_orders.each do |order|
# Order.pay_process_order_queue(order.order_id, table_id)
oqs = OrderQueueStation.new
oqs.pay_process_order_queue(order.order_id, table_id)
assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id)
from = getCloudDomain #get sub domain in cloud mode
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
end
#for card sale data
card_data = Array.new
card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id)
if !card_sale_trans_ref_no.nil?
card_sale_trans_ref_no.each do |cash_sale_trans|
card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s
card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s
card_no = cash_sale_trans.pan.last(4)
card_no = card_no.rjust(19,"**** **** **** ")
card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id})
end end
end
#for card sale data #card_balance amount for Paymal payment
card_data = Array.new card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id)
card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id)
if !card_sale_trans_ref_no.nil?
card_sale_trans_ref_no.each do |cash_sale_trans|
card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s
card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s
card_no = cash_sale_trans.pan.last(4)
card_no = card_no.rjust(19,"**** **** **** ")
card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id})
end
end
#card_balance amount for Paymal payment # get printer info
card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) print_settings = PrintSetting.find_by_unique_code(unique_code)
# Calculate Food and Beverage Total
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
other_amount = SaleItem.calculate_other_charges(sale_items)
# get printer info printer = Printer::ReceiptPrinter.new(print_settings)
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
# Calculate Food and Beverage Total
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
other_amount = SaleItem.calculate_other_charges(sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref)
#end #end
end end
logger.debug 'saleObj++++++++++++++++++++++++++'
logger.debug saleObj.to_json
if !saleObj.nil? if !saleObj.nil?
# InventoryJob.perform_now(self.id) # InventoryJob.perform_now(self.id)
# InventoryDefinition.calculate_product_count(saleObj) # InventoryDefinition.calculate_product_count(saleObj)
@@ -330,7 +242,7 @@ class Origami::PaymentsController < BaseOrigamiController
end end
if path.include? ("credit_payment") if path.include? ("credit_payment")
@sale_payment = SalePayment.get_credit_amount_due_left(sale_id) @sale_payment = SalePayment.where(sale_id: sale_id, payment_method: 'creditnote').select("SUM(payment_amount) as payment_amount")
end end
@member_discount = MembershipSetting.find_by_discount_and_shop_code(1,@shop.shop_code) @member_discount = MembershipSetting.find_by_discount_and_shop_code(1,@shop.shop_code)
@@ -381,7 +293,7 @@ class Origami::PaymentsController < BaseOrigamiController
# @shop = shop_detail #show shop info # @shop = shop_detail #show shop info
@customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'") @customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"])
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
@@ -636,11 +548,14 @@ class Origami::PaymentsController < BaseOrigamiController
current_balance = nil current_balance = nil
order_source = params[:type] order_source = params[:type]
if(Sale.exists?(sale_id)) if Sale.exists?(sale_id)
saleObj = Sale.find(sale_id) saleObj = Sale.find(sale_id)
#calculate cash acmount #calculate cash acmount
cash = saleObj.total_amount cash = saleObj.total_amount
sale_payment = SalePayment.new
sale_payment.process_payment(saleObj, current_user, cash, "foc" ,remark)
if saleObj.discount_type == "member_discount" if saleObj.discount_type == "member_discount"
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0) saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
saleObj.compute_by_sale_items(0, nil, order_source) saleObj.compute_by_sale_items(0, nil, order_source)
@@ -648,9 +563,6 @@ class Origami::PaymentsController < BaseOrigamiController
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0) saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
sale_payment = SalePayment.new
sale_payment.process_payment(saleObj, current_user, cash, "foc" ,remark)
bookings = Booking.where("sale_id='#{sale_id}'") bookings = Booking.where("sale_id='#{sale_id}'")
if bookings[0].dining_facility_id.to_i > 0 if bookings[0].dining_facility_id.to_i > 0
table = DiningFacility.find(bookings[0].dining_facility_id) table = DiningFacility.find(bookings[0].dining_facility_id)
@@ -659,8 +571,6 @@ class Origami::PaymentsController < BaseOrigamiController
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
end end
# For Cashier by Zone # For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'") bookings = Booking.where("sale_id='#{sale_id}'")
@@ -795,7 +705,7 @@ class Origami::PaymentsController < BaseOrigamiController
end end
end end
# get printer info # get printer info
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code) print_settings = PrintSetting.find_by_unique_code(unique_code)
printer = Printer::ReceiptPrinter.new(print_settings) printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name) printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name)
@@ -817,8 +727,10 @@ class Origami::PaymentsController < BaseOrigamiController
sale_id = params[:sale_id] sale_id = params[:sale_id]
order_source = params[:cashier_type] order_source = params[:cashier_type]
tax_type = params[:tax_type] tax_type = params[:tax_type]
remark = "Change tax to #{tax_type.upcase} for Sale ID #{sale_id} By #{current_login_employee.name}"
sale = Sale.find(sale_id) sale = Sale.find(sale_id)
sale.compute_by_sale_items(sale.total_discount, nil, order_source, tax_type) sale.compute_by_sale_items(sale.total_discount, nil, order_source, tax_type)
SaleAudit.record_audit_change_tax(sale_id,remark,current_login_employee.name)
render json: JSON.generate({:status => true}) render json: JSON.generate({:status => true})
end end

View File

@@ -14,7 +14,7 @@ class Origami::PendingOrderController < BaseOrigamiController
def show def show
id = params[:sale_id] id = params[:sale_id]
if id.start_with?("SAL") if id.include? "SAL"
@sale = Sale.find(id) @sale = Sale.find(id)
if @sale.sale_status == "new" if @sale.sale_status == "new"
@bookings = @sale.bookings.first @bookings = @sale.bookings.first
@@ -22,7 +22,7 @@ class Origami::PendingOrderController < BaseOrigamiController
else else
redirect_to "/origami/#{params[:type]}" and return redirect_to "/origami/#{params[:type]}" and return
end end
elsif (id.start_with?("BKI") || id.start_with?("CBKI")) elsif id.include? "BKI"
@bookings = Booking.find(id) @bookings = Booking.find(id)
@order = @bookings.orders.where(status: "new").first @order = @bookings.orders.where(status: "new").first
@order_items = @bookings.order_items @order_items = @bookings.order_items

View File

@@ -10,24 +10,27 @@ class Origami::QuickServiceController < ApplicationController
def index def index
today = DateTime.now today = DateTime.now
day = Date.today.wday day = Date.today.wday
# if params[:menu] == "true"
@menus = [] @menus = []
@menu = [] @menu = []
@zone = Zone.all @zone = Zone.all
@customer = Customer.all @customer = Customer.all
@tables = Table.all.active.order('status desc') @tables = Table.active.order('status desc')
@rooms = Room.all.active.order('status desc') @rooms = Room.active.order('status desc')
@cashier_type = "quick_service" @cashier_type = "quick_service"
display_type = Lookup.find_by_lookup_type("display_type") display_type = Lookup.find_by_lookup_type("display_type")
if !display_type.nil? && display_type.value.to_i ==2 if !display_type.nil? && display_type.value.to_i == 2
@display_type = display_type.value @display_type = display_type.value
else else
@display_type = nil @display_type = nil
end end
#checked quick_service only #checked quick_service only
@quick_service_only = false @quick_service_only = Lookup.collection_of('quickservice_add_order').any? { |x| x == ["quickserviceaddorder", "1"] }
lookup_dine_in = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('quickservice_add_order')
lookup_dine_in = Lookup.collection_of('quickservice_add_order')
# puts 'lookup_dine_in!!!!'
# puts lookup_dine_in
if !lookup_dine_in.empty? if !lookup_dine_in.empty?
lookup_dine_in.each do |dine_in| lookup_dine_in.each do |dine_in|
if dine_in[0].downcase == "quickserviceaddorder" if dine_in[0].downcase == "quickserviceaddorder"
@@ -37,7 +40,23 @@ class Origami::QuickServiceController < ApplicationController
end end
end end
end end
divided_value =0
exclusive =0
tax_profiles = TaxProfile.where(group_type: "quick_service")
if !tax_profiles.empty?
tax_profiles.each do |tax|
#include or execulive
if tax.inclusive
tax_incl_exec = "inclusive"
rate = tax.rate
divided_value += (100 + rate)/rate
else
exclusive +=tax.rate / 100
end
end
end
@inclusive_tax =divided_value
@exclusive_tax =exclusive
render "origami/addorders/detail" render "origami/addorders/detail"
end end
@@ -52,7 +71,7 @@ class Origami::QuickServiceController < ApplicationController
# @menus = Menu.all # @menus = Menu.all
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
# end # end
if(params[:id][0,3] == "BKI") if params[:id].include? "BKI"
@table_id = nil @table_id = nil
@table = nil @table = nil
@booking = Booking.find(params[:id]) @booking = Booking.find(params[:id])
@@ -109,7 +128,7 @@ class Origami::QuickServiceController < ApplicationController
order = Order.new order = Order.new
order.source = params[:order_source] order.source = params[:order_source]
order.order_type = params[:order_type] order.order_type = params[:order_type]
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile
order.items = items_arr order.items = items_arr
order.guest = params[:guest_info] order.guest = params[:guest_info]
order.table_id = params[:table_id] # this is dining facilities's id order.table_id = params[:table_id] # this is dining facilities's id

View File

@@ -18,96 +18,78 @@ class Origami::RequestBillsController < ApplicationController
else else
table = DiningFacility.find_by(id: booking.dining_facility_id) table = DiningFacility.find_by(id: booking.dining_facility_id)
if sale_data = booking.sale if booking.sale_id.nil?
@status = true if sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source, params[:current_checkin_induties_count])
elsif sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source, params[:current_checkin_induties_count]) # in-duty update
@status = true in_duties = InDuty.where("booking_id=?", booking.id)
# in-duty update if !in_duties.empty?
in_duties = InDuty.where("booking_id=?", booking.id) in_duties.each do |in_duty|
if !in_duties.empty? induty = InDuty.find(in_duty.id)
in_duties.each do |in_duty| induty.sale_id = sale_data.sale_id
induty = InDuty.find(in_duty.id) induty.out_time = Time.now.utc
induty.sale_id = sale_data.sale_id induty.save
induty.out_time = Time.now.utc
induty.save
end
end
end
# Bind shift sale id to sale
# @sale_data.shift_sale_id = shift.id
# @sale_data.save
action_by = current_user.name
type = "REQUEST_BILL"
remark = "Request bill Receipt No #{sale_data.receipt_no}"
sale_audit = SaleAudit.record_audit_sale(sale_data.sale_id,remark,action_by,type )
# Promotion Activation
Promotion.promo_activate(sale_data)
#bill channel
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
from = ""
end
if order.source == "cashier" || order.source == "quick_service"
ActionCable.server.broadcast "bill_channel",table: table, from: from
end
if order.source == "quick_service" || order.source == "food_court"
result = {:status=> @status, :data => sale_data.sale_id }
render :json => result.to_json
else
#check checkInOut pdf print
checkout_time = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('checkout_time')
if !booking.dining_facility_id.nil?
terminal = DiningFacility.find_by_id(booking.dining_facility_id)
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
if (!checkout_time.empty?) && (ENV["SERVER_MODE"] != "cloud") #no print in cloud server
unique_code = "CheckInOutPdf"
printer = PrintSetting.find_by_unique_code_and_shop_code(unique_code,@shop.shop_code)
# print when complete click
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
if !printer.nil?
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, table)
end end
end end
action_by = current_user.name
type = "REQUEST_BILL"
remark = "Request bill Receipt No #{sale_data.receipt_no}"
sale_audit = SaleAudit.record_audit_sale(sale_data.sale_id,remark,action_by,type )
# Promotion Activation
Promotion.promo_activate(sale_data)
#bill channel
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
from = ""
end
if ["quick_service", "cashier"].include? order.source
ActionCable.server.broadcast "bill_channel", table: table, from: from
end
unless ["quick_service", "food_court"].include? order.source
#check checkInOut pdf print
checkout_time = Lookup.collection_of('checkout_time')
if !booking.dining_facility_id.nil?
terminal = DiningFacility.find_by_id(booking.dining_facility_id)
cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
if (!checkout_time.empty?) && (ENV["SERVER_MODE"] != "cloud") #no print in cloud server
unique_code = "CheckInOutPdf"
printer = PrintSetting.find_by_unique_code(unique_code)
# print when complete click
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
if !printer.nil?
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, table)
end
end
end
end
@status = true
sale_id = sale_data.sale_id
else
@status = false
sale_id = nil
end end
else
@status = true
sale_id = booking.sale_id
end end
end end
@status = true
else else
@status = false @status = false
@error_message = "No Current Open Shift for This Employee" @error_message = "No Current Open Shift for This Employee"
end end
if ["quick_service", "food_court"].include? order.source
# Not Use for these printed bill cannot give customer result = {:status=> @status, :data => sale_data.sale_id }
# unique_code = "ReceiptBillPdf" render :json => result.to_json
# #shop detail end
# shop_details = @shop
# # customer= Customer.where('customer_id=' +.customer_id)
# customer= Customer.find(@sale_data.customer_id)
# # get member information
# 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 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, false, nil,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details)
end end
end end

View File

@@ -27,52 +27,33 @@ class Origami::SalesController < BaseOrigamiController
dining = params[:dining_id] dining = params[:dining_id]
sale_id = params[:sale_id] sale_id = params[:sale_id]
tax_type = params[:tax_type] tax_type = params[:tax_type]
sale_data = []
table = DiningFacility.find(dining)
existing_booking = Booking.find_by_sale_id(sale_id)
table.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ").each do |booking|
if booking.sale_id.nil?
order_array = []
booking.booking_orders.each do |booking_order|
booking.booking_status = 'moved' Sale.transaction do
order = Order.find(booking_order.order_id) table = DiningFacility.find(dining)
order.status = 'billed' booking = table.current_checkin_booking
order.order_items.each do |item|
item.order_item_status = 'billed'
end
# create sale item
saleobj = Sale.find(sale_id)
order.order_items.each do |orer_item|
saleobj.add_item (orer_item)
if !orer_item.set_menu_items.nil?
saleobj.add_sub_item(orer_item.set_menu_items)
end
sale_data.push(orer_item)
end
# Re-compute for add sale = Sale.find(sale_id)
saleobj.compute(order.source,tax_type) existing = sale.booking
saleobj.save
order.save
booking.save
order_array.push(order.order_id) sale.sale_items << booking.order_items.to_sale_items
end sale.orders << booking.orders
receipt_no = Sale.find(sale_id).receipt_no sale.compute(booking.orders[0].source, tax_type)
action_by = current_user.name
type = "ADD_TO_EXISTING"
remark = "#{action_by} add to existing order #{order_array} to Receipt No=>#{receipt_no} in #{table.name}" type = "ADD_TO_EXISTING"
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type ) receipt_no = sale.receipt_no
action_by = current_user.name
order_ids = booking.orders.map(&:order_id)
booking_order = BookingOrder.where('booking_id=?',booking) remark = "#{action_by} add to existing order #{order_ids.to_s} to Receipt No=>#{receipt_no} in #{table.name}"
booking_order.each do |bo| sale_audit = SaleAudit.record_audit_sale(sale_id, remark, action_by, type)
bo.booking_id = existing_booking.booking_id
bo.save booking.orders.update_all(status: "billed")
end booking.order_items.update_all(order_item_status: "billed")
end BookingOrder.where(booking_id: booking.booking_id).update_all(booking_id: existing)
booking.booking_status = "moved"
booking.save
end end
end end

View File

@@ -16,377 +16,118 @@ class Origami::SplitBillController < BaseOrigamiController
@sale_data = Array.new @sale_data = Array.new
@current_user = current_user @current_user = current_user
table_bookings = Booking.where("dining_facility_id = #{dining_id} and sale_id IS NOT NULL") @sale_data = @table.current_sales
if !table_bookings.nil?
table_bookings.each do |table_booking|
if table_booking.sale.sale_status != 'waste' && table_booking.sale.sale_status != 'spoile'
@sale_data.push(table_booking.sale)
end
end
end
if @booking if @booking
@booking.booking_orders.each do |booking_order| @orders = @booking.orders
arr_order_items = Array.new @order = @orders[0]
@order = Order.find(booking_order.order_id) @order_items = []
if (@order.status == "new") order_items = []
@orders.push(@order)
@order.order_items.each do |item| @booking.order_items.each do |item|
if !item.set_menu_items.nil? if item.set_menu_items.present?
instance_item_sets = JSON.parse(item.set_menu_items) set_menu_items = JSON.parse(item.set_menu_items)
arr_instance_item_sets = Array.new item.set_menu_items = set_menu_items.map { |x| x["item_instance_name"] }
instance_item_sets.each do |instance_item| item.price = item.price + set_menu_items.inject(0.0) { |sum, x| sum + x["item_instance_name"].to_f }
item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name end
item.price = item.price.to_f + instance_item["price"].to_f
arr_instance_item_sets.push(item_instance_name)
end
item.set_menu_items = arr_instance_item_sets
end
arr_item = Hash.new @order_items += item.qty.to_i.times.map { i = item.as_json; i["qty"] = 1; order_items << i; { item.order_id => i } }
if item.qty.to_i > 1 end
i = 1
while i <= item.qty.to_i do @order_items << { 'all_order' => order_items }
arr_item = {'order_items_id' => item.order_items_id, else
'order_id' => item.order_id, @booking = nil
'order_item_status' => item.order_item_status, end
'item_order_by' => item.item_order_by,
'item_code' => item.item_code,
'item_instance_code' => item.item_instance_code,
'item_name' => item.item_name,
'alt_name' => item.alt_name,
'account_id' => item.account_id,
'qty' => '1.0',
'price' => item.price,
'remark' => item.remark,
'options' => item.options,
'set_menu_items' => item.set_menu_items,
'taxable' => item.taxable,
'completed_by' => item.completed_by,
'created_at' => item.created_at,
'updated_at' => item.updated_at}
i += 1
@order_items.push({@order.order_id => arr_item})
arr_order_items.push(arr_item)
end
else
arr_order_items.push(item)
@order_items.push({@order.order_id => item})
end
end
@order_items.push({'all_order' => arr_order_items})
end
end
else
@booking = nil
end
end end
def create def create
cashier_type = params[:cashier_type] cashier_type = params[:cashier_type]
dining_id = params[:dining_id]
order_ids = params[:order_ids] order_ids = params[:order_ids]
arr_order_ids = nil arr_order_ids = JSON.parse(params[:arr_order_ids]) if params[:arr_order_ids].present?
if !params[:arr_order_ids].nil? orders = JSON.parse(params[:orders]) if params[:orders].present?
arr_order_ids = JSON.parse(params[:arr_order_ids]) order_items = JSON.parse(params[:order_items]) if params[:order_items].present?
end
orders = nil
if !params[:orders].empty?
orders = JSON.parse(params[:orders])
end
order_items = nil
if !params[:order_items].empty?
order_items = JSON.parse(params[:order_items])
end
status = false
if !ShiftSale.current_shift.nil? if !ShiftSale.current_shift.nil?
#create Bill by Booking ID #create Bill by Booking ID
table = 0 table = DiningFacility.find_by(id: params[:dining_id]) if params[:dining_id].present?
if !params[:booking_id].empty?
booking = Booking.find(params[:booking_id])
# for Multiple Cashier by Zone
if booking.dining_facility_id.to_i>0
table = DiningFacility.find(booking.dining_facility_id)
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
else
table = nil
cashier_zone = nil
end
# shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) Booking.transaction do
# get_cashier_by_terminal = Employee.find(shift_by_terminal.employee_id) if params[:booking_id].present?
booking = Booking.find(params[:booking_id])
if sale_data = booking.sale
status = true
elsif sale_data = Sale.generate_invoice_from_booking(booking, current_user, current_user, cashier_type,params[:current_checkin_induties_count])
status = true
else else
status = false type = "TableBooking" if params[:type] == "Table"
end type ||= "RoomBooking"
else
if params[:type] == "Table"
type = "TableBooking"
else
type = "RoomBooking"
end
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => type, split_orders = []
:checkin_at => Time.now.utc, :checkin_by => current_user.name, new_order = nil
:booking_status => "assign",
:shop_code =>@shop.shop_code})
if !orders.nil? booking = Booking.create({:dining_facility_id => table.id, :type => type, :checkin_at => Time.now.utc, :checkin_by => current_user.name, :booking_status => "assign" })
orders.each do |order|
BookingOrder.find_by_order_id(order["id"]).delete if orders.present?
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order["id"]}) split_orders += orders.map { |x| x["id"] }
end end
elsif !order_items.nil?
order_item_count = 0
order_id_count = 0
order_id = nil
arr_order_ids.each do |order| if order_items.present?
order.each do |odr| order_items = order_items.inject([]) do |arr, v|
data = Order.find(odr[0]) v["qty"] = v["qty"].to_i
if data.order_items.count == odr[1] if i = arr.find { |x| x["id"] == v["id"] }
order_id = odr[0] i["qty"] = i["qty"] + v["qty"]
order_id_count += 1
else else
order_item_count += 1 arr << v
end
arr
end
Order.includes(:order_items).where(order_id: order_ids).each do |order|
if order.order_items.any? { |x| order_items.none? { |y| x.order_items_id == y["id"] && x.qty == y["qty"] } }
new_order ||= Order.create({ source: "cashier", order_type: order.order_type, customer_id: order.customer_id, item_count: order_items.length, waiters: current_user.name })
order.order_items.each do |order_item|
if split_item = order_items.find { |x| x["id"] == order_item.order_items_id }
if split_item["qty"] == order_item.qty
new_order.order_items << order_item
else
order_item.qty = order_item.qty - split_item["qty"]
order_item.save
order_item_dup = order_item.dup
order_item_dup.qty = split_item["qty"]
new_order.order_items << order_item_dup
end
end
end
else
split_orders << order
end end
end end
end end
if !order_id.nil? if new_order.present?
if order_id_count > 1 booking.orders << new_order
updated_order_id = Array.new
arr_order_ids.each do |order|
order.each do |odr|
data = Order.find(odr[0])
if data.order_items.count != odr[1]
updated_order_id.push(odr[0])
end
end
end
if !updated_order_id.empty?
order_ids.each do |odr_id|
unless updated_order_id.include?(odr_id)
BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
end
end
order_items.each do |order_item|
if updated_order_id.include?(order_item["order_id"])
update_order_item(order_id, order_item)
end
end
else
order_ids.each do |odr_id|
new_order_status = true
order_items.each do |order_item|
orderItem = OrderItem.find_by_order_id(odr_id)
if !orderItem.nil?
if order_item["id"] == orderItem.order_items_id
if orderItem.qty.to_f != order_item['qty'].to_f
new_order_status = false
end
end
end
end
if new_order_status
BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = create_order(params,order_type,order_items.count,current_user)
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
end
end
end
else
new_order_status = true
order_items.each do |order_item|
orderItem = OrderItem.find(order_item["id"])
if !orderItem.nil?
if order_item["id"] == orderItem.order_items_id
if orderItem.qty.to_f != order_item['qty'].to_f
new_order_status = false
end
end
end
end
if new_order_status
BookingOrder.find_by_order_id(order_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id})
order_items.each do |order_item|
update_order_item(order_id, order_item)
end
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = create_order(params,order_type,order_items.count,current_user)
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
end
end
else
if order_ids.count == 1 && order_item_count == 1
if order_id_count == 0
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = create_order(params,order_type,order_items.count,current_user)
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
else
BookingOrder.find_by_order_id(order_ids[0]).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
order_items.each do |order_item|
update_order_item(order_ids[0], order_item)
end
end
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = create_order(params,order_type,order_items.count,current_user)
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
end
end end
end
if sale_data = Sale.generate_invoice_from_booking(booking, current_user, current_user, cashier_type ,params[:current_checkin_induties_count]) if split_orders.present?
status = true BookingOrder.where(order_id: split_orders).update_all(booking_id: booking.booking_id)
end end
end
Promotion.promo_activate(sale_data)
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
from = ""
end
ActionCable.server.broadcast "bill_channel",table: table,from:from
render :json => { status: status }
else
render :json => { status: false, error_message: 'No Current Open Shift!'}
end
end
def create_order(params,order_type,items_count,current_user)
order = Order.new
order.source = "cashier"
order.order_type = order_type
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
order.item_count = items_count
order.status = "new"
order.table_id = params[:dining_id] # this is dining facilities's id
order.waiters = current_user.name
order.employee_name = current_user.name
order.guest_info = nil
order.shop_code = @shop.shop_code
order.save!
return order
end
def update_order_item(order_id, order_item)
orderItem = OrderItem.find(order_item["id"])
if orderItem.qty.to_f != order_item['qty'].to_f
set_menu_items_obj = Array.new
if !orderItem.set_menu_items.nil?
instance_item_sets = JSON.parse(orderItem.set_menu_items)
instance_item_sets.each_with_index do |instance_item, instance_index|
instance_item_sets[instance_index]["quantity"] = (instance_item["quantity"].to_i - order_item['qty'].to_i).to_s
set_menu_items_obj.push({'item_instance_code' => instance_item["item_instance_code"], 'quantity' => order_item['qty'].to_i, 'price' => instance_item["price"]})
end
orderItem.set_menu_items = instance_item_sets.to_json
end end
same_order = OrderItem.find_by_order_id(order_id) if booking.sale.nil?
if same_order.nil? sale_data = Sale.generate_invoice_from_booking(booking, current_user, current_user, cashier_type, params[:current_checkin_induties_count])
OrderItem.processs_item(orderItem.item_code, Promotion.promo_activate(sale_data)
orderItem.item_instance_code, end
orderItem.item_name,
orderItem.alt_name, if ENV["SERVER_MODE"] == 'cloud'
orderItem.account_id, from = request.subdomain + "." + request.domain
order_item['qty'], else
orderItem.price, from = ""
orderItem.options, end
set_menu_items_obj.to_json,
order_id, ActionCable.server.broadcast "bill_channel", table: table, from:from
orderItem.item_order_by,
orderItem.taxable) render :json => { status: true }
else end
same_order.qty = same_order.qty.to_f + order_item['qty'].to_f else
same_order.set_menu_items = set_menu_items_obj.to_json render :json => { status: false, error_message: 'No Current Open Shift!'}
same_order.save end
end
orderItem.qty = orderItem.qty.to_f - order_item['qty'].to_f
else
orderItem.order_id = order_id
end
orderItem.save!
end end
def update_sale def update_sale

View File

@@ -9,7 +9,7 @@ class Origami::SurveysController < BaseOrigamiController
@id = params[:id] @id = params[:id]
@cashier_type = params[:type] @cashier_type = params[:type]
if(@id[0,3] == "SAL") if @id.include? "SAL"
@sale = Sale.find(@id) @sale = Sale.find(@id)
@receipt_no = @sale.receipt_no @receipt_no = @sale.receipt_no
@grand_total = @sale.grand_total @grand_total = @sale.grand_total
@@ -33,7 +33,7 @@ class Origami::SurveysController < BaseOrigamiController
@table_type = @dining_facility.type @table_type = @dining_facility.type
@receipt_no = nil @receipt_no = nil
@grand_total = nil @grand_total = nil
@survey_data = Survey.find_by_dining_name_and_receipt_no_and_shop_code(@dining_facility.name,nil,@shop.shop_code) @survey_data = Survey.find_by_dining_name_and_receipt_no(@dining_facility.name,nil)
end end
end end

View File

@@ -1,6 +1,7 @@
class Origami::TableInvoicesController < BaseOrigamiController class Origami::TableInvoicesController < BaseOrigamiController
def index def index
@table = DiningFacility.find(params[:table_id]) @table = DiningFacility.find(params[:table_id])
shop = Shop.current_shop
@sale_array = Array.new @sale_array = Array.new
@table.bookings.each do |booking| @table.bookings.each do |booking|
@@ -31,29 +32,7 @@ class Origami::TableInvoicesController < BaseOrigamiController
@membership = MembershipSetting::MembershipSetting @membership = MembershipSetting::MembershipSetting
@payment_methods = PaymentMethodSetting.all @payment_methods = PaymentMethodSetting.all
@sale_array = Array.new @sale_array = @table.current_sales
@table.bookings.each do |booking|
if booking.sale_id.nil?
else
sale = Sale.find(booking.sale_id)
# rounding adjustment
if @shop.is_rounding_adj
a = sale.grand_total % 25 # Modulus
b = sale.grand_total / 25 # Division
#not calculate rounding if modulus is 0 and division is even
#calculate rounding if modulus is zero or not zero and division are not even
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
new_total = Sale.get_rounding_adjustment(sale.grand_total)
sale.rounding_adjustment = new_total-sale.grand_total
sale.update_attributes(grand_total: new_total,old_grand_total: sale.grand_total,rounding_adjustment:sale.rounding_adjustment)
end
end
#end rounding adjustment
if sale.sale_status != "completed" && sale.sale_status != 'void' && sale.sale_status != "waste" && sale.sale_status != "spoile"
@sale_array.push(sale)
end
end
end
@sale = Sale.find(params[:invoice_id]) @sale = Sale.find(params[:invoice_id])
@date = @sale.created_at @date = @sale.created_at

View File

@@ -4,6 +4,9 @@ class Reports::HourlySaleitemController < BaseReportController
@account = Account.where("shop_code='#{@shop.shop_code}'") @account = Account.where("shop_code='#{@shop.shop_code}'")
from, to = get_date_range_from_params from, to = get_date_range_from_params
@start_time = params[:start_time]
@end_time = params[:end_time]
shift_sale_range = '' shift_sale_range = ''
shift = '' shift = ''
@@ -23,9 +26,10 @@ class Reports::HourlySaleitemController < BaseReportController
end end
end end
filter = params[:filter]
account_type = params[:account_type] account_type = params[:account_type]
@type = params[:sale_type] @type = params[:sale_type]
@sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_hourly_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type,@shop.shop_code) @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_hourly_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type,filter,@start_time,@end_time)
@sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil).where("sales.shop_code='#{@shop.shop_code}'") @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil).where("sales.shop_code='#{@shop.shop_code}'")

View File

@@ -5,10 +5,10 @@ class ApplicationRecord < ActiveRecord::Base
super super
return unless subclass.superclass == self return unless subclass.superclass == self
return unless subclass.column_names.include? 'shop_id' return unless subclass.column_names.include? 'shop_code'
subclass.class_eval do subclass.class_eval do
acts_as_tenant(:shop) acts_as_tenant(:shop, foreign_key: 'shop_code', primary_key: 'shop_code')
end end
end end
end end

View File

@@ -63,6 +63,11 @@ class AssignedOrderItem < ApplicationRecord
return order_item return order_item
end end
protected
def self.generate_ids(count = 1)
SeedGenerator.generate_ids(self.name, "AOI", count)
end
private private
def generate_custom_id def generate_custom_id
if self.assigned_order_item_id.nil? if self.assigned_order_item_id.nil?

View File

@@ -6,13 +6,62 @@ class Booking < ApplicationRecord
belongs_to :dining_facility, :optional => true belongs_to :dining_facility, :optional => true
belongs_to :sale, :optional => true belongs_to :sale, :optional => true
has_one :cashier_terminal_by_dining_facility, through: :dining_facility, source: :cashier_terminal
has_one :current_shift_by_dining_facility, through: :dining_facility, source: :current_shift
has_many :booking_orders has_many :booking_orders
has_many :orders, :through => :booking_orders has_many :orders, :through => :booking_orders
has_many :order_items, :through => :orders has_many :order_items, :through => :orders do
def to_sale_items
sale_items = []
proxy_association.load_target.select(&:order_items_id).each do |order_item|
menu_category = order_item.menu_category || OpenStruct.new(name: 'Product', code: '') #get menu category for menu items
sale_items << SaleItem.new({
menu_category_name: menu_category.name,
menu_category_code: menu_category.code,
product_name: order_item.item_name,
product_code: order_item.item_code,
product_alt_name: order_item.alt_name,
account_id: order_item.account_id,
is_taxable: order_item.taxable,
item_instance_code: order_item.item_instance_code,
qty: order_item.qty,
unit_price: order_item.price,
price: order_item.qty * order_item.price,
taxable_price: order_item.qty * order_item.price,
status: order_item.remark
})
if order_item.set_menu_items
JSON.parse(order_item.set_menu_items).each do |item|
instance = MenuItemInstance.find_by_item_instance_code(item["item_instance_code"])
menu_item = instance.menu_item
menu_category = menu_item.menu_category #get menu category for menu items
sale_items << SaleItem.new({
menu_category_name: menu_category.name,
menu_category_code: menu_category.code,
product_name: instance.item_instance_name,
product_code: menu_item.item_code,
product_alt_name: menu_item.alt_name,
account_id: menu_item.account_id,
is_taxable: menu_item.taxable,
item_instance_code: item["item_instance_code"],
qty: item["quantity"],
unit_price: item["price"],
price: item["quantity"].to_f * item["price"].to_f,
taxable_price: item["quantity"].to_f * item["price"].to_f
})
end
end
end
sale_items
end
end
scope :active, -> {where("booking_status != 'moved'")} scope :active, -> {where("booking_status != 'moved'")}
scope :today, -> {where("created_at >= #{Time.now.utc}")} scope :today, -> {where("created_at >= #{Time.now.utc}")}
scope :shop, -> { where("bookings.shop_code=?",Shop.current_shop.shop_code) } scope :assign, -> { where(booking_status: 'assign')}
scope :within_time_limit, -> { where(checkin_at: Lookup.get_checkin_time_limit.hours.ago..DateTime::Infinity.new) }
def self.sync_booking_records(bookings) def self.sync_booking_records(bookings)
if !bookings.nil? if !bookings.nil?

View File

@@ -1,9 +1,10 @@
class CashierTerminal < ApplicationRecord class CashierTerminal < ApplicationRecord
has_many :cashier_terminal_by_zones has_many :cashier_terminal_by_zones
has_many :zones, through: :cashier_terminal_by_zones has_many :zones, through: :cashier_terminal_by_zones
has_one :current_shift, -> { where.not(shift_started_at: nil).where(shift_closed_at: nil) }, class_name: "ShiftSale"
scope :available, -> {where(is_currently_login: false)} scope :available, -> {where(is_currently_login: false)}
scope :is_active, -> {where(is_active: true)} scope :is_active, -> {where(is_active: true)}
# validations # validations
validates_presence_of :name, :printer_name validates_presence_of :name, :printer_name

View File

@@ -35,6 +35,14 @@ class Customer < ApplicationRecord
end end
end end
def self.walkin
self.find_by(name: "WALK-IN")
end
def self.takeaway
self.find_by(name: "TAKEAWAY")
end
def self.get_member_account(customer) def self.get_member_account(customer)
membership = MembershipSetting.active.find_by_membership_type("paypar_url") membership = MembershipSetting.active.find_by_membership_type("paypar_url")
memberaction = MembershipAction.active.find_by_membership_type("get_all_member_account") memberaction = MembershipAction.active.find_by_membership_type("get_all_member_account")

View File

@@ -4,7 +4,7 @@ class DiningCharge < ApplicationRecord
def self.amount_calculate(dining_charges_obj, checkin , checkout) 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 # 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 block_count = 0
price = 0 price = 0
minutes = DiningCharge.time_diff(checkout, checkin) minutes = DiningCharge.time_diff(checkout, checkin)
@@ -13,18 +13,17 @@ class DiningCharge < ApplicationRecord
if dining_minutes <= free_time if dining_minutes <= free_time
price = 0 price = 0
else else
charge_type = dining_charges_obj.charge_type charge_type = dining_charges_obj.charge_type
if charge_type == 'hr' if charge_type == 'hr'
block_count, price = DiningCharge.charges(dining_charges_obj, dining_minutes, 'hr') block_count, price = DiningCharge.charges(dining_charges_obj, dining_minutes, 'hr')
elsif charge_type == 'day' elsif charge_type == 'day'
block_count, price = DiningCharge.charges(dining_charges_obj, dining_minutes, 'day') block_count, price = DiningCharge.charges(dining_charges_obj, dining_minutes, 'day')
end end
end end
return block_count, price return block_count, price
else else
Rails.logger.info "Params not enough" return 0, 0
end end
end end
# dining charges calculate # dining charges calculate
@@ -37,7 +36,7 @@ class DiningCharge < ApplicationRecord
rounding_time = DiningCharge.convert_to_minutes(chargesObj.time_rounding_block.utc.strftime('%H:%M')) rounding_time = DiningCharge.convert_to_minutes(chargesObj.time_rounding_block.utc.strftime('%H:%M'))
if result.to_i < 1 if result.to_i < 1
# for dining minute is under charge_block # for dining minute is under charge_block
if dining_minutes > rounding_time if dining_minutes > rounding_time
rounding_block = dining_minutes / rounding_time rounding_block = dining_minutes / rounding_time
solid_price = rounding_block * chargesObj.time_rounding_block_price solid_price = rounding_block * chargesObj.time_rounding_block_price
@@ -46,7 +45,7 @@ class DiningCharge < ApplicationRecord
else else
return 1, result.to_i,chargesObj.unit_price return 1, result.to_i,chargesObj.unit_price
end end
elsif result.to_i >= 1 elsif result.to_i >= 1
solid_price = result * chargesObj.unit_price solid_price = result * chargesObj.unit_price
@@ -64,7 +63,7 @@ class DiningCharge < ApplicationRecord
else else
solid_price += (roundingblock * chargesObj.time_rounding_block_price) solid_price += (roundingblock * chargesObj.time_rounding_block_price)
return result.to_i, DiningCharge.check_rounding(chargesObj, solid_price, extra_minutes) return result.to_i, DiningCharge.check_rounding(chargesObj, solid_price, extra_minutes)
end end
end end
end end
@@ -74,7 +73,7 @@ class DiningCharge < ApplicationRecord
# rounding_block_remain = roundingblock / 1 # rounding_block_remain = roundingblock / 1
free_time = DiningCharge.convert_to_minutes(chargesObj.minimum_free_time.utc.strftime('%H:%M')) free_time = DiningCharge.convert_to_minutes(chargesObj.minimum_free_time.utc.strftime('%H:%M'))
rounding_block_remain = extra_minutes - free_time rounding_block_remain = extra_minutes - free_time
if chargesObj.time_rounding == "down" if chargesObj.time_rounding == "down"
return solid_price return solid_price
else else

View File

@@ -1,7 +1,20 @@
class DiningFacility < ApplicationRecord class DiningFacility < ApplicationRecord
belongs_to :zone belongs_to :zone
has_many :dining_charges
has_many :in_juties has_many :in_juties
has_one :dining_charge
has_one :cashier_terminal_by_zone, foreign_key: "zone_id", primary_key: "zone_id"
has_one :cashier_terminal, through: :cashier_terminal_by_zone
has_one :current_shift, through: :cashier_terminal
has_many :order_queue_process_by_zones, foreign_key: "zone_id", primary_key: "zone_id"
has_many :order_queue_stations, -> { where(is_active: true) }, through: :order_queue_process_by_zones
has_many :bookings
has_many :current_bookings, -> { left_joins(:sale).assign.within_time_limit.merge(Booking.where(checkout_at: nil).or(Booking.merge(Sale.where(sale_status: ['new', nil])))) }, class_name: "Booking"
has_one :current_checkin_booking, -> { left_joins(:sale).assign.within_time_limit.merge(Sale.where(sale_status: nil)) }, class_name: "Booking"
has_one :current_checkout_booking, -> { left_joins(:sale).assign.within_time_limit.where.not(checkout_at: nil).merge(Sale.where(sale_status: 'new')) }, class_name: "Booking"
has_one :current_reserved_booking, -> { left_joins(:sale).assign.within_time_limit.where.not(reserved_at: nil).merge(Sale.where(sale_status: nil)) }, class_name: "Booking"
has_many :current_sales, -> { where(sale_status: 'new').merge(Booking.assign.within_time_limit) }, through: :bookings, class_name: "Sale", source: "sale"
TABLE_TYPE = "Table" TABLE_TYPE = "Table"
ROOM_TYPE = "Room" ROOM_TYPE = "Room"
@@ -22,7 +35,7 @@ class DiningFacility < ApplicationRecord
end end
def get_booking def get_booking
booking = self.get_current_booking booking = self.current_checkin_booking
if booking if booking
if booking.dining_facility_id.to_i == self.id if booking.dining_facility_id.to_i == self.id
if booking.booking_status == 'assign' if booking.booking_status == 'assign'
@@ -38,26 +51,8 @@ class DiningFacility < ApplicationRecord
Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first #and checkout_at is null Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first #and checkout_at is null
end end
def get_moved_booking
checkin_time_lookup = Lookup.get_checkin_time_limit
Booking.where(dining_facility_id: self.id, booking_status: 'moved', checkout_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first
end
def get_new_booking
# query for new
Booking.where(dining_facility_id: self.id, booking_status: 'assign', sale_id: nil, checkout_at: nil).first
end
def get_current_checkout_booking
checkin_time_lookup = Lookup.get_checkin_time_limit
Booking.where(dining_facility_id: self.id, booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago).first
end
def get_checkout_booking def get_checkout_booking
booking = self.get_current_checkout_booking booking = self.current_reserved_booking
if booking if booking
lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time") lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time")
free_time_min = 0 free_time_min = 0
@@ -97,8 +92,7 @@ class DiningFacility < ApplicationRecord
def self.get_checkin_booking def self.get_checkin_booking
checkin_time_lookup = Lookup.get_checkin_time_limit checkin_time_lookup = Lookup.get_checkin_time_limit
bookings = Booking.where(booking_status: 'assign', checkout_at: nil).where.not(reserved_at: nil).where("checkin_at > ?", checkin_time_lookup.hours.ago) bookings = self.current_checkin_booking
arr_booking = Array.new arr_booking = Array.new
if bookings if bookings
lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time") lookup_checkout_time = Lookup.where("shop_code='#{self.shop_code}'").collection_of("checkout_alert_time")

View File

@@ -2,6 +2,8 @@ class Employee < ApplicationRecord
has_secure_password has_secure_password
has_many :commissioners has_many :commissioners
has_many :shit_sales has_many :shit_sales
has_one :current_shift, -> { where.not(shift_started_at: nil).where(shift_closed_at: nil) },class_name: "ShiftSale"
has_one :cashier_terminal, through: :current_shift
belongs_to :order_queue_station belongs_to :order_queue_station
validates_presence_of :name, :role validates_presence_of :name, :role

View File

@@ -83,21 +83,8 @@ class InventoryDefinition < ApplicationRecord
.order("mi.menu_category_id desc") .order("mi.menu_category_id desc")
end end
def self.get_by_category(shop,filter) def self.get_by_category(filter)
# THEN (SELECT min(balance) FROM stock_journals least_stock = StockJournal.select(:balance).joins("JOIN inventory_definitions ON stock_journals.item_code = inventory_definitions.item_code").order(:id => :desc).limit(1).to_sql
# least_stock = "SELECT (CASE WHEN stock_journals.remark != 'out of stock'
# THEN (SELECT balance FROM stock_journals
# WHERE item_code = inventory_definitions.item_code AND remark != 'out of stock'
# ORDER BY created_at DESC LIMIT 1) ELSE 0 END)
# FROM stock_journals
# WHERE stock_journals.item_code = inventory_definitions.item_code
# ORDER BY stock_journals.created_at DESC LIMIT 1"
least_stock = "(SELECT
(SELECT balance FROM stock_journals WHERE item_code = inventory_definitions.item_code
ORDER BY id DESC LIMIT 1)
FROM stock_journals
WHERE stock_journals.item_code = inventory_definitions.item_code
ORDER BY stock_journals.created_at DESC LIMIT 1)"
@inventory_definitions = InventoryDefinition.select("inventory_definitions.*, @inventory_definitions = InventoryDefinition.select("inventory_definitions.*,
(CASE WHEN sj.credit IS NULL THEN 0 ELSE sj.credit END) as credit, (CASE WHEN sj.credit IS NULL THEN 0 ELSE sj.credit END) as credit,

View File

@@ -60,7 +60,7 @@ class Lookup < ApplicationRecord
end end
def self.collection_of(type) def self.collection_of(type)
Lookup.select("name, value").where("lookup_type" => type ).map { |l| [l.name, l.value] } Lookup.where("lookup_type" => type ).pluck("name, value")
end end
def self.create_shift_sale_lookup(shop_code) def self.create_shift_sale_lookup(shop_code)

View File

@@ -1,5 +1,5 @@
class MembershipSetting < ApplicationRecord class MembershipSetting < ApplicationRecord
scope :active, -> { where(is_active: true) } scope :active, -> { where(is_active: true) }
# MembershipSetting = MembershipSetting.find_by_id(1) MembershipSetting = MembershipSetting.first
end end

View File

@@ -31,26 +31,26 @@ class MenuItem < ApplicationRecord
# Work with item_code = item_instance_code # Work with item_code = item_instance_code
def self.search_by_item_code(item_code) def self.search_by_item_code(item_code)
menu_item_hash = Hash.new MenuItem.left_joins(:menu_item_instances => :menu_instance_item_sets)
mt_instance = MenuItemInstance.find_by_item_instance_code(item_code) .where(menu_item_instances: {item_instance_code: item_code})
if (!mt_instance.nil?) .pluck(:type, :account_id, :item_code, :item_instance_code, :name, :alt_name, :item_instance_name, :price, :promotion_price, :is_on_promotion, "menu_item_instances.is_available", :taxable, :item_set_id)
menu_item = MenuItem.find(mt_instance.menu_item_id) .map { |type, account_id, item_code, item_instance_code, item_name, item_alt_name, item_instance_name, price, promotion_price, is_on_promotion, is_available, taxable, item_set_id|
menu_item_hash[:type] = menu_item.type name = item_instance_name if item_set_id
menu_item_hash[:account_id] = menu_item.account_id name ||= "#{item_name}#{' - ' + item_instance_name if item_instance_name.present?}"
menu_item_hash[:item_code] = menu_item.item_code {
menu_item_hash[:item_instance_code] = mt_instance.item_instance_code type: type,
menu_item_hash[:name] = menu_item.name.to_s + " - " + mt_instance.item_instance_name.to_s account_id: account_id,
menu_item_hash[:alt_name] = menu_item.alt_name.to_s # + " - " + mt_instance.item_instance_name.to_s item_code: item_code,
menu_item_hash[:price] = mt_instance.price item_instance_code: item_instance_code,
menu_item_hash[:promotion_price] = mt_instance.promotion_price name: "#{name}",
menu_item_hash[:is_on_promotion] = mt_instance.is_on_promotion alt_name: "#{item_alt_name}",
menu_item_hash[:is_available] = mt_instance.is_available price: price,
menu_item_hash[:taxable] = menu_item.taxable promotion_price: promotion_price,
is_on_promotion: is_on_promotion,
return menu_item_hash is_available: is_available,
end taxable: taxable
}
return nil }
end end
def self.deleteRecursive(menu_item) def self.deleteRecursive(menu_item)

View File

@@ -26,25 +26,16 @@ class Order < ApplicationRecord
def generate def generate
booking = nil booking = nil
if self.new_booking if self.new_booking
if self.table_id.to_i > 0
table_id = self.table_id
else
table_id = nil
end
#add extra time #add extra time
if self.is_extra_time && self.extra_time if self.is_extra_time && self.extra_time
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking", booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
:checkin_at => Time.now.utc,:checkout_at => Time.now.utc + self.extra_time.to_i, :checkin_at => Time.now.utc, :checkout_at => Time.now.utc + self.extra_time.to_i,
:checkin_by => self.employee_name, :checkin_by => self.employee_name,
:booking_status => "assign", :booking_status => "assign" })
:customer_id => self.customer_id,
:shop_code=>self.shop_code})
else else
booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking", booking = Booking.create({:dining_facility_id => table_id,:type => "TableBooking",
:checkin_at => Time.now.utc, :checkin_by => self.employee_name, :checkin_at => Time.now.utc, :checkin_by => self.employee_name,
:booking_status => "assign", :booking_status => "assign" })
:customer_id => self.customer_id,
:shop_code=>self.shop_code })
end end
#end extra time #end extra time
@@ -54,7 +45,6 @@ class Order < ApplicationRecord
# table.status = "occupied" # table.status = "occupied"
# table.save # table.save
end end
else else
booking = Booking.find(self.booking_id) booking = Booking.find(self.booking_id)
#add extra time #add extra time
@@ -74,7 +64,7 @@ class Order < ApplicationRecord
self.adding_line_items self.adding_line_items
#Add Order Table and Room relation afrer order creation #Add Order Table and Room relation afrer order creation
BookingOrder.create({:booking_id => booking.booking_id, :order => self}) booking.orders << self
#Send order to queue one it done! #Send order to queue one it done!
# if self.source != "quick_service" # if self.source != "quick_service"
@@ -111,7 +101,7 @@ class Order < ApplicationRecord
self.adding_line_items self.adding_line_items
#Add Order Table and Room relation afrer order creation #Add Order Table and Room relation afrer order creation
BookingOrder.create({:booking_id => booking.booking_id, :order => self}) booking.orders << self
#Send order to queue one it done! #Send order to queue one it done!
# if self.source != "quick_service" # if self.source != "quick_service"
@@ -122,7 +112,6 @@ class Order < ApplicationRecord
send_order_broadcast(booking) send_order_broadcast(booking)
return true, booking return true, booking
end end
return false return false
@@ -137,49 +126,36 @@ class Order < ApplicationRecord
def adding_line_items def adding_line_items
if self.items if self.items
#re-order to #re-order to
ordered_list = re_order_items(self.items) items = re_order_items(self.items)
#loop to add all items to order #loop to add all items to order
ordered_list.each do |item| item_instance_codes = items.map { |i| i[:item_instance_code] }
menu_items = MenuItem.search_by_item_code(item_instance_codes)
menu_items += Product.search_by_product_code(item_instance_codes) if menu_items.length < item_instance_codes.length
menu_item = MenuItem.search_by_item_code(item[:item_instance_code]) items.each do |order_item|
menu_item = menu_items.find { |i| i[:item_instance_code].downcase == order_item[:item_instance_code].downcase }
# For Product while item code not in menu item sub_order_items = []
if menu_item.nil? if order_item[:sub_items].length > 0
menu_item = Product.search_by_product_code(item[:item_instance_code]) sub_menu_items = MenuItem.search_by_item_code(order_item[:sub_items].map { |i| i[:item_instance_code] })
end order_item[:sub_items].each do |sub_order_item|
sub_menu_item = sub_menu_items.find { |i| i[:item_instance_code] == sub_order_item[:item_instance_code] }
#if (!menu_item.nil?) sub_order_items << { item_instance_code: sub_order_item[:item_instance_code], item_instance_name: sub_menu_item[:name], quantity: sub_order_item[:quantity], price: sub_menu_item[:price], options: sub_order_item[:options] }
# Rails.logger.debug menu_item
set_order_items = Array.new
##If menu Item set item - must add child items to order as well, where price is only take from menu_item
if (menu_item[:type] == "SetMenuItem")
if (item.include? 'sub_items') || (item.include? :sub_items)
item[:sub_items].each do |si|
# Retrive instance's Price
set_item = MenuItem.search_by_item_code(si[:item_instance_code])
set_order_items.push({"item_instance_code"=>si[:item_instance_code], "item_instance_name"=>set_item[:name], "quantity"=>si[:quantity], "price"=>set_item[:price], "options"=>si[:options]})
end
end
set_order_items = set_order_items.to_json
else
set_order_items = nil
end end
end
# not insert with price 0 sub_order_items = sub_order_items.to_json
# puts item[:price] self.order_items.build({
# puts item item_code: menu_item[:item_code],
# if(item[:price] != 0 ) item_instance_code: order_item[:item_instance_code],
# OrderItem.processs_item(menu_item[:item_code], menu_item[:name], menu_item[:account_id], item_name: menu_item[:name],
# item[:quantity],menu_item[:price], item[:options], set_order_items, self.id, alt_name: menu_item[:alt_name],
# self.employee_name) account_id: menu_item[:account_id],
# end qty: order_item[:quantity],
price: menu_item[:price],
OrderItem.processs_item(menu_item[:item_code], item[:item_instance_code], menu_item[:name], menu_item[:alt_name], menu_item[:account_id], options: order_item[:options],
item[:quantity],menu_item[:price], item[:options], set_order_items, self.id, set_menu_items: sub_order_items,
self.employee_name, menu_item[:taxable]) item_order_by: employee_name,
taxable: menu_item[:taxable]
#end })
end end
self.item_count = self.order_items.count self.item_count = self.order_items.count
@@ -190,7 +166,6 @@ class Order < ApplicationRecord
self.errors.add(:order_items, :blank, message: "Order items cannot be blank") self.errors.add(:order_items, :blank, message: "Order items cannot be blank")
return false return false
end end
end end
def update_items_status_to_billed(items) def update_items_status_to_billed(items)
@@ -211,72 +186,14 @@ class Order < ApplicationRecord
end end
def default_values def default_values
self.customer = Customer.find(1) if self.customer_id.nil? self.customer = Customer.walkin if self.customer_id.nil?
self.source = "emenu" if self.source.nil? self.source = "emenu" if self.source.nil?
self.order_type = "dine-in" if self.order_type.nil? self.order_type = "dine-in" if self.order_type.nil?
end end
protected protected
def re_order_items(form_items) #reorder inputs items as parents and child def re_order_items(items) #reorder inputs items as parents and child
parent_id = Array.new new_items = items.select { |i| i[:parent_order_item_id].blank? }.map { |x| x[:sub_items] = items.select { |y| x[:order_item_id] == y[:parent_order_item_id] }; x }
parents = Array.new
parents_and_children_items = Array.new
new_items_list = Array.new
form_items.each do |parent|
if !parent[:parent_order_item_id].nil?
if (!parent_id.include?(parent[:parent_order_item_id]))
parent_id.push(parent[:parent_order_item_id])
end
end
end
Rails.logger.debug "Parent Id count -> " + parent_id.count.to_s
parent_id.each do |pid|
form_items.each do |item|
Rails.logger.debug "Adding - Parents -> " + pid.to_s + " - " + item[:order_item_id].to_s
if (pid == item[:order_item_id])
parents.push(item)
end
end
end
Rails.logger.debug "Parents count -> " + parents.count.to_s
parents.each do |parent|
children = Array.new
form_items.each do |item|
if (parent[:order_item_id] == item[:parent_order_item_id] )
children.push(item)
#Items to remove for new list
parents_and_children_items.push(item)
end
end
parent[:sub_items] = children
end
Rails.logger.debug "Parent/children Items to remove -> " + parents_and_children_items.count.to_s
#Remove process items
#c = a.reject{ |e| b.include? e }
new_items_list = form_items - parents_and_children_items
Rails.logger.debug "New list count -> " + new_items_list.count.to_s
#Add parent to the list
#new_items_list = new_items_list + parents
Rails.logger.debug "Re-Order List (Parent)-"
Rails.logger.debug parents
Rails.logger.debug "Re-Order List -"
Rails.logger.debug new_items_list
return new_items_list
end end
@@ -485,66 +402,31 @@ class Order < ApplicationRecord
end end
#Process order items and send to order queue #Process order items and send to order queue
def self.process_order_queue(order_id,table_id,source) def self.process_order_queue(order_id, table_id, source)
print_status = nil print_status = nil
cup_status = nil cup_status = nil
#Send to background job for processing #Send to background job for processing
order = Order.find(order_id) order = Order.find(order_id)
sidekiq = Lookup.find_by_lookup_type("sidekiq") sidekiq = Lookup.find_by_lookup_type("sidekiq")
if ENV["SERVER_MODE"] != 'cloud' if ENV["SERVER_MODE"] != 'cloud'
cup_status = `#{"sudo service cups status"}` if Printer::PrinterWorker.printers.blank?
print_status = check_cup_status(cup_status) msg = 'Print Error ! Please contact to service'
ActionCable.server.broadcast "call_waiter_channel", table: msg, time:'print_error', from: ''
end end
end
if print_status if !sidekiq.nil?
if !sidekiq.nil? OrderQueueProcessorJob.perform_later(order_id, table_id)
OrderQueueProcessorJob.perform_later(order_id, table_id) else
else if order
if order oqs = OrderQueueStation.new
oqs = OrderQueueStation.new oqs.process_order(order, table_id, source)
oqs.process_order(order, table_id, source)
end
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
else
if ENV["SERVER_MODE"] != 'cloud'
cup_start = `#{"sudo service cups start"}`
cup_status = `#{"sudo service cups status"}`
print_status = check_cup_status(cup_status)
end
if print_status
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(order_id, table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, source)
end
# assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
# ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
else
if ENV["SERVER_MODE"] != 'cloud'
msg = ' Print Error ! Please contact to service'
ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error'
end
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(order_id, table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id, source)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
end
end end
assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id)
ActionCable.server.broadcast "order_queue_station_channel", order: assign_order
end
end end
def self.check_cup_status(status) def self.check_cup_status(status)

View File

@@ -5,8 +5,10 @@ class OrderItem < ApplicationRecord
before_create :generate_custom_id before_create :generate_custom_id
#Associations #Associations
belongs_to :order, autosave: true belongs_to :order, autosave: true
# belongs_to :order, counter_cache: true has_one :menu_item, foreign_key: "item_code", primary_key: "item_code"
has_one :menu_category, through: :menu_item
# belongs_to :order, counter_cache: true
#Validation #Validation
validates_presence_of :item_code, :item_name, :qty validates_presence_of :item_code, :item_name, :qty
@@ -102,7 +104,13 @@ class OrderItem < ApplicationRecord
end end
end end
protected
def self.generate_ids(count = 1)
SeedGenerator.generate_ids(self.name, "ODI", count)
end
private private
def generate_custom_id def generate_custom_id
if self.order_items_id.nil? if self.order_items_id.nil?
self.order_items_id = SeedGenerator.generate_id(self.class.name, "ODI") self.order_items_id = SeedGenerator.generate_id(self.class.name, "ODI")

View File

@@ -14,104 +14,39 @@ class OrderQueueStation < ApplicationRecord
# validations # validations
validates_presence_of :station_name, :printer_name validates_presence_of :station_name, :printer_name
def process_order (order, table_id, order_source = nil, pdf_status = nil ,change_to=nil,current_user=nil) def process_order(order, table_id, order_source = nil, pdf_status = nil ,change_to=nil, current_user=nil)
oqs_stations = OrderQueueStation.active.where("shop_code='#{order.shop_code}'")
order_items = order.order_items order_items = order.order_items
if table_id.to_i > 0 if table_id.to_i > 0
# get dining # get dining
dining = DiningFacility.find(table_id) dining = DiningFacility.find(table_id)
oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}") oqs_stations = dining.order_queue_stations
booking = Booking.find_by_dining_facility_id(dining.id)
# ToDo per item per printer
oqs_by_zones.each do |oqpbz|
oqs = OrderQueueStation.find(oqpbz.order_queue_station_id)
is_auto_printed = false
oqs_order_items = []
if oqs.is_active
#Get List of items -
pq_items = JSON.parse(oqs.processing_items)
#Loop through the processing items
pq_items.each do |pq_item|
#Processing through the looping items
order_items.each do |order_item|
if (pq_item == order_item.item_code)
# if oqs.id == oqpbz.order_queue_station_id
# #Same Order_items can appear in two location.
# AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
# else
if (order_item.qty > 0)
if pdf_status.nil?
AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs)
end
oqs_order_items.push(order_item)
end
# end
end
end
end
if oqs.auto_print && order_source != "quick_service"
if oqs_order_items.length > 0
if oqs.cut_per_item
print_slip_item(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id)
else
print_slip(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id)
end
is_auto_printed = true
end
end
end
end
else else
oqs_stations.each do |oqs| oqs_stations = OrderQueueStation.active
is_auto_printed = false end
oqs_order_items = []
if oqs.is_active assigned_order_items = []
#Get List of items - oqs_order_items_by_zones = []
pq_items = JSON.parse(oqs.processing_items)
#Loop through the processing items
pq_items.each do |pq_item|
#Processing through the looping items
order_items.each do |order_item|
if (pq_item == order_item.item_code)
# if oqs.id == oqpbz.order_queue_station_id
# #Same Order_items can appear in two location.
# AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
# else
if (order_item.qty > 0) # ToDo per item per printer
if pdf_status.nil? oqs_stations.each do |oqs|
AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs) oqs_order_items = order_items.select { |i| JSON.parse(oqs.processing_items).include? i.item_code }
end oqs_order_items_by_zones << { oqs: oqs, oqs_order_items: oqs_order_items }
oqs_order_items.push(order_item)
end
# end
end
end
end
if oqs.auto_print && order_source != "quick_service" print_status = false
if oqs_order_items.length > 0 if oqs.auto_print && order_source != "quick_service"
if oqs.cut_per_item print_status = true
print_slip_item(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id) if oqs_order_items.length > 0
else if oqs.cut_per_item
print_slip(oqs, order, oqs_order_items,pdf_status,change_to,current_user,table_id) print_slip_item(oqs, order, oqs_order_items, pdf_status, change_to, current_user, table_id)
end else
is_auto_printed = true print_slip(oqs, order, oqs_order_items, pdf_status, change_to, current_user, table_id)
end
end end
end end
end end
end #end else
oqs_order_items.each { |i| AssignedOrderItem.create({ order: order, item_code: i.item_code, instance_code: i.item_instance_code, order_queue_station: oqs, print_status: print_status, delivery_status: false }) }
end
end end
def pay_process_order_queue (order_id, table_id) def pay_process_order_queue (order_id, table_id)
@@ -213,80 +148,31 @@ class OrderQueueStation < ApplicationRecord
#Print order_items in 1 slip #Print order_items in 1 slip
def print_slip(oqs, order, order_items ,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil) def print_slip(oqs, order, order_items ,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
if pdf_status.nil? if pdf_status.nil?
printer = PrintSetting.where("shop_code='#{oqs.shop_code}'").order("id ASC") if print_settings = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
unique_code="OrderSummaryPdf" order_queue_printer = Printer::OrderQueuePrinter.new(print_settings)
order_queue_printer.print_order_summary(print_settings, oqs, order.order_id, order_items, print_status="")
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'OrderSummaryPdf'
unique_code="OrderSummaryPdf"
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
unique_code="OrderSummarySlimPdf"
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
unique_code="OrderSummarySetPdf"
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
unique_code="OrderSummaryCustomisePdf"
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
unique_code="OrderSummarySetCustomisePdf"
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
unique_code="OrderSummarySlimCustomisePdf"
end
end
end end
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,oqs.shop_code)
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings)
order_queue_printer.print_order_summary(print_settings, oqs,order.order_id, order_items, print_status="")
else else
move_print_pdf(change_to,current_user,table_id,order_items,oqs) move_print_pdf(change_to,current_user,table_id,order_items,oqs)
end end
assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id)
AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(print_status: true)
end end
#Print order_item in 1 slip per item #Print order_item in 1 slip per item
def print_slip_item(oqs, order, assigned_items,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil) def print_slip_item(oqs, order, assigned_items,pdf_status=nil,change_to=nil,current_user=nil,table_id=nil)
if pdf_status.nil? if pdf_status.nil?
printer = PrintSetting.where("shop_code='#{oqs.shop_code}'").order("id ASC")
unique_code="OrderItemPdf"
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'OrderItemPdf'
unique_code="OrderItemPdf"
elsif printer_setting.unique_code == 'OrderItemStarPdf'
unique_code="OrderItemStarPdf"
elsif printer_setting.unique_code == 'OrderItemSlimPdf'
unique_code="OrderItemSlimPdf"
elsif printer_setting.unique_code == 'OrderSetItemPdf'
unique_code="OrderSetItemPdf"
elsif printer_setting.unique_code == 'OrderItemCustomisePdf'
unique_code="OrderItemCustomisePdf"
elsif printer_setting.unique_code == 'OrderSetItemCustomisePdf'
unique_code="OrderSetItemCustomisePdf"
elsif printer_setting.unique_code == 'OrderItemSlimCustomisePdf'
unique_code="OrderItemSlimCustomisePdf"
end
end
end
# order_item = OrderItem.where("order_id='#{assigned_item.order_id}' AND item_instance_code='#{assigned_item.instance_code}'").first() # order_item = OrderItem.where("order_id='#{assigned_item.order_id}' AND item_instance_code='#{assigned_item.instance_code}'").first()
# print when complete click # print when complete click
print_settings=PrintSetting.find_by_unique_code_and_shop_code(unique_code,oqs.shop_code) if print_settings = PrintSetting.where("unique_code REGEXP ?", "order.*item.*pdf").first
order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) order_queue_printer = Printer::OrderQueuePrinter.new(print_settings)
if !assigned_items.nil? if !assigned_items.nil?
assigned_items.each do |order_item| assigned_items.each do |order_item|
order_queue_printer.print_order_item(print_settings, oqs,order_item.order_id, order_item.order_items_id, print_status="" ) order_queue_printer.print_order_item(print_settings, oqs,order_item.order_id, order_item.order_items_id, print_status="" )
end
end end
end end
else else
move_print_pdf(change_to,current_user,table_id,assigned_items,oqs) move_print_pdf(change_to,current_user,table_id,assigned_items,oqs)
end end
assigned =AssignedOrderItem.where("order_id = '#{ order.order_id }'").pluck(:assigned_order_item_id)
AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(print_status: true)
end end
def move_print_pdf(change_to,current_user,change_from,order_items,oqs) def move_print_pdf(change_to,current_user,change_from,order_items,oqs)
@@ -299,7 +185,7 @@ class OrderQueueStation < ApplicationRecord
@date = DateTime.now @date = DateTime.now
@shop = Shop.current_shop @shop = Shop.current_shop
unique_code = "MoveTablePdf" unique_code = "MoveTablePdf"
# pdf_no = PrintSetting.where(:unique_code => unique_code).count # pdf_no = PrintSetting.where(:unique_code => unique_code).count
print_settings = PrintSetting.find_by_unique_code(unique_code) print_settings = PrintSetting.find_by_unique_code(unique_code)
# printer_array = [] # printer_array = []

View File

@@ -1,41 +1,18 @@
class Printer::OrderQueuePrinter < Printer::PrinterWorker class Printer::OrderQueuePrinter < Printer::PrinterWorker
def print_order_item(print_settings,oqs, order_id, order_item_id, print_status, before_updated_qty="", options="") def print_order_item(print_settings, oqs, order_id, order_item_id, print_status, before_updated_qty="", options="")
# Must be one print # Must be one print
if print_settings.print_copies == 0 if print_settings.print_copies == 0
print_settings.print_copies = 1 print_settings.print_copies = 1
print_settings.save! print_settings.save!
end end
order_item = print_query('order_item', order_item_id) #OrderItem.find_by_item_code(item_code) order_item = print_query('order_item', order_item_id) #OrderItem.find_by_item_code(item_code)
options = order_item[0].options options = order_item[0].options
# filename = "tmp/order_item_#{order_id}_#{order_item_id}" + ".pdf"
# pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
print_setting = PrintSetting.all
# check for item not to show # check for item not to show
pdf = ''
# if order_item[0].price != 0 # if order_item[0].price != 0
if !print_setting.empty? pdf = print_settings.unique_code.constantize.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
print_setting.each do |print_settings|
if print_settings.unique_code == 'OrderItemPdf'
pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
elsif print_settings.unique_code == 'OrderItemStarPdf'
pdf = OrderItemStarPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
elsif print_settings.unique_code == 'OrderItemSlimPdf'
pdf = OrderItemSlimPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
elsif print_settings.unique_code == 'OrderSetItemPdf'
pdf = OrderSetItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
elsif print_settings.unique_code == 'OrderItemCustomisePdf'
pdf = OrderItemCustomisePdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
elsif print_settings.unique_code == 'OrderSetItemCustomisePdf'
pdf = OrderSetItemCustomisePdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
elsif print_settings.unique_code == 'OrderItemSlimCustomisePdf'
pdf = OrderItemSlimCustomisePdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
end
end
end
# end # end
@@ -47,28 +24,18 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
pdf.render_file filename pdf.render_file filename
if oqs.print_copy if ENV["SERVER_MODE"] != "cloud"
#no print in cloud server self.print(filename, oqs.printer_name)
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
end
#For print copy
# pdf.render_file filename.gsub(".","-copy.")
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
else
print_settings.print_copies = 1
print_settings.save!
#no print in cloud server
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
end
end end
#For print copy
# pdf.render_file filename.gsub(".","-copy.")
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
return filename, order_id, oqs.printer_name return filename, order_id, oqs.printer_name
end end
# Query for per order # Query for per order
def print_order_summary(print_settings,oqs, order_id, order_items, print_status, before_updated_qty="", options="") def print_order_summary(print_settings, oqs, order_id, order_items, print_status, before_updated_qty="", options="")
#Use CUPS service #Use CUPS service
#Generate PDF #Generate PDF
#Print #Print
@@ -78,113 +45,56 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
print_settings.save! print_settings.save!
end end
print_setting = PrintSetting.all.order("id ASC") shop = Shop.current_shop
order=print_query('order_summary', order_id) directory_name = "public/orders_#{shop.shop_code}"
# shop = Shop.current_shop
directory_name = 'public/orders_'+ oqs.shop_code
Dir.mkdir(directory_name) unless File.exists?(directory_name) Dir.mkdir(directory_name) unless File.exists?(directory_name)
# For Print Per Item # For Print Per Item
if oqs.cut_per_item if oqs.cut_per_item
order_items.each do|odi| order_items.each do |odi|
odi_item=print_query('order_item', odi.order_items_id) odi_item = print_query('order_item', odi.order_items_id)
filename = directory_name + "/order_item_#{order_id}" + ".pdf" filename = directory_name + "/order_item_#{order_id}.pdf"
# filename = "tmp/order_item_#{order_id}" + ".pdf" # filename = "tmp/order_item_#{order_id}" + ".pdf"
# For Item Options # For Item Options
options = odi.options == "[]"? "" : odi.options options = odi.options == "[]" ? "" : odi.options
# check for item not to show # check for item not to show
#if odi.price != 0 #if odi.price != 0
pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) pdf = print_settings.unique_code.constantize.new(print_settings, odi_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
if !print_setting.empty?
print_setting.each do |print_settings|
if print_settings.unique_code == 'OrderItemPdf'
pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderItemStarPdf'
pdf = OrderItemStarPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty)
elsif print_settings.unique_code == 'OrderItemSlimPdf'
pdf = OrderItemSlimPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSetItemPdf'
pdf = OrderSetItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderItemCustomisePdf'
pdf = OrderItemCustomisePdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSetItemCustomisePdf'
pdf = OrderSetItemCustomisePdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderItemSlimCustomisePdf'
pdf = OrderItemSlimCustomisePdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty)
end
end
end
# pdf.render_file "tmp/order_item.pdf" # pdf.render_file "tmp/order_item.pdf"
pdf.render_file filename pdf.render_file filename
if oqs.print_copy #no print in cloud server
#no print in cloud server if ENV["SERVER_MODE"] != "cloud"
if ENV["SERVER_MODE"] != "cloud" self.print(filename, oqs.printer_name)
self.print(filename, oqs.printer_name) # self.print(filename.gsub(".","-copy."), oqs.printer_name)
# self.print(filename.gsub(".","-copy."), oqs.printer_name) end
end
else
print_settings.print_copies = 1
print_settings.save!
#no print in cloud server
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
end
end
#end #end
end end
# For Print Order Summary # For Print Order Summary
else else
filename = directory_name + "/order_summary_#{order_id}" + ".pdf" order = print_query('order_summary', order_id)
filename = directory_name + "/order_summary_#{order_id}.pdf"
# filename = "tmp/order_summary_#{order_id}" + ".pdf" # filename = "tmp/order_summary_#{order_id}" + ".pdf"
pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) pdf = print_settings.unique_code.constantize.new(print_settings, order, print_status, order_items, oqs.use_alternate_name, before_updated_qty)
if !print_setting.empty?
print_setting.each do |print_settings|
if print_settings.unique_code == 'OrderSummaryPdf'
pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSummarySlimPdf'
pdf = OrderSummarySlimPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSummarySetPdf'
pdf = OrderSummarySetPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSummaryCustomisePdf'
pdf = OrderSummaryCustomisePdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSummarySetCustomisePdf'
pdf = OrderSummarySetCustomisePdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSummarySlimCustomisePdf'
pdf = OrderSummarySlimCustomisePdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty)
end
end
end
pdf.render_file filename pdf.render_file filename
if oqs.print_copy #no print in cloud server
#no print in cloud server if ENV["SERVER_MODE"] != "cloud"
if ENV["SERVER_MODE"] != "cloud" self.print(filename, oqs.printer_name)
self.print(filename, oqs.printer_name)
end
#For print copy
# pdf.render_file filename.gsub(".","-copy.")
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
else
print_settings.print_copies = 1
print_settings.save!
#no print in cloud server
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
end
end end
#For print copy
# pdf.render_file filename.gsub(".","-copy.")
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
end end
return filename, order_id, oqs.printer_name return filename, order_id, oqs.printer_name
end end
# Print for orders in booking # Print for orders in booking
def print_booking_summary(print_settings,oqs, booking_id, print_status,before_updated_qty="") def print_booking_summary(print_settings, oqs, booking_id, print_status,before_updated_qty="")
# Must be one print # Must be one print
if print_settings.print_copies == 0 if print_settings.print_copies == 0
print_settings.print_copies = 1 print_settings.print_copies = 1
@@ -193,7 +103,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
print_setting = PrintSetting.all.order("id ASC") print_setting = PrintSetting.all.order("id ASC")
order=print_query('booking_summary', booking_id) order = print_query('booking_summary', booking_id)
# shop = Shop.current_shop # shop = Shop.current_shop
@@ -210,72 +120,10 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
# check for item not to show # 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,before_updated_qty) pdf = print_settings.unique_code.constantize.new(print_settings, odi, print_status, options, oqs.use_alternate_name, before_updated_qty)
if !print_setting.empty?
print_setting.each do |print_settings|
if print_settings.unique_code == 'OrderItemPdf'
pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderItemStarPdf'
pdf = OrderItemStarPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderItemSlimPdf'
pdf = OrderItemSlimPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSetItemPdf'
pdf = OrderSetItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderItemCustomisePdf'
pdf = OrderItemCustomisePdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSetItemCustomisePdf'
pdf = OrderSetItemCustomisePdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderItemSlimCustomisePdf'
pdf = OrderItemSlimCustomisePdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty)
end
end
end
pdf.render_file filename
if oqs.print_copy pdf.render_file filename
#no print in cloud server
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
end
#For print copy
# pdf.render_file filename.gsub(".","-copy.")
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
else
print_settings.print_copies = 1
print_settings.save!
#no print in cloud server
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
end
end
#end
end
# For Print Order Summary
else
# filename = "tmp/booking_summary_#{booking_id}" + ".pdf"
filename = directory_name + "/booking_summary_#{booking_id}" + ".pdf"
pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
if !print_setting.empty?
print_setting.each do |print_settings|
if print_settings.unique_code == 'OrderSummaryPdf'
pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSummarySlimPdf'
pdf = OrderSummarySlimPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSummarySetPdf'
pdf = OrderSummarySetPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSummaryCustomisePdf'
pdf = OrderSummaryCustomisePdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSummarySetCustomisePdf'
pdf = OrderSummarySetCustomisePdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
elsif print_settings.unique_code == 'OrderSummarySlimCustomisePdf'
pdf = OrderSummarySlimCustomisePdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty)
end
end
end
pdf.render_file filename
if oqs.print_copy
#no print in cloud server #no print in cloud server
if ENV["SERVER_MODE"] != "cloud" if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name) self.print(filename, oqs.printer_name)
@@ -283,50 +131,45 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
#For print copy #For print copy
# pdf.render_file filename.gsub(".","-copy.") # pdf.render_file filename.gsub(".","-copy.")
# self.print(filename.gsub(".","-copy."), oqs.printer_name) # self.print(filename.gsub(".","-copy."), oqs.printer_name)
else #end
print_settings.print_copies = 1
print_settings.save!
#no print in cloud server
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
end
end end
# For Print Order Summary
else
# filename = "tmp/booking_summary_#{booking_id}" + ".pdf"
filename = directory_name + "/booking_summary_#{booking_id}" + ".pdf"
pdf = print_settings.unique_code.constantize.new(print_settings, order, print_status, oqs.use_alternate_name, before_updated_qty)
pdf.render_file filename
#no print in cloud server
if ENV["SERVER_MODE"] != "cloud"
self.print(filename, oqs.printer_name)
end
#For print copy
# pdf.render_file filename.gsub(".","-copy.")
# self.print(filename.gsub(".","-copy."), oqs.printer_name)
end end
return filename, booking_id, oqs.printer_name return filename, booking_id, oqs.printer_name
end end
# Query for OQS with status # Query for OQS with status
def print_query(type, id) def print_query(type, id)
query = 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, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name")
.joins("left join orders ON orders.order_id = order_items.order_id")
.joins("left join booking_orders AS bo ON bo.order_id=order_items.order_id")
.joins("left join bookings AS b ON b.booking_id = bo.booking_id")
.joins("left join dining_facilities AS df ON df.id = b.dining_facility_id")
.joins("left join customers as cus ON cus.customer_id = orders.customer_id")
.joins("left join menu_items as item ON item.item_code = order_items.item_code")
if type == "order_item" if type == "order_item"
OrderItem.select("orders.source,cus.contact_no,rder_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, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name") query.where("order_items.order_items_id = ?", id)
.joins("left join orders ON orders.order_id = order_items.order_id
left join booking_orders AS bo ON bo.order_id=order_items.order_id
left join bookings AS b ON b.booking_id = bo.booking_id
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.order_items_id = '#{ id }'")
.group("order_items.item_code") .group("order_items.item_code")
elsif type == "order_summary" elsif type == "order_summary"
OrderItem.select("orders.source,cus.contact_no,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, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name") query.where("orders.order_id = ?", id)
.joins("left join orders ON orders.order_id = order_items.order_id
left join booking_orders AS bo ON bo.order_id=order_items.order_id
left join bookings AS b ON b.booking_id = bo.booking_id
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 }'")
.group("order_items.order_items_id") .group("order_items.order_items_id")
else else
# order summary for booking # order summary for booking
OrderItem.select("orders.source,cus.contact_no,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, order_items.set_menu_items, cus.name as customer, df.type, df.name as dining,item.alt_name as alt_name") query.where("b.booking_id = ?", id)
.joins("left join orders ON orders.order_id = order_items.order_id
left join booking_orders AS bo ON bo.order_id=order_items.order_id
left join bookings AS b ON b.booking_id = bo.booking_id
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 }'")
end end
end end

View File

@@ -37,21 +37,22 @@ class Printer::PrinterWorker
Cups.default_printer Cups.default_printer
end end
def print(file_path,printer_destination = nil ) def self.printer_exists?(printer)
# if printer_destination.nil? Cups.show_destinations.include? printer
# printer_destination = self.printer_destination end
# end
# def print(file_path, printer_destination = nil )
# puts printer_destination if printer_destination.nil?
# puts '........Printer Destination..........' printer_destination = self.printer_destination
# end
# copy = self.print_copies
# #Print only when printer information is not null copy = self.print_copies
# if !self.printer_destination.nil? #Print only when printer information is not null
# (1..copy).each do if !self.printer_destination.nil?
# page = Cups::PrintJob.new(file_path, printer_destination) (1..copy).each do
# page.print page = Cups::PrintJob.new(file_path, printer_destination)
# end page.print
# end end
end
end end
end end

View File

@@ -4,26 +4,9 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
#Use CUPS service #Use CUPS service
#Generate PDF #Generate PDF
#Print #Print
printer = PrintSetting.all printer = PrintSetting.where("unique_code REGEXP ?", "order.*item.*pdf").first
pdf = OrderItemPdf.new pdf = printer.unique_code.constantize.new
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'OrderItemPdf'
pdf = OrderItemPdf.new
elsif printer_setting.unique_code == 'OrderItemSlimPdf'
pdf = OrderItemSlimPdf.new
elsif printer_setting.unique_code == 'OrderSetItemPdf'
pdf = OrderSetItemPdf.new
elsif printer_setting.unique_code == 'OrderItemCustomisePdf'
pdf = OrderItemCustomisePdf.new
elsif printer_setting.unique_code == 'OrderSetItemCustomisePdf'
pdf = OrderSetItemCustomisePdf.new
elsif printer_setting.unique_code == 'OrderItemSlimCustomisePdf'
pdf = OrderItemSlimCustomisePdf.new
end
end
end
pdf.render_file "tmp/order_item_queue_#{order_id}_#{order_item_id}" + ".pdf" pdf.render_file "tmp/order_item_queue_#{order_id}_#{order_item_id}" + ".pdf"
#no print in cloud server #no print in cloud server
if ENV["SERVER_MODE"] != "cloud" if ENV["SERVER_MODE"] != "cloud"
@@ -36,26 +19,9 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
#Generate PDF #Generate PDF
#Print #Print
filename = "tmp/order_summary_#{booking_id}" + ".pdf" filename = "tmp/order_summary_#{booking_id}" + ".pdf"
printer = PrintSetting.all printer = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
pdf = OrderSummaryPdf.new pdf = printer.unique_code.constantize.new
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'OrderSummaryPdf'
pdf = OrderSummaryPdf.new
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
pdf = OrderSummarySlimPdf.new
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
pdf = OrderSummarySetPdf.new
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
pdf = OrderSummaryCustomisePdf.new
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
pdf = OrderSummarySetCustomisePdf.new
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
pdf = OrderSummarySlimCustomisePdf.new
end
end
end
pdf.render_file filename pdf.render_file filename
#no print in cloud server #no print in cloud server
if ENV["SERVER_MODE"] != "cloud" if ENV["SERVER_MODE"] != "cloud"
@@ -67,26 +33,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
#Use CUPS service #Use CUPS service
#Generate PDF #Generate PDF
#Print #Print
printer = PrintSetting.all printer = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
filename = "tmp/order_summary_#{booking_id}" + ".pdf" filename = "tmp/order_summary_#{booking_id}" + ".pdf"
pdf = OrderSummaryPdf.new pdf = printer.unique_code.constantize.new
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'OrderSummaryPdf'
pdf = OrderSummaryPdf.new
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
pdf = OrderSummarySlimPdf.new
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
pdf = OrderSummarySetPdf.new
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
pdf = OrderSummaryCustomisePdf.new
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
pdf = OrderSummarySetCustomisePdf.new
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
pdf = OrderSummarySlimCustomisePdf.new
end
end
end
pdf.render_file filename pdf.render_file filename
#no print in cloud server #no print in cloud server
if ENV["SERVER_MODE"] != "cloud" if ENV["SERVER_MODE"] != "cloud"
@@ -98,26 +48,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
#Use CUPS service #Use CUPS service
#Generate PDF #Generate PDF
#Print #Print
printer = PrintSetting.all printer = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
filename = "tmp/order_summary_#{booking_id}" + ".pdf" filename = "tmp/order_summary_#{booking_id}" + ".pdf"
pdf = OrderSummaryPdf.new pdf = printer.unique_code.constantize.new
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'OrderSummaryPdf'
pdf = OrderSummaryPdf.new
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
pdf = OrderSummarySlimPdf.new
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
pdf = OrderSummarySetPdf.new
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
pdf = OrderSummaryCustomisePdf.new
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
pdf = OrderSummarySetCustomisePdf.new
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
pdf = OrderSummarySlimCustomisePdf.new
end
end
end
pdf.render_file filename pdf.render_file filename
#no print in cloud server #no print in cloud server
if ENV["SERVER_MODE"] != "cloud" if ENV["SERVER_MODE"] != "cloud"
@@ -129,26 +63,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
#Use CUPS service #Use CUPS service
#Generate PDF #Generate PDF
#Print #Print
printer = PrintSetting.all printer = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
filename = "tmp/order_summary_#{booking_id}" + ".pdf" filename = "tmp/order_summary_#{booking_id}" + ".pdf"
pdf = OrderSummaryPdf.new pdf = printer.unique_code.constantize.new
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'OrderSummaryPdf'
pdf = OrderSummaryPdf.new
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
pdf = OrderSummarySlimPdf.new
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
pdf = OrderSummarySetPdf.new
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
pdf = OrderSummaryCustomisePdf.new
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
pdf = OrderSummarySetCustomisePdf.new
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
pdf = OrderSummarySlimCustomisePdf.new
end
end
end
pdf.render_file filename pdf.render_file filename
#no print in cloud server #no print in cloud server
if ENV["SERVER_MODE"] != "cloud" if ENV["SERVER_MODE"] != "cloud"
@@ -160,26 +78,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
#Use CUPS service #Use CUPS service
#Generate PDF #Generate PDF
#Print #Print
printer = PrintSetting.all printer = PrintSetting.where("unique_code REGEXP ?", "order.*summary.*pdf").first
filename = "tmp/order_summary_#{booking_id}" + ".pdf" filename = "tmp/order_summary_#{booking_id}" + ".pdf"
pdf = OrderSummaryPdf.new pdf = printer.unique_code.constantize.new
if !printer.empty?
printer.each do |printer_setting|
if printer_setting.unique_code == 'OrderSummaryPdf'
pdf = OrderSummaryPdf.new
elsif printer_setting.unique_code == 'OrderSummarySlimPdf'
pdf = OrderSummarySlimPdf.new
elsif printer_setting.unique_code == 'OrderSummarySetPdf'
pdf = OrderSummarySetPdf.new
elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf'
pdf = OrderSummaryCustomisePdf.new
elsif printer_setting.unique_code == 'OrderSummarySetCustomisePdf'
pdf = OrderSummarySetCustomisePdf.new
elsif printer_setting.unique_code == 'OrderSummarySlimCustomisePdf'
pdf = OrderSummarySlimCustomisePdf.new
end
end
end
pdf.render_file filename pdf.render_file filename
#no print in cloud server #no print in cloud server
if ENV["SERVER_MODE"] != "cloud" if ENV["SERVER_MODE"] != "cloud"
@@ -192,32 +94,12 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
#Use CUPS service #Use CUPS service
#Generate PDF #Generate PDF
#Print #Print
puts printer_settings.to_json if printer_settings
if !printer_settings.nil? if !printer_settings.unique_code.match?(/receiptbillorder/i)
if !printer_settings.unique_code.strip.downcase.include? ("receiptbillorder") if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf
pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,transaction_ref) pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
settings = PrintSetting.where("shop_code='#{shop_details.shop_code}'") else
if !settings.nil? pdf = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code.constantize.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
settings.each do |setting|
if setting.unique_code == 'ReceiptBillPdf'
pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,transaction_ref)
elsif setting.unique_code == 'ReceiptBillStarPdf'
pdf = ReceiptBillStarPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,transaction_ref)
end
end
end
receipt_bill_a5_pdf = Lookup.where("shop_code='#{shop_details.shop_code}'").collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
if !receipt_bill_a5_pdf.empty?
receipt_bill_a5_pdf.each do |receipt_bilA5|
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
if receipt_bilA5[1] == '1'
pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,transaction_ref)
# else
# 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,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount)
end
end
end
end end
else else
#doemal online order pdf template #doemal online order pdf template

View File

@@ -5,29 +5,23 @@ class Product < ApplicationRecord
mount_uploader :image_path, ProductImageUploader mount_uploader :image_path, ProductImageUploader
def self.search_by_product_code(item_code) def self.search_by_product_code(item_code)
account = Account.find_by_title('Product') Product.joins("JOIN accounts ON accounts.title = 'Product'")
if !account.nil? .where(item_code: item_code)
account_id = account.id .pluck("accounts.id AS account_id", :item_code, :name, :alt_name, :unit_price, :taxable)
else .map { |account_id, item_code, item_name, item_alt_name, price, taxable|
account_id = 1 {
end type: 'Product',
account_id: account_id,
menu_item_hash = Hash.new item_code: item_code,
mt_instance = Product.find_by_item_code(item_code) item_instance_code: item_code,
if (!mt_instance.nil?) name: "#{item_name}",
menu_item_hash[:type] = 'Product' alt_name: "#{item_name}",
menu_item_hash[:account_id] = account_id price: price,
menu_item_hash[:item_code] = mt_instance.item_code promotion_price: 0,
menu_item_hash[:item_instance_code] = mt_instance.item_code is_on_promotion: 0,
menu_item_hash[:name] = mt_instance.name.to_s is_available: 0,
menu_item_hash[:alt_name] = mt_instance.alt_name.to_s taxable: taxable
menu_item_hash[:price] = mt_instance.unit_price }
menu_item_hash[:promotion_price] = 0 }
menu_item_hash[:is_on_promotion] = 0 end
menu_item_hash[:is_available] = 0
menu_item_hash[:taxable] = mt_instance.taxable
return menu_item_hash
end
end
end end

View File

@@ -5,21 +5,25 @@ class Sale < ApplicationRecord
#primary key - need to be unique generated for multiple shops #primary key - need to be unique generated for multiple shops
before_create :generate_custom_id before_create :generate_custom_id
before_create :generate_receipt_no before_create :generate_receipt_no
belongs_to :cashier, foreign_key: "cashier_id", class_name: "Employee" belongs_to :cashier, foreign_key: "cashier_id", class_name: "Employee"
belongs_to :customer, :optional => true belongs_to :customer, :optional => true
belongs_to :shift_sale belongs_to :shift_sale
has_one :survey, foreign_key: "receipt_no" has_one :current_shift_by_cashier, through: :cashier, source: :current_shift
has_one :cashier_terminal_by_shift_sale, through: :shift_sale, source: :cashier_terminal
has_one :survey, foreign_key: "receipt_no"
has_many :sale_audits has_many :sale_audits
has_many :sale_items has_many :sale_items
has_many :sale_discount_items has_many :sale_discount_items
has_many :sale_discounts has_many :sale_discounts
has_many :sale_taxes has_many :sale_taxes
has_many :sale_payments has_many :sale_payments
has_many :payments_for_credits, through: :sale_audits
has_many :sale_orders has_many :sale_orders
has_many :sale_payments_for_credits, through: :sale_audits
has_many :orders, through: :sale_orders has_many :orders, through: :sale_orders
has_many :order_items, through: :sale_orders has_many :order_items, through: :sale_orders
has_many :bookings has_many :bookings
has_one :booking
has_many :product_commissions has_many :product_commissions
before_validation :round_to_precision before_validation :round_to_precision
@@ -31,9 +35,7 @@ class Sale < ApplicationRecord
scope :completed, -> { where(sale_status: 'completed') } scope :completed, -> { where(sale_status: 'completed') }
scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) } scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) }
scope :along_with_sale_payments_except_void_between, -> (from, to) { joins(sanitize_sql_array(["LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) } scope :along_with_sale_payments_except_void_between, -> (from, to) { joins(sanitize_sql_array(["LEFT JOIN sale_payments ON sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) }
scope :shop, -> { where("sales.shop_code=?",Shop.current_shop.shop_code) }
def qty_of(item_instance_code) def qty_of(item_instance_code)
order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first
@@ -82,186 +84,114 @@ class Sale < ApplicationRecord
Rails.logger.debug '........ Sale data sync completed .......' Rails.logger.debug '........ Sale data sync completed .......'
end end
end end
def self.generate_invoice_from_booking(booking, requested_by, cashier, order_source = nil, current_checkin_induties_count)
if booking
Rails.logger.debug "Booking -> " + booking.id.to_s
Rails.logger.debug "Booking -> Booking Order Count -> " + booking.booking_orders.count.to_s
#get all order attached to this booking and combine into 1 invoice
unless sale = booking.sale def self.generate_invoice_from_booking(booking, requested_by, cashier, order_source = nil, in_duties_count = 0)
sale = booking.build_sale( Sale.transaction do
if booking
current = Time.now
#get all order attached to this booking and combine into 1 invoice
sale = booking.sale || booking.build_sale(
{ {
tax_type: "execulive" # Default Tax - Values tax_type: "execulive" # Default Tax - Values
} }
) )
end
booking.booking_orders.each do |order|
sale.generate_invoice_from_order(order.order_id, booking, requested_by, cashier, order_source)
# saleObj = Sale.find(sale_id)
# order = booking.booking_orders.take.order
# link_order_sale(order.order_id)
end
# InventoryJob.perform_now(self.id)
# InventoryDefinition.calculate_product_count(saleObj)
if cashier.role == 'cashier'
# dining charges sale.cashier = cashier
charges = DiningCharge.where('dining_facility_id=?', booking.dining_facility_id).take sale.shift_sale = cashier.current_shift
if !charges.nil? elsif booking.dining_facility
block_count, diningprice = DiningCharge.amount_calculate(charges, booking.checkin_at, booking.checkout_at) if sale.shift_sale = booking.current_shift_by_dining_facility
if charges.charge_type =='hr' sale.cashier = sale.shift_sale.employee
dining_time = booking.checkin_at.strftime('%H:%M %p').to_s + " - " + booking.checkout_at.strftime('%H:%M %p').to_s
else
dining_time = booking.checkin_at.strftime('%B %d, %H:%M %p').to_s + " - " + booking.checkout_at.strftime('%B %d, %H:%M %p').to_s
end
later_time = booking.checkout_at
early_time = booking.checkin_at
distance_in_minutes = ((later_time - early_time)/60.0).round
basic_pay_amount = 0
name = ""
if current_checkin_induties_count != "0"
basic_pay = Commission.where('commission_type=?','Basic Pay')
basic_pay.each do |pay|
basic_pay_amount = pay.amount
name = pay.name
end
induties_pay_amount = (current_checkin_induties_count.to_i * (distance_in_minutes / 60.0).to_f * basic_pay_amount).to_i
sale.create_saleitem_indutycharges(charges, current_checkin_induties_count.to_i, induties_pay_amount, booking.dining_facility.name, dining_time, order_source, basic_pay_amount)
end
sale.create_saleitem_diningcharges(charges, block_count, diningprice, booking.dining_facility.name, dining_time, order_source)
end
return sale
end
end
def generate_invoice_from_order(order_id, booking, requested_by, cashier = nil, order_source = nil)
taxable = true
order = Order.find(order_id)
# current cashier login
open_cashier = Employee.where("role = 'cashier' AND token_session <> ''")
current_shift = ShiftSale.current_shift
# shift with terminal zone
# set cashier
if order_source.present? && order_source.downcase == "emenu"
if !booking.dining_facility_id.nil?
table = DiningFacility.find(booking.dining_facility_id)
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{cashier_zone.cashier_terminal_id}").first
#for multiple zone with terminal
if shift.nil?
multiple_zone = CashierTerminalByZone.where("zone_id = #{table.zone_id}")
multiple_zone.each do |zone|
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and cashier_terminal_id = #{zone.cashier_terminal_id}").first
if !shift.nil? then
break
end
end end
end end
end
else if sale.shift_sale.nil?
shift = ShiftSale.current_open_shift(cashier) if sale.cashier = Employee.where(role: 'cashier').where.not(token_session: [nil, '']).first
end sale.shift_sale = sale.current_shift_by_cashier
# set cashier
if shift != nil #if current login employee open shift
self.cashier_id = cashier.id
self.cashier_name = cashier.name
self.shift_sale_id = shift.id
else
if open_cashier.count>0 # if we have two open cashier
# table and terminal in multiple shift
self.cashier_id = open_cashier[0].id
self.cashier_name = open_cashier[0].name
shift_id = ShiftSale.current_open_shift(open_cashier[0])
if shift_id
self.shift_sale_id = shift_id.id
else else
self.shift_sale_id = current_shift.id sale.shift_sale = ShiftSale.current_shift
sale.cashier = sale.shift_sale.employee
end end
else
self.cashier_id = current_shift.employee_id
self.cashier_name = Employee.find(current_shift.employee_id).name
self.shift_sale_id = current_shift.id
end
end
# set waiter
self.requested_by = requested_by.name
self.requested_at = DateTime.now.utc.getlocal
self.shop_code = Shop.current_shop.shop_code
Rails.logger.debug "Order -> #{order.id} | order_status -> #{order.status}"
if order
self.customer_id = order.customer_id
Rails.logger.debug "Order -> #{order.id} | Items Count -> #{order.order_items.count}"
order.order_items.each do |item|
self.add_item(item)
if !item.set_menu_items.nil?
self.add_sub_item(item.set_menu_items)
end end
sale.cashier_name = sale.cashier.name
sale.requested_by = requested_by.name
sale.requested_at = current
sale.sale_items << booking.order_items.to_sale_items
if booking.dining_facility.present? && dining_charge = booking.dining_facility.dining_charge
block_count, dining_price = DiningCharge.amount_calculate(dining_charge, booking.checkin_at, booking.checkout_at)
format = "%I:%M %p" if dining_charge.charge_type == "hr"
format ||= "%B %d, %I:%M %p"
dining_time = "#{booking.checkin_at.strftime(format)} - #{booking.checkout_at.strftime(format)}"
sale.sale_items.build({
menu_category_name: "Dining Charge",
menu_category_code: "DiningCharge",
product_name: "#{booking.dining_facility.name} ( #{dining_time} )",
product_code: dining_charge.item_code,
product_alt_name: '-',
account_id: 0,
is_taxable: dining_charge.taxable,
qty: block_count,
unit_price: dining_charge.unit_price,
price: dining_price,
taxable_price: dining_price,
})
if in_duties_count.to_i > 0
basic_pay = Commission.find_by(commission_type: 'Basic Pay')
in_duties_pay_amount = (in_duties_count.to_i * ((booking.checkout_at - booking.checkin_at) / 1.hours) * basic_pay_amount).to_i
sale.sale_items.build({
menu_category_name: "Induty Charge",
menu_category_code: "IndutyCharge",
product_name: "#{basic_pay.name} ( #{dining_time} )",
product_code: "",
product_alt_name: '-',
account_id: 0,
is_taxable: dining_charge.taxable,
qty: in_duties_count,
unit_price: basic_pay.amount,
price: in_duties_pay_amount,
taxable_price: in_duties_pay_amount,
})
end
end
sale.orders << booking.orders
sale.customer_id = booking.orders[0].customer_id
sale.compute(booking.orders[0].source)
booking.orders.update_all(status: "billed")
booking.order_items.update_all(order_item_status: "billed")
booking.checkout_at = current unless booking.checkout_at && booking.checkout_at > current
booking.checkout_by = requested_by.name
booking.save
return sale
end end
self.orders << order
end end
#compute sales summary
if order_source.nil?
order_source = order.source
end
self.compute(order_source)
#Update the order items that is billed
order.update_items_status_to_billed(nil)
order.status = "billed"
order.save
if !booking.checkout_at.nil?
if booking.checkout_at.utc < Time.now.utc
booking.checkout_at = Time.now.utc.getlocal
end
else
booking.checkout_at = Time.now.utc.getlocal
end
booking.checkout_by = requested_by.name
booking.save
# InventoryJob.perform_now(self.id)
# saleObj = Sale.find(self.id)
# InventoryDefinition.calculate_product_count(saleObj)
return self
end end
#fOR Quick Service pay and create #fOR Quick Service pay and create
def self.request_bill(order,current_user,current_login_employee) def self.request_bill(order, current_user, current_login_employee)
if !ShiftSale.current_shift.nil? if !ShiftSale.current_shift.nil?
order_id = order.order_id # order_id order_id = order.order_id # order_id
bk_order = BookingOrder.find_by_order_id(order_id) booking = order.booking
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
if @sale_data = check_booking.sale if booking.sale.nil?
# Create Sale if it doesn't exist sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source)
@sale_items = SaleItem.where("sale_id=?",@sale_id) # Promotion Activation
elsif @sale_data = Sale.generate_invoice_from_booking(check_booking,current_login_employee,current_user,order.source) Promotion.promo_activate(sale_data)
@sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id)
end end
# Bind shift sale id to sale return true, sale_data
# @sale_data.shift_sale_id = shift.id
# @sale_data.save
# Promotion Activation
Promotion.promo_activate(@sale_data)
@status = true
return @status, @sale_data
else else
@status = false return false, "No Current Open Shift for This Employee"
@message = "No Current Open Shift for This Employee"
end end
end end
#This is when spilt bill is request - then we cannot link order to invoice #This is when spilt bill is request - then we cannot link order to invoice
@@ -532,6 +462,19 @@ class Sale < ApplicationRecord
end end
tax_profiles = unique_tax_profiles(order_source, self.customer_id) tax_profiles = unique_tax_profiles(order_source, self.customer_id)
if tax_type.nil?
if tax_profiles.count == 2
tax_type = "all"
elsif tax_profiles.count == 1
if tax_profiles.name.downcase == "service charges"
tax_type = "Service Charges"
else
tax_type = "Commercial Tax"
end
elsif tax_profiles.count < 1
tax_type = "no_tax"
end
end
# #Creat new tax records # #Creat new tax records
if self.payment_status != 'foc' && tax_type.to_s == "all" if self.payment_status != 'foc' && tax_type.to_s == "all"
@@ -690,14 +633,6 @@ class Sale < ApplicationRecord
self.total_tax = total_tax_amount self.total_tax = total_tax_amount
end end
def product_get_unit_price(item_code)
menu_item_hash =MenuItem.search_by_item_code(item_code)
if (menu_instance_code)
return menu_ item_hash[:item_instance_code], menu_item_hash[:price]
end
return nil,nil
end
def link_order_sale(order_id) def link_order_sale(order_id)
#create if it doesn't exist #create if it doesn't exist
saleOrder = SaleOrder.where("sale_id=? and order_id=?", self.id, order_id).take saleOrder = SaleOrder.where("sale_id=? and order_id=?", self.id, order_id).take
@@ -861,11 +796,15 @@ def self.daily_sales_list(from,to)
daily_total = connection.select_all("SELECT daily_total = connection.select_all("SELECT
IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total, IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total,
IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as total_sale,
IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total, IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total,
IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount, IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount,
IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount, IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount,
IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount, IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount,
IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj, IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj,
IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21 as tax,
(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0))-(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale,
(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale,
CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
SUM(kbzpay_amount) as kbzpay_amount, SUM(kbzpay_amount) as kbzpay_amount,
SUM(mpu_amount) as mpu_amount, SUM(mpu_amount) as mpu_amount,
@@ -1129,7 +1068,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
end end
def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_type,customer_id,shop_code) def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account_type, customer_id)
# date_type_selection = get_sql_function_for_report_type(report_type) # date_type_selection = get_sql_function_for_report_type(report_type)
if account_type.blank? if account_type.blank?
account_type = '' account_type = ''
@@ -1141,8 +1080,6 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_
customer_id = customer_id.to_s customer_id = customer_id.to_s
customer_id[0] = "" customer_id[0] = ""
customer_id = customer_id.chomp("]") customer_id = customer_id.chomp("]")
else
customer_id = '"CUS-000000000000"'
end end
query = self.get_staff_meal_query() query = self.get_staff_meal_query()
@@ -1299,7 +1236,7 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay
.includes(:bookings => :dining_facility) .includes(:bookings => :dining_facility)
.select("sales.*, SUM(sale_payments.payment_amount) AS payments_for_credits_amount") .select("sales.*, SUM(sale_payments.payment_amount) AS payments_for_credits_amount")
.joins(:bookings) .joins(:bookings)
.left_joins(:sale_payments_for_credits) .left_joins(:payments_for_credits)
.completed .completed
.where.not(total_amount: 0) .where.not(total_amount: 0)
.group(:sale_id) .group(:sale_id)
@@ -1352,16 +1289,16 @@ def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,
if order_source.present? if order_source.present?
if order_source == "cashier" if order_source == "cashier"
credits = credits.where("order_sources.source IN (?)", ['cashier', 'emenu']) credits = credits.where("orders.source IN (?)", ['cashier', 'emenu'])
else else
credits = credits.where("order_sources.source = ?", order_source) credits = credits.where("orders.source = ?", order_source)
end end
end end
if filter == 'paid' if filter == 'paid'
credits = credits.where("payments_for_credits IS NOT NULL") credits = credits.where("payments_for_credits.sale_id IS NOT NULL")
elsif filter == 'unpaid' elsif filter == 'unpaid'
credits = credits.where("payments_for_credits IS NULL") credits = credits.where("payments_for_credits.sale_id IS NULL")
end end
if shift.present? if shift.present?
@@ -1428,96 +1365,57 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type)
end end
end end
def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type,shop_code) def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type)
sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) payments_total = SalePayment.select("
FROM sale_payments sales.receipt_date as sale_date,
INNER JOIN sale_audits sa SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount,
ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id SUM(case when (sale_payments.payment_method='master') then sale_payments.payment_amount else 0 end) as master_amount,
INNER JOIN sales ON sa.sale_id = sales.sale_id SUM(case when (sale_payments.payment_method='visa') then sale_payments.payment_amount else 0 end) as visa_amount,
WHERE sales.sale_status='completed' and sales.shop_code='#{shop_code}'" 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='paypar') then sale_payments.payment_amount else 0 end) as paypar_amount,
SUM(case when (sale_payments.payment_method='unionpay') then sale_payments.payment_amount else 0 end) as unionpay_amount,
SUM(case when (sale_payments.payment_method='alipay') then sale_payments.payment_amount else 0 end) as alipay_amount,
SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount,
SUM(case when (sale_payments.payment_method='paymal') then sale_payments.payment_amount else 0 end) as paymal_amount,
SUM(case when (sale_payments.payment_method='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount,
SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_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='cash') then
sales.amount_changed else 0 end) as total_change_amount,
SUM(case when (sale_payments.payment_method='creditnote') then
sale_payments.payment_amount else 0 end) -
SUM(case when (sale_audits.sale_audit_id IS NOT NULL) then
sale_payments.payment_amount else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
.joins(:sale).left_joins(:sale_audit)
.merge(Sale.completed.receipt_date_between(from, to))
sales = Sale.select(Sale.column_names)
.select("SUM(sale_payments.payment_amount) as payment_for_credits_amount")
.left_joins(:payments_for_credits)
.group(:sale_id)
sale_payment = SalePayment.select("sales.amount_changed as change_amount,sales.receipt_no, sale_payments.*, sales.receipt_date as sale_date,
sales.cashier_name as cashier_name")
.joins("JOIN (#{sales.to_sql}) as sales ON sales.sale_id = sale_payments.sale_id")
.where("sale_payments.payment_method != 'creditnote' OR payment_for_credits_amount - sale_payments.payment_amount <= 0")
.where.not(payment_amount: 0)
.merge(Sale.completed.receipt_date_between(from, to))
if shift.present? if shift.present?
shift_ids = shift.map(&:id).join(",") payments_total = payments_total.where(sales: {shift_sale_id: shift.to_a})
sub_query += " AND sales.shift_sale_id in (#{shift_ids})" sale_payment = sale_payment.merge(Sale.where(sales: {shift_sale_id: shift.to_a}))
elsif shift_sale_range.present? elsif shift_sale_range.present?
shift_ids = shift_sale_range.map(&:id).join(",") payments_total = payments_total.where(sales: {shift_sale_id: shift_sale_range.to_a})
sub_query += " AND sales.shift_sale_id in (#{shift_ids})" sale_payment = sale_payment.merge(Sale.where(sales: {shift_sale_id: shift_sale_range.to_a}))
else
sub_query += " AND sales.receipt_date between '#{from}' and '#{to}'"
end end
sub_query1 = "CASE WHEN (SELECT SUM(sale_payments.payment_amount) if payment_type.present?
FROM sale_payments sale_payment = sale_payment.where(payment_method: payment_type)
WHERE sale_payments.payment_method = 'creditnote'
AND sale_payments.sale_id = s.sale_id
) - (SELECT SUM(sale_payments.payment_amount)
FROM sale_payments
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
WHERE sale_payments.sale_id = s.sale_id) = 0
THEN sale_payments.sale_id = s.sale_id
AND sale_payments.payment_method!='creditnote' ELSE 1 END"
sale_payment = SalePayment.select("s.amount_changed as change_amount,s.receipt_no, sale_payments.*,s.receipt_date as sale_date,
s.cashier_name as cashier_name")
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.where("(#{sub_query1}) and s.shop_code='#{shop_code}'")
.order('s.receipt_no DESC')
payments_total = SalePayment.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
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='master') then sale_payments.payment_amount else 0 end) as master_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='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount,
SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_amount,
SUM(case when (sale_payments.payment_method='unionpay') then sale_payments.payment_amount else 0 end) as unionpay_amount,
SUM(case when (sale_payments.payment_method='alipay') then sale_payments.payment_amount else 0 end) as alipay_amount,
SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount,
SUM(case when (sale_payments.payment_method='paymal') then sale_payments.payment_amount else 0 end) as paymal_amount,
SUM(case when (sale_payments.payment_method='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount,
SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_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='cash') then sales.amount_changed else 0 end) as total_change_amount,
(CASE WHEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end)) > 0 THEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) - (#{sub_query})) ELSE 0 END) as credit_amount,
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
.joins("join sales on sales.sale_id = sale_payments.sale_id")
.where("sales.shop_code='#{shop_code}'")
if shift.present?
all_total = payments_total.where("sales.shift_sale_id in (?) and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a)
# .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')")
if payment_type.blank?
sale_type = sale_payment.where(" s.sale_status = 'completed' and payment_amount != 0 and s.shift_sale_id in (?)",shift.to_a)
.order("payment_method")
else
sale_type = sale_payment.where(" payment_method= '#{payment_type}' and payment_amount != 0 and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift.to_a)
end
elsif shift_sale_range.present?
all_total = payments_total.where("sales.shift_sale_id in (?) and sale_status= 'completed' and sale_payments.payment_amount != 0", shift_sale_range.to_a)
# .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')")
if payment_type.blank?
sale_type = sale_payment.where(" s.sale_status = 'completed' and payment_amount != 0 and s.shift_sale_id in (?)",shift_sale_range.to_a)
.order("payment_method")
else
sale_type = sale_payment.where(" payment_method='#{payment_type}' and payment_amount != 0 and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift_sale_range.to_a)
end
else
all_total = payments_total.where("sales.receipt_date between ? and ? and sales.sale_status= 'completed' and sale_payments.payment_amount != 0", from,to)
# .group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')")
if payment_type.blank?
sale_type = sale_payment.where(" s.sale_status = 'completed' and payment_amount != 0 and s.receipt_date between ? and ? ",from,to)
.order("payment_method")
else
sale_type = sale_payment.where(" payment_method='#{payment_type}' and payment_amount != 0 and s.sale_status = 'completed' and s.receipt_date between ? and ? ",from,to)
end
end end
return all_total,sale_type return payments_total, sale_payment
end end
def self.get_wastes_and_spoilages(from,to,status) def self.get_wastes_and_spoilages(from,to,status)
@@ -1550,10 +1448,10 @@ end
cash = 0.0 cash = 0.0
self.sale_payments.each do |pay| self.sale_payments.each do |pay|
if pay.payment_method == 'cash' if pay.payment_method == 'cash'
cash = pay.payment_amount-self.amount_changed cash += pay.payment_amount
end end
end end
return cash return cash - self.amount_changed
end end
def get_credit_amount def get_credit_amount
@@ -2130,6 +2028,7 @@ end
def unique_tax_profiles(order_source, customer_id) def unique_tax_profiles(order_source, customer_id)
tax_data = TaxProfile.where(group_type: order_source) tax_data = TaxProfile.where(group_type: order_source)
customer_tax_profiles = Customer.select(:tax_profiles).where(customer_id: customer_id).first customer_tax_profiles = Customer.select(:tax_profiles).where(customer_id: customer_id).first
if customer_tax_profiles.present? if customer_tax_profiles.present?
tax_data = tax_data.where(id: customer_tax_profiles.tax_profiles) tax_data = tax_data.where(id: customer_tax_profiles.tax_profiles)
@@ -2159,7 +2058,7 @@ def self.employee_sale(shift=nil,from=nil,to=nil,from_time=nil,to_time=nil, curr
end end
# Start hourly sale item report # Start hourly sale item report
def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,account_type,shop_code) def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,account_type,filter,start_time,end_time)
# date_type_selection = get_sql_function_for_report_type(report_type) # date_type_selection = get_sql_function_for_report_type(report_type)
if account_type.blank? if account_type.blank?
account_type = '' account_type = ''
@@ -2167,7 +2066,26 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco
account_type = " and acc.title = '#{account_type}'" account_type = " and acc.title = '#{account_type}'"
end end
query = self.get_hourly_item_query(type) if start_time.blank? || end_time.blank?
receipt_date = "sales.receipt_date between '#{from}' and '#{to}'"
query = self.get_hourly_item_query(type,filter,true)
else
start_time = Time.parse(start_time).utc
end_time = Time.parse(end_time).utc
receipt_date = "sales.receipt_date between '#{start_time}' and '#{end_time}'"
query = self.get_hourly_item_query(type,filter,false)
end
unless start_time.blank? && end_time.blank?
from_date = from.to_date
to_date = to.to_date
from_date_time = DateTime.new(from_date.year, from_date.month, from_date.day, start_time.hour, start_time.min, start_time.sec, start_time.zone)
to_date_time = DateTime.new(to_date.year, to_date.month, to_date.day, end_time.hour, end_time.min, end_time.sec, end_time.zone)
receipt_date = "sales.receipt_date between '#{from_date_time}' and '#{to_date_time}'"
query = self.get_hourly_item_query(type,filter,false)
end
# query = self.get_hourly_item_query(type,filter)
discount_query = 0 discount_query = 0
total_card_amount = 0 total_card_amount = 0
@@ -2228,7 +2146,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
else else
query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) query = query.where("#{receipt_date} #{account_type} and sale_status='completed'")
if type.nil? || type == 'all' || type == "other" if type.nil? || type == 'all' || type == "other"
other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
end end
@@ -2255,11 +2173,16 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco
return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
end end
def self.get_hourly_item_query(type) def self.get_hourly_item_query(type,filter,status)
if status
group_by = "acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price,hour"
else
group_by = "acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price"
end
check_product = "i.menu_category_name != 'product'" check_product = "i.menu_category_name != 'product'"
if type == "revenue" if type == "revenue"
sale_type = "i.qty > 0 and status IS NULL" sale_type = "i.qty > 0 and status IS NULL"
elsif type == "all" || type.nil? elsif type == "all" || type.nil? || type.empty?
sale_type = "#{check_product}" sale_type = "#{check_product}"
elsif type == "discount" elsif type == "discount"
sale_type = "#{check_product} and i.status = 'Discount'" sale_type = "#{check_product} and i.status = 'Discount'"
@@ -2287,8 +2210,8 @@ def self.get_hourly_item_query(type)
" JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id") " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id")
# "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ") # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ")
query = query.joins(" JOIN accounts acc ON acc.id = i.account_id") query = query.joins(" JOIN accounts acc ON acc.id = i.account_id")
query = query.where("#{sale_type}") query = query.where("#{sale_type} and i.product_name LIKE '%#{filter}%'" )
query = query.group("acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price,hour") query = query.group("#{group_by}")
.order("hour asc") .order("hour asc")
# query = query.order("i.menu_category_name asc, SUM(i.qty) desc") # query = query.order("i.menu_category_name asc, SUM(i.qty) desc")
end end

View File

@@ -6,7 +6,7 @@ class SaleAudit < ApplicationRecord
belongs_to :sale belongs_to :sale
belongs_to :sale_payments_for_credit, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment" belongs_to :payments_for_credit, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment"
def self.sync_sale_audit_records(sale_audits) def self.sync_sale_audit_records(sale_audits)
if !sale_audits.nil? if !sale_audits.nil?
@@ -124,6 +124,17 @@ class SaleAudit < ApplicationRecord
sale_audit.save! sale_audit.save!
end end
def self.record_audit_change_tax(sale_id, remark, action_by)
sale_audit = SaleAudit.new()
sale_audit.sale_id = sale_id
sale_audit.action = "CHANGE_TAX"
sale_audit.action_at = DateTime.now.utc
sale_audit.action_by = action_by
sale_audit.remark = remark
sale_audit.approved_by = action_by
sale_audit.save!
end
def self.paymal_search(sale_id) def self.paymal_search(sale_id)
amount = nil amount = nil
paymal = SaleAudit.where("sale_id =? and action = 'PAYMAL'",sale_id) paymal = SaleAudit.where("sale_id =? and action = 'PAYMAL'",sale_id)

View File

@@ -280,6 +280,11 @@ class SaleItem < ApplicationRecord
# Loader Service SFTP End # Loader Service SFTP End
protected
def self.generate_ids(count = 1)
SeedGenerator.generate_ids(self.name, "SLI", count)
end
private private
def generate_custom_id def generate_custom_id
if self.sale_item_id.nil? if self.sale_item_id.nil?

View File

@@ -66,32 +66,26 @@ class SalePayment < ApplicationRecord
return self.save return self.save
end end
def process_payment(invoice, action_by, cash_amount, payment_method,remark=nil,payment_for=false) def process_payment(invoice, action_by, cash_amount, payment_method, remark=nil, payment_for=false)
self.sale = invoice self.sale = invoice
self.received_amount = cash_amount self.received_amount = cash_amount
self.payment_reference = remark self.payment_reference = remark
self.action_by = action_by self.action_by = action_by
#get all payment for this invoices #get all payment for this invoices
if payment_for if payment_for
invoice_sale_payments = SalePayment.get_sale_payment_for_credit(invoice) amount_due = SalePayment.get_credit_amount_due_left(self.sale_id).first.payment_amount
amount_due = SalePayment.get_credit_amount_due_left(self.sale_id)[0] ? SalePayment.get_credit_amount_due_left(self.sale_id)[0].payment_amount.to_f : 0
else else
invoice_sale_payments = invoice.sale_payments amount_due = invoice.sale_payments
amount_due = invoice.grand_total .map(&:payment_amount).reduce(invoice.grand_total, :-)
end end
invoice_sale_payments.each do |payment| if amount_due > 0
if (payment.payment_status == "paid" )
amount_due = amount_due - payment.payment_amount
end
end
if (amount_due > 0)
payment_status = false payment_status = false
membership_data = nil membership_data = nil
#route to payment type #route to payment type
case payment_method case payment_method
when "cash" when "cash"
payment_status ,outstanding_amount ,balance_amount = cash_payment(payment_for) payment_status, outstanding_amount, balance_amount = cash_payment(payment_for)
when "creditnote" when "creditnote"
if !self.sale.customer_id.nil? if !self.sale.customer_id.nil?
payment_status = creditnote_payment(self.customer_id) payment_status = creditnote_payment(self.customer_id)
@@ -156,7 +150,7 @@ class SalePayment < ApplicationRecord
# update complete order items in oqs # update complete order items in oqs
booking = Booking.find_by_sale_id(sale_id) booking = Booking.find_by_sale_id(sale_id)
booking.booking_orders.each do |sodr| booking.booking_orders.each do |sodr|
assigned =AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").pluck(:assigned_order_item_id) assigned = AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").pluck(:assigned_order_item_id)
AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(delivery_status: true) AssignedOrderItem.where('assigned_order_item_id IN (?)', assigned).update_all(delivery_status: true)
# AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi| # AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi|
# aoi.delivery_status = 1 # aoi.delivery_status = 1
@@ -164,7 +158,7 @@ class SalePayment < ApplicationRecord
# end # end
end end
return true, self.save,membership_data, outstanding_amount ,balance_amount return true, self.save, membership_data, outstanding_amount, balance_amount
else else
#record an payment in sale-audit #record an payment in sale-audit
remark = "Payment failed - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" remark = "Payment failed - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]"
@@ -173,6 +167,7 @@ class SalePayment < ApplicationRecord
return false, self.save,membership_data return false, self.save,membership_data
end end
else else
sale_update_payment_status(0)
#record an payment in sale-audit #record an payment in sale-audit
remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]"
sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by.name) sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by.name)
@@ -412,19 +407,19 @@ class SalePayment < ApplicationRecord
def foc_payment def foc_payment
payment_status = false payment_status = false
sale = self.sale
# add to sale item with foc # add to sale item with foc
sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }'") sale_items = sale.sale_items
sale_items.each do|item| sale_items.each do|item|
SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) SaleItem.update_existing_item(item.qty, item, sale.sale_id, "foc", item.unit_price, item.price)
end end
sale = Sale.find(self.sale.sale_id)
sale.compute_by_sale_items(sale.total_discount,'','','',"foc") sale.compute_by_sale_items(sale.total_discount,'','','',"foc")
self.payment_method = "foc" self.payment_method = "foc"
self.payment_amount = self.received_amount self.payment_amount = self.received_amount
# self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
self.outstanding_amount = 0.00 self.outstanding_amount = 0.00
self.payment_status = "paid" self.payment_status = "paid"
payment_status = self.save! payment_status = self.save!
@@ -633,85 +628,61 @@ class SalePayment < ApplicationRecord
return payment_status return payment_status
end end
def sale_update_payment_status(paid_amount,check_foc = false) def sale_update_payment_status(paid_amount, check_foc = false)
#update amount_outstanding #update amount_outstanding
self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f sale = self.sale
self.sale.save! total_payment_amount = sale.sale_payments.reload.sum(&:payment_amount)
self.sale.amount_changed = self.sale.amount_received.to_f - self.sale.grand_total.to_f sale.amount_received = sale.amount_received.to_f + paid_amount.to_f
all_received_amount = 0.0 sale.amount_changed = total_payment_amount - sale.grand_total.to_f
sObj = Sale.find(self.sale_id)
is_credit = 0 is_credit = sale.sale_payments.any? { |x| x.payment_method == "creditnote" }
is_foc = 0 is_foc = sale.sale_payments.any? { |x| x.payment_method == "foc" }
is_kbz_pay = 0
method_status = false if sale.grand_total <= total_payment_amount && sale.sale_status == "new"
sObj.sale_payments.each do |spay| sale.payment_status = "paid"
all_received_amount += spay.payment_amount.to_f if is_credit
if spay.payment_method == "creditnote" sale.payment_status = "outstanding"
is_credit = 1 end
end if is_foc
if spay.payment_method == "foc" sale.payment_status = "foc"
is_foc = 1
end
if spay.payment_method == KbzPay::KBZ_PAY
is_kbz_pay = 1
end
if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote" || spay.payment_method == KbzPay::KBZ_PAY || spay.payment_method =="paymal"
method_status = true
end
end
if (self.sale.grand_total <= all_received_amount) && method_status
if is_credit == 0
self.sale.payment_status = "paid"
else
self.sale.payment_status = "outstanding"
end end
if is_foc == 0 sale.sale_status = "completed"
self.sale.payment_status = "paid"
else
self.sale.payment_status = "foc"
end
if is_kbz_pay == 1 if MembershipSetting.find_by_rebate(1) && is_foc == 0 && is_credit == 0
self.sale.payment_status = 'paid' response = rebat(sale)
end
self.sale.sale_status = "completed"
if MembershipSetting.find_by_rebate_and_shop_code(1,self.sale.shop_code) && is_foc == 0 && is_credit == 0
response = rebat(sObj)
#record an payment in sale-audit #record an payment in sale-audit
remark = "#{response} Rebate- for Customer #{self.sale.customer_id} | Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} " remark = "#{response} Rebate- for Customer #{sale.customer_id} | Sale Id [#{sale.sale_id}]| pay amount -> #{self.received_amount} "
sale_audit = SaleAudit.record_paymal(sObj.sale_id, remark, 1) sale_audit = SaleAudit.record_paymal(sale.sale_id, remark, 1)
if !response.nil? if !response.nil?
if response["status"] == true if response["status"] == true
self.sale.rebate_status = 'true' sale.rebate_status = 'true'
end end
if response["status"] == false if response["status"] == false
self.sale.rebate_status = 'false' sale.rebate_status = 'false'
end end
if response[:status] == false if response[:status] == false
self.sale.rebate_status = 'false' sale.rebate_status = 'false'
end end
if response[:status] == "no_member" if response[:status] == "no_member"
self.sale.rebate_status = nil sale.rebate_status = nil
end end
end end
end end
self.sale.save! sale.save!
if check_foc if check_foc
table_update_status(sObj) table_update_status(sale)
update_shift update_shift
elsif paid_amount.to_f > 0 #|| paid_amount != "0.0" elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
table_update_status(sObj) table_update_status(sale)
update_shift update_shift
elsif method_status && paid_amount.to_f == 0 && is_credit == 0 elsif paid_amount.to_f == 0 && !is_credit
table_update_status(sObj) table_update_status(sale)
update_shift update_shift
end end
end end
@@ -745,7 +716,8 @@ class SalePayment < ApplicationRecord
# update for shift with credit payment # update for shift with credit payment
def update_shift_for_credit_payment def update_shift_for_credit_payment
shift = ShiftSale.find_by_id(self.sale.shift_sale_id) shift_credit = ShiftSale.find_by_id(self.sale.shift_sale_id)
shift = ShiftSale.find_by_id(ShiftSale.current_shift)
if !shift.nil? if !shift.nil?
credit_payment_left = get_credit_payment_left[0].payment_amount.to_f credit_payment_left = get_credit_payment_left[0].payment_amount.to_f
if self.payment_method == "cash" if self.payment_method == "cash"
@@ -763,41 +735,28 @@ class SalePayment < ApplicationRecord
shift.other_sales = shift.other_sales.to_f + self.received_amount.to_f shift.other_sales = shift.other_sales.to_f + self.received_amount.to_f
end end
if credit_payment_left == 0 || credit_payment_left >= self.received_amount.to_f if credit_payment_left == 0 || credit_payment_left >= self.received_amount.to_f
shift.credit_sales = shift.credit_sales.to_f - self.received_amount.to_f if shift.id == shift_credit.id
shift.credit_sales = shift_credit.credit_sales.to_f - self.received_amount.to_f
end
else else
shift.credit_sales = shift.credit_sales.to_f - (self.received_amount.to_f + credit_payment_left) shift.credit_sales = shift_credit.credit_sales.to_f - (self.received_amount.to_f + credit_payment_left)
end end
shift.save shift.save
end end
end end
def table_update_status(sale_obj) def table_update_status(sale_obj)
status = true puts "Update staus 1"
sale_count = 0 if booking = sale_obj.booking
if booking = sale_obj.bookings[0] puts "Update staus 2"
if booking.dining_facility_id.to_i > 0 if booking.dining_facility
puts "Update staus 3"
table = booking.dining_facility table = booking.dining_facility
if Booking.left_joins(:sale).where(dining_facility_id: booking.dining_facility_id).where.not(booking_status: 'moved').where("sales.sale_status NOT IN ('completed', 'void', 'spoile', 'waste') OR sales.sale_status IS NULL").exists? if !table.current_bookings.exists?
status = false puts "Update staus 3"
table.update_attributes(status: "available")
end end
if status
table.update_attributes(status: "available")
# table.status = "available"
# table.save
end
# type = 'payment'
#Send to background job for processing
# OrderBroadcastJob.perform_later(table,type)
#if ENV["SERVER_MODE"] != 'cloud'
# if ENV["SERVER_MODE"] == 'cloud'
# from = request.subdomain + "." + request.domain
# else
# from = ""
# end
# ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
#end
end end
end end
end end
@@ -955,13 +914,16 @@ class SalePayment < ApplicationRecord
#credit payment query #credit payment query
def self.get_credit_sales(params) def self.get_credit_sales(params)
total_payment_amounts = SalePayment.select("sale_payments.sale_id, SUM(sale_payments.payment_amount) as total_payment_amount").group(:sale_id)
payments = SalePayment.select("sale_payments.sale_id, sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount") payments = SalePayment.select("sale_payments.sale_id, sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount")
.select("SUM(sale_payments.payment_amount) OVER (PARTITION BY sale_payments.sale_id) total_payment_amount") .select("total_payment_amount")
.joins("JOIN (#{total_payment_amounts.to_sql}) AS total_payment_amounts ON total_payment_amounts.sale_id = sale_payments.sale_id")
credit_sales = Sale.select("sales.sale_id, sales.receipt_no, sales.receipt_date as sale_date, sales.cashier_name") credit_sales = Sale.select("sales.sale_id, sales.receipt_no, sales.receipt_date as sale_date, sales.cashier_name")
.select("sale_payments.sale_payment_id, sale_payments.payment_amount").select("customers.name as customer_name") .select("sale_payments.sale_payment_id, sale_payments.payment_amount").select("customers.name as customer_name")
.joins("JOIN (#{payments.to_sql}) AS sale_payments ON sale_payments.sale_id = sales.sale_id").joins(:customer).joins(:orders) .joins("JOIN (#{payments.to_sql}) AS sale_payments ON sale_payments.sale_id = sales.sale_id").joins(:customer).joins(:orders)
.completed.paid.where("sale_payments.payment_method = 'creditnote' AND sales.grand_total > sale_payments.total_payment_amount - sale_payments.payment_amount").shop .completed.where("sale_payments.payment_method = 'creditnote' AND sales.grand_total > sale_payments.total_payment_amount - sale_payments.payment_amount")
.group(:receipt_no) .group(:receipt_no)
.order(:receipt_date).order(:receipt_no) .order(:receipt_date).order(:receipt_no)
@@ -984,64 +946,29 @@ class SalePayment < ApplicationRecord
end end
def self.get_credit_amount_due_left(sale_id) def self.get_credit_amount_due_left(sale_id)
query = SalePayment.select("(SUM(sale_payments.payment_amount) - SalePayment.left_joins(:sale_audit).where(sale_id: sale_id)
(CASE WHEN SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id .select("SUM(CASE WHEN sale_payments.payment_method = 'creditnote' THEN sale_payments.payment_amount ELSE 0 END) - SUM(CASE WHEN sale_audits.sale_audit_id IS NOT NULL THEN sale_payments.payment_amount ELSE 0 END) AS payment_amount")
THEN SUM(sale_payments.payment_amount) ELSE 0 END)) as payment_amount")
.joins(" LEFT JOIN sale_audits sa on SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id")
.where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{sale_id}'")
return query
end end
def self.get_credit_total_left(sale_id) def self.get_credit_total_left(sale_id)
query = SalePayment.select("(SUM(sale_payments.payment_amount) - SalePayment.left_joins(:sale_audit).where(sale_id: sale_id)
(SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) AS payment_amount .select("SUM(CASE WHEN sale_payments.payment_method = 'creditnote' THEN sale_payments.payment_amount ELSE 0 END) - SUM(CASE WHEN sale_audits.sale_audit_id IS NOT NULL THEN sale_payments.payment_amount ELSE 0 END) AS payment_amount")
FROM sale_payments
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
WHERE sale_payments.sale_id = '#{sale_id}')) as payment_amount")
.where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{sale_id}'")
return query
end end
def self.get_sale_payment_for_credit(sale_data) def self.get_sale_payment_for_credit(sale_data)
query = sale_data.sale_payments sale_data.sale_payments
.joins(" JOIN sale_audits sa on SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id") .joins(:sale_audit)
.where("sa.action='SALEPAYMENT' AND sa.remark IS NOT NULL
AND DATE_FORMAT(sale_payments.created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(sale_payments.created_at,'%Y-%m-%d') = '#{Date.today.prev_day}'
") #AND sale_payments.payment_method!='cash'
.group("sale_payments.sale_payment_id")
return query
end end
def get_credit_payment_left def get_credit_payment_left
sql = "SELECT SUM(payment_amount) SalePayment.left_joins(:sale_audit).where(sale_id: sale_id)
from sale_payments .select("SUM(CASE WHEN sale_payments.payment_method = 'creditnote' THEN sale_payments.payment_amount ELSE 0 END) - SUM(CASE WHEN sale_audits.sale_audit_id IS NOT NULL THEN sale_payments.payment_amount ELSE 0 END) AS payment_amount")
join sale_audits on SUBSTRING_INDEX(remark,'||',1)=sale_payment_id
where sale_payments.sale_id = '#{self.sale_id}'"
query = SalePayment.select("(SUM(payment_amount) - (#{sql})) as payment_amount")
.where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{self.sale_id}'")
return query
end end
def self.get_sale_payments(sale_data) def self.get_sale_payments(sale_data)
sql = "SELECT SUM(payment_amount) sale_data.sale_payments
FROM sale_payments where payment_method='creditnote' .merge(SalePayment.where.not(payment_method: 'creditnote')
and sale_id='#{sale_data.sale_id}'" .or(SalePayment.where.not(SalePayment.arel_table[:payment_amount].lteq(sale_data.sale_payments.joins(:sale_audit).sum(:payment_amount)))))
sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
FROM sale_payments where payment_method='creditnote'
and sale_id='#{sale_data.sale_id}'"
query = sale_data.sale_payments
.where("CASE WHEN ((#{sql}) - (#{sql1})
ELSE SUM(payment_amount) END
FROM sale_payments
JOIN sales s ON s.sale_id=sale_payments.sale_id
JOIN sale_audits sa
ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id
where sa.sale_id='#{sale_data.sale_id}')) = 0
THEN payment_method!='creditnote' ELSE 1 END")
.group("sale_payments.sale_payment_id")
return query
end end
private private

View File

@@ -3,19 +3,44 @@ class SeedGenerator < ApplicationRecord
def self.generate_id(model, prefix) def self.generate_id(model, prefix)
model_name = self.get_model_name(model) model_name = self.get_model_name(model)
prefix ||= ''
prefix << '-' if prefix.present?
if ENV["SERVER_MODE"] == 'cloud' if ENV["SERVER_MODE"] == 'cloud'
prefix = "C#{prefix}" prefix << 'C'
else
prefix << 'L'
end end
cur_val, next_val = self.update_seed(model_name) if shop = Shop.current_shop
prefix << shop.shop_code
if (cur_val == 0)
cur_val, next_val = self.execute_query(model_name)
end end
padding_len = 15 - prefix.length seed = self.update_seed(model_name)
saleOrderId = prefix +"-"+ cur_val.to_s.to_s.rjust((14-prefix.length)+1,'0') length = 16 - prefix.length
return saleOrderId prefix + seed.to_s.rjust(length, '0')
end
def self.generate_ids(model, prefix, count = 1)
model_name = self.get_model_name(model)
prefix ||= ''
prefix << '-' if prefix.present?
if ENV["SERVER_MODE"] == 'cloud'
prefix << 'C'
else
prefix << 'L'
end
if shop = Shop.current_shop
prefix << shop.shop_code
end
start = self.update_seed(model_name, count)
stop = start + count - 1
length = 16 - prefix.length
(start..stop).map { |c| prefix + c.to_s.rjust(length, '0') }
end end
def self.sync_seed_generator_records(seed_generators) def self.sync_seed_generator_records(seed_generators)
@@ -58,7 +83,7 @@ class SeedGenerator < ApplicationRecord
end end
end end
return new_receipt_no return new_receipt_no
end end
# Generate for 4 digit Code # Generate for 4 digit Code
@@ -85,7 +110,7 @@ class SeedGenerator < ApplicationRecord
# padding_len = 6 - prefix.length # padding_len = 6 - prefix.length
# count = 5-prefix.length # count = 5-prefix.length
# end # end
# next_code = prefix + seed.current.to_s.to_s.rjust((count)+1,'0') # next_code = prefix + seed.current.to_s.to_s.rjust((count)+1,'0')
# return next_code # return next_code
# end # end
@@ -100,41 +125,13 @@ class SeedGenerator < ApplicationRecord
return model_name return model_name
end end
def self.execute_query(model) def self.update_seed(model, count = 1)
current = 0 SeedGenerator.transaction do
nex = 0 seed = SeedGenerator.lock.find_by_model(model)
seed.next = seed.next + (count * seed.increase_by)
sql = "INSERT INTO seed_generators (model, created_at, updated_at) seed.current = seed.next - seed.increase_by
VALUES('#{ model }', NOW(), NOW()) seed.save!
ON DUPLICATE KEY UPDATE current = current + 1, next = next + 1;" seed.next_before_last_save
select_sql = "select * from seed_generators where model='#{model}';"
ActiveRecord::Base.connection.execute(sql);
select_result = ActiveRecord::Base.connection.execute(select_sql);
select_result.each do |row|
current = row [3]
nex = row[4]
end end
return current, nex
end
def self.update_seed(model)
current = 0
nex = 0
update_sql = "UPDATE seed_generators set current = next, next = next + 1 WHERE model='#{model}';"
select_sql = "select * from seed_generators where model='#{model}';"
update_result = ActiveRecord::Base.connection.execute(update_sql);
select_result = ActiveRecord::Base.connection.execute(select_sql);
select_result.each do |row|
current = row [3]
nex = row[4]
end
return current, nex
end end
end end

View File

@@ -19,7 +19,7 @@ class ShiftSale < ApplicationRecord
def self.current_shift def self.current_shift
# today_date = DateTime.now.strftime("%Y-%m-%d") # today_date = DateTime.now.strftime("%Y-%m-%d")
shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null").first shift = ShiftSale.where.not(shift_started_at: nil).where(shift_closed_at: nil).first
return shift return shift
end end

View File

@@ -1,4 +1,6 @@
class TaxProfile < ApplicationRecord class TaxProfile < ApplicationRecord
has_one :lookup, -> { where(lookup_type: 'tax_profiles') }, foreign_key: "value", primary_key: "group_type"
default_scope { order('order_by asc') } default_scope { order('order_by asc') }
# validations # validations
validates_presence_of :name, :rate, :group_type validates_presence_of :name, :rate, :group_type

View File

@@ -1,7 +1,7 @@
class OrderSummaryPdf < Prawn::Document class OrderSummaryPdf < Prawn::Document
include NumberFormattable include NumberFormattable
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 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(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) def initialize(print_settings, order, print_status, order_items = nil, alt_name, before_updated_qty)
self.page_width = print_settings.page_width self.page_width = print_settings.page_width
self.page_height = print_settings.page_height self.page_height = print_settings.page_height
self.header_font_size = print_settings.header_font_size.to_i self.header_font_size = print_settings.header_font_size.to_i

View File

@@ -388,25 +388,12 @@ class ReceiptBillA5Pdf < Prawn::Document
def sale_payment(sale_data,precision,delimiter) def sale_payment(sale_data,precision,delimiter)
stroke_horizontal_rule stroke_horizontal_rule
# move_down 10
sql = "SELECT SUM(payment_amount)
FROM sale_payments where payment_method='creditnote'
and sale_id='#{sale_data.sale_id}'"
sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
FROM sale_payments where payment_method='creditnote'
and sale_id='#{sale_data.sale_id}'"
sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method") query = sale_data.sale_payments
.where("(CASE WHEN ((#{sql}) - (#{sql1}) .merge(SalePayment.where.not(payment_method: 'creditnote')
ELSE SUM(payment_amount) END .or(SalePayment.where.not(SalePayment.arel_table[:payment_amount].lteq(sale_data.sale_payments.joins(:sale_audit).sum(:payment_amount)))))
FROM sale_payments
JOIN sales s ON s.sale_id=sale_payments.sale_id query.each do |payment|
JOIN sale_audits sa
ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id
where sa.sale_id='#{sale_data.sale_id}')) = 0
THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id)
.group("payment_method")
sale_payments.each do |payment|
y_position = cursor y_position = cursor
if payment.payment_method == "paypar" if payment.payment_method == "paypar"
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
@@ -614,12 +601,16 @@ class ReceiptBillA5Pdf < Prawn::Document
end end
def sign(sale_data) def sign(sale_data)
sql = "SELECT SUM(payment_amount) # sql = "SELECT SUM(payment_amount)
FROM sale_payments where payment_method='creditnote' # FROM sale_payments where payment_method='creditnote'
and sale_id='#{sale_data.sale_id}'" # and sale_id='#{sale_data.sale_id}'"
sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) # sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
FROM sale_payments where payment_method='creditnote' # FROM sale_payments where payment_method='creditnote'
and sale_id='#{sale_data.sale_id}'" # and sale_id='#{sale_data.sale_id}'"
sql = SalePayment.select("(SUM(payment_amount))").where("payment_method='creditnote'
and sale_id='#{sale_data.sale_id}'").to_sql
sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ("
sql1 += sql
SalePayment.where("(CASE WHEN ((#{sql}) - (#{sql1}) SalePayment.where("(CASE WHEN ((#{sql}) - (#{sql1})
ELSE SUM(payment_amount) END ELSE SUM(payment_amount) END

View File

@@ -453,12 +453,15 @@ class ReceiptBillPdf < Prawn::Document
def sale_payment(sale_data,precision,delimiter) def sale_payment(sale_data,precision,delimiter)
stroke_horizontal_rule stroke_horizontal_rule
#move_down line_move #move_down line_move
sql = "SELECT SUM(payment_amount) # sql = "SELECT SUM(payment_amount)
FROM sale_payments where payment_method='creditnote' # FROM sale_payments where payment_method='creditnote'
and sale_id='#{sale_data.sale_id}'" # and sale_id='#{sale_data.sale_id}'"
sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) sql = SalePayment.select("(SUM(payment_amount))").where("payment_method='creditnote' and sale_id='#{sale_data.sale_id}'").to_sql
FROM sale_payments where payment_method='creditnote' # sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
and sale_id='#{sale_data.sale_id}'" # FROM sale_payments where payment_method='creditnote'
# and sale_id='#{sale_data.sale_id}'"
sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ("
sql1 += sql
sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method") sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method")
.where("(CASE WHEN ((#{sql}) - (#{sql1}) .where("(CASE WHEN ((#{sql}) - (#{sql1})
@@ -685,21 +688,11 @@ class ReceiptBillPdf < Prawn::Document
end end
def sign(sale_data) def sign(sale_data)
sql = "SELECT SUM(payment_amount) query = sale_data.sale_payments
FROM sale_payments where payment_method='creditnote' .merge(SalePayment.where.not(payment_method: 'creditnote')
and sale_id='#{sale_data.sale_id}'" .or(SalePayment.where.not(SalePayment.arel_table[:payment_amount].lteq(sale_data.sale_payments.joins(:sale_audit).sum(:payment_amount)))))
sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
FROM sale_payments where payment_method='creditnote' query.each do |payment|
and sale_id='#{sale_data.sale_id}'"
SalePayment.where("(CASE WHEN ((#{sql}) - (#{sql1})
ELSE SUM(payment_amount) END
FROM sale_payments
JOIN sales s ON s.sale_id=sale_payments.sale_id
JOIN sale_audits sa
ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id
where sa.sale_id='#{sale_data.sale_id}')) = 0
THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id).each do |payment|
if payment.payment_method == "creditnote" if payment.payment_method == "creditnote"
y_position = cursor y_position = cursor

View File

@@ -383,12 +383,16 @@ class ReceiptBillStarPdf < Prawn::Document
def sale_payment(sale_data,precision,delimiter) def sale_payment(sale_data,precision,delimiter)
stroke_horizontal_rule stroke_horizontal_rule
#move_down line_move #move_down line_move
sql = "SELECT SUM(payment_amount) # sql = "SELECT SUM(payment_amount)
FROM sale_payments where payment_method='creditnote' # FROM sale_payments where payment_method='creditnote'
and sale_id='#{sale_data.sale_id}'" # and sale_id='#{sale_data.sale_id}'"
sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) # sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
FROM sale_payments where payment_method='creditnote' # FROM sale_payments where payment_method='creditnote'
and sale_id='#{sale_data.sale_id}'" # and sale_id='#{sale_data.sale_id}'"
sql = SalePayment.select("(SUM(payment_amount))").where("payment_method='creditnote'
and sale_id='#{sale_data.sale_id}'").to_sql
sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ("
sql1 += sql
sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method") sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method")
.where("(CASE WHEN ((#{sql}) - (#{sql1}) .where("(CASE WHEN ((#{sql}) - (#{sql1})
@@ -609,21 +613,11 @@ class ReceiptBillStarPdf < Prawn::Document
end end
def sign(sale_data) def sign(sale_data)
sql = "SELECT SUM(payment_amount) query = sale_data.sale_payments
FROM sale_payments where payment_method='creditnote' .merge(SalePayment.where.not(payment_method: 'creditnote')
and sale_id='#{sale_data.sale_id}'" .or(SalePayment.where.not(SalePayment.arel_table[:payment_amount].lteq(sale_data.sale_payments.joins(:sale_audit).sum(:payment_amount)))))
sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
FROM sale_payments where payment_method='creditnote'
and sale_id='#{sale_data.sale_id}'"
SalePayment.where("(CASE WHEN ((#{sql}) - (#{sql1}) query.each do |payment|
ELSE SUM(payment_amount) END
FROM sale_payments
JOIN sales s ON s.sale_id=sale_payments.sale_id
JOIN sale_audits sa
ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id
where sa.sale_id='#{sale_data.sale_id}')) = 0
THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id).each do |payment|
if payment.payment_method == "creditnote" if payment.payment_method == "creditnote"
y_position = cursor y_position = cursor

View File

@@ -2,56 +2,25 @@
attr_format = [] attr_format = []
# Format for attributes json # Format for attributes json
if item.is_available if item.is_available
# Format for attributes json
attr_format = []
# Format for attributes json
if item.item_attributes.count > 0 if item.item_attributes.count > 0
item.item_attributes.each do|attr_id| item_attributes = item.item_attributes.map(&:to_s)
menu_attr = MenuItemAttribute.find(attr_id) attr_format = @item_attributes.select { |x| item_attributes.include?(x.id.to_s) }.group_by {|att| att.attribute_type.strip }.map { |type, values| {type: type, values: values.map { |x| x.name.strip } } }
if attr_format.count == 0
attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] })
next
end
attr_format.each do |af|
if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]}
if menu_attr.attribute_type == af[:type]
af[:values].push(menu_attr.name)
end
else
new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] }
attr_format.push(new_attr)
break
end
end
end
end end
# Format for option json # Format for option json
opt_format = [] opt_format = []
# Format for attributes json # Format for attributes json
if item.item_options.count > 0 if item.item_options.count > 0
item.item_options.each do|opt| item_options = item.item_options.map(&:to_s)
menu_opt = MenuItemOption.find(opt) opt_format = @item_options.select { |x| item_options.include?(x.id.to_s) }.group_by {|opt| opt.option_type.strip }.map { |type, values| {type: type, values: values.map { |x| x.name.strip } } }
if opt_format.count == 0
opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] })
next
end
opt_format.each do |of|
if menu_opt.option_type.in? opt_format.map {|k| k[:type]}
if menu_opt.option_type == of[:type]
of[:values].push(menu_opt.name)
end
else
new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] }
opt_format.push(new_opt)
break
end
end
end
end end
#Menu Item Information #Menu Item Information
json.id item.id json.id item.id
json.code item.item_code json.code item.item_code
json.name item.name json.name item.name
json.alt_name item.alt_name json.alt_name item.alt_name
if !request_url.nil? && request_url != '' && !item.image_path.nil? if !request_url.nil? && request_url != '' && !item.image_path.nil?
@@ -75,9 +44,7 @@ if item.is_available
json.alt_name its.alt_name json.alt_name its.alt_name
json.min_selectable_qty its.min_selectable_qty json.min_selectable_qty its.min_selectable_qty
json.max_selectable_qty its.max_selectable_qty json.max_selectable_qty its.max_selectable_qty
json.instances its.menu_item_instances do |i| json.instances its.menu_item_instances.map { |i| {id: i.id} }
json.id i.id
end
end end
json.attributes attr_format json.attributes attr_format
@@ -97,7 +64,8 @@ if item.is_available
json.instances item.menu_item_instances do |is| json.instances item.menu_item_instances do |is|
if is.is_available if is.is_available
# Convert id to name for attributes # Convert id to name for attributes
instance_attr = [] item_attributes = is.item_attributes.map(&:to_s)
instance_attr = @item_attributes.select{ |x| item_attributes.include?(x.id.to_s) }.pluck(:name)
is.item_attributes.each do |ia| is.item_attributes.each do |ia|
# mItemAttr = MenuItemAttribute.find(is) # mItemAttr = MenuItemAttribute.find(is)

View File

@@ -50,7 +50,7 @@
<% end%> <% end%>
<!-- else quick_service or cashier for table --> <!-- else quick_service or cashier for table -->
<% else %> <% else %>
<% if @table.get_current_checkout_booking.nil? %> <% if @table.current_checkout_booking.nil? %>
<% if !menu.code.include? "SPL" %> <% if !menu.code.include? "SPL" %>
<li class="nav-item "> <li class="nav-item ">
<p class="hidden menu-id"><%= menu.id %></p> <p class="hidden menu-id"><%= menu.id %></p>
@@ -118,7 +118,7 @@
<% end%> <% end%>
<!-- else quick_service or cashier for table --> <!-- else quick_service or cashier for table -->
<% else %> <% else %>
<% if @table.get_current_checkout_booking.nil? %> <% if @table.current_checkout_booking.nil? %>
<% if !menu.code.include? "SPL" %> <% if !menu.code.include? "SPL" %>
<div class="card custom-card testimonial-card animated fadeInRight menu_category sub_click" data-id="<%=menu.id%>"> <div class="card custom-card testimonial-card animated fadeInRight menu_category sub_click" data-id="<%=menu.id%>">
<div class='card-block custom-card-block'> <div class='card-block custom-card-block'>

View File

@@ -11,15 +11,14 @@
<div class="row "> <div class="row ">
<div class="col-lg-4 col-md-4 col-sm-4" style="padding-left: 17px;"> <div class="col-lg-4 col-md-4 col-sm-4" style="padding-left: 17px;">
<%= form_tag inventory_path, :id => "filter_form", :method => :get do %> <%= form_tag inventory_path, :id => "filter_form", :method => :get do %>
<!-- col-lg-4 col-md-4 col-sm-4 -->
<!-- <label class="font-14"><%= t("views.right_panel.detail.product") %></label> -->
<input type="text" class="form-control" name="filter" id="Product" type="text" placeholder="Product" style="height: 32px;">
</div>
<!-- col-lg-4 col-md-4 col-sm-4 --> <div class="col-lg-2 col-md-2 col-sm-2 text-">
<!-- <label class="font-14"><%= t("views.right_panel.detail.product") %></label> --> <input type="submit" value="Filter" class='btn btn-primary'>
<input type="text" class="form-control" name="filter" id="Product" type="text" placeholder="Product" style="height: 32px;"> </div>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 text-">
<input type="submit" value="Filter" class='btn btn-primary'>
</div>
<% end %> <% end %>
<div class="col-lg-6 col-md-6 col-sm-6" style="padding-right: 15px;"> <div class="col-lg-6 col-md-6 col-sm-6" style="padding-right: 15px;">

View File

@@ -31,15 +31,13 @@ json.is_sub_item item.is_sub_item
json.unit item.unit json.unit item.unit
# Item Sets of Menu Item # Item Sets of Menu Item
json.item_sets item.item_sets.includes(:menu_item_instances) do |its| json.item_sets item.item_sets do |its|
json.id its.id json.id its.id
json.name its.name json.name its.name
json.alt_name its.alt_name json.alt_name its.alt_name
json.min_selectable_qty its.min_selectable_qty json.min_selectable_qty its.min_selectable_qty
json.max_selectable_qty its.max_selectable_qty json.max_selectable_qty its.max_selectable_qty
json.instances its.menu_item_instances do |i| json.instances its.menu_item_instances.map { |i| {id: i.id} }
json.id i.id
end
end end
json.attributes attr_format json.attributes attr_format

View File

@@ -10,6 +10,8 @@
</div> </div>
<input type="hidden" name="type" id="role" value="<%= current_user.role%>"> <input type="hidden" name="type" id="role" value="<%= current_user.role%>">
<input type="hidden" name="cashier_type" id="cashier_type" value="<%= type%>"> <input type="hidden" name="cashier_type" id="cashier_type" value="<%= type%>">
<input type="hidden" name="inclusive_tax" id="inclusive_tax" value="<%= @inclusive_tax%>">
<input type="hidden" name="exclusive_tax" id="exclusive_tax" value="<%= @exclusive_tax%>">
<input type="hidden" name="link_type" id="link_type" value="<%= @cashier_type %>"> <input type="hidden" name="link_type" id="link_type" value="<%= @cashier_type %>">
<input type="hidden" name="display_type" id="display_type" value="<%= @display_type%>"> <input type="hidden" name="display_type" id="display_type" value="<%= @display_type%>">
<div class="row m-t--20"> <div class="row m-t--20">
@@ -52,7 +54,7 @@
<% end%> <% end%>
<!-- else quick_service or cashier for table --> <!-- else quick_service or cashier for table -->
<% else %> <% else %>
<% if @table.get_current_checkout_booking.nil? %> <% if @table.current_checkout_booking.nil? %>
<% if !menu.code.include? "SPL" %> <% if !menu.code.include? "SPL" %>
<li class="nav-item "> <li class="nav-item ">
<p class="hidden menu-id"><%= menu.id %></p> <p class="hidden menu-id"><%= menu.id %></p>
@@ -120,7 +122,7 @@
<% end%> <% end%>
<!-- else quick_service or cashier for table --> <!-- else quick_service or cashier for table -->
<% else %> <% else %>
<% if @table.get_current_checkout_booking.nil? %> <% if @table.current_checkout_booking.nil? %>
<% if !menu.code.include? "SPL" %> <% if !menu.code.include? "SPL" %>
<div class="card custom-card testimonial-card animated fadeInRight menu_category sub_click" data-id="<%=menu.id%>"> <div class="card custom-card testimonial-card animated fadeInRight menu_category sub_click" data-id="<%=menu.id%>">
<div class='card-block custom-card-block'> <div class='card-block custom-card-block'>
@@ -199,7 +201,7 @@
<div class="col-md-3 col-lg-3 col-sm-3">Table : <%=@table.name%></div> <div class="col-md-3 col-lg-3 col-sm-3">Table : <%=@table.name%></div>
<p class="hidden" id="table_id"><%=@table_id%></p> <p class="hidden" id="table_id"><%=@table_id%></p>
<p class="hidden" id="table_type"><%=@table.type%></p> <p class="hidden" id="table_type"><%=@table.type%></p>
<p class="hidden" id="table_get_current"><%=@table.get_current_checkout_booking%></p> <p class="hidden" id="table_get_current"><%=@table.current_checkout_booking%></p>
<% end%> <% end%>
<p class="hidden" id="booking_id"><%=@booking_id%></p> <p class="hidden" id="booking_id"><%=@booking_id%></p>
@@ -231,7 +233,7 @@
<p class="hidden" id="table_type"><%=@table.type%></p> <p class="hidden" id="table_type"><%=@table.type%></p>
<p class="hidden" id="booking_id"><%=@booking_id%></p> <p class="hidden" id="booking_id"><%=@booking_id%></p>
<p class="hidden" id="customer_id"><%=@customer ? @customer.customer_id : ''%></p> <p class="hidden" id="customer_id"><%=@customer ? @customer.customer_id : ''%></p>
<p class="hidden" id="table_get_current"><%=@table.get_current_checkout_booking%></p> <p class="hidden" id="table_get_current"><%=@table.current_checkout_booking%></p>
</div> </div>
<div class="col-md-3 col-lg-3 col-sm-3"> <div class="col-md-3 col-lg-3 col-sm-3">
<button type="button" class="btn btn-xs btn-danger waves-effect" id='clear_all'>Clear <button type="button" class="btn btn-xs btn-danger waves-effect" id='clear_all'>Clear
@@ -259,19 +261,28 @@
<div class="card-footer custom-card-footer" style="padding: 0.35rem 0.15rem !important;"> <div class="card-footer custom-card-footer" style="padding: 0.35rem 0.15rem !important;">
<table class="table" id="order-charges-table" border="0"> <table class="table" id="order-charges-table" border="0">
<tr> <%if @cashier_type=='quick_service' %>
<td colspan="2" style="padding:2px; text-align:" class="charges-name" width="25%"><strong>Total:</strong></td> <tr>
<td colspan="3" style="padding:2px; text-align:" class="charges-name" width="25%"><strong>Tax:</strong></td>
<td style="padding:2px; text-align:" width="25%" class="item-attr"><strong id="total_tax">0.00</strong></td>
</tr>
<tr>
<td colspan="2" style="padding:2px; text-align:" class="charges-name" width="25%"><strong>Total + tax:</strong></td>
<% else %>
<tr>
<td colspan="2" style="padding:2px; text-align:" class="charges-name" width="25%"><strong>Total:</strong></td>
<% end %>
<td style="padding:2px;" width="15%"><strong id="total_qty">0</strong></td> <td style="padding:2px;" width="15%"><strong id="total_qty">0</strong></td>
<td style="padding:2px; text-align:" width="25%" class="item-attr"><strong id="sub_total">0.00</strong></td> <td style="padding:2px; text-align:" width="25%" class="item-attr"><strong id="sub_total">0.00</strong></td>
</tr> </tr>
</table> </table>
<% if type && modify_order%> <% if type && modify_order%>
<input type="hidden" name="customer_id" id="customer_id" value="CUS-000000000001"> <input type="hidden" name="customer_id" id="customer_id" value="<%= walkin.customer_id %>">
<button type="button" class="btn btn-primary action-btn create col-md-11" id="create_pay_order" disabled="disabled" style="padding-top:15px !important;padding-bottom:15px !important;">Update Order & Pay</button> <button type="button" class="btn btn-primary action-btn create col-md-11" id="create_pay_order" disabled="disabled" style="padding-top:15px !important;padding-bottom:15px !important;">Update Order & Pay</button>
<%elsif !modify_order && type%> <%elsif !modify_order && type%>
<input type="hidden" name="customer_id" id="customer_id" value="CUS-000000000001"> <input type="hidden" name="customer_id" id="customer_id" value="<%= walkin.customer_id %>">
<% if current_user.role != "waiter"%> <% if current_user.role != "waiter"%>
<% if @quick_service_only %> <% if @quick_service_only %>
@@ -794,6 +805,8 @@
$(document).on('click', '#clear_all', function(event){ $(document).on('click', '#clear_all', function(event){
$(".summary-items tbody").empty(); $(".summary-items tbody").empty();
$('#sub_total').text("0.00"); $('#sub_total').text("0.00");
$('#total_qty').text("0");
$('#total_tax').text("0");
$(".create").attr("disabled","disabled"); $(".create").attr("disabled","disabled");
customer_display_view(null,"reload"); customer_display_view(null,"reload");
}); });

View File

@@ -22,7 +22,7 @@
<div class="input-append col-md-7 form-group pull-left"> <div class="input-append col-md-7 form-group pull-left">
<input type="text" name="filter" style="margin-right:10px" id="search" placeholder="Search" class="form-control input-sm col-md-9"> <input type="text" name="filter" style="margin-right:10px" id="search" placeholder="Search" class="form-control input-sm col-md-9">
<input type="hidden" name="type" id="type" value=""> <input type="hidden" name="type" id="type" value="">
<button type="submit" class="btn btn-primary btn-sm">Search</button> <button type="submit" class="btn btn-primary btn-sm">Search</button>
</div> </div>
<% end %> <% end %>
<button id="member_acc_no" class="btn btn-success btn-sm"><span class="fa fa-credit-card"></span> Member Card</button> --> <button id="member_acc_no" class="btn btn-success btn-sm"><span class="fa fa-credit-card"></span> Member Card</button> -->
@@ -72,7 +72,7 @@
</thead> </thead>
<tbody> <tbody>
<% if @crm_customers.count > 0 %> <% if @crm_customers.count > 0 %>
<% @i = 0 %> <% @i = 0 %>
<% @crm_customers.each do |crm_customer| %> <% @crm_customers.each do |crm_customer| %>
@@ -80,7 +80,7 @@
<td> <td>
<input type="radio" style="width:20px;" name="checkbox" class="checkbox_check" ></td> <input type="radio" style="width:20px;" name="checkbox" class="checkbox_check" ></td>
<td> <td>
<% if crm_customer.customer_id != "CUS-000000000001" && crm_customer.customer_id != "CUS-000000000002" %> <% if crm_customer.customer_id != "" && crm_customer.customer_id != "" %>
<%= @i += 1 %> <%= @i += 1 %>
<%else%> <%else%>
- -
@@ -156,7 +156,7 @@
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> <%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %>
<span class="patch_method"></span> <span class="patch_method"></span>
<%= f.error_notification %> <%= f.error_notification %>
<%= f.hidden_field :id, :class => "form-control col-md-6 " %> <%= f.hidden_field :id, :class => "form-control col-md-6 " %>
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane active" role="tabpanel" id="step1"> <div class="tab-pane active" role="tabpanel" id="step1">
<div class="form-group"> <div class="form-group">
@@ -225,7 +225,7 @@
<div class="form-group"> <div class="form-group">
<div class="col-sm-12 col-md-12 col-lg-12" align="right"> <div class="col-sm-12 col-md-12 col-lg-12" align="right">
<button type="button" class="btn btn-md bg-blue btn-info-full next-step">Next</button> <button type="button" class="btn btn-md bg-blue btn-info-full next-step">Next</button>
</div> </div>
</div> </div>
</div> <!-- .end-of-step1 --> </div> <!-- .end-of-step1 -->
<div class="tab-pane" role="tabpanel" id="complete"> <div class="tab-pane" role="tabpanel" id="complete">
@@ -238,12 +238,12 @@
<% if f.object.image_path? %> <% if f.object.image_path? %>
<p><%= f.object.name %></p> <p><%= f.object.name %></p>
<%= image_tag f.object.image_path.url, :class => "img-thumbnail" %> <%= image_tag f.object.image_path.url, :class => "img-thumbnail" %>
<% else %> <% else %>
<%= image_tag "/image/menu_images/default.png", :class => "img-thumbnail" %> <%= image_tag "/image/menu_images/default.png", :class => "img-thumbnail" %>
<% end %> <% end %>
</div> </div>
<%= f.file_field :image_path, :class => "img-thumbnail" %> <%= f.file_field :image_path, :class => "img-thumbnail" %>
</div> </div>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@@ -291,7 +291,7 @@
<option value="<%= ct.value %>"> <option value="<%= ct.value %>">
<%= ct.name %></option> <%= ct.name %></option>
<%end %> <%end %>
</select> </select>
</div> </div>
</div> </div>
@@ -316,7 +316,7 @@
<div class="form-group"> <div class="form-group">
<div class="col-sm-12 col-md-12 col-lg-12"> <div class="col-sm-12 col-md-12 col-lg-12">
<label class="control-label"><%= t("views.right_panel.detail.paypar_account_no") %>:</label> <label class="control-label"><%= t("views.right_panel.detail.paypar_account_no") %>:</label>
<div class="-group"> <div class="-group">
<input type="text" class="form-control" id="paypar_account_no" name="customer[paypar_account_no]" readonly/> <input type="text" class="form-control" id="paypar_account_no" name="customer[paypar_account_no]" readonly/>
<div class="input-group-addon"><span class="fa fa-credit-card"></span></div> <div class="input-group-addon"><span class="fa fa-credit-card"></span></div>
</div> </div>
@@ -332,7 +332,7 @@
<option value="<%= member.value %>"> <option value="<%= member.value %>">
<%= member.name %></option> <%= member.name %></option>
<%end %> <%end %>
</select> </select>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@@ -363,7 +363,7 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var cashier_type = "<%= @cashier_type %>"; var cashier_type = "<%= @cashier_type %>";
var page = "<%= @page %>"; var page = "<%= @page %>";
var paypar_account_no = []; var paypar_account_no = [];
$(function() { $(function() {
paypar_account_no = JSON.parse('<%= @paypar_accountno.to_json.html_safe %>', function (key, value) { paypar_account_no = JSON.parse('<%= @paypar_accountno.to_json.html_safe %>', function (key, value) {
@@ -391,14 +391,14 @@
$('.datepicker').css('cursor','pointer');*/ $('.datepicker').css('cursor','pointer');*/
// Read Card Reader // Read Card Reader
$("#paypar_account_no").on('focus', function(e){ $("#paypar_account_no").on('focus', function(e){
if($(this).val() == ''){ if($(this).val() == ''){
$("#sxModal").show(); $("#sxModal").show();
setTimeout(function(){ setTimeout(function(){
getCardNo(); getCardNo();
$("#sxModal").hide(); $("#sxModal").hide();
},100); },100);
} }
}); });
$(document).ready(function () { $(document).ready(function () {
@@ -406,20 +406,20 @@
}); });
// Read Card Reader // Read Card Reader
$("#member_acc_no").on('click', function(e){ $("#member_acc_no").on('click', function(e){
localStorage.setItem("member_card",true); localStorage.setItem("member_card",true);
var cardNo = ""; var cardNo = "";
var customer_id = ''; var customer_id = '';
var customer_name = ''; var customer_name = '';
var sale_id = $("#sale_id").val() || 0; var sale_id = $("#sale_id").val() || 0;
var customer_mamber_card_no = 0; var customer_mamber_card_no = 0;
$("#sxModal").show(); $("#sxModal").show();
setTimeout(function(){ setTimeout(function(){
getCardNo(); getCardNo();
$("#sxModal").hide(); $("#sxModal").hide();
customer_mamber_card_no = $("#search").val(); customer_mamber_card_no = $("#search").val();
if(sale_id != 0 && customer_mamber_card_no != 0){ if(sale_id != 0 && customer_mamber_card_no != 0){
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/origami/"+sale_id+"/get_customer" , url: "/origami/"+sale_id+"/get_customer" ,
@@ -442,7 +442,7 @@
} }
} }
}); });
} }
},100); },100);
}); });
@@ -450,12 +450,12 @@
/*new customer UI func:*/ /*new customer UI func:*/
//Initialize tooltips //Initialize tooltips
$('.nav-tabs > li a[title]').tooltip(); $('.nav-tabs > li a[title]').tooltip();
//Wizard //Wizard
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) { $('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
var $target = $(e.target); var $target = $(e.target);
if ($target.parent().hasClass('disabled')) { if ($target.parent().hasClass('disabled')) {
return false; return false;
} }
@@ -522,21 +522,21 @@
} }
// QR Code Reader // QR Code Reader
$("#qr_code").on('click', function(e){ $("#qr_code").on('click', function(e){
var code = ""; var code = "";
var customer_id = ''; var customer_id = '';
var customer_name = ''; var customer_name = '';
var sale_id = $("#sale_id").val() || 0; var sale_id = $("#sale_id").val() || 0;
var customer_mamber_card_no = 0; var customer_mamber_card_no = 0;
setTimeout(function(){ setTimeout(function(){
code=getQRCode(); code=getQRCode();
setQRCode(code); setQRCode(code);
}, 100); }, 100);
customer_mamber_card_no = $("#search").val(); customer_mamber_card_no = $("#search").val();
if(sale_id != 0 && customer_mamber_card_no != 0){ if(sale_id != 0 && customer_mamber_card_no != 0){
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/origami/"+sale_id+"/get_customer" , url: "/origami/"+sale_id+"/get_customer" ,
@@ -558,8 +558,8 @@
update_sale(customer_id, customer_name,sale_id); update_sale(customer_id, customer_name,sale_id);
} }
} }
}); });
} }
}); });
// Read qrcode from java // Read qrcode from java
@@ -595,12 +595,12 @@
data: {}, data: {},
dataType: "json", dataType: "json",
success: function(data) { success: function(data) {
var taxes = JSON.stringify(data.tax_profiles); var taxes = JSON.stringify(data.tax_profiles);
var parse_taxes = JSON.parse(taxes); var parse_taxes = JSON.parse(taxes);
$.each(parse_taxes, function(i, value){ $.each(parse_taxes, function(i, value){
$("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected"); $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected");
}); });
$('#customer_id').val(data.id); $('#customer_id').val(data.id);
$('#customer_name').val(data.name); $('#customer_name').val(data.name);
$('#customer_company').val(data.company); $('#customer_company').val(data.company);
@@ -701,7 +701,7 @@
location.reload(); location.reload();
} }
} }
}); });
}); });
} }
@@ -724,9 +724,9 @@
window.location.href = '/origami/room/'+id; window.location.href = '/origami/room/'+id;
} }
} }
} }
}); });
$("#sxModal .btn_cancel").on('click',function(){ $("#sxModal .btn_cancel").on('click',function(){
@@ -734,4 +734,3 @@
}); });
</script> </script>

View File

@@ -41,21 +41,21 @@ if (menu.menu_categories)
attr_format = [] attr_format = []
# Format for attributes json # Format for attributes json
if item.item_attributes.count > 0 if item.item_attributes.count > 0
item_attributes = @item_attributes.select{ |x| item.item_attributes.include?(x.id.to_s) } item_attributes = item.item_attributes.map(&:to_s)
attr_format = item_attributes.group_by {|att| att.attribute_type }.map { |type, values| {type: type, values: values.map(&:name)} } attr_format = @item_attributes.select { |x| item_attributes.include?(x.id.to_s) }.group_by {|att| att.attribute_type.strip }.map { |type, values| {type: type, values: values.map { |x| x.name.strip } } }
end end
# Format for option json # Format for option json
opt_format = [] opt_format = []
# Format for attributes json # Format for attributes json
if item.item_options.count > 0 if item.item_options.count > 0
item_options = @item_options.select{ |x| item.item_options.include?(x.id.to_s) } item_options = item.item_options.map(&:to_s)
opt_format = item_options.group_by {|opt| opt.option_type }.map { |type, values| {type: type, values: values.map(&:name)} } opt_format = @item_options.select { |x| item_options.include?(x.id.to_s) }.group_by {|opt| opt.option_type.strip }.map { |type, values| {type: type, values: values.map { |x| x.name.strip } } }
end end
#Menu Item Information #Menu Item Information
json.id item.id json.id item.id
json.code item.item_code json.code item.item_code
json.name item.name json.name item.name
json.alt_name item.alt_name json.alt_name item.alt_name
json.image item.image_path.url json.image item.image_path.url
@@ -69,15 +69,14 @@ if (menu.menu_categories)
json.unit item.unit json.unit item.unit
# Item Sets of Menu Item # Item Sets of Menu Item
json.item_sets item.item_sets.map { |its| json.item_sets item.item_sets do |its|
{ id: its.id, json.id its.id
name: its.name, json.name its.name
alt_name: its.alt_name, json.alt_name its.alt_name
min_selectable_qty: its.min_selectable_qty, json.min_selectable_qty its.min_selectable_qty
max_selectable_qty: its.max_selectable_qty, json.max_selectable_qty its.max_selectable_qty
instances: its.menu_item_instances.map { |i| {id: i.id} } json.instances its.menu_item_instances.map { |i| {id: i.id} }
} end
}
json.attributes attr_format json.attributes attr_format
json.options opt_format json.options opt_format
@@ -85,7 +84,8 @@ if (menu.menu_categories)
json.instances item.menu_item_instances do |is| json.instances item.menu_item_instances do |is|
if is.is_available if is.is_available
# Convert id to name for attributes # Convert id to name for attributes
instance_attr = @item_attributes.select{ |x| item.item_attributes.include?(x.id) }.pluck(:name) item_attributes = is.item_attributes.map(&:to_s)
instance_attr = @item_attributes.select{ |x| item_attributes.include?(x.id.to_s) }.pluck(:name)
json.id is.id json.id is.id
json.code is.item_instance_code json.code is.item_instance_code

View File

@@ -813,8 +813,10 @@
if ($("#server_mode").val() != "cloud") { // first bill not used in cloud if ($("#server_mode").val() != "cloud") { // first bill not used in cloud
if (discount) { if (discount) {
if(checkReceiptNoInFirstBillData(receipt_no,"")){ if(checkReceiptNoInFirstBillData(receipt_no,"")){
$("button.change_tax").hide();
$("#pay").show(); $("#pay").show();
}else{ }else{
$("button.change_tax").show();
$("#pay").hide(); $("#pay").hide();
} }
} }

View File

@@ -1686,9 +1686,8 @@ $(document).ready(function(){
$("#customer_name").on("click",function(){ $("#customer_name").on("click",function(){
//start customer modal popup //start customer modal popup
if((cashier_type=='quick_service' || cashier_type=='food_court') && (customer_id!=undefined) && (customer_id!=null) && (customer_id!="")){ if((cashier_type=='quick_service' || cashier_type=='food_court') && (customer_id!=undefined) && (customer_id!=null) && (customer_id!="")){
// if((customer_id == 'CUS-000000000001') && (customer_name == 'WALK-IN')){
$("#is_memberModal").modal({show : true, backdrop: false, keyboard : false}); $("#is_memberModal").modal({show : true, backdrop: false, keyboard : false});
// }
} }
}); });

View File

@@ -24,15 +24,15 @@
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th colspan="<%= column_count = @payment_methods.length + 8 %>"> <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%></th> <th colspan="<%= column_count = @payment_methods.length + 12 %>"> <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%></th>
</tr> </tr>
<% @count = 1 %> <% @count = 1 %>
<% @payment_methods.each_slice(10) do |slice| %> <% @payment_methods.each_slice(10) do |slice| %>
<tr> <!-- <tr>
<th></th> <th></th>
<th></th> <th></th>
<% alph = "A" %> <% alph = "A" %>
<% slice.each do |payment_method| %> <% slice.each do |payment_method| %>
<th style="text-align:center;"> <th style="text-align:center;">
<%= alph %> <%= alph %>
@@ -46,7 +46,7 @@
<th style="text-align:center;"><%= alph = alph.ord.next.chr %></th> <th style="text-align:center;"><%= alph = alph.ord.next.chr %></th>
<th style="text-align:center;"><%= alph = alph.ord.next.chr %></th> <th style="text-align:center;"><%= alph = alph.ord.next.chr %></th>
<th style="text-align:center;"><%= alph = alph.ord.next.chr %></th> <th style="text-align:center;"><%= alph = alph.ord.next.chr %></th>
</tr> </tr> -->
<!-- <tr> <!-- <tr>
<th style='text-align:center;'><%= t("views.right_panel.detail.sr") %></th> <th style='text-align:center;'><%= t("views.right_panel.detail.sr") %></th>
<th style='text-align:center;'><%= t("views.right_panel.detail.date") %></th> <th style='text-align:center;'><%= t("views.right_panel.detail.date") %></th>
@@ -73,6 +73,12 @@
<th></th> <th></th>
<th colspan="<%= @count + 1 %>" style='text-align:center;'>Income</th> <th colspan="<%= @count + 1 %>" style='text-align:center;'>Income</th>
<th colspan=4 style='text-align:center;'>Outgoing</th> <th colspan=4 style='text-align:center;'>Outgoing</th>
<th style='text-align:center;' data-toggle="tooltip" data-placement="top" title="Gross Sales = (Income+Discount) - (FOC+Void)"><i class="material-icons md-18">live_help</i></th>
<th style='text-align:center;' data-toggle="tooltip" data-placement="top" title="Total Sales = Gross Sales - Discount"><i class="material-icons md-18">live_help</i></th>
<% if @tax.blank? %>
<th style='text-align:center;' data-toggle="tooltip" data-placement="top" title="Tax = Total Sales / 21"><i class="material-icons md-18">live_help</i></th>
<th style='text-align:center;' data-toggle="tooltip" data-placement="top" title="Net Sales = Total Sales - Tax"><i class="material-icons md-18">live_help</i></th>
<% end %>
</tr> </tr>
<tr> <tr>
<th style='text-align:center;'><%= t("views.right_panel.detail.sr") %></th> <th style='text-align:center;'><%= t("views.right_panel.detail.sr") %></th>
@@ -122,7 +128,12 @@
<th style='text-align:center;'>(<%= t("views.right_panel.detail.discount") %>)</th> <th style='text-align:center;'>(<%= t("views.right_panel.detail.discount") %>)</th>
<!-- <th style='text-align:center;'><%= t("views.right_panel.detail.grand_total") %> + <br/> <%= t("views.right_panel.detail.rnd_adj_sh") %></th> --> <!-- <th style='text-align:center;'><%= t("views.right_panel.detail.grand_total") %> + <br/> <%= t("views.right_panel.detail.rnd_adj_sh") %></th> -->
<th style='text-align:center;'><%= t("views.right_panel.detail.rnd_adj_sh") %></th> <th style='text-align:center;'><%= t("views.right_panel.detail.rnd_adj_sh") %></th>
<th style='text-align:center;'><%= t("views.right_panel.detail.grand_total") %></th> <th style='text-align:center;'><%= t("views.right_panel.detail.gross_sales") %></th>
<th style='text-align:center;'><%= t("views.right_panel.detail.total_sales") %></th>
<% if @tax.blank? %>
<th style='text-align:center;'><%= t("views.right_panel.detail.tax") %></th>
<th style='text-align:center;'><%= t("views.right_panel.detail.net_sales") %></th>
<% end %>
</tr> </tr>
</thead> </thead>
@@ -148,6 +159,10 @@
<% total = 0 %> <% total = 0 %>
<% grand_total = 0 %> <% grand_total = 0 %>
<% old_grand_total = 0 %> <% old_grand_total = 0 %>
<% gross_sale = 0 %>
<% total_sale = 0 %>
<% tax = 0 %>
<% net_sale = 0 %>
<% count = 1 %> <% rounding_adj = 0 %> <% count = 1 %> <% rounding_adj = 0 %>
<% @sale_data.each do |sale| %> <% @sale_data.each do |sale| %>
<% void += sale[:void_amount] %> <% void += sale[:void_amount] %>
@@ -171,6 +186,10 @@
<% grand_total += sale[:grand_total].to_f %> <% grand_total += sale[:grand_total].to_f %>
<% old_grand_total += sale[:old_grand_total].to_f %> <% old_grand_total += sale[:old_grand_total].to_f %>
<% rounding_adj += sale[:rounding_adj].to_f %> <% rounding_adj += sale[:rounding_adj].to_f %>
<% gross_sale += sale[:gross_sale].to_f %>
<% total_sale += sale[:total_sale].to_f %>
<% tax += sale[:tax].to_f %>
<% net_sale += sale[:net_sale].to_f %>
<tr> <tr>
<td style='text-align:right;'><%= count %></td> <td style='text-align:right;'><%= count %></td>
<td><%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %></td> <td><%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %></td>
@@ -218,7 +237,12 @@
<td style='text-align:right;'>(<%= number_format(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>)</td> <td style='text-align:right;'>(<%= number_format(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>)</td>
<!-- <td style='text-align:right;'><%= number_format(sale[:grand_total].to_f + sale[:rounding_adj].to_f , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> --> <!-- <td style='text-align:right;'><%= number_format(sale[:grand_total].to_f + sale[:rounding_adj].to_f , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> -->
<td style='text-align:right;'><%= number_format(sale[:rounding_adj].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> <td style='text-align:right;'><%= number_format(sale[:rounding_adj].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(sale[:grand_total], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> <td style='text-align:right;'><%= number_format(sale[:gross_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(sale[:total_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% if @tax.blank? %>
<td style='text-align:right;'><%= number_format(sale[:tax], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(sale[:net_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
</tr> </tr>
<% count = count + 1 %> <% count = count + 1 %>
@@ -303,7 +327,12 @@
<td style='text-align:right;'>(<%= number_format(discount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>)</td> <td style='text-align:right;'>(<%= number_format(discount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>)</td>
<td style='text-align:right;'><%= number_format(rounding_adj, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> <td style='text-align:right;'><%= number_format(rounding_adj, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(grand_total, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> <td style='text-align:right;'><%= number_format(gross_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(total_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% if @tax.blank? %>
<td style='text-align:right;'><%= number_format(tax, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
</tr> </tr>
<tr style="font-weight:600;"> <tr style="font-weight:600;">
@@ -315,19 +344,23 @@
<% @tax.each do |tax| <% @tax.each do |tax|
total_tax += tax.tax_amount.to_f %> total_tax += tax.tax_amount.to_f %>
<tr style="font-weight:600;"> <tr style="font-weight:600;">
<td colspan="<%= colspan %>" style='text-align:right;'><%= tax.tax_name rescue '-'%></td> <td colspan="<%= colspan + 2 %>" style='text-align:right;'><%= tax.tax_name rescue '-'%></td>
<td colspan="2" style='text-align:right;'><%= number_format(tax.tax_amount, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> <td colspan="5" style='text-align:right;'><%= number_format(tax.tax_amount, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr> </tr>
<% end %> <% end %>
<% end %> <% net = grand_total %>
<% net = net - rounding_adj%>
<% net = grand_total %> <% net = net - total_tax %>
<% net = net - rounding_adj%> <tr style="font-weight:600;">
<% net = net - total_tax %> <td colspan="<%= colspan + 2 %>" style='text-align:right;'><%= t("views.right_panel.detail.net_amount") %></td>
<td colspan="5" style='text-align:right;'><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<% else %>
<tr style="font-weight:600;"> <tr style="font-weight:600;">
<td colspan="<%= colspan %>" style='text-align:right;'><%= t("views.right_panel.detail.net_amount") %></td> <td colspan="<%= colspan + 2 %>" style='text-align:right;'><%= t("views.right_panel.detail.net_amount") %></td>
<td colspan="2" style='text-align:right;'><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> <td colspan="5" style='text-align:right;'><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr> </tr>
<% end %>
</tbody> </tbody>
<% end %> <% end %>
</table> </table>

View File

@@ -7,249 +7,307 @@
<body> <body>
<div class="row"> <div class="row">
<div class="col-md-12 col-lg-12"> <div class="col-md-12 col-lg-12">
<div class="card" style="width:129%;"> <div class="card mbl_card">
<div class="body table-responsive"> <div class="body table-responsive">
<table class="table table-bordered"> <table class="table table-bordered">
<thead> <thead>
<tr> <tr>
<th colspan="<%= column_count = @payment_methods.length + 8 %>"> <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%></th> <th colspan="<%= column_count = @payment_methods.length + 12 %>"> <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%></th>
</tr> </tr>
<tr> <% @count = 1 %>
<% @payment_methods.each_slice(10) do |slice| %>
<% end %>
<tr>
<th></th>
<th></th>
<th colspan="<%= @count + 1 %>" style='text-align:center;'>Income</th>
<th colspan=4 style='text-align:center;'>Outgoing</th>
</tr>
<tr>
<th style='text-align:center;'><%= t("views.right_panel.detail.sr") %></th> <th style='text-align:center;'><%= t("views.right_panel.detail.sr") %></th>
<th style='text-align:center;'><%= t("views.right_panel.detail.date") %></th> <th style='text-align:center;'><%= t("views.right_panel.detail.date") %></th>
<% if @payment_methods.include? ("MPU") %> <% if @payment_methods.include? ("MPU") %>
<th style='text-align:center;' class='mobile'><%= t("views.right_panel.detail.mpu_sales") %></th> <th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.mpu_sales") %></th>
<% end %> <% end %>
<% if @payment_methods.include? ("Master") %> <% if @payment_methods.include? ("Master") %>
<th style='text-align:center;'><%= t("views.right_panel.detail.master_sales") %></th> <th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.master_sales") %></th>
<% end %> <% end %>
<% if @payment_methods.include? ("VISA") %> <% if @payment_methods.include? ("VISA") %>
<th style='text-align:center;'><%= t("views.right_panel.detail.visa_sales") %></th> <th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.visa_sales") %></th>
<% end %> <% end %>
<% if @payment_methods.include? ("JCB") %> <% if @payment_methods.include? ("JCB") %>
<th style='text-align:center;'><%= t("views.right_panel.detail.jcb_sales") %></th> <th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.jcb_sales") %></th>
<% end %> <% end %>
<% if @payment_methods.include? ("UNIONPAY") %> <% if @payment_methods.include? ("UNIONPAY") %>
<th style='text-align:center;'><%= t("views.right_panel.detail.unionpay_sales") %></th> <th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.unionpay_sales") %></th>
<% end %> <% end %>
<% if @payment_methods.include? ("KBZPay") %> <% if @payment_methods.include? ("KBZPay") %>
<th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.kbzpay_sales") %></th> <th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.kbzpay_sales") %></th>
<% end %> <% end %>
<% if @payment_methods.include? ("Alipay") %> <% if @payment_methods.include? ("Alipay") %>
<th style='text-align:center;'><%= t("views.right_panel.detail.alipay_sales") %></th> <th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.alipay_sales") %></th>
<% end %> <% end %>
<% if @payment_methods.include? ("PAYMAL") %> <% if @payment_methods.include? ("PAYMAL") %>
<th style='text-align:center;'><%= t("views.right_panel.detail.paymal_sales") %></th> <th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.paymal_sales") %></th>
<% end %> <% end %>
<% if @payment_methods.include? ("DINGA") %> <% if @payment_methods.include? ("DINGA") %>
<th style='text-align:center;'><%= t("views.right_panel.detail.dinga_sales") %></th> <th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.dinga_sales") %></th>
<% end %> <% end %>
<% if @payment_methods.include? ("JunctionPay") %> <% if @payment_methods.include? ("JunctionPay") %>
<th style='text-align:center;'><%= t("views.right_panel.detail.junctionpay_sales") %></th> <th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.junctionpay_sales") %></th>
<% end %> <% end %>
<% if @payment_methods.include? ("Redeem") %> <% if @payment_methods.include? ("Redeem") %>
<th style='text-align:center;'><%= t("views.right_panel.detail.redeem_sales") %></th> <th style='text-align:center;' class="d-none d-sm-table-cell"><%= t("views.right_panel.detail.redeem_sales") %></th>
<% end %>
<% if @payment_methods.include? ("GiftVoucher") %>
<th style='text-align:center;'><%= t("views.right_panel.detail.giftvoucher_sales") %></th>
<% end %> <% end %>
<th style='text-align:center;'><%= t("views.right_panel.detail.cash_sales") %></th> <th style='text-align:center;'><%= t("views.right_panel.detail.cash_sales") %></th>
<th style='text-align:center;'><%= t("views.right_panel.detail.credit_sales") %></th> <th style='text-align:center;'><%= t("views.right_panel.detail.credit_sales") %></th>
<th style='text-align:center;'><%= t("views.right_panel.detail.void_amount") %></th> <th style='text-align:center;'><%= t("views.right_panel.detail.void_amount") %></th>
<th style='text-align:center;'><%= t("views.right_panel.detail.foc_sales") %></th> <th style='text-align:center;'><%= t("views.right_panel.detail.foc_sales") %></th>
<% if @payment_methods.include? ("GiftVoucher") %>
<th style='text-align:center;'><%= t("views.right_panel.detail.giftvoucher_sales") %></th>
<% end %>
<th style='text-align:center;'>(<%= t("views.right_panel.detail.discount") %>)</th>
<!-- <th style='text-align:center;'><%= t("views.right_panel.detail.grand_total") %> + <br/> <%= t("views.right_panel.detail.rnd_adj_sh") %></th> -->
<th style='text-align:center;'><%= t("views.right_panel.detail.rnd_adj_sh") %></th>
<th style='text-align:center;'><%= t("views.right_panel.detail.grand_total") %></th>
<th style='text-align:center;'>(<%= t("views.right_panel.detail.discount") %>)</th>
<!-- <th style='text-align:center;'><%= t("views.right_panel.detail.grand_total") %> + <br/> <%= t("views.right_panel.detail.rnd_adj_sh") %></th> -->
<th style='text-align:center;'><%= t("views.right_panel.detail.rnd_adj_sh") %></th>
<th style='text-align:center;'><%= t("views.right_panel.detail.gross_sales") %></th>
<th style='text-align:center;'><%= t("views.right_panel.detail.total_sales") %></th>
<% if @tax.blank? %>
<th style='text-align:center;'><%= t("views.right_panel.detail.tax") %></th>
<% end %>
<th style='text-align:center;'><%= t("views.right_panel.detail.net_sales") %></th>
</tr> </tr>
</thead> </thead>
<% unless @sale_data.blank? %> <% unless @sale_data.blank? %>
<tbody>
<tbody> <% void = 0 %>
<% void = 0 %> <% mpu = 0 %>
<% mpu = 0 %> <% master = 0 %>
<% master = 0 %> <% visa = 0 %>
<% visa = 0 %> <% jcb = 0 %>
<% jcb = 0 %> <% unionpay = 0 %>
<% unionpay = 0 %> <% alipay = 0 %>
<% alipay = 0 %> <% paymal = 0 %>
<% paymal = 0 %> <% dinga = 0 %>
<% dinga = 0 %> <% junctionpay = 0 %>
<% junctionpay = 0 %> <% giftvoucher = 0 %>
<% giftvoucher = 0 %> <% paypar = 0 %>
<% paypar = 0 %> <% cash = 0 %>
<% cash = 0 %> <% credit = 0 %>
<% credit = 0 %> <% foc = 0 %>
<% foc = 0 %> <% discount = 0 %>
<% discount = 0 %> <% kbzpay = 0 %>
<% kbzpay = 0 %> <% total = 0 %>
<% total = 0 %> <% grand_total = 0 %>
<% grand_total = 0 %> <% old_grand_total = 0 %>
<% old_grand_total = 0 %> <% gross_sale = 0 %>
<% count = 1 %> <% rounding_adj = 0 %> <% total_sale = 0 %>
<% @sale_data.each do |sale| %> <% tax = 0 %>
<% void += sale[:void_amount] %> <% net_sale = 0 %>
<% mpu += sale[:mpu_amount] %> <% count = 1 %> <% rounding_adj = 0 %>
<% master += sale[:master_amount] %> <% @sale_data.each do |sale| %>
<% visa += sale[:visa_amount] %> <% void += sale[:void_amount] %>
<% jcb += sale[:jcb_amount] %> <% mpu += sale[:mpu_amount] %>
<% unionpay += sale[:unionpay_amount] %> <% master += sale[:master_amount] %>
<% alipay += sale[:alipay_amount] %> <% visa += sale[:visa_amount] %>
<% paymal += sale[:paymal_amount] %> <% jcb += sale[:jcb_amount] %>
<% dinga += sale[:dinga_amount] %> <% unionpay += sale[:unionpay_amount] %>
<% junctionpay += sale[:junctionpay_amount] %> <% alipay += sale[:alipay_amount] %>
<% giftvoucher += sale[:giftvoucher_amount] %> <% paymal += sale[:paymal_amount] %>
<% paypar += sale[:paypar_amount] %> <% dinga += sale[:dinga_amount] %>
<% cash += sale[:cash_amount]-sale[:total_change_amount] %> <% junctionpay += sale[:junctionpay_amount] %>
<% credit += sale[:credit_amount] %> <% giftvoucher += sale[:giftvoucher_amount] %>
<% foc += sale[:foc_amount] %> <% paypar += sale[:paypar_amount] %>
<% discount += sale[:total_discount] %> <% cash += sale[:cash_amount]-sale[:total_change_amount] %>
<% kbzpay += sale[:kbzpay_amount] %> <% credit += sale[:credit_amount] %>
<% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %> <% foc += sale[:foc_amount] %>
<% grand_total += sale[:grand_total].to_f %> <% discount += sale[:total_discount] %>
<% old_grand_total += sale[:old_grand_total].to_f %> <% kbzpay += sale[:kbzpay_amount] %>
<% rounding_adj += sale[:rounding_adj].to_f %> <% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %>
<tr> <% grand_total += sale[:grand_total].to_f %>
<td style='text-align:right;'><%= count %></td> <% old_grand_total += sale[:old_grand_total].to_f %>
<td><%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %></td> <% rounding_adj += sale[:rounding_adj].to_f %>
<% if @payment_methods.include? ("MPU") %> <% gross_sale += sale[:gross_sale].to_f %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:mpu_amount]),delimiter => ',') rescue '-'%></td> <% total_sale += sale[:total_sale].to_f %>
<% end %> <% tax += sale[:tax].to_f %>
<% if @payment_methods.include? ("Master") %> <% net_sale += sale[:net_sale].to_f %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:master_amount]),delimiter => ',') rescue '-'%></td> <tr>
<% end %> <td style='text-align:right;'><%= count %></td>
<% if @payment_methods.include? ("VISA") %> <td><%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %></td>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:visa_amount]),delimiter => ',') rescue '-'%></td> <% if @payment_methods.include? ("MPU") %>
<% end %> <td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:mpu_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% if @payment_methods.include? ("JCB") %> <% end %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:jcb_amount]),delimiter => ',') rescue '-'%></td> <% if @payment_methods.include? ("Master") %>
<% end %> <td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:master_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% if @payment_methods.include? ("UNIONPAY") %> <% end %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:unionpay_amount]),delimiter => ',') rescue '-'%></td> <% if @payment_methods.include? ("VISA") %>
<% end %> <td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:visa_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% if @payment_methods.include? ("Alipay") %> <% end %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:alipay_amount]),delimiter => ',') rescue '-'%></td> <% if @payment_methods.include? ("JCB") %>
<% end %> <td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:jcb_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% if @payment_methods.include? ("KBZPay") %> <% end %>
<% if @payment_methods.include? ("UNIONPAY") %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:unionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
<% if @payment_methods.include? ("Alipay") %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:alipay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
<% if @payment_methods.include? ("KBZPay") %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:kbzpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> <td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:kbzpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %> <% end %>
<% if @payment_methods.include? ("PAYMAL") %> <% if @payment_methods.include? ("PAYMAL") %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:paymal_amount]),delimiter => ',') rescue '-'%></td> <td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:paymal_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %> <% end %>
<% if @payment_methods.include? ("DINGA") %> <% if @payment_methods.include? ("DINGA") %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:dinga_amount]),delimiter => ',') rescue '-'%></td> <td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:dinga_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %> <% end %>
<% if @payment_methods.include? ("JunctionPay") %> <% if @payment_methods.include? ("JunctionPay") %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:junctionpay_amount]),delimiter => ',') rescue '-'%></td> <td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:junctionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %> <% end %>
<% if @payment_methods.include? ("Redeem") %> <% if @payment_methods.include? ("Redeem") %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:paypar_amount]),delimiter => ',') rescue '-'%></td> <td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(sale[:paypar_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %> <% end %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:cash_amount]-sale[:total_change_amount]), delimiter: delimiter) rescue '-'%></td> <% if @payment_methods.include? ("GiftVoucher") %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:credit_amount]),delimiter => ',') rescue '-'%></td> <td style='text-align:right;'><%= number_format(sale[:giftvoucher_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='color:red;text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:void_amount]), delimiter => ',') rescue '-'%></td> <% end %>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:foc_amount]),delimiter => ',') rescue '-'%></td> <td style='text-align:right;'><%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision:precision.to_i, delimiter: delimiter) rescue '-'%></td>
<% if @payment_methods.include? ("GiftVoucher") %> <td style='text-align:right;'><%= number_format(sale[:credit_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:giftvoucher_amount]),delimiter => ',') rescue '-'%></td> <td style='color:red;text-align:right;'><%= number_format(sale[:void_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %> <td style='text-align:right;'><%= number_format(sale[:foc_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'>(<%= number_with_delimiter(sprintf("%.2f",sale[:total_discount]), delimiter => ',') rescue '-'%>)</td>
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:rounding_adj].to_f),delimiter => ',') rescue '-'%></td>
<!-- <td style='text-align:right;'><%= number_with_delimiter(sale[:grand_total].to_f + sale[:rounding_adj].to_f ,delimiter => ',') rescue '-'%></td> -->
<td style='text-align:right;'><%= number_with_delimiter(sprintf("%.2f",sale[:grand_total]),delimiter => ',') rescue '-'%></td>
</tr> <td style='text-align:right;'>(<%= number_format(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>)</td>
<% count = count + 1 %> <!-- <td style='text-align:right;'><%= number_format(sale[:grand_total].to_f + sale[:rounding_adj].to_f , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> -->
<% end %> <td style='text-align:right;'><%= number_format(sale[:rounding_adj].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% colspan = 7 %> <td style='text-align:right;'><%= number_format(sale[:gross_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<tr style="font-weight:600;"> <td style='text-align:right;'><%= number_format(sale[:total_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td colspan="2" style='text-align:center;'><b>Total</b></td> <% if @tax.blank? %>
<% if @payment_methods.include? ("MPU") %> <td style='text-align:right;'><%= number_format(sale[:tax], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% colspan += 1 %> <% end %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",mpu),delimiter => ',') rescue '-'%></b></td> <td style='text-align:right;'><%= number_format(sale[:net_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
<% if @payment_methods.include? ("Master") %>
<% colspan += 1 %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",master),delimiter => ',') rescue '-'%></b></td>
<% end %>
<% if @payment_methods.include? ("VISA") %>
<% colspan += 1 %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",visa), delimiter => ',') rescue '-'%></b></td>
<% end %>
<% if @payment_methods.include? ("JCB") %>
<% colspan += 1 %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",jcb),delimiter => ',') rescue '-'%></b></td>
<% end %>
<% if @payment_methods.include? ("UNIONPAY") %>
<% colspan += 1 %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",unionpay),delimiter => ',') rescue '-'%></b></td>
<% end %>
<% if @payment_methods.include? ("Alipay") %>
<% colspan += 1 %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",alipay),delimiter => ',') rescue '-'%></b></td>
<% end %>
<% if @payment_methods.include? ("KBZPay") %>
<% colspan += 1 %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",kbzpay),delimiter => ',') rescue '-'%></b></td>
<% end %>
<% if @payment_methods.include? ("PAYMAL") %>
<% colspan += 1 %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",paymal),delimiter => ',') rescue '-'%></b></td>
<% end %>
<% if @payment_methods.include? ("DINGA") %>
<% colspan += 1 %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",dinga),delimiter => ',') rescue '-'%></b></td>
<% end %>
<% if @payment_methods.include? ("JunctionPay") %>
<% colspan += 1 %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",junctionpay),delimiter => ',') rescue '-'%></b></td>
<% end %>
<% if @payment_methods.include? ("Redeem") %>
<% colspan += 1 %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",paypar),delimiter => ',') rescue '-'%></b></td>
<% end %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",cash),delimiter => ',') rescue '-'%></b></td>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",credit),delimiter => ',') rescue '-'%></b></td>
<td style='color:red;text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",void),delimiter => ',') rescue '-'%></b></td>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",foc), delimiter => ',') rescue '-'%></b></td>
<% if @payment_methods.include? ("GiftVoucher") %>
<% colspan += 1 %>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",giftvoucher), delimiter => ',') rescue '-'%></b></td>
<% end %>
<td style='text-align:right;'><b>(<%= number_with_delimiter(discount,delimiter => ',') rescue '-'%>)</b></td>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",rounding_adj),delimiter => ',') rescue '-'%></b></td>
<td style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",grand_total),delimiter => ',') rescue '-'%></b></td>
</tr> </tr>
<tr> <% count = count + 1 %>
<td colspan="<%= column_count %>">&nbsp;</td> <% end %>
<% colspan = 7 %>
<tr style="font-weight:600;">
<td colspan="2" style='text-align:center;'>Total</td>
<% if @payment_methods.include? ("MPU") %>
<% if !request.user_agent.include? "Mobile" %>
<% colspan += 1 %>
<% end %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(mpu , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end%>
<% if @payment_methods.include? ("Master") %>
<% if !request.user_agent.include? "Mobile" %>
<% colspan += 1 %>
<% end %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(master, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end%>
<% if @payment_methods.include? ("VISA") %>
<% if !request.user_agent.include? "Mobile" %>
<% colspan += 1 %>
<% end %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(visa, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end%>
<% if @payment_methods.include? ("JCB") %>
<% if !request.user_agent.include? "Mobile" %>
<% colspan += 1 %>
<% end %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(jcb, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end%>
<% if @payment_methods.include? ("UNIONPAY") %>
<% if !request.user_agent.include? "Mobile" %>
<% colspan += 1 %>
<% end %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(unionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
<% if @payment_methods.include? ("Alipay") %>
<% if !request.user_agent.include? "Mobile" %>
<% colspan += 1 %>
<% end %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(alipay, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
<% if @payment_methods.include? ("KBZPay") %>
<% if !request.user_agent.include? "Mobile" %>
<% colspan += 1 %>
<% end %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(kbzpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
<% if @payment_methods.include? ("PAYMAL") %>
<% if !request.user_agent.include? "Mobile" %>
<% colspan += 1 %>
<% end %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(paymal, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
<% if @payment_methods.include? ("DINGA") %>
<% if !request.user_agent.include? "Mobile" %>
<% colspan += 1 %>
<% end %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(dinga, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
<% if @payment_methods.include? ("JunctionPay") %>
<% if !request.user_agent.include? "Mobile" %>
<% colspan += 1 %>
<% end %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(junctionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
<% if @payment_methods.include? ("Redeem") %>
<% if !request.user_agent.include? "Mobile" %>
<% colspan += 1 %>
<% end %>
<td style='text-align:right;' class="d-none d-sm-table-cell"><%= number_format(paypar, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
<% if @payment_methods.include? ("GiftVoucher") %>
<% colspan += 1 %>
<td style='text-align:right;'><%= number_format(giftvoucher, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<% end %>
<td style='text-align:right;'><%= number_format(cash, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(credit, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='color:red;text-align:right;'><%= number_format(void, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(foc, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'>(<%= number_format(discount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>)</td>
<td style='text-align:right;'><%= number_format(rounding_adj, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(gross_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(total_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(tax, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td style='text-align:right;'><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<tr style="font-weight:600;">
<td colspan="<%= column_count %>">&nbsp;</td>
</tr>
<% total_tax = 0 %>
<% net = 0 %>
<% unless @tax.blank? %>
<% @tax.each do |tax|
total_tax += tax.tax_amount.to_f %>
<tr style="font-weight:600;">
<td colspan="<%= colspan %>" style='text-align:right;'><%= tax.tax_name rescue '-'%></td>
<td colspan="2" style='text-align:right;'><%= number_format(tax.tax_amount, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<% end %>
<% net = grand_total %>
<% net = net - rounding_adj%>
<% net = net - total_tax %>
<tr style="font-weight:600;">
<td colspan="<%= colspan %>" style='text-align:right;'><%= t("views.right_panel.detail.net_amount") %></td>
<td colspan="5" style='text-align:right;'><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr> </tr>
<% total_tax = 0 %> <% else %>
<% net = 0 %> <tr style="font-weight:600;">
<% unless @tax.blank? %> <td colspan="<%= colspan %>" style='text-align:right;'><%= t("views.right_panel.detail.net_amount") %></td>
<% @tax.each do |tax| <td colspan="5" style='text-align:right;'><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
total_tax += tax.tax_amount.to_f %> </tr>
<tr style="font-weight:600;"> <% end %>
<td colspan="<%= colspan %>" style='text-align:right;'><b><%= tax.tax_name rescue '-'%></b></td> </tbody>
<td colspan="2" style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",tax.tax_amount),delimiter => ',') rescue '-'%></b></td> <% end %>
</tr> </table>
<% end %>
<% end %>
<% net = grand_total %>
<% net = net - rounding_adj%>
<% net = net - total_tax %>
<tr style="font-weight:600;">
<td colspan="<%= colspan %>" style='text-align:right;'><b><%= t("views.right_panel.detail.net_amount") %></b></td>
<td colspan="2" style='text-align:right;'><b><%= number_with_delimiter(sprintf("%.2f",net),delimiter => ',') rescue '-'%></b></td>
</tr>
</tbody>
<% end %>
</table>
</div>
</div> </div>
</div> </div>
</div> </div>
</div>
</div> </div>
</body> </body>

View File

@@ -2,6 +2,57 @@
<%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %>
<% if period_type != false %> <% if period_type != false %>
<div class="row"> <div class="row">
<div class="col-lg-4 col-md-4 col-sm-4" style="padding-left: 17px;">
<%= form_tag reports_hourly_saleitem_index_path, :id => "filter_form", :method => :get do %>
<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.product") %></label>
<input type="text" class="form-control" name="filter" id="Product" type="text" placeholder="Product" style="height: 32px;">
</div>
<!-- <div class="col-lg-2 col-md-2 col-sm-2 text-">
<input type="submit" value="Filter" class='btn btn-primary'>
</div> -->
<% end %>
<div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.from_time") %></label>
<input data-behaviour='timepicker' class="form-control m-t-3 timepicker" value="<%= @start_time %>" name="start_time" id="start_time" type="text" placeholder="From Time" style="height: 32px;">
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.to_time") %></label>
<input data-behaviour='timepicker' class="form-control m-t-3 timepicker" value="<%= @end_time %>" name="end_time" id="end_time" type="text" placeholder="To Time" style="height: 32px;">
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.from") %></label>
<input data-behaviour='datepicker' class="form-control m-t-3 datepicker" name="from" id="from" type="text" placeholder="From date" style="height: 32px;">
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.to") %></label>
<input data-behaviour='datepicker' class="form-control m-t-3 datepicker" name="to" id="to" type="text" placeholder="To date" style="height: 32px;">
</div>
<!-- <input type="hidden" name="report_type" value="sale_item" id="sel_sale_type"> -->
<!-- <div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
<label class="font-14 mbl_lbl">Select Type</label>
<select name="sale_type" id="sel_sale_type" class="form-control">
<option value="">Select Type</option>
<option value="revenue" selected>Revenue Only</option>
<option value="all">All Type</option>
<option value="discount">Discount Only</option>
<option value="void">Void Only</option>
<option value="foc">Foc Only</option>
<option value="promotion">Promotion Only</option>
<option value="other">Other Amount Only</option>
</select>
</div> -->
<!-- <div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.select_account") %></label>
<select name="account_type" id="account_type" class="form-control">
<option value = "">Select Account</option>
<% @account.each do |acc| %>
<option value="<%=acc.title%>" class="<%=acc.title%>" > <%=acc.title%></option>
<%end %>
</select>
</div> -->
<div class="col-lg-2 col-md-2 col-sm-2 mbl-style"> <div class="col-lg-2 col-md-2 col-sm-2 mbl-style">
<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.select_period") %></label> <label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.select_period") %></label>
<select name="period" id="sel_period" class="form-control"> <select name="period" id="sel_period" class="form-control">
@@ -18,39 +69,6 @@
<option value="9">Last year</option> <option value="9">Last year</option>
</select> </select>
</div> </div>
<!-- <input type="hidden" name="report_type" value="sale_item" id="sel_sale_type"> -->
<div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
<label class="font-14 mbl_lbl">Select Type</label>
<select name="sale_type" id="sel_sale_type" class="form-control">
<option value="">Select Type</option>
<option value="revenue" selected>Revenue Only</option>
<option value="all">All Type</option>
<option value="discount">Discount Only</option>
<option value="void">Void Only</option>
<option value="foc">Foc Only</option>
<option value="promotion">Promotion Only</option>
<option value="other">Other Amount Only</option>
</select>
</div>
<!-- <div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.select_account") %></label>
<select name="account_type" id="account_type" class="form-control">
<option value = "">Select Account</option>
<% @account.each do |acc| %>
<option value="<%=acc.title%>" class="<%=acc.title%>" > <%=acc.title%></option>
<%end %>
</select>
</div> -->
<div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
<!-- <label class="">Select Shift Period</label> -->
<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.from") %></label>
<input data-behaviour='datepicker' class="form-control m-t-3 datepicker" name="from" id="from" type="text" placeholder="From date" style="height: 32px;">
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-mbl-view mbl-style">
<label class="font-14 mbl_lbl"><%= t("views.right_panel.detail.to") %></label>
<input data-behaviour='datepicker' class="form-control m-t-3 datepicker" name="to" id="to" type="text" placeholder="To date" style="height: 32px;">
</div>
<div class="col-lg-2 col-md-2 col-sm-2 mbl-style"> <div class="col-lg-2 col-md-2 col-sm-2 mbl-style">
<label class="font-14 mbl_lbl">All Shift</label> <label class="font-14 mbl_lbl">All Shift</label>
<select class="form-control select" name="shift_name" id="shift_name" > <select class="form-control select" name="shift_name" id="shift_name" >

View File

@@ -18,7 +18,10 @@
</div> </div>
<div class="margin-top-20"> <div class="margin-top-20">
<div class="card"> <div class="card">
<div colspan="7" class="report-table-header">
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
</div>
<% if @start_time.blank? || @end_time.blank? %>
<table class="table table-striped" border="0"> <table class="table table-striped" border="0">
<% time_arr = Array.new %> <% time_arr = Array.new %>
<% acc_arr = Array.new %> <% acc_arr = Array.new %>
@@ -32,17 +35,21 @@
<% grand_total = 0 %> <% grand_total = 0 %>
<% @sale_data.each do |sale| %> <% @sale_data.each do |sale| %>
<% if !time_arr.include?(sale.date_format) %> <% if !time_arr.include?(sale.date_format) %>
<% sale_item_count =1 %> <% sale_item_count =1 %>
<% time_count = time_count + 1 %> <% time_count = time_count + 1 %>
<thead> <thead>
<td>&nbsp;</td> <!-- <td>&nbsp;</td> -->
<tr> <tr>
<td> <td>
<strong>Time :<%= sale.date_format %></strong> <% if @start_time.blank? || @end_time.blank? %>
</td> <strong>Time :<%= sale.date_format %></strong>
<% else %>
<strong>Time : <%= "#{@start_time} - #{@end_time}" %></strong>
<% end %>
</td>
<td></td> <td></td>
<td></td> <td></td>
<td colspan="3" style="text-align:right"><strong></strong></td> <td colspan="3" style="text-align:right"><strong></strong></td>
</tr> </tr>
<tr> <tr>
<td><strong>Menu Category</strong></td> <td><strong>Menu Category</strong></td>
@@ -51,7 +58,7 @@
<td><strong>Qty</strong></td> <td><strong>Qty</strong></td>
<td><strong>Price</strong></td> <td><strong>Price</strong></td>
<td><strong>Total Price</strong></td> <td><strong>Total Price</strong></td>
</tr> </tr>
</thead> </thead>
<% time_arr.push(sale.date_format) %> <% time_arr.push(sale.date_format) %>
<% menu_cat_arr.clear %> <% menu_cat_arr.clear %>
@@ -88,24 +95,24 @@
end %> end %>
<% grand_total += sale.grand_total %> <% grand_total += sale.grand_total %>
<% if !sale.item_code.nil?%>
<% if !sale.item_code.nil?%> <% waste_and_spoil_item_count += sale.qty.to_i %>
<% waste_and_spoil_item_count += sale.qty.to_i %> <tr>
<tr> <% if !menu_cat_arr.include?(sale.menu_category_name) %>
<% if !menu_cat_arr.include?(sale.menu_category_name) %>
<td><%= sale.menu_category_name %></td> <td><%= sale.menu_category_name %></td>
<% menu_cat_arr.push(sale.menu_category_name) %> <% menu_cat_arr.push(sale.menu_category_name) %>
<% else %> <% else %>
<td>&nbsp;</td> <td>&nbsp;</td>
<% end %> <% end %>
<td><%= sale.item_code %></td> <td><%= sale.item_code %></td>
<td><%= sale.product_name %></td> <td><%= sale.product_name %></td>
<td><%= sale.total_item.to_i %></td> <td><%= sale.total_item.to_i %></td>
<td><%= number_format(sale.unit_price.to_i, precision:precision.to_i,delimiter:delimiter) %></td> <td><%= number_format(sale.unit_price.to_i, precision:precision.to_i,delimiter:delimiter) %></td>
<td><%= number_format(sale.grand_total.to_i, precision:precision.to_i,delimiter:delimiter) %></td> <td><%= number_format(sale.grand_total.to_i, precision:precision.to_i,delimiter:delimiter) %></td>
<!-- <td><%= sale.date_format %></td> --> <!-- <td><%= sale.date_format %></td> -->
</tr> </tr>
<% end %> <% end %>
<!-- new tr --> <!-- new tr -->
<% count = count + 1 %> <% count = count + 1 %>
<% @hourly_total_qty.each do |hr| %> <% @hourly_total_qty.each do |hr| %>
@@ -134,6 +141,272 @@
</tbody> </tbody>
<% end %> <% end %>
</table> </table>
<% else %>
<table class="table table-striped" id="items_table" border="0">
<thead>
<tr>
<th colspan="7"> <%= t("views.right_panel.detail.from_time") %> : <%= @start_time rescue '-' %> - <%= t("views.right_panel.detail.to_time") %> : <%= @end_time rescue '-'%></th>
</tr>
<% if @shift_from %>
<tr>
<% if @shift_data.employee %>
<% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %>
<% end %>
<th colspan="7"> <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )</th>
</tr>
<% end %>
<tr>
<th>&nbsp;</th>
<th><%= t("views.right_panel.header.menu_category") %></th>
<th><%= t("views.right_panel.detail.code") %></th>
<th><%= t("views.right_panel.detail.product") %></th>
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></th>
<th><%= t("views.right_panel.detail.unit_price") %></th>
<th><%= t("views.right_panel.detail.revenue") %></th>
</tr>
</thead>
<tbody>
<% acc_arr = Array.new %>
<% cate_arr = Array.new %>
<% p_qty = 0 %>
<% sub_qty = 0 %>
<% sub_total = 0 %>
<% other_sub_total = 0 %>
<% product_sub_total = 0 %>
<% count = 0 %>
<% row_count = 0 %>
<% total_price = 0 %>
<% cate_count = 0 %>
<% acc_count = 0 %>
<% grand_total = 0 %>
<% total_qty = 0 %>
<% total_amount = 0 %>
<% discount = 0 %>
<% total_item_foc = 0 %>
<% total_item_dis = 0.0 %>
<% total_tax = 0 %>
<% unless @sale_data.blank? %>
<% @sale_data.each do |sale| %>
<% row_count += 1 %>
<!-- all total qty sum -->
<% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion"
total_qty += sale.total_item
end %>
<% if sale.status_type == "foc" && sale.price > 0
total_qty += sale.total_item
end %>
<% if sale.status_type == "Discount"
total_qty += sale.total_item*(-1)
end %>
<% if sale.status_type =="promotion" && @type == "promotion"
total_qty += sale.total_item*(-1)
end %>
<!-- end all total qty -->
<% if sale.status_type == "foc" && sale.grand_total < 0
total_item_foc += sale.grand_total*(-1)
end %>
<% if sale.status_type == "Discount" && sale.grand_total < 0
total_item_dis += sale.grand_total*(-1)
end %>
<% if !acc_arr.include?(sale.account_id) %>
<tr>
<td><b><%= sale.account_name %></b></td>
<td colspan="4">&nbsp;</td>
<td><%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %></td>
<td>
<% @totalByAccount.each do |account, total| %>
<% if sale.account_id == account %>
<b><%= number_format(total, precision:precision.to_i,delimiter:delimiter) %></b>
<% grand_total += total %>
<% end %>
<% end %>
</td>
</tr>
<% acc_arr.push(sale.account_id) %>
<% end %>
<tr>
<td>&nbsp;</td>
<% if !cate_arr.include?(sale.menu_category_id) %>
<td><%= sale.menu_category_name %></td>
<% cate_arr.push(sale.menu_category_id) %>
<% else %>
<td>&nbsp;</td>
<% end %>
<td><%= sale.item_code rescue '-' %></td>
<td><%= sale.product_name rescue '-' %></td>
<% if sale.status_type != "Discount" %>
<td><%= sale.total_item rescue '-' %></td>
<%else%>
<td><%= sale.total_item*(-1) rescue '-' %></td>
<% end %>
<td><%= number_format(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td><%= number_format(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<!-- sub total -->
<% @menu_cate_count.each do |key,value| %>
<% if sale.account_id == key %>
<% count = count + 1 %>
<% sub_total += sale.grand_total %>
<% #sub_qty += sale.total_item %>
<% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion"
sub_qty += sale.total_item
end %>
<% if sale.status_type =="Discount"
sub_qty += sale.total_item*(-1)
end %>
<% if sale.status_type == "promotion" && @type == "promotion"
sub_qty += sale.total_item*(-1)
end %>
<% if count == value %>
<tr>
<td colspan="3">&nbsp;</td>
<td><b>Total <%= sale.account_name %> Qty </b> </td>
<td><b><%= sub_qty %></b></td>
<td><%= t("views.right_panel.detail.sub_total") %></td>
<td ><span class="underline"><%= number_format(sub_total , precision:precision.to_i,delimiter:delimiter)%> </span></td>
</tr>
<% sub_total = 0.0%>
<% sub_qty = 0 %>
<% count = 0%>
<% end %>
<% end %>
<% end %>
<!-- end sub total -->
<% end %>
<!--Product Sale -->
<% if @product.present?%>
<tr>
<td><b>Product</b></td>
<td colspan="4">&nbsp;</td>
<td></td>
</tr>
<% @product.each do |product| %>
<% if product.total_item > 0
total_qty += product.total_item
end %>
<% grand_total +=product.grand_total
p_qty += product.total_item%>
<tr>
<td>&nbsp;</td>
<td>Product</td>
<td><%= product.product_code rescue '-' %></td>
<td><%= product.product_name rescue '-' %></td>
<td><%= product.total_item rescue '-' %></td>
<td> <%= number_format(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td> <%= number_format(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<!-- sub total -->
<% product_sub_total += product.grand_total %>
<!-- end sub total -->
<% end %>
<tr>
<td colspan="3">&nbsp;</td>
<td><b>Total Product Qty </b> </td>
<td><b><%= p_qty %></b></td>
<td><%= t("views.right_panel.detail.sub_total") %></td>
<td ><span><%= number_format(product_sub_total , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<%end%>
<!-- End Product Sale -->
<!--Other Charges -->
<% if @type == "other" || @other_charges.present?%>
<tr>
<td><b>Other Charges</b></td>
<td colspan="4">&nbsp;</td>
<td></td>
</tr>
<% @other_charges.each do |other| %>
<% if other.total_item > 0
total_qty += other.total_item
end %>
<% grand_total +=other.grand_total%>
<tr>
<td>&nbsp;</td>
<td>Other Charges</td>
<td><%= other.item_code rescue '-' %></td>
<td><%= other.product_name rescue '-' %></td>
<td><%= other.total_item rescue '-' %></td>
<td> <%= number_format(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td> <%= number_format(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<!-- sub total -->
<% other_sub_total += other.grand_total %>
<!-- end sub total -->
<% end %>
<tr>
<td colspan="5">&nbsp;</td>
<td><%= t("views.right_panel.detail.sub_total") %></td>
<td ><span><%= number_format(other_sub_total , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<%end%>
<!-- End Other Charges -->
<tr style="border-top:2px solid grey;">
<td colspan="3">&nbsp;</td>
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></td>
<td><span><%= total_qty%></span></td>
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %></td>
<td><span><%= number_format(grand_total , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<% if @type =="" || @type =="all" || @type.nil? %>
<tr class="foc_payment">
<td colspan="5">&nbsp;</td>
<td>Total FOC Amount</td>
<td><span><%= number_format(@foc_data , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<tr class="foc_payment" style="border-top:2px solid grey;border-bottom:2px solid grey;">
<td colspan="5">&nbsp;</td>
<td style="border-bottom:2px solid grey;"><%= t("views.right_panel.detail.net_amount") %></td>
<td style="border-bottom:2px solid grey;"><span><%= number_format(grand_total -@foc_data , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<% end %>
<% end %>
<% if @type == "other"%>
<tr>
<td><b>Other Charges</b></td>
<td colspan="4">&nbsp;</td>
<td></td>
</tr>
<% @other_charges.each do |other| %>
<% if other.total_item > 0
total_qty += other.total_item
end %>
<% grand_total +=other.grand_total%>
<tr>
<td>&nbsp;</td>
<td>Other Charges</td>
<td><%= other.item_code rescue '-' %></td>
<td><%= other.product_name rescue '-' %></td>
<td><%= other.total_item rescue '-' %></td>
<td> <%= number_format(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td> <%= number_format(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<!-- sub total -->
<% other_sub_total += other.grand_total %>
<!-- end sub total -->
<% end %>
<tr>
<td colspan="5">&nbsp;</td>
<td><%= t("views.right_panel.detail.sub_total") %></td>
<td ><span><%= number_format(other_sub_total , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<%end%>
</tbody>
</table>
<% end %>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -8,7 +8,11 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<div class="margin-top-20"> <div class="margin-top-20">
<div class="card"> <div class="card">
<div colspan="7" class="report-table-header">
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
</div>
<% if @start_time.blank? || @end_time.blank? %>
<table class="table table-striped" border="0"> <table class="table table-striped" border="0">
<% time_arr = Array.new %> <% time_arr = Array.new %>
<% acc_arr = Array.new %> <% acc_arr = Array.new %>
@@ -22,17 +26,21 @@
<% grand_total = 0 %> <% grand_total = 0 %>
<% @sale_data.each do |sale| %> <% @sale_data.each do |sale| %>
<% if !time_arr.include?(sale.date_format) %> <% if !time_arr.include?(sale.date_format) %>
<% sale_item_count =1 %> <% sale_item_count =1 %>
<% time_count = time_count + 1 %> <% time_count = time_count + 1 %>
<thead> <thead>
<td>&nbsp;</td> <!-- <td>&nbsp;</td> -->
<tr> <tr>
<td> <td>
<strong>Time :<%= sale.date_format %></strong> <% if @start_time.blank? || @end_time.blank? %>
</td> <strong>Time :<%= sale.date_format %></strong>
<% else %>
<strong>Time : <%= "#{@start_time} - #{@end_time}" %></strong>
<% end %>
</td>
<td></td> <td></td>
<td></td> <td></td>
<td colspan="3" style="text-align:right"><strong></strong></td> <td colspan="3" style="text-align:right"><strong></strong></td>
</tr> </tr>
<tr> <tr>
<td><strong>Menu Category</strong></td> <td><strong>Menu Category</strong></td>
@@ -41,7 +49,7 @@
<td><strong>Qty</strong></td> <td><strong>Qty</strong></td>
<td><strong>Price</strong></td> <td><strong>Price</strong></td>
<td><strong>Total Price</strong></td> <td><strong>Total Price</strong></td>
</tr> </tr>
</thead> </thead>
<% time_arr.push(sale.date_format) %> <% time_arr.push(sale.date_format) %>
<% menu_cat_arr.clear %> <% menu_cat_arr.clear %>
@@ -78,24 +86,24 @@
end %> end %>
<% grand_total += sale.grand_total %> <% grand_total += sale.grand_total %>
<% if !sale.item_code.nil?%>
<% if !sale.item_code.nil?%> <% waste_and_spoil_item_count += sale.qty.to_i %>
<% waste_and_spoil_item_count += sale.qty.to_i %> <tr>
<tr> <% if !menu_cat_arr.include?(sale.menu_category_name) %>
<% if !menu_cat_arr.include?(sale.menu_category_name) %>
<td><%= sale.menu_category_name %></td> <td><%= sale.menu_category_name %></td>
<% menu_cat_arr.push(sale.menu_category_name) %> <% menu_cat_arr.push(sale.menu_category_name) %>
<% else %> <% else %>
<td>&nbsp;</td> <td>&nbsp;</td>
<% end %> <% end %>
<td><%= sale.item_code %></td> <td><%= sale.item_code %></td>
<td><%= sale.product_name %></td> <td><%= sale.product_name %></td>
<td><%= sale.total_item.to_i %></td> <td><%= sale.total_item.to_i %></td>
<td><%= number_format(sale.unit_price.to_i, precision:precision.to_i,delimiter:delimiter) %></td> <td><%= number_format(sale.unit_price.to_i, precision:precision.to_i,delimiter:delimiter) %></td>
<td><%= number_format(sale.grand_total.to_i, precision:precision.to_i,delimiter:delimiter) %></td> <td><%= number_format(sale.grand_total.to_i, precision:precision.to_i,delimiter:delimiter) %></td>
<!-- <td><%= sale.date_format %></td> --> <!-- <td><%= sale.date_format %></td> -->
</tr> </tr>
<% end %> <% end %>
<!-- new tr --> <!-- new tr -->
<% count = count + 1 %> <% count = count + 1 %>
<% @hourly_total_qty.each do |hr| %> <% @hourly_total_qty.each do |hr| %>
@@ -118,11 +126,278 @@
</tr> </tr>
<% footer_arr.push(sale.sale_id) %> <% footer_arr.push(sale.sale_id) %>
<% else %> <% else %>
<% end %> <% end %>
<% end %> <% end %>
</tbody> </tbody>
<% end %> <% end %>
</table> </table>
<% else %>
<table class="table table-striped" id="items_table" border="0">
<thead>
<tr>
<th colspan="7"> <%= t("views.right_panel.detail.from_time") %> : <%= @start_time rescue '-' %> - <%= t("views.right_panel.detail.to_time") %> : <%= @end_time rescue '-'%></th>
</tr>
<% if @shift_from %>
<tr>
<% if @shift_data.employee %>
<% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %>
<% end %>
<th colspan="7"> <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )</th>
</tr>
<% end %>
<tr>
<th>&nbsp;</th>
<th><%= t("views.right_panel.header.menu_category") %></th>
<th><%= t("views.right_panel.detail.code") %></th>
<th><%= t("views.right_panel.detail.product") %></th>
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></th>
<th><%= t("views.right_panel.detail.unit_price") %></th>
<th><%= t("views.right_panel.detail.revenue") %></th>
</tr>
</thead>
<tbody>
<% acc_arr = Array.new %>
<% cate_arr = Array.new %>
<% p_qty = 0 %>
<% sub_qty = 0 %>
<% sub_total = 0 %>
<% other_sub_total = 0 %>
<% product_sub_total = 0 %>
<% count = 0 %>
<% row_count = 0 %>
<% total_price = 0 %>
<% cate_count = 0 %>
<% acc_count = 0 %>
<% grand_total = 0 %>
<% total_qty = 0 %>
<% total_amount = 0 %>
<% discount = 0 %>
<% total_item_foc = 0 %>
<% total_item_dis = 0.0 %>
<% total_tax = 0 %>
<% unless @sale_data.blank? %>
<% @sale_data.each do |sale| %>
<% row_count += 1 %>
<!-- all total qty sum -->
<% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion"
total_qty += sale.total_item
end %>
<% if sale.status_type == "foc" && sale.price > 0
total_qty += sale.total_item
end %>
<% if sale.status_type == "Discount"
total_qty += sale.total_item*(-1)
end %>
<% if sale.status_type =="promotion" && @type == "promotion"
total_qty += sale.total_item*(-1)
end %>
<!-- end all total qty -->
<% if sale.status_type == "foc" && sale.grand_total < 0
total_item_foc += sale.grand_total*(-1)
end %>
<% if sale.status_type == "Discount" && sale.grand_total < 0
total_item_dis += sale.grand_total*(-1)
end %>
<% if !acc_arr.include?(sale.account_id) %>
<tr>
<td><b><%= sale.account_name %></b></td>
<td colspan="4">&nbsp;</td>
<td><%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %></td>
<td>
<% @totalByAccount.each do |account, total| %>
<% if sale.account_id == account %>
<b><%= number_format(total, precision:precision.to_i,delimiter:delimiter) %></b>
<% grand_total += total %>
<% end %>
<% end %>
</td>
</tr>
<% acc_arr.push(sale.account_id) %>
<% end %>
<tr>
<td>&nbsp;</td>
<% if !cate_arr.include?(sale.menu_category_id) %>
<td><%= sale.menu_category_name %></td>
<% cate_arr.push(sale.menu_category_id) %>
<% else %>
<td>&nbsp;</td>
<% end %>
<td><%= sale.item_code rescue '-' %></td>
<td><%= sale.product_name rescue '-' %></td>
<% if sale.status_type != "Discount" %>
<td><%= sale.total_item rescue '-' %></td>
<%else%>
<td><%= sale.total_item*(-1) rescue '-' %></td>
<% end %>
<td><%= number_format(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td><%= number_format(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<!-- sub total -->
<% @menu_cate_count.each do |key,value| %>
<% if sale.account_id == key %>
<% count = count + 1 %>
<% sub_total += sale.grand_total %>
<% #sub_qty += sale.total_item %>
<% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion"
sub_qty += sale.total_item
end %>
<% if sale.status_type =="Discount"
sub_qty += sale.total_item*(-1)
end %>
<% if sale.status_type == "promotion" && @type == "promotion"
sub_qty += sale.total_item*(-1)
end %>
<% if count == value %>
<tr>
<td colspan="3">&nbsp;</td>
<td><b>Total <%= sale.account_name %> Qty </b> </td>
<td><b><%= sub_qty %></b></td>
<td><%= t("views.right_panel.detail.sub_total") %></td>
<td ><span class="underline"><%= number_format(sub_total , precision:precision.to_i,delimiter:delimiter)%> </span></td>
</tr>
<% sub_total = 0.0%>
<% sub_qty = 0 %>
<% count = 0%>
<% end %>
<% end %>
<% end %>
<!-- end sub total -->
<% end %>
<!--Product Sale -->
<% if @product.present?%>
<tr>
<td><b>Product</b></td>
<td colspan="4">&nbsp;</td>
<td></td>
</tr>
<% @product.each do |product| %>
<% if product.total_item > 0
total_qty += product.total_item
end %>
<% grand_total +=product.grand_total
p_qty += product.total_item%>
<tr>
<td>&nbsp;</td>
<td>Product</td>
<td><%= product.product_code rescue '-' %></td>
<td><%= product.product_name rescue '-' %></td>
<td><%= product.total_item rescue '-' %></td>
<td> <%= number_format(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td> <%= number_format(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<!-- sub total -->
<% product_sub_total += product.grand_total %>
<!-- end sub total -->
<% end %>
<tr>
<td colspan="3">&nbsp;</td>
<td><b>Total Product Qty </b> </td>
<td><b><%= p_qty %></b></td>
<td><%= t("views.right_panel.detail.sub_total") %></td>
<td ><span><%= number_format(product_sub_total , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<%end%>
<!-- End Product Sale -->
<!--Other Charges -->
<% if @type == "other" || @other_charges.present?%>
<tr>
<td><b>Other Charges</b></td>
<td colspan="4">&nbsp;</td>
<td></td>
</tr>
<% @other_charges.each do |other| %>
<% if other.total_item > 0
total_qty += other.total_item
end %>
<% grand_total +=other.grand_total%>
<tr>
<td>&nbsp;</td>
<td>Other Charges</td>
<td><%= other.item_code rescue '-' %></td>
<td><%= other.product_name rescue '-' %></td>
<td><%= other.total_item rescue '-' %></td>
<td> <%= number_format(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td> <%= number_format(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<!-- sub total -->
<% other_sub_total += other.grand_total %>
<!-- end sub total -->
<% end %>
<tr>
<td colspan="5">&nbsp;</td>
<td><%= t("views.right_panel.detail.sub_total") %></td>
<td ><span><%= number_format(other_sub_total , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<%end%>
<!-- End Other Charges -->
<tr style="border-top:2px solid grey;">
<td colspan="3">&nbsp;</td>
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></td>
<td><span><%= total_qty%></span></td>
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %></td>
<td><span><%= number_format(grand_total , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<% if @type =="" || @type =="all" || @type.nil? %>
<tr class="foc_payment">
<td colspan="5">&nbsp;</td>
<td>Total FOC Amount</td>
<td><span><%= number_format(@foc_data , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<tr class="foc_payment" style="border-top:2px solid grey;border-bottom:2px solid grey;">
<td colspan="5">&nbsp;</td>
<td style="border-bottom:2px solid grey;"><%= t("views.right_panel.detail.net_amount") %></td>
<td style="border-bottom:2px solid grey;"><span><%= number_format(grand_total -@foc_data , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<% end %>
<% end %>
<% if @type == "other"%>
<tr>
<td><b>Other Charges</b></td>
<td colspan="4">&nbsp;</td>
<td></td>
</tr>
<% @other_charges.each do |other| %>
<% if other.total_item > 0
total_qty += other.total_item
end %>
<% grand_total +=other.grand_total%>
<tr>
<td>&nbsp;</td>
<td>Other Charges</td>
<td><%= other.item_code rescue '-' %></td>
<td><%= other.product_name rescue '-' %></td>
<td><%= other.total_item rescue '-' %></td>
<td> <%= number_format(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td> <%= number_format(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<!-- sub total -->
<% other_sub_total += other.grand_total %>
<!-- end sub total -->
<% end %>
<tr>
<td colspan="5">&nbsp;</td>
<td><%= t("views.right_panel.detail.sub_total") %></td>
<td ><span><%= number_format(other_sub_total , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<%end%>
</tbody>
</table>
<% end %>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -136,23 +136,24 @@
<% sale_payments = result.sale_payments %> <% sale_payments = result.sale_payments %>
<% if sale_payments.length > 0%> <% if sale_payments.length > 0%>
<% sale_payments.each do |rec| %> <% sale_payments.each do |rec| %>
<% next if rec.payment_method == 'credit_note' && result.payments_for_credits_amount < rec.payment_amount %> <% if rec.payment_amount > 0 %>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Payment <%= rec.payment_method.upcase %></td>
<td><%= number_format(rec.payment_amount, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %> ( <%= rec.payment_status %> )</td>
<td>&nbsp;</td>
</tr>
<% if !rec.payment_reference.nil? %>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>Payment Ref.</td> <td>Payment <%= rec.payment_method.upcase %></td>
<td><%= rec.payment_reference %></td> <td><%= number_format(rec.payment_amount, precision: precision, delimiter: delimiter, strip_insignificant_zeros: strip_insignificant_zeros) %> ( <%= rec.payment_status %> )</td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<% if !rec.payment_reference.nil? %>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>Payment Ref.</td>
<td><%= rec.payment_reference %></td>
<td>&nbsp;</td>
</tr>
<% end %>
<% end %> <% end %>
<% end %> <% end %>
<% if result.amount_changed != 0 %> <% if result.amount_changed != 0 %>

View File

@@ -9,7 +9,7 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="margin-top-20"> <div class="margin-top-20">
<div class="card"> <div class="card">
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped" border="0"> <table class="table table-striped" border="0">
<thead> <thead>
<tr> <tr>
@@ -18,9 +18,9 @@
</tr> </tr>
<% if @shift_from %> <% if @shift_from %>
<tr> <tr>
<% if @shift_data.employee %> <% if @shift_data.employee %>
<% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %>
<% end %> <% end %>
<th colspan="7"><%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )</th> <th colspan="7"><%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )</th>
</tr> </tr>
<% end %> <% end %>
@@ -28,19 +28,18 @@
<th><b><%= t("views.right_panel.detail.shift_name") %></b></th> <th><b><%= t("views.right_panel.detail.shift_name") %></b></th>
<th><b><%= t("views.right_panel.detail.table") %></b></th> <th><b><%= t("views.right_panel.detail.table") %></b></th>
<th><b><%= t("views.right_panel.detail.receipt_no") %></b></th> <th><b><%= t("views.right_panel.detail.receipt_no") %></b></th>
<th><b><%= t :cashier %> <%= t("views.right_panel.detail.name") %></b></th> <th><b><%= t :cashier %> <%= t("views.right_panel.detail.name") %></b></th>
<th><b><%= t("views.right_panel.detail.revenue") %></b></th> <th><b><%= t("views.right_panel.detail.revenue") %></b></th>
<th>&nbsp;</th> <th>&nbsp;</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% grand_total = 0 %> <% grand_total = 0 %>
<% @sale_data.each do |result| %> <% @sale_data.each do |result| %>
<% grand_total = grand_total.to_f + result.grand_total.to_f%> <% grand_total = grand_total.to_f + result.grand_total.to_f%>
<% table_name=nil <% table_name=nil
table_type =nil table_type =nil
if result.table_id.to_i>0 if table = result.bookings[0].dining_facility
table = DiningFacility.find(result.table_id)
table_type = table.type table_type = table.type
table_name = table.name table_name = table.name
end %> end %>
@@ -48,7 +47,7 @@
<td><%= @shift_from %> - <%= @shift_to %></td> <td><%= @shift_from %> - <%= @shift_to %></td>
<td><%= table_type %> - <%= table_name %></td> <td><%= table_type %> - <%= table_name %></td>
<td><%= result.receipt_no rescue '-' %> </td> <td><%= result.receipt_no rescue '-' %> </td>
<td><%= result.cashier_name rescue '-' %></td> <td><%= result.cashier_name rescue '-' %></td>
<td><%=result.grand_total%></td> <td><%=result.grand_total%></td>
<!-- <td>&nbsp;</td> --> <!-- <td>&nbsp;</td> -->
</tr> </tr>
@@ -67,8 +66,8 @@
<% if item.price.to_i < 0.to_i %> <% if item.price.to_i < 0.to_i %>
<% if item.qty.to_i < 0.to_i%> <% if item.qty.to_i < 0.to_i%>
[PROMO QTY]<%= item.product_name rescue '-' %> [PROMO QTY]<%= item.product_name rescue '-' %>
<% else %> <% else %>
[PROMO PRICE]<%= item.product_name rescue '-' %> [PROMO PRICE]<%= item.product_name rescue '-' %>
<% end %> <% end %>
<% else %> <% else %>
<%= item.product_name rescue '-' %> <%= item.product_name rescue '-' %>
@@ -77,71 +76,71 @@
<td><%= item.qty rescue '-' %></td> <td><%= item.qty rescue '-' %></td>
<td><%= item.unit_price rescue '-' %></td> <td><%= item.unit_price rescue '-' %></td>
<td><%= item.price rescue '-' %></td> <td><%= item.price rescue '-' %></td>
<td><%=l item.created_at.utc.getlocal, :format => :short rescue '-' %> </td> <td><%=l item.created_at.utc.getlocal, :format => :short rescue '-' %> </td>
</tr> </tr>
<% end %> <% end %>
<tr><td colspan="5">&nbsp;</td></tr> <tr><td colspan="5">&nbsp;</td></tr>
<%survey = Survey.find_by_receipt_no(result.receipt_no)%> <%survey = Survey.find_by_receipt_no(result.receipt_no)%>
<% if !survey.nil?%> <% if !survey.nil?%>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>No. of Guest</td> <td>No. of Guest</td>
<td><%= survey.total_customer rescue '-' %></td> <td><%= survey.total_customer rescue '-' %></td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<% end %> <% end %>
<% if !result.total_amount.nil?%> <% if !result.total_amount.nil?%>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %></td> <td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %></td>
<td><%= result.total_amount %></td> <td><%= result.total_amount %></td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<% end %> <% end %>
<% if result.total_discount.to_f > 0 %> <% if result.total_discount.to_f > 0 %>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td><%= t("views.right_panel.detail.total") %> <td><%= t("views.right_panel.detail.total") %>
<%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.discount") %>
<%= t("views.right_panel.detail.amount") %></td> <%= t("views.right_panel.detail.amount") %></td>
<td> - <%= result.total_discount %> </td> <td> - <%= result.total_discount %> </td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<% end %> <% end %>
<% if !result.total_tax.nil? %> <% if !result.total_tax.nil? %>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>Tax Amount </td> <td>Tax Amount </td>
<td><%= result.total_tax %> </td> <td><%= result.total_tax %> </td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<% end %> <% end %>
<% sale_payments = SalePayment.get_sale_payments(result) %> <% sale_payments = result.sale_payments %>
<% if sale_payments.length > 0%> <% if sale_payments.length > 0%>
<% sale_payments.each do |rec| %> <% sale_payments.each do |rec| %>
<%if rec.payment_amount.to_f > 0 %> <%if rec.payment_amount.to_f > 0 %>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td>
<td>Payment <%= rec.payment_method.upcase %></td>
<td><%= rec.payment_amount %> ( <%= result.payment_status %> )</td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> <td>Payment <%= rec.payment_method.upcase %></td>
<td><%= rec.payment_amount %> ( <%= rec.payment_status %> )</td>
<td>&nbsp;</td>
</tr>
<% if !rec.payment_reference.nil? %> <% if !rec.payment_reference.nil? %>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>Payment Ref.</td> <td>Payment Ref.</td>
<td><%= rec.payment_reference %></td> <td><%= rec.payment_reference %></td>
<td>&nbsp;</td> <td>&nbsp;</td>
@@ -149,10 +148,10 @@
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
<% if result.amount_changed != 0 && !result.amount_changed.nil? %> <% if result.amount_changed != 0 && !result.amount_changed.nil? %>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td><%= t("views.right_panel.detail.change") %> <%= t("views.right_panel.detail.amount") %></td> <td><%= t("views.right_panel.detail.change") %> <%= t("views.right_panel.detail.amount") %></td>
<td><%= result.amount_changed %></td> <td><%= result.amount_changed %></td>
<td>&nbsp;</td> <td>&nbsp;</td>
@@ -161,32 +160,32 @@
<% if !result.customer_id.nil?%> <% if !result.customer_id.nil?%>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>Customer</td> <td>Customer</td>
<td><%= result.customer.name rescue '-'%> <td><%= result.customer.name rescue '-'%>
(<%= result.customer.company rescue '-' %>) (<%= result.customer.company rescue '-' %>)
</td> </td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>
<tr style="border-top:4px double #666;"> <tr style="border-top:4px double #666;">
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td><b>Total Nett</b> - <b><%= grand_total %></b></td> <td><b>Total Nett</b> - <b><%= grand_total %></b></td>
<td>&nbsp;</td> <td>&nbsp;</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</body> </body>
</html> </html>

View File

@@ -121,7 +121,7 @@
<td><%= sale.total_item rescue '-' %></td> <td><%= sale.total_item rescue '-' %></td>
<%else%> <%else%>
<td><%= sale.total_item*(-1) rescue '-' %></td> <td><%= sale.total_item*(-1) rescue '-' %></td>
<% end %> <% end %>
<td><%= number_format(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> <td><%= number_format(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td><%= number_format(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> <td><%= number_format(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>

View File

@@ -11,7 +11,7 @@
<%= f.input :seater %> <%= f.input :seater %>
<%= f.input :order_by %> <%= f.input :order_by %>
<%= f.input :is_active %> <%= f.input :is_active %>
<% if @settings_room.dining_charges.length == 0 %> <% if @settings_room.dining_charge.nil? %>
<% if @settings_room.id != nil %> <% if @settings_room.id != nil %>
<div class=""> <div class="">
<div class=""> <div class="">
@@ -20,33 +20,31 @@
</div> </div>
<% end %> <% end %>
<% else %> <% else %>
<% @settings_room.dining_charges.each do |dc| %> <% dc = @settings_room.dining_charge %>
<div class="card"> <div class="card">
<div class="col-md-"> <div class="col-md-">
<table class="table"> <table class="table">
<tr><td colspan="2"> <tr><td colspan="2">
<div class="col-md-10"><b><u>Dining Charge</u></b></div></td> <div class="col-md-10"><b><u>Dining Charge</u></b></div></td>
</tr> </tr>
<tr> <tr>
<td class="align-right">Item code :</td> <td class="align-right">Item code :</td>
<td class="align-left"><%= dc.item_code %></td> <td class="align-left"><%= dc.item_code %></td>
<td class="align-right">Unit price : </td> <td class="align-right">Unit price : </td>
<td class="align-left"><%= dc.unit_price %></td> <td class="align-left"><%= dc.unit_price %></td>
<td class="align-right">Charge type : </td> <td class="align-right">Charge type : </td>
<td class="align-left"><%= dc.charge_type %></td> <td class="align-left"><%= dc.charge_type %></td>
<td> <td>
<%= link_to 'Edit Charges', edit_settings_zone_room_dining_charge_path(@zone,@settings_room,dc),:class => 'btn bg-deep-purple' %> <%= link_to 'Edit Charges', edit_settings_zone_room_dining_charge_path(@zone,@settings_room,dc),:class => 'btn bg-deep-purple' %>
<!-- <button class="btn btn-primary" src="<%= edit_settings_zone_room_dining_charge_path(@zone,@settings_room,dc) %>">Edit Charge</button> --> <!-- <button class="btn btn-primary" src="<%= edit_settings_zone_room_dining_charge_path(@zone,@settings_room,dc) %>">Edit Charge</button> -->
</td> </td>
</tr> </tr>
</table> </table>
</div>
</div> </div>
<% end %> </div>
<% end %> <% end %>
</div> </div>
@@ -62,7 +60,7 @@
<div class="body"> <div class="body">
<h5><i class="material-icons md-18">view_headline <%= t("views.right_panel.header.page_detail") %></i></h5> <h5><i class="material-icons md-18">view_headline <%= t("views.right_panel.header.page_detail") %></i></h5>
<p> <p>
1) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.room_txt") %> <%= t("views.right_panel.detail.name_txt2") %> <br> 1) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.room_txt") %> <%= t("views.right_panel.detail.name_txt2") %> <br>
2) <%= t("views.right_panel.detail.status") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.status_txt") %> <br> 2) <%= t("views.right_panel.detail.status") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.status_txt") %> <br>
3) <%= t("views.right_panel.detail.seater") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.seat_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.room_txt") %> <br> 3) <%= t("views.right_panel.detail.seater") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.seat_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.room_txt") %> <br>
4) <%= t("views.right_panel.detail.order_by") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.order_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.room_txt") %> <br> 4) <%= t("views.right_panel.detail.order_by") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.order_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.room_txt") %> <br>
@@ -78,7 +76,6 @@
2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.zone_txt") %> <%= t("views.right_panel.detail.detail_txt") %> <br> 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.zone_txt") %> <%= t("views.right_panel.detail.detail_txt") %> <br>
</p> </p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -11,14 +11,14 @@
<%= f.input :seater %> <%= f.input :seater %>
<%= f.input :order_by %> <%= f.input :order_by %>
<%= f.input :is_active %> <%= f.input :is_active %>
<% if @settings_table.dining_charges.length == 0 %> <% if @settings_table.dining_charge.nil? %>
<% if @settings_table.id != nil %> <% if @settings_table.id != nil %>
<div class="col-md-"> <div class="col-md-">
<%= link_to 'Add For Extra Charges', new_settings_zone_table_dining_charge_path(@zone,@settings_table),:class => 'btn bg-deep-purple' %> <%= link_to 'Add For Extra Charges', new_settings_zone_table_dining_charge_path(@zone,@settings_table),:class => 'btn bg-deep-purple' %>
</div> </div>
<% end %> <% end %>
<% else %> <% else %>
<% @settings_table.dining_charges.each do |dc| %> <% dc = @settings_table.dining_charge %>
<div class="card"> <div class="card">
<div class="body"> <div class="body">
<span class="card-title"><b><u>Dining Charge</u></b></span> <span class="card-title"><b><u>Dining Charge</u></b></span>
@@ -48,7 +48,6 @@
</table> </table>
</div> </div>
</div> </div>
<% end %>
<% end %> <% end %>
</div> </div>
@@ -64,7 +63,7 @@
<div class="body"> <div class="body">
<h5><i class="material-icons md-18">view_headline <%= t("views.right_panel.header.page_detail") %></i></h5> <h5><i class="material-icons md-18">view_headline <%= t("views.right_panel.header.page_detail") %></i></h5>
<p> <p>
1) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.table_txt") %> <%= t("views.right_panel.detail.name_txt2") %> <br> 1) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.table_txt") %> <%= t("views.right_panel.detail.name_txt2") %> <br>
2) <%= t("views.right_panel.detail.status") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.status_txt") %> <br> 2) <%= t("views.right_panel.detail.status") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.status_txt") %> <br>
3) <%= t("views.right_panel.detail.seater") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.seat_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.table_txt") %> <br> 3) <%= t("views.right_panel.detail.seater") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.seat_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.table_txt") %> <br>
4) <%= t("views.right_panel.detail.order_by") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.order_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.table_txt") %> <br> 4) <%= t("views.right_panel.detail.order_by") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.order_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.table_txt") %> <br>
@@ -81,8 +80,6 @@
2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.zone_txt") %> <br> 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.zone_txt") %> <br>
</p> </p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -53,43 +53,42 @@
<span class="hidden" id="delete_text"> <span class="hidden" id="delete_text">
<h6>Are you sure you want to delete this row ?</h6> <h6>Are you sure you want to delete this row ?</h6>
<h6>This action can't be undo. </h6> <h6>This action can't be undo. </h6>
</span> </span>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<% @table.dining_charges.each do |dc| %> <% dc = @table.dining_charge %>
<div class="card"> <div class="card">
<div class="body"> <div class="body">
<h4 class="card-title">Dining Charge</h4> <h4 class="card-title">Dining Charge</h4>
<table class="table"> <table class="table">
<thead> <thead>
<th>Item Code</th> <th>Item Code</th>
<th>Unit Price</th> <th>Unit Price</th>
<th>Charge Type</th> <th>Charge Type</th>
<th>Free Time</th> <th>Free Time</th>
<th>Charges Block</th> <th>Charges Block</th>
<th>Time Rounding</th> <th>Time Rounding</th>
<th>Actions</th> <th>Actions</th>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td><%= dc.item_code %></td> <td><%= dc.item_code %></td>
<td><%= dc.unit_price %></td> <td><%= dc.unit_price %></td>
<td><%= dc.charge_type %></td> <td><%= dc.charge_type %></td>
<td><%= (dc.minimum_free_time).utc.strftime("%H:%M") %></td> <td><%= (dc.minimum_free_time).utc.strftime("%H:%M") %></td>
<td><%= (dc.charge_block).utc.strftime("%H:%M") %></td> <td><%= (dc.charge_block).utc.strftime("%H:%M") %></td>
<td><%= dc.time_rounding %></td> <td><%= dc.time_rounding %></td>
<td><%= link_to 'Edit Charges', edit_settings_zone_table_dining_charge_path(@zone,@settings_table,dc),:class => 'btn bg-deep-purple' %> <td><%= link_to 'Edit Charges', edit_settings_zone_table_dining_charge_path(@zone,@settings_table,dc),:class => 'btn bg-deep-purple' %>
<!-- <button class="btn btn-primary" src="<%= edit_settings_zone_table_dining_charge_path(@zone,@settings_table,dc) %>">Edit Charge</button> --> <!-- <button class="btn btn-primary" src="<%= edit_settings_zone_table_dining_charge_path(@zone,@settings_table,dc) %>">Edit Charge</button> -->
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div>
</div> </div>
<% end %> </div>
</div> </div>
</div> </div>
</div> </div>
@@ -98,7 +97,7 @@
<div class="body"> <div class="body">
<h5><i class="material-icons md-18">view_headline <%= t("views.right_panel.header.page_detail") %></i></h5> <h5><i class="material-icons md-18">view_headline <%= t("views.right_panel.header.page_detail") %></i></h5>
<p> <p>
1) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.table_txt") %> <%= t("views.right_panel.detail.name_txt") %> <%= t("views.right_panel.detail.table_txt") %><br> 1) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.table_txt") %> <%= t("views.right_panel.detail.name_txt") %> <%= t("views.right_panel.detail.table_txt") %><br>
2) <%= t("views.right_panel.detail.status") %> - <%= t("views.right_panel.detail.table_txt") %> <%= t("views.right_panel.detail.status_txt") %> <br> 2) <%= t("views.right_panel.detail.status") %> - <%= t("views.right_panel.detail.table_txt") %> <%= t("views.right_panel.detail.status_txt") %> <br>
3) <%= t("views.right_panel.detail.seater") %> - <%= t("views.right_panel.detail.seat_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.table_txt") %> <br> 3) <%= t("views.right_panel.detail.seater") %> - <%= t("views.right_panel.detail.seat_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.table_txt") %> <br>
4) <%= t("views.right_panel.detail.order_by") %> - <%= t("views.right_panel.detail.order_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.table_txt") %> <br> 4) <%= t("views.right_panel.detail.order_by") %> - <%= t("views.right_panel.detail.order_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.table_txt") %> <br>
@@ -118,8 +117,6 @@
2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.zone_txt") %> <br> 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.zone_txt") %> <br>
</p> </p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -28,9 +28,24 @@ set :linked_dirs, %w{log tmp/pids tmp/puma tmp/cache tmp/sockets vendor/bundle p
set :tests, [] set :tests, []
set :pty, true set :pty, true
set :puma_jungle_conf, '/etc/puma.conf' #set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_run_path, '/usr/local/bin/run-puma' #set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind, %w(tcp://0.0.0.0:9393) set :puma_bind, %w(tcp://0.0.0.0:9393)
#set :puma_conf, "#{shared_path}/puma.rb"
#set :puma_access_log, "#{shared_path}/log/puma_access.log"
#set :puma_error_log, "#{shared_path}/log/puma_error.log"
#set :puma_role, :app
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
set :puma_threads, [0, 16]
set :puma_workers, 2
#set :puma_worker_timeout, nil
#set :puma_init_active_record, false
#set :puma_preload_app, false
#set :puma_daemonize, false
#set :puma_plugins, [] #accept array of plugins
#set :puma_tag, fetch(:application)
#set :puma_restart_command, 'bundle exec puma'
#set :enable_ssl, true #set :enable_ssl, true

View File

@@ -9,11 +9,11 @@
# set :rails_env, :production # set :rails_env, :production
set :stage, :production set :stage, :production
set :server_name, "a.c2l.shop" set :server_name, "doemal.app"
set :branch, "r-1902001-01" set :branch, "r-1902001-01"
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}" set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
server '167.71.194.57', user: 'deploy', roles: %w{web app db}, primary: true server '178.128.58.251', user: 'deploy', roles: %w{web app db}, primary: true
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}" set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"
set :rbenv_ruby, '2.6.5' set :rbenv_ruby, '2.6.5'

View File

@@ -0,0 +1 @@
SECRET_KEY_BASE=33c956cc0e41623bf4e0aedbb16061fa7460a993452b58311d07009782dc242925a52dbb79b506c35308e65cda7cb07b014f78daea0a7ea883a535dc14b33a09

View File

@@ -0,0 +1,6 @@
production:
adapter: postgresql
host: localhost
database: iticket
username: wathon
password: root

View File

@@ -0,0 +1,11 @@
<%= fetch(:deploy_to) %>/shared/log/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
sharedscripts
endscript
copytruncate
}

View File

@@ -0,0 +1,2 @@
<% application = fetch(:application) %>
set mail-format { subject: <%= "#{fetch(:full_app_name)} - #{fetch(:rails_env)}" %> $SERVICE $EVENT at $DATE }

Some files were not shown because too many files have changed in this diff Show More