Files
tripz-llc/backend/src/modules/credit/entities/credit-txn.entity.ts
T

55 lines
1.8 KiB
TypeScript

import {
Column,
CreateDateColumn,
Entity,
Index,
PrimaryGeneratedColumn,
} from 'typeorm';
/**
* أنواع حركات الرصيد التشغيلي (docs/18).
* `topup` و`signup_bonus` و`promo_bonus` مفصولة عمداً: المدفوع فعلاً إيراد،
* والهدايا تكلفة تسويق — خلطها يُفسد المحاسبة.
*/
export type CreditTxnType =
| 'topup' // شحن مدفوع — إيراد
| 'signup_bonus' // مكافأة تسجيل — تكلفة تجنيد
| 'promo_bonus' // حافز باقة («اشحن 50 خذ 55») — تكلفة تسويق
| 'referral_bonus'// مكافأة إحالة — تكلفة تجنيد، منفصلة عن حافز الباقة
| 'commission' // خصم عمولة رحلة
| 'adjustment'; // تسوية يدوية من الأدمن
/** حركة على الرصيد التشغيلي. الجدول: tripz_credit_txns. دفتر append-only. */
@Entity('credit_txns')
@Index(['tenant_id', 'driver_id', 'created_at'])
export class CreditTxn {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ type: 'uuid' })
tenant_id: string;
@Column({ type: 'uuid' })
driver_id: string;
/** موجب = إضافة · سالب = خصم. القيمة الموقَّعة تجعل مجموع الدفتر = الرصيد. */
@Column({ type: 'numeric', precision: 12, scale: 3 })
amount: number;
@Column({ type: 'varchar' })
type: CreditTxnType;
@Column({ type: 'numeric', precision: 12, scale: 3, nullable: true })
balance_after: number | null;
/** الرحلة سبب الخصم — بدونه لا يعرف السائق «لماذا نقص رصيدي؟» (docs/18 §6). */
@Column({ type: 'uuid', nullable: true })
trip_id: string | null;
@Column({ type: 'varchar', nullable: true })
ref: string | null;
@CreateDateColumn()
created_at: Date;
}