import{R as se}from"./RapportDynamique-DI8KNc5X.js";import{b as re,B as ie,g as ue,v as de}from"./primevue-CfIk0_DY.js";import{C as ce}from"./ComboDynamique-BzWI4ISP.js";import{s as me}from"./selectDate-Dai2cu2_.js";import{_ as pe}from"./FavorisSwitch-BFqqA1tj.js";import{a as i,o as fe,b as g,c as V,d as a,v as o,a7 as k,k as B,p as y,I as G,l as ve,y as m}from"./vue-core-Di3IuVqe.js";import{u as ge,s,b as j,S as E,o as D}from"./index-BxIwIJfy.js";import{D as be}from"./DataGrid-CoMfrBJA.js";import"./ReportViewer-BNzhW7G2.js";import"./stimulsoft-B2-Y-rC1.js";import"./cjs-helpers-psZwOBky.js";import"./PDFButton-DhVJ6hNy.js";import"./moment-BeHQNF8T.js";import"./vue-cal-DKMVGERa.js";import"./useAgGridConfig-Dp3DkgaV.js";const Ce={class:"page-wrapper"},xe={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},we={class:"btns flex items-center gap-2"},ye={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},Ae={class:"hidden lg:grid lg:grid-cols-5 gap-4 mb-4"},he={key:0},Ve={class:"flex flex-col",style:{gap:"16px"}},ke={key:0},De={class:"grille-container"},je={__name:"ChiffreAffaireParModeDePaiement",props:["masquerFermer"],setup(L){const{showError:P,showWarn:b}=ge(),K=L,$=i(),A=i(),R=i(),O=i([]),p=i(""),C=i(!1),M=i(0),x=i(!1),S=()=>{x.value=!1,w()},F=i(s.state.dossier.dated),_=i(s.state.dossier.datef),r=i([]),f=i(""),v=i(""),d=i(0),W=m(()=>!!s.state.enreg_option_comm?.numerotation_par_agence),U=m(()=>s.state.userCommun6?.id_agence||0),H=m(()=>!!s.state.userCommun6?.Access_Agence),q=m(()=>U.value>0&&!H.value),I=m(()=>W.value),J=m(()=>["CA","pourcentage"]),Q=({selectedRows:l})=>{O.value=l},X=l=>{R.value=l.api},Y=l=>{if(!r.value||r.value.length===0)return 0;const e=r.value.reduce((n,u)=>n+(parseFloat(u.CA)||0),0);return e===0?0:parseFloat(l)/e*100},Z=()=>l=>{if(l.value==null||l.value===""||l.value==="null")return"";const e=parseFloat(l.value);if(isNaN(e))return"";const n=D(e);return l.node&&l.node?.rowPinned?`<span style="font-weight: 600;">${n}</span>`:`<span class="font-bold text-green-600">${n}</span>`},ee=()=>l=>{if(l.value==null||l.value===""||l.value==="null"){if(l.data&&l.data.CA){const u=Y(l.data.CA),h=D(u);return`
          <div class="flex items-center justify-end gap-2 bg-cyan-50 px-2 py-1 rounded">
            <div class="w-16 bg-gray-200 rounded-full h-2 mr-2">
              <div class="bg-blue-600 h-2 rounded-full transition-all duration-300" style="width: ${u}%"></div>
            </div>
            <span class="font-medium text-blue-600">${h}%</span>
          </div>
        `}return""}if(l.node&&l.node?.rowPinned)return'<span style="font-weight: 600;">100%</span>';const e=l.value,n=D(e);return`
      <div class="flex items-center justify-end gap-2 bg-cyan-50 px-2 py-1 rounded">
        <div class="w-16 bg-gray-200 rounded-full h-2 mr-2">
          <div class="bg-blue-600 h-2 rounded-full transition-all duration-300" style="width: ${e}%"></div>
        </div>
        <span class="font-medium text-blue-600">${n}%</span>
      </div>
    `},T=(l,e)=>{F.value=l,_.value=e};fe(async()=>{await le(),d.value=U.value,w()});const le=async()=>{try{const e=(await j.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:817,mail:s.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(b("Vous n'avez pas le droit, veuillez consulter l'administrateur"),E("ChiffreAffaireParModeDePaiement")))}catch(l){const e=l.response?.data?.message||l.message;P(e)}},w=async()=>{s.state.afficher_in_progress=!0;try{const l=await j.post(`${s.lienApi}/ChiffreAffaireParModeDePaiement/${s.db}`,{dateDu:F.value,dateAu:_.value,IDcommercial:f.value||null,IDmodep:v.value||null,id_agence:d.value,rechercheString:p.value},{headers:{"Content-Type":"application/json"}});if(r.value=l.data,r.value&&r.value.length>0){const e=r.value.reduce((n,u)=>n+(parseFloat(u.CA)||0),0);r.value=r.value.map(n=>({...n,pourcentage:e>0?parseFloat(n.CA)/e*100:0}))}}catch(l){const e=l.response?.data?.message||l.message;P(e)}finally{s.state.afficher_in_progress=!1}},te=()=>{if(!r.value||r.value.length===0){b("Aucune donnée à imprimer");return}C.value=!0},ae=()=>{if(!A.value){b("Grille non initialisée");return}if(r.value.length===0){b("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");A.value.exportToExcel(`Chiffre d'affaire par mode de paiement_${s.state.enreg_societe.Nom}_${e}.xlsx`)};return(l,e)=>{const n=re,u=ie,h=pe,N=ue,z=me,c=ce,oe=de,ne=se;return g(),V("div",Ce,[a("div",xe,[a("div",we,[o(n,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=t=>w()),text:"",loading:k(s).state.afficher_in_progress},null,8,["loading"]),o(n,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=t=>$.value.toggle(t))}),o(u,{ref_key:"actionsMenu",ref:$,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>ae()},{label:"Imprimer",icon:"pi pi-print",command:()=>te()}],popup:!0},null,8,["model"]),K.masquerFermer?y("",!0):(g(),B(n,{key:0,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=t=>k(E)("ChiffreAffaireParModeDePaiement"))}))]),a("div",ye,[o(n,{icon:"pi pi-filter",text:"",class:"p-button lg:!hidden",onClick:e[3]||(e[3]=t=>x.value=!0),"aria-label":"Filtres"}),o(h,{fen:"ChiffreAffaireParModeDePaiement",text:"Chiffre Affaire Par Mode De Paiement"})])]),a("div",null,[a("div",Ae,[a("div",null,[e[17]||(e[17]=a("label",{class:"block text-sm"},"Recherche",-1)),o(N,{size:"small",modelValue:p.value,"onUpdate:modelValue":e[4]||(e[4]=t=>p.value=t),placeholder:"Rechercher dans le CA par mode de paiement...",class:"w-full",onKeyup:e[5]||(e[5]=G(t=>w(),["enter"]))},null,8,["modelValue"])]),a("div",null,[e[18]||(e[18]=a("label",{class:"block text-sm"},"Période",-1)),o(z,{onSelectDate:T,resetCounter:M.value},null,8,["resetCounter"])]),a("div",null,[e[19]||(e[19]=a("label",{class:"block text-sm"},"Serveur/Commercial",-1)),o(c,{modelValue:f.value,"onUpdate:modelValue":e[6]||(e[6]=t=>f.value=t),placeholder:"Sélectionner un commercial",table:"commercial",class:"w-full"},null,8,["modelValue"])]),a("div",null,[e[20]||(e[20]=a("label",{class:"block text-sm"},"Mode de paiement",-1)),o(c,{modelValue:v.value,"onUpdate:modelValue":e[7]||(e[7]=t=>v.value=t),table:"modep",class:"w-full"},null,8,["modelValue"])]),I.value?(g(),V("div",he,[e[21]||(e[21]=a("label",{class:"block text-sm"},"Agence",-1)),o(c,{modelValue:d.value,"onUpdate:modelValue":e[8]||(e[8]=t=>d.value=t),placeholder:"Toutes les agences",table:"agence",class:"w-full",size:"small",disabled:q.value},null,8,["modelValue","disabled"])])):y("",!0)])]),o(oe,{visible:x.value,"onUpdate:visible":e[15]||(e[15]=t=>x.value=t),position:"right",header:"Filtres",style:{width:"90%","max-width":"360px"}},{default:ve(()=>[a("div",Ve,[a("div",null,[e[22]||(e[22]=a("label",{class:"block",style:{"margin-bottom":"4px"}},"Recherche",-1)),o(N,{size:"small",modelValue:p.value,"onUpdate:modelValue":e[9]||(e[9]=t=>p.value=t),placeholder:"Rechercher dans le CA par mode de paiement...",class:"w-full",onKeyup:e[10]||(e[10]=G(t=>S(),["enter"]))},null,8,["modelValue"])]),a("div",null,[e[23]||(e[23]=a("label",{class:"block",style:{"margin-bottom":"4px"}},"Période",-1)),o(z,{onSelectDate:T,resetCounter:M.value},null,8,["resetCounter"])]),a("div",null,[e[24]||(e[24]=a("label",{class:"block",style:{"margin-bottom":"4px"}},"Serveur/Commercial",-1)),o(c,{modelValue:f.value,"onUpdate:modelValue":e[11]||(e[11]=t=>f.value=t),placeholder:"Sélectionner un commercial",table:"commercial",class:"w-full"},null,8,["modelValue"])]),a("div",null,[e[25]||(e[25]=a("label",{class:"block",style:{"margin-bottom":"4px"}},"Mode de paiement",-1)),o(c,{modelValue:v.value,"onUpdate:modelValue":e[12]||(e[12]=t=>v.value=t),table:"modep",class:"w-full"},null,8,["modelValue"])]),I.value?(g(),V("div",ke,[e[26]||(e[26]=a("label",{class:"block",style:{"margin-bottom":"4px"}},"Agence",-1)),o(c,{modelValue:d.value,"onUpdate:modelValue":e[13]||(e[13]=t=>d.value=t),placeholder:"Toutes les agences",table:"agence",class:"w-full",size:"small",disabled:q.value},null,8,["modelValue","disabled"])])):y("",!0),o(n,{icon:"pi pi-search",label:"Rechercher",onClick:e[14]||(e[14]=t=>S()),loading:k(s).state.afficher_in_progress},null,8,["loading"])])]),_:1},8,["visible"]),e[27]||(e[27]=a("div",{class:"h-2"},null,-1)),a("div",De,[o(be,{ref_key:"dataGrid",ref:A,"excel-file-name":"Chiffre affaire par mode de paiement","excel-sheet-name":"Chiffre affaire par mode de paiement","row-data":r.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":{Mode:280,CA:200,pourcentage:200},"custom-renderers":{CA:Z(),pourcentage:ee()},"enable-totals":!0,"numeric-columns":J.value,"totals-columns":["CA"],onRowClicked:l.handleRowClick,onSelectionChanged:Q,onGridReady:X},null,8,["row-data","custom-renderers","numeric-columns","onRowClicked"])]),C.value?(g(),B(ne,{key:0,show:C.value,dataList:r.value,titre:"Chiffre Affaire Par Mode De Paiement",gridApi:R.value,onClose:e[16]||(e[16]=t=>C.value=!1)},null,8,["show","dataList","gridApi"])):y("",!0)])}}};export{je as default};
