update invoice detail
This commit is contained in:
@@ -13,6 +13,7 @@ import type { InvoiceItem as ApiInvoiceItem } from './types/InvoiceTypes'
|
|||||||
import { Paths } from '@/config/Paths'
|
import { Paths } from '@/config/Paths'
|
||||||
import { useGetPaymentInvoice } from '../payment/hooks/usePaymentData'
|
import { useGetPaymentInvoice } from '../payment/hooks/usePaymentData'
|
||||||
import InvoicePaymentList from './InvoicePaymentList'
|
import InvoicePaymentList from './InvoicePaymentList'
|
||||||
|
import { formatItemDiscountDisplay } from './utils/invoiceItem'
|
||||||
|
|
||||||
interface TableInvoiceItem extends RowDataType {
|
interface TableInvoiceItem extends RowDataType {
|
||||||
id: string
|
id: string
|
||||||
@@ -20,7 +21,8 @@ interface TableInvoiceItem extends RowDataType {
|
|||||||
title: string
|
title: string
|
||||||
quantity: string
|
quantity: string
|
||||||
unitPrice: string
|
unitPrice: string
|
||||||
discount: string
|
discountValue: string
|
||||||
|
discountPercent: string
|
||||||
totalPrice: string
|
totalPrice: string
|
||||||
confirmed: boolean
|
confirmed: boolean
|
||||||
confirmedAt: string | null
|
confirmedAt: string | null
|
||||||
@@ -57,17 +59,20 @@ const InvoiceDetail: FC = () => {
|
|||||||
: null
|
: null
|
||||||
|
|
||||||
const items: TableInvoiceItem[] =
|
const items: TableInvoiceItem[] =
|
||||||
invoice?.items?.map((item: ApiInvoiceItem) => ({
|
invoice?.items?.map((item: ApiInvoiceItem) => {
|
||||||
|
const discounts = formatItemDiscountDisplay(item)
|
||||||
|
return {
|
||||||
id: item.id,
|
id: item.id,
|
||||||
image: item.product?.images?.[0] ?? null,
|
image: item.product?.images?.[0] ?? null,
|
||||||
title: item.product?.title || '-',
|
title: item.product?.title || '-',
|
||||||
quantity: String(item.quantity),
|
quantity: String(item.quantity),
|
||||||
unitPrice: formatPrice(item.unitPrice),
|
unitPrice: formatPrice(item.unitPrice),
|
||||||
discount: item.discount ? `${NumberFormat(item.discount)}٪` : '۰',
|
discountValue: discounts.value,
|
||||||
|
discountPercent: discounts.percent,
|
||||||
totalPrice: formatPrice(item.total ?? 0),
|
totalPrice: formatPrice(item.total ?? 0),
|
||||||
confirmed: !!item.confirmedAt,
|
confirmed: !!item.confirmedAt,
|
||||||
confirmedAt: item.confirmedAt,
|
confirmedAt: item.confirmedAt,
|
||||||
})) ?? []
|
}}) ?? []
|
||||||
|
|
||||||
const handlePrint = () => {
|
const handlePrint = () => {
|
||||||
window.print()
|
window.print()
|
||||||
@@ -97,8 +102,12 @@ const InvoiceDetail: FC = () => {
|
|||||||
title: 'مبلغ واحد',
|
title: 'مبلغ واحد',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'discount',
|
key: 'discountValue',
|
||||||
title: 'تخفیف',
|
title: 'تخفیف (مبلغ)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'discountPercent',
|
||||||
|
title: 'تخفیف (درصد)',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'totalPrice',
|
key: 'totalPrice',
|
||||||
@@ -253,10 +262,10 @@ const InvoiceDetail: FC = () => {
|
|||||||
<span className='text-[#8C90A3]'>جمع کل:</span>
|
<span className='text-[#8C90A3]'>جمع کل:</span>
|
||||||
<span className='text-black font-medium'>{formatPrice(invoice.subTotal)}</span>
|
<span className='text-black font-medium'>{formatPrice(invoice.subTotal)}</span>
|
||||||
</div>
|
</div>
|
||||||
{invoice.discount > 0 && (
|
{(invoice.discount ?? 0) > 0 && (
|
||||||
<div className='flex justify-between text-xs'>
|
<div className='flex justify-between text-xs'>
|
||||||
<span className='text-[#8C90A3]'>تخفیف:</span>
|
<span className='text-[#8C90A3]'>تخفیف:</span>
|
||||||
<span className='text-black'>{formatPrice(invoice.discount)}</span>
|
<span className='text-black'>{formatPrice(invoice.discount ?? 0)}</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{invoice.enableTax && invoice.taxAmount > 0 && (
|
{invoice.enableTax && invoice.taxAmount > 0 && (
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ export type InvoiceItem = {
|
|||||||
quantity: number;
|
quantity: number;
|
||||||
unitPrice: number;
|
unitPrice: number;
|
||||||
subTotal: number | null;
|
subTotal: number | null;
|
||||||
discount: number;
|
discount: number | null;
|
||||||
|
discountPercent: number | null;
|
||||||
total: number | null;
|
total: number | null;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
confirmedAt: string | null;
|
confirmedAt: string | null;
|
||||||
@@ -58,7 +59,7 @@ export type Invoice = {
|
|||||||
user: InvoiceUser;
|
user: InvoiceUser;
|
||||||
request: InvoiceRequest;
|
request: InvoiceRequest;
|
||||||
invoiceNumber: number;
|
invoiceNumber: number;
|
||||||
discount: number;
|
discount: number | null;
|
||||||
subTotal: number;
|
subTotal: number;
|
||||||
taxAmount: number;
|
taxAmount: number;
|
||||||
total: number;
|
total: number;
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { NumberFormat } from '@/config/func';
|
||||||
|
import type { InvoiceItem } from '../types/InvoiceTypes';
|
||||||
|
|
||||||
|
export function formatItemDiscountDisplay(item: Pick<InvoiceItem, 'discount' | 'discountPercent'>): {
|
||||||
|
value: string;
|
||||||
|
percent: string;
|
||||||
|
} {
|
||||||
|
return {
|
||||||
|
value: item.discount != null && item.discount > 0 ? `${NumberFormat(item.discount)} ریال` : '-',
|
||||||
|
percent: item.discountPercent != null && item.discountPercent > 0 ? `${item.discountPercent}٪` : '-',
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user