From 58dcf588dfa8396132c00fff02cfcdad7915961f Mon Sep 17 00:00:00 2001 From: Sunandar Date: Tue, 31 Jan 2017 11:33:00 +0630 Subject: [PATCH] edti dashboard --- app/controllers/batches_controller.rb | 4 +- app/controllers/home_controller.rb | 8 +++ app/models/batch_line_item.rb | 3 +- app/views/batches/index.html.erb | 4 +- app/views/home/dashboard.html.erb | 78 ++++++++++++++++++++++++++- app/views/users/index.html.erb | 4 +- 6 files changed, 93 insertions(+), 8 deletions(-) diff --git a/app/controllers/batches_controller.rb b/app/controllers/batches_controller.rb index 83ac263..9573273 100644 --- a/app/controllers/batches_controller.rb +++ b/app/controllers/batches_controller.rb @@ -1,5 +1,7 @@ class BatchesController < ApplicationController def index - @batches=Batch.all.page(params[:page]).per(2) + @batches=Batch.joins('inner join users on users.id=batches.user_id') + .select('batches.*,users.name as user_name').order('batches.id desc').page(params[:page]) + end end \ No newline at end of file diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 000d78b..33d3f51 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -5,6 +5,14 @@ class HomeController < ApplicationController redirect_to new_member_session_path end def dashboard + today= Date.today.strftime("%Y-%m-%d") @users=User.all + @batches=Batch.joins('inner join users on users.id=batches.user_id') + .where("to_char(batches.created_at,'YYYY-mm-dd')=?",today) + .select('batches.*,users.name as user_name').order('batches.id desc') + + @batchLineItems=BatchLineItem.joins('inner join batches on batches.id=batch_line_items.batch_id').select('batch_line_items.*,batches.order_ref as batch_name') + .where("to_char(batches.created_at,'YYYY-mm-dd')=?",today) + .page(params[:page]).per(5) end end diff --git a/app/models/batch_line_item.rb b/app/models/batch_line_item.rb index 325e11e..db8c83b 100644 --- a/app/models/batch_line_item.rb +++ b/app/models/batch_line_item.rb @@ -43,8 +43,7 @@ class BatchLineItem < ApplicationRecord def self.to_csv(user_id) encrypt_key="" - find_user=User.find_by_id(user_id) - + find_user=User.find_by_id(user_id) if !find_user.nil? encrypt_key=find_user.secrect_key end diff --git a/app/views/batches/index.html.erb b/app/views/batches/index.html.erb index 95fcb2c..717cf91 100644 --- a/app/views/batches/index.html.erb +++ b/app/views/batches/index.html.erb @@ -14,7 +14,7 @@ Order Ref - Created By + Created By Qty Processing Qty Success Qty Fail @@ -26,7 +26,7 @@ <% @batches.each do |batch| %> <%= batch.order_ref rescue '' %> - <%= batch.created_by rescue '' %> + <%= batch.user_name rescue '' %> <%= batch.qty_processing rescue '' %> <%= batch.qty_success rescue '' %> <%= batch.qty_fail rescue '' %> diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 81781d5..52fd98f 100644 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -1,6 +1,6 @@
-
+
User List
@@ -30,5 +30,81 @@
+
+
+
+
+
Latest Batch
+
+ <% if @batches.empty? %> +

There is no batch created for today.

+ <% else %> + + + + + + + + + + + + + + <% @batches.each do |batch| %> + + + + + + + + + + <% end %> + +
Order RefCreated ByQty ProcessingQty SuccessQty FailExport CountCreatd At
<%= batch.order_ref rescue '' %><%= batch.user_name rescue '' %><%= batch.qty_processing rescue '' %><%= batch.qty_success rescue '' %><%= batch.qty_fail rescue '' %><%= batch.export_count %><%= batch.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %>
+ <% end %> +
+
+
+
+
+
Latest Batch Line Item
+
+ <% if @batchLineItems.empty? %> +

There is no batch line item for today.

+ <% else %> + + + + + + + + + + + + + + + <% @batchLineItems.each do |item| %> + + + + + + + + + + <% end %> + +
Serail NoWristband CodeManufacture UIDBatch NoCard TypeCreated At Update At
<%= item.serial_no rescue '' %><%= item.wristband_code rescue '' %><%= item.manufacture_uid rescue '' %><%= item.batch_name rescue '' %><%= item.card_type rescue '' %><%= item.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %><%= item.updated_at.strftime("%e,%b %Y %I:%M %p") rescue '' %>
+ <% end %> + <%=paginate @batchLineItems %> +
\ No newline at end of file diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index bf3e8ba..d1d9878 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -39,8 +39,8 @@ <%= user.created_at.strftime("%e,%b %Y %I:%M %p") rescue '' %> <%= link_to 'Detail', - user_path(user), :class => 'btn btn-primary btn-sm ' %> - <%= link_to t('.edit', :default => t("helpers.links.edit")), + user_path(user), :class => 'btn btn-primary btn-sm' %> + <%= link_to 'Edit', edit_user_path(user), :class => 'btn btn-primary btn-sm' %> <%= link_to 'Delete', user_path(user), method: :delete, data: { confirm: 'Are you sure?' },:class => 'btn btn-primary btn-sm' %>