771 lines
30 KiB
Ruby
Executable File
771 lines
30 KiB
Ruby
Executable File
class Origami::PaymentsController < BaseOrigamiController
|
|
authorize_resource :class => false
|
|
def index
|
|
end
|
|
|
|
def first_bill
|
|
sale_id = params[:sale_id] # sale_id
|
|
sale_data = Sale.find_by_sale_id(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}'")
|
|
# if bookings.count > 1
|
|
# # for Multiple Booking
|
|
# table = DiningFacility.find(bookings[0].dining_facility_id)
|
|
# else
|
|
# table = DiningFacility.find(bookings[0].dining_facility_id)
|
|
# end
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
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)
|
|
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)
|
|
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
|
end
|
|
end
|
|
|
|
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
|
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
|
|
# Print for First Bill to Customer
|
|
unique_code = "ReceiptBillPdf"
|
|
print_settings = PrintSetting.all
|
|
if !print_settings.nil?
|
|
print_settings.each do |setting|
|
|
if setting.unique_code == 'ReceiptBillPdf'
|
|
unique_code = "ReceiptBillPdf"
|
|
elsif setting.unique_code == 'ReceiptBillStarPdf'
|
|
unique_code = "ReceiptBillStarPdf"
|
|
end
|
|
end
|
|
end
|
|
|
|
if !receipt_bill_a5_pdf.empty?
|
|
receipt_bill_a5_pdf.each do |receipt_bilA5|
|
|
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
|
|
if receipt_bilA5[1] == '1'
|
|
unique_code = "ReceiptBillA5Pdf"
|
|
else
|
|
unique_code = unique_code#{}"ReceiptBillPdf"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
#shop detail
|
|
## shop_detail = Shop.first
|
|
# customer= Customer.where('customer_id=' +.customer_id)
|
|
customer = Customer.find(sale_data.customer_id)
|
|
# rounding adjustment
|
|
if shop_detail.is_rounding_adj
|
|
a = sale_data.grand_total % 25 # Modulus
|
|
b = sale_data.grand_total / 25 # Division
|
|
#not calculate rounding if modulus is 0 and division is even
|
|
#calculate rounding if modulus is zero or not zero and division are not even
|
|
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
|
|
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
|
|
rounding_adj = new_total-sale_data.grand_total
|
|
sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj)
|
|
end
|
|
end
|
|
#end rounding adjustment
|
|
#record for sale audit
|
|
action_by = current_user.name
|
|
type = "FIRST_BILL"
|
|
|
|
remark = "#{action_by} print out first bill for Receipt No #{sale_data.receipt_no}"
|
|
sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type )
|
|
# get member information
|
|
rebate = MembershipSetting.find_by_rebate(1)
|
|
if customer.membership_id != nil && rebate
|
|
# member_info = Customer.get_member_account(customer)
|
|
# current_balance = SaleAudit.paymal_search(sale_id)
|
|
current_balance = 0
|
|
end
|
|
# get printer info
|
|
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
|
|
# find order id by sale id
|
|
# sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
|
|
|
|
# Calculate price_by_accounts
|
|
item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale_items)
|
|
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale_items)
|
|
|
|
other_amount = SaleItem.calculate_other_charges(sale_items)
|
|
|
|
printer = Printer::ReceiptPrinter.new(print_settings)
|
|
|
|
filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_detail, "Frt",current_balance,nil,other_amount,nil,nil,nil)
|
|
|
|
result = {
|
|
:filepath => filename,
|
|
:printer_model => print_settings.brand_name,
|
|
:printer_url => print_settings.api_settings
|
|
}
|
|
|
|
# Mobile Print
|
|
render :json => result.to_json
|
|
# end
|
|
end
|
|
|
|
def create
|
|
cash = params[:cash]
|
|
sale_id = params[:sale_id]
|
|
member_info = nil
|
|
type = params[:type]
|
|
tax_type = params[:tax_type]
|
|
path = request.fullpath
|
|
latest_order_no = nil
|
|
|
|
if(Sale.exists?(sale_id))
|
|
saleObj = Sale.find(sale_id)
|
|
sale_items = SaleItem.get_all_sale_items(sale_id)
|
|
#shop_detail = Shop.first
|
|
# rounding adjustment
|
|
if !path.include? ("credit_payment")
|
|
if shop_detail.is_rounding_adj
|
|
a = saleObj.grand_total % 25 # Modulus
|
|
b = saleObj.grand_total / 25 # Division
|
|
#not calculate rounding if modulus is 0 and division is even
|
|
#calculate rounding if modulus is zero or not zero and division are not even
|
|
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
|
|
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
|
|
rounding_adj = new_total-saleObj.grand_total
|
|
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
|
|
end
|
|
end
|
|
end
|
|
#end rounding adjustment
|
|
|
|
sale_payment = SalePayment.new
|
|
if path.include? ("credit_payment")
|
|
sale_payment.process_payment(saleObj, current_user, cash, "cash", nil, true)
|
|
else
|
|
sale_payment.process_payment(saleObj, current_user, cash, "cash")
|
|
end
|
|
|
|
if !path.include? ("credit_payment")
|
|
rebate_amount = nil
|
|
|
|
# For Cashier by Zone
|
|
# bookings = Booking.where("sale_id='#{sale_id}'")
|
|
bookings = Booking.find_by_sale_id(sale_id)
|
|
|
|
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 = DiningFacility.find(bookings.dining_facility_id)
|
|
cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id)
|
|
cashier_terminal = CashierTerminal.find(cashier_zone.cashier_terminal_id)
|
|
|
|
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
|
|
end
|
|
|
|
# For Print
|
|
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
|
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
|
|
unique_code = "ReceiptBillPdf"
|
|
print_settings = PrintSetting.all
|
|
if !print_settings.nil?
|
|
print_settings.each do |setting|
|
|
if setting.unique_code == 'ReceiptBillPdf'
|
|
unique_code = "ReceiptBillPdf"
|
|
elsif setting.unique_code == 'ReceiptBillStarPdf'
|
|
unique_code = "ReceiptBillStarPdf"
|
|
end
|
|
end
|
|
end
|
|
|
|
if !receipt_bill_a5_pdf.empty?
|
|
receipt_bill_a5_pdf.each do |receipt_bilA5|
|
|
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
|
|
if receipt_bilA5[1] == '1'
|
|
unique_code = "ReceiptBillA5Pdf"
|
|
# else
|
|
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
customer= Customer.find(saleObj.customer_id)
|
|
|
|
# get member information
|
|
rebate = MembershipSetting.find_by_rebate(1)
|
|
credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote')
|
|
|
|
if customer.membership_id != nil && rebate && credit_data.nil?
|
|
member_info = Customer.get_member_account(customer)
|
|
|
|
if member_info["status"] == true
|
|
rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
|
|
current_balance = SaleAudit.paymal_search(sale_id)
|
|
end
|
|
end
|
|
|
|
#orders print out
|
|
if params[:type] == "quick_service"
|
|
booking = Booking.find_by_sale_id(sale_id)
|
|
if booking.dining_facility_id.to_i>0
|
|
table_id = booking.dining_facility_id
|
|
else
|
|
table_id = 0
|
|
end
|
|
|
|
latest_order = booking.booking_orders.order("order_id DESC").limit(1).first()
|
|
if !latest_order.nil?
|
|
latest_order_no = latest_order.order_id
|
|
end
|
|
|
|
booking.booking_orders.each do |order|
|
|
# Order.pay_process_order_queue(order.order_id, table_id)
|
|
oqs = OrderQueueStation.new
|
|
oqs.pay_process_order_queue(order.order_id, table_id)
|
|
|
|
assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id)
|
|
from = getCloudDomain #get sub domain in cloud mode
|
|
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
|
|
end
|
|
|
|
end
|
|
|
|
#for card sale data
|
|
card_data = Array.new
|
|
card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id)
|
|
if !card_sale_trans_ref_no.nil?
|
|
card_sale_trans_ref_no.each do |cash_sale_trans|
|
|
card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s
|
|
card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s
|
|
card_no = cash_sale_trans.pan.last(4)
|
|
card_no = card_no.rjust(19,"**** **** **** ")
|
|
card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id})
|
|
end
|
|
end
|
|
|
|
#card_balance amount for Paymal payment
|
|
card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id)
|
|
|
|
# get printer info
|
|
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
# Calculate Food and Beverage Total
|
|
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
|
|
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
|
|
other_amount = SaleItem.calculate_other_charges(sale_items)
|
|
|
|
printer = Printer::ReceiptPrinter.new(print_settings)
|
|
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
|
|
|
|
render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name})
|
|
|
|
#end
|
|
end
|
|
end
|
|
end
|
|
|
|
def show
|
|
path = request.fullpath
|
|
sale_id = params[:sale_id]
|
|
@trans_flag = true
|
|
if params[:type] == "transaction"
|
|
@trans_flag = false
|
|
@cashier_type = "cashier"
|
|
else
|
|
@cashier_type = params[:type]
|
|
end
|
|
|
|
if path.include? ("credit_payment")
|
|
@sale_payment = SalePayment.get_credit_amount_due_left(sale_id)
|
|
end
|
|
|
|
@member_discount = MembershipSetting.find_by_discount(1)
|
|
@membership_rebate_balance=0
|
|
|
|
if Sale.exists?(sale_id)
|
|
@cash = 0.0
|
|
@other = 0.0
|
|
@ppamount = 0.0
|
|
@visacount= 0.0
|
|
@jcbcount= 0.0
|
|
@mastercount = 0.0
|
|
@unionpaycount = 0.0
|
|
@alipaycount = 0.0
|
|
@junctionpaycount = 0.0
|
|
@credit = 0.0
|
|
@paymalcount = 0.0
|
|
@dingacount = 0.0
|
|
@giftvouchercount = 0.0
|
|
@sale_data = Sale.find_by_sale_id(sale_id)
|
|
@balance = 0
|
|
@accountable_type = ''
|
|
@table_no = ''
|
|
@dining = ''
|
|
@other_payment = 0.0
|
|
@pdf_view = nil
|
|
@lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView")
|
|
if !@lookup_pdf.nil?
|
|
@pdf_view = @lookup_pdf.value
|
|
end
|
|
|
|
#for changable on/off
|
|
@changable_tax = true
|
|
lookup_changable_tax = Lookup.collection_of('changable_tax')
|
|
if !lookup_changable_tax.empty?
|
|
lookup_changable_tax.each do |changable_tax|
|
|
if changable_tax[0].downcase == "change"
|
|
if changable_tax[1] == '0'
|
|
@changable_tax = false
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
@shop = shop_detail #show shop info
|
|
|
|
@customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'")
|
|
|
|
saleObj = Sale.find(sale_id)
|
|
|
|
#total customer with individual total amount
|
|
@individual_total = Array.new
|
|
if !saleObj.equal_persons.nil?
|
|
per_person_amount = saleObj.grand_total.to_f / saleObj.equal_persons.to_i
|
|
@individual_total.push({'total_customer' => saleObj.equal_persons.to_i, 'per_person_amount' => per_person_amount.to_f })
|
|
end
|
|
|
|
# rounding adjustment
|
|
# if @shop.is_rounding_adj
|
|
# a = saleObj.grand_total % 25 # Modulus
|
|
# b = saleObj.grand_total / 25 # Division
|
|
# #not calculate rounding if modulus is 0 and division is even
|
|
# #calculate rounding if modulus is zero or not zero and division are not even
|
|
# if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
|
|
# new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
|
|
# @rounding_adj = new_total-saleObj.grand_total
|
|
# else
|
|
# @rounding_adj = @sale_data.rounding_adjustment
|
|
# end
|
|
# else
|
|
# @rounding_adj = @sale_data.rounding_adjustment
|
|
# end
|
|
#end rounding adjustment
|
|
|
|
# rounding adjustment
|
|
if @shop.is_rounding_adj
|
|
a = saleObj.grand_total % 25 # Modulus
|
|
b = saleObj.grand_total / 25 # Division
|
|
#not calculate rounding if modulus is 0 and division is even
|
|
#calculate rounding if modulus is zero or not zero and division are not even
|
|
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
|
|
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
|
|
@rounding_adj = new_total-saleObj.grand_total
|
|
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj)
|
|
@sale_data.grand_total = new_total
|
|
@sale_data.old_grand_total = saleObj.grand_total
|
|
@sale_data.rounding_adjustment = @rounding_adj
|
|
else
|
|
@rounding_adj = @sale_data.rounding_adjustment
|
|
end
|
|
else
|
|
@rounding_adj = @sale_data.rounding_adjustment
|
|
end
|
|
#end rounding adjustment
|
|
|
|
# get printer info
|
|
@print_settings = PrintSetting.get_precision_delimiter()
|
|
|
|
#get customer amount
|
|
@customer = Customer.find(@sale_data.customer_id)
|
|
# accounts = @customer.tax_profiles
|
|
accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC")
|
|
@account_arr =[]
|
|
@tax_arr =[]
|
|
accounts.each do |acc|
|
|
account = TaxProfile.find(acc.id)
|
|
# @account_arr.push(account)
|
|
@tax_arr.push(account.name)
|
|
end
|
|
sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id)
|
|
if !sale_taxes.empty?
|
|
sale_taxes.each do |sale_tax|
|
|
@account_arr.push(sale_tax)
|
|
end
|
|
end
|
|
rebate = MembershipSetting.find_by_rebate(1)
|
|
# get member information
|
|
if @customer.membership_id != nil && rebate
|
|
response = Customer.get_member_account(@customer)
|
|
if response["status"]==true
|
|
response["account_data"].each do |res|
|
|
if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
|
|
@balance = @balance.to_f + res["balance"].to_f
|
|
# @accountable_type = res["accountable_type"]
|
|
@accountable_type = "Rebate Balance"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
#end customer amount
|
|
|
|
#paymal payment
|
|
|
|
@sale_data.bookings.each do |sbk|
|
|
if sbk.dining_facility_id.to_i >0
|
|
df = DiningFacility.find(sbk.dining_facility_id)
|
|
@table_no = df.type + ' ' + df.name
|
|
@checkin_time = sbk.checkin_at
|
|
@dining = df
|
|
break
|
|
else
|
|
@table_no = nil
|
|
@checkin_time = nil
|
|
@dining = nil
|
|
end
|
|
end
|
|
|
|
if path.include? ("credit_payment")
|
|
@sale_payment_data = SalePayment.get_sale_payment_for_credit(@sale_data)
|
|
else
|
|
@sale_payment_data = SalePayment.get_sale_payments(@sale_data)
|
|
end
|
|
@sale_payment_data.each do |spay|
|
|
if spay.payment_method == "cash"
|
|
@cash += spay.payment_amount
|
|
end
|
|
if spay.payment_method !="creditnote"
|
|
@other_payment += spay.payment_amount
|
|
end
|
|
|
|
if spay.payment_method == "mpu"
|
|
@other += spay.payment_amount
|
|
elsif spay.payment_method == "paypar"
|
|
@ppamount += spay.payment_amount
|
|
elsif spay.payment_method == "visa"
|
|
@visacount += spay.payment_amount
|
|
elsif spay.payment_method == "jcb"
|
|
@jcbcount += spay.payment_amount
|
|
elsif spay.payment_method == "master"
|
|
@mastercount += spay.payment_amount
|
|
elsif spay.payment_method == "unionpay"
|
|
@unionpaycount += spay.payment_amount
|
|
elsif spay.payment_method == "JunctionPay"
|
|
@junctionpaycount += spay.payment_amount
|
|
elsif spay.payment_method == "creditnote"
|
|
@credit += spay.payment_amount
|
|
elsif spay.payment_method == "paymal"
|
|
@paymalcount += spay.payment_amount
|
|
elsif spay.payment_method == "alipay"
|
|
@alipaycount += spay.payment_amount
|
|
elsif spay.payment_method == "dinga"
|
|
@dingacount += spay.payment_amount
|
|
elsif spay.payment_method == "giftvoucher"
|
|
@giftvouchercount += spay.payment_amount
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
def reprint
|
|
sale_id = params[:sale_id]
|
|
member_info = nil
|
|
latest_order_no = nil
|
|
saleObj = Sale.find(sale_id)
|
|
|
|
# For Cashier by Zone
|
|
bookings = Booking.where("sale_id='#{sale_id}'")
|
|
|
|
booking = Booking.find_by_sale_id(sale_id)
|
|
latest_order = booking.booking_orders.joins(" JOIN orders ON orders.order_id = booking_orders.order_id").where("orders.source = 'quick_service'").order("order_id DESC").limit(1).first()
|
|
if !latest_order.nil?
|
|
latest_order_no = latest_order.order_id
|
|
end
|
|
# if bookings.count > 1
|
|
# # for Multiple Booking
|
|
# table = DiningFacility.find(bookings[0].dining_facility_id)
|
|
# else
|
|
# table = DiningFacility.find(bookings[0].dining_facility_id)
|
|
# end
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
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)
|
|
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)
|
|
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
|
end
|
|
end
|
|
|
|
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
|
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
|
|
unique_code = "ReceiptBillPdf"
|
|
if !receipt_bill_a5_pdf.empty?
|
|
receipt_bill_a5_pdf.each do |receipt_bilA5|
|
|
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
|
|
if receipt_bilA5[1] == '1'
|
|
unique_code = "ReceiptBillA5Pdf"
|
|
else
|
|
unique_code = "ReceiptBillPdf"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
customer= Customer.find(saleObj.customer_id)
|
|
|
|
#shop detail
|
|
#shop_detail = Shop.first
|
|
# get member information
|
|
rebate = MembershipSetting.find_by_rebate(1)
|
|
if customer.membership_id != nil && rebate
|
|
member_info = Customer.get_member_account(customer)
|
|
rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
|
|
current_balance = SaleAudit.paymal_search(sale_id)
|
|
end
|
|
|
|
#for card sale data
|
|
card_data = Array.new
|
|
card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id)
|
|
if !card_sale_trans_ref_no.nil?
|
|
card_sale_trans_ref_no.each do |cash_sale_trans|
|
|
card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s
|
|
card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s
|
|
card_no = cash_sale_trans.pan.last(4)
|
|
card_no = card_no.rjust(19,"**** **** **** ")
|
|
card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id})
|
|
end
|
|
end
|
|
|
|
#card_balance amount for Paymal payment
|
|
card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id)
|
|
|
|
# get printer info
|
|
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
|
|
# Calculate price_by_accounts
|
|
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
|
|
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
|
|
other_amount = SaleItem.calculate_other_charges(saleObj.sale_items)
|
|
|
|
printer = Printer::ReceiptPrinter.new(print_settings)
|
|
filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
|
|
|
|
result = {
|
|
:status => true,
|
|
:filepath => filename,
|
|
:printer_model => print_settings.brand_name,
|
|
:printer_url => print_settings.api_settings
|
|
}
|
|
|
|
# Mobile Print
|
|
render :json => result.to_json
|
|
# end
|
|
end
|
|
|
|
def foc
|
|
cash = params[:cash]
|
|
sale_id = params[:sale_id]
|
|
sub_total = params[:sub_total]
|
|
remark = params[:remark]
|
|
member_info = nil
|
|
rebate_amount = nil
|
|
current_balance = nil
|
|
order_source = params[:type]
|
|
|
|
if(Sale.exists?(sale_id))
|
|
saleObj = Sale.find(sale_id)
|
|
#calculate cash acmount
|
|
cash = saleObj.total_amount
|
|
|
|
if saleObj.discount_type == "member_discount"
|
|
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
|
|
saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0,order_source)
|
|
end
|
|
|
|
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
|
|
|
|
sale_payment = SalePayment.new
|
|
sale_payment.process_payment(saleObj, current_user, cash, "foc" ,remark)
|
|
|
|
bookings = Booking.where("sale_id='#{sale_id}'")
|
|
if bookings[0].dining_facility_id.to_i > 0
|
|
table = DiningFacility.find(bookings[0].dining_facility_id)
|
|
type = 'payment'
|
|
from = getCloudDomain #get sub domain in cloud mode
|
|
ActionCable.server.broadcast "order_channel",table: table,type:type,from:from
|
|
end
|
|
|
|
|
|
|
|
# For Cashier by Zone
|
|
bookings = Booking.where("sale_id='#{sale_id}'")
|
|
|
|
shift = ShiftSale.current_open_shift(current_user.id)
|
|
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)
|
|
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)
|
|
cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id)
|
|
end
|
|
end
|
|
|
|
# Re-call Sale Data
|
|
saleObj = Sale.find(sale_id)
|
|
|
|
# if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
|
unique_code = "ReceiptBillPdf"
|
|
customer= Customer.find(saleObj.customer_id)
|
|
|
|
#shop detail
|
|
#shop_detail = Shop.first
|
|
|
|
# get printer info
|
|
print_settings=PrintSetting.find_by_unique_code(unique_code)
|
|
# Calculate Food and Beverage Total
|
|
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
|
|
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
|
|
|
|
other_amount = SaleItem.calculate_other_charges(saleObj.sale_items)
|
|
|
|
printer = Printer::ReceiptPrinter.new(print_settings)
|
|
|
|
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "FOC",nil,nil,other_amount,nil,nil,nil)
|
|
result = {
|
|
:status => true,
|
|
:filepath => filename,
|
|
:printer_model => print_settings.brand_name,
|
|
:printer_url => print_settings.api_settings
|
|
}
|
|
|
|
# Mobile Print
|
|
render :json => result.to_json
|
|
|
|
if params[:type] == "quick_service"
|
|
booking = Booking.find_by_sale_id(sale_id)
|
|
if booking.dining_facility_id.to_i>0
|
|
table_id = booking.dining_facility_id
|
|
else
|
|
table_id = 0
|
|
end
|
|
|
|
booking.booking_orders.each do |order|
|
|
Order.pay_process_order_queue(order.order_id,table_id)
|
|
end
|
|
end
|
|
# end
|
|
end
|
|
end
|
|
|
|
def rounding_adj
|
|
|
|
saleObj = Sale.find(params[:sale_id])
|
|
@shop = shop_detail
|
|
|
|
if @shop.is_rounding_adj
|
|
a = saleObj.grand_total % 25 # Modulus
|
|
b = saleObj.grand_total / 25 # Division
|
|
#not calculate rounding if modulus is 0 and division is even
|
|
#calculate rounding if modulus is zero or not zero and division are not even
|
|
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
|
|
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
|
|
rounding_adj = new_total-saleObj.grand_total
|
|
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
|
|
end
|
|
end
|
|
end
|
|
|
|
#print function for receipt
|
|
def print
|
|
filename = params[:filename]
|
|
receipt_no = params[:receipt_no]
|
|
printer_name = params[:printer_name]
|
|
cashier_type = params[:type]
|
|
|
|
if cashier_type.strip.downcase == "doemal_order"
|
|
unique_code = "ReceiptBillOrderPdf"
|
|
else
|
|
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
|
|
unique_code = "ReceiptBillPdf"
|
|
print_settings = PrintSetting.all
|
|
if !print_settings.nil?
|
|
print_settings.each do |setting|
|
|
if setting.unique_code == 'ReceiptBillPdf'
|
|
unique_code = "ReceiptBillPdf"
|
|
elsif setting.unique_code == 'ReceiptBillStarPdf'
|
|
unique_code = "ReceiptBillStarPdf"
|
|
end
|
|
end
|
|
end
|
|
if !receipt_bill_a5_pdf.empty?
|
|
receipt_bill_a5_pdf.each do |receipt_bilA5|
|
|
if receipt_bilA5[0] == 'ReceiptBillA5Pdf'
|
|
if receipt_bilA5[1] == '1'
|
|
unique_code = "ReceiptBillA5Pdf"
|
|
# else
|
|
# unique_code = "ReceiptBillPdf"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
# get printer info
|
|
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)
|
|
|
|
result = {
|
|
:status => true,
|
|
:filepath => filename,
|
|
:printer_model => print_settings.brand_name,
|
|
:printer_url => print_settings.api_settings
|
|
}
|
|
Rails.logger.debug "$$$$$$$$$ result ::"
|
|
Rails.logger.debug result
|
|
# Mobile Print
|
|
render :json => result.to_json
|
|
# render :json => {status: true}
|
|
end
|
|
|
|
#changable tax for sale
|
|
def change_tax
|
|
sale_id = params[:sale_id]
|
|
order_source = params[:cashier_type]
|
|
tax_type = params[:tax_type]
|
|
sale = Sale.find(sale_id)
|
|
sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount,nil,order_source,tax_type)
|
|
|
|
render json: JSON.generate({:status => true})
|
|
end
|
|
|
|
#get cloud domain
|
|
def getCloudDomain
|
|
from = ""
|
|
if ENV["SERVER_MODE"] == 'cloud'
|
|
from = request.subdomain + "." + request.domain
|
|
end
|
|
|
|
return from
|
|
end
|
|
end |