import { BaseServiceClass } from '../baseService'; import { TransferRequest } from '../TransferRequest'; import IInventoryItem, { IInventoryByStore, IInventoryItemHistory } from '../../Interfaces/Product/IInventoryItem'; import { CartTypeEnum } from '../../Interfaces/Cart'; import { IFilledDimensionUnits } from '../../Interfaces/Declination'; export default class Inventory extends BaseServiceClass { constructor(data: IInventoryItem, collection: { path: string; }, user: string); save: (newInventoryData?: Partial, options?: any, saveToDatabase?: boolean, update?: boolean, merge?: boolean) => Promise; delete: () => Promise; getHistoryInventory: () => Promise; setQuantitiesWithInventoryItemByStore: (inventory: Partial) => Promise; setQuantitiesWithWebInventoryItemByStore: (inventory: Partial[], webQty: number) => Promise; private _modifyQuantitiesByStore; private _modifyQuantitiesOnlyWeb; /** * Returns calculated new value for web inventory * @param type - The inventory type to calculate * @param operation - If quantities should be added or removed * @param amount - The quantity to adjust * @param ignoreNewNegativeValues - Optionnal. If true, will replace calculated qte with 0 if current qte was positive, and keep current value if it was already negative and is 'available' inventory (since only available web quantites could be negative). */ private _getNewWebQuantity; private _orderCompleted; handleOrderDelivered: (storeId: string, qte: number, cartType?: CartTypeEnum) => Promise; handleOrderPickedupInStore: (storeId: string, qte: number, cartType?: CartTypeEnum) => Promise; handleOrderProcessedForShipping: (storeId: string, qte: number, cartType?: CartTypeEnum) => Promise; handleNewQuantities: (storeId: string, qte: number, cartType?: CartTypeEnum, saveToDatabase?: boolean) => Promise; handleUpdateWebInventory: (qte: number) => Promise; handleProductSold: (storeId: string | undefined, qte: number, cartType?: CartTypeEnum, web?: boolean) => Promise; /** * Update inventory on cart item modified (POS modify cart process). * @param storeId The store associated to the order. If cart still at status 5, might be undefined (unless quantities already reserved for order) * @param qte The quantities to ajust * @param cartType The associated cart's type * @param options.onlyWeb Optionnal. If only web inventory should be ajusted * @param options.reservedQteDiff Optionnal. Reserved quantities difference for given cart item. Expressed in sell_unit (must be converted to inventory_unit) * @returns {Promise} */ handleProductModified: (storeId: string | undefined, qte: number, cartType?: CartTypeEnum, options?: { onlyWeb?: boolean; reservedQteDiff?: number; }) => Promise; /** * Update inventory for a specific item if order was cancelled or refunded. * @param toStoreId The store where quantities will be ADDED * @param fromStoreId The store where quantities will vbe REMOVED * @param qte The quantity to ajust * @param operationType If cart was cancelled or refunded * @param cartType If cart is web, POS, or Pickup Now * @param options.deleteItem Optionnal. If item should not be returned to the stores inventory (broken, misplaced, old batch, etc...) * @param options.onlyWeb Optionnal. If inventory should only be updated for web inventory (and not for stores). Mostly depends on the cart's status when cancelled. * @param options.orderAssociatedTransfers Optionnal. Array of TransferRequest objects associated to cart. Used when cart is cancelled * @param options.saveToDatabase Optionnal. Mostly used for dev purpuses (and for unit testing). Otherwise, save is done logically at the end of the update process * @param options.reservedQte Optionnal. Quantity reserved in processing inventory for cart item as of now. Expressed in sell_unit (must be converted to inventory_unit) * @param options.otherUnits Optionnal. Other units for corresponding cart item. If not defined, will use those found in InventoryItem data */ handleOrderCancelled: (toStoreId: string, fromStoreId: string, qte: number, operationType: 'refunded' | 'cancelled', cartType?: CartTypeEnum, options?: { deleteItem?: boolean; onlyWeb?: boolean; orderAssociatedTransfers?: TransferRequest[]; saveToDatabase?: boolean; reservedQte?: number; otherUnits?: IFilledDimensionUnits[]; }) => Promise; handleOrderReadyForProcessing: (storeId: string, qte: number, cartType: CartTypeEnum) => Promise; handleOrderInDelivery: (storeId: string, qte: number, cartType: CartTypeEnum) => Promise; handleChangedProcessingStore: (oldStoreId: string, newStoreId: string, qte: number, cartType: CartTypeEnum) => Promise; handleTransferInTransit: (storeId: string, qte: number, cartType?: CartTypeEnum, forOrder?: boolean, fromProcessing?: boolean) => Promise; /** * Adjust store quantities * @param storeFromId Origin store id * @param storeToId Target store id * @param qte Total quantity received * @param cartType Cart type, GR only? * @param options.forOrder True if associated to an order * @param options.maxProcessingQte Quantity to place in processing, extra will go in available * @param options.skipWebUpdateForAvailable If web inventory update should be skipped for available quantities (for when transfer is received for a already processed cart) * @returns the new inventory item data */ handleTransferReceived: (storeFromId: string, storeToId: string, qte: number, cartType: CartTypeEnum | undefined, options: { forOrder?: boolean; maxProcessingQte?: number; skipWebUpdateForAvailable?: boolean; additionnalWebQuantitiesReserved?: boolean; }) => Promise; /** * Cancel value in transit - Adjust the in transit negatively without adjusting any other quantity. * @param storeId The store to apply the change * @param qte The quantity to remove * @param cartType Cart type, GR only? * @param forOrder True if associated to an order * @returns updated data */ handleCancelInTransit: (storeId: string, qte: number, cartType?: CartTypeEnum, forOrder?: boolean) => Promise; /** * Cancelled transfer with status TO_BE_PREPARED - Take quantities reserved in processing inventory, and put back in available. ⚠️ _**IMPORTANT** - Should first check if space has associated space_option before using function!_ * @param storeId The store to apply the change * @param qte The quantity to remove * @param cartType Cart type, GR only? * @param forOrder True if associated to an order * @param additionnalWebQuantitiesReserved Extra quantities were added to transfer (other than those needed for cart). If so, they were reserved, and must return in stock too. */ handleCancelToBePrepared: (storeId: string, qte: number, cartType?: CartTypeEnum, forOrder?: boolean, additionnalWebQuantitiesReserved?: number) => Promise; /** * Reserve inventory for store on transfer changed to status TO_BE_PREPARED. ⚠️ _**IMPORTANT** - Should first check if space has associated space_option before using function!_ * @param storeId The store ID for the "from" store in transfer. * @param qte The quantity to add or remove from inventory. * @param cartType Optionnal. Passed to _modifyQuantitiesByStore. Used to check if web inventory should be updated. * @param forOrder Optionnal. If transfer is associated to an order. WIll not update web inventory if true (since it was already reserved with order) * @param webQte Optionnal. If provided, used as value to update web inventory. Also bypasses check forOrder, so if provided web inventory is ALWAYS ypdated with provided value. */ handleTransferToBePrepared: (storeId: string, qte: number, cartType?: CartTypeEnum, forOrder?: boolean, webQte?: number | undefined) => Promise; handlePOSCartFastComplete: (storeId: string, qte: number, cartType: CartTypeEnum, quantitiesAlreadyReserved?: number) => Promise; handleChangeCanSellOnline: (storeId: string, qte: number, newCanSellOnline: boolean, saveToDatabase?: boolean) => Promise; /** * Reserve a quantity from the available web inventory and store if provided * @param qty The quantity to reserve * @param storeId The store id to use for reservation, undefined if web only * @returns the new inventory data */ handleReserveInventory: (qty: number, storeId: string | undefined) => Promise; /** * Release a quantity from the processing web inventory and store if provided * @param qty The quantity to release * @param storeId The store id to use for reservation, undefined if web only * @returns the new inventory data */ handleUnreserveInventory: (qty: number, storeId: string | undefined) => Promise; }