import{_ as H}from"./Imprimer-Bot4QNbk.js";import{b1 as K,f as Q,o as h,c as X,b as t,a as n,q as S,z as Y,av as Z,ax as ee,i as le,d as te,F as oe,r as a,e as ae}from"./vendor-BDR7yMJi.js";import{_ as ne}from"./ComboDynamique-DbhbUtR4.js";import{_ as se}from"./FavorisSwitch-DFHH_fud.js";import{u as ie,a as I,s,S as $,h as re,m as ue,A as ce}from"./index-BSaHX2oa.js";import{_ as de}from"./DataGrid-DbeHIyBR.js";import{_ as x}from"./MultiComboDynamique-DA2hl5CL.js";import"./ReportViewer-Cmd4kpyP.js";import"./EnvoieDocumentsMail-P3u1QAl1.js";import"./useAgGridConfig-DxO2r97K.js";const me={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},pe={class:"btns flex items-center gap-2"},ve={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},fe={class:"grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-8 gap-4 mb-4"},be={class:"col-span-2"},ge={style:{height:"calc(100vh - 260px)",width:"100%"}},ke={__name:"ReleveClientGlobal",setup(_e){const{showError:C,showInfo:R,showWarn:k}=ie(),u=a(!1),D=a({}),c=a([]),f=a(),d=a(),r=a(""),m=a([]),b=a("Actif"),p=a([]),v=a([]),T=a(0),g=a(2),G=[{Id:0,Libelle:"Tous"},{Id:1,Libelle:"Soldé"},{Id:2,Libelle:"Non Soldé"}],A=[{Id:"",Libelle:"----"},{Id:"Actif",Libelle:"Actif"},{Id:"En sommeil",Libelle:"En sommeil"}],L=a(0),N=ae(()=>["Report","Debit","Credit","Solde"]),P=()=>l=>{if(l.value===null||l.value===void 0||l.value===""||l.value==="null")return"";const e=parseFloat(l.value);if(isNaN(e))return"";const i=re(e);return l.node?.rowPinned?`<span style="font-weight: 600;">${i}</span>`:e>=0?`<span style="color: #16a34a; font-weight: bold;">${i}</span>`:`<span style="color: #dc2626; font-weight: bold;">${i}</span>`},_=a(""),E=({event:l,ndoc:e,rowIndex:i})=>{r.value=e,_.value=e,w.value=i,z()},U=({selectedRows:l})=>{},j=l=>{d.value=l.api},w=a(-1);K(()=>{d.value&&w.value>=0&&setTimeout(()=>{_.value&&d.value.forEachNode(l=>{l.data?.code_client===_.value&&l.setSelected(!0,!1,!0)}),d.value.ensureIndexVisible(w.value,"middle")},50)}),Q(async()=>{await F(),await V()});const F=async()=>{try{const e=(await I.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:410,mail:s.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(k("Vous n'avez pas le droit, veuillez consulter l'administrateur"),$("ReleveClientGlobal")))}catch(l){C("Une erreur s'est produite lors de la vérification des droits."+l)}},V=async()=>{s.state.afficher_in_progress=!0;try{const{data:l}=await I.post(`${s.lienApi}/ReleveClientGlobal/${s.db}`,{maDate:`${s.state.annee_fiscale}0101`,echu:L.value,isSolde:g.value,code_client:r.value,IDfamille_client:v.value.length>0?v.value.join(","):"0",IDville:m.value.length>0?m.value.join(","):"0",ID_representant:T.value,IDcommercial:p.value.length>0?p.value.join(","):"0",Comercial_par:s.state.enreg_option_comm.Comercial_par,typeClient:b.value},{headers:{"Content-Type":"application/json"}});c.value=l}catch(l){const e=l.response?.data?.message||l.message;C(`Une erreur est survenue : 
 ${e}`)}finally{s.state.afficher_in_progress=!1}},z=async()=>{const l=await ue.ReleveClientParDate();ce({id:"ReleveClientParDate",text:`Relevé client par date : ${r.value}`,content:l.default,props:{code_client:r,ParamJusteNonSolde:!0,fermerParRetour:!0}})},B=()=>{u.value=!0},M=()=>{if(!f.value){R("Grille non initialisée");return}if(c.value.length===0){R("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");f.value.exportToExcel(`Releve Client Global_${s.state.enreg_societe.Nom}_${e}.xlsx`)};return(l,e)=>{const i=Y,q=Z,O=se,J=ne,y=ee,W=H;return h(),X(oe,null,[t("div",me,[t("div",pe,[n(i,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=o=>V()),text:"",loading:S(s).state.afficher_in_progress},null,8,["loading"]),n(i,{label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=o=>l.$refs.actionsMenu.toggle(o)),text:""}),n(q,{ref:"actionsMenu",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:M},{label:"Imprimer",icon:"pi pi-print",command:B}],popup:!0},null,8,["model"]),n(i,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=()=>S($)("ReleveClientGlobal"))})]),t("div",ve,[n(O,{fen:"ReleveClientGlobal",text:"Releve Client Global"})])]),t("div",null,[t("div",fe,[t("div",be,[e[10]||(e[10]=t("label",{class:"block text-sm"},"Client",-1)),n(J,{modelValue:r.value,"onUpdate:modelValue":e[3]||(e[3]=o=>r.value=o),placeholder:"Tous les clients",table:"client",class:"w-full",size:"small"},null,8,["modelValue"])]),t("div",null,[e[11]||(e[11]=t("label",{class:"block text-sm"},"Situation",-1)),n(y,{size:"small",modelValue:g.value,"onUpdate:modelValue":e[4]||(e[4]=o=>g.value=o),placeholder:"Situation",options:G,optionLabel:"Libelle",optionValue:"Id",class:"w-full"},null,8,["modelValue"])]),t("div",null,[e[12]||(e[12]=t("label",{class:"block text-sm"},"Famille client",-1)),n(x,{modelValue:v.value,"onUpdate:modelValue":e[5]||(e[5]=o=>v.value=o),placeholder:"Toutes les familles",table:"famille_client",class:"w-full"},null,8,["modelValue"])]),t("div",null,[e[13]||(e[13]=t("label",{class:"block text-sm"},"Ville",-1)),n(x,{modelValue:m.value,"onUpdate:modelValue":e[6]||(e[6]=o=>m.value=o),placeholder:"Toutes les villes",table:"ville",class:"w-full"},null,8,["modelValue"])]),t("div",null,[e[14]||(e[14]=t("label",{class:"block text-sm"},"Commercial",-1)),n(x,{modelValue:p.value,"onUpdate:modelValue":e[7]||(e[7]=o=>p.value=o),placeholder:"Tous les commerciaux",table:"commercial",class:"w-full"},null,8,["modelValue"])]),t("div",null,[e[15]||(e[15]=t("label",{class:"block text-sm"},"Type client",-1)),n(y,{size:"small",modelValue:b.value,"onUpdate:modelValue":e[8]||(e[8]=o=>b.value=o),placeholder:"Type",options:A,optionLabel:"Libelle",optionValue:"Id",class:"w-full"},null,8,["modelValue"])])])]),e[16]||(e[16]=t("div",{class:"h-2"},null,-1)),t("div",ge,[n(de,{ref_key:"dataGrid",ref:f,"excel-file-name":"Releve client global","excel-sheet-name":"Releve client global","row-data":c.value,"document-number-fields":["code_client"],"excluded-columns":[],"enable-totals":!0,"numeric-columns":N.value,"totals-columns":["Report","Debit","Credit","Solde"],"column-widths":{nom:350,mail:250},"custom-renderers":{Solde:P()},"column-order":["code_client","nom","Report","Debit","Credit","Solde","tel","gsm","mail","Ville"],"show-checkbox":!1,onRowClicked:E,onSelectionChanged:U,onGridReady:j},null,8,["row-data","numeric-columns","custom-renderers"])]),u.value?(h(),le(W,{key:0,show:u.value,onClose:e[9]||(e[9]=o=>u.value=!1),Response:D.value,data:c.value,RapportName:"/classique/commercial/ReleveClientGlobal"},null,8,["show","Response","data"])):te("",!0)],64)}}};export{ke as default};
