@@ -98,7 +98,27 @@ export default function UkupniIzvjestaj() {
9898 const [ activeDates , setActiveDates ] = useState ( [ ] ) ;
9999 const [ selectedDate , setSelectedDate ] = useState ( null ) ;
100100 const receiptRef = useRef ( ) ;
101+ const handleStorno = async ( receiptId ) => {
102+ if ( ! window . confirm ( "Jeste li sigurni da želite stornirati ovaj račun?" ) ) return ;
101103
104+ try {
105+ const res = await fetch ( `${ import . meta. env . VITE_API_URL } /api/receipts/${ receiptId } /storno` , {
106+ method : 'PUT' ,
107+ credentials : "include" ,
108+ } ) ;
109+
110+ if ( res . ok ) {
111+ alert ( "Račun uspješno storniran." ) ;
112+ handleDateClick ( new Date ( selectedDate ) ) ;
113+ } else {
114+ const errData = await res . json ( ) ;
115+ alert ( `Greška: ${ errData . message || 'Neuspjelo storniranje' } ` ) ;
116+ }
117+ } catch ( error ) {
118+ console . error ( "Storno error:" , error ) ;
119+ alert ( "Došlo je do greške na mreži." ) ;
120+ }
121+ } ;
102122 useEffect ( ( ) => {
103123 fetch ( `${ import . meta. env . VITE_API_URL } /api/receipts/active-dates` , { credentials : "include" } )
104124 . then ( res => res . json ( ) )
@@ -382,9 +402,11 @@ export default function UkupniIzvjestaj() {
382402 </ thead >
383403 < tbody >
384404 { dayReceipts . map ( ( r ) => {
385- const isStorno = r . status === 'STORNO' || r . status === 'RACUN_STORNIRAN' ;
405+ const isStorno = r . status === 'STORNO' ;
406+ const isCancelled = r . status === 'RACUN_STORNIRAN' ;
407+
386408 return (
387- < tr key = { r . id } style = { { borderBottom : '1px solid #eee' , color : isStorno ? '#999' : '#333' } } >
409+ < tr key = { r . id } style = { { borderBottom : '1px solid #eee' , color : ( isStorno || isCancelled ) ? '#999' : '#333' } } >
388410 < td style = { { padding : '10px 15px' , fontWeight : '500' } } > { r . invoiceNumber } </ td >
389411 < td style = { { padding : '10px 15px' , textAlign : 'center' } } >
390412 { new Date ( r . createdAt ) . toLocaleTimeString ( "hr-HR" , { hour : '2-digit' , minute : '2-digit' } ) }
@@ -394,7 +416,30 @@ export default function UkupniIzvjestaj() {
394416 { parseFloat ( r . brutto ) . toFixed ( 2 ) } €
395417 </ td >
396418 < td style = { { padding : '10px 15px' , textAlign : 'center' , fontSize : '0.85rem' } } >
397- { isStorno ? < span style = { { color : '#d32f2f' } } > STORNO</ span > : < span style = { { color : '#388e3c' } } > OK</ span > }
419+ { isCancelled ? (
420+ < span style = { { color : '#ef6c00' , fontWeight : 'bold' } } > OTKAZANO</ span >
421+ ) : isStorno ? (
422+ < span style = { { color : '#d32f2f' , fontWeight : 'bold' } } > STORNO</ span >
423+ ) : (
424+ < div style = { { display : 'flex' , alignItems : 'center' , justifyContent : 'center' , gap : '10px' } } >
425+ < span style = { { color : '#388e3c' } } > OK</ span >
426+ < button
427+ onClick = { ( ) => handleStorno ( r . id ) }
428+ style = { {
429+ background : '#fee2e2' ,
430+ color : '#b91c1c' ,
431+ border : '1px solid #f87171' ,
432+ padding : '2px 8px' ,
433+ borderRadius : '4px' ,
434+ cursor : 'pointer' ,
435+ fontSize : '11px' ,
436+ fontWeight : 'bold'
437+ } }
438+ >
439+ Storniraj
440+ </ button >
441+ </ div >
442+ ) }
398443 </ td >
399444 </ tr >
400445 ) ;
0 commit comments