diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 4db5e225..e6bb4811 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -130,9 +130,9 @@ class Origami::PaymentsController < BaseOrigamiController sale_payment = SalePayment.new if path.include? ("credit_payment") - sale_payment.process_payment(saleObj, current_user.name, cash, "cash", nil, true) + sale_payment.process_payment(saleObj, current_user, cash, "cash", nil, true) else - sale_payment.process_payment(saleObj, current_user.name, cash, "cash") + sale_payment.process_payment(saleObj, current_user, cash, "cash") end if !path.include? ("credit_payment") diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 36f88638..5b89c1d1 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -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 diff --git a/app/views/reports/payment_method/index.xls.erb b/app/views/reports/payment_method/index.xls.erb index fa4ee81e..9e42b9f3 100755 --- a/app/views/reports/payment_method/index.xls.erb +++ b/app/views/reports/payment_method/index.xls.erb @@ -43,24 +43,36 @@