print credit payment
This commit is contained in:
@@ -89,7 +89,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
|||||||
path = request.fullpath
|
path = request.fullpath
|
||||||
latest_order_no = nil
|
latest_order_no = nil
|
||||||
is_kbz = params[:is_kbz]
|
is_kbz = params[:is_kbz]
|
||||||
credit_pdf = Lookup.find_by_lookup_type("credit_pdf")
|
|
||||||
|
|
||||||
if saleObj = Sale.find(sale_id)
|
if saleObj = Sale.find(sale_id)
|
||||||
sale_items = SaleItem.get_all_sale_items(sale_id)
|
sale_items = SaleItem.get_all_sale_items(sale_id)
|
||||||
@@ -107,7 +107,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
|||||||
sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user)
|
sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
if !path.include? ("credit_payment")
|
|
||||||
rebate_amount = nil
|
rebate_amount = nil
|
||||||
|
|
||||||
# For Cashier by Zone
|
# For Cashier by Zone
|
||||||
@@ -201,108 +201,18 @@ class Origami::PaymentsController < BaseOrigamiController
|
|||||||
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
|
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)
|
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
|
||||||
other_amount = SaleItem.calculate_other_charges(sale_items)
|
other_amount = SaleItem.calculate_other_charges(sale_items)
|
||||||
|
credit_pdf = Lookup.find_by_lookup_type("credit_pdf")
|
||||||
|
if (path.include? ("credit_payment")) && !credit_pdf.nil? && credit_pdf.value.to_i == 1
|
||||||
|
printed_status = 'credit_payment'
|
||||||
|
else
|
||||||
|
printed_status = 'Paid'
|
||||||
|
end
|
||||||
|
|
||||||
printer = Printer::ReceiptPrinter.new(print_settings)
|
printer = Printer::ReceiptPrinter.new(print_settings)
|
||||||
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, 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)
|
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, printed_status,current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
|
||||||
|
|
||||||
#end
|
#end
|
||||||
elsif (path.include? ("credit_payment")) && !credit_pdf.nil? && credit_pdf.value.to_i == 1
|
|
||||||
|
|
||||||
rebate_amount = nil
|
|
||||||
# For Cashier by Zone
|
|
||||||
booking = saleObj.booking
|
|
||||||
|
|
||||||
if current_user.role == 'cashier'
|
|
||||||
cashier_terminal = current_user.cashier_terminal
|
|
||||||
elsif booking.dining_facility
|
|
||||||
cashier_terminal = booking.cashier_terminal_by_dining_facility
|
|
||||||
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
|
|
||||||
|
|
||||||
if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf
|
|
||||||
unique_code = "ReceiptBillA5Pdf"
|
|
||||||
else
|
|
||||||
unique_code = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code
|
|
||||||
end
|
|
||||||
|
|
||||||
customer = saleObj.customer
|
|
||||||
|
|
||||||
# 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 type == "quick_service"
|
|
||||||
if booking.dining_facility_id.present?
|
|
||||||
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|
|
|
||||||
|
|
||||||
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_credit(print_settings, false, nil, 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)
|
|
||||||
end
|
|
||||||
if !saleObj.nil?
|
if !saleObj.nil?
|
||||||
# InventoryJob.perform_now(self.id)
|
# InventoryJob.perform_now(self.id)
|
||||||
# InventoryDefinition.calculate_product_count(saleObj)
|
# InventoryDefinition.calculate_product_count(saleObj)
|
||||||
|
|||||||
@@ -119,11 +119,15 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
|||||||
if count == 1
|
if count == 1
|
||||||
filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf"
|
filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf"
|
||||||
pdf.render_file filename
|
pdf.render_file filename
|
||||||
if printed_status != 'Paid'
|
if printed_status != 'Paid' && printed_status != 'credit_payment'
|
||||||
#no print in cloud server
|
#no print in cloud server
|
||||||
if ENV["SERVER_MODE"] != "cloud"
|
if ENV["SERVER_MODE"] != "cloud"
|
||||||
self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name)
|
self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name)
|
||||||
end
|
end
|
||||||
|
elsif printed_status == 'credit_payment'
|
||||||
|
filename = directory_name + "/receipt_bill_credit_#{sale_data.receipt_no}.pdf"
|
||||||
|
pdf.render_file filename
|
||||||
|
self.print(directory_name + "/receipt_bill_credit_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
|
filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
|
|
||||||
cashier_info(sale_data, customer_name, latest_order_no)
|
cashier_info(sale_data, customer_name, latest_order_no)
|
||||||
line_items(sale_items,precision,delimiter)
|
line_items(sale_items,precision,delimiter)
|
||||||
all_total(sale_data,precision,delimiter)
|
all_total(sale_data,precision,delimiter,printed_status)
|
||||||
|
|
||||||
|
|
||||||
if member_info != nil
|
if member_info != nil
|
||||||
@@ -94,6 +94,9 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
end
|
end
|
||||||
|
|
||||||
if kbz_pay_status
|
if kbz_pay_status
|
||||||
|
if printed_status == 'credit_payment'
|
||||||
|
printed_status = 'Paid'
|
||||||
|
end
|
||||||
kbzpay_qr_generator(printed_status, qr_code)
|
kbzpay_qr_generator(printed_status, qr_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -305,7 +308,7 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_total(sale_data,precision,delimiter)
|
def all_total(sale_data,precision,delimiter,printed_status)
|
||||||
move_down line_move
|
move_down line_move
|
||||||
item_name_width = self.item_width
|
item_name_width = self.item_width
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
@@ -432,15 +435,20 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
end
|
end
|
||||||
move_down line_move
|
move_down line_move
|
||||||
|
|
||||||
sale_payment(sale_data,precision,delimiter)
|
sale_payment(sale_data,precision,delimiter,printed_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
def sale_payment(sale_data,precision,delimiter)
|
def sale_payment(sale_data,precision,delimiter,printed_status)
|
||||||
stroke_horizontal_rule
|
stroke_horizontal_rule
|
||||||
#move_down line_move
|
#move_down line_move
|
||||||
# sql = "SELECT SUM(payment_amount)
|
# sql = "SELECT SUM(payment_amount)
|
||||||
# FROM sale_payments where payment_method='creditnote'
|
# FROM sale_payments where payment_method='creditnote'
|
||||||
# and sale_id='#{sale_data.sale_id}'"
|
# and sale_id='#{sale_data.sale_id}'"
|
||||||
|
|
||||||
|
if printed_status == 'credit_payment'
|
||||||
|
sale_payments = SalePayment.select(:payment_amount, :payment_method, :updated_at)
|
||||||
|
.where("sale_id = '#{sale_data.sale_id}' AND payment_method != 'creditnote'")
|
||||||
|
else
|
||||||
sql = SalePayment.select("(SUM(payment_amount))").where("payment_method='creditnote' and sale_id='#{sale_data.sale_id}'").to_sql
|
sql = SalePayment.select("(SUM(payment_amount))").where("payment_method='creditnote' and sale_id='#{sale_data.sale_id}'").to_sql
|
||||||
# sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
|
# sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
|
||||||
# FROM sale_payments where payment_method='creditnote'
|
# FROM sale_payments where payment_method='creditnote'
|
||||||
@@ -458,13 +466,16 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
where sa.sale_id='#{sale_data.sale_id}')) = 0
|
where sa.sale_id='#{sale_data.sale_id}')) = 0
|
||||||
THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id)
|
THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id)
|
||||||
.group("payment_method")
|
.group("payment_method")
|
||||||
|
end
|
||||||
|
|
||||||
sale_payments.each do |payment|
|
sale_payments.each do |payment|
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
if payment.payment_method == "paypar"
|
if payment.payment_method == "paypar"
|
||||||
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
||||||
text "Redeem Payment", :size => self.item_font_size,:align => :left
|
text "Redeem Payment", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
|
elsif printed_status == 'credit_payment'
|
||||||
|
text "#{payment.payment_method.capitalize} Payment on #{payment.updated_at.strftime('%d-%m-%Y')}", :left_margin => -10, :size => self.item_font_size,:align => :left
|
||||||
else
|
else
|
||||||
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
|
||||||
text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left
|
text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left
|
||||||
@@ -741,7 +752,9 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
move_down line_move
|
move_down line_move
|
||||||
stroke_horizontal_rule
|
stroke_horizontal_rule
|
||||||
move_down line_move
|
move_down line_move
|
||||||
|
if printed_status == 'credit_payment'
|
||||||
|
printed_status = 'Paid'
|
||||||
|
end
|
||||||
move_down line_move
|
move_down line_move
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
bounding_box([0, y_position], :width =>self.label_width) do
|
bounding_box([0, y_position], :width =>self.label_width) do
|
||||||
|
|||||||
Reference in New Issue
Block a user