Let cheques be received or paid without an invoice, and remind staff three days before due date.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Cheque" ALTER COLUMN "paymentId" DROP NOT NULL;
|
||||
ALTER TABLE "Cheque" ALTER COLUMN "invoiceId" DROP NOT NULL;
|
||||
ALTER TABLE "Cheque" ADD COLUMN "amount" DECIMAL(18,2);
|
||||
ALTER TABLE "Cheque" ADD COLUMN "currency" TEXT NOT NULL DEFAULT 'IRR';
|
||||
ALTER TABLE "Cheque" ADD COLUMN "personId" TEXT;
|
||||
ALTER TABLE "Cheque" ADD COLUMN "ownerId" TEXT;
|
||||
|
||||
UPDATE "Cheque" AS c
|
||||
SET
|
||||
"amount" = p."amount",
|
||||
"currency" = p."currency"
|
||||
FROM "Payment" AS p
|
||||
WHERE c."paymentId" = p."id";
|
||||
|
||||
UPDATE "Cheque" AS c
|
||||
SET
|
||||
"personId" = i."personId",
|
||||
"ownerId" = i."ownerId"
|
||||
FROM "Invoice" AS i
|
||||
WHERE c."invoiceId" = i."id";
|
||||
|
||||
UPDATE "Cheque" SET "amount" = 0 WHERE "amount" IS NULL;
|
||||
|
||||
ALTER TABLE "Cheque" ALTER COLUMN "amount" SET NOT NULL;
|
||||
|
||||
CREATE INDEX "Cheque_personId_idx" ON "Cheque"("personId");
|
||||
CREATE INDEX "Cheque_ownerId_idx" ON "Cheque"("ownerId");
|
||||
|
||||
ALTER TABLE "Cheque" ADD CONSTRAINT "Cheque_personId_fkey" FOREIGN KEY ("personId") REFERENCES "Person"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
ALTER TABLE "Cheque" ADD CONSTRAINT "Cheque_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,5 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Cheque" ADD COLUMN "direction" TEXT NOT NULL DEFAULT 'in';
|
||||
ALTER TABLE "Cheque" ADD COLUMN "reminderNotifiedAt" TIMESTAMP(3);
|
||||
|
||||
CREATE INDEX "Cheque_organizationId_direction_dueDate_idx" ON "Cheque"("organizationId", "direction", "dueDate");
|
||||
@@ -213,6 +213,7 @@ model User {
|
||||
salesGoals SalesGoal[] @relation("SalesGoalUser")
|
||||
commissionPercent Decimal @default(0) @db.Decimal(8, 2)
|
||||
commissionEntries CommissionEntry[]
|
||||
receivedCheques Cheque[] @relation("ChequeOwner")
|
||||
assignedTickets Ticket[] @relation("TicketAssignee")
|
||||
reportedTickets Ticket[] @relation("TicketReporter")
|
||||
ticketMessages TicketMessage[] @relation("TicketMessageAuthor")
|
||||
@@ -291,6 +292,7 @@ model Person {
|
||||
accountingLinks PersonAccountingLink[]
|
||||
accountingDocuments AccountingDocumentLog[]
|
||||
openingBalances PartyOpeningBalance[]
|
||||
cheques Cheque[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@ -1284,26 +1286,38 @@ model CommissionEntry {
|
||||
@@index([status])
|
||||
}
|
||||
|
||||
/// چک دریافتی وصل به پرداخت فاکتور
|
||||
/// چک دریافتی؛ مستقل یا وصل به پرداخت فاکتور
|
||||
model Cheque {
|
||||
id String @id @default(cuid())
|
||||
organizationId String
|
||||
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
||||
paymentId String @unique
|
||||
payment Payment @relation(fields: [paymentId], references: [id], onDelete: Cascade)
|
||||
invoiceId String
|
||||
invoice Invoice @relation(fields: [invoiceId], references: [id], onDelete: Cascade)
|
||||
paymentId String? @unique
|
||||
payment Payment? @relation(fields: [paymentId], references: [id], onDelete: Cascade)
|
||||
invoiceId String?
|
||||
invoice Invoice? @relation(fields: [invoiceId], references: [id], onDelete: Cascade)
|
||||
personId String?
|
||||
person Person? @relation(fields: [personId], references: [id], onDelete: SetNull)
|
||||
ownerId String?
|
||||
owner User? @relation("ChequeOwner", fields: [ownerId], references: [id], onDelete: SetNull)
|
||||
amount Decimal @db.Decimal(18, 2)
|
||||
currency String @default("IRR")
|
||||
number String
|
||||
bank String
|
||||
dueDate DateTime
|
||||
/// pending | cleared | bounced
|
||||
status String @default("pending")
|
||||
/// in = دریافتی، out = پرداختی
|
||||
direction String @default("in")
|
||||
reminderNotifiedAt DateTime?
|
||||
notes String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([organizationId, status, dueDate])
|
||||
@@index([organizationId, direction, dueDate])
|
||||
@@index([invoiceId])
|
||||
@@index([personId])
|
||||
@@index([ownerId])
|
||||
}
|
||||
|
||||
/// مانده اول دوره طرفحساب (مثبت = بدهکار ما)
|
||||
|
||||
Reference in New Issue
Block a user