import{b as N,y as z}from"./primevue-CfIk0_DY.js";import{a as o,o as U,j as E,H as P,b as _,c as R,d as a,v as i,a7 as w,k as M,p as O,f as H,t as W,y,E as q}from"./vue-core-Di3IuVqe.js";import{u as J,s as t,b,S as x}from"./index-BxIwIJfy.js";import{D as K}from"./DataGrid-CoMfrBJA.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const Q={class:"page-wrapper"},X={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},Y={class:"btns flex items-center gap-2"},Z={class:"flex items-end gap-3 p-1",style:{"margin-bottom":"8px"}},ee={style:{width:"200px"}},se={style:{width:"180px"}},te={class:"ml-auto",style:{"white-space":"nowrap"}},ae={class:"text-gray-600"},le={class:"grille-container"},me={__name:"ListeNumerosCreuses",props:{typeDoc:{type:String,default:"FC",validator:p=>["BL","FC"].includes(p)}},setup(p){const{showError:u,showWarn:h,showSuccess:$}=J(),B=p,S=[{Id:"BL",Libelle:"Bons de livraison"},{Id:"FC",Libelle:"Factures"}],V=[{Id:"1",Libelle:"Série 1"},{Id:"2",Libelle:"Série 2"}],c=q({lecture:!1,ajout:!1}),l=o(B.typeDoc),m=o("1"),f=o([]),d=o([]),k=o(!1),I=o(),T=o(),v=y(()=>l.value==="BL"?"BL":"factures"),L=y(()=>l.value==="BL"?"ListeBLCrues":"ListeFacturesCreuses"),D=y(()=>l.value==="BL"?1204:1205),j=s=>{T.value=s.api},F=({selectedRows:s})=>{d.value=s};U(async()=>{const s=t.state.tabs?.currentTabId;s==="ListeBLCrues"?l.value="BL":s==="ListeFacturesCreuses"&&(l.value="FC"),await A(),r()});const r=async()=>{t.state.afficher_in_progress=!0;try{const s=await b.post(`${t.lienApi}/numerosCreuses/${t.db}/${l.value}/${m.value}/${t.state.annee_fiscale}`,{},{headers:{"Content-Type":"application/json"}});f.value=s.data}catch(s){u(`Une erreur est survenue lors de l'affichage des ${v.value} sautés
 ${s}`)}finally{t.state.afficher_in_progress=!1}},A=async()=>{try{const e=(await b.post(`${t.lienApi}/verifierDroit/${t.state.dbCommun6}`,{id_utilisateur:t.userId,id_page:D.value,mail:t.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(c.lecture=e.lecture,c.ajout=e.ajout),c.lecture||(h("Vous n'avez pas le droit, veuillez consulter l'administrateur"),x(L.value))}catch(s){u("Une erreur est survenue : "+(s.response?.data?.message||s.message))}finally{t.state.afficher_in_progress=!1}},G=async()=>{if(!d.value||d.value.length<=0){h({title:"Aucun élément sélectionné",text:"Veuillez sélectionner au moins un élément avant de générer."});return}try{const s=await b.post(`${t.lienApi}/enregistrerNumeroCreuse/${t.db}/${l.value}`,d.value,{headers:{"Content-Type":"application/json"}}),e=s.data;s.status===201?$(`${e.message}`):u(e.message),await r()}catch(s){u(`Une erreur est survenue lors de la génération
 ${s}`)}};return(s,e)=>{const g=N,C=z;return E((_(),R("div",Q,[a("div",X,[a("div",Y,[i(g,{icon:"pi pi-search",label:"Afficher",text:"",onClick:e[0]||(e[0]=n=>r()),loading:w(t).state.afficher_in_progress},null,8,["loading"]),k.value?O("",!0):(_(),M(g,{key:0,icon:"pi pi-cog",label:"Générer",text:"",onClick:e[1]||(e[1]=n=>G())})),i(g,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=n=>w(x)(L.value))})])]),a("div",Z,[a("div",ee,[e[5]||(e[5]=a("label",{class:"block"},"Type",-1)),i(C,{size:"small",modelValue:l.value,"onUpdate:modelValue":e[3]||(e[3]=n=>l.value=n),options:S,optionLabel:"Libelle",optionValue:"Id",placeholder:"Type",class:"w-full",onChange:r},null,8,["modelValue"])]),a("div",se,[e[6]||(e[6]=a("label",{class:"block"},"Série",-1)),i(C,{size:"small",modelValue:m.value,"onUpdate:modelValue":e[4]||(e[4]=n=>m.value=n),options:V,optionLabel:"Libelle",optionValue:"Id",placeholder:"Série",class:"w-full",onChange:r},null,8,["modelValue"])]),a("div",te,[a("span",ae,[e[7]||(e[7]=H("Total : ",-1)),a("b",null,W(f.value.length),1)])])]),a("div",le,[i(K,{ref_key:"agGrid",ref:I,"excel-file-name":`Liste ${v.value} sautes`,"excel-sheet-name":`Liste ${v.value} sautes`,"row-data":f.value,"excluded-columns":[],"column-widths":{num:150},"enable-totals":!1,onGridReady:j,onSelectionChanged:F},null,8,["excel-file-name","excel-sheet-name","row-data"])])],512)),[[P,c.lecture]])}}};export{me as default};
