import{_ as he}from"./RapportDynamique-BvCuWpYR.js";import{w as we,f as Ce,o as P,c as xe,b as l,a as o,z as be,av as Pe,i as G,q as ye,d as y,ax as Ae,j as d,t as $e,v as Se,h as N,x as De,y as ke,H as qe,r as n,ar as Re,e as F}from"./vendor-0kGcmQpG.js";import{_ as Te}from"./selectDate-B99dlzOe.js";import{_ as Le}from"./FavorisSwitch-DD6nTfzi.js";import{u as Ge,a as A,s as i,S as V}from"./index-Bn9WoKhP.js";import{_ as j}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const Ne={key:0},Fe={class:"w-full mb-6 flex flex-col sm:flex-row items-center align-baseline gap-3"},Ve={class:"flex items-center gap-3 lg:w-1/4 lg:justify-end whitespace-nowrap"},je={class:"text-primary mt-2 bg-white p-2"},Ie={class:"grid grid-cols-1 md:grid-cols-5 gap-4 mb-4"},Be={style:{height:"calc(100vh - 300px)"}},Ee={style:{height:"calc(100vh - 300px)"}},Ke={__name:"SituationPeriodique",props:["masquerFermer"],setup(I){const{showError:$,showWarn:C,showInfo:S}=Ge(),B=I,D=n(),k=n(),E=n(),z=n(),M=n([]),U=n([]),O=n([]),W=n([]),q=n(),v=n(""),f=n(""),m=n([]),c=n([]),g=n([]),s=n([]),H=F(()=>["ttc","mtregle"]),J=F(()=>["montant"]),h=n(!1),K=[{Id:"1",Libelle:"Global"},{Id:"2",Libelle:" Détaillé"}],p=n("1"),_=n("0"),r=Re({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),Q=({event:t,ndoc:e})=>{},X=({selectedRows:t})=>{O.value=t},Y=t=>{E.value=t.api},Z=({event:t,ndoc:e})=>{},ee=({selectedRows:t})=>{W.value=t},te=t=>{z.value=t.api},ne=()=>t=>!t.row||!t.row.doc||!t.row.ndoc?"":`${t.row.doc}${t.row.ndoc}`,oe=t=>t.map(e=>({...e,document:`${e.doc}${e.ndoc}`})),R=t=>t.map(e=>({...e})),ae=()=>{const t={date:120,code:90,nom:250,commercial:200,modep:200,montant:90,date_ech:90,ville:200,ref_paiement:200};return p.value==="2"&&(t.ndocument=90,t.datedoc=90),t},le=()=>{if(!c.value||c.value.length===0)return[];let t=c.value.length;const e={ttc:0,mtregle:0};return c.value.forEach(a=>{e.ttc+=parseFloat(a.ttc)||0,e.mtregle+=parseFloat(a.mtregle)||0}),[{document:`${t} Lignes`,date:"",code_client:"",clientNom:"",commercialLibelle:"",ttc:e.ttc,mtregle:e.mtregle}]},ie=()=>{if(!s.value||s.value.length===0)return[];let t=s.value.length;const e={montant:0};s.value.forEach(w=>{e.montant+=parseFloat(w.montant)||0});const a={ndoc:`${t} Lignes`,date:"",code:"",nom:"",commercial:"",modep:"",montant:e.montant,date_ech:"",ville:"",ref_paiement:""};return p.value==="2"&&(a.ndocument="",a.datedoc=""),[a]};we(p,()=>{g.value.length>0&&(s.value=R(g.value))});const se=()=>{v.value&&f.value&&x()};Ce(async()=>{await re()});const re=async()=>{try{const e=(await A.post(`${i.lienApi}/verifierDroit/${i.state.dbCommun6}`,{id_utilisateur:i.userId,id_page:802,mail:i.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(r.lecture=e.lecture,r.ajout=e.ajout,r.modif=e.modif,r.supp=e.supp,r.devalidation=e.devalidation,r.validation=e.validation),r.lecture||(C("Vous n'avez pas le droit, veuillez consulter l'administrateur"),V("SituationPeriodique"))}catch(t){$(`Une erreur s'est produite lors de la vérification des droits.
 ${t}`)}},ue=(t,e)=>{v.value=t,f.value=e,x()},x=async()=>{if(!v.value||!f.value){C("Veuillez sélectionner une période");return}i.state.afficher_in_progress=!0;try{m.value=[];const t=await A.post(`${i.lienApi}/SituationPeriodiqueCA/${i.db}`,{DateDebut:v.value,DateFin:f.value},{headers:{"Content-Type":"application/json"}});m.value=t.data,c.value=oe(t.data),g.value=[];const e=await A.post(`${i.lienApi}/SituationPeriodiquePaiement/${i.db}`,{DateDebut:v.value,DateFin:f.value,detailOuGlobal:p.value},{headers:{"Content-Type":"application/json"}});g.value=e.data,s.value=R(e.data),setTimeout(()=>{c.value.length>0&&(M.value=le()),s.value.length>0&&(U.value=ie())},100)}catch(t){const e=t.response?.data?.message||t.message;$("Une erreur est survenue : "+e)}finally{i.state.afficher_in_progress=!1}},ce=()=>{if(!m.value||m.value.length===0){C("Aucune donnée à imprimer");return}h.value=!0},de=async()=>{const t=_.value==="0"?c.value:s.value,e=_.value==="0"?"CA":"Paiement",a=_.value==="0"?D.value:k.value;if(!a){S("Grille non initialisée");return}if(t.length===0){S("Aucune donnée à exporter");return}const b=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");a.exportToExcel(`Situation Periodique_${e}_${i.state.enreg_societe.Nom}_${b}.xlsx`)};return(t,e)=>{const a=be,w=Pe,b=Le,me=Te,pe=Ae,T=Se,ve=$e,L=ke,fe=De,_e=qe,ge=he;return r.lecture?(P(),xe("div",Ne,[l("div",Fe,[o(a,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:e[0]||(e[0]=u=>x())}),o(a,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=u=>q.value.toggle(u))}),o(w,{ref_key:"actionsMenu",ref:q,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>de()},{label:"Imprimer",icon:"pi pi-list",command:()=>ce()}],popup:!0},null,8,["model"]),B.masquerFermer?y("",!0):(P(),G(a,{key:0,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=u=>ye(V)("SituationPeriodique"))})),e[6]||(e[6]=l("div",{class:"w-full lg:w-2/4 flex justify-center px-4"},null,-1)),l("div",Ve,[o(b,{fen:"SituationPeriodique",text:"Situation périodique"})])]),e[10]||(e[10]=l("div",{class:"h-2"},null,-1)),l("div",je,[l("div",Ie,[l("div",null,[o(me,{onSelectDate:ue,defaultPeriod:"today"})]),l("div",null,[o(pe,{size:"small",modelValue:p.value,"onUpdate:modelValue":e[3]||(e[3]=u=>p.value=u),options:K,optionLabel:"Libelle",optionValue:"Id",placeholder:"Nature Paiement",class:"w-full",onChange:se},null,8,["modelValue"])])]),o(_e,{value:_.value,"onUpdate:value":e[4]||(e[4]=u=>_.value=u)},{default:d(()=>[o(ve,null,{default:d(()=>[o(T,{value:"0"},{default:d(()=>[...e[7]||(e[7]=[N("Chiffre d'affaire",-1)])]),_:1}),o(T,{value:"1"},{default:d(()=>[...e[8]||(e[8]=[N("Paiements",-1)])]),_:1})]),_:1}),o(fe,null,{default:d(()=>[o(L,{value:"0"},{default:d(()=>[l("div",Be,[o(j,{ref_key:"dataGridCA",ref:D,"excel-file-name":"Situation periodique","excel-sheet-name":"Situation periodique","row-data":m.value,"document-number-fields":["ndoc"],"excluded-columns":["IDcommercial"],"column-widths":{document:120,date:120,code_client:90,clientNom:250,commercialLibelle:200,ttc:150,mtregle:150},"custom-renderers":{document:ne()},"date-only":["datedoc","date_ech"],"enable-totals":!0,"numeric-columns":H.value,"totals-columns":["ttc","mtregle"],onRowClicked:Q,onSelectionChanged:X,onGridReady:Y},null,8,["row-data","custom-renderers","numeric-columns"])])]),_:1}),o(L,{value:"1"},{default:d(()=>[l("div",Ee,[o(j,{ref_key:"dataGridPaiement",ref:k,"excel-file-name":"Situation periodique","excel-sheet-name":"Situation periodique","row-data":s.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":ae(),"enable-totals":!0,"numeric-columns":J.value,"totals-columns":["montant"],onRowClicked:Z,onSelectionChanged:ee,onGridReady:te},null,8,["row-data","column-widths","numeric-columns"])])]),_:1})]),_:1})]),_:1},8,["value"]),e[9]||(e[9]=l("div",null,null,-1))]),h.value?(P(),G(ge,{key:0,show:h.value,dataList:m.value,titre:"Situation périodique",gridApi:t.gridApi,onClose:e[5]||(e[5]=u=>h.value=!1)},null,8,["show","dataList","gridApi"])):y("",!0)])):y("",!0)}}};export{Ke as default};
