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 629b2542..acfbe88d 100755 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -26,7 +26,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/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index 2460031d..f33f6d11 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -2,8 +2,6 @@ $(document).ready(function() { $('body').bootstrapMaterialDesign(); var height = ($(window).height() - ($('.legal').outerHeight() + $('.user-info').outerHeight() + $('.navbar').innerHeight())); -console.log(height); -console.log($('#order-detail-slimscroll').attr('data-height')) $('#custom-slimscroll').slimScroll({ height: height, diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 15f5f423..db6dd039 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -59,6 +59,7 @@ class Api::OrdersController < Api::ApiController @order.guest = params[:guest_info] @order.table_id = params[:table_id] # this is dining facilities's id @order.new_booking = true + @order.waiters = current_login_employee.name @order.employee_name = current_login_employee.name #Create Table Booking or Room Booking if !params["booking_id"].nil? 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/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index af843c7e..8e92f52d 100755 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -124,7 +124,7 @@ class Oqs::HomeController < BaseOqsController .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id left join orders as od ON od.order_id = assigned_order_items.order_id - left join order_items as odt ON odt.item_code = assigned_order_items.item_code AND odt.order_id = assigned_order_items.order_id + left join order_items as odt ON odt.item_instance_code = assigned_order_items.instance_code AND odt.order_id = assigned_order_items.order_id left join customers as cus ON cus.customer_id = od.customer_id left join booking_orders as bo on bo.order_id = assigned_order_items.order_id left join bookings as bk on bk.booking_id = bo.booking_id @@ -142,7 +142,7 @@ class Oqs::HomeController < BaseOqsController .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id left join orders as od ON od.order_id = assigned_order_items.order_id - left join order_items as odt ON odt.item_code = assigned_order_items.item_code AND odt.order_id = assigned_order_items.order_id + left join order_items as odt ON odt.item_instance_code = assigned_order_items.instance_code AND odt.order_id = assigned_order_items.order_id left join customers as cus ON cus.customer_id = od.customer_id left join booking_orders as bo on bo.order_id = assigned_order_items.order_id left join bookings as bk on bk.booking_id = bo.booking_id @@ -161,7 +161,7 @@ class Oqs::HomeController < BaseOqsController query = AssignedOrderItem.select("count(odt.item_code) as total,oqs.id as station_id") .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id left join orders as od ON od.order_id = assigned_order_items.order_id - left join order_items as odt ON odt.item_code = assigned_order_items.item_code AND odt.order_id = assigned_order_items.order_id + left join order_items as odt ON odt.item_instance_code = assigned_order_items.instance_code AND odt.order_id = assigned_order_items.order_id left join customers as cus ON cus.customer_id = od.customer_id left join booking_orders as bo on bo.order_id = assigned_order_items.order_id left join bookings as bk on bk.booking_id = bo.booking_id diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 7bde1e98..8098dfe9 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -68,6 +68,7 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController @order.table_id = params[:table_id] # this is dining facilities's id @order.new_booking = true @order.waiters = current_login_employee.name + @order.employee_name = current_login_employee.name #Create Table Booking or Room Booking if !params["booking_id"].nil? # check booking id is already completed. diff --git a/app/models/assigned_order_item.rb b/app/models/assigned_order_item.rb index 34c97c6f..85dd71c7 100755 --- a/app/models/assigned_order_item.rb +++ b/app/models/assigned_order_item.rb @@ -7,10 +7,11 @@ class AssignedOrderItem < ApplicationRecord belongs_to :order belongs_to :order_queue_station - def self.assigned_order_item (order, item_code, order_queue_station ) + def self.assigned_order_item (order, item_code, instance_code, order_queue_station ) assigned_order_item = AssignedOrderItem.new() assigned_order_item.order = order assigned_order_item.item_code = item_code + assigned_order_item.instance_code = instance_code assigned_order_item.order_queue_station = order_queue_station assigned_order_item.print_status = false assigned_order_item.delivery_status = false @@ -23,7 +24,7 @@ class AssignedOrderItem < ApplicationRecord oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type as table_type, - odt.order_id, odt.item_code, odt.item_name, + odt.order_id, odt.item_code, odt.item_instance_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index d85dffa7..9ed86b85 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -70,7 +70,7 @@ class OrderQueueStation < ApplicationRecord # else if (order_item.price != 0) - AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs) oqs_order_items.push(order_item) end # end diff --git a/app/models/sale.rb b/app/models/sale.rb index f9bd6c7b..87e2d6d5 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -605,7 +605,7 @@ end def self.get_item_query() query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code, " + - "(SUM(i.qty * i.unit_price)) as grand_total,SUM(i.qty) as total_item," + + "(i.qty * i.unit_price) as grand_total,(i.qty) as total_item," + " i.unit_price as unit_price,i.product_name as product_name, mc.name as" + " menu_category_name,mc.id as menu_category_id ") @@ -617,7 +617,7 @@ def self.get_item_query() query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id") query = query.where("i.unit_price > 0") - query = query.group('i.product_code ').order("mi.account_id, mi.menu_category_id") + query = query.group("i.item_instance_code").order("mi.account_id, mi.menu_category_id") end def self.get_by_shift_items(shift_sale_range, shift, from, to, status) @@ -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 diff --git a/db/migrate/20170414090001_create_assigned_order_items.rb b/db/migrate/20170414090001_create_assigned_order_items.rb index 3eaf58cf..e7cd8986 100755 --- a/db/migrate/20170414090001_create_assigned_order_items.rb +++ b/db/migrate/20170414090001_create_assigned_order_items.rb @@ -3,6 +3,7 @@ class CreateAssignedOrderItems < ActiveRecord::Migration[5.1] create_table :assigned_order_items, :id => false do |t| t.string :assigned_order_item_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing t.string :item_code, :null => false, :index => true + t.string :instance_code, :null => false, :index => true t.references :order_queue_station, foreign_key: true t.string :order_id, foreign_key: true, :limit => 16 t.boolean :print_status