From 5e344dc4a6a6d155e537f866703e4401daf7687b Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Fri, 9 Aug 2019 14:21:24 +0630 Subject: [PATCH 01/20] waste and spoil report --- Gemfile.lock | 269 +++++++++-------- app/controllers/home_controller.rb | 25 +- .../reports/hourly_saleitem_controller.rb | 197 ++++++++++++ .../reports/saleitem_controller.rb | 2 +- app/models/sale.rb | 20 +- .../_shift_sale_report_filter.html.erb | 146 +++++++++ .../reports/hourly_saleitem/index.html.erb | 114 +++++++ .../reports/hourly_saleitem/index.xls.erb | 282 ++++++++++++++++++ .../waste_and_spoilage/index-bk.html.erb | 99 ++++++ .../reports/waste_and_spoilage/index.html.erb | 71 ++--- config/database.yml.sample | 6 +- config/routes.rb | 2 + 12 files changed, 1044 insertions(+), 189 deletions(-) create mode 100644 app/controllers/reports/hourly_saleitem_controller.rb create mode 100644 app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb create mode 100644 app/views/reports/hourly_saleitem/index.html.erb create mode 100644 app/views/reports/hourly_saleitem/index.xls.erb create mode 100644 app/views/reports/waste_and_spoilage/index-bk.html.erb diff --git a/Gemfile.lock b/Gemfile.lock index b0e3f84d..1b1180a1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,83 +1,82 @@ GIT remote: https://github.com/capistrano/rbenv.git - revision: c029e4128e4a8f25adda35795f5729bd4f62e51f + revision: b8807f3bbb3f424ac42cc8838a38822e028d0aa3 specs: - capistrano-rbenv (2.1.3) + capistrano-rbenv (2.1.4) capistrano (~> 3.1) sshkit (~> 1.3) GEM remote: https://rubygems.org/ specs: - actioncable (5.1.4) - actionpack (= 5.1.4) + actioncable (5.1.7) + actionpack (= 5.1.7) nio4r (~> 2.0) websocket-driver (~> 0.6.1) - actionmailer (5.1.4) - actionpack (= 5.1.4) - actionview (= 5.1.4) - activejob (= 5.1.4) + actionmailer (5.1.7) + actionpack (= 5.1.7) + actionview (= 5.1.7) + activejob (= 5.1.7) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.1.4) - actionview (= 5.1.4) - activesupport (= 5.1.4) + actionpack (5.1.7) + actionview (= 5.1.7) + activesupport (= 5.1.7) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.1.4) - activesupport (= 5.1.4) + actionview (5.1.7) + activesupport (= 5.1.7) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.1.4) - activesupport (= 5.1.4) + activejob (5.1.7) + activesupport (= 5.1.7) globalid (>= 0.3.6) - activemodel (5.1.4) - activesupport (= 5.1.4) - activerecord (5.1.4) - activemodel (= 5.1.4) - activesupport (= 5.1.4) + activemodel (5.1.7) + activesupport (= 5.1.7) + activerecord (5.1.7) + activemodel (= 5.1.7) + activesupport (= 5.1.7) arel (~> 8.0) - activesupport (5.1.4) + activesupport (5.1.7) concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (~> 0.7) + i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) aescrypt (1.0.0) - airbrussh (1.3.0) + airbrussh (1.3.2) sshkit (>= 1.6.1, != 1.7.0) arel (8.0.0) axlsx (2.0.1) htmlentities (~> 4.3.1) nokogiri (>= 1.4.1) rubyzip (~> 1.0.0) - axlsx_rails (0.5.1) + axlsx_rails (0.5.2) actionpack (>= 3.1) axlsx (>= 2.0.1) - bcrypt (3.1.11) - bindex (0.5.0) + bcrypt (3.1.13) + bindex (0.8.1) builder (3.2.3) - byebug (9.1.0) + byebug (11.0.1) cancancan (1.17.0) - capistrano (3.10.1) + capistrano (3.11.0) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) sshkit (>= 1.9.0) - capistrano-bundler (1.3.0) + capistrano-bundler (1.6.0) capistrano (~> 3.1) - sshkit (~> 1.2) - capistrano-rails (1.3.1) + capistrano-rails (1.4.0) capistrano (~> 3.1) capistrano-bundler (~> 1.1) - carrierwave (1.2.1) + carrierwave (1.3.1) activemodel (>= 4.0.0) activesupport (>= 4.0.0) mime-types (>= 1.16) - chartkick (2.2.5) + chartkick (3.2.1) chronic (0.10.2) chunky_png (1.3.11) coffee-rails (4.2.2) @@ -87,46 +86,45 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.0.5) - connection_pool (2.2.1) - crass (1.0.2) + concurrent-ruby (1.1.5) + connection_pool (2.2.2) + crass (1.0.4) cups (0.1.10) - database_cleaner (1.6.2) + database_cleaner (1.7.0) diff-lcs (1.3) - erubi (1.7.0) + erubi (1.8.0) execjs (2.7.0) factory_girl (4.9.0) activesupport (>= 3.0.0) factory_girl_rails (4.9.0) factory_girl (~> 4.9.0) railties (>= 3.0.0) - faker (1.8.4) - i18n (~> 0.5) - ffi (1.9.18) - filterrific (2.1.2) - font-awesome-rails (4.7.0.2) - railties (>= 3.2, < 5.2) - globalid (0.4.1) + faker (2.1.0) + i18n (>= 0.7) + ffi (1.11.1) + filterrific (5.2.1) + font-awesome-rails (4.7.0.5) + railties (>= 3.2, < 6.1) + globalid (0.4.2) activesupport (>= 4.2.0) htmlentities (4.3.4) - httparty (0.15.6) + httparty (0.15.7) multi_xml (>= 0.5.2) - i18n (0.9.1) + i18n (1.6.0) concurrent-ruby (~> 1.0) - jbuilder (2.7.0) + jbuilder (2.9.1) activesupport (>= 4.2.0) - multi_json (>= 1.2) - jquery-fileupload-rails (0.4.7) + jquery-fileupload-rails (1.0.0) actionpack (>= 3.1) railties (>= 3.1) - sass (>= 3.2) - jquery-rails (4.3.1) + sassc + jquery-rails (4.3.5) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) jquery-ui-rails (6.0.1) railties (>= 3.2.16) - json (2.1.0) + json (2.2.0) kaminari (1.0.1) activesupport (>= 4.1.0) kaminari-actionview (= 1.0.1) @@ -142,39 +140,38 @@ GEM listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - loofah (2.1.1) + loofah (2.2.3) crass (~> 1.0.2) nokogiri (>= 1.5.9) - mail (2.7.0) + mail (2.7.1) mini_mime (>= 0.1.1) material_icons (2.2.1) railties (>= 3.2) - method_source (0.9.0) - mime-types (3.1) + method_source (0.9.2) + mime-types (3.2.2) mime-types-data (~> 3.2015) - mime-types-data (3.2016.0521) - mini_magick (4.8.0) - mini_mime (1.0.0) - mini_portile2 (2.3.0) - minitest (5.10.3) - momentjs-rails (2.17.1) + mime-types-data (3.2019.0331) + mini_magick (4.9.5) + mini_mime (1.0.2) + mini_portile2 (2.4.0) + minitest (5.11.3) + momentjs-rails (2.20.1) railties (>= 3.1) - multi_json (1.12.2) multi_xml (0.6.0) mysql2 (0.4.10) nested_form (0.3.2) - net-scp (1.2.1) - net-ssh (>= 2.6.5) - net-ssh (4.2.0) - nio4r (2.1.0) - nokogiri (1.8.1) - mini_portile2 (~> 2.3.0) + net-scp (2.0.0) + net-ssh (>= 2.6.5, < 6.0.0) + net-ssh (5.2.0) + nio4r (2.4.0) + nokogiri (1.10.3) + mini_portile2 (~> 2.4.0) pdf-core (0.7.0) - pdfjs_viewer-rails (0.2.0) + pdfjs_viewer-rails (0.3.1) json (> 1.8.4) rails (> 4.2.0) sass-rails (~> 5.0) - pg (0.21.0) + pg (1.1.4) prawn (2.2.2) pdf-core (~> 0.7.0) ttfunk (~> 1.5) @@ -183,40 +180,40 @@ GEM rqrcode (>= 0.4.1) prawn-table (0.2.2) prawn (>= 1.3.0, < 3.0.0) - puma (3.10.0) - rack (2.0.3) - rack-cors (1.0.2) - rack-protection (2.0.0) + puma (3.12.1) + rack (2.0.7) + rack-cors (1.0.3) + rack-protection (2.0.5) rack - rack-test (0.7.0) + rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.1.4) - actioncable (= 5.1.4) - actionmailer (= 5.1.4) - actionpack (= 5.1.4) - actionview (= 5.1.4) - activejob (= 5.1.4) - activemodel (= 5.1.4) - activerecord (= 5.1.4) - activesupport (= 5.1.4) + rails (5.1.7) + actioncable (= 5.1.7) + actionmailer (= 5.1.7) + actionpack (= 5.1.7) + actionview (= 5.1.7) + activejob (= 5.1.7) + activemodel (= 5.1.7) + activerecord (= 5.1.7) + activesupport (= 5.1.7) bundler (>= 1.3.0) - railties (= 5.1.4) + railties (= 5.1.7) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.0.3) - loofah (~> 2.0) - railties (5.1.4) - actionpack (= 5.1.4) - activesupport (= 5.1.4) + rails-html-sanitizer (1.1.0) + loofah (~> 2.2, >= 2.2.2) + 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.2.1) - rb-fsevent (0.10.2) - rb-inotify (0.9.10) - ffi (>= 0.5.0, < 2) + rake (12.3.3) + rb-fsevent (0.10.3) + rb-inotify (0.10.0) + ffi (~> 1.0) redis (3.3.5) roo (1.13.2) nokogiri @@ -224,89 +221,91 @@ GEM spreadsheet (> 0.6.4) rqrcode (0.10.1) chunky_png (~> 1.0) - rspec-core (3.7.0) - rspec-support (~> 3.7.0) - rspec-expectations (3.7.0) + rspec-core (3.8.2) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.4) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-mocks (3.7.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.7.0) - rspec-rails (3.7.1) + rspec-support (~> 3.8.0) + rspec-rails (3.8.2) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.7.0) - rspec-expectations (~> 3.7.0) - rspec-mocks (~> 3.7.0) - rspec-support (~> 3.7.0) - rspec-support (3.7.0) - ruby-ole (1.2.12.1) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.2) + ruby-ole (1.2.12.2) rubyzip (1.0.0) - sass (3.5.3) + sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.6) + sass-rails (5.0.7) railties (>= 4.0.0, < 6) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + sassc (2.0.1) + ffi (~> 1.9) + rake schema_to_scaffold (0.8.0) activesupport (>= 3.2.1) - shoulda-matchers (3.1.2) + shoulda-matchers (3.1.3) activesupport (>= 4.0.0) - sidekiq (5.0.5) - concurrent-ruby (~> 1.0) - connection_pool (~> 2.2, >= 2.2.0) + sidekiq (5.2.7) + connection_pool (~> 2.2, >= 2.2.2) + rack (>= 1.5.0) rack-protection (>= 1.5.0) - redis (>= 3.3.4, < 5) - simple_form (3.5.0) - actionpack (> 4, < 5.2) - activemodel (> 4, < 5.2) - spreadsheet (1.1.4) + redis (>= 3.3.5, < 5) + simple_form (4.1.0) + actionpack (>= 5.0) + activemodel (>= 5.0) + spreadsheet (1.2.4) 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) - sprockets (3.7.1) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sshkit (1.15.1) + sshkit (1.20.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) tether-rails (1.4.0) rails (>= 3.1) - thor (0.20.0) + thor (0.20.3) thread_safe (0.3.6) - tilt (2.0.8) + tilt (2.0.9) to_xls-rails (1.3.1) spreadsheet (>= 0.8.5) ttfunk (1.5.1) - turbolinks (5.0.1) - turbolinks-source (~> 5) - turbolinks-source (5.0.3) - tzinfo (1.2.4) + turbolinks (5.2.0) + turbolinks-source (~> 5.2) + turbolinks-source (5.2.0) + tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (3.2.0) + uglifier (4.1.20) execjs (>= 0.3.0, < 3) - web-console (3.5.1) + web-console (3.7.0) actionview (>= 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) - whenever (0.9.7) + websocket-extensions (0.1.4) + whenever (1.0.0) chronic (>= 0.6.3) PLATFORMS @@ -375,4 +374,4 @@ RUBY VERSION ruby 2.4.1p111 BUNDLED WITH - 2.0.1 + 2.0.2 diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 32344c77..49b4ff5d 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,11 +1,11 @@ -class HomeController < ApplicationController +class HomeController < ApplicationController # layout "application", except: [:index, :show] - # skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy] + # skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy] before_action :check_user, only: :dashboard # Special check for only dashboard - def check_user + def check_user if current_user.nil? redirect_to root_path end @@ -42,8 +42,8 @@ class HomeController < ApplicationController route_by_role(@employee) else flash[:notice] ="Invalid PIN for Employee. Please try again!" - render :show - end + render :show + end end def create @@ -117,7 +117,8 @@ class HomeController < ApplicationController @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) - + logger.debug 'hourly_sales<>><><><<<<<<>><<<><><><><><><><><><<>><' + logger.debug @hourly_sales.to_json employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time) # .sum("(CASE WHEN sp.payment_method='cash' THEN ((sp.payment_amount) - (sales.amount_changed)) ELSE (sp.payment_amount) END)") @employee_sales = [] @@ -145,7 +146,7 @@ class HomeController < ApplicationController if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" pay = Sale.payment_sale('card', today, current_user,@from,@to,@from_time,@to_time) @sale_data.push({'card' => pay.payment_amount}) - else + else pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to,@from_time,@to_time) @sale_data.push({payment.payment_method => pay.payment_amount}) end @@ -154,7 +155,7 @@ class HomeController < ApplicationController @summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to,@from_time,@to_time) @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time) # @total_other_customer = Sale.total_other_customer(today,current_user) - + @total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time) @total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time) @account_data = Array.new @@ -168,7 +169,7 @@ class HomeController < ApplicationController end @top_items = Sale.top_items(today,current_user,@from,@to,@from_time,@to_time) - @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time) + @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time) # get printer info @print_settings = PrintSetting.get_precision_delimiter() @@ -231,7 +232,7 @@ class HomeController < ApplicationController def get_date_range_from_params from = params[:from] - to = params[:to] + to = params[:to] from_time = params[:from_time] to_time = params[:to_time] @@ -243,8 +244,8 @@ class HomeController < ApplicationController # from = f_time.beginning_of_day.utc.getlocal # to = t_time.end_of_day.utc.getlocal - from = DateTime.parse(from).utc.getlocal.strftime('%Y-%m-%d') - to = DateTime.parse(to).utc.getlocal.strftime('%Y-%m-%d') + from = DateTime.parse(from).utc.getlocal.strftime('%Y-%m-%d') + to = DateTime.parse(to).utc.getlocal.strftime('%Y-%m-%d') end return from, to, from_time, to_time diff --git a/app/controllers/reports/hourly_saleitem_controller.rb b/app/controllers/reports/hourly_saleitem_controller.rb new file mode 100644 index 00000000..68883c68 --- /dev/null +++ b/app/controllers/reports/hourly_saleitem_controller.rb @@ -0,0 +1,197 @@ +class Reports::HourlySaleitemController < BaseReportController + authorize_resource :class => false + def index + + @account = Account.all + from, to = get_date_range_from_params + + shift_sale_range = '' + + shift = '' + if params[:shift_name].to_i != 0 + + shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + if shift_sale.shift_closed_at.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) + else + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + end + + account_type = params[:account_type] + @type = params[:sale_type] + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) + logger.debug 'product>>>>>>>>>>>>>>>>>>>>>>>>>>' + logger.debug @sale_data.group(:date_format) + + @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) + + @account_cate_count = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} + + + @menu_cate_count = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|cate| @menu_cate_count[cate.account_id] += 1} + + + @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + + @from = from + @to = to + + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + + if shift.present? + shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end + + respond_to do |format| + format.html + format.xls + end + end + + def show + from, to, report_type = get_date_range_from_params + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + sale_data = @sale_data + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + logger.debug 'show date arr####################' + logger.debug date_arr + end + + # @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + # @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end + + def print_sale_items + from, to = get_date_range_from_params + + shift_sale_range = '' + + shift = '' + shift_name = 'All Shift' + if params[:shift_name].to_i != 0 + + shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + if shift_sale.shift_closed_at.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) + else + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + + sh_name = "#{shift_sale.shift_started_at.utc.getlocal.strftime('%d %B %l:%M%p')} - #{shift_sale.shift_closed_at.utc.getlocal.strftime('%d %B %l:%M%p')}" + employee = Employee.find(shift_sale.employee_id) + shift_name = employee.nil? ? sh_name : "#{sh_name} (#{employee.name})" + end + + shop_details = shop_detail + account_type = params[:account_type] + @type = params[:period_type] + period_name = get_period_name(params[:period]) + + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) + other_charges = Sale.get_other_charges() + if shift.present? + @total_other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + else + @total_other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + end + + # get printer info + print_settings = PrintSetting.find_by_unique_code('SaleItemsPdf') # SaleItemsPdf + print_settings_star = PrintSetting.find_by_unique_code('SaleItemsStarPdf') + + # if print_settings.nil? && print_settings_star.nil? + # @print_setting = PrintSetting.new(name: "SaleItemsPdf", unique_code: "SaleItemsPdf", template: "",font: "Zawgyi-One", header_font_size: "10", item_font_size: "8", printer_name: "", api_settings: "", brand_name: nil, printer_type: nil, page_width: "210", page_height: "1450", print_copies: "1", precision: "0", delimiter: "0", heading_space: "5" ) + # @print_setting.save + # end + + if print_settings.nil? + if !print_settings_star.nil? + printer = Printer::CashierStationPrinter.new(print_settings_star) + printer.print_sale_items_report(print_settings_star, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) + end + else + printer = Printer::CashierStationPrinter.new(print_settings) + printer.print_sale_items_report(print_settings, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) + end + + respond_to do |format| + format.html { redirect_to '/en/reports/saleitem/', notice: 'Printing Completed.'} + format + end + end + + def get_period_name(period) + period_name = '-' + unless period.nil? or period.blank? + case period.to_i + when PERIOD["today"] + period_name = "Today" + + when PERIOD["yesterday"] + period_name = "Yesterday" + + when PERIOD["this_week"] + period_name = "This Week" + + when PERIOD["last_week"] + period_name = "Last Week" + + when PERIOD["last_7"] + period_name = "Last 7 days" + + when PERIOD["this_month"] + period_name = "This Month" + + when PERIOD["last_month"] + period_name = "Last Month" + + when PERIOD["last_30"] + period_name = "Last 30 Days" + + when PERIOD["this_year"] + period_name = "This Year" + + when PERIOD["last_year"] + period_name = "Last Year" + + end + end + return period_name + end + +end diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index b581eae8..f3062d69 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -64,7 +64,7 @@ class Reports::SaleitemController < BaseReportController def show from, to, report_type = get_date_range_from_params @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) - + sale_data = @sale_data date_arr = Array.new @sale_data.each do |sale| local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") diff --git a/app/models/sale.rb b/app/models/sale.rb index 7f8c2a65..15a27809 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -86,7 +86,7 @@ class Sale < ApplicationRecord # InventoryJob.perform_now(self.id) InventoryDefinition.calculate_product_count(saleObj) - + # dining charges charges = DiningCharge.where('dining_facility_id=?',booking.dining_facility_id).take @@ -1084,13 +1084,15 @@ def self.get_item_query(type) elsif type == "promotion" sale_type = "#{check_product} and i.status = 'promotion'" end - query = Sale.select("acc.title as account_name, + query = Sale.select("sales.sale_id,acc.title as account_name, i.item_instance_code as item_code,i.account_id as account_id, " + "SUM(i.qty * i.unit_price) as grand_total, SUM(i.qty) as total_item,i.qty as qty," + "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 ") + "i.menu_category_name,i.menu_category_code as menu_category_id, " + + "date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p') + as date_format") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id") @@ -1182,7 +1184,8 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou else query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) - + logger.debug 'get_by_shift_items??????????????????????????????????????' + logger.debug query.to_json if type.nil? || type == 'all' || type == "other" other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) end @@ -1639,6 +1642,13 @@ end end def self.hourly_sales(today,current_user,from,to,from_time,to_time) + logger.debug 'hourly_sales<<<<<<<<<<<<<<<<<<<<<<<<' + logger.debug today + logger.debug current_user.to_json + logger.debug from + logger.debug to + logger.debug from_time + logger.debug to_time if (!from.nil? && !to.nil?) && (from != "" && to!="") if current_user.nil? query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time) @@ -2775,6 +2785,8 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time= end query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') + logger.debug 'sales data>>>>>>>>>>>>>>>>>>>>>>>' + logger.debug query.to_json end return query diff --git a/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb b/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb new file mode 100644 index 00000000..fab1ad38 --- /dev/null +++ b/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb @@ -0,0 +1,146 @@ +
+ <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> + <% if period_type != false %> +
+
+ + +
+ +
+ + +
+
+ + + +
+
+ + + +
+
+ + +
+
+ + +
+
+
+ +
+
+ <% end %> + + <% end %> +
+ + diff --git a/app/views/reports/hourly_saleitem/index.html.erb b/app/views/reports/hourly_saleitem/index.html.erb new file mode 100644 index 00000000..f5491203 --- /dev/null +++ b/app/views/reports/hourly_saleitem/index.html.erb @@ -0,0 +1,114 @@ +
+ +
+
+ <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_waste_and_spoilage_index_path} %> +
+ +
+
+ + + <% time_arr = Array.new %> + <% menu_cat_arr = Array.new %> + <% footer_arr = Array.new %> + <% count = 0 %> + <% waste_and_spoil_item_count = 0%> + <% total_qty = 0 %> + <% time_count = 0 %> + <% @sale_data.each do |sale| %> + <% if !time_arr.include?(sale.date_format) %> + <% time_count = time_count + 1 %> + + + + + + + + + + + + + + + + + + <% time_arr.push(sale.date_format) %> + <% menu_cat_arr.clear %> + <% count = 0 %> + <% end %> + + + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" + total_qty += sale.total_item + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> + + <% if !sale.item_code.nil?%> + <% waste_and_spoil_item_count += sale.qty.to_i %> + + <% if !menu_cat_arr.include?(sale.menu_category_name) %> + + <% menu_cat_arr.push(sale.menu_category_name) %> + <% else %> + + <% end %> + + + + + + + + <% end %> + + + + <% count = count + 1 %> + <% logger.debug ' normal count+++++++++++++++++++++++++' %> + <% logger.debug sale.sale_items.count %> + <% logger.debug 'time_count count------------------------------------' %> + <% logger.debug time_count %> + <% if sale.sale_items.count == count %> + + + + + + + + <% footer_arr.push(sale.sale_id) %> + <% end %> + + <% end %> + +
 
