This commit is contained in:
Myat Zin Wai Maw
2019-12-13 10:12:08 +06:30
parent 79598c0126
commit f45849de49
39 changed files with 123 additions and 1121 deletions

View File

@@ -11,6 +11,8 @@ class Booking < ApplicationRecord
has_many :order_items, :through => :orders
scope :active, -> {where("booking_status != 'moved'")}
scope :today, -> {where("created_at >= #{Time.now.utc}")}
scope :shop, -> { where("bookings.shop_code=?",Shop.current_shop.shop_code) }
def self.sync_booking_records(bookings)
if !bookings.nil?
@@ -84,7 +86,7 @@ class Booking < ApplicationRecord
joins(" LEFT JOIN dining_facilities df ON df.id=bookings.dining_facility_id")
.where("booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}' OR df.name LIKE ?","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%")
end
.order("sale_id DESC")
.shop.order("sale_id DESC")
end
def self.get_sync_data(sale_id)

View File

@@ -7,6 +7,7 @@ class DiningFacility < ApplicationRecord
ROOM_TYPE = "Room"
default_scope { order('order_by asc') }
scope :shop, -> { where("shop_code=?",Shop.current_shop.shop_code) }
scope :active, -> {where(is_active: true)}

View File

@@ -8,6 +8,7 @@ class Menu < ApplicationRecord
#Default Scope to pull the active version only
default_scope { order("created_at asc") }
scope :active, -> {where("is_active = true")}
scope :shop, -> { where("menus.shop_code=?",Shop.current_shop.shop_code) }
def self.current_menu
today = DateTime.now

View File

@@ -192,6 +192,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
#Use CUPS service
#Generate PDF
#Print
puts printer_settings.to_json
if !printer_settings.nil?
if !printer_settings.unique_code.strip.downcase.include? ("receiptbillorder")
pdf = ReceiptBillPdf.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,transaction_ref)

View File

@@ -32,6 +32,7 @@ class Sale < ApplicationRecord
scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) }
scope :along_with_sale_payments_except_void_between, -> (from, to) { joins(sanitize_sql_array(["LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) }
scope :shop, -> { where("sales.shop_code=?",Shop.current_shop.shop_code) }
def qty_of(item_instance_code)
@@ -832,7 +833,7 @@ class Sale < ApplicationRecord
return num
end
def self.daily_sales_list(from,to,shop_code)
def self.daily_sales_list(from,to)
sales = select("
sales.*,
SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount,
@@ -853,7 +854,7 @@ def self.daily_sales_list(from,to,shop_code)
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
.along_with_sale_payments_except_void_between(from, to)
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to).shop
.group("sale_id").to_sql
daily_total = connection.select_all("SELECT
@@ -2431,39 +2432,40 @@ def self.get_check_sale_data(transaction_date)
.group("sales.receipt_no,sales.sale_status")
end
def paymal_payment_void
puts self.sale_payments.to_json
membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",self.shop_code)
membership_actions_data = MembershipAction.find_by_membership_type_and_shop_code("void",self.shop_code)
if !membership_actions_data.nil?
sale_payments =self.sale_payments.where("payment_reference is not null")
account_no =sale_payments[0].payment_reference
url = membership_setting.gateway_url.to_s + membership_actions_data.gateway_url.to_s
merchant_uid = membership_actions_data.merchant_account_id
auth_token = membership_actions_data.auth_token
params = { receipt_no:self.receipt_no,
account_no:account_no,
merchant_uid:merchant_uid,
auth_token:auth_token}.to_json
if !sale_payments.empty?
account_no =sale_payments[0].payment_reference
url = membership_setting.gateway_url.to_s + membership_actions_data.gateway_url.to_s
merchant_uid = membership_actions_data.merchant_account_id
auth_token = membership_actions_data.auth_token
params = { receipt_no:self.receipt_no,
account_no:account_no,
merchant_uid:merchant_uid,
auth_token:auth_token}.to_json
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => params,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
},
:timeout => 10
)
rescue Errno::ECONNREFUSED
response = { "status" => false, "message" => "Can't open membership server"}
rescue Net::OpenTimeout
response = { "status" => false, "message" => "No internet connection " }
rescue OpenURI::HTTPError
response = { "status" => false, "message" => "No internet connection "}
rescue SocketError
response = { "status" => false, "message" => "No internet connection "}
end
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => params,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
},
:timeout => 10
)
rescue Errno::ECONNREFUSED
response = { "status" => false, "message" => "Can't open membership server"}
rescue Net::OpenTimeout
response = { "status" => false, "message" => "No internet connection " }
rescue OpenURI::HTTPError
response = { "status" => false, "message" => "No internet connection "}
rescue SocketError
response = { "status" => false, "message" => "No internet connection "}
end
end
else
response = { "status" => false}
end

View File

@@ -655,7 +655,7 @@ class SalePayment < ApplicationRecord
if spay.payment_method == KbzPay::KBZ_PAY
is_kbz_pay = 1
end
if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote" || spay.payment_method == KbzPay::KBZ_PAY
if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote" || spay.payment_method == KbzPay::KBZ_PAY || spay.payment_method =="paymal"
method_status = true
end
end
@@ -954,14 +954,14 @@ class SalePayment < ApplicationRecord
#credit payment query
def self.get_credit_sales(params,shop_code)
def self.get_credit_sales(params)
payments = SalePayment.select("sale_payments.sale_id, sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount")
.select("SUM(sale_payments.payment_amount) OVER (PARTITION BY sale_payments.sale_id) total_payment_amount")
credit_sales = Sale.select("sales.sale_id, sales.receipt_no, sales.receipt_date as sale_date, sales.cashier_name")
.select("sale_payments.sale_payment_id, sale_payments.payment_amount").select("customers.name as customer_name")
.joins("JOIN (#{payments.to_sql}) AS sale_payments ON sale_payments.sale_id = sales.sale_id").joins(:customer).joins(:orders)
.completed.paid.where("sale_payments.payment_method = 'creditnote' AND sales.grand_total > sale_payments.total_payment_amount - sale_payments.payment_amount and sales.shop_code=?",shop_code)
.completed.paid.where("sale_payments.payment_method = 'creditnote' AND sales.grand_total > sale_payments.total_payment_amount - sale_payments.payment_amount").shop
.group(:receipt_no)
.order(:receipt_date).order(:receipt_no)

View File

@@ -28,10 +28,10 @@ class SaleTax < ApplicationRecord
end
end
def self.get_tax(from,to,shop_code)
def self.get_tax(from,to)
query = SaleTax.select("sale_taxes.tax_name,SUM(sale_taxes.tax_payable_amount) as tax_amount")
.joins("join sales on sales.sale_id = sale_taxes.sale_id")
.where("sales.shop_code='#{shop_code}' and sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0 AND inclusive = 0", 'completed', from, to)
.where("sales.shop_code=? and sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0 AND inclusive = 0",Shop.current_shop.shop_code, 'completed', from, to)
.group("sale_taxes.tax_name")
end

View File

@@ -4,6 +4,8 @@ class Zone < ApplicationRecord
has_many :rooms, dependent: :destroy
has_many :order_queue_stations
has_many :cashier_terminals
scope :shop, -> { where("shop_code=?",Shop.current_shop.shop_code) }
# validations
validates_presence_of :name, :created_by