diff --git a/include/controllers/default/cockpit/community/index.php b/include/controllers/default/cockpit/community/index.php
index f5a5a472b..8ace3dc18 100644
--- a/include/controllers/default/cockpit/community/index.php
+++ b/include/controllers/default/cockpit/community/index.php
@@ -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]);
+ }
}
\ No newline at end of file
diff --git a/include/library/Crunchbutton/Restaurant.php b/include/library/Crunchbutton/Restaurant.php
index a26fb8ba2..2627c7e52 100644
--- a/include/library/Crunchbutton/Restaurant.php
+++ b/include/library/Crunchbutton/Restaurant.php
@@ -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 ){
diff --git a/include/views/default/cockpit/community/csv.phtml b/include/views/default/cockpit/community/csv.phtml
new file mode 100644
index 000000000..3ead6c1aa
--- /dev/null
+++ b/include/views/default/cockpit/community/csv.phtml
@@ -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";
+}
+?>
\ No newline at end of file
diff --git a/include/views/default/cockpit/community/index.phtml b/include/views/default/cockpit/community/index.phtml
index f0214c8de..8137c6523 100644
--- a/include/views/default/cockpit/community/index.phtml
+++ b/include/views/default/cockpit/community/index.phtml
@@ -19,6 +19,10 @@
}
?>
+
+
+ Report (orders for the past 14 days by community)
+