import{_ as W}from"./Imprimer-DluCFs7h.js";import{C as J}from"./ComboDynamique-BzWI4ISP.js";import{s as K}from"./selectDate-Dai2cu2_.js";import{b as Q,B as X}from"./primevue-CfIk0_DY.js";import{o as Y,b as w,c as Z,j as k,H as S,k as $,p as V,d as a,v as r,a7 as ee,F as te,a as o,E as oe,y as ae}from"./vue-core-Di3IuVqe.js";import{u as ie,s as i,b as q,S as M}from"./index-BxIwIJfy.js";import{D as se}from"./DataGrid-CoMfrBJA.js";import le from"./DetailAffaire-7hGd3zga.js";import"./ReportViewer-BNzhW7G2.js";import"./stimulsoft-B2-Y-rC1.js";import"./cjs-helpers-psZwOBky.js";import"./PDFButton-DhVJ6hNy.js";import"./moment-BeHQNF8T.js";import"./vue-cal-DKMVGERa.js";import"./useAgGridConfig-Dp3DkgaV.js";const re={class:"page-wrapper"},ne={class:"flex min-w-full justify-between p-2"},ce={class:"flex items-center gap-2"},ue={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 w-full mb-6 p-2"},fe={class:"field"},pe={class:"field"},de={class:"field"},me={class:"grille-container"},qe={__name:"SuiviDesAffaires",setup(ve){const{showError:v,showInfo:y,showWarn:N}=ie(),c=oe({lecture:!1,ajout:!1}),T=async()=>{try{const e=(await q.post(`${i.lienApi}/verifierDroit/${i.state.dbCommun6}`,{id_utilisateur:i.userId,id_page:907,mail:i.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(c.lecture=e.lecture,c.ajout=e.ajout),c.lecture||(N("Vous n'avez pas le droit, veuillez consulter l'administrateur"),M("SuiviDesAffaires"))}catch(t){v("Une erreur est survenue : "+(t.response?.data?.message||t.message))}},b=o(),n=o(),u=o(!1),f=o(!1),g=o(null),D=o(""),A=o(""),h=o(""),x=o(0),p=o([]),I=o([]),_=o(null),C=o(""),j=ae(()=>{const t={};return t.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"}},t.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"}},t.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"}},t.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é"}},t.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"}},t.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"}},t.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"}},t}),B=({event:t,ndoc:e,rowIndex:s})=>{const m=t.data;_.value=m.affaire_id,C.value=m.lib_affaire,g.value=s,P()},E=({selectedRows:t})=>{I.value=t},F=t=>{n.value=t.api};Y(async()=>{await T(),d()});const G=(t,e)=>{D.value=t,A.value=e,d()},d=async()=>{i.state.afficher_in_progress=!0;try{const t=await q.post(`${i.lienApi}/suiviDesAffaires/${i.db}`,{sai_dateDu:D.value,sai_dateAu:A.value,Combo_Affaire:x.value,sai_code_client:h.value},{headers:{"Content-Type":"application/json"}});p.value=t.data}catch(t){const e=t.response?.data?.message||t.message;v(`Une erreur est survenue : 
 ${e}`)}finally{i.state.afficher_in_progress=!1}},P=async()=>{try{f.value=!0,i.dispatch("tabs/changeTab",{id:"SuiviDesAffaires",newProps:{text:`Affaire N°${_.value}`,iconFermer:!1}})}catch(t){const e=t.response?.data?.message||t.message;v(`Une erreur est survenue : ${e}`)}finally{i.state.afficher_in_progress=!1}},U=()=>{f.value=!1,i.dispatch("tabs/changeTab",{id:"SuiviDesAffaires",newProps:{text:"Suivi des affaires",iconFermer:!0}}),d(),g.value!=null&&n.value&&setTimeout(()=>{const t=n.value.getDisplayedRowCount();if(t>0){const e=Math.min(g.value,t-1),s=n.value.getDisplayedRowAtIndex(e);s&&(n.value.deselectAll(),s.setSelected(!0),n.value.ensureNodeVisible(s,"middle"))}},100)},L=()=>{u.value=!0},z=()=>{if(!b.value){y("Grille non initialisée");return}if(p.value.length===0){y("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");b.value.exportToExcel(`SuiviDesAffaires_${i.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const s=Q,m=X,O=K,R=J,H=W;return w(),Z(te,null,[f.value?k((w(),$(le,{key:0,ndoc:_.value,onClose:U,lib_affaire:C.value},null,8,["ndoc","lib_affaire"])),[[S,c.lecture]]):V("",!0),k(a("div",re,[a("div",ne,[a("div",ce,[r(s,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:e[0]||(e[0]=l=>d())}),r(s,{label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=l=>t.$refs.actionsMenuList.toggle(l)),text:"",class:"mr-3"}),r(m,{ref:"actionsMenuList",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:z},{label:"Imprimer la liste",icon:"pi pi-print",command:L}],popup:!0},null,8,["model"]),r(s,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=l=>ee(M)("SuiviDesAffaires"))})])]),a("div",ue,[a("div",fe,[e[6]||(e[6]=a("label",{for:"devise",class:"block mb-2"}," Période ",-1)),r(O,{onSelectDate:G})]),a("div",pe,[e[7]||(e[7]=a("label",{for:"devise",class:"block mb-2"}," Client ",-1)),r(R,{class:"w-full",placeholder:"Client",table:"client",modelValue:h.value,"onUpdate:modelValue":e[3]||(e[3]=l=>h.value=l)},null,8,["modelValue"])]),a("div",de,[e[8]||(e[8]=a("label",{for:"devise",class:"block mb-2"}," Affaire ",-1)),r(R,{class:"w-full",placeholder:"Affaire",table:"affaire",modelValue:x.value,"onUpdate:modelValue":e[4]||(e[4]=l=>x.value=l)},null,8,["modelValue"])])]),e[9]||(e[9]=a("div",{class:"h-2"},null,-1)),a("div",me,[r(se,{ref_key:"dataGrid",ref:b,"excel-file-name":"Suivi des affaires","excel-sheet-name":"Suivi des affaires","row-data":p.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":j.value,onRowClicked:B,onSelectionChanged:E,onGridReady:F},null,8,["row-data","custom-status-colors"])])],512),[[S,!f.value&&c.lecture]]),u.value?(w(),$(H,{key:1,show:u.value,onClose:e[5]||(e[5]=l=>u.value=!1),data:p.value,RapportName:"/classique/commercial/suivieDesAffaires"},null,8,["show","data"])):V("",!0)],64)}}};export{qe as default};