+ Time :<%= sale.date_format %> + Date :
Menu CategoryItem CodeItem NameQtyPriceTotal Price
<%= sale.menu_category_name %> <%= sale.item_code %><%= sale.product_name %><%= sale.total_item.to_i %><%= sale.unit_price %><%= sale.price %><%= sale.date_format %>
 Total Qty:<%= total_qty%>Grand Total:
+
+
+
+
+
diff --git a/app/views/reports/hourly_saleitem/index.xls.erb b/app/views/reports/hourly_saleitem/index.xls.erb new file mode 100644 index 00000000..8f326e27 --- /dev/null +++ b/app/views/reports/hourly_saleitem/index.xls.erb @@ -0,0 +1,282 @@ + + + + + + + +
+
+
+
+
+ + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + <% p_qty = 0 %> + <% sub_qty = 0 %> + <% sub_total = 0 %> + <% other_sub_total = 0 %> + <% product_sub_total = 0 %> + <% count = 0 %> + <% total_price = 0 %> + <% cate_count = 0 %> + <% acc_count = 0 %> + <% grand_total = 0 %> + <% total_qty = 0 %> + <% total_amount = 0 %> + <% discount = 0 %> + <% total_item_foc = 0 %> + <% total_item_dis = 0.0 %> + <% total_tax = 0 %> + <% unless @sale_data.blank? %> + <% @sale_data.each do |sale| %> + + + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" + total_qty += sale.total_item + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.remark =="promotion" + total_qty += sale.total_item + end %> + + + <% if sale.status_type == "foc" && sale.grand_total < 0 + total_item_foc += sale.grand_total*(-1) + end %> + + <% if sale.status_type == "Discount" && sale.grand_total < 0 + total_item_dis += sale.grand_total*(-1) + end %> + + <% if !acc_arr.include?(sale.account_id) %> + + + + + + + <% acc_arr.push(sale.account_id) %> + <% end %> + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + <% if sale.status_type != "Discount" %> + + <%else%> + + <% end %> + + + + + + + <% @menu_cate_count.each do |key,value| %> + <% if sale.account_id == key %> + <% count = count + 1 %> + <% sub_total += sale.grand_total %> + <% #sub_qty += sale.total_item %> + <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion" + sub_qty += sale.total_item + end %> + <% if sale.status_type =="Discount" + sub_qty += sale.total_item*(-1) + end %> + + <% if sale.remark == "promotion" + sub_qty += sale.total_item + end %> + <% if count == value %> + + + + + + + + <% sub_total = 0.0%> + <% sub_qty = 0 %> + <% count = 0%> + <% end %> + <% end %> + <% end %> + + <% end %> + + <% if @product.present?%> + + + + + + + <% @product.each do |product| %> + <% if product.total_item > 0 + total_qty += product.total_item + end %> + <% grand_total +=product.grand_total + p_qty += product.total_item%> + + + + + + + + + + + + <% product_sub_total += product.grand_total %> + + <% end %> + + + + + + + + + <%end%> + + + + <% if @type == "other" || @other_charges.present?%> + + + + + + + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + + + + + + + + + + + + <% other_sub_total += other.grand_total %> + + <% end %> + + + + + + <%end%> + + + + + + + + + <% end %> + <% if @type == "other"%> + + + + + + + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + + + + + + + + + + + + <% other_sub_total += other.grand_total %> + + <% end %> + + + + + + <%end%> + +
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
<%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
 <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %>
<%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> + <% if sale.account_id == account %> + <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> + <% grand_total += total %> + <% end %> + <% end %> +
 <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.total_item*(-1) rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%>
Product 
 Product<%= product.product_code rescue '-' %><%= product.product_name rescue '-' %><%= product.total_item rescue '-' %> <%= number_with_precision(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 Total Product Qty <%= p_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%>
Other Charges 
 Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
 <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%>
Other Charges 
 Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
+
+
+
+
+
+ + \ No newline at end of file diff --git a/app/views/reports/waste_and_spoilage/index-bk.html.erb b/app/views/reports/waste_and_spoilage/index-bk.html.erb new file mode 100644 index 00000000..d034fce3 --- /dev/null +++ b/app/views/reports/waste_and_spoilage/index-bk.html.erb @@ -0,0 +1,99 @@ +
+ +
+
+ <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_waste_and_spoilage_index_path} %> +
+ +
+
+ + +
Report For <%= @sale_type? @sale_type : 'Waste' %>
+ <% receipt_arr = Array.new %> + <% menu_cat_arr = Array.new %> + <% footer_arr = Array.new %> + <% count = 0 %> + <% waste_and_spoil_item_count = 0%> + <% @sale_data.each do |sale| %> + <% if !receipt_arr.include?(sale.receipt_no) %> + + + + + + + + + + + + + + + + + + <% receipt_arr.push(sale.receipt_no) %> + <% menu_cat_arr.clear %> + <% count = 0 %> + <% end %> + + + <% if !sale.item_instance_code.nil?%> + <% waste_and_spoil_item_count += sale.qty.to_i %> + + <% if !menu_cat_arr.include?(sale.name) %> + + <% menu_cat_arr.push(sale.name) %> + <% else %> + + <% end %> + + + + + + + <% end %> + + <% count = count + 1 %> + <% if sale.sale_items.count == count %> + + + + + + + + <% footer_arr.push(sale.sale_id) %> + <% end %> + + <% end %> +
 
