import{_ as J}from"./RapportDynamique-BvCuWpYR.js";import{_ as Q}from"./ComboDynamique-CzrtYPe1.js";import{_ as X}from"./selectDate-B99dlzOe.js";import{r as l,f as Y,o as b,c as Z,b as a,a as i,q as D,z as ee,av as te,i as k,d as M,aP as ne,M as ae,F as oe,e as le}from"./vendor-0kGcmQpG.js";import{_ as re}from"./FavorisSwitch-DD6nTfzi.js";import{u as se,s as r,a as V,S as R,h as _}from"./index-Bn9WoKhP.js";import{_ as ie}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const ue={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},de={class:"btns flex items-center gap-2"},ce={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},me={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-4"},pe={style:{height:"calc(100vh - 220px)"}},xe={__name:"ChiffreAffaireParModeDePaiement",props:["masquerFermer"],setup(F){const{showError:w,showWarn:d}=se(),S=F,x=l(),v=l(),y=l(),I=l([]),g=l(""),c=l(!1),N=l(0),A=l(r.state.dossier.dated),P=l(r.state.dossier.datef),o=l([]),m=l(""),p=l(""),f=l(""),q=le(()=>["CA","pourcentage"]),j=({selectedRows:t})=>{I.value=t},B=t=>{y.value=t.api},E=t=>{if(!o.value||o.value.length===0)return 0;const e=o.value.reduce((n,u)=>n+(parseFloat(u.CA)||0),0);return e===0?0:parseFloat(t)/e*100},G=()=>t=>{if(t.value==null||t.value===""||t.value==="null")return"";const e=parseFloat(t.value);if(isNaN(e))return"";const n=_(e);return t.node&&t.node.rowPinned?`<span style="font-weight: 600;">${n}</span>`:`<span class="font-bold text-green-600">${n}</span>`},L=()=>t=>{if(t.value==null||t.value===""||t.value==="null"){if(t.data&&t.data.CA){const u=E(t.data.CA),C=_(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">${C}%</span>
          </div>
        `}return""}if(t.node&&t.node.rowPinned)return'<span style="font-weight: 600;">100%</span>';const e=t.value,n=_(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=(t,e)=>{A.value=t,P.value=e};Y(async()=>{await z(),h()});const z=async()=>{try{const e=(await V.post(`${r.lienApi}/verifierDroit/${r.state.dbCommun6}`,{id_utilisateur:r.userId,id_page:817,mail:r.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(d("Vous n'avez pas le droit, veuillez consulter l'administrateur"),R("ChiffreAffaireParModeDePaiement")))}catch(t){const e=t.response?.data?.message||t.message;w(e)}},h=async()=>{r.state.afficher_in_progress=!0;try{m.value=`and cast(date as date) between '${A.value}' and '${P.value}'`,p.value&&(m.value+=` and paiementc.IDcommercial ='${p.value}'`),f.value&&(m.value+=` and paiementc.IDmodep='${f.value}'`);const t=await V.post(`${r.lienApi}/ChiffreAffaireParModeDePaiement/${r.db}`,{condition:m.value,rechercheString:g.value},{headers:{"Content-Type":"application/json"}});if(o.value=t.data,o.value&&o.value.length>0){const e=o.value.reduce((n,u)=>n+(parseFloat(u.CA)||0),0);o.value=o.value.map(n=>({...n,pourcentage:e>0?parseFloat(n.CA)/e*100:0}))}}catch(t){const e=t.response?.data?.message||t.message;w(e)}finally{r.state.afficher_in_progress=!1}},U=()=>{if(!o.value||o.value.length===0){d("Aucune donnée à imprimer");return}c.value=!0},K=()=>{if(!v.value){d("Grille non initialisée");return}if(o.value.length===0){d("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");v.value.exportToExcel(`Chiffre d'affaire par mode de paiement_${r.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const n=ee,u=te,C=re,O=ae,W=X,$=Q,H=J;return b(),Z(oe,null,[a("div",ue,[a("div",de,[i(n,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=s=>h()),text:"",loading:D(r).state.afficher_in_progress},null,8,["loading"]),i(n,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=s=>x.value.toggle(s))}),i(u,{ref_key:"actionsMenu",ref:x,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>K()},{label:"Imprimer",icon:"pi pi-print",command:()=>U()}],popup:!0},null,8,["model"]),S.masquerFermer?M("",!0):(b(),k(n,{key:0,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=s=>D(R)("ChiffreAffaireParModeDePaiement"))}))]),a("div",ce,[i(C,{fen:"ChiffreAffaireParModeDePaiement",text:"Chiffre Affaire Par Mode De Paiement"})])]),a("div",null,[a("div",me,[a("div",null,[e[8]||(e[8]=a("label",{class:"block text-sm"},"Recherche",-1)),i(O,{size:"small",modelValue:g.value,"onUpdate:modelValue":e[3]||(e[3]=s=>g.value=s),placeholder:"Rechercher dans le CA par mode de paiement...",class:"w-full",onKeyup:e[4]||(e[4]=ne(s=>h(),["enter"]))},null,8,["modelValue"])]),a("div",null,[e[9]||(e[9]=a("label",{class:"block text-sm"},"Période",-1)),i(W,{onSelectDate:T,resetCounter:N.value},null,8,["resetCounter"])]),a("div",null,[e[10]||(e[10]=a("label",{class:"block text-sm"},"Serveur/Commercial",-1)),i($,{modelValue:p.value,"onUpdate:modelValue":e[5]||(e[5]=s=>p.value=s),placeholder:"Sélectionner un commercial",table:"commercial",class:"w-full"},null,8,["modelValue"])]),a("div",null,[e[11]||(e[11]=a("label",{class:"block text-sm"},"Mode de paiement",-1)),i($,{modelValue:f.value,"onUpdate:modelValue":e[6]||(e[6]=s=>f.value=s),table:"modep",class:"w-full"},null,8,["modelValue"])])])]),e[12]||(e[12]=a("div",{class:"h-2"},null,-1)),a("div",pe,[i(ie,{ref_key:"dataGrid",ref:v,"excel-file-name":"Chiffre affaire par mode de paiement","excel-sheet-name":"Chiffre affaire par mode de paiement","row-data":o.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":{Mode:280,CA:200,pourcentage:200},"custom-renderers":{CA:G(),pourcentage:L()},"enable-totals":!0,"numeric-columns":q.value,"totals-columns":["CA"],onRowClicked:t.handleRowClick,onSelectionChanged:j,onGridReady:B},null,8,["row-data","custom-renderers","numeric-columns","onRowClicked"])]),c.value?(b(),k(H,{key:0,show:c.value,dataList:o.value,titre:"Chiffre Affaire Par Mode De Paiement",gridApi:y.value,onClose:e[7]||(e[7]=s=>c.value=!1)},null,8,["show","dataList","gridApi"])):M("",!0)],64)}}};export{xe as default};
