payment checkpoint 3
This commit is contained in:
@@ -14,7 +14,8 @@
|
||||
"./client": "./src/index.ts",
|
||||
"./shared/schemas" : "./shared/schemas/index.ts",
|
||||
"./usedSchemas" : "./usedSchemas/index.ts",
|
||||
"./generated/prisma" : "./generated/prisma/index.d.ts"
|
||||
"./generated/prisma" : "./generated/prisma/index.d.ts",
|
||||
"./types" : "./types/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "^6.10.0",
|
||||
|
||||
@@ -55,6 +55,7 @@ model Patient {
|
||||
appointments Appointment[]
|
||||
claims Claim[]
|
||||
groups PdfGroup[]
|
||||
payment Payment[]
|
||||
|
||||
@@index([insuranceId])
|
||||
@@index([createdAt])
|
||||
@@ -135,10 +136,12 @@ model ServiceLine {
|
||||
toothNumber String?
|
||||
toothSurface String?
|
||||
billedAmount Float
|
||||
totalPaid Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
totalAdjusted Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
status ServiceLineStatus @default(UNPAID)
|
||||
|
||||
claim Claim @relation(fields: [claimId], references: [id], onDelete: Cascade)
|
||||
servicePayments ServiceLinePayment[]
|
||||
serviceLineTransactions ServiceLineTransaction[]
|
||||
}
|
||||
|
||||
enum ServiceLineStatus {
|
||||
@@ -196,57 +199,45 @@ enum PdfCategory {
|
||||
|
||||
model Payment {
|
||||
id Int @id @default(autoincrement())
|
||||
claimId Int @unique
|
||||
patientId Int
|
||||
userId Int
|
||||
claimId Int @unique
|
||||
updatedById Int?
|
||||
totalBilled Decimal @db.Decimal(10, 2)
|
||||
totalPaid Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
totalDue Decimal @db.Decimal(10, 2)
|
||||
status PaymentStatus @default(PENDING)
|
||||
receivedDate DateTime?
|
||||
paymentMethod PaymentMethod?
|
||||
notes String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
claim Claim @relation(fields: [claimId], references: [id], onDelete: Cascade)
|
||||
updatedBy User? @relation("PaymentUpdatedBy", fields: [updatedById], references: [id])
|
||||
transactions PaymentTransaction[]
|
||||
claim Claim @relation(fields: [claimId], references: [id], onDelete: Cascade)
|
||||
patient Patient @relation(fields: [patientId], references: [id], onDelete: Cascade)
|
||||
updatedBy User? @relation("PaymentUpdatedBy", fields: [updatedById], references: [id])
|
||||
transactions ServiceLineTransaction[]
|
||||
|
||||
@@index([id])
|
||||
@@index([claimId])
|
||||
@@index([patientId])
|
||||
}
|
||||
|
||||
model PaymentTransaction {
|
||||
id Int @id @default(autoincrement())
|
||||
paymentId Int
|
||||
amount Decimal @db.Decimal(10, 2)
|
||||
method PaymentMethod
|
||||
transactionId String?
|
||||
receivedDate DateTime
|
||||
payerName String?
|
||||
notes String?
|
||||
createdAt DateTime @default(now())
|
||||
payment Payment @relation(fields: [paymentId], references: [id], onDelete: Cascade)
|
||||
serviceLinePayments ServiceLinePayment[]
|
||||
model ServiceLineTransaction {
|
||||
id Int @id @default(autoincrement())
|
||||
paymentId Int
|
||||
serviceLineId Int
|
||||
transactionId String?
|
||||
paidAmount Decimal @db.Decimal(10, 2)
|
||||
adjustedAmount Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
method PaymentMethod
|
||||
receivedDate DateTime
|
||||
payerName String?
|
||||
notes String?
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
payment Payment @relation(fields: [paymentId], references: [id], onDelete: Cascade)
|
||||
serviceLine ServiceLine @relation(fields: [serviceLineId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([paymentId])
|
||||
}
|
||||
|
||||
model ServiceLinePayment {
|
||||
id Int @id @default(autoincrement())
|
||||
transactionId Int
|
||||
serviceLineId Int
|
||||
paidAmount Decimal @db.Decimal(10, 2)
|
||||
adjustedAmount Decimal @default(0.00) @db.Decimal(10, 2)
|
||||
notes String?
|
||||
|
||||
transaction PaymentTransaction @relation(fields: [transactionId], references: [id], onDelete: Cascade)
|
||||
serviceLine ServiceLine @relation(fields: [serviceLineId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([transactionId])
|
||||
@@index([serviceLineId])
|
||||
}
|
||||
|
||||
|
||||
2
packages/db/types/index.ts
Normal file
2
packages/db/types/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
export * from "./payment-types";
|
||||
149
packages/db/types/payment-types.ts
Normal file
149
packages/db/types/payment-types.ts
Normal file
@@ -0,0 +1,149 @@
|
||||
import {
|
||||
PaymentUncheckedCreateInputObjectSchema,
|
||||
PaymentTransactionCreateInputObjectSchema,
|
||||
ServiceLinePaymentCreateInputObjectSchema,
|
||||
ClaimUncheckedCreateInputObjectSchema,
|
||||
ClaimStatusSchema,
|
||||
StaffUncheckedCreateInputObjectSchema,
|
||||
PaymentMethodSchema,
|
||||
PaymentStatusSchema
|
||||
} from "@repo/db/usedSchemas";
|
||||
import { Prisma } from "@repo/db/generated/prisma";
|
||||
import { z } from "zod";
|
||||
import { Decimal } from "decimal.js";
|
||||
|
||||
// ========== BASIC TYPES ==========
|
||||
|
||||
// Payment basic type from Zod
|
||||
export type Payment = z.infer<typeof PaymentUncheckedCreateInputObjectSchema>;
|
||||
|
||||
// Zod input type for creating a transaction
|
||||
export type PaymentTransactionInput = z.infer<
|
||||
typeof PaymentTransactionCreateInputObjectSchema
|
||||
>;
|
||||
|
||||
// Prisma output type for single transaction (fetched with includes)
|
||||
export type PaymentTransactionRecord = Prisma.PaymentTransactionGetPayload<{
|
||||
include: {
|
||||
serviceLinePayments: {
|
||||
include: { serviceLine: true };
|
||||
};
|
||||
};
|
||||
}>;
|
||||
|
||||
// Type for ServiceLinePayment input (used for updates/creates)
|
||||
export type ServiceLinePayment = z.infer<
|
||||
typeof ServiceLinePaymentCreateInputObjectSchema
|
||||
>;
|
||||
|
||||
// Enum for payment
|
||||
export type PaymentStatus = z.infer<typeof PaymentStatusSchema>;
|
||||
export type PaymentMethod = z.infer<typeof PaymentMethodSchema>
|
||||
|
||||
// ✅ Runtime arrays (used in code logic / map / select options)
|
||||
export const paymentStatusOptions = PaymentStatusSchema.options;
|
||||
export const paymentMethodOptions = PaymentMethodSchema.options;
|
||||
|
||||
|
||||
// ========== 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
|
||||
export const insertPaymentSchema = (
|
||||
PaymentUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
|
||||
).omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
export type InsertPayment = z.infer<typeof insertPaymentSchema>;
|
||||
|
||||
// For updating an existing payment (partial updates)
|
||||
export const updatePaymentSchema = (
|
||||
PaymentUncheckedCreateInputObjectSchema as unknown as z.ZodObject<any>
|
||||
)
|
||||
.omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
})
|
||||
.partial();
|
||||
export type UpdatePayment = z.infer<typeof updatePaymentSchema>;
|
||||
|
||||
// Input for updating a payment with new transactions + updated service payments
|
||||
export type UpdatePaymentInput = {
|
||||
newTransactions: PaymentTransactionInput[];
|
||||
servicePayments: PartialServicePaymentInput[];
|
||||
totalPaid: Decimal;
|
||||
totalDue: Decimal;
|
||||
status: PaymentStatus;
|
||||
};
|
||||
|
||||
// ========== EXTENDED TYPES ==========
|
||||
|
||||
// Payment with full nested data
|
||||
export type PaymentWithExtras = Prisma.PaymentGetPayload<{
|
||||
include: {
|
||||
claim: {
|
||||
include: {
|
||||
serviceLines: true;
|
||||
};
|
||||
};
|
||||
transactions: {
|
||||
include: {
|
||||
serviceLinePayments: {
|
||||
include: {
|
||||
serviceLine: true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
updatedBy: true;
|
||||
};
|
||||
}> & {
|
||||
patientName: string;
|
||||
paymentDate: Date;
|
||||
paymentMethod: string;
|
||||
};
|
||||
|
||||
// Claim model with embedded service lines
|
||||
export type Claim = z.infer<typeof ClaimUncheckedCreateInputObjectSchema>;
|
||||
export type ClaimStatus = z.infer<typeof ClaimStatusSchema>;
|
||||
|
||||
export type Staff = z.infer<typeof StaffUncheckedCreateInputObjectSchema>;
|
||||
|
||||
export type ClaimWithServiceLines = Claim & {
|
||||
serviceLines: {
|
||||
id: number;
|
||||
claimId: number;
|
||||
procedureCode: string;
|
||||
procedureDate: Date;
|
||||
oralCavityArea: string | null;
|
||||
toothNumber: string | null;
|
||||
toothSurface: string | null;
|
||||
billedAmount: number;
|
||||
status: string;
|
||||
}[];
|
||||
staff: Staff | null;
|
||||
};
|
||||
|
||||
export type NewTransactionPayload = {
|
||||
paymentId: number;
|
||||
amount: number;
|
||||
method: PaymentMethod;
|
||||
payerName?: string;
|
||||
notes?: string;
|
||||
receivedDate: Date;
|
||||
serviceLinePayments: {
|
||||
serviceLineId: number;
|
||||
paidAmount: number;
|
||||
adjustedAmount: number;
|
||||
notes?: string;
|
||||
}[];
|
||||
};
|
||||
@@ -11,4 +11,6 @@ export * from '../shared/schemas/enums/PdfCategory.schema'
|
||||
export * from '../shared/schemas/enums/ClaimStatus.schema'
|
||||
export * from '../shared/schemas/objects/PaymentUncheckedCreateInput.schema'
|
||||
export * from '../shared/schemas/objects/PaymentTransactionCreateInput.schema'
|
||||
export * from '../shared/schemas/objects/ServiceLinePaymentCreateInput.schema'
|
||||
export * from '../shared/schemas/objects/ServiceLinePaymentCreateInput.schema'
|
||||
export * from '../shared/schemas/enums/PaymentMethod.schema'
|
||||
export * from '../shared/schemas/enums/PaymentStatus.schema'
|
||||
Reference in New Issue
Block a user