Skip to content

Commit

Permalink
Add method for pending invoices
Browse files Browse the repository at this point in the history
Add route and controller for pending invoices
  • Loading branch information
epintozzi committed Dec 2, 2016
1 parent 4df20fc commit 3294cbe
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Api::V1::Merchants::PendingInvoicesController < ApplicationController

def index
merchant = Merchant.find(params[:merchant_id])
render json: merchant.customers_with_pending_invoices
end

end
2 changes: 1 addition & 1 deletion app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ def favorite_merchant

Merchant.find(merchant_id)
end

end
4 changes: 4 additions & 0 deletions app/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ class Invoice < ApplicationRecord
has_many :transactions
has_many :invoice_items
has_many :items, through: :invoice_items

scope :successful, -> { includes(:transactions).where(transactions: {result: "success"}) }
scope :pending, -> { where.not(id: Transaction.where(result: "success").pluck('DISTINCT invoice_id') ) }

end
4 changes: 4 additions & 0 deletions app/models/merchant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ def self.top_merchants_by_items_sold(number)
joins(invoices: [:invoice_items, :transactions]).merge(Transaction.successful).group(:id).order("sum(invoice_items.quantity) DESC").limit(number)
end

def customers_with_pending_invoices
customers.where(id: invoices.pending.pluck('DISTINCT customer_id')).uniq
end

end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
resources :invoices, only: [:index]
get '/favorite_customer' => 'favorite_customers#index', as: "favorite_customer"
get '/revenue' => 'revenues#index', as: "revenue"
get '/customers_with_pending_invoices' => 'pending_invoices#index', as: "customers_with_pending_invoices"
end
end

Expand Down
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"covered_percent": 95.7
"covered_percent": 95.38
}
}
10 changes: 9 additions & 1 deletion coverage/.resultset.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@
1,
1,
1,
null,
1,
1,
null,
null
],
"/Users/ebarth26/turing/3module/projects/rales_engine/app/models/item.rb": [
Expand Down Expand Up @@ -353,6 +357,10 @@
1,
null,
null,
1,
0,
null,
null,
null
],
"/Users/ebarth26/turing/3module/projects/rales_engine/app/models/transaction.rb": [
Expand Down Expand Up @@ -648,6 +656,6 @@
null
]
},
"timestamp": 1480658955
"timestamp": 1480662335
}
}
92 changes: 70 additions & 22 deletions coverage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@
<img src="./assets/0.10.0/loading.gif" alt="loading"/>
</div>
<div id="wrapper" style="display:none;">
<div class="timestamp">Generated <abbr class="timeago" title="2016-12-01T23:09:15-07:00">2016-12-01T23:09:15-07:00</abbr></div>
<div class="timestamp">Generated <abbr class="timeago" title="2016-12-02T00:05:35-07:00">2016-12-02T00:05:35-07:00</abbr></div>
<ul class="group_tabs"></ul>

