fix first bill amount less than actual sales

This commit is contained in:
Thein Lin Kyaw
2019-09-27 20:35:05 +06:30
parent 9d330bb28c
commit 327a6e17bf
10 changed files with 242 additions and 313 deletions

View File

@@ -19,13 +19,12 @@ class Api::BillController < Api::ApiController
# for Multiple Cashier by Zone
table = DiningFacility.find(booking.dining_facility_id)
bk_order = BookingOrder.find_by_booking_id(booking.booking_id)
order = Order.find(bk_order.order_id)
order = booking.orders.first
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?
cashier = Employee.find(shift.employee_id)
@@ -40,65 +39,59 @@ class Api::BillController < Api::ApiController
end
end
if booking
if booking.sale_id.nil?
@sale = Sale.new
@status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee, cashier, order.source,params[:current_checkin_induties_count])
@sale_data = Sale.find_by_sale_id(@sale_id)
else
@status = true
@sale_id = booking.sale_id
@sale_data = Sale.find_by_sale_id(@sale_id)
end
if @sale_data = booking.sale
@status = true
elsif @sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, cashier, order.source, params[:current_checkin_induties_count])
@status = true
else
@status = false
end
end
else
@status = false
@status = false
@error_message = "There is no order for '#{params[:booking_id]}'"
end
elsif (params[:order_id])
order = Order.find(params[:order_id])
@sale = Sale.new
@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)
# 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
# Bind shift sale id to sale
# @sale_data.shift_sale_id = shift_by_terminal.id
# @sale_data.save
if @status
if @sale_data
#check checkInOut pdf print
check_booking = Booking.find_by_sale_id(@sale_id)
checkout_time = Lookup.collection_of('checkout_time')
terminal = DiningFacility.find_by_id(check_booking.dining_facility_id)
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
# print when complete click
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
if !printer.nil?
order_queue_printer.print_check_in_out(printer,cashier_terminal , check_booking, table)
order_queue_printer.print_check_in_out(printer,cashier_terminal , booking, table)
end
end
end
Promotion.promo_activate(@sale)
Promotion.promo_activate(@sale_data)
#BillBroadcastJob.perform_later(table)
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
else
from = ""
end
ActionCable.server.broadcast "bill_channel",table: table, from: from
end
ActionCable.server.broadcast "bill_channel",table: table, from: from
end
else
@status = false
@error_message = "No Current Open Shift"
@@ -139,7 +132,7 @@ class Api::BillController < Api::ApiController
is_extra_time = false
extra_time = ''
# params[:order_items].each { |i|
# params[:order_items].each { |i|
# i["item_instance_code"] = i["item_instance_code"].downcase.to_s
# if i["item_instance_code"].include? "ext"
# is_extra_time = true
@@ -175,18 +168,16 @@ class Api::BillController < Api::ApiController
booking_order = BookingOrder.find_by_booking_id(@booking.booking_id)
order = Order.find(booking_order.order_id)
if @booking.sale_id.nil?
@sale = Sale.new
@status, @sale_id = @sale.generate_invoice_from_booking(@booking.booking_id, current_login_employee, cashier, order.source,params[:current_checkin_induties_count])
@sale_data = Sale.find_by_sale_id(@sale_id)
else
if @sale_data = @booking.sale
@status = true
@sale_id = @booking.sale_id
@sale_data = Sale.find_by_sale_id(@sale_id)
elsif @sale_data = Sale.generate_invoice_from_booking(@booking, current_login_employee, cashier, order.source,params[:current_checkin_induties_count])
@status = true
else
@status = false
end
end
# Promotion.promo_activate(@sale)
@status = true
# Promotion.promo_activate(@sale)
# @status = true
# render json: JSON.generate({:status => true, :sale_id => @sale_id, :sale_data => @sale_data.to_json })
else
@status = false
@@ -197,7 +188,7 @@ class Api::BillController < Api::ApiController
@status = false
@error_message = "Create order failed, some error occurred!"
# render json: JSON.generate({:status => false, :error_message => "Create order failed, some error occurred!"})
end
end
else
@status = false
@error_message = "Parameters missing!"

