import{_ as G}from"./Imprimer-CqTc6qE9.js";import{_ as L}from"./ComboDynamique-CzrtYPe1.js";import{_ as U}from"./selectDate-B99dlzOe.js";import{f as j,o as h,c as z,i as D,d as k,an as O,ap as H,b as a,a as s,z as J,av as K,q as Q,F as W,r as t,e as X}from"./vendor-0kGcmQpG.js";import{u as Y,s as n,a as Z,S as ee}from"./index-Bn9WoKhP.js";import{_ as oe}from"./DataGrid-tb6QVwpZ.js";import te from"./DetailAffaire-C8ONUOaM.js";import"./ReportViewer-1Jmo7TFF.js";import"./useAgGridConfig-DjXMc6wb.js";const ae={class:"w-full flex flex-col overflow-hidden overflow-y-auto",style:{height:"calc(100vh - 108px)"}},ie={class:"flex min-w-full justify-between p-2"},le={class:"flex items-center gap-2"},se={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 w-full mb-6 p-2"},ne={class:"field"},re={class:"field"},ce={class:"field"},ue={style:{height:"calc(100vh - 220px)"}},we={__name:"SuiviDesAffaires",setup(fe){const{showError:x,showInfo:w}=Y(),m=t(),r=t(),c=t(!1),u=t(!1),v=t(null),y=t(""),R=t(""),_=t(""),b=t(0),f=t([]),S=t([]),g=t(null),A=t(""),$=X(()=>{const o={};return o.marge={positive:{color:"#10b981",icon:"pi-arrow-up",text:"Marge positive"},negative:{color:"#ef4444",icon:"pi-arrow-down",text:"Marge négative"},neutral:{color:"#6b7280",icon:"pi-minus",text:"Marge nulle"}},o.Reliquat_a_facturer={high:{color:"#f59e0b",icon:"pi-exclamation-triangle",text:"Reliquat élevé à facturer"},medium:{color:"#3b82f6",icon:"pi-info-circle",text:"Reliquat moyen à facturer"},low:{color:"#10b981",icon:"pi-check-circle",text:"Reliquat faible à facturer"},none:{color:"#6b7280",icon:"pi-minus-circle",text:"Rien à facturer"}},o.Reliquat_a_payer={high:{color:"#dc2626",icon:"pi-exclamation-triangle",text:"Reliquat élevé à payer"},medium:{color:"#f59e0b",icon:"pi-info-circle",text:"Reliquat moyen à payer"},low:{color:"#3b82f6",icon:"pi-check-circle",text:"Reliquat faible à payer"},none:{color:"#6b7280",icon:"pi-minus-circle",text:"Rien à payer"}},o.factureeNonPaye={high:{color:"#dc2626",icon:"pi-times-circle",text:"Important facturé non payé"},medium:{color:"#f59e0b",icon:"pi-exclamation-circle",text:"Moyen facturé non payé"},low:{color:"#3b82f6",icon:"pi-info-circle",text:"Peu facturé non payé"},none:{color:"#10b981",icon:"pi-check-circle",text:"Tout payé"}},o.vente={high:{color:"#10b981",icon:"pi-chart-line",text:"Ventes élevées"},medium:{color:"#3b82f6",icon:"pi-chart-bar",text:"Ventes moyennes"},low:{color:"#6b7280",icon:"pi-minus",text:"Ventes faibles"}},o.achat={high:{color:"#8b5cf6",icon:"pi-shopping-cart",text:"Achats élevés"},medium:{color:"#06b6d4",icon:"pi-shopping-bag",text:"Achats moyens"},low:{color:"#6b7280",icon:"pi-minus",text:"Achats faibles"}},o.charges={high:{color:"#f59e0b",icon:"pi-exclamation-triangle",text:"Charges élevées"},medium:{color:"#3b82f6",icon:"pi-info-circle",text:"Charges moyennes"},low:{color:"#10b981",icon:"pi-check-circle",text:"Charges faibles"}},o}),q=({event:o,ndoc:e,rowIndex:i})=>{const d=o.data;g.value=d.affaire_id,A.value=d.lib_affaire,v.value=i,T()},V=({selectedRows:o})=>{S.value=o},M=o=>{r.value=o.api};j(async()=>{p()});const N=(o,e)=>{y.value=o,R.value=e,p()},p=async()=>{n.state.afficher_in_progress=!0;try{const o=await Z.post(`${n.lienApi}/suiviDesAffaires/${n.db}`,{sai_dateDu:y.value,sai_dateAu:R.value,Combo_Affaire:b.value,sai_code_client:_.value},{headers:{"Content-Type":"application/json"}});f.value=o.data}catch(o){const e=o.response?.data?.message||o.message;x(`Une erreur est survenue : 
 ${e}`)}finally{n.state.afficher_in_progress=!1}},T=async()=>{try{u.value=!0,n.dispatch("tabs/changeTab",{id:"SuiviDesAffaires",newProps:{text:`Affaire N°${g.value}`,iconFermer:!1}})}catch(o){const e=o.response?.data?.message||o.message;x(`Une erreur est survenue : ${e}`)}finally{n.state.afficher_in_progress=!1}},I=()=>{u.value=!1,n.dispatch("tabs/changeTab",{id:"SuiviDesAffaires",newProps:{text:"Suivi des affaires",iconFermer:!0}}),p(),v.value!=null&&r.value&&setTimeout(()=>{const o=r.value.getDisplayedRowCount();if(o>0){const e=Math.min(v.value,o-1),i=r.value.getDisplayedRowAtIndex(e);i&&(r.value.deselectAll(),i.setSelected(!0),r.value.ensureNodeVisible(i,"middle"))}},100)},F=()=>{c.value=!0},P=()=>{if(!m.value){w("Grille non initialisée");return}if(f.value.length===0){w("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");m.value.exportToExcel(`SuiviDesAffaires_${n.state.enreg_societe.Nom}_${e}.xlsx`)};return(o,e)=>{const i=J,d=K,B=U,C=L,E=G;return h(),z(W,null,[u.value?(h(),D(te,{key:0,ndoc:g.value,onClose:I,lib_affaire:A.value},null,8,["ndoc","lib_affaire"])):k("",!0),O(a("div",ae,[a("div",ie,[a("div",le,[s(i,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:e[0]||(e[0]=l=>p())}),s(i,{label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=l=>o.$refs.actionsMenuList.toggle(l)),text:"",class:"mr-3"}),s(d,{ref:"actionsMenuList",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:P},{label:"Imprimer la liste",icon:"pi pi-print",command:F}],popup:!0},null,8,["model"]),s(i,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=l=>Q(ee)("SuiviDesAffaires"))})])]),a("div",se,[a("div",ne,[e[6]||(e[6]=a("label",{for:"devise",class:"block mb-2"}," Période ",-1)),s(B,{onSelectDate:N})]),a("div",re,[e[7]||(e[7]=a("label",{for:"devise",class:"block mb-2"}," Client ",-1)),s(C,{class:"w-full",placeholder:"Client",table:"client",modelValue:_.value,"onUpdate:modelValue":e[3]||(e[3]=l=>_.value=l)},null,8,["modelValue"])]),a("div",ce,[e[8]||(e[8]=a("label",{for:"devise",class:"block mb-2"}," Affaire ",-1)),s(C,{class:"w-full",placeholder:"Affaire",table:"affaire",modelValue:b.value,"onUpdate:modelValue":e[4]||(e[4]=l=>b.value=l)},null,8,["modelValue"])])]),e[9]||(e[9]=a("div",{class:"h-2"},null,-1)),a("div",ue,[s(oe,{ref_key:"dataGrid",ref:m,"excel-file-name":"Suivi des affaires","excel-sheet-name":"Suivi des affaires","row-data":f.value,"document-number-fields":["affaire_id"],"excluded-columns":[],"numeric-columns":["Reliquat_a_facturer","Reliquat_a_payer","achat","charges","marge","montant","paiement","vente","factureeNonPaye"],"custom-status-colors":$.value,onRowClicked:q,onSelectionChanged:V,onGridReady:M},null,8,["row-data","custom-status-colors"])])],512),[[H,!u.value]]),c.value?(h(),D(E,{key:1,show:c.value,onClose:e[5]||(e[5]=l=>c.value=!1),data:f.value,RapportName:"/classique/commercial/suivieDesAffaires"},null,8,["show","data"])):k("",!0)],64)}}};export{we as default};
