From e0fe0ee8ab69dec19a1cb73eac16c30b911d3213 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 23 Mar 2018 18:06:53 +0630 Subject: [PATCH] dashboard update --- app/controllers/home_controller.rb | 21 +++++--- app/views/home/dashboard.html.erb | 56 +++++++++++++++++++--- app/views/origami/dashboard/index.html.erb | 4 +- config/locales/en.yml | 2 + config/locales/mm.yml | 2 + 5 files changed, 70 insertions(+), 15 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index f097ba6f..da8695d8 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -80,14 +80,21 @@ class HomeController < ApplicationController end def dashboard - @from, @to = get_date_range_from_params + @from, @to, @from_time, @to_time = get_date_range_from_params @shop = Shop.first today = DateTime.now.strftime('%Y-%m-%d') - @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() - + if !@from.nil? && !@to.nil? + @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + else + @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() + end + if !@from.nil? && !@to.nil? + @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + else + @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() + end @top_products = Sale.top_products(today,@from,@to).sum('i.qty') @bottom_products = Sale.bottom_products(today,@from,@to).sum('i.qty') @hourly_sales = Sale.hourly_sales(today,@from,@to).sum(:grand_total) @@ -190,7 +197,9 @@ 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] if from.present? && to.present? f_date = DateTime.parse(from) @@ -201,7 +210,7 @@ class HomeController < ApplicationController to = t_time.end_of_day.utc.getlocal end - return from, to + return from, to, from_time, to_time end #Shop Name in Navbor diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index aee947c7..6ee68d97 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -68,16 +68,26 @@
-
+
- +
-
+
- +
+
+ + + +
+
+ + + +

@@ -340,21 +350,53 @@ $('.btn_generate').on('click',function(){ var from = $("#from").val(); var to = $("#to").val(); + var from_time = $("#from_time").val(); + var to_time = $("#to_time").val(); + + if(check(from,to,from_time,to_time)){ + var params = '?'; + if((from!='' && to!='') && (from_time!='' && to_time!='')){ + params += 'from='+from+'&to='+to+'&from_time='+from_time+'&to_time='+to_time; + }else{ + params += 'from='+from+'&to='+to; + } + window.location.href = '/dashboard'+params; + } + }); + + function check(from,to,from_time,to_time){ + var status = true; if((from=='') && (to=='')){ + status = false; $('#fromErr').html("can't be blank"); $('#toErr').html("can't be blank"); }else if((from!='') && (to=='')){ + status = false; $('#fromErr').html(""); $('#toErr').html("can't be blank"); }else if((from=='') && (to!='')){ + status = false; $('#fromErr').html("can't be blank"); $('#toErr').html(""); }else{ + status = true; $('#fromErr').html(""); $('#toErr').html(""); } - if((from!='') && (to!='')){ - window.location.href = '/dashboard?from='+from+'&to='+to; + + if(((from_time=='') && (to_time=='')) || ((from_time!='') && (to_time!=''))){ + status = true; + $('#from_timeErr').html(""); + $('#to_timeErr').html(""); + }else if((from_time!='') && (to_time=='')){ + status = false; + $('#from_timeErr').html(""); + $('#to_timeErr').html("can't be blank"); + }else if((from_time=='') && (to_time!='')){ + status = false; + $('#from_timeErr').html("can't be blank"); + $('#to_timeErr').html(""); } - }); + return status; + } \ No newline at end of file diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index 5361ac27..228da935 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -22,7 +22,7 @@
arrow_forward
-
Quick Service
+
<%= t :quick_service %>
@@ -30,7 +30,7 @@
arrow_forward
-
Cashier
+
<%= t :dine_in_order %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index da68414c..84a7b03a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -72,6 +72,8 @@ en: payment: "Payment" backend: "Backend" date_time: "DateTime" + dine_in_order: "Dine In Order" + quick_service: "Quick Service" views: btn: diff --git a/config/locales/mm.yml b/config/locales/mm.yml index d3ca2d0f..f18136c4 100644 --- a/config/locales/mm.yml +++ b/config/locales/mm.yml @@ -67,6 +67,8 @@ mm: payment: "ငွေပေးချေမှု" backend: "နောက်ကွယ်" date_time: "ရက်စွဲအချိန်" + dine_in_order: "Dine In Order" + quick_service: "Quick Service" views: btn: