import{f as q,w as L,g as P,o as u,c as m,b as f,a as o,z as K,d as v,i as F,av as O,q as U,r}from"./vendor-0kGcmQpG.js";import{u as W,s as n,a as J,S as Q,k as X,h as d}from"./index-Bn9WoKhP.js";const Y={class:"flex flex-col"},Z={class:"w-full flex flex-wrap items-start md:flex-row justify-start gap-3"},ee={key:0},te={class:"mt-4 bg-white p-4 border border-gray-300 shadow-md"},le={key:0,class:"flex justify-end mb-2"},ae={key:1,class:"flex justify-end mb-2"},re={style:"height: calc(100vh - 240px)",class:"ag-theme-quartz"},se={__name:"EtatDescriptifConsommations",setup(ie){const{showError:h,showWarn:b}=W(),C=r(),N=r(),k=r();let p=r(!1);const s=r([]),V=r(),l=r(!1),c=r(null),w=r(!1),D=r([{headerName:"Date",field:"Date",width:120,valueFormatter:e=>e.value?X(e.value):"",editable:()=>l.value,cellEditor:"agDateCellEditor",sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"Nom ou raison sociale du Fournisseur",field:"NomraisonsocialeFournisseur",width:250,editable:()=>l.value,sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"Identifiant fiscal du fournisseur",field:"Identifiantfiscalournisseur",width:200,editable:()=>l.value,sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"Adresse fournisseur",field:"Adressefournisseur",width:200,editable:()=>l.value,sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"Réf. de la facture",field:"Réffacture",width:150,editable:()=>l.value,sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"Volume d'achat Nom (litres)",field:"VolumeachatNombre",width:180,type:"numericColumn",headerClass:"numeric-header-custom",valueFormatter:e=>e.value?d(e.value):"",cellStyle:{textAlign:"right"},editable:()=>l.value,cellEditor:"agNumberCellEditor",sortable:!0,resizable:!0,filter:"agTextColumnFilter",aggFunc:"sum"},{headerName:"Nombre de Km parcourus",field:"NombreParcourus",width:180,type:"numericColumn",headerClass:"numeric-header-custom",valueFormatter:e=>e.value?d(e.value):"",cellStyle:{textAlign:"right"},editable:()=>l.value,cellEditor:"agNumberCellEditor",sortable:!0,resizable:!0,filter:"agTextColumnFilter",aggFunc:"sum"},{headerName:"Valeur (HT)",field:"ValeurHT",width:120,type:"numericColumn",headerClass:"numeric-header-custom",valueFormatter:e=>e.value?d(e.value):"",cellStyle:{textAlign:"right"},editable:()=>l.value,cellEditor:"agNumberCellEditor",onCellValueChanged:e=>{e.newValue!==e.oldValue&&(x(e.data),e.api.refreshCells({rowNodes:[e.node]}))},sortable:!0,resizable:!0,filter:"agTextColumnFilter",aggFunc:"sum"},{headerName:"Taux en %",field:"Tauxen",width:100,type:"numericColumn",headerClass:"numeric-header-custom",valueFormatter:e=>e.value?d(e.value):"",cellStyle:{textAlign:"right"},editable:()=>l.value,cellEditor:"agNumberCellEditor",onCellValueChanged:e=>{e.newValue!==e.oldValue&&(x(e.data),e.api.refreshCells({rowNodes:[e.node]}))},sortable:!0,resizable:!0,filter:"agTextColumnFilter"},{headerName:"TVA",field:"TVA",width:120,type:"numericColumn",headerClass:"numeric-header-custom",valueFormatter:e=>e.value?d(e.value):"",cellStyle:{textAlign:"right"},editable:()=>l.value,cellEditor:"agNumberCellEditor",sortable:!0,resizable:!0,filter:"agTextColumnFilter",aggFunc:"sum"},{headerName:"Actions",field:"actions",width:100,cellRenderer:e=>l.value?`
        <div class="flex justify-center">
          <button class="delete-btn p-2 text-red-600 hover:text-red-800"
                  data-id="${e.data.id}"
                  title="Supprimer">
            <i class="pi pi-trash"></i>
          </button>
        </div>
      `:"",cellStyle:{textAlign:"center"},sortable:!1,resizable:!1,filter:!1,pinned:"right"}]),A=r({sortable:!0,resizable:!0,filter:"agTextColumnFilter",suppressHeaderMenuButton:!0}),R=r({mode:"singleRow",checkboxes:!1,enableClickSelection:!0}),S=e=>{k.value=e.api,e.api.sizeColumnsToFit()},z=e=>{c.value=e.api.getSelectedRows()[0]||null};q(async()=>{await g()});const g=async()=>{n.state.afficher_in_progress=!0;try{const{data:e}=await J.post(`${n.lienApi}/EtatConsommationGasoil/${n.db}`,{annee_fiscale:n.state.annee_fiscale},{headers:{"Content-Type":"application/json"}});s.value=e.map((t,a)=>({...t,id:t.id||a+1}))}catch(e){h(e.message)}finally{n.state.afficher_in_progress=!1}},E=()=>{l.value=!0,p.value=!0},_=async()=>{p.value=!1,l.value=!1,await g()},$=async()=>{try{n.state.afficher_in_progress=!0,l.value=!1,p.value=!1}catch(e){h("Une erreur est survenue lors de l'enregistrement: "+e.message)}finally{n.state.afficher_in_progress=!1}};L(V,async e=>{e&&await g()});const x=e=>{e.ValeurHT&&e.Tauxen&&(e.TVA=e.ValeurHT*e.Tauxen/100)},M=()=>{const t={id:Math.max(...s.value.map(a=>a.id),0)+1,Date:new Date,NomraisonsocialeFournisseur:"",Identifiantfiscalournisseur:"",Adressefournisseur:"",Réffacture:"",VolumeachatNombre:0,NombreParcourus:0,ValeurHT:0,Tauxen:20,TVA:0};s.value.push(t),c.value=t},B=e=>{b({title:"Confirmation",text:"Voulez-vous vraiment supprimer cette ligne?",showCancelButton:!0,confirmButtonText:"Oui, supprimer",cancelButtonText:"Annuler",callback:()=>{s.value=s.value.filter(t=>t.id!==e.id)}})},y=()=>{w.value=!w.value},T=()=>{window.print()},I=()=>{},G=()=>{if(!c.value){b("Veuillez sélectionner une ligne à supprimer");return}B(c.value)};return(e,t)=>{const a=K,j=O,H=P("ag-grid-vue");return u(),m("div",Y,[f("div",Z,[l.value?v("",!0):(u(),m("div",ee,[o(a,{onClick:t[0]||(t[0]=i=>E()),text:"",icon:"pi pi-pencil",label:"Modifier"})])),l.value?(u(),F(a,{key:1,text:"",icon:"pi pi-save",label:"Enregistrer",onClick:t[1]||(t[1]=i=>$())})):v("",!0),f("div",null,[o(a,{text:"",icon:"pi pi-cog",label:"Actions",onClick:t[2]||(t[2]=i=>C.value.toggle(i))}),o(j,{ref_key:"actionsMenu",ref:C,model:[{label:"Importer",icon:"pi pi-upload",command:()=>I()},{label:"Supprimer",icon:"pi pi-trash",command:()=>G()}],popup:!0},null,8,["model"])]),l.value?(u(),F(a,{key:2,text:"",icon:"pi pi-times",label:"Annuler",onClick:t[3]||(t[3]=i=>_())})):v("",!0),o(a,{icon:"pi pi-times",label:"Fermer",text:"",onClick:t[4]||(t[4]=i=>U(Q)("EtatDescriptifConsommations"))})]),f("div",te,[l.value?(u(),m("div",le,[o(a,{icon:"pi pi-plus",label:"Ajouter",onClick:t[5]||(t[5]=i=>M()),class:"mr-2"}),o(a,{icon:"pi pi-search",label:"Rechercher",onClick:t[6]||(t[6]=i=>y()),class:"mr-2"}),o(a,{icon:"pi pi-print",label:"Imprimer",onClick:t[7]||(t[7]=i=>T())})])):(u(),m("div",ae,[o(a,{icon:"pi pi-search",label:"Rechercher",onClick:t[8]||(t[8]=i=>y()),class:"mr-2"}),o(a,{icon:"pi pi-print",label:"Imprimer",onClick:t[9]||(t[9]=i=>T())})])),f("div",re,[o(H,{ref_key:"agGrid",ref:N,localeText:e.$agGridLocale,rowData:s.value,columnDefs:D.value,defaultColDef:A.value,theme:e.$agGridTheme,rowSelection:R.value,suppressRowClickSelection:!1,pinnedBottomRowData:e.pinnedBottomRowData,getContextMenuItems:e.getContextMenuItems,onGridReady:S,onRowClicked:e.onRowClick,onSelectionChanged:z,onFilterChanged:e.onFilterChanged,onSortChanged:e.onFilterChanged,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["localeText","rowData","columnDefs","defaultColDef","theme","rowSelection","pinnedBottomRowData","getContextMenuItems","onRowClicked","onFilterChanged","onSortChanged"])])])])}}};export{se as default};
