fixed conflict
This commit is contained in:
9
Capfile
9
Capfile
@@ -22,10 +22,15 @@ require "capistrano/bundler"
|
|||||||
require "capistrano/rails"
|
require "capistrano/rails"
|
||||||
require "capistrano/rails/assets"
|
require "capistrano/rails/assets"
|
||||||
require "capistrano/rails/migrations"
|
require "capistrano/rails/migrations"
|
||||||
# require "capistrano/passenger"
|
require "capistrano/scm/git"
|
||||||
|
install_plugin Capistrano::SCM::Git
|
||||||
|
|
||||||
|
require 'capistrano/puma'
|
||||||
|
install_plugin Capistrano::Puma, load_hooks: false # Default puma tasks
|
||||||
|
install_plugin Capistrano::Puma::Monit # if you need the monit tasks
|
||||||
|
install_plugin Capistrano::Puma::Jungle # if you need the jungle tasks
|
||||||
|
|
||||||
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
|
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
|
||||||
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
|
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
|
||||||
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
|
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
|
||||||
Dir.glob('lib/capistrano/**/*.rb').each { |r| import r }
|
Dir.glob('lib/capistrano/**/*.rb').each { |r| import r }
|
||||||
|
|
||||||
|
|||||||
6
Gemfile
6
Gemfile
@@ -1,6 +1,8 @@
|
|||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
#ruby '2.4.1'
|
#ruby '2.4.1'
|
||||||
ruby '2.5.7'
|
ruby '2.5.7'
|
||||||
|
|
||||||
git_source(:github) do |repo_name|
|
git_source(:github) do |repo_name|
|
||||||
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
||||||
"https://github.com/#{repo_name}.git"
|
"https://github.com/#{repo_name}.git"
|
||||||
@@ -45,7 +47,8 @@ gem 'mini_magick'
|
|||||||
gem 'jquery-fileupload-rails', '~> 0.4.7'
|
gem 'jquery-fileupload-rails', '~> 0.4.7'
|
||||||
|
|
||||||
#Report and Printing gems
|
#Report and Printing gems
|
||||||
gem 'cups'
|
#gem 'cups' #remove for cloud installation
|
||||||
|
gem 'cups', '~>0.0.7'
|
||||||
gem 'prawn'
|
gem 'prawn'
|
||||||
gem 'prawn-table'
|
gem 'prawn-table'
|
||||||
gem 'prawn-qrcode'
|
gem 'prawn-qrcode'
|
||||||
@@ -115,6 +118,7 @@ group :development do
|
|||||||
gem 'capistrano-bundler'
|
gem 'capistrano-bundler'
|
||||||
gem 'capistrano-rails'
|
gem 'capistrano-rails'
|
||||||
gem 'capistrano-rbenv', github: "capistrano/rbenv"
|
gem 'capistrano-rbenv', github: "capistrano/rbenv"
|
||||||
|
gem 'capistrano3-puma'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
|
|||||||
14
Gemfile.lock
14
Gemfile.lock
@@ -72,11 +72,15 @@ GEM
|
|||||||
capistrano-rails (1.4.0)
|
capistrano-rails (1.4.0)
|
||||||
capistrano (~> 3.1)
|
capistrano (~> 3.1)
|
||||||
capistrano-bundler (~> 1.1)
|
capistrano-bundler (~> 1.1)
|
||||||
|
capistrano3-puma (3.1.1)
|
||||||
|
capistrano (~> 3.7)
|
||||||
|
capistrano-bundler
|
||||||
|
puma (~> 3.4)
|
||||||
carrierwave (1.3.1)
|
carrierwave (1.3.1)
|
||||||
activemodel (>= 4.0.0)
|
activemodel (>= 4.0.0)
|
||||||
activesupport (>= 4.0.0)
|
activesupport (>= 4.0.0)
|
||||||
mime-types (>= 1.16)
|
mime-types (>= 1.16)
|
||||||
chartkick (3.2.1)
|
chartkick (3.2.2)
|
||||||
chronic (0.10.2)
|
chronic (0.10.2)
|
||||||
chunky_png (1.3.11)
|
chunky_png (1.3.11)
|
||||||
coffee-rails (4.2.2)
|
coffee-rails (4.2.2)
|
||||||
@@ -89,7 +93,7 @@ GEM
|
|||||||
concurrent-ruby (1.1.5)
|
concurrent-ruby (1.1.5)
|
||||||
connection_pool (2.2.2)
|
connection_pool (2.2.2)
|
||||||
crass (1.0.5)
|
crass (1.0.5)
|
||||||
cups (0.1.10)
|
cups (0.0.7)
|
||||||
database_cleaner (1.7.0)
|
database_cleaner (1.7.0)
|
||||||
diff-lcs (1.3)
|
diff-lcs (1.3)
|
||||||
erubi (1.9.0)
|
erubi (1.9.0)
|
||||||
@@ -265,7 +269,7 @@ GEM
|
|||||||
simple_form (5.0.1)
|
simple_form (5.0.1)
|
||||||
actionpack (>= 5.0)
|
actionpack (>= 5.0)
|
||||||
activemodel (>= 5.0)
|
activemodel (>= 5.0)
|
||||||
spreadsheet (1.2.4)
|
spreadsheet (1.2.5)
|
||||||
ruby-ole (>= 1.0)
|
ruby-ole (>= 1.0)
|
||||||
spring (2.1.0)
|
spring (2.1.0)
|
||||||
spring-watcher-listen (2.0.1)
|
spring-watcher-listen (2.0.1)
|
||||||
@@ -321,10 +325,11 @@ DEPENDENCIES
|
|||||||
capistrano-bundler
|
capistrano-bundler
|
||||||
capistrano-rails
|
capistrano-rails
|
||||||
capistrano-rbenv!
|
capistrano-rbenv!
|
||||||
|
capistrano3-puma
|
||||||
carrierwave (~> 1.0)
|
carrierwave (~> 1.0)
|
||||||
chartkick
|
chartkick
|
||||||
coffee-rails (~> 4.2)
|
coffee-rails (~> 4.2)
|
||||||
cups
|
cups (~> 0.0.7)
|
||||||
database_cleaner
|
database_cleaner
|
||||||
factory_girl_rails (~> 4.0)
|
factory_girl_rails (~> 4.0)
|
||||||
faker
|
faker
|
||||||
@@ -370,6 +375,7 @@ DEPENDENCIES
|
|||||||
whenever
|
whenever
|
||||||
|
|
||||||
RUBY VERSION
|
RUBY VERSION
|
||||||
|
|
||||||
ruby 2.4.1p111
|
ruby 2.4.1p111
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class Api::ApiController < ActionController::API
|
class Api::ApiController < ActionController::API
|
||||||
# include TokenVerification
|
include TokenVerification
|
||||||
|
include ActionController::MimeResponds
|
||||||
|
|
||||||
# before_action :lookup_domain
|
# before_action :lookup_domain
|
||||||
helper_method :current_token, :current_login_employee, :get_cashier
|
helper_method :current_token, :current_login_employee, :get_cashier
|
||||||
|
|||||||
90
app/controllers/api/loader_service/load_data_controller.rb
Normal file
90
app/controllers/api/loader_service/load_data_controller.rb
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
require "net/http"
|
||||||
|
class Api::LoaderService::LoadDataController < Api::ApiController
|
||||||
|
skip_before_action :authenticate
|
||||||
|
|
||||||
|
def get_sale_data_rage
|
||||||
|
load_time_start = params[:load_time]
|
||||||
|
load_time_end = params[:load_time_end]
|
||||||
|
unless load_time_start.nil? || load_time_end.nil?
|
||||||
|
@sale_data = Sale.get_load_sale_range(load_time_start.to_datetime,load_time_end.to_datetime)
|
||||||
|
if !@sale_data.empty?
|
||||||
|
@out = {general_status: true, data: @sale_data}
|
||||||
|
else
|
||||||
|
@out = {general_status: false, data: "Data is empty."}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@out = {general_status: false, data: "load_time is missing."}
|
||||||
|
end
|
||||||
|
render :json => @out
|
||||||
|
end
|
||||||
|
|
||||||
|
# SFTP for BreadTalk Start
|
||||||
|
|
||||||
|
# Detail Sale
|
||||||
|
def get_detail_sale_data
|
||||||
|
data = params['data']
|
||||||
|
transaction_date = data[:transaction_date].to_s
|
||||||
|
detail_sale_data = SaleItem.get_detail_sale_data(transaction_date)
|
||||||
|
json = detail_sale_data.to_json
|
||||||
|
trans_count = JSON.parse(json).count
|
||||||
|
unless detail_sale_data.empty?
|
||||||
|
out = { :status => "success", :transaction_count => trans_count, :data => detail_sale_data }
|
||||||
|
else
|
||||||
|
out = { :status => "fail", :data => "Data is empty" }
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.json {render json: out }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Tender sale
|
||||||
|
def get_tender_sale_data
|
||||||
|
data = params['data']
|
||||||
|
transaction_date = data['transaction_date'].to_s
|
||||||
|
tender_sale_data = Sale.get_tender_sale_data(transaction_date)
|
||||||
|
json = tender_sale_data.to_json
|
||||||
|
trans_count = JSON.parse(json).count
|
||||||
|
unless tender_sale_data.empty?
|
||||||
|
out = { :status => "success", :transaction_count => trans_count, :data => tender_sale_data }
|
||||||
|
else
|
||||||
|
out = { :status => "fail", :data => "Data is empty" }
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.json { render json: out }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Daily_Sale summary
|
||||||
|
def get_daily_sale_data
|
||||||
|
data = params['data']
|
||||||
|
transaction_date = data['transaction_date'].to_s
|
||||||
|
daily_sale_data = Sale.get_daily_sale_data(transaction_date)
|
||||||
|
unless daily_sale_data.empty?
|
||||||
|
out = { :status => "success", :data => daily_sale_data}
|
||||||
|
else
|
||||||
|
out = { :status => "fail", :data => "Data is empty"}
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.json { render json: out }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check Sale Data
|
||||||
|
def get_check_sale_data
|
||||||
|
data = params['data']
|
||||||
|
transaction_date = data['transaction_date'].to_s
|
||||||
|
check_sale_data = Sale.get_check_sale_data(transaction_date)
|
||||||
|
json = check_sale_data.to_json
|
||||||
|
trans_count = JSON.parse(json).count
|
||||||
|
unless check_sale_data.empty?
|
||||||
|
out = { :status => "success", :transaction_count => trans_count, :data => check_sale_data}
|
||||||
|
else
|
||||||
|
out = { :status => "fail", :data => "Data is empty"}
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.json { render json: out }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# SFTP for BreadTalk End
|
||||||
|
end
|
||||||
@@ -8,7 +8,7 @@ class Api::VoidController < Api::ApiController
|
|||||||
|
|
||||||
if sale.discount_type == "member_discount"
|
if sale.discount_type == "member_discount"
|
||||||
sale.update_attributes(total_discount: 0)
|
sale.update_attributes(total_discount: 0)
|
||||||
sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source)
|
sale.compute_by_sale_items(0, nil, order_source)
|
||||||
end
|
end
|
||||||
|
|
||||||
# update count for shift sale
|
# update count for shift sale
|
||||||
@@ -39,4 +39,3 @@ class Api::VoidController < Api::ApiController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ class Origami::AddordersController < BaseOrigamiController
|
|||||||
def getCloudDomain
|
def getCloudDomain
|
||||||
from = ""
|
from = ""
|
||||||
if ENV["SERVER_MODE"] == 'cloud'
|
if ENV["SERVER_MODE"] == 'cloud'
|
||||||
from = request.subdomain + "." + request.domain
|
from = request.subdomain.to_s + "." + request.domain.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
return from
|
return from
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ class Origami::CustomersController < BaseOrigamiController
|
|||||||
if status == true
|
if status == true
|
||||||
render json: JSON.generate({:status => true})
|
render json: JSON.generate({:status => true})
|
||||||
if(id == "SAL")
|
if(id == "SAL")
|
||||||
sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount, nil, order_source)
|
sale.compute_by_sale_items(sale.total_discount, nil, order_source)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
render json: JSON.generate({:status => false, :error_message => "Record not found"})
|
render json: JSON.generate({:status => false, :error_message => "Record not found"})
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
overall_discount = params[:overall_discount]
|
overall_discount = params[:overall_discount]
|
||||||
sub_total = params[:sub_total]
|
sub_total = params[:sub_total]
|
||||||
|
|
||||||
|
|
||||||
if Sale.exists?(sale_id)
|
if Sale.exists?(sale_id)
|
||||||
sale = Sale.find(sale_id)
|
sale = Sale.find(sale_id)
|
||||||
if sale.bookings[0].dining_facility_id.to_i > 0
|
if sale.bookings[0].dining_facility_id.to_i > 0
|
||||||
@@ -57,13 +56,16 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
|
|
||||||
sale_item = SaleItem.new
|
sale_item = SaleItem.new
|
||||||
|
|
||||||
if !origin_sale_item.nil?
|
# if !origin_sale_item.nil?
|
||||||
menu_category = MenuCategory.get_menu_category(origin_sale_item.product_code) #get menu category for menu items
|
# menu_category = MenuCategory.get_menu_category(origin_sale_item.product_code) #get menu category for menu items
|
||||||
if !menu_category.nil?
|
# if !menu_category.nil?
|
||||||
sale_item.menu_category_code = menu_category.code
|
# sale_item.menu_category_code = menu_category.code
|
||||||
sale_item.menu_category_name = menu_category.name
|
# sale_item.menu_category_name = menu_category.name
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
|
sale_item.menu_category_code = origin_sale_item.menu_category_code
|
||||||
|
sale_item.menu_category_name = origin_sale_item.menu_category_name
|
||||||
|
|
||||||
sale_item.sale_id = sale_id
|
sale_item.sale_id = sale_id
|
||||||
sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id
|
sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id
|
||||||
@@ -73,7 +75,7 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
sale_item.status = "Discount"
|
sale_item.status = "Discount"
|
||||||
|
|
||||||
sale_item.qty = -1
|
sale_item.qty = -1
|
||||||
sale_item.unit_price = di["price"].to_f * (-1)
|
sale_item.unit_price = di["price"].to_f * -1
|
||||||
sale_item.taxable_price = di["price"]
|
sale_item.taxable_price = di["price"]
|
||||||
sale_item.is_taxable = 1
|
sale_item.is_taxable = 1
|
||||||
sale_item.account_id = origin_sale_item.account_id
|
sale_item.account_id = origin_sale_item.account_id
|
||||||
@@ -100,7 +102,7 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
|
|
||||||
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"OVERALLDISCOUNT" )
|
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"OVERALLDISCOUNT" )
|
||||||
end
|
end
|
||||||
sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f, nil,order_source)
|
sale.compute_by_sale_items(overall_discount.to_f, nil,order_source)
|
||||||
if !table.nil?
|
if !table.nil?
|
||||||
result = {:status=> "Success", :table_id => table_id, :table_type => table.type }
|
result = {:status=> "Success", :table_id => table_id, :table_type => table.type }
|
||||||
else
|
else
|
||||||
@@ -155,7 +157,7 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
# sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
|
# sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax;
|
||||||
# sale.save
|
# sale.save
|
||||||
# Re-calc All Amount in Sale
|
# Re-calc All Amount in Sale
|
||||||
sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount, nil, order_source)
|
sale.compute_by_sale_items(sale.total_discount, nil, order_source)
|
||||||
if table.nil?
|
if table.nil?
|
||||||
result = {:status=> "Success"}
|
result = {:status=> "Success"}
|
||||||
else
|
else
|
||||||
@@ -217,7 +219,7 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"REMOVEALLDISCOUNT" )
|
sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"REMOVEALLDISCOUNT" )
|
||||||
|
|
||||||
# Re-calc All Amount in Sale
|
# Re-calc All Amount in Sale
|
||||||
sale.compute_by_sale_items(sale_id, sale.sale_items, 0, nil, order_source)
|
sale.compute_by_sale_items(0, nil, order_source)
|
||||||
if table.nil?
|
if table.nil?
|
||||||
result = {:status=> "Success"}
|
result = {:status=> "Success"}
|
||||||
else
|
else
|
||||||
@@ -318,7 +320,7 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
if response["discount_bonus_earned"]
|
if response["discount_bonus_earned"]
|
||||||
discount_amount = discount_amount + response["discount_bonus_earned"]
|
discount_amount = discount_amount + response["discount_bonus_earned"]
|
||||||
end
|
end
|
||||||
sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount', order_source, tax_type)
|
sale.compute_by_sale_items(discount_amount, 'member_discount', order_source, tax_type)
|
||||||
result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type }
|
result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type }
|
||||||
elsif response["status"] == "500"
|
elsif response["status"] == "500"
|
||||||
result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type }
|
result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type }
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class Origami::OtherChargesController < BaseOrigamiController
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Re-calc All Amount in Sale
|
# Re-calc All Amount in Sale
|
||||||
sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount, nil, cashier_type)
|
sale.compute_by_sale_items(sale.total_discount, nil, cashier_type)
|
||||||
end
|
end
|
||||||
if !table.nil?
|
if !table.nil?
|
||||||
dining = {:table_id => table_id, :table_type => table.type }
|
dining = {:table_id => table_id, :table_type => table.type }
|
||||||
|
|||||||
@@ -64,15 +64,9 @@ class Origami::PaymentsController < BaseOrigamiController
|
|||||||
customer = Customer.find(sale_data.customer_id)
|
customer = Customer.find(sale_data.customer_id)
|
||||||
# rounding adjustment
|
# rounding adjustment
|
||||||
if shop_detail.is_rounding_adj
|
if shop_detail.is_rounding_adj
|
||||||
a = sale_data.grand_total % 25 # Modulus
|
new_total = Sale.get_rounding_adjustment(sale_data.grand_total)
|
||||||
b = sale_data.grand_total / 25 # Division
|
rounding_adj = new_total - sale_data.grand_total
|
||||||
#not calculate rounding if modulus is 0 and division is even
|
sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
|
||||||
#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(sale_data.grand_total)
|
|
||||||
rounding_adj = new_total-sale_data.grand_total
|
|
||||||
sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
#end rounding adjustment
|
#end rounding adjustment
|
||||||
#record for sale audit
|
#record for sale audit
|
||||||
@@ -151,15 +145,9 @@ class Origami::PaymentsController < BaseOrigamiController
|
|||||||
# rounding adjustment
|
# rounding adjustment
|
||||||
if !path.include? ("credit_payment")
|
if !path.include? ("credit_payment")
|
||||||
if shop_detail.is_rounding_adj
|
if shop_detail.is_rounding_adj
|
||||||
a = saleObj.grand_total % 25 # Modulus
|
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
|
||||||
b = saleObj.grand_total / 25 # Division
|
rounding_adj = new_total - saleObj.grand_total
|
||||||
#not calculate rounding if modulus is 0 and division is even
|
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0
|
||||||
#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)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
#end rounding adjustment
|
#end rounding adjustment
|
||||||
@@ -655,7 +643,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
|||||||
|
|
||||||
if saleObj.discount_type == "member_discount"
|
if saleObj.discount_type == "member_discount"
|
||||||
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
|
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
|
||||||
saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0,order_source)
|
saleObj.compute_by_sale_items(0, nil, order_source)
|
||||||
end
|
end
|
||||||
|
|
||||||
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
|
saleObj.update_attributes(grand_total: 0, rounding_adjustment: 0, amount_received: 0, amount_changed: 0)
|
||||||
@@ -830,7 +818,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
|||||||
order_source = params[:cashier_type]
|
order_source = params[:cashier_type]
|
||||||
tax_type = params[:tax_type]
|
tax_type = params[:tax_type]
|
||||||
sale = Sale.find(sale_id)
|
sale = Sale.find(sale_id)
|
||||||
sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount,nil,order_source,tax_type)
|
sale.compute_by_sale_items(sale.total_discount, nil, order_source, tax_type)
|
||||||
|
|
||||||
render json: JSON.generate({:status => true})
|
render json: JSON.generate({:status => true})
|
||||||
end
|
end
|
||||||
@@ -839,7 +827,7 @@ class Origami::PaymentsController < BaseOrigamiController
|
|||||||
def getCloudDomain
|
def getCloudDomain
|
||||||
from = ""
|
from = ""
|
||||||
if ENV["SERVER_MODE"] == 'cloud'
|
if ENV["SERVER_MODE"] == 'cloud'
|
||||||
from = request.subdomain + "." + request.domain
|
from = request.subdomain.to_s + "." + request.domain.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
return from
|
return from
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class Origami::PendingOrderController < BaseOrigamiController
|
|||||||
else
|
else
|
||||||
redirect_to "/origami/#{params[:type]}" and return
|
redirect_to "/origami/#{params[:type]}" and return
|
||||||
end
|
end
|
||||||
elsif (id.start_with?("BKI")|| id.start_with?("CBKI"))
|
elsif (id.start_with?("BKI") || id.start_with?("CBKI"))
|
||||||
@bookings = Booking.find(id)
|
@bookings = Booking.find(id)
|
||||||
@order = @bookings.orders.where(status: "new").first
|
@order = @bookings.orders.where(status: "new").first
|
||||||
@order_items = @bookings.order_items
|
@order_items = @bookings.order_items
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class Origami::SaleEditController < BaseOrigamiController
|
|||||||
remark = "Void Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}"
|
remark = "Void Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}"
|
||||||
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMVOID" )
|
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMVOID" )
|
||||||
|
|
||||||
saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order_source)
|
saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source)
|
||||||
ProductCommission.create_product_commission(@newsaleitem, saleitemObj)
|
ProductCommission.create_product_commission(@newsaleitem, saleitemObj)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ class Origami::SaleEditController < BaseOrigamiController
|
|||||||
saleitemObj.status = 'foc'
|
saleitemObj.status = 'foc'
|
||||||
saleitemObj.remark = remark
|
saleitemObj.remark = remark
|
||||||
saleitemObj.save
|
saleitemObj.save
|
||||||
@newsaleitem = SaleItem.new
|
|
||||||
@newsaleitem = saleitemObj.dup
|
@newsaleitem = saleitemObj.dup
|
||||||
@newsaleitem.qty = saleitemObj.qty * -1
|
@newsaleitem.qty = saleitemObj.qty * -1
|
||||||
@newsaleitem.unit_price = saleitemObj.unit_price * 1
|
@newsaleitem.unit_price = saleitemObj.unit_price * 1
|
||||||
@@ -95,7 +95,7 @@ class Origami::SaleEditController < BaseOrigamiController
|
|||||||
remark = "FOC Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}Receipt No #{saleObj.receipt_no}"
|
remark = "FOC Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}Receipt No #{saleObj.receipt_no}"
|
||||||
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMFOC" )
|
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMFOC" )
|
||||||
|
|
||||||
saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order_source)
|
saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source)
|
||||||
ProductCommission.create_product_commission(@newsaleitem, saleitemObj)
|
ProductCommission.create_product_commission(@newsaleitem, saleitemObj)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -143,17 +143,17 @@ class Origami::SaleEditController < BaseOrigamiController
|
|||||||
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMEDIT" )
|
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMEDIT" )
|
||||||
# saleitemObj.remark = 'edit'
|
# saleitemObj.remark = 'edit'
|
||||||
|
|
||||||
unless saleitemObj.product_name.include? 'updated'
|
unless saleitemObj.product_name.include? 'UPDATED'
|
||||||
saleitemObj.product_name = saleitemObj.product_name + ' (UPDATED)'
|
saleitemObj.product_name = saleitemObj.product_name + ' (UPDATED)'
|
||||||
end
|
end
|
||||||
|
|
||||||
saleitemObj.save
|
saleitemObj.save
|
||||||
|
|
||||||
# re-calc tax
|
# re-calc tax
|
||||||
saleObj = Sale.find(saleitemObj.sale_id)
|
# saleObj = Sale.find(saleitemObj.sale_id)
|
||||||
|
|
||||||
order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id
|
# order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id
|
||||||
order = Order.find(order_id)
|
# order = Order.find(order_id)
|
||||||
|
|
||||||
# order.order_items.each do |o|
|
# order.order_items.each do |o|
|
||||||
# if saleitemObj.product_code == o.item_code
|
# if saleitemObj.product_code == o.item_code
|
||||||
@@ -163,7 +163,7 @@ class Origami::SaleEditController < BaseOrigamiController
|
|||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
|
|
||||||
saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order_source)
|
sale.compute_by_sale_items(saleObj.total_discount, nil, order_source)
|
||||||
|
|
||||||
ProductCommission.edit_product_commission(saleitemObj)
|
ProductCommission.edit_product_commission(saleitemObj)
|
||||||
end
|
end
|
||||||
@@ -196,7 +196,7 @@ class Origami::SaleEditController < BaseOrigamiController
|
|||||||
remark = "Cancle Void Sale Item ID #{saleitemObj.sale_item_id} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}|Receipt No #{saleObj.receipt_no}"
|
remark = "Cancle Void Sale Item ID #{saleitemObj.sale_item_id} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}|Receipt No #{saleObj.receipt_no}"
|
||||||
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"ITEMCANCELVOID" )
|
sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"ITEMCANCELVOID" )
|
||||||
|
|
||||||
saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount, order_source)
|
saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source)
|
||||||
ProductCommission.remove_product_commission(saleitemObj)
|
ProductCommission.remove_product_commission(saleitemObj)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -214,9 +214,9 @@ class Origami::SaleEditController < BaseOrigamiController
|
|||||||
item.save
|
item.save
|
||||||
ProductCommission.remove_product_commission(item)
|
ProductCommission.remove_product_commission(item)
|
||||||
end
|
end
|
||||||
|
saleObj.sale_items.reset
|
||||||
# re-calc tax
|
# re-calc tax
|
||||||
saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order_source)
|
saleObj.compute_by_sale_items(saleObj.total_discount,nil, order_source)
|
||||||
end
|
end
|
||||||
|
|
||||||
def apply_void
|
def apply_void
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Origami::VoidController < BaseOrigamiController
|
|||||||
sale = Sale.find_by_sale_id(sale_id)
|
sale = Sale.find_by_sale_id(sale_id)
|
||||||
if sale.discount_type == "member_discount"
|
if sale.discount_type == "member_discount"
|
||||||
sale.update_attributes(total_discount: 0)
|
sale.update_attributes(total_discount: 0)
|
||||||
sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source)
|
sale.compute_by_sale_items(0, nil, order_source)
|
||||||
end
|
end
|
||||||
|
|
||||||
# update count for shift sale
|
# update count for shift sale
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class Origami::WasteSpoileController < BaseOrigamiController
|
|||||||
sale.sale_status = remark
|
sale.sale_status = remark
|
||||||
sale.save
|
sale.save
|
||||||
|
|
||||||
# sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source)
|
|
||||||
# add to sale item with foc
|
# add to sale item with foc
|
||||||
# sale_items = SaleItem.where("sale_id='#{ sale_id }' and status is null")
|
# sale_items = SaleItem.where("sale_id='#{ sale_id }' and status is null")
|
||||||
|
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ class Transactions::SalesController < ApplicationController
|
|||||||
|
|
||||||
if sale.discount_type == "member_discount"
|
if sale.discount_type == "member_discount"
|
||||||
sale.update_attributes(total_discount: 0)
|
sale.update_attributes(total_discount: 0)
|
||||||
sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source)
|
sale.compute_by_sale_items(0, nil, order_source)
|
||||||
end
|
end
|
||||||
|
|
||||||
# update count for shift sale
|
# update count for shift sale
|
||||||
|
|||||||
@@ -227,8 +227,8 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
|
|||||||
count = printer_settings.print_copies
|
count = printer_settings.print_copies
|
||||||
|
|
||||||
# override print copies for print worker loop
|
# override print copies for print worker loop
|
||||||
print_settings.print_copies = 1
|
# print_settings.print_copies = 1
|
||||||
print_settings.save!
|
# print_settings.save!
|
||||||
end
|
end
|
||||||
directory_name = 'public/receipts'
|
directory_name = 'public/receipts'
|
||||||
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
||||||
|
|||||||
@@ -11,37 +11,23 @@ class Promotion < ApplicationRecord
|
|||||||
PROMO_TYPE3 = "Net_price" # 1800 => 1000 => 1000
|
PROMO_TYPE3 = "Net_price" # 1800 => 1000 => 1000
|
||||||
PROMO_TYPE4 = "Percentage"
|
PROMO_TYPE4 = "Percentage"
|
||||||
|
|
||||||
|
def is_promo_day
|
||||||
|
promo_day.include? Date.today.wday.to_s
|
||||||
|
end
|
||||||
|
|
||||||
def self.promo_activate(saleObj)
|
def self.promo_activate(saleObj)
|
||||||
array_same =[]
|
|
||||||
current_day = Time.now.strftime("%Y-%m-%d")
|
current_day = Time.now.strftime("%Y-%m-%d")
|
||||||
current_time = Time.now.strftime('%H:%M:%S')
|
current_time = Time.now.strftime('%H:%M:%S')
|
||||||
day = Date.today.wday
|
day = Date.today.wday
|
||||||
promoList = is_between_promo_datetime(current_day,current_time)
|
promoList = is_between_promo_datetime(current_day,current_time)
|
||||||
puts "promoList - " + promoList.size.to_s
|
|
||||||
if promoList.size > 0
|
promoList.each do |promo|
|
||||||
itemList = combine_item(saleObj)
|
if promo.is_promo_day
|
||||||
itemList.each do|list|
|
if item = saleObj.qty_of(promo.original_product)
|
||||||
list.each do |l|
|
check_promo_type(promo, item, saleObj)
|
||||||
array_same.push({
|
|
||||||
item_instance_code: l.item_instance_code,
|
|
||||||
order_id:l.order_id,
|
|
||||||
qty:l.qty
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
item_list =[]
|
|
||||||
array_same.group_by do |same|
|
|
||||||
same.values_at :item_instance_code
|
|
||||||
end.map do |(item_instance_code), array_same|
|
|
||||||
quantities = array_same.map { |p| p[:qty] }
|
|
||||||
qty = quantities.all? ? quantities.reduce(:+) : nil
|
|
||||||
item_list.push({ item_instance_code: item_instance_code, qty: qty })
|
|
||||||
end
|
|
||||||
Rails.logger.debug "-------promo_activate array_same-------"
|
|
||||||
puts item_list.to_json
|
|
||||||
is_promo_day(promoList,day, item_list, saleObj.sale_id)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.is_between_promo_datetime(current_day,current_time) #database is not local time
|
def self.is_between_promo_datetime(current_day,current_time) #database is not local time
|
||||||
@@ -49,45 +35,7 @@ class Promotion < ApplicationRecord
|
|||||||
return promoList
|
return promoList
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.combine_item(saleObj)
|
def self.check_promo_type(promo, orderitem, saleObj)
|
||||||
# order_id = saleObj.sale_orders[0][0].order_id
|
|
||||||
# itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
|
|
||||||
# array_same =[]
|
|
||||||
itemList = []
|
|
||||||
saleObj.sale_orders.each do |so|
|
|
||||||
# itemList << OrderItem.where("order_id = ?",so.order_id).group(["item_instance_code", "order_id"]).sum(:qty)
|
|
||||||
itemList << OrderItem.where("order_id = ?",so.order_id).select(:item_instance_code,:order_id,:qty)
|
|
||||||
end
|
|
||||||
|
|
||||||
return itemList
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.is_promo_day(promoList, day, orderitemList, sale_id)
|
|
||||||
puts "Today date - " + day.to_s
|
|
||||||
promoList.each do |promo|
|
|
||||||
dayresult = promo.promo_day.include?(day.to_s)
|
|
||||||
if dayresult
|
|
||||||
orderitemList.each do |item|
|
|
||||||
find_promo_item(promo, item, sale_id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.find_promo_item(promo, orderitem, sale_id)
|
|
||||||
item_code = OrderItem.find_by_item_instance_code(orderitem[:item_instance_code]).item_code
|
|
||||||
# orderitem.each do |odr_item|
|
|
||||||
if promo.original_product.downcase.to_s == orderitem[:item_instance_code]
|
|
||||||
if promo.min_qty.to_i > orderitem[:qty].to_i
|
|
||||||
return false
|
|
||||||
else
|
|
||||||
check_promo_type(promo,orderitem, sale_id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.check_promo_type(promo, orderitem, sale_id)
|
|
||||||
promo.promotion_products.each do |promo_product|
|
promo.promotion_products.each do |promo_product|
|
||||||
if promo_product.item_code.downcase == orderitem[:item_instance_code]
|
if promo_product.item_code.downcase == orderitem[:item_instance_code]
|
||||||
same = true
|
same = true
|
||||||
@@ -98,19 +46,19 @@ class Promotion < ApplicationRecord
|
|||||||
# same, promo_product = check_giveaway_product(promo, orderitem[0][0])
|
# same, promo_product = check_giveaway_product(promo, orderitem[0][0])
|
||||||
if promo.promo_type == Promotion::PROMO_TYPE1
|
if promo.promo_type == Promotion::PROMO_TYPE1
|
||||||
if same
|
if same
|
||||||
give_promotion_same_product(orderitem[:qty], promo.min_qty, promo_product.min_qty, orderitem, sale_id,promo_product.item_code)
|
give_promotion_same_product(orderitem[:qty], promo.min_qty, promo_product.min_qty, orderitem, saleObj, promo_product.item_code)
|
||||||
else
|
else
|
||||||
give_promotion_second_product(orderitem[:qty], promo.min_qty, promo_product.item_code, orderitem, sale_id)
|
give_promotion_second_product(orderitem[:qty], promo.min_qty, promo_product.item_code, orderitem, saleObj)
|
||||||
end
|
end
|
||||||
|
|
||||||
elsif promo.promo_type == Promotion::PROMO_TYPE2
|
elsif promo.promo_type == Promotion::PROMO_TYPE2
|
||||||
give_promotion_nett_off(same,promo_product,promo.min_qty, orderitem, sale_id)
|
give_promotion_nett_off(same,promo_product,promo.min_qty, orderitem, saleObj)
|
||||||
|
|
||||||
elsif promo.promo_type == Promotion::PROMO_TYPE3
|
elsif promo.promo_type == Promotion::PROMO_TYPE3
|
||||||
give_promotion_nett_price(same,promo_product,promo.min_qty, orderitem, sale_id)
|
give_promotion_nett_price(same,promo_product,promo.min_qty, orderitem, saleObj)
|
||||||
|
|
||||||
elsif promo.promo_type == Promotion::PROMO_TYPE4
|
elsif promo.promo_type == Promotion::PROMO_TYPE4
|
||||||
give_promotion_discount(same,promo_product,promo.min_qty, orderitem, sale_id)
|
give_promotion_discount(same,promo_product,promo.min_qty, orderitem, saleObj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -128,104 +76,64 @@ class Promotion < ApplicationRecord
|
|||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.give_promotion_same_product(qty, promoqty, foc_min_qty, orderitem, sale_id,promo_product)
|
def self.give_promotion_same_product(qty, promoqty, foc_min_qty, orderitem, saleObj,promo_product)
|
||||||
item =''
|
puts " Order qty: " + qty.to_s + " / promoqty: " + promoqty.to_s + " / giveaway: " + foc_min_qty.to_s
|
||||||
puts " Order qty: " + qty.to_s + " / promoqty: " + promoqty.to_s + " / giveaway: " + foc_min_qty.to_s
|
multiple = qty.to_i / promoqty.to_i # loop count
|
||||||
multiple = qty.to_i / promoqty.to_i # loop count
|
charge_qty = 0
|
||||||
charge_qty = 0
|
foc_qty = 0
|
||||||
foc_qty = 0
|
if multiple > 0
|
||||||
if multiple > 0
|
multiple.times.each do |key|
|
||||||
multiple.times.each do |key|
|
if qty > promoqty
|
||||||
if qty > promoqty
|
charge_qty += promoqty
|
||||||
charge_qty += promoqty
|
different = qty - promoqty
|
||||||
different = qty - promoqty
|
qty = different
|
||||||
qty = different
|
if different == 0
|
||||||
if different == 0
|
foc_qty += foc_min_qty
|
||||||
foc_qty += foc_min_qty
|
|
||||||
else
|
|
||||||
foc_qty += foc_min_qty
|
|
||||||
qty = qty - foc_min_qty
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
charge_qty += qty
|
foc_qty += foc_min_qty
|
||||||
|
qty = qty - foc_min_qty
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
charge_qty += qty
|
||||||
end
|
end
|
||||||
if multiple == foc_qty
|
end
|
||||||
charge_qty += qty
|
if multiple == foc_qty
|
||||||
end
|
|
||||||
else
|
|
||||||
charge_qty += qty
|
charge_qty += qty
|
||||||
end
|
end
|
||||||
sale_order =SaleOrder.where("sale_id=?",sale_id)
|
else
|
||||||
price =0
|
charge_qty += qty
|
||||||
source =''
|
end
|
||||||
sale_order.each do|order|
|
|
||||||
source = Order.find(order.order_id).source
|
|
||||||
end
|
|
||||||
|
|
||||||
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first
|
price = 0
|
||||||
item ={
|
source = saleObj.orders.first.source
|
||||||
item_code:item.item_code,
|
item = saleObj.order_items.where(item_instance_code: promo_product).first
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
if promo_product.downcase != item[:item_instance_code]
|
|
||||||
|
|
||||||
sale_order.each do|order|
|
if !item.nil?
|
||||||
source = Order.find(order.order_id).source
|
update_existing_item(foc_qty, item, saleObj, "promotion", item[:price], source)
|
||||||
end
|
end
|
||||||
item = OrderItem.where("item_code = ?",promo_product).order("order_items_id DESC").first
|
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
end
|
|
||||||
if !item.nil?
|
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion", item[:price],source)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
# AA - 10 # 3 # BB # orderList, #S34345
|
# AA - 10 # 3 # BB # orderList, #S34345
|
||||||
def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id)
|
def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, saleObj)
|
||||||
source =''
|
|
||||||
item =''
|
|
||||||
puts "..... orderitem_count: " + orderitem_count.to_s + " / foc_min_qty: " + foc_min_qty.to_s + " /promo_product: " + promo_product + " orderitem: " + orderitem.to_s
|
puts "..... orderitem_count: " + orderitem_count.to_s + " / foc_min_qty: " + foc_min_qty.to_s + " /promo_product: " + promo_product + " orderitem: " + orderitem.to_s
|
||||||
|
|
||||||
promotion_qty = orderitem_count.to_i / foc_min_qty.to_i # get foc item qty
|
promotion_qty = orderitem_count.to_i / foc_min_qty.to_i # get foc item qty
|
||||||
foc_qty = find_second_item_qty(sale_id, promo_product)
|
foc_qty = saleObj.qty_of(promo_product).qty rescue 0
|
||||||
if (foc_qty < promotion_qty)
|
if (foc_qty < promotion_qty)
|
||||||
promotion_qty = foc_qty
|
promotion_qty = foc_qty
|
||||||
end
|
end
|
||||||
# item = OrderItem.find_by_item_instance_code(promo_product)
|
# item = OrderItem.find_by_item_instance_code(promo_product)
|
||||||
sale_order =SaleOrder.where("sale_id=?",sale_id)
|
|
||||||
price =0
|
price = 0
|
||||||
sale_order.each do|order|
|
source = saleObj.orders.first.source
|
||||||
source = Order.find(order.order_id).source
|
item = saleObj.order_items.where(item_instance_code: promo_product).first
|
||||||
end
|
|
||||||
item = OrderItem.where("item_instance_code = ?",promo_product).order("order_items_id DESC").first
|
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
# item = OrderItem.where("item_instance_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first
|
|
||||||
if !item.nil?
|
if !item.nil?
|
||||||
# source = Order.find(item.order_id).source
|
update_existing_item(promotion_qty, item, saleObj, "promotion", item[:price],source)
|
||||||
update_existing_item(promotion_qty, item, sale_id, "promotion", item[:price],source)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.update_existing_item(qty, item, saleObj, type, item_price,source)
|
||||||
def self.update_existing_item(qty, item, sale_id, type, item_price,source)
|
if qty > 0
|
||||||
if qty >0
|
|
||||||
menu_category = MenuCategory.get_menu_category(item[:item_code]) #get menu category for menu items
|
menu_category = MenuCategory.get_menu_category(item[:item_code]) #get menu category for menu items
|
||||||
|
|
||||||
sale_item = SaleItem.new
|
sale_item = SaleItem.new
|
||||||
@@ -247,216 +155,85 @@ class Promotion < ApplicationRecord
|
|||||||
sale_item.price = qty * item_price * (-1)
|
sale_item.price = qty * item_price * (-1)
|
||||||
|
|
||||||
sale_item.is_taxable = 1
|
sale_item.is_taxable = 1
|
||||||
sale_item.sale_id = sale_id
|
sale_item.sale = saleObj
|
||||||
sale_item.save
|
sale_item.save
|
||||||
sale = Sale.find(sale_id)
|
|
||||||
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount,nil,source)
|
saleObj.sale_items << sale_item
|
||||||
|
saleObj.compute_by_sale_items(saleObj.total_discount, nil, source)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.give_promotion_nett_off(same, promo_product, foc_min_qty, orderitem, sale_id)
|
def self.give_promotion_nett_off(same, promo_product, foc_min_qty, orderitem, saleObj)
|
||||||
item =''
|
|
||||||
source =''
|
|
||||||
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
||||||
sale_order =SaleOrder.where("sale_id=?",sale_id)
|
|
||||||
if same
|
|
||||||
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
|
||||||
# item = OrderItem.find_by_item_instance_code(orderitem[0][0])
|
|
||||||
|
|
||||||
price =0
|
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
||||||
sale_order.each do|order|
|
if !same
|
||||||
source = Order.find(order.order_id).source
|
order_qty = saleObj.qty_of(promo_product.item_code).qty rescue 0
|
||||||
end
|
|
||||||
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first
|
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
# item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
|
|
||||||
if !item.nil?
|
|
||||||
# source = Order.find(item.order_id).source
|
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
|
||||||
end
|
|
||||||
|
|
||||||
else
|
|
||||||
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
|
||||||
# foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
|
|
||||||
# item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
|
||||||
# item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
|
|
||||||
sale_order.each do|order|
|
|
||||||
source = Order.find(order.order_id).source
|
|
||||||
end
|
|
||||||
item = OrderItem.where("item_instance_code = ?",promo_product.item_code).order("order_items_id DESC").first
|
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
if !item.nil?
|
|
||||||
# source = Order.find(item.order_id).source
|
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.give_promotion_nett_price(same, promo_product, foc_min_qty, orderitem, sale_id)
|
|
||||||
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
|
||||||
sale_order =SaleOrder.where("sale_id=?",sale_id)
|
|
||||||
source =''
|
|
||||||
item =''
|
|
||||||
if same
|
|
||||||
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
|
||||||
# item = OrderItem.find_by_item_instance_code(orderitem[0][0]) # need to specify with menu item instance
|
|
||||||
# item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
|
|
||||||
sale_order.each do|order|
|
|
||||||
source = Order.find(order.order_id).source
|
|
||||||
end
|
|
||||||
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first
|
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
if !item.nil?
|
|
||||||
price = item[:price].to_i - promo_product.net_price.to_i
|
|
||||||
# source = Order.find(item.order_id).source
|
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
|
||||||
end
|
|
||||||
|
|
||||||
else
|
|
||||||
order_qty = find_second_item_qty(sale_id, promo_product.item_code)# need to check for qty
|
|
||||||
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
||||||
|
|
||||||
if foc_qty > order_qty
|
if foc_qty > order_qty
|
||||||
foc_qty = order_qty
|
foc_qty = order_qty
|
||||||
end
|
end
|
||||||
# item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
end
|
||||||
# item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
|
|
||||||
sale_order.each do|order|
|
|
||||||
source = Order.find(order.order_id).source
|
|
||||||
end
|
|
||||||
item = OrderItem.where("item_instance_code",promo_product.item_code).order("order_items_id DESC").first
|
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
|
|
||||||
if !item.nil?
|
source = saleObj.orders.first.source
|
||||||
price = item[:price].to_i - promo_product.net_price.to_i
|
item = saleObj.order_items.where(item_instance_code: promo_product.item_code).first
|
||||||
# source = Order.find(item.order_id).source
|
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
if !item.nil?
|
||||||
|
update_existing_item(foc_qty, item, saleObj, "promotion nett off", promo_product.net_off,source)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.give_promotion_discount(same, promo_product, foc_min_qty, orderitem, sale_id)
|
def self.give_promotion_nett_price(same, promo_product, foc_min_qty, orderitem, saleObj)
|
||||||
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
||||||
sale_order =SaleOrder.where("sale_id=?",sale_id)
|
|
||||||
source =''
|
|
||||||
item =''
|
|
||||||
if same
|
|
||||||
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
|
||||||
# item = OrderItem.find_by_item_instance_code(orderitem[0][0])
|
|
||||||
# item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first
|
|
||||||
sale_order.each do|order|
|
|
||||||
source = Order.find(order.order_id).source
|
|
||||||
end
|
|
||||||
item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first
|
|
||||||
item ={
|
|
||||||
item_code:item.item_code,
|
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
# total = orderitem[1].to_i * item.price
|
|
||||||
if !item.nil?
|
|
||||||
total = item[:price]
|
|
||||||
price = calculate_discount(total, promo_product.percentage)
|
|
||||||
# source = Order.find(item.order_id).source
|
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
|
|
||||||
end
|
|
||||||
|
|
||||||
else
|
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
||||||
order_qty = find_second_item_qty(sale_id, promo_product.item_code) #need to check
|
if !same
|
||||||
|
order_qty = saleObj.qty_of(promo_product.item_code).qty rescue 0
|
||||||
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
||||||
# give total qty is 1
|
|
||||||
#foc_qty = (foc_qty - foc_qty) + 1
|
|
||||||
if foc_qty > order_qty
|
if foc_qty > order_qty
|
||||||
foc_qty = order_qty
|
foc_qty = order_qty
|
||||||
end
|
end
|
||||||
# item = OrderItem.find_by_item_instance_code(promo_product.item_code)
|
end
|
||||||
# item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first
|
|
||||||
sale_order.each do|order|
|
source = saleObj.orders.first.source
|
||||||
source = Order.find(order.order_id).source
|
item = saleObj.order_items.where(item_instance_code: promo_product.item_code).first
|
||||||
end
|
|
||||||
item = OrderItem.where("item_instance_code = ?",promo_product.item_code).order("order_items_id DESC").first
|
if !item.nil?
|
||||||
item ={
|
price = item[:price].to_i - promo_product.net_price.to_i
|
||||||
item_code:item.item_code,
|
update_existing_item(foc_qty, item, saleObj, "promotion nett price", price,source)
|
||||||
item_instance_code:item.item_instance_code,
|
|
||||||
item_name:item.item_name,
|
|
||||||
alt_name:item.alt_name,
|
|
||||||
account_id:item.account_id,
|
|
||||||
price:item.price
|
|
||||||
}
|
|
||||||
# total = item.price * foc_qty
|
|
||||||
if !item.nil?
|
|
||||||
total = item[:price]
|
|
||||||
price = calculate_discount(total, promo_product.percentage)
|
|
||||||
# source = Order.find(item.order_id).source
|
|
||||||
update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_second_item_qty(sale_id, promo_item)
|
def self.give_promotion_discount(same, promo_product, foc_min_qty, orderitem, saleObj)
|
||||||
array_same =[]
|
puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s
|
||||||
saleObj = Sale.find_by_sale_id(sale_id)
|
|
||||||
itemList = combine_item(saleObj)
|
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
||||||
itemList.each do|list|
|
if !same
|
||||||
list.each do |l|
|
order_qty = saleObj.qty_of(promo_product.item_code).qty rescue 0
|
||||||
array_same.push({
|
foc_qty = orderitem[:qty].to_i / foc_min_qty
|
||||||
item_instance_code: l.item_instance_code,
|
|
||||||
order_id:l.order_id,
|
if foc_qty > order_qty
|
||||||
qty:l.qty
|
foc_qty = order_qty
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
item_list =[]
|
|
||||||
array_same.group_by do |same|
|
|
||||||
same.values_at :item_instance_code
|
|
||||||
end.map do |(item_instance_code), array_same|
|
|
||||||
quantities = array_same.map { |p| p[:qty] }
|
|
||||||
qty = quantities.all? ? quantities.reduce(:+) : nil
|
|
||||||
item_list.push({ item_instance_code: item_instance_code, qty: qty })
|
|
||||||
end
|
|
||||||
item_list.each do |item|
|
|
||||||
if item[:item_instance_code] == promo_item.downcase
|
|
||||||
return item[:qty].to_i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.calculate_discount(total, percentage)
|
source = saleObj.orders.first.source
|
||||||
return (total.to_i * percentage.to_i) / 100
|
item = saleObj.order_items.where(item_instance_code: promo_product.item_code).first
|
||||||
end
|
puts saleObj
|
||||||
|
puts item
|
||||||
|
# total = orderitem[1].to_i * item.price
|
||||||
|
if item
|
||||||
|
total = item[:price]
|
||||||
|
price = calculate_discount(total, promo_product.percentage)
|
||||||
|
# source = Order.find(item.order_id).source
|
||||||
|
update_existing_item(foc_qty, item, saleObj, "promotion discount", price,source)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.calculate_discount(total, percentage)
|
||||||
|
return (total * percentage) / 100
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,14 +14,20 @@ class Sale < ApplicationRecord
|
|||||||
has_many :sale_payments
|
has_many :sale_payments
|
||||||
has_many :sale_orders
|
has_many :sale_orders
|
||||||
has_many :orders, through: :sale_orders
|
has_many :orders, through: :sale_orders
|
||||||
|
has_many :order_items, through: :sale_orders
|
||||||
has_many :bookings
|
has_many :bookings
|
||||||
has_many :product_commissions
|
has_many :product_commissions
|
||||||
|
|
||||||
|
before_validation :round_to_precision
|
||||||
after_update :update_stock_journal
|
after_update :update_stock_journal
|
||||||
|
|
||||||
scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") }
|
scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") }
|
||||||
scope :complete_sale, -> { where("sale_status = 'completed' and receipt_date BETWEEN '#{DateTime.now.utc.beginning_of_day}' AND '#{DateTime.now.utc.end_of_day}'") }
|
scope :complete_sale, -> { where("sale_status = 'completed' and receipt_date BETWEEN '#{DateTime.now.utc.beginning_of_day}' AND '#{DateTime.now.utc.end_of_day}'") }
|
||||||
|
|
||||||
|
def qty_of(item_instance_code)
|
||||||
|
order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first
|
||||||
|
end
|
||||||
|
|
||||||
REPORT_TYPE = {
|
REPORT_TYPE = {
|
||||||
"daily" => 0,
|
"daily" => 0,
|
||||||
"monthly" => 1,
|
"monthly" => 1,
|
||||||
@@ -355,8 +361,8 @@ class Sale < ApplicationRecord
|
|||||||
sale_item.save
|
sale_item.save
|
||||||
|
|
||||||
# Re-calc
|
# Re-calc
|
||||||
sale = Sale.find(self.id)
|
self.sale_items << sale_item
|
||||||
self.compute_by_sale_items(self.id, sale.sale_items, self.total_discount, nil, order_source)
|
self.compute_by_sale_items(self.total_discount, nil, order_source)
|
||||||
end
|
end
|
||||||
def create_saleitem_indutycharges(chargeObj, current_checkin_induties_count, induties_pay_amount, dining_name, dining_time, order_source = nil, basic_pay_amount)
|
def create_saleitem_indutycharges(chargeObj, current_checkin_induties_count, induties_pay_amount, dining_name, dining_time, order_source = nil, basic_pay_amount)
|
||||||
sale_item = SaleItem.new
|
sale_item = SaleItem.new
|
||||||
@@ -374,8 +380,8 @@ class Sale < ApplicationRecord
|
|||||||
sale_item.price = induties_pay_amount
|
sale_item.price = induties_pay_amount
|
||||||
sale_item.save
|
sale_item.save
|
||||||
# Re-calc
|
# Re-calc
|
||||||
sale = Sale.find(self.id)
|
self.sale_items << sale_item
|
||||||
self.compute_by_sale_items(self.id, sale.sale_items, self.total_discount, nil, order_source)
|
self.compute_by_sale_items(self.total_discount, nil, order_source)
|
||||||
end
|
end
|
||||||
def update_item (item)
|
def update_item (item)
|
||||||
#save sale_audit
|
#save sale_audit
|
||||||
@@ -397,14 +403,12 @@ class Sale < ApplicationRecord
|
|||||||
|
|
||||||
#compute - invoice total
|
#compute - invoice total
|
||||||
def compute(order_source = nil, tax_type = nil)
|
def compute(order_source = nil, tax_type = nil)
|
||||||
sales_items = self.sale_items
|
|
||||||
|
|
||||||
#Computation Fields
|
#Computation Fields
|
||||||
subtotal_price = 0
|
subtotal_price = 0
|
||||||
total_taxable = 0
|
total_taxable = 0
|
||||||
rounding_adjustment = 0
|
rounding_adjustment = 0
|
||||||
|
|
||||||
sales_items.each do |item|
|
self.sale_items.each do |item|
|
||||||
#compute each item and added to total
|
#compute each item and added to total
|
||||||
subtotal_price = subtotal_price + item.price
|
subtotal_price = subtotal_price + item.price
|
||||||
|
|
||||||
@@ -418,66 +422,59 @@ class Sale < ApplicationRecord
|
|||||||
apply_tax(total_taxable, order_source, tax_type)
|
apply_tax(total_taxable, order_source, tax_type)
|
||||||
|
|
||||||
self.total_amount = subtotal_price
|
self.total_amount = subtotal_price
|
||||||
self.total_discount = total_discount
|
# self.total_discount = total_discount
|
||||||
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
||||||
self.grand_total_round
|
# self.grand_total_round
|
||||||
#compute rounding adjustment
|
#compute rounding adjustment
|
||||||
adjust_rounding
|
# adjust_rounding
|
||||||
|
|
||||||
self.save!
|
self.save!
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#compute - invoice total
|
#compute - invoice total
|
||||||
def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil,tax_type=nil,type=nil)
|
def compute_by_sale_items(total_discount, discount_type=nil, order_source=nil, tax_type=nil, type=nil)
|
||||||
shop = Shop.first
|
shop = Shop.first
|
||||||
sale = Sale.find(sale_id)
|
|
||||||
sales_items = sale_itemss
|
|
||||||
|
|
||||||
#Computation Fields
|
#Computation Fields
|
||||||
subtotal_price = 0
|
subtotal_price = 0
|
||||||
total_taxable = 0
|
total_taxable = 0
|
||||||
rounding_adjustment = 0
|
rounding_adjustment = 0
|
||||||
|
|
||||||
sales_items.each do |item|
|
self.sale_items.each do |item|
|
||||||
#compute each item and added to total
|
#compute each item and added to total
|
||||||
subtotal_price = subtotal_price + item.price
|
subtotal_price = subtotal_price + item.price
|
||||||
|
|
||||||
# check for item is taxable and calculate
|
# check for item is taxable and calculate
|
||||||
if item.is_taxable
|
if item.is_taxable
|
||||||
total_taxable = total_taxable + item.taxable_price
|
total_taxable = total_taxable + item.taxable_price
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
compute_tax(sale, total_taxable, total_discount, order_source, tax_type)
|
|
||||||
sale.total_amount = subtotal_price
|
compute_tax(total_taxable, total_discount, order_source, tax_type)
|
||||||
sale.total_discount = total_discount
|
self.total_amount = subtotal_price
|
||||||
|
self.total_discount = total_discount
|
||||||
if type =="foc"
|
if type =="foc"
|
||||||
sale.grand_total = 0
|
self.grand_total = 0
|
||||||
else
|
else
|
||||||
sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax
|
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
||||||
sale.grand_total_round
|
# sale.grand_total_round
|
||||||
end
|
end
|
||||||
|
|
||||||
if discount_type == "member_discount"
|
if discount_type == "member_discount"
|
||||||
sale.discount_type = discount_type
|
self.discount_type = discount_type
|
||||||
end
|
end
|
||||||
#compute rounding adjustment
|
#compute rounding adjustment
|
||||||
# adjust_rounding
|
# adjust_rounding
|
||||||
sale.rounding_adjustment = compute_adjust_rounding(sale.grand_total)
|
self.save!
|
||||||
|
|
||||||
sale.save!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# No Use too many wrong
|
# No Use too many wrong
|
||||||
def compute_without_void(order_source = nil)
|
def compute_without_void(order_source = nil)
|
||||||
sales_items = self.sale_items
|
|
||||||
|
|
||||||
#Computation Fields
|
#Computation Fields
|
||||||
subtotal_price = 0
|
subtotal_price = 0
|
||||||
total_taxable = 0
|
total_taxable = 0
|
||||||
rounding_adjustment = 0
|
rounding_adjustment = 0
|
||||||
|
|
||||||
sales_items.each do |item|
|
self.sale_items.each do |item|
|
||||||
if item.status != 'void' && item.status != 'foc'
|
if item.status != 'void' && item.status != 'foc'
|
||||||
#compute each item and added to total
|
#compute each item and added to total
|
||||||
subtotal_price = subtotal_price + item.price
|
subtotal_price = subtotal_price + item.price
|
||||||
@@ -491,17 +488,17 @@ class Sale < ApplicationRecord
|
|||||||
|
|
||||||
apply_tax(total_taxable, order_source)
|
apply_tax(total_taxable, order_source)
|
||||||
self.total_amount = subtotal_price
|
self.total_amount = subtotal_price
|
||||||
self.total_discount = total_discount
|
# self.total_discount = total_discount
|
||||||
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
self.grand_total = (self.total_amount - self.total_discount) + self.total_tax
|
||||||
self.grand_total_round
|
# self.grand_total_round
|
||||||
#compute rounding adjustment
|
#compute rounding adjustment
|
||||||
adjust_rounding
|
# adjust_rounding
|
||||||
|
|
||||||
self.save!
|
self.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tax Re-Calculte
|
# Tax Re-Calculte
|
||||||
def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil, tax_type=nil)
|
def compute_tax(total_taxable, total_discount = 0, order_source = nil, tax_type=nil)
|
||||||
shop = Shop.first
|
shop = Shop.first
|
||||||
|
|
||||||
#if tax is not apply create new record
|
#if tax is not apply create new record
|
||||||
@@ -509,93 +506,49 @@ class Sale < ApplicationRecord
|
|||||||
# #delete existing and create new
|
# #delete existing and create new
|
||||||
# existing_tax.delete
|
# existing_tax.delete
|
||||||
# end
|
# end
|
||||||
taxes = SaleTax.where("sale_id='#{sale.sale_id}'").pluck(:sale_tax_id)
|
taxes = SaleTax.where("sale_id='#{self.sale_id}'").destroy_all
|
||||||
SaleTax.where("sale_tax_id IN (?)", taxes).destroy_all
|
|
||||||
|
|
||||||
total_tax_amount = 0
|
total_tax_amount = 0
|
||||||
tax_incl_exec = "exclusive"
|
tax_incl_exec = "exclusive"
|
||||||
#tax_profile - list by order_by
|
#tax_profile - list by order_by
|
||||||
# tax_profiles = TaxProfile.all.order("order_by asc")
|
# tax_profiles = TaxProfile.all.order("order_by asc")
|
||||||
# customer = Customer.find(sale.customer_id)
|
# customer = Customer.find(sale.customer_id)
|
||||||
arr_tax = []
|
|
||||||
arr_tax = unique_tax_profiles(order_source, self.customer_id)
|
|
||||||
|
|
||||||
if !arr_tax.empty?
|
|
||||||
if tax_type.nil?
|
|
||||||
tax_profiles = TaxProfile.where(:id => arr_tax)
|
|
||||||
else
|
|
||||||
tax_profiles = TaxProfile.where("group_type=?",order_source)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
tax_profiles = TaxProfile.where("group_type=?",order_source)
|
|
||||||
end
|
|
||||||
|
|
||||||
# #Creat new tax records
|
|
||||||
if order_source.to_s == "emenu"
|
if order_source.to_s == "emenu"
|
||||||
order_source = "cashier"
|
order_source = "cashier"
|
||||||
end
|
end
|
||||||
|
|
||||||
if sale.payment_status != 'foc'
|
tax_profiles = unique_tax_profiles(order_source, self.customer_id)
|
||||||
|
|
||||||
|
# #Creat new tax records
|
||||||
|
if self.payment_status != 'foc'
|
||||||
tax_profiles.each do |tax|
|
tax_profiles.each do |tax|
|
||||||
if tax.group_type.to_s == order_source.to_s
|
sale_tax = SaleTax.new(:sale => self)
|
||||||
if tax_type
|
sale_tax.tax_name = tax.name
|
||||||
if tax_type.to_s == tax.name.to_s || tax_type == 'all'
|
sale_tax.tax_rate = tax.rate
|
||||||
sale_tax = SaleTax.new(:sale => sale)
|
|
||||||
sale_tax.tax_name = tax.name
|
|
||||||
sale_tax.tax_rate = tax.rate
|
|
||||||
|
|
||||||
# substract , to give after discount
|
# substract , to give after discount
|
||||||
total_tax = total_taxable - total_discount
|
total_tax = total_taxable - total_discount
|
||||||
#include or execulive
|
#include or execulive
|
||||||
if tax.inclusive
|
if tax.inclusive
|
||||||
tax_incl_exec = "inclusive"
|
tax_incl_exec = "inclusive"
|
||||||
rate = tax.rate
|
rate = tax.rate
|
||||||
divided_value = (100 + rate)/rate
|
divided_value = (100 + rate)/rate
|
||||||
sale_tax.tax_payable_amount = total_tax / divided_value
|
sale_tax.tax_payable_amount = total_tax / divided_value
|
||||||
else
|
else
|
||||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
||||||
end
|
|
||||||
#new taxable amount is standard rule for step by step
|
|
||||||
if shop.calc_tax_order
|
|
||||||
total_taxable = total_taxable + sale_tax.tax_payable_amount
|
|
||||||
end
|
|
||||||
sale_tax.inclusive = tax.inclusive
|
|
||||||
sale_tax.save
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# customer.tax_profiles.each do |cus_tax|
|
|
||||||
# if cus_tax.to_i == tax.id
|
|
||||||
sale_tax = SaleTax.new(:sale => sale)
|
|
||||||
sale_tax.tax_name = tax.name
|
|
||||||
sale_tax.tax_rate = tax.rate
|
|
||||||
|
|
||||||
# substract , to give after discount
|
|
||||||
total_tax = total_taxable - total_discount
|
|
||||||
#include or execulive
|
|
||||||
if tax.inclusive
|
|
||||||
tax_incl_exec = "inclusive"
|
|
||||||
rate = tax.rate
|
|
||||||
divided_value = (100 + rate)/rate
|
|
||||||
sale_tax.tax_payable_amount = total_tax / divided_value
|
|
||||||
else
|
|
||||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
|
||||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
|
||||||
end
|
|
||||||
#new taxable amount is standard rule for step by step
|
|
||||||
if shop.calc_tax_order
|
|
||||||
total_taxable = total_taxable + sale_tax.tax_payable_amount
|
|
||||||
end
|
|
||||||
sale_tax.inclusive = tax.inclusive
|
|
||||||
sale_tax.save
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
#new taxable amount is standard rule for step by step
|
||||||
|
if shop.calc_tax_order
|
||||||
|
total_taxable = total_taxable + sale_tax.tax_payable_amount
|
||||||
|
end
|
||||||
|
sale_tax.inclusive = tax.inclusive
|
||||||
|
sale_tax.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
sale.tax_type = tax_incl_exec
|
self.tax_type = tax_incl_exec
|
||||||
sale.total_tax = total_tax_amount
|
self.total_tax = total_tax_amount
|
||||||
end
|
end
|
||||||
|
|
||||||
# Tax Calculate
|
# Tax Calculate
|
||||||
@@ -608,8 +561,7 @@ class Sale < ApplicationRecord
|
|||||||
# existing_tax.delete
|
# existing_tax.delete
|
||||||
# end
|
# end
|
||||||
|
|
||||||
taxes = SaleTax.where("sale_id='#{self.sale_id}'").pluck(:sale_tax_id)
|
taxes = SaleTax.where("sale_id='#{self.sale_id}'").destroy_all
|
||||||
SaleTax.where("sale_tax_id IN (?)", taxes).destroy_all
|
|
||||||
|
|
||||||
total_tax_amount = 0
|
total_tax_amount = 0
|
||||||
tax_incl_exec = "exclusive"
|
tax_incl_exec = "exclusive"
|
||||||
@@ -622,77 +574,34 @@ class Sale < ApplicationRecord
|
|||||||
# tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id)
|
# tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id)
|
||||||
# customer = Customer.find(self.customer_id).tax_profiles
|
# customer = Customer.find(self.customer_id).tax_profiles
|
||||||
|
|
||||||
arr_tax = []
|
tax_profiles = unique_tax_profiles(order_source, self.customer_id)
|
||||||
arr_tax = unique_tax_profiles(order_source, self.customer_id)
|
|
||||||
|
|
||||||
if !arr_tax.empty?
|
|
||||||
if tax_type.nil?
|
|
||||||
tax_profiles = TaxProfile.where(:id => arr_tax)
|
|
||||||
else
|
|
||||||
tax_profiles = TaxProfile.where("group_type=?",order_source)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
tax_profiles = TaxProfile.where("group_type=?",order_source)
|
|
||||||
end
|
|
||||||
#Create new tax records
|
#Create new tax records
|
||||||
tax_profiles.each do |tax|
|
tax_profiles.each do |tax|
|
||||||
if tax.group_type.to_s == order_source.to_s
|
sale_tax = SaleTax.new(:sale => self)
|
||||||
if tax_type
|
sale_tax.tax_name = tax.name
|
||||||
if tax_type.to_s == tax.name.to_s || tax_type == 'all'
|
sale_tax.tax_rate = tax.rate
|
||||||
sale_tax = SaleTax.new(:sale => self)
|
|
||||||
sale_tax.tax_name = tax.name
|
|
||||||
sale_tax.tax_rate = tax.rate
|
|
||||||
|
|
||||||
# substract , to give after discount
|
# substract , to give after discount
|
||||||
total_tax = total_taxable - total_discount
|
total_tax = total_taxable - self.total_discount
|
||||||
#include or execulive
|
#include or execulive
|
||||||
if tax.inclusive
|
if tax.inclusive
|
||||||
tax_incl_exec = "inclusive"
|
tax_incl_exec = "inclusive"
|
||||||
rate = tax.rate
|
rate = tax.rate
|
||||||
divided_value = (100 + rate)/rate
|
divided_value = (100 + rate)/rate
|
||||||
sale_tax.tax_payable_amount = total_tax / divided_value
|
sale_tax.tax_payable_amount = total_tax / divided_value
|
||||||
else
|
else
|
||||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
||||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
||||||
end
|
|
||||||
#new taxable amount is standard rule for step by step
|
|
||||||
if shop.calc_tax_order
|
|
||||||
total_taxable = total_taxable + sale_tax.tax_payable_amount
|
|
||||||
end
|
|
||||||
sale_tax.inclusive = tax.inclusive
|
|
||||||
sale_tax.save
|
|
||||||
end
|
|
||||||
else
|
|
||||||
# customer.tax_profiles.each do |cus_tax|
|
|
||||||
# if cus_tax.to_i == tax.id
|
|
||||||
sale_tax = SaleTax.new(:sale => self)
|
|
||||||
sale_tax.tax_name = tax.name
|
|
||||||
sale_tax.tax_rate = tax.rate
|
|
||||||
|
|
||||||
# substract , to give after discount
|
|
||||||
total_tax = total_taxable - self.total_discount
|
|
||||||
#include or execulive
|
|
||||||
if tax.inclusive
|
|
||||||
tax_incl_exec = "inclusive"
|
|
||||||
rate = tax.rate
|
|
||||||
divided_value = (100 + rate)/rate
|
|
||||||
sale_tax.tax_payable_amount = total_tax / divided_value
|
|
||||||
else
|
|
||||||
sale_tax.tax_payable_amount = total_tax * tax.rate / 100
|
|
||||||
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
|
|
||||||
end
|
|
||||||
|
|
||||||
#new taxable amount is standard rule for step by step
|
|
||||||
if shop.calc_tax_order
|
|
||||||
total_taxable = total_taxable + sale_tax.tax_payable_amount
|
|
||||||
end
|
|
||||||
|
|
||||||
sale_tax.inclusive = tax.inclusive
|
|
||||||
sale_tax.save
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#new taxable amount is standard rule for step by step
|
||||||
|
if shop.calc_tax_order
|
||||||
|
total_taxable = total_taxable + sale_tax.tax_payable_amount
|
||||||
|
end
|
||||||
|
|
||||||
|
sale_tax.inclusive = tax.inclusive
|
||||||
|
sale_tax.save
|
||||||
end
|
end
|
||||||
self.tax_type = tax_incl_exec
|
self.tax_type = tax_incl_exec
|
||||||
self.total_tax = total_tax_amount
|
self.total_tax = total_tax_amount
|
||||||
@@ -727,42 +636,16 @@ class Sale < ApplicationRecord
|
|||||||
shop_details = Shop.first
|
shop_details = Shop.first
|
||||||
# rounding adjustment
|
# rounding adjustment
|
||||||
if shop_details.is_rounding_adj
|
if shop_details.is_rounding_adj
|
||||||
a = self.grand_total % 25 # Modulus
|
new_total = Sale.get_rounding_adjustment(self.grand_total)
|
||||||
b = self.grand_total / 25 # Division
|
self.rounding_adjustment = new_total - self.grand_total
|
||||||
#not calculate rounding if modulus is 0 and division is even
|
self.old_grand_total = self.grand_total
|
||||||
#calculate rounding if modulus is zero or not zero and division are not even
|
self.grand_total = new_total
|
||||||
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
|
|
||||||
new_total = Sale.get_rounding_adjustment(self.grand_total)
|
|
||||||
self.rounding_adjustment = new_total - self.grand_total
|
|
||||||
else
|
|
||||||
self.rounding_adjustment = 0.00
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
self.rounding_adjustment = 0.00
|
self.rounding_adjustment = 0.00
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def compute_adjust_rounding(grand_total)
|
|
||||||
shop_details = Shop.first
|
|
||||||
# rounding adjustment
|
|
||||||
if shop_details.is_rounding_adj
|
|
||||||
a = grand_total % 25 # Modulus
|
|
||||||
b = 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(grand_total)
|
|
||||||
rounding_adjustment = new_total - grand_total
|
|
||||||
else
|
|
||||||
rounding_adjustment = 0.00
|
|
||||||
end
|
|
||||||
else
|
|
||||||
rounding_adjustment = 0.00
|
|
||||||
end
|
|
||||||
return rounding_adjustment
|
|
||||||
end
|
|
||||||
|
|
||||||
#Generate new Receipt No when it is not assigned
|
#Generate new Receipt No when it is not assigned
|
||||||
def generate_receipt_no
|
def generate_receipt_no
|
||||||
#shop_code and client_code
|
#shop_code and client_code
|
||||||
@@ -857,115 +740,69 @@ class Sale < ApplicationRecord
|
|||||||
# if get_rounded_amt == true
|
# if get_rounded_amt == true
|
||||||
value = 0
|
value = 0
|
||||||
|
|
||||||
num = num.to_f.round
|
# num = num.to_f.round
|
||||||
get_last_no = num.to_s.last(2).to_f
|
mod = num % 50
|
||||||
if get_last_no.between?(0,25)
|
if mod > 0 && mod <= 25
|
||||||
## down to 0
|
num -= mod
|
||||||
num -= get_last_no
|
elsif mod > 25
|
||||||
else
|
num += 50 - mod
|
||||||
if get_last_no.between?(26,50)
|
|
||||||
## up to 50
|
|
||||||
value = 50 - get_last_no.to_f
|
|
||||||
num += value
|
|
||||||
puts 'up to 50'
|
|
||||||
else
|
|
||||||
if get_last_no.between?(51, 75)
|
|
||||||
## down to 50
|
|
||||||
value = get_last_no.to_f - 50
|
|
||||||
num -= value
|
|
||||||
puts 'down to 50'
|
|
||||||
else
|
|
||||||
## up to 100
|
|
||||||
value = 100 - get_last_no.to_f
|
|
||||||
num += value
|
|
||||||
puts 'up to 100'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
# end
|
|
||||||
return num
|
return num
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.daily_sales_list(from,to)
|
def self.daily_sales_list(from,to)
|
||||||
sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN
|
sales = select("
|
||||||
(SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount)) ELSE 0 END)
|
sales.*,
|
||||||
FROM sale_payments
|
SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount,
|
||||||
INNER JOIN sale_audits sa ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id
|
SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount,
|
||||||
INNER JOIN sales s ON s.sale_id=sa.sale_id
|
SUM(case when (sale_payments.payment_method='master') then sale_payments.payment_amount else 0 end) as master_amount,
|
||||||
WHERE s.sale_status='completed'
|
SUM(case when (sale_payments.payment_method='visa') then sale_payments.payment_amount else 0 end) as visa_amount,
|
||||||
AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') = DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d')"
|
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 end) < sales.grand_total
|
||||||
|
THEN sales.grand_total - SUM(case when sale_payments.payment_method not in('creditnote') then sale_payments.payment_amount 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")
|
||||||
|
.joins("LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND DATE(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30')) = DATE(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'))")
|
||||||
|
.where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to)
|
||||||
|
.group("sale_id").to_sql
|
||||||
|
|
||||||
payments_total = Sale.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
|
daily_total = connection.select_all("SELECT
|
||||||
SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount,
|
IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total,
|
||||||
SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount,
|
IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total,
|
||||||
SUM(case when (sale_payments.payment_method='master') then sale_payments.payment_amount else 0 end) as master_amount,
|
IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount,
|
||||||
SUM(case when (sale_payments.payment_method='visa') then sale_payments.payment_amount else 0 end) as visa_amount,
|
IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount,
|
||||||
SUM(case when (sale_payments.payment_method='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount,
|
IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount,
|
||||||
SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_amount,
|
IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj,
|
||||||
SUM(case when (sale_payments.payment_method='unionpay') then sale_payments.payment_amount else 0 end) as unionpay_amount,
|
CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date,
|
||||||
SUM(case when (sale_payments.payment_method='alipay') then sale_payments.payment_amount else 0 end) as alipay_amount,
|
SUM(kbzpay_amount) as kbzpay_amount,
|
||||||
SUM(case when (sale_payments.payment_method='paymal') then sale_payments.payment_amount else 0 end) as paymal_amount,
|
SUM(mpu_amount) as mpu_amount,
|
||||||
SUM(case when (sale_payments.payment_method='dinga') then sale_payments.payment_amount else 0 end) as dinga_amount,
|
SUM(master_amount) as master_amount,
|
||||||
SUM(case when (sale_payments.payment_method='JunctionPay') then sale_payments.payment_amount else 0 end) as junctionpay_amount,
|
SUM(visa_amount) as visa_amount,
|
||||||
SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
|
SUM(jcb_amount) as jcb_amount,
|
||||||
(CASE WHEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end)) > 0 THEN (SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) - (#{sub_query})) ELSE 0 END) as credit_amount,
|
SUM(paypar_amount) as paypar_amount,
|
||||||
SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount,
|
SUM(unionpay_amount) as unionpay_amount,
|
||||||
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
|
SUM(alipay_amount) as alipay_amount,
|
||||||
.joins(" join sale_payments on sale_payments.sale_id = sales.sale_id")
|
SUM(paymal_amount) as paymal_amount,
|
||||||
.where("sale_status = ? AND sales.receipt_date between ? and ? ", 'completed', from, to)
|
SUM(dinga_amount) as dinga_amount,
|
||||||
.group("DATE_FORMAT((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')),'%Y-%m-%d')")
|
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)
|
||||||
|
|
||||||
daily_total = Array.new
|
return daily_total
|
||||||
|
|
||||||
payments_total.each do |pay|
|
|
||||||
sale_date = pay.sale_date
|
|
||||||
diff_time = payments_total.first.sale_date.beginning_of_day.utc - from
|
|
||||||
diff = diff_time % 86400
|
|
||||||
from_date = sale_date.beginning_of_day.utc - diff
|
|
||||||
to_date = sale_date.end_of_day.utc - diff
|
|
||||||
|
|
||||||
total_sale = Sale.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 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")
|
|
||||||
.where("(sale_status = ? OR sale_status = ?) AND receipt_date between ? and ? AND total_amount != 0", 'completed', 'void', from_date, to_date)
|
|
||||||
|
|
||||||
total_sale.each do |sale|
|
|
||||||
grand_total = sale.grand_total
|
|
||||||
old_grand_total = sale.old_grand_total
|
|
||||||
total_discount = sale.total_discount
|
|
||||||
void_amount = sale.void_amount
|
|
||||||
total_change_amount = sale.total_change_amount
|
|
||||||
total = {:sale_date => pay.sale_date,
|
|
||||||
:mpu_amount => pay.mpu_amount,
|
|
||||||
:master_amount => pay.master_amount,
|
|
||||||
:visa_amount => pay.visa_amount,
|
|
||||||
:jcb_amount => pay.jcb_amount,
|
|
||||||
:paypar_amount => pay.paypar_amount,
|
|
||||||
:unionpay_amount => pay.unionpay_amount,
|
|
||||||
:alipay_amount => pay.alipay_amount,
|
|
||||||
:kbzpay_amount => pay.kbzpay_amount,
|
|
||||||
:paymal_amount => pay.paymal_amount,
|
|
||||||
:dinga_amount => pay.dinga_amount,
|
|
||||||
:junctionpay_amount => pay.junctionpay_amount,
|
|
||||||
:cash_amount => pay.cash_amount,
|
|
||||||
:credit_amount => pay.credit_amount,
|
|
||||||
:foc_amount => pay.foc_amount,
|
|
||||||
:giftvoucher_amount => pay.giftvoucher_amount,
|
|
||||||
:total_discount => total_discount,
|
|
||||||
:total_change_amount => total_change_amount,
|
|
||||||
:grand_total => grand_total,
|
|
||||||
:old_grand_total => old_grand_total,
|
|
||||||
:void_amount => void_amount,
|
|
||||||
:rounding_adj => sale.rounding_adj}
|
|
||||||
daily_total.push(total)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
return daily_total
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_by_range_by_saleitems(from,to,status,report_type)
|
def self.get_by_range_by_saleitems(from,to,status,report_type)
|
||||||
@@ -1267,73 +1104,64 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,order_source)
|
def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,order_source)
|
||||||
sub_query = "SELECT (CASE WHEN SUM(payment_amount) > 0
|
order_sources = Order.select("sale_orders.sale_id, orders.source")
|
||||||
THEN DATE_FORMAT(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30'),'%d %b %y %h:%i%p') ELSE '-' END)
|
.joins(:sale_orders).to_sql
|
||||||
FROM `sale_payments`
|
|
||||||
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
|
||||||
WHERE sale_audits.sale_id = s.sale_id"
|
|
||||||
|
|
||||||
sub_query1 = "SELECT (CASE WHEN SUM(payment_amount) > 0 THEN SUM(payment_amount) -
|
credit_payments = SalePayment.select("
|
||||||
(SUM(payment_amount) - (SELECT SUM(payment_amount) FROM sale_payments WHERE payment_method='creditnote' AND sale_id=s.sale_id)) ELSE 0 END)
|
sales.sale_id,
|
||||||
FROM `sale_payments`
|
DATE_FORMAT(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30'),'%d %b %y %h:%i%p') as credit_payment_receipt_date,
|
||||||
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
sale_payments.payment_amount as credit_payment,
|
||||||
WHERE sale_audits.sale_id = s.sale_id"
|
employees.name as credit_payment_cashier_name,
|
||||||
|
CONCAT(DATE_FORMAT(CONVERT_TZ(shift_started_at,'+00:00','+06:30'),'%d %b %y %h:%i%p'),' - ',DATE_FORMAT(CONVERT_TZ(shift_closed_at,'+00:00','+06:30'),'%d %b %y %h:%i%p')) as credit_payment_shift_name")
|
||||||
|
.joins("JOIN sales ON sales.sale_id = sale_payments.sale_id")
|
||||||
|
.joins("JOIN sale_audits ON sale_audits.sale_id = sales.sale_id AND SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id")
|
||||||
|
.joins("JOIN shift_sales ON shift_sales.id = sales.shift_sale_id")
|
||||||
|
.joins("JOIN employees ON employees.id = shift_sales.employee_id").to_sql
|
||||||
|
|
||||||
sub_query2 = "SELECT (CASE WHEN shift_closed_at IS NOT NULL AND credit_payment > 0
|
credits = SalePayment.select("
|
||||||
THEN CONCAT(DATE_FORMAT(CONVERT_TZ(shift_started_at,'+00:00','+06:30'),'%d %b %y %h:%i%p'),' - ',DATE_FORMAT(CONVERT_TZ(shift_closed_at,'+00:00','+06:30'),'%d %b %y %h:%i%p'))
|
sale_payments.sale_payment_id,
|
||||||
ELSE '-' END)
|
sale_payments.payment_method,
|
||||||
FROM shift_sales
|
sale_payments.payment_amount,
|
||||||
WHERE shift_sales.id = s.shift_sale_id"
|
sale_payments.payment_status,
|
||||||
|
sales.sale_id,
|
||||||
|
sales.receipt_no,
|
||||||
|
sales.receipt_date as sale_date,
|
||||||
|
order_sources.source as order_source,
|
||||||
|
sales.cashier_name,
|
||||||
|
customers.name as customer_name,
|
||||||
|
IFNULL(credit_payments.credit_payment_receipt_date, '-') as credit_payment_receipt_date,
|
||||||
|
IFNULL(credit_payments.credit_payment, 0) as credit_payment,
|
||||||
|
IFNULL(credit_payments.credit_payment_cashier_name, '-') as credit_payment_cashier_name,
|
||||||
|
IFNULL(credit_payments.credit_payment_shift_name, '-') as credit_payment_shift_name")
|
||||||
|
.joins("JOIN sales ON sales.sale_id = sale_payments.sale_id")
|
||||||
|
.joins("JOIN shift_sales ON shift_sales.id = sales.shift_sale_id")
|
||||||
|
.joins("JOIN customers ON customers.customer_id = sales.customer_id")
|
||||||
|
.joins("JOIN (#{order_sources}) order_sources ON order_sources.sale_id = sales.sale_id")
|
||||||
|
.joins("LEFT JOIN (#{credit_payments}) credit_payments ON credit_payments.sale_id = sales.sale_id")
|
||||||
|
.where("sale_payments.payment_method= ? AND sales.sale_status = ?", 'creditnote', 'completed')
|
||||||
|
|
||||||
sub_query3 = "SELECT (CASE WHEN shift_closed_at IS NOT NULL OR shift_closed_at IS NULL AND credit_payment > 0
|
if order_source.present?
|
||||||
THEN employees.name ELSE '-' END)
|
|
||||||
FROM shift_sales
|
|
||||||
INNER JOIN employees ON employees.id=shift_sales.employee_id
|
|
||||||
WHERE shift_sales.id = s.shift_sale_id"
|
|
||||||
|
|
||||||
filter_check = ""
|
|
||||||
if filter == 'paid'
|
|
||||||
filter_check = " AND (SELECT (CASE WHEN SUM(payment_amount) > 0 THEN SUM(payment_amount) ELSE 0 END)
|
|
||||||
FROM `sale_payments`
|
|
||||||
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
|
||||||
WHERE sale_audits.sale_id = s.sale_id) > 0"
|
|
||||||
elsif filter == 'unpaid'
|
|
||||||
filter_check = " AND (SELECT (CASE WHEN SUM(payment_amount) > 0 THEN SUM(payment_amount) ELSE 0 END)
|
|
||||||
FROM `sale_payments`
|
|
||||||
INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id
|
|
||||||
WHERE sale_audits.sale_id = s.sale_id) = 0"
|
|
||||||
end
|
|
||||||
order_source_query = "(select orders.source FROM orders JOIN sale_orders so ON so.order_id=orders.order_id WHERE so.sale_id=s.sale_id GROUP BY so.sale_id)"
|
|
||||||
|
|
||||||
if order_source.blank?
|
|
||||||
source = ""
|
|
||||||
else
|
|
||||||
if order_source == "cashier"
|
if order_source == "cashier"
|
||||||
source = "and #{order_source_query}='cashier' or #{order_source_query}='emenu'"
|
credits = credits.where("order_sources.source IN (?)", ['cashier', 'emenu'])
|
||||||
else
|
else
|
||||||
source = "and #{order_source_query}='#{order_source}'"
|
credits = credits.where("order_sources.source = ?", order_source)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
query = SalePayment.select("s.receipt_no, sale_payments.*,
|
|
||||||
SUM(sale_payments.payment_amount) as payment_amount,
|
if filter == 'paid'
|
||||||
s.receipt_date as sale_date,
|
credits = credits.where("credit_payment IS NOT NULL")
|
||||||
#{order_source_query} as order_source,
|
elsif filter == 'unpaid'
|
||||||
s.cashier_name as cashier_name,
|
credits = credits.where("credit_payment IS NULL")
|
||||||
(#{sub_query}) as credit_payment_receipt_date,
|
end
|
||||||
(#{sub_query1}) as credit_payment,
|
|
||||||
(#{sub_query3}) as credit_payment_cashier_name,
|
|
||||||
(#{sub_query2}) as credit_payment_shift_name")
|
|
||||||
.joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
|
|
||||||
.joins("INNER JOIN shift_sales ss ON ss.id = s.shift_sale_id")
|
|
||||||
|
|
||||||
if shift.present?
|
if shift.present?
|
||||||
query = query.where("sale_payments.payment_method= 'creditnote' and s.sale_status = 'completed' #{filter_check} and s.shift_sale_id in (?) #{source}",shift.to_a)
|
credits = credits.where("sales.shift_sale_id in (?)",shift.to_a)
|
||||||
elsif shift_sale_range.present?
|
elsif shift_sale_range.present?
|
||||||
query = query.where("sale_payments.payment_method='creditnote' and s.sale_status = 'completed' #{filter_check} and s.shift_sale_id in (?) #{source}",shift_sale_range.to_a)
|
credits = credits.where("sales.shift_sale_id in (?)",shift_sale_range.to_a)
|
||||||
else
|
else
|
||||||
query = query.where("sale_payments.payment_method='creditnote' and s.sale_status = 'completed' #{filter_check} and s.receipt_date between ? and ? #{source}",from,to)
|
credits = credits.where("sales.receipt_date between ? and ?",from,to)
|
||||||
end
|
end
|
||||||
query = query.group("s.sale_id")
|
credits = credits.group("sales.sale_id")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_void_sale(shift,from,to)
|
def self.get_void_sale(shift,from,to)
|
||||||
@@ -2646,20 +2474,15 @@ def self.get_sale_data_for_other_payment_credit(sale_id)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unique_tax_profiles(order_source, customer_id)
|
def unique_tax_profiles(order_source, customer_id)
|
||||||
tax_data = TaxProfile.where("group_type='#{order_source}'").pluck(:id)
|
tax_data = TaxProfile
|
||||||
customer_tax_profiles = Customer.find(customer_id).tax_profiles
|
.where(group_type: order_source)
|
||||||
|
|
||||||
arr_data = []
|
customer_tax_profiles = Customer.select(:tax_profiles).where(customer_id: customer_id).first
|
||||||
if !customer_tax_profiles.empty?
|
if customer_tax_profiles.present?
|
||||||
customer_tax_profiles.each do |value1|
|
tax_data = tax_data.where(id: customer_tax_profiles.tax_profiles)
|
||||||
if tax_data.include? value1.to_i
|
|
||||||
arr_data.push(value1.to_i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return arr_data
|
|
||||||
else
|
|
||||||
return tax_data
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return tax_data
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil)
|
||||||
@@ -2885,6 +2708,139 @@ def grand_total_round
|
|||||||
self.grand_total =self.grand_total.round(print_settings.precision.to_i)
|
self.grand_total =self.grand_total.round(print_settings.precision.to_i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Loader Service SFTP Start
|
||||||
|
def self.get_load_sale_range(load_time_start,load_time_end)
|
||||||
|
query = Sale.select("sales.sale_id,
|
||||||
|
CONVERT(receipt_date, TIME) as transaction_time,
|
||||||
|
CONVERT(receipt_date, DATE) as transaction_date,
|
||||||
|
receipt_no as transaction_no,
|
||||||
|
SUM(i.qty) as item_no,
|
||||||
|
'MMK' as currency_salesamount,
|
||||||
|
IFNULL((total_amount-total_discount)-((total_amount-total_discount)/21),0) as total_salesamount,
|
||||||
|
IFNULL(amount_changed,0) as change_amt,
|
||||||
|
IFNULL(total_amount-total_discount,0) as grand_salesamount,
|
||||||
|
'5' as tax_percent,
|
||||||
|
'MMK' as currency_payment,
|
||||||
|
IFNULL(amount_received,0) as paymentamount,
|
||||||
|
sp.payment_amount as payment_method,
|
||||||
|
CASE
|
||||||
|
WHEN sales.sale_status='completed' THEN 'Sales'
|
||||||
|
WHEN sales.sale_status='void' THEN 'Void'
|
||||||
|
END as sale_type,
|
||||||
|
sales.updated_at as load_time")
|
||||||
|
.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" +
|
||||||
|
" JOIN sale_payments sp ON sp.sale_id = sales.sale_id")
|
||||||
|
.where("(sale_status=? OR sale_status=?) AND sp.payment_method !=? AND sales.updated_at between ? AND ?", 'completed', 'void', 'foc', load_time_start, load_time_end)
|
||||||
|
.group("receipt_no")
|
||||||
|
.order("receipt_date")
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get_tender_sale_data(transaction_date)
|
||||||
|
query = Sale.select("sales.receipt_no as check_num,
|
||||||
|
DATE_FORMAT(sales.receipt_date, '%d %b %Y') as business_date,
|
||||||
|
sales.receipt_date as transaction_date,
|
||||||
|
'36017' as item_id,
|
||||||
|
'Cash Received' as item_name,
|
||||||
|
'1' as qty,
|
||||||
|
'Tender' as transaction_type,
|
||||||
|
'0' as sales,
|
||||||
|
CASE WHEN sales.sale_status = 'void' THEN '1' ELSE '0' END as is_void
|
||||||
|
")
|
||||||
|
.where("DATE(sales.receipt_date)=? AND sales.sale_status != ?", transaction_date, :void)
|
||||||
|
.order("sales.receipt_no")
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get_daily_sale_data(transaction_date)
|
||||||
|
query = Sale.connection.select_all("SELECT s.receipt_date as business_date,
|
||||||
|
(SUM(s.grand_total)+SUM(s.total_discount)) as gross_sales,
|
||||||
|
SUM(s.total_discount) as discount,
|
||||||
|
SUM(s.grand_total) as sales,
|
||||||
|
SUM(s.grand_total)/21 as tax,
|
||||||
|
0 as service_charge,
|
||||||
|
SUM(s.grand_total) - (SUM(s.grand_total)/21) as net_sales,
|
||||||
|
SUM(s.credit_amount) as credit_amount,
|
||||||
|
SUM(s.voucher_sales) as voucher_sales,
|
||||||
|
0 as staff_meal_amt,
|
||||||
|
0 as round_amt,
|
||||||
|
0 as raw_wastage_amt,
|
||||||
|
0 as semi_wastage_amt,
|
||||||
|
CASE WHEN s.sale_status='waste' THEN SUM(s.total_amount) ELSE 0 END as wastage_amt,
|
||||||
|
CASE WHEN s.sale_status='spoile' THEN SUM(s.total_amount) ELSE 0 END as spoilage_amt,
|
||||||
|
0 as sampling_amt,
|
||||||
|
0 as other_amt,
|
||||||
|
SUM(s.qty) as total_qty,
|
||||||
|
(SELECT COUNT(sales.sale_id) FROM sales WHERE DATE(sales.receipt_date)='#{transaction_date}') as total_transaction,
|
||||||
|
(SELECT COUNT(sales.sale_id) FROM sales WHERE (sales.sale_status='completed' OR sales.sale_status='void') AND DATE(sales.receipt_date)='#{transaction_date}') as valid_transaction_count,
|
||||||
|
(SELECT COUNT(sales.sale_id) FROM sales WHERE (sales.sale_status IN('new','pending',null)) AND DATE(sales.receipt_date)='#{transaction_date}') as invalid_transaction_count,
|
||||||
|
0 as overing_transaction_count,
|
||||||
|
0 as cancle_transaction_count,
|
||||||
|
0 as no_of_pax,
|
||||||
|
0 as no_of_adult,
|
||||||
|
0 as no_of_child
|
||||||
|
FROM (
|
||||||
|
SELECT s.*, SUM(qty) as qty
|
||||||
|
FROM (
|
||||||
|
SELECT sales.*,
|
||||||
|
SUM(CASE WHEN sp.payment_method IN('mpu','master','visa','jcb','unionpay','alipay') THEN sp.payment_amount ELSE 0 END) as credit_amount,
|
||||||
|
SUM(case when (sp.payment_method='giftvoucher') then sp.payment_amount else 0 end) as voucher_sales
|
||||||
|
FROM sales
|
||||||
|
LEFT JOIN sale_payments sp ON sp.sale_id = sales.sale_id
|
||||||
|
WHERE DATE(sales.receipt_date) = '#{transaction_date}'
|
||||||
|
AND sales.sale_status!='void'
|
||||||
|
AND sales.sale_status='completed'
|
||||||
|
GROUP BY sales.sale_id) AS s
|
||||||
|
LEFT JOIN sale_items si ON si.sale_id = s.sale_id
|
||||||
|
GROUP BY s.sale_id) as s
|
||||||
|
GROUP BY DATE(s.receipt_date)").to_hash
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get_check_sale_data(transaction_date)
|
||||||
|
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,
|
||||||
|
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"
|
||||||
|
|
||||||
|
query = Sale.select("
|
||||||
|
sales.receipt_no as check_num,
|
||||||
|
sales.receipt_date as business_date,
|
||||||
|
sales.requested_at as check_open_time,
|
||||||
|
sales.updated_at as check_close_time,
|
||||||
|
(sales.grand_total + sales.total_discount) as gross_sales,
|
||||||
|
sales.total_discount as discount_amt,
|
||||||
|
sales.grand_total as sales,
|
||||||
|
(sales.grand_total/21) as tax_amt,
|
||||||
|
0 as service_charges,
|
||||||
|
(sales.grand_total - (sales.grand_total/21)) as net_sales,
|
||||||
|
receivables.credit_card_sales as credit_card_sales,
|
||||||
|
receivables.voucher_sales as voucher_sales,
|
||||||
|
0 as staff_meal_amt,
|
||||||
|
sales.rounding_adjustment as rounding_amt,
|
||||||
|
CASE WHEN sales.sale_status='waste' THEN sales.total_amount ELSE 0 END as wastage_amt,
|
||||||
|
CASE WHEN sales.sale_status='spoile' THEN sales.total_amount ELSE 0 END as spoilage_amt,
|
||||||
|
0 as sampling_amt,
|
||||||
|
SUM(i.qty) as qty,
|
||||||
|
0 as no_of_pax,
|
||||||
|
0 as no_of_adult,
|
||||||
|
0 as no_of_child,
|
||||||
|
shift_sales.cashier_terminal_id as pos_id,
|
||||||
|
sales.cashier_id as employee_code,
|
||||||
|
employees.name as employee_name,
|
||||||
|
CASE WHEN sales.sale_status='completed' THEN 1 ELSE 0 END is_valid,
|
||||||
|
0 as overing,
|
||||||
|
0 as cancle,
|
||||||
|
CONCAT( employees.name, ' Cash&Go receipt generated and completed.') as remarks")
|
||||||
|
.joins("LEFT JOIN shift_sales ON shift_sales.id = sales.shift_sale_id")
|
||||||
|
.joins("LEFT JOIN sale_items i ON i.sale_id = sales.sale_id")
|
||||||
|
.joins("LEFT JOIN (" + sale_receivables_subquery + ") as receivables ON receivables.sale_id = sales.sale_id")
|
||||||
|
.joins("LEFT JOIN employees ON employees.id = sales.cashier_id")
|
||||||
|
.where("DATE(sales.receipt_date) = ? AND sales.sale_status != ?", transaction_date, :void)
|
||||||
|
.group("sales.receipt_no,sales.sale_status")
|
||||||
|
end
|
||||||
|
|
||||||
|
# Loader Service SFTP End
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def generate_custom_id
|
def generate_custom_id
|
||||||
@@ -2893,6 +2849,20 @@ private
|
|||||||
end
|
end
|
||||||
end
|
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)
|
||||||
|
precision = PrintSetting.get_precision_delimiter().precision.to_i
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
def update_stock_journal
|
def update_stock_journal
|
||||||
if self.sale_status == "void" && self.sale_status_before_last_save != "void"
|
if self.sale_status == "void" && self.sale_status_before_last_save != "void"
|
||||||
self.sale_items.each do |item|
|
self.sale_items.each do |item|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class SaleItem < ApplicationRecord
|
|||||||
def compute_item
|
def compute_item
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before_validation :round_to_precision
|
||||||
after_update :update_stock_journal
|
after_update :update_stock_journal
|
||||||
|
|
||||||
# Add Sale Items
|
# Add Sale Items
|
||||||
@@ -88,7 +89,7 @@ class SaleItem < ApplicationRecord
|
|||||||
# sale_item.save
|
# sale_item.save
|
||||||
if type != "foc"
|
if type != "foc"
|
||||||
sale = Sale.find(sale_id)
|
sale = Sale.find(sale_id)
|
||||||
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount)
|
sale.compute_by_sale_items(sale.total_discount)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -231,6 +232,24 @@ class SaleItem < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def round_to_precision
|
||||||
|
unit_price_fraction = self.unit_price % 1
|
||||||
|
price_fraction = self.unit_price % 1
|
||||||
|
# is_dining_charge = self.menu_category_code == 'DingingCharge'
|
||||||
|
|
||||||
|
if self.unit_price != self.unit_price_was || self.price != self.price_was
|
||||||
|
if unit_price_fraction > 0 || price_fraction > 0
|
||||||
|
if ['Discount', 'promotion'].include?(self.status)
|
||||||
|
precision = PrintSetting.get_precision_delimiter().precision.to_i
|
||||||
|
|
||||||
|
self.unit_price = self.unit_price.round(precision)
|
||||||
|
self.price = (self.unit_price * self.qty).round(precision)
|
||||||
|
self.taxable_price = self.price
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update_stock_journal
|
def update_stock_journal
|
||||||
is_void = self.status == "void" && self.status_before_last_save != "void"
|
is_void = self.status == "void" && self.status_before_last_save != "void"
|
||||||
cancel_void = self.status_before_last_save == "void" && self.status.nil?
|
cancel_void = self.status_before_last_save == "void" && self.status.nil?
|
||||||
@@ -275,4 +294,57 @@ class SaleItem < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Loader Service SFTP Start
|
||||||
|
# Detail Sale Data
|
||||||
|
def self.get_detail_sale_data(transaction_date)
|
||||||
|
query = SaleItem.select("
|
||||||
|
sale_items.sale_item_id as id,
|
||||||
|
sale_items.sale_id as parent_id,
|
||||||
|
s.receipt_no as check_num,
|
||||||
|
s.receipt_date as business_date,
|
||||||
|
s.receipt_date as transaction_date,
|
||||||
|
'' as item_seq,
|
||||||
|
sale_items.menu_category_code as category_code,
|
||||||
|
sale_items.menu_category_name as category_name,
|
||||||
|
'' as sub_category_code,
|
||||||
|
'' as sub_category_name,
|
||||||
|
'' as report_group_code,
|
||||||
|
'' as report_group_name,
|
||||||
|
sale_items.product_code as item_id,
|
||||||
|
sale_items.product_name as item_name,
|
||||||
|
sale_items.qty as qty,
|
||||||
|
CASE
|
||||||
|
WHEN s.sale_status = 'completed' OR s.sale_status = 'void' THEN 'Sales'
|
||||||
|
WHEN s.sale_status = 'waste' THEN 'Waste'
|
||||||
|
WHEN s.sale_status = 'spoile' THEN 'Spoil'
|
||||||
|
END as transaction_type,
|
||||||
|
sale_items.price as gross_sales,
|
||||||
|
'' as discount_code,
|
||||||
|
CASE
|
||||||
|
WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0
|
||||||
|
END as discount_amt,
|
||||||
|
(sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) as sales,
|
||||||
|
((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21) as tax_amt,
|
||||||
|
'' as service_charges,
|
||||||
|
((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END)) - ((sale_items.price - (CASE WHEN i.unit_price IS NOT NULL THEN i.unit_price ELSE 0 END))/21)) as net_sales,
|
||||||
|
'0' as is_set_item,
|
||||||
|
'0' as is_staff_meal,
|
||||||
|
'0' as is_raw_wastage,
|
||||||
|
'0' as is_semi_wastage,
|
||||||
|
CASE WHEN s.sale_status = 'waste' THEN 1 ELSE 0 END as is_wastage,
|
||||||
|
CASE WHEN s.sale_status = 'spoile' THEN 1 ELSE 0 END as is_spoilage,
|
||||||
|
'0' as is_sampling,
|
||||||
|
'1' as tax_able,
|
||||||
|
CASE
|
||||||
|
WHEN s.sale_status = 'void' THEN 1 ELSE 0
|
||||||
|
END as is_void
|
||||||
|
")
|
||||||
|
.joins("LEFT JOIN sales s ON s.sale_id = sale_items.sale_id")
|
||||||
|
.joins("LEFT JOIN sale_items i ON sale_items.sale_id = i.sale_id AND sale_items.item_instance_code = i.item_instance_code AND i.status = 'Discount' AND sale_items.qty = abs(i.qty)")
|
||||||
|
.where("DATE(s.receipt_date) = ? AND s.sale_status != 'void' AND (sale_items.status NOT IN('Discount', 'void','foc') OR sale_items.status IS NULL)", transaction_date)
|
||||||
|
.order("s.receipt_no")
|
||||||
|
end
|
||||||
|
|
||||||
|
# Loader Service SFTP End
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class SaleOrder < ApplicationRecord
|
|||||||
|
|
||||||
belongs_to :sale
|
belongs_to :sale
|
||||||
belongs_to :order
|
belongs_to :order
|
||||||
|
has_many :order_items, foreign_key: "order_id", primary_key: "order_id"
|
||||||
|
|
||||||
def create_sale_order(sale_id, order_id)
|
def create_sale_order(sale_id, order_id)
|
||||||
# sale_order = SaleOrder.new
|
# sale_order = SaleOrder.new
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ class SalePayment < ApplicationRecord
|
|||||||
SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price)
|
SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price)
|
||||||
end
|
end
|
||||||
sale = Sale.find(self.sale.sale_id)
|
sale = Sale.find(self.sale.sale_id)
|
||||||
sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount,'','','',"foc")
|
sale.compute_by_sale_items(sale.total_discount,'','','',"foc")
|
||||||
|
|
||||||
self.payment_method = "foc"
|
self.payment_method = "foc"
|
||||||
self.payment_amount = self.received_amount
|
self.payment_amount = self.received_amount
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ class SaleTax < ApplicationRecord
|
|||||||
before_create :generate_custom_id
|
before_create :generate_custom_id
|
||||||
belongs_to :sale
|
belongs_to :sale
|
||||||
|
|
||||||
|
before_validation :round_to_precision
|
||||||
|
|
||||||
def self.sync_sale_tax_records(sale_taxes)
|
def self.sync_sale_tax_records(sale_taxes)
|
||||||
if !sale_taxes.nil?
|
if !sale_taxes.nil?
|
||||||
sale_taxes.each do |t|
|
sale_taxes.each do |t|
|
||||||
@@ -38,4 +40,13 @@ class SaleTax < ApplicationRecord
|
|||||||
self.sale_tax_id = SeedGenerator.generate_id(self.class.name, "STI")
|
self.sale_tax_id = SeedGenerator.generate_id(self.class.name, "STI")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def round_to_precision
|
||||||
|
if self.tax_payable_amount != self.tax_payable_amount_was
|
||||||
|
if self.tax_payable_amount % 1 > 0
|
||||||
|
precision = PrintSetting.get_precision_delimiter().precision.to_i
|
||||||
|
self.tax_payable_amount = self.tax_payable_amount.round(precision)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ class OrderItemCustomisePdf < Prawn::Document
|
|||||||
|
|
||||||
# add option
|
# add option
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
bounding_box([0,y_position], :width => self.item_width) do
|
||||||
text "#{options}", :size => self.item_font_size,:align => :left
|
text "#{options}", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class OrderItemPdf < Prawn::Document
|
|||||||
|
|
||||||
# add option
|
# add option
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
bounding_box([0,y_position], :width => self.item_width) do
|
||||||
text "#{options}", :size => self.item_font_size,:align => :left
|
text "#{options}", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class OrderItemSlimPdf < Prawn::Document
|
|||||||
|
|
||||||
# add option
|
# add option
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
bounding_box([0,y_position], :width => self.item_width) do
|
||||||
text "#{options}", :size => self.item_font_size,:align => :left
|
text "#{options}", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class OrderItemStarPdf < Prawn::Document
|
|||||||
|
|
||||||
# add option
|
# add option
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
bounding_box([0,y_position], :width => self.item_width) do
|
||||||
text "#{options}", :size => self.item_font_size,:align => :left
|
text "#{options}", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ class OrderSetItemCustomisePdf < Prawn::Document
|
|||||||
|
|
||||||
# add option
|
# add option
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
bounding_box([0,y_position], :width => self.item_width) do
|
||||||
text "#{options}", :size => self.item_font_size,:align => :left
|
text "#{options}", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ class OrderSetItemPdf < Prawn::Document
|
|||||||
|
|
||||||
# add option
|
# add option
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do
|
bounding_box([0,y_position], :width => self.item_width) do
|
||||||
text "#{options}", :size => self.item_font_size,:align => :left
|
text "#{options}", :size => self.item_font_size,:align => :left
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -44,24 +44,22 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="order-detail-slimscroll" data-height="160">
|
<div id="order-detail-slimscroll" data-height="160">
|
||||||
<div class="card-text dining">
|
<div class="card-text dining">
|
||||||
<span id="discount_itemsErr" style="color:red;"></span>
|
<span id="discount_itemsErr" style="color:red;"></span>
|
||||||
<table class="table table-default" id="order-items-table">
|
<table class="table table-default" id="order-items-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="item-name">Items</th>
|
<th class="item-name">Items</th>
|
||||||
<th class="item-attr">QTY</th>
|
<th class="item-attr">QTY</th>
|
||||||
<th class="item-attr">Price</th>
|
<th class="item-attr">Price</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% sub_total = 0 %>
|
<% sub_total = 0 %>
|
||||||
<% @sale_data.sale_items.each do |sale_item| %>
|
<% @sale_data.sale_items.each do |sale_item| %>
|
||||||
<%
|
<% sub_total += sale_item.qty * sale_item.unit_price %>
|
||||||
sub_total += sale_item.qty*sale_item.unit_price
|
<% if sale_item.price > 0 && sale_item.status.blank? %>
|
||||||
if sale_item.price != 0 && sale_item.status != "void" && sale_item.status != "foc"
|
<tr class="item-row item" id=<%= sale_item.sale_item_id %> >
|
||||||
%>
|
|
||||||
<tr class="item-row" id=<%= sale_item.sale_item_id %> >
|
|
||||||
<td style="width:60%; text-align:left">
|
<td style="width:60%; text-align:left">
|
||||||
<span id="item-account-type" class="hidden"><%=sale_item.account_id%></span>
|
<span id="item-account-type" class="hidden"><%=sale_item.account_id%></span>
|
||||||
<span id="item-account-qty" class="hidden"><%=sale_item.qty%></span>
|
<span id="item-account-qty" class="hidden"><%=sale_item.qty%></span>
|
||||||
@@ -74,14 +72,26 @@
|
|||||||
<span id="item-total-price"><%=(sale_item.qty*sale_item.unit_price)%></span>
|
<span id="item-total-price"><%=(sale_item.qty*sale_item.unit_price)%></span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<%
|
<% elsif sale_item.price < 0 && sale_item.status == "Discount" %>
|
||||||
end
|
<tr class="item-row discount" id=<%= sale_item.sale_item_id %> >
|
||||||
end
|
<td style="width:60%; text-align:left">
|
||||||
%>
|
<span id="item-account-type" class="hidden"><%=sale_item.account_id%></span>
|
||||||
</tbody>
|
<span id="item-account-qty" class="hidden"><%=sale_item.qty%></span>
|
||||||
</table>
|
<span id="item-name-price"><%=sale_item.product_name%>@<%=sale_item.unit_price%></span>
|
||||||
</div>
|
</td>
|
||||||
</div>
|
<td style="width:20%; text-align:right">
|
||||||
|
<span id="item-qty"><%=sale_item.qty.abs%></span>
|
||||||
|
</td>
|
||||||
|
<td style="width:20%; text-align:right">
|
||||||
|
<span id="item-total-price"><%=(sale_item.qty*sale_item.unit_price)%></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<table class="table" id="order-charges-table" border="0">
|
<table class="table" id="order-charges-table" border="0">
|
||||||
<tr>
|
<tr>
|
||||||
@@ -132,7 +142,7 @@
|
|||||||
<div class="form-horizontal">
|
<div class="form-horizontal">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="text" id="discount-amount" name="discount-amount" value="<%= @sale_data.total_discount rescue 0 %>" class="form-control" />
|
<input type="text" id="discount-amount" name="discount-amount" value="0" class="form-control" />
|
||||||
<span id="discount-amountErr" style="color:red;"></span>
|
<span id="discount-amountErr" style="color:red;"></span>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
@@ -270,6 +280,9 @@
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var cashier_type = "<%= @cashier_type %>";
|
var cashier_type = "<%= @cashier_type %>";
|
||||||
|
var totalAmount = <%= sub_total %>;
|
||||||
|
var totalDiscount = <%= @sale_data.total_discount %>
|
||||||
|
var precision = <%= precision %>;
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
setHeaderBreadCrumb(_DISCOUNTS_);
|
setHeaderBreadCrumb(_DISCOUNTS_);
|
||||||
/* check webview loaded*/
|
/* check webview loaded*/
|
||||||
@@ -326,28 +339,12 @@ var cashier_type = "<%= @cashier_type %>";
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Select Sale Item
|
// Select Sale Item
|
||||||
$('.item-row').on('click',function(){
|
$('#order-items-table').on('click', '.item-row', function(){
|
||||||
if($(this).hasClass('selected-item') == true){
|
if($(this).hasClass('selected-item') == true){
|
||||||
$(this).removeClass('selected-item');
|
$(this).removeClass('selected-item');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(parseInt($(this).children().find("#item-account-qty").text()) >0 && parseInt($(this).children().find("#item-total-price").text()) >0){
|
$(this).addClass('selected-item');
|
||||||
|
|
||||||
$(this).addClass('selected-item');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Select discount-item
|
|
||||||
$('#order-items-table tbody').on('click', '.discount-item-row',function(){
|
|
||||||
if($(this).hasClass('selected-item') == true){
|
|
||||||
$(this).removeClass('selected-item');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(parseInt($(this).children().find("#item-account-qty").text()) >0 && parseInt($(this).children().find("#item-total-price").text()) >0){
|
|
||||||
|
|
||||||
$(this).addClass('selected-item');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -401,7 +398,7 @@ var cashier_type = "<%= @cashier_type %>";
|
|||||||
if(sale_items.length == 0 && account_types.length == 0){
|
if(sale_items.length == 0 && account_types.length == 0){
|
||||||
calculate_overall_discount(0, discount_value);
|
calculate_overall_discount(0, discount_value);
|
||||||
}
|
}
|
||||||
else {
|
else if(sale_items.length > 0){
|
||||||
calculate_item_discount(0, discount_value, sale_items, account_types);
|
calculate_item_discount(0, discount_value, sale_items, account_types);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,16 +421,25 @@ var cashier_type = "<%= @cashier_type %>";
|
|||||||
var discount_value = $('#discount-amount').val();
|
var discount_value = $('#discount-amount').val();
|
||||||
var ajax_url = "/origami/" + sale_id + "/discount";
|
var ajax_url = "/origami/" + sale_id + "/discount";
|
||||||
|
|
||||||
// Selected Items
|
if(discount_value!=""){
|
||||||
var sale_items = get_selected_sale_items();
|
if(discount_value > 0){
|
||||||
// Selected Account
|
$("#discount-amountErr").val("");
|
||||||
var account_types = get_selected_account_types();
|
|
||||||
|
|
||||||
if(sale_items.length == 0 && account_types.length == 0){
|
// Selected Items
|
||||||
calculate_overall_discount(1, discount_value);
|
var sale_items = get_selected_sale_items();
|
||||||
}
|
// Selected Account
|
||||||
else {
|
var account_types = get_selected_account_types();
|
||||||
calculate_item_discount(1, discount_value, sale_items, account_types);
|
|
||||||
|
if(sale_items.length == 0 && account_types.length == 0){
|
||||||
|
calculate_overall_discount(1, discount_value);
|
||||||
|
} else if(sale_items.length > 0){
|
||||||
|
calculate_item_discount(1, discount_value, sale_items, account_types);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$("#discount-amountErr").html("Discount must be greater than 0!");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$("#discount-amountErr").html("can't be blank");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove Selection
|
// Remove Selection
|
||||||
@@ -444,14 +450,17 @@ var cashier_type = "<%= @cashier_type %>";
|
|||||||
$("#remove-item").on('click', function(e){
|
$("#remove-item").on('click', function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var origin_sub_total = parseFloat($("#order-sub-total").text());
|
var origin_sub_total = parseFloat($("#order-sub-total").text());
|
||||||
var total = 0;
|
// var total = 0;
|
||||||
|
|
||||||
$('.discount-item-row.selected-item').each(function(i){
|
$('.item-row.new-discount').each(function(i){
|
||||||
var amount = parseFloat($(this).find('#item-total-price').text());
|
var amount = parseFloat($(this).find('#item-total-price').text());
|
||||||
total = total + Math.abs(amount);
|
totalAmount += Math.abs(amount)
|
||||||
|
// total = total + Math.abs(amount);
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
});
|
});
|
||||||
$("#order-sub-total").text(origin_sub_total + total);
|
|
||||||
|
$("#order-sub-total").text(totalAmount);
|
||||||
|
$("#order-discount").text(totalDiscount.toFixed(<%= precision.to_i %>));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pay Discount for Payment
|
// Pay Discount for Payment
|
||||||
@@ -462,7 +471,7 @@ var cashier_type = "<%= @cashier_type %>";
|
|||||||
}
|
}
|
||||||
$("#loading_wrapper").show();
|
$("#loading_wrapper").show();
|
||||||
var sale_id = $('#sale-id').text();
|
var sale_id = $('#sale-id').text();
|
||||||
var discount_items = JSON.stringify(get_discount_item_rows());
|
var discount_items = JSON.stringify(get_new_discount_item_rows());
|
||||||
var overall_discount = $("#order-discount").text();
|
var overall_discount = $("#order-discount").text();
|
||||||
var sub_total = $('#order-sub-total').text();
|
var sub_total = $('#order-sub-total').text();
|
||||||
var ajax_url = "/origami/" + sale_id + "/discount";
|
var ajax_url = "/origami/" + sale_id + "/discount";
|
||||||
@@ -500,13 +509,7 @@ var cashier_type = "<%= @cashier_type %>";
|
|||||||
var sale_id = $('#sale-id').text();
|
var sale_id = $('#sale-id').text();
|
||||||
var discount_items = [];
|
var discount_items = [];
|
||||||
|
|
||||||
// Selected Items
|
var sale_items = get_selected_discount_items();
|
||||||
var sale_items = get_selected_sale_items();
|
|
||||||
if(sale_items.length == 0){
|
|
||||||
//swal("Information!", "You have no selected item!");
|
|
||||||
swal ( "Oops" , "You have no selected item!" , "error" );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(var i=0;i < sale_items.length;i++){
|
for(var i=0;i < sale_items.length;i++){
|
||||||
if(sale_items[i].price < 0){
|
if(sale_items[i].price < 0){
|
||||||
@@ -625,14 +628,13 @@ var cashier_type = "<%= @cashier_type %>";
|
|||||||
/* Remove Selection */
|
/* Remove Selection */
|
||||||
function selection_remove(){
|
function selection_remove(){
|
||||||
$(".item-row").removeClass("selected-item");
|
$(".item-row").removeClass("selected-item");
|
||||||
$(".discount_item_row").removeClass("selected-item");
|
|
||||||
$(".accounts-type").removeClass("selected-account");
|
$(".accounts-type").removeClass("selected-account");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get Item rows but not discount*/
|
/* Get Item rows but not discount*/
|
||||||
function get_item_rows(){
|
function get_item_rows(){
|
||||||
var sale_items = [];
|
var sale_items = [];
|
||||||
$('.item-row').not('.discount-item-row').each(function(i){
|
$('.item-row.item').not('.discount').each(function(i){
|
||||||
var sale_item = {};
|
var sale_item = {};
|
||||||
sale_item.id = $(this).attr('id').substr(0,16);
|
sale_item.id = $(this).attr('id').substr(0,16);
|
||||||
sale_item.name = $(this).find('#item-name-price').text().split('@')[0];
|
sale_item.name = $(this).find('#item-name-price').text().split('@')[0];
|
||||||
@@ -644,9 +646,9 @@ var cashier_type = "<%= @cashier_type %>";
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get discount Item rows */
|
/* Get discount Item rows */
|
||||||
function get_discount_item_rows(){
|
function get_new_discount_item_rows(){
|
||||||
var sale_items = [];
|
var sale_items = [];
|
||||||
$('.discount-item-row').each(function(i){
|
$('.item-row.new-discount').each(function(i){
|
||||||
var sale_item = {};
|
var sale_item = {};
|
||||||
sale_item.id = $(this).attr('id');
|
sale_item.id = $(this).attr('id');
|
||||||
sale_item.name = $(this).find('#item-name-price').text();
|
sale_item.name = $(this).find('#item-name-price').text();
|
||||||
@@ -658,23 +660,23 @@ var cashier_type = "<%= @cashier_type %>";
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get discount Item rows */
|
/* Get discount Item rows */
|
||||||
// function get_selected_discount_items(){
|
function get_selected_discount_items(){
|
||||||
// var sale_items = [];
|
var sale_items = [];
|
||||||
// $('.discount-item-row').hasClass('.selected-item').each(function(i){
|
$('.item-row.discount.selected-item').each(function(i){
|
||||||
// var sale_item = {};
|
var sale_item = {};
|
||||||
// sale_item.id = $(this).attr('id');
|
sale_item.id = $(this).attr('id');
|
||||||
// sale_item.name = $(this).find('#item-name-price').text();
|
sale_item.name = $(this).find('#item-name-price').text();
|
||||||
// sale_item.account_id = $(this).find('#item_account_type').text();
|
sale_item.account_id = $(this).find('#item_account_type').text();
|
||||||
// sale_item.price = $(this).find('#item-total-price').text();
|
sale_item.price = $(this).find('#item-total-price').text();
|
||||||
// sale_items.push(sale_item);
|
sale_items.push(sale_item);
|
||||||
// });
|
});
|
||||||
// return sale_items;
|
return sale_items;
|
||||||
// }
|
}
|
||||||
|
|
||||||
/* Get Selected Sale Item's ID and Price */
|
/* Get Selected Sale Item's ID and Price */
|
||||||
function get_selected_sale_items(){
|
function get_selected_sale_items(){
|
||||||
var sale_items = [];
|
var sale_items = [];
|
||||||
$('.item-row.selected-item').each(function(i){
|
$('.item-row.item.selected-item').each(function(i){
|
||||||
var sale_item = {};
|
var sale_item = {};
|
||||||
sale_item.id = $(this).attr('id').substr(0,16);
|
sale_item.id = $(this).attr('id').substr(0,16);
|
||||||
sale_item.name = $(this).find('#item-name-price').text().split('@')[0];
|
sale_item.name = $(this).find('#item-name-price').text().split('@')[0];
|
||||||
@@ -700,14 +702,14 @@ function get_selected_account_types(){
|
|||||||
|
|
||||||
/* Calculate Overall Discount*/
|
/* Calculate Overall Discount*/
|
||||||
function calculate_overall_discount(type, amount){
|
function calculate_overall_discount(type, amount){
|
||||||
var origin_sub_total = parseFloat($("#order-sub-total").text());
|
var origin_sub_total = parseFloat($("#order-sub-total").text()) + parseFloat($("#order-discount").text());
|
||||||
var dis_amount = 0;
|
var dis_amount = 0;
|
||||||
var sub_total = 0;
|
var sub_total = 0;
|
||||||
var total_discount = 0;
|
var total_discount = 0;
|
||||||
|
|
||||||
// For Net Pay
|
// For Net Pay
|
||||||
if(type == 0){
|
if(type == 0){
|
||||||
total_discount = amount;
|
total_discount = Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Percentage Pay
|
// For Percentage Pay
|
||||||
@@ -722,10 +724,12 @@ function calculate_overall_discount(type, amount){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
total_discount = (origin_sub_total * amount)/100;
|
total_discount = Math.round(totalAmount * amount / 100 * Math.pow(10, precision)) / Math.pow(10, precision);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub_total = parseFloat(totalAmount) - parseFloat(total_discount)
|
||||||
|
|
||||||
$("#order-discount").text(parseFloat(total_discount).toFixed(<%= precision.to_i %>));
|
$("#order-discount").text(parseFloat(total_discount).toFixed(<%= precision.to_i %>));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -736,12 +740,13 @@ function calculate_item_discount(type, amount, sale_items, account_types){
|
|||||||
var sub_total = 0;
|
var sub_total = 0;
|
||||||
var total_discount = 0;
|
var total_discount = 0;
|
||||||
var arrItemName = "";
|
var arrItemName = "";
|
||||||
|
|
||||||
$("#discount_itemsErr").html("");
|
$("#discount_itemsErr").html("");
|
||||||
$("#discount-amountErr").html("");
|
$("#discount-amountErr").html("");
|
||||||
// For Net Pay
|
// For Net Pay
|
||||||
if(origin_sub_total > 0){
|
if(origin_sub_total > 0){
|
||||||
if(type == 0){
|
if(type == 0){
|
||||||
dis_amount = (0 - amount);
|
dis_amount = -Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision);
|
||||||
if(sale_items.length > 0){
|
if(sale_items.length > 0){
|
||||||
for(var i=0;i < sale_items.length;i++){
|
for(var i=0;i < sale_items.length;i++){
|
||||||
// if(account_types.length > 0){
|
// if(account_types.length > 0){
|
||||||
@@ -755,20 +760,19 @@ function calculate_item_discount(type, amount, sale_items, account_types){
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// else {
|
// else {
|
||||||
if(parseFloat(amount) > parseFloat(sale_items[i].price)){
|
if(parseFloat(amount) > parseFloat(sale_items[i].price)){
|
||||||
arrItemName += ", " + sale_items[i].name;
|
arrItemName += ", " + sale_items[i].name;
|
||||||
|
}else{
|
||||||
|
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
|
||||||
|
total_discount = parseFloat(total_discount) + parseFloat(amount);
|
||||||
|
|
||||||
|
if(parseFloat(origin_sub_total) >= parseFloat(total_discount)){
|
||||||
|
$("#order-items-table tbody").append(discount_item_row);
|
||||||
}else{
|
}else{
|
||||||
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
|
total_discount = parseFloat(total_discount) - parseFloat(amount);
|
||||||
total_discount = parseFloat(total_discount) + parseFloat(amount);
|
$("#discount-amountErr").html("Discount is greater than sub total!");
|
||||||
|
|
||||||
if(parseFloat(origin_sub_total) >= parseFloat(total_discount)){
|
|
||||||
$("#order-items-table tbody").append(discount_item_row);
|
|
||||||
}else{
|
|
||||||
total_discount = parseFloat(total_discount) - parseFloat(amount);
|
|
||||||
$("#discount-amountErr").html("Discount is greater than sub total!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -806,6 +810,8 @@ function calculate_item_discount(type, amount, sale_items, account_types){
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
sub_total = parseFloat(origin_sub_total) - parseFloat(total_discount);
|
sub_total = parseFloat(origin_sub_total) - parseFloat(total_discount);
|
||||||
|
totalAmount = sub_total
|
||||||
|
$("#order-sub-total").text(parseFloat(sub_total).toFixed(<%= precision.to_i %>));
|
||||||
}
|
}
|
||||||
|
|
||||||
// For Percentage Pay
|
// For Percentage Pay
|
||||||
@@ -835,7 +841,7 @@ function calculate_item_discount(type, amount, sale_items, account_types){
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// else {
|
// else {
|
||||||
dis_amount = 0 - ((sale_items[i].price * amount)/100);
|
dis_amount = -Math.round(sale_items[i].price * amount / 100 * Math.pow(10, precision)) / Math.pow(10, precision);
|
||||||
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
|
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
|
||||||
|
|
||||||
total_discount = total_discount + dis_amount;
|
total_discount = total_discount + dis_amount;
|
||||||
@@ -848,6 +854,8 @@ function calculate_item_discount(type, amount, sale_items, account_types){
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
sub_total = parseFloat(origin_sub_total) + parseFloat(total_discount);
|
sub_total = parseFloat(origin_sub_total) + parseFloat(total_discount);
|
||||||
|
totalAmount = sub_total
|
||||||
|
$("#order-sub-total").text(parseFloat(sub_total).toFixed(<%= precision.to_i %>));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// No Needs For Auto Selected
|
// No Needs For Auto Selected
|
||||||
@@ -874,7 +882,6 @@ function calculate_item_discount(type, amount, sale_items, account_types){
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#order-sub-total").text(parseFloat(sub_total).toFixed(<%= precision.to_i %>));
|
|
||||||
}else{
|
}else{
|
||||||
$("#discount-amountErr").html("Discount is greater than sub total!");
|
$("#discount-amountErr").html("Discount is greater than sub total!");
|
||||||
}
|
}
|
||||||
@@ -886,7 +893,7 @@ function item_row_template(type, item, discount_amount, amount){
|
|||||||
if(type == 1){
|
if(type == 1){
|
||||||
dis_str = dis_str + "(" + amount + "%)"
|
dis_str = dis_str + "(" + amount + "%)"
|
||||||
}
|
}
|
||||||
var discount_item_row = "<tr class='discount-item-row' id='" + item.id + "'>" +
|
var discount_item_row = "<tr class='item-row new-discount' id='" + item.id + "'>" +
|
||||||
"<td style='width: 60%; text-align: left;'>" +
|
"<td style='width: 60%; text-align: left;'>" +
|
||||||
"<span id='item_account_type' class='hidden'>" +
|
"<span id='item_account_type' class='hidden'>" +
|
||||||
item.account_id +
|
item.account_id +
|
||||||
|
|||||||
@@ -81,7 +81,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td><%= credit.cashier_name rescue '-' %></td>
|
<td><%= credit.cashier_name rescue '-' %></td>
|
||||||
<td><%= credit.sale.customer.name rescue '-' %></td>
|
<td><%= credit.customer_name rescue '-' %></td>
|
||||||
<td><%= number_with_precision(credit.payment_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
<td><%= number_with_precision(credit.payment_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
||||||
<td>
|
<td>
|
||||||
<%if credit.credit_payment_shift_name == '-' %>
|
<%if credit.credit_payment_shift_name == '-' %>
|
||||||
|
|||||||
@@ -53,7 +53,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td><%= credit.cashier_name rescue '-' %></td>
|
<td><%= credit.cashier_name rescue '-' %></td>
|
||||||
<td><%= credit.sale.customer.name rescue '-' %></td>
|
<td><%= credit.customer_name rescue '-' %></td>
|
||||||
<td><%= credit.payment_amount rescue '-' %></td>
|
<td><%= credit.payment_amount rescue '-' %></td>
|
||||||
<td>
|
<td>
|
||||||
<%if credit.credit_payment_shift_name == '-' %>
|
<%if credit.credit_payment_shift_name == '-' %>
|
||||||
|
|||||||
@@ -138,8 +138,7 @@
|
|||||||
delimiter = ""
|
delimiter = ""
|
||||||
end
|
end
|
||||||
%>
|
%>
|
||||||
<% unless @sale_data.empty? %>
|
<% unless @sale_data.blank? %>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<% void = 0 %>
|
<% void = 0 %>
|
||||||
<% mpu = 0 %>
|
<% mpu = 0 %>
|
||||||
@@ -322,7 +321,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<% total_tax = 0 %>
|
<% total_tax = 0 %>
|
||||||
<% net = 0 %>
|
<% net = 0 %>
|
||||||
<% unless @tax.empty? %>
|
<% unless @tax.blank? %>
|
||||||
<% @tax.each do |tax|
|
<% @tax.each do |tax|
|
||||||
total_tax += tax.tax_amount.to_f %>
|
total_tax += tax.tax_amount.to_f %>
|
||||||
<tr style="font-weight:600;">
|
<tr style="font-weight:600;">
|
||||||
|
|||||||
@@ -76,7 +76,7 @@
|
|||||||
delimiter = ""
|
delimiter = ""
|
||||||
end
|
end
|
||||||
%>
|
%>
|
||||||
<% unless @sale_data.empty? %>
|
<% unless @sale_data.blank? %>
|
||||||
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<% void = 0 %>
|
<% void = 0 %>
|
||||||
@@ -235,7 +235,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<% total_tax = 0 %>
|
<% total_tax = 0 %>
|
||||||
<% net = 0 %>
|
<% net = 0 %>
|
||||||
<% unless @tax.empty? %>
|
<% unless @tax.blank? %>
|
||||||
<% @tax.each do |tax|
|
<% @tax.each do |tax|
|
||||||
total_tax += tax.tax_amount.to_f %>
|
total_tax += tax.tax_amount.to_f %>
|
||||||
<tr style="font-weight:600;">
|
<tr style="font-weight:600;">
|
||||||
|
|||||||
@@ -98,8 +98,8 @@
|
|||||||
<%if !@sale_data.nil? %>
|
<%if !@sale_data.nil? %>
|
||||||
<% @sale_data.each do |result| %>
|
<% @sale_data.each do |result| %>
|
||||||
|
|
||||||
<% grand_total +=result.grand_total.to_f %>
|
<% grand_total += result.grand_total.to_f %>
|
||||||
<% old_grand_total += result.grand_total_after_rounding() %>
|
<% old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f %>
|
||||||
<% total_tax += result.total_tax.to_f %>
|
<% total_tax += result.total_tax.to_f %>
|
||||||
<% total_sum += result.total_amount.to_f %>
|
<% total_sum += result.total_amount.to_f %>
|
||||||
<% discount_amt += result.total_discount.to_f %>
|
<% discount_amt += result.total_discount.to_f %>
|
||||||
@@ -124,50 +124,35 @@
|
|||||||
</td>
|
</td>
|
||||||
<td><%= result.receipt_no rescue '-' %> </td>
|
<td><%= result.receipt_no rescue '-' %> </td>
|
||||||
<td><%= result.cashier_name rescue '-' %></td>
|
<td><%= result.cashier_name rescue '-' %></td>
|
||||||
<td><%= number_with_precision(result.total_amount, precision: precision.to_i ,delimiter: delimiter) %></td>
|
<td><%= number_with_precision(result.total_amount, precision: precision.to_i, delimiter: delimiter) %></td>
|
||||||
<td><%= number_with_precision(result.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue '0' %>
|
<td><%= number_with_precision(result.total_discount, precision: precision.to_i, delimiter: delimiter) rescue '0' %>
|
||||||
</td>
|
</td>
|
||||||
<!-- <%if result.customer.customer_type == "Takeaway"%>
|
|
||||||
<td><%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %></td>
|
|
||||||
<%end%> -->
|
|
||||||
<% if !result.sale_taxes.empty? %>
|
<% if !result.sale_taxes.empty? %>
|
||||||
<% num = 1
|
<% num = 1 %>
|
||||||
if tax_flag && tax_count > 0 %>
|
<% if tax_flag && tax_count > 0 %>
|
||||||
<% while num <= tax_count %>
|
<% while num <= tax_count %>
|
||||||
<td>
|
<td><%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
|
<% num += 1 %>
|
||||||
</td>
|
<% end %>
|
||||||
<% num += 1
|
<% end %>
|
||||||
end %>
|
<% result.sale_taxes.each do |tax| %>
|
||||||
<% end %>
|
<td><%= number_with_precision(tax.tax_payable_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<% result.sale_taxes.each do |tax| %>
|
<%end%>
|
||||||
<td>
|
<% num = 1 %>
|
||||||
<%= number_with_precision(tax.tax_payable_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %>
|
<% if !tax_flag && tax_count > 0 %>
|
||||||
</td>
|
<% while num <= tax_count %>
|
||||||
<%end%>
|
<td><%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<% num = 1
|
<% num += 1 %>
|
||||||
if tax_flag==false && tax_count > 0 %>
|
<% end %>
|
||||||
<% while num <= tax_count %>
|
<% end %>
|
||||||
<td>
|
<% else %>
|
||||||
<%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
|
<% @tax_profiles.each do |tax| %>
|
||||||
</td>
|
<td><%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<% num += 1
|
<% end %>
|
||||||
end %>
|
<%end%>
|
||||||
<% end %>
|
<td><%= number_with_precision(result.grand_total - result.rounding_adjustment, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<% else %>
|
<td><%= number_with_precision(result.rounding_adjustment.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<% @tax_profiles.each do |tax| %>
|
<td><%= number_with_precision(result.grand_total, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<td><%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
|
||||||
<% end %>
|
|
||||||
<%end%>
|
|
||||||
|
|
||||||
<% if result.old_grand_total.nil? %>
|
|
||||||
<td><%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
|
||||||
<%else%>
|
|
||||||
<td><%= number_with_precision(result.old_grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
|
||||||
<%end%>
|
|
||||||
|
|
||||||
<td><%= result.rounding_adjustment.to_f rescue '-' %></td>
|
|
||||||
<td><%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) %></td>
|
|
||||||
<% if @lookup.value.to_i == 1 %>
|
<% if @lookup.value.to_i == 1 %>
|
||||||
<td>
|
<td>
|
||||||
<!-- ############### Need to Check SyncStatus ############# -->
|
<!-- ############### Need to Check SyncStatus ############# -->
|
||||||
@@ -185,54 +170,34 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<tr style="border-top:4px double #666;">
|
<tr style="border-top:4px double #666;">
|
||||||
<td colspan="3"> </td>
|
<td colspan="3"> </td>
|
||||||
<td><b><%= number_with_precision(total_sum, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></b></td>
|
<td><b><%= number_with_precision(total_sum, precision: precision.to_i, delimiter: delimiter) rescue '-' %></b></td>
|
||||||
<td><b><%= number_with_precision(discount_amt, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></b></td>
|
<td><b><%= number_with_precision(discount_amt, precision: precision.to_i, delimiter: delimiter) rescue '-' %></b></td>
|
||||||
<!-- <% if !@sale_taxes.empty?
|
|
||||||
@sale_taxes.each do |tax| %>
|
|
||||||
<td>
|
|
||||||
<b><%= number_with_precision(tax.st_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></b>
|
|
||||||
</td>
|
|
||||||
<% end %>
|
|
||||||
<% else %>
|
|
||||||
<% @tax_profiles.each do |tax| %>
|
|
||||||
<td><b>0</b></td>
|
|
||||||
<% end %>
|
|
||||||
<% end %> -->
|
|
||||||
|
|
||||||
<% if !@sale_taxes.empty? %>
|
<% if !@sale_taxes.empty? %>
|
||||||
<% num = 1
|
<% num = 1
|
||||||
if ttax_flag && ttax_count > 0 %>
|
if ttax_flag && ttax_count > 0 %>
|
||||||
<% while num <= ttax_count %>
|
<% while num <= ttax_count %>
|
||||||
<td>
|
<td><%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) %></td>
|
||||||
<%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
|
|
||||||
</td>
|
|
||||||
<% num += 1
|
<% num += 1
|
||||||
end %>
|
end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% @sale_taxes.each do |tax| %>
|
<% @sale_taxes.each do |tax| %>
|
||||||
<td>
|
<td><%= number_with_precision(tax.st_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<%= number_with_precision(tax.st_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %>
|
|
||||||
</td>
|
|
||||||
<%end%>
|
<%end%>
|
||||||
<% num = 1
|
<% num = 1
|
||||||
if ttax_flag==false && ttax_count > 0 %>
|
if ttax_flag==false && ttax_count > 0 %>
|
||||||
<% while num <= ttax_count %>
|
<% while num <= ttax_count %>
|
||||||
<td>
|
<td><%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) %></td>
|
||||||
<%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
|
|
||||||
</td>
|
|
||||||
<% num += 1
|
<% num += 1
|
||||||
end %>
|
end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<% @tax_profiles.each do |tax| %>
|
<% @tax_profiles.each do |tax| %>
|
||||||
<td><%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
<td><%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%end%>
|
<%end%>
|
||||||
|
<td><b><%= number_with_precision(old_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '0' %></b></td>
|
||||||
<td><b><%= number_with_precision(old_grand_total.to_f, precision: precision.to_i ,delimiter: delimiter) rescue '0' %></b></td>
|
<td><b><%= number_with_precision(rounding_adj.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %></b></td>
|
||||||
|
<td><b><%= number_with_precision(grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %></b></td>
|
||||||
<td><b><%= rounding_adj.to_f rescue '-' %></b></td>
|
|
||||||
<td><b><%= number_with_precision(grand_total.to_f, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></b></td>
|
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %></th>
|
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %></th>
|
||||||
<th><%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> </th>
|
<th><%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> </th>
|
||||||
<% @tax_profiles.each do |tax| %>
|
<% @tax_profiles.each do |tax| %>
|
||||||
<th><%= tax.name %></th>
|
<th><%= tax.name %></th>
|
||||||
<% end %>
|
<% end %>
|
||||||
<!-- <th>Other Amount</th> -->
|
<!-- <th>Other Amount</th> -->
|
||||||
<th><%= t("views.right_panel.detail.grand_total") %></th>
|
<th><%= t("views.right_panel.detail.grand_total") %></th>
|
||||||
@@ -74,11 +74,11 @@
|
|||||||
end
|
end
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%if !@sale_data.nil? %>
|
<%if @sale_data %>
|
||||||
<% @sale_data.each do |result| %>
|
<% @sale_data.each do |result| %>
|
||||||
|
|
||||||
<% grand_total +=result.grand_total.to_f %>
|
<% grand_total += result.grand_total.to_f %>
|
||||||
<% old_grand_total += result.grand_total_after_rounding() %>
|
<% old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f %>
|
||||||
<% total_tax += result.total_tax.to_f %>
|
<% total_tax += result.total_tax.to_f %>
|
||||||
<% total_sum += result.total_amount.to_f %>
|
<% total_sum += result.total_amount.to_f %>
|
||||||
<% discount_amt += result.total_discount.to_f %>
|
<% discount_amt += result.total_discount.to_f %>
|
||||||
@@ -91,59 +91,45 @@
|
|||||||
tax_flag = false
|
tax_flag = false
|
||||||
end
|
end
|
||||||
end %>
|
end %>
|
||||||
|
<tr>
|
||||||
<tr>
|
<td>
|
||||||
<td>
|
<%if result.type %>
|
||||||
<%if result.type %>
|
<%= result.type %> - <%= result.name %>
|
||||||
<%= result.type %> - <%= result.name %>
|
<% else %>
|
||||||
<% else %>
|
-
|
||||||
-
|
<% end %>
|
||||||
<% end %>
|
</td>
|
||||||
</td>
|
<td><%= result.receipt_no rescue '-' %> </td>
|
||||||
<td><%= result.receipt_no rescue '-' %> </td>
|
<td><%= result.cashier_name rescue '-' %></td>
|
||||||
<td><%= result.cashier_name rescue '-' %></td>
|
<td><%= number_with_precision(result.total_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<td><%= number_with_precision(result.total_amount, precision: precision.to_i ,delimiter: delimiter) %></td>
|
<td><%= number_with_precision(result.total_discount, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<td><%= number_with_precision(result.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue '0' %>
|
<% if !result.sale_taxes.empty? %>
|
||||||
</td>
|
<% num = 1 %>
|
||||||
<% if !result.sale_taxes.empty? %>
|
<% if tax_flag && tax_count > 0 %>
|
||||||
<% num = 1
|
<% while num <= tax_count %>
|
||||||
if tax_flag && tax_count > 0 %>
|
<td><%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<% while num <= tax_count %>
|
<% num += 1 %>
|
||||||
<td>
|
<% end %>
|
||||||
<%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
|
|
||||||
</td>
|
|
||||||
<% num += 1
|
|
||||||
end %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% result.sale_taxes.each do |tax| %>
|
<% result.sale_taxes.each do |tax| %>
|
||||||
<td>
|
<td><%= number_with_precision(tax.tax_payable_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
||||||
<%= number_with_precision(tax.tax_payable_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %>
|
<% end %>
|
||||||
</td>
|
<% num = 1
|
||||||
<%end%>
|
if tax_flag==false && tax_count > 0 %>
|
||||||
<% num = 1
|
<% while num <= tax_count %>
|
||||||
if tax_flag==false && tax_count > 0 %>
|
<td><%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<% while num <= tax_count %>
|
<% num += 1
|
||||||
<td>
|
end %>
|
||||||
<%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
|
|
||||||
</td>
|
|
||||||
<% num += 1
|
|
||||||
end %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<% @tax_profiles.each do |tax| %>
|
<% @tax_profiles.each do |tax| %>
|
||||||
<td><%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
<td><%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%end%>
|
<%end%>
|
||||||
|
<td><%= number_with_precision(result.grand_total - result.rounding_adjustment, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<% if result.old_grand_total.nil? %>
|
<td><%= number_with_precision(result.rounding_adjustment.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<td><%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
<td><%= number_with_precision(result.grand_total, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<%else%>
|
</tr>
|
||||||
<td><%= number_with_precision(result.old_grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
|
||||||
<%end%>
|
|
||||||
|
|
||||||
<td><%= result.rounding_adjustment.to_f rescue '-' %></td>
|
|
||||||
<td><%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) %></td>
|
|
||||||
</tr>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
<tr style="border-top:4px double #666;">
|
<tr style="border-top:4px double #666;">
|
||||||
<td colspan="3"> </td>
|
<td colspan="3"> </td>
|
||||||
@@ -153,23 +139,17 @@
|
|||||||
<% num = 1
|
<% num = 1
|
||||||
if ttax_flag && ttax_count > 0 %>
|
if ttax_flag && ttax_count > 0 %>
|
||||||
<% while num <= ttax_count %>
|
<% while num <= ttax_count %>
|
||||||
<td>
|
<td><%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
|
|
||||||
</td>
|
|
||||||
<% num += 1
|
<% num += 1
|
||||||
end %>
|
end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% @sale_taxes.each do |tax| %>
|
<% @sale_taxes.each do |tax| %>
|
||||||
<td>
|
<td><%= number_with_precision(tax.st_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
||||||
<%= number_with_precision(tax.st_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %>
|
|
||||||
</td>
|
|
||||||
<%end%>
|
<%end%>
|
||||||
<% num = 1
|
<% num = 1
|
||||||
if ttax_flag==false && ttax_count > 0 %>
|
if ttax_flag==false && ttax_count > 0 %>
|
||||||
<% while num <= ttax_count %>
|
<% while num <= ttax_count %>
|
||||||
<td>
|
<td><%= number_with_precision(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %></td>
|
||||||
<%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
|
|
||||||
</td>
|
|
||||||
<% num += 1
|
<% num += 1
|
||||||
end %>
|
end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -178,12 +158,9 @@
|
|||||||
<td><%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
<td><%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%end%>
|
<%end%>
|
||||||
|
<td><b><%= number_with_precision(old_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '0' %></b></td>
|
||||||
<td><b><%= number_with_precision(old_grand_total.to_f, precision: precision.to_i ,delimiter: delimiter) rescue '0' %></b></td>
|
<td><b><%= number_with_precision(rounding_adj.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %></b></td>
|
||||||
|
<td><b><%= number_with_precision(grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %></b></td>
|
||||||
<td><b><%= rounding_adj.to_f rescue '-' %></b></td>
|
|
||||||
<td><b><%= number_with_precision(grand_total.to_f, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></b></td>
|
|
||||||
<td></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3"> </td>
|
<td colspan="3"> </td>
|
||||||
|
|||||||
@@ -114,4 +114,3 @@
|
|||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
100
config/deploy.rb
100
config/deploy.rb
@@ -1,20 +1,106 @@
|
|||||||
lock "3.10.1"
|
# config valid only for current version of Capistrano
|
||||||
|
lock '3.11.2'
|
||||||
|
|
||||||
set :application, "zsai"
|
set :application, 'SmartsalesSX'
|
||||||
set :repo_url, 'git@bitbucket.org:code2lab/sxrestaurant.git'
|
|
||||||
|
|
||||||
set :deploy_user, 'deploy'
|
set :deploy_user, 'deploy'
|
||||||
|
set :deploy_to, '/home/deploy/apps/SmartsalesSX'
|
||||||
|
|
||||||
set :rbenv_type, :global
|
# setup repo details
|
||||||
|
#set :scm, :git
|
||||||
|
set :repo_url, 'git@gitlab.com:code2lab/SXRestaurant.git'
|
||||||
|
|
||||||
|
# setup rbenv.
|
||||||
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
|
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
|
||||||
|
|
||||||
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
|
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
|
||||||
|
|
||||||
|
# how many old releases do we want to keep, not much
|
||||||
set :keep_releases, 5
|
set :keep_releases, 5
|
||||||
|
|
||||||
set :linked_files, %w{config/database.yml config/secrets.yml config/puma.rb config/sidekiq.yml config/shops.json config/cable.yml}
|
# files we want symlinking to specific entries in shared
|
||||||
|
set :linked_files, %w{config/database.yml config/secrets.yml}
|
||||||
|
|
||||||
set :linked_dirs, %w{bin log tmp/puma tmp/pids tmp/cache tmp/sockets vendor/bundle public/system pids sockets}
|
# dirs we want symlinking to shared
|
||||||
|
set :linked_dirs, %w{log tmp/pids tmp/puma tmp/cache tmp/sockets vendor/bundle public/system}
|
||||||
|
|
||||||
|
# what specs should be run before deployment is allowed to
|
||||||
|
# continue, see lib/capistrano/tasks/run_tests.cap
|
||||||
set :tests, []
|
set :tests, []
|
||||||
set :pty, true
|
set :pty, true
|
||||||
|
|
||||||
|
set :puma_jungle_conf, '/etc/puma.conf'
|
||||||
|
set :puma_run_path, '/usr/local/bin/run-puma'
|
||||||
|
set :puma_bind, %w(tcp://0.0.0.0:9393)
|
||||||
|
|
||||||
|
#set :enable_ssl, true
|
||||||
|
|
||||||
|
# which config files should be copied by deploy:setup_config
|
||||||
|
# see documentation in lib/capistrano/tasks/setup_config.cap
|
||||||
|
# for details of operations
|
||||||
|
set(:config_files, %w(
|
||||||
|
database.yml
|
||||||
|
log_rotation
|
||||||
|
monit.conf
|
||||||
|
sidekiq_init.sh
|
||||||
|
sidekiq.yml
|
||||||
|
))
|
||||||
|
|
||||||
|
# which config files should be made executable after copying
|
||||||
|
# by deploy:setup_config
|
||||||
|
set(:executable_config_files, %w(
|
||||||
|
sidekiq_init.sh
|
||||||
|
))
|
||||||
|
|
||||||
|
# files which need to be symlinked to other parts of the
|
||||||
|
# filesystem. For example nginx virtualhosts, log rotation
|
||||||
|
# init scripts etc. The full_app_name variable isn't
|
||||||
|
# available at this point so we use a custom template {{}}
|
||||||
|
# tag and then add it at run time.
|
||||||
|
set(:symlinks, [
|
||||||
|
{
|
||||||
|
source: "sidekiq_init.sh",
|
||||||
|
link: "/etc/init.d/sidekiq_{{full_app_name}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "log_rotation",
|
||||||
|
link: "/etc/logrotate.d/{{full_app_name}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "monit",
|
||||||
|
link: "/etc/monit/conf.d/{{full_app_name}}.conf"
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
# this:
|
||||||
|
# http://www.capistranorb.com/documentation/getting-started/flow/
|
||||||
|
# is worth reading for a quick overview of what tasks are called
|
||||||
|
# and when for `cap stage deploy`
|
||||||
|
|
||||||
|
namespace :deploy do
|
||||||
|
# make sure we're deploying what we think we're deploying
|
||||||
|
before :deploy, "deploy:check_revision"
|
||||||
|
# only allow a deploy with passing tests to deployed
|
||||||
|
before :deploy, "deploy:run_tests"
|
||||||
|
# compile assets locally then rsync
|
||||||
|
after 'deploy:symlink:shared', 'deploy:compile_assets_locally'
|
||||||
|
Rake::Task["deploy:assets:precompile"].clear_actions
|
||||||
|
|
||||||
|
after :finishing, 'deploy:cleanup'
|
||||||
|
|
||||||
|
#nginx will be install in the Load Balancer - No need to deploy there
|
||||||
|
# remove the default nginx configuration as it will tend
|
||||||
|
# to conflict with our configs.
|
||||||
|
#before 'deploy:setup_config', 'nginx:remove_default_vhost'
|
||||||
|
|
||||||
|
# reload nginx to it will pick up any modified vhosts from
|
||||||
|
# setup_config
|
||||||
|
#after 'deploy:setup_config', 'nginx:reload'
|
||||||
|
|
||||||
|
# Restart monit so it will pick up any monit configurations
|
||||||
|
# we've added
|
||||||
|
#after 'deploy:setup_config', 'monit:restart'
|
||||||
|
|
||||||
|
# As of Capistrano 3.1, the `deploy:restart` task is not called
|
||||||
|
# automatically.
|
||||||
|
after 'finishing', 'puma:jungle:restart'
|
||||||
|
end
|
||||||
|
|||||||
@@ -9,13 +9,12 @@
|
|||||||
# set :rails_env, :production
|
# set :rails_env, :production
|
||||||
|
|
||||||
set :stage, :production
|
set :stage, :production
|
||||||
set :server_name, "svr.sxrestaurant.host"
|
set :server_name, "a.c2l.shop"
|
||||||
|
set :branch, "r-1902001-01"
|
||||||
|
|
||||||
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
|
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
|
||||||
|
server '167.71.194.57', user: 'deploy', roles: %w{web app db}, primary: true
|
||||||
server '52.77.219.228', user: 'deploy', roles: %w{web app db}, primary: true
|
|
||||||
|
|
||||||
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"
|
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"
|
||||||
set :rbenv_ruby, '2.4.1'
|
set :rbenv_ruby, '2.6.5'
|
||||||
set :rails_env, :production
|
set :rails_env, :production
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ class ActionController::Base
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
# check for license file
|
# check for license file
|
||||||
if check_license
|
# if check_license
|
||||||
current_license(ENV["SX_PROVISION_URL"])
|
# current_license(ENV["SX_PROVISION_URL"])
|
||||||
else
|
# else
|
||||||
redirect_to activate_path
|
# redirect_to activate_path
|
||||||
end
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
application_path="#{File.expand_path("../..", __FILE__)}"
|
# application_path="#{File.expand_path("../..", __FILE__)}"
|
||||||
directory application_path
|
# directory application_path
|
||||||
#environment ENV.fetch("RAILS_ENV") { "production" }
|
# #environment ENV.fetch("RAILS_ENV") { "production" }
|
||||||
environment "production"
|
# environment "production"
|
||||||
pidfile "#{application_path}/tmp/puma/pid"
|
# pidfile "#{application_path}/tmp/puma/pid"
|
||||||
state_path "#{application_path}/tmp/puma/state"
|
# state_path "#{application_path}/tmp/puma/state"
|
||||||
stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
|
# stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
|
||||||
port ENV.fetch("PORT") { 62158 }
|
# port ENV.fetch("PORT") { 62158 }
|
||||||
workers 2
|
# workers 2
|
||||||
preload_app!
|
# preload_app!
|
||||||
threads 1,1
|
# threads 1,1
|
||||||
|
|||||||
@@ -117,6 +117,14 @@ scope "(:locale)", locale: /en|mm/ do
|
|||||||
|
|
||||||
#API for sync cloud
|
#API for sync cloud
|
||||||
post 'sync_data' => 'sync#sync_data'
|
post 'sync_data' => 'sync#sync_data'
|
||||||
|
|
||||||
|
namespace :loader_service do
|
||||||
|
post "get_sale_data" => "load_data#get_sale_data_rage"
|
||||||
|
post "get_detail_sale_data" => "load_data#get_detail_sale_data"
|
||||||
|
post "get_tender_sale_data" => "load_data#get_tender_sale_data"
|
||||||
|
post "get_daily_sale_data" => "load_data#get_daily_sale_data"
|
||||||
|
post "get_check_sale_data" => "load_data#get_check_sale_data"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#--------- Cashier ------------#
|
#--------- Cashier ------------#
|
||||||
|
|||||||
12
lib/capistrano/substitute_strings.rb
Normal file
12
lib/capistrano/substitute_strings.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# we often want to refer to variables which
|
||||||
|
# are defined in subsequent stage files. This
|
||||||
|
# let's us use the {{var}} to represent fetch(:var)
|
||||||
|
# in strings which are only evaluated at runtime.
|
||||||
|
|
||||||
|
def sub_strings(input_string)
|
||||||
|
output_string = input_string
|
||||||
|
input_string.scan(/{{(\w*)}}/).each do |var|
|
||||||
|
output_string.gsub!("{{#{var[0]}}}", fetch(var[0].to_sym))
|
||||||
|
end
|
||||||
|
output_string
|
||||||
|
end
|
||||||
14
lib/capistrano/tasks/check_revision.cap
Normal file
14
lib/capistrano/tasks/check_revision.cap
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace :deploy do
|
||||||
|
desc "checks whether the currently checkout out revision matches the
|
||||||
|
remote one we're trying to deploy from"
|
||||||
|
task :check_revision do
|
||||||
|
branch = fetch(:branch)
|
||||||
|
unless `git rev-parse HEAD` == `git rev-parse #{branch}`
|
||||||
|
puts "WARNING: HEAD is not the same as #{branch}"
|
||||||
|
puts "Run `git push` to sync changes or make sure you've"
|
||||||
|
puts "checked out the branch: #{branch} as you can only deploy"
|
||||||
|
puts "if you've got the target branch checked out"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
17
lib/capistrano/tasks/compile_assets_locally.cap
Normal file
17
lib/capistrano/tasks/compile_assets_locally.cap
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
namespace :deploy do
|
||||||
|
desc "compiles assets locally then rsyncs"
|
||||||
|
task :compile_assets_locally do
|
||||||
|
run_locally do
|
||||||
|
execute "RAILS_ENV=#{fetch(:rails_env)} bundle exec rake assets:precompile"
|
||||||
|
end
|
||||||
|
on roles(:app) do |role|
|
||||||
|
run_locally do
|
||||||
|
execute"rsync -av ./public/assets/ #{role.user}@#{role.hostname}:#{release_path}/public/assets/;"
|
||||||
|
end
|
||||||
|
sudo "chmod -R 755 #{release_path}/public/assets/"
|
||||||
|
end
|
||||||
|
run_locally do
|
||||||
|
execute "rm -rf ./public/assets"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
14
lib/capistrano/tasks/logs.cap
Normal file
14
lib/capistrano/tasks/logs.cap
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace :logs do
|
||||||
|
task :tail, :file do |t, args|
|
||||||
|
if args[:file]
|
||||||
|
on roles(:app) do
|
||||||
|
execute "tail -f #{shared_path}/log/#{args[:file]}.log"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "please specify a logfile e.g: 'rake logs:tail[logfile]"
|
||||||
|
puts "will tail 'shared_path/log/logfile.log'"
|
||||||
|
puts "remember if you use zsh you'll need to format it as:"
|
||||||
|
puts "rake 'logs:tail[logfile]' (single quotes)"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
10
lib/capistrano/tasks/monit.cap
Normal file
10
lib/capistrano/tasks/monit.cap
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace :monit do
|
||||||
|
%w(start stop restart).each do |task_name|
|
||||||
|
desc "#{task_name} Monit"
|
||||||
|
task task_name do
|
||||||
|
on roles(:app), in: :sequence, wait: 5 do
|
||||||
|
sudo "service monit #{task_name}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
22
lib/capistrano/tasks/nginx.cap
Normal file
22
lib/capistrano/tasks/nginx.cap
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
namespace :nginx do
|
||||||
|
%w(start stop restart reload).each do |task_name|
|
||||||
|
desc "#{task } Nginx"
|
||||||
|
task task_name do
|
||||||
|
on roles(:app), in: :sequence, wait: 5 do
|
||||||
|
sudo "/etc/init.d/nginx #{task_name}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Remove default Nginx Virtual Host"
|
||||||
|
task "remove_default_vhost" do
|
||||||
|
on roles(:app) do
|
||||||
|
if test("[ -f /etc/nginx/sites-enabled/default ]")
|
||||||
|
sudo "rm /etc/nginx/sites-enabled/default"
|
||||||
|
puts "removed default Nginx Virtualhost"
|
||||||
|
else
|
||||||
|
puts "No default Nginx Virtualhost to remove"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
10
lib/capistrano/tasks/restart.cap
Normal file
10
lib/capistrano/tasks/restart.cap
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace :deploy do
|
||||||
|
desc 'Commands for unicorn application'
|
||||||
|
%w(start stop force-stop restart upgrade reopen-logs).each do |command|
|
||||||
|
task command.to_sym do
|
||||||
|
on roles(:app), in: :sequence, wait: 5 do
|
||||||
|
sudo "/etc/init.d/unicorn_#{fetch(:full_app_name)} #{command}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
18
lib/capistrano/tasks/run_tests.cap
Normal file
18
lib/capistrano/tasks/run_tests.cap
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace :deploy do
|
||||||
|
desc "Runs test before deploying, can't deploy unless they pass"
|
||||||
|
task :run_tests do
|
||||||
|
test_log = "log/capistrano.test.log"
|
||||||
|
tests = fetch(:tests)
|
||||||
|
tests.each do |test|
|
||||||
|
puts "--> Running tests: '#{test}', please wait ..."
|
||||||
|
unless system "bundle exec rspec #{test} > #{test_log} 2>&1"
|
||||||
|
puts "--> Tests: '#{test}' failed. Results in: #{test_log} and below:"
|
||||||
|
system "cat #{test_log}"
|
||||||
|
exit;
|
||||||
|
end
|
||||||
|
puts "--> '#{test}' passed"
|
||||||
|
end
|
||||||
|
puts "--> All tests passed"
|
||||||
|
system "rm #{test_log}"
|
||||||
|
end
|
||||||
|
end
|
||||||
33
lib/capistrano/tasks/setup_config.cap
Normal file
33
lib/capistrano/tasks/setup_config.cap
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
namespace :deploy do
|
||||||
|
task :setup_config do
|
||||||
|
on roles(:app) do
|
||||||
|
# make the config dir
|
||||||
|
execute :mkdir, "-p #{shared_path}/config"
|
||||||
|
full_app_name = fetch(:full_app_name)
|
||||||
|
|
||||||
|
# config files to be uploaded to shared/config, see the
|
||||||
|
# definition of smart_template for details of operation.
|
||||||
|
# Essentially looks for #{filename}.erb in deploy/#{full_app_name}/
|
||||||
|
# and if it isn't there, falls back to deploy/#{shared}. Generally
|
||||||
|
# everything should be in deploy/shared with params which differ
|
||||||
|
# set in the stage files
|
||||||
|
config_files = fetch(:config_files)
|
||||||
|
config_files.each do |file|
|
||||||
|
smart_template file
|
||||||
|
end
|
||||||
|
|
||||||
|
# which of the above files should be marked as executable
|
||||||
|
executable_files = fetch(:executable_config_files)
|
||||||
|
executable_files.each do |file|
|
||||||
|
execute :chmod, "+x #{shared_path}/config/#{file}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# symlink stuff which should be... symlinked
|
||||||
|
symlinks = fetch(:symlinks)
|
||||||
|
|
||||||
|
symlinks.each do |symlink|
|
||||||
|
sudo "ln -nfs #{shared_path}/config/#{symlink[:source]} #{sub_strings(symlink[:link])}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
32
lib/capistrano/template.rb
Normal file
32
lib/capistrano/template.rb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# will first try and copy the file:
|
||||||
|
# config/deploy/#{full_app_name}/#{from}.erb
|
||||||
|
# to:
|
||||||
|
# shared/config/to
|
||||||
|
# if the original source path doesn exist then it will
|
||||||
|
# search in:
|
||||||
|
# config/deploy/shared/#{from}.erb
|
||||||
|
# this allows files which are common to all enviros to
|
||||||
|
# come from a single source while allowing specific
|
||||||
|
# ones to be over-ridden
|
||||||
|
# if the target file name is the same as the source then
|
||||||
|
# the second parameter can be left out
|
||||||
|
def smart_template(from, to=nil)
|
||||||
|
to ||= from
|
||||||
|
full_to_path = "#{shared_path}/config/#{to}"
|
||||||
|
if from_erb_path = template_file(from)
|
||||||
|
from_erb = StringIO.new(ERB.new(File.read(from_erb_path)).result(binding))
|
||||||
|
upload! from_erb, full_to_path
|
||||||
|
info "copying: #{from_erb} to: #{full_to_path}"
|
||||||
|
else
|
||||||
|
error "error #{from} not found"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def template_file(name)
|
||||||
|
if File.exist?((file = "config/deploy/#{fetch(:full_app_name)}/#{name}.erb"))
|
||||||
|
return file
|
||||||
|
elsif File.exist?((file = "config/deploy/shared/#{name}.erb"))
|
||||||
|
return file
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user