@@ -8,6 +8,8 @@ export default function Povijest() {
88 const [ loading , setLoading ] = useState ( true ) ;
99 const [ , setError ] = useState ( null ) ;
1010 const [ filter , setFilter ] = useState ( "" ) ;
11+ const [ filterPayment , setFilterPayment ] = useState ( '' ) ;
12+ const [ filterStatus , setFilterStatus ] = useState ( '' ) ;
1113 const [ reportType , setReportType ] = useState ( "transactions" ) ;
1214 const [ showDatePicker , setShowDatePicker ] = useState ( false ) ;
1315
@@ -226,12 +228,19 @@ export default function Povijest() {
226228 }
227229 } ;
228230
231+ const uniquePaymentTypes = [ ...new Set ( transactions . map ( t => t . receipt ?. paymentType ) . filter ( Boolean ) ) ] ;
232+
229233 const filteredTransactions = transactions . filter ( t => {
230234 const transactionSessionDay = getSessionDate ( t . createdAt ) ;
231- const matchesSearch = ! filter ||
235+ const matchesSearch = ! filter ||
232236 t . receipt ?. invoiceNumber ?. toLowerCase ( ) . includes ( filter . toLowerCase ( ) ) ||
233237 t . user ?. name ?. toLowerCase ( ) . includes ( filter . toLowerCase ( ) ) ;
234- return matchesSearch && transactionSessionDay >= startDate && transactionSessionDay <= endDate ;
238+ if ( ! matchesSearch ) return false ;
239+ if ( transactionSessionDay < startDate || transactionSessionDay > endDate ) return false ;
240+ if ( filterPayment && t . receipt ?. paymentType !== filterPayment ) return false ;
241+ if ( filterStatus === 'STORNO_OTKAZANO' && t . receipt ?. status !== 'STORNO' && t . receipt ?. status !== 'RACUN_STORNIRAN' ) return false ;
242+ else if ( filterStatus && filterStatus !== 'STORNO_OTKAZANO' && t . receipt ?. status !== filterStatus ) return false ;
243+ return true ;
235244 } ) ;
236245
237246 const articlesReport = getArticlesReport ( ) ;
@@ -306,7 +315,7 @@ export default function Povijest() {
306315 boxShadow : '0 10px 40px rgba(0,0,0,0.15)' ,
307316 padding : '20px' ,
308317 zIndex : 1000 ,
309- minWidth : '520px '
318+ minWidth : '320px '
310319 } } ref = { datePickerRef } >
311320 < div style = { { marginBottom : '15px' , display : 'flex' , justifyContent : 'space-between' , alignItems : 'center' } } >
312321 < h3 style = { { margin : 0 , color : '#1a202c' , fontSize : '16px' } } > Odaberi razdoblje</ h3 >
@@ -318,41 +327,28 @@ export default function Povijest() {
318327 </ button >
319328 </ div >
320329
321- < div style = { { display : 'grid' , gridTemplateColumns : '1fr 1fr' , gap : '15px' , marginBottom : '15px' } } >
322- < div >
323- < label style = { { fontSize : '12px' , fontWeight : 'bold' , color : '#718096' , display : 'block' , marginBottom : '8px' } } > POČETNI DATUM</ label >
324- < Calendar
325- value = { tempStartDate }
326- onChange = { handleDateSelection }
327- tileClassName = { ( { date } ) => {
328- if ( tempStartDate && tempEndDate ) {
329- if ( date . toDateString ( ) === tempStartDate . toDateString ( ) ) return 'date-range-start' ;
330- if ( date . toDateString ( ) === tempEndDate . toDateString ( ) ) return 'date-range-end' ;
331- if ( date > tempStartDate && date < tempEndDate ) return 'date-range-middle' ;
332- } else if ( tempStartDate && date . toDateString ( ) === tempStartDate . toDateString ( ) ) {
333- return 'date-range-start' ;
334- }
335- return '' ;
336- } }
337- />
338- </ div >
339- < div >
340- < label style = { { fontSize : '12px' , fontWeight : 'bold' , color : '#718096' , display : 'block' , marginBottom : '8px' } } > ZAVRŠNI DATUM</ label >
341- < Calendar
342- value = { tempEndDate }
343- onChange = { handleDateSelection }
344- tileClassName = { ( { date } ) => {
345- if ( tempStartDate && tempEndDate ) {
346- if ( date . toDateString ( ) === tempStartDate . toDateString ( ) ) return 'date-range-start' ;
347- if ( date . toDateString ( ) === tempEndDate . toDateString ( ) ) return 'date-range-end' ;
348- if ( date > tempStartDate && date < tempEndDate ) return 'date-range-middle' ;
349- } else if ( tempStartDate && date . toDateString ( ) === tempStartDate . toDateString ( ) ) {
350- return 'date-range-start' ;
351- }
352- return '' ;
353- } }
354- />
355- </ div >
330+ < div style = { { marginBottom : '10px' } } >
331+ < label style = { { fontSize : '12px' , fontWeight : 'bold' , color : '#718096' , display : 'block' , marginBottom : '8px' } } >
332+ { ! tempStartDate || ( tempStartDate && tempEndDate ) ? 'KLIKNI POČETNI DATUM' : 'KLIKNI ZAVRŠNI DATUM' }
333+ </ label >
334+ < Calendar
335+ value = { tempStartDate }
336+ onChange = { handleDateSelection }
337+ tileClassName = { ( { date } ) => {
338+ if ( tempStartDate && tempEndDate ) {
339+ if ( date . toDateString ( ) === tempStartDate . toDateString ( ) ) return 'date-range-start' ;
340+ if ( date . toDateString ( ) === tempEndDate . toDateString ( ) ) return 'date-range-end' ;
341+ if ( date > tempStartDate && date < tempEndDate ) return 'date-range-middle' ;
342+ } else if ( tempStartDate && date . toDateString ( ) === tempStartDate . toDateString ( ) ) {
343+ return 'date-range-start' ;
344+ }
345+ return '' ;
346+ } }
347+ />
348+ </ div >
349+ < div style = { { fontSize : '13px' , color : '#4a5568' , marginBottom : '15px' } } >
350+ { tempStartDate && < span > Od: < strong > { tempStartDate . toISOString ( ) . split ( 'T' ) [ 0 ] } </ strong > </ span > }
351+ { tempStartDate && tempEndDate && < span > → Do: < strong > { tempEndDate . toISOString ( ) . split ( 'T' ) [ 0 ] } </ strong > </ span > }
356352 </ div >
357353
358354 < div style = { { display : 'flex' , gap : '10px' , justifyContent : 'flex-end' } } >
@@ -476,15 +472,38 @@ export default function Povijest() {
476472 placeholder = "Pretraži po broju računa ili prodavaču..."
477473 value = { filter }
478474 onChange = { ( e ) => setFilter ( e . target . value ) }
479- style = { {
480- width : '100%' ,
481- padding : '12px 15px' ,
482- borderRadius : '8px' ,
475+ style = { {
476+ width : '100%' ,
477+ padding : '12px 15px' ,
478+ borderRadius : '8px' ,
483479 border : '1px solid #e2e8f0' ,
484480 fontSize : '15px' ,
485- outline : 'none'
481+ outline : 'none' ,
482+ marginBottom : '10px'
486483 } }
487484 />
485+ < div style = { { display : 'flex' , gap : '12px' , alignItems : 'center' , flexWrap : 'wrap' } } >
486+ < select value = { filterPayment } onChange = { e => setFilterPayment ( e . target . value ) }
487+ style = { { padding : '8px 12px' , borderRadius : '6px' , border : '1px solid #e2e8f0' , fontSize : '14px' } } >
488+ < option value = "" > Sva plaćanja</ option >
489+ { uniquePaymentTypes . map ( pt => < option key = { pt } value = { pt } > { pt } </ option > ) }
490+ </ select >
491+ < select value = { filterStatus } onChange = { e => setFilterStatus ( e . target . value ) }
492+ style = { { padding : '8px 12px' , borderRadius : '6px' , border : '1px solid #e2e8f0' , fontSize : '14px' } } >
493+ < option value = "" > Svi statusi</ option >
494+ < option value = "RACUN" > AKTIVAN</ option >
495+ < option value = "STORNO" > STORNO</ option >
496+ < option value = "RACUN_STORNIRAN" > OTKAZANO</ option >
497+ < option value = "STORNO_OTKAZANO" > STORNO + OTKAZANO</ option >
498+ </ select >
499+ { ( filterPayment || filterStatus ) && (
500+ < button onClick = { ( ) => { setFilterPayment ( '' ) ; setFilterStatus ( '' ) ; } }
501+ style = { { padding : '8px 12px' , borderRadius : '6px' , border : '1px solid #e2e8f0' , background : '#f7fafc' , cursor : 'pointer' , fontSize : '13px' } } >
502+ Resetiraj filtere
503+ </ button >
504+ ) }
505+ < span style = { { color : '#718096' , fontSize : '13px' } } > { filteredTransactions . length } / { transactions . filter ( t => { const d = getSessionDate ( t . createdAt ) ; return d >= startDate && d <= endDate ; } ) . length } transakcija</ span >
506+ </ div >
488507 </ div >
489508 ) }
490509
0 commit comments