From a498eec8325edd7f4133c42307566ac717687cce Mon Sep 17 00:00:00 2001
From: Aung Ye Kyaw
Date: Thu, 30 Jan 2020 05:25:23 +0000
Subject: [PATCH 01/28] Update Gemfile ruby version and mysql2 version ## gem
'mysql2', '~> 0.5.2'
---
Gemfile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Gemfile b/Gemfile
index 11a34b3c..92b133de 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,6 +1,6 @@
source 'https://rubygems.org'
-#ruby '2.4.1'
+ruby '2.6.5'
#ruby '2.5.7'
git_source(:github) do |repo_name|
@@ -15,7 +15,7 @@ gem 'rails', '~> 5.1.0'
#gem 'mysql2', '>= 0.3.18', '< 0.5'
gem 'pg'
-gem 'mysql2'
+gem 'mysql2', '~> 0.5.2'
#Use PosgreSQL
From 4e8049581e11ccc4231429db8391d80521a80b11 Mon Sep 17 00:00:00 2001
From: NyanLinHtut
Date: Fri, 31 Jan 2020 17:19:36 +0630
Subject: [PATCH 02/28] fixed redeem
---
app/models/sale_audit.rb | 2 +-
app/models/sale_payment.rb | 13 +++++++------
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb
index 0cc5b9e7..5aa42545 100755
--- a/app/models/sale_audit.rb
+++ b/app/models/sale_audit.rb
@@ -142,7 +142,7 @@ class SaleAudit < ApplicationRecord
if paymal[0]
remark = paymal[0].remark.split("}")
response = "["+remark[0]+'}]'
- response = JSON.parse(response)
+ # response = JSON.parse(response)
puts response
if response[0]["status"] == true
if response[0]["current_rebate_amount"].present?
diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb
index 36bc6de3..607b22da 100755
--- a/app/models/sale_payment.rb
+++ b/app/models/sale_payment.rb
@@ -233,9 +233,9 @@ class SalePayment < ApplicationRecord
return response;
end
- def self.redeem(paypar_url,token,membership_id,received_amount,sale_id)
- # membership_actions_data = MembershipAction.find_by_membership_type("redeem");
- membership_actions_data = PaymentMethodSetting.find_by_payment_method("Redeem")
+ def redeem(paypar_url,token,membership_id,received_amount,sale_id)
+ membership_actions_data = MembershipAction.find_by_membership_type("redeem");
+ # membership_actions_data = PaymentMethodSetting.find_by_payment_method("Redeem")
puts "This is membership_actions_data"
puts membership_actions_data.to_json
if !membership_actions_data.nil?
@@ -243,8 +243,9 @@ class SalePayment < ApplicationRecord
url = paypar_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
- campaign_type_id = JSON.parse(membership_actions_data.additional_parameters)["campaign_type_id"]
+ campaign_type_id = membership_actions_data.additional_parameters["campaign_type_id"]
sale_data = Sale.find_by_sale_id(sale_id)
+ account_no = Customer.find_by_customer_id(self.sale.customer_id).paypar_account_no
if sale_data
others = 0
@@ -261,7 +262,7 @@ class SalePayment < ApplicationRecord
redeem_amount:received_amount,
receipt_no:sale_data.receipt_no,
campaign_type_id:campaign_type_id,
- account_no:"",
+ account_no: account_no,
merchant_uid:merchant_uid,
auth_token:auth_token}.to_json,
:headers => {
@@ -504,7 +505,7 @@ class SalePayment < ApplicationRecord
#Next time - validate if the vochure number is valid - within
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)
+ membership_data = redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id)
#record an payment in sale-audit
remark = "#{membership_data} Redeem- for Customer #{self.sale.customer_id} Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} "
From d2cfe06f3a6e333ea630fb2f5c6c414edfbd5b2a Mon Sep 17 00:00:00 2001
From: NyanLinHtut
Date: Fri, 31 Jan 2020 17:36:34 +0630
Subject: [PATCH 03/28] fixed redeem
---
app/models/sale_payment.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb
index 607b22da..a0b3501a 100755
--- a/app/models/sale_payment.rb
+++ b/app/models/sale_payment.rb
@@ -243,7 +243,7 @@ class SalePayment < ApplicationRecord
url = paypar_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
- campaign_type_id = membership_actions_data.additional_parameters["campaign_type_id"]
+ campaign_type_id = membership_actions_data.additional_parameter["campaign_type_id"]
sale_data = Sale.find_by_sale_id(sale_id)
account_no = Customer.find_by_customer_id(self.sale.customer_id).paypar_account_no
From c2dffba4eff73dd08059f69b13d12fdea10b486d Mon Sep 17 00:00:00 2001
From: Myat Zin Wai Maw
Date: Mon, 3 Feb 2020 09:59:15 +0630
Subject: [PATCH 04/28] rebate
---
app/models/sale_payment.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb
index 06350f6f..e06d32ce 100755
--- a/app/models/sale_payment.rb
+++ b/app/models/sale_payment.rb
@@ -655,7 +655,7 @@ class SalePayment < ApplicationRecord
sale.sale_status = "completed"
- if MembershipSetting.find_by_rebate(1) && is_foc == 0 && is_credit == 0
+ if MembershipSetting.find_by_rebate(1) && !is_foc && !is_credit
response = rebat(sale)
#record an payment in sale-audit
From b980fd7fc4a91cb752ba6aba3b191ecc2188f2b9 Mon Sep 17 00:00:00 2001
From: Myat Zin Wai Maw
Date: Mon, 3 Feb 2020 17:23:24 +0630
Subject: [PATCH 05/28] old balance in receipt
---
Gemfile.lock | 5 ++++-
app/models/sale_audit.rb | 4 ++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/Gemfile.lock b/Gemfile.lock
index 50647fba..f56a2d36 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -351,7 +351,7 @@ DEPENDENCIES
material_icons
mini_magick
momentjs-rails
- mysql2
+ mysql2 (~> 0.5.2)
nested_form
pdfjs_viewer-rails
pg
@@ -380,5 +380,8 @@ DEPENDENCIES
web-console (>= 3.3.0)
whenever
+RUBY VERSION
+ ruby 2.6.5p114
+
BUNDLED WITH
2.0.2
diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb
index 5aa42545..e566182a 100755
--- a/app/models/sale_audit.rb
+++ b/app/models/sale_audit.rb
@@ -142,8 +142,8 @@ class SaleAudit < ApplicationRecord
if paymal[0]
remark = paymal[0].remark.split("}")
response = "["+remark[0]+'}]'
- # response = JSON.parse(response)
- puts response
+ response = JSON.parse(response)
+ # puts response
if response[0]["status"] == true
if response[0]["current_rebate_amount"].present?
amount = response[0]["current_rebate_amount"]
From 306b4302992609ffd6cf4a9c2f11c2e2918f85cb Mon Sep 17 00:00:00 2001
From: Thein Lin Kyaw
Date: Thu, 20 Feb 2020 11:07:06 +0630
Subject: [PATCH 06/28] update check_in_process
---
.../api/check_in_process_controller.rb | 139 +++++++-----------
app/controllers/api/orders_controller.rb | 6 +-
2 files changed, 56 insertions(+), 89 deletions(-)
diff --git a/app/controllers/api/check_in_process_controller.rb b/app/controllers/api/check_in_process_controller.rb
index 2a04ff6b..c12ae517 100644
--- a/app/controllers/api/check_in_process_controller.rb
+++ b/app/controllers/api/check_in_process_controller.rb
@@ -19,12 +19,13 @@ class Api::CheckInProcessController < Api::ApiController
table = DiningFacility.find(params[:dining_id])
#Send to background job for processing
- if ENV["SERVER_MODE"] == 'cloud'
- from = request.subdomain + "." + request.domain
- else
- from = ""
- end
- ActionCable.server.broadcast "check_in_booking_channel",table: table,from:from
+ if ENV["SERVER_MODE"] == 'cloud'
+ from = request.subdomain + "." + request.domain
+ else
+ from = ""
+ end
+ ActionCable.server.broadcast "check_in_booking_channel",table: table,from:from
+
check_out_time = nil
extra_minutes = nil
alert_time_min = 0
@@ -65,93 +66,59 @@ class Api::CheckInProcessController < Api::ApiController
if params[:dining_id]
dining_facility = DiningFacility.find(params[:dining_id])
if dining_facility.is_active && dining_facility.status == "available"
- if params[:checkin_time]
- checkin_at = nil
- if !params[:checkin_time].empty?
- checkin_at = Time.parse(params[:checkin_time]).utc
+ if dining_facility.current_checkin_booking.nil?
+ if params[:checkin_time].present?
+ checkin_at = Time.parse(params[:checkin_time])
else
- checkin_at = Time.now.utc
+ checkin_at = Time.now
end
- if !checkin_at.nil?
- if dining_facility.check_time(checkin_at, "checkin")
- booking = dining_facility.get_current_booking
- if booking.nil?
+ checkout_at = nil
+ lookup_checkout_time = Lookup.collection_of("checkout_time")
+ today = Time.now
+ if !lookup_checkout_time.empty?
- booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
- :checkin_by=>current_login_employee.name,:checkin_at => checkin_at,:checkout_at =>nil, :booking_status => "assign", :reserved_at => nil, :reserved_by => nil })
- if booking.save!
- dining_facility.status = "occupied"
- dining_facility.save!
- render :json => { :status => true, :booking_id => booking.booking_id, :checkin_at => booking.checkin_at.utc.getlocal.strftime("%Y-%m-%d %H:%M:%S"), :message => "Check-in success" }
- else
- render :json => { :status => false, :error_message => "Booking does not create successfully!" }
- end
- else
- render :json => { :status => false, :error_message => "Booking already exist!" }
+ lookup_checkout_time.each do |checkout_time|
+ start_time, end_time = checkout_time[0].split("-").map{ |t| Time.parse(t.strip).strftime("%H:%M%p") }
+ if start_time <= today.strftime("%H:%M%p") && today.strftime("%H:%M%p") <= end_time
+ checkout_at = checkin_at + (checkout_time[1]).to_i.minutes
end
- else
- render :json => { :status => false, :error_message => "Checkin time not available!" }
end
- else
- render :json => { :status => false, :error_message => "Operation failed!" }
end
+
+ booking = nil
+ ActiveRecord::Base.transaction do
+ booking = Booking.create({
+ :dining_facility_id => params[:dining_id],
+ :type => "TableBooking",
+ :checkin_by => current_login_employee.name,
+ :checkin_at => checkin_at,
+ :checkout_at => checkout_at,
+ :booking_status => "assign",
+ :reserved_at => checkout_at,
+ :reserved_by => current_login_employee.name })
+
+ dining_facility.status = "occupied"
+ dining_facility.save!
+ end
+
+ terminal = DiningFacility.find_by_id(booking.dining_facility_id)
+ cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
+
+ if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
+ unique_code = "CheckInOutPdf"
+ printer = PrintSetting.find_by_unique_code(unique_code)
+
+ # print when complete click
+ order_queue_printer = Printer::OrderQueuePrinter.new(printer)
+
+ if !printer.nil?
+ order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, dining_facility)
+ end
+ end
+ render :json => { :status => true, :booking_id => booking.booking_id, :checkin_at => booking.checkin_at.strftime("%Y-%m-%d %H:%M"), :checkout_at => booking.checkout_at.strftime("%Y-%m-%d %H:%M") }
else
- booking = dining_facility.current_checkout_booking
- if booking.nil?
- lookup_checkout_time = Lookup.collection_of("checkout_time")
-
- if !lookup_checkout_time.empty?
- today = Time.now.utc.getlocal
- checkout_at = Time.now.utc.getlocal
-
- lookup_checkout_time.each do |checkout_time|
- arr_time = checkout_time[0].split("-")
- start_time = Time.parse(arr_time[0].strip).utc.getlocal.strftime("%H:%M%p")
- end_time = Time.parse(arr_time[1].strip).utc.getlocal.strftime("%H:%M%p")
- if start_time <= today.strftime("%H:%M%p") && today.strftime("%H:%M%p") <= end_time
- checkout_at = checkout_at + (checkout_time[1]).to_i.minutes
- end
- end
-
- if checkout_at.strftime("%Y-%m-%d %H:%M%p") >= today.strftime("%Y-%m-%d %H:%M%p")
- # if dining_facility.type == "Table"
- # type = "TableBooking"
- # else
- # type = "RoomBooking"
- # end
-
- booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
- :checkin_by=>current_login_employee.name,:checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign", :reserved_at => checkout_at, :reserved_by => current_login_employee.name })
- if booking.save!
- dining_facility.status = "occupied"
- dining_facility.save!
- end
- terminal = DiningFacility.find_by_id(booking.dining_facility_id)
- cashier_terminal = CashierTerminal.find_by_id(terminal.zone_id)
-
- if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
-
- unique_code = "CheckInOutPdf"
- printer = PrintSetting.find_by_unique_code(unique_code)
-
- # print when complete click
- order_queue_printer = Printer::OrderQueuePrinter.new(printer)
-
- if !printer.nil?
- order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, dining_facility)
- end
- end
- render :json => { :status => true, :booking_id => booking.booking_id, :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") }
- else
- render :json => { :status => true }
- end
- else
- render :json => { :status => true }
- end
- else
- render :json => { :status => false, :error_message => "Booking already exist!" }
- end
+ render :json => { :status => false, :error_message => "Booking already exist!" }
end
else
error_message = "#{dining_facility.type} is not available!"
@@ -161,6 +128,8 @@ class Api::CheckInProcessController < Api::ApiController
error_message = "dining_id is required!"
render :json => { :status => false, :error_message => error_message }
end
+ rescue ActiveRecord::RecordInvalid => exception
+ render :json => { :status => false, :error_message => exception.message }
end
def request_time
diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb
index 0c79f303..4f94ae9b 100755
--- a/app/controllers/api/orders_controller.rb
+++ b/app/controllers/api/orders_controller.rb
@@ -37,18 +37,16 @@ class Api::OrdersController < Api::ApiController
@booking = table.get_booking
end
- @tax_profile = nil
+ @tax_profile = TaxProfile.where("lower(group_type)='cashier'")
# arr_tax = []
# if !arr_tax.empty?
# @tax_profile = TaxProfile.where(:id => arr_tax)
# else
- @tax_profile = TaxProfile.where("lower(group_type)='cashier'")
+ # @tax_profile = TaxProfile.where("lower(group_type)='cashier'")
# end
@shop = Shop.current_shop
- puts "Hello world"
- puts @shop.to_json
return @shop.to_json
end
From 98538a5a0d94f2f9af9ea024ba80fe4a0524abea Mon Sep 17 00:00:00 2001
From: yarzar_code
Date: Fri, 21 Feb 2020 14:00:55 +0630
Subject: [PATCH 07/28] Credit pdf
---
.../origami/payments_controller.rb | 97 ++
app/models/printer/receipt_printer.rb | 9 +
app/pdf/credit_bill_pdf.rb | 838 ++++++++++++++++++
3 files changed, 944 insertions(+)
create mode 100644 app/pdf/credit_bill_pdf.rb
diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb
index 82e76119..787ea62c 100755
--- a/app/controllers/origami/payments_controller.rb
+++ b/app/controllers/origami/payments_controller.rb
@@ -89,6 +89,7 @@ class Origami::PaymentsController < BaseOrigamiController
path = request.fullpath
latest_order_no = nil
is_kbz = params[:is_kbz]
+ credit_pdf = Lookup.find_by_lookup_type("credit_pdf")
if saleObj = Sale.find(sale_id)
sale_items = SaleItem.get_all_sale_items(sale_id)
@@ -205,6 +206,102 @@ class Origami::PaymentsController < BaseOrigamiController
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
#end
+ elsif (path.include? ("credit_payment")) && !credit_pdf.nil? && credit_pdf.value.to_i == 1
+
+ rebate_amount = nil
+ # For Cashier by Zone
+ booking = saleObj.booking
+
+ if current_user.role == 'cashier'
+ cashier_terminal = current_user.cashier_terminal
+ elsif booking.dining_facility
+ cashier_terminal = booking.cashier_terminal_by_dining_facility
+ end
+
+ cashier_terminal ||= saleObj.cashier_terminal_by_shift_sale
+
+ if booking.dining_facility
+ ActionCable.server.broadcast(
+ "order_channel",
+ table: booking.dining_facility,
+ type: 'payment',
+ from: getCloudDomain
+ )
+ end
+
+ # For Print
+
+ if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf
+ unique_code = "ReceiptBillA5Pdf"
+ else
+ unique_code = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code
+ end
+
+ customer = saleObj.customer
+
+ # get member information
+ rebate = MembershipSetting.find_by_rebate(1)
+ credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote')
+
+ if customer.membership_id != nil && rebate && credit_data.nil?
+ member_info = Customer.get_member_account(customer)
+
+ if member_info["status"] == true
+ rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
+ current_balance = SaleAudit.paymal_search(sale_id)
+ end
+ end
+
+ #orders print out
+ if type == "quick_service"
+ if booking.dining_facility_id.present?
+ table_id = booking.dining_facility_id
+ else
+ table_id = 0
+ end
+
+ latest_order = booking.booking_orders.order("order_id DESC").limit(1).first()
+ if !latest_order.nil?
+ latest_order_no = latest_order.order_id
+ end
+
+ booking.booking_orders.each do |order|
+
+ oqs = OrderQueueStation.new
+ oqs.pay_process_order_queue(order.order_id, table_id)
+
+ assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id)
+ from = getCloudDomain #get sub domain in cloud mode
+ ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
+ end
+
+ end
+
+ #for card sale data
+ card_data = Array.new
+ card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id)
+ if !card_sale_trans_ref_no.nil?
+ card_sale_trans_ref_no.each do |cash_sale_trans|
+ card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s
+ card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s
+ card_no = cash_sale_trans.pan.last(4)
+ card_no = card_no.rjust(19,"**** **** **** ")
+ card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id})
+ end
+ end
+
+ #card_balance amount for Paymal payment
+ card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id)
+
+ # get printer info
+ print_settings = PrintSetting.find_by_unique_code(unique_code)
+ # Calculate Food and Beverage Total
+ item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
+ discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
+ other_amount = SaleItem.calculate_other_charges(sale_items)
+
+ printer = Printer::ReceiptPrinter.new(print_settings)
+ filename, sale_receipt_no, printer_name = printer.print_credit(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
end
if !saleObj.nil?
# InventoryJob.perform_now(self.id)
diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb
index 4d96112f..d456c980 100755
--- a/app/models/printer/receipt_printer.rb
+++ b/app/models/printer/receipt_printer.rb
@@ -138,7 +138,16 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
Rails.logger.debug "############## filename::" + filename
return filename, sale_data.receipt_no, cashier_terminal.printer_name
end
+ #print credit
+ def print_credit(printer_settings, kbz_pay_status, qr_code, cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,order_reservation)
+ pdf = CreditBillPdf.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)
+
+ directory_name = 'public/receipts'
+ filename = directory_name + "/credit_receipt_bill_#{sale_data.receipt_no}.pdf"
+ pdf.render_file filename
+ self.print(directory_name + "/credit_receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name)
+ end
# stock check
def print_stock_check_result(print_settings,stockcheck, stockcheck_items,checker_name, shop_details)
pdf = StockResultPdf.new(print_settings,stockcheck, stockcheck_items,checker_name, shop_details)
diff --git a/app/pdf/credit_bill_pdf.rb b/app/pdf/credit_bill_pdf.rb
new file mode 100644
index 00000000..f2ce2469
--- /dev/null
+++ b/app/pdf/credit_bill_pdf.rb
@@ -0,0 +1,838 @@
+require 'prawn/measurement_extensions'
+class CreditBillPdf < Prawn::Document
+ include NumberFormattable
+
+ attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move
+
+ def initialize(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount)
+ self.page_width = printer_settings.page_width
+ self.page_height = printer_settings.page_height
+ self.header_font_size = printer_settings.header_font_size.to_i
+ self.item_font_size = printer_settings.item_font_size.to_i
+ self.margin = 0
+ self.price_width = 60
+ self.qty_width = 25
+ self.total_width = 60
+ self.item_width = self.page_width - ((self.qty_width + self.price_width + self.total_width))
+ self.item_height = 15
+ self.item_description_width = (self.page_width-5) / 2
+ self.label_width = 100
+
+ self.description_width = 150
+ self.price_num_width = 50
+ self.line_move = 2
+ # @item_width = self.page_width.to_i / 2
+ # @qty_width = @item_width.to_i / 3
+ # @double = @qty_width * 1.3
+ # @half_qty = @qty_width / 2
+ #setting page margin and width
+ super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
+
+ # db font setup
+ if printer_settings.font != ""
+ font_families.update("#{printer_settings.font}" => {
+ :normal => "public/fonts/#{printer_settings.font}.ttf",
+ :italic => "public/fonts/#{printer_settings.font}.ttf",
+ :bold => "public/fonts/#{printer_settings.font}.ttf",
+ :bold_italic => "public/fonts/#{printer_settings.font}.ttf"
+ })
+
+ font "#{printer_settings.font}"
+ fallback_fonts ["Courier", "Helvetica", "Times-Roman"]
+ end
+ # font "public/fonts/Zawgyi-One.ttf"
+ # font "public/fonts/padauk.ttf"
+
+ header(shop_details)
+
+ stroke_horizontal_rule
+
+ cashier_info(sale_data, customer_name, latest_order_no)
+ line_items(sale_items,precision,delimiter)
+ all_total(sale_data,precision,delimiter)
+
+
+ if member_info != nil
+ member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance)
+ end
+
+ customer(customer_name)
+
+ #start card sale trans data
+ if card_data != nil
+ card_sale_data(card_data)
+ end
+ #end card sale trans data
+ #start card blanace amount
+ if !card_balance_amount.nil?
+ card_balance_data(card_balance_amount)
+ end
+ #end card blanace amount
+
+ if discount_price_by_accounts.length > 0 && shop_details.show_account_info
+ discount_account(discount_price_by_accounts,precision,delimiter)
+ end
+
+ if shop_details.show_account_info
+ items_account(item_price_by_accounts,precision,delimiter)
+ if other_charges_amount
+ show_other_charges_amount(other_charges_amount,precision,delimiter)
+ end
+ end
+
+ #start for individual payment
+ if !sale_data.equal_persons.nil?
+ individual_payment(sale_data,sale_data.equal_persons, precision, delimiter)
+ end
+ #end for individual payment
+
+ sign(sale_data)
+
+ if shop_details.note && !shop_details.note.nil?
+ shop_note(shop_details)
+ end
+
+ if kbz_pay_status
+ kbzpay_qr_generator(printed_status, qr_code)
+ end
+
+ footer(printed_status)
+ end
+
+ def header (shop_details)
+ text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center
+ move_down line_move
+ text "#{shop_details.address}", :size => self.item_font_size,:align => :center
+ # move_down self.item_height
+ move_down line_move
+ text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center
+ move_down line_move
+
+ stroke_horizontal_rule
+ end
+
+ def cashier_info(sale_data, customer_name, latest_order_no)
+ if latest_order_no.nil?
+ move_down line_move
+ text "Booking : #{ sale_data.bookings[0].booking_id }", :size => self.header_font_size+2,:align => :left
+ move_down line_move
+ end
+ move_down line_move
+ if !latest_order_no.nil?
+ move_down line_move
+ text "OrderNo : #{ latest_order_no }", :size => self.header_font_size,:align => :left
+ end
+ move_down line_move
+
+ # move_down 2
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.description_width + self.price_num_width, :height => self.item_height) do
+ text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left
+ end
+
+ if sale_data.bookings[0].dining_facility_id.to_i > 0
+ bounding_box([self.description_width - 2,y_position], :width => self.price_num_width, :height => self.item_height) do
+ text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right
+ end
+ end
+
+ move_down line_move
+ y_position = cursor
+ bounding_box([0, y_position], :width =>self.label_width, :height => self.item_height) do
+ text "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left
+ end
+ bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do
+ text "C: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :right
+ end
+
+ move_down line_move
+ # credit_date = SalePayment.select(:created_at).where("sale_id = '#{sale_data.sale_id}' AND payment_method = 'creditnote'")
+ y_position = cursor
+ if sale_data.bookings[0].dining_facility_id.to_i > 0
+ time = sale_data.receipt_date.strftime('%d-%m-%Y') +"("+ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') +"-"+ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p')+")"
+ else
+ time = sale_data.receipt_date.strftime('%d-%m-%Y %H:%M %p')
+ end
+
+ bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do
+ text "Credit Date : #{ time }",:size => self.item_font_size,:align => :left
+ end
+ move_down line_move
+
+ y_position = cursor
+ time = DateTime.now
+ time = time.strftime('%d-%m-%Y (%H:%M %p)')
+
+
+ bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do
+ text "Payment Date : #{ time }",:size => self.item_font_size,:align => :left
+ end
+
+ # bounding_box([self.item_description_width,y_position], :width =>self.label_width+5) do
+ # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') }
+ # - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') })" ,
+ # :size => self.item_font_size,:align => :right
+ # end
+ move_down line_move
+ stroke_horizontal_rule
+ end
+
+ def line_items(sale_items,precision,delimiter)
+ if precision.to_i > 0
+ item_label_qty_front_width = (self.item_width+self.price_width) + 5
+ item_label_qty_end_width = self.qty_width + 4
+ item_label_total_front_width = (self.item_width+self.price_width) + 10
+ item_label_total_end_width = self.total_width + 9
+ else
+ self.item_width = self.item_width.to_i + 8
+ item_label_qty_front_width = (self.item_width+self.price_width) + 8
+ item_label_qty_end_width = self.qty_width + 7
+ item_label_total_front_width = (self.item_width+self.price_width) + 5
+ item_label_total_end_width = self.total_width + 4
+ end
+ move_down line_move
+ y_position = cursor
+ move_down line_move
+ pad_top(15) {
+ # @item_width.to_i + @half_qty.to_i
+ text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
+ text_box "Price", :at =>[(self.item_width),y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
+ text_box "Qty", :at =>[item_label_qty_front_width,y_position], :width => item_label_qty_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
+ text_box "Total", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
+ }
+ # move_down line_move
+ stroke_horizontal_rule
+ add_line_item_row(sale_items,precision,delimiter)
+ end
+
+ def add_line_item_row(sale_items,precision,delimiter)
+
+ if precision.to_i > 0
+ item_name_width = (self.item_width+self.price_width)
+ item_qty_front_width = (self.item_width+self.price_width) + 5
+ item_qty_end_width = self.qty_width + 4
+ item_total_front_width = item_name_width + 10
+ item_total_end_width = self.total_width + 9
+ else
+ item_name_width = (self.item_width+self.price_width)
+ item_qty_front_width = item_name_width + 8
+ item_qty_end_width = self.qty_width + 7
+ item_total_front_width = item_name_width + 5
+ item_total_end_width = self.total_width + 4
+ end
+
+ y_position = cursor
+ move_down line_move
+ @sub_total = 0.0
+ total_qty = 0.0
+ show_price = Lookup.find_by_lookup_type("show_price")
+ sale_items.each do |item|
+ # check for item not to show
+
+ if item.status != 'Discount' && item.qty > 0
+ if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0
+ total_qty += item.qty
+ else
+ if item.price != 0
+ total_qty += item.qty
+ end
+ end
+ end
+
+ product_name = item.product_name
+
+ # if item.status = 'promotion' && (item.remark =='promotion nett price' || item.remark == 'promotion discount')
+ # sub_total += -item.price #(item.qty*item.unit_price) - comment for room charges
+ # qty = -item.qty
+ # total_price = -item.price #item.qty*item.unit_price - comment for room charges
+ # price = -item.unit_price
+ # else
+ @sub_total += item.price #(item.qty*item.unit_price) - comment for room charges
+ qty = item.qty
+ total_price = item.price #item.qty*item.unit_price - comment for room charges
+ price = item.unit_price
+
+ # end
+
+
+ if !show_price.nil? && show_price.value.to_i>0
+ item_row(item,precision,delimiter,product_name,price,qty ,total_price)
+ else
+ if item.price != 0
+ item_row(item,precision,delimiter,product_name,price,qty ,total_price)
+ end
+ end
+
+ end
+
+ stroke_horizontal_rule
+
+ move_down line_move
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do
+ text "Sub Total", :size => self.item_font_size,:align => :left
+ end
+ text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
+ text_box "#{number_format(@sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
+ end
+
+ def item_row(item,precision,delimiter,product_name,price,qty ,total_price)
+ if precision.to_i > 0
+ item_name_width = (self.item_width+self.price_width)
+ item_qty_front_width = (self.item_width+self.price_width) + 5
+ item_qty_end_width = self.qty_width + 4
+ item_total_front_width = item_name_width + 10
+ item_total_end_width = self.total_width + 9
+ else
+ item_name_width = (self.item_width+self.price_width)
+ item_qty_front_width = item_name_width + 8
+ item_qty_end_width = self.qty_width + 7
+ item_total_front_width = item_name_width + 5
+ item_total_end_width = self.total_width + 4
+ end
+ y_position = cursor
+
+ pad_top(15) {
+ bounding_box([0,y_position], :width =>self.item_width) do
+ text "#{product_name}", :size => self.item_font_size,:align => :left
+ end
+ # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size
+ text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
+ text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
+ text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
+
+ if show_alt_name
+ if !(item.product_alt_name).empty?
+ move_down 2
+ # font("public/fonts/NotoSansCJKtc-Regular.ttf") do
+ text "(#{item.product_alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true
+ # end
+ end
+ end
+ move_down line_move
+ }
+
+
+ end
+
+ def all_total(sale_data,precision,delimiter)
+ move_down line_move
+ item_name_width = self.item_width
+ y_position = cursor
+ if sale_data.discount_type == 'member_discount'
+ dis_type = "Member Discount:"
+ else
+ dis_type = "Overall Discount:"
+ end
+
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "#{ dis_type }", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right
+ end
+
+ service_tax_desc = ""
+ service_tax_amount = 0
+ service_tax_rate = 0
+ com_tax_desc = ""
+ com_tax_amount = 0
+ com_tax_rate = 0
+ if sale_data.sale_taxes.length > 0
+ incl_tax = ""
+ if sale_data.tax_type == "inclusive"
+ incl_tax = "Incl."
+ end
+
+ find_lookup = Lookup.find_by_lookup_type('show_total_before_tax')
+ if find_lookup.nil? || find_lookup == nil
+ lookup = Lookup.new(lookup_type: 'show_total_before_tax', name: 'Show Total Before Tax', value: '0')
+ lookup.save
+ end
+ check_lookup_type = Lookup.find_by_lookup_type('show_total_before_tax')
+ if check_lookup_type.value == '1'
+ sale_data.sale_taxes.each do |st|
+ if (st.tax_name.include? "Service")
+ service_tax_desc = st.tax_name
+ service_tax_amount = st.tax_payable_amount
+ if incl_tax
+ service_tax_rate = st.tax_rate.to_i
+ end
+ end
+ if (st.tax_name.include? "Commercial")
+ com_tax_desc = st.tax_name
+ com_tax_amount = st.tax_payable_amount
+ if incl_tax
+ com_tax_rate = st.tax_rate.to_i
+ end
+ end
+ end
+ move_down line_move
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "#{ service_tax_desc } (#{incl_tax} #{ service_tax_rate }%)", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
+ end
+ move_down line_move
+ y_position = cursor
+ stroke_horizontal_rule
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Total Before Tax", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{service_tax_amount.to_i + @sub_total.to_i}" , :size => self.item_font_size,:align => :right
+ end
+ move_down line_move
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "#{ com_tax_desc } (#{incl_tax} #{ com_tax_rate.to_i }%)", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
+ end
+ else
+ sale_data.sale_taxes.each do |st|
+ move_down line_move
+ y_position = cursor
+
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
+ end
+ end
+ end
+ else
+
+ end
+
+ # move_down 5
+ # y_position = cursor
+
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ # text "Total Tax", :size => self.item_font_size,:align => :left
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ # text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right
+ # end
+
+ if sale_data.rounding_adjustment != 0.0
+ move_down line_move
+ y_position = cursor
+
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Rounding Adjustment", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right
+ end
+ end
+
+ move_down line_move
+ y_position = cursor
+ move_down line_move
+ bounding_box([0,y_position], :width =>self.item_description_width) do
+ text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right
+ end
+ move_down line_move
+
+ sale_payment(sale_data,precision,delimiter)
+ end
+
+ def sale_payment(sale_data,precision,delimiter)
+ stroke_horizontal_rule
+ #move_down line_move
+ # sql = "SELECT SUM(payment_amount)
+ # FROM sale_payments where payment_method='creditnote'
+ # and sale_id='#{sale_data.sale_id}'"
+ sql = SalePayment.select("(SUM(payment_amount))").where("payment_method='creditnote' and sale_id='#{sale_data.sale_id}'").to_sql
+ # sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
+ # FROM sale_payments where payment_method='creditnote'
+ # and sale_id='#{sale_data.sale_id}'"
+ sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ("
+ sql1 += sql
+
+ # sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method")
+ # .where("(CASE WHEN ((#{sql}) - (#{sql1})
+ # ELSE SUM(payment_amount) END
+ # FROM sale_payments
+ # JOIN sales s ON s.sale_id=sale_payments.sale_id
+ # JOIN sale_audits sa
+ # ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id
+ # where sa.sale_id='#{sale_data.sale_id}')) = 0
+ # THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id)
+ # .group("payment_method")
+
+ sale_payments = SalePayment.select("SUM(payment_amount) as payment_amount, payment_method")
+ .where("sale_id = '#{sale_data.sale_id}' AND ((payment_method = 'cash' AND outstanding_amount = 0) OR (payment_method != 'cash' AND payment_method != 'creditnote'))").group("payment_method")
+
+ credit_sql = SalePayment.select("SUM(sale_payments.outstanding_amount) as amount_due")
+ .where(" sale_id='#{sale_data.sale_id}' AND payment_method ='creditnote'")
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Amount Due ", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(credit_sql.first.amount_due.abs, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
+
+ end
+ move_down line_move
+ sale_payments.each do |payment|
+ y_position = cursor
+ if payment.payment_method == "paypar"
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Redeem Payment", :size => self.item_font_size,:align => :left
+ end
+ else
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left
+ end
+ end
+
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
+ end
+ move_down line_move
+ end
+ if sale_data.amount_received > 0
+ y_position = cursor
+ move_down line_move
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Change Amount", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
+ end
+ # move_down line_move
+ end
+ end
+
+ # show member information
+ def member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance)
+ if rebate_amount != nil
+ if rebate_amount["status"] == true
+ stroke_horizontal_rule
+ total = 0
+ balance = 0
+ rebate_balance =0
+ redeem = 0
+ redeem_count = 0
+ rebate_amount["data"].each do |res|
+ total = total + res["balance"]
+ #total redeem amount
+ if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Redeem"
+ redeem = redeem + res["withdraw"]
+ balance = balance + res["balance"]
+ end
+ #end Total redem
+ #total Rebate Earn
+ if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebateAccount" && res["status"]== "Rebate"
+
+ rebate_balance = rebate_balance + res["deposit"]
+
+ move_down line_move
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Rebate Earn", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
+ end
+
+ end
+ # Total Rebate Amount if birthday
+ if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebatebonusAccount" && res["status"]== "Rebate"
+ rebate_balance = rebate_balance + res["deposit"]
+ move_down line_move
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
+ end
+ end
+ #end Total rebate if birthday
+ end
+
+ move_down line_move
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Redeem Amount", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right
+ end
+
+ if current_balance != nil
+ move_down line_move
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Old Balance", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right
+ end
+ end
+
+ end
+ end
+
+ if member_info["status"] == true && member_info["data"].present?
+ total_balance = 0
+ member_info["data"].each do |res|
+
+ if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
+ total_balance = total_balance + res["balance"]
+
+ end
+ end
+ move_down line_move
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Total Balance", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{number_format(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
+ end
+ end
+
+ end
+
+ def customer(customer_name)
+ # move_down line_move
+ y_position = cursor
+ #move_down line_move
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Customer Name", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{ customer_name }" , :size => self.item_font_size,:align => :right
+ end
+ move_down line_move
+ stroke_horizontal_rule
+ end
+
+
+ def discount_account(discount_price_by_accounts,precision,delimiter)
+
+ stroke_horizontal_rule
+ move_down line_move
+ y_position = cursor
+ discount_price_by_accounts.each do |ipa|
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "(" + "#{ number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right
+ end
+ move_down line_move
+ end
+ end
+
+ def items_account(item_price_by_accounts,precision,delimiter)
+ stroke_horizontal_rule
+ move_down line_move
+ y_position = cursor
+ item_price_by_accounts.each do |ipa|
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.label_width) do
+ text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
+ text "#{number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
+ end
+ move_down line_move
+ end
+ end
+
+ def show_other_charges_amount(other_amount,precision,delimiter)
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.label_width) do
+ text "Other Charges", :size => self.item_font_size,:align => :left
+ end
+ bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
+ text "#{number_format(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
+ end
+ move_down line_move
+ end
+
+ #individual payment per person
+ def individual_payment(sale_data, survey, precision, delimiter)
+ # per_person = sale_data.grand_total.to_f / survey.total_customer.to_i
+ per_person = sale_data.grand_total.to_f / survey.to_i
+ stroke_horizontal_rule
+ move_down line_move
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.label_width+50) do
+ text "Split Bill for #{sale_data.equal_persons} persons", :size => self.item_font_size+1,:align => :left
+ end
+
+ bounding_box([0,y_position], :width =>self.label_width) do
+ move_down 15
+ text "Amount Due (per person)", :size => self.item_font_size,:align => :left
+ end
+
+ bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
+ move_down 15
+ text "#{number_format(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right
+ end
+ end
+
+ def sign(sale_data)
+ query = sale_data.sale_payments
+ .merge(SalePayment.where.not(payment_method: 'creditnote')
+ .or(SalePayment.where.not(SalePayment.arel_table[:payment_amount].lteq(sale_data.sale_payments.joins(:sale_audit).sum(:payment_amount)))))
+
+ query.each do |payment|
+ if payment.payment_method == "creditnote"
+
+ y_position = cursor
+ stroke_horizontal_rule
+
+ bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
+ move_down 70
+ stroke_horizontal_rule
+ end
+
+ bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
+ move_down 73
+ text "Approved By" , :size => self.item_font_size,:align => :center
+ end
+ break;
+ end
+ end
+ if sale_data.payment_status == "foc" || sale_data.payment_status == "waste" || sale_data.payment_status == "spoile"
+
+ y_position = cursor
+ stroke_horizontal_rule
+
+ bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
+ move_down 70
+ stroke_horizontal_rule
+ end
+
+ if sale_data.payment_status == "foc"
+ bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
+ move_down 73
+ text "Acknowledged By" , :size => self.item_font_size,:align => :center
+ end
+ elsif sale_data.payment_status == "waste" || sale_data.payment_status == "spoile"
+ bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
+ move_down 73
+ text "Approved By" , :size => self.item_font_size,:align => :center
+ end
+ end
+ end
+
+ end
+
+ def shop_note(shop)
+ move_down line_move
+ stroke_horizontal_rule
+ move_down line_move
+
+ move_down line_move
+ y_position = cursor
+
+ text "#{shop.note}", :size => self.item_font_size, :align => :left
+
+ move_down line_move
+ end
+
+ def kbzpay_qr_generator(status, qr_code)
+ if status == 'Frt'
+ move_down line_move
+ move_down line_move
+ text "Scan to pay with KBZ Pay", :size => self.header_font_size, :align => :center
+ move_down line_move
+ print_qr_code(qr_code, pos: [39, cursor], extent: 161, stroke: false, dot: 1000)
+ move_down line_move
+ text "This QR code will be expired after 20 minutes.", :size => self.item_font_size, :align => :center
+ move_down line_move
+ move_down line_move
+ end
+ end
+
+ def footer(printed_status)
+ move_down line_move
+ stroke_horizontal_rule
+ move_down line_move
+
+ move_down line_move
+ y_position = cursor
+ bounding_box([0, y_position], :width =>self.label_width) do
+ text "#{printed_status}",:style => :bold, :size => header_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do
+ text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size,:align => :left
+ end
+
+ move_down line_move
+ end
+
+ #start card sale trans data
+ def card_sale_data(card_data)
+ if card_data != nil && !card_data.empty?
+ move_down line_move
+ stroke_horizontal_rule
+ move_down line_move
+
+ y_position = cursor
+ card_data.each do |data|
+ if data['app'] == 'CUP'
+ data['app'] = 'UNIONPAY'
+ elsif data['app'] == 'MASTERCARD'
+ data['app'] = 'MASTER'
+ end
+ text "DATE/TIME: #{data['res_date']} #{data['res_time']} ", :size => @item_font_size, :align => :left
+ text "BATCH NUM: #{data['batch_no']} TRACE#: #{data['trace']}",:size => @item_font_size, :align => :left
+ text "RREF NUM: #{data['ref_no']} APPR CODE: #{data['app_code']} ",:size => @item_font_size, :align => :left
+ text "TID: #{data['tid']} ",:size => @item_font_size, :align => :left
+ text "#{data['app']} #{data['pan']} ",:size => @item_font_size, :align => :left
+ end
+ end
+ end
+
+ #start card balance data
+ def card_balance_data(card_balance_amount)
+ if card_balance_amount > 0
+ move_down line_move
+ stroke_horizontal_rule
+ move_down line_move
+
+ y_position = cursor
+ bounding_box([0, y_position], :width =>self.label_width) do
+ text "Card Balance: ",:style => :bold, :size => header_font_size,:align => :left
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
+ text "#{card_balance_amount}" , :size => self.item_font_size,:align => :right
+ end
+ end
+ end
+
+ #check ReceiptBillAltName included
+ def show_alt_name
+ bill_alt_name = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
+ status = false
+ if !bill_alt_name.empty?
+ bill_alt_name.each do |alt_name|
+ if alt_name[0] == 'ReceiptBillAltName'
+ if alt_name[1] == '1'
+ status = true
+ else
+ status = false
+ end
+ end
+ end
+ end
+ return status
+ end
+end
From 06647b39176101d7ed18d6aee88d65c9b7591c64 Mon Sep 17 00:00:00 2001
From: NyanLinHtut
Date: Mon, 24 Feb 2020 18:16:20 +0630
Subject: [PATCH 08/28] fixed inventroy item balance
---
app/models/inventory_definition.rb | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb
index fc535853..a1e06505 100755
--- a/app/models/inventory_definition.rb
+++ b/app/models/inventory_definition.rb
@@ -82,7 +82,9 @@ class InventoryDefinition < ApplicationRecord
end
def self.get_by_category(filter)
- least_stock = StockJournal.select(:balance).joins("JOIN inventory_definitions ON stock_journals.item_code = inventory_definitions.item_code").order(:id => :desc).limit(1).to_sql
+ least_stock = StockJournal.select(:balance)
+ .where('stock_journals.updated_at = (SELECT MAX(stock_journals.updated_at) FROM stock_journals WHERE (stock_journals.item_code = inventory_definitions.item_code))')
+ .order(:id => :desc).to_sql
@inventory_definitions = InventoryDefinition.select("inventory_definitions.*,
(CASE WHEN sj.credit IS NULL THEN 0 ELSE sj.credit END) as credit,
From d403585f12935a800ba496f8d89faaa1859d1c72 Mon Sep 17 00:00:00 2001
From: yarzar_code
Date: Tue, 25 Feb 2020 13:58:10 +0630
Subject: [PATCH 09/28] print credit payment
---
.../origami/payments_controller.rb | 110 ++----------------
app/models/printer/receipt_printer.rb | 6 +-
app/pdf/receipt_bill_pdf.rb | 29 +++--
3 files changed, 36 insertions(+), 109 deletions(-)
diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb
index 787ea62c..8a186075 100755
--- a/app/controllers/origami/payments_controller.rb
+++ b/app/controllers/origami/payments_controller.rb
@@ -89,7 +89,7 @@ class Origami::PaymentsController < BaseOrigamiController
path = request.fullpath
latest_order_no = nil
is_kbz = params[:is_kbz]
- credit_pdf = Lookup.find_by_lookup_type("credit_pdf")
+
if saleObj = Sale.find(sale_id)
sale_items = SaleItem.get_all_sale_items(sale_id)
@@ -107,7 +107,7 @@ class Origami::PaymentsController < BaseOrigamiController
sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user)
end
- if !path.include? ("credit_payment")
+
rebate_amount = nil
# For Cashier by Zone
@@ -201,108 +201,18 @@ class Origami::PaymentsController < BaseOrigamiController
item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
other_amount = SaleItem.calculate_other_charges(sale_items)
-
+ credit_pdf = Lookup.find_by_lookup_type("credit_pdf")
+ if (path.include? ("credit_payment")) && !credit_pdf.nil? && credit_pdf.value.to_i == 1
+ printed_status = 'credit_payment'
+ else
+ printed_status = 'Paid'
+ end
+
printer = Printer::ReceiptPrinter.new(print_settings)
- filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
+ filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, printed_status,current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
#end
- elsif (path.include? ("credit_payment")) && !credit_pdf.nil? && credit_pdf.value.to_i == 1
- rebate_amount = nil
- # For Cashier by Zone
- booking = saleObj.booking
-
- if current_user.role == 'cashier'
- cashier_terminal = current_user.cashier_terminal
- elsif booking.dining_facility
- cashier_terminal = booking.cashier_terminal_by_dining_facility
- end
-
- cashier_terminal ||= saleObj.cashier_terminal_by_shift_sale
-
- if booking.dining_facility
- ActionCable.server.broadcast(
- "order_channel",
- table: booking.dining_facility,
- type: 'payment',
- from: getCloudDomain
- )
- end
-
- # For Print
-
- if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf
- unique_code = "ReceiptBillA5Pdf"
- else
- unique_code = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code
- end
-
- customer = saleObj.customer
-
- # get member information
- rebate = MembershipSetting.find_by_rebate(1)
- credit_data = SalePayment.find_by_sale_id_and_payment_method(sale_id,'creditnote')
-
- if customer.membership_id != nil && rebate && credit_data.nil?
- member_info = Customer.get_member_account(customer)
-
- if member_info["status"] == true
- rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
- current_balance = SaleAudit.paymal_search(sale_id)
- end
- end
-
- #orders print out
- if type == "quick_service"
- if booking.dining_facility_id.present?
- table_id = booking.dining_facility_id
- else
- table_id = 0
- end
-
- latest_order = booking.booking_orders.order("order_id DESC").limit(1).first()
- if !latest_order.nil?
- latest_order_no = latest_order.order_id
- end
-
- booking.booking_orders.each do |order|
-
- oqs = OrderQueueStation.new
- oqs.pay_process_order_queue(order.order_id, table_id)
-
- assign_order = AssignedOrderItem.assigned_order_item_by_job(order.order_id)
- from = getCloudDomain #get sub domain in cloud mode
- ActionCable.server.broadcast "order_queue_station_channel",order: assign_order,from:from
- end
-
- end
-
- #for card sale data
- card_data = Array.new
- card_sale_trans_ref_no = Sale.getCardSaleTrans(sale_id)
- if !card_sale_trans_ref_no.nil?
- card_sale_trans_ref_no.each do |cash_sale_trans|
- card_res_date = cash_sale_trans.res_date.strftime("%Y-%m-%d").to_s
- card_res_time = cash_sale_trans.res_time.strftime("%H:%M").to_s
- card_no = cash_sale_trans.pan.last(4)
- card_no = card_no.rjust(19,"**** **** **** ")
- card_data.push({'res_date' => card_res_date, 'res_time' => card_res_time, 'batch_no' => cash_sale_trans.batch_no, 'trace' => cash_sale_trans.trace, 'pan' => card_no, 'app' => cash_sale_trans.app, 'tid' => cash_sale_trans.terminal_id, 'app_code' => cash_sale_trans.app_code, 'ref_no' => cash_sale_trans.ref_no, 'mid' => cash_sale_trans.merchant_id})
- end
- end
-
- #card_balance amount for Paymal payment
- card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id)
-
- # get printer info
- print_settings = PrintSetting.find_by_unique_code(unique_code)
- # Calculate Food and Beverage Total
- item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items)
- discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
- other_amount = SaleItem.calculate_other_charges(sale_items)
-
- printer = Printer::ReceiptPrinter.new(print_settings)
- filename, sale_receipt_no, printer_name = printer.print_credit(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
- end
if !saleObj.nil?
# InventoryJob.perform_now(self.id)
# InventoryDefinition.calculate_product_count(saleObj)
diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb
index d456c980..ff3132d0 100755
--- a/app/models/printer/receipt_printer.rb
+++ b/app/models/printer/receipt_printer.rb
@@ -119,11 +119,15 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
if count == 1
filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf"
pdf.render_file filename
- if printed_status != 'Paid'
+ if printed_status != 'Paid' && printed_status != 'credit_payment'
#no print in cloud server
if ENV["SERVER_MODE"] != "cloud"
self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name)
end
+ elsif printed_status == 'credit_payment'
+ filename = directory_name + "/receipt_bill_credit_#{sale_data.receipt_no}.pdf"
+ pdf.render_file filename
+ self.print(directory_name + "/receipt_bill_credit_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name)
end
else
filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf"
diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb
index 5f698b8f..198c0a12 100755
--- a/app/pdf/receipt_bill_pdf.rb
+++ b/app/pdf/receipt_bill_pdf.rb
@@ -50,7 +50,7 @@ class ReceiptBillPdf < Prawn::Document
cashier_info(sale_data, customer_name, latest_order_no)
line_items(sale_items,precision,delimiter)
- all_total(sale_data,precision,delimiter)
+ all_total(sale_data,precision,delimiter,printed_status)
if member_info != nil
@@ -94,6 +94,9 @@ class ReceiptBillPdf < Prawn::Document
end
if kbz_pay_status
+ if printed_status == 'credit_payment'
+ printed_status = 'Paid'
+ end
kbzpay_qr_generator(printed_status, qr_code)
end
@@ -305,7 +308,7 @@ class ReceiptBillPdf < Prawn::Document
end
- def all_total(sale_data,precision,delimiter)
+ def all_total(sale_data,precision,delimiter,printed_status)
move_down line_move
item_name_width = self.item_width
y_position = cursor
@@ -432,15 +435,20 @@ class ReceiptBillPdf < Prawn::Document
end
move_down line_move
- sale_payment(sale_data,precision,delimiter)
+ sale_payment(sale_data,precision,delimiter,printed_status)
end
- def sale_payment(sale_data,precision,delimiter)
+ def sale_payment(sale_data,precision,delimiter,printed_status)
stroke_horizontal_rule
#move_down line_move
# sql = "SELECT SUM(payment_amount)
# FROM sale_payments where payment_method='creditnote'
- # and sale_id='#{sale_data.sale_id}'"
+ # and sale_id='#{sale_data.sale_id}'"
+
+ if printed_status == 'credit_payment'
+ sale_payments = SalePayment.select(:payment_amount, :payment_method, :updated_at)
+ .where("sale_id = '#{sale_data.sale_id}' AND payment_method != 'creditnote'")
+ else
sql = SalePayment.select("(SUM(payment_amount))").where("payment_method='creditnote' and sale_id='#{sale_data.sale_id}'").to_sql
# sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
# FROM sale_payments where payment_method='creditnote'
@@ -458,13 +466,16 @@ class ReceiptBillPdf < Prawn::Document
where sa.sale_id='#{sale_data.sale_id}')) = 0
THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id)
.group("payment_method")
-
+ end
+
sale_payments.each do |payment|
y_position = cursor
if payment.payment_method == "paypar"
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "Redeem Payment", :size => self.item_font_size,:align => :left
- end
+ end
+ elsif printed_status == 'credit_payment'
+ text "#{payment.payment_method.capitalize} Payment on #{payment.updated_at.strftime('%d-%m-%Y')}", :left_margin => -10, :size => self.item_font_size,:align => :left
else
bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left
@@ -741,7 +752,9 @@ class ReceiptBillPdf < Prawn::Document
move_down line_move
stroke_horizontal_rule
move_down line_move
-
+ if printed_status == 'credit_payment'
+ printed_status = 'Paid'
+ end
move_down line_move
y_position = cursor
bounding_box([0, y_position], :width =>self.label_width) do
From 7e2ec07b86aa96a22f2ab9819c4a4780c8a8992f Mon Sep 17 00:00:00 2001
From: yarzar_code
Date: Tue, 25 Feb 2020 14:04:39 +0630
Subject: [PATCH 10/28] credit payment readme
---
README.md | 437 +++++++++++++++++++++++++-----------------------------
1 file changed, 204 insertions(+), 233 deletions(-)
diff --git a/README.md b/README.md
index 67fcc40b..b8c1cb62 100755
--- a/README.md
+++ b/README.md
@@ -4,161 +4,151 @@ SXRestuarant is a new Dedicate project for SmartSales Restaurant. It is improvem
Things you may want to cover:
-* Ruby version
-ruby 2.4.1p111
+- Ruby version
+ ruby 2.4.1p111
-* Membership Details
-Osaka =>
- Auth Token => wu8YvlLmah0CL => New => v3
- => rj0MJ0XI5GsKZehE => Old => v2
- => code2lab => Old
+- Membership Details
+ Osaka =>
+ Auth Token => wu8YvlLmah0CL => New => v3
+ => rj0MJ0XI5GsKZehE => Old => v2
+ => code2lab => Old
- Merchant account => RxzaYyAGzm7VqAZ4hKnv
- Campaign Id => {"campaign_type_id": 5}
+ Merchant account => RxzaYyAGzm7VqAZ4hKnv
+ Campaign Id => {"campaign_type_id": 5}
BITP
- Auth Token => pZBHXEFbGNj/G => New => V3
- iua0SjUHzRaQw
- => rj0MJ0XI5GsKZehE => Old => V2
- => code2lab => Old
+Auth Token => pZBHXEFbGNj/G => New => V3
+iua0SjUHzRaQw
+=> rj0MJ0XI5GsKZehE => Old => V2
+=> code2lab => Old
- Merchant account => vWSsseoZCzxd6xcNf_uS
+ Merchant account => vWSsseoZCzxd6xcNf_uS
Campaign Id => {"campaign_type_id": 1}
java -jar ~/Documents/Jade.jar http://192.168.1.88:3002
java -jar ~/Documents/c2l_jade.jar http://192.168.1.151:3002
Person and Extra Time
- category_code = SPL... //for menu categories special
- 1) must create Person in settings/accounts
- 2) must create Adult and Child in settings/item_attributes
- 3) must be PSA_[a-z/0-9] for Adult and PSC_[a-z/0-9] for Child in settings/menu_categories/[cat_id]/simple_menu_items
- 3) must be PSAI_[a-z/0-9] for Adult and PSCI_[a-z/0-9] for Child in settings/simple_menu_items/[item_id]/menu_item_instances
+category_code = SPL... //for menu categories special
+
+1. must create Person in settings/accounts
+2. must create Adult and Child in settings/item_attributes
+3. must be PSA*[a-z/0-9] for Adult and PSC*[a-z/0-9] for Child in settings/menu_categories/[cat_id]/simple_menu_items
+4. must be PSAI*[a-z/0-9] for Adult and PSCI*[a-z/0-9] for Child in settings/simple_menu_items/[item_id]/menu_item_instances
For Extra Time
- item_instance_code
- * must start with 'Ext'[a..z]'_'[1..100]
- * note : don't add character after '_'
+item_instance_code
+
+- must start with 'Ext'[a..z]'\_'[1..100]
+- note : don't add character after '\_'
For Order Printing
- 1)) ********* Order Pdf *********
- 1) settings/print_settings
- (a) Unique Code => OrderItemPdf & OrderSummaryPdf
- (b) Font is present => {Header font size:11, Item Font Size:9}
- Font is blank => {Header font size:12, Item Font Size:10}
- 2)) ********* Order Set Pdf *********
- 1) settings/print_settings
- (a) Unique Code => OrderSetItemPdf & OrderSummarySetPdf
- (b) Font is present => {Header font size:11, Item Font Size:9}
- Font is blank => {Header font size:12, Item Font Size:10}
- 3)) ********* Order Slim Pdf *********
- 1) settings/print_settings
- (a) Unique Code => OrderItemSlimPdf & OrderSummarySlimPdf
- (b) Font is present => {Header font size:11, Item Font Size:9}
- Font is blank => {Header font size:12, Item Font Size:10}
- 4)) ********* Order Customise PDF *********
- 1) settings/print_settings
- (a) Unique Code => OrderItemCustomisePdf & OrderSummaryCustomisePdf
- (b) Can change Header font size and Item Font Size as you like
- 5)) ********* Order Set Pdf *********
- 1) settings/print_settings
- (a) Unique Code => OrderSetItemCustomisePdf & OrderSummarySetCustomisePdf
- (b) Can change Header font size and Item Font Size as you like
- 6)) ********* Order Slim Customise PDF
- 1) settings/print_settings
- (a) Unique Code => OrderItemSlimCustomisePdf & OrderSummarySlimCustomisePdf
- (b) Can change Header font size and Item Font Size as you like
-For Check in-out Printing
- ********* Check in-out Pdf *********
- 1) settings/print_settings
- (a) Unique Code => CheckInOutPdf
- (b) Heading Space => 5
+1)) \***\*\*\*\*** Order Pdf \***\*\*\*\*** 1) settings/print_settings
+(a) Unique Code => OrderItemPdf & OrderSummaryPdf
+(b) Font is present => {Header font size:11, Item Font Size:9}
+Font is blank => {Header font size:12, Item Font Size:10}
+2)) \***\*\*\*\*** Order Set Pdf \***\*\*\*\*** 1) settings/print_settings
+(a) Unique Code => OrderSetItemPdf & OrderSummarySetPdf
+(b) Font is present => {Header font size:11, Item Font Size:9}
+Font is blank => {Header font size:12, Item Font Size:10}
+3)) \***\*\*\*\*** Order Slim Pdf \***\*\*\*\*** 1) settings/print_settings
+(a) Unique Code => OrderItemSlimPdf & OrderSummarySlimPdf
+(b) Font is present => {Header font size:11, Item Font Size:9}
+Font is blank => {Header font size:12, Item Font Size:10}
+4)) \***\*\*\*\*** Order Customise PDF \***\*\*\*\*** 1) settings/print_settings
+(a) Unique Code => OrderItemCustomisePdf & OrderSummaryCustomisePdf
+(b) Can change Header font size and Item Font Size as you like
+5)) \***\*\*\*\*** Order Set Pdf \***\*\*\*\*** 1) settings/print_settings
+(a) Unique Code => OrderSetItemCustomisePdf & OrderSummarySetCustomisePdf
+(b) Can change Header font size and Item Font Size as you like
+6)) \***\*\*\*\*** Order Slim Customise PDF 1) settings/print_settings
+(a) Unique Code => OrderItemSlimCustomisePdf & OrderSummarySlimCustomisePdf
+(b) Can change Header font size and Item Font Size as you like
+For Check in-out Printing \***\*\*\*\*** Check in-out Pdf \***\*\*\*\*** 1) settings/print_settings
+(a) Unique Code => CheckInOutPdf
+(b) Heading Space => 5
For ReceiptBillA5Pdf
- *** change ReceiptBillPdf to ReceiptBillA5Pdf
- 1) settings/print_settings , width:680, height:1450, Header font Size:16, Item font size:14
- 2) settings/lookups => { type:print_settings, name:ReceiptBillA5Pdf, value:1 }
+\*\*\* change ReceiptBillPdf to ReceiptBillA5Pdf 1) settings/print_settings , width:680, height:1450, Header font Size:16, Item font size:14 2) settings/lookups => { type:print_settings, name:ReceiptBillA5Pdf, value:1 }
-For ReceiptBillAltName options
- 1) settings/lookups => { type:print_settings, name:ReceiptBillAltName, value:1 }
+For ReceiptBillAltName options 1) settings/lookups => { type:print_settings, name:ReceiptBillAltName, value:1 }
For Using Star Printer
- *** Need to change these print settings
- 1) settings/print_settings/unique_code => OrderItemStarPdf
- 2) settings/print_settings/unique_code => ReceiptBillStarPdf
- 3) settings/print_settings/unique_code => SaleItemsStarPdf
- *** Other print settings aren't need to change.
+**_ Need to change these print settings 1) settings/print_settings/unique_code => OrderItemStarPdf 2) settings/print_settings/unique_code => ReceiptBillStarPdf 3) settings/print_settings/unique_code => SaleItemsStarPdf
+_** Other print settings aren't need to change.
-For Show Sale Items Summary at CloseCashierPrint
- 1) settings/print_settings
- a) Check => Shift Sale Items
+For Show Sale Items Summary at CloseCashierPrint 1) settings/print_settings
+a) Check => Shift Sale Items
-For Show/Hide AddOrder Button in QuickService
- 1) settings/lookups => {type:quickservice_add_order, name: QuickServiceAddOrder, value:1 OR 0}
+For Show/Hide AddOrder Button in QuickService 1) settings/lookups => {type:quickservice_add_order, name: QuickServiceAddOrder, value:1 OR 0}
-For Show Print Button in ReceiptNo Report
- 1) settings/lookups => {type:reprint_receipt, name: Reprint Receipt in Report, value:1}
+For Show Print Button in ReceiptNo Report 1) settings/lookups => {type:reprint_receipt, name: Reprint Receipt in Report, value:1}
+
+For Credit Payment Receipt Pdf and Print
+
+1. settings/lookups => { type:credit_pdf, name: Credit Pdf, value:1 }
For Bank Integration setting
- 1) rake db:migrate for card_sale_trans, card_settle_trans
- 2) settings/lookups => { type:bank_integration, name: Bank Integration, value:1 }
+
+1. rake db:migrate for card_sale_trans, card_settle_trans
+2. settings/lookups => { type:bank_integration, name: Bank Integration, value:1 }
For checkout time and checkout alert time
- 1) checkout time => { type: checkout_time, name: 9:00 AM - 12:00 PM, value: 120 }
- 2) checkout alert time => { type: checkout_alert_time, name: 8:00 AM - 12:00 PM, value: 60 }
- * you can add multiple record for checkout time and checkout alert time
- * type must be 'checkout_time' and 'checkout_alert_time'
- * you can change name and value
- * name must be time range [12hr => 8:30 AM - 1:45 PM, 24hr => 8:00 - 13:45]
- * value must be minutes[60]
+
+1. checkout time => { type: checkout_time, name: 9:00 AM - 12:00 PM, value: 120 }
+2. checkout alert time => { type: checkout_alert_time, name: 8:00 AM - 12:00 PM, value: 60 }
+
+- you can add multiple record for checkout time and checkout alert time
+- type must be 'checkout_time' and 'checkout_alert_time'
+- you can change name and value
+- name must be time range [12hr => 8:30 AM - 1:45 PM, 24hr => 8:00 - 13:45]
+- value must be minutes[60]
For call waiter pdf
- * Backend > Printer > Print Settings > New
- i) Name : Calling Waiter
- ii) Unique Code: CallWaiterPdf
- iii)Template: ...
- iv) Font: Zawgyi-One
- v) Printer: #printer name
-Membership Actions SQL
- * update membership_actions set additional_parameter='{\"campaign_type_id\":5}' where id=10;
+- Backend > Printer > Print Settings > New
+ i) Name : Calling Waiter
+ ii) Unique Code: CallWaiterPdf
+ iii)Template: ...
+ iv) Font: Zawgyi-One
+ v) Printer: #printer name
-SQL Update after rake clear:data runned
- * update seed_generators
- i) TableBooking, Order, OrderItem, sale, SaleOrder, SaleItem, SaleTax, SalePayment, SaleAudit, AssignedOrderItem => { current:0, next:0 }
- ** Note :: do not update Customer
+Membership Actions SQL \* update membership_actions set additional_parameter='{\"campaign_type_id\":5}' where id=10;
+
+SQL Update after rake clear:data runned \* update seed_generators
+i) TableBooking, Order, OrderItem, sale, SaleOrder, SaleItem, SaleTax, SalePayment, SaleAudit, AssignedOrderItem => { current:0, next:0 }
+\*\* Note :: do not update Customer
Change type in mysql
- *run if you got font error for Myanmar, Chinese, etc...
- => ALTER TABLE [table_name] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci #for table
- => ALTER DATABASE [database_name] CHARACTER SET utf8 COLLATE utf8_unicode_ci #for database
+\*run if you got font error for Myanmar, Chinese, etc...
+=> ALTER TABLE [table_name] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci #for table
+=> ALTER DATABASE [database_name] CHARACTER SET utf8 COLLATE utf8_unicode_ci #for database
-For split bill
- 1) settings/lookups => { type:split_bill, name:SplitBill, value:1 }
+For split bill 1) settings/lookups => { type:split_bill, name:SplitBill, value:1 }
-For Sidekiq
- 1) If you want to use sidekiq
- => Create New Lookups => lookup_type = sidekiq, Name = sidekiq , Value = 1 or 0
+For Sidekiq 1) If you want to use sidekiq
+=> Create New Lookups => lookup_type = sidekiq, Name = sidekiq , Value = 1 or 0
-For Clear Menu
- 1) rake clear:menu # menu,menu item,menu category,menu item instance,account,item option,item attribute,item set
+For Clear Menu 1) rake clear:menu # menu,menu item,menu category,menu item instance,account,item option,item attribute,item set
For Check CUp status
-###please open
+###please open
sudo cat /etc/sudoers
+
### cope and parse
+
%superuser ALL=(ALL) NOPASSWD: ALL
<---- Extra Fields Script ----->
DROP TABLE IF EXISTS `display_images`;
CREATE TABLE `display_images` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT,
- `shop_id` int(11) DEFAULT NULL,
- `image` blob,
- `created_by` varchar(255) DEFAULT NULL,
- `created_at` datetime NOT NULL,
- `updated_at` datetime NOT NULL,
- PRIMARY KEY (`id`)
+`id` bigint(20) NOT NULL AUTO_INCREMENT,
+`shop_id` int(11) DEFAULT NULL,
+`image` blob,
+`created_by` varchar(255) DEFAULT NULL,
+`created_at` datetime NOT NULL,
+`updated_at` datetime NOT NULL,
+PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE customers
@@ -190,118 +180,104 @@ ADD COLUMN group_type VARCHAR(255) after name;
<---- Extra Fields Script ----->
For CloseCashierCustomisePdf in lookups
- *** change CloseCashierPdf to CloseCashierCustomisePdf
- 1) settings/print_settings
- 2) settings/lookups => { type:print_settings, name: CloseCashierCustomisePdf, value:1 }
+\*\*\* change CloseCashierPdf to CloseCashierCustomisePdf 1) settings/print_settings 2) settings/lookups => { type:print_settings, name: CloseCashierCustomisePdf, value:1 }
<---- Extra Fields Script ----->
For MoveTablePdf in lookups
- *** Both Table and Room Moving ***
- 1) settings/lookups => { type:print_settings, name: MoveTablePdf, value:1 }
+**_ Both Table and Room Moving _** 1) settings/lookups => { type:print_settings, name: MoveTablePdf, value:1 }
-For MoveTablePdf in print settings
- * Backend > Printer > Print Settings > New
- i) Name : Move Table
- ii) Unique Code: MoveTablePdf
- iii)Template: ...
- iv) Font: Zawgyi-One v) Printer: #printer name
+For MoveTablePdf in print settings \* Backend > Printer > Print Settings > New
+i) Name : Move Table
+ii) Unique Code: MoveTablePdf
+iii)Template: ...
+iv) Font: Zawgyi-One v) Printer: #printer name
-/* Tax Profile Group Types in lookups */
-1) settings/lookups => { type:tax_profiles, name: Cashier, value:cashier }
-2) settings/lookups => { type:tax_profiles, name: Quick Service, value: quick_service }
-3) settings/lookups => { type:tax_profiles, name: Doemal, value: doemal }
-4) settings/lookups => { type:tax_profiles, name: Food Court, value: food_court }
-/* Tax Profile Group Types in lookups */
+/_ Tax Profile Group Types in lookups _/
-/*Receipt Pdf View in lookups */
-1) settings/lookups => { type:ReceiptPdfView, name: Receipt Pdf View, value:1 or 0 }
+1. settings/lookups => { type:tax_profiles, name: Cashier, value:cashier }
+2. settings/lookups => { type:tax_profiles, name: Quick Service, value: quick_service }
+3. settings/lookups => { type:tax_profiles, name: Doemal, value: doemal }
+4. settings/lookups => { type:tax*profiles, name: Food Court, value: food_court }
+ /* Tax Profile Group Types in lookups \_/
+
+/_Receipt Pdf View in lookups _/
+
+1. settings/lookups => { type:ReceiptPdfView, name: Receipt Pdf View, value:1 or 0 }
=> 1 is active and 0 is in-active
-Add Kitchen Role of Employee
- => 1) settings/lookups => { type:employee_roles, name: Kitchen, value:kitchen }
+Add Kitchen Role of Employee
+=> 1) settings/lookups => { type:employee_roles, name: Kitchen, value:kitchen }
-Add Base URL for DOEMAL
- 1) settings/lookups => { type:order_reservation, name: BaseURL, value:'{doemal url}' }
- 2) settings/lookups => { type:order_reservation, name: Token, value:'{doemal token}' }
+Add Base URL for DOEMAL 1) settings/lookups => { type:order_reservation, name: BaseURL, value:'{doemal url}' } 2) settings/lookups => { type:order_reservation, name: Token, value:'{doemal token}' }
Add Feature for Dine-in Cashier
- ** '0' means can not use dine-in cashier and '1' means can use dine-in cashier **
- => settings/lookups => { type:dinein_cashier, name: DineInCashier, value:'{0 or 1}' }
+** '0' means can not use dine-in cashier and '1' means can use dine-in cashier **
+=> settings/lookups => { type:dinein_cashier, name: DineInCashier, value:'{0 or 1}' }
Add Feature for Quick Service
- ** '0' means can not use quick service and '1' means can use quick service **
- => settings/lookups => { type:quick_service, name: QuickService, value:'{0 or 1}' }
+** '0' means can not use quick service and '1' means can use quick service **
+=> settings/lookups => { type:quick_service, name: QuickService, value:'{0 or 1}' }
Add Feature for Order and Reservation
- ** '0' means can not use order reservation and '1' means can use order reservation **
- => settings/lookups => { type:order_reservation, name: OrderReservation, value:'{0 or 1}' }
+** '0' means can not use order reservation and '1' means can use order reservation **
+=> settings/lookups => { type:order_reservation, name: OrderReservation, value:'{0 or 1}' }
-For Price 0 in receipt bill
- 2) settings/lookups => { type:show_price, name:Show Price, value:1 }
+For Price 0 in receipt bill 2) settings/lookups => { type:show_price, name:Show Price, value:1 }
+For Price 0 in receipt bill 2) settings/lookups => { type:order_by, name:Order By, value:name }
-For Price 0 in receipt bill
- 2) settings/lookups => { type:order_by, name:Order By, value:name }
+For Aston Request => Gift Voucher 1) settings/payment_method_settings => {payment_method:'GiftVoucher', is_active:true, ...}
-For Aston Request => Gift Voucher
- 1) settings/payment_method_settings => {payment_method:'GiftVoucher', is_active:true, ...}
-
-For Login expiry time
- 1) settings/lookups => {type:expity_time, name:login, value: {minutes}}
- * value should be minute only (30 / 60 / 120 / etc.)
+For Login expiry time 1) settings/lookups => {type:expity_time, name:login, value: {minutes}} \* value should be minute only (30 / 60 / 120 / etc.)
Menu Image (Import guideline)
- => First, check shop_code, is there in shops table and prefix shop_code in image name?
- => You all must do this step
- * If there is shop_code in shops table (mark in one place/ note and set NULL for this record for a while) and prefix shop_code for image name (like (121_ABC.png)), and copy and paste images into Application/[sxrestaurant]/public/image/menu_images.
- * If there is shop_code/ no shop_code in shops table but no prefix in image name (* skip set NULL step) , copy and paste images into Application/…./image/menu_images.
- => Second, import [menu].xlsx file in /settings/menus and then checked image is uploaded into Application/[sxrestaurant]/public/image/menu_images and insert into menu_items table in database.
- => Last, if shop has shop_code, update marked/noted shop_code into shops table again.
+ => First, check shop_code, is there in shops table and prefix shop_code in image name?
+ => You all must do this step
+ * If there is shop_code in shops table (mark in one place/ note and set NULL for this record for a while) and prefix shop_code for image name (like (121_ABC.png)), and copy and paste images into Application/[sxrestaurant]/public/image/menu_images.
+ * If there is shop_code/ no shop_code in shops table but no prefix in image name (* skip set NULL step) , copy and paste images into Application/…./image/menu_images.
+ => Second, import [menu].xlsx file in /settings/menus and then checked image is uploaded into Application/[sxrestaurant]/public/image/menu_images and insert into menu_items table in database.
+ => Last, if shop has shop_code, update marked/noted shop_code into shops table again.
-For Edit Order Open & Close
- 1) settings/lookups => {type:edit_order, name:EditOrderOrigami, value: {1 or 0}}
+For Edit Order Open & Close 1) settings/lookups => {type:edit_order, name:EditOrderOrigami, value: {1 or 0}}
-For Dashboard Settings for supervisor and cashier
- 1) settings/lookups => {type:dashboard_settings, name:supervisor, value: {1 or 0}}
- 2) settings/lookups => {type:dashboard_settings, name:cashier, value: {1 or 0}}
+For Dashboard Settings for supervisor and cashier 1) settings/lookups => {type:dashboard_settings, name:supervisor, value: {1 or 0}} 2) settings/lookups => {type:dashboard_settings, name:cashier, value: {1 or 0}}
-For Customer Settings On/Off
- 1) settings/lookups => {type:customer_settings, name:create, value: {1 or 0}}
+For Customer Settings On/Off 1) settings/lookups => {type:customer_settings, name:create, value: {1 or 0}}
-For TaxProfiles On/Off
- 1) settings/lookups => {type:changable_tax, name:change, value: {1 or 0}}
+For TaxProfiles On/Off 1) settings/lookups => {type:changable_tax, name:change, value: {1 or 0}}
-For Add Kitchen Role
- 1) settings/lookups => {type:employee_roles, name:Kitchen, value:kitchen}
+For Add Kitchen Role 1) settings/lookups => {type:employee_roles, name:Kitchen, value:kitchen}
For Food Court Settings On/Off
- ** '0' means can not use food court and '1' means can use food court **
- => settings/lookups => { type:food_court, name: FoodCourt, value:'{0 or 1}' }
+** '0' means can not use food court and '1' means can use food court **
+=> settings/lookups => { type:food_court, name: FoodCourt, value:'{0 or 1}' }
For Number Formats
- Precision
- => settings/lookups => { lookup_type: number_format, name: precision, value: {0..2} }
- Delimiter
- => settings/lookups => { lookup_type: number_format, name: delimiter, value: { ',', '\u0020', '', ... }
- Strip insignificant zeros
- => settings/lookups => { lookup_type: number_format, name: strip_insignificant_zeros,
- value: {true: => ['1', 't', 'true', 'on', 'y', 'yes'], false: => ['0', 'f', 'false', 'off', 'n', 'no', ...] }
+Precision
+=> settings/lookups => { lookup_type: number_format, name: precision, value: {0..2} }
+Delimiter
+=> settings/lookups => { lookup_type: number_format, name: delimiter, value: { ',', '\u0020', '', ... }
+Strip insignificant zeros
+=> settings/lookups => { lookup_type: number_format, name: strip_insignificant_zeros,
+value: {true: => ['1', 't', 'true', 'on', 'y', 'yes'], false: => ['0', 'f', 'false', 'off', 'n', 'no', ...] }
For Booking checkin time limit
- settings/lookups =>
- { lookup_type: checkin_time_limit, name: CheckinTimeLimit, value: total hours before checkout (e.g., '48')) }
+settings/lookups =>
+{ lookup_type: checkin_time_limit, name: CheckinTimeLimit, value: total hours before checkout (e.g., '48')) }
-/* Customer Types in lookups */
-1) settings/lookups => { type:customer_type, name: Dinein, value:Dinein }
-2) settings/lookups => { type:customer_type, name: Takeaway, value: Takeaway }
-3) settings/lookups => { type:customer_type, name: Doemal, value: Doemal }
-4) settings/lookups => { type:customer_type, name: FoodCourt, value: FoodCourt }
-/* Tax Profile Group Types in lookups */
+/_ Customer Types in lookups _/
+
+1. settings/lookups => { type:customer_type, name: Dinein, value:Dinein }
+2. settings/lookups => { type:customer_type, name: Takeaway, value: Takeaway }
+3. settings/lookups => { type:customer_type, name: Doemal, value: Doemal }
+4. settings/lookups => { type:customer*type, name: FoodCourt, value: FoodCourt }
+ /* Tax Profile Group Types in lookups \_/
For Online Order Receipt Setting
-1) settings/lookups => { type:order_reservation, name:ReceiptBill, value: {0 or 1} }
-2) settings/print_settings => {name: ReceiptBillOrder, unique_code: ReceiptBillOrderPdf, ....}
+
+1. settings/lookups => { type:order_reservation, name:ReceiptBill, value: {0 or 1} }
+2. settings/print_settings => {name: ReceiptBillOrder, unique_code: ReceiptBillOrderPdf, ....}
For Close Cashier Print Settings
settings/lookups => {type:close_cashier_print, name:CloseCashierPrint, value: {0 or 1} }
@@ -315,99 +291,94 @@ settings/lookups => {type:show_total_before_tax, name:Show Total Before Tax, val
For Using Staff Meal
settings/lookups => { type:customer_type, name: Staff, value:Staff }
-* ToDo list
+- ToDo list
1. Migration
2. Quick Service
3. Order & Reservation
+- System Dependencies
-* System Dependencies
+- Configuration
-* Configuration
+- Database creation
-* Database creation
+- Database initialization
-* Database initialization
+- How to run the test suite
-* How to run the test suite
-
-* Services (job queues, cache servers, search engines, etc.)
-
-* Deployment instructions
+- Services (job queues, cache servers, search engines, etc.)
+- Deployment instructions
* Features
1. OQS
- 1. Filter
- 2. Order Item to each Stations
- 3. Edit Order Item
+ 1. Filter
+ 2. Order Item to each Stations
+ 3. Edit Order Item
2. Origami(Sale)
- 1. Sale
- 2. Add Customer for membership
- 3. Discount and Member Discount for Sale
- 4. Assign Commissioner
- 5. Add other charges to Sale
+ 1. Sale
+ 2. Add Customer for membership
+ 3. Discount and Member Discount for Sale
+ 4. Assign Commissioner
+ 5. Add other charges to Sale
3. CRM
- 1. Customer Management
+ 1. Customer Management
- 2. Queue Management
+ 2. Queue Management
4. Backend
- 1. Dining Setup
+ 1. Dining Setup
- 2. Queue Station Setup
+ 2. Queue Station Setup
- 3. Menu Setup
+ 3. Menu Setup
- 4. Cashier Terminal Setup
+ 4. Cashier Terminal Setup
- 5. Tax Profile Setup
+ 5. Tax Profile Setup
- 6. Printer Setup
+ 6. Printer Setup
- 7. Payment Integration
+ 7. Payment Integration
- 8. Employee Management
+ 8. Employee Management
- 9. Promotion Setup
+ 9. Promotion Setup
- 10. Commissioner Setup
+ 10. Commissioner Setup
- 11. Membership Integration
-
-
-5. Inventory
+ 11. Membership Integration
+5) Inventory
6. Report
-
-* UI Standard
+- UI Standard
1. Layout
- 1. 2-Column => Main Content - col-9, Information - col-3
- 2. 3-Column => Sub Lint - col-2, Main Content - col-7, Information - col-3
+ 1. 2-Column => Main Content - col-9, Information - col-3
+ 2. 3-Column => Sub Lint - col-2, Main Content - col-7, Information - col-3
- > Pixel
+ > Pixel
- Main Header Bar - height => 50 px
- Side Navigation - Weight => 230 px
- Main Content Padding => 15 px
+ Main Header Bar - height => 50 px
+ Side Navigation - Weight => 230 px
+ Main Content Padding => 15 px
2. Color
- > BUTTON
+ > BUTTON
- 1. Submit/Add/Edit/Confirm buttons => btn-primary (theme color)
- 2. Show/Detail Buttons => btn-info
- 3. Delete => btn-delete
- 4. Cancel/Back => btn-default
+ 1. Submit/Add/Edit/Confirm buttons => btn-primary (theme color)
+ 2. Show/Detail Buttons => btn-info
+ 3. Delete => btn-delete
+ 4. Cancel/Back => btn-default
From 93b293af0697ebd8154a9df98a5e3e2f35f2c6f0 Mon Sep 17 00:00:00 2001
From: NyanLinHtut
Date: Wed, 26 Feb 2020 16:50:10 +0630
Subject: [PATCH 11/28] fixed inventroy
---
app/models/inventory_definition.rb | 49 ++++++++++++++++--------------
1 file changed, 26 insertions(+), 23 deletions(-)
diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb
index a1e06505..a7f91477 100755
--- a/app/models/inventory_definition.rb
+++ b/app/models/inventory_definition.rb
@@ -1,5 +1,8 @@
class InventoryDefinition < ApplicationRecord
+ has_many :stock_journals
+ has_one :menu_item_instance, foreign_key: "item_instance_code", primary_key: "item_code"
+
scope :active, -> {where(:is_active => true)}
def self.calculate_product_count(saleObj=nil,saleobj_after_req_bill=nil)
@@ -69,7 +72,7 @@ class InventoryDefinition < ApplicationRecord
end
def self.search_by_category(cat_id)
- @inventory_definitions = InventoryDefinition.select("inventory_definitions.*,
+ inventory_definitions = InventoryDefinition.select("inventory_definitions.*,
mi.name as item_name,mii.item_instance_name as instance_name," +
"mi.item_code as item_code,mii.item_instance_code as instance_code," +
"mc.name as menu_category_name,mc.id as menu_category_id ")
@@ -82,29 +85,29 @@ class InventoryDefinition < ApplicationRecord
end
def self.get_by_category(filter)
- least_stock = StockJournal.select(:balance)
- .where('stock_journals.updated_at = (SELECT MAX(stock_journals.updated_at) FROM stock_journals WHERE (stock_journals.item_code = inventory_definitions.item_code))')
- .order(:id => :desc).to_sql
+ least_stock = StockJournal.select(:inventory_definition_id, :credit, :debit, :balance)
+ .joins("JOIN (
+ #{StockJournal.select("item_code, MAX(created_at) created_at").group(:item_code).to_sql}) last_stock_journals
+ ON last_stock_journals.item_code = stock_journals.item_code
+ AND last_stock_journals.created_at = stock_journals.created_at").to_sql
- @inventory_definitions = InventoryDefinition.select("inventory_definitions.*,
- (CASE WHEN sj.credit IS NULL THEN 0 ELSE sj.credit END) as credit,
- (CASE WHEN sj.debit IS NULL THEN 0 ELSE sj.debit END) as debit,
- (#{least_stock}) as balance,"+
- "acc.title as account_name,mi.name as item_name,
- mii.item_instance_name as instance_name," +
- "mc.name as menu_category_name,mc.id as menu_category_id "
- )
- .joins(" LEFT JOIN stock_journals sj ON sj.inventory_definition_id=inventory_definitions.id")
- .joins("JOIN menu_item_instances mii ON mii.item_instance_code = inventory_definitions.item_code" +
- " JOIN menu_items mi ON mi.id = mii.menu_item_id" +
- " JOIN menu_categories mc ON mc.id = mi.menu_category_id ")
- .joins(" JOIN accounts acc ON acc.id = mi.account_id")
- .where("inventory_definitions.item_code LIKE ? OR inventory_definitions.min_order_level LIKE ?
- OR inventory_definitions.max_stock_level LIKE ? OR sj.balance LIKE ? OR mi.name LIKE ?
- OR mii.item_instance_name LIKE ? OR mc.name LIKE ?","%#{filter}%","%#{filter}%","%#{filter}%",
- "%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%")
- .group("mi.menu_category_id,inventory_definitions.item_code")
- .order("balance asc, mi.name asc,acc.title desc,mi.menu_category_id desc")
+ inventory_definitions = InventoryDefinition
+ .select("inventory_definitions.*,
+ stock_journals.credit as credit,
+ stock_journals.debit as debit,
+ stock_journals.balance as balance,
+ accounts.title as account_name,
+ menu_items.name as item_name,
+ menu_item_instances.item_instance_name as instance_name,
+ menu_categories.name as menu_category_name,
+ menu_categories.id as menu_category_id")
+ .joins("LEFT JOIN (#{least_stock}) stock_journals on stock_journals.inventory_definition_id = inventory_definitions.id")
+ .joins(menu_item_instance: { menu_item: [:menu_category, :account]})
+ .where("inventory_definitions.item_code LIKE :filter OR inventory_definitions.min_order_level LIKE :filter
+ OR inventory_definitions.max_stock_level LIKE :filter OR stock_journals.balance LIKE :filter OR menu_items.name LIKE :filter
+ OR menu_item_instances.item_instance_name LIKE :filter OR menu_categories.name LIKE :filter", filter: "%#{filter}%")
+ .group("menu_items.menu_category_id, inventory_definitions.item_code")
+ .order("balance asc, menu_items.name asc, accounts.title desc, menu_items.menu_category_id desc")
end
end
From aff75a6ec84ac4b530e2b5b19bda5d66c19dbbbc Mon Sep 17 00:00:00 2001
From: yarzar_code
Date: Wed, 26 Feb 2020 17:40:34 +0630
Subject: [PATCH 12/28] Delete credit_bill_pdf.rb
---
app/models/printer/receipt_printer.rb | 9 -
app/pdf/credit_bill_pdf.rb | 838 --------------------------
2 files changed, 847 deletions(-)
delete mode 100644 app/pdf/credit_bill_pdf.rb
diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb
index ff3132d0..ac3e6f3f 100755
--- a/app/models/printer/receipt_printer.rb
+++ b/app/models/printer/receipt_printer.rb
@@ -142,16 +142,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
Rails.logger.debug "############## filename::" + filename
return filename, sale_data.receipt_no, cashier_terminal.printer_name
end
- #print credit
- def print_credit(printer_settings, kbz_pay_status, qr_code, cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,order_reservation)
- pdf = CreditBillPdf.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)
-
- directory_name = 'public/receipts'
- filename = directory_name + "/credit_receipt_bill_#{sale_data.receipt_no}.pdf"
- pdf.render_file filename
- self.print(directory_name + "/credit_receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name)
- end
# stock check
def print_stock_check_result(print_settings,stockcheck, stockcheck_items,checker_name, shop_details)
pdf = StockResultPdf.new(print_settings,stockcheck, stockcheck_items,checker_name, shop_details)
diff --git a/app/pdf/credit_bill_pdf.rb b/app/pdf/credit_bill_pdf.rb
deleted file mode 100644
index f2ce2469..00000000
--- a/app/pdf/credit_bill_pdf.rb
+++ /dev/null
@@ -1,838 +0,0 @@
-require 'prawn/measurement_extensions'
-class CreditBillPdf < Prawn::Document
- include NumberFormattable
-
- attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move
-
- def initialize(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount)
- self.page_width = printer_settings.page_width
- self.page_height = printer_settings.page_height
- self.header_font_size = printer_settings.header_font_size.to_i
- self.item_font_size = printer_settings.item_font_size.to_i
- self.margin = 0
- self.price_width = 60
- self.qty_width = 25
- self.total_width = 60
- self.item_width = self.page_width - ((self.qty_width + self.price_width + self.total_width))
- self.item_height = 15
- self.item_description_width = (self.page_width-5) / 2
- self.label_width = 100
-
- self.description_width = 150
- self.price_num_width = 50
- self.line_move = 2
- # @item_width = self.page_width.to_i / 2
- # @qty_width = @item_width.to_i / 3
- # @double = @qty_width * 1.3
- # @half_qty = @qty_width / 2
- #setting page margin and width
- super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height])
-
- # db font setup
- if printer_settings.font != ""
- font_families.update("#{printer_settings.font}" => {
- :normal => "public/fonts/#{printer_settings.font}.ttf",
- :italic => "public/fonts/#{printer_settings.font}.ttf",
- :bold => "public/fonts/#{printer_settings.font}.ttf",
- :bold_italic => "public/fonts/#{printer_settings.font}.ttf"
- })
-
- font "#{printer_settings.font}"
- fallback_fonts ["Courier", "Helvetica", "Times-Roman"]
- end
- # font "public/fonts/Zawgyi-One.ttf"
- # font "public/fonts/padauk.ttf"
-
- header(shop_details)
-
- stroke_horizontal_rule
-
- cashier_info(sale_data, customer_name, latest_order_no)
- line_items(sale_items,precision,delimiter)
- all_total(sale_data,precision,delimiter)
-
-
- if member_info != nil
- member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance)
- end
-
- customer(customer_name)
-
- #start card sale trans data
- if card_data != nil
- card_sale_data(card_data)
- end
- #end card sale trans data
- #start card blanace amount
- if !card_balance_amount.nil?
- card_balance_data(card_balance_amount)
- end
- #end card blanace amount
-
- if discount_price_by_accounts.length > 0 && shop_details.show_account_info
- discount_account(discount_price_by_accounts,precision,delimiter)
- end
-
- if shop_details.show_account_info
- items_account(item_price_by_accounts,precision,delimiter)
- if other_charges_amount
- show_other_charges_amount(other_charges_amount,precision,delimiter)
- end
- end
-
- #start for individual payment
- if !sale_data.equal_persons.nil?
- individual_payment(sale_data,sale_data.equal_persons, precision, delimiter)
- end
- #end for individual payment
-
- sign(sale_data)
-
- if shop_details.note && !shop_details.note.nil?
- shop_note(shop_details)
- end
-
- if kbz_pay_status
- kbzpay_qr_generator(printed_status, qr_code)
- end
-
- footer(printed_status)
- end
-
- def header (shop_details)
- text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center
- move_down line_move
- text "#{shop_details.address}", :size => self.item_font_size,:align => :center
- # move_down self.item_height
- move_down line_move
- text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center
- move_down line_move
-
- stroke_horizontal_rule
- end
-
- def cashier_info(sale_data, customer_name, latest_order_no)
- if latest_order_no.nil?
- move_down line_move
- text "Booking : #{ sale_data.bookings[0].booking_id }", :size => self.header_font_size+2,:align => :left
- move_down line_move
- end
- move_down line_move
- if !latest_order_no.nil?
- move_down line_move
- text "OrderNo : #{ latest_order_no }", :size => self.header_font_size,:align => :left
- end
- move_down line_move
-
- # move_down 2
- y_position = cursor
- bounding_box([0,y_position], :width =>self.description_width + self.price_num_width, :height => self.item_height) do
- text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left
- end
-
- if sale_data.bookings[0].dining_facility_id.to_i > 0
- bounding_box([self.description_width - 2,y_position], :width => self.price_num_width, :height => self.item_height) do
- text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right
- end
- end
-
- move_down line_move
- y_position = cursor
- bounding_box([0, y_position], :width =>self.label_width, :height => self.item_height) do
- text "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left
- end
- bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do
- text "C: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :right
- end
-
- move_down line_move
- # credit_date = SalePayment.select(:created_at).where("sale_id = '#{sale_data.sale_id}' AND payment_method = 'creditnote'")
- y_position = cursor
- if sale_data.bookings[0].dining_facility_id.to_i > 0
- time = sale_data.receipt_date.strftime('%d-%m-%Y') +"("+ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') +"-"+ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p')+")"
- else
- time = sale_data.receipt_date.strftime('%d-%m-%Y %H:%M %p')
- end
-
- bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do
- text "Credit Date : #{ time }",:size => self.item_font_size,:align => :left
- end
- move_down line_move
-
- y_position = cursor
- time = DateTime.now
- time = time.strftime('%d-%m-%Y (%H:%M %p)')
-
-
- bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do
- text "Payment Date : #{ time }",:size => self.item_font_size,:align => :left
- end
-
- # bounding_box([self.item_description_width,y_position], :width =>self.label_width+5) do
- # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') }
- # - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') })" ,
- # :size => self.item_font_size,:align => :right
- # end
- move_down line_move
- stroke_horizontal_rule
- end
-
- def line_items(sale_items,precision,delimiter)
- if precision.to_i > 0
- item_label_qty_front_width = (self.item_width+self.price_width) + 5
- item_label_qty_end_width = self.qty_width + 4
- item_label_total_front_width = (self.item_width+self.price_width) + 10
- item_label_total_end_width = self.total_width + 9
- else
- self.item_width = self.item_width.to_i + 8
- item_label_qty_front_width = (self.item_width+self.price_width) + 8
- item_label_qty_end_width = self.qty_width + 7
- item_label_total_front_width = (self.item_width+self.price_width) + 5
- item_label_total_end_width = self.total_width + 4
- end
- move_down line_move
- y_position = cursor
- move_down line_move
- pad_top(15) {
- # @item_width.to_i + @half_qty.to_i
- text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix
- text_box "Price", :at =>[(self.item_width),y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
- text_box "Qty", :at =>[item_label_qty_front_width,y_position], :width => item_label_qty_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
- text_box "Total", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
- }
- # move_down line_move
- stroke_horizontal_rule
- add_line_item_row(sale_items,precision,delimiter)
- end
-
- def add_line_item_row(sale_items,precision,delimiter)
-
- if precision.to_i > 0
- item_name_width = (self.item_width+self.price_width)
- item_qty_front_width = (self.item_width+self.price_width) + 5
- item_qty_end_width = self.qty_width + 4
- item_total_front_width = item_name_width + 10
- item_total_end_width = self.total_width + 9
- else
- item_name_width = (self.item_width+self.price_width)
- item_qty_front_width = item_name_width + 8
- item_qty_end_width = self.qty_width + 7
- item_total_front_width = item_name_width + 5
- item_total_end_width = self.total_width + 4
- end
-
- y_position = cursor
- move_down line_move
- @sub_total = 0.0
- total_qty = 0.0
- show_price = Lookup.find_by_lookup_type("show_price")
- sale_items.each do |item|
- # check for item not to show
-
- if item.status != 'Discount' && item.qty > 0
- if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0
- total_qty += item.qty
- else
- if item.price != 0
- total_qty += item.qty
- end
- end
- end
-
- product_name = item.product_name
-
- # if item.status = 'promotion' && (item.remark =='promotion nett price' || item.remark == 'promotion discount')
- # sub_total += -item.price #(item.qty*item.unit_price) - comment for room charges
- # qty = -item.qty
- # total_price = -item.price #item.qty*item.unit_price - comment for room charges
- # price = -item.unit_price
- # else
- @sub_total += item.price #(item.qty*item.unit_price) - comment for room charges
- qty = item.qty
- total_price = item.price #item.qty*item.unit_price - comment for room charges
- price = item.unit_price
-
- # end
-
-
- if !show_price.nil? && show_price.value.to_i>0
- item_row(item,precision,delimiter,product_name,price,qty ,total_price)
- else
- if item.price != 0
- item_row(item,precision,delimiter,product_name,price,qty ,total_price)
- end
- end
-
- end
-
- stroke_horizontal_rule
-
- move_down line_move
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do
- text "Sub Total", :size => self.item_font_size,:align => :left
- end
- text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
- text_box "#{number_format(@sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
- end
-
- def item_row(item,precision,delimiter,product_name,price,qty ,total_price)
- if precision.to_i > 0
- item_name_width = (self.item_width+self.price_width)
- item_qty_front_width = (self.item_width+self.price_width) + 5
- item_qty_end_width = self.qty_width + 4
- item_total_front_width = item_name_width + 10
- item_total_end_width = self.total_width + 9
- else
- item_name_width = (self.item_width+self.price_width)
- item_qty_front_width = item_name_width + 8
- item_qty_end_width = self.qty_width + 7
- item_total_front_width = item_name_width + 5
- item_total_end_width = self.total_width + 4
- end
- y_position = cursor
-
- pad_top(15) {
- bounding_box([0,y_position], :width =>self.item_width) do
- text "#{product_name}", :size => self.item_font_size,:align => :left
- end
- # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size
- text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
- text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
- text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
-
- if show_alt_name
- if !(item.product_alt_name).empty?
- move_down 2
- # font("public/fonts/NotoSansCJKtc-Regular.ttf") do
- text "(#{item.product_alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true
- # end
- end
- end
- move_down line_move
- }
-
-
- end
-
- def all_total(sale_data,precision,delimiter)
- move_down line_move
- item_name_width = self.item_width
- y_position = cursor
- if sale_data.discount_type == 'member_discount'
- dis_type = "Member Discount:"
- else
- dis_type = "Overall Discount:"
- end
-
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "#{ dis_type }", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right
- end
-
- service_tax_desc = ""
- service_tax_amount = 0
- service_tax_rate = 0
- com_tax_desc = ""
- com_tax_amount = 0
- com_tax_rate = 0
- if sale_data.sale_taxes.length > 0
- incl_tax = ""
- if sale_data.tax_type == "inclusive"
- incl_tax = "Incl."
- end
-
- find_lookup = Lookup.find_by_lookup_type('show_total_before_tax')
- if find_lookup.nil? || find_lookup == nil
- lookup = Lookup.new(lookup_type: 'show_total_before_tax', name: 'Show Total Before Tax', value: '0')
- lookup.save
- end
- check_lookup_type = Lookup.find_by_lookup_type('show_total_before_tax')
- if check_lookup_type.value == '1'
- sale_data.sale_taxes.each do |st|
- if (st.tax_name.include? "Service")
- service_tax_desc = st.tax_name
- service_tax_amount = st.tax_payable_amount
- if incl_tax
- service_tax_rate = st.tax_rate.to_i
- end
- end
- if (st.tax_name.include? "Commercial")
- com_tax_desc = st.tax_name
- com_tax_amount = st.tax_payable_amount
- if incl_tax
- com_tax_rate = st.tax_rate.to_i
- end
- end
- end
- move_down line_move
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "#{ service_tax_desc } (#{incl_tax} #{ service_tax_rate }%)", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
- end
- move_down line_move
- y_position = cursor
- stroke_horizontal_rule
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Total Before Tax", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{service_tax_amount.to_i + @sub_total.to_i}" , :size => self.item_font_size,:align => :right
- end
- move_down line_move
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "#{ com_tax_desc } (#{incl_tax} #{ com_tax_rate.to_i }%)", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
- end
- else
- sale_data.sale_taxes.each do |st|
- move_down line_move
- y_position = cursor
-
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
- end
- end
- end
- else
-
- end
-
- # move_down 5
- # y_position = cursor
-
- # bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- # text "Total Tax", :size => self.item_font_size,:align => :left
- # end
- # bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- # text "( " +"#{sale_data.total_tax}" +" )" , :size => self.item_font_size,:align => :right
- # end
-
- if sale_data.rounding_adjustment != 0.0
- move_down line_move
- y_position = cursor
-
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Rounding Adjustment", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right
- end
- end
-
- move_down line_move
- y_position = cursor
- move_down line_move
- bounding_box([0,y_position], :width =>self.item_description_width) do
- text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right
- end
- move_down line_move
-
- sale_payment(sale_data,precision,delimiter)
- end
-
- def sale_payment(sale_data,precision,delimiter)
- stroke_horizontal_rule
- #move_down line_move
- # sql = "SELECT SUM(payment_amount)
- # FROM sale_payments where payment_method='creditnote'
- # and sale_id='#{sale_data.sale_id}'"
- sql = SalePayment.select("(SUM(payment_amount))").where("payment_method='creditnote' and sale_id='#{sale_data.sale_id}'").to_sql
- # sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount)
- # FROM sale_payments where payment_method='creditnote'
- # and sale_id='#{sale_data.sale_id}'"
- sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ("
- sql1 += sql
-
- # sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method")
- # .where("(CASE WHEN ((#{sql}) - (#{sql1})
- # ELSE SUM(payment_amount) END
- # FROM sale_payments
- # JOIN sales s ON s.sale_id=sale_payments.sale_id
- # JOIN sale_audits sa
- # ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id
- # where sa.sale_id='#{sale_data.sale_id}')) = 0
- # THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id)
- # .group("payment_method")
-
- sale_payments = SalePayment.select("SUM(payment_amount) as payment_amount, payment_method")
- .where("sale_id = '#{sale_data.sale_id}' AND ((payment_method = 'cash' AND outstanding_amount = 0) OR (payment_method != 'cash' AND payment_method != 'creditnote'))").group("payment_method")
-
- credit_sql = SalePayment.select("SUM(sale_payments.outstanding_amount) as amount_due")
- .where(" sale_id='#{sale_data.sale_id}' AND payment_method ='creditnote'")
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Amount Due ", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(credit_sql.first.amount_due.abs, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
-
- end
- move_down line_move
- sale_payments.each do |payment|
- y_position = cursor
- if payment.payment_method == "paypar"
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Redeem Payment", :size => self.item_font_size,:align => :left
- end
- else
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left
- end
- end
-
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
- end
- move_down line_move
- end
- if sale_data.amount_received > 0
- y_position = cursor
- move_down line_move
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Change Amount", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
- end
- # move_down line_move
- end
- end
-
- # show member information
- def member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance)
- if rebate_amount != nil
- if rebate_amount["status"] == true
- stroke_horizontal_rule
- total = 0
- balance = 0
- rebate_balance =0
- redeem = 0
- redeem_count = 0
- rebate_amount["data"].each do |res|
- total = total + res["balance"]
- #total redeem amount
- if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Redeem"
- redeem = redeem + res["withdraw"]
- balance = balance + res["balance"]
- end
- #end Total redem
- #total Rebate Earn
- if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebateAccount" && res["status"]== "Rebate"
-
- rebate_balance = rebate_balance + res["deposit"]
-
- move_down line_move
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Rebate Earn", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
- end
-
- end
- # Total Rebate Amount if birthday
- if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebatebonusAccount" && res["status"]== "Rebate"
- rebate_balance = rebate_balance + res["deposit"]
- move_down line_move
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
- end
- end
- #end Total rebate if birthday
- end
-
- move_down line_move
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Redeem Amount", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right
- end
-
- if current_balance != nil
- move_down line_move
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Old Balance", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right
- end
- end
-
- end
- end
-
- if member_info["status"] == true && member_info["data"].present?
- total_balance = 0
- member_info["data"].each do |res|
-
- if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
- total_balance = total_balance + res["balance"]
-
- end
- end
- move_down line_move
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Total Balance", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{number_format(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
- end
- end
-
- end
-
- def customer(customer_name)
- # move_down line_move
- y_position = cursor
- #move_down line_move
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Customer Name", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{ customer_name }" , :size => self.item_font_size,:align => :right
- end
- move_down line_move
- stroke_horizontal_rule
- end
-
-
- def discount_account(discount_price_by_accounts,precision,delimiter)
-
- stroke_horizontal_rule
- move_down line_move
- y_position = cursor
- discount_price_by_accounts.each do |ipa|
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "(" + "#{ number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right
- end
- move_down line_move
- end
- end
-
- def items_account(item_price_by_accounts,precision,delimiter)
- stroke_horizontal_rule
- move_down line_move
- y_position = cursor
- item_price_by_accounts.each do |ipa|
- y_position = cursor
- bounding_box([0,y_position], :width =>self.label_width) do
- text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
- text "#{number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
- end
- move_down line_move
- end
- end
-
- def show_other_charges_amount(other_amount,precision,delimiter)
- y_position = cursor
- bounding_box([0,y_position], :width =>self.label_width) do
- text "Other Charges", :size => self.item_font_size,:align => :left
- end
- bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
- text "#{number_format(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right
- end
- move_down line_move
- end
-
- #individual payment per person
- def individual_payment(sale_data, survey, precision, delimiter)
- # per_person = sale_data.grand_total.to_f / survey.total_customer.to_i
- per_person = sale_data.grand_total.to_f / survey.to_i
- stroke_horizontal_rule
- move_down line_move
- y_position = cursor
- bounding_box([0,y_position], :width =>self.label_width+50) do
- text "Split Bill for #{sale_data.equal_persons} persons", :size => self.item_font_size+1,:align => :left
- end
-
- bounding_box([0,y_position], :width =>self.label_width) do
- move_down 15
- text "Amount Due (per person)", :size => self.item_font_size,:align => :left
- end
-
- bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
- move_down 15
- text "#{number_format(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right
- end
- end
-
- def sign(sale_data)
- query = sale_data.sale_payments
- .merge(SalePayment.where.not(payment_method: 'creditnote')
- .or(SalePayment.where.not(SalePayment.arel_table[:payment_amount].lteq(sale_data.sale_payments.joins(:sale_audit).sum(:payment_amount)))))
-
- query.each do |payment|
- if payment.payment_method == "creditnote"
-
- y_position = cursor
- stroke_horizontal_rule
-
- bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
- move_down 70
- stroke_horizontal_rule
- end
-
- bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
- move_down 73
- text "Approved By" , :size => self.item_font_size,:align => :center
- end
- break;
- end
- end
- if sale_data.payment_status == "foc" || sale_data.payment_status == "waste" || sale_data.payment_status == "spoile"
-
- y_position = cursor
- stroke_horizontal_rule
-
- bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
- move_down 70
- stroke_horizontal_rule
- end
-
- if sale_data.payment_status == "foc"
- bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
- move_down 73
- text "Acknowledged By" , :size => self.item_font_size,:align => :center
- end
- elsif sale_data.payment_status == "waste" || sale_data.payment_status == "spoile"
- bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
- move_down 73
- text "Approved By" , :size => self.item_font_size,:align => :center
- end
- end
- end
-
- end
-
- def shop_note(shop)
- move_down line_move
- stroke_horizontal_rule
- move_down line_move
-
- move_down line_move
- y_position = cursor
-
- text "#{shop.note}", :size => self.item_font_size, :align => :left
-
- move_down line_move
- end
-
- def kbzpay_qr_generator(status, qr_code)
- if status == 'Frt'
- move_down line_move
- move_down line_move
- text "Scan to pay with KBZ Pay", :size => self.header_font_size, :align => :center
- move_down line_move
- print_qr_code(qr_code, pos: [39, cursor], extent: 161, stroke: false, dot: 1000)
- move_down line_move
- text "This QR code will be expired after 20 minutes.", :size => self.item_font_size, :align => :center
- move_down line_move
- move_down line_move
- end
- end
-
- def footer(printed_status)
- move_down line_move
- stroke_horizontal_rule
- move_down line_move
-
- move_down line_move
- y_position = cursor
- bounding_box([0, y_position], :width =>self.label_width) do
- text "#{printed_status}",:style => :bold, :size => header_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do
- text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size,:align => :left
- end
-
- move_down line_move
- end
-
- #start card sale trans data
- def card_sale_data(card_data)
- if card_data != nil && !card_data.empty?
- move_down line_move
- stroke_horizontal_rule
- move_down line_move
-
- y_position = cursor
- card_data.each do |data|
- if data['app'] == 'CUP'
- data['app'] = 'UNIONPAY'
- elsif data['app'] == 'MASTERCARD'
- data['app'] = 'MASTER'
- end
- text "DATE/TIME: #{data['res_date']} #{data['res_time']} ", :size => @item_font_size, :align => :left
- text "BATCH NUM: #{data['batch_no']} TRACE#: #{data['trace']}",:size => @item_font_size, :align => :left
- text "RREF NUM: #{data['ref_no']} APPR CODE: #{data['app_code']} ",:size => @item_font_size, :align => :left
- text "TID: #{data['tid']} ",:size => @item_font_size, :align => :left
- text "#{data['app']} #{data['pan']} ",:size => @item_font_size, :align => :left
- end
- end
- end
-
- #start card balance data
- def card_balance_data(card_balance_amount)
- if card_balance_amount > 0
- move_down line_move
- stroke_horizontal_rule
- move_down line_move
-
- y_position = cursor
- bounding_box([0, y_position], :width =>self.label_width) do
- text "Card Balance: ",:style => :bold, :size => header_font_size,:align => :left
- end
- bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
- text "#{card_balance_amount}" , :size => self.item_font_size,:align => :right
- end
- end
- end
-
- #check ReceiptBillAltName included
- def show_alt_name
- bill_alt_name = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
- status = false
- if !bill_alt_name.empty?
- bill_alt_name.each do |alt_name|
- if alt_name[0] == 'ReceiptBillAltName'
- if alt_name[1] == '1'
- status = true
- else
- status = false
- end
- end
- end
- end
- return status
- end
-end
From d8a99d2d76c55c303924dc93200a97d89e8f4232 Mon Sep 17 00:00:00 2001
From: NyanLinHtut
Date: Wed, 4 Mar 2020 16:11:34 +0630
Subject: [PATCH 13/28] fixed sub category at inventory
---
.../inventory_definitions/_form.html.erb | 90 +++++++++++++++++--
1 file changed, 85 insertions(+), 5 deletions(-)
diff --git a/app/views/inventory/inventory_definitions/_form.html.erb b/app/views/inventory/inventory_definitions/_form.html.erb
index 66497616..00a62045 100644
--- a/app/views/inventory/inventory_definitions/_form.html.erb
+++ b/app/views/inventory/inventory_definitions/_form.html.erb
@@ -172,11 +172,31 @@
});
$(document).ready(function () {
- var menus = JSON.parse(localStorage.getItem("menus"));;
- if (menus != null) {
- menu_cache_append(menus);
- }else{
- $("#menu_data").removeClass("hidden");
+ // var menus = JSON.parse(localStorage.getItem("menus"));;
+ // if (menus != null) {
+ // menu_cache_append(menus);
+ // }else{
+ // getAllMenu();
+ // $("#menu_data").removeClass("hidden");
+ // }
+ getAllMenu();
+
+ function getAllMenu(){
+ $.ajax({
+ type: "GET",
+ url: '/origami/get_all_menu',
+ data: {},
+ success:function(result){
+ var menus = JSON.stringify(result);
+ localStorage.setItem("menus", menus);
+ if (result != null ) {
+ menu_cache_append(result);
+ $("#loading_wrapper").hide();
+ $("#oqs_loading_wrapper").css("display", "none");
+ $(".page-loader-wrapper").css("display", "none");
+ }
+ }
+ });
}
function menu_cache_append(menus){
@@ -328,6 +348,66 @@
});
//End menu category Click
+ //show menu item list when click menu category
+ function show_sub_category_list(url,sub_category,menu_id){
+
+ var sub_category_list = $('.sub_category_list');
+ sub_category_list.empty();
+
+ menus = JSON.parse(localStorage.getItem("menus"));
+ if (menus != null) {
+ for(var j in menus) {
+ var categories = menus[j]["categories"];
+ for(var ii in categories) {
+ if (menu_id == categories[ii]["parent_id"]) {
+ $(sub_category).removeClass('hidden');
+ row = '' ;
+ $(sub_category).append(row);
+ }
+ }
+ }
+ }else{
+ if (type != -1 && modify_order != -1) {
+ var url = "../../../addorders/"+url;
+ }if(modify_order== -1 && type != -1){
+ var url = 'addorders/'+url;
+ }
+ if (type ==-1 && modify_order == -1){
+ var url = url;
+ }
+ //Start Ajax
+ $.ajax({
+ type: "GET",
+ url: url,
+ data: {},
+ dataType: "json",
+ success: function(data) {
+ var sub_category_list = $('.sub_category_list');
+ sub_category_list.empty();
+ data = data.sub_category;
+ if (data.length > 0) {
+ // if ((sub_category.hasClass('hidden'))) {
+ $(sub_category).removeClass('hidden');
+ // }else{
+ // $(sub_category).addClass('hidden');
+ // }
+ for(var i in data) {
+
+ row = '' ;
+ $(sub_category).append(row);
+ //end is_sub_item false
+ }
+ }
+ }
+ });
+ //end Ajax
+ }
+ }
+
//click menu sidebar menu category
$(document).on('click', '.menu_sub_category', function(event){
// event.preventDefault();
From 5f93048a156f583a8b9c2f98c95592f66a2b1823 Mon Sep 17 00:00:00 2001
From: yarzar_code
Date: Wed, 25 Mar 2020 14:24:43 +0630
Subject: [PATCH 14/28] FOC fixed
---
app/models/card_sale_tran.rb | 1 -
app/models/card_settle_tran.rb | 1 -
app/models/sale.rb | 41 +++++++++++++--------------
app/models/sale_payment.rb | 52 ++++++++++++++++++++--------------
4 files changed, 50 insertions(+), 45 deletions(-)
diff --git a/app/models/card_sale_tran.rb b/app/models/card_sale_tran.rb
index ea76e45a..ba624d0e 100644
--- a/app/models/card_sale_tran.rb
+++ b/app/models/card_sale_tran.rb
@@ -67,7 +67,6 @@ class CardSaleTran < ApplicationRecord
shift_closed_at As closing_date,")
.order("shift_sales.id DESC")
return query = query.where("shift_sales.shift_started_at >= ?" , from)
- byebug
end
end
\ No newline at end of file
diff --git a/app/models/card_settle_tran.rb b/app/models/card_settle_tran.rb
index 2f087ef3..dd526020 100644
--- a/app/models/card_settle_tran.rb
+++ b/app/models/card_settle_tran.rb
@@ -64,6 +64,5 @@ class CardSettleTran < ApplicationRecord
shift_closed_at As closing_date,")
.order("shift_sales.id DESC")
return query = query.where("shift_sales.shift_started_at >= ?" , from)
- byebug
end
end
diff --git a/app/models/sale.rb b/app/models/sale.rb
index ce7caf7c..52f7acd3 100644
--- a/app/models/sale.rb
+++ b/app/models/sale.rb
@@ -1421,33 +1421,32 @@ def grand_total_after_rounding
end
def get_cash_amount
- cash = 0.0
- self.sale_payments.each do |pay|
- if pay.payment_method == 'cash'
- cash += pay.payment_amount
- end
- end
- return cash - self.amount_changed
+ self.sale_payments.where(payment_method: 'cash', payment_status: 'paid')
+ .pluck(:payment_amount).reduce(:+)
end
def get_credit_amount
- credit = 0.0
- self.sale_payments.each do |pay|
- if pay.payment_method == 'creditnote'
- credit += pay.payment_amount
- end
- end
- return credit
+ self.sale_payments.where(payment_method: 'creditnote')
+ .pluck(:payment_status, :payment_amount)
+ .inject(0.0) { |sum, pay|
+ if pay[0] == 'outstanding'
+ sum += pay[1]
+ else
+ sum -= pay[1]
+ end
+ }
end
def get_other_amount
- other = 0.0
- self.sale_payments.each do |pay|
- if pay.payment_method != 'cash' && pay.payment_method != 'creditnote'
- other += pay.payment_amount
- end
- end
- return other
+ self.sale_payments.where.not(payment_method: ['cash', 'creditnote'])
+ .pluck(:payment_status, :payment_amount)
+ .inject(0.0) { |sum, pay|
+ if pay[0] == 'paid'
+ sum += pay[1]
+ else
+ sum -= pay[1]
+ end
+ }
end
def get_commerical_tax
diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb
index 6240f634..498c32c9 100755
--- a/app/models/sale_payment.rb
+++ b/app/models/sale_payment.rb
@@ -75,6 +75,8 @@ class SalePayment < ApplicationRecord
#get all payment for this invoices
if payment_for
amount_due = SalePayment.get_credit_amount_due_left(self.sale_id).first.payment_amount
+ elsif payment_method == 'foc'
+ amount_due = invoice.total_amount
else
amount_due = invoice.sale_payments
.map(&:payment_amount).reduce(invoice.grand_total, :-)
@@ -412,6 +414,7 @@ class SalePayment < ApplicationRecord
def foc_payment
payment_status = false
sale = self.sale
+ sale.sale_payments.update_all(payment_status: "cancelled")
# add to sale item with foc
sale_items = sale.sale_items
@@ -428,7 +431,7 @@ class SalePayment < ApplicationRecord
self.payment_status = "paid"
payment_status = self.save!
# sale_update_payment_status(self.received_amount)
- sale_update_payment_status(0)
+ sale_update_payment_status(0, true)
return payment_status
end
@@ -638,21 +641,28 @@ class SalePayment < ApplicationRecord
def sale_update_payment_status(paid_amount, check_foc = false)
#update amount_outstanding
sale = self.sale
- total_payment_amount = sale.sale_payments.reload.sum(&:payment_amount)
+ sale_payments = sale.sale_payments.reload
+
+ is_credit = sale_payments.any? { |x| x.payment_method == "creditnote" }
+ is_foc = sale_payments.any? { |x| x.payment_method == "foc" } || check_foc
+
+ if is_foc
+ total_payment_amount = 0.0
+ else
+ total_payment_amount = sale_payments.sum(&:payment_amount)
+ end
+
sale.amount_received = sale.amount_received.to_f + paid_amount.to_f
sale.amount_changed = total_payment_amount - sale.grand_total.to_f
- is_credit = sale.sale_payments.any? { |x| x.payment_method == "creditnote" }
- is_foc = sale.sale_payments.any? { |x| x.payment_method == "foc" }
-
- if sale.grand_total <= total_payment_amount && sale.sale_status == "new"
+ if is_foc
+ sale.payment_status = 'foc'
+ sale.sale_status = 'completed'
+ elsif sale.grand_total <= total_payment_amount && sale.sale_status == "new"
sale.payment_status = "paid"
if is_credit
sale.payment_status = "outstanding"
end
- if is_foc
- sale.payment_status = "foc"
- end
sale.sale_status = "completed"
@@ -679,25 +689,24 @@ class SalePayment < ApplicationRecord
end
end
end
+ end
- sale.save!
+ sale.save!
- if check_foc
- table_update_status(sale)
- update_shift
- elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
- table_update_status(sale)
- update_shift
- elsif paid_amount.to_f == 0 && !is_credit
- table_update_status(sale)
- update_shift
- end
+ if check_foc
+ table_update_status(sale)
+ update_shift
+ elsif paid_amount.to_f > 0 #|| paid_amount != "0.0"
+ table_update_status(sale)
+ update_shift
+ elsif paid_amount.to_f == 0 && !is_credit
+ table_update_status(sale)
+ update_shift
end
end
# update for cashier shift
def update_shift
-
shift = ShiftSale.current_open_shift(self.action_by.id)
if shift.nil?
@@ -735,7 +744,6 @@ class SalePayment < ApplicationRecord
else
# extra_changed_amount = self.received_amount.to_f + credit_payment_left
shift.cash_sales = shift.cash_sales.to_f + (self.received_amount.to_f + credit_payment_left)
-
self.sale.amount_received = self.sale.amount_received.to_f - credit_payment_left
self.sale.amount_changed = self.sale.amount_changed.to_f - credit_payment_left
self.sale.save!
From d45f725bee56fa84adefe8255e452ef2c03fae76 Mon Sep 17 00:00:00 2001
From: yarzar_code
Date: Wed, 25 Mar 2020 18:01:35 +0630
Subject: [PATCH 15/28] foc pdf fixed
---
app/models/sale_payment.rb | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb
index 498c32c9..a33b0db9 100755
--- a/app/models/sale_payment.rb
+++ b/app/models/sale_payment.rb
@@ -142,9 +142,6 @@ class SalePayment < ApplicationRecord
remark = "#{self.sale_payment_id}||#{shift_sale_id} -> #{remark}"
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by.name)
- if payment_method == "cash"
- update_shift_for_credit_payment
- end
else
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by.name)
end
@@ -377,12 +374,8 @@ class SalePayment < ApplicationRecord
private
def cash_payment(payment_for=false)
- status = false
+
sale_payments_data = SalePayment.find_by_sale_id(self.sale_id)
- if sale_payments_data.nil?
- status = true
- end
-
payment_status = false
self.payment_method = "cash"
@@ -397,8 +390,11 @@ class SalePayment < ApplicationRecord
self.payment_status = "paid"
payment_status = self.save!
if !payment_for
- sale_update_payment_status(self.received_amount,status)
+ sale_update_payment_status(self.received_amount)
+ else
+ update_shift_for_credit_payment()
end
+
balance_amount =0.0
outstanding_amount =0.0
if self.sale.grand_total.to_f > self.received_amount.to_f
From eb9b4a9ec05942f3312e2cbdeaf6745912b420c6 Mon Sep 17 00:00:00 2001
From: Myat Zin Wai Maw
Date: Wed, 22 Apr 2020 18:41:10 +0630
Subject: [PATCH 16/28] credit
---
app/models/sale.rb | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/app/models/sale.rb b/app/models/sale.rb
index 52f7acd3..849d8c8a 100644
--- a/app/models/sale.rb
+++ b/app/models/sale.rb
@@ -763,8 +763,10 @@ def self.daily_sales_list(from,to)
SUM(case when (sale_payments.payment_method='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount,
SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount,
SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
- CASE WHEN SUM(case when sale_payments.payment_method not in('creditnote') then sale_payments.payment_amount end) < sales.grand_total
- THEN sales.grand_total - SUM(case when sale_payments.payment_method not in('creditnote') then sale_payments.payment_amount end)
+ CASE WHEN SUM(case when sale_payments.payment_method not in('creditnote')
+ then sale_payments.payment_amount else 0 end) < sales.grand_total
+ THEN sales.grand_total - SUM(case when sale_payments.payment_method not in('creditnote')
+ then sale_payments.payment_amount else 0 end)
ELSE 0 END as credit_amount,
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")
From d60853e9e54b6def50db970a0fcb36a79246e2de Mon Sep 17 00:00:00 2001
From: Thein Lin Kyaw
Date: Wed, 29 Apr 2020 14:15:41 +0630
Subject: [PATCH 17/28] fix shift sale balance
---
app/models/sale.rb | 16 +++++++---------
app/models/sale_payment.rb | 9 ++++++---
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/app/models/sale.rb b/app/models/sale.rb
index 849d8c8a..1a032e1d 100644
--- a/app/models/sale.rb
+++ b/app/models/sale.rb
@@ -1424,7 +1424,7 @@ end
def get_cash_amount
self.sale_payments.where(payment_method: 'cash', payment_status: 'paid')
- .pluck(:payment_amount).reduce(:+)
+ .pluck(:payment_amount).reduce(0, :+) - self.amount_changed
end
def get_credit_amount
@@ -2309,15 +2309,13 @@ private
end
def round_to_precision
- if (self.total_amount != self.total_amount_was || self.total_discount != self.total_discount_was || self.total_tax != self.total_tax_was)
- if (self.total_amount % 1 > 0 || self.total_discount % 1 > 0 || self.total_tax % 1 > 0)
- self.total_amount = self.total_amount.round(precision)
- self.total_discount = self.total_discount.round(precision)
- self.total_tax = self.total_tax.round(precision)
- self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
- end
- adjust_rounding
+ if (self.total_amount % 1 > 0 || self.total_discount % 1 > 0 || self.total_tax % 1 > 0)
+ self.total_amount = self.total_amount.round(precision)
+ self.total_discount = self.total_discount.round(precision)
+ self.total_tax = self.total_tax.round(precision)
+ self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
end
+ adjust_rounding
end
def update_stock_journal
diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb
index a33b0db9..ee89704a 100755
--- a/app/models/sale_payment.rb
+++ b/app/models/sale_payment.rb
@@ -81,7 +81,7 @@ class SalePayment < ApplicationRecord
amount_due = invoice.sale_payments
.map(&:payment_amount).reduce(invoice.grand_total, :-)
end
-
+
if amount_due > 0
payment_status = false
membership_data = nil
@@ -374,7 +374,7 @@ class SalePayment < ApplicationRecord
private
def cash_payment(payment_for=false)
-
+
sale_payments_data = SalePayment.find_by_sale_id(self.sale_id)
payment_status = false
@@ -391,7 +391,7 @@ class SalePayment < ApplicationRecord
payment_status = self.save!
if !payment_for
sale_update_payment_status(self.received_amount)
- else
+ else
update_shift_for_credit_payment()
end
@@ -636,6 +636,9 @@ class SalePayment < ApplicationRecord
def sale_update_payment_status(paid_amount, check_foc = false)
#update amount_outstanding
+ if ['completed'].include? sale.sale_status
+ return
+ end
sale = self.sale
sale_payments = sale.sale_payments.reload
From af8a3c7a54d0633e5ad0cf1c7fba02a9c01dedea Mon Sep 17 00:00:00 2001
From: Thein Lin Kyaw
Date: Thu, 30 Apr 2020 18:08:55 +0630
Subject: [PATCH 18/28] generate task shift_sales rake
---
.../origami/payments_controller.rb | 12 +-
lib/tasks/shift_sales.rake | 121 ++++++++++++++++++
2 files changed, 127 insertions(+), 6 deletions(-)
create mode 100644 lib/tasks/shift_sales.rake
diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb
index 8a186075..0d464b09 100755
--- a/app/controllers/origami/payments_controller.rb
+++ b/app/controllers/origami/payments_controller.rb
@@ -89,7 +89,7 @@ class Origami::PaymentsController < BaseOrigamiController
path = request.fullpath
latest_order_no = nil
is_kbz = params[:is_kbz]
-
+
if saleObj = Sale.find(sale_id)
sale_items = SaleItem.get_all_sale_items(sale_id)
@@ -98,7 +98,7 @@ class Origami::PaymentsController < BaseOrigamiController
Rails.logger.info '################ CASH PAYMENT #################'
sale_payment = SalePayment.new
if path.include? ("credit_payment")
- sale_payment.process_payment(saleObj, current_user, cash, "cash", nil, true)
+ sale_payment.process_payment(saleObj, current_user, cash, "creditnote", nil, true)
else
sale_payment.process_payment(saleObj, current_user, cash, "cash")
end
@@ -107,7 +107,7 @@ class Origami::PaymentsController < BaseOrigamiController
sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user)
end
-
+
rebate_amount = nil
# For Cashier by Zone
@@ -202,17 +202,17 @@ class Origami::PaymentsController < BaseOrigamiController
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
other_amount = SaleItem.calculate_other_charges(sale_items)
credit_pdf = Lookup.find_by_lookup_type("credit_pdf")
- if (path.include? ("credit_payment")) && !credit_pdf.nil? && credit_pdf.value.to_i == 1
+ if (path.include? ("credit_payment")) && !credit_pdf.nil? && credit_pdf.value.to_i == 1
printed_status = 'credit_payment'
else
printed_status = 'Paid'
end
-
+
printer = Printer::ReceiptPrinter.new(print_settings)
filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, printed_status,current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil)
#end
-
+
if !saleObj.nil?
# InventoryJob.perform_now(self.id)
# InventoryDefinition.calculate_product_count(saleObj)
diff --git a/lib/tasks/shift_sales.rake b/lib/tasks/shift_sales.rake
new file mode 100644
index 00000000..09d9de66
--- /dev/null
+++ b/lib/tasks/shift_sales.rake
@@ -0,0 +1,121 @@
+namespace :shift_sales do
+ desc "TODO"
+ task :audit, [:shift_sale_id, :repayment] => [:environment] do |tasks, args|
+ Rails.logger = Logger.new(STDOUT)
+ ActiveRecord::Base.transaction do
+ shift_sale = ShiftSale.find(args[:shift_sale_id])
+
+ total_revenue = 0
+ total_discounts = 0
+ total_taxes = 0
+ grand_total = 0
+ cash_sales = 0
+ credit_sales = 0
+ other_sales = 0
+ nett_sales = 0
+ commercial_taxes = 0
+ total_rounding = 0
+ total_receipt = 0
+ total_void = 0
+ dining_count = 0
+ takeaway_count = 0
+
+ sales = shift_sale.sales.order(:created_at)
+ sales.each do |sale|
+
+ new_grand_total = sale.total_amount - sale.total_discount + sale.total_tax + sale.rounding_adjustment
+ old_grand_total = sale.total_amount - sale.total_discount + sale.total_tax
+ amount_changed = sale.amount_received - new_grand_total
+
+ cash_amount = 0
+ credit_amount = 0
+ other_amount = 0
+
+ sale_payments = sale.sale_payments.order(:created_at)
+ sale_payments.each do |sale_payment|
+
+ if sale_payment.payment_method == 'creditnote'
+ credit_amount += sale_payment.payment_amount
+ else
+ if SaleAudit.where("SUBSTRING_INDEX(sale_audits.remark,'||',1) = ? AND sale_audits.sale_id = ?", sale_payment.sale_payment_id, sale.sale_id).exists?
+ if sale_payment.created_at.between?(shift_sale.shift_started_at, shift_sale.shift_closed_at)
+ if credit_amount >= sale_payment.payment_amount
+ credit_amount -= sale_payment.payment_amount
+ else
+ credit_amount = 0
+ end
+ if sale_payment.payment_method == 'cash'
+ cash_amount += sale_payment.payment_amount
+ else
+ other_amount += sale_payment.payment_amount
+ end
+ end
+ else
+ if sale_payment.payment_method == 'cash'
+ cash_amount += sale_payment.payment_amount
+ else
+ other_amount += sale_payment.payment_amount
+ end
+ outstanding_amount = new_grand_total - sale_payment.payment_amount
+ sale_payment.update_columns(outstanding_amount: outstanding_amount)
+ end
+ end
+ end
+
+ sale.update_columns(grand_total: new_grand_total, old_grand_total: old_grand_total, amount_changed: amount_changed)
+
+ if sale.sale_status != 'void'
+ total_revenue += sale.total_amount
+ total_discounts += sale.total_discount
+ total_taxes += sale.total_tax
+ grand_total += sale.grand_total
+ cash_sales += cash_amount - sale.amount_changed
+ credit_sales += credit_amount
+ other_sales += other_amount
+ nett_sales += sale.total_amount - sale.total_discount
+ commercial_taxes += sale.get_commerical_tax
+ total_rounding += sale.rounding_adjustment
+ total_receipt += 1
+ if sale.customer.customer_type == 'Dinein'
+ dining_count += 1
+ else
+ takeaway_count += 1
+ end
+ else
+ total_receipt += 1
+ total_void += 1
+ end
+ end
+
+ if args[:repayment]
+ SalePayment.joins(:sale, :sale_audit).where(sale_payments: {created_at: shift_sale.shift_started_at..shift_sale.shift_closed_at}).where.not(sales: {shift_sale_id: shift_sale.id}).each do |sale_payment|
+ if sale_payment.payment_method == 'cash'
+ cash_amount += sale_payment.payment_amount
+ else
+ other_amount += sale_payment.payment_amount
+ end
+ end
+ end
+
+ shift_sale.update_columns(
+ {
+ total_revenue: total_revenue,
+ total_discounts: total_discounts,
+ total_taxes: total_taxes,
+ grand_total: grand_total,
+ cash_sales: cash_sales,
+ credit_sales: credit_sales,
+ other_sales: other_sales,
+ nett_sales: nett_sales,
+ commercial_taxes: commercial_taxes,
+ total_rounding: total_rounding,
+ total_receipt: total_receipt,
+ total_void: total_void,
+ dining_count: dining_count,
+ takeaway_count: takeaway_count,
+ }
+ )
+ end
+ end
+
+end
From dde2b44be3212ee853a2b98e245430b76395c0e2 Mon Sep 17 00:00:00 2001
From: Myat Zin Wai Maw
Date: Thu, 7 May 2020 15:10:26 +0630
Subject: [PATCH 19/28] creditnote
---
app/controllers/origami/payments_controller.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb
index 0d464b09..8693e6be 100755
--- a/app/controllers/origami/payments_controller.rb
+++ b/app/controllers/origami/payments_controller.rb
@@ -98,7 +98,7 @@ class Origami::PaymentsController < BaseOrigamiController
Rails.logger.info '################ CASH PAYMENT #################'
sale_payment = SalePayment.new
if path.include? ("credit_payment")
- sale_payment.process_payment(saleObj, current_user, cash, "creditnote", nil, true)
+ sale_payment.process_payment(saleObj, current_user, cash, "cash", nil, true)
else
sale_payment.process_payment(saleObj, current_user, cash, "cash")
end
From 115ed3c06bd630b6f2d971097188b0b68228ed96 Mon Sep 17 00:00:00 2001
From: Thein Lin Kyaw
Date: Sun, 17 May 2020 13:55:38 +0630
Subject: [PATCH 20/28] fix rounding adjustment
---
app/models/sale.rb | 2 +-
lib/tasks/shift_sales.rake | 66 +++++++++++++++++++++++++-------------
2 files changed, 45 insertions(+), 23 deletions(-)
diff --git a/app/models/sale.rb b/app/models/sale.rb
index 1a032e1d..f990c947 100644
--- a/app/models/sale.rb
+++ b/app/models/sale.rb
@@ -2313,8 +2313,8 @@ private
self.total_amount = self.total_amount.round(precision)
self.total_discount = self.total_discount.round(precision)
self.total_tax = self.total_tax.round(precision)
- self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
end
+ self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
adjust_rounding
end
diff --git a/lib/tasks/shift_sales.rake b/lib/tasks/shift_sales.rake
index 09d9de66..a7817b92 100644
--- a/lib/tasks/shift_sales.rake
+++ b/lib/tasks/shift_sales.rake
@@ -23,9 +23,28 @@ namespace :shift_sales do
sales = shift_sale.sales.order(:created_at)
sales.each do |sale|
- new_grand_total = sale.total_amount - sale.total_discount + sale.total_tax + sale.rounding_adjustment
- old_grand_total = sale.total_amount - sale.total_discount + sale.total_tax
- amount_changed = sale.amount_received - new_grand_total
+ sale.grand_total = sale.total_amount - sale.total_discount + sale.total_tax
+ sale.old_grand_total = grand_total
+
+ license = License.new(ENV["SX_PROVISION_URL"])
+ shop_name = license.read_license_no_decrypt("shop_name")
+
+ shop = if Rails.env.production? || shop_name.present?
+ Shop.find_by(name: shop_name)
+ else
+ Shop.first
+ end
+
+ if shop.is_rounding_adj
+ new_total = Sale.get_rounding_adjustment(sale.grand_total)
+ sale.rounding_adjustment = new_total - sale.grand_total
+ sale.old_grand_total = sale.grand_total
+ sale.grand_total = new_total
+ else
+ sale.rounding_adjustment = 0.00
+ end
+
+ sale.amount_changed = sale.amount_received - sale.grand_total
cash_amount = 0
credit_amount = 0
@@ -56,13 +75,18 @@ namespace :shift_sales do
else
other_amount += sale_payment.payment_amount
end
- outstanding_amount = new_grand_total - sale_payment.payment_amount
- sale_payment.update_columns(outstanding_amount: outstanding_amount)
+ sale_payment.outstanding_amount = sale.grand_total - sale_payment.payment_amount
+ sale_payment.update_columns(outstanding_amount: sale_payment.outstanding_amount)
end
end
end
- sale.update_columns(grand_total: new_grand_total, old_grand_total: old_grand_total, amount_changed: amount_changed)
+ sale.update_columns(
+ grand_total: sale.grand_total,
+ old_grand_total: sale.old_grand_total,
+ rounding_adjustment: sale.rounding_adjustment,
+ amount_changed: sale.amount_changed
+ )
if sale.sale_status != 'void'
total_revenue += sale.total_amount
@@ -98,22 +122,20 @@ namespace :shift_sales do
end
shift_sale.update_columns(
- {
- total_revenue: total_revenue,
- total_discounts: total_discounts,
- total_taxes: total_taxes,
- grand_total: grand_total,
- cash_sales: cash_sales,
- credit_sales: credit_sales,
- other_sales: other_sales,
- nett_sales: nett_sales,
- commercial_taxes: commercial_taxes,
- total_rounding: total_rounding,
- total_receipt: total_receipt,
- total_void: total_void,
- dining_count: dining_count,
- takeaway_count: takeaway_count,
- }
+ total_revenue: total_revenue,
+ total_discounts: total_discounts,
+ total_taxes: total_taxes,
+ grand_total: grand_total,
+ cash_sales: cash_sales,
+ credit_sales: credit_sales,
+ other_sales: other_sales.to_f,
+ nett_sales: nett_sales,
+ commercial_taxes: commercial_taxes,
+ total_rounding: total_rounding,
+ total_receipt: total_receipt,
+ total_void: total_void,
+ dining_count: dining_count,
+ takeaway_count: takeaway_count
)
end
end
From e5a27aaac969eca48aba33d8e81eb511154a8d2c Mon Sep 17 00:00:00 2001
From: Thein Lin Kyaw
Date: Wed, 20 May 2020 19:01:55 +0630
Subject: [PATCH 21/28] update rake task shift_sales:audit
---
lib/tasks/shift_sales.rake | 239 +++++++++++++++++++------------------
1 file changed, 126 insertions(+), 113 deletions(-)
diff --git a/lib/tasks/shift_sales.rake b/lib/tasks/shift_sales.rake
index a7817b92..7c814f31 100644
--- a/lib/tasks/shift_sales.rake
+++ b/lib/tasks/shift_sales.rake
@@ -1,142 +1,155 @@
namespace :shift_sales do
desc "TODO"
- task :audit, [:shift_sale_id, :repayment] => [:environment] do |tasks, args|
+ task :audit, [:shift_sale_ids, :repayment] => [:environment] do |tasks, args|
Rails.logger = Logger.new(STDOUT)
- ActiveRecord::Base.transaction do
- shift_sale = ShiftSale.find(args[:shift_sale_id])
- total_revenue = 0
- total_discounts = 0
- total_taxes = 0
- grand_total = 0
- cash_sales = 0
- credit_sales = 0
- other_sales = 0
- nett_sales = 0
- commercial_taxes = 0
- total_rounding = 0
- total_receipt = 0
- total_void = 0
- dining_count = 0
- takeaway_count = 0
+ if args[:shift_sale_ids].empty?
+ return
+ end
- sales = shift_sale.sales.order(:created_at)
- sales.each do |sale|
+ if args[:shift_sale_ids].include? '..'
+ shift_sales_ids = args[:shift_sale_ids].split('..').inject { |s,e| s.to_i..e.to_i }
+ else
+ shift_sales_ids = args[:shift_sale_ids].split(' ')
+ end
- sale.grand_total = sale.total_amount - sale.total_discount + sale.total_tax
- sale.old_grand_total = grand_total
+ shift_sales_ids.each do |shift_sale_id|
+ ActiveRecord::Base.transaction do
+ shift_sale = ShiftSale.find(shift_sale_id)
- license = License.new(ENV["SX_PROVISION_URL"])
- shop_name = license.read_license_no_decrypt("shop_name")
+ total_revenue = 0
+ total_discounts = 0
+ total_taxes = 0
+ grand_total = 0
+ cash_sales = 0
+ credit_sales = 0
+ other_sales = 0
+ nett_sales = 0
+ commercial_taxes = 0
+ total_rounding = 0
+ total_receipt = 0
+ total_void = 0
+ dining_count = 0
+ takeaway_count = 0
- shop = if Rails.env.production? || shop_name.present?
- Shop.find_by(name: shop_name)
- else
- Shop.first
- end
+ sales = shift_sale.sales.order(:created_at)
+ sales.each do |sale|
- if shop.is_rounding_adj
- new_total = Sale.get_rounding_adjustment(sale.grand_total)
- sale.rounding_adjustment = new_total - sale.grand_total
- sale.old_grand_total = sale.grand_total
- sale.grand_total = new_total
- else
- sale.rounding_adjustment = 0.00
- end
+ sale.grand_total = sale.total_amount - sale.total_discount + sale.total_tax
+ sale.old_grand_total = grand_total
- sale.amount_changed = sale.amount_received - sale.grand_total
+ license = License.new(ENV["SX_PROVISION_URL"])
+ shop_name = license.read_license_no_decrypt("shop_name")
- cash_amount = 0
- credit_amount = 0
- other_amount = 0
-
- sale_payments = sale.sale_payments.order(:created_at)
- sale_payments.each do |sale_payment|
-
- if sale_payment.payment_method == 'creditnote'
- credit_amount += sale_payment.payment_amount
+ shop = if Rails.env.production? || shop_name.present?
+ Shop.find_by(name: shop_name)
else
- if SaleAudit.where("SUBSTRING_INDEX(sale_audits.remark,'||',1) = ? AND sale_audits.sale_id = ?", sale_payment.sale_payment_id, sale.sale_id).exists?
- if sale_payment.created_at.between?(shift_sale.shift_started_at, shift_sale.shift_closed_at)
- if credit_amount >= sale_payment.payment_amount
- credit_amount -= sale_payment.payment_amount
- else
- credit_amount = 0
+ Shop.first
+ end
+
+ if shop.is_rounding_adj
+ new_total = Sale.get_rounding_adjustment(sale.grand_total)
+ sale.rounding_adjustment = new_total - sale.grand_total
+ sale.old_grand_total = sale.grand_total
+ sale.grand_total = new_total
+ else
+ sale.rounding_adjustment = 0.00
+ end
+
+ sale.amount_changed = sale.amount_received - sale.grand_total
+
+ cash_amount = 0
+ credit_amount = 0
+ other_amount = 0
+
+ sale_payments = sale.sale_payments.order(:created_at)
+ sale_payments.each do |sale_payment|
+
+ if sale_payment.payment_method == 'creditnote'
+ credit_amount += sale_payment.payment_amount
+ else
+ if SaleAudit.where("SUBSTRING_INDEX(sale_audits.remark,'||',1) = ? AND sale_audits.sale_id = ?", sale_payment.sale_payment_id, sale.sale_id).exists?
+ if sale_payment.created_at.between?(shift_sale.shift_started_at, shift_sale.shift_closed_at)
+ if credit_amount >= sale_payment.payment_amount
+ credit_amount -= sale_payment.payment_amount
+ else
+ credit_amount = 0
+ end
+ if sale_payment.payment_method == 'cash'
+ cash_amount += sale_payment.payment_amount
+ else
+ other_amount += sale_payment.payment_amount
+ end
end
+ else
if sale_payment.payment_method == 'cash'
cash_amount += sale_payment.payment_amount
else
other_amount += sale_payment.payment_amount
end
+ sale_payment.outstanding_amount = sale.grand_total - sale_payment.payment_amount
+ sale_payment.update_columns(outstanding_amount: sale_payment.outstanding_amount)
end
+ end
+ end
+
+ sale.update_columns(
+ grand_total: sale.grand_total,
+ old_grand_total: sale.old_grand_total,
+ rounding_adjustment: sale.rounding_adjustment,
+ amount_changed: sale.amount_changed
+ )
+
+ if sale.sale_status != 'void'
+ total_revenue += sale.total_amount
+ total_discounts += sale.total_discount
+ total_taxes += sale.total_tax
+ grand_total += sale.grand_total
+ cash_sales += cash_amount - sale.amount_changed
+ credit_sales += credit_amount
+ other_sales += other_amount
+ nett_sales += sale.total_amount - sale.total_discount
+ commercial_taxes += sale.get_commerical_tax
+ total_rounding += sale.rounding_adjustment
+ total_receipt += 1
+ if sale.customer.customer_type == 'Dinein'
+ dining_count += 1
else
- if sale_payment.payment_method == 'cash'
- cash_amount += sale_payment.payment_amount
- else
- other_amount += sale_payment.payment_amount
- end
- sale_payment.outstanding_amount = sale.grand_total - sale_payment.payment_amount
- sale_payment.update_columns(outstanding_amount: sale_payment.outstanding_amount)
+ takeaway_count += 1
+ end
+ else
+ total_receipt += 1
+ total_void += sale.grand_total
+ end
+ end
+
+ if args[:repayment]
+ SalePayment.joins(:sale, :sale_audit).where(sale_payments: {created_at: shift_sale.shift_started_at..shift_sale.shift_closed_at}).where.not(sales: {shift_sale_id: shift_sale.id}).each do |sale_payment|
+ if sale_payment.payment_method == 'cash'
+ cash_amount += sale_payment.payment_amount
+ else
+ other_amount += sale_payment.payment_amount
end
end
end
- sale.update_columns(
- grand_total: sale.grand_total,
- old_grand_total: sale.old_grand_total,
- rounding_adjustment: sale.rounding_adjustment,
- amount_changed: sale.amount_changed
+ shift_sale.update_columns(
+ total_revenue: total_revenue,
+ total_discounts: total_discounts,
+ total_taxes: total_taxes,
+ grand_total: grand_total,
+ cash_sales: cash_sales,
+ credit_sales: credit_sales,
+ other_sales: other_sales.to_f,
+ nett_sales: nett_sales,
+ commercial_taxes: commercial_taxes,
+ total_rounding: total_rounding,
+ total_receipt: total_receipt,
+ total_void: total_void,
+ dining_count: dining_count,
+ takeaway_count: takeaway_count
)
-
- if sale.sale_status != 'void'
- total_revenue += sale.total_amount
- total_discounts += sale.total_discount
- total_taxes += sale.total_tax
- grand_total += sale.grand_total
- cash_sales += cash_amount - sale.amount_changed
- credit_sales += credit_amount
- other_sales += other_amount
- nett_sales += sale.total_amount - sale.total_discount
- commercial_taxes += sale.get_commerical_tax
- total_rounding += sale.rounding_adjustment
- total_receipt += 1
- if sale.customer.customer_type == 'Dinein'
- dining_count += 1
- else
- takeaway_count += 1
- end
- else
- total_receipt += 1
- total_void += 1
- end
end
-
- if args[:repayment]
- SalePayment.joins(:sale, :sale_audit).where(sale_payments: {created_at: shift_sale.shift_started_at..shift_sale.shift_closed_at}).where.not(sales: {shift_sale_id: shift_sale.id}).each do |sale_payment|
- if sale_payment.payment_method == 'cash'
- cash_amount += sale_payment.payment_amount
- else
- other_amount += sale_payment.payment_amount
- end
- end
- end
-
- shift_sale.update_columns(
- total_revenue: total_revenue,
- total_discounts: total_discounts,
- total_taxes: total_taxes,
- grand_total: grand_total,
- cash_sales: cash_sales,
- credit_sales: credit_sales,
- other_sales: other_sales.to_f,
- nett_sales: nett_sales,
- commercial_taxes: commercial_taxes,
- total_rounding: total_rounding,
- total_receipt: total_receipt,
- total_void: total_void,
- dining_count: dining_count,
- takeaway_count: takeaway_count
- )
end
end
From 8bae89eeac5717c497429c8f245123cb8af13c48 Mon Sep 17 00:00:00 2001
From: Thein Lin Kyaw
Date: Fri, 22 May 2020 17:28:23 +0630
Subject: [PATCH 22/28] update rake shift_sales:audit
---
lib/tasks/shift_sales.rake | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/lib/tasks/shift_sales.rake b/lib/tasks/shift_sales.rake
index 7c814f31..9f7e92b3 100644
--- a/lib/tasks/shift_sales.rake
+++ b/lib/tasks/shift_sales.rake
@@ -1,6 +1,6 @@
namespace :shift_sales do
desc "TODO"
- task :audit, [:shift_sale_ids, :repayment] => [:environment] do |tasks, args|
+ task :audit, [:shift_sale_ids, :shop_code, :repayment] => [:environment] do |tasks, args|
Rails.logger = Logger.new(STDOUT)
if args[:shift_sale_ids].empty?
@@ -38,13 +38,10 @@ namespace :shift_sales do
sale.grand_total = sale.total_amount - sale.total_discount + sale.total_tax
sale.old_grand_total = grand_total
- license = License.new(ENV["SX_PROVISION_URL"])
- shop_name = license.read_license_no_decrypt("shop_name")
-
- shop = if Rails.env.production? || shop_name.present?
- Shop.find_by(name: shop_name)
+ if args[:shop_code]
+ shop = Shop.find_by!(shop_code: args[:shop_code])
else
- Shop.first
+ shop = Shop.first
end
if shop.is_rounding_adj
From 4a3d429a532a6e995af0350c20140433594115da Mon Sep 17 00:00:00 2001
From: Thein Lin Kyaw
Date: Thu, 28 May 2020 12:05:42 +0630
Subject: [PATCH 23/28] dashboard sale revenue
---
app/views/home/dashboard.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb
index 6cd52f4e..b7bd5c44 100755
--- a/app/views/home/dashboard.html.erb
+++ b/app/views/home/dashboard.html.erb
@@ -189,7 +189,7 @@
| <%= @summ_sale.total_receipt %> |
- <% revenue = @summ_sale.total_amount - @summ_sale.total_discount%>
+ <% revenue = @summ_sale.grand_total - @summ_sale.total_discount - @summ_sale.total_tax %>
| <%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : |
<%= number_format( revenue, precision: precision.to_i ,delimiter: delimiter) %> |
From 51932b8a86ca5084a303a9e772463b0d8548d951 Mon Sep 17 00:00:00 2001
From: Thein Lin Kyaw
Date: Mon, 1 Jun 2020 15:46:27 +0630
Subject: [PATCH 24/28] other payments
---
app/assets/javascripts/origami.js | 4 +-
.../origami/others_payments_controller.rb | 85 +++
.../origami/payments_controller.rb | 279 ++++------
app/models/sale_payment.rb | 22 +-
.../others_payments/create.json.jbuilder | 5 +
.../origami/others_payments/index.html.erb | 4 +-
.../origami/others_payments/new.html.erb | 279 ++++++++++
app/views/origami/payments/show.html.erb | 498 ++++++------------
config/initializers/action_controller.rb | 10 +-
config/routes.rb | 52 +-
10 files changed, 665 insertions(+), 573 deletions(-)
create mode 100644 app/views/origami/others_payments/create.json.jbuilder
create mode 100644 app/views/origami/others_payments/new.html.erb
diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js
index 8c910119..d282b611 100755
--- a/app/assets/javascripts/origami.js
+++ b/app/assets/javascripts/origami.js
@@ -326,8 +326,8 @@ function setCommPorts(comPortLists) {
/** pay with CB bank **/
function pay_withBank(cmd_type, payment_type, bnk_bill_amount,sale_id,receipt_no,cashier_type) {
$("#loading_wrapper").show();
- var com_port = $("#com_port_name").val();
- reqCardSaleTrans(cmd_type, payment_type, bnk_bill_amount, sale_id, receipt_no, com_port,cashier_type);
+ var com_port = $("#com_port_name").val();
+ reqCardSaleTrans(cmd_type, payment_type, bnk_bill_amount, sale_id, receipt_no, com_port,cashier_type);
}
//add req data to card_sale_trans table
diff --git a/app/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb
index 3d95bbb0..964af260 100755
--- a/app/controllers/origami/others_payments_controller.rb
+++ b/app/controllers/origami/others_payments_controller.rb
@@ -39,7 +39,92 @@ class Origami::OthersPaymentsController < BaseOrigamiController
# end
end
+ def new
+ @sale_id = params[:sale_id]
+ @cashier_type = params[:type]
+ payment_methods = PaymentMethodSetting.pluck(:payment_method)
+ if @payment_method = payment_methods.find { |m| m.parameterize == params[:method] }
+ path = request.fullpath
+ # limit master_amount
+ if path.include? ("credit_payment")
+ sale_data = Sale.get_sale_data_for_other_payment_credit(@sale_id)
+ else
+ sale_data = Sale.find_by_sale_id(@sale_id)
+ end
+ total = 0
+ @shop = Shop.current_shop
+ @paid_amount = 0
+ @can_paid = 0
+ @rounding_adj = 0
+ @member_discount = 0
+ @sub_total = 0
+ @membership_id = nil
+ @receipt_no = nil
+ if !sale_data.nil?
+ total = sale_data.grand_total
+
+ others = 0
+
+ if @shop.is_rounding_adj
+ new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
+ else
+ new_total = sale_data.grand_total
+ end
+
+ @rounding_adj = new_total-sale_data.grand_total
+
+ if path.include? ("credit_payment")
+ sale_payment_data = SalePayment.get_sale_payment_for_credit(sale_data)
+ else
+ sale_payment_data = sale_data.sale_payments
+ end
+
+ sale_payment_data.each do |sale_payment|
+ if sale_payment.payment_method == @payment_method.parameterize
+ @paid_amount = @paid_amount + sale_payment.payment_amount
+ else
+ others = others + sale_payment.payment_amount
+ end
+ end
+ @can_paid = total - @paid_amount - others
+ @member_discount = MembershipSetting.find_by_discount(1)
+ @sub_total = sale_data.total_amount
+ @membership_id = sale_data.customer.membership_id
+ #for bank integration
+ @receipt_no = sale_data.receipt_no
+ end
+ bank_integration = Lookup.collection_of('bank_integration')
+ @bank_integration = 0
+ if !bank_integration[0].nil?
+ @bank_integration = bank_integration[0][1]
+ end
+ else
+ if path.include? ("credit_payment")
+ redirect_to "sale/#{@sale_id}/#{@cashier_type}/payment/others_payment"
+ else
+ redirect_to "sale/#{@sale_id}/#{@cashier_type}/credit_payment/others_payment"
+ end
+ end
+ end
+
def create
+ cash = params[:amount]
+ sale_id = params[:sale_id]
+ ref_no = params[:ref_no]
+ payment_method = params[:method]
+ if PaymentMethodSetting.pluck(:payment_method).map(&:parameterize).include? payment_method
+ if saleObj = Sale.find(sale_id)
+ shop_details = Shop.current_shop
+
+ path = request.fullpath
+ payment_for = false
+ if path.include? ("credit_payment")
+ payment_for = true
+ end
+ sale_payment = SalePayment.new
+ @status, @sale = sale_payment.process_payment(saleObj, current_user, cash, payment_method, ref_no, payment_for)
+ end
+ end
end
end
diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb
index 8693e6be..e86449ac 100755
--- a/app/controllers/origami/payments_controller.rb
+++ b/app/controllers/origami/payments_controller.rb
@@ -51,7 +51,8 @@ class Origami::PaymentsController < BaseOrigamiController
#TODO :: KBZPAY ( QR )
# On/Off setting ( show or not qr )
# qrCode = "00020101021202021110500346KBZ005ab0ed5c1ed09d1c4585ff1313170389160831435294600062000040732kp1e78f7efddca190042638341afb88d50200006KBZPay0106KBZPay5303MMK5802MM62170813PAY_BY_QRCODE64060002my6304FBBD"
- kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
+ kbz_pay_method = PaymentMethodSetting.where(payment_method: KbzPay::KBZ_PAY, gateway_communication_type: ['api', 'Api'], is_active: true)
+ .where.not(gateway_url: [nil, ''], auth_token: [nil, ''], merchant_account_id: [nil, '']).last
status = false
qr = nil
@@ -232,15 +233,29 @@ class Origami::PaymentsController < BaseOrigamiController
# end
def show
+ @sale = Sale.find(params[:sale_id])
+ @shop = Shop.current_shop
+ @customer = @sale.customer
+ @customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"])
+ @member_discount = MembershipSetting.find_by_discount(1)
+
+ if dining_facility = @sale.booking.dining_facility
+ @table_no = dining_facility.type + ' ' + dining_facility.name
+ @checkin_time = @sale.booking.checkin_at
+ @dining = dining_facility
+ end
+
display_type = Lookup.find_by_lookup_type("display_type")
- if !display_type.nil? && display_type.value.to_i ==2
+ if !display_type.nil? && display_type.value.to_i ==2
@display_type = display_type.value
else
@display_type = nil
- end
+ end
+
path = request.fullpath
- sale_id = params[:sale_id]
+
@trans_flag = true
+
if params[:type] == "transaction"
@trans_flag = false
@cashier_type = "cashier"
@@ -248,201 +263,111 @@ class Origami::PaymentsController < BaseOrigamiController
@cashier_type = params[:type]
end
- if path.include? ("credit_payment")
- @sale_payment = SalePayment.where(sale_id: sale_id, payment_method: 'creditnote').select("SUM(payment_amount) as payment_amount")
+ if path.include? 'credit_payment'
+ @sale_payment = false
+ @amount_due = @sale.sale_payments.where(payment_method: 'creditnote').pluck('SUM(payment_amount)').first
+ payments = @sale.sale_payments.joins(:sale_audit).group_by(&:payment_method).map { |method, payments| [method, payments.sum { |payment| payment.payment_amount }] }
+ else
+ @sale_payment = true
+ @amount_due = @sale.grand_total
+ payments = @sale.sale_payments.left_joins(:sale_audit).where(sale_audits: {sale_audit_id: nil}).group_by(&:payment_method).map { |method, payments| [method, payments.sum { |payment| payment.payment_amount }] }
end
- @member_discount = MembershipSetting.find_by_discount(1)
- @membership_rebate_balance=0
+ @payment_methods = PaymentMethodSetting.where(is_active: true).pluck(:payment_method)
+ @cash = payments.inject(0) { |sum, payment| sum + payment[1] if payment[0] == 'cash' }
+ @credit = payments.inject(0) { |sum, payment| sum + payment[1] if payment[0] == 'creditnote' }
+ @other_payments = payments.select { |payment| !['cash', 'creditnote'].include? payment[0] }.map { |method, amount| [ @payment_methods.find { |payment_method| payment_method.parameterize == method }, amount ] }
+ @other_payment = @other_payments.sum { |payment| payment[1] }
- if Sale.exists?(sale_id)
- @cash = 0.0
- @kbz_pay_amount = 0.0
- @other = 0.0
- @ppamount = 0.0
- @visacount= 0.0
- @jcbcount= 0.0
- @mastercount = 0.0
- @unionpaycount = 0.0
- @alipaycount = 0.0
- @junctionpaycount = 0.0
- @credit = 0.0
- @paymalcount = 0.0
- @dingacount = 0.0
- @giftvouchercount = 0.0
- @sale_data = Sale.find_by_sale_id(sale_id)
- @balance = 0
- @accountable_type = ''
- @table_no = ''
- @dining = ''
- @other_payment = 0.0
- @pdf_view = nil
- @lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView")
- if !@lookup_pdf.nil?
- @pdf_view = @lookup_pdf.value
- end
+ #total customer with individual total amount
+ @individual_total = Array.new
+ if !@sale.equal_persons.nil?
+ per_person_amount = @sale.grand_total / @sale.equal_persons.to_i
+ @individual_total.push({'total_customer' => @sale.equal_persons.to_i, 'per_person_amount' => per_person_amount })
+ end
- amount = SalePayment.get_kbz_pay_amount(sale_id, current_user)
- @kbz_pay_amount += amount.to_f
-
- #for changable on/off
- @changable_tax = true
- lookup_changable_tax = Lookup.collection_of('changable_tax')
- if !lookup_changable_tax.empty?
- lookup_changable_tax.each do |changable_tax|
- if changable_tax[0].downcase == "change"
- if changable_tax[1] == '0'
- @changable_tax = false
- end
+ #for changable on/off
+ @changable_tax = true
+ lookup_changable_tax = Lookup.collection_of('changable_tax')
+ if !lookup_changable_tax.empty?
+ lookup_changable_tax.each do |changable_tax|
+ if changable_tax[0].downcase == "change"
+ if changable_tax[1] == '0'
+ @changable_tax = false
end
end
end
+ end
- @shop = shop_detail #show shop info
+ # get printer info
+ @print_settings = PrintSetting.get_precision_delimiter()
- @customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"])
+ @pdf_view = nil
+ @lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView")
+ if !@lookup_pdf.nil?
+ @pdf_view = @lookup_pdf.value
+ end
- saleObj = Sale.find(sale_id)
+ # amount = SalePayment.get_kbz_pay_amount(sale_id, current_user)
+ # @kbz_pay_amount += amount.to_f
- #total customer with individual total amount
- @individual_total = Array.new
- if !saleObj.equal_persons.nil?
- per_person_amount = saleObj.grand_total.to_f / saleObj.equal_persons.to_i
- @individual_total.push({'total_customer' => saleObj.equal_persons.to_i, 'per_person_amount' => per_person_amount.to_f })
+ # rounding adjustment
+ # if @shop.is_rounding_adj
+ # a = saleObj.grand_total % 25 # Modulus
+ # b = saleObj.grand_total / 25 # Division
+ # #not calculate rounding if modulus is 0 and division is even
+ # #calculate rounding if modulus is zero or not zero and division are not even
+ # if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
+ # new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
+ # @rounding_adj = new_total-saleObj.grand_total
+ # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj)
+ # @sale_data.grand_total = new_total
+ # @sale_data.old_grand_total = saleObj.grand_total
+ # @sale_data.rounding_adjustment = @rounding_adj
+ # else
+ # @rounding_adj = @sale_data.rounding_adjustment
+ # end
+ # else
+ # @rounding_adj = @sale_data.rounding_adjustment
+ # end
+ #end rounding adjustment
+
+ # accounts = @customer.tax_profiles
+ accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC")
+ @account_arr =[]
+ @tax_arr =[]
+
+ accounts.each do |acc|
+ account = TaxProfile.find(acc.id)
+ # @account_arr.push(account)
+ @tax_arr.push(account.name)
+ end
+
+ sale_taxes = @sale.sale_taxes
+ if !sale_taxes.empty?
+ sale_taxes.each do |sale_tax|
+ @account_arr.push(sale_tax)
end
+ end
- # rounding adjustment
- # if @shop.is_rounding_adj
- # a = saleObj.grand_total % 25 # Modulus
- # b = saleObj.grand_total / 25 # Division
- # #not calculate rounding if modulus is 0 and division is even
- # #calculate rounding if modulus is zero or not zero and division are not even
- # if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
- # new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
- # @rounding_adj = new_total-saleObj.grand_total
- # else
- # @rounding_adj = @sale_data.rounding_adjustment
- # end
- # else
- # @rounding_adj = @sale_data.rounding_adjustment
- # end
- #end rounding adjustment
+ rebate = MembershipSetting.find_by_rebate(1)
- # rounding adjustment
- if @shop.is_rounding_adj
- a = saleObj.grand_total % 25 # Modulus
- b = saleObj.grand_total / 25 # Division
- #not calculate rounding if modulus is 0 and division is even
- #calculate rounding if modulus is zero or not zero and division are not even
- if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
- new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
- @rounding_adj = new_total-saleObj.grand_total
- saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj)
- @sale_data.grand_total = new_total
- @sale_data.old_grand_total = saleObj.grand_total
- @sale_data.rounding_adjustment = @rounding_adj
- else
- @rounding_adj = @sale_data.rounding_adjustment
- end
- else
- @rounding_adj = @sale_data.rounding_adjustment
- end
- #end rounding adjustment
-
- # get printer info
- @print_settings = PrintSetting.get_precision_delimiter()
-
- #get customer amount
- @customer = Customer.find(@sale_data.customer_id)
- # accounts = @customer.tax_profiles
- accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC")
- @account_arr =[]
- @tax_arr =[]
- accounts.each do |acc|
- account = TaxProfile.find(acc.id)
- # @account_arr.push(account)
- @tax_arr.push(account.name)
- end
- sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id)
- if !sale_taxes.empty?
- sale_taxes.each do |sale_tax|
- @account_arr.push(sale_tax)
- end
- end
- rebate = MembershipSetting.find_by_rebate(1)
- # get member information
- if @customer.membership_id != nil && rebate
- response = Customer.get_member_account(@customer)
- if response["status"]==true
- response["account_data"].each do |res|
+ # get member information
+ @balance = 0
+ @accountable_type = ''
+ if @customer.membership_id != nil && rebate
+ response = Customer.get_member_account(@customer)
+ if response["status"]==true
+ response["account_data"].each do |res|
if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
@balance = @balance.to_f + res["balance"].to_f
# @accountable_type = res["accountable_type"]
@accountable_type = "Rebate Balance"
end
end
- end
- end
-
- #end customer amount
-
- #paymal payment
-
- @sale_data.bookings.each do |sbk|
- if sbk.dining_facility_id.to_i >0
- df = DiningFacility.find(sbk.dining_facility_id)
- @table_no = df.type + ' ' + df.name
- @checkin_time = sbk.checkin_at
- @dining = df
- break
- else
- @table_no = nil
- @checkin_time = nil
- @dining = nil
- end
- end
-
- if path.include? ("credit_payment")
- @sale_payment_data = SalePayment.get_sale_payment_for_credit(@sale_data)
- else
- @sale_payment_data = SalePayment.get_sale_payments(@sale_data)
- end
- @sale_payment_data.each do |spay|
- if spay.payment_method == "cash"
- @cash += spay.payment_amount
- end
- if spay.payment_method !="creditnote"
- @other_payment += spay.payment_amount
- end
-
- if spay.payment_method == "mpu"
- @other += spay.payment_amount
- elsif spay.payment_method == "paypar"
- @ppamount += spay.payment_amount
- elsif spay.payment_method == "visa"
- @visacount += spay.payment_amount
- elsif spay.payment_method == "jcb"
- @jcbcount += spay.payment_amount
- elsif spay.payment_method == "master"
- @mastercount += spay.payment_amount
- elsif spay.payment_method == "unionpay"
- @unionpaycount += spay.payment_amount
- elsif spay.payment_method == "JunctionPay"
- @junctionpaycount += spay.payment_amount
- elsif spay.payment_method == "creditnote"
- @credit += spay.payment_amount
- elsif spay.payment_method == "paymal"
- @paymalcount += spay.payment_amount
- elsif spay.payment_method == "alipay"
- @alipaycount += spay.payment_amount
- elsif spay.payment_method == "dinga"
- @dingacount += spay.payment_amount
- elsif spay.payment_method == "giftvoucher"
- @giftvouchercount += spay.payment_amount
- end
-
end
end
+ #end customer amount
end
def reprint
diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb
index ee89704a..70812e11 100755
--- a/app/models/sale_payment.rb
+++ b/app/models/sale_payment.rb
@@ -36,7 +36,8 @@ class SalePayment < ApplicationRecord
def self.get_kbz_pay_amount(sale_id, current_user)
amount = 0
- kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last
+ kbz_pay_method = PaymentMethodSetting.where(payment_method: KbzPay::KBZ_PAY, gateway_communication_type: ['api', 'Api'], is_active: true)
+ .where.not(gateway_url: [nil, ''], auth_token: [nil, ''], merchant_account_id: [nil, '']).last
sale_payment = SalePayment.where('sale_id=? and payment_method=? and payment_status!=?', sale_id, KbzPay::KBZ_PAY, 'dead').last
if !sale_payment.nil? and !kbz_pay_method.nil?
if sale_payment.payment_status == 'pending'
@@ -81,7 +82,7 @@ class SalePayment < ApplicationRecord
amount_due = invoice.sale_payments
.map(&:payment_amount).reduce(invoice.grand_total, :-)
end
-
+
if amount_due > 0
payment_status = false
membership_data = nil
@@ -121,10 +122,8 @@ class SalePayment < ApplicationRecord
payment_status,membership_data = dinga_payment
when "GiftVoucher"
payment_status = giftvoucher_payment
- when KbzPay::KBZ_PAY
- payment_status = kbz_payment
- else
- puts "it was something else"
+ else
+ payment_status = external_terminal_card_payment(payment_method, payment_for)
end
if payment_status
@@ -623,17 +622,6 @@ class SalePayment < ApplicationRecord
return payment_status
end
- def kbz_payment
- payment_status = false
- self.payment_amount = self.received_amount
- self.payment_reference = self.payment_reference
- self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
- self.payment_status = "paid"
- payment_status = self.save!
- # sale_update_payment_status(self.received_amount)
- return payment_status
- end
-
def sale_update_payment_status(paid_amount, check_foc = false)
#update amount_outstanding
if ['completed'].include? sale.sale_status
diff --git a/app/views/origami/others_payments/create.json.jbuilder b/app/views/origami/others_payments/create.json.jbuilder
new file mode 100644
index 00000000..9767a7d8
--- /dev/null
+++ b/app/views/origami/others_payments/create.json.jbuilder
@@ -0,0 +1,5 @@
+if(@status)
+ json.status @status
+else
+ json.status false
+end
diff --git a/app/views/origami/others_payments/index.html.erb b/app/views/origami/others_payments/index.html.erb
index 8bbc9747..d9ea86bc 100755
--- a/app/views/origami/others_payments/index.html.erb
+++ b/app/views/origami/others_payments/index.html.erb
@@ -19,7 +19,7 @@
<% end %>
-
<%= payment_method.payment_method %>
+
<%= payment_method.payment_method %>
<% end %>
@@ -45,7 +45,7 @@
payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment");
if(payment_type) {
$(".others-payment").hide();
- $(payment_type).each(function(i){
+ $(payment_type).each(function(i){
$("."+payment_type[i]).show();
});
}
diff --git a/app/views/origami/others_payments/new.html.erb b/app/views/origami/others_payments/new.html.erb
new file mode 100644
index 00000000..8962ceb6
--- /dev/null
+++ b/app/views/origami/others_payments/new.html.erb
@@ -0,0 +1,279 @@
+
+
+
+
+
+
<%= @membership_id%>
+
<%= @member_discount%>
+
<%= @sub_total%>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb
index 4f5d387a..6ed4044e 100755
--- a/app/views/origami/payments/show.html.erb
+++ b/app/views/origami/payments/show.html.erb
@@ -9,24 +9,24 @@
+ <%= render 'shared/license_expire_warning' %>
<%= render 'layouts/header' %>
<% flash.each do |type, message| %>
@@ -22,7 +23,6 @@
<%= message %>
<% end %>
- <%= render 'shared/license_expire_warning' %>
<%= yield %>
diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb
index e767bafe..c7b52bb8 100644
--- a/app/views/oqs/home/index.html.erb
+++ b/app/views/oqs/home/index.html.erb
@@ -1,5 +1,5 @@
-
+
<%= @filter %>
diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb
index 27d13860..c0e3a61d 100644
--- a/app/views/origami/addorders/detail.html.erb
+++ b/app/views/origami/addorders/detail.html.erb
@@ -4,7 +4,7 @@
<% type = request.path_info.include?('quick_service') || request.path_info.include?('food_court')%>
<% modify_order = request.path_info.include?('modify_order')%>
-
+
diff --git a/app/views/origami/cash_ins/new.html.erb b/app/views/origami/cash_ins/new.html.erb
index 5b23656e..675a82c4 100755
--- a/app/views/origami/cash_ins/new.html.erb
+++ b/app/views/origami/cash_ins/new.html.erb
@@ -1,4 +1,4 @@
-
+
<%= t :cash_in %>
diff --git a/app/views/origami/cash_outs/new.html.erb b/app/views/origami/cash_outs/new.html.erb
index ea83b2e0..f31feb62 100755
--- a/app/views/origami/cash_outs/new.html.erb
+++ b/app/views/origami/cash_outs/new.html.erb
@@ -1,4 +1,4 @@
-
+
<%= t :cash_out %>
diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb
index 5d24c9d1..2fa34e8c 100755
--- a/app/views/origami/discounts/index.html.erb
+++ b/app/views/origami/discounts/index.html.erb
@@ -1,4 +1,4 @@
-
+
diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb
index 39c33749..a583e659 100755
--- a/app/views/origami/home/index.html.erb
+++ b/app/views/origami/home/index.html.erb
@@ -1,4 +1,4 @@
-
+
diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb
index 8e3c3b18..c6bdfca3 100755
--- a/app/views/origami/home/show.html.erb
+++ b/app/views/origami/home/show.html.erb
@@ -1,4 +1,4 @@
-
+
diff --git a/app/views/origami/order_reservation/index.html.erb b/app/views/origami/order_reservation/index.html.erb
index 4355c06a..dcc6af33 100644
--- a/app/views/origami/order_reservation/index.html.erb
+++ b/app/views/origami/order_reservation/index.html.erb
@@ -1,6 +1,6 @@
<%= stylesheet_link_tag 'order_reservation', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'order_reservation', 'data-turbolinks-track': 'reload' %>
-
+
<%
pending_count = 0
diff --git a/app/views/origami/other_charges/index.html.erb b/app/views/origami/other_charges/index.html.erb
index 886eda51..06208b2f 100755
--- a/app/views/origami/other_charges/index.html.erb
+++ b/app/views/origami/other_charges/index.html.erb
@@ -1,4 +1,4 @@
-
+
@@ -202,7 +202,7 @@
<%else%>
<%end%>
-
+
diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb
index 6ed4044e..c9795298 100755
--- a/app/views/origami/payments/show.html.erb
+++ b/app/views/origami/payments/show.html.erb
@@ -1,4 +1,4 @@
-
+
diff --git a/app/views/origami/pending_order/index.html.erb b/app/views/origami/pending_order/index.html.erb
index 903c13a5..fe8ba72f 100644
--- a/app/views/origami/pending_order/index.html.erb
+++ b/app/views/origami/pending_order/index.html.erb
@@ -1,4 +1,4 @@
-
+
diff --git a/app/views/origami/pending_order/show.html.erb b/app/views/origami/pending_order/show.html.erb
index 73ee0040..9ad89797 100644
--- a/app/views/origami/pending_order/show.html.erb
+++ b/app/views/origami/pending_order/show.html.erb
@@ -1,4 +1,4 @@
-
+
diff --git a/app/views/origami/shifts/show.html.erb b/app/views/origami/shifts/show.html.erb
index a752e5b5..ec529e8c 100755
--- a/app/views/origami/shifts/show.html.erb
+++ b/app/views/origami/shifts/show.html.erb
@@ -1,4 +1,4 @@
-
+
diff --git a/app/views/origami/surveys/_form.html.erb b/app/views/origami/surveys/_form.html.erb
index 8bc99b8b..40e52db6 100755
--- a/app/views/origami/surveys/_form.html.erb
+++ b/app/views/origami/surveys/_form.html.erb
@@ -1,4 +1,4 @@
-
+
diff --git a/app/views/renew_license/expire.html.erb b/app/views/renew_license/expire.html.erb
index 67e9fe1a..d29c5923 100644
--- a/app/views/renew_license/expire.html.erb
+++ b/app/views/renew_license/expire.html.erb
@@ -8,13 +8,24 @@
text = "Your license will expire in #{day}."
end
%>
+
-
-
+
-
Renew Your License
+
Review Your License
<%= link_to origami_dashboard_url do %>

<% end %>
@@ -51,11 +62,10 @@
-
+
- <%= link_to 'Home', origami_dashboard_url, class: 'btn btn-primary btn-lg' %>
- <%= link_to 'Renew License', renew_url, class: 'btn btn-primary btn-lg float-right m-l-5 m-r-5' %>
-
+ <%= link_to 'Review License', renew_url, class: 'btn btn-primary btn-lg float-right m-l-10 m-r-5' %>
+ <%= link_to 'Go To Home', origami_dashboard_url, class: 'btn btn-default btn-lg float-right' %>
@@ -64,9 +74,9 @@
diff --git a/app/views/shared/_license_expire_warning.html.erb b/app/views/shared/_license_expire_warning.html.erb
index 0949aff7..a1292d4c 100644
--- a/app/views/shared/_license_expire_warning.html.erb
+++ b/app/views/shared/_license_expire_warning.html.erb
@@ -10,12 +10,38 @@
end
%>
<% if license_status == 0 || license_status == 2 %>
-
+
<%= text %>
- <%= link_to 'Renew License', expire_url, class: 'btn btn-sm btn-primary', style: "margin-left: 40px !important"%>
-
-<% end %>
\ No newline at end of file
+<% end %>
+
+
\ No newline at end of file
diff --git a/config/license.yml b/config/license.yml
index 6148ed67..edd39369 100644
--- a/config/license.yml
+++ b/config/license.yml
@@ -1,19 +1,17 @@
---
localhost:
- iv_key: c5bODYtxFPckKXr3bLPdnQ==
+ iv_key: 03TLQUDDVSOPa/lEEHqhVw==
shop_name: scdemo3
email: hanwintun@code2lab.com
telephone: ''
fax: ''
address: ''
- dbhost: eFiEpFewQVPPylY1pefN2ZIVmxg9v7G1YrnHtNIPIbQQg7WtffKz35uCcOwgwzEvCTPUhPQama4B80FHyTpn3Q==
- dbschema: PRMtXnRsDZQjF319ItO7Lw==
- dbusername: QYngtMBsTBV/B17XiH5zhQ==
- dbpassword: vXsZqV2sJQ+tjIiGBb7N8A==
+ dbhost: gG0jQLrVX6l0dZaA5wVP9bNTrfgzotwAcjcFKQmM9WUQ5121pkwg+9mYh5XDrIwL4//1UNjRR6CNZPorBMGtAw==
+ dbschema: M9ddWoBb89JN51Ld1r7vTw==
+ dbusername: 8Lc2lKIyJld/xfG6+ZxcOw==
+ dbpassword: "+EhtSe5kJuVKp+wFMRlmoA=="
api_token: UQFLAbMvJxUCnDVCOhIdqYZEGRqVQMvI
app_token: DvRXGlomaBFpGVLYsidekVVZyqosntouTA
- plan_sku: AqCfY9X2C03i+XBLnvRz5w==
- renewable_date: 'MXf+rRgjWFxIRgpf+Aa4JA==
-
-'
- plan_name: bDYhVmEo9MNZmfIxwxE30BFHUKWTDVkVDnUiE6htM5Y=
+ plan_sku: 2NY6p1HAlR7UqE8AsBEytg==
+ renewable_date: vlKVqrJyCB6LxXTkv63COg==
+ plan_name: 6NSPpVHcwHBoFZPcVNjkvD6F5quXIWVaWieCRzpspbE=
From 98ca01533e66feda02b89729af1abb724faaa1ab Mon Sep 17 00:00:00 2001
From: NyanLinHtut
Date: Mon, 8 Jun 2020 10:13:55 +0630
Subject: [PATCH 28/28] change hardcoded payment methods
---
.../origami/discounts_controller.rb | 2 +-
.../origami/others_payments_controller.rb | 2 +-
app/controllers/origami/shifts_controller.rb | 4 +-
.../reports/payment_method_controller.rb | 26 +-
.../reports/shiftsale_controller.rb | 5 +-
app/models/printer/cashier_station_printer.rb | 6 +-
app/models/sale.rb | 156 +++++------
app/models/sale_payment.rb | 12 +-
app/models/shift_sale.rb | 16 +-
app/pdf/close_cashier_pdf.rb | 251 +++++++++---------
app/views/origami/dashboard/index.html.erb | 55 ++--
app/views/origami/payments/show.html.erb | 13 +-
app/views/reports/dailysale/index.html.erb | 177 +-----------
app/views/reports/dailysale/index.xls.erb | 162 +----------
.../reports/payment_method/index.html.erb | 31 +--
.../reports/payment_method/index.xls.erb | 30 +--
16 files changed, 302 insertions(+), 646 deletions(-)
diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb
index 6f4690f0..19a9f087 100755
--- a/app/controllers/origami/discounts_controller.rb
+++ b/app/controllers/origami/discounts_controller.rb
@@ -87,7 +87,7 @@ class Origami::DiscountsController < BaseOrigamiController
remark = "Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} "
sale_audit = SaleAudit.record_audit_discount(sale_item.sale_id,sale.cashier_name, action_by,remark,"ITEMDISCOUNT" )
-
+
end
end
diff --git a/app/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb
index 964af260..fb75288d 100755
--- a/app/controllers/origami/others_payments_controller.rb
+++ b/app/controllers/origami/others_payments_controller.rb
@@ -5,7 +5,7 @@ class Origami::OthersPaymentsController < BaseOrigamiController
@cashier_type = params[:type]
path = request.fullpath
if path.include? ("credit_payment")
- @payment_method_setting = PaymentMethodSetting.where("LOWER(payment_method) in ('mpu','visa','master','jcb','unionpay','alipay') and is_active='1'")
+ @payment_method_setting = PaymentMethodSetting.where("is_active='1'")
else
@payment_method_setting = PaymentMethodSetting.all
end
diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb
index f28c1428..be13f2d0 100755
--- a/app/controllers/origami/shifts_controller.rb
+++ b/app/controllers/origami/shifts_controller.rb
@@ -112,7 +112,7 @@ class Origami::ShiftsController < BaseOrigamiController
@total_takeway = ShiftSale.get_total_takeway(@shift).total_takeway_amount
@total_other_charges = ShiftSale.get_total_other_charges(@shift).total_other_charges_amount
@total_credit_payments = ShiftSale.get_shift_sales_with_credit_payment(shift_id).total_credit_payments
-
+ @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method")
# get printer info
print_settings = PrintSetting.find_by_unique_code(unique_code)
printer = Printer::CashierStationPrinter.new(print_settings)
@@ -125,7 +125,7 @@ class Origami::ShiftsController < BaseOrigamiController
end
find_close_cashier_print = Lookup.collection_of('close_cashier_print')
if find_close_cashier_print[0][1].to_i > 0
- printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments)
+ printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments,@payment_methods)
end
end
end
diff --git a/app/controllers/reports/payment_method_controller.rb b/app/controllers/reports/payment_method_controller.rb
index 414c4e07..752a2f4e 100644
--- a/app/controllers/reports/payment_method_controller.rb
+++ b/app/controllers/reports/payment_method_controller.rb
@@ -1,28 +1,30 @@
-class Reports::PaymentMethodController < BaseReportController
+class Reports::PaymentMethodController < BaseReportController
# authorize_resource :class => false
def index
- @payments = [["All Payment",''],["Cash Payment","cash"], ["KBZ Payment", KbzPay::KBZ_PAY], ["Credit Payment","creditnote"],
- ["FOC Payment","foc"], ["MPU Payment","mpu"], ["Visa Payment","visa"],
- ["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"],
- ["Alipay Payment","alipay"],["Paymal Payment", "paymal"],["Dinga Payment","dinga"],
- ["JunctionPay","junctionpay"],["Redeem Payment","paypar"],["Gift Voucher","giftvoucher"]]
+ @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method")
+
+ @payments = [["All Payment",''],["Cash Payment","cash"], ["Credit Payment","creditnote"],
+ ["FOC Payment","foc"]]
+
+ @payment_methods.each do |m|
+ @payments.push(["#{m} Payment", m.parameterize])
+ end
from, to = get_date_range_from_params
- @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED)
@shift = ''
if params[:shift_name].to_i != 0
shift_sale = ShiftSale.find(params[:shift_name])
- if to.blank?
+ if to.blank?
@shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at)
else
- @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at)
+ @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at)
end
end
@payment_type = params[:payment_type]
- @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift_sale_range,@shift,from,to,@payment_type)
+ @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift,from,to,@payment_type)
@from = from
@to = to
# get printer info
@@ -58,10 +60,10 @@ class Reports::PaymentMethodController < BaseReportController
end
out = {:status => 'ok', :message => date_arr}
-
+
respond_to do |format|
format.json { render json: out }
end
end
-end
\ No newline at end of file
+end
diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb
index 0c42a05f..ce927f8e 100755
--- a/app/controllers/reports/shiftsale_controller.rb
+++ b/app/controllers/reports/shiftsale_controller.rb
@@ -80,6 +80,7 @@ class Reports::ShiftsaleController < BaseReportController
@total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total)
#other payment details for mpu or visa like card
@other_payment = ShiftSale.get_by_shift_other_payment(@shift)
+ @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method")
# Calculate price_by_accounts
@total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount')
@@ -95,8 +96,8 @@ class Reports::ShiftsaleController < BaseReportController
printer = Printer::CashierStationPrinter.new(print_settings)
# printer.print_close_cashier(print_settings,cashier_terminal,@shift, nil, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments)
- printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments)
-
+ printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments,@payment_methods)
+
respond_to do |format|
format.html { redirect_to '/en/reports/shiftsale/', notice: 'Printing Completed.'}
format
diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb
index 5e37164f..63ffc53e 100755
--- a/app/models/printer/cashier_station_printer.rb
+++ b/app/models/printer/cashier_station_printer.rb
@@ -38,7 +38,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
# self.print(filename, cashier_terminal.printer_name)
# end
- def print_close_cashier(printer_settings,cashier_terminal,shift_sale, sale_items, total_other_charges_info,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
+ def print_close_cashier(printer_settings,cashier_terminal,shift_sale, sale_items, total_other_charges_info,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods)
if !sale_items.blank? or !sale_items.nil?
@account_cate_count = Hash.new {|hash, key| hash[key] = 0}
@@ -59,7 +59,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
cashier = shift_sale.employee.name
shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p")
filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf"
- pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
+ pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods)
close_cashier_pdf = Lookup.collection_of("print_settings") #print_settings with name:CloseCashierPdf
if !close_cashier_pdf.empty?
@@ -68,7 +68,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker
if close_cashier[1] == '1'
pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
else
- pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
+ pdf = CloseCashierPdf.new(printer_settings,shift_sale, sale_items, total_other_charges_info, @account_cate_count, @menu_cate_count, @totalByAccount, shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods)
end
end
end
diff --git a/app/models/sale.rb b/app/models/sale.rb
index f990c947..aa2b6992 100644
--- a/app/models/sale.rb
+++ b/app/models/sale.rb
@@ -748,66 +748,46 @@ class Sale < ApplicationRecord
return num
end
-def self.daily_sales_list(from,to)
+ def self.daily_sales_list(from,to)
+ payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
+
sales = select("
- sales.*,
- SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_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='unionpay') then sale_payments.payment_amount else 0 end) as unionpay_amount,
- SUM(case when (sale_payments.payment_method='alipay') then sale_payments.payment_amount else 0 end) as alipay_amount,
- SUM(case when (sale_payments.payment_method='paymal') then sale_payments.payment_amount else 0 end) as paymal_amount,
- SUM(case when (sale_payments.payment_method='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount,
- SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount,
- SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
- CASE WHEN SUM(case when sale_payments.payment_method not in('creditnote')
- then sale_payments.payment_amount else 0 end) < sales.grand_total
- THEN sales.grand_total - SUM(case when sale_payments.payment_method not in('creditnote')
- then sale_payments.payment_amount else 0 end)
- ELSE 0 END as credit_amount,
- 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)
- .group("sale_id").to_sql
+ sales.*,
+ #{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method}"}.join(', ')},
+ SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
+ CASE WHEN SUM(case when sale_payments.payment_method not in('creditnote')
+ then sale_payments.payment_amount else 0 end) < sales.grand_total
+ THEN sales.grand_total - SUM(case when sale_payments.payment_method not in('creditnote')
+ then sale_payments.payment_amount else 0 end)
+ 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")
+ .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)
+ .group("sale_id").to_sql
daily_total = connection.select_all("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 grand_total else 0 end),0) as total_sale,
- IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_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='completed') then amount_changed else 0 end),0) as total_change_amount,
- 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,
- IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21 as tax,
- (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0))-(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale,
- (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,
- SUM(kbzpay_amount) as kbzpay_amount,
- SUM(mpu_amount) as mpu_amount,
- SUM(master_amount) as master_amount,
- SUM(visa_amount) as visa_amount,
- SUM(jcb_amount) as jcb_amount,
- SUM(paypar_amount) as paypar_amount,
- SUM(unionpay_amount) as unionpay_amount,
- SUM(alipay_amount) as alipay_amount,
- SUM(paymal_amount) as paymal_amount,
- SUM(dinga_amount) as dinga_amount,
- SUM(junctionpay_amount) as junctionpay_amount,
- SUM(cash_amount) as cash_amount,
- SUM(credit_amount) as credit_amount,
- SUM(giftvoucher_amount) as giftvoucher_amount,
- SUM(foc_amount) as foc_amount
- FROM (
- #{sales}
- ) as s
- GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys)
+ 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 grand_total else 0 end),0) as total_sale,
+ IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_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='completed') then amount_changed else 0 end),0) as total_change_amount,
+ 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,
+ IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21 as tax,
+ (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0))-(IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale,
+ (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| "SUM(#{method}) as #{method}"}.join(', ')},
+ SUM(cash_amount) as cash_amount,
+ SUM(credit_amount) as credit_amount,
+ SUM(foc_amount) as foc_amount
+ FROM (
+ #{sales}
+ ) as s
+ GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys)
return daily_total
-end
+ end
def self.get_by_range_by_saleitems(from,to,status,report_type)
query = Sale.select("
@@ -973,6 +953,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
other_charges = self.get_other_charges()
end
product = self.get_product_sale()
+ payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
if shift.present?
query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a)
@@ -982,7 +963,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
- sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
+ sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_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='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")
@@ -1005,7 +986,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
- sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
+ sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_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='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")
@@ -1029,7 +1010,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
- sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
+ sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_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='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")
@@ -1060,6 +1041,8 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account
customer_id = customer_id.to_s
customer_id[0] = ""
customer_id = customer_id.chomp("]")
+ else
+ customer_id = "''"
end
query = self.get_staff_meal_query()
@@ -1076,16 +1059,17 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account
# other_charges = self.get_other_charges()
# end
product = self.get_product_sale()
+ payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
if shift.present?
- query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift.to_a)
+ query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN (#{customer_id})",shift.to_a)
# if type.nil? || type == 'all' || type == "other"
# other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
# end
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
- sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
+ sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_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='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")
@@ -1101,14 +1085,14 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account
### => get all sales range in shift_sales
elsif shift_sale_range.present?
- query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",shift_sale_range.to_a)
+ query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed' and sales.customer_id IN (#{customer_id})",shift_sale_range.to_a)
# if type.nil? || type == 'all' || type == "other"
# other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
# end
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
- sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
+ sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_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='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")
@@ -1124,7 +1108,7 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
else
- query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed' and sales.customer_id IN(#{customer_id})",from,to)
+ query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed' and sales.customer_id IN (#{customer_id})",from,to)
# if type.nil? || type == 'all' || type == "other"
# other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to)
# end
@@ -1132,7 +1116,7 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
- sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
+ sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_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='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")
@@ -1343,20 +1327,12 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type)
end
end
-def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type)
+def self.get_payment_method_by_shift(shift,from,to,payment_type)
+ payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
+
payments_total = SalePayment.select("
sales.receipt_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='unionpay') then sale_payments.payment_amount else 0 end) as unionpay_amount,
- SUM(case when (sale_payments.payment_method='alipay') then sale_payments.payment_amount else 0 end) as alipay_amount,
- SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount,
- SUM(case when (sale_payments.payment_method='paymal') then sale_payments.payment_amount else 0 end) as paymal_amount,
- SUM(case when (sale_payments.payment_method='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount,
- SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount,
+ #{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method}"}.join(', ')},
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='cash') then
sales.amount_changed else 0 end) as total_change_amount,
@@ -1384,9 +1360,6 @@ def self.get_payment_method_by_shift(shift_sale_range,shift,from,to,payment_type
if shift.present?
payments_total = payments_total.where(sales: {shift_sale_id: shift.to_a})
sale_payment = sale_payment.merge(Sale.where(sales: {shift_sale_id: shift.to_a}))
- elsif shift_sale_range.present?
- payments_total = payments_total.where(sales: {shift_sale_id: shift_sale_range.to_a})
- sale_payment = sale_payment.merge(Sale.where(sales: {shift_sale_id: shift_sale_range.to_a}))
end
if payment_type.present?
@@ -1513,11 +1486,12 @@ end
end
payments_for_credits = SalePayment.joins(:sale_audit).to_sql
+ payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
query = employee_sale(shift, from, to)
.joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id")
.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount,
- CASE WHEN sale_payments.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card'
+ CASE WHEN sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }) THEN 'card'
ELSE sale_payments.payment_method END AS payment_method, employees.name AS e_name")
end
@@ -1541,8 +1515,9 @@ end
end
def self.total_card_sale(current_user=nil,from=nil,to=nil)
+ payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
query = Sale.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
- .where('sales.sale_status = "completed" 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" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")')
+ .where("sales.sale_status = 'completed' and (sp.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }))")
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
@@ -1602,10 +1577,11 @@ end
end
def self.total_payment_methods(current_user=nil,from=nil,to=nil)
- query = Sale.select("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END as payment_method")
+ payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
+ query = Sale.select("CASE WHEN sp.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }) THEN 'card' ELSE sp.payment_method END as payment_method")
.where("sales.sale_status = 'completed'")
.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id")
- .group("CASE WHEN sp.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' ELSE sp.payment_method END")
+ .group("CASE WHEN sp.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') }) THEN 'card' ELSE sp.payment_method END")
if (!from.nil? && !to.nil?)
query = query.receipt_date_between(from, to)
@@ -2039,6 +2015,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco
other_charges = self.get_other_charges()
end
product = self.get_product_sale()
+ payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
if shift.present?
query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a)
@@ -2048,7 +2025,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
- sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
+ sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_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='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")
@@ -2071,7 +2048,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco
product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
- sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
+ sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_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='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")
@@ -2095,7 +2072,7 @@ def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,acco
discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount)
change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed)
- sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount,
+ sale_cash = Sale.select("SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as card_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='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")
@@ -2255,8 +2232,9 @@ def self.get_daily_sale_data(transaction_date)
end
def self.get_check_sale_data(transaction_date)
+ payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
sale_receivables_subquery = "SELECT sale_payments.sale_id,
- CASE WHEN sale_payments.payment_method = 'mpu' OR sale_payments.payment_method = 'visa' OR sale_payments.payment_method = 'master' OR sale_payments.payment_method = 'jcb' OR sale_payments.payment_method = 'paypar' OR sale_payments.payment_method = 'unionpay' OR sale_payments.payment_method = 'alipay' OR sale_payments.payment_method = 'paymal' OR sale_payments.payment_method = 'dinga' OR sale_payments.payment_method = 'JunctionPay' THEN SUM(sale_payments.payment_amount) ELSE SUM(0) END as credit_card_sales,
+ SUM(case when (sale_payments.payment_method IN (#{payment_methods.map{ |pm| "\"#{pm}\"" }.join(', ') })) then (sale_payments.payment_amount) else 0 end) as credit_card_sales,
CASE WHEN sale_payments.payment_method = 'giftvoucher' THEN SUM(sale_payments.payment_amount) ELSE SUM(0) END as voucher_sales
FROM sale_payments
GROUP BY sale_payments.sale_id, sale_payments.payment_method"
@@ -2315,7 +2293,9 @@ private
self.total_tax = self.total_tax.round(precision)
end
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
- adjust_rounding
+ if (!['foc'].include? self.payment_status)
+ adjust_rounding
+ end
end
def update_stock_journal
diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb
index 70812e11..9ade9920 100755
--- a/app/models/sale_payment.rb
+++ b/app/models/sale_payment.rb
@@ -11,7 +11,7 @@ class SalePayment < ApplicationRecord
attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status,:action_by
scope :credits, -> { where(payment_method: 'creditnote') }
- scope :cards, -> { where(payment_method: ['mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher']) }
+ scope :cards, -> { where(payment_method: PaymentMethodSetting.where("is_active='1'").pluck("payment_method")) }
def self.sync_sale_payment_records(sale_payments)
if !sale_payments.nil?
@@ -364,10 +364,16 @@ class SalePayment < ApplicationRecord
# Check for Card Payment
def self.get_sale_payments_by_card(sale_payments)
# Check for Card Payment
+ payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
sale_payments.each do |sp|
- if sp.payment_method == "jcb" || sp.payment_method == "mpu" || sp.payment_method == "visa" || sp.payment_method == "master" || sp.payment_method == "unionpay" || sp.payment_method == "alipay"
- return true;
+ payment_methods.each do |m|
+ if sp.payment_method == m
+ return true;
+ end
end
+ # if sp.payment_method == "jcb" || sp.payment_method == "mpu" || sp.payment_method == "visa" || sp.payment_method == "master" || sp.payment_method == "unionpay" || sp.payment_method == "alipay"
+ # return true;
+ # end
end
end
diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb
index 56db452f..f3280f76 100755
--- a/app/models/shift_sale.rb
+++ b/app/models/shift_sale.rb
@@ -150,21 +150,11 @@ class ShiftSale < ApplicationRecord
end
def self.get_by_shift_other_payment(shift)
+ payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method)
other_payment = Sale.select("sale_payments.payment_method as name,
- 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='visa') then (sale_payments.payment_amount) else 0 end) as visa_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='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='alipay') then (sale_payments.payment_amount) else 0 end) as alipay_amount,
- SUM(case when (sale_payments.payment_method='KBZPay') then (sale_payments.payment_amount) else 0 end) as kbzpay_amount,
- SUM(case when (sale_payments.payment_method='dinga') then (sale_payments.payment_amount) else 0 end) as dinga_amount,
- 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='JunctionPay') then (sale_payments.payment_amount) else 0 end) as junctionpay_amount,
- SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount,
- SUM(case when (sale_payments.payment_method='paymal') then (sale_payments.payment_amount) else 0 end) as paymal_amount,
- SUM(case when (sale_payments.payment_method='paypar') then (sale_payments.payment_amount) else 0 end) as paypar_amount")
+ #{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as #{method}"}.join(', ')},
+ SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id)
end
diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb
index 976c3d93..e6b594bc 100755
--- a/app/pdf/close_cashier_pdf.rb
+++ b/app/pdf/close_cashier_pdf.rb
@@ -2,7 +2,7 @@ class CloseCashierPdf < Prawn::Document
include NumberFormattable
attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width
- def initialize(printer_settings, shift_sale, sale_items, total_other_charges_info, acc_cate_count, menu_cate_count, total_by_acc, shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments)
+ def initialize(printer_settings, shift_sale, sale_items, total_other_charges_info, acc_cate_count, menu_cate_count, total_by_acc, shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments,payment_methods)
self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width
self.page_height = printer_settings.page_height
self.header_font_size = printer_settings.header_font_size.to_i
@@ -43,7 +43,7 @@ class CloseCashierPdf < Prawn::Document
stroke_horizontal_rule
- shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments)
+ shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments,payment_methods)
if !sale_items.nil? or !sale_items.blank?
sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges_info)
@@ -63,7 +63,7 @@ class CloseCashierPdf < Prawn::Document
stroke_horizontal_rule
end
- def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments)
+ def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments,payment_methods)
move_down 7
y_position = cursor
bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do
@@ -173,125 +173,138 @@ class CloseCashierPdf < Prawn::Document
if shift_sale.other_sales > 0
other_payment.each do |other|
@total_foc = other.foc_amount.round(2)
- if other.mpu_amount && other.mpu_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "MPU Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+
+ if !payment_methods.nil?
+ payment_methods.each do |method|
+ y_position = cursor
+ bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ text "#{method} Payment :", :size => self.item_font_size, :align => :right
+ end
+ bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ text "#{ number_format(other[method.parameterize.to_sym], :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ end
end
end
- if other.visa_amount && other.visa_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "VISA Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
- end
- end
-
- if other.master_amount && other.master_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "Master Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
- end
- end
-
- if other.jcb_amount && other.jcb_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "JCB Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
- end
- end
-
- if other.unionpay_amount && other.unionpay_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
- end
- end
-
- if other.alipay_amount && other.alipay_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "Alipay Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
- end
- end
-
- if other.kbzpay_amount && other.kbzpay_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "KBZ Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{ number_format(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
- end
- end
-
- if other.junctionpay_amount && other.junctionpay_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "JunctionPay Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
- end
- end
-
- if other.dinga_amount && other.dinga_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "Dinga Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
- end
- end
-
- if other.paypar_amount && other.paypar_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "Redeem Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
- end
- end
-
- if other.paymal_amount && other.paymal_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "Paymal Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
- end
- end
-
- if other.giftvoucher_amount && other.giftvoucher_amount.to_f > 0
- y_position = cursor
- bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
- text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right
- end
- bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
- text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
- end
- end
+ # if other.mpu_amount && other.mpu_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "MPU Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
+ #
+ # if other.visa_amount && other.visa_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "VISA Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
+ #
+ # if other.master_amount && other.master_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "Master Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
+ #
+ # if other.jcb_amount && other.jcb_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "JCB Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
+ #
+ # if other.unionpay_amount && other.unionpay_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
+ #
+ # if other.alipay_amount && other.alipay_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "Alipay Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
+ #
+ # if other.kbzpay_amount && other.kbzpay_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "KBZ Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{ number_format(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
+ #
+ # if other.junctionpay_amount && other.junctionpay_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "JunctionPay Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
+ #
+ # if other.dinga_amount && other.dinga_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "Dinga Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
+ #
+ # if other.paypar_amount && other.paypar_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "Redeem Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
+ #
+ # if other.paymal_amount && other.paymal_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "Paymal Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
+ #
+ # if other.giftvoucher_amount && other.giftvoucher_amount.to_f > 0
+ # y_position = cursor
+ # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do
+ # text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right
+ # end
+ # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do
+ # text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right
+ # end
+ # end
end
else
y_position = cursor
diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb
index 713ba6a5..38df56b3 100644
--- a/app/views/origami/dashboard/index.html.erb
+++ b/app/views/origami/dashboard/index.html.erb
@@ -96,36 +96,35 @@
<% if !(@total_payment_methods.nil?) %>
- <% @total_payment_methods.each do |payment| %>
- <% if !@sale_data[0].empty? %>
- <% if payment.payment_method != 'mpu' && payment.payment_method != 'visa' && payment.payment_method != 'master' && payment.payment_method != 'jcb' %>
-
- <% if payment.payment_method == 'paypar' %>
- | Redeem Sale : |
- <% else %>
- <%= payment.payment_method.to_s.capitalize %> Sale : |
- <% end %>
-
- <% @sale_data.each do |data| %>
- <% pay_mth = payment.payment_method %>
- <%= data[""+pay_mth+""] %>
+ <% @total_payment_methods.each do |payment| %>
+ <% if !@sale_data[0].empty? %>
+ <% if payment.payment_method != 'mpu' && payment.payment_method != 'visa' && payment.payment_method != 'master' && payment.payment_method != 'jcb' %>
+ |
+ <% if payment.payment_method == 'paypar' %>
+ | Redeem Sale : |
+ <% else %>
+ <%= payment.payment_method.to_s.capitalize %> Sale : |
+ <% end %>
+
+ <% @sale_data.each do |data| %>
+ <% pay_mth = payment.payment_method %>
+ <%= data[""+pay_mth+""] %>
+ <% end %>
+ |
+
+ <% end %>
<% end %>
-
-
- <% end %>
- <% end %>
- <% end %>
-
- <% total_card = @sale_data.select { |hash| hash["card"]!=nil }.first %>
- <% if !total_card.nil? %>
-
- | <%= t("views.right_panel.detail.other_payment") %> : |
-
- <%= total_card["card"].to_f %>
- |
-
- <% end %>
+ <% end %>
+ <% total_card = @sale_data.select { |hash| hash["card"]!=nil }.first %>
+ <% if !total_card.nil? %>
+
+ | <%= t("views.right_panel.detail.other_payment") %> : |
+
+ <%= total_card["card"].to_f %>
+ |
+
+ <% end %>
<% end %>
diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb
index 6ed4044e..482a2402 100755
--- a/app/views/origami/payments/show.html.erb
+++ b/app/views/origami/payments/show.html.erb
@@ -600,9 +600,9 @@ $(document).ready(function(){
}
// if ($("#server_mode").val() != "cloud") { // first bill not used in cloud
- payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment");
- other_payment = payment_methods.find(x => payment_type.indexOf(x) >= 0)
- // console.log(payment_type)
+ payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment")
+
+ console.log(payment_type)
// console.log(parseInt(jQuery.inArray("MPU", payment_type)))
if (member_id && member_discount) {
if(parseInt(jQuery.inArray("Credit", payment_type)) == -1){
@@ -611,7 +611,7 @@ $(document).ready(function(){
$("#credit_payment").show();
}
- if(other_payment){
+ if(payment_type && payment_methods.some(x => payment_type.indexOf(x) >= 0)){
$("#card_payment").show();
} else{
$("#card_payment").hide();
@@ -680,9 +680,8 @@ $(document).ready(function(){
$('#pay').click(function() {
sub_total = $('#sub-total').text();
member = $('#membership_id').text();
- // console.log(member)
- if (other_payment && !other_payments.some(x => x[0] == other_payment && x[1] > 0 ) && sub_total != 0.0 && member) {
- swal("Oops","Please Pay with " + other_payment + " Payment","warning");
+ if (payment_type && !other_payments.some(x => payment_type.indexOf(x[0]) >= 0 && x[1] > 0 ) && sub_total != 0.0 && member) {
+ swal("Oops","Please Pay with " + payment_methods.find(x => payment_type.indexOf(x) >= 0) + " Payment","warning");
} else {
$( "#loading_wrapper").show();
if($('#balance').text() > 0){
diff --git a/app/views/reports/dailysale/index.html.erb b/app/views/reports/dailysale/index.html.erb
index 13b315de..db25ce0c 100755
--- a/app/views/reports/dailysale/index.html.erb
+++ b/app/views/reports/dailysale/index.html.erb
@@ -82,44 +82,11 @@
| <%= t("views.right_panel.detail.sr") %> |
- <%= t("views.right_panel.detail.date") %> |
+ <%= t("views.righ_panel.detail.date") %> |
+ <% @payment_methods.each do |method| %>
+ <%= t("views.right_panel.detail.#{method}") %> |
+ <% end %>
- <% if @payment_methods.include? ("MPU") %>
- <%= t("views.right_panel.detail.mpu_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("Master") %>
- <%= t("views.right_panel.detail.master_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("VISA") %>
- <%= t("views.right_panel.detail.visa_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("JCB") %>
- <%= t("views.right_panel.detail.jcb_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("UNIONPAY") %>
- <%= t("views.right_panel.detail.unionpay_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("KBZPay") %>
- <%= t("views.right_panel.detail.kbzpay_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("Alipay") %>
- <%= t("views.right_panel.detail.alipay_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("PAYMAL") %>
- <%= t("views.right_panel.detail.paymal_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("DINGA") %>
- <%= t("views.right_panel.detail.dinga_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("JunctionPay") %>
- <%= t("views.right_panel.detail.junctionpay_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("Redeem") %>
- <%= t("views.right_panel.detail.redeem_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("GiftVoucher") %>
- <%= t("views.right_panel.detail.giftvoucher_sales") %> |
- <% end %>
<%= t("views.right_panel.detail.cash_sales") %> |
<%= t("views.right_panel.detail.credit_sales") %> |
<%= t("views.right_panel.detail.void_amount") %> |
@@ -140,22 +107,10 @@
<% unless @sale_data.blank? %>
<% void = 0 %>
- <% mpu = 0 %>
- <% master = 0 %>
- <% visa = 0 %>
- <% jcb = 0 %>
- <% unionpay = 0 %>
- <% alipay = 0 %>
- <% paymal = 0 %>
- <% dinga = 0 %>
- <% junctionpay = 0 %>
- <% giftvoucher = 0 %>
- <% paypar = 0 %>
<% cash = 0 %>
<% credit = 0 %>
<% foc = 0 %>
<% discount = 0 %>
- <% kbzpay = 0 %>
<% total = 0 %>
<% grand_total = 0 %>
<% old_grand_total = 0 %>
@@ -164,24 +119,13 @@
<% tax = 0 %>
<% net_sale = 0 %>
<% count = 1 %> <% rounding_adj = 0 %>
+
<% @sale_data.each do |sale| %>
<% void += sale[:void_amount] %>
- <% mpu += sale[:mpu_amount] %>
- <% master += sale[:master_amount] %>
- <% visa += sale[:visa_amount] %>
- <% jcb += sale[:jcb_amount] %>
- <% unionpay += sale[:unionpay_amount] %>
- <% alipay += sale[:alipay_amount] %>
- <% paymal += sale[:paymal_amount] %>
- <% dinga += sale[:dinga_amount] %>
- <% junctionpay += sale[:junctionpay_amount] %>
- <% giftvoucher += sale[:giftvoucher_amount] %>
- <% paypar += sale[:paypar_amount] %>
<% cash += sale[:cash_amount]-sale[:total_change_amount] %>
<% credit += sale[:credit_amount] %>
<% foc += sale[:foc_amount] %>
<% discount += sale[:total_discount] %>
- <% kbzpay += sale[:kbzpay_amount] %>
<% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %>
<% grand_total += sale[:grand_total].to_f %>
<% old_grand_total += sale[:old_grand_total].to_f %>
@@ -193,41 +137,8 @@
| <%= count %> |
<%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %> |
- <% if @payment_methods.include? ("MPU") %>
- <%= number_format(sale[:mpu_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("Master") %>
- <%= number_format(sale[:master_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("VISA") %>
- <%= number_format(sale[:visa_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("JCB") %>
- <%= number_format(sale[:jcb_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("UNIONPAY") %>
- <%= number_format(sale[:unionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("Alipay") %>
- <%= number_format(sale[:alipay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("KBZPay") %>
- <%= number_format(sale[:kbzpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("PAYMAL") %>
- <%= number_format(sale[:paymal_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("DINGA") %>
- <%= number_format(sale[:dinga_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("JunctionPay") %>
- <%= number_format(sale[:junctionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("Redeem") %>
- <%= number_format(sale[:paypar_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("GiftVoucher") %>
- <%= number_format(sale[:giftvoucher_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
+ <% @payment_methods.each do |method| %>
+ <%= number_format(sale[method.parameterize.to_sym], precision:precision.to_i, delimiter: delimiter) rescue 0 %> |
<% end %>
<%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision:precision.to_i, delimiter: delimiter) rescue '-'%> |
<%= number_format(sale[:credit_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
@@ -236,7 +147,7 @@
(<%= number_format(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>) |
- <%= number_format(sale[:rounding_adj].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
+ <%= number_format(sale[:rounding_adj], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
<%= number_format(sale[:gross_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
<%= number_format(sale[:total_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
<% if @tax.blank? %>
@@ -250,75 +161,9 @@
<% colspan = 7 %>
| Total |
- <% if @payment_methods.include? ("MPU") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(mpu , precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end%>
- <% if @payment_methods.include? ("Master") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(master, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end%>
- <% if @payment_methods.include? ("VISA") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(visa, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end%>
- <% if @payment_methods.include? ("JCB") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(jcb, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end%>
- <% if @payment_methods.include? ("UNIONPAY") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(unionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("Alipay") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(alipay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("KBZPay") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(kbzpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("PAYMAL") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(paymal, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("DINGA") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(dinga, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("JunctionPay") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(junctionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("Redeem") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(paypar, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("GiftVoucher") %>
- <% colspan += 1 %>
- <%= number_format(giftvoucher, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
+ <% @payment_methods.each do |method| %>
+ <% colspan += 1 %>
+ <%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[method.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue 0 %> |
<% end %>
<%= number_format(cash, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
<%= number_format(credit, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
diff --git a/app/views/reports/dailysale/index.xls.erb b/app/views/reports/dailysale/index.xls.erb
index f3d0aa2b..cc0eced9 100755
--- a/app/views/reports/dailysale/index.xls.erb
+++ b/app/views/reports/dailysale/index.xls.erb
@@ -27,41 +27,8 @@
<%= t("views.right_panel.detail.sr") %> |
<%= t("views.right_panel.detail.date") %> |
- <% if @payment_methods.include? ("MPU") %>
- <%= t("views.right_panel.detail.mpu_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("Master") %>
- <%= t("views.right_panel.detail.master_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("VISA") %>
- <%= t("views.right_panel.detail.visa_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("JCB") %>
- <%= t("views.right_panel.detail.jcb_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("UNIONPAY") %>
- <%= t("views.right_panel.detail.unionpay_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("KBZPay") %>
- <%= t("views.right_panel.detail.kbzpay_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("Alipay") %>
- <%= t("views.right_panel.detail.alipay_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("PAYMAL") %>
- <%= t("views.right_panel.detail.paymal_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("DINGA") %>
- <%= t("views.right_panel.detail.dinga_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("JunctionPay") %>
- <%= t("views.right_panel.detail.junctionpay_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("Redeem") %>
- <%= t("views.right_panel.detail.redeem_sales") %> |
- <% end %>
- <% if @payment_methods.include? ("GiftVoucher") %>
- <%= t("views.right_panel.detail.giftvoucher_sales") %> |
+ <% @payment_methods.each do |method| %>
+ <%= t("views.right_panel.detail.#{method}") %> |
<% end %>
<%= t("views.right_panel.detail.cash_sales") %> |
<%= t("views.right_panel.detail.credit_sales") %> |
@@ -108,22 +75,10 @@
<% count = 1 %> <% rounding_adj = 0 %>
<% @sale_data.each do |sale| %>
<% void += sale[:void_amount] %>
- <% mpu += sale[:mpu_amount] %>
- <% master += sale[:master_amount] %>
- <% visa += sale[:visa_amount] %>
- <% jcb += sale[:jcb_amount] %>
- <% unionpay += sale[:unionpay_amount] %>
- <% alipay += sale[:alipay_amount] %>
- <% paymal += sale[:paymal_amount] %>
- <% dinga += sale[:dinga_amount] %>
- <% junctionpay += sale[:junctionpay_amount] %>
- <% giftvoucher += sale[:giftvoucher_amount] %>
- <% paypar += sale[:paypar_amount] %>
<% cash += sale[:cash_amount]-sale[:total_change_amount] %>
<% credit += sale[:credit_amount] %>
<% foc += sale[:foc_amount] %>
<% discount += sale[:total_discount] %>
- <% kbzpay += sale[:kbzpay_amount] %>
<% total += sale[:grand_total].to_f + sale[:rounding_adj].to_f %>
<% grand_total += sale[:grand_total].to_f %>
<% old_grand_total += sale[:old_grand_total].to_f %>
@@ -135,41 +90,8 @@
| <%= count %> |
<%= sale[:sale_date].strftime("#{sale[:sale_date].day.ordinalize} %b") rescue '-' %> |
- <% if @payment_methods.include? ("MPU") %>
- <%= number_format(sale[:mpu_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("Master") %>
- <%= number_format(sale[:master_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("VISA") %>
- <%= number_format(sale[:visa_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("JCB") %>
- <%= number_format(sale[:jcb_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("UNIONPAY") %>
- <%= number_format(sale[:unionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("Alipay") %>
- <%= number_format(sale[:alipay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("KBZPay") %>
- <%= number_format(sale[:kbzpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("PAYMAL") %>
- <%= number_format(sale[:paymal_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("DINGA") %>
- <%= number_format(sale[:dinga_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("JunctionPay") %>
- <%= number_format(sale[:junctionpay_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("Redeem") %>
- <%= number_format(sale[:paypar_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("GiftVoucher") %>
- <%= number_format(sale[:giftvoucher_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
+ <% @payment_methods.each do |method| %>
+ <%= number_format(sale[method.parameterize.to_sym], precision:precision.to_i, delimiter: delimiter) rescue 0 %> |
<% end %>
<%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision:precision.to_i, delimiter: delimiter) rescue '-'%> |
<%= number_format(sale[:credit_amount], precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
@@ -192,75 +114,9 @@
<% colspan = 7 %>
| Total |
- <% if @payment_methods.include? ("MPU") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(mpu , precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end%>
- <% if @payment_methods.include? ("Master") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(master, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end%>
- <% if @payment_methods.include? ("VISA") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(visa, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end%>
- <% if @payment_methods.include? ("JCB") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(jcb, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end%>
- <% if @payment_methods.include? ("UNIONPAY") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(unionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("Alipay") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(alipay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("KBZPay") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(kbzpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("PAYMAL") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(paymal, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("DINGA") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(dinga, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("JunctionPay") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(junctionpay, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("Redeem") %>
- <% if !request.user_agent.include? "Mobile" %>
- <% colspan += 1 %>
- <% end %>
- <%= number_format(paypar, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
- <% end %>
- <% if @payment_methods.include? ("GiftVoucher") %>
- <% colspan += 1 %>
- <%= number_format(giftvoucher, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
+ <% @payment_methods.each do |method| %>
+ <% colspan += 1 %>
+ <%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[method.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue 0 %> |
<% end %>
<%= number_format(cash, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
<%= number_format(credit, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
@@ -293,12 +149,12 @@
<% net = net - total_tax %>
| <%= t("views.right_panel.detail.net_amount") %> |
- <%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
+ <%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
<% else %>
| <%= t("views.right_panel.detail.net_amount") %> |
- <%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
+ <%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%> |
<% end %>
diff --git a/app/views/reports/payment_method/index.html.erb b/app/views/reports/payment_method/index.html.erb
index ed0ffec3..93f7be28 100755
--- a/app/views/reports/payment_method/index.html.erb
+++ b/app/views/reports/payment_method/index.html.erb
@@ -40,42 +40,25 @@
<% end %>
- | <%= t("views.right_panel.detail.mpu_sales") %> |
- <%= t("views.right_panel.detail.master_sales") %> |
- <%= t("views.right_panel.detail.visa_sales") %> |
- <%= t("views.right_panel.detail.jcb_sales") %> |
- <%= t("views.right_panel.detail.unionpay_sales") %> |
- <%= t("views.right_panel.detail.alipay_sales") %> |
- <%= t("views.right_panel.detail.kbzpay_sales") %> |
-
- <%= t("views.right_panel.detail.dinga_sales") %> |
- <%= t("views.right_panel.detail.junctionpay_sales") %> |
- <%= t("views.right_panel.detail.redeem_sales") %> |
+ <% @payment_methods.each do |method| %>
+ <%= t("views.right_panel.detail.#{method} Sales") %> |
+ <% end %>
<%= t("views.right_panel.detail.cash_sales") %> |
<%= t("views.right_panel.detail.credit_sales") %> |
<%= t("views.right_panel.detail.foc_sales") %> |
- <%= t("views.right_panel.detail.giftvoucher_sales") %> |
<% unless @sale_data.empty? %>
<% @sale_data.each do |sale| %>
- | <%= number_format(sale[:mpu_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:master_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:visa_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:jcb_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:unionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:alipay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:kbzpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
-
- <%= number_format(sale[:dinga_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:junctionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:paypar_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
+ <% @payment_methods.each do |method| %>
+ <%= number_format(sale[method.parameterize.to_sym] , precision: precision.to_i ,delimiter: delimiter) rescue 0 %> |
+ <% end %>
<%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
<%= number_format(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
<%= number_format(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
+
<% end %>
diff --git a/app/views/reports/payment_method/index.xls.erb b/app/views/reports/payment_method/index.xls.erb
index a6fcf35d..ec4dfbee 100755
--- a/app/views/reports/payment_method/index.xls.erb
+++ b/app/views/reports/payment_method/index.xls.erb
@@ -27,42 +27,24 @@
<% end %>
- | <%= t("views.right_panel.detail.mpu_sales") %> |
- <%= t("views.right_panel.detail.master_sales") %> |
- <%= t("views.right_panel.detail.visa_sales") %> |
- <%= t("views.right_panel.detail.jcb_sales") %> |
- <%= t("views.right_panel.detail.unionpay_sales") %> |
- <%= t("views.right_panel.detail.alipay_sales") %> |
- <%= t("views.right_panel.detail.kbzpay_sales") %> |
-
- <%= t("views.right_panel.detail.dinga_sales") %> |
- <%= t("views.right_panel.detail.junctionpay_sales") %> |
- <%= t("views.right_panel.detail.redeem_sales") %> |
+ <% @payment_methods.each do |method| %>
+ <%= t("views.right_panel.detail.#{method} Sales") %> |
+ <% end %>
<%= t("views.right_panel.detail.cash_sales") %> |
<%= t("views.right_panel.detail.credit_sales") %> |
<%= t("views.right_panel.detail.foc_sales") %> |
- <%= t("views.right_panel.detail.giftvoucher_sales") %> |
<% unless @sale_data.empty? %>
<% @sale_data.each do |sale| %>
- | <%= number_format(sale[:mpu_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:master_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:visa_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:jcb_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:unionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:alipay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:kbzpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
-
- <%= number_format(sale[:dinga_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:junctionpay_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:paypar_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
+ <% @payment_methods.each do |method| %>
+ <%= number_format(sale[method.parameterize.to_sym] , precision: precision.to_i ,delimiter: delimiter) rescue 0 %> |
+ <% end %>
<%= number_format(sale[:cash_amount]-sale[:total_change_amount], precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
<%= number_format(sale[:credit_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
<%= number_format(sale[:foc_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
- <%= number_format(sale[:giftvoucher_amount] , precision: precision.to_i ,delimiter: delimiter) rescue '-' %> |
<% end %>