import{f as I,g as G,o as p,c as L,b as g,i as x,z as M,d as y,a as f,q as j,F as J,r as c,aJ as z,aK as H}from"./vendor-BDR7yMJi.js";import{u as V,a as q,s as C,S as O,j as W,h as v}from"./index-BSaHX2oa.js";const K={class:"w-full mb-6 flex flex-col sm:flex-row items-center gap-3 p-1"},X={style:{height:"calc(100vh - 180px)"}},Z={__name:"ImportationEcritures",props:["numeros","type"],emits:["close"],setup(o,{emit:w}){const{showError:F}=V(),S=c(null);let u=null;const d=c([]),k=c(null),A=c([{headerName:"Journal",field:"CodeJournal",width:120,sortable:!0,filter:"agTextColumnFilter",cellStyle:{textAlign:"center"}},{headerName:"Date",field:"date",width:120,sortable:!0,filter:"agTextColumnFilter",cellStyle:{textAlign:"center"},valueFormatter:e=>W(e.value)},{headerName:"N° Pièce",field:"Piece",width:120,sortable:!0,filter:"agTextColumnFilter",cellStyle:{textAlign:"center"}},{headerName:"Reference",field:"Reference",width:120,sortable:!0,filter:"agTextColumnFilter",cellStyle:{textAlign:"center"}},{headerName:"Compte",field:"code_comptable",width:120,sortable:!0,filter:"agTextColumnFilter",cellStyle:{textAlign:"center"}},{headerName:"Libellé d'écriture",field:"libelle",width:360,sortable:!0,filter:"agTextColumnFilter",cellStyle:{textAlign:"center"}},{headerName:"Debit",field:"debit",width:120,sortable:!0,filter:"agTextColumnFilter",type:"numericColumn",headerClass:"numeric-header-custom",cellStyle:{textAlign:"center"},valueFormatter:e=>v(e.value),aggFunc:"sum"},{headerName:"Credit",field:"credit",width:120,sortable:!0,filter:"agTextColumnFilter",type:"numericColumn",headerClass:"numeric-header-custom",cellStyle:{textAlign:"center"},valueFormatter:e=>v(e.value),aggFunc:"sum"}]),N=w;I(async()=>{if(o.type)switch(o.type){case"facturec":await s("SP_comptabiliserFacturesClient_Excel");break;case"avoirc":await s("SP_comptabiliserAvoirClient_Excel");break;case"facturef":await s("SP_comptabiliserFacturesFournisseur_Excel");break;case"avoirf":await s("SP_comptabiliserAvoirFournisseur_Excel");break}});const s=async e=>{try{const t=await q.post(`${C.lienApi}/${e}/${C.db}`,{numeros:o.numeros},{headers:{"Content-Type":"application/json"}});d.value=t.data.map((a,n)=>({...a,id:a.id||`row_${n}`}))}catch(t){F(`Erreur lors de la récupération des données: ${t.message}`)}},D=e=>{u=e.api},E=()=>{if(u){const e=u.getSelectedRows();k.value=e.length>0?e[0]:null}},T=()=>["copy","copyWithHeaders","separator","export"],_=async()=>{},R=()=>{const e=document.createElement("input");e.setAttribute("type","file"),document.importNode(e),e.click(),e.addEventListener("change",async t=>{var a=t.target.files,n,i;for(n=0,i=a[n];n!=a.length;++n){var h=new FileReader;h.onload=function(P){var $=P.target.result,b=z($,{type:"binary"});const B=b.SheetNames.map(r=>({text:r,value:r}))[0].value,m=H.sheet_to_json(b.Sheets[B],{defval:""});let l=[];m.length>0&&(l=Object.keys(m[0])),d.value=m.map(r=>({Journal:r[l[0]]||"",Date:r[l[1]],NPiece:r[l[2]],Reference:r[l[3]],Compte:r[l[4]],LibelleEcriture:r[l[5]],Debit:r[l[6]],Credit:r[l[7]]}))},h.readAsBinaryString(i)}})};return(e,t)=>{const a=M,n=G("ag-grid-vue");return p(),L(J,null,[g("div",K,[o.type?y("",!0):(p(),x(a,{key:0,onClick:R,icon:"pi pi-file-excel",label:"Importer",text:""})),f(a,{onClick:t[0]||(t[0]=i=>_()),icon:"pi pi-save",label:"Enregistrer",text:""}),f(a,{onClick:t[1]||(t[1]=i=>N("close")),icon:"pi pi-times",label:"Annuler",text:""}),o.type?y("",!0):(p(),x(a,{key:1,icon:"pi pi-times",label:"Fermer",text:"",onClick:t[2]||(t[2]=i=>j(O)("ImportationEcritures"))}))]),g("div",null,[g("div",X,[f(n,{ref_key:"agGrid",ref:S,class:"ag-theme-quartz",style:{height:"100%"},columnDefs:A.value,rowData:d.value,rowSelection:"single",animateRows:!0,enableRangeSelection:!0,suppressRowClickSelection:!1,suppressMenuHide:!1,defaultColDef:{resizable:!0,sortable:!0,filter:"agTextColumnFilter",minWidth:50,suppressHeaderMenuButton:!0},statusBar:{statusPanels:[{statusPanel:"agTotalAndFilteredRowCountComponent",align:"left"},{statusPanel:"agAggregationComponent",align:"right"}]},localeText:e.$agGridLocale,getContextMenuItems:T,onGridReady:D,onSelectionChanged:E},null,8,["columnDefs","rowData","localeText"])])])],64)}}};export{Z as default};
