b-b-calculations
Version:
A cart calculation engine for buffalo burger restaurants
33 lines • 1.44 kB
TypeScript
import { IPromocodeConfig } from '../models/Promocode';
/**
* Calculates the discount value from a given promocode (coupon) based on its configuration
* and the current checkout context.
*
* @param {IPromocodeConfig | undefined} coupon - The promocode configuration object (or undefined if none is applied).
* @param {number} itemsNetPrice - The total net price of items in the cart (before VAT and fees).
* @param {number} deliveryFeesEgp - Delivery fees in EGP.
* @param {string} deliveryType - The type of delivery ("DELIVERY", "PICKUP", "DINEIN", etc.).
* @param {number} appType - Numeric code representing the app type (mapped in `appTypeMap`).
*
* @returns {number} The calculated discount amount in EGP. Returns 0 if the promocode is not valid or does not match conditions.
*
* @example
* const coupon = {
* valid: true,
* data: {
* is_active: true,
* start_date: Date.now() - 1000,
* end_date: Date.now() + 100000,
* min_basket: 100,
* delivery_type: 'all',
* discount_type: 'percentage',
* discount_value: 10
* }
* };
*
* const discount = calculatePromocodeValue(coupon, 200, 20, 'DELIVERY', 1);
* console.log(discount);
* // output 20 (10% of 200)
*/
export declare function calculatePromocodeValue(coupon: IPromocodeConfig | null, itemsNetPrice: number, deliveryFeesEgp: number, deliveryType: number, appType: number): number;
//# sourceMappingURL=promocode.d.ts.map