payment type and storage udpated

This commit is contained in:
2025-08-09 00:50:57 +05:30
parent b95af918d5
commit 31ed4cd1da
4 changed files with 32 additions and 74 deletions

View File

@@ -910,15 +910,11 @@ export const storage: IStorage = {
serviceLines: true, serviceLines: true,
}, },
}, },
transactions: { serviceLineTransactions: {
include: {
serviceLinePayments: {
include: { include: {
serviceLine: true, serviceLine: true,
}, },
}, },
},
},
updatedBy: true, updatedBy: true,
}, },
}); });
@@ -929,7 +925,7 @@ export const storage: IStorage = {
...payment, ...payment,
patientName: payment.claim?.patientName ?? "", patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt, paymentDate: payment.createdAt,
paymentMethod: payment.transactions[0]?.method ?? "OTHER", paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
}; };
}, },
@@ -945,15 +941,11 @@ export const storage: IStorage = {
serviceLines: true, serviceLines: true,
}, },
}, },
transactions: { serviceLineTransactions: {
include: {
serviceLinePayments: {
include: { include: {
serviceLine: true, serviceLine: true,
}, },
}, },
},
},
updatedBy: true, updatedBy: true,
}, },
}); });
@@ -964,7 +956,7 @@ export const storage: IStorage = {
...payment, ...payment,
patientName: payment.claim?.patientName ?? "", patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt, paymentDate: payment.createdAt,
paymentMethod: payment.transactions[0]?.method ?? "OTHER", paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
}; };
}, },
@@ -980,15 +972,11 @@ export const storage: IStorage = {
serviceLines: true, serviceLines: true,
}, },
}, },
transactions: { serviceLineTransactions: {
include: {
serviceLinePayments: {
include: { include: {
serviceLine: true, serviceLine: true,
}, },
}, },
},
},
updatedBy: true, updatedBy: true,
}, },
}); });
@@ -997,7 +985,7 @@ export const storage: IStorage = {
...payment, ...payment,
patientName: payment.claim?.patientName ?? "", patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt, paymentDate: payment.createdAt,
paymentMethod: payment.transactions[0]?.method ?? "OTHER", paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
})); }));
}, },
@@ -1017,15 +1005,11 @@ export const storage: IStorage = {
serviceLines: true, serviceLines: true,
}, },
}, },
transactions: { serviceLineTransactions: {
include: {
serviceLinePayments: {
include: { include: {
serviceLine: true, serviceLine: true,
}, },
}, },
},
},
updatedBy: true, updatedBy: true,
}, },
}); });
@@ -1034,7 +1018,7 @@ export const storage: IStorage = {
...payment, ...payment,
patientName: payment.claim?.patientName ?? "", patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt, paymentDate: payment.createdAt,
paymentMethod: payment.transactions[0]?.method ?? "OTHER", paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
})); }));
}, },
@@ -1058,15 +1042,11 @@ export const storage: IStorage = {
serviceLines: true, serviceLines: true,
}, },
}, },
transactions: { serviceLineTransactions: {
include: {
serviceLinePayments: {
include: { include: {
serviceLine: true, serviceLine: true,
}, },
}, },
},
},
updatedBy: true, updatedBy: true,
}, },
}); });
@@ -1075,7 +1055,7 @@ export const storage: IStorage = {
...payment, ...payment,
patientName: payment.claim?.patientName ?? "", patientName: payment.claim?.patientName ?? "",
paymentDate: payment.createdAt, paymentDate: payment.createdAt,
paymentMethod: payment.transactions[0]?.method ?? "OTHER", paymentMethod: payment.serviceLineTransactions[0]?.method ?? "OTHER",
})); }));
}, },

View File

