updated for api bill controller

This commit is contained in:
Yan
2017-06-28 16:56:43 +06:30
54 changed files with 1066 additions and 163 deletions

View File

@@ -6,6 +6,10 @@ class Employee < ApplicationRecord
validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true
validates :password, numericality: true, length: {in: 3..9}, allow_blank: true
def self.all_emp_except_waiter
Employee.where('role!=?','waiter')
end
def self.collection
Employee.select("id, name").map { |e| [e.name, e.id] }
end

View File

@@ -0,0 +1,2 @@
class PaymentJournal < ApplicationRecord
end

View File

@@ -270,7 +270,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

51
app/models/shift_sale.rb Normal file
View File

@@ -0,0 +1,51 @@
#Description
#total_revenue = sum of all sub-total from sales table
#total_discounts = sum of all discount (overall) from sales tables
#total_taxes = sum of all taxes from sales table (Service + Goverment Tax (commercial_taxes))
#grand_total = total_revenue - total_discounts + total_taxes
#nett_sales = grand_total - commercial_taxes
#cash_sales = cash payment total revenue
#credit_sales = credit payment total revenue
#others_sales = [Sum of each of other payment type --- mpu, jcb, visa,master, rebate, vochure]
#commercial_taxes = Total Goverment tax due
#cash_in = Payment receive
#Cash_out = Payment issues for misc payments
class ShiftSale < ApplicationRecord
belongs_to :cashier_terminal
belongs_to :employee
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
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