close cashier pdf and receipt bill pdf changes for credit payment

This commit is contained in:
phyusin
2018-07-12 15:50:58 +06:30
parent ebd3918cfa
commit 03abeabb4e
12 changed files with 116 additions and 52 deletions

View File

@@ -38,7 +38,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
# self.print(filename, cashier_terminal.printer_name)
# end
def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile)
def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
#Use CUPS service
#Generate PDF
@@ -46,16 +46,16 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
cashier = shift_sale.employee.name
shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p")
filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf"
pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile)
pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
close_cashier_pdf = Lookup.collection_of("print_settings") #print_settings with name:CloseCashierPdf
if !close_cashier_pdf.empty?
close_cashier_pdf.each do |close_cashier|
if close_cashier[0] == 'CloseCashierCustomisePdf'
if close_cashier[1] == '1'
pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,@total_waste,@total_spoile)
pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
else
pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile)
pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
end
end
end

View File

@@ -889,25 +889,26 @@ class SalePayment < ApplicationRecord
end
def get_credit_payment_left
query = SalePayment.select("(CASE WHEN (SUM(payment_amount) - (SELECT SUM(payment_amount)
sql = "SELECT SUM(payment_amount)
from sale_payments
join sale_audits on SUBSTRING_INDEX(remark,'||',1)=sale_payment_id
where sale_payments.sale_id = '#{self.sale_id}')) > 0 THEN (SUM(payment_amount) - (SELECT SUM(payment_amount)
from sale_payments
join sale_audits on SUBSTRING_INDEX(remark,'||',1)=sale_payment_id
where sale_payments.sale_id = '#{self.sale_id}')) ELSE 0 END) as payment_amount")
where sale_payments.sale_id = '#{self.sale_id}'"
query = SalePayment.select("(CASE WHEN (SUM(payment_amount) - (#{sql})) > 0 THEN (SUM(payment_amount) - (#{sql})) ELSE 0 END) as payment_amount")
.where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{self.sale_id}'")
return query
end
def self.get_sale_payments(sale_data)
query = sale_data.sale_payments
.where("CASE WHEN ((SELECT SUM(payment_amount)
sql = "SELECT SUM(payment_amount)
FROM sale_payments where payment_method='creditnote'
and sale_id='#{sale_data.sale_id}') -
(SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
and sale_id='#{sale_data.sale_id}'"
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'
and sale_id='#{sale_data.sale_id}')
and sale_id='#{sale_data.sale_id}'"
query = sale_data.sale_payments
.where("CASE WHEN ((#{sql}) - (#{sql1})
ELSE SUM(payment_amount) END
FROM sale_payments
JOIN sales s ON s.sale_id=sale_payments.sale_id

View File

@@ -178,4 +178,11 @@ class ShiftSale < ApplicationRecord
end
def self.get_shift_sales_with_credit_payment(shift_id)
query = SalePayment.select("(CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) as total_credit_payments")
.joins(" JOIN sale_audits sa ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id")
.where("SUBSTRING_INDEX(SUBSTRING_INDEX(sa.remark,'||',-1),' -> ',1) = #{shift_id}")
.first()
end
end