merged master

This commit is contained in:
Yan
2017-06-07 17:45:40 +06:30
25 changed files with 142 additions and 91 deletions

View File

@@ -3,5 +3,7 @@ class Account < ApplicationRecord
has_many :menu_items
# belongs_to :lookup , :class_name => "Lookup"
def self.collection
Account.select("id, title").map { |e| [e.title, e.id] }
end
end

View File

@@ -1,10 +1,10 @@
class MenuItem < ApplicationRecord
#belongs_to :account
belongs_to :menu_category, :optional => true
has_many :menu_item_instances
belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true
has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
belongs_to :account
validates_presence_of :item_code, :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item

View File

@@ -1,6 +1,6 @@
class SaleAudit < ApplicationRecord
self.primary_key = "sale_audit_id"
#primary key - need to be unique generated for SaleAudit
before_create :generate_custom_id
@@ -44,13 +44,14 @@ class SaleAudit < ApplicationRecord
sale_audit.save!
end
def record_payment(sale_id, remark, action_by)
def self.record_payment(sale_id, remark, action_by)
sale_audit = SaleAudit.new()
sale_audit.sale_id = sale_id
sale_audit.action = "SALEPAYMENT"
sale_audit.action_at = DateTime.now.utc
sale_audit.action_by = action_by
sale_audit.remark = remark
sale_audit.approved_by = Time.now
sale_audit.save!
end

View File

@@ -1,17 +1,21 @@
class SalePayment < ApplicationRecord
self.primary_key = "sale_payment_id"
#primary key - need to be unique generated for multiple shops
before_create :generate_custom_id
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
def process_payment(invoice, action_by, cash_amount)
def process_payment(invoice, action_by)
self.sale = invoice
self.received_amount = cash_amount
payment_method = "cash"
amount_due = invoice.grand_total
#get all payment for this invoices
invoice.sale_payments.each do |payment|
if (payment.payment_status == "paid" )
@@ -22,32 +26,33 @@ class SalePayment < ApplicationRecord
if (amount_due > 0)
payment_status = false
#route to payment type
switch (payment_method)
case "cash"
case payment_method
when "cash"
payment_status = cash_payment
case "creditnote"
payment_status = creditnote_payment
case "visa"
payment_status = external_terminal_card_payment(:visa)
case "master"
payment_status = external_terminal_card_payment(:master)
case "jcb"
payment_status = external_terminal_card_payment(:jcb)
case "mpu"
payment_status = external_terminal_card_payment(:mpu)
case "unionpay"
payment_status = external_terminal_card_payment(:unionpay)
case "vochure"
payment_status = vochure_payment
case "giftcard"
payment_status = giftcard_payment
case "paypar"
#TODO: implement paypar implementation
when "creditnote"
if !self.customer_id.nil?
payment_status = creditnote_payment(self.customer_id)
end
when "visa"
payment_status = external_terminal_card_payment(:visa)
when "master"
payment_status = external_terminal_card_payment(:master)
when "jcb"
payment_status = external_terminal_card_payment(:jcb)
when "mpu"
payment_status = external_terminal_card_payment(:mpu)
when "unionpay"
payment_status = external_terminal_card_payment(:unionpay)
when "vochure"
payment_status = vochure_payment
when "giftcard"
payment_status = giftcard_payment
when "paypar"
payment_status = paypar_payment
else
puts "it was something else"
end
#record an payment in sale-audit
remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{amount} | Payment Status ->#{payment_status}"
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
@@ -66,10 +71,9 @@ class SalePayment < ApplicationRecord
private
def cash_payment
payment_status = false
self.payment_method = "cash"
self.payment_amount = self.received_amount
self.outstanding_amount = self.sale.grand_total - received_amount
self.outstanding_amount = self.sale.grand_total - self.received_amount
self.payment_status = "paid"
payment_method = self.save!
@@ -78,7 +82,8 @@ class SalePayment < ApplicationRecord
return payment_status
end
def creditnote_payment(self.customer_id)
def creditnote_payment(customer_id)
payment_status = false
self.payment_method = "creditnote"
@@ -147,11 +152,12 @@ class SalePayment < ApplicationRecord
end
def sale_update_payment_status(paid_amount)
puts "paid_amount"
puts paid_amount
#update amount_outstanding
self.sale.amount_received = self.sale.amount_received + paid_amount
self.sale.amount_changed = amount - self.sale.amount_received
if (self.sale.grand_total <= self.sale.amount_received && self.sale.amount_changed > 0)
self.sale.amount_changed = amount - self.sale.amount_received
if (self.sale.grand_total <= self.sale.amount_received && self.sale.amount_changed > 0)
self.sale.payment_status = "paid"
self.sale.sale_status = "completed"
self.sale.save!