@@ -10,6 +10,7 @@ import {InboundInvoiceAttachmentType, ProformaInvoiceAttachmentType, SignedTimes
1010import { Link } from 'react-router' ;
1111import { ConsultantModel } from '../../consultant/models/ConsultantModel' ;
1212import { ProjectLinkWithModal } from '../controls/ProjectLinkWithModal' ;
13+ import InvoiceModel from '../../invoice/models/InvoiceModel' ;
1314
1415interface InboundInvoicesTableProps {
1516 projectMonths : FullProjectMonthModel [ ] ;
@@ -25,6 +26,7 @@ interface GroupedInvoices {
2526
2627export 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