class PaymentJournal < ApplicationRecord

  def cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user)
    self.payment_references = reference
    self.remark = remark
    self.credit_amount = amount
    self.payment_method = payment_method
    self.payment_status = 'paid'
    self.payment_method_references = payment_method_reference
    self.created_by = current_user
    self.save
  end

  def cash_out(payment_reference, remark, amount, current_user)
    self.payment_references = payment_reference
    self.remark = remark
    self.debit_amount = amount
    self.payment_status = 'paid'
    self.created_by = current_user
    self.save
  end

  # def self.today_cash_in(current_user)
  #   credit = 0.0
  #   today_date = DateTime.now.strftime("%Y-%m-%d")
  #   pj_credit = PaymentJournal.where("TO_CHAR(created_at, 'YYYY-MM-DD')=? and created_by=?",today_date, current_user)
  #   pj_credit.each do |obj|
  #     credit += obj.credit_amount
  #   end
  #   return credit
  # end
  #
  # def self.today_cash_out(current_user)
  #   debit = 0.0
  #   today_date = DateTime.now.strftime("%Y-%m-%d")
  #   pj_debit = PaymentJournal.where("TO_CHAR(created_at, 'YYYY-MM-DD')=? and created_by=?",today_date, current_user)
  #   pj_debit.each do |obj|
  #      debit += obj.debit_amount
  #   end
  #   return debit
  # end

end