@@ -215,7 +215,7 @@ model Payment {
claim Claim @relation(fields: [claimId], references: [id], onDelete: Cascade) claim Claim @relation(fields: [claimId], references: [id], onDelete: Cascade)
patient Patient @relation(fields: [patientId], references: [id], onDelete: Cascade) patient Patient @relation(fields: [patientId], references: [id], onDelete: Cascade)
updatedBy User? @relation("PaymentUpdatedBy", fields: [updatedById], references: [id]) updatedBy User? @relation("PaymentUpdatedBy", fields: [updatedById], references: [id])
transactions ServiceLineTransaction[] serviceLineTransactions ServiceLineTransaction[]
@@index([id]) @@index([id])
@@index([claimId]) @@index([claimId])

View File

@@ -1,12 +1,11 @@
import { import {
PaymentUncheckedCreateInputObjectSchema, PaymentUncheckedCreateInputObjectSchema,
PaymentTransactionCreateInputObjectSchema,
ServiceLinePaymentCreateInputObjectSchema,
ClaimUncheckedCreateInputObjectSchema, ClaimUncheckedCreateInputObjectSchema,
ServiceLineTransactionCreateInputObjectSchema,
ClaimStatusSchema, ClaimStatusSchema,
StaffUncheckedCreateInputObjectSchema, StaffUncheckedCreateInputObjectSchema,
PaymentMethodSchema, PaymentMethodSchema,
PaymentStatusSchema PaymentStatusSchema,
} from "@repo/db/usedSchemas"; } from "@repo/db/usedSchemas";
import { Prisma } from "@repo/db/generated/prisma"; import { Prisma } from "@repo/db/generated/prisma";
import { z } from "zod"; import { z } from "zod";
@@ -18,43 +17,28 @@ import { Decimal } from "decimal.js";
export type Payment = z.infer<typeof PaymentUncheckedCreateInputObjectSchema>; export type Payment = z.infer<typeof PaymentUncheckedCreateInputObjectSchema>;
// Zod input type for creating a transaction // Zod input type for creating a transaction
export type PaymentTransactionInput = z.infer< export type ServiceLineTransactionInput = z.infer<
typeof PaymentTransactionCreateInputObjectSchema typeof ServiceLineTransactionCreateInputObjectSchema
>; >;
// Prisma output type for single transaction (fetched with includes) // Prisma output type for single transaction (fetched with includes)
export type PaymentTransactionRecord = Prisma.PaymentTransactionGetPayload<{ export type ServiceLineTransactionRecord =
Prisma.ServiceLineTransactionGetPayload<{
include: { include: {
serviceLinePayments: { serviceLine: true;
include: { serviceLine: true };
};
}; };
}>; }>;
// Type for ServiceLinePayment input (used for updates/creates)
export type ServiceLinePayment = z.infer<
typeof ServiceLinePaymentCreateInputObjectSchema
>;
// Enum for payment // Enum for payment
export type PaymentStatus = z.infer<typeof PaymentStatusSchema>; export type PaymentStatus = z.infer<typeof PaymentStatusSchema>;
export type PaymentMethod = z.infer<typeof PaymentMethodSchema> export type PaymentMethod = z.infer<typeof PaymentMethodSchema>;
// ✅ Runtime arrays (used in code logic / map / select options) // ✅ Runtime arrays (used in code logic / map / select options)
export const paymentStatusOptions = PaymentStatusSchema.options; export const paymentStatusOptions = PaymentStatusSchema.options;
export const paymentMethodOptions = PaymentMethodSchema.options; export const paymentMethodOptions = PaymentMethodSchema.options;
// ========== INPUT TYPES ========== // ========== INPUT TYPES ==========
// Used to update individual service line payment
export type PartialServicePaymentInput = {
id: number;
paidAmount: Decimal;
adjustedAmount: Decimal;
notes: string | null;
};
// For creating a new payment // For creating a new payment
export const insertPaymentSchema = ( export const insertPaymentSchema = (
PaymentUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any> PaymentUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
@@ -78,8 +62,7 @@ export type UpdatePayment = z.infer<typeof updatePaymentSchema>;
// Input for updating a payment with new transactions + updated service payments // Input for updating a payment with new transactions + updated service payments
export type UpdatePaymentInput = { export type UpdatePaymentInput = {
newTransactions: PaymentTransactionInput[]; newTransactions: ServiceLineTransactionInput[];
servicePayments: PartialServicePaymentInput[];
totalPaid: Decimal; totalPaid: Decimal;
totalDue: Decimal; totalDue: Decimal;
status: PaymentStatus; status: PaymentStatus;
@@ -95,15 +78,11 @@ export type PaymentWithExtras = Prisma.PaymentGetPayload<{
serviceLines: true; serviceLines: true;
}; };
}; };
transactions: { serviceLineTransactions: {
include: {
serviceLinePayments: {
include: { include: {
serviceLine: true; serviceLine: true;
}; };
}; };
};
};
updatedBy: true; updatedBy: true;
}; };
}> & { }> & {
@@ -140,7 +119,7 @@ export type NewTransactionPayload = {
payerName?: string; payerName?: string;
notes?: string; notes?: string;
receivedDate: Date; receivedDate: Date;
serviceLinePayments: { serviceLineTransactions: {
serviceLineId: number; serviceLineId: number;
paidAmount: number; paidAmount: number;
adjustedAmount: number; adjustedAmount: number;

View File

@@ -10,7 +10,6 @@ export * from '../shared/schemas/objects/PdfGroupUncheckedCreateInput.schema'
export * from '../shared/schemas/enums/PdfCategory.schema' export * from '../shared/schemas/enums/PdfCategory.schema'
export * from '../shared/schemas/enums/ClaimStatus.schema' export * from '../shared/schemas/enums/ClaimStatus.schema'
export * from '../shared/schemas/objects/PaymentUncheckedCreateInput.schema' export * from '../shared/schemas/objects/PaymentUncheckedCreateInput.schema'
export * from '../shared/schemas/objects/PaymentTransactionCreateInput.schema' export * from '../shared/schemas/objects/ServiceLineTransactionCreateInput.schema'
export * from '../shared/schemas/objects/ServiceLinePaymentCreateInput.schema'
export * from '../shared/schemas/enums/PaymentMethod.schema' export * from '../shared/schemas/enums/PaymentMethod.schema'
export * from '../shared/schemas/enums/PaymentStatus.schema' export * from '../shared/schemas/enums/PaymentStatus.schema'