diff --git a/App/app/(portal)/admin/companies/actions.ts b/App/app/(portal)/admin/companies/actions.ts index bb05530..8099dc3 100644 --- a/App/app/(portal)/admin/companies/actions.ts +++ b/App/app/(portal)/admin/companies/actions.ts @@ -15,6 +15,7 @@ const companySchema = z.object({ telephone: z.string().optional(), mobile: z.string().optional(), email: z.string().email("Invalid email").optional().or(z.literal("")), + invoiceEmail: z.string().email("Invalid invoice email").optional().or(z.literal("")), invoiceAddress: z.string().optional(), }); @@ -31,13 +32,14 @@ export async function createCompany(formData: FormData): Promise { telephone: (formData.get("telephone") as string) || undefined, mobile: (formData.get("mobile") as string) || undefined, email: (formData.get("email") as string) || undefined, + invoiceEmail: (formData.get("invoiceEmail") as string) || undefined, invoiceAddress: (formData.get("invoiceAddress") as string) || undefined, }); if (!parsed.success) return { error: parsed.error.errors[0]?.message ?? "Validation failed" }; - const { name, gstNumber, address, telephone, mobile, email, invoiceAddress } = parsed.data; + const { name, gstNumber, address, telephone, mobile, email, invoiceEmail, invoiceAddress } = parsed.data; await db.company.create({ - data: { name, gstNumber: gstNumber ?? null, address: address ?? null, telephone: telephone ?? null, mobile: mobile ?? null, email: email || null, invoiceAddress: invoiceAddress ?? null }, + data: { name, gstNumber: gstNumber ?? null, address: address ?? null, telephone: telephone ?? null, mobile: mobile ?? null, email: email || null, invoiceEmail: invoiceEmail || null, invoiceAddress: invoiceAddress ?? null }, }); revalidatePath("/admin/companies"); return { ok: true }; @@ -59,14 +61,15 @@ export async function updateCompany(formData: FormData): Promise { telephone: (formData.get("telephone") as string) || undefined, mobile: (formData.get("mobile") as string) || undefined, email: (formData.get("email") as string) || undefined, + invoiceEmail: (formData.get("invoiceEmail") as string) || undefined, invoiceAddress: (formData.get("invoiceAddress") as string) || undefined, }); if (!parsed.success) return { error: parsed.error.errors[0]?.message ?? "Validation failed" }; - const { name, gstNumber, address, telephone, mobile, email, invoiceAddress } = parsed.data; + const { name, gstNumber, address, telephone, mobile, email, invoiceEmail, invoiceAddress } = parsed.data; await db.company.update({ where: { id }, - data: { name, gstNumber: gstNumber ?? null, address: address ?? null, telephone: telephone ?? null, mobile: mobile ?? null, email: email || null, invoiceAddress: invoiceAddress ?? null }, + data: { name, gstNumber: gstNumber ?? null, address: address ?? null, telephone: telephone ?? null, mobile: mobile ?? null, email: email || null, invoiceEmail: invoiceEmail || null, invoiceAddress: invoiceAddress ?? null }, }); revalidatePath("/admin/companies"); return { ok: true }; diff --git a/App/app/(portal)/admin/companies/companies-table.tsx b/App/app/(portal)/admin/companies/companies-table.tsx index 5094dab..9a06164 100644 --- a/App/app/(portal)/admin/companies/companies-table.tsx +++ b/App/app/(portal)/admin/companies/companies-table.tsx @@ -15,6 +15,7 @@ export type CompanyRow = { telephone: string | null; mobile: string | null; email: string | null; + invoiceEmail: string | null; invoiceAddress: string | null; isActive: boolean; }; @@ -91,7 +92,8 @@ export function CompaniesTable({ companies }: { companies: CompanyRow[] }) { {c.telephone &&

☎ {c.telephone}

} {c.mobile &&

📱 {c.mobile}

} {c.email &&

✉ {c.email}

} - {!c.telephone && !c.mobile && !c.email && } + {c.invoiceEmail &&

📄 {c.invoiceEmail}

} + {!c.telephone && !c.mobile && !c.email && !c.invoiceEmail && } diff --git a/App/app/(portal)/admin/companies/company-form.tsx b/App/app/(portal)/admin/companies/company-form.tsx index c0ac4a0..3be7f95 100644 --- a/App/app/(portal)/admin/companies/company-form.tsx +++ b/App/app/(portal)/admin/companies/company-form.tsx @@ -13,6 +13,7 @@ type CompanyRow = { telephone: string | null; mobile: string | null; email: string | null; + invoiceEmail: string | null; invoiceAddress: string | null; isActive: boolean; }; @@ -33,8 +34,12 @@ function CompanyFormFields({ company }: { company?: CompanyRow }) {
- - + + +
+
+ +
diff --git a/App/app/(portal)/admin/companies/page.tsx b/App/app/(portal)/admin/companies/page.tsx index b7d4700..72e29ba 100644 --- a/App/app/(portal)/admin/companies/page.tsx +++ b/App/app/(portal)/admin/companies/page.tsx @@ -26,6 +26,7 @@ export default async function AdminCompaniesPage() { telephone: c.telephone, mobile: c.mobile, email: c.email, + invoiceEmail: c.invoiceEmail, invoiceAddress: c.invoiceAddress, isActive: c.isActive, }))} diff --git a/App/app/api/po/[id]/export/route.ts b/App/app/api/po/[id]/export/route.ts index 0f0a8c9..535f1e2 100644 --- a/App/app/api/po/[id]/export/route.ts +++ b/App/app/api/po/[id]/export/route.ts @@ -74,9 +74,11 @@ export async function GET(request: NextRequest, { params }: Props) { const CO_TEL = telParts.length > 0 ? telParts.join(" / ") : DEFAULT_CO_TEL; const INV_ADDR = co?.invoiceAddress ?? (co?.address ? `${co.name}, ${co.address}` : DEFAULT_INV_ADDR); + // invoiceEmail takes priority over general email for the Invoice Details line + const invoiceContactEmail = co?.invoiceEmail ?? co?.email ?? null; const INV_GST = [ - co?.email ? `Email: ${co.email}` : null, - co?.gstNumber ? `GST NO: ${co.gstNumber}` : null, + invoiceContactEmail ? `Email: ${invoiceContactEmail}` : null, + co?.gstNumber ? `GST NO: ${co.gstNumber}` : null, ].filter(Boolean).join(" ") || DEFAULT_INV_GST; // ── Computed data ───────────────────────────────────────────────────────── diff --git a/App/prisma/migrations/20260531000000_company_invoice_email/migration.sql b/App/prisma/migrations/20260531000000_company_invoice_email/migration.sql new file mode 100644 index 0000000..29a13d8 --- /dev/null +++ b/App/prisma/migrations/20260531000000_company_invoice_email/migration.sql @@ -0,0 +1,2 @@ +-- Add invoiceEmail field to Company (separate from main contact email) +ALTER TABLE "Company" ADD COLUMN "invoiceEmail" TEXT; diff --git a/App/prisma/schema.prisma b/App/prisma/schema.prisma index 5a423f1..8cbf5ef 100644 --- a/App/prisma/schema.prisma +++ b/App/prisma/schema.prisma @@ -122,6 +122,7 @@ model Company { telephone String? mobile String? email String? + invoiceEmail String? invoiceAddress String? isActive Boolean @default(true) createdAt DateTime @default(now())