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

@@ -12,7 +12,7 @@ gem 'rails', '~> 5.1.0'
#gem 'mysql2', '>= 0.3.18', '< 0.5'
gem 'pg'
gem 'mysql2', '>= 0.3.18', '< 0.5'
gem 'mysql2'
#Use PosgreSQL
@@ -133,4 +133,4 @@ gem 'momentjs-rails' # for date-range selector
# gem 'bootstrap-datepicker-rails' # date picker
# gem 'jquery-datetimepicker-rails'
# gem 'select2-rails' # for multi-select and auto-complete select box
gem "chartkick" #chart lib
gem "chartkick" #chart lib

View File

@@ -47,7 +47,7 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
aescrypt (1.0.0)
airbrussh (1.3.3)
airbrussh (1.3.4)
sshkit (>= 1.6.1, != 1.7.0)
arel (8.0.0)
axlsx (2.0.1)
@@ -92,14 +92,14 @@ GEM
cups (0.1.10)
database_cleaner (1.7.0)
diff-lcs (1.3)
erubi (1.8.0)
erubi (1.9.0)
execjs (2.7.0)
factory_girl (4.9.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.9.0)
factory_girl (~> 4.9.0)
railties (>= 3.0.0)
faker (2.2.2)
faker (2.4.0)
i18n (~> 1.6.0)
ffi (1.11.1)
filterrific (5.2.1)
@@ -154,16 +154,16 @@ GEM
mini_magick (4.9.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.11.3)
minitest (5.12.0)
momentjs-rails (2.20.1)
railties (>= 3.1)
multi_xml (0.6.0)
mysql2 (0.4.10)
mysql2 (0.5.2)
nested_form (0.3.2)
net-scp (2.0.0)
net-ssh (>= 2.6.5, < 6.0.0)
net-ssh (5.2.0)
nio4r (2.5.1)
nio4r (2.5.2)
nokogiri (1.10.4)
mini_portile2 (~> 2.4.0)
pdf-core (0.7.0)
@@ -219,8 +219,10 @@ GEM
nokogiri
rubyzip
spreadsheet (> 0.6.4)
rqrcode (0.10.1)
rqrcode (1.1.1)
chunky_png (~> 1.0)
rqrcode_core (~> 0.1.0)
rqrcode_core (0.1.0)
rspec-core (3.8.2)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.4)
@@ -283,16 +285,16 @@ GEM
rails (>= 3.1)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.9)
tilt (2.0.10)
to_xls-rails (1.3.1)
spreadsheet (>= 0.8.5)
ttfunk (1.5.1)
turbolinks (5.2.0)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.1.20)
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
web-console (3.7.0)
actionview (>= 5.0)
@@ -338,7 +340,7 @@ DEPENDENCIES
material_icons
mini_magick
momentjs-rails
mysql2 (>= 0.3.18, < 0.5)
mysql2
nested_form
pdfjs_viewer-rails
pg

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

View File

@@ -8,6 +8,8 @@ class Order < ApplicationRecord
belongs_to :customer
has_many :order_items, autosave: true , inverse_of: :order
has_many :assigned_order_items
has_one :booking_order
has_one :booking, through: :booking_order
#internal references attributes for business logic control
attr_accessor :items, :guest, :table_id, :new_booking, :booking_type, :employee_name, :booking_id, :extra_time, :is_extra_time

View File

