import { ICustomPriceItem } from '../../Interfaces/G2'; import Cart from '../../lib/Cart'; import IPromiseToPurchase, { IBank, IBankAdjustment } from '../../Interfaces/PromiseToPurchase'; import { IBankRule } from '../../Interfaces/PromiseToPurchase/BankType'; import Space from '../Space'; import { IApplicablePromiseBank, IBankUsed } from '../../Interfaces/Cart'; import IQueryOptions from '../../Interfaces/Query/IProductQueryOptions'; import { IQueryProps } from '../../Interfaces/Product'; import { SearchResponse } from '@algolia/client-search'; import IIndexedCustomerPromiseToPurchase from '../../Interfaces/PromiseToPurchase/IIndexedCustomerPromiseToPurchase'; import IIndexedBankUsed from '../../Interfaces/PromiseToPurchase/IIndexedBankUsed'; import { BaseServiceClass } from '../baseService'; export default class PromiseToPurchase extends BaseServiceClass { data: () => IPromiseToPurchase; /** * @deprecated a promise to purchase cannot be deleted. */ delete: () => Promise; static fetch: ({ app, api, hpp, page, query, filters, indice, f, space, useProspr }: IQueryProps) => Promise>; /** * * @param space * @param hpp * @param page * @param query * @param filters * @param indice * @param f * @param useProspr */ static fetchHistory: ({ app, api, hpp, page, query, filters, indice, f, useProspr }: IQueryProps) => Promise | undefined>; /** * Save the changes to a promise to purchase * @param partial the partial containing the changes * @param saveToDatabase whether or not the changes should be persisted * @param options.noEvent whether to trigger onWritePromise or not */ save: (partial?: Partial, saveToDatabase?: boolean, noEvent?: boolean) => Promise; /** * Returns a bank object. * @param bankTypeId */ getBank(bankTypeId: string): IBank | undefined; /** * Adjust the amount remaining in a bank and adds an entry in the bank adjustments history. * @param adjustment the adjustment entry * @param bankTypeId the bank type id to be updated * @param bankNowEmpty Optionnal. If set, will set bank as inactive */ adjustAmountLeftInPromise: (adjustment: Omit, bankTypeId: string, bankNowEmpty?: boolean) => Promise; /** * Returns all the rules for a bank. */ getRulesForAllBanks: () => Promise<{ type_id: string; version: number; rules: IBankRule[]; }[] | undefined>; /** * Retrieves the default settings to build an empty promise to purchase so that it can be edited. */ constructDefaultPromiseToPurchase: (space: Space, customer_id?: string) => Promise; /** * Retrieves and returns all the carts using a this promise to purchase. * @param options the query options. */ getAssociatedCarts: (options?: IQueryOptions) => Promise; /** * Returns calculated remaining amounts for each bank * @param actualCart the cart that we are trying to pay * @param applicableBanks the banks that could be applied for user on cart * @param applicableBanksHistory list of history entries for applicable banks * @param space the Space obj * @returns an array of banks used */ static calculateRemainingAmounts: (actualCart: Cart, applicableBanks: IApplicablePromiseBank[], applicableBanksHistory: IIndexedBankUsed[], space: Space) => Promise; /** * Function isValid * @description checks if a promise to purchase can be used based on the presence of a custom price list and the validity of the ending and starting date * @param customPriceList the custom price list * @param checkDate the date to use for checking validity * @returns true if valid, false if not */ isValid: (customPriceList: string | ICustomPriceItem[] | undefined, checkDate?: Date) => boolean; static getDefaultPromiseToPurchase: (customerId: string) => IPromiseToPurchase; /** * Disables empty banks for a specific customer's promise to purchase. * If the disabled banks were the last active banks of the PA, disable the PA * @async * @param {{ [bankId: string]: number; }} bankIDsWithRemainingAmounts - The bank IDs to disable. */ disableEmptyPABanks: (bankIDsWithRemainingAmounts: { [bankId: string]: number; }) => Promise; /** * Function deactivate * @description deactivates the promise * @param save save to database? */ deactivate: (save?: boolean) => Promise; /** * Function activate * @description activates the promise from a given date * @param newDate the date of starting validity * @param save save to database? */ activate: (newDate?: Date, save?: boolean) => Promise; archive: (save?: boolean) => Promise; }