import{_ as z}from"./RapportDynamique-xqwJEOK-.js";import{f as O,o as w,c as q,b as s,a as i,q as y,z as U,av as W,ax as J,i as H,d as K,F as Q,r as a,e as f}from"./vendor-BDR7yMJi.js";import{_ as X}from"./FavorisSwitch-DFHH_fud.js";import{u as Y,a as h,s as o,S as b,m as Z,A as ee,h as x}from"./index-BSaHX2oa.js";import{_ as ne}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.js";const te={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},se={class:"btns flex items-center gap-2"},oe={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},ie={class:"grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-6 gap-4 mb-4"},ae={style:{height:"calc(100vh - 280px)",width:"100%"}},fe={__name:"SituationFinanciereClients",setup(re){const{showError:u,showInfo:d,showWarn:C}=Y(),$=f(()=>[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:E},{label:"Imprimer",icon:"pi pi-print",command:T}]),r=a([]),_=a(),c=a(!1),p=a(),v=a(),m=a(0),S=[{Id:0,Libelle:"Tous"},{Id:1,Libelle:"Actifs"},{Id:2,Libelle:"En sommeil"}],F=f(()=>["solde_initial","devis_encours","cmd_encours","bl_non_facture","ca_net_annee","reste_a_payer","encaissements_annee","portefeuille","plafond_credit","depassement"]),R=["solde_initial","devis_encours","cmd_encours","bl_non_facture","ca_net_annee","reste_a_payer","encaissements_annee","portefeuille","depassement"],k=["code_client","nom","solde_initial","devis_encours","cmd_encours","bl_non_facture","ca_net_annee","reste_a_payer","encaissements_annee","portefeuille","plafond_credit","depassement"],A={nom:250,code_client:120},V=()=>n=>{if(n.value===null||n.value===void 0||n.value==="")return"";const e=parseFloat(n.value);if(isNaN(e))return"";const t=x(e);return n.node?.rowPinned?`<span style="font-weight: 600;">${t}</span>`:e>0?`<span style="color: #dc2626; font-weight: bold;">${t}</span>`:t},I=()=>n=>{if(n.value===null||n.value===void 0||n.value==="")return"";const e=parseFloat(n.value);if(isNaN(e))return"";const t=x(e);return n.node?.rowPinned?`<span style="font-weight: 600;">${t}</span>`:e>0?`<span style="color: #dc2626; font-weight: bold;">${t}</span>`:e<0?`<span style="color: #16a34a; font-weight: bold;">${t}</span>`:t},N=f(()=>({depassement:V(),reste_a_payer:I()})),D=async({event:n})=>{const e=n.data.code_client;if(e)try{const t=await Z.ReleveClientParDate();ee({id:"ReleveClientParDate",text:`Relevé: ${e}`,content:t.default,props:{code_client:e,ParamJusteNonSolde:!0,fermerParRetour:!0}})}catch(t){u(`Erreur lors de l'ouverture du relevé: ${t.message}`)}},L=n=>{v.value=n.api};O(async()=>{await P(),await g()});const P=async()=>{try{const e=(await h.post(`${o.lienApi}/verifierDroit/${o.state.dbCommun6}`,{id_utilisateur:o.userId,id_page:411,mail:o.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(C("Vous n'avez pas le droit, veuillez consulter l'administrateur"),b("SituationFinanciereClients")))}catch(n){u(`Une erreur s'est produite lors de la vérification des droits.
 ${n}`)}},g=async()=>{o.state.afficher_in_progress=!0;try{const n=await h.post(`${o.lienApi}/SituationFinanciereClients/${o.db}`,{filtre_client:m.value},{headers:{"Content-Type":"application/json"}});r.value=n.data}catch(n){const e=n.response?.data?.message||n.message;u(`Une erreur est survenue : 
 ${e}`)}finally{o.state.afficher_in_progress=!1}},T=()=>{if(r.value.length===0){d("Aucune donnée à imprimer");return}c.value=!0},E=()=>{if(!p.value){d("Grille non initialisée");return}if(r.value.length===0){d("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");p.value.exportToExcel(`Situation_Financiere_Clients_${e}.xlsx`)};return(n,e)=>{const t=U,M=W,B=X,G=J,j=z;return w(),q(Q,null,[s("div",te,[s("div",se,[i(t,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=l=>g()),text:"",loading:y(o).state.afficher_in_progress},null,8,["loading"]),i(t,{label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=l=>_.value.toggle(l)),text:""}),i(M,{ref_key:"actionsMenu",ref:_,model:$.value,popup:!0},null,8,["model"]),i(t,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=()=>y(b)("SituationFinanciereClients"))})]),s("div",oe,[i(B,{fen:"SituationFinanciereClients",text:"Situation Financière Clients"})])]),s("div",null,[s("div",ie,[s("div",null,[e[5]||(e[5]=s("label",{class:"block text-sm"},"Type client",-1)),i(G,{size:"small",modelValue:m.value,"onUpdate:modelValue":e[3]||(e[3]=l=>m.value=l),placeholder:"Type",options:S,optionLabel:"Libelle",optionValue:"Id",class:"w-full"},null,8,["modelValue"])])])]),e[6]||(e[6]=s("div",{class:"h-2"},null,-1)),s("div",ae,[i(ne,{ref_key:"dataGrid",ref:p,"excel-file-name":"Situation financiere clients","excel-sheet-name":"Situation financiere clients","row-data":r.value,"enable-totals":!0,"numeric-columns":F.value,"totals-columns":R,"column-widths":A,"custom-renderers":N.value,"column-order":k,onRowClicked:D,onGridReady:L},null,8,["row-data","numeric-columns","custom-renderers"])]),c.value?(w(),H(j,{key:0,show:c.value,dataList:r.value,titre:"Situation Financière Clients",gridApi:v.value,onClose:e[4]||(e[4]=l=>c.value=!1)},null,8,["show","dataList","gridApi"])):K("",!0)],64)}}};export{fe as default};
