import{f as D,o as C,c as M,i as B,d as F,an as I,ap as N,b as r,a as n,z as V,av as G,q,F as z,ar as O,r as o}from"./vendor-BDR7yMJi.js";import{u as L,s as a,S as h,a as g}from"./index-BSaHX2oa.js";import{_ as P}from"./DataGrid-DbeHIyBR.js";import H from"./ChiffrageDetail-DycOWo66.js";import"./useAgGridConfig-DxO2r97K.js";import"./PiecesJointes-BVFc0aqb.js";import"./ComboDynamique-DbhbUtR4.js";import"./Discussion-CRGXfryM.js";import"./EnvoieDocumentsMail-P3u1QAl1.js";import"./ReportViewer-Cmd4kpyP.js";const W={class:"w-full flex flex-col overflow-hidden overflow-y-auto",style:{height:"calc(100vh - 108px)"}},J={class:"flex flex-col gap-3 sm:flex-row sm:justify-between sm:items-center"},K={class:"flex flex-col gap-2 sm:flex-row sm:gap-3"},Q={class:"flex flex-wrap gap-2 sm:gap-3"},U={style:{height:"calc(100vh - 220px)",width:"100%"}},ne={__name:"Chiffrage",setup(X){const{showError:f,showWarn:_}=L(),d=o([]),v=o(!1),c=o(""),u=o(!1),p=o(null),m=o(),i=o(),b=o([]),s=O({lecture:!1,ajout:!1,modif:!1,supp:!1}),y=({ndoc:e,rowIndex:t})=>{c.value=e,p.value=t,w()},$=({selectedRows:e})=>{b.value=e},T=e=>{i.value=e.api};D(async()=>{await k(),x()});const k=async()=>{if(!a.getters.hasModule(24)){_("Module Chiffrage non activé"),h("Chiffrage");return}try{const t=(await g.post(`${a.lienApi}/verifierDroit/${a.state.dbCommun6}`,{id_utilisateur:a.userId,id_page:323,mail:a.state.userCloud.mail})).data;t&&Object.keys(t).length>0&&(s.lecture=t.lecture,s.ajout=t.ajout,s.modif=t.modif,s.supp=t.supp),s.lecture||(_("Vous n'avez pas le droit, veuillez consulter l'administrateur"),h("Chiffrage"))}catch(e){f(`Erreur vérification des droits: ${e}`)}},x=async()=>{a.state.afficher_in_progress=!0,v.value=!0;try{const e=await g.post(`${a.lienApi}/chiffrage/${a.db}`);d.value=e.data}catch(e){f("Erreur: "+(e.response?.data?.message||e.message))}finally{a.state.afficher_in_progress=!1,v.value=!1}},R=async()=>{try{const e=await g.post(`${a.lienApi}/AjouterEtRenvoyerChiffrage/${a.db}`,{});c.value=e.data.id_chiffrage,w()}catch{f("Erreur lors de la création")}},w=()=>{u.value=!0,a.dispatch("tabs/changeTab",{id:"Chiffrage",newProps:{text:`Chiffrage N°${c.value}`,iconFermer:!1}})},A=async()=>{u.value=!1,await x(),p.value!=null&&i.value&&setTimeout(()=>{const e=i.value.getDisplayedRowCount();if(e>0){const t=Math.min(p.value,e-1),l=i.value.getDisplayedRowAtIndex(t);l&&(i.value.deselectAll(),l.setSelected(!0),i.value.ensureNodeVisible(l,"middle"))}},100),a.dispatch("tabs/changeTab",{id:"Chiffrage",newProps:{text:"Chiffrage",iconFermer:!0}})},E=()=>{if(!m.value||d.value.length===0)return;const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");m.value.exportToExcel(`Chiffrages_${e}.xlsx`)};return(e,t)=>{const l=V,S=G;return C(),M(z,null,[u.value?(C(),B(H,{key:0,ndoc:c.value,onClose:A},null,8,["ndoc"])):F("",!0),I(r("div",W,[r("div",J,[r("div",K,[r("div",Q,[n(l,{icon:"pi pi-plus",label:"Ajouter",onClick:R,text:"",disabled:!s.ajout},null,8,["disabled"]),n(l,{label:"Actions",icon:"pi pi-cog",onClick:t[0]||(t[0]=j=>e.$refs.actionsMenu.toggle(j)),text:""}),n(S,{ref:"actionsMenu",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:E}],popup:!0},null,8,["model"]),n(l,{icon:"pi pi-times",label:"Fermer",onClick:t[1]||(t[1]=()=>q(h)("Chiffrage")),text:""})])])]),r("div",U,[n(P,{ref_key:"dataGrid",ref:m,"excel-file-name":"Chiffrage","excel-sheet-name":"Chiffrage","row-data":d.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc","id_chiffrage"],"column-widths":{date_creation:120,nom_client:200,libelle:250,effectif_total:100,total_ht:150,total_avec_marge:150,marge_appliquee:100,statut:100,libelle_opportunite:200},"column-headers":{date_creation:"Date",nom_client:"Client",libelle:"Libellé",effectif_total:"Effectif",total_ht:"Total HT",total_avec_marge:"Total TTC",marge_appliquee:"Marge",statut:"Statut",libelle_opportunite:"Opportunité"},onRowClicked:y,onSelectionChanged:$,onGridReady:T},null,8,["row-data"])])],512),[[N,!u.value&&s.lecture]])],64)}}};export{ne as default};
