fix first bill amount less than actual sales
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -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
|
||||
|
||||
|
||||
24
Gemfile.lock
24
Gemfile.lock
@@ -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
|
||||
|
||||
@@ -19,8 +19,7 @@ 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)
|
||||
|
||||
@@ -40,40 +39,34 @@ 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
|
||||
if @sale_data = booking.sale
|
||||
@status = true
|
||||
@sale_id = booking.sale_id
|
||||
@sale_data = Sale.find_by_sale_id(@sale_id)
|
||||
end
|
||||
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
|
||||
@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
|
||||
@@ -85,11 +78,11 @@ class Api::BillController < Api::ApiController
|
||||
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
|
||||
|
||||
Promotion.promo_activate(@sale)
|
||||
Promotion.promo_activate(@sale_data)
|
||||
|
||||
#BillBroadcastJob.perform_later(table)
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
@@ -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
|
||||
# @status = true
|
||||
# render json: JSON.generate({:status => true, :sale_id => @sale_id, :sale_data => @sale_data.to_json })
|
||||
else
|
||||
@status = false
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -54,11 +41,11 @@ 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
|
||||
if ENV["SERVER_MODE"] == 'cloud'
|
||||
@@ -71,14 +58,13 @@ 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
|
||||
@@ -89,12 +75,13 @@ class Origami::RequestBillsController < ApplicationController
|
||||
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
|
||||
@status = true
|
||||
else
|
||||
@status = false
|
||||
@error_message = "No Current Open Shift for This Employee"
|
||||
|
||||
@@ -117,16 +117,12 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
# 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
|
||||
if sale_data = booking.sale
|
||||
status = true
|
||||
sale_id = booking.sale_id
|
||||
sale_data = Sale.find_by_sale_id(sale_id)
|
||||
end
|
||||
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"
|
||||
@@ -332,8 +328,9 @@ 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])
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
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
|
||||
if (booking)
|
||||
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
|
||||
|
||||
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)
|
||||
unless sale = booking.sale
|
||||
sale = booking.build_sale(
|
||||
{
|
||||
tax_type: "execulive" # Default Tax - Values
|
||||
}
|
||||
)
|
||||
end
|
||||
booking.sale_id = sale_id
|
||||
saleObj = Sale.find(sale_id)
|
||||
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)
|
||||
# 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,54 +100,36 @@ 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"
|
||||
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 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)
|
||||
@@ -203,29 +183,25 @@ class Sale < ApplicationRecord
|
||||
Rails.logger.debug "Order -> #{order.id} | Items Count -> #{order.order_items.count}"
|
||||
|
||||
order.order_items.each do |item|
|
||||
add_item(item)
|
||||
self.add_item(item)
|
||||
if !item.set_menu_items.nil?
|
||||
add_sub_item(item.set_menu_items)
|
||||
self.add_sub_item(item.set_menu_items)
|
||||
end
|
||||
end
|
||||
|
||||
# link_order_sale(order.id)
|
||||
|
||||
self.orders << order
|
||||
end
|
||||
self.save!
|
||||
|
||||
#compute sales summary
|
||||
if order_source.nil?
|
||||
order_source = order.source
|
||||
end
|
||||
compute(order_source)
|
||||
self.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
|
||||
@@ -238,35 +214,25 @@ class Sale < ApplicationRecord
|
||||
booking.save
|
||||
|
||||
# InventoryJob.perform_now(self.id)
|
||||
saleObj = Sale.find(self.id)
|
||||
# saleObj = Sale.find(self.id)
|
||||
# InventoryDefinition.calculate_product_count(saleObj)
|
||||
|
||||
return true, self.id
|
||||
end
|
||||
|
||||
return false, nil
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -214,10 +214,10 @@ class SaleItem < ApplicationRecord
|
||||
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
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user