@@ -11,8 +11,11 @@ const CroatianDateTime = () => {
1111
1212export default function Prodaja ( ) {
1313 const [ articles , setArticles ] = useState ( [ ] ) ;
14+ const [ categories , setCategories ] = useState ( [ ] ) ;
1415 const [ selectedItems , setSelectedItems ] = useState ( [ ] ) ;
1516 const [ paymentMethod , setPaymentMethod ] = useState ( "Gotovina" ) ;
17+ const [ locations , setLocations ] = useState ( [ ] ) ;
18+ const [ selectedLocationId , setSelectedLocationId ] = useState ( "" ) ;
1619 const [ loading , setLoading ] = useState ( true ) ;
1720 const [ searchParams ] = useSearchParams ( ) ;
1821 const [ offlineCount , setOfflineCount ] = useState ( 0 ) ;
@@ -32,8 +35,27 @@ export default function Prodaja() {
3235 const offline = JSON . parse ( localStorage . getItem ( "offline_receipts" ) || "[]" ) ;
3336 setOfflineCount ( offline . length ) ;
3437 fetchArticles ( ) ;
38+ fetchLocations ( ) ;
39+ fetchCategories ( ) ;
3540 } , [ ] ) ;
3641
42+ const fetchLocations = async ( ) => {
43+ try {
44+ const response = await fetch ( `${ import . meta. env . VITE_API_URL } /api/prodajna-mjesta` , { credentials : "include" } ) ;
45+ const data = await response . json ( ) ;
46+ if ( response . ok && Array . isArray ( data ) ) {
47+ setLocations ( data . filter ( loc => loc . active ) ) ;
48+ if ( data . length > 0 && ! selectedLocationId ) {
49+ setSelectedLocationId ( String ( data [ 0 ] . id ) ) ;
50+ }
51+ } else {
52+ setLocations ( [ ] ) ;
53+ }
54+ } catch {
55+ setLocations ( [ ] ) ;
56+ }
57+ } ;
58+
3759 const fetchArticles = async ( ) => {
3860 try {
3961 const response = await fetch ( `${ import . meta. env . VITE_API_URL } /api/articles` , { credentials : "include" } ) ;
@@ -46,6 +68,16 @@ export default function Prodaja() {
4668 }
4769 } ;
4870
71+ const fetchCategories = async ( ) => {
72+ try {
73+ const response = await fetch ( `${ import . meta. env . VITE_API_URL } /api/categories` , { credentials : "include" } ) ;
74+ const data = await response . json ( ) ;
75+ setCategories ( response . ok && Array . isArray ( data ) ? data . filter ( c => c . active ) : [ ] ) ;
76+ } catch {
77+ setCategories ( [ ] ) ;
78+ }
79+ } ;
80+
4981 const syncOfflineReceipts = async ( ) => {
5082 const offline = JSON . parse ( localStorage . getItem ( "offline_receipts" ) || "[]" ) ;
5183 if ( offline . length === 0 ) return ;
@@ -109,6 +141,7 @@ export default function Prodaja() {
109141
110142 const receiptData = {
111143 receiptNumber : `RCN-${ Date . now ( ) } ` ,
144+ prodajnoMjestoId : selectedLocationId ? Number ( selectedLocationId ) : null ,
112145 invoiceType : "RAČUN" ,
113146 paymentType : paymentMethod === "Kartica" ? "KARTICA" : "GOTOVINA" ,
114147 brutto : totalBrutto ,
@@ -174,6 +207,7 @@ export default function Prodaja() {
174207 tax : receipt . taxValue ?? totalTax ,
175208 jir : receipt . jir ?? "" ,
176209 zki : receipt . zki ?? "" ,
210+ location : locations . find ( ( loc ) => String ( loc . id ) === String ( selectedLocationId ) ) ?. name || "" ,
177211 link : buildPoreznaLink ( receipt . jir , receipt . invoiceDate || receipt . createdAt || new Date ( ) , receipt . brutto ?? totalBrutto ) ,
178212 phone : "0916043415" ,
179213 email : "info@kset.org" ,
@@ -195,7 +229,7 @@ export default function Prodaja() {
195229 @media (min-width: 768px) {
196230 .prodaja-layout {
197231 display: grid;
198- grid-template-columns: 1fr 380px ;
232+ grid-template-columns: 1fr 450px ;
199233 gap: 20px;
200234 height: calc(100vh - 120px);
201235 align-items: start;
@@ -209,12 +243,12 @@ export default function Prodaja() {
209243
210244 .grid {
211245 display: grid;
212- grid-template-columns: repeat(auto-fill, minmax(160px, 1fr) ) !important;
246+ grid-template-columns: repeat(2, 1fr) !important;
213247 gap: 15px !important;
214248 }
215249
216250 .article-card {
217- min-height: 120px ;
251+ min-height: 140px ;
218252 display: flex;
219253 flex-direction: column;
220254 justify-content: center;
@@ -224,6 +258,15 @@ export default function Prodaja() {
224258 border-radius: 12px !important;
225259 box-shadow: 0 2px 4px rgba(0,0,0,0.05);
226260 transition: transform 0.1s, border-color 0.1s;
261+ word-break: break-word;
262+ overflow-wrap: break-word;
263+ }
264+
265+ .article-card h3 {
266+ word-break: break-word;
267+ overflow-wrap: break-word;
268+ white-space: normal;
269+ margin: 0 0 8px 0;
227270 }
228271
229272 .article-card:active {
@@ -265,9 +308,9 @@ export default function Prodaja() {
265308 display: flex !important;
266309 align-items: center !important;
267310 justify-content: center !important;
268- line-height: 0 !important; /* Prevents vertical clipping */
311+ line-height: 0 !important;
269312 padding: 0 !important;
270- padding-bottom: 4px !important; /* Visual optical center adjustment */
313+ padding-bottom: 4px !important;
271314 cursor: pointer;
272315 background-color: #f8f9fa;
273316 border: 1px solid #ddd;
@@ -295,16 +338,30 @@ export default function Prodaja() {
295338 }
296339` } </ style >
297340
298- < div style = { { display : 'flex' , alignItems : 'center' , justifyContent : 'space-between' , marginBottom : '20px' } } >
299- < h1 >
300- Prodaja
301- { offlineCount > 0 && (
341+ < div style = { { display : 'flex' , alignItems : 'center' , justifyContent : 'space-between' , marginBottom : '20px' , flexWrap : 'wrap' , gap : '10px' } } >
342+ < div style = { { display : 'flex' , alignItems : 'center' , gap : '10px' } } >
343+ < h1 style = { { margin : 0 } } >
344+ Prodaja
345+ </ h1 >
346+ < label style = { { fontSize : '14px' , color : '#333' } } >
347+ Prodajno mjesto:
348+ < select
349+ value = { selectedLocationId }
350+ onChange = { ( e ) => setSelectedLocationId ( e . target . value ) }
351+ style = { { marginLeft : '8px' , padding : '5px 8px' , borderRadius : '4px' , border : '1px solid #ccc' } }
352+ >
353+ < option value = "" > (nije odabrano)</ option >
354+ { locations . map ( loc => (
355+ < option key = { loc . id } value = { loc . id } > { loc . name } ({ loc . businessSpace } )</ option >
356+ ) ) }
357+ </ select >
358+ </ label >
359+ </ div >
360+ { offlineCount > 0 && (
302361 < span style = { { color : 'red' , fontSize : '14px' , marginLeft : '10px' } } >
303362 ({ offlineCount } čekaju sinkronizaciju)
304363 </ span >
305364 ) }
306- </ h1 >
307-
308365 { offlineCount > 0 && (
309366 < button
310367 onClick = { syncOfflineReceipts }
@@ -327,7 +384,7 @@ export default function Prodaja() {
327384
328385 < div className = "prodaja-layout" >
329386 < div className = "articles-grid" >
330- < h2 > { categoryId ? " Artikli u kategoriji" : "Svi artikli" } </ h2 >
387+ < h2 > { categoryId ? ` Artikli u kategoriji ${ categories . find ( c => c . id === categoryId ) ?. name } ` : "Svi artikli" } </ h2 >
331388 < div className = "grid" >
332389 { filteredArticles . map ( article => (
333390 < div key = { article . id } className = "article-card" onClick = { ( ) => addItem ( article ) } style = { { cursor : 'pointer' } } >
0 commit comments