diff --git a/services/nginx/app/objects/orders_o.php b/services/nginx/app/objects/orders_o.php index cf2e1d9f..68cc8ee4 100644 --- a/services/nginx/app/objects/orders_o.php +++ b/services/nginx/app/objects/orders_o.php @@ -289,4 +289,17 @@ class orders_o extends db } return false; } + + /** + * Get the order history for a vehicle plate + * @param string $plate The vehicle plate + * @return array The order history + */ + public function get_vehicle_order_history(string $plate): array + { + global $db; + $sql = "SELECT * FROM $this->table WHERE reg_1 = '$plate' OR reg_2 = '$plate' OR reg_3 = '$plate'"; + $result = $db->query($sql); + return $db->fetch_all($result); + } } \ No newline at end of file diff --git a/services/nginx/app/routes/vehiclePlateLookupRoute.php b/services/nginx/app/routes/vehiclePlateLookupRoute.php new file mode 100644 index 00000000..30992e1a --- /dev/null +++ b/services/nginx/app/routes/vehiclePlateLookupRoute.php @@ -0,0 +1,38 @@ +get('/department/license-plate/lookup', function () { + // Require the user to be logged in + global $response; + $this->requirePermission('department_license_plate_lookup'); + // Get the user object + $user = (new authentication())->get_user(); + // Check if the request was successful + if ($user) { + // Make sure the vehicle plate is set + if (!(string)$this->fromRequest('plate')) { + $response->error('Plate parameter is required', 400); + } + // Return the vehicle order history + $response->success((new orders_o())->get_vehicle_order_history($this->fromRequest('plate'))); + } else { + // Log the incident + (new logs_o())->add('orders', 'global', 1, 0, 'FETCH_VEHICLE_ORDER_HISTORY', 'No user found, or invalid session'); + // Return an error + $response->error('Invalid session', 400); + } + }); + } +} \ No newline at end of file diff --git a/services/nginx/app/statistics/economic_s.php b/services/nginx/app/statistics/economic_s.php index 4b621420..2790af59 100644 --- a/services/nginx/app/statistics/economic_s.php +++ b/services/nginx/app/statistics/economic_s.php @@ -280,22 +280,56 @@ class economic_s // Get the economic class $economic = new economic(); - $drafts = $economic->invoices->drafts->get([ - '(date$gte:' . $start . '$and:date$lte:' . $end . ')' => '', // To allow for time filtering, we need to add the time frame to the query - ], - [ - 'skipPages' => 0, - 'pageSize' => 1000, // Since the limit is 1000, we need to set the page size to 1000. - ] - )->collection; - $booked = $economic->invoices->booked->get([ - '(date$gte:' . $start . '$and:date$lte:' . $end . ')' => '', // To allow for time filtering, we need to add the time frame to the query - ], - [ - 'skipPages' => 0, - 'pageSize' => 1000, // Since the limit is 1000, we need to set the page size to 1000. - ] - )->collection; + $repeat['drafts'] = [ + 'invoiceCount' => 0, + 'repeat' => true, + 'pageCount' => 0, + ]; + $drafts = []; + while ($repeat['drafts']['repeat']) { + $repeat['drafts']['repeat'] = false; + // Merge the draft collection, since the limit is 1000, we need to get all the drafts + $drafts_tmp = $economic->invoices->drafts->get([ + '(date$gte:' . $start . '$and:date$lte:' . $end . ')' => '', // To allow for time filtering, we need to add the time frame to the query + ], + [ + 'skipPages' => $repeat['drafts']['pageCount'], + 'pageSize' => 1000, // Since the limit is 1000, we need to set the page size to 1000. + ] + )->collection; + $drafts = array_merge($drafts, $drafts_tmp); + + // If the count of the drafts is equal to the limit, we need to repeat the process + if (count($drafts_tmp) == 1000) { + $repeat['drafts']['repeat'] = true; + $repeat['drafts']['pageCount']++; + } + } + $repeat['booked'] = [ + 'invoiceCount' => 0, + 'repeat' => true, + 'pageCount' => 0, + ]; + $booked = []; + while ($repeat['booked']['repeat']) { + $repeat['booked']['repeat'] = false; + // Merge the booked collection, since the limit is 1000, we need to get all the booked + $booked_tmp = $economic->invoices->booked->get([ + '(date$gte:' . $start . '$and:date$lte:' . $end . ')' => '', // To allow for time filtering, we need to add the time frame to the query + ], + [ + 'skipPages' => $repeat['booked']['invoiceCount'], + 'pageSize' => 1000, // Since the limit is 1000, we need to set the page size to 1000. + ] + )->collection; + $booked = array_merge($booked, $booked_tmp); + + // If the count of the booked is equal to the limit, we need to repeat the process + if (count($booked_tmp) == 1000) { + $repeat['booked']['repeat'] = true; + $repeat['booked']['pageCount']++; + } + } $drafts_total = 0; $booked_total = 0;