Skip to content

Commit a53e218

Browse files
committed
/inbound-invoies: list all credit notes
1 parent f28bb4b commit a53e218

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

frontend/src/components/project/inbound-invoices/InboundInvoicesTable.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {InboundInvoiceAttachmentType, ProformaInvoiceAttachmentType, SignedTimes
1010
import {Link} from 'react-router';
1111
import {ConsultantModel} from '../../consultant/models/ConsultantModel';
1212
import {ProjectLinkWithModal} from '../controls/ProjectLinkWithModal';
13+
import InvoiceModel from '../../invoice/models/InvoiceModel';
1314

1415
interface InboundInvoicesTableProps {
1516
projectMonths: FullProjectMonthModel[];
@@ -25,6 +26,7 @@ interface GroupedInvoices {
2526

2627
export const InboundInvoicesTable = ({projectMonths}: InboundInvoicesTableProps) => {
2728
const tax = useSelector((state: ConfacState) => state.config.defaultInvoiceLines[0].tax);
29+
const allInvoices = useSelector((state: ConfacState) => state.invoices);
2830

2931
// Group by consultant
3032
const groupedByConsultant = projectMonths.reduce((acc, pm) => {
@@ -200,9 +202,24 @@ export const InboundInvoicesTable = ({projectMonths}: InboundInvoicesTableProps)
200202
</td>
201203
<td>
202204
{pm.invoice && (
203-
<Link to={`/invoices/${pm.invoice._id}`}>
204-
#{pm.invoice.number}
205-
</Link>
205+
<>
206+
{pm.invoice.creditNotas?.length > 0 ? (
207+
[pm.invoice, ...pm.invoice.creditNotas
208+
.map(id => allInvoices.find(inv => inv._id === id))
209+
.filter((inv): inv is InvoiceModel => inv !== undefined)]
210+
.sort((a, b) => a.number - b.number)
211+
.map((inv, idx, arr) => (
212+
<span key={inv._id}>
213+
<Link to={`/invoices/${inv._id}`}>#{inv.number}</Link>
214+
{idx < arr.length - 1 && ', '}
215+
</span>
216+
))
217+
) : (
218+
<Link to={`/invoices/${pm.invoice._id}`}>
219+
#{pm.invoice.number}
220+
</Link>
221+
)}
222+
</>
206223
)}
207224
</td>
208225
</tr>

0 commit comments

Comments
 (0)