@7365admin1/core 3.99.1-staging.407 → 3.99.1-staging.408

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@7365admin1/core": minor
3
+ ---
4
+
5
+ Dashboard Low Stock: each app's tile now lists only its own kind of organisation's inventory store at the site (a cleaning company no longer sees the security company's store, and the other way round), and the Property Management and Security dashboards gain the Low Stock tile (`supplyAlert`, basis `below-alert-level`) wherever their store serves the site. Sites without such a store are unchanged.
package/dist/index.d.ts CHANGED
@@ -15643,6 +15643,47 @@ declare function useNewDashboardRepo(): {
15643
15643
  period?: Period | undefined;
15644
15644
  type?: string | undefined;
15645
15645
  }) => Promise<{
15646
+ supplyAlert: {
15647
+ items: {
15648
+ name: any;
15649
+ qty: any;
15650
+ }[];
15651
+ basis: "below-alert-level";
15652
+ };
15653
+ openWorkOrder: {
15654
+ count: any;
15655
+ inProgress: any;
15656
+ percentage: number | null;
15657
+ };
15658
+ openIncidents: {
15659
+ count: any;
15660
+ highSeverity: number | null;
15661
+ highSeverityUnavailableReason: string;
15662
+ percentage: number | null;
15663
+ };
15664
+ visitors: {
15665
+ count: any;
15666
+ currentlyOnSite: number;
15667
+ percentage: number | null;
15668
+ };
15669
+ patrolCompliance: {
15670
+ count: number | null;
15671
+ checkpointsDue: any;
15672
+ unavailableReason: string | null;
15673
+ missedCheckpoints: any;
15674
+ missed: any;
15675
+ percentage: number | null;
15676
+ };
15677
+ activePatrolItems: {
15678
+ id: string;
15679
+ title: any;
15680
+ subtitle: string;
15681
+ person: any;
15682
+ status: any;
15683
+ time: string;
15684
+ }[];
15685
+ } | {
15686
+ supplyAlert?: undefined;
15646
15687
  openWorkOrder: {
15647
15688
  count: any;
15648
15689
  inProgress: any;
@@ -15677,6 +15718,56 @@ declare function useNewDashboardRepo(): {
15677
15718
  }[];
15678
15719
  }>;
15679
15720
  getPropertyManagementDashboard: (siteId: string, period?: Period, type?: string, facility?: string) => Promise<{
15721
+ supplyAlert: {
15722
+ items: {
15723
+ name: any;
15724
+ qty: any;
15725
+ }[];
15726
+ basis: "below-alert-level";
15727
+ };
15728
+ openWorkOrder: {
15729
+ count: any;
15730
+ inProgress: any;
15731
+ percentage: number | null;
15732
+ };
15733
+ openIncidents: {
15734
+ count: any;
15735
+ highSeverity: number | null;
15736
+ highSeverityUnavailableReason: string;
15737
+ percentage: number | null;
15738
+ };
15739
+ visitors: {
15740
+ count: any;
15741
+ currentlyOnSite: number;
15742
+ percentage: number | null;
15743
+ };
15744
+ facilityBooking: {
15745
+ count: any;
15746
+ ongoing: any;
15747
+ waitingApproval: any;
15748
+ byStatus: {
15749
+ Pending: number;
15750
+ Approved: number;
15751
+ Ongoing: number;
15752
+ "For Review": number;
15753
+ "With Balance": number;
15754
+ "With Refund": number;
15755
+ Completed: number;
15756
+ Rejected: number;
15757
+ Cancelled: number;
15758
+ };
15759
+ percentage: number | null;
15760
+ };
15761
+ workOrderStatus: {
15762
+ pending: number;
15763
+ inProgress: number;
15764
+ completed: number;
15765
+ };
15766
+ upcomingEvents: mongodb.WithId<bson.Document>[];
15767
+ todayReminders: mongodb.WithId<bson.Document>[];
15768
+ todayAttentions: any[];
15769
+ } | {
15770
+ supplyAlert?: undefined;
15680
15771
  openWorkOrder: {
15681
15772
  count: any;
15682
15773
  inProgress: any;
package/dist/index.js CHANGED
@@ -92248,7 +92248,7 @@ function useNewDashboardRepo() {
92248
92248
  },
92249
92249
  activePatrolItems
92250
92250
  };
92251
- return data;
92251
+ return { ...data, ...await inventorySupplyTile(siteIdObj, "security_agency") };
92252
92252
  }
92253
92253
  async function getPropertyManagementDashboard(siteId, period = "today" /* TODAY */, type, facility) {
92254
92254
  const siteIdObj = (0, import_node_server_utils261.toObjectId)(siteId);
@@ -92687,7 +92687,7 @@ function useNewDashboardRepo() {
92687
92687
  todayReminders,
92688
92688
  todayAttentions
92689
92689
  };
92690
- return data;
92690
+ return { ...data, ...await inventorySupplyTile(siteIdObj, "property_management_agency") };
92691
92691
  }
92692
92692
  function areaChecklistScheduleLookup(site, serviceType, createdAtRange) {
92693
92693
  return [
@@ -92712,24 +92712,38 @@ function useNewDashboardRepo() {
92712
92712
  { $unwind: { path: "$scheduleDoc", preserveNullAndEmptyArrays: false } }
92713
92713
  ];
92714
92714
  }
92715
+ async function inventoryLowStock(site, serviceType) {
92716
+ const natures = serviceType === "property_management_agency" ? ["property_management_agency", "real_estate_developer"] : [serviceType];
92717
+ const siteStores = await db2.collection("inventory.stores").find({ sites: site, status: "active" }, { projection: { _id: 1, org: 1 } }).toArray();
92718
+ if (!siteStores.length)
92719
+ return null;
92720
+ const ownOrgs = new Set(
92721
+ (await db2.collection("organizations").find(
92722
+ { _id: { $in: siteStores.map((store) => store.org) }, nature: { $in: natures } },
92723
+ { projection: { _id: 1 } }
92724
+ ).toArray()).map((org) => org._id.toString())
92725
+ );
92726
+ const stores = siteStores.filter((store) => ownOrgs.has(String(store.org)));
92727
+ if (!stores.length)
92728
+ return null;
92729
+ return db2.collection("inventory.items").aggregate([
92730
+ {
92731
+ $match: {
92732
+ store: { $in: stores.map((store) => store._id) },
92733
+ status: "active",
92734
+ reorderLevel: { $gt: 0 },
92735
+ $expr: { $lte: ["$onHand", "$reorderLevel"] }
92736
+ }
92737
+ },
92738
+ { $sort: { onHand: 1 } },
92739
+ { $limit: 5 },
92740
+ { $project: { _id: 1, name: 1, qty: "$onHand" } }
92741
+ ]).toArray();
92742
+ }
92715
92743
  async function lowStockItems(site, serviceType) {
92716
- const stores = await db2.collection("inventory.stores").find({ sites: site, status: "active" }, { projection: { _id: 1 } }).toArray();
92717
- if (stores.length) {
92718
- const items2 = await db2.collection("inventory.items").aggregate([
92719
- {
92720
- $match: {
92721
- store: { $in: stores.map((store) => store._id) },
92722
- status: "active",
92723
- reorderLevel: { $gt: 0 },
92724
- $expr: { $lte: ["$onHand", "$reorderLevel"] }
92725
- }
92726
- },
92727
- { $sort: { onHand: 1 } },
92728
- { $limit: 5 },
92729
- { $project: { _id: 1, name: 1, qty: "$onHand" } }
92730
- ]).toArray();
92731
- return { items: items2, basis: SUPPLY_BASIS_BELOW_ALERT_LEVEL };
92732
- }
92744
+ const inventory = await inventoryLowStock(site, serviceType);
92745
+ if (inventory)
92746
+ return { items: inventory, basis: SUPPLY_BASIS_BELOW_ALERT_LEVEL };
92733
92747
  const items = await supplyCollection.aggregate([
92734
92748
  { $match: { site, serviceType, status: "active" } },
92735
92749
  { $sort: { qty: 1 } },
@@ -92738,6 +92752,10 @@ function useNewDashboardRepo() {
92738
92752
  ]).toArray();
92739
92753
  return { items, basis: SUPPLY_BASIS_LOWEST_QUANTITY };
92740
92754
  }
92755
+ async function inventorySupplyTile(site, serviceType) {
92756
+ const items = await inventoryLowStock(site, serviceType);
92757
+ return items ? { supplyAlert: { items: items.map((item) => ({ name: item.name, qty: item.qty })), basis: SUPPLY_BASIS_BELOW_ALERT_LEVEL } } : {};
92758
+ }
92741
92759
  async function getServiceDashboard({
92742
92760
  site,
92743
92761
  serviceType,