import{r as o,d as i,B as t,h as n}from"./p-03169580.js";import{g as e}from"./p-a7283b6e.js";import{s as l}from"./p-e1ee6da1.js";import"./p-59c95c5f.js";import"./p-3775d1fc.js";import"./p-80de33dc.js";import"./p-c2fbed0d.js";import"./p-5717491f.js";import"./p-de14d315.js";function d(o){const i={amountDeducted:(o===null||o===void 0?void 0:o.amountDeducted)||0,amountOwed:0,amountBilled:0,amountPaid:(o===null||o===void 0?void 0:o.amountPaid)||0,general:0,levels:{},sites:{}};for(const t of(o===null||o===void 0?void 0:o.services)||[]){i.general=i.general+((t===null||t===void 0?void 0:t.total)||0);i.amountOwed=i.amountOwed+((t===null||t===void 0?void 0:t.total)||0);i.amountBilled=i.amountBilled+((t===null||t===void 0?void 0:t.total)||0)}for(const t of(o===null||o===void 0?void 0:o.sites)||[]){if(!i.sites[t===null||t===void 0?void 0:t.id])i.sites[t.id]=0;if(!i.levels[(t===null||t===void 0?void 0:t.level)||0])i.levels[(t===null||t===void 0?void 0:t.level)||0]=0;for(const o of(t===null||t===void 0?void 0:t.services)||[]){i.sites[t.id]=i.sites[t.id]+((o===null||o===void 0?void 0:o.total)||0);i.levels[(t===null||t===void 0?void 0:t.level)||0]=i.levels[(t===null||t===void 0?void 0:t.level)||0]+((o===null||o===void 0?void 0:o.total)||0);i.amountOwed=i.amountOwed+((o===null||o===void 0?void 0:o.total)||0);i.amountBilled=i.amountBilled+((o===null||o===void 0?void 0:o.total)||0)}}for(const t of(o===null||o===void 0?void 0:o.payments)||[]){i.amountPaid=i.amountPaid+((t===null||t===void 0?void 0:t.amount)||0)}i.amountOwed=((i===null||i===void 0?void 0:i.amountBilled)||0)-((i===null||i===void 0?void 0:i.amountPaid)||0);return i}const s="app-scope ion-infinite-scroll-content{display:none}";let a=class{constructor(t){o(this,t);this.fireenjinTrigger=i(this,"fireenjinTrigger",7);this.fireenjinSubmit=i(this,"fireenjinSubmit",7);this.fireenjinFetch=i(this,"fireenjinFetch",7);this.floodteamOpenModal=i(this,"floodteamOpenModal",7);this.floodteamOpenPopover=i(this,"floodteamOpenPopover",7);this.invoiceTypes=e();this.invoiceType="mitigation";this.attachments=[]}async fetchJob(){if(!this.jobId)return;this.fireenjinFetch.emit({endpoint:"findJob",cacheKey:"jobs",params:{id:this.jobId,withPayments:false,withUsers:true,withSites:true,withPayModel:true,withPhotos:true,withEfiles:true,withPayables:false,withReadings:true}})}async openSendEfileModal(o){var i;o.preventDefault();o.stopPropagation();this.floodteamOpenModal.emit({component:"modal-send-email",cssClass:"modal-send-email",componentProps:{job:l.job,templateFilter:o=>{var i,t;return!(o===null||o===void 0?void 0:o.partial)&&((t=(i=o===null||o===void 0?void 0:o.tags)===null||i===void 0?void 0:i.includes)===null||t===void 0?void 0:t.call(i,"job"))},attachments:this.attachments,users:((i=l.job)===null||i===void 0?void 0:i.users)||[]}})}async sendEmail(o,i){var t;o.preventDefault();o.stopPropagation();if(!((t=l===null||l===void 0?void 0:l.session)===null||t===void 0?void 0:t.uid))return;this.fireenjinSubmit.emit({endpoint:"sendTemplateEmail",data:{templateId:"0xtJNtGRrT3GIosbN7iP",userIds:[i],data:{app:{url:window.location.origin},job:l.job}}})}async generatePdf(o,i=null){this.fireenjinSubmit.emit({endpoint:"generatePdf",data:{filename:i,jobId:this.jobId,templateId:o}})}async send(o){this.generatePdf("tA7FCnTudK0Sd887IeuU","Invoice PDF");this.openSendEfileModal(o)}onChange(o){var i,t;if(((i=o===null||o===void 0?void 0:o.target)===null||i===void 0?void 0:i.name)==="type"){this.invoiceType=((t=o===null||o===void 0?void 0:o.target)===null||t===void 0?void 0:t.value)||null}}async componentDidLoad(){if(!(t===null||t===void 0?void 0:t.isBrowser))return;this.fireenjinTrigger.emit({name:"subscribe",payload:{collection:"jobs",id:this.jobId,callback:()=>{this.fetchJob()}}});this.fetchJob()}disconnectedCallback(){this.fireenjinTrigger.emit({name:"unsubscribe",payload:{collection:"jobs",id:this.jobId}})}render(){var o;return[n("ion-content",{class:"ion-padding"},n("floodteam-title-bar",{back:`/jobs/${this.jobId}`},n("ion-text",{onClick:o=>this.floodteamOpenPopover.emit({event:o,component:"popover-invoice-select",componentProps:{value:this.invoiceType}}),style:{display:"flex",alignItems:"end",cursor:"pointer"}},((o=this.invoiceTypes.find((o=>(o===null||o===void 0?void 0:o.value)===this.invoiceType)))===null||o===void 0?void 0:o.label)||"Other",n("ion-icon",{name:"chevron-down"})),n("ion-buttons",{slot:"end"},n("ion-button",{fill:"clear",onClick:o=>this.send(o)},"Send"),n("ion-button",{fill:"outline",onClick:()=>this.floodteamOpenModal.emit({component:"modal-render-template",componentProps:{templateId:"tA7FCnTudK0Sd887IeuU",headerTitle:"Invoice",data:{job:l.job,totals:d(l.job)}}})},"Preview"))),n("floodteam-form-scope",{invoiceType:this.invoiceType,jobId:this.jobId})),n("floodteam-navigation-footer",null)]}};a.style=s;export{a as app_scope};
//# sourceMappingURL=p-57e54102.entry.js.map