merge with origin master

This commit is contained in:
Yan
2017-06-29 14:08:20 +06:30
25 changed files with 369 additions and 29 deletions

View File

@@ -1,6 +1,7 @@
class Employee < ApplicationRecord
has_secure_password
has_many :shit_sales
validates_presence_of :name, :role
validates_presence_of :password, :on => [:create]
validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true

View File

@@ -1,2 +1,22 @@
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
end

View File

@@ -39,8 +39,8 @@ class SaleItem < ApplicationRecord
# Check for actual sale items
sale_items.each do |si|
if si.account_id == a.id
account_price[:price] = account_price[:price] + si.price
end
account_price[:price] = account_price[:price] + si.price
end
end
price_accounts.push(account_price)
end
@@ -57,8 +57,8 @@ class SaleItem < ApplicationRecord
# Check for actual sale items
sale_items.where("is_taxable = false AND remark = 'Discount'").find_each do |si|
if si.account_id == a.id
discount_account[:price] = (discount_account[:price] + si.price) * -1
end
discount_account[:price] = (discount_account[:price] + si.price) * -1
end
end
discount_accounts.push(discount_account)
end

View File

@@ -247,12 +247,14 @@ class SalePayment < ApplicationRecord
end
self.sale.sale_status = "completed"
self.sale.save!
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
if shift
shift.update(self.sale)
end
table_update_status(sObj)
rebat(sObj)
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
puts shift
if !shift.nil?
puts ">>>> shift >>>>>>"
shift.update(self.sale)
end
end
end

View File

@@ -14,13 +14,14 @@
class ShiftSale < ApplicationRecord
belongs_to :cashier_terminal
belongs_to :employee
belongs_to :employee, :foreign_key => 'employee_id'
def self.current_open_shift(current_user)
#if current_user
#find open shift where is open today and is not closed and login by current cashier
today_date = DateTime.now.strftime("%Y-%m-%d")
shift = ShiftSale.where("TO_CHAR(shift_started_at, 'YYYY-MM-DD')=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user.id}",today_date).take
puts today_date
shift = ShiftSale.where("TO_CHAR(shift_started_at, 'YYYY-MM-DD')=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}",today_date).take
return shift
#end
@@ -35,7 +36,7 @@ class ShiftSale < ApplicationRecord
end
def update(sale)
saleobj = Sale.find(sale)
saleobj = Sale.find_by_sale_id(sale)
self.total_revenue = self.total_revenue + saleobj.total_amount
self.total_discounts = self.total_discounts + saleobj.total_discount
self.total_taxes = self.total_taxes + saleobj.total_tax