From 2d5ae6da930509db39556fd552483a733c9199ce Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Fri, 4 Oct 2019 18:20:14 +0630 Subject: [PATCH 01/23] fixed split bill --- app/controllers/origami/split_bill_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index 3db5ce94..fb6db35f 100755 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -333,7 +333,7 @@ class Origami::SplitBillController < BaseOrigamiController end end - Promotion.promo_activate(sale) + Promotion.promo_activate(sale_data) if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain else From e2790c1b3b1a757707c57a61cd7b65f7ea70950a Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 16 Oct 2019 10:33:19 +0630 Subject: [PATCH 02/23] get update --- Gemfile | 2 +- Gemfile.lock | 27 ++++++++++++------------ app/controllers/api/api_controller.rb | 2 +- app/models/order_reservation.rb | 2 +- config/initializers/action_controller.rb | 10 ++++----- config/puma.rb | 22 +++++++++---------- 6 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Gemfile b/Gemfile index 66c149ef..1a15a61a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.4.1' +ruby '2.3.1' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" diff --git a/Gemfile.lock b/Gemfile.lock index 01c505f6..84791b6b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,7 +62,7 @@ GEM builder (3.2.3) byebug (11.0.1) cancancan (1.17.0) - capistrano (3.11.1) + capistrano (3.11.2) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -99,7 +99,7 @@ GEM factory_girl_rails (4.9.0) factory_girl (~> 4.9.0) railties (>= 3.0.0) - faker (2.4.0) + faker (2.5.0) i18n (~> 1.6.0) ffi (1.11.1) filterrific (5.2.1) @@ -140,7 +140,7 @@ GEM listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - loofah (2.2.3) + loofah (2.3.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -154,7 +154,7 @@ GEM mini_magick (4.9.5) mini_mime (1.0.2) mini_portile2 (2.4.0) - minitest (5.12.0) + minitest (5.12.2) momentjs-rails (2.20.1) railties (>= 3.1) multi_xml (0.6.0) @@ -202,15 +202,15 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.2.0) - loofah (~> 2.2, >= 2.2.2) + rails-html-sanitizer (1.3.0) + loofah (~> 2.3) railties (5.1.7) actionpack (= 5.1.7) activesupport (= 5.1.7) method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (12.3.3) + rake (13.0.0) rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) @@ -225,10 +225,10 @@ GEM rqrcode_core (0.1.0) rspec-core (3.8.2) rspec-support (~> 3.8.0) - rspec-expectations (3.8.4) + rspec-expectations (3.8.5) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) - rspec-mocks (3.8.1) + rspec-mocks (3.8.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.8.0) rspec-rails (3.8.2) @@ -239,7 +239,7 @@ GEM rspec-expectations (~> 3.8.0) rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) - rspec-support (3.8.2) + rspec-support (3.8.3) ruby-ole (1.2.12.2) rubyzip (1.0.0) sass (3.7.4) @@ -262,12 +262,13 @@ GEM rack (>= 1.5.0) rack-protection (>= 1.5.0) redis (>= 3.3.5, < 5) - simple_form (4.1.0) + simple_form (5.0.1) actionpack (>= 5.0) activemodel (>= 5.0) spreadsheet (1.2.4) ruby-ole (>= 1.0) - spring (2.1.0) + spring (2.0.2) + activesupport (>= 4.2) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) @@ -370,7 +371,7 @@ DEPENDENCIES whenever RUBY VERSION - ruby 2.4.1p111 + ruby 2.3.1p112 BUNDLED WITH 2.0.2 diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index a5112ffe..ad38376a 100755 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -1,5 +1,5 @@ class Api::ApiController < ActionController::API - include TokenVerification + # include TokenVerification # before_action :lookup_domain helper_method :current_token, :current_login_employee, :get_cashier diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 0be86204..8de88ee2 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -75,7 +75,7 @@ class OrderReservation < ApplicationRecord order_reservation.discount_amount = order_reserve[:payment_info][:discount_amount] order_reservation.convenience_charge = order_reserve[:payment_info][:convenience_charge] order_reservation.grand_total = order_reserve[:payment_info][:grand_total] - order_reservation.transaction_fee = order_reserve[:payment_info][:transaction_fee] + # order_reservation.transaction_fee = order_reserve[:payment_info][:transaction_fee] order_reservation.order_remark = order_reserve[:order_info][:order_remark] end if order_reserve[:reservation_info] diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 205c330a..85f38ec5 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -21,11 +21,11 @@ class ActionController::Base end else # check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) - else - redirect_to activate_path - end + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end end end diff --git a/config/puma.rb b/config/puma.rb index d24425ae..f0013d25 100755 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,11 +1,11 @@ -application_path="#{File.expand_path("../..", __FILE__)}" -directory application_path -#environment ENV.fetch("RAILS_ENV") { "production" } -environment "production" -pidfile "#{application_path}/tmp/puma/pid" -state_path "#{application_path}/tmp/puma/state" -stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log" -port ENV.fetch("PORT") { 62158 } -workers 2 -preload_app! -threads 1,1 +# application_path="#{File.expand_path("../..", __FILE__)}" +# directory application_path +# #environment ENV.fetch("RAILS_ENV") { "production" } +# environment "production" +# pidfile "#{application_path}/tmp/puma/pid" +# state_path "#{application_path}/tmp/puma/state" +# stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log" +# port ENV.fetch("PORT") { 62158 } +# workers 2 +# preload_app! +# threads 1,1 From 565c0a5ec48a0e72bc7818f3c1469b75fe366579 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 23 Oct 2019 11:37:38 +0630 Subject: [PATCH 03/23] production --- Gemfile.lock | 2 +- config/deploy/production.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index a64de866..c0dd2cf8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,7 +62,7 @@ GEM builder (3.2.3) byebug (11.0.1) cancancan (1.17.0) - capistrano (3.11.2) + capistrano (3.10.1) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 8c23cfa6..23a6daf7 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -12,6 +12,7 @@ set :stage, :production set :server_name, "svr.sxrestaurant.host" set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}" + 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)}" From 1330422b6042dfd4238a5701f7dad20c3b54a7a3 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 23 Oct 2019 11:56:30 +0630 Subject: [PATCH 04/23] action controller --- config/initializers/action_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 845d363e..205c330a 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -20,7 +20,7 @@ class ActionController::Base end else - check for license file + # check for license file if check_license current_license(ENV["SX_PROVISION_URL"]) else From b025cc2cfd2b10df84cc1cee458efa4eef108752 Mon Sep 17 00:00:00 2001 From: Aung Ye Kyaw Date: Thu, 24 Oct 2019 05:40:56 +0000 Subject: [PATCH 05/23] Update Gemfile Ruby version change 2.3.1 to 2.4.1 (may be someone changed) --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 1a15a61a..66c149ef 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.3.1' +ruby '2.4.1' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" From 0be67f4f121a9a1e850a01cd1432676e4c3d3ff3 Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 12:33:21 +0630 Subject: [PATCH 06/23] SX cap production setup files --- lib/capistrano/substitute_strings.rb | 12 +++++++ lib/capistrano/tasks/check_revision.cap | 14 ++++++++ .../tasks/compile_assets_locally.cap | 17 ++++++++++ lib/capistrano/tasks/logs.cap | 14 ++++++++ lib/capistrano/tasks/monit.cap | 10 ++++++ lib/capistrano/tasks/nginx.cap | 22 +++++++++++++ lib/capistrano/tasks/restart.cap | 10 ++++++ lib/capistrano/tasks/run_tests.cap | 18 ++++++++++ lib/capistrano/tasks/setup_config.cap | 33 +++++++++++++++++++ lib/capistrano/template.rb | 32 ++++++++++++++++++ 10 files changed, 182 insertions(+) create mode 100644 lib/capistrano/substitute_strings.rb create mode 100644 lib/capistrano/tasks/check_revision.cap create mode 100644 lib/capistrano/tasks/compile_assets_locally.cap create mode 100644 lib/capistrano/tasks/logs.cap create mode 100644 lib/capistrano/tasks/monit.cap create mode 100644 lib/capistrano/tasks/nginx.cap create mode 100644 lib/capistrano/tasks/restart.cap create mode 100644 lib/capistrano/tasks/run_tests.cap create mode 100644 lib/capistrano/tasks/setup_config.cap create mode 100644 lib/capistrano/template.rb diff --git a/lib/capistrano/substitute_strings.rb b/lib/capistrano/substitute_strings.rb new file mode 100644 index 00000000..d4b24432 --- /dev/null +++ b/lib/capistrano/substitute_strings.rb @@ -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 diff --git a/lib/capistrano/tasks/check_revision.cap b/lib/capistrano/tasks/check_revision.cap new file mode 100644 index 00000000..72b4aa12 --- /dev/null +++ b/lib/capistrano/tasks/check_revision.cap @@ -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 diff --git a/lib/capistrano/tasks/compile_assets_locally.cap b/lib/capistrano/tasks/compile_assets_locally.cap new file mode 100644 index 00000000..e6264e81 --- /dev/null +++ b/lib/capistrano/tasks/compile_assets_locally.cap @@ -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 diff --git a/lib/capistrano/tasks/logs.cap b/lib/capistrano/tasks/logs.cap new file mode 100644 index 00000000..7bbfac2e --- /dev/null +++ b/lib/capistrano/tasks/logs.cap @@ -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 diff --git a/lib/capistrano/tasks/monit.cap b/lib/capistrano/tasks/monit.cap new file mode 100644 index 00000000..5dbac6a2 --- /dev/null +++ b/lib/capistrano/tasks/monit.cap @@ -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 diff --git a/lib/capistrano/tasks/nginx.cap b/lib/capistrano/tasks/nginx.cap new file mode 100644 index 00000000..dfadd5c6 --- /dev/null +++ b/lib/capistrano/tasks/nginx.cap @@ -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 diff --git a/lib/capistrano/tasks/restart.cap b/lib/capistrano/tasks/restart.cap new file mode 100644 index 00000000..ff8c028f --- /dev/null +++ b/lib/capistrano/tasks/restart.cap @@ -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 diff --git a/lib/capistrano/tasks/run_tests.cap b/lib/capistrano/tasks/run_tests.cap new file mode 100644 index 00000000..32f26f9c --- /dev/null +++ b/lib/capistrano/tasks/run_tests.cap @@ -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 diff --git a/lib/capistrano/tasks/setup_config.cap b/lib/capistrano/tasks/setup_config.cap new file mode 100644 index 00000000..81ce88d9 --- /dev/null +++ b/lib/capistrano/tasks/setup_config.cap @@ -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 diff --git a/lib/capistrano/template.rb b/lib/capistrano/template.rb new file mode 100644 index 00000000..07bd0be3 --- /dev/null +++ b/lib/capistrano/template.rb @@ -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 From bfc697376286b61049872eee350da51778b4cf27 Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 13:00:40 +0630 Subject: [PATCH 07/23] Gem lock update --- Gemfile.lock | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0db34edf..7928786c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,7 +62,7 @@ GEM builder (3.2.3) byebug (11.0.1) cancancan (1.17.0) - capistrano (3.10.1) + capistrano (3.11.2) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -72,15 +72,11 @@ GEM capistrano-rails (1.4.0) capistrano (~> 3.1) capistrano-bundler (~> 1.1) -<<<<<<< HEAD capistrano3-puma (3.1.1) capistrano (~> 3.7) capistrano-bundler puma (~> 3.4) - carrierwave (1.2.1) -======= carrierwave (1.3.1) ->>>>>>> b025cc2cfd2b10df84cc1cee458efa4eef108752 activemodel (>= 4.0.0) activesupport (>= 4.0.0) mime-types (>= 1.16) @@ -107,8 +103,8 @@ GEM factory_girl_rails (4.9.0) factory_girl (~> 4.9.0) railties (>= 3.0.0) - faker (2.5.0) - i18n (~> 1.6.0) + faker (2.6.0) + i18n (>= 1.6, < 1.8) ffi (1.11.1) filterrific (5.2.1) font-awesome-rails (4.7.0.5) @@ -148,7 +144,7 @@ GEM listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - loofah (2.3.0) + loofah (2.3.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -231,23 +227,23 @@ GEM chunky_png (~> 1.0) rqrcode_core (~> 0.1.0) rqrcode_core (0.1.0) - rspec-core (3.8.2) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.5) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.2) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-rails (3.9.0) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.3) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) ruby-ole (1.2.12.2) rubyzip (1.0.0) sass (3.7.4) @@ -273,10 +269,9 @@ GEM simple_form (5.0.1) actionpack (>= 5.0) activemodel (>= 5.0) - spreadsheet (1.2.4) + spreadsheet (1.2.5) ruby-ole (>= 1.0) - spring (2.0.2) - activesupport (>= 4.2) + spring (2.1.0) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) @@ -380,7 +375,7 @@ DEPENDENCIES whenever RUBY VERSION - ruby 2.3.1p112 + ruby 2.4.1p111 BUNDLED WITH 2.0.2 From 77ed76c36864cadee1d17e1adad99eb73a08da08 Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 13:04:12 +0630 Subject: [PATCH 08/23] Update Gemfile to use ruby 2.6.5 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 73701b6c..9f51df74 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.4.1' +ruby '2.6.5' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" From af3efbe607e68a4fe378ff40c363a2e5d151f88e Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 13:06:45 +0630 Subject: [PATCH 09/23] Update Gemfile to use ruby 2.6.5 --- Gemfile | 2 +- Gemfile.lock | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 9f51df74..c489fc3e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.6.5' + git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" diff --git a/Gemfile.lock b/Gemfile.lock index 7928786c..e28d4fd6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -374,8 +374,5 @@ DEPENDENCIES web-console (>= 3.3.0) whenever -RUBY VERSION - ruby 2.4.1p111 - BUNDLED WITH 2.0.2 From dc1f83ddc9b683c6f09063e442915c94a883ab0b Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 13:14:49 +0630 Subject: [PATCH 10/23] remove cups installation for cloud in Gemfile --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c489fc3e..143907b6 100644 --- a/Gemfile +++ b/Gemfile @@ -44,7 +44,7 @@ gem 'mini_magick' gem 'jquery-fileupload-rails', '~> 0.4.7' #Report and Printing gems -gem 'cups' +#gem 'cups' #remove for cloud installation gem 'prawn' gem 'prawn-table' gem 'prawn-qrcode' From 2e2117a8203764bd8c85dc96905eccc85fc37b8b Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 13:20:26 +0630 Subject: [PATCH 11/23] Remove cups for cloud --- Gemfile.lock | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e28d4fd6..db4f94aa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,7 +93,6 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) - cups (0.1.10) database_cleaner (1.7.0) diff-lcs (1.3) erubi (1.9.0) @@ -329,7 +328,6 @@ DEPENDENCIES carrierwave (~> 1.0) chartkick coffee-rails (~> 4.2) - cups database_cleaner factory_girl_rails (~> 4.0) faker From cec212bb394dae01f0e7a21946188e27efe0ef8a Mon Sep 17 00:00:00 2001 From: Nweni Date: Tue, 29 Oct 2019 10:06:00 +0630 Subject: [PATCH 12/23] dump --- dump.rdb | Bin 1864 -> 1864 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/dump.rdb b/dump.rdb index e4cb2863ade5864c70f85f677175fe6da53f30c9..42a27347f402a7cb6e6710a1d8f90f36e350dfb7 100644 GIT binary patch delta 100 zcmX@XcY<$%0rNul4HJz$Cg-!UPX5AbG`W*adg3Y3$?j}wlU3McC%zQD@1@%}v)pp@=pL3YWBo8*DQqP#|C2N?dFKRMjN((!u- E0OzD65&!@I delta 116 zcmX@XcY<$%0khSYWfP4(Ca-3cU^CY>GCRO9`2d^bWOjCW9`53j#1gBt#LS%3l+6zr zAFxc`z$nUMYyegwK3SDfcH%Ud$y|)m6VI|we5^XTpHXV!2HD9@jOIXvQj-s|NldJk Uo_w86ob&(G?^>_Q<2Q8z02jk4^#A|> From d4a90d6563241c995846c8325532a1ce1c9bbf04 Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Tue, 29 Oct 2019 10:38:50 +0630 Subject: [PATCH 13/23] docker changes --- config/deploy.rb | 1 + docker-compose.yml | 60 ++++++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 6dba4c2d..05bba77d 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -83,6 +83,7 @@ namespace :deploy do 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' diff --git a/docker-compose.yml b/docker-compose.yml index d1a961f7..ab61383d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,31 +1,33 @@ version: '3' services: - code2lab: - build: - context: . - dockerfile: ./Dockerfile - links: - - redis - volumes: - - .:/sxrestaurant - env_file: - - .code2lab.env - ports: - - '8082:62158' - environment: - - REDIS_URL=redis://redis:6379/0 - sidekiq: - build: . - command: bundle exec sidekiq -C config/sidekiq.yml - links: - - redis - volumes: - - .:/sxrestaurant - environment: - - REDIS_URL=redis://redis:6379/0 - redis: - image: redis - ports: - - '6380:6379' - volumes: - - ../data/redis:/data \ No newline at end of file + code2lab: + build: + context: . + dockerfile: ./Dockerfile + links: + - redis + volumes: + - .:/sxrestaurant + - "/etc/timezone:/etc/timezone:ro" + - "/etc/localtime:/etc/localtime:ro" + env_file: + - .code2lab.env + ports: + - '62160:62158' + environment: + - REDIS_URL=redis://172.17.0.1:6380/0 + sidekiq: + build: . + command: bundle exec sidekiq -C config/sidekiq.yml + links: + - redis + volumes: + - .:/sxrestaurant + environment: + - REDIS_URL=redis://172.17.0.1:6380/0 + redis: + image: redis + ports: + - '6380:6379' + volumes: + - ../data/redis:/data From 83e7f22b13954d9a92d074c397c2faadb38b32dc Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Tue, 29 Oct 2019 14:15:43 +0630 Subject: [PATCH 14/23] menu form is_ordering and is_active to data type boolean --- app/views/settings/menus/_form.html.erb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/views/settings/menus/_form.html.erb b/app/views/settings/menus/_form.html.erb index 15842333..770a18b3 100755 --- a/app/views/settings/menus/_form.html.erb +++ b/app/views/settings/menus/_form.html.erb @@ -7,8 +7,8 @@
<%= f.input :name,:input_html=>{:class=>"col-md-9"} %> - <%= f.input :is_active,:input_html=>{:class=>"col-md-9"} %> - <%= f.input :is_ordering,:input_html=>{:class=>"col-md-9"} %> + <%= f.input :is_active,:input_html=>{:class=>"col-md-9"}, as: :boolean %> + <%= f.input :is_ordering,:input_html=>{:class=>"col-md-9"}, as: :boolean %>
@@ -50,7 +50,7 @@ <% end %>
- +
@@ -58,7 +58,7 @@
<% end %> - +
@@ -81,7 +81,7 @@ 2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.menu_txt") %>

