Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant into crm
This commit is contained in:
@@ -4,30 +4,67 @@ class Ability
|
||||
def initialize(user)
|
||||
user ||= Employee.new
|
||||
|
||||
if user.role? :administrator
|
||||
if user.role == "administrator"
|
||||
|
||||
can :manage, :all
|
||||
|
||||
elsif user.role? :cashier
|
||||
can :read, Order
|
||||
can :update, Order
|
||||
can :completed_order_item, Order
|
||||
elsif user.role == "manager"
|
||||
|
||||
can :manage, Menu
|
||||
can :manage, MenuCategory
|
||||
can :manage, MenuItemAttribute
|
||||
can :manage, MenuItemInstance
|
||||
can :manage, MenuItemOption
|
||||
can :manage, SetMenuItem
|
||||
can :manage, OrderQueueStation
|
||||
can :manage, Zone
|
||||
can :manage, CashierTerminal
|
||||
can :manage, Employee
|
||||
can :manage, MembershipSetting
|
||||
can :manage, MembershipAction
|
||||
can :manage, PaymentMethodSetting
|
||||
can :manage, TaxProfile
|
||||
can :manage, PrintSetting
|
||||
can :manage, Account
|
||||
|
||||
can :manage, Order
|
||||
can :manage, Sale
|
||||
|
||||
can :index, :dailysale
|
||||
can :index, :saleitem
|
||||
|
||||
elsif user.role == "cashier"
|
||||
|
||||
can :read, Order
|
||||
can :update, Order
|
||||
|
||||
can :read, Sale
|
||||
can :update, Sale
|
||||
can :read, Sale
|
||||
can :update, Sale
|
||||
|
||||
can :add_customer, Customer
|
||||
can :update_sale_by_customer, Customer
|
||||
|
||||
can :index, :discount
|
||||
can :create, :discount
|
||||
|
||||
can :show, :payment
|
||||
can :create, :payment
|
||||
can :reprint, :payment
|
||||
|
||||
can :move_dining, :movetable
|
||||
can :moving, :movetable
|
||||
|
||||
can :move_dining, :moveroom
|
||||
|
||||
elsif user.role? :accountant
|
||||
elsif user.role == "accountant"
|
||||
|
||||
can :read, Order
|
||||
can :update, Order
|
||||
can :completed_order_item, Order
|
||||
|
||||
can :read, Sale
|
||||
can :update, Sale
|
||||
can :manual_complete_sale, Sale
|
||||
can :index, :dailysale
|
||||
can :index, :saleitem
|
||||
can :index, :receiptno
|
||||
can :show, :dailysale
|
||||
can :show, :saleitem
|
||||
can :show, :receiptno
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,7 +27,7 @@ class Order < ApplicationRecord
|
||||
if self.new_booking
|
||||
|
||||
booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking",
|
||||
:checkin_at => Time.now.utc, :checkin_by => self.employee_name,
|
||||
:checkin_at => Time.now.utc.getlocal, :checkin_by => self.employee_name,
|
||||
:booking_status => "assign" })
|
||||
table = DiningFacility.find(self.table_id)
|
||||
table.status = "occupied"
|
||||
|
||||
@@ -22,7 +22,8 @@ class OrderQueueStation < ApplicationRecord
|
||||
|
||||
#Assign OQS id to order Items
|
||||
oqs_stations.each do |oqs|
|
||||
is_auto_printed = false
|
||||
is_auto_printed = false
|
||||
oqs_order_items = []
|
||||
#Get List of items -
|
||||
pq_items = JSON.parse(oqs.processing_items)
|
||||
|
||||
@@ -37,15 +38,16 @@ class OrderQueueStation < ApplicationRecord
|
||||
# else
|
||||
|
||||
AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs)
|
||||
# end
|
||||
|
||||
# Auto Printing
|
||||
if oqs.auto_print && is_auto_printed == false
|
||||
print_slip(oqs, order, order_items)
|
||||
is_auto_printed = true
|
||||
end
|
||||
oqs_order_items.push(order_item)
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
# Auto Printing
|
||||
# ToDo per item per printer
|
||||
if oqs.auto_print && is_auto_printed == false
|
||||
print_slip(oqs, order, oqs_order_items)
|
||||
is_auto_printed = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -103,7 +103,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
# Query for OQS with status
|
||||
def print_query(type, id)
|
||||
if type == "order_item"
|
||||
OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining")
|
||||
OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.type, df.name as dining")
|
||||
.joins("left join orders ON orders.order_id = order_items.order_id
|
||||
left join booking_orders AS bo ON bo.order_id=order_items.order_id
|
||||
left join bookings AS b ON b.booking_id = bo.booking_id
|
||||
@@ -112,7 +112,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
.where("order_items.item_code = '#{ id }'")
|
||||
.group("order_items.item_code")
|
||||
elsif type == "order_summary"
|
||||
OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining")
|
||||
OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.type, df.name as dining")
|
||||
.joins("left join orders ON orders.order_id = order_items.order_id
|
||||
left join booking_orders AS bo ON bo.order_id=order_items.order_id
|
||||
left join bookings AS b ON b.booking_id = bo.booking_id
|
||||
@@ -122,7 +122,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
|
||||
.group("order_items.order_items_id")
|
||||
else
|
||||
# order summary for booking
|
||||
OrderItem.select("order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining")
|
||||
OrderItem.select("order_items.order_id, order_items.item_code, order_items.item_name, order_items.qty, order_items.price, order_items.options, order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.type, df.name as dining")
|
||||
.joins("left join orders ON orders.order_id = order_items.order_id
|
||||
left join booking_orders AS bo ON bo.order_id=order_items.order_id
|
||||
left join bookings AS b ON b.booking_id = bo.booking_id
|
||||
|
||||
@@ -21,9 +21,9 @@ class Sale < ApplicationRecord
|
||||
"daily" => 0,
|
||||
"monthly" => 1,
|
||||
"yearly" => 2
|
||||
}
|
||||
}
|
||||
|
||||
SALE_STATUS_COMPLETED = "completed"
|
||||
SALE_STATUS_COMPLETED = "completed"
|
||||
|
||||
def generate_invoice_from_booking(booking_id, requested_by)
|
||||
booking = Booking.find(booking_id)
|
||||
@@ -98,7 +98,7 @@ class Sale < ApplicationRecord
|
||||
order.save
|
||||
|
||||
booking.sale_id = self.id
|
||||
booking.checkout_at = Time.now.utc
|
||||
booking.checkout_at = Time.now.utc.getlocal
|
||||
booking.checkout_by = requested_by.name
|
||||
booking.save
|
||||
|
||||
@@ -115,7 +115,7 @@ class Sale < ApplicationRecord
|
||||
def generate_invoice_by_items (items, requested_by)
|
||||
taxable = true
|
||||
self.requested_by = requested_by
|
||||
self.requested_at = DateTime.now.utc
|
||||
self.requested_at = DateTime.now.utc.getlocal
|
||||
|
||||
items.each do |item|
|
||||
add_item(item)
|
||||
@@ -185,7 +185,7 @@ class Sale < ApplicationRecord
|
||||
sales_items.each do |item|
|
||||
#compute each item and added to total
|
||||
subtotal_price = subtotal_price + item.price
|
||||
total_taxable = total_taxable + item.taxable_price
|
||||
total_taxable = total_taxable + (item.taxable_price * item.qty)
|
||||
end
|
||||
|
||||
apply_tax (total_taxable)
|
||||
@@ -199,6 +199,31 @@ class Sale < ApplicationRecord
|
||||
|
||||
end
|
||||
|
||||
def compute_without_void
|
||||
sales_items = self.sale_items
|
||||
|
||||
#Computation Fields
|
||||
subtotal_price = 0
|
||||
total_taxable = 0
|
||||
rounding_adjustment = 0
|
||||
|
||||
sales_items.each do |item|
|
||||
if item.remark != 'void'
|
||||
#compute each item and added to total
|
||||
subtotal_price = subtotal_price + item.price
|
||||
total_taxable = total_taxable + item.taxable_price
|
||||
end
|
||||
end
|
||||
|
||||
apply_tax (total_taxable)
|
||||
self.total_amount = subtotal_price
|
||||
self.total_discount = total_discount
|
||||
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
||||
#compute rounding adjustment
|
||||
adjust_rounding
|
||||
|
||||
self.save!
|
||||
end
|
||||
# Tax Calculate
|
||||
def apply_tax(total_taxable)
|
||||
#if tax is not apply create new record
|
||||
@@ -354,28 +379,28 @@ def self.get_by_range_by_saleitems(from,to,status,report_type)
|
||||
mc.name as menu_category_name,
|
||||
mc.id as menu_category_id ")
|
||||
.group('mi.id')
|
||||
.order("mi.menu_category_id")
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
|
||||
JOIN menu_items mi ON i.product_code = mi.item_code" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id
|
||||
.order("mi.menu_category_id")
|
||||
|
||||
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id
|
||||
JOIN menu_items mi ON i.product_code = mi.item_code" +
|
||||
" JOIN menu_categories mc ON mc.id = mi.menu_category_id
|
||||
JOIN employees ea ON ea.id = sales.cashier_id")
|
||||
|
||||
|
||||
|
||||
query = query.where("receipt_date between ? and ? and sale_status=?",from,to,status)
|
||||
|
||||
|
||||
|
||||
|
||||
case report_type.to_i
|
||||
when REPORT_TYPE["daily"]
|
||||
return query
|
||||
when REPORT_TYPE["monthly"]
|
||||
|
||||
return query.group("MONTH(date)")
|
||||
|
||||
return query.group("MONTH(date)")
|
||||
when REPORT_TYPE["yearly"]
|
||||
return query.group("YEAR(date)")
|
||||
return query.group("YEAR(date)")
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -9,7 +9,6 @@ class SalePayment < ApplicationRecord
|
||||
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status
|
||||
|
||||
def process_payment(invoice, action_by, cash_amount, payment_method)
|
||||
|
||||
self.sale = invoice
|
||||
self.received_amount = cash_amount
|
||||
amount_due = invoice.grand_total
|
||||
@@ -28,7 +27,7 @@ class SalePayment < ApplicationRecord
|
||||
when "cash"
|
||||
payment_status = cash_payment
|
||||
when "creditnote"
|
||||
if !self.customer_id.nil?
|
||||
if !self.sale.customer_id.nil?
|
||||
payment_status = creditnote_payment(self.customer_id)
|
||||
end
|
||||
when "visa"
|
||||
@@ -54,7 +53,7 @@ class SalePayment < ApplicationRecord
|
||||
#record an payment in sale-audit
|
||||
remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}"
|
||||
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
|
||||
|
||||
|
||||
return true, self.save
|
||||
else
|
||||
#record an payment in sale-audit
|
||||
@@ -94,10 +93,15 @@ class SalePayment < ApplicationRecord
|
||||
sale_data = Sale.find_by_sale_id(sale_id)
|
||||
|
||||
if sale_data
|
||||
others = 0
|
||||
sale_data.sale_payments.each do |sale_payment|
|
||||
others = others + sale_payment.payment_amount
|
||||
end
|
||||
redeem_prices = sale_data.grand_total -others
|
||||
# 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,
|
||||
:body => { generic_customer_id:membership_id,total_amount: redeem_prices,total_sale_transaction_amount: sale_data.grand_total,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'
|
||||
@@ -137,7 +141,7 @@ class SalePayment < ApplicationRecord
|
||||
self.payment_method = "creditnote"
|
||||
self.payment_amount = self.received_amount
|
||||
self.customer_id = self.customer_id
|
||||
self.outstanding_amount = 0 - self.received_amount
|
||||
self.outstanding_amount = 0 - self.received_amount.to_f
|
||||
self.payment_status = "outstanding"
|
||||
payment_method = self.save!
|
||||
|
||||
@@ -202,10 +206,7 @@ class SalePayment < ApplicationRecord
|
||||
customer_data = Customer.find_by_customer_id(self.sale.customer_id)
|
||||
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
|
||||
membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id)
|
||||
puts 'mmmmmmmmmmmmmmmmmmmmmmmmmmm'
|
||||
puts membership_data.to_json
|
||||
puts "amountttttttttttttttttttttt"
|
||||
puts self.received_amount
|
||||
|
||||
if membership_data["status"]==true
|
||||
self.payment_method = "paypar"
|
||||
self.payment_amount = self.received_amount
|
||||
@@ -266,8 +267,7 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
def rebat(sObj)
|
||||
rebate_prices = SaleItem.calculate_rebate_by_account(sObj.sale_items)
|
||||
puts "eeeeeeeeeeeeeeeeeeeeeeee"
|
||||
puts rebate_prices
|
||||
|
||||
generic_customer_id = sObj.customer.membership_id
|
||||
if generic_customer_id != nil || generic_customer_id != "" || generic_customer_id != 0
|
||||
paypar = sObj.sale_payments
|
||||
@@ -292,7 +292,7 @@ class SalePayment < ApplicationRecord
|
||||
|
||||
# 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,
|
||||
response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,total_sale_transaction_amount: sObj.grand_total,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id,
|
||||
receipt_no: receipt_no,auth_token:auth_token}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
|
||||
Reference in New Issue
Block a user