route changes

This commit is contained in:
San Wai Lwin
2018-03-13 14:51:07 +06:30
parent 694feb9c06
commit 9228168ebc
49 changed files with 1906 additions and 707 deletions

View File

@@ -65,7 +65,8 @@ class Ability
can :create, :payment
can :reprint, :payment
can :rounding_adj, :payment
can :foc, :payment
can :foc, :payment
can :print, :payment
can :move_dining, :movetable
can :moving, :movetable
@@ -111,10 +112,10 @@ class Ability
can :index, :other_charge
can :create, :other_charge
# can :index, :discount
# can :create, :discount
# can :remove_discount_items, :discount
# can :remove_all_discount, :discount
can :index, :discount
can :create, :discount
can :remove_discount_items, :discount
can :remove_all_discount, :discount
can :member_discount, :discount
can :first_bill, :payment
@@ -122,6 +123,7 @@ class Ability
can :create, :payment
can :reprint, :payment
can :rounding_adj, :payment
can :print, :payment
can :move_dining, :movetable
can :moving, :movetable
@@ -180,6 +182,7 @@ class Ability
can :show, :payment
can :reprint, :payment
can :rounding_adj, :payment
can :print, :payment
can :manage, Commission
can :manage, Commissioner
@@ -191,6 +194,26 @@ class Ability
elsif user.role == "waiter"
can :index, :home
can :show, :home
can :manage, Customer
can :get_customer, Customer
can :add_customer, Customer
can :update_sale_by_customer, Customer
can :index, :other_charge
can :create, :other_charge
can :index, :discount
can :create, :discount
can :remove_discount_items, :discount
can :remove_all_discount, :discount
can :member_discount, :discount
#ability for move table
can :move_dining, :movetable
can :moving, :movetable
can :move_dining, :moveroom
#ability for split_bill
can :index, :split_bill
can :create, :split_bill

View File

@@ -286,23 +286,51 @@ class Order < ApplicationRecord
#Process order items and send to order queue
def process_order_queue
#Send to background job for processing
cup_status = `#{"sudo service cups status"}`
order = Order.find(self.id)
cup_status = `#{"sudo service cups status"}`
print_status = check_cup_status(cup_status)
sidekiq = Lookup.find_by_lookup_type("sidekiq")
if print_status
OrderQueueProcessorJob.perform_later(self.id, self.table_id)
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(self.id, self.table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, self.table_id)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
else
cup_start = `#{"sudo service cups start"}`
cup_status = `#{"sudo service cups status"}`
print_status = check_cup_status(cup_status)
if print_status
OrderQueueProcessorJob.perform_later(self.id, self.table_id)
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(self.id, self.table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, self.table_id)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
else
msg = ' Print Error ! Please contact to service'
ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error'
OrderQueueProcessorJob.perform_later(self.id, self.table_id)
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(self.id, self.table_id)
else
if order
oqs = OrderQueueStation.new
oqs.process_order(order, self.table_id)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
end
end
@@ -310,8 +338,18 @@ class Order < ApplicationRecord
#Process order items and send to order queue
def self.pay_process_order_queue(id,table_id)
#Send to background job for processing
OrderQueueProcessorJob.perform_later(id, table_id)
sidekiq = Lookup.find_by_lookup_type("sidekiq")
if !sidekiq.nil?
OrderQueueProcessorJob.perform_later(id, table_id)
else
order = Order.find(id)
if order
oqs = OrderQueueStation.new
oqs.process_order(order, table_id)
end
assign_order = AssignedOrderItem.assigned_order_item_by_job(id)
ActionCable.server.broadcast "order_queue_station_channel",order: assign_order
end
end
def check_cup_status(status)

View File

