From 9647a28f91e0cdc8a2aec6c968854093dac7cc8e Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 15 Nov 2017 13:27:42 +0630 Subject: [PATCH] dashboard chart UI --- Gemfile | 1 + Gemfile.lock | 4 +- app/assets/javascripts/application.js | 3 +- app/controllers/home_controller.rb | 10 +- app/models/sale.rb | 9 +- app/views/home/dashboard.html.erb | 366 +++++++------------------- 6 files changed, 114 insertions(+), 279 deletions(-) diff --git a/Gemfile b/Gemfile index 7dfb53f9..2c0c7b9e 100755 --- a/Gemfile +++ b/Gemfile @@ -121,3 +121,4 @@ gem 'momentjs-rails' # for date-range selector # gem 'bootstrap-datepicker-rails' # date picker # gem 'jquery-datetimepicker-rails' # gem 'select2-rails' # for multi-select and auto-complete select box +gem "chartkick" #chart lib \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index e136381d..76fa4aef 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,6 +49,7 @@ GEM activemodel (>= 4.0.0) activesupport (>= 4.0.0) mime-types (>= 1.16) + chartkick (2.2.5) chronic (0.10.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) @@ -261,6 +262,7 @@ DEPENDENCIES byebug cancancan (~> 1.10) carrierwave (~> 1.0) + chartkick coffee-rails (~> 4.2) cups (~> 0.0.7) database_cleaner @@ -303,4 +305,4 @@ DEPENDENCIES whenever BUNDLED WITH - 1.15.3 + 1.16.0 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 66714f33..6435a17e 100755 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -27,7 +27,8 @@ //= require autosize/autosize.js //= require jquery-countto/jquery.countTo.js //= require raphael/raphael.min -//= require chartjs/Chart.bundle.js +//= require Chart.bundle +//= require chartkick //= require fileinput.min //= require settings/processing_items //= require BSBMaterial/admin.js diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 1586158e..8cfdfd22 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -67,13 +67,21 @@ class HomeController < ApplicationController @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() - @top_products = Sale.top_products(today) + @top_products = Sale.top_products(today).sum('i.qty') @hourly_sales = Sale.hourly_sales(today).sum(:grand_total) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) @employee_sales = Sale.employee_sales(today).sum(:grand_total) @inventories = StockJournal.inventory_balances(today).sum(:balance) + #@employee_sales = Hash.new + #employee_sales.each do |key, value| + # if(@employee_sales.has_key? key[1]) + # @employee_sales[key[1]].push({key[0] => value}) + # else + # @employee_sales[key[1]] = [key[0] => value] + # end + #end @total_sale = Sale.total_sale(today) @total_count = Sale.total_count(today) @total_card = Sale.total_card_sale(today) diff --git a/app/models/sale.rb b/app/models/sale.rb index f9bd6c7b..84eb86f8 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -904,7 +904,7 @@ end query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") - .where("(i.qty > 0 ) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ + .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ "and payment_status='paid' and sale_status= 'completed'") .group('mi.name') .order("SUM(i.qty) DESC").limit(5) @@ -918,10 +918,11 @@ end def self.employee_sales(today) query = Sale.select("e.name as employee_name,grand_total") - .where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) + .where('sales.payment_status="paid" and sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) .joins("join employees e on e.id=sales.cashier_id") - .group('e.name') - .order('e.name ASC') + .joins("join sale_payments sp on sp.sale_id=sales.sale_id") + .group("sp.payment_method","e.name") + .order('e.name') end def self.total_sale(today) diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index f26d9e07..a48a440a 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -1,70 +1,75 @@
-
-

<%= t :dashboard %>

+
+

<%= t :dashboard %>

+
+ + +
+
+
+
+ help +
+
+
<%= t :sale_count %>
+
+
+
+
+
+
+
+ attach_money +
+
+
<%= t :total_sale %>
+
+
+
- -
-
-
-
- help -
-
-
<%= t :sale_count %>
-
-
-
+
+
+
+ person_add
-
-
-
- attach_money -
-
-
<%= t :total_sale %>
-
-
-
-
- -
-
-
- person_add -
-
-
<%= t :total_credit %>
-
-
-
-
-
-
-
- credit_card -
-
-
<%= t :total_card %>
-
-
-
+
+
<%= t :total_credit %>
+
+
- - +
+
+
+ credit_card +
+
+
<%= t :total_card %>
+
+
+
+
+
+ + - <% if current_user.role == 'administrator' || current_user.role == 'manager' %> -
-
-
-
-

dashboard<%= (t :top) + " " + (t :products) %>

- -
+ <% if current_user.role == 'administrator' || current_user.role == 'manager' %> +
+
+
+
+
+
+

dashboard<%= (t :top) + " " + (t :products) %>

+ + <%= pie_chart @top_products %>
-
+
+
+
-
-
-
-

av_timer<%= (t :hourly) + " " + (t :sale) %>

- -
-
-
-
-
-
-

assignment_ind<%= (t :staff) + " " + (t :sale) %>

- -
-
-
+
+
+
+

av_timer<%= (t :hourly) + " " + (t :sale) %>

+ + <%= column_chart @hourly_sales %> +
+
- <% end %> -
+
+
+
+
+
+

assignment_ind<%= (t :staff) + " " + (t :sale) %>

+ + <%= column_chart @employee_sales %> +
+
+
+
+
+ +
+ <% end %> +
\ No newline at end of file