Report - orders for the last past 14 days
This commit is contained in:
parent
3354fa1163
commit
b51c75415a
@ -12,6 +12,12 @@ class Controller_community extends Crunchbutton_Controller_Account {
|
||||
|
||||
c::view()->page = 'community';
|
||||
|
||||
// Report with the orders from the last 14 days
|
||||
if( $slug == 'report' ){
|
||||
$this->report();
|
||||
exit;
|
||||
}
|
||||
|
||||
if( $slug ){
|
||||
|
||||
$permission = "community-communities-{$slug}";
|
||||
@ -128,5 +134,23 @@ class Controller_community extends Crunchbutton_Controller_Account {
|
||||
return $info;
|
||||
}
|
||||
|
||||
public function report(){
|
||||
$interval = 14;
|
||||
$communities = Restaurant::getCommunities();
|
||||
$orders = [];
|
||||
$days = [];
|
||||
foreach ( $communities as $community ) {
|
||||
$orders[ $community ] = Restaurant::getOrdersFromLastDaysByCommunity( $community, $interval );
|
||||
}
|
||||
$today = new DateTime( $time, new DateTimeZone( 'America/Los_Angeles' ) );
|
||||
for( $i = 0; $i <= $interval; $i++ ){
|
||||
$days[] = $today->format( 'm/d/Y' );
|
||||
$today->modify( '-1 day' );
|
||||
}
|
||||
c::view()->days = $days;
|
||||
c::view()->orders = $orders;
|
||||
c::view()->layout('layout/csv');
|
||||
c::view()->display('community/csv', ['display' => true, 'filter' => false]);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1627,6 +1627,13 @@ class Crunchbutton_Restaurant extends Cana_Table_Trackchange {
|
||||
return Hour::restaurantClosesIn( $this );
|
||||
}
|
||||
|
||||
public function getOrdersFromLastDaysByCommunity( $community, $days = 14 ){
|
||||
$query = "SELECT SUM(1) orders, DATE_FORMAT( o.date, '%m/%d/%Y' ) day FROM `order` o
|
||||
INNER JOIN restaurant r ON r.id_restaurant = o.id_restaurant AND r.community = '$community'
|
||||
WHERE o.date > DATE_SUB(CURDATE(), INTERVAL $days DAY) AND o.name NOT LIKE '%test%' GROUP BY day ORDER BY o.date ASC";
|
||||
return c::db()->get( $query );
|
||||
}
|
||||
|
||||
// Return minutes left to open
|
||||
public function opensIn( $dt = null ) {
|
||||
if( $this->open_for_business ){
|
||||
|
||||
26
include/views/default/cockpit/community/csv.phtml
Normal file
26
include/views/default/cockpit/community/csv.phtml
Normal file
@ -0,0 +1,26 @@
|
||||
<?
|
||||
$separator = ',';
|
||||
$headers = [ 'Date' ];
|
||||
foreach( $this->orders as $communities => $day ){
|
||||
$headers[] = $communities;
|
||||
}
|
||||
echo implode( $separator, $headers ) . "\n";
|
||||
|
||||
// print dates
|
||||
$content = [];
|
||||
foreach( $this->days as $day ){
|
||||
ob_start();
|
||||
echo $day . $separator;
|
||||
foreach( $this->orders as $communities => $days ){
|
||||
foreach( $days as $orders ){
|
||||
if( $orders->day == $day ){
|
||||
echo $orders->orders;
|
||||
}
|
||||
}
|
||||
echo $separator;
|
||||
}
|
||||
$output = ob_get_clean();
|
||||
$output = preg_replace('/\n|\r|\t/i', '', $output);
|
||||
echo "$output\n";
|
||||
}
|
||||
?>
|
||||
@ -19,6 +19,10 @@
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<br/><br/><br/>
|
||||
<a class="btn btn-default" href="/community/report/">
|
||||
<i class="icon-cloud-download"></i> Report (orders for the past 14 days by community)</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user