1import{h as Be}from"./moment.9709ab41.js";import{_ as Y}from"./SectionCard.b1264c1b.js";import{i as N,p as Re,s as T,ax as de,aw as X,ar as Ie,ap as Se,aq as $e,aC as L,d as q,v as J,o as P,b as E,w as t,h as S,u as a,a as K,e as n,t as l,a9 as H,aD as Te,az as Oe,g as Fe,c as ue,l as ke,U as Pe}from"./index.be450d7f.js";import{_ as W}from"./ReportActions.471f6f88.js";import{c as ne}from"./index.036e0e3c.js";import{a as Ce,u as Ne}from"./firebaseRef.079e6a15.js";import{u as we,l as he}from"./useCostumers.7832b2e4.js";import{f as $,c as me,a as ge,b as pe,r as ve,d as _e,e as ye,g as xe}from"./commissionDetailColumns.6d23f57f.js";import"./Modal.6932f673.js";var ee=(O,o,h)=>{const r={dates:{start:N(O),end:N(o)},customer:N(h),loading:N(!0),completeLoaderInvoice:N(!1)},k={firebase:Re.functions(),customers:we()},v={formatDate:i=>i.toISOString().replace(".000",""),calculateBalance:i=>i.filter(d=>d.status!=="pending").reduce((d,C)=>{const p=parseFloat(C.amount);return C.transaction_type==="outbound"?d.outbound+=p:d.inbound+=p,d},{outbound:0,inbound:0}),getTotalInfoAds:(i,d)=>i.reduce((C,p)=>(C[`${d}_views`]+=parseInt(String(p.totalViews)),C[`${d}_count`]+=1,C[`${d}_amount`]+=parseFloat(String(p.totalCents)),C),{[`${d}_views`]:0,[`${d}_count`]:0,[`${d}_amount`]:0})},B=async i=>{const d=await he.post("/api/getInvoices",{data:{customerId:i.id,dateFrom:v.formatDate(new Date(r.dates.start.value)),dateTo:v.formatDate(new Date(r.dates.end.value))}});return{customer:i,metrics:d.data.data}},g=ne(async()=>{try{if(!k.customers.getCustomers.value||!r.dates.start.value||!r.dates.end.value)return null;r.loading.value=!0,r.completeLoaderInvoice.value=!1;const i=await Promise.all(k.customers.getCustomers.value.map(B));return r.completeLoaderInvoice.value=!0,r.loading.value=!1,i}catch(i){return r.loading.value=!1,console.error("Error fetching customer metrics:",i),null}},null),D=T(()=>{if(r.loading.value=!0,!g.value)return null;try{return g.value.map(d=>{const C=d.metrics.map(p=>{let _=p.stream;return _||(_={id:p.streamId,title:"Stream deleted",date:p.transaction?new Date(p.transaction.displayedDate.seconds*1e3).toISOString():new Date(p.dateOriginal).toISOString()}),{customer:d.customer,salesRep:Ce(de(X,"customers",d.customer.addedByUserId)),stream:_,...p}});return{customer:d.customer,metrics:C}})}catch(i){return console.log(i),null}}),u=T(()=>{if(!D.value)return null;const i=Ie(X,"users");return D.value.map(d=>{const C=d.metrics.map(p=>{if(p.salesRep.data.value.email){const _=Se(i,$e("email","==",p.salesRep.data.value.email));return{...p,salesRepUser:p.salesRep.data.value.email?Ne(_):null}}return{...p,salesRepUser:null}});return{...d,metrics:C}})}),e=ne(async()=>{if(r.loading.value=!0,k.customers.getCustomers.value.length<=0)return[];const i=v.formatDate(new Date(r.dates.start.value)),d=k.customers.getCustomers.value.map(async p=>({balance:(await he.post("/api/getRemainingBalance",{customerId:p.id,dateTo:i})).data,customer:p})),C=await Promise.all(d);return r.loading.value=!0,C},[]),s=T(()=>{if(r.loading.value=!0,!u.value||e.value.length===0)return r.loading.value=!1,[];try{const i=u.value.map(C=>{const p=L.groupBy(C.metrics,"customer.addedByUserId");return Object.entries(p).flatMap(([m,f])=>{const I=L.groupBy(f,"customer.id");return Object.entries(I).flatMap(([R,F])=>{const j=F.filter(w=>w.type!=="credit"),V=F.filter(w=>w.type==="credit").map(w=>({...w,dateFormat:new Date(w.dateOriginal).toISOString().split("T")[0]})),U=L.groupBy(V,"dateFormat");let M=Object.entries(U).map(([w,b],G,re)=>{var te,ae,oe,se;const be=b.reduce((ie,ce)=>ie+ce.totalCents,0),z=((oe=(ae=(te=b[0].salesRepUser)==null?void 0:te.data)==null?void 0:ae.value)==null?void 0:oe[0])||{},De=(z==null?void 0:z.commission)||"0";return{advertiserId:b[0].advertiserId,email:((se=b[0].salesRepUser)==null?void 0:se.data.value.email)||"no Email",customer:b[0].customer,state:b[0].customer.state,totalCents:be,logo_amount:0,logo_count:0,logo_views:0,video_amount:0,video_count:0,video_views:0,dateOriginal:b[0].dateOriginal,date:w,type:"credit",percentage:De,title:"Deposit",extra:0,dateFormat:w}});const le=L.groupBy(j,"streamId"),Z=Object.entries(le).map(([w,b])=>{var te,ae,oe,se,ie,ce;const G=L.groupBy(b,"type"),re=v.getTotalInfoAds(G.logo_view||[],"logo"),be=v.getTotalInfoAds(G.video_view||[],"video"),z=((oe=(ae=(te=b[0].salesRepUser)==null?void 0:te.data)==null?void 0:ae.value)==null?void 0:oe[0])||{},De=(z==null?void 0:z.commission)||"0";return{...re,...be,dateOriginal:b[0].stream.date,advertiserId:b[0].advertiserId,email:((ce=(ie=(se=b[0].salesRep)==null?void 0:se.data)==null?void 0:ie.value)==null?void 0:ce.email)||"no Email",customer:b[0].customer,totalCents:0,percentage:De,date:w,type:"consumed",state:b[0].customer.state,title:b[0].stream.title,extra:0,dateFormat:b[0].stream.date}});if(M.length>0){const w=e.value.find(G=>G.customer.id===M[0].customer.id),b=M.sort((G,re)=>new Date(G.dateOriginal).getTime()-new Date(re.dateOriginal).getTime());w&&(b[0].extra=w.balance.remainingBalance,b[0].title=w.balance.inbound===0?"CreateAccount":"Deposit"),M=b}else{const w=e.value.find(b=>b.customer.id===Z[0].advertiserId);w&&(Z[0].extra=w.balance.remainingBalance)}let Q=0;const fe=[...Z,...M].sort((w,b)=>new Date(w.dateOriginal).getTime()-new Date(b.dateOriginal).getTime()).map(w=>{const b=Q+w.totalCents+w.extra-(w.logo_amount+w.video_amount);return Q=b,{...w,endingBalance:b}}),Ae=fe.reduce((w,b)=>(w.logo_amount+=b.logo_amount,w.video_amount+=b.video_amount,w.totalCents+=b.totalCents+b.extra,w.percentage=b.percentage,w),{logo_amount:0,video_amount:0,totalCents:0});return fe.push({advertiserId:"",customer:"",totalCents:0,logo_amount:0,logo_count:0,logo_views:0,video_amount:0,video_count:0,video_views:0,dateOriginal:"",date:R,state:"",type:"total",title:"Total",extra:0,endingBalance:Q,dateFormat:R,...Ae}),fe})})});return r.loading.value=!1,i.flat()||[]}catch(i){return console.log(i,"error"),r.loading.value=!1,[]}}),y=T(()=>{if(r.loading.value=!0,!g.value)return null;try{return g.value.map(d=>{const C=L.groupBy(d.metrics,"type"),p=C.logo_view,_=C.video_view,m=C.credit;return{...d,metrics:{logo:p||[],video:_||[],credits:m||[]}}})}catch(i){return console.log(i),null}}),c=T(()=>{if(r.loading.value=!0,!r.completeLoaderInvoice.value)return r.loading.value=!1,[];if(!y.value||e.value.length===0)return r.loading.value=!1,[];try{const i=e.value,d=y.value.map(f=>{const I=v.getTotalInfoAds(f.metrics.logo,"logo"),A=v.getTotalInfoAds(f.metrics.video,"video"),R=i.find(V=>f.customer.id===V.customer.id),F=R?R.balance.remainingBalance:0,j=f.metrics.credits.reduce((V,U)=>U.totalCents+V,0);return{...f,account:`${f.customer.firstName} ${f.customer.lastName}`,state:f.customer.state,...I,...A,credits:j,endingBalance:j+F-(I.logo_amount+A.video_amount)}}),C=L.groupBy(d,"state"),p=Object.entries(C).flatMap(([f,I])=>{const A=I.reduce((F,j)=>(F.video_amount+=j.video_amount,F.logo_amount+=j.logo_amount,F.credits+=j.credits,F.endingBalance+=j.endingBalance,F),{video_amount:0,logo_amount:0,credits:0,endingBalance:0});return[...I,{account:"SubTotal",credits:0,customer:I[0].customer,logo_amount:0,logo_count:0,logo_views:0,metrics:{},state:f,video_amount:0,video_count:0,video_views:0,...A,endingBalance:A.endingBalance}]}),m=p.filter(f=>f.account==="SubTotal").reduce((f,I)=>(f.video_amount+=I.video_amount,f.logo_amount+=I.logo_amount,f.credits+=I.credits,f.endingBalance+=I.endingBalance,f),{video_amount:0,logo_amount:0,credits:0,endingBalance:0});return r.loading.value=!1,[...p,{account:"Total",credits:0,customer:{},logo_amount:0,logo_count:0,logo_views:0,metrics:{},state:"",video_amount:0,video_count:0,video_views:0,...m,endingBalance:m.endingBalance}]}catch{return r.loading.value=!0,[]}});return{updateDates:(i,d,C)=>{r.dates.start.value=i,r.dates.end.value=d,r.customer.value=C,r.completeLoaderInvoice.value=!1},detailCustomers:s,getBalanceCustomerAndTerritory:c,getCustomers:k.customers.getCustomers,loading:r.loading}};const Ve=K("div",{class:"px-4 py-8 text-sm text-gray-600"}," No data available for the selected range. ",-1),Ke=q({__name:"SummaryByCustomerAndTerritory",props:{startDate:null,endD
1ate:null,customerId:null},setup(O){const o=O,h=`report-${Math.random().toString(36).slice(2,10)}`,{getBalanceCustomerAndTerritory:r,updateDates:k,loading:v}=ee(o.startDate,o.endDate,o.customerId);J(()=>[o.endDate,o.startDate,o.customerId],()=>k(o.startDate,o.endDate,o.customerId));const B=[{key:"account",label:"Account"},{key:"state",label:"Territory"},{key:"credits",label:"Deposit",align:"right"},{key:"video_amount",label:"Commercial",align:"right"},{key:"logo_amount",label:"Logo",align:"right"},{key:"total",label:"Total",align:"right"},{key:"endingBalance",label:"Ending Balance",align:"right"}],g=u=>{const e=Number(u);return Number.isFinite(e)?e.toFixed(2):"\u2014"},D=T(()=>{var u;return((u=r.value)!=null?u:[]).map((e,s)=>{var y,c;return{...e,__rowKey:`${(y=e.account)!=null?y:"row"}-${(c=e.state)!=null?c:""}-${s}`}})});return(u,e)=>(P(),E(Y,{title:"Summary by Customer and Territory",sub:"Account balances grouped by state",flush:""},{actions:t(()=>[S(W,{"table-id":h,filename:"summary-by-customer",disabled:a(D).length===0||a(v)},null,8,["disabled"])]),default:t(()=>[K("div",{id:h},[S(H,{columns:B,rows:a(D),loading:a(v),"skeleton-rows":5,"row-key":"__rowKey"},{"cell-credits":t(({row:s})=>[n(l(g(s.credits)),1)]),"cell-video_amount":t(({row:s})=>[n(l(g(s.video_amount)),1)]),"cell-logo_amount":t(({row:s})=>[n(l(g(s.logo_amount)),1)]),"cell-total":t(({row:s})=>[n(l(g(s.logo_amount+s.video_amount)),1)]),"cell-endingBalance":t(({row:s})=>[n(l(g(s.endingBalance)),1)]),empty:t(()=>[Ve]),_:1},8,["rows","loading"])])]),_:1}))}}),Me=K("div",{class:"px-4 py-8 text-sm text-gray-600"}," No detail available for the selected range. ",-1),Ue=q({__name:"DetailByCustomer",props:{startDate:null,endDate:null,customerId:null},setup(O){const o=O,h=`report-${Math.random().toString(36).slice(2,10)}`,{detailCustomers:r,updateDates:k,loading:v}=ee(o.startDate,o.endDate,o.customerId);J(()=>[o.endDate,o.startDate,o.customerId],()=>k(o.startDate,o.endDate,o.customerId));const B=[{key:"account",label:"Account"},{key:"state",label:"Territory"},{key:"dateOriginal",label:"Date"},{key:"title",label:"Event"},{key:"deposit",label:"Deposit",align:"right"},{key:"video_amount",label:"Commercial",align:"right"},{key:"logo_amount",label:"Logo",align:"right"},{key:"total",label:"Total",align:"right"},{key:"endingBalance",label:"Ending Balance",align:"right"},{key:"email",label:"Sales Rep"},{key:"percentage",label:"%",align:"center"},{key:"commission",label:"Commission",align:"right"}],g=s=>{const y=Number(s);return Number.isFinite(y)?y.toFixed(2):"\u2014"},D=s=>typeof s!="string"||s.length===0?"":Be(s).format("MMM DD, YYYY"),u=s=>{var x,i;const y=(parseFloat(s.percentage)||0)/100,c=Number((x=s.logo_amount)!=null?x:0)+Number((i=s.video_amount)!=null?i:0);return g(c*y)},e=T(()=>{var s;return((s=r.value)!=null?s:[]).map((y,c)=>{var x,i,d;return{...y,__rowKey:`${(d=(i=(x=y.streamId)!=null?x:y.advertiserId)!=null?i:y.type)!=null?d:"row"}-${c}`}})});return(s,y)=>(P(),E(Y,{title:"Detail by Customer",sub:"Per-stream breakdown with sales rep commission",flush:""},{actions:t(()=>[S(W,{"table-id":h,filename:"detail-by-customer",disabled:a(e).length===0||a(v)},null,8,["disabled"])]),default:t(()=>[K("div",{id:h},[S(H,{columns:B,rows:a(e),loading:a(v),"skeleton-rows":6,"row-key":"__rowKey"},{"cell-account":t(({row:c})=>{var x,i,d,C;return[n(l(`${(i=(x=c.customer)==null?void 0:x.firstName)!=null?i:""} ${(C=(d=c.customer)==null?void 0:d.lastName)!=null?C:""}`.trim()||"\u2014"),1)]}),"cell-dateOriginal":t(({row:c})=>[n(l(D(c.dateOriginal)),1)]),"cell-deposit":t(({row:c})=>{var x,i;return[n(l(g(Number((x=c.totalCents)!=null?x:0)+Number((i=c.extra)!=null?i:0))),1)]}),"cell-video_amount":t(({row:c})=>[n(l(g(c.video_amount)),1)]),"cell-logo_amount":t(({row:c})=>[n(l(g(c.logo_amount)),1)]),"cell-total":t(({row:c})=>{var x,i;return[n(l(g(Number((x=c.logo_amount)!=null?x:0)+Number((i=c.video_amount)!=null?i:0))),1)]}),"cell-endingBalance":t(({row:c})=>[n(l(g(c.endingBalance)),1)]),"cell-percentage":t(({row:c})=>{var x;return[n(l(`${(x=c.percentage)!=null?x:0}%`),1)]}),"cell-commission":t(({row:c})=>[n(l(u(c)),1)]),empty:t(()=>[Me]),_:1},8,["rows","loading"])])]),_:1}))}}),Ee=n("KJZZ"),je=n("KJZZ"),Ye=q({__name:"CommissionAllEntities",props:{startDate:null,endD
1ate:null},setup(O){const o=O,h=`report-${Math.random().toString(36).slice(2,10)}`,{detailCustomers:r,updateDates:k,loading:v}=ee(o.startDate,o.endDate,null);J(()=>[o.endDate,o.startDate],()=>k(o.startDate,o.endDate,null));const B=[{key:"email",label:"Sales Rep"},{key:"percentage",label:"%",align:"center"},{key:"salesRepCommission",label:"Commission",align:"right"},{key:"distPartner",label:"Dist Partner"},{key:"distPercentage",label:"%",align:"center"},{key:"distCommission",label:"Commission",align:"right"},{key:"association",label:"Association"},{key:"assocPercentage",label:"%",align:"center"},{key:"assocCommission",label:"Commission",align:"right"},...ye],g=T(()=>{var D;return((D=r.value)!=null?D:[]).map((u,e)=>{var s,y,c;return{...u,__rowKey:`${(c=(y=(s=u.streamId)!=null?s:u.advertiserId)!=null?y:u.type)!=null?c:"row"}-${e}`}})});return(D,u)=>(P(),E(Y,{title:"Commission Detail \u2014 All Entities",flush:""},{actions:t(()=>[S(W,{"table-id":h,filename:"commission-all-entities",disabled:a(g).length===0||a(v)},null,8,["disabled"])]),default:t(()=>[K("div",{id:h},[S(H,{columns:B,rows:a(g),loading:a(v),"skeleton-rows":6,"row-key":"__rowKey"},{"cell-percentage":t(({row:e})=>{var s;return[n(l(e.type==="consumed"?"":`${(s=e.percentage)!=null?s:0}%`),1)]}),"cell-salesRepCommission":t(({row:e})=>[n(l(a($)(a(me)(e))),1)]),"cell-distPartner":t(()=>[Ee]),"cell-distPercentage":t(({row:e})=>{var s;return[n(l((s=e.percentage)!=null?s:0)+"%",1)]}),"cell-distCommission":t(({row:e})=>[n(l(a($)(a(me)(e))),1)]),"cell-association":t(()=>[je]),"cell-assocPercentage":t(({row:e})=>{var s;return[n(l((s=e.percentage)!=null?s:0)+"%",1)]}),"cell-assocCommission":t(({row:e})=>[n(l(a($)(a(me)(e))),1)]),"cell-account":t(({row:e})=>[n(l(a(ge)(e)),1)]),"cell-dateOriginal":t(({row:e})=>[n(l(a(pe)(e.dateOriginal)),1)]),"cell-deposit":t(({row:e})=>[n(l(a($)(a(ve)(e))),1)]),"cell-video_amount":t(({row:e})=>[n(l(a($)(e.video_amount)),1)]),"cell-logo_amount":t(({row:e})=>[n(l(a($)(e.logo_amount)),1)]),"cell-total":t(({row:e})=>[n(l(a($)(a(_e)(e))),1)]),"cell-endingBalance":t(({row:e})=>[n(l(a($)(e.endingBalance)),1)]),_:1},8,["rows","loading"])])]),_:1}))}}),Ze=q({__name:"CommissionSalesRep",props:{startDate:null,endDate:null},setup(O){const o=O,h=`report-${Math.random().toString(36).slice(2,10)}`,{detailCustomers:r,updateDates:k,loading:v}=ee(o.startDate,o.endDate,null);J(()=>[o.endDate,o.startDate],()=>k(o.startDate,o.endDate,null));const B=[{key:"email",label:"Sales Rep"},{key:"percentage",label:"%",align:"center"},{key:"commission",label:"Commission",align:"right"},...ye],g=T(()=>{var D;return((D=r.value)!=null?D:[]).map((u,e)=>{var s,y,c;return{...u,__rowKey:`${(c=(y=(s=u.streamId)!=null?s:u.advertiserId)!=null?y:u.type)!=null?c:"row"}-${e}`}})});return(D,u)=>(P(),E(Y,{title:"Commission Detail \u2014 Sales Rep",flush:""},{actions:t(()=>[S(W,{"table-id":h,filename:"commission-sales-rep",disabled:a(g).length===0||a(v)},null,8,["disabled"])]),default:t(()=>[K("div",{id:h},[S(H,{columns:B,rows:a(g),loading:a(v),"skeleton-rows":6,"row-key":"__rowKey"},{"cell-percentage":t(({row:e})=>{var s;return[n(l((s=e.percentage)!=null?s:0)+"%",1)]}),"cell-commission":t(({row:e})=>[n(l(a($)(a(me)(e))),1)]),"cell-account":t(({row:e})=>[n(l(a(ge)(e)),1)]),"cell-dateOriginal":t(({row:e})=>[n(l(a(pe)(e.dateOriginal)),1)]),"cell-deposit":t(({row:e})=>[n(l(a($)(a(ve)(e))),1)]),"cell-video_amount":t(({row:e})=>[n(l(a($)(e.video_amount)),1)]),"cell-logo_amount":t(({row:e})=>[n(l(a($)(e.logo_amount)),1)]),"cell-total":t(({row:e})=>[n(l(a($)(a(_e)(e))),1)]),"cell-endingBalance":t(({row:e})=>[n(l(a($)(e.endingBalance)),1)]),_:1},8,["rows","loading"])])]),_:1}))}}),Le=n("KJZZ"),qe=n("5%"),Je=q({__name:"CommissionDistPartner",props:{startDate:null,endDate:null},setup(O){const o=O,h=`report-${Math.random().toString(36).slice(2,10)}`,{detailCustomers:r,updateDates:k,loading:v}=ee(o.startDate,o.endDate,null);J(()=>[o.endDate,o.startDate],()=>k(o.startDate,o.endDate,null));const B=[{key:"distPartner",label:"Dist Partner"},{key:"distPercentage",label:"%",align:"center"},{key:"distCommission",label:"Commission",align:"right"},...ye],g=T(()=>{var D;return((D=r.value)!=null?D:[]).map((u,e)=>{var s,y,c;return{...u,__rowKey:`${(c=(y=(s=u.streamId)!=null?s:u.advertiserId)!=null?y:u.type)!=null?c:"row"}-${e}`}})});return(D,u)=>(P(),E(Y,{title:"Commission Detail \u2014 Distribution Partner",flush:""},{actions:t(()=>[S(W,{"table-id":h,filename:"commission-dist-partner",disabled:a(g).length===0||a(v)},null,8,["disabled"])]),default:t(()=>[K("div",{id:h},[S(H,{columns:B,rows:a(g),loading:a(v),"skeleton-rows":6,"row-key":"__rowKey"},{"cell-distPartner":t(()=>[Le]),"cell-distPercentage":t(()=>
1[qe]),"cell-distCommission":t(({row:e})=>[n(l(a($)(a(xe)(e,.05))),1)]),"cell-account":t(({row:e})=>[n(l(a(ge)(e)),1)]),"cell-dateOriginal":t(({row:e})=>[n(l(a(pe)(e.dateOriginal)),1)]),"cell-deposit":t(({row:e})=>[n(l(a($)(a(ve)(e))),1)]),"cell-video_amount":t(({row:e})=>[n(l(a($)(e.video_amount)),1)]),"cell-logo_amount":t(({row:e})=>[n(l(a($)(e.logo_amount)),1)]),"cell-total":t(({row:e})=>[n(l(a($)(a(_e)(e))),1)]),"cell-endingBalance":t(({row:e})=>[n(l(a($)(e.endingBalance)),1)]),_:1},8,["rows","loading"])])]),_:1}))}}),Ge=n("KJZZ"),ze=n("25%"),He=q({__name:"CommissionAssociations",props:{startDate:null,endDate:null},setup(O){const o=O,h=`report-${Math.random().toString(36).slice(2,10)}`,{detailCustomers:r,updateDates:k,loading:v}=ee(o.startDate,o.endDate,null);J(()=>[o.endDate,o.startDate],()=>k(o.startDate,o.endDate,null));const B=[{key:"association",label:"Association"},{key:"assocPercentage",label:"%",align:"center"},{key:"assocCommission",label:"Commission",align:"right"},...ye],g=T(()=>{var D;return((D=r.value)!=null?D:[]).map((u,e)=>{var s,y,c;return{...u,__rowKey:`${(c=(y=(s=u.streamId)!=null?s:u.advertiserId)!=null?y:u.type)!=null?c:"row"}-${e}`}})});return(D,u)=>(P(),E(Y,{title:"Commission Detail \u2014 Associations",flush:""},{actions:t(()=>[S(W,{"table-id":h,filename:"commission-associations",disabled:a(g).length===0||a(v)},null,8,["disabled"])]),default:t(()=>[K("div",{id:h},[S(H,{columns:B,rows:a(g),loading:a(v),"skeleton-rows":6,"row-key":"__rowKey"},{"cell-association":t(()=>[Ge]),"cell-assocPercentage":t(()=>[ze]),"cell-assocCommission":t(({row:e})=>[n(l(a($)(a(xe)(e,.25))),1)]),"cell-account":t(({row:e})=>[n(l(a(ge)(e)),1)]),"cell-dateOriginal":t(({row:e})=>[n(l(a(pe)(e.dateOriginal)),1)]),"cell-deposit":t(({row:e})=>[n(l(a($)(a(ve)(e))),1)]),"cell-video_amount":t(({row:e})=>[n(l(a($)(e.video_amount)),1)]),"cell-logo_amount":t(({row:e})=>[n(l(a($)(e.logo_amount)),1)]),"cell-total":t(({row:e})=>[n(l(a($)(a(_e)(e))),1)]),"cell-endingBalance":t(({row:e})=>[n(l(a($)(e.endingBalance)),1)]),_:1},8,["rows","loading"])])]),_:1}))}});var We=(O,o,h)=>{const r=N(O),k=N(o),v=N(!0),B=N(h),g=[{location:"Utah",distPatrner:{name:"Other",commission:.25}}],D=[{location:"Utah",association:{name:"UHSSA",commission:.05}}];J([r,k],()=>{v.value=!0});const{getCustomers:u}=we(),e=ne(async()=>{try{if(!r.value||!k.value)return null;const _=new Date(r.value),m=new Date(k.value),f=u.value.map(async A=>(await he.post("/api/getInvoices",{data:{customerId:A.id,dateFrom:_.toISOString().replace(".000",""),dateTo:m.toISOString().replace(".000","")}})).data.data.map(F=>({...F,customer:A})));return(await Promise.all(f.flat())).flat()}catch{return null}},null),s=ne(async()=>{const _=Ie(X,"users"),m=Se(_,$e("role","==","salesRep"));return(await Te(m)).docs.map(I=>I.data())},[]),y=ne(async()=>{if(!e.value||!s.value||s.value.length<=0)return null;const _=e.value.filter(I=>I.type!=="credit"),m=L.groupBy(_,"customer.addedByUserId"),f=Object.entries(m).map(async([I,A])=>{const R=A.reduce((Z,Q)=>(Q.totalCents&&(Z=Z+parseFloat(Q.totalCents.toString())),Z),0),F=de(X,"customers",I),V=(await Oe(F)).data(),U=V==null?void 0:V.email,M=s.value.find(Z=>Z.email===U),le=(M==null?void 0:M.commission)||0;return console.log(M,"percentage",V,R,le),{type:"Sales Rep",salesRep:Ce(de(X,"customers",I)),total:(R*parseFloat(le)/100).toFixed(2)}});return await Promise.all(f)},null),c=T(()=>y.value?y.value.map(m=>{const f=m.salesRep.data.value.email;return{type:m.type,amount:m.total,name:f}}):[]),x=T(()=>{if(!e.value)return null;const _=e.value.filter(I=>I.type!=="credit"),m=L.groupBy(_,"transaction.advertiserId");return Object.entries(m).map(([I,A])=>({account:Ce(de(X,"users",I)),value:A}))}),i=T(()=>{if(!x.value)return[];const _=x.value.reduce((m,f)=>{const I=f.account.data.value.state,A=g.find(U=>U.location===I),R=A?A.location:"Other",F=A?A.distPatrner.name:"Other",V=f.value.reduce((U,M)=>U+M.totalCents,0)*.25;return m[R]?m[R].amount=m[R].amount+V:m[R]={name:F,type:"Dist Partners",amount:parseFloat(V.toFixed(2))},m},{});return Object.values(_)}),d=T(()=>{if(!x.value)return[];const _=x.value.reduce((m,f)=>{const I=f.account.data.value.state,A=D.find(U=>U.location===I),R=A?A.location:"Other",F=A?A.association.name:"Other",V=f.value.reduce((U,M)=>U+M.totalCents,0)*.05;
1return m[R]?m[R].amount=m[R].amount+V:m[R]={name:F,type:"Commission",amount:parseFloat(V.toFixed(2))},m},{});return Object.values(_)}),C=T(()=>{v.value=!0;let _=[];return B.value===0?_=[...c.value||[],...i.value||[],...d.value||[]]:B.value===1?_=c.value||[]:B.value===2?_=i.value||[]:B.value===3&&(_=d.value||[]),v.value=!1,_});return{updateDates:(_,m,f)=>{r.value=_,k.value=m,B.value=f},getSalesCommision:C,loading:v}};const Qe=K("div",{class:"px-4 py-8 text-sm text-gray-600"}," No commission data for the selected range. ",-1),Xe=q({__name:"CommissionSummary",props:{startDate:null,endDate:null,typeCommsision:null},setup(O){const o=O,h=`report-${Math.random().toString(36).slice(2,10)}`,{getSalesCommision:r,updateDates:k,loading:v}=We(o.startDate,o.endDate,o.typeCommsision);J(()=>[o.endDate,o.startDate,o.typeCommsision],()=>k(o.startDate,o.endDate,o.typeCommsision));const B=[{key:"type",label:"Commission Type"},{key:"name",label:"Name",sortable:!0},{key:"amount",label:"Commission",sortable:!0,align:"right"}],g=u=>{const e=Number(u);return Number.isFinite(e)?e.toFixed(2):"\u2014"},D=T(()=>{var u;return((u=r.value)!=null?u:[]).map((e,s)=>{var y,c;return{...e,__rowKey:`${(y=e.type)!=null?y:"row"}-${(c=e.name)!=null?c:s}`}})});return(u,e)=>(P(),E(Y,{title:"Commission Summary",flush:""},{actions:t(()=>[S(W,{"table-id":h,filename:"commission-summary",disabled:a(D).length===0||a(v)},null,8,["disabled"])]),default:t(()=>[K("div",{id:h},[S(H,{columns:B,rows:a(D),loading:a(v),"skeleton-rows":4,"row-key":"__rowKey"},{"cell-amount":t(({row:s})=>[n(l(g(s.amount)),1)]),empty:t(()=>[Qe]),_:1},8,["rows","loading"])])]),_:1}))}}),et={class:"mx-auto max-w-7xl px-4 py-6 lg:px-8 lg:py-8"},tt=K("header",{class:"mb-6"},[K("h1",{class:"font-sans text-3xl font-black text-classic"}," Administrative reports "),K("p",{class:"mt-1 text-sm text-gray-600"}," Customer balances, sales detail and commission breakdowns. ")],-1),at={class:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4"},ot={class:"flex items-end"},st=n(" Apply filters "),nt={key:0,class:"space-y-4"},lt={key:1,class:"space-y-4"},rt={key:2,class:"space-y-4"},yt=q({__name:"AdvancedReports",setup(O){const o=Be().format("YYYY-MM-DD"),h=N(0),r=N(0),k=N(0),v=N(null),B=N(o),g=N(o),D=N(o),u=N(o),e=T(()=>u.value||o),s=()=>{B.value=D.value,g.value=u.value},y=[{label:"Sales Report Summary by Customer and Territory",value:0},{label:"Sales Report Detail by Customer",value:1},{label:"Commission Summary Report - All",value:2},{label:"Commission Detail Reports",value:3}],c=[{label:"All",value:0},{label:"Sales Rep",value:1},{label:"Dist Partner",value:2},{label:"Associations",value:3}],x=[{label:"All",value:0},{label:"Sales Rep",value:1},{label:"Dist Partner",value:2},{label:"Associations",value:3}],{getCustomers:i}=we(),d=T(()=>i.value.length<=0?[]:i.value.map(C=>({label:`${C.firstName} ${C.lastName}`,value:C.id})));return(C,p)=>{const _=Fe("FormKit");return P(),ue("div",et,[tt,S(Y,{title:"Filters",class:"mb-6"},{default:t(()=>[K("div",at,[S(_,{modelValue:h.value,"onUpdate:modelValue":p[0]||(p[0]=m=>h.value=m),type:"select",label:"Report type",options:y,name:"reportType",placeholder:"Report type"},null,8,["modelValue"]),S(_,{modelValue:D.value,"onUpdate:modelValue":p[1]||(p[1]=m=>D.value=m),type:"date",label:"Start date",name:"startDate",max:a(e),validation:"required","validation-visibility":"live"},null,8,["modelValue","max"]),S(_,{modelValue:u.value,"onUpdate:modelValue":p[2]||(p[2]=m=>u.value=m),type:"date",label:"End date",name:"endDate",min:D.value||void 0,max:a(o),validation:"required","validation-visibility":"live"},null,8,["modelValue","min","max"]),K("div",ot,[S(Pe,{variant:"primary",size:"sm",class:"w-full",onClick:s},{default:t(()=>[st]),_:1})])])]),_:1}),h.value===0||h.value===1?(P(),ue("section",nt,[S(Y,{title:"Customer",sub:"Optional \u2014 filter to one account"},{default:t(()=>[S(_,{modelValue:v.value,"onUpdate:modelValue":p[3]||(p[3]=m=>v.value=m),type:"select",label:"Name customer",options:a(d),name:"customer",placeholder:"All customers"},null,8,["modelValue","options"])]),_:1}
1),h.value===0?(P(),E(Ke,{key:0,"end-date":g.value,"start-date":B.value,"customer-id":v.value},null,8,["end-date","start-date","customer-id"])):(P(),E(Ue,{key:1,"end-date":g.value,"start-date":B.value,"customer-id":v.value},null,8,["end-date","start-date","customer-id"]))])):h.value===2?(P(),ue("section",lt,[S(Y,{title:"Commission type"},{default:t(()=>[S(_,{modelValue:r.value,"onUpdate:modelValue":p[4]||(p[4]=m=>r.value=m),type:"select",label:"Commission type",options:c,name:"commisionType"},null,8,["modelValue"])]),_:1}),S(Xe,{"end-date":g.value,"start-date":B.value,"type-commsision":r.value},null,8,["end-date","start-date","type-commsision"])])):h.value===3?(P(),ue("section",rt,[S(Y,{title:"Commission type"},{default:t(()=>[S(_,{modelValue:k.value,"onUpdate:modelValue":p[5]||(p[5]=m=>k.value=m),type:"select",label:"Commission type",options:x,name:"commisionSummary"},null,8,["modelValue"])]),_:1}),k.value===0?(P(),E(Ye,{key:0,"end-date":g.value,"start-date":B.value},null,8,["end-date","start-date"])):k.value===1?(P(),E(Ze,{key:1,"end-date":g.value,"start-date":B.value},null,8,["end-date","start-date"])):k.value===2?(P(),E(Je,{key:2,"end-date":g.value,"start-date":B.value},null,8,["end-date","start-date"])):k.value===3?(P(),E(He,{key:3,"end-date":g.value,"start-date":B.value},null,8,["end-date","start-date"])):ke("",!0)])):ke("",!0)])}}});export{yt as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.