vendor: 4,732 bytes, lines 1-11
1import{c as we,F as Pe,r,G as _e,H as Ie,j as e,J as ke,K as be,N as Oe,x as Ce,C as ze,f as Me,e as le,s as Y,a as A,b as Fe,L as Ke,B as d,I as P,M as He,t as U}from"./index-BK1sFRZj.js";import{C as S,a as E,b as F,c as K}from"./card-BeHTkU89.js";import{u as Ue,e as Ve,S as oe,a as de,b as ue,c as me,d as _}from"./select-CoDbtEwq.js";import{D as Q,a as Z,b as X,c as G}from"./dialog-Dlan3cK0.js";import{T as Be,a as Je,b as B,c as J}from"./tabs-D8EJYn1T.js";import{T as ne,a as re,b as V,c as N,d as ie,e as w}from"./table-DQNpo3KR.js";import{T as Qe}from"./textarea-4Wp5-Fkf.js";import{Z as Ze}from"./zap-DNf7QcBe.js";import{L as Xe}from"./link-2-CoiFlkpy.js";import{U as Ge}from"./upload-2J3xhVSd.js";import{E as We}from"./eye-D2XLq0GA.js";import{R as Ne}from"./refresh-cw-DSqJpxSP.js";import{D as ce}from"./download-CC3LER-Z.js";import{T as Ye}from"./trash-2-CwA3J-i0.js";import{S as et}from"./shield-Dvvsu2ef.js";import"./index-Dk8kPU04.js";import"./chevron-down-JNotcG1N.js";import"./chevron-up-6qfqPAup.js";/** 2 * @license lucide-react v0.453.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const tt=we("FileSearch",[["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4.268 21a2 2 0 0 0 1.727 1H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"ms7g94"}],["path",{d:"m9 18-1.5-1.5",key:"1j6qii"}],["circle",{cx:"5",cy:"14",r:"3",key:"ufru5t"}]]);/** 7 * @license lucide-react v0.453.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const st=we("Unlink",[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]]);var he="Checkbox",[at,Lt]=Pe(he),[nt,rt]=at(he),Se=r.forwardRef((s,x)=>{const{__scopeCheckbox:a,name:p,checked:h,defaultChecked:u,required:y,disabled:m,value:v="on",onCheckedChange:j,form:f,...g}=s,[l,n]=r.useState(null),k=_e(x,C=>n(C)),L=r.useRef(!1),i=l?f||!!l.closest("form"):!0,[b=!1,I]=Ie({prop:h,defaultProp:u,onChange:j}),T=r.useRef(b);return r.useEffect(()=>{const C=l==null?void 0:l.form;if(C){const $=()=>I(T.current);return C.addEventListener("reset",$),()=>C.removeEventListener("reset",$)}},[l,I]),e.jsxs(nt,{scope:a,state:b,disabled:m,children:[e.jsx(ke.button,{type:"button",role:"checkbox","aria-checked":H(b)?"mixed":b,"aria-required":y,"data-state":Re(b),"data-disabled":m?"":void 0,disabled:m,value:v,...g,ref:k,onKeyDown:be(s.onKeyDown,C=>{C.key==="Enter"&&C.preventDefault()}),onClick:be(s.onClick,C=>{I($=>H($)?!0:!$),i&&(L.current=C.isPropagationStopped(),L.current||C.stopPropagation())})}),i&&e.jsx(it,{control:l,bubbles:!L.current,name:p,value:v,checked:b,required:y,disabled:m,form:f,style:{transform:"translateX(-100%)"},defaultChecked:H(u)?!1:u})]})});Se.displayName=he;var Ee="CheckboxIndicator",Te=r.forwardRef((s,x)=>{const{__scopeCheckbox:a,forceMount:p,...h}=s,u=rt(Ee,a);return e.jsx(Oe,{present:p||H(u.state)||u.state===!0,children:e.jsx(ke.span,{"data-state":Re(u.state),"data-disabled":u.disabled?"":void 0,...h,ref:x,style:{pointerEvents:"none",...s.style}})})});Te.displayName=Ee;var it=s=>{const{control:x,checked:a,bubbles:p=!0,defaultChecked:h,...u}=s,y=r.useRef(null),m=Ue(a),v=Ve(x);r.useEffect(()=>{const f=y.current,g=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(g,"checked").set;if(m!==a&&n){const k=new Event("click",{bubbles:p});f.indeterminate=H(a),n.call(f,H(a)?!1:a),f.dispatchEvent(k)}},[m,a,p]);const j=r.useRef(H(a)?!1:a);return e.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:h??j.current,...u,tabIndex:-1,ref:y,style:{...s.style,...v,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})};function H(s){return s==="indeterminate"}function Re(s){return H(s)?"indeterminate":s?"checked":"unchecked"}var qe=Se,ct=Te;const Le=r.forwardRef(({className:s,...x},a)=>e.jsx(qe,{ref:a,className:Ce("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s),...x,children:e.jsx(ct,{className:Ce("flex items-center justify-center text-current"),children:e.jsx(ze,{className:"h-4 w-4"})})}));
11Le.displayName=qe.displayName;const c="/api/bank",lt=s=>Array.isArray(s==null?void 0:s.permissions)&&s.permissions.includes("rapprochement_bancaire"),D=s=>Number(s||0).toLocaleString("fr-FR",{style:"currency",currency:"EUR"}),M=s=>s?new Date(s).toLocaleDateString("fr-FR"):"â";function ot(){return e.jsx("div",{className:"flex min-h-[55vh] items-center justify-center text-center",children:e.jsxs("div",{children:[e.jsx(et,{className:"mx-auto mb-4 h-12 w-12 text-muted-foreground"}),e.jsx("h1",{className:"text-2xl font-bold",children:"Accès non autorisé"}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"Permission rapprochement bancaire requise."})]})})}function $t(){var je,fe,ve,ge,ye;const{user:s,isLoading:x}=Me(),a=lt(s),p=le(),{toast:h}=Y(),[u,y]=r.useState(""),[m,v]=r.useState(""),[j,f]=r.useState("all"),[g,l]=r.useState(null),[n,k]=r.useState(null),[L,i]=r.useState(null),[b,I]=r.useState(!1),[T,C]=r.useState(null),$=A({queryKey:[c+"/rapprochements"],enabled:a}),xe=A({queryKey:[c+"/justificatifs"],enabled:a}),$e=A({queryKey:[c+"/statements"],enabled:a}),ee=A({queryKey:[c+"/email-import/status"],enabled:a}),Ae=A({queryKey:[c+"/email-import/history"],enabled:a}),pe=A({queryKey:[c+"/conflicts"],enabled:a&&b});A({queryKey:[c+"/transactions",u,m,j],queryFn:async()=>{const t=new URLSearchParams({limit:"500"});u&&t.set("search",u),m&&t.set("category",m),j!=="all"&&t.set("visible",j);const o=await fetch(`${c}/transactions?${t}`,{credentials:"include"});if(!o.ok)throw new Error("Transactions indisponibles");return o.json()},enabled:a});const te=()=>{["/rapprochements","/justificatifs","/statements","/email-import/history","/email-import/status"].forEach(t=>p.invalidateQueries({queryKey:[c+t]}))},R=Fe({mutationFn:async({method:t="POST",path:o,data:O})=>{var q;const z=await U(t,c+o,O);return(q=z.headers.get("content-type"))!=null&&q.includes("json")?z.json():null},onSuccess:()=>{te(),h({title:"Opération effectuée"})},onError:t=>h({title:"Erreur",description:t.message,variant:"destructive"})}),se=r.useMemo(()=>{var t;return(((t=$.data)==null?void 0:t.transactions)||[]).filter(o=>`${o.description} ${o.amount} ${o.justificatifName||""}`.toLowerCase().includes(u.toLowerCase()))},[$.data,u]),De=async()=>{var t;if(T!=null&&T.length)try{const o=new FormData;Array.from(T).forEach(q=>o.append("files",q));const O=await fetch(`${c}/justificatifs/upload`,{method:"POST",credentials:"include",body:o}),z=await O.json();if(!O.ok)throw new Error(z.message||"Envoi impossible");C(null),te(),h({title:"Justificatifs importés",description:(t=z.results)==null?void 0:t.map(q=>`${q.filename}: ${q.status}`).join(" · ")})}catch(o){h({title:"Erreur",description:o.message,variant:"destructive"})}},W=async(t,o)=>{try{const O=await fetch(c+t,{credentials:"include"});if(!O.ok)throw new Error("Téléchargement impossible");const z=URL.createObjectURL(await O.blob()),q=document.createElement("a");q.href=z,q.download=o,q.click(),URL.revokeObjectURL(z)}catch(O){h({title:"Erreur",description:O.message,variant:"destructive"})}};if(x)return null;if(!a)return e.jsx(ot,{});const ae=((je=$.data)==null?void 0:je.unmatched_justificatifs)||(xe.data||[]).filter(t=>!t.rapprochementCount);return e.jsxs("div",{className:"container mx-auto max-w-7xl space-y-6 px-4 py-8",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Rapprochements bancaires"}),e.jsx("p",{className:"text-muted-foreground",children:"Justificatifs, transactions, trésorerie et imports e-mail â LâAérosol Marseille."})]}),e.jsx(Ke,{href:"/admin-banque",children:e.jsx(d,{variant:"outline",children:"Configuration bancaire"})})]}),e.jsxs(Be,{defaultValue:"reconcile",children:[e.jsxs(Je,{className:"grid h-auto w-full grid-cols-2 md:grid-cols-5",children:[e.jsx(B,{value:"reconcile",children:"Rapprocher"}),e.jsx(B,{value:"justifs",children:"Justificatifs"}),e.jsx(B,{value:"statements",children:"Relevés"}),e.jsx(B,{value:"cashflow",children:"Trésorerie"}),e.jsx(B,{value:"email",children:"E-mail"})]}),e.jsxs(J,{value:"reconcile",className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(S,{children:e.jsxs(E,{className:"pt-5",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Transactions"}),e.jsx("p",{className:"text-2xl font-bold",children:((fe=$.data)==null?void 0:fe.total)??se.length})]})}),e.jsx(S,{children:e.jsxs(E,{className:"pt-5",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Justificatifs à traiter"}),e.jsx("p",{className:"text-2xl font-bold",children:ae.length})]})}),e.jsx(S,{children:e.jsxs(E,{className:"flex gap-2 pt-5",children:[e.jsxs(d,{size:"sm",onClick:()=>R.mutate({path:"/rapprochements/auto-match"}),children:[e.jsx(Ze,{className:"mr-1 h-4 w-4"}),"Rapprocher automatiquement"]}),e.jsx(d,{size:"sm",variant:"outline",onClick:()=>I(!0),children:"Conflits candidats"})]})})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs(S,{children:[e.jsxs(F,{children:[e.jsx(K,{className:"text-lg",children:"Transactions"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{placeholder:"Rechercherâ¦",value:u,onChange:t=>y(t.target.value)}),e.jsx(P,{placeholder:"Catégorie",value:m,onChange:t=>v(t.target.value)}),e.jsxs(oe,{value:j,onValueChange:f,children:[e.jsx(de,{className:"w-32",children:e.jsx(ue,{})}),e.jsxs(me,{children:[e.jsx(_,{value:"all",children:"Toutes"}),e.jsx(_,{value:"true",children:"Visibles"}),e.jsx(_,{value:"false",children:"Masquées"})]})]})]})]}),e.jsx(E,{className:"max-h-[540px] overflow-auto p-0",children:e.jsxs(ne,{children:[e.jsx(re,{children:e.jsxs(V,{children:[e.jsx(N,{children:"Date"}),e.jsx(N,{children:"Libellé"}),e.jsx(N,{children:"Montant"}),e.jsx(N,{children:"Justificatif"})]})}),e.jsx(ie,{children:se.filter(t=>!m||t.category===m).filter(t=>j==="all"||String(t.visible!==!1)===j).map(t=>e.jsxs(V,{className:t.rapprochementId?"bg-green-50/60":"",children:[e.jsx(w,{children:M(t.date||t.transactionDate)}),e.jsxs(w,{className:"max-w-[200px] truncate",children:[t.description,e.jsxs("div",{className:"mt-1 flex gap-1",children:[e.jsx(P,{className:"h-6 w-28 text-xs",defaultValue:t.category||"",placeholder:"Catégorie",onBlur:o=>o.target.value!==(t.category||"")&&R.mutate({method:"PATCH",path:`/transactions/${t.id}`,data:{category:o.target.value||null}})}),e.jsx(Le,{checked:t.visible!==!1,onCheckedChange:o=>R.mutate({method:"PATCH",path:`/transactions/${t.id}`,data:{visible:o===!0}})})]})]}),e.jsx(w,{children:D(t.amount)}),e.jsx(w,{children:t.justificatifName?e.jsxs("span",{children:[t.justificatifName," ",e.jsx(d,{variant:"ghost",size:"icon",onClick:()=>R.mutate({method:"DELETE",path:`/rapprochements/${t.rapprochementId}`}),children:e.jsx(st,{className:"h-3 w-3"})}),e.jsx(ut,{transactionId:t.id})]}):e.jsx(d,{size:"sm",variant:"outline",onClick:()=>
11l(ae[0]||null),children:"Lier"})})]},t.id))})]})})]}),e.jsxs(S,{children:[e.jsx(F,{children:e.jsx(K,{className:"text-lg",children:"à rapprocher"})}),e.jsx(E,{className:"space-y-2",children:ae.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded border p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate font-medium",children:t.originalName}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.extractedEmitter||"Ãmetteur inconnu"," · ",M(t.extractedDate)," · ",D(t.extractedAmount||t.totalAmount)]})]}),e.jsxs(d,{size:"sm",onClick:()=>l(t),children:[e.jsx(Xe,{className:"mr-1 h-4 w-4"}),"Lier"]})]},t.id))})]})]})]}),e.jsxs(J,{value:"justifs",className:"space-y-4",children:[e.jsxs(S,{children:[e.jsx(F,{children:e.jsx(K,{children:"Importer plusieurs justificatifs"})}),e.jsxs(E,{className:"flex gap-2",children:[e.jsx(P,{type:"file",accept:"application/pdf,image/jpeg,image/png,image/webp",multiple:!0,onChange:t=>C(t.target.files)}),e.jsxs(d,{disabled:!(T!=null&&T.length),onClick:De,children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),"Envoyer"]})]})]}),e.jsxs(S,{children:[e.jsx(F,{children:e.jsx(K,{children:"Justificatifs et OCR"})}),e.jsx(E,{className:"p-0",children:e.jsxs(ne,{children:[e.jsx(re,{children:e.jsxs(V,{children:[e.jsx(N,{children:"Document"}),e.jsx(N,{children:"OCR"}),e.jsx(N,{children:"Ãmetteur / date"}),e.jsx(N,{children:"Montant"}),e.jsx(N,{children:"Actions"})]})}),e.jsx(ie,{children:(xe.data||[]).map(t=>e.jsxs(V,{children:[e.jsxs(w,{children:[t.originalName||t.original_name,t.children_count?e.jsxs("span",{className:"ml-1 text-xs text-muted-foreground",children:["(",t.children_count," enfant(s))"]}):null]}),e.jsx(w,{children:t.ocrStatus||t.ocr_status}),e.jsxs(w,{children:[t.extractedEmitter||t.vendor||"â"," · ",M(t.extractedDate||t.invoiceDate||t.invoice_date)]}),e.jsx(w,{children:D(t.extractedAmount||t.totalAmount||t.amount)}),e.jsxs(w,{className:"whitespace-nowrap",children:[e.jsx(d,{variant:"ghost",size:"icon",onClick:()=>k(t),children:e.jsx(We,{className:"h-4 w-4"})}),e.jsx(d,{variant:"ghost",size:"icon",onClick:()=>i(t),children:e.jsx(tt,{className:"h-4 w-4"})}),e.jsx(d,{variant:"ghost",size:"icon",title:"Relancer lâOCR",onClick:()=>R.mutate({path:`/justificatifs/${t.id}/retry-ocr`}),children:e.jsx(Ne,{className:"h-4 w-4"})}),e.jsx(d,{variant:"ghost",size:"icon",onClick:()=>W(`/justificatifs/${t.id}/download`,t.originalName||t.original_name||"justificatif"),children:e.jsx(ce,{className:"h-4 w-4"})}),e.jsx(d,{variant:"ghost",size:"icon",onClick:()=>R.mutate({method:"DELETE",path:`/justificatifs/${t.id}`}),children:e.jsx(Ye,{className:"h-4 w-4 text-destructive"})})]})]},t.id))})]})})]})]}),e.jsx(J,{value:"statements",children:e.jsxs(S,{children:[e.jsx(F,{children:e.jsx(K,{children:"Relevés importés"})}),e.jsx(E,{className:"p-0",children:e.jsxs(ne,{children:[e.jsx(re,{children:e.jsxs(V,{children:[e.jsx(N,{children:"Fichier"}),e.jsx(N,{children:"Période"}),e.jsx(N,{children:"Transactions"}),e.jsx(N,{children:"Statut"}),e.jsx(N,{})]})}),e.jsx(ie,{children:($e.data||[]).map(t=>e.jsxs(V,{children:[e.jsx(w,{children:t.filename}),e.jsxs(w,{children:[M(t.startDate)," â ",M(t.endDate)]}),e.jsx(w,{children:t.transactionCount}),e.jsx(w,{children:t.status}),e.jsx(w,{children:e.jsx(d,{size:"sm",variant:"outline",onClick:()=>W(`/statements/${t.id}/download`,t.filename),children:"Télécharger"})})]},t.id))})]})})]})}),e.jsx(J,{value:"cashflow",children:e.jsx(mt,{allowed:a})}),e.jsxs(J,{value:"email",className:"space-y-4",children:[e.jsxs(S,{children:[e.jsx(F,{children:e.jsx(K,{children:"Import e-mail de justificatifs"})}),e.jsxs(E,{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Statut : ",(ve=ee.data)!=null&&ve.configured?"configuré":"non configuré"," ",(ge=ee.data)!=null&&ge.lastImportAt?`· dernier import ${M(ee.data.lastImportAt)}`:""]}),e.jsxs(d,{onClick:()=>R.mutate({path:"/email-import/run"}),children:[e.jsx(He,{className:"mr-2 h-4 w-4"}),"Importer maintenant"]}),e.jsx(d,{variant:"outline",onClick:()=>R.mutate({path:"/email-import/test"}),children:"Tester la connexion"}),e.jsxs(d,{variant:"outline",onClick:()=>R.mutate({path:"/email-import/retry-traites"}),children:[e.jsx(Ne,{className:"mr-2 h-4 w-4"}),"Réessayer les traités"]}),e.jsxs(d,{variant:"outline",onClick:()=>W("/export-zip","export-rapprochements.zip"),children:[e.jsx(ce,{className:"mr-2 h-4 w-4"}),"Exporter ZIP"]}),e.jsxs(d,{variant:"outline",onClick:()=>W("/export-zip?sinceLastExport=true","export-rapprochements-depuis-dernier-export.zip"),children:[e.jsx(ce,{className:"mr-2 h-4 w-4"}),"Depuis le dernier export"]})]})]}),e.jsxs(S,{children:[e.jsx(F,{children:e.jsx(K,{children:"Historique"})}),e.jsx(E,{children:(Ae.data||[]).map((t,o)=>e.jsxs("p",{className:"border-b py-2 text-sm",children:[M(t.createdAt||t.importedAt)," â ",t.status||"Terminé"," â ",t.importedCount??t.count??0," document(s)"]},t.id||o))})]})]})]}),e.jsx(Q,{open:!!g,onOpenChange:t=>!t&&l(null),children:e.jsxs(Z,{children:[e.jsx(X,{children:e.jsx(G,{children:"Lier un justificatif"})}),e.jsx("p",{className:"font-medium",children:g==null?void 0:g.originalName}),e.jsx("div",{className:"max-h-80 overflow-auto space-y-2",children:se.filter(t=>!t.rapprochementId).map(t=>e.jsxs(d,{variant:"outline",className:"w-full justify-between",onClick:()=>{g&&R.mutate({path:"/rapprochements",data:{transactionId:t.id,justificatifId:g.id}}),l(null)},children:[t.description,e.jsx("span",{children:D(t.amount)})]},t.id))})]})}),e.jsx(Q,{open:b,onOpenChange:I,children:e.jsxs(Z,{className:"max-w-2xl",children:[e.jsx(X,{children:e.jsx(G,{children:"Conflits de rapprochement"})}),e.jsxs("div",{className:"max-h-[60vh] space-y-4 overflow-auto",children:[(pe.data||[]).map(t=>e.jsxs("div",{className:"rounded border p-3",children:[e.jsxs("p",{className:"font-medium",children:[t.original_name," · ",D(t.amount)]}),e.jsxs("p",{className:"mb-2 text-xs text-muted-foreground",children:[t.vendor||"Ãmetteur inconnu"," · ",M(t.invoice_date)]}),(t.candidates||[]).map(o=>e.jsxs(d,{variant:"outline",className:"mb-1 mr-1",onClick:()=>R.mutate({path:"/rapprochements",data:{transactionId:o.id,justificatifId:t.justificatif_id,matchType:"manual"}}),children:[o.description," â ",D(o.amount)]},o.id))]},t.justificatif_id)),!((ye=pe.data)!=null&&ye.length)&&e.jsx("p",{className:"text-muted-foreground",children:"Aucun conflit détecté."})]})]})}),e.jsx(Q,{open:!!n,onOpenChange:t=>!t&&k(null),children:e.jsxs(Z,{className:"max-w-5xl",children:[e.jsx(X,{children:e.jsx(G,{children:n==null?void 0:n.originalName})}),n&&e.jsx("iframe",{className:"h-[70vh] w-full bg-muted",title:"Aperçu privé du justificatif",src:`${c}/justificatifs/${n.id}/download`})]})}),e.jsx(Q,{open:!!L,onOpenChange:t=>!t&&i(null),children:e.jsxs(Z,{children:[e.jsx(X,{children:e.jsx(G,{children:"Corriger les données OCR"})}),L&&e.jsx(dt,{justif:L,done:()=>{i(null),te()}})]})})]})}function dt({justif:s,done:x}){const[a,p]=r.useState(s.vendor||s.extractedEmitter||""),[h,u]=r.useState(s.invoiceDate||s.invoice_date||s.extractedDate||""),[y,m]=r.useState(String(s.amount||s.extractedAmount||s.totalAmount||"")),[v,j]=r.useState(""),{toast:f}=Y(),g=async()=>{try{await U("PATCH",`${c}/justificatifs/${s.id}`,{vendor:a,invoiceDate:h,amount:y,notes:v}),f({title:"Correction enregistrée"}),x()}catch(l){f({title:"Erreur",description:l.message,variant:"destructive"})}};return e.jsxs("div",{className:"space-y-3",children:[e.jsx(P,{value:a,onChange:l=>p(l.target.value),placeholder:"Ãmetteur"}),e.jsx(P,{type:"date",value:h==null?void 0:h.slice(0,10),onChange:l=>u(l.target.value)}),e.jsx(P,{value:y,onChange:l=>m(l.target.value),placeholder:"Montant"}
11),e.jsx(Qe,{value:v,onChange:l=>j(l.target.value),placeholder:"Notes"}),e.jsx(d,{className:"w-full",onClick:g,children:"Enregistrer"})]})}function ut({transactionId:s}){const[x,a]=r.useState(!1),[p,h]=r.useState("billing_invoice"),[u,y]=r.useState(""),m=le(),{toast:v}=Y(),j=A({queryKey:[c+"/external-links",s],queryFn:async()=>(await fetch(`${c}/external-links?transactionId=${s}`,{credentials:"include"})).json(),enabled:x}),f=A({queryKey:[c+`/lookups/${p==="pos_order"?"orders":"invoices"}`,u],queryFn:async()=>(await fetch(`${c}/lookups/${p==="pos_order"?"orders":"invoices"}?search=${encodeURIComponent(u)}`,{credentials:"include"})).json(),enabled:x}),g=async n=>{try{await U("POST",`${c}/external-links`,{transactionId:s,targetType:p,targetId:n}),m.invalidateQueries({queryKey:[c+"/external-links",s]}),v({title:"Lien externe créé"})}catch(k){v({title:"Erreur",description:k.message,variant:"destructive"})}},l=async n=>{try{await U("DELETE",`${c}/external-links/${n}`),m.invalidateQueries({queryKey:[c+"/external-links",s]}),v({title:"Lien externe supprimé"})}catch(k){v({title:"Erreur",description:k.message,variant:"destructive"})}};return e.jsxs(e.Fragment,{children:[e.jsx(d,{size:"sm",variant:"ghost",onClick:()=>a(!0),children:"Liens"}),e.jsx(Q,{open:x,onOpenChange:a,children:e.jsxs(Z,{children:[e.jsx(X,{children:e.jsx(G,{children:"Lier à une facture ou commande"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(oe,{value:p,onValueChange:n=>h(n),children:[e.jsx(de,{children:e.jsx(ue,{})}),e.jsxs(me,{children:[e.jsx(_,{value:"billing_invoice",children:"Facture"}),e.jsx(_,{value:"manual_invoice",children:"Facture manuelle"}),e.jsx(_,{value:"pos_order",children:"Commande POS"})]})]}),e.jsx(P,{value:u,onChange:n=>y(n.target.value),placeholder:"Rechercher"})]}),e.jsx("div",{className:"max-h-40 overflow-auto",children:(f.data||[]).map(n=>e.jsxs(d,{className:"mb-1 w-full justify-between",variant:"outline",onClick:()=>g(n.id),children:[n.number||n.orderNumber||`#${n.id}`,e.jsx("span",{children:n.totalTtc?D(n.totalTtc):n.totalCents?D(n.totalCents/100):""})]},n.id))}),e.jsx("div",{className:"border-t pt-2",children:(j.data||[]).map(n=>e.jsxs("div",{className:"flex justify-between py-1 text-sm",children:[e.jsxs("span",{children:[n.target_type," #",n.target_id]}),e.jsx(d,{size:"sm",variant:"ghost",onClick:()=>l(n.id),children:"Supprimer"})]},n.id))})]})})]})}function mt({allowed:s}){var k,L;const x=le(),{toast:a}=Y(),[p,h]=r.useState(""),[u,y]=r.useState(""),[m,v]=r.useState("monthly"),j=A({queryKey:[c+"/treso"],enabled:s}),f=()=>{x.invalidateQueries({queryKey:[c+"/treso"]}),x.invalidateQueries({queryKey:[c+"/cash-flow"]})},g=async()=>{try{await U("POST",c+"/cash-flow",{label:p,amount:-Math.abs(Number(u)),frequency:m,category:"autre"}),h(""),y(""),f(),a({title:"Ãlément récurrent ajouté"})}catch(i){a({title:"Erreur",description:i.message,variant:"destructive"})}},l=async i=>{const b=window.prompt("Libellé",i.label),I=window.prompt("Montant",i.amount);if(!(!b||I===null))try{await U("PATCH",`${c}/cash-flow/${i.id}`,{label:b,amount:Number(I),frequency:i.frequency,category:i.category,isActive:i.is_active??!0}),f(),a({title:"Ãlément mis à jour"})}catch(T){a({title:"Erreur",description:T.message,variant:"destructive"})}},n=async i=>{if(window.confirm("Supprimer cet élément récurrent ?"))try{await U("DELETE",`${c}/cash-flow/${i}`),f(),a({title:"Ãlément supprimé"})}catch(b){a({title:"Erreur",description:b.message,variant:"destructive"})}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(S,{children:[e.jsx(F,{children:e.jsx(K,{children:"Trésorerie et sorties récurrentes"})}),e.jsxs(E,{className:"flex flex-wrap gap-2",children:[e.jsx(P,{className:"w-52",placeholder:"Libellé",value:p,onChange:i=>h(i.target.value)}),e.jsx(P,{className:"w-32",type:"number",placeholder:"Montant",value:u,onChange:i=>y(i.target.value)}),e.jsxs(oe,{value:m,onValueChange:v,children:[e.jsx(de,{className:"w-36",children:e.jsx(ue,{})}),e.jsxs(me,{children:[e.jsx(_,{value:"monthly",children:"Mensuel"}),e.jsx(_,{value:"quarterly",children:"Trimestriel"}),e.jsx(_,{value:"annual",children:"Annuel"}),e.jsx(_,{value:"once",children:"Ponctuel"})]})]}),e.jsx(d,{onClick:g,children:"Ajouter"})]})]}),e.jsx(S,{children:e.jsxs(E,{className:"pt-5",children:[e.jsxs("p",{className:"mb-3 text-sm text-muted-foreground",children:["Solde bancaire visible : ",D((k=j.data)==null?void 0:k.bankBalance)]}),e.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"Ãléments manuels"}),(((L=j.data)==null?void 0:L.manualItems)||[]).map(i=>e.jsxs("div",{className:"flex items-center justify-between border-b py-2",children:[e.jsxs("span",{children:[i.label," · ",i.frequency]}),e.jsxs("span",{className:"flex items-center gap-1",children:[D(i.amount),e.jsx(d,{size:"sm",variant:"ghost",onClick:()=>l(i),children:"Modifier"}),e.jsx(d,{size:"sm",variant:"ghost",className:"text-destructive",onClick:()=>n(i.id),children:"Supprimer"})]})]},i.id))]})})]})}export{$t as default};
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.