import{_ as W}from"./RapportDynamique-BvCuWpYR.js";import{u as J,s as n,a as h,S as $,f as p,g as K,h as C}from"./index-Bn9WoKhP.js";import{r as l,f as X,o as w,c as Y,b as o,a as i,q as k,z as Z,j as ee,av as te,i as T,d as q,h as N,F as oe,e as ne}from"./vendor-0kGcmQpG.js";import{_ as se}from"./FavorisSwitch-DD6nTfzi.js";import{_ as ae}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const le={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},ie={class:"btns flex items-center gap-2"},re={class:"flex items-center p-2"},ue={class:"flex flex-row gap-3 px-4 items-end"},de={class:"flex flex-col"},ce={class:"flex flex-col"},pe={class:"flex flex-col"},me={class:"flex flex-col"},fe={style:{height:"calc(100vh - 220px)"}},Ae={__name:"ComparaisonPeriodiqueDuCA",props:["masquerFermer"],setup(F){const{showInfo:_,showError:A,showWarn:D}=J(),R=F,m=l(),P=l(),H=l([]),b=l(),u=l(!1),r=l([]),f=l(new Date(n.state.annee_fiscale-1,0,1)),v=l(new Date(n.state.annee_fiscale-1,11,31)),x=l(new Date(n.state.annee_fiscale,0,1)),g=l(new Date(n.state.annee_fiscale,11,31)),M=ne(()=>["CA HT Période 1","CA HT Période 2","Évolution %"]),S=({event:t,ndoc:e})=>{},z=({selectedRows:t})=>{H.value=t},B=t=>{P.value=t.api},E=()=>t=>{if(t.value==null||t.value===""||t.value==="null")return"";const e=parseFloat(t.value);if(isNaN(e))return"";const s=C(e);return t.node&&t.node.rowPinned?`<span style="font-weight: 600;">${s}</span>`:`<span class="font-medium text-blue-600">${s}</span>`},G=()=>t=>{if(t.value==null||t.value===""||t.value==="null")return"";const e=parseFloat(t.value);if(isNaN(e))return"";const s=C(e);return t.node&&t.node.rowPinned?`<span style="font-weight: 600;">${s}</span>`:`<span class="font-medium text-green-600">${s}</span>`},I=()=>t=>{if(t.value==null||t.value===""||t.value==="null")return"";const e=parseFloat(t.value)||0,s=j(e),d=C(e);return t.node&&t.node.rowPinned?`<span style="font-weight: 600;">${d}%</span>`:`
      <div class="flex items-center justify-end gap-2">
        <i class="${e>0?"pi pi-arrow-up text-green-600":e<0?"pi pi-arrow-down text-red-600":"pi pi-minus text-gray-400"} text-xs"></i>
        <span style="color: ${s}" class="font-bold">
          ${d}%
        </span>
      </div>
    `},j=t=>t<0?"#dc2626":t>0?"#16a34a":"#6b7280";X(async()=>{await L(),y()});const L=async()=>{try{const e=(await h.post(`${n.lienApi}/verifierDroit/${n.state.dbCommun6}`,{id_utilisateur:n.userId,id_page:809,mail:n.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(D("Vous n'avez pas le droit, veuillez consulter l'administrateur"),$("ComparaisonPeriodiqueDuCA")))}catch(t){const e=t.response?.data?.message||t.message;A(e)}},y=async()=>{n.state.afficher_in_progress=!0;try{const t=await h.post(`${n.lienApi}/ComparaisonPeriodiqueDuCA/${n.state.nomBase}`,{date1Du:p(f.value),date1Au:p(v.value),date2Du:p(x.value),date2Au:p(g.value)});r.value=t.data.map(e=>({"Code client":e.code_client,Nom:e.nom,"CA HT Période 1":e.montant1,"CA HT Période 2":e.montant2,"Évolution %":e.variation}))}catch(t){const e=t.response?.data?.message||t.message;A(e)}finally{n.state.afficher_in_progress=!1}},U=()=>{if(!r.value||r.value.length===0){D("Aucune donnée à imprimer");return}u.value=!0},O=()=>{if(!m.value){_("Grille non initialisée");return}if(r.value.length===0){_("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");m.value.exportToExcel(`Comparaison CA_${n.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const s=Z,d=se,V=te,c=K,Q=W;return w(),Y(oe,null,[o("div",le,[o("div",ie,[i(s,{icon:"pi pi-chart-line",label:"Comparer",onClick:y,text:"",loading:k(n).state.afficher_in_progress},null,8,["loading"]),i(s,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[0]||(e[0]=a=>b.value?.toggle(a))}),i(V,{ref_key:"actionsMenu",ref:b,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>O()},{label:"Imprimer",icon:"pi pi-print",command:()=>U()},{label:"Favoris",icon:"pi pi-star",template:"favorisTemplate"}],popup:!0},{favorisTemplate:ee(()=>[o("div",re,[i(d,{fen:"ComparaisonPeriodiqueDuCA",text:"Comparaison Periodique CA"}),e[7]||(e[7]=o("span",{class:"font-semibold ml-2 text-primary"},"Favoris",-1))])]),_:1},8,["model"]),R.masquerFermer?q("",!0):(w(),T(s,{key:0,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=a=>k($)("ComparaisonPeriodiqueDuCA"))}))]),e[8]||(e[8]=o("div",{class:"flex items-center gap-3 whitespace-nowrap"},null,-1))]),o("div",ue,[o("div",de,[e[9]||(e[9]=o("label",{class:"text-sm"},[o("i",{class:"pi pi-calendar text-blue-600 mr-2"}),N(" Période 1 - Du ")],-1)),i(c,{size:"small",modelValue:f.value,"onUpdate:modelValue":e[2]||(e[2]=a=>f.value=a),placeholder:"Date Du","input-class":"w-64"},null,8,["modelValue"])]),o("div",ce,[e[10]||(e[10]=o("label",{class:"text-sm"},"Période 1 - Au",-1)),i(c,{size:"small",modelValue:v.value,"onUpdate:modelValue":e[3]||(e[3]=a=>v.value=a),placeholder:"Date Au","input-class":"w-64"},null,8,["modelValue"])]),o("div",pe,[e[11]||(e[11]=o("label",{class:"text-sm"},[o("i",{class:"pi pi-calendar text-green-600 mr-2"}),N(" Période 2 - Du ")],-1)),i(c,{size:"small",modelValue:x.value,"onUpdate:modelValue":e[4]||(e[4]=a=>x.value=a),placeholder:"Date Du","input-class":"w-64"},null,8,["modelValue"])]),o("div",me,[e[12]||(e[12]=o("label",{class:"text-sm"},"Période 2 - Au",-1)),i(c,{size:"small",modelValue:g.value,"onUpdate:modelValue":e[5]||(e[5]=a=>g.value=a),placeholder:"Date Au","input-class":"w-64"},null,8,["modelValue"])])]),e[13]||(e[13]=o("div",{class:"h-2"},null,-1)),o("div",fe,[i(ae,{ref_key:"dataGrid",ref:m,"excel-file-name":"Comparaison periodique du CA","excel-sheet-name":"Comparaison periodique du CA","row-data":r.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":{"Code client":140,Nom:500,"CA HT Période 1":150,"CA HT Période 2":150,"Évolution %":120},"custom-renderers":{"CA HT Période 1":E(),"CA HT Période 2":G(),"Évolution %":I()},"enable-totals":!0,"numeric-columns":M.value,"totals-columns":["CA HT Période 1","CA HT Période 2","Évolution %"],onRowClicked:S,onSelectionChanged:z,onGridReady:B},null,8,["row-data","custom-renderers","numeric-columns"])]),u.value?(w(),T(Q,{key:0,show:u.value,dataList:r.value,titre:"Comparaison Periodique Du CA",gridApi:P.value,onClose:e[6]||(e[6]=a=>u.value=!1)},null,8,["show","dataList","gridApi"])):q("",!0)],64)}}};export{Ae as default};
