diff --git a/application/WarehouseShippingNote/WarehouseShippingNoteController.php b/application/WarehouseShippingNote/WarehouseShippingNoteController.php
index 8f9e179fe..f4820c5f5 100644
--- a/application/WarehouseShippingNote/WarehouseShippingNoteController.php
+++ b/application/WarehouseShippingNote/WarehouseShippingNoteController.php
@@ -671,6 +671,74 @@ class WarehouseShippingNoteController extends TTCrud {
}
}
+ protected function getRecentCalendarEventsAction()
+ {
+ $worker = UserModel::getOne($this->user->id);
+ if (!$worker || !empty($worker->name)) {
+ die($worker->name);
+ self::returnJson([]);
+ return;
+ }
+
+ $calendars = CalendarModel::getAll();
+
+ // loop through all calendars and find the one with user_id as the worker's id
+ $calendarId = null;
+ foreach ($calendars as $calendar) {
+ if ($calendar->user_id == $worker->id) {
+ $calendarId = $calendar->go_calendar_id;
+ break;
+ }
+ }
+
+ $eventsJson = CalendarModel::getCalendarEvents($this->user);
+ $allEvents = json_decode($eventsJson, true)['data'] ?? [];
+
+ if (!is_array($allEvents)) {
+ self::returnJson([]);
+ return;
+ }
+
+
+ $endDate = new DateTime();
+ $startDate = (new DateTime())->modify('-3 days');
+ $startTimestamp = $startDate->setTime(0, 0, 0)->getTimestamp();
+ $endTimestamp = $endDate->setTime(23, 59, 59)->getTimestamp();
+
+ $filteredEvents = array_filter($allEvents, function ($event) use ($startTimestamp, $endTimestamp, $calendarId) {
+ if (!isset($event['cstart']) && !isset($event['category']) || (intval($event['calendar_id']['calendar_id']) !== $calendarId)) {
+ return false;
+ }
+ $eventStartTimestamp = strtotime($event['cstart']['cstart'] ?? $event['cstart']);
+ if (empty($event['location']['location']) || empty($event['category']['category'])) {
+ return false;
+ }
+ if (date('H', $eventStartTimestamp) < 5 || date('H', $eventStartTimestamp) > 21) {
+ return false;
+ }
+
+ return $eventStartTimestamp >= $startTimestamp && $eventStartTimestamp <= $endTimestamp;
+ });
+
+ usort($filteredEvents, function ($a, $b) {
+ $timeA = strtotime($a['cstart']['cstart'] ?? $a['cstart']);
+ $timeB = strtotime($b['cstart']['cstart'] ?? $b['cstart']);
+ return $timeB <=> $timeA;
+ });
+
+ $limitedEvents = array_slice($filteredEvents, 0, 20);
+
+ $finalResponse = array_map(function ($event) {
+ $eventStart = $event['cstart']['cstart'] ?? $event['cstart'];
+ return [
+ 'date' => date('Y-m-d H:i:s', strtotime($eventStart)),
+ 'location' => $event['location']['location'] ?? '',
+ 'category' => $event['category']['category'] ?? ''
+ ];
+ }, $limitedEvents);
+
+ self::returnJson($finalResponse);
+ }
protected function createNewLogAction() {
$postData = json_decode(file_get_contents('php://input'), true);
diff --git a/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js b/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js
index 45c01e557..3a4df25d7 100644
--- a/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js
+++ b/public/js/pages/WarehouseShippingNote/WarehouseShippingNote.js
@@ -420,33 +420,53 @@ Vue.component('warehouse-shipping-note', {
@close="shippingNoteModalId = null;$refs.table.$refs.table.refreshTable()"
@open-article-modal="articleModalId = true;window.console.log($event)"
@open-signing-modal="signingShippingNoteId = $event"/>
-
-