import{b as S,f as Y}from"./primevue-CfIk0_DY.js";import{u as z,b as u,s,S as g}from"./index-BxIwIJfy.js";import{h}from"./moment-BeHQNF8T.js";import{o as E,P as T,h as G,b as B,k as N,l as v,d as U,v as f,E as R,a as o}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";const I={class:"ag-theme-quartz",style:{height:"480px",width:"100%"}},W={__name:"ClotureMensuelle",setup(V){const{showError:c,showSuccess:b,showWarn:C}=z(),l=R({lecture:!1,ajout:!1}),r=o(!1),w=()=>{r.value=!1,g("ClotureMensuelle")},i=o([]),_=o(),d=o(),x=["janvier","février","mars","avril","mai","juin","juillet","août","septembre","octobre","novembre","décembre"],M=o([{headerName:"Mois",field:"libelleMois",flex:2,sortable:!1,filter:!1},{headerName:"Clôture",field:"Cloture",flex:1,cellRenderer:e=>e.node?.rowPinned?"":`
        <div class="flex justify-center items-center h-full">
          <input type="checkbox" ${e.value?"checked":""}
                 data-mois="${e.data.mois}"
                 class="cloture-checkbox cursor-pointer"
                 style="width: 16px; height: 16px;"
                 onchange="window.handleClotureMensuelleChange && window.handleClotureMensuelleChange(this, '${e.data.mois}')" />
        </div>
      `,cellStyle:{textAlign:"center"},sortable:!1,resizable:!1,filter:!1}]),$=o({sortable:!1,resizable:!0,suppressHeaderMenuButton:!0}),y=o({mode:"singleRow",checkboxes:!1,enableClickSelection:!1}),D=e=>{d.value=e.api,window.handleClotureMensuelleChange=(t,n)=>{const a=i.value.find(m=>m.mois===n);a&&(a.Cloture=t.checked)},setTimeout(()=>{d.value&&d.value.sizeColumnsToFit()},100)},k=async()=>{try{const{data:e}=await u.post(`${s.lienApi}/getClotureMensuelle/${s.db}`,{annee_fiscale:s.state.annee_fiscale,ExerciceDu:h(s.state.enreg_option_compta.ExerciceDu).format("YYYY-MM-DD"),ExerciceAu:h(s.state.enreg_option_compta.ExerciceAu).format("YYYY-MM-DD")});i.value=e.map(t=>{const n=parseInt(t.mois.substring(4,6),10),a=t.mois.substring(0,4);return{...t,Cloture:!!t.Cloture,libelleMois:`${x[n-1]} ${a}`}})}catch(e){const t=e.response?.data?.message||e.message;c(`Une erreur est survenue : ${t}`)}},j=async()=>{try{await u.post(`${s.lienApi}/enregistrerClotureMensuelle/${s.db}`,{lignes:i.value});try{const e=await u.post(`${s.lienApi}/Options_compta/${s.db}/${s.state.annee_fiscale}`);e.data&&(s.state.enreg_option_compta=e.data)}catch{}b("Clôtures mensuelles enregistrées avec succès"),r.value=!1}catch(e){const t=e.response?.data?.message||e.message;c(`Une erreur est survenue : ${t}`)}},A=async()=>{try{const t=(await u.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:2403,mail:s.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;t&&Object.keys(t).length>0&&(l.lecture=t.lecture,l.ajout=t.ajout),l.lecture||(C("Vous n'avez pas le droit, veuillez consulter l'administrateur"),g("ClotureMensuelle"))}catch(e){c("Une erreur est survenue : "+(e.response?.data?.message||e.message))}};return E(async()=>{await A(),l.lecture&&(r.value=!0,k())}),T(()=>{delete window.handleClotureMensuelleChange}),(e,t)=>{const n=G("ag-grid-vue"),a=S,m=Y;return B(),N(m,{visible:r.value,"onUpdate:visible":t[2]||(t[2]=p=>r.value=p),modal:"",draggable:!1,header:"Clôture mensuelle des écritures",style:{width:"520px"},breakpoints:{"640px":"95vw"},onHide:w},{footer:v(()=>[f(a,{icon:"pi pi-times",label:"Fermer",text:"",onClick:t[0]||(t[0]=p=>r.value=!1)}),f(a,{icon:"pi pi-save",label:"Enregistrer",disabled:!l.ajout,onClick:t[1]||(t[1]=p=>j())},null,8,["disabled"])]),default:v(()=>[U("div",I,[f(n,{ref_key:"agGrid",ref:_,localeText:e.$agGridLocale,rowData:i.value,columnDefs:M.value,defaultColDef:$.value,theme:e.$agGridTheme,rowSelection:y.value,onGridReady:D,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["localeText","rowData","columnDefs","defaultColDef","theme","rowSelection"])])]),_:1},8,["visible"])}}};export{W as default};