@@ -197,17 +197,28 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
print_settings.print_copies = 1
print_settings.save!
directory_name = 'public/receipts'
Dir.mkdir(directory_name) unless File.exists?(directory_name)
begin
if count == 1
pdf.render_file "tmp/receipt_bill_#{sale_data.receipt_no}.pdf"
self.print("tmp/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name)
filename = "/receipts/receipt_bill_#{sale_data.receipt_no}.pdf"
pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf"
if printed_status != 'Paid'
self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name)
end
else
pdf.render_file "tmp/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
self.print("tmp/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf", cashier_terminal.printer_name)
filename = "/receipts/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
if printed_status != 'Paid'
self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf", cashier_terminal.printer_name)
end
end
count -= 1
end until count == 0
return filename, sale_data.receipt_no, cashier_terminal.printer_name
end
# stock check
@@ -247,4 +258,23 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
self.print("tmp/print_call_waiter.pdf")
end
#print receipt pdf from js
def print_receipt_pdf(filename,receipt_no,print_copies,printer_name)
count = print_copies.to_i
# if count == 0
# self.print("public"+filename, printer_name)
# else
begin
if count == 1
self.print("public"+filename, printer_name)
else
filename = "public/receipts/receipt_bill_#{receipt_no}_#{count}.pdf"
self.print(filename, printer_name)
end
count -= 1
end until count == 0
# end
end
end

2
app/models/receipt.rb Normal file
View File

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

View File

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

View File

