PageSourceSearch

https://app.upmetrics.co/chunks/ClNUZVL6.js

js upmetrics.co collected 2026-09-24 09:36:52 UTC 15,194 bytes, 1 lines download raw bytes

1import{r as R,j as r}from"./Dem1e8VV.js";import{d as Ve}from"./CNFvtpL4.js";import{u as z,ay as rt,cA as it,cB as ct,cf as dt,y as P,gj as ut,ci as pt,g4 as ft,cE as mt,c1 as Ct,c2 as Ot,b$ as Y,dU as ye,aK as St}from"../entry/whq2ljq-.js";import"./BnZNklX7.js";import{g as ht,a as Me,b as je,P as At,A as _t,t as Nt,c as ve,Z as Tt,d as Fe,G as Be,E as gt,R as Lt,s as Rt,F as Et,e as It,f as xt}from"./DR1JvnZi.js";import{S as Pt}from"./D0_jY_ez.js";import{c as bt,r as Dt,b as yt,o as Ge,T as X,V as Mt,a as Ue}from"./BtOoKPxr.js";import{u as re,F as ie,s as jt}from"./DDMThJ-o.js";import"./phrJN640.js";import{p as ke}from"./B6JQPiWR.js";import"./Dh95b2SR.js";import"./BS4HFmLj.js";const We={byComponent:"COS_PLAN.CHART_BY_COMPONENT",totalCostOfSales:"COS_PLAN.CHART_TOTAL",grossMargin:"COS_PLAN.CHART_GROSS_MARGIN"},$e=Rt("cost","totalCostOfSales",We);function vt(t){const{businessId:S,projection:i,year:E}=Ve(),d=z(),{humanizeCompactInteger:N}=rt(),[h,s]=R.useState("byComponent");R.useEffect(()=>{S&&s($e.get(S))},[S]);const{labels:C,components:f,totalSeries:u,marginSeries:p,actualTotalSeries:l,actualMarginSeries:T}=t,O=h==="grossMargin",g=l.some(m=>m!==null),L=T.some(m=>m!==null),b=R.useMemo(()=>{if(h==="byComponent")return f.filter(c=>c.series.some(A=>A!==0)).flatMap(c=>{var F;const A=d(`COS_PLAN.${c.key}`),_={name:A,data:c.series,dataType:"plannedData",key:c.id,color:c.color,stack:"planned",legendName:A};return(F=c.actualSeries)!=null&&F.some(n=>n!=null)?[_,{..._,data:c.actualSeries,dataType:"actualData",color:ht(c.color),stack:"actual",linkedTo:":previous"}]:[_]});if(O){const c={name:d("COS_PLAN.GROSS_MARGIN"),data:p,dataType:"plannedData",key:"grossMargin",color:Me,legendName:d("COS_PLAN.PLANNED")};return L?[c,{...c,name:`${d("COS_PLAN.GROSS_MARGIN")} (${d("COS_PLAN.ACTUAL")})`,data:T,dataType:"actualData",color:je,legendName:d("COS_PLAN.ACTUAL")}]:[c]}const m={name:d("COS_PLAN.CHART_TOTAL"),data:u,dataType:"plannedData",key:"totalCostOfSales",color:Me,fillColor:At,legendName:d("COS_PLAN.PLANNED")};return g?[m,{...m,name:`${d("COS_PLAN.CHART_TOTAL")} (${d("COS_PLAN.ACTUAL")})`,data:l,dataType:"actualData",color:je,fillColor:_t,legendName:d("COS_PLAN.ACTUAL")}]:[m]},[h,O,f,u,p,l,T,g,L,d]),x=h==="byComponent"?f.some(m=>{var c;return(c=m.actualSeries)==null?void 0:c.some(A=>A!=null&&A!==0)}):O?L:g,H=R.useMemo(()=>{var A;const c=bt(h==="byComponent"?l:O?T:l);return c.length?Dt(c,d("FORECAST_OVERVIEW.RECORDED_BOUNDARY",{period:(A=C[Math.max(...c)])!=null?A:"",raw:!0}),C.length):[]},[h,O,T,l,C,d]),j=R.useMemo(()=>{if(!C.length)return{};const m=h==="byComponent"?"column":O?"spline":"areaspline",c=Nt(b,m),A=_=>O?`${Math.round(_!=null?_:0)}%`:N(_!=null?_:0,2,!0);return{chart:{type:m,spacingBottom:0},title:{text:void 0},xAxis:{categories:C,gridLineWidth:1,gridLineColor:Be,gridLineDashStyle:"Dash",lineWidth:0,labels:{style:{color:Fe}},plotLines:H},yAxis:{gridLineWidth:1,gridLineColor:Be,gridLineDashStyle:"Dash",lineWidth:0,labels:{formatter:function(){return A(this.value)},style:{color:Fe}},plotLines:O?[{value:0,width:1,color:Tt,zIndex:3}]:void 0,title:{text:""}},tooltip:{useHTML:!0,shared:!0,backgroundColor:"transparent",borderWidth:0,shadow:!1,padding:0,formatter:function(){if(!this.points||this.points.length===0)return"";const _=this.points[0].category,F=gt(this.points);let n;if(h==="byComponent"){let I=0,B=0,G=!1;Object.values(F).forEach(D=>{var U;I+=(U=D.planned)!=null?U:0,D.actual!=null&&(B+=D.actual,G=!0)}),n={label:d("COS_PLAN.CHART_TOTAL"),planned:I,actual:G?B:void 0}}return Lt(_,F,x,d,A,n,O?{higherIsBetter:!0,varianceUnit:"points"}:{higherIsBetter:!1})}},legend:{enabled:b.length>1,margin:6,padding:4,itemDistance:18,labelFormatter:function(){return this.userOptions.legendName||this.name}},credits:{enabled:!1},plotOptions:{areaspline:{fillOpacity:.2},column:{stacking:"normal",borderWidth:2,borderColor:ve,borderRadius:2,groupPadding:.1},series:{lineWidth:2,marker:{enabled:!1,states:{hover:{enabled:!0,radius:4,lineWidth:2,lineColor:ve}}},clip:!0}},series:c,accessibility:{enabled:!1}}},[b,C,h,O,H]),v=R.useCallback(m=>{s(m),S&&$e.set(S,m)},[S]);return{selectedOption:h,handleOptionChange:v,chartOptions:j,chartKey:`${S}-${i}-${E}`,showsRecordedStack:h==="byComponent"&&x}
1}const He={"metaInfo.parentType":"cost"},we={"metaInfo.parentType":"revenue"},Ke={"metaInfo.isCOS":!0};function Ft(){const{businessId:t,projection:S,year:i}=Ve(),E=z(),d=it(),N=ct(),s=!!dt().isActualEnabled(t),C=R.useMemo(()=>d.getDataFilterMeta(t,S,i),[t,S,i]),{dataKeys:f,columns:u}=R.useMemo(()=>N.getColumnAndKeys(t,C),[t,C]),p=P(()=>ut.findOne({businessId:t},{fields:{"plannedData.generalTotalCostOfSales":1,"plannedData.revenueTotalCostOfSales":1,"actualData.generalTotalCostOfSales":1,"actualData.revenueTotalCostOfSales":1}}),[t]),l=P(()=>pt.findOne({businessId:t},{fields:{"plannedData.totalCostOfSales":1,"actualData.totalCostOfSales":1}}),[t]),T=P(()=>ft.findOne({businessId:t},{fields:{"plannedData.netRevenue":1,"actualData.netRevenue":1}}),[t]),O=P(()=>{var n;return(n=mt.find({businessId:t},{sort:{position:1},fields:{title:1,color:1,position:1}}))==null?void 0:n.fetch()},[t]),g=P(()=>{var n;return(n=Ct.find({businessId:t},{sort:{position:1},fields:{title:1,color:1,position:1}}))==null?void 0:n.fetch()},[t]),L=P(()=>{var n;return(n=Ot.find({businessId:t},{sort:{position:1},fields:{title:1,color:1,position:1}}))==null?void 0:n.fetch()},[t]),b=R.useMemo(()=>(O!=null?O:[]).map(n=>n._id),[O]),x=R.useMemo(()=>(g!=null?g:[]).map(n=>n._id),[g]),H=R.useMemo(()=>(L!=null?L:[]).map(n=>n._id),[L]),j=P(()=>{var n;return(n=Y.find({businessId:t,...He},{fields:{"metaInfo.name":1,groupId:1,isSetupPending:1}}))==null?void 0:n.fetch()},[t]),v=P(()=>{var n;return(n=Y.find({businessId:t,...we},{fields:{"metaInfo.name":1,groupId:1,isSetupPending:1}}))==null?void 0:n.fetch()},[t]),m=P(()=>{var n;return(n=ye.find({businessId:t,...Ke},{fields:{"metaInfo.name":1,groupId:1,isSetupPending:1}}))==null?void 0:n.fetch()},[t]),c=re({collection:Y,seriesKey:ie.cost.seriesKey,filter:He},b),A=re({collection:Y,seriesKey:ie.cost.seriesKey,filter:we},x),_=re({collection:ye,seriesKey:ie.payroll.seriesKey,filter:Ke},H),F=f.join("|");return R.useMemo(()=>{var Se,he,Ae,_e,Ne,Te,ge,Le,Re,Ee,Ie,xe;const n=e=>N.getSeriesData(f,e)||[],I=e=>e.reduce((a,o)=>a+(o||0),0),B=n((Se=p==null?void 0:p.plannedData)==null?void 0:Se.generalTotalCostOfSales),G=n((he=p==null?void 0:p.plannedData)==null?void 0:he.revenueTotalCostOfSales),D=n((Ae=l==null?void 0:l.plannedData)==null?void 0:Ae.totalCostOfSales),U=n((_e=T==null?void 0:T.plannedData)==null?void 0:_e.netRevenue),w=B.map((e,a)=>(e||0)+(G[a]||0)+(D[a]||0)),ce=I(B),de=I(G),ue=I(D),y=ce+de+ue,K=I(U),V=[],Z=s?n((Ne=p==null?void 0:p.actualData)==null?void 0:Ne.generalTotalCostOfSales):V,q=s?n((Te=p==null?void 0:p.actualData)==null?void 0:Te.revenueTotalCostOfSales):V,J=s?n((ge=l==null?void 0:l.actualData)==null?void 0:ge.totalCostOfSales):V,W=s?n((Le=T==null?void 0:T.actualData)==null?void 0:Le.netRevenue):V,Q=e=>(Z[e]||0)+(q[e]||0)+(J[e]||0),pe=I(Z)+I(q)+I(J),ee=I(W),M=s?yt(f,[(Re=p==null?void 0:p.actualData)==null?void 0:Re.generalTotalCostOfSales,(Ee=p==null?void 0:p.actualData)==null?void 0:Ee.revenueTotalCostOfSales,(Ie=l==null?void 0:l.actualData)==null?void 0:Ie.totalCostOfSales]):[],te=new Set(M),Ye=M.reduce((e,a)=>{var o;return e+((o=w[a])!=null?o:0)},0),Xe=Ge(f.map((e,a)=>Q(a)),te),ze=f.map((e,a)=>{if(!te.has(a))return null;const o=W[a]||0;return o>0?(o-Q(a))/o*100:null}),Ze=K>0?(K-y)/K*100:null,qe=ee>0&&M.length>0?(ee-pe)/ee*100:null,Je=U.reduce((e,a,o)=>((a||0)>0&&e.push(o),e),[]),Qe=ke(w.map((e,a)=>{const o=U[a]||0;return o>0?(o-e)/o*100:0}),Je),fe=M.filter(e=>(W[e]||0)>0);let me=null;fe.length>=2&&(me=ke(f.map((e,a)=>{const o=W[a]||0;return o>0?(o-Q(a))/o*100:0}),fe));const et=w.map((e,a)=>{const o=U[a]||0;return o>0?(o-e)/o*100:null}),tt=e=>M.reduce((a,o)=>a+(e[o]||0),0),ae=(e,a)=>M.length?{actual:I(a),plannedToDate:tt(e),actualSeries:Ge(a,te)}:{actual:null,plannedToDate:0,actualSeries:null},Ce=[{id:"materials",key:"DIRECT_MATERIALS",total:ce,series:B,color:"#0F67EA",...ae(B,Z)},{id:"streamCosts",key:"REVENUE_SPECIFIC",total:de,series:G,color:"#00857A",...ae(G,q)},{id:"labour",key:"DIRECT_LABOUR",total:ue,series:D,color:"#B54AC4",...ae(D,J)}].map(e=>({...e,share:y>0?e.total/y*100:0})),se=[...Ce].sort((e,a)=>a.total-e.total)[0],ne=(e,a,o)=>(e!=null?e:[]).map($=>{var k;return{id:$._id,name:$.title,color:$.color,total:(k=a[$._id])!=null?k:0,share:0,actual:0,meta:o}}),oe=[...ne(O,c.totalByGroup,"DIRECT_MATERIALS"),...ne(g,A.totalByGroup,"REVENUE_SPECIFIC"),...ne(L,_.totalByGroup,"DIRECT_LABOUR")].map(e=>({...e,share:y>0?e.total/y*100:0})).sort((e,a)=>a.total-e.total),at=((xe=oe[0])==null?void 0:xe.total)>0?oe[0]:void 0,le=(e,a,o,$)=>(e!=null?e:[]).map(k=>{var Pe,be,De;return{id:k._id,name:((Pe=k.metaInfo)==null?void 0:Pe.name)||"",color:(be=(o!=null?o:[]).find(lt=>lt._id===k.groupId))==null?void 0:be.color,total:(De=a[k._id])!=null?De:0,share:0,actual:0,meta:$}}),st=[...le(j,c.totalByItem,O,"DIRECT_MATERIALS"),...le(v,A.totalByItem,g,"REVENUE_SPECIFIC"),...le(m,_.totalByItem,L,"DIRECT_LABOUR")].filter(e=>e.total>0).map(e=>({...e,share:y>0?e.total/y*100:0})).sort((e,a)=>a.total-e.total),nt=jt(S,i,u,E("FORECAST_SCOPE.YEARS",{count:f.length,raw:!0})),Oe=[c,A,_].reduce((e,a)=>{var o;return e+Object.keys((o=a.totalByItem)!=null?o:{}).length}
1,0),ot=[...j!=null?j:[],...v!=null?v:[],...m!=null?m:[]].filter(e=>e.isSetupPending).map(e=>{var a,o;return{id:e._id,name:(o=(a=e.metaInfo)==null?void 0:a.name)!=null?o:""}});return{labels:u!=null?u:[],scopeLabel:nt,total:y,isUnstarted:Oe===0,hasRows:Oe>0,totalSeries:w,components:Ce,largest:se&&se.total>0?se:void 0,groups:oe,rows:st,largestGroup:at,pendingRows:ot,revenue:K,grossMargin:Ze,actualGrossMargin:qe,marginSeries:et,actualTotalSeries:Xe,actualMarginSeries:ze,marginTrend:Qe,actualMarginTrend:me,hasActuals:s,actualTotal:pe,plannedToDate:Ye,recordedPeriods:M.length,recordedIndices:M}},[p,l,T,F,s,S,i,E,O,g,L,j,v,m,c,A,_])}function Bt({total:t,revenue:S,grossMargin:i,components:E,pendingRows:d}){const N=E.map(s=>`${s.id}:${Math.round(s.total)}`).join("|"),h=d.map(s=>`${s.id}:${s.name}`).join("|");return R.useMemo(()=>{const s=[];if(d.forEach(f=>{s.push({id:`unfinished:${f.id}`,rowId:f.id,subject:f.name,message:"NOTE_NEEDS_SETUP"})}),S<=0)return s;i!=null&&i<0?s.push({id:"negative-margin",subject:"",message:"NOTE_NEGATIVE_MARGIN"}):i!=null&&i<10&&s.push({id:"thin-margin",subject:"",message:"NOTE_THIN_MARGIN"}),t<=0&&s.push({id:"no-cost-of-sales",subject:"",message:"NOTE_NO_COST_OF_SALES"});const C=E.find(f=>f.id==="labour");return t>0&&C&&(C.total<=0?s.push({id:"no-labour",subject:"",message:"NOTE_NO_DIRECT_LABOUR"}):C.share>=70&&s.push({id:"labour-heavy",subject:"",message:"NOTE_LABOUR_HEAVY"})),s},[t,S,i,N,h])}function Gt({total:t,scopeLabel:S,largest:i,marginTrend:E,actualMarginTrend:d,grossMargin:N,actualGrossMargin:h,isActualEnabled:s,actual:C,plannedToDate:f,recordedPeriods:u,hasRows:p}){var L,b;const l=z(),{formatCompactNumber:T}=St(),O=x=>T(x,1,!0),g=x=>`${x.toFixed(x%1===0?0:1)}%`;return r.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[r.jsxs(X,{label:`${l("COS_PLAN.TOTAL_COST_OF_SALES")} · ${S}`,note:s&&u?void 0:l("COS_PLAN.INCLUDES_LABOUR"),children:[r.jsx("span",{className:"text-2xl font-bold tabular-nums tracking-tight text-foreground",children:p?O(t):"—"}),s&&!!u&&(()=>{const x=f?((C!=null?C:0)-f)/f*100:null;return r.jsxs("span",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1",children:[r.jsxs("span",{className:"text-xs text-muted-foreground",children:[l("COS_PLAN.ACTUAL")," ",r.jsx("span",{className:"font-semibold tabular-nums text-foreground",children:C!=null?O(C):"—"})]}),r.jsx(Mt,{value:x,higherIsBetter:!1}),!!u&&r.jsx("span",{className:"text-xs text-muted-foreground",children:l("COS_PLAN.RECORDED_PERIODS",{count:u})})]})})()]}),r.jsx(X,{label:l("COS_PLAN.GROSS_MARGIN"),note:N==null?l("COS_PLAN.MARGIN_NEEDS_REVENUE"):s&&h!=null?r.jsxs(r.Fragment,{children:[l("COS_PLAN.ACTUAL")," ",r.jsx("span",{className:"font-semibold text-foreground",children:g(h)})," ",l("COS_PLAN.SO_FAR")]}):N<0?r.jsx("span",{className:"font-semibold text-destructive",children:l("COS_PLAN.MARGIN_NEGATIVE")}):l("COS_PLAN.MARGIN_HINT"),children:r.jsx("span",{className:N!=null&&N<0?"text-lg font-semibold tabular-nums text-destructive":"text-lg font-semibold tabular-nums text-foreground",children:N==null?"—":g(N)})}),r.jsx(X,{label:l("COS_PLAN.LARGEST_GROUP"),note:i?r.jsxs("span",{className:"font-semibold text-foreground",children:[g(i.share)," ",l("COS_PLAN.SHARE_OF_TOTAL")]}):void 0,children:r.jsxs("span",{className:"flex items-center gap-2 truncate text-lg font-semibold text-foreground",children:[(i==null?void 0:i.color)&&r.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:i.color}}),r.jsx("span",{className:"truncate",title:(L=i==null?void 0:i.name)!=null?L:void 0,children:(b=i==null?void 0:i.name)!=null?b:"—"})]})}),r.jsx(X,{label:l("COS_PLAN.MARGIN_TREND"),note:d!=null?r.jsxs("span",{className:"flex flex-wrap items-center gap-x-2",children:[r.jsx("span",{children:l("COS_PLAN.MARGIN_TREND_HINT")}),r.jsxs("span",{className:"flex items-center gap-1",children:[l("COS_PLAN.ACTUAL"),r.jsx("span",{className:"text-xs",children:r.jsx(Ue,{value:d,higherIsBetter:!0,suffix:" pts"})})]})]}):E!=null?l("COS_PLAN.MARGIN_TREND_HINT"):l("COS_PLAN.MARGIN_TREND_NONE"),children:r.jsx(Ue,{value:E,higherIsBetter:!0,suffix:" pts"})})]})}function qt(){const t=Ft(),{selectedOption:S,handleOptionChange:i,chartOptions:E,chartKey:d,showsRecordedStack:N}=vt(t),h=Bt({total:t.total,revenue:t.revenue,grossMargin:t.grossMargin,components:t.components,pendingRows:t.pendingRows}),s=z(),C=t.groups.map(u=>({...u,meta:s(`COS_PLAN.${u.meta}`,{raw:!0})})),f=t.rows.map(u=>({...u,meta:s(`COS_PLAN.${u.meta}`,{raw:!0})}));return t.isUnstarted?null:r.jsxs("div",{className:"space-y-4",children:[r.jsx(Gt,{hasRows:t.hasRows,total:t.total,scopeLabel:t.scopeLabel,largest:t.largestGroup,marginTrend:t.marginTrend,actualMarginTrend:t.actualMarginTrend,grossMargin:t.grossMargin,actualGrossMargin:t.actualGrossMargin,isActualEnabled:t.hasActuals,actual:t.actualTotal,plannedToDate:t.plannedToDate,recordedPeriods:t.recordedPeriods}),r.jsx(Et,{notes:h,i18n:"COS_PLAN"}),r.jsxs("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-[2fr_1fr] [&>*]:min-w-0",children:[r.jsx(It,{isEmpty:!t.hasRows,chartOptions:E,options:We,selectedOption:S,onOptionChange:i,chartKey:`${d}:${S}
1`,subtitle:N?s("COS_PLAN.CHART_RECORDED_HINT"):void 0}),r.jsxs("div",{className:"flex flex-col gap-4 xl:h-0 xl:min-h-full",children:[r.jsx(xt,{className:"flex-1",groups:C,alternate:{rows:f,groupLabel:s("COS_PLAN.MIX_BY_GROUP",{raw:!0}),rowLabel:s("COS_PLAN.MIX_BY_ITEM",{raw:!0})},title:s("COS_PLAN.COST_MIX"),scopeLabel:t.scopeLabel,emptyLabel:s("COS_PLAN.MIX_EMPTY",{raw:!0})}),r.jsx(Pt,{title:s("COS_PLAN.BY_COMPONENT"),higherIsBetter:!1,segments:t.components.map(u=>({label:s(`COS_PLAN.${u.key}`,{raw:!0}),value:u.total,color:u.color,actual:u.actual,plannedToDate:u.plannedToDate}))})]})]})]})}export{qt as OverviewComponent};

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.