Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge to Main #70

Merged
merged 51 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
f7f24e9
Write test for admin dashboard, create route
jenniferhalloran Jun 2, 2022
4b40ad4
Pass test for admin dashboard
jenniferhalloran Jun 2, 2022
de57c5c
Write tests for admin dashboard links
jenniferhalloran Jun 2, 2022
0e94493
Create routes for links
jenniferhalloran Jun 2, 2022
c48a00e
Create empty views for the admin/merchants and admin/invoices
jenniferhalloran Jun 2, 2022
65a213d
Test: add test for item's #best_sales_date
ruezheng Jun 2, 2022
7161e1c
Feat: add method #best_sales_date to item.rb
ruezheng Jun 2, 2022
fcf72c7
Write feature test for incomplete invoices on admin show page
jenniferhalloran Jun 2, 2022
0772611
Write model test for incomplete_invoice_ids method
jenniferhalloran Jun 2, 2022
9c7a0fa
Create incomplete invoices section in admin dashboard view
jenniferhalloran Jun 2, 2022
005d276
Add merchant invoices show route for links
jenniferhalloran Jun 2, 2022
3626864
Create actions in the admin invoices controller so links work
jenniferhalloran Jun 2, 2022
21e5f3f
Write incomplete_invoice_ids method and pass tests
jenniferhalloran Jun 2, 2022
cc953e8
Feat: add best_sales_date to items index
ruezheng Jun 2, 2022
579c723
Fix: best_sales_date test data
ruezheng Jun 2, 2022
07b750a
Fix: spacing
ruezheng Jun 2, 2022
63e8210
Merge pull request #62 from ruezheng/fix_items_best_day
jenniferhalloran Jun 2, 2022
edde127
Merge branch 'almost-main' into feat/admin-dashboard
ruezheng Jun 3, 2022
191159a
Merge pull request #63 from ruezheng/feat/admin-dashboard
ruezheng Jun 3, 2022
99a3c9c
Test: Update Invoice Item Status
ZacHazelwood Jun 3, 2022
6812b3e
Feat: Update Invoice Item Status with selector
ZacHazelwood Jun 3, 2022
da465bd
Add missing 'end'
ZacHazelwood Jun 3, 2022
b15ddc9
Test: Invoice class method
ZacHazelwood Jun 3, 2022
e995529
Reinstate Invoice model method to display unique Invoice IDs
ZacHazelwood Jun 3, 2022
d87f0bd
Move variable to correct location
ZacHazelwood Jun 3, 2022
339aef6
Merge branch 'almost-main' into invoice_show_update_item
ZacHazelwood Jun 3, 2022
3536f22
Merge pull request #64 from ruezheng/invoice_show_update_item
jenniferhalloran Jun 3, 2022
b609e90
Test: Admin Merchant Index Page
ZacHazelwood Jun 3, 2022
6816cb5
Feat: Admin Merchant Index Page
ZacHazelwood Jun 3, 2022
2ff18db
Test: Admin Merchant Show displays name
ZacHazelwood Jun 3, 2022
c4c6bdc
Test: Admin Merchant Show displays name
ZacHazelwood Jun 3, 2022
193cf6a
Feat: Admin Merchant Show displays name
ZacHazelwood Jun 3, 2022
2a6d565
Test: admin index page lists the names of the top 5 customers with th…
ruezheng Jun 3, 2022
1979b20
Test: customer model ::top_customers returns the names of the top 5 c…
ruezheng Jun 3, 2022
36db5cf
Feat: add ::top_customers and #count_of_transactions to Customer model
ruezheng Jun 3, 2022
ffc40cc
Feat: add name of top 5 customers and number of successful transactio…
ruezheng Jun 3, 2022
7a44f77
Feat: add ordered list
ruezheng Jun 3, 2022
cf9bdd9
Style: add jumbotron to layouts to format header
ruezheng Jun 3, 2022
4f5c17b
Style: add nav bar to admin dashboard
ruezheng Jun 3, 2022
97da00d
Style: change spacing
ruezheng Jun 3, 2022
9df7336
Move 'incomplete_invoice_ids' to the invoice model and change method
jenniferhalloran Jun 3, 2022
3f23bc6
Add more test data, update view/controller to access invoices not inv…
jenniferhalloran Jun 3, 2022
beb3a30
Merge branch 'almost-main' into feat/incomplete_invoices
jenniferhalloran Jun 3, 2022
d39b955
Merge pull request #65 from ruezheng/admin_merchants_index_show
jenniferhalloran Jun 3, 2022
2a47cf5
Merge pull request #66 from ruezheng/top_customers
ZacHazelwood Jun 3, 2022
a9ee67e
Merge pull request #67 from ruezheng/bootstrap
ZacHazelwood Jun 3, 2022
7207fec
Merge branch 'almost-main' into feat/incomplete_invoices
jenniferhalloran Jun 3, 2022
2e0ad0f
Merge pull request #68 from ruezheng/feat/incomplete_invoices
ZacHazelwood Jun 3, 2022
02def9b
Fix errors/failing tests from merge
jenniferhalloran Jun 3, 2022
a447cf0
Merge pull request #69 from ruezheng/fix_merge_errors-JH
ruezheng Jun 3, 2022
e822d3f
Refactor: remove helped method and add to ::top_customers
ruezheng Jun 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/controllers/admin/invoices_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Admin::InvoicesController < ApplicationController

