import{f as z,o as C,c as B,i as F,d as I,an as N,ap as G,b as u,a as f,z as O,av as L,q as P,F as H,ar as W,r as i}from"./vendor-0kGcmQpG.js";import{u as J,a as d,s as t,S as y}from"./index-Bn9WoKhP.js";import{_ as K}from"./DataGrid-tb6QVwpZ.js";import Q from"./ChiffrageDetail-D-fCMK0N.js";import"./useAgGridConfig-DjXMc6wb.js";import"./PiecesJointes-Dkmk2u4H.js";import"./ComboDynamique-CzrtYPe1.js";const U={class:"w-full flex flex-col overflow-hidden overflow-y-auto",style:{height:"calc(100vh - 108px)"}},X={class:"flex flex-col gap-3 sm:flex-row sm:justify-between sm:items-center"},Y={class:"flex flex-col gap-2 sm:flex-row sm:gap-3"},Z={class:"flex flex-wrap gap-2 sm:gap-3"},ee={style:{height:"calc(100vh - 220px)",width:"100%"}},ce={__name:"Chiffrage",setup(ae){const{confirmAction:w,showError:n,showWarn:$,showSuccess:x}=J(),m=i([]),b=i(!1),c=i(""),p=i(!1),h=i(null),g=i(),l=i(),o=i([]),r=W({lecture:!1,ajout:!1,modif:!1,supp:!1}),S=({ndoc:e,rowIndex:a})=>{c.value=e,h.value=a,_()},A=({selectedRows:e})=>{o.value=e},E=e=>{l.value=e.api};z(async()=>{await T(),v()});const T=async()=>{try{const a=(await d.post(`${t.lienApi}/verifierDroit/${t.state.dbCommun6}`,{id_utilisateur:t.userId,id_page:323,mail:t.state.userCloud.mail})).data;a&&Object.keys(a).length>0&&(r.lecture=a.lecture,r.ajout=a.ajout,r.modif=a.modif,r.supp=a.supp),r.lecture||($("Vous n'avez pas le droit, veuillez consulter l'administrateur"),y("Chiffrage"))}catch(e){n(`Erreur vérification des droits: ${e}`)}},v=async()=>{t.state.afficher_in_progress=!0,b.value=!0;try{const e=await d.post(`${t.lienApi}/chiffrage/${t.db}`);m.value=e.data}catch(e){n("Erreur: "+(e.response?.data?.message||e.message))}finally{t.state.afficher_in_progress=!1,b.value=!1}},k=async()=>{try{const e=await d.post(`${t.lienApi}/AjouterEtRenvoyerChiffrage/${t.db}`,{});c.value=e.data.id_chiffrage,_()}catch{n("Erreur lors de la création")}},_=()=>{p.value=!0,t.dispatch("tabs/changeTab",{id:"Chiffrage",newProps:{text:`Chiffrage N°${c.value}`,iconFermer:!1}})},R=async()=>{p.value=!1,await v(),h.value!=null&&l.value&&setTimeout(()=>{const e=l.value.getDisplayedRowCount();if(e>0){const a=Math.min(h.value,e-1),s=l.value.getDisplayedRowAtIndex(a);s&&(l.value.deselectAll(),s.setSelected(!0),l.value.ensureNodeVisible(s,"middle"))}},100),t.dispatch("tabs/changeTab",{id:"Chiffrage",newProps:{text:"Chiffrage",iconFermer:!0}})},D=async()=>{if(o.value.length!==1)return;const e=o.value[0].id_chiffrage;if(await w({message:"Voulez-vous dupliquer ce chiffrage ?"}))try{const s=await d.post(`${t.lienApi}/dupliquerChiffrage/${t.db}/${e}`);x("Chiffrage dupliqué avec succès"),c.value=s.data.id_chiffrage,_()}catch(s){n("Erreur: "+(s.response?.data?.message||s.message))}},j=async()=>{if(!(o.value.length===0||!await w({message:`Voulez-vous supprimer ${o.value.length} chiffrage(s) ?`})))try{for(const a of o.value)await d.post(`${t.lienApi}/supprimerChiffrage/${t.db}/${a.id_chiffrage}`);x("Suppression effectuée"),v()}catch(a){n("Erreur: "+(a.response?.data?.message||a.message))}},q=()=>{if(!g.value||m.value.length===0)return;const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");g.value.exportToExcel(`Chiffrages_${e}.xlsx`)};return(e,a)=>{const s=O,V=L;return C(),B(H,null,[p.value?(C(),F(Q,{key:0,ndoc:c.value,onClose:R},null,8,["ndoc"])):I("",!0),N(u("div",U,[u("div",X,[u("div",Y,[u("div",Z,[f(s,{icon:"pi pi-plus",label:"Ajouter",onClick:k,text:"",disabled:!r.ajout},null,8,["disabled"]),f(s,{label:"Actions",icon:"pi pi-cog",onClick:a[0]||(a[0]=M=>e.$refs.actionsMenu.toggle(M)),text:""}),f(V,{ref:"actionsMenu",model:[{label:"Dupliquer",icon:"pi pi-copy",command:D,disabled:o.value.length!==1},{label:"Supprimer",icon:"pi pi-trash",command:j,disabled:!r.supp||o.value.length===0},{separator:!0},{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:q}],popup:!0},null,8,["model"]),f(s,{icon:"pi pi-times",label:"Fermer",onClick:a[1]||(a[1]=()=>P(y)("Chiffrage")),text:""})])])]),u("div",ee,[f(K,{ref_key:"dataGrid",ref:g,"excel-file-name":"Chiffrage","excel-sheet-name":"Chiffrage","row-data":m.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:S,onSelectionChanged:A,onGridReady:E},null,8,["row-data"])])],512),[[G,!p.value&&r.lecture]])],64)}}};export{ce as default};
