This commit is contained in:
Nweni
2017-06-20 18:59:34 +06:30
parent bdb42daad7
commit a9e1d8c3d1
20 changed files with 970 additions and 149 deletions

View File

@@ -1,5 +1,5 @@
class BookingOrder < ApplicationRecord
#primary key - need to be unique
#primary key - need to be unique
belongs_to :booking
belongs_to :order

View File

@@ -11,7 +11,7 @@ class Order < ApplicationRecord
#internal references attributes for business logic control
attr_accessor :items, :guest, :table_id, :new_booking, :booking_type, :employee_name, :booking_id
scope :active, -> { where("date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") }
#Main Controller method to create new order - validate all inputs and generate new order
# order_item : {
# order_item_code : "",

View File

@@ -1,4 +1,4 @@
class Room < DiningFacility
# has_many :bookings, :foreign_key => 'dining_facility_id'
has_many :bookings, :foreign_key => 'dining_facility_id'
end

View File

@@ -15,6 +15,7 @@ class Sale < ApplicationRecord
has_many :bookings
scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") }
scope :complete_sale, -> { where("sale_status = 'completed' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") }
def generate_invoice_from_booking(booking_id, requested_by)
booking = Booking.find(booking_id)
@@ -23,7 +24,7 @@ class Sale < ApplicationRecord
if (booking)
Rails.logger.debug "Booking -> Booking Order Count -> " + booking.booking_orders.count.to_s
#get all order attached to this booking and combine into 1 invoice
booking.booking_orders.each do |order|
if booking.sale_id
status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by)
@@ -281,15 +282,15 @@ class Sale < ApplicationRecord
end
end
def self.daily_sales_list(from,to)
def self.daily_sales_list(from,to)
payments_total = Sale.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount,
SUM(case when (sale_payments.payment_method='master') then sale_payments.payment_amount else 0 end) as master_amount,
SUM(case when (sale_payments.payment_method='visa') then sale_payments.payment_amount else 0 end) as visa_amount,
SUM(case when (sale_payments.payment_method='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount,
SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_amount,
SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='credit') then sale_payments.payment_amount else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount,
SUM(case when (sale_payments.payment_method='master') then sale_payments.payment_amount else 0 end) as master_amount,
SUM(case when (sale_payments.payment_method='visa') then sale_payments.payment_amount else 0 end) as visa_amount,
SUM(case when (sale_payments.payment_method='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount,
SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_amount,
SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='credit') then sale_payments.payment_amount else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
.joins("join (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0", 'completed', from, to)
@@ -304,27 +305,27 @@ class Sale < ApplicationRecord
from_date = sale_date.beginning_of_day.utc - diff
to_date = sale_date.end_of_day.utc - diff
total_sale = Sale.select("IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total,
IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount,
IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount,
total_sale = Sale.select("IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total,
IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount,
IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount,
IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj")
.where("(sale_status = ? OR sale_status = ?) AND receipt_date between ? and ? AND total_amount != 0", 'completed', 'void', from_date, to_date)
total_sale.each do |sale|
grand_total = sale.grand_total
total_discount = sale.total_discount
void_amount = sale.void_amount
total = {:sale_date => pay.sale_date,
void_amount = sale.void_amount
total = {:sale_date => pay.sale_date,
:mpu_amount => pay.mpu_amount,
:master_amount => pay.master_amount,
:visa_amount => pay.visa_amount,
:jcb_amount => pay.jcb_amount,
:paypar_amount => pay.paypar_amount,
:cash_amount => pay.cash_amount,
:credit_amount => pay.credit_amount,
:cash_amount => pay.cash_amount,
:credit_amount => pay.credit_amount,
:foc_amount => pay.foc_amount,
:total_discount => total_discount,
:grand_total => grand_total,
:total_discount => total_discount,
:grand_total => grand_total,
:void_amount => void_amount,
:rounding_adj => sale.rounding_adj}
daily_total.push(total)

View File

@@ -67,7 +67,7 @@ class SalePayment < ApplicationRecord
end
def self.get_paypar_account(url,token,membership_id,campaign_type_id,merchant_uid,auth_token)
# Control for Paypar Cloud
# Control for Paypar Cloud
begin
response = HTTParty.get(url,
:body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
@@ -91,14 +91,14 @@ class SalePayment < ApplicationRecord
campaign_type_id = membership_actions_data.additional_parameter["campaign_type_id"]
sale_data = Sale.find_by_sale_id(sale_id)
if sale_data
# Control for Paypar Cloud
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
},
},
:timeout => 10
)
rescue Net::OpenTimeout
@@ -238,10 +238,17 @@ class SalePayment < ApplicationRecord
end
def table_update_status(sale_obj)
booking = Booking.find_by_sale_id(sale_obj.id)
status = true
booking = Booking.find_by_sale_id(sale_obj.id)
if booking
table = DiningFacility.find(booking.dining_facility_id)
if table
bookings = table.bookings
bookings.each do |tablebooking|
if tablebooking.sale.sale_status != 'completed'
status = false
end
end
if status
table.status = "available"
table.save
end
@@ -274,7 +281,7 @@ class SalePayment < ApplicationRecord
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
# Control for Paypar Cloud
# Control for Paypar Cloud
begin
response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id,
receipt_no: receipt_no,auth_token:auth_token}.to_json,

View File

@@ -1,4 +1,4 @@
class Table < DiningFacility
has_many :dining_ins
# has_many :bookings, :foreign_key => 'dining_facility_id'
has_many :bookings, :foreign_key => 'dining_facility_id'
end

View File

@@ -1,3 +1,2 @@
class TableBooking < Booking
belongs_to :sale
end