def index

end

def show

end
end
10 changes: 10 additions & 0 deletions app/controllers/admin/merchants_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Admin::MerchantsController < ApplicationController

def index
@merchants = Merchant.all
end

def show
@merchant = Merchant.find(params[:id])
end
end
7 changes: 7 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AdminController < ApplicationController

def index
@invoices = Invoice.all
@customers = Customer.all
end
end
15 changes: 14 additions & 1 deletion app/controllers/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@ class InvoicesController < ApplicationController
before_action :find_merchant

def index
@invoices = @merchant.invoices
@invoices = Invoice.invoices_with_merchant_items(@merchant)
end

def show
@invoice = Invoice.find(params[:id])
end


def update
invoice = Invoice.find(params[:id])
invoice_item = InvoiceItem.find(params[:invoice_item_id])
invoice_item.update(invoice_item_params)
redirect_to merchant_invoice_path(@merchant, invoice)
end

private
def invoice_item_params
params.permit(:status)
end
end
10 changes: 10 additions & 0 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Customer < ApplicationRecord

validates_presence_of :first_name, :last_name

# TODO: refactor these methods they are basically the same

def self.favorite_customers(count)
joins(invoices: :transactions).
where(transactions: {result: true}).
Expand All @@ -18,4 +20,12 @@ def self.favorite_customers(count)
def self.count_successful_transactions(id)
Customer.find(id).transactions.where(result: true).count
end

def self.top_customers
joins(invoices: :transactions)
.where(transactions: {result: true})
.group(:id).select("customers.*, COUNT(transactions) AS transaction_count")
.order("transaction_count desc")
.limit(5)
end
end
11 changes: 11 additions & 0 deletions app/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ def invoice_customer
def total_revenue
invoice_items.sum('invoice_items.unit_price * invoice_items.quantity')
end

def self.incomplete_invoices
joins(:invoice_items)
.where.not(invoice_items: {status: 1})
.distinct
.order(:created_at)
end

def self.invoices_with_merchant_items(merchant)
merchant.invoices.distinct(:id)
end
end
11 changes: 11 additions & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@ class Item < ApplicationRecord
validates_presence_of :name, :description, :unit_price

enum status: { 'disabled' => 0, 'enabled' => 1 }

def best_sales_date
invoices
.joins(:invoice_items)
.select("invoices.*, MAX(invoice_items.quantity) AS most_sold")
.group(:id)
.order(most_sold: :desc)
.first
.created_at
.strftime("%a, %d %b %Y")
end
end
14 changes: 7 additions & 7 deletions app/models/merchant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ class Merchant < ApplicationRecord

validates :name, presence: true

def items_ready_to_ship
Merchant.joins(invoice_items: [invoice: :transactions]).
where(merchants: {id: self.id}, invoice_items: {status: [0,2]}, invoices: {status: [1,2]}, transactions: {result: true}).
select("items.name, invoices.id, invoices.created_at").
order("invoices.created_at ASC")
end

def top_five_items
items
.joins(invoice_items: [invoice: :transactions])
Expand All @@ -16,11 +23,4 @@ def top_five_items
.order('revenue desc')
.limit(5)
end

def items_ready_to_ship
Merchant.joins(invoice_items: [invoice: :transactions]).
where(merchants: {id: self.id}, invoice_items: {status: [0,2]}, invoices: {status: [1,2]}, transactions: {result: true}).
select("items.name, invoices.id, invoices.created_at").
order("invoices.created_at ASC")
end
end
27 changes: 27 additions & 0 deletions app/views/admin/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= render 'partials/navbar_admin' %>
<%= render 'partials/two_columns' %>

<div class="row">
<div class="column";>
<div class ="incomplete-invoices">
<h3 style="text-align:center;"> Incomplete Invoices </h3>
<hr><br>
<ul><% @invoices.incomplete_invoices.each do |invoice| %>
<li> <%= link_to "#{invoice.id}", admin_invoice_path(invoice) %> <i>Created on: <%= invoice.created_at.strftime("%A, %d %b %Y") %> </i></li>
<% end %></ul>
</div>
</div>


