update shift and multiple
This commit is contained in:
@@ -6,13 +6,15 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
belongs_to :sale
|
||||
|
||||
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status
|
||||
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status,:action_by
|
||||
|
||||
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
|
||||
|
||||
puts action_by
|
||||
puts "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
self.action_by = action_by
|
||||
#get all payment for this invoices
|
||||
if payment_for
|
||||
invoice_sale_payments = SalePayment.get_sale_payment_for_credit(invoice)
|
||||
@@ -84,12 +86,12 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
remark = "#{self.sale_payment_id}||#{shift_sale_id} -> #{remark}"
|
||||
|
||||
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
|
||||
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by.name)
|
||||
if payment_method == "cash"
|
||||
update_shift_for_credit_payment
|
||||
end
|
||||
else
|
||||
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
|
||||
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by.name)
|
||||
end
|
||||
|
||||
# update complete order items in oqs
|
||||
@@ -107,7 +109,7 @@ class SalePayment < ApplicationRecord
|
||||
else
|
||||
#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)
|
||||
sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by.name)
|
||||
|
||||
return false, "No outstanding Amount"
|
||||
end
|
||||
@@ -620,15 +622,25 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
# update for cashier shift
|
||||
def update_shift
|
||||
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
|
||||
|
||||
shift = ShiftSale.current_open_shift(self.action_by.id)
|
||||
|
||||
if shift.nil?
|
||||
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
|
||||
end
|
||||
|
||||
if !shift.nil?
|
||||
shift.update(self.sale)
|
||||
self.sale.shift_sale_id = shift.id
|
||||
self.sale.cashier_id = shift.employee_id
|
||||
self.sale.cashier_name = Employee.find(shift.employee_id).name
|
||||
self.sale.save
|
||||
else
|
||||
shift = ShiftSale.current_shift
|
||||
shift.update(self.sale)
|
||||
self.sale.shift_sale_id = shift.id
|
||||
self.sale.cashier_id = shift.employee_id
|
||||
self.sale.cashier_name = Employee.find(shift.employee_id).name
|
||||
self.sale.save
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user