import{r as s,f as X,o as d,c,b as t,a as i,q as L,z as Z,E as ee,B as M,d as v,ax as te,aS as le,ar as ae,$ as se}from"./vendor-BDR7yMJi.js";import{u as oe,s as a,a as x,S as $,h as ne,g as ie}from"./index-BSaHX2oa.js";import{_ as re}from"./selectDate-Dd47YHbm.js";import{_ as ue}from"./ComboDynamique-DbhbUtR4.js";import{c as de}from"./imageTraitements-7eElINlT.js";import{_ as ce}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.js";const me={class:"w-full flex flex-col overflow-hidden overflow-y-auto",style:{height:"calc(100vh - 120)"}},pe={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},fe={class:"btns flex items-center gap-2"},ve={class:"flex items-center gap-3 whitespace-nowrap"},xe={key:0,class:"text-right"},_e={class:"text-sm font-bold text-green-600"},be={key:1,class:"text-right"},ge={class:"text-sm font-bold text-blue-600"},he={class:"bg-white mb-2 p-3"},ye={class:"flex items-end flex-wrap gap-6"},we={class:"flex items-end gap-4 flex-wrap"},Ve={class:"flex flex-col",style:{"min-width":"200px"}},Ce={class:"flex flex-col",style:{"min-width":"180px"}},Le={class:"flex flex-col",style:{"min-width":"100px"}},De={class:"flex items-end gap-4 flex-wrap"},Se={class:"flex flex-col",style:{"min-width":"120px"}},ke={class:"flex flex-col",style:{"min-width":"140px"}},Ie={key:0,class:"flex flex-col",style:{"min-width":"150px"}},Fe={key:1,class:"flex flex-col",style:{"min-width":"130px"}},Me={style:{height:"calc(100vh - 220px)"}},Ee={__name:"FacturationMultiple",setup($e){const{showSuccess:T,showError:m,showWarn:D}=oe(),z=de(x,a),B=s({}),n=s([]),S=s(),_=s([]),U=s(),R=s(),p=s(""),b=s(""),k=s(a.state.dossier.dated),I=s(a.state.dossier.datef),f=s("2"),g=s(0),r=s(new Date),u=s(!1),F=s(""),j=[{Id:0,Libelle:"Tout"},{Id:1,Libelle:"Série 1"},{Id:2,Libelle:"Série 2"}],h=s(1),A=[{Id:"2",Libelle:"Séparé"},{Id:"1",Libelle:"Groupé"}],E=[{Id:!1,Libelle:"Date choisie"},{Id:!0,Libelle:"Date du BL"}],y=ae({lecture:!1,ajout:!1}),G=({event:l,ndoc:e})=>{},N=({selectedRows:l})=>{n.value=l},P=l=>{R.value=l.api},Y=()=>n.value.reduce((l,e)=>l+(parseFloat(e["Montant TTC"])||0),0),q=(l,e)=>{k.value=l,I.value=e};X(async()=>{await H()});const H=async()=>{try{const e=(await x.post(`${a.lienApi}/verifierDroit/${a.state.dbCommun6}`,{id_utilisateur:a.userId,id_page:407,mail:a.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(y.lecture=e.lecture,y.ajout=e.ajout),y.lecture||(D("Vous n'avez pas le droit, veuillez consulter l'administrateur"),$("FacturationMultiple"))}catch(l){m("Une erreur s'est produite lors de la vérification des droits."+l)}},w=async()=>{a.state.afficher_in_progress=!0;try{p.value="",p.value=" and nfacturec=0 and valide=1 and nbl2=0 ",F.value&&(p.value+=` and ${F.value}`);const l=await x.post(`${a.lienApi}/facturationMultiple/${a.db}`,{dateDu:k.value,dateAu:I.value,code_client:b.value||"",serie:h.value,condition:p.value},{headers:{"Content-Type":"application/json"}});_.value=l.data,n.value=[];for(const e of _.value)e.code_client&&(B.value[e.code_client]=await z.loadImage(e.code_client,"client"))}catch(l){m(`Une erreur est survenue lors de l'affichage des bons de livraison.
 ${l}`)}finally{a.state.afficher_in_progress=!1}},O=async()=>{if(!u.value&&r.value&&r.value.getFullYear()!=a.state.annee_fiscale)return m("La date de facturation doit être dans l'année fiscale actuelle."),!1;if(!n.value||n.value.length===0){D("Sélectionnez d'abord au moins une ligne");return}S.value=n.value.map(l=>l.nbl);try{a.state.afficher_in_progress=!0,await x.post(`${a.lienApi}/SP_facturationEnMasse/${a.db}`,{nbls:S.value,montantMax:g.value||0,dateFacturation:se(r.value).format("YYYY-MM-DD"),dateFactureEgaleDateBL:u.value?1:0,groupeSepare:f.value||0,id_utilisateur:a.userId},{headers:{"Content-Type":"application/json"}}),T("Les factures ont été générées avec succès"),w()}catch(l){m(`Une erreur est survenue. Veuillez réessayer.
 ${l}`)}finally{a.state.afficher_in_progress=!1}};return(l,e)=>{const V=Z,W=ue,J=re,C=te,K=ie,Q=le;return d(),c("div",me,[t("div",pe,[t("div",fe,[i(V,{icon:"pi pi-search",label:"Rechercher",onClick:w,text:"",loading:L(a).state.afficher_in_progress},null,8,["loading"]),i(V,{icon:"pi pi-file",label:"Générer",text:"",onClick:e[0]||(e[0]=o=>O()),disabled:!n.value.length,class:ee(n.value.length?"text-green-600":"")},null,8,["disabled","class"]),i(V,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=o=>L($)("FacturationMultiple"))})]),t("div",ve,[n.value.length>0?(d(),c("div",xe,[e[9]||(e[9]=t("span",{class:"text-sm text-gray-600"},"Sélectionnés:",-1)),t("div",_e,M(n.value.length)+" BL",1)])):v("",!0),n.value.length>0?(d(),c("div",be,[e[10]||(e[10]=t("span",{class:"text-sm text-gray-600"},"Total TTC:",-1)),t("div",ge,M(L(ne)(Y())),1)])):v("",!0)])]),t("div",he,[t("div",ye,[t("div",we,[t("div",Ve,[e[11]||(e[11]=t("label",{class:"text-sm font-medium mb-1"},"Client",-1)),i(W,{modelValue:b.value,"onUpdate:modelValue":e[2]||(e[2]=o=>b.value=o),placeholder:"Tous",table:"client"},null,8,["modelValue"])]),t("div",Ce,[e[12]||(e[12]=t("label",{class:"text-sm font-medium mb-1"},"Période",-1)),i(J,{onSelectDate:q,defaultPeriod:"month"})]),t("div",Le,[e[13]||(e[13]=t("label",{class:"text-sm font-medium mb-1"},"Série",-1)),i(C,{size:"small",modelValue:h.value,"onUpdate:modelValue":e[3]||(e[3]=o=>h.value=o),options:j,optionLabel:"Libelle",optionValue:"Id",onChange:e[4]||(e[4]=o=>w())},null,8,["modelValue"])])]),t("div",De,[t("div",Se,[e[14]||(e[14]=t("label",{class:"text-sm font-medium mb-1"},"Type",-1)),i(C,{size:"small",modelValue:f.value,"onUpdate:modelValue":e[5]||(e[5]=o=>f.value=o),options:A,optionLabel:"Libelle",optionValue:"Id"},null,8,["modelValue"])]),t("div",ke,[e[15]||(e[15]=t("label",{class:"text-sm font-medium mb-1"},"Date Facture",-1)),i(C,{size:"small",modelValue:u.value,"onUpdate:modelValue":e[6]||(e[6]=o=>u.value=o),options:E,optionLabel:"Libelle",optionValue:"Id"},null,8,["modelValue"])]),u.value?v("",!0):(d(),c("div",Ie,[e[16]||(e[16]=t("label",{class:"text-sm font-medium mb-1"},"Date",-1)),i(K,{size:"small",modelValue:r.value,"onUpdate:modelValue":e[7]||(e[7]=o=>r.value=o)},null,8,["modelValue"])])),f.value==="1"?(d(),c("div",Fe,[e[17]||(e[17]=t("label",{class:"text-sm font-medium mb-1"},"Montant Max",-1)),i(Q,{size:"small",locale:"fr-FR",modelValue:g.value,"onUpdate:modelValue":e[8]||(e[8]=o=>g.value=o),mode:"decimal",minFractionDigits:2},null,8,["modelValue"])])):v("",!0)])])]),e[18]||(e[18]=t("div",{class:"h-2"},null,-1)),t("div",Me,[i(ce,{ref_key:"dataGrid",ref:U,"excel-file-name":"Facturation multiple","excel-sheet-name":"Facturation multiple","row-data":_.value,"document-number-fields":["nbl"],"excluded-columns":["nbl"],"column-widths":{date:160,client:300,"Montant TTC":180,"Montant réglé":150,commercial:180,utilisateur:160,appelation:250},"allow-selection":!0,onRowClicked:G,onSelectionChanged:N,onGridReady:P},null,8,["row-data"])])])}}};export{Ee as default};
