/** * Displays "Monthly Report" meta box. */ public function monthlyReport() { $currentMonth = intval(date('m')); $currentYear = intval(date('Y')); $currentDay = intval(date('d')); $selectedMonth = isset($_GET['month']) ? intval($_GET['month']) : $currentMonth; $selectedYear = isset($_GET['year']) ? intval($_GET['year']) : $currentYear; $nextYear = $selectedMonth == 12 ? $selectedYear + 1 : $selectedYear; $nextMonth = $selectedMonth == 12 ? 1 : $selectedMonth + 1; $previousYear = $selectedMonth == 1 ? $selectedYear - 1 : $selectedYear; $previousMonth = $selectedMonth == 1 ? 12 : $selectedMonth - 1; $orders = $this->orderService->findFromMonth($selectedMonth, $selectedYear); $currentTime = strtotime($selectedYear . '-' . $selectedMonth . '-1'); if ($currentTime >= strtotime($currentYear . '-' . $currentMonth . '-1')) { $days = range($currentTime, strtotime($currentYear . '-' . $currentMonth . '-' . $currentDay + 1), 24 * 3600); } else { $days = range($currentTime, strtotime($nextYear . '-' . $nextMonth . '-1'), 24 * 3600); } $orderAmountsData = $orderCountsData = array_fill_keys($days, 0); $orderAmounts = $orderCounts = array(); foreach ($orders as $order) { /** @var $order Order */ $debug = $order->getStateToSave(); unset($debug['items']); $day = strtotime($order->getCreatedAt()->format('Y-m-d')); $orderCountsData[$day] += 1; $orderAmountsData[$day] += $order->getSubtotal() + $order->getShippingPrice(); } foreach ($orderCountsData as $day => $value) { $orderCounts[] = array($day, $value); } foreach ($orderAmountsData as $day => $value) { $orderAmounts[] = array($day, $value); } unset($orderAmountsData, $orderCountsData); Render::output('admin/dashboard/monthlyReport', array('orders' => $orders, 'selectedMonth' => $selectedMonth, 'selectedYear' => $selectedYear, 'currentMonth' => $currentMonth, 'currentYear' => $currentYear, 'nextMonth' => $nextMonth, 'nextYear' => $nextYear, 'previousMonth' => $previousMonth, 'previousYear' => $previousYear, 'orderCounts' => $orderCounts, 'orderAmounts' => $orderAmounts)); }
/** * @param $month int Month to find orders from. * @param $year int Year to find orders from. * @return array List of orders from selected month. */ public function findFromMonth($month, $year) { return $this->service->findFromMonth($month, $year); }