public function forTemplate() { $this->setTemplate('ReportPage'); $this->setData('Title', 'Reports'); $this->setData('TotalCustomers', $this->data['TotalCustomers'] ?? CustomerRepository::getTotalCount()); $this->setData('TotalOrders', $this->data['TotalOrders'] ?? OrderRepository::getTotalCount()); $this->setData('TopCustomersByNumOfOrders', $this->data['TopCustomersByNumOfOrders'] ?? CustomerRepository::getTopByNumOfOrders()); $this->setData('TopOrdersByRevenue', $this->data['TopOrdersByRevenue'] ?? OrderRepository::getTopOrdersByRevenue()); $this->setData('FilterForm', $this->getFilterForm(), false); parent::forTemplate(); }
public function chartdata() { $customers = CustomerRepository::getAll(); $orders = OrderRepository::getAll(); foreach ($customers as $customer) { $date = (string) $customer->getCreated(); $data[$date] = $data[$date] ?? ['Customers' => 0, 'Orders' => 0]; $data[$date]['Customers']++; } foreach ($orders as $order) { $date = (string) $order->getPurchaseDate(); $data[$date] = $data[$date] ?? ['Customers' => 0, 'Orders' => 0]; $data[$date]['Orders']++; } //format data for the map foreach ($data as $date => $value) { $formattedData[] = [$date, $value['Customers'], $value['Orders']]; } sort($formattedData); $formattedData[0] = ['Day', 'Customer', 'Orders']; return $this->handleJsonResponse($formattedData); }