merge with origin master
This commit is contained in:
@@ -31,6 +31,12 @@ class Customer < ApplicationRecord
|
||||
)
|
||||
rescue Net::OpenTimeout
|
||||
response = { status: false }
|
||||
|
||||
rescue OpenURI::HTTPError
|
||||
response = { status: false}
|
||||
|
||||
rescue SocketError
|
||||
response = { status: false}
|
||||
end
|
||||
|
||||
return response;
|
||||
@@ -55,6 +61,12 @@ class Customer < ApplicationRecord
|
||||
)
|
||||
rescue Net::OpenTimeout
|
||||
response = { status: false }
|
||||
|
||||
rescue OpenURI::HTTPError
|
||||
response = { status: false}
|
||||
|
||||
rescue SocketError
|
||||
response = { status: false}
|
||||
end
|
||||
|
||||
return response;
|
||||
|
||||
@@ -38,6 +38,7 @@ class Order < ApplicationRecord
|
||||
booking.save!
|
||||
self.default_values
|
||||
|
||||
# cashier already opened?
|
||||
if self.save!
|
||||
|
||||
self.adding_line_items
|
||||
|
||||
@@ -19,4 +19,25 @@ class PaymentJournal < ApplicationRecord
|
||||
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
|
||||
|
||||
@@ -25,7 +25,7 @@ class Sale < ApplicationRecord
|
||||
SALE_STATUS_OUTSTANDING = "outstanding"
|
||||
SALE_STATUS_COMPLETED = "completed"
|
||||
|
||||
def generate_invoice_from_booking(booking_id, requested_by, cashier)
|
||||
def generate_invoice_from_booking(booking_id, requested_by, cashier)
|
||||
booking = Booking.find(booking_id)
|
||||
status = false
|
||||
Rails.logger.debug "Booking -> " + booking.id.to_s
|
||||
@@ -66,7 +66,7 @@ class Sale < ApplicationRecord
|
||||
#Default Tax - Values
|
||||
self.tax_type = "exclusive"
|
||||
|
||||
# set cashier
|
||||
# set cashier
|
||||
if cashier != nil
|
||||
self.cashier_id = cashier[0].id
|
||||
self.cashier_name = cashier[0].name
|
||||
@@ -270,8 +270,6 @@ class Sale < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def product_get_unit_price(item_code)
|
||||
menu_item_hash =MenuItem.search_by_item_code(item_code)
|
||||
if (menu_instance_code)
|
||||
@@ -444,10 +442,51 @@ def self.get_by_range_by_saleitems(from,to,status,report_type)
|
||||
|
||||
end
|
||||
|
||||
|
||||
def self.get_by_shiftsales(from,to)
|
||||
return ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to)
|
||||
end
|
||||
|
||||
def get_cash_amount
|
||||
cash = 0.0
|
||||
self.sale_payments.each do |pay|
|
||||
if pay.payment_method == 'cash'
|
||||
cash = pay.payment_amount
|
||||
end
|
||||
end
|
||||
return cash
|
||||
end
|
||||
|
||||
def get_credit_amount
|
||||
credit = 0.0
|
||||
self.sale_payments.each do |pay|
|
||||
if pay.payment_method == 'creditnote'
|
||||
credit = pay.payment_amount
|
||||
end
|
||||
end
|
||||
return credit
|
||||
end
|
||||
|
||||
def get_other_amount
|
||||
other = 0.0
|
||||
self.sale_payments.each do |pay|
|
||||
if pay.payment_method != 'cash' && pay.payment_method != 'creditnote'
|
||||
other += pay.payment_amount
|
||||
end
|
||||
end
|
||||
return other
|
||||
end
|
||||
|
||||
def get_commerical_tax
|
||||
tax = 0.0
|
||||
self.sale_taxes.each do |tax|
|
||||
if tax.tax_name == "Commerical Tax"
|
||||
tax += tax.tax_payable_amount
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def generate_custom_id
|
||||
|
||||
@@ -77,6 +77,12 @@ class SalePayment < ApplicationRecord
|
||||
)
|
||||
rescue Net::OpenTimeout
|
||||
response = { status: false }
|
||||
|
||||
rescue OpenURI::HTTPError
|
||||
response = { status: false}
|
||||
|
||||
rescue SocketError
|
||||
response = { status: false}
|
||||
end
|
||||
return response;
|
||||
end
|
||||
@@ -110,6 +116,12 @@ class SalePayment < ApplicationRecord
|
||||
)
|
||||
rescue Net::OpenTimeout
|
||||
response = false
|
||||
|
||||
rescue OpenURI::HTTPError
|
||||
response = { status: false}
|
||||
|
||||
rescue SocketError
|
||||
response = { status: false}
|
||||
end
|
||||
else
|
||||
response = false;
|
||||
@@ -131,7 +143,6 @@ class SalePayment < ApplicationRecord
|
||||
self.payment_status = "paid"
|
||||
payment_method = self.save!
|
||||
sale_update_payment_status(self.received_amount)
|
||||
|
||||
return payment_status
|
||||
end
|
||||
|
||||
@@ -146,7 +157,6 @@ class SalePayment < ApplicationRecord
|
||||
payment_method = self.save!
|
||||
|
||||
sale_update_payment_status(self.received_amount)
|
||||
|
||||
return payment_status
|
||||
end
|
||||
|
||||
@@ -161,7 +171,6 @@ class SalePayment < ApplicationRecord
|
||||
payment_method = self.save!
|
||||
|
||||
sale_update_payment_status(self.received_amount)
|
||||
|
||||
return payment_status
|
||||
end
|
||||
|
||||
@@ -175,7 +184,6 @@ class SalePayment < ApplicationRecord
|
||||
self.outstanding_amount = self.sale.grand_total- self.received_amount
|
||||
self.payment_status = "paid"
|
||||
payment_method = self.save!
|
||||
|
||||
sale_update_payment_status(self.received_amount)
|
||||
|
||||
return payment_status
|
||||
@@ -192,7 +200,6 @@ class SalePayment < ApplicationRecord
|
||||
self.outstanding_amount = self.sale.grand_total- self.received_amount
|
||||
self.payment_status = "paid"
|
||||
payment_method = self.save!
|
||||
|
||||
sale_update_payment_status(self.received_amount)
|
||||
|
||||
return payment_status
|
||||
@@ -220,7 +227,6 @@ class SalePayment < ApplicationRecord
|
||||
else
|
||||
sale_update_payment_status(0)
|
||||
end
|
||||
|
||||
return payment_status
|
||||
|
||||
end
|
||||
@@ -249,16 +255,20 @@ class SalePayment < ApplicationRecord
|
||||
self.sale.save!
|
||||
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)
|
||||
if paid_amount != "0.0"
|
||||
update_shift
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def update_shift
|
||||
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
|
||||
if !shift.nil?
|
||||
shift.update(self.sale)
|
||||
end
|
||||
end
|
||||
|
||||
def table_update_status(sale_obj)
|
||||
status = true
|
||||
booking = Booking.find_by_sale_id(sale_obj.id)
|
||||
@@ -314,6 +324,12 @@ class SalePayment < ApplicationRecord
|
||||
}, :timeout => 10)
|
||||
rescue Net::OpenTimeout
|
||||
response = { status: false }
|
||||
|
||||
rescue OpenURI::HTTPError
|
||||
response = { status: false}
|
||||
|
||||
rescue SocketError
|
||||
response = { status: false}
|
||||
end
|
||||
return response
|
||||
# puts response.to_json
|
||||
@@ -321,6 +337,8 @@ class SalePayment < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
private
|
||||
def generate_custom_id
|
||||
self.sale_payment_id = SeedGenerator.generate_id(self.class.name, "SPI")
|
||||
|
||||
@@ -21,7 +21,7 @@ class ShiftSale < ApplicationRecord
|
||||
#find open shift where is open today and is not closed and login by current cashier
|
||||
today_date = DateTime.now.strftime("%Y-%m-%d")
|
||||
puts today_date
|
||||
shift = ShiftSale.where("DATE(shift_started_at)= #{ today_date } and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take
|
||||
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
|
||||
@@ -37,16 +37,26 @@ class ShiftSale < ApplicationRecord
|
||||
|
||||
def update(sale)
|
||||
saleobj = Sale.find_by_sale_id(sale)
|
||||
self.total_revenue = self.total_revenue + saleobj.total_amount
|
||||
cash = saleobj.get_cash_amount
|
||||
credit = saleobj.get_credit_amount
|
||||
other_sales = saleobj.get_other_amount
|
||||
tax = saleobj.get_commerical_tax
|
||||
self.total_revenue = self.total_revenue.to_f + saleobj.total_amount.to_f
|
||||
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.cash_sales = self.cash_sales.to_f + cash.to_f
|
||||
self.credit_sales = self.credit_sales.to_i + credit.to_f
|
||||
self.other_sales = self.other_sales.to_i + other_sales.to_f
|
||||
self.nett_sales = self.grand_total.to_i - self.commercial_taxes
|
||||
self.commercial_taxes = self.commercial_taxes.to_i + tax.to_f
|
||||
self.save
|
||||
|
||||
end
|
||||
|
||||
def get_closing_balance(shift)
|
||||
shiftobj = ShiftSale.find(shift)
|
||||
closing_balance = shiftobj.grand_total + shiftobj.cash_in - shiftobj.cash_out + shiftobj.total_cash
|
||||
return closing_balance
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user