import{r as B,f as O,a5 as o,o as F,i as V,j as k,b as A,c as I,a as T,s as J,d as P,E as $,S as R}from"./vendor-BDR7yMJi.js";import{_,u as j,a as U,s as m}from"./index-BSaHX2oa.js";const H={key:0,class:"loading-overlay"},M={__name:"ReportViewer",props:{show:Boolean,ttc_ht:String,avecEntete:{type:Boolean,default:!0},urlFichier:String,isEnvoiMail:{type:Boolean,default:!1},data:[Array,Object],nomFichier:String},emits:["close","saveFichierPDF"],setup(s,{emit:N}){const{showError:D}=j(),v=N,b=B(s.show),g=B(!0),C=async()=>{try{const e=new o.Stimulsoft.Report.StiReport;e.loadFile(s.urlFichier),s.nomFichier&&(e.reportName=s.nomFichier,e.reportAlias=s.nomFichier);const t=s.data,a={...m.state.enreg_societe};a.avecEntete=s.avecEntete,a.ttc_ht=s.ttc_ht;const d=m.state.enreg_option_comm?.affichage_prix_doc||"BOTH";a.suffixePrix=d==="HT"?"HT":"TTC",a.lienApi=m.lienApi,a.cloudId=m.cloudId,a.id_societe=m.id_societe;const i=(r,f)=>{if(!r)return;const w=Array.isArray(f)?f[0]:f;if(!w)return;const E=new Set;for(let l=0;l<r.columns.count;l++){const u=r.columns.getByIndex(l);E.add(u.nameInSource||u.name)}for(const l in w)if(Object.hasOwn(w,l)){const u=w[l];if(Array.isArray(u)||E.has(l))continue;let h="System.String";typeof u=="number"?h=Number.isInteger(u)?"System.Int32":"System.Decimal":typeof u=="boolean"?h="System.Boolean":u instanceof Date&&(h="System.DateTime");const L=new o.Stimulsoft.Report.Dictionary.StiDataColumn(l,l,l,h);r.columns.add(L)}},S=t&&!Array.isArray(t)&&typeof t=="object"&&(t.Entete||t.Lignes);let c,n;S?(c=t.Entete||[],n=t.Lignes||[]):(c=Array.isArray(t)?t:[],n=null),i(e.dictionary.dataSources.getByName("Entete"),c),i(e.dictionary.dataSources.getByName("Autres"),[a]),n&&i(e.dictionary.dataSources.getByName("Lignes"),n);let y=new o.Stimulsoft.System.Data.DataSet("Entete");y.readJson(JSON.stringify({root:c}));let p=new o.Stimulsoft.System.Data.DataSet("Autres");if(p.readJson(JSON.stringify({root:[a]})),e.dictionary.databases.clear(),e.regData("Entete","Entete",y),e.regData("Autres","Autres",p),n){let r=new o.Stimulsoft.System.Data.DataSet("Lignes");r.readJson(JSON.stringify({root:n})),e.regData("Lignes","Lignes",r)}if(S){for(const r of Object.keys(t))if(r!=="Entete"&&r!=="Lignes")if(Array.isArray(t[r])){i(e.dictionary.dataSources.getByName(r),t[r]);const f=new o.Stimulsoft.System.Data.DataSet(r);f.readJson(JSON.stringify({root:t[r]})),e.regData(r,r,f)}else a[r]=t[r];i(e.dictionary.dataSources.getByName("Autres"),[a]),p=new o.Stimulsoft.System.Data.DataSet("Autres"),p.readJson(JSON.stringify({root:[a]})),e.regData("Autres","Autres",p)}const x=e.dictionary.variables.getByName("Len");if(x){const r=n?n.length:c.length;r>0&&(x.valueObject=r)}return e}catch(e){throw D(`Une erreur est survenue lors du chargement du rapport : ${e}`),e}};return O(async()=>{const e=new o.Stimulsoft.Viewer.StiViewerOptions;e.appearance.interfaceType=o.Stimulsoft.Viewer.StiInterfaceType.Mouse,e.appearance.pageBorderColor=o.Stimulsoft.System.Drawing.Color.fromArgb(255,255,255,255),e.appearance.backgroundColor=o.Stimulsoft.System.Drawing.Color.fromArgb(255,255,255,255),e.appearance.showPageShadow=!1,e.toolbar.zoom=130,e.toolbar.printDestination=o.Stimulsoft.Viewer.StiPrintDestination.Direct,e.exports.showExportToPdf=!0;const t=new o.Stimulsoft.Viewer.StiViewer(e,"StiViewer",!1);try{const a=await C();s.isEnvoiMail?a.renderAsync(()=>{a.exportDocumentAsync(async d=>{const i=s.nomFichier||s.urlFichier.split("/").pop().split(".")[0],S=new Blob([new Uint8Array(d)],{type:"application/pdf"}),c=new File([S],i+new Date().getTime()+".pdf",{type:"application/pdf"}),n=new FormData;n.append("file",c);try{(await U.post(`${m.lienApi}/upload_un_fichier_sans_suppression`,n,{headers:{"x-custom-filename":i+".pdf","x-path":`temp/${m.cloudId}/${m.id_societe}/envoiemailrapports`}})).status===200&&v("saveFichierPDF",c)}catch(y){D(`Une erreur est survenue : ${y}`)}},o.Stimulsoft.Report.StiExportFormat.Pdf)}):a.renderAsync(()=>{t.report=a,t.renderHtml("viewer"),g.value=!1})}catch(a){D(`Une erreur est survenue : ${a}`),g.value=!1}}),(e,t)=>{const a=J,d=R;return F(),V(d,{visible:b.value,"onUpdate:visible":[t[1]||(t[1]=i=>b.value=i),t[2]||(t[2]=i=>v("close"))],modal:"",maximizable:"",header:" ",style:{width:"80vw",height:"100vh"}},{default:k(()=>[A("button",{onClick:t[0]||(t[0]=i=>v("close")),class:"close-btn",title:"Fermer"},"✕"),g.value?(F(),I("div",H,[T(a,{style:{width:"50px",height:"50px"},strokeWidth:"4"}),t[3]||(t[3]=A("p",{class:"loading-text"},"Chargement du rapport...",-1))])):P("",!0),A("div",{id:"viewer",class:$(["flex-1",{hidden:g.value}])},null,2)]),_:1},8,["visible"])}}},q=_(M,[["__scopeId","data-v-6e9f3034"]]);export{q as R};