+ Receipt No :<%= sale.receipt_no %> + Date : <%= sale.created_at.utc.getlocal.strftime("%e,%b %Y %I:%M %p") %>
Menu CategoryItem NameItem CodeQtyPriceTotal Price
<%= sale.name %> <%= sale.product_name %><%= sale.product_code %><%= sale.qty.to_i %><%= sale.unit_price %><%= sale.price %>
Total Qty: + + <%= waste_and_spoil_item_count %> + <% waste_and_spoil_item_count = 0%> + Grand Total: + + <%= sale.grand_total %> + +
+
+
+
+
+
diff --git a/app/views/reports/waste_and_spoilage/index.html.erb b/app/views/reports/waste_and_spoilage/index.html.erb index 879a9bd5..e81eb1ca 100755 --- a/app/views/reports/waste_and_spoilage/index.html.erb +++ b/app/views/reports/waste_and_spoilage/index.html.erb @@ -18,46 +18,47 @@
- +
Report For <%= @sale_type? @sale_type : 'Waste' %>
- <% receipt_arr = Array.new %> - <% menu_cat_arr = Array.new %> - <% footer_arr = Array.new %> - <% count = 0 %> - <% waste_and_spoil_item_count = 0%> - <% @sale_data.each do |sale| %> - <% if !receipt_arr.include?(sale.receipt_no) %> - - + + + - + - <% receipt_arr.push(sale.receipt_no) %> - <% menu_cat_arr.clear %> - <% count = 0 %> - <% end %> - + + - <% if !sale.item_instance_code.nil?%> + <% receipt_arr = Array.new %> + <% menu_cat_arr = Array.new %> + <% footer_arr = Array.new %> + <% count = 0 %> + <% waste_and_spoil_item_count = 0%> + <% grand_total = 0%> + <% unless @sale_data.blank? %> + <% @sale_data.each do |sale| %> + <% if !sale.item_instance_code.nil?%> <% waste_and_spoil_item_count += sale.qty.to_i %> + <% grand_total += sale.grand_total.to_i %> + <% end %> - <% if !menu_cat_arr.include?(sale.name) %> + <% if !menu_cat_arr.include?(sale.name) %> <% menu_cat_arr.push(sale.name) %> <% else %> @@ -68,33 +69,35 @@ - - <% end %> - + + + <% count = count + 1 %> - <% if sale.sale_items.count == count %> + <% if @sale_data.length == count %> - + - - + <% footer_arr.push(sale.sale_id) %> <% end %> - - <% end %> + <% end %> + <% end %> + +
 
