This commit is contained in:
Nweni
2017-06-28 15:29:44 +06:30
parent 55278c83bc
commit 986655052a
9 changed files with 100 additions and 22 deletions

View File

@@ -263,7 +263,6 @@ class Sale < ApplicationRecord
end
private
def product_get_unit_price(item_code)

View File

@@ -247,6 +247,10 @@ 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)
end

View File

@@ -19,7 +19,33 @@ class ShiftSale < ApplicationRecord
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
@shift = ShiftSale.where("cast(shift_started_at as date) = #{DateTime.now.to_date} and shift_started_at is null and employee_id = #{current_user.id}").limit(1)
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
return shift
#end
end
def create(opening_balance,current_user)
self.cashier_terminal_id = CashierTerminal.first.id
self.shift_started_at = DateTime.now
self.employee_id = current_user.id
self.opening_balance = opening_balance
self.save
end
def update(sale)
saleobj = Sale.find(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
self.grand_total = self.grand_total + saleobj.grand_total
# self.nett_sales =
# self.cash_sales =
# self.credit_sales =
# self.other_sales =
# self.commercial_taxes =
self.save
end
end