-
+ - From 6b6c945af7fa25bda39cd53bc8e18830eecc08f2 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 30 Oct 2019 10:23:28 +0630 Subject: [PATCH 15/23] gemfile --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 143907b6..5df23eb0 100644 --- a/Gemfile +++ b/Gemfile @@ -45,6 +45,7 @@ gem 'jquery-fileupload-rails', '~> 0.4.7' #Report and Printing gems #gem 'cups' #remove for cloud installation +# gem 'cups' gem 'prawn' gem 'prawn-table' gem 'prawn-qrcode' From d4e9f3217eb293a483d3977dab86474e24b0e909 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 30 Oct 2019 10:33:54 +0630 Subject: [PATCH 16/23] gem --- Gemfile.lock | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 393a2ac8..c0941977 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,7 +89,6 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) - cups (0.1.10) database_cleaner (1.7.0) diff-lcs (1.3) erubi (1.9.0) @@ -325,7 +324,6 @@ DEPENDENCIES carrierwave (~> 1.0) chartkick coffee-rails (~> 4.2) - cups database_cleaner factory_girl_rails (~> 4.0) faker From 41178978d23b5959cb242590c6a3063327308e7a Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 30 Oct 2019 10:38:49 +0630 Subject: [PATCH 17/23] gem lock --- Gemfile | 2 +- Gemfile.lock | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 5df23eb0..a49cf828 100644 --- a/Gemfile +++ b/Gemfile @@ -45,7 +45,7 @@ gem 'jquery-fileupload-rails', '~> 0.4.7' #Report and Printing gems #gem 'cups' #remove for cloud installation -# gem 'cups' +gem 'cups', '~>0.0.7' gem 'prawn' gem 'prawn-table' gem 'prawn-qrcode' diff --git a/Gemfile.lock b/Gemfile.lock index db4f94aa..3a70c5bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,7 +80,7 @@ GEM activemodel (>= 4.0.0) activesupport (>= 4.0.0) mime-types (>= 1.16) - chartkick (3.2.1) + chartkick (3.2.2) chronic (0.10.2) chunky_png (1.3.11) coffee-rails (4.2.2) @@ -93,6 +93,7 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) + cups (0.0.7) database_cleaner (1.7.0) diff-lcs (1.3) erubi (1.9.0) @@ -270,7 +271,8 @@ GEM activemodel (>= 5.0) spreadsheet (1.2.5) ruby-ole (>= 1.0) - spring (2.1.0) + spring (2.0.2) + activesupport (>= 4.2) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) @@ -328,6 +330,7 @@ DEPENDENCIES carrierwave (~> 1.0) chartkick coffee-rails (~> 4.2) + cups (~> 0.0.7) database_cleaner factory_girl_rails (~> 4.0) faker From 359679d41906c7bbb4bfd25d38b37ac6d9e381f2 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 30 Oct 2019 16:52:16 +0630 Subject: [PATCH 18/23] CBKI --- app/controllers/api/authenticate_controller.rb | 2 +- app/controllers/origami/addorders_controller.rb | 2 +- app/controllers/origami/payments_controller.rb | 2 +- app/controllers/origami/pending_order_controller.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/authenticate_controller.rb b/app/controllers/api/authenticate_controller.rb index 8fb10040..02043be9 100755 --- a/app/controllers/api/authenticate_controller.rb +++ b/app/controllers/api/authenticate_controller.rb @@ -1,5 +1,5 @@ class Api::AuthenticateController < Api::ApiController - skip_before_action :authenticate + # skip_before_action :authenticate def create emp_id = params[:emp_id] diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index ba302f88..597b5d28 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -305,7 +305,7 @@ class Origami::AddordersController < BaseOrigamiController def getCloudDomain from = "" if ENV["SERVER_MODE"] == 'cloud' - from = request.subdomain + "." + request.domain + from = request.subdomain.to_s + "." + request.domain.to_s end return from diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 5de37662..963d6ee3 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -839,7 +839,7 @@ class Origami::PaymentsController < BaseOrigamiController def getCloudDomain from = "" if ENV["SERVER_MODE"] == 'cloud' - from = request.subdomain + "." + request.domain + from = request.subdomain.to_s + "." + request.domain.to_s end return from diff --git a/app/controllers/origami/pending_order_controller.rb b/app/controllers/origami/pending_order_controller.rb index 4b412c17..773a217e 100644 --- a/app/controllers/origami/pending_order_controller.rb +++ b/app/controllers/origami/pending_order_controller.rb @@ -22,7 +22,7 @@ class Origami::PendingOrderController < BaseOrigamiController else redirect_to "/origami/#{params[:type]}" and return end - elsif id.start_with?("BKI") + elsif (id.start_with?("BKI") || id.start_with?("CBKI")) @bookings = Booking.find(id) @order = @bookings.orders.where(status: "new").first @order_items = @bookings.order_items From d95499f24d9399f272813671e3782c79c252e272 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 30 Oct 2019 17:58:17 +0630 Subject: [PATCH 19/23] authenticate --- app/controllers/api/api_controller.rb | 2 +- app/controllers/api/authenticate_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index ad38376a..a5112ffe 100755 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -1,5 +1,5 @@ class Api::ApiController < ActionController::API - # include TokenVerification + include TokenVerification # before_action :lookup_domain helper_method :current_token, :current_login_employee, :get_cashier diff --git a/app/controllers/api/authenticate_controller.rb b/app/controllers/api/authenticate_controller.rb index 02043be9..8fb10040 100755 --- a/app/controllers/api/authenticate_controller.rb +++ b/app/controllers/api/authenticate_controller.rb @@ -1,5 +1,5 @@ class Api::AuthenticateController < Api::ApiController - # skip_before_action :authenticate + skip_before_action :authenticate def create emp_id = params[:emp_id] From d2cf13cd3b8d48732f3e37c9086caddceef6fe77 Mon Sep 17 00:00:00 2001 From: Nweni Date: Fri, 1 Nov 2019 12:08:15 +0630 Subject: [PATCH 20/23] dump --- dump.rdb | Bin 1864 -> 1864 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/dump.rdb b/dump.rdb index 42a27347f402a7cb6e6710a1d8f90f36e350dfb7..2b0eb54ec77065e59631cfc96f9a0a9087d16625 100644 GIT binary patch delta 195 zcmX@XcY<$%f%xsbU9rD7N{drdbaPX44}Dn6$MBEgx9H?`jN&ZD1_u}>doUVK=3zGw z0f{GD Date: Fri, 1 Nov 2019 16:26:24 +0630 Subject: [PATCH 21/23] gemfile --- Gemfile.lock | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index c0941977..22c5244f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,6 +89,7 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) + cups (0.0.7) database_cleaner (1.7.0) diff-lcs (1.3) erubi (1.9.0) @@ -324,6 +325,7 @@ DEPENDENCIES carrierwave (~> 1.0) chartkick coffee-rails (~> 4.2) + cups database_cleaner factory_girl_rails (~> 4.0) faker From b73136dc79f1e815c712d159743bbd008afc3f31 Mon Sep 17 00:00:00 2001 From: Nweni Date: Fri, 1 Nov 2019 16:28:18 +0630 Subject: [PATCH 22/23] print copies --- app/models/printer/receipt_printer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index b45c722b..f7b35a5a 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -227,8 +227,8 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker count = printer_settings.print_copies # override print copies for print worker loop - print_settings.print_copies = 1 - print_settings.save! + # print_settings.print_copies = 1 + # print_settings.save! end directory_name = 'public/receipts' Dir.mkdir(directory_name) unless File.exists?(directory_name) From 216dfe4f2f8e1ebe36806898936b4812d7788db6 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Wed, 13 Nov 2019 13:34:11 +0630 Subject: [PATCH 23/23] add loader service api --- app/controllers/api/api_controller.rb | 23 +-- .../api/authenticate_controller.rb | 2 +- .../loader_service/load_data_controller.rb | 90 ++++++++++++ app/models/sale.rb | 135 +++++++++++++++++- app/models/sale_item.rb | 53 +++++++ config/routes.rb | 8 ++ 6 files changed, 298 insertions(+), 13 deletions(-) create mode 100644 app/controllers/api/loader_service/load_data_controller.rb diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index a5112ffe..0e8ea909 100755 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -1,5 +1,6 @@ class Api::ApiController < ActionController::API include TokenVerification + include ActionController::MimeResponds # before_action :lookup_domain helper_method :current_token, :current_login_employee, :get_cashier @@ -23,25 +24,25 @@ class Api::ApiController < ActionController::API @employee = Employee.find_by_token_session(current_token) end - # def lookup_domain - # if request.subdomain.present? && request.subdomain != "www" - # from = request.subdomain.downcase + "." + request.domain.downcase + # def lookup_domain + # if request.subdomain.present? && request.subdomain != "www" + # from = request.subdomain.downcase + "." + request.domain.downcase # @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase # if (!@license.nil?) - # logger.info "Location - " + @license.dbhost - # ActiveRecord::Base.establish_connection(website_connection(@license)) - # # authenticate_session_token + # logger.info "Location - " + @license.dbhost + # ActiveRecord::Base.establish_connection(website_connection(@license)) + # # authenticate_session_token # # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema # else # # reconnect_default_db # logger.info 'License is nil' # # redirect_to root_url(:host => request.domain) + "store_error" # render :json => [{ status: false, message: 'Invalid Access!'}] - # end - # end + # end + # end # end - # def website_connection(license) + # def website_connection(license) # default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, # :username => license.dbusername, :password => license.dbpassword) # end @@ -55,8 +56,8 @@ class Api::ApiController < ActionController::API # @default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup # end - # def cache_license(url, lookup) - # @license = License.new(url, lookup) + # def cache_license(url, lookup) + # @license = License.new(url, lookup) # if (@license.detail_with_local_cache(lookup) == true) # return @license diff --git a/app/controllers/api/authenticate_controller.rb b/app/controllers/api/authenticate_controller.rb index 8fb10040..aad8607c 100755 --- a/app/controllers/api/authenticate_controller.rb +++ b/app/controllers/api/authenticate_controller.rb @@ -40,7 +40,7 @@ class Api::AuthenticateController < Api::ApiController @status = false @error_message = "This employee is not active!" # render json: JSON.generate({:status => false, :error_message => "This employee is not active!"}) - end + end else @status = false @error_message = "Bad Emp_ID or Password!" diff --git a/app/controllers/api/loader_service/load_data_controller.rb b/app/controllers/api/loader_service/load_data_controller.rb new file mode 100644 index 00000000..58b89c3d --- /dev/null +++ b/app/controllers/api/loader_service/load_data_controller.rb @@ -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 diff --git a/app/models/sale.rb b/app/models/sale.rb index 8be79db3..a50aff81 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -2861,7 +2861,7 @@ def self.get_hourly_item_query(type) "i.status as status_type,i.remark as remark,"+ "i.unit_price,i.price as price,i.product_name as product_name, " + "i.menu_category_name,i.menu_category_code as menu_category_id, " + - + "concat(hour(CONVERT_TZ(receipt_date,'+00:00', '+06:30')), ':00 - ', hour(CONVERT_TZ(receipt_date,'+00:00', '+06:30')) + 1, ':00') as date_format," + "hour(CONVERT_TZ(receipt_date,'+00:00', '+06:30')) as hour") @@ -2885,6 +2885,139 @@ def grand_total_round self.grand_total =self.grand_total.round(print_settings.precision.to_i) 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 def generate_custom_id diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index d17edc6e..fee930f4 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -275,4 +275,57 @@ class SaleItem < ApplicationRecord 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 diff --git a/config/routes.rb b/config/routes.rb index bbc7a816..b3c5ff6e 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,6 +117,14 @@ scope "(:locale)", locale: /en|mm/ do #API for sync cloud 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 #--------- Cashier ------------#