Update backend to use firebase-admin SDK for FCM
This commit is contained in:
@@ -6,6 +6,8 @@ export interface QuoteInput {
|
||||
waitingMin?: number;
|
||||
at?: Date; // لحظة الحساب (لاختيار النافذة الزمنية)
|
||||
geofenceMultiplier?: number;
|
||||
/** وزن الحمولة بالكيلوغرام — للشحنات والطرود فقط (L3). */
|
||||
weightKg?: number;
|
||||
}
|
||||
|
||||
export interface QuoteBreakdown {
|
||||
@@ -14,6 +16,7 @@ export interface QuoteBreakdown {
|
||||
distance: number;
|
||||
time: number;
|
||||
waiting: number;
|
||||
weight: number;
|
||||
bookingFee: number;
|
||||
subtotal: number;
|
||||
surgeMultiplier: number;
|
||||
@@ -38,18 +41,21 @@ export class TariffEngine {
|
||||
|
||||
if (def.mode === 'fixed_quote') {
|
||||
// سعر ثابت متفَق عليه (خط ثابت / وجهة بسعر معلن): لا مسافة ولا زمن.
|
||||
// كان يسقط سابقاً إلى الفرع المتري فيُحسب بالعدّاد رغم اسمه — أي أن
|
||||
// «السعر الثابت» لم يكن ثابتاً أبداً.
|
||||
const fixed = Math.max(0, def.fixed_fare ?? 0);
|
||||
const waitingOnly = waitingMin * (win.per_min_waiting ?? 0);
|
||||
// الانتظار وحده يُضاف: بقاء الراكب ربع ساعة تكلفة حقيقية على السائق
|
||||
// مهما كان الخط ثابتاً. ولا حدّ أدنى هنا — السعر المعلن **هو** الاتفاق،
|
||||
// ورفعه بحدّ أدنى يعني إعلان سعر وتحصيل غيره.
|
||||
|
||||
// --- L3: وزن الحمولة (شحنات على خطوط ثابتة) ---
|
||||
const weightKg = Math.max(0, input.weightKg ?? 0);
|
||||
let weightCharge = 0;
|
||||
if (def.weight && weightKg > def.weight.free_kg) {
|
||||
weightCharge = (weightKg - def.weight.free_kg) * def.weight.per_kg_above;
|
||||
}
|
||||
|
||||
const multiplier =
|
||||
(def.surge?.enabled && def.surge.multiplier ? def.surge.multiplier : 1) *
|
||||
(input.geofenceMultiplier ?? 1.0);
|
||||
const fixedTotal = TariffEngine.round(
|
||||
(fixed + waitingOnly) * multiplier,
|
||||
(fixed + waitingOnly + weightCharge) * multiplier,
|
||||
def.rounding,
|
||||
);
|
||||
return {
|
||||
@@ -58,8 +64,9 @@ export class TariffEngine {
|
||||
distance: 0,
|
||||
time: 0,
|
||||
waiting: TariffEngine.n(waitingOnly),
|
||||
weight: TariffEngine.n(weightCharge),
|
||||
bookingFee: 0,
|
||||
subtotal: TariffEngine.n(fixed + waitingOnly),
|
||||
subtotal: TariffEngine.n(fixed + waitingOnly + weightCharge),
|
||||
surgeMultiplier: multiplier,
|
||||
total: fixedTotal,
|
||||
currency: def.currency,
|
||||
@@ -84,8 +91,15 @@ export class TariffEngine {
|
||||
const waitingCharge = waitingMin * (win.per_min_waiting ?? 0);
|
||||
const bookingFee = def.booking_fee ?? 0;
|
||||
|
||||
// --- L3: وزن الحمولة ---
|
||||
const weightKg = Math.max(0, input.weightKg ?? 0);
|
||||
let weightCharge = 0;
|
||||
if (def.weight && weightKg > def.weight.free_kg) {
|
||||
weightCharge = (weightKg - def.weight.free_kg) * def.weight.per_kg_above;
|
||||
}
|
||||
|
||||
let subtotal =
|
||||
win.flag + distanceCharge + timeCharge + waitingCharge + bookingFee;
|
||||
win.flag + distanceCharge + timeCharge + waitingCharge + weightCharge + bookingFee;
|
||||
|
||||
const surgeMultiplier =
|
||||
def.surge?.enabled && def.surge.multiplier ? def.surge.multiplier : 1;
|
||||
@@ -104,6 +118,7 @@ export class TariffEngine {
|
||||
distance: TariffEngine.n(distanceCharge),
|
||||
time: TariffEngine.n(timeCharge),
|
||||
waiting: TariffEngine.n(waitingCharge),
|
||||
weight: TariffEngine.n(weightCharge),
|
||||
bookingFee,
|
||||
subtotal: TariffEngine.n(subtotal),
|
||||
surgeMultiplier,
|
||||
|
||||
Reference in New Issue
Block a user