Merge branch 'r-1902001-01' into foodcourt

This commit is contained in:
Thein Lin Kyaw
2020-09-10 10:31:07 +06:30
184 changed files with 2672 additions and 1021 deletions

View File

@@ -59,9 +59,9 @@ class Booking < ApplicationRecord
end
end
scope :active, -> {where("booking_status != 'moved'")}
scope :today, -> {where("created_at >= #{Time.now.utc}")}
scope :assign, -> { where(booking_status: 'assign')}
scope :active, -> { where('booking_status != ?', 'moved') }
scope :today, -> { where('created_at >= ?', Time.now) }
scope :assign, -> { where(booking_status: 'assign') }
def self.sync_booking_records(bookings)
if !bookings.nil?

View File

@@ -28,7 +28,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end
else
ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}",
queue: oqs.station_name,
queue: oqs.printer_name,
unique_code: print_settings.unique_code,
print_copies: print_settings.print_copies,
data: {
@@ -73,7 +73,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker
end
else
ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}",
queue: oqs.station_name,
queue: oqs.printer_name,
unique_code: print_settings.unique_code,
print_copies: print_settings.print_copies,
data: {

View File

@@ -115,7 +115,8 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
filename = "#{directory_name}/receipt_bill_#{sale_data.receipt_no}#{count != 1 ? "_#{count}" : ''}.pdf"
pdf.render_file filename
if !Lookup.where(lookup_type: "ReceiptPdfView").pluck(:value).include?('1')
if printed_status != 'Paid' || !Lookup.where(lookup_type: "ReceiptPdfView").pluck(:value).include?('1')
#no print in cloud server
puts "SERVER_MODE #{ENV["SERVER_MODE"]}"
if ENV["SERVER_MODE"] != "cloud"
@@ -125,7 +126,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
Rails.logger.debug "############## filename::" + filename
else
if !Lookup.where(lookup_type: "ReceiptPdfView").pluck(:value).include?('1')
if printed_status != 'Paid' || !Lookup.where(lookup_type: "ReceiptPdfView").pluck(:value).include?('1')
sale_payments = SalePayment
.select(:payment_method, 'SUM(`sale_payments`.`payment_amount`) AS `payment_amount`')
.where(sale_id: sale_data.sale_id).group(:payment_method)

View File

@@ -804,7 +804,7 @@ class Sale < ApplicationRecord
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
.sale_payments_with_audit_except_void_between(from, to)
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
.group("sale_id").to_sql
.group("sale_id")
sale_taxes = Sale.select('sales.sale_id, sale_taxes.tax_name')
.joins(:sale_taxes)
@@ -829,13 +829,13 @@ class Sale < ApplicationRecord
(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale,
CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
#{payment_methods.map { |method| pm = method == 'paypar' ? 'redeem' : method; "SUM(`#{pm}`) as `#{pm}`"}.push('').join(', ')}
SUM(cash_amount) as cash_amount,
SUM(credit_amount) as credit_amount,
SUM(foc_amount) as foc_amount
SUM(`cash_amount`) as `cash_amount`,
SUM(`credit_amount`) as `credit_amount`,
SUM(`foc_amount`) as `foc_amount`
FROM (
#{sales}
#{sales.to_sql}
) as s
JOIN (#{sale_taxes.to_sql}) AS st ON s.sale_id = st.sale_id
LEFT JOIN (#{sale_taxes.to_sql}) AS st ON s.sale_id = st.sale_id
GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys)
return daily_total
end
@@ -1254,6 +1254,36 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range, shift, from, to, paymen
return query
end
def self.get_shift_sales_by_customer(shift_sale_range, shift, from, to, membership_type, customer_filter)
## => left join -> show all sales although no orders
query = Sale.includes(:sale_items).select("sales.*, sale_payments.*")
.select("customers.customer_id, customers.name as customer_name,customers.membership_type as membership_type, dining_facilities.name, dining_facilities.type")
.joins("INNER JOIN sale_payments ON sale_payments.sale_id = sales.sale_id")
.joins("INNER JOIN bookings ON bookings.sale_id = sales.sale_id")
.joins("LEFT JOIN dining_facilities ON dining_facilities.id = bookings.dining_facility_id")
.completed.where.not(total_amount: 0)
.group("sales.sale_id")
if customer_filter.present?
query = query.joins(sanitize_sql_array(["INNER JOIN customers ON customers.customer_id = sales.customer_id AND " +
"customers.name LIKE :filter", filter: "%#{customer_filter}%"]))
else
query = query.joins(:customer)
end
if !membership_type.blank?
query = query.where("customers.membership_type = (?)", membership_type)
end
if shift.present?
query = query.where("sales.shift_sale_id in (?)", shift.to_a)
elsif shift_sale_range.present?
query = query.where("sales.shift_sale_id in (?)", shift_sale_range.to_a)
else
query = query.where("sales.receipt_date between ? and ?", from, to)
end
return query.group_by(&:membership_type)
end
def self.get_shift_sales_by_receipt_no_detail(shift_sale_range, shift, from, to, payment_type, customer_filter)
## => left join -> show all sales although no orders
puts customer_filter

View File

@@ -1,9 +1,6 @@
class SeedGenerator < ApplicationRecord
# Generate ID for Tables
def self.generate_id(model, prefix)
# model_name = self.get_model_name(model)
model_name = model
prefix ||= ''
prefix << '-' if prefix.present?
@@ -17,15 +14,12 @@ class SeedGenerator < ApplicationRecord
prefix << shop.shop_code
end
seed = self.update_seed(model_name)
seed = self.update_seed(model)
length = 16 - prefix.length
prefix + seed.to_s.rjust(length, '0')
end
def self.generate_ids(model, prefix, count = 1)
# model_name = self.get_model_name(model)
model_name = model
prefix ||= ''
prefix << '-' if prefix.present?
@@ -39,7 +33,7 @@ class SeedGenerator < ApplicationRecord
prefix << shop.shop_code
end
start = self.update_seed(model_name, count)
start = self.update_seed(model, count)
stop = start + count - 1
length = 16 - prefix.length
(start..stop).map { |c| prefix + c.to_s.rjust(length, '0') }
@@ -129,7 +123,8 @@ class SeedGenerator < ApplicationRecord
def self.update_seed(model, count = 1)
SeedGenerator.transaction do
seed = SeedGenerator.lock.find_by_model(model)
seed = SeedGenerator.lock.find_by_model(get_model_name(model)) ||
SeedGenerator.lock.find_by_model(model)
seed.next = seed.next + (count * seed.increase_by)
seed.current = seed.next - seed.increase_by
seed.save!