Files
Canteen-Management-System/counter-frontend/dist/assets/POS-Bp9lDbPa.js
Sidharth Prabhu f876fa9239 Bug Fixes
2026-08-04 14:10:10 +05:30

7 lines
11 KiB
JavaScript

import{t as e}from"./proxy-cLldRXEc.js";import{t}from"./AnimatePresence-CcsC7tO8.js";import{t as n}from"./minus-wD8f4ZO0.js";import{t as r}from"./plus-CtPxjhzP.js";import{t as i}from"./trash-2-B3saCmcm.js";import{g as a,h as o,i as s,m as c,r as l,s as u}from"./index-B-Yfb7Zz.js";var d=u(`cake`,[[`path`,{d:`M20 21v-8a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v8`,key:`1w3rig`}],[`path`,{d:`M4 16s.5-1 2-1 2.5 2 4 2 2.5-2 4-2 2.5 2 4 2 2-1 2-1`,key:`n2jgmb`}],[`path`,{d:`M2 21h20`,key:`1nyx9w`}],[`path`,{d:`M7 8v3`,key:`1qtyvj`}],[`path`,{d:`M12 8v3`,key:`hwp4zt`}],[`path`,{d:`M17 8v3`,key:`1i6e5u`}],[`path`,{d:`M7 4h.01`,key:`1bh4kh`}],[`path`,{d:`M12 4h.01`,key:`1ujb9j`}],[`path`,{d:`M17 4h.01`,key:`1upcoc`}]]),f=u(`coffee`,[[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M14 2v2`,key:`6buw04`}],[`path`,{d:`M16 8a1 1 0 0 1 1 1v8a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1h14a4 4 0 1 1 0 8h-1`,key:`pwadti`}],[`path`,{d:`M6 2v2`,key:`colzsn`}]]),p=u(`ice-cream-cone`,[[`path`,{d:`m7 11 4.08 10.35a1 1 0 0 0 1.84 0L17 11`,key:`1v6356`}],[`path`,{d:`M17 7A5 5 0 0 0 7 7`,key:`151p3v`}],[`path`,{d:`M17 7a2 2 0 0 1 0 4H7a2 2 0 0 1 0-4`,key:`1sdaij`}]]),m=u(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),h=u(`phone`,[[`path`,{d:`M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384`,key:`9njp5v`}]]),g=u(`pizza`,[[`path`,{d:`m12 14-1 1`,key:`11onhr`}],[`path`,{d:`m13.75 18.25-1.25 1.42`,key:`1yisr3`}],[`path`,{d:`M17.775 5.654a15.68 15.68 0 0 0-12.121 12.12`,key:`1qtqk6`}],[`path`,{d:`M18.8 9.3a1 1 0 0 0 2.1 7.7`,key:`fbbbr2`}],[`path`,{d:`M21.964 20.732a1 1 0 0 1-1.232 1.232l-18-5a1 1 0 0 1-.695-1.232A19.68 19.68 0 0 1 15.732 2.037a1 1 0 0 1 1.232.695z`,key:`1hyfdd`}]]),_=u(`utensils-crossed`,[[`path`,{d:`m16 2-2.3 2.3a3 3 0 0 0 0 4.2l1.8 1.8a3 3 0 0 0 4.2 0L22 8`,key:`n7qcjb`}],[`path`,{d:`M15 15 3.3 3.3a4.2 4.2 0 0 0 0 6l7.3 7.3c.7.7 2 .7 2.8 0L15 15Zm0 0 7 7`,key:`d0u48b`}],[`path`,{d:`m2.1 21.8 6.4-6.3`,key:`yn04lh`}],[`path`,{d:`m19 5-7 7`,key:`194lzd`}]]),v=a(o(),1),y=c(),b=e=>{let t=e.toUpperCase();return t.includes(`ICE`)?p:t.includes(`JUICE`)||t.includes(`DRINK`)?_:t.includes(`COFFEE`)||t.includes(`TEA`)||t.includes(`BISCUIT`)?f:t.includes(`PIZZA`)||t.includes(`SNACK`)?g:t.includes(`CAKE`)||t.includes(`SWEET`)||t.includes(`CHOCO`)?d:_},x=()=>{let[a,o]=(0,v.useState)([]),[c,u]=(0,v.useState)([`ALL`]),[d,f]=(0,v.useState)(!0),[p,g]=(0,v.useState)(`ALL`),[_,x]=(0,v.useState)([]),[S,C]=(0,v.useState)(``);(0,v.useEffect)(()=>{w()},[]);let w=async()=>{try{f(!0);let[e,t]=await Promise.all([fetch(`https://cmsapi.rit-services.in/api/products?size=1000`),fetch(`https://cmsapi.rit-services.in/api/products/categories`)]);e.ok&&o((await e.json()).content||[]),t.ok&&u([`ALL`,...await t.json()])}catch(e){console.error(`Error fetching data:`,e)}finally{f(!1)}},T=(0,v.useMemo)(()=>a.filter(e=>{if(!e)return!1;let t=(S||``).toLowerCase(),n=(e.name||``).toLowerCase().includes(t),r=p===`ALL`||e.category===p;return n&&r}),[a,S,p]),E=e=>{_.find(t=>t.id===e.id)?x(_.map(t=>t.id===e.id?{...t,quantity:t.quantity+1}:t)):x([..._,{...e,quantity:1}])},D=(e,t)=>{x(_.map(n=>{if(n.id===e){let e=Math.max(1,n.quantity+t);return{...n,quantity:e}}return n}))},O=e=>{x(_.filter(t=>t.id!==e))},k=_.reduce((e,t)=>e+t.price*t.quantity,0);return(0,y.jsxs)(`div`,{className:`h-[calc(100vh-64px)] flex overflow-hidden`,children:[(0,y.jsxs)(`div`,{className:`flex-1 flex flex-col bg-slate-50 overflow-hidden`,children:[(0,y.jsx)(`div`,{className:`p-4 bg-white border-b border-slate-200 overflow-x-auto no-scrollbar`,children:(0,y.jsx)(`div`,{className:`flex gap-4`,children:c.map(e=>{let t=b(e);return(0,y.jsxs)(`button`,{onClick:()=>g(e),className:`flex items-center gap-2 px-6 py-3 rounded-xl text-xs font-black transition-all border-2 whitespace-nowrap ${p===e?`bg-primary text-white border-primary shadow-lg shadow-primary/20`:`bg-white text-slate-400 border-indigo-50 hover:border-primary/30`}`,children:[(0,y.jsx)(t,{size:16}),e]},e)})})}),(0,y.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6 flex flex-col gap-6 custom-scrollbar`,children:[(0,y.jsxs)(`div`,{className:`relative group max-w-2xl`,children:[(0,y.jsx)(s,{className:`absolute left-4 top-1/2 -translate-y-1/2 text-slate-400 group-focus-within:text-primary transition-colors`,size:20}),(0,y.jsx)(`input`,{type:`text`,placeholder:`Search Product...`,value:S,onChange:e=>C(e.target.value),className:`w-full pl-12 pr-4 py-4 bg-white border border-slate-200 rounded-2xl text-sm font-semibold outline-none focus:ring-4 focus:ring-primary/5 focus:border-primary transition-all shadow-sm`})]}),d?(0,y.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,y.jsx)(m,{className:`animate-spin text-primary`,size:48})}):T.length===0?(0,y.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-slate-400`,children:[(0,y.jsx)(l,{size:64,className:`mb-4 opacity-20`}),(0,y.jsx)(`p`,{className:`font-bold`,children:`No products found`})]}):(0,y.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-6`,children:T.map(t=>(0,y.jsxs)(e.div,{whileHover:{y:-4},whileTap:{scale:.98},onClick:()=>E(t),className:`bg-white rounded-[2rem] p-5 border border-slate-100 shadow-sm hover:shadow-xl hover:border-primary/20 transition-all cursor-pointer group flex flex-col relative`,children:[(0,y.jsx)(`div`,{className:`absolute top-4 right-4 z-10`,children:(0,y.jsxs)(`span`,{className:`px-2.5 py-1 rounded-lg text-[10px] font-black border uppercase tracking-wider ${(t.stock||0)<20?`bg-rose-50 text-rose-500 border-rose-100`:`bg-emerald-50 text-emerald-500 border-emerald-100`}`,children:[t.stock||0,` left`]})}),(0,y.jsx)(`div`,{className:`aspect-square bg-slate-50 rounded-2xl mb-4 flex items-center justify-center text-slate-200 group-hover:bg-primary/5 transition-colors overflow-hidden`,children:t.imageData?(0,y.jsx)(`img`,{src:t.imageData,alt:t.name,className:`w-full h-full object-cover`}):(0,y.jsx)(l,{size:48})}),(0,y.jsx)(`h3`,{className:`text-xs font-black text-slate-800 leading-snug mb-1 line-clamp-2 uppercase`,children:t.name}),(0,y.jsx)(`div`,{className:`mt-auto`,children:(0,y.jsxs)(`p`,{className:`text-lg font-black text-primary`,children:[`🅡`,t.price]})})]},t.id))})]})]}),(0,y.jsxs)(`div`,{className:`w-[450px] bg-white border-l border-slate-200 flex flex-col shadow-[-10px_0_30px_rgba(0,0,0,0.02)]`,children:[(0,y.jsxs)(`div`,{className:`p-6 border-b border-slate-100 flex justify-between items-center`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h2`,{className:`text-xl font-black text-slate-900 tracking-tight`,children:`Current Order`}),(0,y.jsxs)(`p`,{className:`text-[10px] font-bold text-slate-400 uppercase tracking-widest flex items-center gap-1.5 mt-0.5`,children:[(0,y.jsx)(h,{size:10,className:`text-primary`}),` +91 9043941910`]})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,y.jsx)(`button`,{className:`px-4 py-2 bg-slate-50 text-slate-600 rounded-xl text-[10px] font-black uppercase hover:bg-slate-100 transition-colors`,children:`View Orders`}),(0,y.jsxs)(`span`,{className:`bg-primary text-white text-[10px] font-black px-3 py-1.5 rounded-lg uppercase shadow-lg shadow-primary/20`,children:[_.length,` items`]})]})]}),(0,y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-6 flex flex-col gap-4 custom-scrollbar`,children:(0,y.jsx)(t,{mode:`popLayout`,children:_.length===0?(0,y.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center text-slate-400 gap-4`,children:[(0,y.jsx)(`div`,{className:`w-20 h-20 bg-slate-50 rounded-3xl flex items-center justify-center`,children:(0,y.jsx)(l,{size:40,className:`text-slate-200`})}),(0,y.jsxs)(`div`,{children:[(0,y.jsx)(`h3`,{className:`font-black text-slate-600`,children:`Cart is empty`}),(0,y.jsx)(`p`,{className:`text-xs font-medium`,children:`Select products to start billing`})]})]}):_.map(t=>(0,y.jsxs)(e.div,{layout:!0,initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,scale:.95},className:`bg-[#ebfaf4] border border-[#d1f4e6] rounded-[2rem] p-5 relative group`,children:[(0,y.jsxs)(`div`,{className:`flex justify-between items-start mb-4`,children:[(0,y.jsxs)(`div`,{className:`flex-1 pr-12`,children:[(0,y.jsx)(`h4`,{className:`text-[11px] font-black text-slate-800 uppercase tracking-tight leading-tight`,children:t.name}),(0,y.jsxs)(`p`,{className:`text-[10px] font-bold text-[#42ab7e] mt-1 uppercase`,children:[`🅡`,t.price,` each`]})]}),(0,y.jsx)(`button`,{onClick:()=>O(t.id),className:`w-9 h-9 bg-white text-rose-500 rounded-xl flex items-center justify-center shadow-sm border border-rose-50 hover:bg-rose-50 transition-colors`,children:(0,y.jsx)(i,{size:16})})]}),(0,y.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,y.jsxs)(`div`,{className:`flex items-center bg-white rounded-xl p-1 shadow-sm border border-slate-50`,children:[(0,y.jsx)(`button`,{onClick:()=>D(t.id,-1),className:`w-8 h-8 flex items-center justify-center text-slate-400 hover:text-primary transition-colors`,children:(0,y.jsx)(n,{size:14})}),(0,y.jsx)(`span`,{className:`w-10 text-center font-black text-sm text-slate-900`,children:t.quantity}),(0,y.jsx)(`button`,{onClick:()=>D(t.id,1),className:`w-8 h-8 flex items-center justify-center text-slate-400 hover:text-primary transition-colors`,children:(0,y.jsx)(r,{size:14})})]}),(0,y.jsx)(`div`,{className:`text-right`,children:(0,y.jsxs)(`p`,{className:`text-lg font-black text-slate-900 tracking-tight`,children:[`🅡`,t.price*t.quantity]})})]})]},t.id))})}),(0,y.jsxs)(`div`,{className:`p-8 bg-slate-50 border-t border-slate-200 shadow-[0_-10px_40px_rgba(0,0,0,0.03)] rounded-t-[3rem]`,children:[(0,y.jsxs)(`div`,{className:`flex justify-between items-center mb-6`,children:[(0,y.jsx)(`span`,{className:`text-lg font-black text-slate-900`,children:`Total:`}),(0,y.jsxs)(`span`,{className:`text-4xl font-black text-primary tracking-tighter`,children:[`🅡`,k]})]}),(0,y.jsx)(`button`,{disabled:_.length===0,onClick:async()=>{if(_.length!==0){f(!0);try{let e={userId:1,totalAmount:k,paymentMethod:`CASH`,status:`COMPLETED`,items:_.map(e=>({productId:e.id,productName:e.name,price:e.price,quantity:e.quantity}))},t=sessionStorage.getItem(`counterToken`),n=await fetch(`https://cmsapi.rit-services.in/api/orders`,{method:`POST`,headers:{"Content-Type":`application/json`,...t?{Authorization:`Bearer ${t}`}:{}},body:JSON.stringify(e)});if(n.ok)alert(`Order placed successfully! Stock has been updated.`),x([]),w();else{let e=`Unknown error`;try{let t=await n.text();try{let n=JSON.parse(t);e=n.error||n.message||JSON.stringify(n)}catch{e=t||n.statusText}}catch{e=n.statusText}alert(`Failed to place order: ${e}`)}}catch(e){console.error(`Order error:`,e),alert(`Network error while placing order.`)}finally{f(!1)}}},className:`w-full bg-primary text-white py-5 rounded-[2rem] font-black text-sm uppercase tracking-[0.2em] shadow-2xl shadow-primary/20 hover:scale-[1.02] active:scale-[0.98] transition-all disabled:opacity-50 disabled:scale-100 disabled:shadow-none`,children:`Complete Order`})]})]}),(0,y.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
.custom-scrollbar::-webkit-scrollbar { width: 5px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 10px; }
`}})]})};export{x as default};