Menu Category Item Name Item Code Qty PriceTotal PriceTotal Price
<%= sale.name %><%= sale.qty.to_i %> <%= sale.unit_price %> <%= sale.price %>
Total Qty: Total Qty: <%= waste_and_spoil_item_count %> <% waste_and_spoil_item_count = 0%> Grand Total: + - <%= sale.grand_total %> + <%= grand_total %>
- \ No newline at end of file + diff --git a/config/database.yml.sample b/config/database.yml.sample index 211fb2f0..5da58ff0 100755 --- a/config/database.yml.sample +++ b/config/database.yml.sample @@ -4,13 +4,13 @@ default: &default pool: 5 timeout: 5000 encoding: unicode - username: wunna - password: admin123 + username: nlh + password: 7812co2Y port: 5432 development: <<: *default - database: SXDatabase + database: sxdemo production: <<: *default database: paymal diff --git a/config/routes.rb b/config/routes.rb index fa085c5a..a59aa75f 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -523,6 +523,7 @@ scope "(:locale)", locale: /en|mm/ do resources :receipt_no_detail resources :dailysale, :only => [:index, :show] resources :saleitem, :only => [:index, :show] + resources :hourly_saleitem, :only => [:index, :show] resources :shiftsale, :only => [:index, :show] resources :credit_payment, :only => [:index, :show] resources :void_sale, :only => [:index, :show] @@ -537,6 +538,7 @@ scope "(:locale)", locale: /en|mm/ do resources :card_settle_tran get "saleitem/get_shift_by_date", to: "saleitem#show", as: "get_shift_by_sale_item" + get "hourly_saleitem/get_shift_by_date", to: "hourly_saleitem#show", as: "get_shift_by_hourly_saleitem" get "receipt_no/get_shift_by_date", to: "receipt_no#get_shift_by_date", as: "get_shift_by_date" get "order_reservation/get_shift_by_date", to: "order_reservation#show", as: "get_shift_by_order_reservation" get "induty/get_shift_by_date", to: "induty#show", as: "get_shift_by_induty" From e443c5431ec87edd7c6abe1fed68210d92ba3091 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Mon, 19 Aug 2019 10:45:50 +0630 Subject: [PATCH 02/20] hourly sale items report --- .../reports/hourly_saleitem_controller.bk.rb | 200 +++++++++ .../reports/hourly_saleitem_controller.rb | 12 +- app/models/sale.rb | 140 ++++++- app/views/layouts/_left_sidebar.html.erb | 3 + .../_shift_sale_report_filter.html.erb | 4 +- .../reports/hourly_saleitem/index.bk.html.erb | 121 ++++++ .../reports/hourly_saleitem/index.html.erb | 229 ++++++++-- .../reports/hourly_saleitem/index.xls.erb | 394 ++++++------------ 8 files changed, 801 insertions(+), 302 deletions(-) create mode 100644 app/controllers/reports/hourly_saleitem_controller.bk.rb create mode 100644 app/views/reports/hourly_saleitem/index.bk.html.erb diff --git a/app/controllers/reports/hourly_saleitem_controller.bk.rb b/app/controllers/reports/hourly_saleitem_controller.bk.rb new file mode 100644 index 00000000..88a61335 --- /dev/null +++ b/app/controllers/reports/hourly_saleitem_controller.bk.rb @@ -0,0 +1,200 @@ +class Reports::HourlySaleitemController < BaseReportController + authorize_resource :class => false + def index + + @account = Account.all + from, to = get_date_range_from_params + + shift_sale_range = '' + + shift = '' + if params[:shift_name].to_i != 0 + + shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + if shift_sale.shift_closed_at.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) + else + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + end + + account_type = params[:account_type] + @type = params[:sale_type] + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) + logger.debug 'product>>>>>>>>>>>>>>>>>>>>>>>>>>' + # logger.debug @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"Date" =>key , "total_qty" => qty.sum{|d| d.qty.to_i}}} + + @hourly_total_qty = @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"date" => key , "total_qty" => qty.sum{|d| d.qty.to_i}}} + logger.debug @hourly_total_qty + + @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) + + @account_cate_count = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} + + + @menu_cate_count = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|cate| @menu_cate_count[cate.account_id] += 1} + + + @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + + @from = from + @to = to + + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + + if shift.present? + shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end + + respond_to do |format| + format.html + format.xls + end + end + + def show + from, to, report_type = get_date_range_from_params + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + sale_data = @sale_data + date_arr = Array.new + @sale_data.each do |sale| + local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") + local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p") + opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc + closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc + shift_id = sale.id.nil? ? '-' : sale.id + str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} + date_arr.push(str) + logger.debug 'show date arr####################' + logger.debug date_arr + end + + # @totalByAccount = Hash.new {|hash, key| hash[key] = 0} + # @sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total} + + out = {:status => 'ok', :message => date_arr} + + respond_to do |format| + format.json { render json: out } + end + end + + def print_sale_items + from, to = get_date_range_from_params + + shift_sale_range = '' + + shift = '' + shift_name = 'All Shift' + if params[:shift_name].to_i != 0 + + shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',shift_sale.shift_started_at) + else + if shift_sale.shift_closed_at.blank? + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',shift_sale.shift_started_at) + else + shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) + end + end + + sh_name = "#{shift_sale.shift_started_at.utc.getlocal.strftime('%d %B %l:%M%p')} - #{shift_sale.shift_closed_at.utc.getlocal.strftime('%d %B %l:%M%p')}" + employee = Employee.find(shift_sale.employee_id) + shift_name = employee.nil? ? sh_name : "#{sh_name} (#{employee.name})" + end + + shop_details = shop_detail + account_type = params[:account_type] + @type = params[:period_type] + period_name = get_period_name(params[:period]) + + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) + other_charges = Sale.get_other_charges() + if shift.present? + @total_other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + else + @total_other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + end + + # get printer info + print_settings = PrintSetting.find_by_unique_code('SaleItemsPdf') # SaleItemsPdf + print_settings_star = PrintSetting.find_by_unique_code('SaleItemsStarPdf') + + # if print_settings.nil? && print_settings_star.nil? + # @print_setting = PrintSetting.new(name: "SaleItemsPdf", unique_code: "SaleItemsPdf", template: "",font: "Zawgyi-One", header_font_size: "10", item_font_size: "8", printer_name: "", api_settings: "", brand_name: nil, printer_type: nil, page_width: "210", page_height: "1450", print_copies: "1", precision: "0", delimiter: "0", heading_space: "5" ) + # @print_setting.save + # end + + if print_settings.nil? + if !print_settings_star.nil? + printer = Printer::CashierStationPrinter.new(print_settings_star) + printer.print_sale_items_report(print_settings_star, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) + end + else + printer = Printer::CashierStationPrinter.new(print_settings) + printer.print_sale_items_report(print_settings, shop_details, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) + end + + respond_to do |format| + format.html { redirect_to '/en/reports/saleitem/', notice: 'Printing Completed.'} + format + end + end + + def get_period_name(period) + period_name = '-' + unless period.nil? or period.blank? + case period.to_i + when PERIOD["today"] + period_name = "Today" + + when PERIOD["yesterday"] + period_name = "Yesterday" + + when PERIOD["this_week"] + period_name = "This Week" + + when PERIOD["last_week"] + period_name = "Last Week" + + when PERIOD["last_7"] + period_name = "Last 7 days" + + when PERIOD["this_month"] + period_name = "This Month" + + when PERIOD["last_month"] + period_name = "Last Month" + + when PERIOD["last_30"] + period_name = "Last 30 Days" + + when PERIOD["this_year"] + period_name = "This Year" + + when PERIOD["last_year"] + period_name = "Last Year" + + end + end + return period_name + end + +end diff --git a/app/controllers/reports/hourly_saleitem_controller.rb b/app/controllers/reports/hourly_saleitem_controller.rb index 68883c68..019af7a1 100644 --- a/app/controllers/reports/hourly_saleitem_controller.rb +++ b/app/controllers/reports/hourly_saleitem_controller.rb @@ -26,9 +26,9 @@ class Reports::HourlySaleitemController < BaseReportController account_type = params[:account_type] @type = params[:sale_type] - @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) - logger.debug 'product>>>>>>>>>>>>>>>>>>>>>>>>>>' - logger.debug @sale_data.group(:date_format) + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_hourly_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) + # logger.debug 'product>>>>>>>>>>>>>>>>>>>>>>>>>>' + # logger.debug @sale_data.group(:date_format) @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) @@ -56,6 +56,8 @@ class Reports::HourlySaleitemController < BaseReportController @shift_data = sh end end + # @hourly_total_qty = @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"date" => key , "total_qty" => qty.sum{|d| d.qty.to_i}}} + @hourly_total_qty = @sale_data.group_by(&:date_format).map { |k,v|{"date" => k , "total_qty" => v.count }} respond_to do |format| format.html @@ -76,8 +78,6 @@ class Reports::HourlySaleitemController < BaseReportController shift_id = sale.id.nil? ? '-' : sale.id str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date} date_arr.push(str) - logger.debug 'show date arr####################' - logger.debug date_arr end # @totalByAccount = Hash.new {|hash, key| hash[key] = 0} @@ -122,7 +122,7 @@ class Reports::HourlySaleitemController < BaseReportController @type = params[:period_type] period_name = get_period_name(params[:period]) - @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_hourly_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) other_charges = Sale.get_other_charges() if shift.present? @total_other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) diff --git a/app/models/sale.rb b/app/models/sale.rb index acbb25b7..ed469667 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1184,8 +1184,6 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou else query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) - logger.debug 'get_by_shift_items??????????????????????????????????????' - logger.debug query.to_json if type.nil? || type == 'all' || type == "other" other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) end @@ -2785,8 +2783,6 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time= end query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") .order('receipt_date') - logger.debug 'sales data>>>>>>>>>>>>>>>>>>>>>>>' - logger.debug query.to_json end return query @@ -2816,6 +2812,142 @@ def self.employee_sale(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil return query end +# Start hourly sale item report +def self.get_by_hourly_items(shift_sale_range, shift, from, to, status,type,account_type) + # date_type_selection = get_sql_function_for_report_type(report_type) + if account_type.blank? + account_type = '' + else + account_type = " and acc.title = '#{account_type}'" + end + + query = self.get_hourly_item_query(type) + + discount_query = 0 + total_card_amount = 0 + total_cash_amount = 0 + total_credit_amount = 0 + total_foc_amount = 0 + total_grand_total = 0 + + if type.nil? || type == 'all' || type == "other" + other_charges = self.get_other_charges() + end + product = self.get_product_sale() + + if shift.present? + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift.to_a) + if type.nil? || type == 'all' || type == "other" + other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + end + product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) + discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount) + change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.to_a) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + ### => get all sales range in shift_sales + elsif shift_sale_range.present? + query = query.where("sales.shift_sale_id IN (?) #{account_type} and sale_status='completed'",shift_sale_range.to_a) + if type.nil? || type == 'all' || type == "other" + other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + end + product = product.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a) + discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount) + change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.shift_sale_id in (?) and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift_sale_range.to_a) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + else + query = query.where("sales.receipt_date between ? and ? #{account_type} and sale_status='completed'",from,to) + if type.nil? || type == 'all' || type == "other" + other_charges = other_charges.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + end + product = product.where("sales.receipt_date between ? and ? and sale_status='completed'",from,to) + + discount_query = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:total_discount) + change_amount = Sale.where("sales.receipt_date between ? and ? and sale_status ='completed'", from,to).sum(:amount_changed) + sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar' or sale_payments.payment_method = 'unionpay' or sale_payments.payment_method = 'alipay' or sale_payments.payment_method = 'paymal' or sale_payments.payment_method = 'dinga' or sale_payments.payment_method = 'JunctionPay' or sale_payments.payment_method = 'giftvoucher') then (sale_payments.payment_amount) else 0 end) as card_amount, + SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount, + SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount") + .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") + .where("sales.receipt_date between ? and ? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", from,to) + sale_cash.each do |s_c| + total_cash_amount += s_c.cash_amount.to_f + total_card_amount += s_c.card_amount.to_f + total_credit_amount += s_c.credit_amount.to_f + total_foc_amount += s_c.foc_amount.to_f + end + total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f + + end + + return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount +end + +def self.get_hourly_item_query(type) + check_product = "i.menu_category_name != 'product'" + if type == "revenue" + sale_type = "i.qty > 0 and status IS NULL" + elsif type == "all" || type.nil? + sale_type = "#{check_product}" + elsif type == "discount" + sale_type = "#{check_product} and i.status = 'Discount'" + elsif type == "foc" + sale_type = "#{check_product} and i.status = 'foc' and i.item_instance_code IS NOT NULL and i.qty > 0" + elsif type == "void" + sale_type = "#{check_product} and i.status = 'void' and i.item_instance_code IS NOT NULL and i.qty > 0" + elsif type == "other" + sale_type = "#{check_product} and i.item_instance_code IS NULL" + elsif type == "promotion" + sale_type = "#{check_product} and i.status = 'promotion'" + end + query = Sale.select("sales.sale_id,acc.title as account_name, + i.item_instance_code as item_code,i.account_id as account_id, " + + "SUM(i.qty * i.unit_price) as grand_total, + SUM(i.qty) as total_item,i.qty as qty," + + "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, " + + "date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p') + as date_format") + + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + + " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id") + # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ") + query = query.joins(" JOIN accounts acc ON acc.id = i.account_id") + query = query.where("#{sale_type}") + query = query.group("acc.title,i.account_id,i.menu_category_code,i.item_instance_code,i.product_name,i.unit_price") + .order("date_format asc") + # query = query.order("i.menu_category_name asc, SUM(i.qty) desc") +end + +# End hourly sale item report + private def generate_custom_id diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index d9f12423..4fee71b1 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -285,6 +285,9 @@
  • Sale Items +
  • +
  • + Hourly Sale Items
  • Product Sale diff --git a/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb b/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb index fab1ad38..4ca6ccf9 100644 --- a/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb +++ b/app/views/reports/hourly_saleitem/_shift_sale_report_filter.html.erb @@ -32,7 +32,7 @@ -
    +
    diff --git a/app/views/reports/hourly_saleitem/index.bk.html.erb b/app/views/reports/hourly_saleitem/index.bk.html.erb new file mode 100644 index 00000000..5992d5cd --- /dev/null +++ b/app/views/reports/hourly_saleitem/index.bk.html.erb @@ -0,0 +1,121 @@ +
    + +
    +
    + <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_waste_and_spoilage_index_path} %> +
    + +
    +
    + + + <% time_arr = Array.new %> + <% menu_cat_arr = Array.new %> + <% footer_arr = Array.new %> + <% count = 0 %> + <% waste_and_spoil_item_count = 0%> + <% total_qty = 0 %> + <% time_count = 0 %> + <% @sale_data.each do |sale| %> + <% if !time_arr.include?(sale.date_format) %> + <% time_count = time_count + 1 %> + + + + + + + + + + + + + + + + + + <% time_arr.push(sale.date_format) %> + <% menu_cat_arr.clear %> + <% count = 0 %> + <% end %> + + + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" + total_qty += sale.total_item + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> + + <% if !sale.item_code.nil?%> + <% waste_and_spoil_item_count += sale.qty.to_i %> + + <% if !menu_cat_arr.include?(sale.menu_category_name) %> + + <% menu_cat_arr.push(sale.menu_category_name) %> + <% else %> + + <% end %> + + + + + + + + <% end %> + + + + + <% @hourly_total_qty.each do |qty| %> + <% qty_count = qty["total_qty"] %> + <% logger.debug ' qty count+++++++++++++++++++++++++' %> + <% logger.debug qty_count %> + <% #logger.debug ' normal count+++++++++++++++++++++++++' %> + <% #logger.debug sale.sale_items.count %> + <% end %> + + <% count = count + 1 %> + <% logger.debug 'count ------------------------------------' %> + <% logger.debug count %> + <% if sale.sale_items.count == count %> + + + + + + + + <% footer_arr.push(sale.sale_id) %> + <% end %> + + <% end %> + +
     
    + Time :<%= sale.date_format %> + Date :
    Menu CategoryItem CodeItem NameQtyPriceTotal Price
    <%= sale.menu_category_name %> <%= sale.item_code %><%= sale.product_name %><%= sale.total_item.to_i %><%= sale.unit_price %><%= sale.price %><%= sale.date_format %>
     Total Qty:<%= total_qty%>Grand Total:
    +
    +
    +
    +
    +
    diff --git a/app/views/reports/hourly_saleitem/index.html.erb b/app/views/reports/hourly_saleitem/index.html.erb index f5491203..a51ebe98 100644 --- a/app/views/reports/hourly_saleitem/index.html.erb +++ b/app/views/reports/hourly_saleitem/index.html.erb @@ -2,7 +2,7 @@ + + diff --git a/app/views/reports/hourly_saleitem/index.xls.erb b/app/views/reports/hourly_saleitem/index.xls.erb index 8f326e27..df37f29e 100644 --- a/app/views/reports/hourly_saleitem/index.xls.erb +++ b/app/views/reports/hourly_saleitem/index.xls.erb @@ -9,274 +9,138 @@
    -
    - - - - - - <% if @shift_from %> - - <% if @shift_data.employee %> - <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> - - - <% end %> - - - - - - - - - - - - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> - <% acc_arr = Array.new %> - <% cate_arr = Array.new %> - <% p_qty = 0 %> - <% sub_qty = 0 %> - <% sub_total = 0 %> - <% other_sub_total = 0 %> - <% product_sub_total = 0 %> - <% count = 0 %> - <% total_price = 0 %> - <% cate_count = 0 %> - <% acc_count = 0 %> - <% grand_total = 0 %> - <% total_qty = 0 %> - <% total_amount = 0 %> - <% discount = 0 %> - <% total_item_foc = 0 %> - <% total_item_dis = 0.0 %> - <% total_tax = 0 %> - <% unless @sale_data.blank? %> - <% @sale_data.each do |sale| %> - - - <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" - total_qty += sale.total_item - end %> - <% if sale.status_type == "foc" && sale.price > 0 - total_qty += sale.total_item - end %> - <% if sale.status_type == "Discount" - total_qty += sale.total_item*(-1) - end %> - <% if sale.remark =="promotion" - total_qty += sale.total_item - end %> - - - <% if sale.status_type == "foc" && sale.grand_total < 0 - total_item_foc += sale.grand_total*(-1) - end %> +
    +
    +
    - <% if sale.status_type == "Discount" && sale.grand_total < 0 - total_item_dis += sale.grand_total*(-1) - end %> - - <% if !acc_arr.include?(sale.account_id) %> -
    - - - - - - <% acc_arr.push(sale.account_id) %> - <% end %> - - - <% if !cate_arr.include?(sale.menu_category_id) %> - - <% cate_arr.push(sale.menu_category_id) %> - <% else %> - - <% end %> - - - <% if sale.status_type != "Discount" %> - - <%else%> - - <% end %> - - - - - +
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
     <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %>
    <%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> - <% @totalByAccount.each do |account, total| %> - <% if sale.account_id == account %> - <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> - <% grand_total += total %> - <% end %> - <% end %> -
     <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.total_item*(-1) rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
    + <% time_arr = Array.new %> + <% acc_arr = Array.new %> + <% sale_item_count =0 %> + <% menu_cat_arr = Array.new %> + <% footer_arr = Array.new %> + <% count = 0 %> + <% waste_and_spoil_item_count = 0%> + <% total_qty = 0 %> + <% time_count = 0 %> + <% grand_total = 0 %> + <% @sale_data.each do |sale| %> + <% if !time_arr.include?(sale.date_format) %> + <% sale_item_count =1 %> + <% time_count = time_count + 1 %> + + + + + + + + + + + + + + + + + + <% time_arr.push(sale.date_format) %> + <% menu_cat_arr.clear %> + <% count = 0 %> + <% else %> + <% sale_item_count =sale_item_count +1 %> + <% end %> + + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" + total_qty += sale.total_item + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> - <% @menu_cate_count.each do |key,value| %> - <% if sale.account_id == key %> - <% count = count + 1 %> - <% sub_total += sale.grand_total %> - <% #sub_qty += sale.total_item %> - <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion" - sub_qty += sale.total_item - end %> - <% if sale.status_type =="Discount" - sub_qty += sale.total_item*(-1) - end %> + + <% if sale.status_type == "foc" && sale.grand_total < 0 + grand_total += sale.grand_total*(-1) + end %> - <% if sale.remark == "promotion" - sub_qty += sale.total_item - end %> - <% if count == value %> - - - - - - - - <% sub_total = 0.0%> - <% sub_qty = 0 %> - <% count = 0%> - <% end %> - <% end %> - <% end %> - - <% end %> - - <% if @product.present?%> - - - - - - - <% @product.each do |product| %> - <% if product.total_item > 0 - total_qty += product.total_item - end %> - <% grand_total +=product.grand_total - p_qty += product.total_item%> - - - - - - - - - - - - <% product_sub_total += product.grand_total %> - - <% end %> - - - - + <% if sale.status_type == "Discount" && sale.grand_total < 0 + grand_total += sale.grand_total*(-1) + end %> - - - - <%end%> - + <% if sale.status_type == "promotion" && sale.grand_total < 0 + grand_total += sale.grand_total*(-1) + end %> - - <% if @type == "other" || @other_charges.present?%> - - - - - - - <% @other_charges.each do |other| %> - <% if other.total_item > 0 - total_qty += other.total_item - end %> - <% grand_total +=other.grand_total%> - - - - - - - - - - - - <% other_sub_total += other.grand_total %> - - <% end %> - - - - - - <%end%> - - - - - - - - - <% end %> - <% if @type == "other"%> - - - - - - - <% @other_charges.each do |other| %> - <% if other.total_item > 0 - total_qty += other.total_item - end %> - <% grand_total +=other.grand_total%> - - - - - - - - - - - - <% other_sub_total += other.grand_total %> - - <% end %> - - - - - - <%end%> - -
     
    + Time :<%= sale.date_format %> +
    Menu CategoryItem CodeItem NameQtyPriceTotal Price
     Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%>
    Product 
     Product<%= product.product_code rescue '-' %><%= product.product_name rescue '-' %><%= product.total_item rescue '-' %> <%= number_with_precision(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     Total Product Qty <%= p_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges 
     Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%>
    Other Charges 
     Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
     <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
    -
    -
    -
    -
    -
    + <% grand_total += sale.grand_total %> + + <% if !sale.item_code.nil?%> + <% waste_and_spoil_item_count += sale.qty.to_i %> + + <% if !menu_cat_arr.include?(sale.menu_category_name) %> + <%= sale.menu_category_name %> + <% menu_cat_arr.push(sale.menu_category_name) %> + <% else %> +   + <% end %> + <%= sale.item_code %> + <%= sale.product_name %> + <%= sale.total_item.to_i %> + <%= sale.unit_price.to_i %> + <%= sale.grand_total.to_i %> + <%= sale.date_format %> + + <% end %> + + <% count = count + 1 %> + <% @hourly_total_qty.each do |hr| %> + <% if hr["date"].to_s == sale.date_format.to_s && hr["total_qty"].to_i ==sale_item_count%> + + + Total Qty: + + + <%= total_qty.to_i %> + <% total_qty = 0%> + + Grand Total: + + + <%= grand_total.to_i %> + <% grand_total = 0 %> + + + + <% footer_arr.push(sale.sale_id) %> + <% else %> + <% end %> + <% end %> + + <% end %> + +
    + + - \ No newline at end of file + From 919e6f61b3fc5e0913aa9d471b173b6fccba18ac Mon Sep 17 00:00:00 2001 From: Git Code2lab Date: Wed, 28 Aug 2019 11:57:33 +0000 Subject: [PATCH 03/20] Update puma.rb --- config/puma.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/puma.rb b/config/puma.rb index fd89392f..dcc85b12 100755 --- a/config/puma.rb +++ b/config/puma.rb @@ -8,3 +8,4 @@ stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/ port ENV.fetch("PORT") { 62158 } workers 2 preload_app! +threads 1,1 \ No newline at end of file From 06349e23cc001009f5413c60b97b6c9a30e9d28d Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Thu, 29 Aug 2019 18:33:13 +0630 Subject: [PATCH 04/20] - --- app/models/order.rb | 36 +++++++++++------------ app/views/api/shifts/create.json.jbuilder | 2 +- app/views/crm/customers/index.html.erb | 29 +++++++++--------- config/initializers/action_controller.rb | 10 +++---- config/puma.rb | 20 ++++++------- 5 files changed, 49 insertions(+), 48 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 26451207..00ecd4ca 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -41,14 +41,14 @@ class Order < ApplicationRecord :booking_status => "assign" }) end #end extra time - + if self.table_id.to_i > 0 table = DiningFacility.find(self.table_id) table.update_attributes(status:"occupied") # table.status = "occupied" # table.save end - + else booking = Booking.find(self.booking_id) #add extra time @@ -56,7 +56,7 @@ class Order < ApplicationRecord if !booking.checkout_at.nil? new_time = booking.checkout_at + self.extra_time.to_i booking.update_attributes(checkout_at: new_time) - end + end end #end extra time end @@ -74,7 +74,7 @@ class Order < ApplicationRecord #Send order to queue one it done! # if self.source != "quick_service" # process_order_queue - # end + # end #send order to broadcast job # send_order_broadcast(booking) @@ -138,7 +138,7 @@ class Order < ApplicationRecord ordered_list.each do |item| menu_item = MenuItem.search_by_item_code(item[:item_instance_code]) - + # For Product while item code not in menu item if menu_item.nil? menu_item = Product.search_by_product_code(item[:item_instance_code]) @@ -148,7 +148,7 @@ class Order < ApplicationRecord # Rails.logger.debug menu_item set_order_items = Array.new ##If menu Item set item - must add child items to order as well, where price is only take from menu_item - if (menu_item[:type] == "SetMenuItem") + if (menu_item[:type] == "SetMenuItem") if (item.include? 'sub_items') || (item.include? :sub_items) item[:sub_items].each do |si| # Retrive instance's Price @@ -286,7 +286,7 @@ class Order < ApplicationRecord # Counter number of quantityf end - + #Process order items and send to order queue def self.pay_process_order_queue(id,table_id) # if ENV["SERVER_MODE"] != 'cloud' @@ -294,7 +294,7 @@ class Order < ApplicationRecord if !sidekiq.nil? OrderQueueProcessorJob.perform_later(id, table_id) else - order = Order.find(id) + order = Order.find(id) if order oqs = OrderQueueStation.new oqs.process_order(order, table_id) @@ -314,11 +314,11 @@ class Order < ApplicationRecord # OrderBroadcastJob.perform_later(table,type) if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain - else + else from = "" end ActionCable.server.broadcast "order_channel",table: table,type:type,from:from - + end end @@ -434,7 +434,7 @@ class Order < ApplicationRecord if from.present? && to.present? order = Order.where("DATE_FORMAT(date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(date,'%d-%m-%Y') <= ?", from,to) query = order.where(keyword) - else + else where("order_id LIKE ? OR status LIKE ? OR order_type LIKE ? OR source='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%") end end @@ -442,12 +442,12 @@ class Order < ApplicationRecord def self.send_customer_view(booking) @status = "" @data_array = Array.new - if(!booking.sale_id.nil?) + if(!booking.sale_id.nil?) sale = Sale.find(booking.sale_id) if sale.sale_status != "completed" && sale.sale_status != 'void' @data_array.push(sale) @status = "sale" - @data_obj = sale + @data_obj = sale end else @@ -474,7 +474,7 @@ class Order < ApplicationRecord end if ENV["SERVER_MODE"] == 'cloud' from = request.subdomain + "." + request.domain - else + else from = "" end ActionCable.server.broadcast "second_display_channel",data: @data_array,status:@status,from:from @@ -484,11 +484,11 @@ class Order < ApplicationRecord def self.process_order_queue(order_id,table_id,source) print_status = nil cup_status = nil - + #Send to background job for processing - order = Order.find(order_id) + order = Order.find(order_id) sidekiq = Lookup.find_by_lookup_type("sidekiq") - + if ENV["SERVER_MODE"] != 'cloud' cup_status = `#{"sudo service cups status"}` print_status = check_cup_status(cup_status) @@ -526,7 +526,7 @@ class Order < ApplicationRecord else if ENV["SERVER_MODE"] != 'cloud' - msg = ' Print Error ! Please contact to service' + msg = ' Print Error ! Please contact to service' ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error' end if !sidekiq.nil? diff --git a/app/views/api/shifts/create.json.jbuilder b/app/views/api/shifts/create.json.jbuilder index c5b02c92..fd15892a 100644 --- a/app/views/api/shifts/create.json.jbuilder +++ b/app/views/api/shifts/create.json.jbuilder @@ -29,4 +29,4 @@ if @status == true else json.status false json.error_message @error_message -end \ No newline at end of file +end diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 55295c9e..d379b12b 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -62,7 +62,7 @@ <%end %> - +
    <%= paginate @crm_customers %> @@ -76,8 +76,8 @@ - + + --> @@ -122,8 +122,9 @@ <% end %> <%= crm_customer.card_no rescue '-' %> + <%= crm_customer.paypar_account_no rescue '-' %> - <% if crm_customer.membership_id.nil? && !crm_customer.membership_type.nil? && !crm_customer.membership_type =="" && !crm_customer.paypar_account_no =="" && !crm_customer.paypar_account_no.nil? %> + <% if crm_customer.membership_id.nil? && !crm_customer.membership_type.nil? && !crm_customer.membership_type.blank? && !crm_customer.paypar_account_no.blank? && !crm_customer.paypar_account_no.nil? %> <%= link_to t("views.btn.sync"), crm_customer_sync_path(crm_customer), :class => "btn btn-md bg-green waves-effect" %> <% end %> <% if @customer_update_phone_email_membertype %> @@ -138,7 +139,7 @@ <% end %> - +
    <% if @create_flag %> @@ -178,10 +179,10 @@ // QR Code Reader $("#qr_code").on('click', function(e){ - var code = ""; + var code = ""; setTimeout(function(){ code=getQRCode(); - setQRCode(code); + setQRCode(code); },100); }); @@ -199,12 +200,12 @@ /*new customer UI func:*/ //Initialize tooltips $('.nav-tabs > li a[title]').tooltip(); - + //Wizard $('a[data-toggle="tab"]').on('show.bs.tab', function (e) { var $target = $(e.target); - + if ($target.parent().hasClass('disabled')) { return false; } @@ -256,10 +257,10 @@ url: url, data: {}, dataType: "json", - success: function(data) { - // Selected for Taxes - var taxes = JSON.stringify(data.tax_profiles); - var parse_taxes = JSON.parse(taxes); + success: function(data) { + // Selected for Taxes + var taxes = JSON.stringify(data.tax_profiles); + var parse_taxes = JSON.parse(taxes); $.each(parse_taxes, function(i, value){ $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected").css({'color':'#fff','background':'#215d9c'}); }); @@ -272,7 +273,7 @@ $('#customer_salutation').val(data.salutation); $('#customer_nrc_no').val(data.nrc_no); $('#customer_card_no').val(data.card_no); - $('#customer_type').val(data.customer_type); + $('#customer_type').val(data.customer_type); $('#paypar_account_no').val(data.paypar_account_no); $('#customer_address').val(data.address); $('#customer_date_of_birth').val(data.date_of_birth); 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 fd89392f..6a545bed 100755 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,10 +1,10 @@ -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! +# 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! From f0be0d19a1ebadf5b2f3cb9552469765b29f89d5 Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Fri, 30 Aug 2019 14:03:48 +0630 Subject: [PATCH 05/20] nothing --- .../reports/hourly_saleitem_controller.rb | 3 ++ .../reports/saleitem_controller.rb | 2 +- app/models/printer/printer_worker.rb | 26 +++++++------- app/models/sale.rb | 2 +- .../reports/hourly_saleitem/index.html.erb | 36 ++++++++++--------- config/initializers/action_controller.rb | 10 +++--- config/puma.rb | 20 +++++------ 7 files changed, 52 insertions(+), 47 deletions(-) diff --git a/app/controllers/reports/hourly_saleitem_controller.rb b/app/controllers/reports/hourly_saleitem_controller.rb index 68883c68..893d4d17 100644 --- a/app/controllers/reports/hourly_saleitem_controller.rb +++ b/app/controllers/reports/hourly_saleitem_controller.rb @@ -56,7 +56,10 @@ class Reports::HourlySaleitemController < BaseReportController @shift_data = sh end end + # @hourly_total_qty = @sale_data.group_by {|s| s.date_format }.collect{|key,qty| {"date" => key , "total_qty" => qty.sum{|d| d.qty.to_i}}} + @hourly_total_qty = @sale_data.group_by(&:date_format).map { |k,v|{"date" => k , "total_qty" => v.count }} + puts @hourly_total_qty.to_json respond_to do |format| format.html format.xls diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index f3062d69..b581eae8 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -64,7 +64,7 @@ class Reports::SaleitemController < BaseReportController def show from, to, report_type = get_date_range_from_params @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) - sale_data = @sale_data + date_arr = Array.new @sale_data.each do |sale| local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p") diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index fee19a31..8bbf1c6d 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -38,20 +38,20 @@ class Printer::PrinterWorker end def print(file_path,printer_destination = nil ) - if printer_destination.nil? - printer_destination = self.printer_destination - end + # if printer_destination.nil? + # printer_destination = self.printer_destination + # end - puts printer_destination - puts '........Printer Destination..........' + # puts printer_destination + # puts '........Printer Destination..........' - copy = self.print_copies - #Print only when printer information is not null - if !self.printer_destination.nil? - (1..copy).each do - page = Cups::PrintJob.new(file_path, printer_destination) - page.print - end - end + # copy = self.print_copies + # #Print only when printer information is not null + # if !self.printer_destination.nil? + # (1..copy).each do + # page = Cups::PrintJob.new(file_path, printer_destination) + # page.print + # end + # end end end diff --git a/app/models/sale.rb b/app/models/sale.rb index acbb25b7..68620a1b 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1092,7 +1092,7 @@ def self.get_item_query(type) "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, " + "date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p') - as date_format") + as date_format") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id") diff --git a/app/views/reports/hourly_saleitem/index.html.erb b/app/views/reports/hourly_saleitem/index.html.erb index f5491203..e98f61a7 100644 --- a/app/views/reports/hourly_saleitem/index.html.erb +++ b/app/views/reports/hourly_saleitem/index.html.erb @@ -11,7 +11,7 @@
    <%= render :partial=>'shift_sale_report_filter', - :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_waste_and_spoilage_index_path} %> + :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_hourly_saleitem_index_path} %>
    <%= t("views.btn.exp_to_excel") %> @@ -21,6 +21,7 @@ <% time_arr = Array.new %> + <% sale_item_count =0 %> <% menu_cat_arr = Array.new %> <% footer_arr = Array.new %> <% count = 0 %> @@ -29,6 +30,7 @@ <% time_count = 0 %> <% @sale_data.each do |sale| %> <% if !time_arr.include?(sale.date_format) %> + <% sale_item_count =1 %> <% time_count = time_count + 1 %> @@ -52,6 +54,9 @@ <% time_arr.push(sale.date_format) %> <% menu_cat_arr.clear %> <% count = 0 %> + <% else %> + <%= time_arr %> + <% sale_item_count =sale_item_count +1 %> <% end %> @@ -85,24 +90,21 @@ <% end %> - - <% count = count + 1 %> - <% logger.debug ' normal count+++++++++++++++++++++++++' %> - <% logger.debug sale.sale_items.count %> - <% logger.debug 'time_count count------------------------------------' %> - <% logger.debug time_count %> - <% if sale.sale_items.count == count %> - - - - - - - - <% footer_arr.push(sale.sale_id) %> - <% end %> + <% @hourly_total_qty.each do |hr| %> + <% if hr["date"].to_s == sale.date_format.to_s && hr["total_qty"].to_i ==sale_item_count%> + + + + + + + + <% footer_arr.push(sale.sale_id) %> + <% total_qty =0%> + <% end %> + <% end %> <% end %> 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 fd89392f..6a545bed 100755 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,10 +1,10 @@ -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! +# 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! From 9b0e77674e0c469e4b7b111b1b1281d765b8ff3c Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Mon, 2 Sep 2019 16:22:09 +0630 Subject: [PATCH 06/20] update sale item xls --- .../reports/saleitem_controller.rb | 3 +-- app/views/reports/saleitem/index.xls.erb | 12 ----------- config/initializers/action_controller.rb | 10 +++++----- config/puma.rb | 20 +++++++++---------- 4 files changed, 16 insertions(+), 29 deletions(-) diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index b581eae8..0d339fd6 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -54,8 +54,7 @@ class Reports::SaleitemController < BaseReportController @shift_data = sh end end - - respond_to do |format| + respond_to do |format| format.html format.xls end diff --git a/app/views/reports/saleitem/index.xls.erb b/app/views/reports/saleitem/index.xls.erb index 8f326e27..1b5dd998 100755 --- a/app/views/reports/saleitem/index.xls.erb +++ b/app/views/reports/saleitem/index.xls.erb @@ -108,12 +108,7 @@ <% end %> - <% if !cate_arr.include?(sale.menu_category_id) %> - <% cate_arr.push(sale.menu_category_id) %> - <% else %> - - <% end %> <% if sale.status_type != "Discount" %> @@ -143,13 +138,6 @@ sub_qty += sale.total_item end %> <% if count == value %> - - - - - - - <% sub_total = 0.0%> <% sub_qty = 0 %> <% count = 0%> diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 85f38ec5..205c330a 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 6a545bed..fd89392f 100755 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,10 +1,10 @@ -# 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! +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! From b00b9fc75c20e5f52eaa1de726cd9808bdeb3497 Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Tue, 3 Sep 2019 17:33:27 +0630 Subject: [PATCH 07/20] sync receipt --- app/models/assigned_order_item.rb | 4 +++- app/models/booking.rb | 4 +++- app/models/order.rb | 4 +++- app/models/order_item.rb | 4 +++- app/models/printer/printer_worker.rb | 26 +++++++++++++------------- app/models/sale.rb | 4 +++- app/models/sale_audit.rb | 4 +++- app/models/sale_item.rb | 4 +++- app/models/sale_order.rb | 6 ++++-- app/models/sale_payment.rb | 4 +++- app/models/sale_tax.rb | 4 +++- 11 files changed, 44 insertions(+), 24 deletions(-) diff --git a/app/models/assigned_order_item.rb b/app/models/assigned_order_item.rb index 9359fd66..c1b0162e 100755 --- a/app/models/assigned_order_item.rb +++ b/app/models/assigned_order_item.rb @@ -64,6 +64,8 @@ class AssignedOrderItem < ApplicationRecord private def generate_custom_id - self.assigned_order_item_id = SeedGenerator.generate_id(self.class.name, "AOI") + if self.assigned_order_item_id.nil? + self.assigned_order_item_id = SeedGenerator.generate_id(self.class.name, "AOI") + end end end diff --git a/app/models/booking.rb b/app/models/booking.rb index 374dd0cf..e4afb8c7 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -122,6 +122,8 @@ class Booking < ApplicationRecord private def generate_custom_id - self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI") + if self.booking_id.nil? + self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI") + end end end diff --git a/app/models/order.rb b/app/models/order.rb index 26451207..f53eb7e8 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -557,7 +557,9 @@ class Order < ApplicationRecord private def generate_custom_id - self.order_id = SeedGenerator.generate_id(self.class.name, "ODR") + if self.order_id.nil? + self.order_id = SeedGenerator.generate_id(self.class.name, "ODR") + end end def set_order_date diff --git a/app/models/order_item.rb b/app/models/order_item.rb index c5d715f3..0ac03e9b 100755 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -97,6 +97,8 @@ class OrderItem < ApplicationRecord private def generate_custom_id - self.order_items_id = SeedGenerator.generate_id(self.class.name, "ODI") + if self.order_items_id.nil? + self.order_items_id = SeedGenerator.generate_id(self.class.name, "ODI") + end end end diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index 8bbf1c6d..fee19a31 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -38,20 +38,20 @@ class Printer::PrinterWorker end def print(file_path,printer_destination = nil ) - # if printer_destination.nil? - # printer_destination = self.printer_destination - # end + if printer_destination.nil? + printer_destination = self.printer_destination + end - # puts printer_destination - # puts '........Printer Destination..........' + puts printer_destination + puts '........Printer Destination..........' - # copy = self.print_copies - # #Print only when printer information is not null - # if !self.printer_destination.nil? - # (1..copy).each do - # page = Cups::PrintJob.new(file_path, printer_destination) - # page.print - # end - # end + copy = self.print_copies + #Print only when printer information is not null + if !self.printer_destination.nil? + (1..copy).each do + page = Cups::PrintJob.new(file_path, printer_destination) + page.print + end + end end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 56377de5..8f5c7eb0 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -2951,6 +2951,8 @@ end private def generate_custom_id - self.sale_id = SeedGenerator.generate_id(self.class.name, "SAL") + if self.sale_id.nil? + self.sale_id = SeedGenerator.generate_id(self.class.name, "SAL") + end end end diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index 36734ec1..d96034ad 100755 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -176,6 +176,8 @@ class SaleAudit < ApplicationRecord private def generate_custom_id - self.sale_audit_id = SeedGenerator.generate_id(self.class.name, "SAI") + if self.sale_audit_id.nil? + self.sale_audit_id = SeedGenerator.generate_id(self.class.name, "SAI") + end end end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index d8be28b7..b8ada0ed 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -223,6 +223,8 @@ class SaleItem < ApplicationRecord private def generate_custom_id - self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI") + if self.sale_item_id.nil? + self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI") + end end end diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index ab50e228..bbd68829 100755 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -34,7 +34,9 @@ class SaleOrder < ApplicationRecord private def generate_sale_order_id # self.class.name - saleOrderId = SeedGenerator.generate_id(self.class.name, 'SOI') - self.sale_order_id = saleOrderId + if self.sale_order_id.nil? + self.sale_order_id = SeedGenerator.generate_id(self.class.name, 'SOI') + end + end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 4808860a..7050eb25 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -1065,6 +1065,8 @@ class SalePayment < ApplicationRecord private def generate_custom_id - self.sale_payment_id = SeedGenerator.generate_id(self.class.name, "SPI") + if self.sale_payment_id.nil? + self.sale_payment_id = SeedGenerator.generate_id(self.class.name, "SPI") + end end end diff --git a/app/models/sale_tax.rb b/app/models/sale_tax.rb index bd89ec1b..06c73253 100755 --- a/app/models/sale_tax.rb +++ b/app/models/sale_tax.rb @@ -34,6 +34,8 @@ class SaleTax < ApplicationRecord private def generate_custom_id - self.sale_tax_id = SeedGenerator.generate_id(self.class.name, "STI") + if self.sale_tax_id.nil? + self.sale_tax_id = SeedGenerator.generate_id(self.class.name, "STI") + end end end From f3f74db446ffaa0e0ea6c5c4e30dca3c61b1210a Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Tue, 3 Sep 2019 18:29:57 +0630 Subject: [PATCH 08/20] delete puts in employee --- app/controllers/settings/employees_controller.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/controllers/settings/employees_controller.rb b/app/controllers/settings/employees_controller.rb index baefd752..c416cc87 100755 --- a/app/controllers/settings/employees_controller.rb +++ b/app/controllers/settings/employees_controller.rb @@ -30,9 +30,6 @@ class Settings::EmployeesController < ApplicationController # POST /employees # POST /employees.json def create - puts "puts ssssssssssssssssssssssssss" - puts employee_params.to_json - @employee = Employee.new(employee_params) respond_to do |format| From 34c3dc47ae006dea9836edf946b9d242b08b9982 Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Wed, 4 Sep 2019 18:19:06 +0630 Subject: [PATCH 09/20] discount --- app/assets/stylesheets/origami.scss | 7 ------ app/models/printer/printer_worker.rb | 26 +++++++++++----------- app/models/sale_payment.rb | 4 +--- app/views/origami/discounts/index.html.erb | 21 ++++++++++++----- config/initializers/action_controller.rb | 10 ++++----- config/puma.rb | 22 +++++++++--------- 6 files changed, 46 insertions(+), 44 deletions(-) diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 6bbce5a3..64cc2937 100755 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -298,13 +298,6 @@ select.form-control { /* Discount */ -.discount-item-row { - cursor: pointer; -} - -tr.discount-item-row:hover { - background-color: #e3e3e3 !important; -} .required abbr{ color: red !important; } diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index fee19a31..8bbf1c6d 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -38,20 +38,20 @@ class Printer::PrinterWorker end def print(file_path,printer_destination = nil ) - if printer_destination.nil? - printer_destination = self.printer_destination - end + # if printer_destination.nil? + # printer_destination = self.printer_destination + # end - puts printer_destination - puts '........Printer Destination..........' + # puts printer_destination + # puts '........Printer Destination..........' - copy = self.print_copies - #Print only when printer information is not null - if !self.printer_destination.nil? - (1..copy).each do - page = Cups::PrintJob.new(file_path, printer_destination) - page.print - end - end + # copy = self.print_copies + # #Print only when printer information is not null + # if !self.printer_destination.nil? + # (1..copy).each do + # page = Cups::PrintJob.new(file_path, printer_destination) + # page.print + # end + # end end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 7050eb25..2574c7f9 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -395,7 +395,6 @@ class SalePayment < ApplicationRecord self.payment_status = "paid" payment_status = self.save! - if !payment_for sale_update_payment_status(self.received_amount,status) end @@ -661,8 +660,7 @@ class SalePayment < ApplicationRecord method_status = true end end - - if (self.sale.grand_total <= all_received_amount) && method_status + if (self.sale.grand_total.round <= all_received_amount) && method_status if is_credit == 0 self.sale.payment_status = "paid" else diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index e23e4e6f..55144c41 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -50,6 +50,7 @@ >
     
    <%= sale.date_format %>
     Total Qty:<%= total_qty%>Grand Total:
     Total Qty:<%= total_qty%>Grand Total:
     <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %> <%= sale.product_name rescue '-' %>
     Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%>
    + <%=sale_item.product_name%>@<%=sale_item.unit_price%> @@ -313,10 +314,13 @@ var cashier_type = "<%= @cashier_type %>"; // Select Sale Item $('.item-row').on('click',function(){ if($(this).hasClass('selected-item') == true){ - $(this).removeClass('selected-item'); + $(this).removeClass('selected-item'); } else { - $(this).addClass('selected-item'); + if(parseInt($(this).children().find("#item-account-qty").text()) >0 && parseInt($(this).children().find("#item-total-price").text()) >0){ + + $(this).addClass('selected-item'); + } } }); @@ -326,14 +330,16 @@ var cashier_type = "<%= @cashier_type %>"; $(this).removeClass('selected-item'); } else { - $(this).addClass('selected-item'); + if(parseInt($(this).children().find("#item-account-qty").text()) >0 && parseInt($(this).children().find("#item-total-price").text()) >0){ + + $(this).addClass('selected-item'); + } } }); // Select for account types $(".accounts-type").on('click', function(e){ var account_id = $(this).attr('id').substr(8); - if($(this).hasClass('selected-account') == true){ $(this).removeClass('selected-account'); $(".item-row").each(function(i){ @@ -346,7 +352,12 @@ var cashier_type = "<%= @cashier_type %>"; $(this).addClass('selected-account'); $(".item-row").each(function(i){ if($(this).children().find("#item-account-type").text() == account_id){ - $(this).addClass("selected-item"); + if(parseInt($(this).children().find("#item-account-qty").text()) >0 && parseInt($(this).children().find("#item-total-price").text()) >0){ + $(this).addClass("selected-item"); + } + else{ + console.log("discount item"); + } } }); } 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 dcc85b12..66214eff 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 \ No newline at end of file +# 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 \ No newline at end of file From 1ced4a3d6dc991f0f75cde34cd29751bc026f504 Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Thu, 5 Sep 2019 11:57:26 +0630 Subject: [PATCH 10/20] discount --- app/models/printer/printer_worker.rb | 26 ++++++++++++------------ app/models/sale_payment.rb | 2 +- config/initializers/action_controller.rb | 10 ++++----- config/puma.rb | 22 ++++++++++---------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index 8bbf1c6d..fee19a31 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -38,20 +38,20 @@ class Printer::PrinterWorker end def print(file_path,printer_destination = nil ) - # if printer_destination.nil? - # printer_destination = self.printer_destination - # end + if printer_destination.nil? + printer_destination = self.printer_destination + end - # puts printer_destination - # puts '........Printer Destination..........' + puts printer_destination + puts '........Printer Destination..........' - # copy = self.print_copies - # #Print only when printer information is not null - # if !self.printer_destination.nil? - # (1..copy).each do - # page = Cups::PrintJob.new(file_path, printer_destination) - # page.print - # end - # end + copy = self.print_copies + #Print only when printer information is not null + if !self.printer_destination.nil? + (1..copy).each do + page = Cups::PrintJob.new(file_path, printer_destination) + page.print + end + end end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 2574c7f9..42a4452c 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -660,7 +660,7 @@ class SalePayment < ApplicationRecord method_status = true end end - if (self.sale.grand_total.round <= all_received_amount) && method_status + if (self.sale.grand_total <= all_received_amount) && method_status if is_credit == 0 self.sale.payment_status = "paid" else diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 85f38ec5..205c330a 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 66214eff..dcc85b12 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 \ No newline at end of file +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 \ No newline at end of file From 258aba669bdf32a954371897e0967bb04d683bf9 Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Thu, 5 Sep 2019 18:12:17 +0630 Subject: [PATCH 11/20] precision --- .../origami/discounts_controller.rb | 2 ++ app/controllers/origami/home_controller.rb | 3 ++- app/models/sale.rb | 15 +++++++++++ app/views/origami/discounts/index.html.erb | 26 ++++++++++++++----- app/views/origami/home/show.html.erb | 24 +++++++++++++---- 5 files changed, 58 insertions(+), 12 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 22092a50..cd73d174 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -3,6 +3,8 @@ class Origami::DiscountsController < BaseOrigamiController #discount page show from origami index with selected order def index + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() @webview = false if check_mobile @webview = true diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 2ba8cd3e..fe074210 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -17,7 +17,8 @@ class Origami::HomeController < BaseOrigamiController # origami table detail def show - + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() @webview = check_mobile @tables = Table.unscoped.all.active.order('status desc') diff --git a/app/models/sale.rb b/app/models/sale.rb index 8f5c7eb0..2c451b5b 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -452,6 +452,7 @@ class Sale < ApplicationRecord self.total_amount = subtotal_price self.total_discount = total_discount self.grand_total = (self.total_amount - self.total_discount) + self.total_tax + self.grand_total_round #compute rounding adjustment adjust_rounding @@ -461,6 +462,7 @@ class Sale < ApplicationRecord #compute - invoice total def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil,tax_type=nil) + shop = Shop.first sale = Sale.find(sale_id) sales_items = sale_itemss @@ -484,6 +486,7 @@ class Sale < ApplicationRecord sale.total_amount = subtotal_price sale.total_discount = total_discount sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax + sale.grand_total_round if discount_type == "member_discount" sale.discount_type = discount_type end @@ -519,6 +522,7 @@ class Sale < ApplicationRecord self.total_amount = subtotal_price self.total_discount = total_discount self.grand_total = (self.total_amount - self.total_discount) + self.total_tax + self.grand_total_round #compute rounding adjustment adjust_rounding @@ -2948,6 +2952,17 @@ end # End hourly sale item report + +#not to show decimal in grand total +def grand_total_round + shop =Shop.first + print_settings = PrintSetting.get_precision_delimiter() + if !print_settings.nil? + self.grand_total =self.grand_total.round(print_settings.precision.to_i) + puts self.grand_total + puts "Hello grand_total_round" + end +end private def generate_custom_id diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 55144c41..cb7fe255 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -2,6 +2,20 @@ + <% if !@print_settings.nil? %> + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + <% end %>
    @@ -72,7 +86,7 @@ - +
    @@ -350,7 +364,7 @@
    Sub Total:<%=sub_total%><%= number_with_precision(sub_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    - + <%if @obj_sale != nil && @obj_sale.discount_type == 'member_discount'%> @@ -359,7 +373,7 @@ <%end%> - + <% if @status_sale == "sale" %> @@ -382,15 +396,15 @@ <% end %> - + - + - + <% end %> From e5917d634de0411adfbce8efcb70e5355956123c Mon Sep 17 00:00:00 2001 From: Aung Ye Kyaw Date: Fri, 6 Sep 2019 07:40:01 +0000 Subject: [PATCH 12/20] Update Gemfile by AYK bundle install Error sassc -v '1.12.1' --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 33a88bd0..44670eda 100644 --- a/Gemfile +++ b/Gemfile @@ -41,7 +41,7 @@ gem 'rack-cors' # image upload gem 'carrierwave', '~> 1.0' gem 'mini_magick' -gem 'jquery-fileupload-rails' +gem 'jquery-fileupload-rails', '~> 0.4.7' #Report and Printing gems gem 'cups' From ac2449931925a75d13d415f5a300c29793b1f2ed Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Tue, 10 Sep 2019 13:12:41 +0630 Subject: [PATCH 13/20] foc --- Gemfile.lock | 23 +++++++++---------- app/controllers/origami/void_controller.rb | 2 +- app/models/sale.rb | 26 +++++++++++----------- app/models/sale_item.rb | 6 +++-- app/models/sale_payment.rb | 3 ++- app/views/layouts/_left_sidebar.html.erb | 8 +++---- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1b1180a1..4c36f330 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,7 +47,7 @@ GEM minitest (~> 5.1) tzinfo (~> 1.1) aescrypt (1.0.0) - airbrussh (1.3.2) + airbrussh (1.3.3) sshkit (>= 1.6.1, != 1.7.0) arel (8.0.0) axlsx (2.0.1) @@ -62,7 +62,7 @@ GEM builder (3.2.3) byebug (11.0.1) cancancan (1.17.0) - capistrano (3.11.0) + capistrano (3.11.1) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -99,8 +99,8 @@ GEM factory_girl_rails (4.9.0) factory_girl (~> 4.9.0) railties (>= 3.0.0) - faker (2.1.0) - i18n (>= 0.7) + faker (2.2.2) + i18n (~> 1.6.0) ffi (1.11.1) filterrific (5.2.1) font-awesome-rails (4.7.0.5) @@ -148,9 +148,9 @@ GEM material_icons (2.2.1) railties (>= 3.2) method_source (0.9.2) - mime-types (3.2.2) + mime-types (3.3) mime-types-data (~> 3.2015) - mime-types-data (3.2019.0331) + mime-types-data (3.2019.0904) mini_magick (4.9.5) mini_mime (1.0.2) mini_portile2 (2.4.0) @@ -163,8 +163,8 @@ GEM net-scp (2.0.0) net-ssh (>= 2.6.5, < 6.0.0) net-ssh (5.2.0) - nio4r (2.4.0) - nokogiri (1.10.3) + nio4r (2.5.1) + nokogiri (1.10.4) mini_portile2 (~> 2.4.0) pdf-core (0.7.0) pdfjs_viewer-rails (0.3.1) @@ -183,7 +183,7 @@ GEM puma (3.12.1) rack (2.0.7) rack-cors (1.0.3) - rack-protection (2.0.5) + rack-protection (2.0.7) rack rack-test (1.1.0) rack (>= 1.0, < 3) @@ -202,7 +202,7 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.1.0) + rails-html-sanitizer (1.2.0) loofah (~> 2.2, >= 2.2.2) railties (5.1.7) actionpack (= 5.1.7) @@ -251,9 +251,8 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sassc (2.0.1) + sassc (2.2.0) ffi (~> 1.9) - rake schema_to_scaffold (0.8.0) activesupport (>= 3.2.1) shoulda-matchers (3.1.3) diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 980fd6bd..0523023e 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -8,7 +8,7 @@ class Origami::VoidController < BaseOrigamiController access_code = params[:access_code] if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) - + puts sale.to_json if sale.discount_type == "member_discount" sale.update_attributes(total_discount: 0) sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source) diff --git a/app/models/sale.rb b/app/models/sale.rb index 2c451b5b..95bbe525 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -461,7 +461,7 @@ class Sale < ApplicationRecord end #compute - invoice total - def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil,tax_type=nil) + def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil,tax_type=nil,type=nil) shop = Shop.first sale = Sale.find(sale_id) sales_items = sale_itemss @@ -473,20 +473,23 @@ class Sale < ApplicationRecord sales_items.each do |item| #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 if item.is_taxable total_taxable = total_taxable + item.taxable_price end end - compute_tax(sale, total_taxable, total_discount, order_source, tax_type) - sale.total_amount = subtotal_price sale.total_discount = total_discount - sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax - sale.grand_total_round + if type =="foc" + sale.grand_total = 0 + else + sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax + sale.grand_total_round + end + if discount_type == "member_discount" sale.discount_type = discount_type end @@ -2955,13 +2958,10 @@ end #not to show decimal in grand total def grand_total_round - shop =Shop.first - print_settings = PrintSetting.get_precision_delimiter() - if !print_settings.nil? - self.grand_total =self.grand_total.round(print_settings.precision.to_i) - puts self.grand_total - puts "Hello grand_total_round" - end + print_settings = PrintSetting.get_precision_delimiter() + if !print_settings.nil? + self.grand_total =self.grand_total.round(print_settings.precision.to_i) + end end private diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index b8ada0ed..bd97e5c5 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -85,8 +85,10 @@ class SaleItem < ApplicationRecord # sale_item.is_taxable = 1 # sale_item.sale_id = sale_id # sale_item.save - sale = Sale.find(sale_id) - sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount) + if type != "foc" + sale = Sale.find(sale_id) + sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount) + end end def self.get_order_items_details(sale_id) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 42a4452c..2e1700f8 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -82,7 +82,6 @@ class SalePayment < ApplicationRecord amount_due = amount_due - payment.payment_amount end end - if (amount_due >= 0) payment_status = false membership_data = nil @@ -419,6 +418,8 @@ class SalePayment < ApplicationRecord sale_items.each do|item| SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) end + sale = Sale.find(self.sale.sale_id) + sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount,'','','',"foc") self.payment_method = "foc" self.payment_amount = self.received_amount diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index 4fee71b1..c948964d 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -103,9 +103,9 @@
  • Sale Items
  • -
  • + <% if order_reservation %>
  • <%= t("views.right_panel.detail.order_reservation") %> @@ -289,9 +289,9 @@
  • Hourly Sale Items
  • -
  • + <% if order_reservation %>
  • <%= t("views.right_panel.detail.order_reservation") %> From 90d0a4ebb1e5168912e538cca66d0ea80fd2a184 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Wed, 11 Sep 2019 13:26:01 +0630 Subject: [PATCH 14/20] fixed inventory --- .../reports/stock_check_controller.rb | 3 +- app/models/inventory_definition.rb | 38 +++++++++++++------ app/models/stock_check_item.rb | 23 +++++++---- app/models/stock_journal.rb | 12 ++++-- .../inventory/_inventory_list.html.erb | 12 +++--- 5 files changed, 57 insertions(+), 31 deletions(-) diff --git a/app/controllers/reports/stock_check_controller.rb b/app/controllers/reports/stock_check_controller.rb index c2f2cf0d..71fc389e 100755 --- a/app/controllers/reports/stock_check_controller.rb +++ b/app/controllers/reports/stock_check_controller.rb @@ -46,6 +46,5 @@ class Reports::StockCheckController < BaseReportController format.json { render json: out } end end - -end +end diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index 189d8dc7..dc2e1052 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -35,7 +35,7 @@ class InventoryDefinition < ApplicationRecord end def self.check_balance(item,inventory_definition) # item => saleItemOBj - stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first + stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first unless stock.nil? modify_balance(item, stock, inventory_definition) else @@ -44,9 +44,12 @@ class InventoryDefinition < ApplicationRecord end def self.modify_balance(item, stock, inventory_definition) #saleitemObj + check_item = StockCheckItem.where('item_code=?', item.item_instance_code).order("id DESC").first if stock.balance.to_i >= item.qty puts ">> stock is greater than order qty" StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition) + check_item.different = check_item.different - item.qty + check_item.save else puts " << stock is less than order qty" data = item @@ -56,8 +59,12 @@ class InventoryDefinition < ApplicationRecord StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition) data.qty = extra_qty StockJournal.add_to_journal(data, 0, "out of stock", inventory_definition) + check_item.different = check_item.different - item.qty + check_item.save else StockJournal.add_to_journal(item, stock.balance, "out of stock", inventory_definition) + check_item.different = check_item.different - item.qty + check_item.save end end end @@ -72,17 +79,24 @@ class InventoryDefinition < ApplicationRecord " JOIN menu_categories mc ON mc.id = mi.menu_category_id ") .where("mc.id=#{cat_id}") .group("mi.menu_category_id,inventory_definitions.item_code") - .order("mi.menu_category_id desc") + .order("mi.menu_category_id desc") end def self.get_by_category(filter) - least_stock = "SELECT (CASE WHEN stock_journals.remark != 'out of stock' - THEN (SELECT min(balance) FROM stock_journals - WHERE item_code = inventory_definitions.item_code AND remark != 'out of stock' - ORDER BY created_at DESC LIMIT 1) ELSE 0 END) - FROM stock_journals - WHERE stock_journals.item_code = inventory_definitions.item_code - ORDER BY stock_journals.created_at DESC LIMIT 1" + # THEN (SELECT min(balance) FROM stock_journals + # least_stock = "SELECT (CASE WHEN stock_journals.remark != 'out of stock' + # THEN (SELECT balance FROM stock_journals + # WHERE item_code = inventory_definitions.item_code AND remark != 'out of stock' + # ORDER BY created_at DESC LIMIT 1) ELSE 0 END) + # FROM stock_journals + # WHERE stock_journals.item_code = inventory_definitions.item_code + # ORDER BY stock_journals.created_at DESC LIMIT 1" + least_stock = "(SELECT + (SELECT balance FROM stock_journals WHERE item_code = inventory_definitions.item_code + ORDER BY created_at DESC LIMIT 1) + FROM stock_journals + WHERE stock_journals.item_code = inventory_definitions.item_code + ORDER BY stock_journals.created_at DESC LIMIT 1)" @inventory_definitions = InventoryDefinition.select("inventory_definitions.*, (CASE WHEN sj.credit IS NULL THEN 0 ELSE sj.credit END) as credit, @@ -92,13 +106,13 @@ class InventoryDefinition < ApplicationRecord mii.item_instance_name as instance_name," + "mc.name as menu_category_name,mc.id as menu_category_id " ) - .joins(" LEFT JOIN stock_journals sj ON sj.inventory_definition_id=inventory_definitions.id") + .joins(" LEFT JOIN stock_journals sj ON sj.inventory_definition_id=inventory_definitions.id") .joins("JOIN menu_item_instances mii ON mii.item_instance_code = inventory_definitions.item_code" + " JOIN menu_items mi ON mi.id = mii.menu_item_id" + " JOIN menu_categories mc ON mc.id = mi.menu_category_id ") .joins(" JOIN accounts acc ON acc.id = mi.account_id") - .where("inventory_definitions.item_code LIKE ? OR inventory_definitions.min_order_level LIKE ? - OR inventory_definitions.max_stock_level LIKE ? OR sj.balance LIKE ? OR mi.name LIKE ? + .where("inventory_definitions.item_code LIKE ? OR inventory_definitions.min_order_level LIKE ? + OR inventory_definitions.max_stock_level LIKE ? OR sj.balance LIKE ? OR mi.name LIKE ? OR mii.item_instance_name LIKE ? OR mc.name LIKE ?","%#{filter}%","%#{filter}%","%#{filter}%", "%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%") .group("mi.menu_category_id,inventory_definitions.item_code") diff --git a/app/models/stock_check_item.rb b/app/models/stock_check_item.rb index 67e8b3aa..f596740a 100755 --- a/app/models/stock_check_item.rb +++ b/app/models/stock_check_item.rb @@ -2,7 +2,13 @@ class StockCheckItem < ApplicationRecord belongs_to :stock_check def create(stock_id, item) - journal_id, balance = StockCheckItem.find_journal(item['sku']) + check_item = StockCheckItem.find_by_item_code(item['sku']) + if check_item.nil? + balance = 0 + else + balance = StockCheckItem.last.different + end + journal_id = StockCheckItem.find_journal(item['sku']) remark, different = StockCheckItem.stock_different(item['qty'], balance ) self.stock_check_id = stock_id self.item_code = item['sku'] @@ -24,13 +30,14 @@ class StockCheckItem < ApplicationRecord end def self.stock_different(stock_check_qty, journal_balance) - if stock_check_qty.to_i == journal_balance.to_i - return 'match', stock_check_qty - elsif stock_check_qty.to_i > journal_balance.to_i - return 'missing order item', stock_check_qty.to_i - journal_balance.to_i - elsif stock_check_qty.to_i < journal_balance.to_i - return 'missing stock', stock_check_qty.to_i - journal_balance.to_i - end + # if stock_check_qty.to_i == journal_balance.to_i + # return 'match', stock_check_qty + # elsif stock_check_qty.to_i > journal_balance.to_i + # return 'missing order item', stock_check_qty.to_i - journal_balance.to_i + # elsif stock_check_qty.to_i < journal_balance.to_i + # return 'missing stock', stock_check_qty.to_i - journal_balance.to_i + # end + return 'add new stock', stock_check_qty.to_i + journal_balance.to_i end def self.get_transaction(from, to, item_code) diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index 9a30d3b0..fc969199 100755 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -8,7 +8,7 @@ class StockJournal < ApplicationRecord journal.credit = balance balance = calculate_balance(balance, item.qty) - + journal.item_code = item.item_instance_code journal.inventory_definition_id = inventory_definition.id journal.debit = item.qty @@ -24,13 +24,19 @@ class StockJournal < ApplicationRecord end def self.from_stock_check(item) + stock_journal = StockJournal.where('item_code=?', item.item_code).order("id DESC").first + if stock_journal.nil? + old_blance = 0 + else + old_blance = stock_journal.balance + end definition_id = InventoryDefinition.find_by_item_code(item.item_code) journal = StockJournal.new journal.item_code = item.item_code journal.inventory_definition_id = definition_id.id journal.debit = 0 journal.credit = item.stock_count - journal.balance = item.stock_count + journal.balance = item.stock_count + old_blance.to_i journal.remark = StockJournal::STOCK_CHECK_TRANS journal.trans_ref = item.id journal.trans_type = StockJournal::STOCK_CHECK_TRANS @@ -43,7 +49,7 @@ class StockJournal < ApplicationRecord .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") if !from_time.nil? && !to_time.nil? query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") - else + else query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") end query = query.group("mii.item_instance_name") diff --git a/app/views/inventory/inventory/_inventory_list.html.erb b/app/views/inventory/inventory/_inventory_list.html.erb index 0f4813f2..682188cd 100755 --- a/app/views/inventory/inventory/_inventory_list.html.erb +++ b/app/views/inventory/inventory/_inventory_list.html.erb @@ -10,16 +10,16 @@ - <% cate_arr = Array.new %> + <% cate_arr = Array.new %> <% - count = 0 - @inventory_definitions.each do |item| + count = 0 + @inventory_definitions.each do |item| count += 1 - %> + %>
  • - <% if !cate_arr.include?(item.menu_category_id) %> + <% if !cate_arr.include?(item.menu_category_id) %> <% cate_arr.push(item.menu_category_id) %> <% else %> @@ -72,4 +72,4 @@ window.location.href = '/inventory/'+ID+'/show'; }); - \ No newline at end of file + From a4e88692341b0d544808b1d6fc6c2410524e43d4 Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Wed, 11 Sep 2019 17:12:15 +0630 Subject: [PATCH 15/20] add foc amount in saleitem report --- app/controllers/origami/void_controller.rb | 1 - app/views/reports/saleitem/index.html.erb | 18 ++++++++++++--- app/views/reports/saleitem/index.xls.erb | 27 +++++++++++++++++++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 0523023e..6af6c275 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -8,7 +8,6 @@ class Origami::VoidController < BaseOrigamiController access_code = params[:access_code] if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) - puts sale.to_json if sale.discount_type == "member_discount" sale.update_attributes(total_discount: 0) sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source) diff --git a/app/views/reports/saleitem/index.html.erb b/app/views/reports/saleitem/index.html.erb index a56d6808..5abe8a0b 100644 --- a/app/views/reports/saleitem/index.html.erb +++ b/app/views/reports/saleitem/index.html.erb @@ -95,7 +95,6 @@ total_qty += sale.total_item*(-1) end %> - <% if sale.status_type == "foc" && sale.grand_total < 0 total_item_foc += sale.grand_total*(-1) end %> @@ -249,9 +248,21 @@ - - + + + <% if @type =="" || @type =="all" || @type.nil? %> + + + + + + + + + + + <% end %> <% end %> <% if @type == "other"%> @@ -296,6 +307,7 @@ \ No newline at end of file From 4668c974fd2fe769975263cd45658972f583d8cb Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Wed, 11 Sep 2019 18:17:16 +0630 Subject: [PATCH 16/20] nett --- app/views/origami/discounts/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index cb7fe255..3b14e05a 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -726,7 +726,7 @@ function calculate_overall_discount(type, amount){ } } - $("#order-discount").text(total_discount.toFixed(<%= precision.to_i %>)); + $("#order-discount").text(parseFloat(total_discount).toFixed(<%= precision.to_i %>)); } /* Calculate Items Discount*/ From 719d5637c2d1ea819bcd1e10a17169b7f466378c Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Thu, 12 Sep 2019 11:03:25 +0630 Subject: [PATCH 17/20] button disabled --- Gemfile.lock | 8 +++----- app/views/origami/home/show.html.erb | 1 + app/views/origami/payments/show.html.erb | 3 +++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 4c36f330..f8bb0d6c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,10 +114,10 @@ GEM concurrent-ruby (~> 1.0) jbuilder (2.9.1) activesupport (>= 4.2.0) - jquery-fileupload-rails (1.0.0) + jquery-fileupload-rails (0.4.7) actionpack (>= 3.1) railties (>= 3.1) - sassc + sass (>= 3.2) jquery-rails (4.3.5) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -251,8 +251,6 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - sassc (2.2.0) - ffi (~> 1.9) schema_to_scaffold (0.8.0) activesupport (>= 3.2.1) shoulda-matchers (3.1.3) @@ -332,7 +330,7 @@ DEPENDENCIES font-awesome-rails (~> 4.7, >= 4.7.0.2) httparty (~> 0.15.5) jbuilder (~> 2.5) - jquery-fileupload-rails + jquery-fileupload-rails (~> 0.4.7) jquery-rails jquery-ui-rails kaminari (~> 1.0.1) diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index ffcf0efb..e8074fe2 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -1265,6 +1265,7 @@ closeOnConfirm: false }, function (isConfirm) { if (isConfirm) { + $('.confirm').prop("disabled",true); var sale_id = $("#sale_id").val();//"<%= @obj_sale.sale_id rescue "" %>" var ajax_url = "/origami/sale/" + sale_id + '/cashier/void'; var remark = $("#remark").val(); diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index ab62eb7e..a40f7f58 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -1511,6 +1511,7 @@ $(document).ready(function(){ closeOnConfirm: false }, function (isConfirm) { if (isConfirm) { + $('.confirm').prop("disabled",true); $.ajax({ type: "POST", url: "/origami/payment/"+cashier_type+"/foc", @@ -1558,6 +1559,7 @@ $(document).ready(function(){ closeOnConfirm: false }, function (isConfirm) { if (isConfirm) { + $('.confirm').prop("disabled",true); var sale_id = $('#sale_id').text(); var remark = $("#remark").val(); var ajax_url = "/origami/sale/" + sale_id +'/'+cashier_type+ '/void'; @@ -1602,6 +1604,7 @@ $(document).ready(function(){ closeOnConfirm: false }, function (isConfirm) { if (isConfirm) { + $('.confirm').prop("disabled",true); var url = "/origami/sale/" + sale_id +'/'+cashier_type+'/waste_and_spoilage'; $.ajax({ type: 'POST', From e0b54728f7f7f0b4e6c3fb30b4e6063d8efd3825 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Thu, 12 Sep 2019 14:50:14 +0630 Subject: [PATCH 18/20] fixed inventory --- .../inventory/inventory_controller.rb | 6 +- .../origami/payments_controller.rb | 12 +++- app/controllers/origami/sales_controller.rb | 16 ++--- app/models/inventory_definition.rb | 66 +++++++++++++++---- app/models/sale.rb | 4 +- app/models/stock_check_item.rb | 5 +- app/models/stock_journal.rb | 42 ++++++++---- 7 files changed, 111 insertions(+), 40 deletions(-) diff --git a/app/controllers/inventory/inventory_controller.rb b/app/controllers/inventory/inventory_controller.rb index d987a59d..4bb844b7 100755 --- a/app/controllers/inventory/inventory_controller.rb +++ b/app/controllers/inventory/inventory_controller.rb @@ -7,14 +7,14 @@ class Inventory::InventoryController < BaseInventoryController @inventory_definitions = InventoryDefinition.get_by_category(filter) end - + def show inventory_definition_id = params[:inventory_definition_id] inventory = InventoryDefinition.find(inventory_definition_id) - @stock_journals = StockJournal.where(item_code: inventory.item_code) + @stock_journals = StockJournal.where(item_code: inventory.item_code).order("id DESC") @stock_journals = Kaminari.paginate_array(@stock_journals).page(params[:page]).per(20) - + respond_to do |format| format.html format.xls diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 2c76f132..956f1a7b 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -180,7 +180,7 @@ class Origami::PaymentsController < BaseOrigamiController else sp.kbz_edit_sale_payment(sp.received_amount.to_f, current_user) end - + # end if !path.include? ("credit_payment") @@ -304,6 +304,12 @@ class Origami::PaymentsController < BaseOrigamiController #end end + logger.debug 'saleObj++++++++++++++++++++++++++' + logger.debug saleObj.to_json + if !saleObj.nil? + # InventoryJob.perform_now(self.id) + InventoryDefinition.calculate_product_count(saleObj) + end end # status, filename, sale_receipt_no, printer_name = Payment.pay(getCloudDomain, cash, sale_id, member_info, type, tax_type, path, latest_order_no, shop_detail, current_user, nil, nil) @@ -741,6 +747,10 @@ class Origami::PaymentsController < BaseOrigamiController end end # end + if !saleObj.nil? + #InventoryJob.perform_now(self.id) + InventoryDefinition.calculate_product_count(saleObj) + end end end diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index 4898dd4f..0549a5a5 100755 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -2,9 +2,9 @@ class Origami::SalesController < BaseOrigamiController def show @webview = false if check_mobile - @webview = true + @webview = true end - + @tables = Table.unscoped.all.active.order('status desc') @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.completed_sale("cashier") @@ -36,7 +36,7 @@ class Origami::SalesController < BaseOrigamiController if booking.sale_id.nil? order_array = [] booking.booking_orders.each do |booking_order| - + booking.booking_status = 'moved' order = Order.find(booking_order.order_id) order.status = 'billed' @@ -60,16 +60,16 @@ class Origami::SalesController < BaseOrigamiController booking.save order_array.push(order.order_id) - + end receipt_no = Sale.find(sale_id).receipt_no action_by = current_user.name type = "ADD_TO_EXISTING" - + remark = "#{action_by} add to existing order #{order_array} to Receipt No=>#{receipt_no} in #{table.name}" sale_audit = SaleAudit.record_audit_sale(sale_id,remark,action_by,type ) - + booking_order = BookingOrder.where('booking_id=?',booking) booking_order.each do |bo| bo.booking_id = existing_booking.booking_id @@ -77,9 +77,9 @@ class Origami::SalesController < BaseOrigamiController end end end - if !sale_data.empty? + # if !sale_data.empty? # InventoryJob.perform_now(self.id) - InventoryDefinition.calculate_product_count(nil,sale_data) + # InventoryDefinition.calculate_product_count(nil,sale_data) end end diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index dc2e1052..4232c7b3 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -44,27 +44,69 @@ class InventoryDefinition < ApplicationRecord end def self.modify_balance(item, stock, inventory_definition) #saleitemObj + void_qty = 0 + if item.product_name.downcase.include?("void") + void_qty = item.qty.abs.to_i + end check_item = StockCheckItem.where('item_code=?', item.item_instance_code).order("id DESC").first if stock.balance.to_i >= item.qty puts ">> stock is greater than order qty" - StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition) - check_item.different = check_item.different - item.qty - check_item.save + if item.qty.to_i > 0 + StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition) + if !void_qty.nil? | void_qty != 0 + check_item.different = check_item.different - item.qty + check_item.save + end + else + if item.product_name.downcase.include?("void") + StockJournal.add_to_journal(item, stock.balance, "void", inventory_definition) + check_item.different = check_item.different + void_qty + check_item.save + end + end else puts " << stock is less than order qty" data = item extra_qty = item.qty.to_i - stock.balance.to_i if stock.balance.to_i > 0 item.qty = stock.balance.to_i - StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition) - data.qty = extra_qty - StockJournal.add_to_journal(data, 0, "out of stock", inventory_definition) - check_item.different = check_item.different - item.qty - check_item.save + if item.qty.to_i > 0 + StockJournal.add_to_journal(item, stock.balance, "ok", inventory_definition) + check_item.different = check_item.different - item.qty + check_item.save + data.qty = extra_qty + StockJournal.add_to_journal(data, 0, "out of stock", inventory_definition) + if !void_qty.nil? | void_qty != 0 + check_item.different = check_item.different - item.qty + check_item.save + else + check_item.different = check_item.different + void_qty + check_item.save + end + else + if item.product_name.downcase.include?("void") + StockJournal.add_to_journal(item, stock.balance, "void", inventory_definition) + check_item.different = check_item.different + void_qty + check_item.save + end + end else - StockJournal.add_to_journal(item, stock.balance, "out of stock", inventory_definition) - check_item.different = check_item.different - item.qty - check_item.save + if item.qty.to_i > 0 + StockJournal.add_to_journal(item, stock.balance, "out of stock", inventory_definition) + if !void_qty.nil? | void_qty != 0 + check_item.different = check_item.different - item.qty + check_item.save + else + check_item.different = check_item.different + void_qty + check_item.save + end + else + if item.product_name.downcase.include?("void") + StockJournal.add_to_journal(item, stock.balance, "void", inventory_definition) + check_item.different = check_item.different + void_qty + check_item.save + end + end end end end @@ -93,7 +135,7 @@ class InventoryDefinition < ApplicationRecord # ORDER BY stock_journals.created_at DESC LIMIT 1" least_stock = "(SELECT (SELECT balance FROM stock_journals WHERE item_code = inventory_definitions.item_code - ORDER BY created_at DESC LIMIT 1) + ORDER BY id DESC LIMIT 1) FROM stock_journals WHERE stock_journals.item_code = inventory_definitions.item_code ORDER BY stock_journals.created_at DESC LIMIT 1)" diff --git a/app/models/sale.rb b/app/models/sale.rb index 95bbe525..96cb8fae 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -84,7 +84,7 @@ class Sale < ApplicationRecord link_order_sale(order.order_id) end # InventoryJob.perform_now(self.id) - InventoryDefinition.calculate_product_count(saleObj) + # InventoryDefinition.calculate_product_count(saleObj) @@ -489,7 +489,7 @@ class Sale < ApplicationRecord sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax sale.grand_total_round end - + if discount_type == "member_discount" sale.discount_type = discount_type end diff --git a/app/models/stock_check_item.rb b/app/models/stock_check_item.rb index f596740a..dfd07397 100755 --- a/app/models/stock_check_item.rb +++ b/app/models/stock_check_item.rb @@ -2,11 +2,12 @@ class StockCheckItem < ApplicationRecord belongs_to :stock_check def create(stock_id, item) - check_item = StockCheckItem.find_by_item_code(item['sku']) + # check_item = StockCheckItem.find_by_item_code(item['sku']) + check_item = StockCheckItem.where('item_code=?', item_code).order("id DESC").first if check_item.nil? balance = 0 else - balance = StockCheckItem.last.different + balance = check_item.different end journal_id = StockCheckItem.find_journal(item['sku']) remark, different = StockCheckItem.stock_different(item['qty'], balance ) diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index fc969199..037c164b 100755 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -5,22 +5,40 @@ class StockJournal < ApplicationRecord def self.add_to_journal(item, balance, stock_message, inventory_definition) # item => saleObj | balance => Stock journal journal = StockJournal.new - journal.credit = balance + if item.qty < 0 + credit_balance = item.qty.abs.to_i + debit = 0 + else + credit_balance = balance + debit = item.qty + end + + journal.credit = credit_balance + balance = calculate_balance(balance, item) + + journal.item_code = item.item_instance_code + journal.inventory_definition_id = inventory_definition.id + journal.debit = debit + journal.balance = balance + journal.remark = stock_message + journal.trans_ref = item.id + journal.trans_type = StockJournal::SALES_TRANS + journal.save + - balance = calculate_balance(balance, item.qty) - journal.item_code = item.item_instance_code - journal.inventory_definition_id = inventory_definition.id - journal.debit = item.qty - journal.balance = balance - journal.remark = stock_message - journal.trans_ref = item.id - journal.trans_type = StockJournal::SALES_TRANS - journal.save end - def self.calculate_balance(balance, qty) - return balance.to_i - qty.to_i + def self.calculate_balance(balance, item) + if item.product_name.downcase.include?("void") + logger.debug 'balance++++++++++++++++++' + logger.debug balance + logger.debug 'qty+++++++++++++++++++++++' + logger.debug item.qty + return balance.to_i + item.qty.abs.to_i + else + return balance.to_i - item.qty.to_i + end end def self.from_stock_check(item) From b2ab2c9632cfd961b8b2eaabe497445ec71a181e Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Thu, 12 Sep 2019 19:29:04 +0630 Subject: [PATCH 19/20] add account name in saleitem xls --- app/views/reports/saleitem/index.xls.erb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/app/views/reports/saleitem/index.xls.erb b/app/views/reports/saleitem/index.xls.erb index b5f7f3ef..799ede63 100755 --- a/app/views/reports/saleitem/index.xls.erb +++ b/app/views/reports/saleitem/index.xls.erb @@ -24,7 +24,7 @@ <% end %> - + @@ -89,25 +89,18 @@ <% if sale.status_type == "Discount" && sale.grand_total < 0 total_item_dis += sale.grand_total*(-1) end %> - <% if !acc_arr.include?(sale.account_id) %> - - - - - - <% acc_arr.push(sale.account_id) %> <% end %> - + From 8e2a9bd5a11a726ff0d51a5a5e5c0b904bf144b3 Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Fri, 13 Sep 2019 16:20:54 +0630 Subject: [PATCH 20/20] add to existing --- app/controllers/origami/sales_controller.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index 0549a5a5..4c02a4f0 100755 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -29,11 +29,8 @@ class Origami::SalesController < BaseOrigamiController sale_data = [] table = DiningFacility.find(dining) existing_booking = Booking.find_by_sale_id(sale_id) - table.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ").each do |booking| - # if !booking.checkout_at.nil? - # existing_booking.update_attributes(checkout_at: checkout_at) - # end - if booking.sale_id.nil? + table.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ").each do |booking| + if booking.sale_id.nil? order_array = [] booking.booking_orders.each do |booking_order| @@ -60,8 +57,7 @@ class Origami::SalesController < BaseOrigamiController booking.save order_array.push(order.order_id) - - end + end receipt_no = Sale.find(sale_id).receipt_no action_by = current_user.name @@ -77,10 +73,6 @@ class Origami::SalesController < BaseOrigamiController end end end - # if !sale_data.empty? - # InventoryJob.perform_now(self.id) - # InventoryDefinition.calculate_product_count(nil,sale_data) - end end -end +end \ No newline at end of file
    Sub Total:<%= sub_total %><%= number_with_precision(sub_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    Discount:(<%= @obj_sale.total_discount rescue 0%>)(<%= number_with_precision(@obj_sale.total_discount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>)
    <%= @obj_sale.total_tax rescue 0%><%= number_with_precision(@obj_sale.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%>
    Rounding Adj:<%= @obj_sale.rounding_adjustment rescue 0%><%= number_with_precision(@obj_sale.rounding_adjustment, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%>
    Grand Total:<%= @obj_sale.grand_total rescue 0%><%= number_with_precision(@obj_sale.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    <%= item.menu_category_name %>  <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %> <%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%>
     Total FOC Amount<%= number_with_precision(@foc_data , precision:precision.to_i,delimiter:delimiter)%>
     <%= t("views.right_panel.detail.net_amount") %><%= number_with_precision(grand_total -@foc_data , precision:precision.to_i,delimiter:delimiter)%>
     <%= t("views.right_panel.header.account_name") %> <%= t("views.right_panel.header.menu_category") %> <%= t("views.right_panel.detail.code") %> <%= t("views.right_panel.detail.product") %>
    <%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> <% if sale.account_id == account %> - <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> + <% grand_total += total %> <% end %> <% end %> -
     <%= sale.account_name %> <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %> <%= sale.product_name rescue '-' %>