1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[23942],{23942:(e,t,s)=>{s.d(t,{o:()=>f});var a=s(95155),r=s(12115),n=s(94465),l=s(31166),i=s(40051),c=s(88376),o=s(94039),u=s(16443),d=s(28956),x=s(15028),m=s(82297),h=s(20467);let b="h-11 w-full px-3 rounded-xl border border-gray-200 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-coral",p="block text-[11px] font-semibold uppercase tracking-wide text-gray-light mb-1";function f(e){let{open:t,onClose:s,target:f,onAdjusted:g,costEditable:j=!1,focusCost:y=!1}=e,[N,v]=(0,r.useState)("corriger"),[_,w]=(0,r.useState)(0),[k,q]=(0,r.useState)("erreur_saisie"),[$,C]=(0,r.useState)(""),[E,S]=(0,r.useState)(""),[F,A]=(0,r.useState)(!1),[L,R]=(0,r.useState)([]),[M,P]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),U=(0,r.useRef)("");(0,r.useEffect)(()=>{t&&(v("corriger"),w(0),q("erreur_saisie"),C(""),S(""),A(!1),U.current=crypto.randomUUID())},[t]);let V=(0,r.useCallback)(async()=>{P(!0),O(null);try{let e=await fetch(`${f.endpoint}/?${f.idParam}=${encodeURIComponent(String(f.idValue))}`);if(!e.ok)throw Error(`Erreur ${e.status}`);let t=await e.json();R(t.rows??[])}catch(e){O(e instanceof Error?e.message:"Erreur")}finally{P(!1)}},[f.endpoint,f.idParam,f.idValue]);(0,r.useEffect)(()=>{t&&"historique"===N&&V()},[t,N,V]);let z=f.qty_on_hand+_,I=z<0,T=(()=>{if(!j)return null;let e=E.trim().replace(",",".");if(!e)return null;let t=Number(e);return Number.isFinite(t)&&t>=0?(0,x.X4)(t):null})(),Q=j&&""!==E.trim()&&null===T,X=0!==_||null!==T,H=!F&&!I&&X&&!Q,B=async()=>{if(H){A(!0);try{let e=await fetch(`${f.endpoint}/`,{method:"POST",headers:{"Content-Type":"application/json","Idempotency-Key":U.current},body:JSON.stringify({[f.idParam]:f.idValue,delta_qty:Math.round(_),reason:k,note:$.trim()||null,new_unit_cost:T,...null!=f.color?{color:f.color}:{},...null!=f.piec?{piec:f.piec}:{}})}),t=await e.json();if(U.current=crypto.randomUUID(),409===e.status)return void u.o.error("Stock insuffisant : la quantit\xe9 ne peut pas descendre sous 0.");if(!e.ok)throw Error(t?.error||"\xc9chec de l'ajustement");u.o.success(null!==T?`Stock ajust\xe9 : ${t.qty_before} â ${t.qty_after} unit\xe9${t.qty_after>1?"s":""} \xb7 prix d'achat ${(0,h.Fb)(Number(t.cump_after)||T)}`:`Stock ajust\xe9 : ${t.qty_before} â ${t.qty_after} unit\xe9${t.qty_after>1?"s":""}`),g?.({qty_on_hand:Number(t.qty_after)||0,avg_cost:Number(t.cump_after)||0}),s()}catch(e){u.o.error(e instanceof Error?e.message:"L'ajustement a \xe9chou\xe9. R\xe9essayez.")}finally{A(!1)}}};return(0,a.jsxs)(n.aF,{open:t,onClose:s,title:"Ajuster le stock",size:"md",closeOnBackdrop:!1,children:[(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("section",{className:"rounded-xl border border-[rgba(15,23,42,0.055)] bg-surface p-4",children:[(0,a.jsxs)("p",{className:"font-semibold text-dark",children:[f.title,f.color?(0,a.jsxs)("span",{className:"ml-1 text-mint font-medium",children:["\xb7 ",f.color]}):null]}),(0,a.jsxs)("p",{className:"text-xs text-gray-500 mt-0.5 tabular-nums",children:[f.subtitlePrefix,"En stock ",f.qty_on_hand," \xb7 co\xfbt moyen ",(0,h.Fb)(f.avg_cost)]})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsx)("button",{type:"button",onClick:()=>v("corriger"),className:`h-9 px-3 rounded-full text-sm font-medium transition-colors ${"corriger"===N?"bg-coral text-white":"bg-white border border-gray-200 text-gray-text hover:border-coral"}`,children:"Corriger"}),(0,a.jsxs)("button",{type:"button",onClick:()=>v("historique"),className:`h-9 px-3 inline-flex items-center gap-1.5 rounded-full text-sm font-medium transition-colors ${"historique"===N?"bg-coral text-white":"bg-white border border-gray-200 text-gray-text hover:border-coral"}`,children:[(0,a.jsx)(d.O4,{className:"w-3.5 h-3.5"})," Historique"]})]}),"corriger"===N?(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{className:p,children:"Variation de quantit\xe9"}),(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("button",{type:"button",onClick:()=>w(e=>e-1),"aria-label":"Retirer une unit\xe9",className:"h-11 w-11 shrink-0 inline-flex items-center justify-center rounded-xl border border-gray-200 text-lg font-semibold hover:bg-gray-50 cursor-pointer",children:"â"}
1),(0,a.jsx)("input",{type:"number",step:1,value:_,onChange:e=>w(Math.round(Number(e.target.value)||0)),"aria-label":"Variation de quantit\xe9 (sign\xe9e)",className:`${b} text-center tabular-nums`}),(0,a.jsx)("button",{type:"button",onClick:()=>w(e=>e+1),"aria-label":"Ajouter une unit\xe9",className:"h-11 w-11 shrink-0 inline-flex items-center justify-center rounded-xl border border-gray-200 text-lg font-semibold hover:bg-gray-50 cursor-pointer",children:"+"})]}),(0,a.jsx)("p",{className:"mt-1 text-xs text-gray-500 tabular-nums",children:0===_?"Aucun changement de quantit\xe9.":`${f.qty_on_hand} ${_>=0?"+":"â"} ${Math.abs(_)} = ${z} unit\xe9${Math.abs(z)>1?"s":""}`})]}),j&&(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:p,children:"Prix d'achat unitaire HT (optionnel)"}),(0,a.jsx)("input",{autoFocus:y,inputMode:"decimal",value:E,onChange:e=>S(e.target.value),placeholder:f.avg_cost>0?`Actuel : ${(0,h.Fb)(f.avg_cost)}`:"Ex : 4,10","aria-invalid":Q||void 0,className:`${b} tabular-nums ${Q?"border-red-300":""}`}),(0,a.jsx)("p",{className:"mt-1 text-xs text-gray-500",children:Q?"Montant illisible : chiffres et virgule uniquement.":"Laissez vide pour conserver le co\xfbt moyen actuel. Renseign\xe9, il remplace le co\xfbt moyen de tout le stock du casier."})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsxs)("span",{className:p,children:["Motif ",(0,a.jsx)("span",{className:"text-amber-500",children:"*"})]}),(0,a.jsx)("select",{value:k,onChange:e=>q(e.target.value),className:`${b} bg-white`,children:m.Qp.map(e=>(0,a.jsx)("option",{value:e,children:f.reasonLabels[e]},e))})]}),(0,a.jsxs)("label",{className:"block",children:[(0,a.jsx)("span",{className:p,children:"Note (optionnel)"}),(0,a.jsx)("input",{value:$,onChange:e=>C(e.target.value),maxLength:500,placeholder:f.notePlaceholder,className:b})]}),X&&(0,a.jsxs)("div",{className:"rounded-xl bg-surface p-4 text-sm space-y-1",children:[(0,a.jsxs)("div",{className:"flex justify-between text-gray-500",children:[(0,a.jsx)("span",{children:"Quantit\xe9 apr\xe8s ajustement"}),(0,a.jsxs)("span",{className:"tabular-nums text-right",children:[f.qty_on_hand," â ",(0,a.jsx)("span",{className:"font-semibold text-dark",children:z})]})]}),(0,a.jsxs)("div",{className:"flex justify-between text-gray-400 text-xs",children:[(0,a.jsx)("span",{children:"Co\xfbt moyen"}),(0,a.jsxs)("span",{className:"tabular-nums text-right",children:[(0,h.Fb)(f.avg_cost)," (inchang\xe9)"]})]})]}),I&&(0,a.jsxs)("p",{className:"text-xs text-amber-600",children:["Le stock ne peut pas descendre sous 0 (disponible ",f.qty_on_hand,"). R\xe9duisez le retrait."]})]}):(0,a.jsx)("div",{children:M?(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(i.EA,{className:"h-12 w-full"}),(0,a.jsx)(i.EA,{className:"h-12 w-full"}),(0,a.jsx)(i.EA,{className:"h-12 w-full"})]}):D?(0,a.jsx)(o.W,{message:D,onRetry:V}):0===L.length?(0,a.jsx)(c.p,{icon:(0,a.jsx)(d.O4,{className:"w-7 h-7"}),title:"Aucun ajustement",description:`Les corrections de ${f.emptyDescEntity} (quantit\xe9 ou co\xfbt) s'afficheront ici.`}):(0,a.jsx)("ul",{className:"divide-y divide-gray-100 rounded-xl border border-[rgba(15,23,42,0.055)]",children:L.map(e=>{let t;return(0,a.jsxs)("li",{className:"p-3 text-sm",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,a.jsx)("span",{className:"font-semibold text-dark",children:f.reasonLabels[e.reason]??("transfert"===e.reason?"Transfert":String(e.reason))}),(0,a.jsx)("span",{className:"text-xs text-gray-400 tabular-nums shrink-0",children:(t=e.created_at)?new Date(t).toLocaleDateString("fr-FR",{day:"2-digit",month:"short",year:"numeric"}):""})]}),(0,a.jsxs)("div",{className:"mt-0.5 text-xs text-gray-500 tabular-nums flex flex-wrap gap-x-3",children:[(0,a.jsxs)("span",{children:["Qt\xe9 ",e.qty_before," â ",e.qty_after,(0,a.jsxs)("span",{className:"text-gray-400",children:[" (",e.delta_qty>=0?"+":"",e.delta_qty,")"]})]}),(0,x.X4)(e.cump_before)!==(0,x.X4)(e.cump_after)&&(0,a.jsxs)("span",{children:["Co\xfbt ",(0,h.Fb)(e.cump_before)," â ",(0,h.Fb)(e.cump_after)]})]}),e.note&&(0,a.jsx)("p",{className:"mt-1 text-xs text-gray-400",children:e.note})]},e.id)})})})]}),(0,a.jsxs)(n.jl,{children:[(0,a.jsx)(l.$,{variant:"secondary",onClick:s,className:"w-full sm:w-auto",children:"Fermer"}),"corriger"===N&&(0,a.jsx)(l.$,{variant:"primary",onClick:B,loading:F,disabled:!H,className:"w-full sm:w-auto",children:"Enregistrer l'ajustement"})]})]})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.