@@ -13,6 +13,7 @@ class Sale < ApplicationRecord
has_many :sale_taxes
has_many :sale_payments
has_many :sale_orders
has_many :orders, through: :sale_orders
has_many :bookings
has_many :product_commissions
@@ -64,34 +65,31 @@ class Sale < ApplicationRecord
Rails.logger.debug '........ Sale data sync completed .......'
end
end
def generate_invoice_from_booking(booking_id, requested_by, cashier, order_source = nil, current_checkin_induties_count)
saleObj =''
booking = Booking.find(booking_id)
status = false
Rails.logger.debug "Booking -> " + booking.id.to_s
if (booking)
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
sale = booking.build_sale(
{
tax_type: "execulive" # Default Tax - Values
}
)
end
booking.booking_orders.each do |order|
# puts "Hello order"
if booking.sale_id
status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by, cashier, order_source)
else
status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by, cashier, order_source)
end
booking.sale_id = sale_id
saleObj = Sale.find(sale_id)
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)
# link_order_sale(order.order_id)
end
# InventoryJob.perform_now(self.id)
# InventoryDefinition.calculate_product_count(saleObj)
# dining charges
charges = DiningCharge.where('dining_facility_id=?',booking.dining_facility_id).take
charges = DiningCharge.where('dining_facility_id=?', booking.dining_facility_id).take
if !charges.nil?
block_count, diningprice = DiningCharge.amount_calculate(charges, booking.checkin_at, booking.checkout_at)
if charges.charge_type =='hr'
@@ -102,171 +100,139 @@ class Sale < ApplicationRecord
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 =""
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
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
create_saleitem_indutycharges(charges, current_checkin_induties_count.to_i, induties_pay_amount, booking.dining_facility.name, dining_time, order_source, basic_pay_amount)
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
create_saleitem_diningcharges(charges, block_count, diningprice, booking.dining_facility.name, dining_time, order_source)
sale.create_saleitem_diningcharges(charges, block_count, diningprice, booking.dining_facility.name, dining_time, order_source)
end
return status, sale_id
return sale
end
end
def generate_invoice_from_order (order_id, sale_id, booking, requested_by, cashier = nil, order_source = nil)
def generate_invoice_from_order(order_id, booking, requested_by, cashier = nil, order_source = nil)
taxable = true
#if sale_id is exsit and validate
#add order to that invoice
if (sale_id)
self.find(sale_id)
end
Rails.logger.debug "Does it have Existing Sale -> [#{self.id.to_s}] - Status [#{self.sale_status}]"
if self.sale_status == "void"
return false, "Invoice is void. Cannot be edited"
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
else
#if this is new sale generate_receipt_no
# generate_receipt_no
order = Order.find(order_id)
#Default Tax - Values
self.tax_type = "exclusive"
# 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.nil?
orderSoure = order_source.downcase
else
orderSoure = nil
end
if orderSoure == "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
shift = ShiftSale.current_open_shift(cashier.id)
end
# 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].id)
if shift_id
self.shift_sale_id = shift_id.id
else
self.shift_sale_id = current_shift.id
end
end
else
shift = ShiftSale.current_open_shift(cashier.id)
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
# 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].id)
if shift_id
self.shift_sale_id = shift_id.id
else
self.shift_sale_id = current_shift.id
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
# set waiter
self.requested_by = requested_by.name
self.requested_at = DateTime.now.utc.getlocal
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
self.orders << order
end
#compute sales summary
if order_source.nil?
order_source = order.source
end
self.compute(order_source)
# set waiter
self.requested_by = requested_by.name
#Update the order items that is billed
order.update_items_status_to_billed(nil)
order.status = "billed"
order.save
self.requested_at = DateTime.now.utc.getlocal
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|
add_item(item)
if !item.set_menu_items.nil?
add_sub_item(item.set_menu_items)
end
end
# link_order_sale(order.id)
end
self.save!
#compute sales summary
if order_source.nil?
order_source = order.source
end
compute(order_source)
#Update the order items that is billed
order.update_items_status_to_billed(nil)
order.status = "billed"
order.save
booking.sale_id = self.id
if !booking.checkout_at.nil?
if booking.checkout_at.utc < Time.now.utc
booking.checkout_at = Time.now.utc.getlocal
end
else
if !booking.checkout_at.nil?
if booking.checkout_at.utc < Time.now.utc
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 true, self.id
else
booking.checkout_at = Time.now.utc.getlocal
end
return false, nil
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
#fOR Quick Service pay and create
def self.request_bill(order,current_user,current_login_employee)
@sale = Sale.new
sale_order=SaleOrder.new
if !ShiftSale.current_shift.nil?
order_id = order.order_id # order_id
bk_order = BookingOrder.find_by_order_id(order_id)
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
if check_booking.sale_id.nil?
if @sale_data = check_booking.sale
# Create Sale if it doesn't exist
# puts "current_login_employee"
# puts current_login_employee.name
@status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee,current_user,order.source)
@sale_data = Sale.find_by_sale_id(@sale_id)
@sale_items = SaleItem.where("sale_id=?",@sale_id)
else
@sale_data = Sale.find_by_sale_id(check_booking.sale_id)
elsif @sale_data = Sale.generate_invoice_from_booking(check_booking,current_login_employee,current_user,order.source)
@sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id)
end

View File

@@ -211,13 +211,13 @@ class SaleItem < ApplicationRecord
# return price
# end
def self.get_all_sale_items(sale_id)
def self.get_all_sale_items(sale_id)
sale_items = SaleItem.select("sale_id,product_code,item_instance_code,
product_name,product_alt_name,account_id,status,remark,
(CASE WHEN (qty > 0 AND remark IS NULL) OR (qty > 0 AND status='foc') OR (qty < 0 AND status = 'foc') OR (qty < 0 AND status='Discount') OR (status='promotion' AND (remark='promotion' OR remark = 'promotion nett price' OR remark= 'promotion discount')) THEN SUM(qty) ELSE qty END) as qty,
SUM(qty) as qty,
unit_price,
taxable_price,
(CASE WHEN (price > 0 AND remark IS NULL) OR (qty > 0 AND status='foc') OR (qty < 0 AND status = 'foc') OR (price < 0 AND status='Discount') OR (status='promotion' AND (remark='promotion' OR remark = 'promotion nett price' OR remark= 'promotion discount')) THEN SUM(price) ELSE price END) as price,
SUM(price) as price,
is_taxable")
.where("sale_id = ?",sale_id)
.order("product_name asc")
@@ -238,11 +238,11 @@ class SaleItem < ApplicationRecord
is_edit = self.qty >= 0 && self.qty != self.qty_was
is_foc = self.status == "foc" && self.status_was != "foc"
cancel_foc = self.status_was == "foc"
if is_foc
StockJournal.update_stock_journal(self.item_instance_code, "foc")
elsif cancel_foc
StockJournal.update_stock_journal(self.item_instance_code, "cancel_foc")
end
# if is_foc
# StockJournal.update_stock_journal(self.item_instance_code, "foc")
# elsif cancel_foc
# StockJournal.update_stock_journal(self.item_instance_code, "cancel_foc")
# end
if is_void or cancel_void or is_edit
found, inventory_definition = InventoryDefinition.find_product_in_inventory(self)
if found

View File

@@ -1,16 +0,0 @@
default: &default
adapter: postgresql
host: localhost
pool: 5
timeout: 5000
encoding: unicode
username: nlh
password: 7812co2Y
port: 5432
development:
<<: *default
database: sxdemo
production:
<<: *default
database: paymal