/// import { IFilledDimensionUnits } from '../../Interfaces/Declination'; import ITransferRequest, { ITransferProductWeight, ITransferProduct, TransferRequestStatusEnum, TransferRequestUpdateContextEnum } from '../../Interfaces/TransferRequest'; import { BaseServiceClass } from '../baseService'; import Space from '../Space'; import { IQueryProps } from '../../Interfaces/Product'; import { SearchResponse } from '@algolia/client-search'; import Cart from '../Cart'; import { IOrderInvoiceNumerotation, ISpaceOptions } from '../../Interfaces/Space'; type SaveTransferOptionsType = { readonly comment?: string | undefined; readonly user: string; readonly markAsCompleted?: boolean; readonly saveToDatabase?: boolean; readonly originalRequestProducts?: ITransferProduct[]; readonly space?: Space | undefined; }; export declare class TransferRequest extends BaseServiceClass { private _listener; private prevProducts; private prevFromStore; private processData; private getCollectionObj; constructor(_data: ITransferRequest, _collection: { path: string; }, _user: string); static fetch: ({ app, api, hpp, page, query, filters, indice, f, space, useProspr }: IQueryProps) => Promise>; static getStatusLabel: (status: TransferRequestStatusEnum) => "Initialisée" | "Ouverte" | "À préparer" | "En transit" | "Annulée" | "Reçue partiellement" | "Reçue"; static checkIfTransferCanBeCancelled: (currentTransferStatus: TransferRequestStatusEnum, statusOrderObj: { [key: number]: TransferRequestStatusEnum[]; }) => boolean; /** * Check if current space has option to update inventory on status changed to TO_BE_PREPARED * @param space Optionnal. IF not provided, will fetch space from DB */ private _checkIfInventoryUpdatedOnStatusToBePrepared; /** * Test if the transfer can be closed * @returns true if the status allow to close the transfer */ checkIfTransferCanBeClosedManually: () => boolean; /** * Checks if provided status is included in "completed" transfer statuses list. * @param statusToCheck */ static checkIfStatusCountsAsCompleted: (statusToCheck: TransferRequestStatusEnum) => boolean; static transferAllowAssignFromStore: (data: ITransferRequest) => boolean; transferAllowAssignFromStore: () => boolean; static transferAllowEditFromStore: (data: ITransferRequest) => boolean; transferAllowEditFromStore: () => boolean; /** * Test if the transfer allow adding products * @param data the request data to verify * @returns true if can add product */ static transferAllowAddProductOnEdit: (data: ITransferRequest) => boolean; transferAllowAddProductOnEdit: () => boolean; /** * Test if the transfer allow deleteing products * @param data the request data to verify * @returns true if can delete product */ static transferAllowProductDelete: (data: ITransferRequest) => boolean; transferAllowProductDelete: () => boolean; /** * Test if the transfer allow editing products * @param data the request data to verify * @returns true if can be edited */ static transferAllowEditProductOnEdit: (data: ITransferRequest) => boolean; transferAllowEditProductOnEdit: () => boolean; /** * Test if the transfer allow deleteing products when editing (not changing status) * @param data the request data to verify * @returns {boolean} true if can delete product */ static transferAllowDeleteProductOnEdit: (data: ITransferRequest) => boolean; transferAllowDeleteProductOnEdit: () => boolean; /** * Test if the transfer has reached a state where it should display weight * @param data the request data to verify * @returns {boolean} */ static transferShouldDisplayWeight: (data: ITransferRequest) => boolean; transferShouldDisplayWeight: () => boolean; /** * Test if the transfer allows products to be updated without a status change * @param data the request data to verify * @param spaceOptions Optionnal. If provided, check added before pushing TO_BE_PREPARED status, to see if `ajust_inventory_on_to_be_prepared` is not set (or else, status not elligible) * @returns {boolean} */ static transferAllowsIndependantProductUpdate: (data: ITransferRequest, spaceOptions: ISpaceOptions | undefined) => boolean; transferAllowsIndependantProductUpdate: (spaceOptions: ISpaceOptions | undefined) => boolean; fetchAssociatedCart: () => Promise; addProduct: (sku: string, parent_slug: string, qte: number, name: string, image?: string, other_units?: IFilledDimensionUnits[], weight?: ITransferProductWeight, count_in_pallet_total?: boolean) => boolean; editProduct: (sku: string, newQte: number) => boolean; deleteProduct: (sku: string) => boolean; data: () => ITransferRequest; isListening: () => boolean; killListener: () => boolean; listen: (callback?: () => void) => boolean; private _getTransferRef; save: (partial: Partial, saveToDatabase?: boolean, merge?: boolean) => Promise; /** * Validate the quantities set before submit * @param strictQty Tell if we should only allow equal quantity * @returns */ validateBeforeSubmit: (strictQty?: boolean) => Promise; /** * Strip out the validation qty field in products data * Do this before saving so the qte_validation doesnt get save in database * @param copyQte should copy validation qty to the actual qty */ clearValidationQuantitiesFromProductData: (copyQte?: boolean) => void; /** * Add the validation quantities to the received amount */ addValidationQuantitiesToReceivedQuantities: () => void; /** * Return the previous quantity received for the provided sku * @param sku the product sku to get * @returns */ getPreviousReceivedQuantity: (sku: string) => number; /** * Return the original reuested quantity * @param sku the product sku to get * @returns */ getOriginalRequestedQuantity: (sku: string) => number; /** * Get the quantity at the requested status * @param sku the product sku * @param status the status to look for * @returns the quantity at the specified status */ getQuantityAtStatus: (sku: string, status: TransferRequestStatusEnum) => number; private getInventoryQuantitiesStillMissingForCartTransfer; private handleFreeTransitInventory; private handleChangeStoreInventory; private handleLiberateToBePreparedReservedQuantities; /** * Update transfer's associated cart with new reserved quantities. Called when quantities received for transfer. */ private handleUpdateAssociatedCartReservedQuantities; /** * Use provided update object to construct new products object for current transfer * @param updatesToDo The product updates to apply * @param updatesToDo.sku The product sku to update * @param updatesToDo.ajustementQte The quantity to ajust. Must be negative if quantity REMOVED, and positive if ADDED. */ constructProductObjFromUpdates: (updatesToDo: { sku: string; ajustmentQte: number; }[]) => ITransferProduct[]; /** * Will update content in transfer without triggering a status change, if current transfer status permits. Still adds entry to the transfer_updates array. * @param updatedContent.products The array of products to update product * @param updatedContent.fromStore The new from store slug value if changed * @param options Options to create the associated transfer_updates entry * @param cancelTransferIfAllProductsAtZero Optionnal. If transfer should be auto-cancelled if all products are now at 0 quantities */ saveUpdatesToContentOnly: (updatedContent: { products?: ITransferProduct[]; fromStore?: string; }, options: SaveTransferOptionsType, cancelTransferIfAllProductsAtZero?: boolean, updateContext?: TransferRequestUpdateContextEnum) => Promise; /** * Change or set the draft property value * @param newVal The new value to assign */ setDraftValue: (newVal: boolean) => void; /** * Change or set the associated_order property value * @param newVal The new value to assign */ setAssociatedOrder: (newVal: string | null) => void; /** * Change or set the transport_ref property value * @param newVal The new value to assign * @param saveToDatabase Do we save the new value in the database */ setTransportRef: (newVal: string, saveToDatabase?: boolean) => Promise; /** * Set the original transfer id property value * @param newVal The new value to assign */ setOriginalTransferId: (newVal: string | undefined) => Promise; /** * Change the completed status to true and save to database */ setAsCompleted: (user: string, comment?: string) => Promise; changeStatus: (newStatus: TransferRequestStatusEnum, comment: string | undefined, user: string, saveToDatabase?: boolean, options?: { setAsCompleted?: boolean; originalRequestProducts?: ITransferProduct[]; space?: Space | undefined; context?: TransferRequestUpdateContextEnum; }) => Promise; /** * Generates updates array and saves transfer for the first time in the database. * @param currentUser * @param comment * @param saveToDatabase * @throws if transfer already has an ID or doesn't have a status set */ saveNewTransfer: (currentUser: string, comment?: string, saveToDatabase?: boolean, skipRef?: boolean) => Promise; /** * Get the total estimated weight by calculating each product's weigth times inventory quantity * @param unit the unit to return * @returns the weight in the requested unit */ static getTotalWeight: (products: ITransferProduct[], unit?: 'pounds' | 'kilograms') => number; /** * Get the total calculated pallet quantities for all transfer items * @param items * @returns */ static getTotalPalletQte: (items: ITransferProduct[]) => number; /** * Get the weight of a selected sku in this transfer * @param sku the product sku * @param unit the unit to return * @returns the weight in the requested unit */ getProductWeight: (sku: string, unit?: 'pounds' | 'kilograms') => number; /** * Fetches applicable transfer status order object by checking space_options for current space. */ private _getOrderObject; /** * Checks if provided "new" status follows current transfer status in the correct transfer status order for space. * @param statusToCheck */ private _checkIfCanChangeToStatus; /** * Creates new entry for a status change, copies transfer_updates property and adds new entry to the start of copied array. * @param newStatus * @param user The email (or id) of Addio user that triggered the status change * @param comment The user added comment for status change (can be undefined) * @returns The copied array with the new value added. */ private _generateNewTransferStatusUpdates; /** * Saves provided status to TransferRequest data. Also generates and saves new entry for `transfer_updates` array. * @param newStatus * @param options */ private _saveNewStatus; /** * Checks update eligibility, then updates status to OPEN. * @param options */ private _setAsOpen; /** * Checks update eligibility, then updates status to TO_BE_PREPARED. Also updates inventory for the origin store (but only if space_option set in space). * @param options */ private _setAsToBePrepared; /** * Checks update eligibility, then updates status to IN_TRANSIT. Also updates inventory for the origin store. * @param options */ private _setAsInTransit; /** * Checks update eligibility, then updates status to RECEIVED. Also updates inventory for both stores. * @param options */ private _setAsReceived; /** * Checks update eligibility, then updates status to RECEIVED_PARTIAL. Also updates inventory for both stores. * @param options * @todo Update inventory logic to deal with partially received quantities. */ private _setAsReceivedPartially; /** * Checks if transfer can be cancelled, and if so, updates status to CANCELLED. * @param options */ private _setAsCancelled; /** * Object regrouping all status change functions */ updateToStatus: { open: (options: SaveTransferOptionsType) => Promise; toBePrepared: (options: SaveTransferOptionsType) => Promise; inTransit: (options: SaveTransferOptionsType) => Promise; received: (options: SaveTransferOptionsType) => Promise; receivedPartial: (options: SaveTransferOptionsType) => Promise; cancelled: (options: SaveTransferOptionsType, context?: TransferRequestUpdateContextEnum) => Promise; }; /** * Get formatted ref string for the transfer. * @param spaceTransferSettings * @returns {string | undefined} */ getFormattedRef: (spaceTransferSettings: IOrderInvoiceNumerotation | undefined) => string | undefined; } export {};