Fix bugs and improvements
fix payment outstanding with amount <= 0 fix payment outstanding with other payments
This commit is contained in:
@@ -7,10 +7,10 @@ class Origami::AddordersController < BaseOrigamiController
|
||||
@webview = true
|
||||
end
|
||||
|
||||
@tables = Table.all.active.order('zone_id asc').group("zone_id")
|
||||
@rooms = Room.all.active.order('zone_id asc').group("zone_id")
|
||||
@all_table = Table.all.active.order('status desc')
|
||||
@all_room = Room.all.active.order('status desc')
|
||||
@tables = Table.active.order('zone_id asc').group("zone_id")
|
||||
@rooms = Room.active.order('zone_id asc').group("zone_id")
|
||||
@all_table = Table.active.order('status desc')
|
||||
@all_room = Room.active.order('status desc')
|
||||
end
|
||||
|
||||
def detail
|
||||
|
||||
@@ -13,13 +13,13 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
booking = sale_data.booking
|
||||
|
||||
if current_user.role == 'cashier'
|
||||
cashier_terminal = shift.cashier_terminal
|
||||
elsif booking.dining_facility_id
|
||||
cashier_terminal = booking.dining_facility.cashier_terminal
|
||||
else
|
||||
cashier_terminal = sale_data.shift_sale.cashier_terminal
|
||||
cashier_terminal = current_user.cashier_terminal
|
||||
elsif booking.dining_facility
|
||||
cashier_terminal = booking.cashier_terminal_by_dining_facility
|
||||
end
|
||||
|
||||
cashier_terminal ||= sale_data.cashier_terminal_by_shift_sale
|
||||
|
||||
customer = sale_data.customer
|
||||
|
||||
#record for sale audit
|
||||
@@ -90,11 +90,9 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
latest_order_no = nil
|
||||
is_kbz = params[:is_kbz]
|
||||
|
||||
if(Sale.exists?(sale_id))
|
||||
saleObj = Sale.find(sale_id)
|
||||
if saleObj = Sale.find(sale_id)
|
||||
sale_items = SaleItem.get_all_sale_items(sale_id)
|
||||
|
||||
sp = SalePayment.where('sale_id=? and payment_method=? and payment_status=?', sale_id, 'kbzpay', 'paid').last
|
||||
if is_kbz == 'false'
|
||||
Rails.logger.info '################ CASH PAYMENT #################'
|
||||
sale_payment = SalePayment.new
|
||||
@@ -104,6 +102,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
sale_payment.process_payment(saleObj, current_user, cash, "cash")
|
||||
end
|
||||
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)
|
||||
end
|
||||
|
||||
@@ -112,24 +111,23 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
|
||||
# For Cashier by Zone
|
||||
# bookings = Booking.where("sale_id='#{sale_id}'")
|
||||
bookings = saleObj.booking
|
||||
booking = saleObj.booking
|
||||
|
||||
shift = ShiftSale.current_open_shift(current_user.id)
|
||||
if !shift.nil?
|
||||
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
||||
else
|
||||
if bookings.dining_facility_id.to_i > 0
|
||||
table = bookings.dining_facility
|
||||
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
||||
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
|
||||
if current_user.role == 'cashier'
|
||||
cashier_terminal = current_user.cashier_terminal
|
||||
elsif booking.dining_facility
|
||||
cashier_terminal = booking.cashier_terminal_by_dining_facility
|
||||
end
|
||||
|
||||
type = 'payment'
|
||||
from = getCloudDomain #get sub domain in cloud mode
|
||||
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
|
||||
else
|
||||
shift = ShiftSale.find(saleObj.shift_sale_id)
|
||||
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
||||
end
|
||||
cashier_terminal ||= saleObj.cashier_terminal_by_shift_sale
|
||||
|
||||
if booking.dining_facility
|
||||
ActionCable.server.broadcast(
|
||||
"order_channel",
|
||||
table: booking.dining_facility,
|
||||
type: 'payment',
|
||||
from: getCloudDomain
|
||||
)
|
||||
end
|
||||
|
||||
# For Print
|
||||
@@ -157,8 +155,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
|
||||
#orders print out
|
||||
if type == "quick_service"
|
||||
booking = Booking.find_by_sale_id(sale_id)
|
||||
if booking.dining_facility_id.to_i>0
|
||||
if booking.dining_facility_id.present?
|
||||
table_id = booking.dining_facility_id
|
||||
else
|
||||
table_id = 0
|
||||
@@ -712,7 +709,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
end
|
||||
end
|
||||
# get printer info
|
||||
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
||||
print_settings = PrintSetting.find_by_unique_code(unique_code)
|
||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||
printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name)
|
||||
|
||||
|
||||
@@ -10,39 +10,23 @@ class Origami::QuickServiceController < ApplicationController
|
||||
def index
|
||||
today = DateTime.now
|
||||
day = Date.today.wday
|
||||
# if params[:menu] == "true"
|
||||
|
||||
@menus = []
|
||||
@menu = []
|
||||
# else
|
||||
# @menus = Menu.all
|
||||
# @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc')
|
||||
# end
|
||||
@zone = Zone.all
|
||||
@customer = Customer.all
|
||||
@tables = Table.all.active.order('status desc')
|
||||
@rooms = Room.all.active.order('status desc')
|
||||
@tables = Table.active.order('status desc')
|
||||
@rooms = Room.active.order('status desc')
|
||||
@cashier_type = "quick_service"
|
||||
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
|
||||
else
|
||||
@display_type = nil
|
||||
end
|
||||
|
||||
#checked quick_service only
|
||||
@quick_service_only = false
|
||||
lookup_dine_in = Lookup.collection_of('quickservice_add_order')
|
||||
puts 'lookup_dine_in!!!!'
|
||||
puts lookup_dine_in
|
||||
if !lookup_dine_in.empty?
|
||||
lookup_dine_in.each do |dine_in|
|
||||
if dine_in[0].downcase == "quickserviceaddorder"
|
||||
if dine_in[1] == '1'
|
||||
@quick_service_only = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@quick_service_only = Lookup.collection_of('quickservice_add_order').any? { |x| x == ["quickserviceaddorder", "1"] }
|
||||
|
||||
render "origami/addorders/detail"
|
||||
end
|
||||
@@ -121,7 +105,7 @@ class Origami::QuickServiceController < ApplicationController
|
||||
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.is_extra_time = is_extra_time
|
||||
order.extra_time = extra_time
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class Origami::RequestBillsController < ApplicationController
|
||||
else
|
||||
table = DiningFacility.find_by(id: booking.dining_facility_id)
|
||||
|
||||
if booking.sale.nil?
|
||||
if booking.sale_id.nil?
|
||||
if sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source, params[:current_checkin_induties_count])
|
||||
# in-duty update
|
||||
in_duties = InDuty.where("booking_id=?", booking.id)
|
||||
@@ -47,13 +47,11 @@ class Origami::RequestBillsController < ApplicationController
|
||||
from = ""
|
||||
end
|
||||
|
||||
if order.source == "cashier" || order.source == "quick_service"
|
||||
ActionCable.server.broadcast "bill_channel",table: table, from: from
|
||||
if ["quick_service", "cashier"].include? order.source
|
||||
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
|
||||
|
||||
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?
|
||||
@@ -74,15 +72,24 @@ class Origami::RequestBillsController < ApplicationController
|
||||
end
|
||||
end
|
||||
@status = true
|
||||
sale_id = sale_data.sale_id
|
||||
else
|
||||
@status = false
|
||||
sale_id = nil
|
||||
end
|
||||
else
|
||||
@status = true
|
||||
sale_id = booking.sale_id
|
||||
end
|
||||
end
|
||||
else
|
||||
@status = false
|
||||
@error_message = "No Current Open Shift for This Employee"
|
||||
end
|
||||
if ["quick_service", "food_court"].include? order.source
|
||||
result = {:status=> @status, :data => sale_data.sale_id }
|
||||
render :json => result.to_json
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -105,7 +105,6 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
booking.orders << new_order
|
||||
end
|
||||
|
||||
puts split_orders
|
||||
if split_orders.present?
|
||||
BookingOrder.where(order_id: split_orders).update_all(booking_id: booking.booking_id)
|
||||
end
|
||||
@@ -122,7 +121,7 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
from = ""
|
||||
end
|
||||
|
||||
ActionCable.server.broadcast "bill_channel",table: table,from:from
|
||||
ActionCable.server.broadcast "bill_channel", table: table, from:from
|
||||
|
||||
render :json => { status: true }
|
||||
end
|
||||
@@ -131,61 +130,6 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
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.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
|
||||
|
||||
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.account_id,
|
||||
order_item['qty'],
|
||||
orderItem.price,
|
||||
orderItem.options,
|
||||
set_menu_items_obj.to_json,
|
||||
order_id,
|
||||
orderItem.item_order_by,
|
||||
orderItem.taxable)
|
||||
else
|
||||
same_order.qty = same_order.qty.to_f + order_item['qty'].to_f
|
||||
same_order.set_menu_items = set_menu_items_obj.to_json
|
||||
same_order.save
|
||||
end
|
||||
orderItem.qty = orderItem.qty.to_f - order_item['qty'].to_f
|
||||
else
|
||||
orderItem.order_id = order_id
|
||||
end
|
||||
orderItem.save!
|
||||
end
|
||||
|
||||
def update_sale
|
||||
sale = Sale.find(params[:sale_id])
|
||||
sale.equal_persons = params[:total_customer].to_i
|
||||
|
||||
@@ -6,6 +6,8 @@ class Booking < ApplicationRecord
|
||||
|
||||
belongs_to :dining_facility, :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 :orders, :through => :booking_orders
|
||||
has_many :order_items, :through => :orders do
|
||||
@@ -13,7 +15,7 @@ class Booking < ApplicationRecord
|
||||
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,
|
||||
|
||||
@@ -4,11 +4,11 @@ class DiningFacility < ApplicationRecord
|
||||
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"
|
||||
|
||||
@@ -3,6 +3,7 @@ class Employee < ApplicationRecord
|
||||
has_many :commissioners
|
||||
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
|
||||
|
||||
validates_presence_of :name, :role
|
||||
|
||||
@@ -9,6 +9,8 @@ class Sale < ApplicationRecord
|
||||
belongs_to :cashier, foreign_key: "cashier_id", class_name: "Employee"
|
||||
belongs_to :customer, :optional => true
|
||||
belongs_to :shift_sale
|
||||
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_items
|
||||
@@ -16,8 +18,8 @@ class Sale < ApplicationRecord
|
||||
has_many :sale_discounts
|
||||
has_many :sale_taxes
|
||||
has_many :sale_payments
|
||||
has_many :payments_for_credits, through: :sale_audits
|
||||
has_many :sale_orders
|
||||
has_many :sale_payments_for_credits, through: :sale_audits
|
||||
has_many :orders, through: :sale_orders
|
||||
has_many :order_items, through: :sale_orders
|
||||
has_many :bookings
|
||||
@@ -32,7 +34,7 @@ class Sale < ApplicationRecord
|
||||
scope :paid, -> { where(payment_status: 'paid')}
|
||||
scope :completed, -> { where(sale_status: 'completed') }
|
||||
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])) }
|
||||
|
||||
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
|
||||
@@ -96,12 +98,19 @@ class Sale < ApplicationRecord
|
||||
if cashier.role == 'cashier'
|
||||
sale.cashier = cashier
|
||||
sale.shift_sale = cashier.current_shift
|
||||
elsif booking.dining_facility_id
|
||||
sale.shift_sale = booking.dining_facility.cashier_terminal.current_shift
|
||||
sale.cashier = booking.dining_facility.cashier_terminal.current_shift.employee
|
||||
else
|
||||
sale.cashier = Employee.where(role: 'cashier').where.not(token_session: [nil, '']).first
|
||||
sale.shift_sale = sale.cashier.current_shift
|
||||
elsif booking.dining_facility
|
||||
if sale.shift_sale = booking.current_shift_by_dining_facility
|
||||
sale.cashier = sale.shift_sale.employee
|
||||
end
|
||||
end
|
||||
|
||||
if sale.shift_sale.nil?
|
||||
if sale.cashier = Employee.where(role: 'cashier').where.not(token_session: [nil, '']).first
|
||||
sale.shift_sale = sale.current_shift_by_cashier
|
||||
else
|
||||
sale.shift_sale = ShiftSale.current_shift
|
||||
sale.cashier = sale.shift_sale.employee
|
||||
end
|
||||
end
|
||||
|
||||
sale.cashier_name = sale.cashier.name
|
||||
@@ -110,7 +119,7 @@ class Sale < ApplicationRecord
|
||||
|
||||
sale.sale_items << booking.order_items.to_sale_items
|
||||
|
||||
if dining_charge = booking.dining_facility.dining_charge
|
||||
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"
|
||||
@@ -173,14 +182,12 @@ class Sale < ApplicationRecord
|
||||
order_id = order.order_id # order_id
|
||||
booking = order.booking
|
||||
|
||||
sale_data = Sale.generate_invoice_from_booking(check_booking, current_login_employee, current_user, order.source)
|
||||
if booking.sale.nil?
|
||||
sale_data = Sale.generate_invoice_from_booking(booking, current_login_employee, current_user, order.source)
|
||||
# Promotion Activation
|
||||
Promotion.promo_activate(sale_data)
|
||||
end
|
||||
|
||||
# Bind shift sale id to sale
|
||||
# @sale_data.shift_sale_id = shift.id
|
||||
# @sale_data.save
|
||||
|
||||
# Promotion Activation
|
||||
Promotion.promo_activate(sale_data)
|
||||
return true, sale_data
|
||||
else
|
||||
return false, "No Current Open Shift for This Employee"
|
||||
@@ -1219,7 +1226,7 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay
|
||||
.includes(:bookings => :dining_facility)
|
||||
.select("sales.*, SUM(sale_payments.payment_amount) AS payments_for_credits_amount")
|
||||
.joins(:bookings)
|
||||
.left_joins(:sale_payments_for_credits)
|
||||
.left_joins(:payments_for_credits)
|
||||
.completed
|
||||
.where.not(total_amount: 0)
|
||||
.group(:sale_id)
|
||||
|
||||
@@ -66,7 +66,7 @@ class SalePayment < ApplicationRecord
|
||||
return self.save
|
||||
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.received_amount = cash_amount
|
||||
self.payment_reference = remark
|
||||
@@ -87,13 +87,14 @@ class SalePayment < ApplicationRecord
|
||||
amount_due = amount_due - payment.payment_amount
|
||||
end
|
||||
end
|
||||
|
||||
if (amount_due > 0)
|
||||
payment_status = false
|
||||
membership_data = nil
|
||||
#route to payment type
|
||||
case payment_method
|
||||
when "cash"
|
||||
payment_status ,outstanding_amount ,balance_amount = cash_payment(payment_for)
|
||||
payment_status, outstanding_amount, balance_amount = cash_payment(payment_for)
|
||||
when "creditnote"
|
||||
if !self.sale.customer_id.nil?
|
||||
payment_status = creditnote_payment(self.customer_id)
|
||||
@@ -157,7 +158,7 @@ class SalePayment < ApplicationRecord
|
||||
# update complete order items in oqs
|
||||
booking = Booking.find_by_sale_id(sale_id)
|
||||
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("order_id = '#{ sodr.order_id }'").find_each do |aoi|
|
||||
# aoi.delivery_status = 1
|
||||
@@ -165,7 +166,7 @@ class SalePayment < ApplicationRecord
|
||||
# end
|
||||
end
|
||||
|
||||
return true, self.save,membership_data, outstanding_amount ,balance_amount
|
||||
return true, self.save, membership_data, outstanding_amount, balance_amount
|
||||
else
|
||||
#record an payment in sale-audit
|
||||
remark = "Payment failed - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]"
|
||||
@@ -173,6 +174,7 @@ class SalePayment < ApplicationRecord
|
||||
return false, "Payment failed"
|
||||
end
|
||||
else
|
||||
sale_update_payment_status(0)
|
||||
#record an payment in sale-audit
|
||||
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)
|
||||
@@ -640,85 +642,62 @@ class SalePayment < ApplicationRecord
|
||||
return payment_status
|
||||
end
|
||||
|
||||
def sale_update_payment_status(paid_amount,check_foc = false)
|
||||
def sale_update_payment_status(paid_amount, check_foc = false)
|
||||
#update amount_outstanding
|
||||
self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f
|
||||
self.sale.save!
|
||||
self.sale.amount_changed = self.sale.amount_received.to_f - self.sale.grand_total.to_f
|
||||
all_received_amount = 0.0
|
||||
sObj = Sale.find(self.sale_id)
|
||||
is_credit = 0
|
||||
is_foc = 0
|
||||
is_kbz_pay = 0
|
||||
method_status = false
|
||||
sObj.sale_payments.each do |spay|
|
||||
all_received_amount += spay.payment_amount.to_f
|
||||
if spay.payment_method == "creditnote"
|
||||
is_credit = 1
|
||||
end
|
||||
if spay.payment_method == "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
|
||||
method_status = true
|
||||
end
|
||||
end
|
||||
if (self.sale.grand_total <= all_received_amount) && method_status
|
||||
if is_credit == 0
|
||||
self.sale.payment_status = "paid"
|
||||
sale = self.sale
|
||||
sale.amount_received = sale.amount_received.to_f + paid_amount.to_f
|
||||
sale.amount_changed = sale.amount_received.to_f - sale.grand_total.to_f
|
||||
|
||||
all_received_amount = sale.sale_payments.reload.sum(&:payment_amount)
|
||||
|
||||
is_credit = sale.sale_payments.any? { |x| x.payment_method == "creditnote" }
|
||||
is_foc = sale.sale_payments.any? { |x| x.payment_method == "foc" }
|
||||
|
||||
if (sale.grand_total <= all_received_amount)
|
||||
if is_credit
|
||||
sale.payment_status = "outstanding"
|
||||
elsif is_foc
|
||||
sale.payment_status = "foc"
|
||||
else
|
||||
self.sale.payment_status = "outstanding"
|
||||
sale.payment_status = "paid"
|
||||
end
|
||||
|
||||
if is_foc == 0
|
||||
self.sale.payment_status = "paid"
|
||||
else
|
||||
self.sale.payment_status = "foc"
|
||||
end
|
||||
|
||||
if is_kbz_pay == 1
|
||||
self.sale.payment_status = 'paid'
|
||||
end
|
||||
|
||||
self.sale.sale_status = "completed"
|
||||
sale.sale_status = "completed"
|
||||
|
||||
if MembershipSetting.find_by_rebate(1) && is_foc == 0 && is_credit == 0
|
||||
response = rebat(sObj)
|
||||
response = rebat(sale)
|
||||
|
||||
#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} "
|
||||
sale_audit = SaleAudit.record_paymal(sObj.sale_id, remark, 1)
|
||||
remark = "#{response} Rebate- for Customer #{sale.customer_id} | Sale Id [#{sale.sale_id}]| pay amount -> #{self.received_amount} "
|
||||
sale_audit = SaleAudit.record_paymal(sale.sale_id, remark, 1)
|
||||
|
||||
if !response.nil?
|
||||
if response["status"] == true
|
||||
self.sale.rebate_status = 'true'
|
||||
sale.rebate_status = 'true'
|
||||
end
|
||||
if response["status"] == false
|
||||
self.sale.rebate_status = 'false'
|
||||
sale.rebate_status = 'false'
|
||||
end
|
||||
|
||||
if response[:status] == false
|
||||
self.sale.rebate_status = 'false'
|
||||
sale.rebate_status = 'false'
|
||||
end
|
||||
if response[:status] == "no_member"
|
||||
self.sale.rebate_status = nil
|
||||
sale.rebate_status = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.sale.save!
|
||||
sale.save!
|
||||
|
||||
if check_foc
|
||||
table_update_status(sObj)
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
|
||||
table_update_status(sObj)
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
elsif method_status && paid_amount.to_f == 0 && is_credit == 0
|
||||
table_update_status(sObj)
|
||||
elsif paid_amount.to_f == 0 && !is_credit
|
||||
table_update_status(sale)
|
||||
update_shift
|
||||
end
|
||||
end
|
||||
@@ -778,32 +757,16 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
|
||||
def table_update_status(sale_obj)
|
||||
status = true
|
||||
sale_count = 0
|
||||
if booking = sale_obj.bookings[0]
|
||||
if booking.dining_facility_id.to_i > 0
|
||||
puts "Update staus 1"
|
||||
if booking = sale_obj.booking
|
||||
puts "Update staus 2"
|
||||
if booking.dining_facility
|
||||
puts "Update staus 3"
|
||||
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?
|
||||
status = false
|
||||
if !table.current_bookings.exists?
|
||||
puts "Update staus 3"
|
||||
table.update_attributes(status: "available")
|
||||
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
|
||||
|
||||
@@ -19,7 +19,7 @@ class ShiftSale < ApplicationRecord
|
||||
|
||||
def self.current_shift
|
||||
# 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
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user