Skip to content

Commit

Permalink
Merge branch 'feature/add-order-scoreboards' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
dshoreman committed Nov 8, 2014
2 parents 7534d95 + 0f5a2d9 commit c66ecbd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
30 changes: 30 additions & 0 deletions controllers/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,36 @@ public function __construct()
BackendMenu::setContext('DShoreman.Shop', 'shop', 'orders');
}

public function index()
{
$this->vars['ordersTotal'] = Order::count();
$this->vars['ordersTotalLast'] = 17;

$this->vars['ordersPaid'] = Order::where('is_paid', 1)->count();
$this->vars['ordersPending'] = $this->vars['ordersTotal'] - $this->vars['ordersPaid'];

$c = $this->vars['ordersCount'] = Order::createdThisMonth()->count();
$cl = $this->vars['ordersCountLast'] = Order::createdLastMonth()->count();
$this->vars['ordersCountClass'] = $this->scoreboardClass($cl, $c);

$v = $this->vars['ordersValue'] = Order::createdThisMonth()->sum('total');
$vl = $this->vars['ordersValueLast'] = Order::createdLastMonth()->sum('total');
$this->vars['ordersValueClass'] = $this->scoreboardClass($vl, $v);

return $this->asExtension('ListController')->index();
}

public function scoreboardClass($oldVal, $newVal)
{
if ($newVal > $oldVal)
return 'positive';

if ($oldVal > $newVal)
return 'negative';

return '';
}

public function update($recordId, $context = null)
{
$this->vars['itemCount'] = 0;
Expand Down
15 changes: 7 additions & 8 deletions controllers/orders/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@
<div data-control="toolbar">
<div class="scoreboard-item control-chart" data-control="chart-pie">
<ul>
<li data-color="#95b753">Paid <span>2</span></li>
<li data-color="#e5a91a">Pending <span>5</span></li>
<li data-color="#95b753">Paid <span><?= $ordersPaid ?></span></li>
<li data-color="#e5a91a">Pending <span><?= $ordersPending ?></span></li>
</ul>
</div>
<div class="scoreboard-item title-value">
<h4>All Orders</h4>
<p>59</p>
<p class="description">previous: 17</p>
<p><?= $ordersTotal ?></p>
</div>
<div class="scoreboard-item title-value">
<h4>Orders this Month</h4>
<p class="positive">42</p>
<p class="description">previous: 17</p>
<p class="<?= $ordersCountClass ?>"><?= $ordersCount ?></p>
<p class="description">previous: <?= $ordersCountLast ?></p>
</div>
<div class="scoreboard-item title-value">
<h4>Sales</h4>
<p class="negative">&pound;1432.87</p>
<p class="description">previous: &pound;1768.13</p>
<p class="<?= $ordersValueClass ?>">&pound;<?= $ordersValue ?></p>
<p class="description">previous: &pound;<?= $ordersValueLast ?></p>
</div>

</div>
Expand Down
14 changes: 14 additions & 0 deletions models/Order.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace DShoreman\Shop\Models;

use Carbon\Carbon;
use Model;

/**
Expand Down Expand Up @@ -36,4 +37,17 @@ class Order extends Model
public $attachOne = [];
public $attachMany = [];

public function scopeCreatedThisMonth($query)
{
return $query->where('created_at', '>=', Carbon::now()->startOfMonth());
}

public function scopeCreatedLastMonth($query)
{
return $query->whereBetween('created_at', [
Carbon::now()->subMonth()->startOfMonth(),
Carbon::now()->subMonth()->endOfMonth()
]);
}

}

0 comments on commit c66ecbd

Please sign in to comment.