@@ -548,11 +548,22 @@ class Sale < ApplicationRecord
#Generate new Receipt No when it is not assigned
def generate_receipt_no
#shop_code and client_code
shop_details = Shop::ShopDetail
#Date-Shift-
if self.receipt_no.nil?
prefix = DateTime.now().utc
#self.receipt_no = prefix.to_s + "/" + self.shit_id.to_s + "/" + SeedGenerator.new_receipt_no().to_s
self.receipt_no = prefix.strftime("%Y%m%d") + "-" + SeedGenerator.new_receipt_no().to_s
if !shop_details.nil?
if !shop_details.shop_code.nil?
self.receipt_no = shop_details.shop_code + "-" + prefix.strftime("%Y%m%d") + "-" + SeedGenerator.new_receipt_no().to_s
else
self.receipt_no = prefix.strftime("%Y%m%d") + "-" + SeedGenerator.new_receipt_no().to_s
end
else
self.receipt_no = prefix.strftime("%Y%m%d") + "-" + SeedGenerator.new_receipt_no().to_s
end
self.receipt_date = prefix
Rails.logger.debug "Receipt No #{self.receipt_no} | Date #{ self.receipt_date.to_s}"
@@ -1170,7 +1181,7 @@ end
if current_user.nil?
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total")
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total")
else
shift = ShiftSale.current_open_shift(current_user.id)
@@ -1184,7 +1195,7 @@ end
if current_user.nil?
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total")
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total")
else
shift = ShiftSale.current_open_shift(current_user.id)
@@ -1202,7 +1213,7 @@ end
if current_user.nil?
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count
else
shift = ShiftSale.current_open_shift(current_user.id)
@@ -1215,7 +1226,7 @@ end
if current_user.nil?
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count
else
shift = ShiftSale.current_open_shift(current_user.id)
@@ -1234,7 +1245,7 @@ end
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount")
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount")
@@ -1253,7 +1264,7 @@ end
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount")
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today)
.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
.sum("sp.payment_amount")
@@ -1276,7 +1287,7 @@ end
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount")
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ?',from,to)
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount")
@@ -1295,7 +1306,7 @@ end
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount")
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today)
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
.sum("payment_amount")
@@ -1318,7 +1329,7 @@ end
.where('sale_status = "completed" and receipt_date between ? and ?',from,to)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
.where('sale_status = "completed" and receipt_date between ? and ?',from,to)
.first()
@@ -1337,7 +1348,7 @@ end
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax')
.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today)
.first()
@@ -1360,7 +1371,7 @@ end
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("distinct sp.payment_method")
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
@@ -1379,7 +1390,7 @@ end
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("distinct sp.payment_method")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
@@ -1406,7 +1417,7 @@ end
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if payment_method == 'card'
query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
@@ -1437,7 +1448,7 @@ end
end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
if payment_method == 'card'
query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today)
@@ -1482,7 +1493,7 @@ end
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to)
@@ -1504,7 +1515,7 @@ end
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(sales.customer_id) as total_dinein_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today)
@@ -1530,7 +1541,7 @@ end
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(sales.customer_id) as total_take_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to)
@@ -1552,7 +1563,7 @@ end
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(sales.customer_id) as total_take_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today)
@@ -1578,7 +1589,7 @@ end
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to)
@@ -1600,7 +1611,7 @@ end
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(distinct sales.customer_id) as total_memb_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today)
@@ -1626,7 +1637,7 @@ end
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(sales.customer_id) as total_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to)
@@ -1648,7 +1659,7 @@ end
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(sales.customer_id) as total_cus")
.joins("JOIN customers as c ON c.customer_id = sales.customer_id")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today)
@@ -1675,7 +1686,7 @@ end
.where('b.status = "billed" and sales.receipt_date between ? and ?',from,to)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(distinct a.order_id) as total_order")
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
.joins("JOIN orders as b ON b.order_id = a.order_id")
@@ -1700,7 +1711,7 @@ end
.where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(distinct a.order_id) as total_order")
.joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id")
.joins("JOIN orders as b ON b.order_id = a.order_id")
@@ -1728,7 +1739,7 @@ end
.joins("JOIN accounts as b ON b.id = a.account_id")
.where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to)
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("distinct b.id as account_id, b.title as title")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.joins("JOIN accounts as b ON b.id = a.account_id")
@@ -1750,7 +1761,7 @@ end
.joins("JOIN accounts as b ON b.id = a.account_id")
.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today)
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("distinct b.id as account_id, b.title as title")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.joins("JOIN accounts as b ON b.id = a.account_id")
@@ -1776,7 +1787,7 @@ end
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to)
@@ -1798,7 +1809,7 @@ end
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
@@ -1826,7 +1837,7 @@ end
.order("SUM(a.qty) DESC")
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ?",from,to)
@@ -1854,7 +1865,7 @@ end
.order("SUM(a.qty) DESC")
.first()
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price")
.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
@@ -1883,7 +1894,7 @@ end
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ?",from,to)
.sum("a.qty")
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ?",from,to)
.sum("a.qty")
@@ -1902,7 +1913,7 @@ end
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
.sum("a.qty")
else
if current_user.role == 'administrator'
if current_user.role == 'administrator' || current_user.role == 'manager'
query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id")
.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today)
.sum("a.qty")
@@ -2011,6 +2022,44 @@ end
.group("bookings.booking_id")
end
def self.all_receipts
query = Sale.select("sales.*, sale_payments.created_at as receipt_close_time,
case when (sale_audits.action='SALEPAYMENT') then sale_audits.remark else 0 end as remark,
case when (sale_taxes.tax_name='Service Charges') then sale_taxes.tax_payable_amount else 0 end as service_charges,
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='unionpay') then sale_payments.payment_amount else 0 end) as unionpay_amount,
SUM(case when (sale_payments.payment_method='creditnote') 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,
SUM(case when (sale_items.status='foc') then sale_items.price else 0 end) as item_foc,
SUM(case when (sale_items.status='Discount') then sale_items.price else 0 end) as item_discount,
SUM(sale_items.qty) as qty,
sales.cashier_name as cashier_name,
surveys.child as child,
surveys.adult as adult")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.joins("join sale_taxes on sale_taxes.sale_id = sales.sale_id")
.joins("join sale_items on sale_items.sale_id = sales.sale_id")
.joins("join sale_audits on sale_audits.sale_id = sales.sale_id")
.joins("left join surveys on surveys.receipt_no = sales.receipt_no")
query = query.where("sale_status != 'new' && sale_payments.payment_amount > 0")
.group("sale_id")
return query
end
def self.all_receipt_details
query = SaleItem.select("sale_items.*, sale_payments.created_at as receipt_close_time,
sales.requested_at as requested_at, sales.receipt_no as receipt_no,sales.sale_id as s_id")
.joins("join sale_payments on sale_payments.sale_id = sale_items.sale_id")
.joins("join sales on sales.sale_id = sale_items.sale_id")
.group("sale_items.sale_item_id")
query = query.where("qty > 0 and sales.sale_status !='new'")
return query
end
private
def generate_custom_id

View File

@@ -356,10 +356,10 @@ class SalePayment < ApplicationRecord
self.sale.save!
table_update_status(sObj)
if check_foc
update_shift
elsif paid_amount != "0.0"
elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
update_shift
end
end