View File

@@ -5,12 +5,12 @@ class Origami::PaymentsController < BaseOrigamiController
def first_bill
sale_id = params[:sale_id] # sale_id
sale_data = Sale.find_by_sale_id(sale_id)
sale_data = Sale.find(sale_id)
sale_items = SaleItem.get_all_sale_items(sale_id)
member_info = nil
# For Cashier by Zone
bookings = Booking.where("sale_id='#{sale_id}'")
booking = Booking.find_by_sale_id(sale_id)
# if bookings.count > 1
# # for Multiple Booking
# table = DiningFacility.find(bookings[0].dining_facility_id)
@@ -21,12 +21,12 @@ class Origami::PaymentsController < BaseOrigamiController
if !shift.nil?
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
else
if bookings[0].dining_facility_id.to_i > 0
table = DiningFacility.find(bookings[0].dining_facility_id)
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)
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
else
shift = ShiftSale.find(saleObj.shift_sale_id)
shift = ShiftSale.find(sale_data.shift_sale_id)
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
end
end

View File

@@ -1,6 +1,6 @@
class Origami::RequestBillsController < ApplicationController
before_action :check_user
def check_user
if current_user.nil?
redirect_to root_path
@@ -8,43 +8,30 @@ class Origami::RequestBillsController < ApplicationController
end
# Print Request Bill and add to sale tables
def print
@sale = Sale.new
sale_order=SaleOrder.new
if !ShiftSale.current_shift.nil?
order_id = params[:id] # order_id
bk_order = BookingOrder.find_by_order_id(order_id)
order = Order.find(order_id)
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
if check_booking.checkin_at.utc.strftime("%Y-%m-%d %H:%M") > Time.now.utc.strftime("%Y-%m-%d %H:%M") && check_booking.checkout_at.nil?
booking = order.booking
if booking.checkin_at.utc > Time.now.utc && booking.checkout_at.nil?
@status = false
@error_message = "Operation failed, Could not request bill!"
else
if check_booking.dining_facility_id.to_i > 0
table = DiningFacility.find(check_booking.dining_facility_id)
else
table = nil
end
if check_booking.sale_id.nil?
# Create Sale if it doesn't exist
@status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source, params[:current_checkin_induties_count])
@sale_data = Sale.find_by_sale_id(@sale_id)
@sale_items = SaleItem.where("sale_id=?",@sale_id)
table = DiningFacility.find(booking.dining_facility_id)
if sale_data = booking.sale
@status = true
elsif sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source, params[:current_checkin_induties_count])
@status = true
# in-duty update
in_duties = InDuty.where("booking_id=?",bk_order.booking_id)
in_duties = InDuty.where("booking_id=?", booking.id)
if !in_duties.empty?
in_duties.each do |in_duty|
induty = InDuty.find(in_duty.id)
induty.sale_id = @sale_id
induty.out_time =Time.now.utc
induty.sale_id = sale_data.sale_id
induty.out_time = Time.now.utc
induty.save
end
end
else
@sale_data = Sale.find_by_sale_id(check_booking.sale_id)
@sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id)
end
# Bind shift sale id to sale
@@ -53,17 +40,17 @@ class Origami::RequestBillsController < ApplicationController
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 )
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)
Promotion.promo_activate(sale_data)
#bill channel
#bill channel
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
else
from = ""
end
@@ -71,30 +58,30 @@ class Origami::RequestBillsController < ApplicationController
ActionCable.server.broadcast "bill_channel",table: table, from: from
end
if order.source == "quick_service" || order.source == "food_court"
result = {:status=> @status, :data => @sale.sale_id }
result = {:status=> @status, :data => sale_data.sale_id }
render :json => result.to_json
else
#check checkInOut pdf print
check_booking = Booking.find_by_sale_id(@sale_id)
checkout_time = Lookup.collection_of('checkout_time')
if !check_booking.dining_facility_id.nil?
terminal = DiningFacility.find_by_id(check_booking.dining_facility_id)
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"
unique_code = "CheckInOutPdf"
printer = PrintSetting.find_by_unique_code(unique_code)
# print when complete click
# print when complete click
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
if !printer.nil?
order_queue_printer.print_check_in_out(printer, cashier_terminal, check_booking, table)
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, table)
end
end
end
end
end
end
end
@status = true
else
@status = false
@error_message = "No Current Open Shift for This Employee"

