@managesome/eposmatic-toolkit 0.2.489 → 0.2.491

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.
@@ -1,5 +1,5 @@
1
- import { ICategory, IIncludedCategory, IItem, IKitchenInventory } from '../../schemas';
2
- import { ICatalog, IMinifiedCategory, IMinifiedItem, ISimplifiedCatalog, ISimplifiedCatalogItem, ISimplifiedCategory, ISimplifiedItem, IWarehouseCatalog } from '../types';
1
+ import { ICategory, IIncludedCategory, IInventoryCategory, IItem, IKitchenInventory } from '../../schemas';
2
+ import { ICatalog, IInventoryCategoryWithItems, IInventoryIncludedCategory, IMinifiedCategory, IMinifiedItem, ISimplifiedCatalog, ISimplifiedCatalogItem, ISimplifiedCategory, ISimplifiedItem, IWarehouseCatalog } from '../types';
3
3
  export declare function getPartialSimplifiedItem(item: Partial<ISimplifiedItem>): Partial<ISimplifiedCatalogItem>;
4
4
  export declare function getSimplifiedItemWithPrice(item: ISimplifiedItem): ISimplifiedCatalogItem;
5
5
  export declare function getSimpleCatalogFetchedData(categories: ISimplifiedCategory[], items: ISimplifiedItem[]): ISimplifiedCatalog[];
@@ -23,9 +23,8 @@ export declare function getSelectedVendorCatalogs(menus: {
23
23
  }[], selectedVendorId: string | null, mappedCatalog: Record<string, IWarehouseCatalog>): IWarehouseCatalog[];
24
24
  /**
25
25
  * Group inventory items by category_id for O(1) lookup.
26
- * Mirrors the warehouse's mappedCatalog: uses item.category_id directly
27
- * as the key. Items with a null/undefined category_id are skipped —
28
- * uncategorized handling belongs in the UI layer.
26
+ * Mirrors the warehouse's mappedCatalog. Items with a null/undefined
27
+ * category_id are stored under the key '' (empty string).
29
28
  */
30
29
  export declare function getInventoryMappedItems(inventory: IKitchenInventory[]): Record<string, IKitchenInventory[]>;
31
30
  /**
@@ -36,4 +35,10 @@ export declare function getInventoryMappedItems(inventory: IKitchenInventory[]):
36
35
  *
37
36
  * When includedCategories is empty, returns ALL items (no filter).
38
37
  */
39
- export declare function getSelectedVendorInventoryItems(mappedInventory: Record<string, IKitchenInventory[]>, includedCategories: IIncludedCategory[]): IKitchenInventory[];
38
+ export declare function getSelectedVendorInventoryItems(mappedInventory: Record<string, IKitchenInventory[]>, includedCategories: IInventoryIncludedCategory[]): IKitchenInventory[];
39
+ /**
40
+ * Group inventory categories with their items, including a synthetic
41
+ * "Uncategorized" entry for items without a category_id.
42
+ * Mirrors getWarehouseCatalogFetchedData for the admin panel.
43
+ */
44
+ export declare function getGroupedInventoryCategories(categories: IInventoryCategory[], items: IKitchenInventory[]): IInventoryCategoryWithItems[];
@@ -17,6 +17,7 @@ exports.getSelectedCatalogs = getSelectedCatalogs;
17
17
  exports.getSelectedVendorCatalogs = getSelectedVendorCatalogs;
18
18
  exports.getInventoryMappedItems = getInventoryMappedItems;
19
19
  exports.getSelectedVendorInventoryItems = getSelectedVendorInventoryItems;
20
+ exports.getGroupedInventoryCategories = getGroupedInventoryCategories;
20
21
  const utils_1 = require("../utils");
21
22
  const catalog_conversion_1 = require("../utils/catalog-conversion");
22
23
  const minified_catalog_1 = require("../utils/minified-catalog");