<div id="content">
<div class="file_list_container" id="AllFiles">
<h2>
<span class="group_name">All Files</span>
(<span class="covered_percent"><span class="green">95.7%</span></span>
(<span class="covered_percent"><span class="green">95.38%</span></span>
covered at
<span class="covered_strength">
<span class="green">
1.1
1.09
</span>
</span> hits/line)
</h2>
<a name="AllFiles"></a>
<div>
<b>59</b> files in total.
<b>256</b> relevant lines.
<span class="green"><b>245</b> lines covered</span> and
<span class="red"><b>11</b> lines missed </span>
<b>260</b> relevant lines.
<span class="green"><b>248</b> lines covered</span> and
<span class="red"><b>12</b> lines missed </span>
</div>
<table class="file_list">
<thead>
Expand Down Expand Up @@ -403,9 +403,9 @@ <h2>
<tr>
<td class="strong"><a href="#a46f2d4d049743599298ff881346d330513aa84c" class="src_link" title="app/models/invoice.rb">app/models/invoice.rb</a></td>
<td class="green strong">100.0 %</td>
<td>7</td>
<td>6</td>
<td>6</td>
<td>11</td>
<td>8</td>
<td>8</td>
<td>0</td>
<td>1.0</td>
</tr>
Expand All @@ -432,12 +432,12 @@ <h2>

<tr>
<td class="strong"><a href="#4b79d10e1e3c8f99254e0a16547821fbd390ec92" class="src_link" title="app/models/merchant.rb">app/models/merchant.rb</a></td>
<td class="green strong">95.0 %</td>
<td>39</td>
<td class="green strong">90.91 %</td>
<td>43</td>
<td>22</td>
<td>20</td>
<td>19</td>
<td>1</td>
<td>1.2</td>
<td>2</td>
<td>1.1</td>
</tr>

<tr>
Expand Down Expand Up @@ -3463,7 +3463,7 @@ <h4><span class="red">62.5 %</span> covered</h4>
<li class="never" data-hits="" data-linenumber="13">


<code class="ruby"> </code>
<code class="ruby"></code>
</li>

<li class="never" data-hits="" data-linenumber="14">
Expand All @@ -3481,8 +3481,8 @@ <h4><span class="red">62.5 %</span> covered</h4>
<h3>app/models/invoice.rb</h3>
<h4><span class="green">100.0 %</span> covered</h4>
<div>
<b>6</b> relevant lines.
<span class="green"><b>6</b> lines covered</span> and
<b>8</b> relevant lines.
<span class="green"><b>8</b> lines covered</span> and
<span class="red"><b>0</b> lines missed.</span>
</div>
</div>
Expand Down Expand Up @@ -3529,6 +3529,30 @@ <h4><span class="green">100.0 %</span> covered</h4>
<li class="never" data-hits="" data-linenumber="7">


<code class="ruby"></code>
</li>

<li class="covered" data-hits="1" data-linenumber="8">
<span class="hits">1</span>

<code class="ruby"> scope :successful, -&gt; { includes(:transactions).where(transactions: {result: &quot;success&quot;}) }</code>
</li>

<li class="covered" data-hits="1" data-linenumber="9">
<span class="hits">1</span>

<code class="ruby"> scope :pending, -&gt; { where.not(id: Transaction.where(result: &quot;success&quot;).pluck(&#39;DISTINCT invoice_id&#39;) ) }</code>
</li>

<li class="never" data-hits="" data-linenumber="10">


<code class="ruby"></code>
</li>

<li class="never" data-hits="" data-linenumber="11">


<code class="ruby">end</code>
</li>

Expand Down Expand Up @@ -3713,11 +3737,11 @@ <h4><span class="yellow">90.0 %</span> covered</h4>
<div class="source_table" id="4b79d10e1e3c8f99254e0a16547821fbd390ec92">
<div class="header">
<h3>app/models/merchant.rb</h3>
<h4><span class="green">95.0 %</span> covered</h4>
<h4><span class="green">90.91 %</span> covered</h4>
<div>
<b>20</b> relevant lines.
<span class="green"><b>19</b> lines covered</span> and
<span class="red"><b>1</b> lines missed.</span>
<b>22</b> relevant lines.
<span class="green"><b>20</b> lines covered</span> and
<span class="red"><b>2</b> lines missed.</span>
</div>
</div>

Expand Down Expand Up @@ -3952,7 +3976,31 @@ <h4><span class="green">95.0 %</span> covered</h4>
<code class="ruby"></code>
</li>

<li class="never" data-hits="" data-linenumber="39">
<li class="covered" data-hits="1" data-linenumber="39">
<span class="hits">1</span>

<code class="ruby"> def customers_with_pending_invoices</code>
</li>

<li class="missed" data-hits="0" data-linenumber="40">


<code class="ruby"> customers.where(id: invoices.pending.pluck(&#39;DISTINCT customer_id&#39;)).uniq</code>
</li>

<li class="never" data-hits="" data-linenumber="41">


<code class="ruby"> end</code>
</li>

<li class="never" data-hits="" data-linenumber="42">


<code class="ruby"></code>
</li>

<li class="never" data-hits="" data-linenumber="43">


<code class="ruby">end</code>
Expand Down

0 comments on commit 3294cbe

Please sign in to comment.