View File

@@ -4,12 +4,12 @@ class Origami::SplitBillController < BaseOrigamiController
def index
@webview = false
if check_mobile
@webview = true
@webview = true
end
dining_id = params[:dining_id]
@cashier_type = params[:type]
@table = DiningFacility.find(dining_id)
@table = DiningFacility.find(dining_id)
@booking = @table.get_booking
@orders = Array.new
@order_items = Array.new
@@ -47,10 +47,10 @@ class Origami::SplitBillController < BaseOrigamiController
arr_item = Hash.new
if item.qty.to_i > 1
i = 1
while i <= item.qty.to_i do
arr_item = {'order_items_id' => item.order_items_id,
'order_id' => item.order_id,
'order_item_status' => item.order_item_status,
while i <= item.qty.to_i do
arr_item = {'order_items_id' => item.order_items_id,
'order_id' => item.order_id,
'order_item_status' => item.order_item_status,
'item_order_by' => item.item_order_by,
'item_code' => item.item_code,
'item_instance_code' => item.item_instance_code,
@@ -91,7 +91,7 @@ class Origami::SplitBillController < BaseOrigamiController
arr_order_ids = JSON.parse(params[:arr_order_ids])
end
orders = nil
if !params[:orders].empty?
if !params[:orders].empty?
orders = JSON.parse(params[:orders])
end
order_items = nil
@@ -102,31 +102,27 @@ class Origami::SplitBillController < BaseOrigamiController
status = false
if !ShiftSale.current_shift.nil?
#create Bill by Booking ID
table = 0
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
table = 0
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)
# get_cashier_by_terminal = Employee.find(shift_by_terminal.employee_id)
if booking
if booking.sale_id.nil?
sale = Sale.new
status, sale_id = sale.generate_invoice_from_booking(params[:booking_id], current_user, current_user, cashier_type,params[:current_checkin_induties_count])
sale_data = Sale.find_by_sale_id(sale_id)
else
status = true
sale_id = booking.sale_id
sale_data = Sale.find_by_sale_id(sale_id)
end
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
status = false
end
else
if params[:type] == "Table"
@@ -283,7 +279,7 @@ class Origami::SplitBillController < BaseOrigamiController
end
else
if order_ids.count == 1 && order_item_count == 1
if order_id_count == 0
if order_id_count == 0
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
@@ -332,18 +328,19 @@ class Origami::SplitBillController < BaseOrigamiController
end
end
sale = Sale.new
status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, current_user, cashier_type ,params[:current_checkin_induties_count])
end
if sale_data = Sale.generate_invoice_from_booking(booking, current_user, current_user, cashier_type ,params[:current_checkin_induties_count])
status = true
end
end
Promotion.promo_activate(sale)
if ENV["SERVER_MODE"] == 'cloud'
from = request.subdomain + "." + request.domain
else
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!'}
@@ -381,17 +378,17 @@ class Origami::SplitBillController < BaseOrigamiController
same_order = OrderItem.find_by_order_id(order_id)
if same_order.nil?
OrderItem.processs_item(orderItem.item_code,
orderItem.item_instance_code,
orderItem.item_name,
orderItem.alt_name,
OrderItem.processs_item(orderItem.item_code,
orderItem.item_instance_code,
orderItem.item_name,
orderItem.alt_name,
orderItem.account_id,
order_item['qty'],
orderItem.price,
orderItem.options,
set_menu_items_obj.to_json,
orderItem.price,
orderItem.options,
set_menu_items_obj.to_json,
order_id,
orderItem.item_order_by,
orderItem.item_order_by,
orderItem.taxable)
else
same_order.qty = same_order.qty.to_f + order_item['qty'].to_f