@7365admin1/core 3.122.6 → 3.123.0

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.
package/dist/index.mjs CHANGED
@@ -89914,7 +89914,7 @@ function useNewDashboardRepo() {
89914
89914
  },
89915
89915
  activePatrolItems
89916
89916
  };
89917
- return data;
89917
+ return { ...data, ...await inventorySupplyTile(siteIdObj, "security_agency") };
89918
89918
  }
89919
89919
  async function getPropertyManagementDashboard(siteId, period = "today" /* TODAY */, type, facility) {
89920
89920
  const siteIdObj = toObjectId19(siteId);
@@ -90353,7 +90353,7 @@ function useNewDashboardRepo() {
90353
90353
  todayReminders,
90354
90354
  todayAttentions
90355
90355
  };
90356
- return data;
90356
+ return { ...data, ...await inventorySupplyTile(siteIdObj, "property_management_agency") };
90357
90357
  }
90358
90358
  function areaChecklistScheduleLookup(site, serviceType, createdAtRange) {
90359
90359
  return [
@@ -90378,24 +90378,38 @@ function useNewDashboardRepo() {
90378
90378
  { $unwind: { path: "$scheduleDoc", preserveNullAndEmptyArrays: false } }
90379
90379
  ];
90380
90380
  }
90381
+ async function inventoryLowStock(site, serviceType) {
90382
+ const natures = serviceType === "property_management_agency" ? ["property_management_agency", "real_estate_developer"] : [serviceType];
90383
+ const siteStores = await db2.collection("inventory.stores").find({ sites: site, status: "active" }, { projection: { _id: 1, org: 1 } }).toArray();
90384
+ if (!siteStores.length)
90385
+ return null;
90386
+ const ownOrgs = new Set(
90387
+ (await db2.collection("organizations").find(
90388
+ { _id: { $in: siteStores.map((store) => store.org) }, nature: { $in: natures } },
90389
+ { projection: { _id: 1 } }
90390
+ ).toArray()).map((org) => org._id.toString())
90391
+ );
90392
+ const stores = siteStores.filter((store) => ownOrgs.has(String(store.org)));
90393
+ if (!stores.length)
90394
+ return null;
90395
+ return db2.collection("inventory.items").aggregate([
90396
+ {
90397
+ $match: {
90398
+ store: { $in: stores.map((store) => store._id) },
90399
+ status: "active",
90400
+ reorderLevel: { $gt: 0 },
90401
+ $expr: { $lte: ["$onHand", "$reorderLevel"] }
90402
+ }
90403
+ },
90404
+ { $sort: { onHand: 1 } },
90405
+ { $limit: 5 },
90406
+ { $project: { _id: 1, name: 1, qty: "$onHand" } }
90407
+ ]).toArray();
90408
+ }
90381
90409
  async function lowStockItems(site, serviceType) {
90382
- const stores = await db2.collection("inventory.stores").find({ sites: site, status: "active" }, { projection: { _id: 1 } }).toArray();
90383
- if (stores.length) {
90384
- const items2 = await db2.collection("inventory.items").aggregate([
90385
- {
90386
- $match: {
90387
- store: { $in: stores.map((store) => store._id) },
90388
- status: "active",
90389
- reorderLevel: { $gt: 0 },
90390
- $expr: { $lte: ["$onHand", "$reorderLevel"] }
90391
- }
90392
- },
90393
- { $sort: { onHand: 1 } },
90394
- { $limit: 5 },
90395
- { $project: { _id: 1, name: 1, qty: "$onHand" } }
90396
- ]).toArray();
90397
- return { items: items2, basis: SUPPLY_BASIS_BELOW_ALERT_LEVEL };
90398
- }
90410
+ const inventory = await inventoryLowStock(site, serviceType);
90411
+ if (inventory)
90412
+ return { items: inventory, basis: SUPPLY_BASIS_BELOW_ALERT_LEVEL };
90399
90413
  const items = await supplyCollection.aggregate([
90400
90414
  { $match: { site, serviceType, status: "active" } },
90401
90415
  { $sort: { qty: 1 } },
@@ -90404,6 +90418,10 @@ function useNewDashboardRepo() {
90404
90418
  ]).toArray();
90405
90419
  return { items, basis: SUPPLY_BASIS_LOWEST_QUANTITY };
90406
90420
  }
90421
+ async function inventorySupplyTile(site, serviceType) {
90422
+ const items = await inventoryLowStock(site, serviceType);
90423
+ return items ? { supplyAlert: { items: items.map((item) => ({ name: item.name, qty: item.qty })), basis: SUPPLY_BASIS_BELOW_ALERT_LEVEL } } : {};
90424
+ }
90407
90425
  async function getServiceDashboard({
90408
90426
  site,
90409
90427
  serviceType,