@@ -223,19 +224,17 @@ function getSelectedVendorCatalogs(menus, selectedVendorId, mappedCatalog) {
223
224
  // ============================================================================
224
225
  /**
225
226
  * Group inventory items by category_id for O(1) lookup.
226
- * Mirrors the warehouse's mappedCatalog: uses item.category_id directly
227
- * as the key. Items with a null/undefined category_id are skipped —
228
- * uncategorized handling belongs in the UI layer.
227
+ * Mirrors the warehouse's mappedCatalog. Items with a null/undefined
228
+ * category_id are stored under the key '' (empty string).
229
229
  */
230
230
  function getInventoryMappedItems(inventory) {
231
231
  const map = {};
232
232
  for (let i = 0; i < inventory.length; i++) {
233
233
  const item = inventory[i];
234
- if (!item.category_id)
235
- continue;
236
- if (!map[item.category_id])
237
- map[item.category_id] = [];
238
- map[item.category_id].push(item);
234
+ const key = item.category_id ?? '';
235
+ if (!map[key])
236
+ map[key] = [];
237
+ map[key].push(item);
239
238
  }
240
239
  return map;
241
240
  }
@@ -262,9 +261,7 @@ function getSelectedVendorInventoryItems(mappedInventory, includedCategories) {
262
261
  const result = [];
263
262
  for (let i = 0; i < includedCategories.length; i++) {
264
263
  const { category_id, excluded_items } = includedCategories[i];
265
- if (!category_id)
266
- continue;
267
- const items = mappedInventory[category_id];
264
+ const items = mappedInventory[category_id ?? ''];
268
265
  if (!items)
269
266
  continue;
270
267
  if (excluded_items.length === 0) {
@@ -282,3 +279,56 @@ function getSelectedVendorInventoryItems(mappedInventory, includedCategories) {
282
279
  }
283
280
  return result;
284
281
  }
282
+ // ============================================================================
283
+ // Admin Panel: Group inventory categories with their items (incl. uncategorized)
284
+ // Mirrors getWarehouseCatalogFetchedData but for IInventoryCategory/IKitchenInventory.
285
+ // ============================================================================
286
+ /**
287
+ * Group inventory categories with their items, including a synthetic
288
+ * "Uncategorized" entry for items without a category_id.
289
+ * Mirrors getWarehouseCatalogFetchedData for the admin panel.
290
+ */
291
+ function getGroupedInventoryCategories(categories, items) {
292
+ const result = [];
293
+ // Group items by category_id
294
+ const itemsByCategory = {};
295
+ const uncategorizedItems = [];
296
+ for (let i = 0; i < items.length; i++) {
297
+ const item = items[i];
298
+ if (item.category_id) {
299
+ if (!itemsByCategory[item.category_id])
300
+ itemsByCategory[item.category_id] = [];
301
+ itemsByCategory[item.category_id].push(item);
302
+ }
303
+ else {
304
+ uncategorizedItems.push(item);
305
+ }
306
+ }
307
+ // Add each category with its items, sorted by category sort_id
308
+ const sortedCategories = [...categories].sort((a, b) => a.sort_id - b.sort_id);
309
+ for (const cat of sortedCategories) {
310
+ result.push({
311
+ category: cat,
312
+ items: itemsByCategory[cat.ref_id] || [],
313
+ });
314
+ }
315
+ // Append uncategorized items as a synthetic category (ref_id: null so the API receives null, not a fake string)
316
+ if (uncategorizedItems.length > 0) {
317
+ const maxSortId = categories.length > 0 ? Math.max(...categories.map((c) => c.sort_id)) : 0;
318
+ result.push({
319
+ category: {
320
+ _id: null,
321
+ ref_id: null,
322
+ tenant_id: '',
323
+ name: 'Uncategorized',
324
+ subtitle: '',
325
+ active: true,
326
+ sort_id: maxSortId + 1,
327
+ createdAt: new Date(0),
328
+ updatedAt: new Date(0),
329
+ },
330
+ items: uncategorizedItems,
331
+ });
332
+ }
333
+ return result;
334
+ }
@@ -12,6 +12,7 @@ export * from './hubrise_deliveries';
12
12
  export * from './hubrise_location';
13
13
  export * from './hubrise_orders';
14
14
  export * from './internal-leads';
15
+ export * from './inventory-catalog';
15
16
  export * from './kpra-generate-invoice';
16
17
  export * from './marketing';
17
18
  export * from './order-engine';
@@ -28,6 +28,7 @@ __exportStar(require("./hubrise_deliveries"), exports);
28
28
  __exportStar(require("./hubrise_location"), exports);
29
29
  __exportStar(require("./hubrise_orders"), exports);
30
30
  __exportStar(require("./internal-leads"), exports);
31
+ __exportStar(require("./inventory-catalog"), exports);
31
32
  __exportStar(require("./kpra-generate-invoice"), exports);
32
33
  __exportStar(require("./marketing"), exports);
33
34
  __exportStar(require("./order-engine"), exports);
@@ -0,0 +1,18 @@
1
+ import { IInventoryCategory, IKitchenInventory } from '../../schemas';
2
+ /**
3
+ * Included category entry for the admin panel's vendor inventory context.
4
+ * Allows null category_id for uncategorized items, unlike IIncludedCategory
5
+ * (which uses category_id: string for courses/menus).
6
+ */
7
+ export interface IInventoryIncludedCategory {
8
+ category_id: string | null;
9
+ excluded_items: string[];
10
+ }
11
+ export type IInventoryCategoryDisplay = Omit<IInventoryCategory, '_id' | 'ref_id'> & {
12
+ _id: string | null;
13
+ ref_id: string | null;
14
+ };
15
+ export interface IInventoryCategoryWithItems {
16
+ category: IInventoryCategoryDisplay;
17
+ items: IKitchenInventory[];
18
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.489",
3
+ "version": "0.2.491",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",