import{r as a,f as V,g as z,o as w,c as G,b as d,a as p,z as I,B as W,i as q,q as M,d as E,F as U,e as j}from"./vendor-0kGcmQpG.js";import{u as H,s as c,a as O,S as X,k as J,h as v,m as n,A as o}from"./index-Bn9WoKhP.js";import{R as K}from"./ReportViewer-1Jmo7TFF.js";const Q={class:"w-full flex flex-col overflow-hidden overflow-y-auto gap-1",style:{height:"calc(100vh - 108px)"}},Y={class:"flex items-center gap-2 p-2"},Z={class:"text-xl font-bold p-4 text-center bg-gray-100 border-b"},ee={class:"h-full overflow-auto p-2"},te={class:"ag-theme-quartz",style:{height:"calc(100vh - 220px)",width:"100%"}},oe={__name:"DetailAffaire",props:{ndoc:{type:String,default:""},close:{type:Function},lib_affaire:{type:String,default:""},fermerParRetour:{type:Boolean,default:!1}},emits:["close"],setup(F,{emit:D}){const{showError:h,showWarn:b}=H(),g=F,R=D,A=a(),C=a(),m=a(g.ndoc),f=a(!1),s=a(null),i=a([]),_={entete:"imprimerDetailAffaireEntete",lignes:"imprimerDetailAffaireLignes"},y=j(()=>{if(i.value.length===0)return[];const e=i.value.reduce((l,r)=>l+(r.vente||0),0),t=i.value.reduce((l,r)=>l+(r.achat||0),0),u=i.value.reduce((l,r)=>l+(r.charges||0),0);return[{date:null,doc:"",libelle:"TOTAUX",vente:e,achat:t,charges:u,ref_doc:null}]}),x=a([{field:"date",headerName:"Date",width:120,sortable:!0,filter:"agDateColumnFilter",valueFormatter:e=>e.value?J(e.value):""},{field:"doc",headerName:"Document",width:160,sortable:!0,filter:"agTextColumnFilter"},{field:"libelle",headerName:"Reference du document",width:250,sortable:!0,filter:"agTextColumnFilter",cellStyle:e=>e.node.rowPinned?{fontWeight:"bold",backgroundColor:"#f3f4f6"}:null},{field:"vente",headerName:"Ventes",width:140,sortable:!0,filter:"agNumberColumnFilter",cellClass:"ag-right-aligned-cell",cellStyle:e=>e.node.rowPinned?{fontWeight:"bold",backgroundColor:"#f3f4f6"}:null,valueFormatter:e=>e.value!==null&&e.value!==void 0?v(e.value):""},{field:"achat",headerName:"Achats",width:140,sortable:!0,filter:"agNumberColumnFilter",cellClass:"ag-right-aligned-cell",cellStyle:e=>e.node.rowPinned?{fontWeight:"bold",backgroundColor:"#f3f4f6"}:null,valueFormatter:e=>e.value!==null&&e.value!==void 0?v(e.value):""},{field:"charges",headerName:"Charges",width:140,sortable:!0,filter:"agNumberColumnFilter",cellClass:"ag-right-aligned-cell",cellStyle:e=>e.node.rowPinned?{fontWeight:"bold",backgroundColor:"#f3f4f6"}:null,valueFormatter:e=>e.value!==null&&e.value!==void 0?v(e.value):""}]),L=a({sortable:!0,filter:"agTextColumnFilter",floatingFilter:!1,resizable:!0,suppressHeaderMenuButton:!0,minWidth:100}),k=e=>{C.value=e.api,e.api.sizeColumnsToFit()},N=()=>{const e=C.value.getSelectedNodes();e.length>0?s.value=e[0].data:s.value=null},B=e=>{s.value=e.data,m.value=e.data.ref_doc,P()};V(async()=>{$()});const $=async()=>{c.state.afficher_in_progress=!0;try{const e=await O.post(`${c.lienApi}/DetailAffaire/${c.db}`,{Combo_Affaire:m.value},{headers:{"Content-Type":"application/json"}});i.value=e.data}catch(e){const t=e.response?.data?.message||e.message;h(`Une erreur est survenue : 
 ${t}`)}finally{c.state.afficher_in_progress=!1}},P=async()=>{if(!s.value||!s.value.ref_doc){b("Veuillez sélectionner un document");return}const e=s.value.ref_doc;try{let t;switch(e.substring(0,2)){case"BL":t=await n.BonDeLivraisonClientLignes(),o({id:"BonDeLivraisonClientLignes",text:`Bon de livraison N° : ${e.substring(2)}`,content:t.default,props:{ndoc:e.substring(2),fermerParRetour:!0}});break;case"FC":t=await n.FactureClientLignes(),o({id:"FactureClientLignes",text:`Facture client N° : ${e.substring(2)}`,content:t.default,props:{ndoc:e.substring(2),fermerParRetour:!0}});break;case"AC":t=await n.AvoirClientLignes(),o({id:"AvoirClientLignes",text:`Avoir client N° : ${e.substring(2)}`,content:t.default,props:{ndoc:e.substring(2),fermerParRetour:!0}});break;case"RC":t=await n.BonDeRetourClientLignes(),o({id:"BonDeRetourClientLignes",text:`Retour client N° : ${e.substring(2)}`,content:t.default,props:{ndoc:e.substring(2),fermerParRetour:!0}});break;case"BR":t=await n.BonrecepLignes(),o({id:"BonrecepLignes",text:`Bon de Réception N° : ${e.substring(2)}`,content:t.default,props:{ndoc:e.substring(2),fermerParRetour:!0}});break;case"FF":t=await n.FactureFrsLignes(),o({id:"FactureFrsLignes",text:`Facture Fournisseur N° : ${e.substring(2)}`,content:t.default,props:{ndoc:e.substring(2),fermerParRetour:!0}});break;case"AF":t=await n.AvoirFrsLignes(),o({id:"AvoirFrsLignes",text:`Avoir Fournisseur N° : ${e.substring(2)}`,content:t.default,props:{ndoc:e.substring(2),fermerParRetour:!0}});break;case"RF":t=await n.BonDeRetourFrsLignes(),o({id:"BonDeRetourFrsLignes",text:`Retour Fournisseur N° : ${e.substring(2)}`,content:t.default,props:{ndoc:e.substring(2),fermerParRetour:!0}});break;default:b("Type de document non reconnu");break}}catch(t){const u=t.response?.data?.message||t.message;h(`Une erreur est survenue : 
 ${u}`)}finally{c.state.afficher_in_progress=!1}},S=()=>{f.value=!0},T=()=>{g.fermerParRetour?X("DetailAffaire"):R("close")};return(e,t)=>{const u=I,l=z("ag-grid-vue");return w(),G(U,null,[d("div",Q,[d("div",Y,[p(u,{icon:"pi pi-print",label:"Imprimer",text:"",onClick:t[0]||(t[0]=r=>S())}),p(u,{icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:t[1]||(t[1]=r=>T())})]),d("div",Z,W(g.lib_affaire),1),d("div",ee,[d("div",te,[p(l,{ref_key:"agGridAffaire",ref:A,rowData:i.value,columnDefs:x.value,defaultColDef:L.value,pinnedBottomRowData:y.value,theme:e.$agGridTheme,localeText:e.$agGridLocale,rowSelection:"single",onGridReady:k,onSelectionChanged:N,onRowDoubleClicked:B,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["rowData","columnDefs","defaultColDef","pinnedBottomRowData","theme","localeText"])])])]),f.value?(w(),q(K,{key:0,show:f.value,onClose:t[2]||(t[2]=r=>f.value=!1),IdDocument:m.value,urls:_,urlFichier:`${M(c).lienApi}/commun/rapports/classique/commercial/detailAffaire.mrt`},null,8,["show","IdDocument","urlFichier"])):E("",!0)],64)}}};export{oe as default};
