merge with r-19
This commit is contained in:
@@ -388,25 +388,12 @@ class ReceiptBillA5Pdf < Prawn::Document
|
||||
|
||||
def sale_payment(sale_data,precision,delimiter)
|
||||
stroke_horizontal_rule
|
||||
# move_down 10
|
||||
sql = "SELECT SUM(payment_amount)
|
||||
FROM sale_payments where payment_method='creditnote'
|
||||
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}'"
|
||||
|
||||
sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method")
|
||||
.where("(CASE WHEN ((#{sql}) - (#{sql1})
|
||||
ELSE SUM(payment_amount) END
|
||||
FROM sale_payments
|
||||
JOIN sales s ON s.sale_id=sale_payments.sale_id
|
||||
JOIN sale_audits sa
|
||||
ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id
|
||||
where sa.sale_id='#{sale_data.sale_id}')) = 0
|
||||
THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id)
|
||||
.group("payment_method")
|
||||
sale_payments.each do |payment|
|
||||
query = sale_data.sale_payments
|
||||
.merge(SalePayment.where.not(payment_method: 'creditnote')
|
||||
.or(SalePayment.where.not(SalePayment.arel_table[:payment_amount].lteq(sale_data.sale_payments.joins(:sale_audit).sum(:payment_amount)))))
|
||||
|
||||
query.each do |payment|
|
||||
y_position = cursor
|
||||
if payment.payment_method == "paypar"
|
||||
bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do
|
||||
@@ -614,12 +601,16 @@ class ReceiptBillA5Pdf < Prawn::Document
|
||||
end
|
||||
|
||||
def sign(sale_data)
|
||||
sql = "SELECT SUM(payment_amount)
|
||||
FROM sale_payments where payment_method='creditnote'
|
||||
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}'"
|
||||
# sql = "SELECT SUM(payment_amount)
|
||||
# FROM sale_payments where payment_method='creditnote'
|
||||
# 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}'"
|
||||
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 ("
|
||||
sql1 += sql
|
||||
|
||||
SalePayment.where("(CASE WHEN ((#{sql}) - (#{sql1})
|
||||
ELSE SUM(payment_amount) END
|
||||
|
||||
Reference in New Issue
Block a user