29 lines
756 B
TypeScript
29 lines
756 B
TypeScript
export interface CreditAdjustment {
|
|
id: string;
|
|
customerId: string;
|
|
cents: number;
|
|
reason: string;
|
|
agent: string;
|
|
at: string;
|
|
}
|
|
|
|
export class CreditLedger {
|
|
private rows: CreditAdjustment[] = [];
|
|
|
|
add(row: Omit<CreditAdjustment, 'id' | 'at'> & { id?: string; at?: string }): CreditAdjustment {
|
|
const rec: CreditAdjustment = {
|
|
id: row.id || `crd_${Date.now().toString(36)}`,
|
|
customerId: row.customerId,
|
|
cents: row.cents,
|
|
reason: row.reason,
|
|
agent: row.agent,
|
|
at: row.at || new Date().toISOString(),
|
|
};
|
|
this.rows.unshift(rec);
|
|
return rec;
|
|
}
|
|
|
|
list(customerId?: string): CreditAdjustment[] {
|
|
return customerId ? this.rows.filter((r) => r.customerId === customerId) : this.rows;
|
|
}
|
|
}
|