import{_ as le}from"./Imprimer-Bot4QNbk.js";import{af as re,f as ie,o as i,c as p,b as n,a as u,z as ue,av as ce,i as B,q as w,d as y,E as h,B as m,aP as de,M as pe,ax as me,F as L,A as fe,r as a}from"./vendor-BDR7yMJi.js";import{_ as ve}from"./ComboDynamique-DbhbUtR4.js";import{_ as _e}from"./selectDate-Dd47YHbm.js";import{_ as xe}from"./FavorisSwitch-DFHH_fud.js";import{u as ge,a as A,s as c,S as E,h as f}from"./index-BSaHX2oa.js";import{_ as we}from"./DataGrid-DbeHIyBR.js";import"./ReportViewer-Cmd4kpyP.js";import"./EnvoieDocumentsMail-P3u1QAl1.js";import"./useAgGridConfig-DxO2r97K.js";const ye={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},he={class:"btns flex items-center gap-2 lg:w-1/4 lg:justify-start lg:ml-0"},be={class:"flex items-center gap-3 lg:w-1/4 lg:justify-end whitespace-nowrap"},Se={key:0,class:"text-right"},$e={class:"flex flex-wrap gap-3 px-4 items-end"},ke={class:"flex flex-col w-full sm:w-auto sm:min-w-48"},Ce={class:"flex flex-col w-full sm:w-auto"},De={class:"flex flex-col w-full sm:w-auto"},Ne={class:"flex flex-col w-full sm:w-auto"},Re={class:"flex flex-col justify-end w-full sm:w-auto"},Fe={key:0,style:{height:"calc(100vh - 240px)"}},Ve={key:1,class:"overflow-y-auto px-8 py-3 flex flex-col gap-1",style:{height:"calc(100vh - 240px)"}},Ie={key:0,class:"text-center text-gray-400 py-10"},ze={class:"flex items-center justify-between"},Be={class:"text-sm text-gray-500"},Le={class:"flex items-center justify-between"},Ae={class:"text-sm text-gray-800 truncate flex-1 mr-3"},Ke={__name:"SituationBancaire",props:{masquerFermer:{type:Boolean,default:!1}},setup(M){const{showError:v,showWarn:k}=ge(),b=a(),j=a(),P=a([]),_=a(!1),l=a([]),C=a(),S=a(""),D=a(""),N=a(""),x=a(null),$=a(1),T=[{Id:1,Libelle:"Réel"},{Id:2,Libelle:"Théorique"},{Id:3,Libelle:"Prévisionnel"}],g=a("0.00"),R=a(window.innerWidth>=1024),F=()=>{R.value=window.innerWidth>=1024};window.addEventListener("resize",F),re(()=>window.removeEventListener("resize",F));const q=t=>{if(!t)return"";const e=new Date(t);return isNaN(e)?t:e.toLocaleDateString("fr-FR",{day:"2-digit",month:"2-digit",year:"numeric"})},U=t=>{const e=parseFloat(t);return isNaN(e)||e===0?"text-gray-500":e>0?"text-green-600":"text-red-600"},G=t=>{const e=parseFloat(t);return isNaN(e)||e===0?"":e>0?"▲":"▼"},W=t=>{const e=t.value||"",o=parseInt(t.data?.typeSituation),d=new Date(t.data?.date_ech),r=new Date;return r.setHours(0,0,0,0),o>=2&&d>r?`<span style="border-left:4px solid #8b5cf6;padding-left:8px">${e} <span style="color:#6d28d9;font-size:11px;font-weight:600">● Prévisionnel</span></span>`:o===2?`<span style="border-left:4px solid #eab308;padding-left:8px">${e} <span style="color:#a16207;font-size:11px;font-weight:600">● Théorique</span></span>`:e},H=(t,e)=>{const o=parseInt(t.typeSituation),d=new Date(t.date_ech),r=new Date;return r.setHours(0,0,0,0),o>=2&&d>r?"bg-violet-50":o===2?"bg-yellow-50":e%2===0?"bg-white":"bg-blue-50"},K=t=>{if(t.value==null||t.value==="")return"";const e=parseFloat(t.value);if(isNaN(e)||e===0)return"";const o=f(Math.abs(e)),d=e>0?"#16a34a":"#dc2626",r=e>0?"▲":"▼";return`<span style="color:${d};font-weight:600">${r} ${o}</span>`},O=t=>{if(t.value==null||t.value==="")return"";const e=parseFloat(t.value);if(isNaN(e))return"";const o=f(e);return`<span style="color:${e>=0?"#1d4ed8":"#dc2626"};font-weight:700">${o}</span>`},J=({event:t,ndoc:e})=>{},Q=({selectedRows:t})=>{P.value=t},X=t=>{j.value=t.api},Y=(t,e)=>{D.value=t,N.value=e};ie(async()=>{await Z()});const Z=async()=>{try{const e=(await A.post(`${c.lienApi}/verifierDroit/${c.state.dbCommun6}`,{id_utilisateur:c.userId,id_page:708,mail:c.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(k("Vous n'avez pas le droit, veuillez consulter l'administrateur"),E("SituationBancaire")))}catch(t){v(`Une erreur s'est produite lors de la vérification des droits.
 ${t}`)}},V=async()=>{if(!x.value){k("Veuillez sélectionner un compte bancaire");return}c.state.afficher_in_progress=!0;try{const t=await A.post(`${c.lienApi}/situationBancaire/${c.db}`,{IDcompte:x.value,Sai_date_du:D.value,Sai_date_Au:N.value,typeSituation:$.value,rechercheString:S.value||""},{headers:{"Content-Type":"application/json"}});l.value=t.data.map(o=>({...o,montant:(parseFloat(o.credit)||0)-(parseFloat(o.debit)||0)}));const e=[...l.value].reverse().find(o=>parseInt(o.typeSituation)===1);g.value=e?.solde_cumul||l.value[l.value.length-1]?.solde_cumul||0}catch(t){const e=t.response?.data?.message||t.message;v("Une erreur est survenue : "+e)}finally{c.state.afficher_in_progress=!1}},ee=()=>{_.value=!0},te=()=>{if(!b.value){v("Grille non initialisée");return}if(l.value.length===0){v("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");b.value.exportToExcel(`Situation_bancaire_${c.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const o=ue,d=ce,r=xe,I=pe,ne=_e,se=ve,oe=me,ae=le;return i(),p(L,null,[n("div",ye,[n("div",he,[u(o,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[0]||(e[0]=s=>C.value.toggle(s))}),u(d,{ref_key:"actionsMenu",ref:C,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>te()},{label:"Imprimer",icon:"pi pi-print",command:()=>ee()}],popup:!0,class:"p-menu-text"},null,8,["model"]),M.masquerFermer?y("",!0):(i(),B(o,{key:0,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=s=>w(E)("SituationBancaire"))}))]),e[9]||(e[9]=n("div",{class:"w-full lg:w-2/4"},null,-1)),n("div",be,[u(r,{fen:"SituationBancaire",text:"Situation bancaire"}),g.value!=="0.00"?(i(),p("div",Se,[e[8]||(e[8]=n("span",{class:"text-sm text-gray-600"},"Solde actuel:",-1)),n("div",{class:h(["text-lg font-bold",parseFloat(g.value)>=0?"text-blue-700":"text-red-600"])},m(w(f)(g.value)),3)])):y("",!0)])]),n("div",$e,[n("div",ke,[e[10]||(e[10]=n("label",{class:"text-sm"},"Recherche",-1)),u(I,{size:"small",modelValue:S.value,"onUpdate:modelValue":e[2]||(e[2]=s=>S.value=s),placeholder:"Rechercher...",class:"w-full",onKeyup:e[3]||(e[3]=de(s=>V(),["enter"]))},null,8,["modelValue"])]),n("div",Ce,[e[11]||(e[11]=n("label",{class:"text-sm"},"Période",-1)),u(ne,{onSelectDate:Y,defaultPeriod:"month"})]),n("div",De,[e[12]||(e[12]=n("label",{class:"text-sm"},"Compte",-1)),u(se,{modelValue:x.value,"onUpdate:modelValue":e[4]||(e[4]=s=>x.value=s),placeholder:"Sélectionner...",table:"compte_bancaire",class:"w-full sm:w-48"},null,8,["modelValue"])]),n("div",Ne,[e[13]||(e[13]=n("label",{class:"text-sm"},"Type",-1)),u(oe,{size:"small",modelValue:$.value,"onUpdate:modelValue":e[5]||(e[5]=s=>$.value=s),options:T,optionLabel:"Libelle",optionValue:"Id",placeholder:"Sélectionner...",class:"w-full sm:w-32"},null,8,["modelValue"])]),n("div",Re,[e[14]||(e[14]=n("div",{class:"h-2"},null,-1)),u(o,{size:"small",icon:"pi pi-search",label:"Afficher",class:"whitespace-nowrap w-full sm:w-auto",onClick:e[6]||(e[6]=s=>V())})])]),e[15]||(e[15]=n("div",{class:"h-2"},null,-1)),R.value?(i(),p("div",Fe,[u(we,{ref_key:"dataGrid",ref:b,"excel-file-name":"Situation bancaire","excel-sheet-name":"Situation bancaire","row-data":l.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc","numero","typeSituation","debit","credit"],"column-widths":{ref_paiement:500,montant:140,solde_cumul:160,date_ope:140,date_ech:140},"date-only":["date_ope","date_ech"],"aggregation-types":{solde_cumul:"last"},"column-order":["date_ope","date_ech","ref_paiement","montant","solde_cumul"],"custom-renderers":{montant:K,solde_cumul:O,ref_paiement:W},onRowClicked:J,onSelectionChanged:Q,onGridReady:X},null,8,["row-data","custom-renderers"])])):(i(),p("div",Ve,[l.value.length===0?(i(),p("div",Ie," Aucune donnée à afficher ")):y("",!0),(i(!0),p(L,null,fe(l.value,(s,z)=>(i(),p("div",{key:z,class:h(["rounded-lg border border-gray-200 flex flex-col shrink-0",H(s,z)]),style:{padding:"12px 20px",margin:"0 8px",gap:"10px"}},[n("div",ze,[n("span",Be,m(q(s.date_ope)),1),n("span",{class:h(["text-base font-bold",U(s.montant)])},m(G(s.montant))+" "+m(w(f)(Math.abs(s.montant))),3)]),n("div",Le,[n("div",Ae,m(s.ref_paiement),1),n("span",{class:h(["text-xs font-semibold whitespace-nowrap",parseFloat(s.solde_cumul)>=0?"text-blue-700":"text-red-600"])},m(w(f)(s.solde_cumul)),3)])],2))),128))])),_.value?(i(),B(ae,{key:2,show:_.value,onClose:e[7]||(e[7]=s=>_.value=!1),data:l.value,modeList:!0,RapportName:"/classique/commercial/Situation_Bancaire"},null,8,["show","data"])):y("",!0)],64)}}};export{Ke as default};
