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