feat(tahesab): sales report snapshot with org-module gate
Sync linked asnad into CRM, filter by group/kind/metal, and require the tahesab superadmin module plus reports role access.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "AccountingAsnadLine" (
|
||||
"id" TEXT NOT NULL,
|
||||
"organizationId" TEXT NOT NULL,
|
||||
"connectionId" TEXT NOT NULL,
|
||||
"personId" TEXT,
|
||||
"linkId" TEXT,
|
||||
"moshtariCode" INTEGER NOT NULL,
|
||||
"lineKey" TEXT NOT NULL,
|
||||
"tahesabId" INTEGER,
|
||||
"factorCode" TEXT,
|
||||
"shFactor" INTEGER,
|
||||
"radif" INTEGER,
|
||||
"tarikh" TEXT NOT NULL,
|
||||
"noRaw" TEXT NOT NULL DEFAULT '',
|
||||
"kind" TEXT NOT NULL DEFAULT 'other',
|
||||
"jensFelez" INTEGER,
|
||||
"noKar" TEXT,
|
||||
"vazn" DOUBLE PRECISION,
|
||||
"tabdilVazn" DOUBLE PRECISION,
|
||||
"mali" DOUBLE PRECISION,
|
||||
"count" DOUBLE PRECISION,
|
||||
"ayar" DOUBLE PRECISION,
|
||||
"mazaneh" DOUBLE PRECISION,
|
||||
"fi" DOUBLE PRECISION,
|
||||
"sharh1" TEXT,
|
||||
"syncedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "AccountingAsnadLine_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "AccountingAsnadLine_connectionId_lineKey_key" ON "AccountingAsnadLine"("connectionId", "lineKey");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "AccountingAsnadLine_organizationId_connectionId_tarikh_idx" ON "AccountingAsnadLine"("organizationId", "connectionId", "tarikh");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "AccountingAsnadLine_organizationId_kind_idx" ON "AccountingAsnadLine"("organizationId", "kind");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "AccountingAsnadLine_personId_idx" ON "AccountingAsnadLine"("personId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "AccountingAsnadLine_linkId_idx" ON "AccountingAsnadLine"("linkId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "AccountingAsnadLine_moshtariCode_idx" ON "AccountingAsnadLine"("moshtariCode");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "AccountingAsnadLine" ADD CONSTRAINT "AccountingAsnadLine_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "AccountingAsnadLine" ADD CONSTRAINT "AccountingAsnadLine_connectionId_fkey" FOREIGN KEY ("connectionId") REFERENCES "AccountingConnection"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "AccountingAsnadLine" ADD CONSTRAINT "AccountingAsnadLine_personId_fkey" FOREIGN KEY ("personId") REFERENCES "Person"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "AccountingAsnadLine" ADD CONSTRAINT "AccountingAsnadLine_linkId_fkey" FOREIGN KEY ("linkId") REFERENCES "PersonAccountingLink"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -196,6 +196,7 @@ model Organization {
|
||||
noteAiSuggestions NoteAiSuggestion[]
|
||||
accountingConnections AccountingConnection[]
|
||||
accountingSyncJobs AccountingSyncJob[]
|
||||
accountingAsnadLines AccountingAsnadLine[]
|
||||
warehouses Warehouse[]
|
||||
stockMovements StockMovement[]
|
||||
partyOpenings PartyOpeningBalance[]
|
||||
@@ -614,6 +615,7 @@ model Person {
|
||||
memoryItems MemoryItem[]
|
||||
accountingLinks PersonAccountingLink[]
|
||||
accountingDocuments AccountingDocumentLog[]
|
||||
asnadLines AccountingAsnadLine[]
|
||||
openingBalances PartyOpeningBalance[]
|
||||
cheques Cheque[]
|
||||
trackingLinks TrackingLink[]
|
||||
@@ -1747,6 +1749,7 @@ model AccountingConnection {
|
||||
productLinks ProductAccountingLink[]
|
||||
documentLogs AccountingDocumentLog[]
|
||||
balanceCaches AccountingBalanceCache[]
|
||||
asnadLines AccountingAsnadLine[]
|
||||
|
||||
@@unique([organizationId, baseUrl, dbName])
|
||||
@@index([organizationId, enabled])
|
||||
@@ -1766,6 +1769,7 @@ model PersonAccountingLink {
|
||||
linkedAt DateTime @default(now())
|
||||
lastBalanceSyncedAt DateTime?
|
||||
balanceCache AccountingBalanceCache?
|
||||
asnadLines AccountingAsnadLine[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@ -1844,6 +1848,51 @@ model AccountingBalanceCache {
|
||||
@@index([connectionId])
|
||||
}
|
||||
|
||||
/// اسنپشات ردیفهای DoListAsnad برای گزارش فروش گروهی
|
||||
model AccountingAsnadLine {
|
||||
id String @id @default(cuid())
|
||||
organizationId String
|
||||
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
||||
connectionId String
|
||||
connection AccountingConnection @relation(fields: [connectionId], references: [id], onDelete: Cascade)
|
||||
personId String?
|
||||
person Person? @relation(fields: [personId], references: [id], onDelete: SetNull)
|
||||
linkId String?
|
||||
link PersonAccountingLink? @relation(fields: [linkId], references: [id], onDelete: SetNull)
|
||||
moshtariCode Int
|
||||
/// کلید پایدار برای upsert: ID تهحساب یا f:factor|r:radif|t:tarikh|n:no
|
||||
lineKey String
|
||||
tahesabId Int?
|
||||
factorCode String?
|
||||
shFactor Int?
|
||||
radif Int?
|
||||
/// شمسی YYYY-MM-DD
|
||||
tarikh String
|
||||
noRaw String @default("")
|
||||
/// sale | return | purchase | other
|
||||
kind String @default("other")
|
||||
jensFelez Int?
|
||||
noKar String?
|
||||
vazn Float?
|
||||
tabdilVazn Float?
|
||||
mali Float?
|
||||
count Float?
|
||||
ayar Float?
|
||||
mazaneh Float?
|
||||
fi Float?
|
||||
sharh1 String?
|
||||
syncedAt DateTime @default(now())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([connectionId, lineKey])
|
||||
@@index([organizationId, connectionId, tarikh])
|
||||
@@index([organizationId, kind])
|
||||
@@index([personId])
|
||||
@@index([linkId])
|
||||
@@index([moshtariCode])
|
||||
}
|
||||
|
||||
model AccountingSyncJob {
|
||||
id String @id @default(cuid())
|
||||
organizationId String
|
||||
|
||||
Reference in New Issue
Block a user