<div class="column">
<div class="top-five-customers">
<h3 style="text-align:center;">Top Customers</h3>
<hr><br>
<ol>
<% @customers.top_customers.each do |customer| %>
<h5><li><%= "#{customer.first_name} #{customer.last_name}" %> - <%= customer.transaction_count %> purchases</li></h5><br>
<% end %>
</ol>
</div>
</div>
</div>
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions app/views/admin/merchants/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>Admin Merchants Index</h1>

<div class="merchant_index">
<ul><% @merchants.each do |merchant| %>
<li><%= merchant.name %></li>
<% end %></ul>
</div>
1 change: 1 addition & 0 deletions app/views/admin/merchants/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1><%= @merchant.name %>'s Admin Page</h1>
11 changes: 9 additions & 2 deletions app/views/invoices/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@
<h2>Invoice Items</h2>
<div class="invoice_items">
<% @invoice.invoice_items.each do |invoice_item| %>
<div id="<%= invoice_item.id %>">
<h4>Item Name: <%= invoice_item.item.name %></h4>
<p>Quantity Sold: <%= invoice_item.quantity %></p>
<p>Sold at: <%= number_to_currency(invoice_item.unit_price) %></p>
<p>Invoice Item Status: <%= invoice_item.status.titleize %></p>
<hr>
<%= form_with url: merchant_invoice_path(@merchant, @invoice), method: :patch do |form| %>
<%= form.select :status, ['pending', 'shipped', 'packaged'], selected: invoice_item.status %>
<%= hidden_field_tag "invoice_item_id", "#{invoice_item.id}" %>
<%= form.submit "Update Invoice Item Status" %>
<% end %>
</div>
<hr>
<% end %>
</div>

Total Revenue: <%= number_to_currency(@invoice.total_revenue) %>
<p><b>Total Revenue:</b> <%= number_to_currency(@invoice.total_revenue) %></p>
3 changes: 1 addition & 2 deletions app/views/items/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<% end %></ul>
</div>


<div class="disabled-items">
<h3>Status: Disabled</h3>
<ul><% @items.each do |item| %>
Expand All @@ -30,12 +29,12 @@
<% end %></ul>
</div>


<div class="top-5">
<h3> Top Five Most Popular Items: </h3>
<ol>
<% @merchant.top_five_items.each do |item| %>
<li> <%= link_to "#{item.name}", merchant_item_path(@merchant, item) %> <i>Total Revenue: <%= number_to_currency(item.revenue) %></i></li>
<p>Top selling date for <%= item.name %> was <%= item.best_sales_date %></p>
<% end %>
</ol>
</div>
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<%= render 'partials/jumbotron' %>
<title>LittleEtsyShop</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
Expand All @@ -10,7 +11,6 @@
</head>

<body>

<% flash.each do |type, msg| %>
<div>
<h3 style= "color:orange"> <%= msg %> </h3>
Expand Down
26 changes: 26 additions & 0 deletions app/views/partials/_jumbotron.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4" style="text-align:center;">Little Esty Shop</h1>
<!-- <p class="lead">This is a modified jumbotron that occupies the entire horizontal space of its parent.</p> -->
</div>
</div>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bootstrap Navbar Sidebar - Fixed to Left or Right</title>
<link rel="stylesheet"
id="theme_link"
href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/4.3.1/materia/bootstrap.min.css"/>
<link rel="stylesheet" href="navbar-fixed-right.min.css">
<link rel="stylesheet" href="navbar-fixed-left.min.css">
<link rel="stylesheet" href="docs.css">
<script
src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha256-pasqAKBDmFT4eHoN2ndd6lN370kFiGUFyTiUHWhU7k8="
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>
<script src="docs.js"></script>
<script async defer src="https://buttons.github.io/buttons.js"></script>
</head>
12 changes: 12 additions & 0 deletions app/views/partials/_navbar_admin.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Welcome to the Admin Dashboard</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link" href="/admin/merchants">Merchants Index</a>
<a class="nav-item nav-link" href="/admin/invoices">Invoices Index</a>
</div>
</div>
</nav>
26 changes: 26 additions & 0 deletions app/views/partials/_two_columns.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}

/* Create two equal columns that floats next to each other */
.column {
float: center;
width: 50%;
padding: 10%;
<!-- border: 1px solid black; -->
}

/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
</style>
</head>
<body>
7 changes: 5 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

resources :merchants, except: [:show] do
resources :items, only: [:index, :show, :edit, :update, :new, :create]
resources :invoices, only: [:index, :show]
resources :invoices, only: [:index, :show, :update]
end

resources :admin, only: [:index]

namespace :admin do
resources :merchants
resources :merchants, only: [:index, :show]
resources :invoices, only: [:index, :show]
end
end
Loading