Unify invoices and quotes UI with discount, tax, and credit notes.
Match list/form mockups on desktop and mobile, wire real APIs for billing fields, and merge proforma into the invoices section. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
-- AlterTable Quote
|
||||
ALTER TABLE "Quote" ADD COLUMN IF NOT EXISTS "discountAmount" DECIMAL(18,2) NOT NULL DEFAULT 0;
|
||||
ALTER TABLE "Quote" ADD COLUMN IF NOT EXISTS "taxPercent" DECIMAL(8,2) NOT NULL DEFAULT 0;
|
||||
ALTER TABLE "Quote" ADD COLUMN IF NOT EXISTS "issuedAt" TIMESTAMP(3);
|
||||
|
||||
-- AlterTable Invoice
|
||||
ALTER TABLE "Invoice" ADD COLUMN IF NOT EXISTS "kind" TEXT NOT NULL DEFAULT 'invoice';
|
||||
ALTER TABLE "Invoice" ADD COLUMN IF NOT EXISTS "discountAmount" DECIMAL(18,2) NOT NULL DEFAULT 0;
|
||||
ALTER TABLE "Invoice" ADD COLUMN IF NOT EXISTS "taxPercent" DECIMAL(8,2) NOT NULL DEFAULT 0;
|
||||
@@ -614,6 +614,9 @@ model Quote {
|
||||
status QuoteStatus @default(draft)
|
||||
currency String @default("IRR")
|
||||
notes String?
|
||||
discountAmount Decimal @default(0) @db.Decimal(18, 2)
|
||||
taxPercent Decimal @default(0) @db.Decimal(8, 2)
|
||||
issuedAt DateTime?
|
||||
validUntil DateTime?
|
||||
personId String?
|
||||
person Person? @relation(fields: [personId], references: [id], onDelete: SetNull)
|
||||
@@ -661,8 +664,11 @@ model Invoice {
|
||||
number String
|
||||
title String
|
||||
status InvoiceStatus @default(draft)
|
||||
kind String @default("invoice") // invoice | credit
|
||||
currency String @default("IRR")
|
||||
notes String?
|
||||
discountAmount Decimal @default(0) @db.Decimal(18, 2)
|
||||
taxPercent Decimal @default(0) @db.Decimal(8, 2)
|
||||
issuedAt DateTime?
|
||||
dueDate DateTime?
|
||||
personId String?
|
||||
|
||||
@@ -20,6 +20,8 @@ const INVOICE_STATUSES = [
|
||||
'canceled',
|
||||
] as const;
|
||||
|
||||
const INVOICE_KINDS = ['invoice', 'credit'] as const;
|
||||
|
||||
const PAYMENT_METHODS = [
|
||||
'cash',
|
||||
'transfer',
|
||||
@@ -79,6 +81,10 @@ export class CreateInvoiceDto {
|
||||
@IsIn(INVOICE_STATUSES)
|
||||
status?: (typeof INVOICE_STATUSES)[number];
|
||||
|
||||
@IsOptional()
|
||||
@IsIn(INVOICE_KINDS)
|
||||
kind?: (typeof INVOICE_KINDS)[number];
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(8)
|
||||
@@ -89,6 +95,18 @@ export class CreateInvoiceDto {
|
||||
@MaxLength(4000)
|
||||
notes?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
discountAmount?: number;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
taxPercent?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
issuedAt?: string | null;
|
||||
@@ -146,6 +164,10 @@ export class UpdateInvoiceDto {
|
||||
@IsIn(INVOICE_STATUSES)
|
||||
status?: (typeof INVOICE_STATUSES)[number];
|
||||
|
||||
@IsOptional()
|
||||
@IsIn(INVOICE_KINDS)
|
||||
kind?: (typeof INVOICE_KINDS)[number];
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(8)
|
||||
@@ -156,6 +178,18 @@ export class UpdateInvoiceDto {
|
||||
@MaxLength(4000)
|
||||
notes?: string | null;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
discountAmount?: number;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
taxPercent?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
issuedAt?: string | null;
|
||||
@@ -231,6 +265,10 @@ export class ListInvoicesQueryDto {
|
||||
@IsIn(INVOICE_STATUSES)
|
||||
status?: (typeof INVOICE_STATUSES)[number];
|
||||
|
||||
@IsOptional()
|
||||
@IsIn(INVOICE_KINDS)
|
||||
kind?: (typeof INVOICE_KINDS)[number];
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
dealId?: string;
|
||||
@@ -239,10 +277,32 @@ export class ListInvoicesQueryDto {
|
||||
@IsString()
|
||||
personId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
companyId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
quoteId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
from?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
to?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
amountMin?: number;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
amountMax?: number;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
|
||||
@@ -34,9 +34,15 @@ export class InvoicesController {
|
||||
return this.invoicesService.list(user.organizationId, user, {
|
||||
q: query.q,
|
||||
status: query.status,
|
||||
kind: query.kind,
|
||||
dealId: query.dealId,
|
||||
personId: query.personId,
|
||||
companyId: query.companyId,
|
||||
quoteId: query.quoteId,
|
||||
from: query.from,
|
||||
to: query.to,
|
||||
amountMin: query.amountMin,
|
||||
amountMax: query.amountMax,
|
||||
page: query.page ?? 1,
|
||||
limit: query.limit ?? 50,
|
||||
});
|
||||
|
||||
@@ -45,22 +45,32 @@ export class InvoicesService {
|
||||
opts: {
|
||||
q?: string;
|
||||
status?: string;
|
||||
kind?: string;
|
||||
dealId?: string;
|
||||
personId?: string;
|
||||
companyId?: string;
|
||||
quoteId?: string;
|
||||
from?: string;
|
||||
to?: string;
|
||||
amountMin?: number;
|
||||
amountMax?: number;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
},
|
||||
): Promise<PaginatedResponse<InvoiceDto>> {
|
||||
const page = opts.page ?? 1;
|
||||
const limit = opts.limit ?? 50;
|
||||
const dateFilter = buildDateRangeFilter(opts.from, opts.to);
|
||||
const where: Prisma.InvoiceWhereInput = {
|
||||
organizationId,
|
||||
...ownerWhere(actor),
|
||||
...(opts.status ? { status: opts.status as never } : {}),
|
||||
...(opts.kind ? { kind: opts.kind } : {}),
|
||||
...(opts.dealId ? { dealId: opts.dealId } : {}),
|
||||
...(opts.personId ? { personId: opts.personId } : {}),
|
||||
...(opts.companyId ? { companyId: opts.companyId } : {}),
|
||||
...(opts.quoteId ? { quoteId: opts.quoteId } : {}),
|
||||
...(dateFilter ? dateFilter : {}),
|
||||
...(opts.q?.trim()
|
||||
? {
|
||||
OR: [
|
||||
@@ -72,6 +82,28 @@ export class InvoicesService {
|
||||
: {}),
|
||||
};
|
||||
|
||||
const hasAmountFilter =
|
||||
opts.amountMin != null || opts.amountMax != null;
|
||||
|
||||
if (hasAmountFilter) {
|
||||
const rows = await this.prisma.invoice.findMany({
|
||||
where,
|
||||
include,
|
||||
orderBy: { updatedAt: 'desc' },
|
||||
});
|
||||
const filtered = rows
|
||||
.map((row) => this.toDto(row))
|
||||
.filter((dto) => {
|
||||
const amount = Math.abs(dto.payableAmount);
|
||||
if (opts.amountMin != null && amount < opts.amountMin) return false;
|
||||
if (opts.amountMax != null && amount > opts.amountMax) return false;
|
||||
return true;
|
||||
});
|
||||
const total = filtered.length;
|
||||
const items = filtered.slice((page - 1) * limit, page * limit);
|
||||
return { items, total, page, limit };
|
||||
}
|
||||
|
||||
const [rows, total] = await this.prisma.$transaction([
|
||||
this.prisma.invoice.findMany({
|
||||
where,
|
||||
@@ -191,6 +223,7 @@ export class InvoicesService {
|
||||
|
||||
const number = await this.nextNumber(organizationId);
|
||||
const installments = dto.installments ?? [];
|
||||
const kind = dto.kind === 'credit' ? 'credit' : 'invoice';
|
||||
|
||||
const row = await this.prisma.invoice.create({
|
||||
data: {
|
||||
@@ -198,8 +231,11 @@ export class InvoicesService {
|
||||
number,
|
||||
title,
|
||||
status,
|
||||
kind,
|
||||
currency,
|
||||
notes,
|
||||
discountAmount: new Prisma.Decimal(dto.discountAmount ?? 0),
|
||||
taxPercent: new Prisma.Decimal(dto.taxPercent ?? 0),
|
||||
issuedAt,
|
||||
dueDate,
|
||||
personId,
|
||||
@@ -268,6 +304,15 @@ export class InvoicesService {
|
||||
data.currency = dto.currency.trim() || 'IRR';
|
||||
}
|
||||
if ('notes' in dto) data.notes = emptyToNull(dto.notes ?? null);
|
||||
if (dto.kind !== undefined) {
|
||||
data.kind = dto.kind === 'credit' ? 'credit' : 'invoice';
|
||||
}
|
||||
if (dto.discountAmount !== undefined) {
|
||||
data.discountAmount = new Prisma.Decimal(dto.discountAmount);
|
||||
}
|
||||
if (dto.taxPercent !== undefined) {
|
||||
data.taxPercent = new Prisma.Decimal(dto.taxPercent);
|
||||
}
|
||||
if ('issuedAt' in dto) {
|
||||
data.issuedAt = dto.issuedAt ? new Date(dto.issuedAt) : null;
|
||||
}
|
||||
@@ -439,10 +484,18 @@ export class InvoicesService {
|
||||
return;
|
||||
}
|
||||
|
||||
const total = invoice.lineItems.reduce(
|
||||
const subtotal = invoice.lineItems.reduce(
|
||||
(sum, item) => sum + Number(item.quantity) * Number(item.unitPrice),
|
||||
0,
|
||||
);
|
||||
const discountAmount = Number(invoice.discountAmount ?? 0);
|
||||
const taxPercent = Number(invoice.taxPercent ?? 0);
|
||||
const taxAmount = roundMoney(
|
||||
Math.max(0, subtotal - discountAmount) * (taxPercent / 100),
|
||||
);
|
||||
const total = Math.abs(
|
||||
roundMoney(subtotal - discountAmount + taxAmount),
|
||||
);
|
||||
const paid = invoice.payments.reduce(
|
||||
(sum, item) => sum + Number(item.amount),
|
||||
0,
|
||||
@@ -580,7 +633,15 @@ export class InvoicesService {
|
||||
lineTotal: quantity * unitPrice,
|
||||
};
|
||||
});
|
||||
const totalAmount = lineItems.reduce((sum, item) => sum + item.lineTotal, 0);
|
||||
const subtotal = lineItems.reduce((sum, item) => sum + item.lineTotal, 0);
|
||||
const discountAmount = Number(row.discountAmount ?? 0);
|
||||
const taxPercent = Number(row.taxPercent ?? 0);
|
||||
const taxAmount = roundMoney(
|
||||
Math.max(0, subtotal - discountAmount) * (taxPercent / 100),
|
||||
);
|
||||
const signedPayable = roundMoney(subtotal - discountAmount + taxAmount);
|
||||
const kind = row.kind === 'credit' ? 'credit' : 'invoice';
|
||||
const payableAmount = kind === 'credit' ? -signedPayable : signedPayable;
|
||||
const payments: PaymentDto[] = row.payments.map((p) => ({
|
||||
id: p.id,
|
||||
amount: Number(p.amount),
|
||||
@@ -608,13 +669,19 @@ export class InvoicesService {
|
||||
number: row.number,
|
||||
title: row.title,
|
||||
status: row.status,
|
||||
kind,
|
||||
currency: row.currency,
|
||||
notes: row.notes,
|
||||
discountAmount,
|
||||
taxPercent,
|
||||
issuedAt: row.issuedAt?.toISOString() ?? null,
|
||||
dueDate: row.dueDate?.toISOString() ?? null,
|
||||
totalAmount,
|
||||
totalAmount: subtotal,
|
||||
subtotal,
|
||||
taxAmount,
|
||||
payableAmount,
|
||||
paidAmount,
|
||||
remainingAmount: Math.max(0, totalAmount - paidAmount),
|
||||
remainingAmount: Math.max(0, Math.abs(payableAmount) - paidAmount),
|
||||
person: row.person
|
||||
? {
|
||||
id: row.person.id,
|
||||
@@ -639,3 +706,23 @@ function emptyToNull(value?: string | null): string | null {
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length ? trimmed : null;
|
||||
}
|
||||
|
||||
function roundMoney(value: number): number {
|
||||
return Math.round((value + Number.EPSILON) * 100) / 100;
|
||||
}
|
||||
|
||||
function buildDateRangeFilter(
|
||||
from?: string,
|
||||
to?: string,
|
||||
): Prisma.InvoiceWhereInput | null {
|
||||
if (!from && !to) return null;
|
||||
const range: Prisma.DateTimeFilter = {};
|
||||
if (from) range.gte = new Date(from);
|
||||
if (to) range.lte = new Date(to);
|
||||
return {
|
||||
OR: [
|
||||
{ issuedAt: range },
|
||||
{ AND: [{ issuedAt: null }, { createdAt: range }] },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -66,6 +66,28 @@ export class CreateQuoteDto {
|
||||
@MaxLength(4000)
|
||||
notes?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
discountAmount?: number;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
taxPercent?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
issuedAt?: string | null;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
validityDays?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
validUntil?: string | null;
|
||||
@@ -115,6 +137,22 @@ export class UpdateQuoteDto {
|
||||
@MaxLength(4000)
|
||||
notes?: string | null;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
discountAmount?: number;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
taxPercent?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
issuedAt?: string | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
validUntil?: string | null;
|
||||
@@ -155,6 +193,18 @@ export class ListQuotesQueryDto {
|
||||
@IsString()
|
||||
personId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
companyId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
from?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
to?: string;
|
||||
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
|
||||
@@ -35,6 +35,9 @@ export class QuotesController {
|
||||
status: query.status,
|
||||
dealId: query.dealId,
|
||||
personId: query.personId,
|
||||
companyId: query.companyId,
|
||||
from: query.from,
|
||||
to: query.to,
|
||||
page: query.page ?? 1,
|
||||
limit: query.limit ?? 50,
|
||||
});
|
||||
|
||||
@@ -38,18 +38,24 @@ export class QuotesService {
|
||||
status?: string;
|
||||
dealId?: string;
|
||||
personId?: string;
|
||||
companyId?: string;
|
||||
from?: string;
|
||||
to?: string;
|
||||
page?: number;
|
||||
limit?: number;
|
||||
},
|
||||
): Promise<PaginatedResponse<QuoteDto>> {
|
||||
const page = opts.page ?? 1;
|
||||
const limit = opts.limit ?? 50;
|
||||
const dateFilter = buildDateRangeFilter(opts.from, opts.to);
|
||||
const where: Prisma.QuoteWhereInput = {
|
||||
organizationId,
|
||||
...ownerWhere(actor),
|
||||
...(opts.status ? { status: opts.status as never } : {}),
|
||||
...(opts.dealId ? { dealId: opts.dealId } : {}),
|
||||
...(opts.personId ? { personId: opts.personId } : {}),
|
||||
...(opts.companyId ? { companyId: opts.companyId } : {}),
|
||||
...(dateFilter ? dateFilter : {}),
|
||||
...(opts.q?.trim()
|
||||
? {
|
||||
OR: [
|
||||
@@ -137,6 +143,19 @@ export class QuotesService {
|
||||
await this.assertProducts(organizationId, lineItems);
|
||||
}
|
||||
|
||||
const issuedAt = dto.issuedAt ? new Date(dto.issuedAt) : null;
|
||||
let validUntil = dto.validUntil ? new Date(dto.validUntil) : null;
|
||||
if (
|
||||
dto.validityDays != null &&
|
||||
Number.isFinite(dto.validityDays) &&
|
||||
dto.validityDays > 0 &&
|
||||
!validUntil
|
||||
) {
|
||||
const base = issuedAt ?? new Date();
|
||||
validUntil = new Date(base);
|
||||
validUntil.setDate(validUntil.getDate() + Math.floor(dto.validityDays));
|
||||
}
|
||||
|
||||
const number = await this.nextNumber(organizationId);
|
||||
const row = await this.prisma.quote.create({
|
||||
data: {
|
||||
@@ -146,7 +165,10 @@ export class QuotesService {
|
||||
status: (dto.status as never) || 'draft',
|
||||
currency,
|
||||
notes,
|
||||
validUntil: dto.validUntil ? new Date(dto.validUntil) : null,
|
||||
discountAmount: new Prisma.Decimal(dto.discountAmount ?? 0),
|
||||
taxPercent: new Prisma.Decimal(dto.taxPercent ?? 0),
|
||||
issuedAt,
|
||||
validUntil,
|
||||
personId,
|
||||
companyId,
|
||||
dealId,
|
||||
@@ -201,6 +223,15 @@ export class QuotesService {
|
||||
data.currency = dto.currency.trim() || 'IRR';
|
||||
}
|
||||
if ('notes' in dto) data.notes = emptyToNull(dto.notes ?? null);
|
||||
if (dto.discountAmount !== undefined) {
|
||||
data.discountAmount = new Prisma.Decimal(dto.discountAmount);
|
||||
}
|
||||
if (dto.taxPercent !== undefined) {
|
||||
data.taxPercent = new Prisma.Decimal(dto.taxPercent);
|
||||
}
|
||||
if ('issuedAt' in dto) {
|
||||
data.issuedAt = dto.issuedAt ? new Date(dto.issuedAt) : null;
|
||||
}
|
||||
if ('validUntil' in dto) {
|
||||
data.validUntil = dto.validUntil ? new Date(dto.validUntil) : null;
|
||||
}
|
||||
@@ -334,7 +365,13 @@ export class QuotesService {
|
||||
lineTotal: quantity * unitPrice,
|
||||
};
|
||||
});
|
||||
const totalAmount = lineItems.reduce((sum, item) => sum + item.lineTotal, 0);
|
||||
const subtotal = lineItems.reduce((sum, item) => sum + item.lineTotal, 0);
|
||||
const discountAmount = Number(row.discountAmount ?? 0);
|
||||
const taxPercent = Number(row.taxPercent ?? 0);
|
||||
const taxAmount = roundMoney(
|
||||
Math.max(0, subtotal - discountAmount) * (taxPercent / 100),
|
||||
);
|
||||
const payableAmount = roundMoney(subtotal - discountAmount + taxAmount);
|
||||
return {
|
||||
id: row.id,
|
||||
number: row.number,
|
||||
@@ -342,8 +379,14 @@ export class QuotesService {
|
||||
status: row.status,
|
||||
currency: row.currency,
|
||||
notes: row.notes,
|
||||
discountAmount,
|
||||
taxPercent,
|
||||
issuedAt: row.issuedAt?.toISOString() ?? null,
|
||||
validUntil: row.validUntil?.toISOString() ?? null,
|
||||
totalAmount,
|
||||
totalAmount: subtotal,
|
||||
subtotal,
|
||||
taxAmount,
|
||||
payableAmount,
|
||||
person: row.person
|
||||
? {
|
||||
id: row.person.id,
|
||||
@@ -365,3 +408,23 @@ function emptyToNull(value?: string | null): string | null {
|
||||
const trimmed = value.trim();
|
||||
return trimmed.length ? trimmed : null;
|
||||
}
|
||||
|
||||
function roundMoney(value: number): number {
|
||||
return Math.round((value + Number.EPSILON) * 100) / 100;
|
||||
}
|
||||
|
||||
function buildDateRangeFilter(
|
||||
from?: string,
|
||||
to?: string,
|
||||
): Prisma.QuoteWhereInput | null {
|
||||
if (!from && !to) return null;
|
||||
const range: Prisma.DateTimeFilter = {};
|
||||
if (from) range.gte = new Date(from);
|
||||
if (to) range.lte = new Date(to);
|
||||
return {
|
||||
OR: [
|
||||
{ issuedAt: range },
|
||||
{ AND: [{ issuedAt: null }, { createdAt: range }] },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -50,7 +50,10 @@ defineProps<{
|
||||
| 'target'
|
||||
| 'pencil'
|
||||
| 'grid'
|
||||
| 'list';
|
||||
| 'list'
|
||||
| 'eye'
|
||||
| 'truck'
|
||||
| 'grip';
|
||||
size?: number;
|
||||
}>();
|
||||
</script>
|
||||
@@ -289,6 +292,25 @@ defineProps<{
|
||||
<circle cx="4.5" cy="12" r="1" fill="currentColor" stroke="none" />
|
||||
<circle cx="4.5" cy="18" r="1" fill="currentColor" stroke="none" />
|
||||
</template>
|
||||
<template v-else-if="name === 'eye'">
|
||||
<path d="M2.5 12S6.5 5.5 12 5.5 21.5 12 21.5 12 17.5 18.5 12 18.5 2.5 12 2.5 12Z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</template>
|
||||
<template v-else-if="name === 'truck'">
|
||||
<path d="M3 7.5h11V16H3z" />
|
||||
<path d="M14 10h4.2l2.3 3.2V16H14z" />
|
||||
<circle cx="7" cy="17.5" r="1.6" />
|
||||
<circle cx="17" cy="17.5" r="1.6" />
|
||||
<path d="M3 16h1.2M8.7 16H15" />
|
||||
</template>
|
||||
<template v-else-if="name === 'grip'">
|
||||
<circle cx="9" cy="7" r="1.2" fill="currentColor" stroke="none" />
|
||||
<circle cx="15" cy="7" r="1.2" fill="currentColor" stroke="none" />
|
||||
<circle cx="9" cy="12" r="1.2" fill="currentColor" stroke="none" />
|
||||
<circle cx="15" cy="12" r="1.2" fill="currentColor" stroke="none" />
|
||||
<circle cx="9" cy="17" r="1.2" fill="currentColor" stroke="none" />
|
||||
<circle cx="15" cy="17" r="1.2" fill="currentColor" stroke="none" />
|
||||
</template>
|
||||
</svg>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -283,8 +283,11 @@ onUnmounted(() => {
|
||||
<span class="chev" aria-hidden="true" />
|
||||
</button>
|
||||
<div v-show="salesOpen" class="nav-sub">
|
||||
<RouterLink to="/quotes" @click="closeMenu">پیشفاکتورها</RouterLink>
|
||||
<RouterLink to="/invoices" @click="closeMenu">فاکتورها</RouterLink>
|
||||
<RouterLink
|
||||
to="/invoices"
|
||||
:class="{ 'router-link-active': route.path.startsWith('/invoices') || route.path.startsWith('/quotes') }"
|
||||
@click="closeMenu"
|
||||
>فاکتورها</RouterLink>
|
||||
<RouterLink to="/sales/forecast" @click="closeMenu">هدف و پیشبینی</RouterLink>
|
||||
<RouterLink to="/notes" @click="closeMenu">یادداشتها</RouterLink>
|
||||
<RouterLink to="/tickets" @click="closeMenu">تیکتها</RouterLink>
|
||||
|
||||
+1965
-422
File diff suppressed because it is too large
Load Diff
+780
-491
File diff suppressed because it is too large
Load Diff
@@ -1,511 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import { api } from '@/lib/api';
|
||||
import { formatMoney as formatMoneyLib } from '@/lib/money';
|
||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||
import MoneyInput from '@/components/MoneyInput.vue';
|
||||
import type {
|
||||
CompanyDto,
|
||||
CreateQuoteRequest,
|
||||
DealLineItemInput,
|
||||
OrganizationDto,
|
||||
PaginatedResponse,
|
||||
PersonDto,
|
||||
ProductDto,
|
||||
QuoteDto,
|
||||
QuoteStatus,
|
||||
} from '@mento/shared';
|
||||
|
||||
type LineDraft = {
|
||||
key: string;
|
||||
productId: string;
|
||||
name: string;
|
||||
quantity: string;
|
||||
unitPrice: string;
|
||||
};
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const id = computed(() =>
|
||||
typeof route.params.id === 'string' ? route.params.id : '',
|
||||
);
|
||||
const isNew = computed(() => route.name === 'quote-new');
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const error = ref('');
|
||||
const number = ref('');
|
||||
const title = ref('پیشفاکتور');
|
||||
const status = ref<QuoteStatus>('draft');
|
||||
const notes = ref('');
|
||||
const validUntil = ref('');
|
||||
const currency = ref('IRR');
|
||||
const enabledCurrencies = ref<string[]>(['IRR']);
|
||||
const personId = ref('');
|
||||
const companyId = ref('');
|
||||
const dealId = ref('');
|
||||
const people = ref<PersonDto[]>([]);
|
||||
const companies = ref<CompanyDto[]>([]);
|
||||
const products = ref<ProductDto[]>([]);
|
||||
const lines = ref<LineDraft[]>([]);
|
||||
|
||||
const statusLabel: Record<QuoteStatus, string> = {
|
||||
draft: 'پیشنویس',
|
||||
sent: 'ارسالشده',
|
||||
accepted: 'تأییدشده',
|
||||
rejected: 'ردشده',
|
||||
expired: 'منقضی',
|
||||
};
|
||||
|
||||
const totalAmount = computed(() =>
|
||||
toLineInputs().reduce((sum, l) => sum + l.quantity * l.unitPrice, 0),
|
||||
);
|
||||
|
||||
function formatMoney(amount: number) {
|
||||
return formatMoneyLib(amount, currency.value);
|
||||
}
|
||||
|
||||
function newLine(): LineDraft {
|
||||
return {
|
||||
key: `${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
|
||||
productId: '',
|
||||
name: '',
|
||||
quantity: '1',
|
||||
unitPrice: '',
|
||||
};
|
||||
}
|
||||
|
||||
function addLine() {
|
||||
lines.value.push(newLine());
|
||||
}
|
||||
|
||||
function removeLine(key: string) {
|
||||
lines.value = lines.value.filter((l) => l.key !== key);
|
||||
}
|
||||
|
||||
function onPickProduct(line: LineDraft) {
|
||||
const product = products.value.find((p) => p.id === line.productId);
|
||||
if (!product) return;
|
||||
line.name = product.name;
|
||||
if (product.unitPrice != null) line.unitPrice = String(product.unitPrice);
|
||||
}
|
||||
|
||||
function toLineInputs(): DealLineItemInput[] {
|
||||
return lines.value
|
||||
.filter((l) => l.name.trim() && l.quantity !== '' && l.unitPrice !== '')
|
||||
.map((l) => ({
|
||||
productId: l.productId || null,
|
||||
name: l.name.trim(),
|
||||
quantity: Number(l.quantity),
|
||||
unitPrice: Number(l.unitPrice),
|
||||
currency: currency.value || 'IRR',
|
||||
}));
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const fromDealId =
|
||||
typeof route.query.fromDealId === 'string'
|
||||
? route.query.fromDealId
|
||||
: typeof route.query.dealId === 'string'
|
||||
? route.query.dealId
|
||||
: '';
|
||||
|
||||
const [peopleRes, companiesRes, productsRes, orgRes] = await Promise.all([
|
||||
api.get<PaginatedResponse<PersonDto>>('/people', { params: { limit: 100 } }),
|
||||
api.get<PaginatedResponse<CompanyDto>>('/companies', { params: { limit: 100 } }),
|
||||
api.get<ProductDto[]>('/products', { params: { activeOnly: true } }),
|
||||
api.get<OrganizationDto>('/organizations/current'),
|
||||
]);
|
||||
people.value = peopleRes.data.items;
|
||||
companies.value = companiesRes.data.items;
|
||||
products.value = productsRes.data;
|
||||
enabledCurrencies.value = orgRes.data.enabledCurrencies?.length
|
||||
? orgRes.data.enabledCurrencies
|
||||
: [orgRes.data.baseCurrency || 'IRR'];
|
||||
currency.value = orgRes.data.baseCurrency || 'IRR';
|
||||
|
||||
if (!isNew.value && id.value) {
|
||||
const { data } = await api.get<QuoteDto>(`/quotes/${id.value}`);
|
||||
number.value = data.number;
|
||||
title.value = data.title;
|
||||
status.value = data.status as QuoteStatus;
|
||||
notes.value = data.notes ?? '';
|
||||
currency.value = data.currency || currency.value;
|
||||
validUntil.value = data.validUntil ? data.validUntil.slice(0, 10) : '';
|
||||
personId.value = data.person?.id ?? '';
|
||||
companyId.value = data.company?.id ?? '';
|
||||
dealId.value = data.deal?.id ?? '';
|
||||
lines.value = (data.lineItems ?? []).map((item) => ({
|
||||
key: item.id,
|
||||
productId: item.productId ?? '',
|
||||
name: item.name,
|
||||
quantity: String(item.quantity),
|
||||
unitPrice: String(item.unitPrice),
|
||||
}));
|
||||
} else if (fromDealId) {
|
||||
dealId.value = fromDealId;
|
||||
title.value = 'پیشفاکتور';
|
||||
} else {
|
||||
if (typeof route.query.personId === 'string' && route.query.personId) {
|
||||
personId.value = route.query.personId;
|
||||
const person = people.value.find((p) => p.id === personId.value);
|
||||
if (person?.company?.id) companyId.value = person.company.id;
|
||||
}
|
||||
if (!lines.value.length) {
|
||||
lines.value = [newLine()];
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
error.value = 'بارگذاری فرم پیشفاکتور ناموفق بود.';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function payload(): CreateQuoteRequest {
|
||||
const fromDealId =
|
||||
isNew.value && typeof route.query.fromDealId === 'string'
|
||||
? route.query.fromDealId
|
||||
: undefined;
|
||||
return {
|
||||
title: title.value.trim(),
|
||||
status: status.value,
|
||||
notes: notes.value || undefined,
|
||||
validUntil: validUntil.value ? new Date(validUntil.value).toISOString() : null,
|
||||
personId: personId.value || null,
|
||||
companyId: companyId.value || null,
|
||||
dealId: dealId.value || null,
|
||||
fromDealId: fromDealId || null,
|
||||
lineItems: toLineInputs(),
|
||||
currency: currency.value || 'IRR',
|
||||
};
|
||||
}
|
||||
|
||||
async function save() {
|
||||
if (!title.value.trim()) {
|
||||
error.value = 'عنوان را وارد کنید.';
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
if (isNew.value) {
|
||||
const { data } = await api.post<QuoteDto>('/quotes', payload());
|
||||
await router.replace({ name: 'quote-detail', params: { id: data.id } });
|
||||
} else {
|
||||
await api.patch(`/quotes/${id.value}`, payload());
|
||||
await load();
|
||||
}
|
||||
} catch (e) {
|
||||
if (axios.isAxiosError(e)) {
|
||||
const msg = (e.response?.data as { message?: string | string[] })?.message;
|
||||
error.value = Array.isArray(msg) ? msg.join('، ') : (msg ?? 'ذخیره ناموفق بود');
|
||||
} else {
|
||||
error.value = 'ذخیره ناموفق بود';
|
||||
}
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function remove() {
|
||||
if (!id.value || !confirm('این پیشفاکتور حذف شود؟')) return;
|
||||
await api.delete(`/quotes/${id.value}`);
|
||||
await router.push({ name: 'quotes' });
|
||||
}
|
||||
|
||||
function printQuote() {
|
||||
window.print();
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
import InvoiceFormView from './InvoiceFormView.vue';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page">
|
||||
<header class="page-head no-print">
|
||||
<div class="head-copy">
|
||||
<p class="crumb">
|
||||
<RouterLink :to="{ name: 'quotes' }">پیشفاکتورها</RouterLink>
|
||||
<span>›</span>
|
||||
<strong>{{ isNew ? 'پیشفاکتور جدید' : number || 'پیشفاکتور' }}</strong>
|
||||
</p>
|
||||
<h1>{{ isNew ? 'پیشفاکتور جدید' : number || 'پیشفاکتور' }}</h1>
|
||||
</div>
|
||||
<div class="head-actions">
|
||||
<button v-if="!isNew" class="btn ghost" type="button" @click="printQuote">چاپ</button>
|
||||
<RouterLink
|
||||
v-if="!isNew && id"
|
||||
class="btn ghost"
|
||||
:to="{ name: 'invoice-new', query: { fromQuoteId: id } }"
|
||||
>
|
||||
صدور فاکتور
|
||||
</RouterLink>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<p v-if="loading" class="muted">در حال بارگذاری…</p>
|
||||
|
||||
<form v-else class="form" @submit.prevent="save">
|
||||
<div class="print-banner">
|
||||
<strong>منتو</strong>
|
||||
<span v-if="number">{{ number }}</span>
|
||||
</div>
|
||||
|
||||
<div class="grid">
|
||||
<div class="field wide">
|
||||
<label>عنوان</label>
|
||||
<input v-model="title" required maxlength="200" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>وضعیت</label>
|
||||
<select v-model="status">
|
||||
<option v-for="(label, key) in statusLabel" :key="key" :value="key">{{ label }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>اعتبار تا</label>
|
||||
<JalaliDateInput v-model="validUntil" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>ارز</label>
|
||||
<select v-model="currency">
|
||||
<option v-for="code in enabledCurrencies" :key="code" :value="code">
|
||||
{{ code }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>شخص</label>
|
||||
<select v-model="personId">
|
||||
<option value="">بدون شخص</option>
|
||||
<option v-for="p in people" :key="p.id" :value="p.id">{{ p.fullName }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>شرکت</label>
|
||||
<select v-model="companyId">
|
||||
<option value="">بدون شرکت</option>
|
||||
<option v-for="c in companies" :key="c.id" :value="c.id">{{ c.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field wide">
|
||||
<label>یادداشت</label>
|
||||
<textarea v-model="notes" rows="3" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="lines-block">
|
||||
<div class="lines-head">
|
||||
<h3>ردیفهای پیشفاکتور</h3>
|
||||
<button class="btn btn-ghost no-print" type="button" @click="addLine">افزودن ردیف</button>
|
||||
</div>
|
||||
<div v-for="line in lines" :key="line.key" class="line-row">
|
||||
<select v-model="line.productId" class="no-print" @change="onPickProduct(line)">
|
||||
<option value="">محصول از کاتالوگ…</option>
|
||||
<option v-for="p in products" :key="p.id" :value="p.id">{{ p.name }}</option>
|
||||
</select>
|
||||
<input v-model="line.name" placeholder="نام ردیف" required />
|
||||
<input v-model="line.quantity" type="number" min="0.01" step="0.01" placeholder="تعداد" />
|
||||
<MoneyInput v-model="line.unitPrice" :decimals="0" placeholder="قیمت واحد" />
|
||||
<button class="btn btn-ghost no-print" type="button" @click="removeLine(line.key)">حذف</button>
|
||||
</div>
|
||||
<p class="total"><strong>جمع:</strong> {{ formatMoney(totalAmount) }}</p>
|
||||
</div>
|
||||
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<div class="form-actions no-print">
|
||||
<button class="btn" type="submit" :disabled="saving">
|
||||
{{ saving ? 'در حال ذخیره…' : 'ذخیره' }}
|
||||
</button>
|
||||
<button
|
||||
v-if="!isNew"
|
||||
class="btn btn-danger"
|
||||
type="button"
|
||||
:disabled="saving"
|
||||
@click="remove"
|
||||
>
|
||||
حذف
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<InvoiceFormView />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
max-width: 860px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.page-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.head-copy {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.crumb {
|
||||
margin: 0 0 0.25rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
color: #94a3b8;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
|
||||
.crumb a {
|
||||
color: #0f766e;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.head-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: clamp(1.25rem, 2.5vw, 1.55rem);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.btn.ghost {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
background: #fff;
|
||||
color: #0f766e;
|
||||
border: 1px solid #99f6e4;
|
||||
border-radius: 12px;
|
||||
min-height: 42px;
|
||||
padding: 0.55rem 1rem;
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.form,
|
||||
.lines-block {
|
||||
display: grid;
|
||||
gap: 0.85rem;
|
||||
background: #fff;
|
||||
border-radius: 18px;
|
||||
padding: 1rem;
|
||||
box-shadow: 0 8px 22px rgba(15, 23, 42, 0.04);
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.field.wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
label {
|
||||
color: var(--muted);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
input,
|
||||
select,
|
||||
textarea {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
padding: 0.7rem 0.85rem;
|
||||
font: inherit;
|
||||
background: #fff;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.lines-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.lines-head h3 {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.line-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1.2fr 1.4fr 0.7fr 0.9fr auto;
|
||||
gap: 0.45rem;
|
||||
}
|
||||
|
||||
.total {
|
||||
margin: 0;
|
||||
text-align: start;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
display: flex;
|
||||
gap: 0.6rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #b42318;
|
||||
}
|
||||
|
||||
.print-banner {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.grid,
|
||||
.line-row {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media print {
|
||||
.no-print {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.print-banner {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
border-bottom: 1px solid #ccc;
|
||||
padding-bottom: 0.5rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.page {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
input,
|
||||
select,
|
||||
textarea {
|
||||
border: 0;
|
||||
padding: 0.2rem 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,580 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import { api } from '@/lib/api';
|
||||
import { formatMoney } from '@/lib/money';
|
||||
import { toFaDigits } from '@/lib/jalali';
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
import type { PaginatedResponse, QuoteDto, QuoteStatus } from '@mento/shared';
|
||||
import { onMounted } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
const data = ref<PaginatedResponse<QuoteDto> | null>(null);
|
||||
const q = ref(typeof route.query.q === 'string' ? route.query.q : '');
|
||||
const status = ref<QuoteStatus | 'all'>(
|
||||
typeof route.query.status === 'string' &&
|
||||
['draft', 'sent', 'accepted', 'rejected', 'expired'].includes(route.query.status)
|
||||
? (route.query.status as QuoteStatus)
|
||||
: 'all',
|
||||
);
|
||||
const filterOpen = ref(false);
|
||||
|
||||
const statusLabel: Record<QuoteStatus, string> = {
|
||||
draft: 'پیشنویس',
|
||||
sent: 'ارسالشده',
|
||||
accepted: 'تأییدشده',
|
||||
rejected: 'ردشده',
|
||||
expired: 'منقضی',
|
||||
};
|
||||
|
||||
const items = computed(() => data.value?.items ?? []);
|
||||
const listEmpty = computed(() => !loading.value && !items.value.length);
|
||||
const statusFilterLabel = computed(() =>
|
||||
status.value === 'all' ? 'همه وضعیتها' : statusLabel[status.value],
|
||||
);
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
filterOpen.value = false;
|
||||
try {
|
||||
const { data: res } = await api.get<PaginatedResponse<QuoteDto>>('/quotes', {
|
||||
params: {
|
||||
q: q.value || undefined,
|
||||
status: status.value === 'all' ? undefined : status.value,
|
||||
dealId: typeof route.query.dealId === 'string' ? route.query.dealId : undefined,
|
||||
limit: 50,
|
||||
},
|
||||
});
|
||||
data.value = res;
|
||||
} catch (e) {
|
||||
if (axios.isAxiosError(e) && !e.response) {
|
||||
error.value = 'اتصال به API برقرار نشد.';
|
||||
} else {
|
||||
error.value = 'بارگذاری پیشفاکتورها ناموفق بود.';
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onSearch() {
|
||||
onMounted(() => {
|
||||
void router.replace({
|
||||
name: 'quotes',
|
||||
query: {
|
||||
...route.query,
|
||||
q: q.value.trim() || undefined,
|
||||
status: status.value === 'all' ? undefined : status.value,
|
||||
},
|
||||
name: 'invoices',
|
||||
query: { ...route.query, doc: 'quote' },
|
||||
});
|
||||
}
|
||||
|
||||
function setStatus(next: QuoteStatus | 'all') {
|
||||
status.value = next;
|
||||
filterOpen.value = false;
|
||||
onSearch();
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [route.query.q, route.query.status, route.query.dealId],
|
||||
() => {
|
||||
q.value = typeof route.query.q === 'string' ? route.query.q : '';
|
||||
status.value =
|
||||
typeof route.query.status === 'string' &&
|
||||
['draft', 'sent', 'accepted', 'rejected', 'expired'].includes(route.query.status)
|
||||
? (route.query.status as QuoteStatus)
|
||||
: 'all';
|
||||
void load();
|
||||
},
|
||||
);
|
||||
|
||||
onMounted(load);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page" @click="filterOpen = false">
|
||||
<header class="page-head">
|
||||
<div class="head-copy">
|
||||
<h1>پیشفاکتورها</h1>
|
||||
<p class="lead">از روی معامله یا جداگانه پیشفاکتور بسازید و وضعیت را پیگیری کنید.</p>
|
||||
</div>
|
||||
<RouterLink class="add-btn" :to="{ name: 'quote-new', query: route.query }" aria-label="پیشفاکتور جدید">
|
||||
<span>+</span>
|
||||
</RouterLink>
|
||||
</header>
|
||||
|
||||
<div class="tools">
|
||||
<form class="search" @submit.prevent="onSearch">
|
||||
<UiIcon name="search" :size="18" />
|
||||
<input v-model="q" type="search" placeholder="جستجو در عنوان یا شماره…" />
|
||||
</form>
|
||||
<div class="filter-wrap" @click.stop>
|
||||
<button class="btn ghost filter-btn" type="button" @click="filterOpen = !filterOpen">
|
||||
<UiIcon name="filter" :size="16" />
|
||||
<span class="btn-full">{{ statusFilterLabel }}</span>
|
||||
<span class="btn-short">وضعیت</span>
|
||||
<UiIcon name="chevron" :size="14" class="chev" />
|
||||
</button>
|
||||
<div v-if="filterOpen" class="popover">
|
||||
<button type="button" :class="{ on: status === 'all' }" @click="setStatus('all')">
|
||||
همه وضعیتها
|
||||
</button>
|
||||
<button
|
||||
v-for="(label, key) in statusLabel"
|
||||
:key="key"
|
||||
type="button"
|
||||
:class="{ on: status === key }"
|
||||
@click="setStatus(key as QuoteStatus)"
|
||||
>
|
||||
{{ label }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<p v-else-if="loading" class="muted">در حال بارگذاری…</p>
|
||||
|
||||
<div v-else-if="listEmpty" class="empty-card">
|
||||
<div class="art" aria-hidden="true">
|
||||
<svg viewBox="0 0 168 148" fill="none">
|
||||
<rect x="38" y="18" width="92" height="112" rx="16" fill="#E7F6F3" />
|
||||
<rect x="50" y="32" width="68" height="84" rx="10" fill="#fff" />
|
||||
<path d="M62 52h28" stroke="#14b8a6" stroke-width="4" stroke-linecap="round" />
|
||||
<path d="M62 68h36" stroke="#99f6e4" stroke-width="4" stroke-linecap="round" />
|
||||
<path d="M62 84h22" stroke="#99f6e4" stroke-width="4" stroke-linecap="round" />
|
||||
<circle cx="118" cy="112" r="20" fill="#14b8a6" />
|
||||
<path d="M118 104v16M110 112h16" stroke="#fff" stroke-width="3" stroke-linecap="round" />
|
||||
</svg>
|
||||
</div>
|
||||
<h2>هنوز پیشفاکتوری نیست</h2>
|
||||
<p>اولین پیشفاکتور را بسازید تا پیشنهادهای قیمت اینجا جمع شوند.</p>
|
||||
<RouterLink class="btn primary wide" :to="{ name: 'quote-new', query: route.query }">
|
||||
<span>+</span>
|
||||
پیشفاکتور جدید
|
||||
</RouterLink>
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="list-head">
|
||||
<strong>{{ toFaDigits(items.length) }} پیشفاکتور</strong>
|
||||
</div>
|
||||
|
||||
<div class="table-wrap desktop-only">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>عنوان</th>
|
||||
<th>شماره</th>
|
||||
<th>وضعیت</th>
|
||||
<th>مشتری / معامله</th>
|
||||
<th>مبلغ</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="quote in items" :key="quote.id">
|
||||
<td>
|
||||
<RouterLink class="title" :to="{ name: 'quote-detail', params: { id: quote.id } }">
|
||||
{{ quote.title }}
|
||||
</RouterLink>
|
||||
</td>
|
||||
<td class="muted">{{ quote.number }}</td>
|
||||
<td>
|
||||
<span class="badge" :class="quote.status">
|
||||
{{ statusLabel[quote.status as QuoteStatus] || quote.status }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="muted">
|
||||
<span v-if="quote.person">{{ quote.person.fullName }}</span>
|
||||
<span v-if="quote.person && quote.deal"> · </span>
|
||||
<span v-if="quote.deal">{{ quote.deal.title }}</span>
|
||||
<span v-if="!quote.person && !quote.deal">—</span>
|
||||
</td>
|
||||
<td>
|
||||
<strong>{{ formatMoney(quote.totalAmount, quote.currency) }}</strong>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="cards mobile-only">
|
||||
<RouterLink
|
||||
v-for="quote in items"
|
||||
:key="quote.id"
|
||||
class="m-card"
|
||||
:to="{ name: 'quote-detail', params: { id: quote.id } }"
|
||||
>
|
||||
<div class="m-top">
|
||||
<strong>{{ quote.title }}</strong>
|
||||
<span class="badge" :class="quote.status">
|
||||
{{ statusLabel[quote.status as QuoteStatus] || quote.status }}
|
||||
</span>
|
||||
</div>
|
||||
<p class="muted">{{ quote.number }}</p>
|
||||
<p v-if="quote.person || quote.deal" class="meta">
|
||||
<span v-if="quote.person">{{ quote.person.fullName }}</span>
|
||||
<span v-if="quote.deal"> · {{ quote.deal.title }}</span>
|
||||
</p>
|
||||
<div class="m-foot">
|
||||
<strong>{{ formatMoney(quote.totalAmount, quote.currency) }}</strong>
|
||||
</div>
|
||||
</RouterLink>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
<p class="muted">در حال انتقال به فاکتورها…</p>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
min-width: 0;
|
||||
overflow-x: clip;
|
||||
}
|
||||
|
||||
.page-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.head-copy {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0 0 0.3rem;
|
||||
font-size: clamp(1.45rem, 2.5vw, 1.85rem);
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.lead,
|
||||
.muted,
|
||||
.error,
|
||||
.meta {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.lead,
|
||||
.muted,
|
||||
.meta {
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #b91c1c;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 999px;
|
||||
background: #14b8a6;
|
||||
color: #fff;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
text-decoration: none;
|
||||
font-size: 1.6rem;
|
||||
font-weight: 700;
|
||||
box-shadow: 0 8px 18px rgba(20, 184, 166, 0.28);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.tools {
|
||||
display: flex;
|
||||
gap: 0.55rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.search {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
background: #fff;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 12px;
|
||||
padding: 0 0.85rem;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.search input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
padding: 0.75rem 0;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.filter-wrap {
|
||||
position: relative;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.35rem;
|
||||
min-height: 42px;
|
||||
padding: 0.55rem 1rem;
|
||||
border-radius: 12px;
|
||||
font-weight: 700;
|
||||
border: 1px solid transparent;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.btn.primary {
|
||||
background: #14b8a6;
|
||||
color: #fff;
|
||||
box-shadow: 0 8px 18px rgba(20, 184, 166, 0.24);
|
||||
}
|
||||
|
||||
.btn.ghost {
|
||||
background: #fff;
|
||||
color: #0f766e;
|
||||
border-color: #99f6e4;
|
||||
}
|
||||
|
||||
.btn.wide {
|
||||
width: min(100%, 320px);
|
||||
}
|
||||
|
||||
.filter-btn .chev {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.btn-short {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.popover {
|
||||
position: absolute;
|
||||
top: calc(100% + 6px);
|
||||
inset-inline-end: 0;
|
||||
min-width: 11rem;
|
||||
background: #fff;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
|
||||
padding: 0.35rem;
|
||||
display: grid;
|
||||
z-index: 8;
|
||||
}
|
||||
|
||||
.popover button {
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-align: start;
|
||||
border: 0;
|
||||
background: none;
|
||||
padding: 0.6rem 0.7rem;
|
||||
border-radius: 8px;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
color: #0f172a;
|
||||
}
|
||||
|
||||
.popover button:hover,
|
||||
.popover button.on {
|
||||
background: #f0fdfa;
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.empty-card {
|
||||
background: #fff;
|
||||
border-radius: 22px;
|
||||
box-shadow: 0 10px 28px rgba(15, 23, 42, 0.05);
|
||||
padding: 2.4rem 1.2rem 2rem;
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
text-align: center;
|
||||
gap: 0.7rem;
|
||||
}
|
||||
|
||||
.art svg {
|
||||
width: 148px;
|
||||
height: auto;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.empty-card h2 {
|
||||
margin: 0.2rem 0 0;
|
||||
font-size: 1.15rem;
|
||||
}
|
||||
|
||||
.empty-card > p {
|
||||
max-width: 22rem;
|
||||
color: #94a3b8;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.list-head {
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.table-wrap {
|
||||
background: #fff;
|
||||
border-radius: 18px;
|
||||
box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.data-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
min-width: 640px;
|
||||
}
|
||||
|
||||
.data-table th,
|
||||
.data-table td {
|
||||
padding: 0.9rem 1rem;
|
||||
text-align: start;
|
||||
border-bottom: 1px solid #f1f5f9;
|
||||
}
|
||||
|
||||
.data-table th {
|
||||
font-size: 0.78rem;
|
||||
color: #94a3b8;
|
||||
font-weight: 700;
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.title {
|
||||
color: #0f172a;
|
||||
font-weight: 700;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.title:hover {
|
||||
color: #0f766e;
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 0.25rem 0.55rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
background: #f1f5f9;
|
||||
color: #475569;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.badge.draft {
|
||||
background: #f1f5f9;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.badge.sent {
|
||||
background: #ecfeff;
|
||||
color: #0e7490;
|
||||
}
|
||||
|
||||
.badge.accepted {
|
||||
background: #ecfdf5;
|
||||
color: #047857;
|
||||
}
|
||||
|
||||
.badge.rejected {
|
||||
background: #fef2f2;
|
||||
color: #b91c1c;
|
||||
}
|
||||
|
||||
.badge.expired {
|
||||
background: #fff7ed;
|
||||
color: #c2410c;
|
||||
}
|
||||
|
||||
.desktop-only {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.mobile-only {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cards {
|
||||
display: grid;
|
||||
gap: 0.65rem;
|
||||
}
|
||||
|
||||
.m-card {
|
||||
background: #fff;
|
||||
border-radius: 16px;
|
||||
padding: 0.95rem 1rem;
|
||||
box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.m-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 0.6rem;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.m-top strong {
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.m-foot {
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.page-head {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.tools {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.search {
|
||||
flex: 1 1 100%;
|
||||
}
|
||||
|
||||
.btn-full {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.btn-short {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.desktop-only {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mobile-only {
|
||||
display: grid;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.add-btn {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
}
|
||||
|
||||
.m-card {
|
||||
padding: 0.85rem;
|
||||
}
|
||||
.muted {
|
||||
color: var(--muted);
|
||||
padding: 1rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -916,8 +916,14 @@ export interface QuoteDto {
|
||||
status: QuoteStatus | string;
|
||||
currency: string;
|
||||
notes: string | null;
|
||||
discountAmount?: number;
|
||||
taxPercent?: number;
|
||||
issuedAt?: string | null;
|
||||
validUntil: string | null;
|
||||
totalAmount: number;
|
||||
subtotal: number;
|
||||
taxAmount: number;
|
||||
payableAmount: number;
|
||||
person: PersonSummaryDto | null;
|
||||
company: CompanySummaryDto | null;
|
||||
deal: DealSummaryDto | null;
|
||||
@@ -932,6 +938,10 @@ export interface CreateQuoteRequest {
|
||||
status?: QuoteStatus | string;
|
||||
currency?: string;
|
||||
notes?: string;
|
||||
discountAmount?: number;
|
||||
taxPercent?: number;
|
||||
issuedAt?: string | null;
|
||||
validityDays?: number;
|
||||
validUntil?: string | null;
|
||||
personId?: string | null;
|
||||
companyId?: string | null;
|
||||
@@ -945,6 +955,9 @@ export interface UpdateQuoteRequest {
|
||||
status?: QuoteStatus | string;
|
||||
currency?: string;
|
||||
notes?: string | null;
|
||||
discountAmount?: number;
|
||||
taxPercent?: number;
|
||||
issuedAt?: string | null;
|
||||
validUntil?: string | null;
|
||||
personId?: string | null;
|
||||
companyId?: string | null;
|
||||
@@ -1006,11 +1019,17 @@ export interface InvoiceDto {
|
||||
number: string;
|
||||
title: string;
|
||||
status: InvoiceStatus | string;
|
||||
kind?: "invoice" | "credit";
|
||||
currency: string;
|
||||
notes: string | null;
|
||||
discountAmount?: number;
|
||||
taxPercent?: number;
|
||||
issuedAt: string | null;
|
||||
dueDate: string | null;
|
||||
totalAmount: number;
|
||||
subtotal: number;
|
||||
taxAmount: number;
|
||||
payableAmount: number;
|
||||
paidAmount: number;
|
||||
remainingAmount: number;
|
||||
person: PersonSummaryDto | null;
|
||||
@@ -1034,8 +1053,11 @@ export interface InvoiceInstallmentInput {
|
||||
export interface CreateInvoiceRequest {
|
||||
title: string;
|
||||
status?: InvoiceStatus | string;
|
||||
kind?: "invoice" | "credit";
|
||||
currency?: string;
|
||||
notes?: string;
|
||||
discountAmount?: number;
|
||||
taxPercent?: number;
|
||||
issuedAt?: string | null;
|
||||
dueDate?: string | null;
|
||||
personId?: string | null;
|
||||
@@ -1051,8 +1073,11 @@ export interface CreateInvoiceRequest {
|
||||
export interface UpdateInvoiceRequest {
|
||||
title?: string;
|
||||
status?: InvoiceStatus | string;
|
||||
kind?: "invoice" | "credit";
|
||||
currency?: string;
|
||||
notes?: string | null;
|
||||
discountAmount?: number;
|
||||
taxPercent?: number;
|
||||
issuedAt?: string | null;
|
||||
dueDate?: string | null;
|
||||
personId?: string | null;
|
||||
|
||||
Reference in New Issue
Block a user