Align companies with the Didar export: new fields, Didar-format Excel import/export, and people linked to companies by Didar code
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "code" TEXT;
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "importSource" TEXT NOT NULL DEFAULT 'manual';
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "sourceRef" TEXT;
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "economicCode" TEXT;
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "registrationNumber" TEXT;
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "otherPhones" TEXT;
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "fax" TEXT;
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "otherEmails" TEXT;
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "province" TEXT;
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "city" TEXT;
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "postalCode" TEXT;
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "groupName" TEXT;
|
||||
ALTER TABLE "Company" ADD COLUMN IF NOT EXISTS "registeredAt" TIMESTAMP(3);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "Company_organizationId_sourceRef_idx" ON "Company"("organizationId", "sourceRef");
|
||||
CREATE INDEX IF NOT EXISTS "Company_organizationId_code_idx" ON "Company"("organizationId", "code");
|
||||
|
||||
-- شرکتهایی که از ورود اشخاص دیدار ساخته شدهاند: کد دیدار شرکت را از customFields اشخاص بازیابی کن
|
||||
UPDATE "Company" c
|
||||
SET "sourceRef" = sub.didar_code,
|
||||
"importSource" = 'didar'
|
||||
FROM (
|
||||
SELECT DISTINCT ON (p."companyId")
|
||||
p."companyId" AS company_id,
|
||||
TRIM(p."customFields"->>'companyDidarId') AS didar_code
|
||||
FROM "Person" p
|
||||
WHERE p."companyId" IS NOT NULL
|
||||
AND jsonb_typeof(p."customFields") = 'object'
|
||||
AND COALESCE(TRIM(p."customFields"->>'companyDidarId'), '') <> ''
|
||||
ORDER BY p."companyId", p."createdAt"
|
||||
) sub
|
||||
WHERE c."id" = sub.company_id
|
||||
AND c."sourceRef" IS NULL;
|
||||
@@ -398,12 +398,28 @@ model Company {
|
||||
organizationId String
|
||||
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
||||
name String
|
||||
/// کد داخلی شرکت (مثل «کد شرکت» در دیدار)
|
||||
code String?
|
||||
/// منبع ورود: manual | didar | tahesab | excel | other
|
||||
importSource String @default("manual")
|
||||
/// شناسه در مبدأ (مثلاً کد دیدار شرکت)
|
||||
sourceRef String?
|
||||
nationalId String?
|
||||
economicCode String?
|
||||
registrationNumber String?
|
||||
phone String?
|
||||
otherPhones String?
|
||||
fax String?
|
||||
email String?
|
||||
otherEmails String?
|
||||
website String?
|
||||
province String?
|
||||
city String?
|
||||
postalCode String?
|
||||
address String?
|
||||
groupName String?
|
||||
notes String?
|
||||
registeredAt DateTime?
|
||||
tags String[] @default([])
|
||||
customFields Json @default("{}")
|
||||
people Person[]
|
||||
@@ -423,6 +439,8 @@ model Company {
|
||||
@@index([organizationId, name])
|
||||
@@index([organizationId, email])
|
||||
@@index([organizationId, phone])
|
||||
@@index([organizationId, sourceRef])
|
||||
@@index([organizationId, code])
|
||||
@@index([ownerId])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user