diff --git a/services/nginx/app/routes/InvoicingPeriodRoute.php b/services/nginx/app/routes/InvoicingPeriodRoute.php index 54615782..3707432b 100644 --- a/services/nginx/app/routes/InvoicingPeriodRoute.php +++ b/services/nginx/app/routes/InvoicingPeriodRoute.php @@ -77,6 +77,38 @@ class InvoicingPeriodRoute ] ); + + $this->get('/superuser/invoicing/period/distribution/all', function () { + // Require the user to be logged in + global $response; + //$this->requirePermission('superuser_invoicing_period'); + self::requireParameters([ + 'dateFrom', + 'dateTo', + ]); + $dateFrom = $this->getParameter('dateFrom'); + $dateTo = $this->getParameter('dateTo'); + // Require the dateFrom and dateTo parameters to be valid dates + self::requireDateFormat($dateFrom, 'Y-m-d'); + self::requireDateFormat($dateTo, 'Y-m-d'); + // Add a day to the dateTo parameter to include the end date in the range + $dateTo = date('Y-m-d 23:59:59', strtotime($dateTo)); + $dateFrom = date('Y-m-d 00:00:00', strtotime($dateFrom)); + // Add date from and date to to the response meta + $response->add_meta('date_from', $dateFrom); + $response->add_meta('date_to', $dateTo); + $result = [ + 'subscriptions' => self::getTransactionsWithItemsNotIncludedInInvoices(self::getVehicleSubscriptions($dateFrom, $dateTo)), + 'fixed_pricing' => self::getOriginalPrice(self::getFixedPricing($dateFrom, $dateTo)), + + ]; + $response->success($result); + }, + [ + 'superuser_invoicing_period' => 'Get the invoicing period for superusers', + ] + ); + $this->get('/superuser/invoicing/period/distribution/fixed-pricing', function () { // Require the user to be logged in global $response; @@ -91,7 +123,11 @@ class InvoicingPeriodRoute self::requireDateFormat($dateFrom, 'Y-m-d'); self::requireDateFormat($dateTo, 'Y-m-d'); // Add a day to the dateTo parameter to include the end date in the range - $dateTo = date('Y-m-d', strtotime($dateTo . ' +1 day')); + $dateFrom = date('Y-m-d 00:00:00', strtotime($dateFrom)); + $dateTo = date('Y-m-d 23:59:59', strtotime($dateTo)); + // Add date from and date to to the response meta + $response->add_meta('date_from', $dateFrom); + $response->add_meta('date_to', $dateTo); $response->success([...self::getOriginalPrice(self::getFixedPricing($dateFrom, $dateTo))]); }, [ @@ -113,7 +149,11 @@ class InvoicingPeriodRoute self::requireDateFormat($dateFrom, 'Y-m-d'); self::requireDateFormat($dateTo, 'Y-m-d'); // Add a day to the dateTo parameter to include the end date in the range - $dateTo = date('Y-m-d', strtotime($dateTo . ' +1 day')); + $dateFrom = date('Y-m-d 00:00:00', strtotime($dateFrom)); + $dateTo = date('Y-m-d 23:59:59', strtotime($dateTo)); + // Add date from and date to to the response meta + $response->add_meta('date_from', $dateFrom); + $response->add_meta('date_to', $dateTo); $response->success([...self::getTransactionsWithItemsNotIncludedInInvoices(self::getVehicleSubscriptions($dateFrom, $dateTo))]); }, [