1import{a as Gt}from"./chunk-I6QFWMCH.js";import{a as Ot,b as Nt}from"./chunk-DWHLWXZ3.js";import{a as qt}from"./chunk-365QIPN4.js";import{a as w}from"./chunk-AS6BC4OJ.js";import{a as wt}from"./chunk-WQ5RY72K.js";import"./chunk-L65ALBMC.js";import"./chunk-KPXXRNKH.js";import{a as Rt}from"./chunk-4PLAMQ7J.js";import{a as It}from"./chunk-QKHIHIK2.js";import{a as Se}from"./chunk-LUOCW6HQ.js";import{a as Ft}from"./chunk-GRCKWKXN.js";import{a as J}from"./chunk-3XTQ6TTI.js";import{a as Et}from"./chunk-JYH4CEVU.js";import"./chunk-HXAL5LGP.js";import{a as Ve,b as $}from"./chunk-OHZXVWME.js";import"./chunk-YXJBJXEH.js";import"./chunk-K6SPPEPZ.js";import{a as Lt}from"./chunk-X3RSROO6.js";import"./chunk-P6BYWFI2.js";import"./chunk-CWNX4Y6X.js";import{a as _t}from"./chunk-QDCFFCPG.js";import{a as Ne}from"./chunk-LOSZH6LX.js";import{a as fe}from"./chunk-QYBXKO73.js";import{a as ge}from"./chunk-SC7OIAJ7.js";import"./chunk-J363OWI3.js";import"./chunk-OANYDW7H.js";import"./chunk-F2QKMJL3.js";import{b as Ct,c as At,d as yt,e as bt,f as Be}from"./chunk-OT7D67RG.js";import"./chunk-FTHQQTSG.js";import"./chunk-VEH24MDR.js";import"./chunk-L22N5WJT.js";import{a as Dt}from"./chunk-WG7WEUJG.js";import{a as Tt,c as pe}from"./chunk-VGGK7HQB.js";import"./chunk-J6WHBBPP.js";import"./chunk-MKF6QG6V.js";import"./chunk-HOI7JMLX.js";import"./chunk-B3XBM5MD.js";import"./chunk-XGLRQSSV.js";import"./chunk-DAOPRFTB.js";import"./chunk-4OCSXWTB.js";import{c as vt}from"./chunk-MVFZ4W5S.js";import"./chunk-NL46MEWC.js";import{a as de,b as me}from"./chunk-QPO6AB24.js";import"./chunk-T2LKHT2R.js";import{a as Ie}from"./chunk-AV7BHVMF.js";import"./chunk-ECX4OUPM.js";import"./chunk-D5ZZMR3T.js";import"./chunk-LB7GZ4RS.js";import{a as ft}from"./chunk-MN2O4OIW.js";import{a as we,k as ue,l as Z,m as N}from"./chunk-XJIYDCB7.js";import"./chunk-OOAKO2NW.js";import"./chunk-CW3A6GGH.js";import"./chunk-LLNDO5TI.js";import"./chunk-LK2H5GWW.js";import"./chunk-LLNUHMNV.js";import"./chunk-QUSGVUOF.js";import"./chunk-CJPLD6EO.js";import"./chunk-PDZ2GFID.js";import{a as ut}from"./chunk-O7GVHEWQ.js";import"./chunk-4W4OTVCU.js";import"./chunk-UBZHVILN.js";import"./chunk-WECRXZVT.js";import"./chunk-SXSN5XUL.js";import"./chunk-XGQFJQG5.js";import"./chunk-7MFB5OWF.js";import{a as ht}from"./chunk-TH4X4PKG.js";import"./chunk-C6BZFLMK.js";import"./chunk-IDHC3I6D.js";import"./chunk-TVZI3GRT.js";import{a as ye}from"./chunk-EMD5D3CD.js";import{f as St}from"./chunk-P7NG7HPQ.js";import"./chunk-CZPI7VJ5.js";import{j as pt}from"./chunk-4VN4MCU7.js";import{a as Oe}from"./chunk-7GVDXUAU.js";import"./chunk-4J4X5EMA.js";import"./chunk-ECECGNR4.js";import"./chunk-2IWGUN3K.js";import{a as mt}from"./chunk-NCZHNS3C.js";import"./chunk-GO7UHMBF.js";import"./chunk-5DDWRNUO.js";import{V as ot,Z as nt,a as Pe,ca as lt,da as Ce,s as he,va as Ae}from"./chunk-6ZVTRFTL.js";import"./chunk-P76QNSQL.js";import{A as Ze,d as $e,h as Je,n as Qe,s as Xe}from"./chunk-Z34FZIQM.js";import"./chunk-SM5FSVVY.js";import"./chunk-TDDXVLK3.js";import{Aa as le,Ab as z,Ba as c,Ca as ce,Ea as et,Ec as gt,Fa as Fe,Ja as X,La as tt,Qa as _,Va as K,Wa as it,Xa as Re,Ya as D,cb as U,fb as Te,gb as b,jb as at,ob as rt,pc as j,sc as dt,tb as Y,uc as x,vc as P,xb as st}from"./chunk-XVA3MWZK.js";import"./chunk-IJOWPJZI.js";import{d as ct,e as M}from"./chunk-U32DLQYF.js";import{Aa as ze,Ac as ne,Bc as R,Cc as Le,Fc as Ye,Ga as be,Kb as I,Lb as O,Mc as T,Nc as C,Qb as h,Rb as m,Sb as f,Tb as A,U as ie,_b as ae,bb as u,cc as v,e as Me,ec as E,ha as g,ic as He,jc as Ee,kc as _e,mb as je,oa as B,oc as We,p as te,pa as V,rb as L,tc as re,uc as Ke,w as W,wb as k,yc as se,zc as oe}from"./chunk-FCFRADKE.js";import{a as d,b as ee,h as De,j as q}from"./chunk-XHGXIXF6.js";var Pt=De(ye());function Wt(l,H){if(l&1){let t=ae();m(0,"div",1)(1,"app-common-data-grid",2),T(2,"mciTranslate"),v("gridReady",function(e){B(t);let a=E();return V(a.onEquipmentGridReady(e))})("onRowSelect",function(){B(t);let e=E();return V(e.rowSelected())}),f()()}if(l&2){let t=E();u(),h("fileName",R(C(2,19,"L.Equipment_Allocated")))("columnDefinition",t.colDefsEquipment)("detailGrid",!0)("getRowIdCB",t.getRowIdCallBack)("gridData",t.equipmentData)("gridHeight",t.equipmentC
1ount*t.gridRowHeight+t.gridBufferSpace)("gridName",t.equipmentData[0]==null||t.equipmentData[0].resource==null?null:t.equipmentData[0].resource.name)("isSliderGrid",!0)("masterDetail",!0)("menuEventCB",t.menuEventCallBack)("pageSize",t.equipmentCount)("showAddButton",!1)("showGridAcceptButton",!1)("showGridDeleteButton",!1)("showGridSettings",!1)("showGridStatusButton",!1)("showPaginator",!1)("showSelectedRowCount",!1)}}var Bt=(()=>{class l{constructor(){this.mathService=g(mt),this.modalService=g(gt),this.viewRef=g(je),this.dateTimeService=g(Ae),this.uiUtilitiesService=g(St),this.compareService=g(ht),this.mciTranslateService=g(ct),this.mciGridService=g(ut),this.exceptionIconService=g(Tt),this.equipmentCount=0,this.gridBufferSpace=64,this.gridRowHeight=40,this.equipmentData=[],this.colDefsEquipment=[],this.canViewGLAccount=!1,this.customFields=[],this.menuEventCallBack=t=>{this.parentParams.resourceClicked(t.actionType,t.rowData)}}agInit(t){this.eventsSubscription=t.clickEvents.subscribe(()=>this.refresh()),this.parentParams=t,this.permissions=this.parentParams?.getPermissions(),this.canViewGLAccount=this.parentParams?.getCanViewGLAccount?.()??!1,this.dataItem=t.data,this.masterGridApi=t.api,this.rowId=t.node.id,this.getEquipmentChildData(),this.configurePopupOptions(),this.setColumnDefs()}configurePopupOptions(){let t=[{action:c.VIEW,canAct:this.permissions?.canView},{action:c.EDIT,canAct:this.permissions?.canEdit},{action:c.DELETE,canAct:this.permissions?.canDelete}];this.popupOptions=t.filter(i=>i.canAct).map(i=>i.action)}setColumnDefs(){let t=[{headerName:_.CONTEXTMENU,context:{isMenuEvent:!0},cellRenderer:"materialGridMenu",cellRendererParams:{buttons:this.popupOptions,filterButtons:(e,a)=>{let r=e?.state?.id;return[b.ALLOCATED,b.REVOKED,b.REJECTED,b.VOIDED].includes(r)?e?.isnegativeallocation?a?.filter(s=>s!==c.EDIT):a:a?.filter(s=>s!==c.DELETE&&s!==c.EDIT)}}},{headerName:this.mciTranslateService.getTranslation(_.EXCEPTION),field:"exceptions",cellRenderer:"exceptionIconCell",context:{excludeExcelExport:!1,isAutoSize:!0},cellRendererParams:e=>({iconClickEvent:a=>{this.onExceptionIconClick(a,e.data)}})},{field:"state",headerName:this.mciTranslateService.getTranslation("L.State"),cellRenderer:"globalStatesCellRenderer"},{field:"agreement.name",headerName:this.mciTranslateService.getTranslation("L.Agreement")},{field:"costobject.ordertype.name",headerName:this.mciTranslateService.getTranslation("L.Order_Type"),filter:"agTextColumnFilter",valueGetter:e=>this.uiUtilitiesService.getOrderTypeTranslation(e?.data?.costobject?.ordertype?.name)},{field:"costobject.purchaseorder.name",headerName:this.mciTranslateService.getTranslation("L.Purchase_Order"),filter:"agTextColumnFilter"},{field:"costobject.purchaseorderline.name",headerName:this.mciTranslateService.getTranslation("L.PO_Line"),filter:"agTextColumnFilter"},{field:"costobject.labelname",headerName:this.mciTranslateService.getTranslation("L.Cost_Object_Type"),filter:"agTextColumnFilter"},{field:"costobject.name",headerName:this.mciTranslateService.getTranslation("L.Cost_Object"),filter:"agTextColumnFilter"},{field:"costobject.operation.name",headerName:this.mciTranslateService.getTranslation("L.Operation_Or_Activity"),filter:"agTextColumnFilter"},{field:"costobject.suboperation.name",headerName:this.mciTranslateService.getTranslation("L.Sub_Operation_Or_Element"),filter:"agTextColumnFilter"},{field:"area.name",headerName:this.mciTranslateService.getTranslation("L.Area_ID"),filter:"agTextColumnFilter",context:{isAutoSize:!0}},{field:"glaccount.code",headerName:this.mciTranslateService.getTranslation("L.GL_Account"),valueGetter:e=>e?.data?.glaccount?.code??e?.data?.glaccount?.name,cellRenderer:e=>e.value??Ce,filter:"agTextColumnFilter",hide:!this.canViewGLAccount}],i=[d({field:"allocated.hours.hourly",headerName:this.mciTranslateService.getTranslation("L.Base"),cellRenderer:e=>this.mathService.formatNumber(e.value),valueGetter:e=>this.mathService.roundDisplay(e?.data?.allocated?.hours?.hourly??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"allocated.hours.overrate",headerName:this.mciTranslateService.getTranslation("L.Over"),cellRenderer:e=>this.mathService.formatNumber(e.value),valueGetter:e=>this.mathService.roundDisplay(e?.data?.allocated?.hours?.overrate??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"allocated.hours.idle",headerName:this.mciTranslateService.getTranslation("L.Idle"),cellRenderer:e=>this.mathService.formatNumber(e.value),valueGetter:e=>this.mathService.roundDisplay(e?.data?.allocated?.hours?.idle??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"allocated.othercharges",headerName:this.mciTranslateService.getTranslation("L.Other_Charge"),cellRenderer:e=>{let a=this.mathService.formatNumber(e?.value),r=e?.data?.currency?.code;return this.mciGridService.cellWithSuffix(a,r)},valueGetter:e=>this.mathService.roundDisplay(e?.data?.allocated?.othercharges??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),{field:"isnonbillable",headerName:this.mciTranslateService.getTranslation("L.Non_Billable"),cellRenderer:"gridSwitch",headerClass:"ag-center-aligned-header",cellClass:"ag-center-aligned-cell",cellRendererParams:{canActivate:this.permissions?.canActivate,canDeactivate:this.permissions?.canDeactivate},context:{isMenuEvent:!0,isAutoSize:!0},resizable:!1},{field:"islumpsum",headerName:this.mciTranslateService.getTranslation("L.Lump_Sum"),cellRenderer:"gridSwitch",headerClass:"ag-center-aligned-header",cellClass:"ag-center-aligned-cell",cellRendererParams:{canActivate:this.permissions?.canActivate,canDeactivate:this.permissions?.canDeactivate},context:{isMenuEvent:!0,isAutoSize:!0},resizable:!1},{field:"issubcontractor",headerName:this.mciTranslateService.getTranslation("L.Sub_Contractor"),cellRenderer:"gridSwitch",headerClass:"ag-center-aligned-header",cellClass:"ag-center-aligned-cell",cellRendererParams:{canActivate:this.permissions?.canActivate,canDeactivate:this.permissions?.canDeactivate},context:{isMenuEvent:!0,isAutoSize:!0},resizable:!1},d({field:"allocated.hours.total",headerName:this.mciTranslateService.getTranslation("L.Total_Hours"),cellRenderer:e=>this.mathService.formatNumber(e?.value),valueGetter:e=>this.mathService.roundDisplay(e?.data?.allocated?.hours?.total??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),{headerName:this.mciTranslateService.getTranslation("L.Attachments"),headerClass:"ag-center-aligned-header",cellClass:"ag-center-aligned-cell",field:"attachmentscount",cellRenderer:"materialGridIcon",cellRendererParams:e=>e?.data?{icon:"attach_file",isDisplayValue:!0,propertyName:"attachmentscount",displayValueCb:a=>a?.data?.totalFiles,disabled:e?.data?.totalFiles<=0,clickEvent:a=>{if(a?.consolidatedattachments?.length){let r={id:a?.id,attachmentData:a.consolidatedattachments},s=Pt.default.clone(this.permissions);s.canDelete=!1,this.modalService.openAttachmentModal(this.viewRef,r,this.mciTranslateService.getTranslation("L.Equipment_Allocated"),this.actionType,s,!1,null,null,!1)}}}:{},comparator:this.compareService.consolidatedAttachmentComparator,context:{isAutoSize:!0},resizable:!1},{field:"comment",cellRenderer:"commentCell",headerName:this.mciTranslateService.getTranslation(_.COMMENT)},{field:"timesheetreference",headerName:this.mciTranslateService.getTranslation("L.Timesheet_Num"),context:{displayFieldName:""},filterParams:{valueGetter:e=>e.data?.timesheetreference?.split(",")}},{field:"revoketimesheetref",headerName:this.mciTranslateService.getTranslation("L.Revoked_Timesheet_Num"),context:{displayFieldName:""},filterParams:{valueGetter:e=>e.data?.revoketimesheetref?.toString()?.split(",")}},{field:"lastedited.date",headerName:this.mciTranslateService.getTranslation("L.Last_Edited"),type:"rightAligned",valueGetter:e=>this.dateTimeService.toLocalizedDateHourMinFormat(e.data.lastedited.date),filter:"agDateColumnFilter",filterParams:{comparator:this.dateTimeService.localizedDateHourMinFilterComparator},comparator:this.dateTimeService.localizedDateHourMinComparator,context:{isAutoSize:!0}},{field:"lastedited.user",headerName:this.mciTranslateService.getTranslation("L.Edited_By")}];this.customFields=this.mciGridService.prepareDynamicCustomFieldColumnDefs(this.equipmentData,"name","name","type"),this.colDefsEquipment=[...t,...this.customFields,...i]}
1onExceptionIconClick(t,i){if(t===Y.REVOKED){let e={exceptionIcon:t,extraData:{resourceId:i?.resource?.id,timesheetDate:i.workdate,organizationId:i.organization.id,timesheetId:i.timesheetid,timesheetRef:i.timesheetreference&&i.timesheetreference.trim()!==""?i.timesheetreference:i.revoketimesheetref}};this.exceptionIconService.onExceptionIconClick(e)}}getEquipmentChildData(){this.dataItem&&(this.equipmentData=this.dataItem?.childData,this.equipmentCount=this.equipmentData?.length)}refresh(){return this.selectCorrectCells(this.equipmentData,this.parentParams.node.parent.data.equipmentChildRowsSelected,this.gridApiEquipment),!1}onEquipmentGridReady(t){this.gridApiEquipment=t.api;let i={id:this.rowId,api:this.gridApiEquipment};this.masterGridApi.addDetailGridInfo(this.rowId,i),this.selectCorrectCells(this.equipmentData,this.parentParams.node.parent.data.equipmentChildRowsSelected,this.gridApiEquipment)}selectCorrectCells(t,i,e){this.parentParams.node.parent.isSelected()&&t?.length>0&&i?e?.forEachNode(a=>{a.setSelected(i.filter(r=>r?.id===a?.data?.id).length>0)}):i?.length||e?.forEachNode(a=>{a.setSelected(!1)}),e?.refreshCells()}getRowIdCallBack(t){return t.data.id=t.data?.allocations?.replaceAll('"',"").split(",")[0],t.data.id}rowSelected(){this.parentParams.node.parent.data.equipmentChildRowsSelected=this.gridApiEquipment?this.gridApiEquipment.getSelectedRows():[];let t=this.parentParams.node.parent.data.equipmentChildRowsSelected.length,i=this.parentParams.node.parent.data.equipmentChildRowsSelected?.map(e=>e?.state?.id);this.parentParams.node.parent.data.selectedChildRowStates=i??[],this.parentParams.node.parent.data.rowsSelected=t,t===0?this.parentParams.node.parent.setSelected(!1):this.parentParams.node.parent.setSelected(!0),this.parentParams.childrenSelected(),this.masterGridApi?.refreshCells()}ngOnDestroy(){this.eventsSubscription.unsubscribe(),this.masterGridApi?.removeDetailGridInfo(this.rowId)}static{this.\u0275fac=function(i){return new(i||l)}}static{this.\u0275cmp=L({type:l,selectors:[["app-equipment-allocated-detail-grid"]],decls:2,vars:1,consts:[["id","grid-detail-section",1,"mci-ui-nested-table-container"],[1,"mci-ui-nested-table"],[3,"gridReady","onRowSelect","columnDefinition","detailGrid","getRowIdCB","gridData","gridHeight","gridName","isSliderGrid","masterDetail","menuEventCB","pageSize","showAddButton","showGridAcceptButton","showGridDeleteButton","showGridSettings","showGridStatusButton","showPaginator","showSelectedRowCount","fileName"]],template:function(i,e){i&1&&(m(0,"div",0),I(1,Wt,3,21,"div",1),f()),i&2&&(u(),O(e.equipmentCount?1:-1))},dependencies:[N,M],encapsulation:2})}}return l})();function Kt(l,H){if(l&1&&(A(0,"drawer-header-dynamic-content",0),T(1,"localizedDate")),l&2){let t=E();h("subTitle2",Le("| ",C(1,3,t.rowData==null?null:t.rowData.timesheetdate)))("globalStateCode",t.rowData==null||t.rowData.state==null?null:t.rowData.state.code)}}var Vt=(()=>{class l extends Ie{constructor(){super(...arguments),this.equipmentAllocationService=g(J),this.allocationService=g($),this.gridData=[],this.columnDefs=[],this.hasOtherStates=!1,this.hasOtherStatesAtRowLevel=!1,this.refreshParentGrid=!1,this.customFields=[],this.isTimesheetDateGreaterToday=!1,this.payDetailsData={},this.canViewAcceptance=!0,this.canViewGLAccount=!1}onSave(){throw new Error("Method not implemented.")}getTranslations(){this.entity=this.mciTranslateService.getTranslation("L.Allocation"),this.entityPlural=this.mciTranslateService.getTranslation("L.Allocations")}ngOnInit(){this.mciTranslateService.onLangChange.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(()=>{this.getTranslations(),this.setColumnDefs(),this.gridApi?.refreshHeader()}),this.getTranslations(),this.drawerService.formConfig$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{if(t!=null){let{rowData:i,actionType:e,permissions:a,extraData:r}=t;this.rowData=i,this.payDetailsData={agreement:i?.agreement,type:i?.type,group:i?.resourcegroup,nethours:i?.nethours,base:i?.baseHrs,over:i?.overHrs,idle:i?.idleHrs,weeklystartdate:i?.weeklystartdate,weeklycumulativehours:i?.weeklycumulativehours,monthlystartdate:i?.monthlystartdate,monthlycumulativebase:i?.monthlycumulativebase,otherchargestotal:i?.otherAllowableCharge??0,currencyabbr:i?.currency?.code,preapproval:i?.preapproval},this.actionType=e,this.permissions=a,this.canViewAcceptance=r?.canViewAcceptance??!0,this.canViewGLAccount=r?.canViewGLAccount??!1,this.isTimesheetDateGreaterToday=!(new Date(this.rowData?.workdate)>new Date&&!r?.allowEquipmentFutureDates),this.recordName=i?.resource?.name??"",this.drawerService.drawer$.value.form?this.form=this.drawerService.drawer$.value.form:this.initializeForm(),this.getAllocatedResource(i)}}),this.drawerService.drawerFooterAction$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>
1{if(t!=null)switch(t){case this.ACTIONS.CLOSE:case this.ACTIONS.CANCEL:this.onFormClose(!1,!1,!1,j.ASYNC_CONFIRM);break;case this.ACTIONS.ACCEPT:this.onAccept();break}})}initializeForm(){this.form=this.formBuilder.group({group:"",organization:"",onSite:this.rowData?.total??""})}onGridReady(t){this.gridApi=t.api,this.setColumnDefs()}getAllocatedResource(t){let i={OrganizationId:t.organization?.id,TimesheetDate:this.dateTimeService.toISODateFormat(t.workdate),ResourceId:t.resource?.id,RasId:t.activity?.rasid};this.equipmentAllocationService.getEquipmentAllocatedResource(i).subscribe(e=>{e[0]?.data?.length&&(e[0]?.data.forEach(a=>{a.consolidatedattachments=this.uiUtilitiesService.formatStringWithMultipleArray(a.consolidatedattachments),a.totalFiles=a?.consolidatedattachments?.length??0,this.hasOtherStates||(this.hasOtherStates=a?.state?.code!==w.ALLOCATED&&a?.state?.code!==w.PARTIALLY_ALLOCATED)}),this.prepareAllocationData(e[0]?.data),this.setColumnDefs(),this.updateFooterButton())})}prepareAllocationData(t){this.customFields=this.mciGridService.prepareDynamicCustomFieldColumnDefs(t,"name","name","format"),this.gridData=t}setColumnDefs(){let t="ag-center-aligned-header",i="ag-center-aligned-cell",e=[{field:"state",headerName:this.mciTranslateService.getTranslation("L.State"),cellRenderer:"globalStatesCellRenderer"},{field:"costobject.ordertype.name",headerName:this.mciTranslateService.getTranslation("L.Order_Type"),filter:"agTextColumnFilter",valueGetter:r=>this.uiUtilitiesService.getOrderTypeTranslation(r?.data?.costobject?.ordertype?.name)},{field:"costobject.purchaseorder.name",headerName:this.mciTranslateService.getTranslation("L.Purchase_Order"),filter:"agTextColumnFilter"},{field:"costobject.purchaseorderline.name",headerName:this.mciTranslateService.getTranslation("L.Purchase_Order_Line"),filter:"agTextColumnFilter"},{field:"costobject.labelname",headerName:this.mciTranslateService.getTranslation("L.Cost_Object_Type"),filter:"agTextColumnFilter"},{field:"costobject.name",headerName:this.mciTranslateService.getTranslation("L.Cost_Object"),filter:"agTextColumnFilter"},{field:"costobject.operation.name",headerName:this.mciTranslateService.getTranslation("L.Operation_Or_Activity"),filter:"agTextColumnFilter"},{field:"costobject.suboperation.name",headerName:this.mciTranslateService.getTranslation("L.Sub_Operation_Or_Element"),filter:"agTextColumnFilter"},{field:"area.name",headerName:this.mciTranslateService.getTranslation("L.Area_ID"),filter:"agTextColumnFilter",context:{isAutoSize:!0}},{field:"glaccount.name",headerName:this.mciTranslateService.getTranslation("L.GL_Account"),filter:"agTextColumnFilter",cellRenderer:r=>r.value||Ce,sortable:!0,context:{isAutoSize:!0},hide:!this.canViewGLAccount}],a=[d({field:"hours.hourly",headerName:this.mciTranslateService.getTranslation("L.Base"),cellRenderer:r=>this.mathService.formatNumber(r?.value),valueGetter:r=>this.mathService.roundHours(r?.data?.hours?.hourly,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"rate.hourly",headerName:this.mciTranslateService.getTranslation("L.Base_Rate"),cellRenderer:r=>this.getCurrencyCellRenderer(r),valueGetter:r=>this.mathService.roundRate(r?.data?.rate?.hourly,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"hours.overrate",headerName:this.mciTranslateService.getTranslation("L.Over"),cellRenderer:r=>this.mathService.formatNumber(r?.value),valueGetter:r=>this.mathService.roundHours(r?.data?.hours?.overrate,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"rate.overrate",headerName:this.mciTranslateService.getTranslation("L.Over_Rate"),cellRenderer:r=>this.getCurrencyCellRenderer(r),valueGetter:r=>this.mathService.roundRate(r?.data?.rate?.overrate,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"hours.idle",headerName:this.mciTranslateService.getTranslation("L.Idle"),cellRenderer:r=>this.mathService.formatNumber(r?.value),valueGetter:r=>this.mathService.roundHours(r?.data?.hours?.idle,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"rate.idle",headerName:this.mciTranslateService.getTranslation("L.Idle_Rate"),cellRenderer:r=>this.getCurrencyCellRenderer(r),valueGetter:r=>this.mathService.roundRate(r?.data?.rate?.idle,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"othercharges",headerName:this.mciTranslateService.getTranslation("L.Other_Charge"),cellRenderer:r=>this.getCurrencyCellRenderer(r),valueGetter:r=>this.mathService.roundRate(r?.data?.othercharges,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),{field:"isnonbillable",headerName:this.mciTranslateService.getTranslation("L.Non_Billable"),cellRenderer:"gridSwitch",headerClass:t,cellClass:i,cellRendererParams:{canActivate:!0,canDeactivate:!0},context:{isMenuEvent:!1,isAutoSize:!0},resizable:!1},{field:"isfixedfee",headerName:this.mciTranslateService.getTranslation("L.Lump_Sum"),cellRenderer:"gridSwitch",headerClass:t,cellClass:i,cellRendererParams:{canActivate:!0,canDeactivate:!0},context:{isMenuEvent:!1,isAutoSize:!0},resizable:!1},{field:"issubcontractor",headerName:this.mciTranslateService.getTranslation("L.Sub_Contractor"),cellRenderer:"gridSwitch",headerClass:t,cellClass:i,cellRendererParams:{canActivate:!0,canDeactivate:!0},context:{isMenuEvent:!1,isAutoSize:!0},resizable:!1},{field:"comment",cellRenderer:"commentCell",headerName:this.mciTranslateService.getTranslation(_.COMMENT)},d({field:"cost",headerName:this.mciTranslateService.getTranslation("L.Total"),cellRenderer:r=>this.mathService.formatNumber(r?.value),valueGetter:r=>this.mathService.roundRate(r?.data?.cost,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),{headerName:this.mciTranslateService.getTranslation("L.Attachment"),cellRenderer:"materialGridIcon",headerClass:t,cellClass:i,field:"attachmentsd
1ata",filter:"agNumberColumnFilter",editable:!1,comparator:this.compareService.consolidatedAttachmentComparator,cellRendererParams:{icon:"attach_file",isDisplayValue:!0,propertyName:"attachmentdata",displayValueCb:r=>r?.data?.totalFiles,clickEvent:r=>{if(r?.consolidatedattachments?.length){let s={id:r?.id,attachmentData:r?.consolidatedattachments};this.modalService.openAttachmentModal(this.viewRef,s,this.mciTranslateService.getTranslation("L.Equipment_Not_Allocated"),this.actionType,this.attachmentsPermissions,!1)}}},context:{isAutoSize:!0},resizable:!1},{field:"timesheetreference",headerName:this.mciTranslateService.getTranslation("L.TS_Ref"),context:{displayFieldName:""},type:"rightAligned",cellRenderer:r=>this.getStringRender(r?.data?.timesheetreference??""),filterParams:{valueGetter:r=>r.data?.timesheetreference}},{field:"revoketimesheetref",headerName:this.mciTranslateService.getTranslation("L.Revoked_Timesheet_Num"),context:{displayFieldName:""},type:"rightAligned",cellRenderer:r=>r?.data?.revoketimesheetref,filterParams:{valueGetter:r=>r.data?.revoketimesheetref}}];this.columnDefs=[...e,...this.customFields,...a]}getCurrencyCellRenderer(t){let i=this.mathService.formatNumber(t?.value),e=this.rowData?.currency?.code;return this.mciGridService.cellWithSuffix(i,e)}onAccept(){this.allocationService.onAcceptance([this.rowData],we.accepted,"activitystatus","resource",Fe.EQUIPMENT,"state","resourcegroup",!0),this.closeDiscardDialog()}updateFooterButton(){let t=this.canViewAcceptance&&this.actionType!==c.ADD&&this.isTimesheetDateGreaterToday&&(this.rowData?.state?.code===Ve.ALLOCATED||this.rowData?.state?.code===Ve.AUTHORIZED_UNACCEPTED),i=[{action:c.CLOSE,style:t?P.SECONDARY:P.PRIMARY,position:x.RIGHT,visible:this.actionType!==c.ADD},{action:c.ACCEPT,style:P.PRIMARY,position:x.RIGHT,visible:t}];this.uiUtilitiesService.updateDrawerFooterButtons(i,this.form)}getStringRender(t){return t!==""?t:Ce}static{this.\u0275fac=(()=>{let t;return function(e){return(t||(t=be(l)))(e||l)}})()}static{this.\u0275cmp=L({type:l,selectors:[["app-equipment-allocated-form"]],features:[k],decls:12,vars:16,consts:[[3,"globalStateCode","subTitle2"],[3,"payDetailsData"],[1,"row","mci-ui-drawer-vertical-top-margin"],[1,"col"],[1,"row"],[1,"mci-ui-card-flat-border","remove-horizontal-margin"],[3,"gridReady","showCheckboxColumn","columnDefinition","gridData","isSliderGrid","showAddButton","showGridDeleteButton","showGridStatusButton","fileName"]],template:function(i,e){i&1&&(I(0,Kt,2,5,"drawer-header-dynamic-content",0),A(1,"equipment-pay-details",1),m(2,"div",2)(3,"div",3)(4,"h6"),re(5),T(6,"mciTranslate"),f()()(),m(7,"div",4)(8,"div",3)(9,"div",5)(10,"app-common-data-grid",6),T(11,"mciTranslate"),v("gridReady",function(r){return e.onGridReady(r)}),f()()()()),i&2&&(O(!(e.rowData==null||e.rowData.state==null)&&e.rowData.state.code?0:-1),u(),h("payDetail
1sData",e.payDetailsData),u(4),Ke(C(6,12,"L.Allocation_Details")),u(5),h("fileName",R(C(11,14,"L.Equipment_Allocation")))("showCheckboxColumn",!1)("columnDefinition",e.columnDefs)("gridData",e.gridData)("isSliderGrid",!0)("showAddButton",!1)("showGridDeleteButton",!1)("showGridStatusButton",!1))},dependencies:[Ne,Rt,N,M,Oe],encapsulation:2})}}return l})();var Ue=De(ye());var Yt=["commentRef"],$t=["jobDetails"],Jt=()=>[];function Qt(l,H){if(l&1&&(A(0,"drawer-header-dynamic-content",3),T(1,"localizedDate")),l&2){let t=E();h("subTitle2",Le("| ",C(1,3,t.rowData==null?null:t.rowData.timesheetdate)))("globalStateCode",t.rowData==null||t.rowData.state==null?null:t.rowData.state.code)}}function Xt(l,H){if(l&1){let t=ae();m(0,"div",21)(1,"div",11)(2,"mci-form-control",22),T(3,"mciTranslate"),v("checkboxChange",function(e){B(t);let a=E();return V(a.noChangesClick(e))}),f()()(),A(4,"hr",13)}if(l&2){let t=E();u(2),h("checkBoxName",R(C(3,7,"L.No_Changes")))("actionType",t.actionType)("displayLabelName",!1)("displayViewField",!1)("form",t.form)("typeOfControl",t.CONTROL_TYPE.CHECKBOX)}}function Zt(l,H){l&1&&(m(0,"mat-panel-description",9)(1,"mat-icon",23),re(2,"fiber_manual_record"),f()())}function ei(l,H){l&1&&(m(0,"mat-panel-description",9)(1,"mat-icon",23),re(2,"fiber_manual_record"),f()())}function ti(l,H){if(l&1){let t=ae();m(0,"mat-expansion-panel",6),v("afterCollapse",function(){B(t);let e=E();return V(e.sections.onCollapse("custom_fields"))}),m(1,"mat-expansion-panel-header",7),v("click",function(){B(t);let e=E();return V(e.sections.onClick("custom_fields"))}),m(2,"mat-panel-title"),A(3,"mci-accordion-panel-title",24),T(4,"mciTranslate"),f(),I(5,ei,3,0,"mat-panel-description",9),f(),m(6,"div",10)(7,"div",11),A(8,"app-dynamic-custom-fields",25),f()()(),A(9,"hr",13)}if(l&2){let t=E();h("expanded",!1),u(3),h("stepNumber",2)("titleLabel",C(4,13,"L.Custom_Fields"))("active",t.sections.isActive("custom_fields"))("done",t.isCustomFieldsDone)("required",t.actionType!==t.ACTIONS.VIEW&&t.hasRequiredCustomFields)("count",t.populatedCustomFieldsCount),u(2),O(t.actionType!==t.ACTIONS.VIEW&&(t.customForm!=null&&t.customForm.touched)&&(t.customForm!=null&&t.customForm.invali
1d)?5:-1),u(3),h("actionType",t.actionType)("customFields",t.customFields)("customFormGroup",t.customForm)("numberOfFieldsPerColumn",2)("showTitle",!1)}}function ii(l,H){l&1&&(m(0,"mat-panel-description",9)(1,"mat-icon",23),re(2,"fiber_manual_record"),f()())}function ai(l,H){if(l&1){let t=ae();m(0,"mat-expansion-panel",6),v("afterCollapse",function(){B(t);let e=E();return V(e.sections.onCollapse("attachments"))}),m(1,"mat-expansion-panel-header",7),v("click",function(){B(t);let e=E();return V(e.sections.onClick("attachments"))}),m(2,"mat-panel-title"),A(3,"mci-accordion-panel-title",18),T(4,"mciTranslate"),f()(),m(5,"div")(6,"div",10)(7,"div",11)(8,"app-upload-attachment",26),v("uploadFilesId",function(e){B(t);let a=E();return V(a.onDownloadFiles(e))}),f()()()()(),A(9,"hr",13)}if(l&2){let t=E();h("expanded",!1),u(3),h("stepNumber",t.attachmentsStepNumber)("titleLabel",C(4,11,"L.Attachments"))("active",t.sections.isActive("attachments"))("done",!!(t.files!=null&&t.files.length))("count",(t.files==null?null:t.files.length)??0),u(5),h("actionType",t.actionType)("files",t.files)("restrictActions",!0)("showDeleteButton",!1)("showTitle",!1)}}var xe=(function(l){return l.hourly="hourly",l.overrate="over",l.rate="rate",l.idle="idle",l.base="base",l.charges="charges",l})(xe||{}),kt=["ordertype","purchaseorder","purchaseorderlines","costelementtype","workorder","networkorder","wbs","costcenter","internalorders","operation","suboperation","activity","element","areaid","glaccount"],Ge=(()=>{class l extends Ie{constructor(){super(...arguments),this.allocationService=g($),this.sections=new Ot(["job_details","custom_fields","allocation_details","attachments","comments"],["job_details","allocation_details"],t=>this.drawerService.showAccordionExpandAllButton(t)),this.locationId="",this.poDefaulting=!1,this.files=[],this.agreementList=[],this.allocationIds=[],this.gridData=[],this.serverGridData=[],this.ALLOCATIONTYPES=X,this.isFromAllocated=!1,this.isRevoked=!1,this.showEditDeleteButtons=!0,this.showEditButton=!0,this.checkboxOptions=[{fieldFormControlName:"isnonbillable",name:this.mciTranslateService.getTranslation("L.Non_Billable")},{fieldFormControlName:"isfixedfee",name:this.mciTranslateService.getTranslation("L.Lump_Sum")},{fieldFormControlName:"issubcontractor",name:this.mciTranslateService.getTranslation("L.Sub_Contractor")}],this.commentTypes=[this.mciTranslateService.getTranslation("L.Rejected_Allocations"),this.mciTranslateService.getTranslation("L.Reject_Allocation"),this.mciTranslateService.getTranslation("L.Void_Timesheets"),this.mciTranslateService.getTranslation("L.Equipment_Allocated_Hours")],this.selectedOrderType={},this.isCurrentAllocatedEditable=t=>(t.data.paytype?.toLocaleLowerCase()===this.chargesTranslated?.toLocaleLowerCase()?!(this.form?.controls?.isnonbillable?.value||this.form?.controls?.isfixedfee?.value||this.form?.controls?.issubcontractor?.value):!0)&&!this.form?.get("nochanges")?.value&&this.actionType!==c.VIEW,this.showZeroRateAlertForEquipment=t=>{let i=t?.data?.paytype?.toLocaleLowerCase(),e=[this.baseTranslated,this.idleTranslated,this.overTranslated].some(a=>a?.toLocaleLowerCase()===i);return(t?.data?.allocated??0)>0&&(t?.data?.rate??0)===0&&e}}getTranslations(){this.entity=this.mciTranslateService.getTranslation("L.Allocation"),this.entityPlural=this.mciTranslateService.getTranslation("L.Allocations"),this.chargesTranslated=this.mciTranslateService.getTranslation("L.Other_Charges"),this.baseTranslated=this.mciTranslateService.getTranslation("L.Base"),this.idleTranslated=this.mciTranslateService.getTranslation("L.Idle"),this.overTranslated=this.mciTranslateService.getTranslation("L.Over")}ngAfterViewInit(){this.drawerService.accordionData({defaultExpand:!0,accordionObj:this.accordion})}get hasRequiredCustomFields(){return this.customFields?.some(t=>t?.isrequired)??!1}get populatedCustomFieldsCount(){return this.customFields?.filter(t=>{let i=this.customForm?.get(t.name)?.value;return i==null||i===""?!1:t.format==="Telephone"?typeof i=="string"?!0:!!i?.internationalNumber:t.format==="Color"?!!i?.id:!0})?.length??0}get isCustomFieldsDone(){return this.customFields?.length?this.hasRequiredCustomFields?this.customForm?.valid??!1:this.populatedCustomFieldsCount>0:!1}get isJobDetailsDone(){return this.form?kt.every(t=>this.form.get(t)?.valid??!0):!1}get hasJobDetailsError(){return kt.some(t=>{let i=this.form?.get(t);return(i?.touched&&i?.invalid)??!1})}get isAttachmentsVisible(){return!!this.files?.length}
1get allocationDetailsStepNumber(){return this.customFields?.length?3:2}get attachmentsStepNumber(){return this.customFields?.length?4:3}get commentsStepNumber(){let t=5;return this.customFields?.length||t--,this.isAttachmentsVisible||t--,t}get isAllocationDetailsDone(){return this.gridData?.some(t=>(t?.allocated??0)>0)??!1}get hasAllocationDetailsError(){return this.actionType!==c.VIEW&&this.formSubmitted&&!this.isAllocationDetailsDone}ngOnInit(){this.mciTranslateService.onLangChange.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(()=>{this.getTranslations(),this.setColumnDefs(),this.gridApi?.refreshHeader()}),this.getTranslations(),this.customForm=this.formBuilder.group({}),this.uiUtilitiesService.site$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{this.locationId=t?.location_id}),this.drawerService.formConfig$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{if(t!=null){let{rowData:i,actionType:e,permissions:a,extraData:r}=t;this.rowData=i,this.actionType=e,this.permissions=a,this.allocationData=r,this.poDefaulting=r?.poDefaulting,this.isFromAllocated=r?.isFromAllocated??!1,this.isRevoked=i?.state?.id===b.REVOKED,this.isFromAllocated===!0&&this.rowData?.state?.id!==b.ALLOCATED&&!this.isRevoked&&(this.showEditDeleteButtons=!1),this.rowData?.isnegativeallocation&&(this.showEditButton=!1),i?.consolidatedattachments?.length&&(i.consolidatedattachments.map(o=>o.name=o.filename),this.files=i.consolidatedattachments),this.setColumnDefs(),this.updateFooterButton(),this.initializeForm();let s=r?.jobDetailsData?.selectedResource?.glaccount;s?.id&&this.form.get("glaccount")?.patchValue(s),this.getEquipmentGridData(r.jobDetailsData.selectedResource),this.rowData&&(this.rowData.customfields=r.jobDetailsData.selectedResource?.customfields),this.loadCustomFields(this.domainTypes.ALLOCATIONS)}}),this.drawerService.drawerFooterAction$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{if(t!=null)switch(t){case this.ACTIONS.CLOSE:case this.ACTIONS.CANCEL:this.onFormClose(!1,!1,!1,j.ASYNC_CONFIRM);break;case this.ACTIONS.EDIT:this.onFormEdit(),this.setHeaderLabels(),this.setColumnDefs(),this.gridApi?.refreshHeader(),this.form.get("isnonbillable").enable(),this.form.get("isfixedfee").enable(),this.form.get("issubcontractor").enable(),this.form.get("nochanges").enable(),this.initializeCheckboxValues();break;case this.ACTIONS.RESUBMIT:case this.ACTIONS.SAVE:this.onSave();break}}),this.allocationService.costObjectsChange$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{t!=null&&this.handleCostObjectChange(t)}),this.drawerService.triggerAccordionExpandOrCollapseAll$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{t!==null&&this.sections.setAll(t)})}setHeaderLabels(){let t=this.uiUtilitiesService.getHeaderLabels(this.actionType,this.entity,this.rowData?.resource?.name,lt,this.rowData?.organization?.name);this.uiUtilitiesService.updateHeaderLabels({customField:"",title:t.title,subtitle:this.rowData?.organization?.name})}setColumnDefs(){this.columnDefs=[this.mciGridService.setZeroRateAlertColumnDef(this.mciTranslateService.getTranslation("M.Zero_Rate_Alert_Hover_Unresolved"),this.showZeroRateAlertForEquipment,!(this.allocationData.jobDetailsData?.locationSettings?.allocation?.zeroratealert??!1)),{field:"paytype",headerName:this.mciTranslateService.getTranslation("L.Pay_Type"),filter:"agTextColumnFilter"},d({field:"available",headerName:this.mciTranslateService.getTranslation("L.Available"),cellRenderer:t=>this.getFormattedHoursCharges(t),valueGetter:t=>this.mathService.roundDisplay(t?.data?.available??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"totalallocated",headerName:this.mciTranslateService.getTranslation("L.Allocated"),cellRenderer:t=>this.getFormattedHoursCharges(t),valueGetter:t=>this.mathService.roundDisplay(t?.data?.totalallocated??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"allocated",headerName:`${this.mciTranslateService.getTranslation("L.Current_Allocated")}`,headerValueGetter:()=>`${this.mciTranslateService.getTranslation("L.Current_Allocated")}${this.actionType===c.EDIT?"*":""}`,editable:this.isCurrentAllocatedEditable,cellClass:t=>this.isCurrentAllocatedEditable(t)?["editable-cell","numeric-column"]:["non-editable-cell","numeric-column"],cellEditor:"materialInputEditor",cellEditorParams:{type:tt.NUMBER},cellRenderer:t=>this.getFormattedHoursCharges(t),valueGetter:t=>this.mathService.roundDisplay(t?.data?.allocated??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"rate",headerName:this.mciTranslateService.getTranslation("L.Rate"),cellRenderer:t=>{let i=this.mathService.formatNumber(t?.value),e=t?.data?.currency?.code;return this.mciGridService.cellWithSuffix(i,e)},valueGetter:t=>this.mathService.roundDisplay(t?.data?.rate??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),{field:"lastediteddate",headerName:this.mciTranslateService.getTranslation("L.Last_Edited"),type:"rightAligned",valueGetter:t=>this.dateTimeService.toLocalizedDateHourMinFormat(t.data.lastediteddate),filter:"agDateColumnFilter",filterParams:{comparator:this.dateTimeService.localizedDateHourMinFilterComparator},comparator:this.dateTimeService.localizedDateHourMinComparator,context:{isAutoSize:!0}},{field:"lasteditedby",headerName:this.mciTranslateService.getTranslation("L.Edited_By")}]}getFormattedHoursCharges(t){let i=this.mathService.formatNumber(t?.value??0),e=this.mciTranslateService.getTranslation("L.Hours_Abbr");return t?.data?.paytype?.toLocaleLowerCase()===this.chargesTranslated.toLocaleLowerCase()&&(e=t?.data?.currency?.code),this.mciGridService.cellWithSuffix(i,e)}updateFooterButton(){let t=[],i=!this.allocationService.validateJobDetailsValues(this.selectedOrderType,this.form),e=this.rowData?.state?.code,a=this.actionType===c.EDIT,r=this.permissions?.canDelete??!1,s=this.permissions?.canEdit??!1,o=[w.ALLOCATED,w.PARTIALLY_ALLOCATED].includes(e),p=[w.REVOKED,w.REJECTED,w.VOIDED].includes(e),S=!o&&!p;t=[{action:c.DELETE,style:P.GHOST_DESTRUCTIVE,position:x.LEFT,visible:!S&&r&&this.showEditDeleteButtons},{action:c.EDIT,style:P.SECONDARY,position:x.RIGHT,visible:!a&&!S&&s&&this.showEditButton&&this.showEditDeleteButtons},{action:c.CANCEL,style:P.SECONDARY,position:x.RIGHT,visible:a&&!S},{action:c.CLOSE,style:P.PRIMARY,position:x.RIGHT,visible:!a||S},{action:c.SAVE,style:P.PRIMARY,position:x.RIGHT,visible:a&&o,useFormDirtyForDisabled:!0,disabled:i},{action:c.RESUBMIT,style:P.PRIMARY,position:x.RIGHT,visible:a&&p,useFormDirtyForDisabled:!0,disabled:i}],setTimeout(()=>{this.uiUtilitiesService.updateDrawerFooterButtons(t,this.form)},100)}selectedOrderTypeEmit(t){this.selectedOrderType=t}initializeForm(){this.form=this.formBuilder.group({timesheetdate:[""],organization:[""],ordertype:[""],costelementtype:[""],areaid:["",$e.required],glaccount:[{value:null,disabled:!0}],isnonbillable:[{value:!1,disabled:this.actionType===c.VIEW||this.actionType===c.EDIT&&!this.allocationData?.nonBillPerms?.edit}],isfixedfee:[{value:!1,disabled:this.actionType===c.VIEW||this.actionType===c.EDIT&&!this.allocationData?.lumpSumPerms?.edit}],issubcontractor:[{value:!1,disabled:this.actionType===c.VIEW||this.actionType===c.EDIT&&!this.allocationData?.subConPerms?.edit}],nochanges:[{value:!1,disabled:this.actionType===c.VIEW}],nocostobject:[{value:!1,disabled:this.actionType===c.VIEW}]}),this.form.get("timesheetdate").setValue(this.rowData?.timesheetdate),this.form.get("organization").setValue(this.rowData?.organization)}onSave(){this.formSubmitted=!0;let t=this.allocationData?.jobDetailsData?.locationSettings?.allocation?.insufficientfundswarning??!1;this.mciFormService.validateAllFormFields(this.form),this.mciFormService.validateAllFormFields(this.customForm),this.jobDetails.validateAgreementForSave([this.allocationData.jobDetailsData.selectedResource]),!this.form.invali
1d&&!this.customForm.invalid?this.saveRejectedEquipment(t):this.onFormHasErrors()}saveRejectedEquipment(t){let i=!0,e=this.prepareRequestObject(t);this.allocationService.upsertResourceDetails(e).subscribe({next:a=>{if(this.closeDiscardDialog(),a?.[0]?.errors?.[0]?.message===Pe&&!a?.[0]?.data?.length){this.notificationBarService.showNotificationMessage(this.mciTranslateService.getTranslation(Pe),""),this.onFormHasErrors();return}a[0].success&&a[0].data?(!a[0]?.data[0]?.issuccess&&a[0]?.data[0]?.moreinfo?.isoverspend?t?(i=!1,this.openInSufficientFundsWarningDialog()):this.modalService.openWarningModal(this.mciTranslateService.getTranslation("M.Cost_Object_Depleted_Message_Singular"),this.mciTranslateService.getTranslation("M.Cost_Object_Depleted_Title_Singular")):this.uiUtilitiesService.showNotificationMessage(this.mciTranslateService.getTranslation("M.Entity_Edited",{entity:this.entity}),""),i&&(this.onFormClose(!0,!1,!1,j.ASYNC_CONFIRM),this.drawerService.requestToReloadTableAfterDrawerAction(!0))):this.onFormHasErrors()},error:()=>{this.closeDiscardDialog(),this.onFormHasErrors()}})}openInSufficientFundsWarningDialog(){let t=this.mciTranslateService.getTranslation("M.Cost_Object_Depleted_Title_Singular"),i=this.mciTranslateService.getTranslation("M.Cost_Object_Depleted_Temporarily_Allocate_Message_Singular"),e=this.mciTranslateService.getTranslation("L.Allocate").toUpperCase(),a=this.mciTranslateService.getTranslation("L.Cancel").toUpperCase();this.modalService.openConfirmationModal(i,t,e,a,!0).afterClosed().subscribe(s=>{s===c.CONFIRM?this.saveRejectedEquipment(!1):this.onFormHasErrors()})}noChangesClick(t){t?(this.form.get("isnonbillable").disable(),this.form.get("isfixedfee").disable(),this.form.get("issubcontractor").disable()):(this.form.get("isnonbillable").enable(),this.form.get("isfixedfee").enable(),this.form.get("issubcontractor").enable()),Object.keys(this.customForm?.controls).forEach(i=>{t?this.customForm.controls[i].disable():this.customForm.controls[i].enable()}),this.setColumnDefs()}onDownloadFiles(t){if(Ue.default.isEmpty(this.locationId)){this.uiUtilitiesService.showNotificationMessage(this.mciTranslateService.getTranslation("L.Select_Location"),"");return}this.fileService.downloadFile(t,this.locationId)}getEquipmentGridData(t){let i=t,e=[];i.rate&&Object.keys(i?.rate).forEach(r=>{let s={paytype:"",available:0,totalallocated:0,allocated:0,rate:0,currency:null,lastediteddate:"",lasteditedby:""},o;r===xe.hourly?(s.paytype=this.baseTranslated,o="baserate"):r===xe.idle?(s.paytype=this.idleTranslated,o="idlerate"):(s.paytype=this.overTranslated,o="overrate");let p=r==="hourly"?"hours":r;s.available=i.available[p]??0,s.totalallocated=i.allocate[p]??0,s.allocated=i.hours[r]??0,s.rate=i?.allocationrates?.[o]??0,s.currency=i.currency,s.lastediteddate=this.rowData?.lastedited?.date,s.lasteditedby=this.rowData?.lastedited?.user,(s.available||s.totalallocated)&&e.push(s)});let a={paytype:this.chargesTranslated,available:i?.available?.othercharges,totalallocated:i?.allocate?.othercharges,allocated:i?.othercharges,rate:0,currency:i.currency,lastediteddate:this.rowData?.lastedited?.date,lasteditedby:this.rowData?.lastedited?.user};(a.available||a.totalallocated)&&e.push(a),this.initializeCheckboxValues(),this.form.controls.issubcontractor?.setValue(this.rowData?.issubcontractor),this.allocationIds=t.allocations?.replaceAll('"',"").split(","),i?.timesheetid&&this.allocationIds.push(i?.timesheetid),this.serverGridData=Ue.default.cloneDeep(e),((this.rowData?.isfixedfee??this.rowData?.islumpsum)||this.rowData?.isnonbillable||this.rowData?.issubcontractor)&&e.forEach(r=>{r.rate=0}),this.gridData=e}initializeCheckboxValues(){let t,i,e;if(this.actionType===c.EDIT){let a=this.allocationService.isCostObjectLumpSum(this.allocationData),r=this.allocationService.isCostObjectNonBillable(this.allocationData),s=this.allocationService.isCostObjectSubContractor(this.allocationData);(a||r||s)&&this.disableCheckboxesAddTooltip(a,r,s),t=this.rowData?.isfixedfee||this.rowData?.islumpsum||a,i=this.rowData?.isnonbillable||r,e=this.rowData?.issubcontractor||s}else t=this.rowData?.isfixedfee||this.rowData?.islumpsum,i=this.rowData?.isnonbillable,e=this.rowData?.issubcontractor;this.form.controls.isnonbillable?.setValue(i),this.form.controls.isfixedfee?.setValue(t),this.form.controls.issubcontractor?.setValue(e)}onCellValueChanged(t){let i=this.serverGridData[t.rowIndex].allocated,e=this.serverGridData[t.rowIndex].totalallocated,a=this.serverGridData[t.rowIndex].available,r=t.newValue;if(t.data.allocated=+t.newValue!=0?+t.newValue:null,r===""||r==="0.00")t.data.availableHours=a+i,t.data.allocatedHours=e-i,this.form.markAsDirty();else{let s=parseFloat(r);if(s>i){let o=s-i;if(o>a){let p,S=this.chargesTranslated.toLocaleLowerCase();t.data?.paytype?.toLocaleLowerCase()===S?p=this.mciTranslateService.getTranslation("M.Cost_Exceed_Available_Cost"):p=this.mciTranslateService.getTranslation("M.Hours_Exceed_Available_Hours"),this.uiUtilitiesService.showNotificationMessage(p),t.data.allocated=i,t.data.available=a,t.data.totalallocated=e}else t.data.available=a-o,t.data.totalallocated=e+o,this.form.markAsDirty()}else{let o=i-s;
1t.data.available=a+o,t.data.totalallocated=e-o,this.form.markAsDirty()}}t.api.refreshCells(),this.form.markAsDirty()}prepareRequestObject(t){return{id:"",classificationname:X.EQUIPMENT,isactive:!0,showinsufficientfundswarning:t,isrejectedallocation:!this.isRevoked,rejectedallocationids:this.isRevoked?[]:this.allocationIds,revokeallocationids:this.isRevoked?this.allocationIds:[],basicinformation:{timesheetdate:this.dateTimeService.toISODateFormat(this.form.controls.timesheetdate?.value),organizationid:this.form.controls.organization?.value?.id},jobdetails:{isnocostobject:!1,temporarycostobjectname:"",ordertypeid:this.form.controls.ordertype?.value?.id,purchaseorderid:this.form.controls.purchaseorderid?.value==="-1"?null:this.form.controls.purchaseorderid?.value,purchaseorderlineid:this.form.controls.purchaseorderlinesid?.value==="-1"?null:this.form.controls.purchaseorderlinesid?.value,costobjecttypekey:this.form.controls.costelementtype?.value?.key,costcenterid:this.form.controls.costcenterid?.value==="-1"?null:this.form.controls.costcenterid?.value,workunitid:this.getWorkUnitId(),operationid:this.getOperationId(),suboperationid:this.getSubOperationId(),wbsid:this.form.controls.wbsid?.value==="-1"?null:this.form.controls.wbsid?.value,areaid:this.form.controls.areaid?.value?.id,glaccountid:this.form.controls.glaccount?.value?.id??null},customfields:this.getCustomFieldsPayload(),equipmentresourceallocations:this.getEquipmentAllocations()}}getEquipmentAllocations(){let t=[],i={agreement:{},resource:{},group:{},type:{},summary:{},attachmentmetadata:[],allocated:[],othercharges:0,isfixedfee:!1,isnonbillable:!1,issubcontractor:!1,isPartialAllocation:!1};if(i.resource.id=this.rowData?.resource?.id,i.agreement.id=this.rowData?.agreement?.id,i.group.id=this.rowData?.resourcegroup?.id,i.type.id=this.rowData?.type?.id,i.summary.id=this.rowData?.activity?.rasid??null,i.isfixedfee=this.form.controls?.isfixedfee.value??!1,i.isnonbillable=this.form.controls?.isnonbillable.value??!1,i.issubcontractor=this.form.controls?.issubcontractor.value??!1,i.isPartialAllocation=this.checkPartialAllocations(),this.gridData.forEach(e=>{let a={type:"",hours:null,rate:null};a.type=this.getPayTypeString(e.paytype),a.hours=e.allocated!=null&&e.allocated!==""?+e.allocated:null,a.rate=e.rate!=null?+e.rate:null,i.allocated.push(a)}),this.rowData?.attachments){let e=[],a=JSON.parse(this.rowData?.attachments);for(let r of a){let s={id:r?.id,filename:r?.filename,sizebytes:r?.sizebytes,datetime:r?.datetime,type:r?.type};e.push(s)}i.attachmentmetadata=e}return t.push(i),t}getPayTypeString(t){let i;switch(t?.toLocaleLowerCase()){case this.baseTranslated.toLocaleLowerCase():i="hours";break;case this.idleTranslated.toLocaleLowerCase():i="idle";break;case this.overTranslated.toLocaleLowerCase():i="overrate";break;case this.chargesTranslated.toLocaleLowerCase():i="othercharges";break;default:break}return i}checkPartialAllocations(){return!!this.gridData.some(i=>i.available>0)}getWorkUnitId(){switch(this.form.get("costelementtype")?.value?.key){case K.WORKORDER:return this.form.controls.workorderid?.value==="-1"?null:this.form.controls.workorderid?.value;case K.NETWORKORDER:return this.form.controls.networkorderid?.value==="-1"?null:this.form.controls.networkorderid?.value;case K.INTERNALORDER:return this.form.controls.internalordersid?.value==="-1"?null:this.form.controls.internalordersid?.value;default:return null}}getOperationId(){return this.form.get("costelementtype")?.value?.key===K.WORKORDER&&this.form.controls.operationid?.value!=="-1"?this.form.controls.operationid?.value??null:this.form.get("costelementtype")?.value?.key===K.NETWORKORDER&&this.form.controls.activityid?.value!=="-1"?this.form.controls.activityid?.value??null:null}getSubOperationId(){return this.form.get("costelementtype")?.value?.key===K.WORKORDER&&this.form.controls.suboperationid?.value!=="-1"?this.form.controls.suboperationid?.value??null:this.form.get("costelementtype")?.value?.key===K.NETWORKORDER&&this.form.controls.elementid?.value!=="-1"?this.form.controls.elementid?.value??null:null}checkboxChangeEvent(t){this.maintainCheckboxState(t);let i=this.form.get("isfixedfee")?.value??!1,e=this.form.get("isnonbillable")?.value??!1,a=this.form.get("issubcontractor")?.value??!1;i||e||a?this.gridData.forEach(r=>{r.rate=0,r.paytype.toLowerCase()===this.chargesTranslated.toLowerCase()&&(r.allocated=0,r.available=0)}):this.gridData.forEach((r,s)=>{r.rate=this.serverGridData[s]?.rate,r.paytype.toLowerCase()===this.chargesTranslated.toLowerCase()&&(r.available=this.serverGridData[s]?.available,r.allocated=this.serverGridData[s]?.allocated)}),this.gridApi?.refreshCells()}maintainCheckboxState(t){let i=t?.source?.id;
1t?.checked&&this.checkboxOptions.forEach(e=>{e?.fieldFormControlName!==i&&this.form.get(e?.fieldFormControlName).setValue(!1)})}disableCheckboxesAddTooltip(t,i,e=!1){if(this.form.controls.isnonbillable.disable(),this.form.controls.isfixedfee.disable(),this.form.controls.issubcontractor.disable(),t){let a=this.checkboxOptions.find(r=>r.fieldFormControlName==="isfixedfee");a.tooltip=this.mciTranslateService.getTranslation("M.Selected_Cost_Object_Lump_Sum")}else if(i){let a=this.checkboxOptions.find(r=>r.fieldFormControlName==="isnonbillable");a.tooltip=this.mciTranslateService.getTranslation("M.Selected_Cost_Object_Non_Billable")}else if(e){let a=this.checkboxOptions.find(r=>r.fieldFormControlName==="issubcontractor");a.tooltip=this.mciTranslateService.getTranslation("M.Selected_Cost_Object_Sub_Contractor")}}handleCostObjectChange(t){let i=t.fixfee||t.nonbillable||t.subcontractor;this.form.get("isfixedfee")?.setValue(t.fixfee),this.form.get("isnonbillable")?.setValue(t.nonbillable),this.form.get("issubcontractor")?.setValue(t.subcontractor),i?(this.disableCheckboxesAddTooltip(t.fixfee,t.nonbillable,t.subcontractor),this.gridData.forEach(e=>{e.rate=0,e.paytype.toLowerCase()===this.chargesTranslated.toLowerCase()&&(e.allocated=0,e.available=0)})):(this.form.controls.isnonbillable.enable(),this.form.controls.isfixedfee.enable(),this.form.controls.issubcontractor.enable(),this.checkboxOptions.forEach(e=>{e.tooltip=""}),this.gridData.forEach((e,a)=>{e.rate=this.serverGridData[a]?.rate,e.paytype.toLowerCase()===this.chargesTranslated.toLowerCase()&&(e.available=this.serverGridData[a]?.available,e.allocated=this.serverGridData[a]?.allocated)})),this.gridApi?.refreshCells()}static{this.\u0275fac=(()=>{let t;return function(e){return(t||(t=be(l)))(e||l)}})()}static{this.\u0275cmp=L({type:l,selectors:[["app-equipment-unresolved-form"]],viewQuery:function(i,e){if(i&1&&He(Be,5)(Yt,5)($t,5),i&2){let a;Ee(a=_e())&&(e.accordion=a.first),Ee(a=_e())&&(e.commentRef=a.first),Ee(a=_e())&&(e.jobDetails=a.first)}},hostAttrs:[2,"display","block"],features:[k],decls:43,vars:63,consts:[["accordion","matAccordion"],["jobDetails",""],["commentRef",""],[3,"globalStateCode","subTitle2"],["autocomplete","off",3,"formGroup"],[1,"mci-ui-accordion","custom-panel-body","accordion-drawer","accordion-drawer-spacing",3,"multi"],[3,"afterCollapse","expanded"],[3,"click"],[3,"stepNumber","titleLabel","active","done","required"],[1,"mci-expansion-panel-header-error-description"],[1,"row"],[1,"col"],[3,"updateFooterButton","selectedOrderTypeEmit","actionType","classification","form","isFullscreen","jobDetailsData","rowData"],[1,"mci-ui-divider"],[1,"mci-ui-card-flat-border","remove-horizontal-margin"],[3,"cellEdit","gridReady","showCheckboxColumn","columnDefinition","gridData","isSliderGrid","pageSize","showAddButton","showPaginator","fileName"],[1,"row","mci-ui-drawer-vertical-top-margin"],[3,"checkboxChangeEvent","actionType","checkboxOptions","displayLabelName","displayViewField","form","typeOfControl"],[3,"stepNumber","titleLabel","active","done","count"],[1,"mci-ui-drawer-vertical-top-margin"],["entityName","allocationIds",3,"actionType","getCommentTypes","ids","saveCommentType"],[1,"row","mci-ui-no-changes-cb"],["fieldFormControlName","nochanges",3,"checkboxChange","actionType","displayLabelName","displayViewField","form","typeOfControl","checkBoxName"],[1,"error-icon"],[3,"stepNumber","titleLabel","active","done","required","count"],[3,"actionType","customFields","customFormGroup","numberOfFieldsPerColumn","showTitle"],[3,"uploadFilesId","actionType","files","restrictActions","showDeleteButton","showTitle"]],template:function(i,e){if(i&1&&(I(0,Qt,2,5,"drawer-header-dynamic-content",3),m(1,"form",4),I(2,Xt,5,9),m(3,"mat-accordion",5,0)(5,"mat-expansion-panel",6),v("afterCollapse",function(){return e.sections.onCollapse("job_details")}),m(6,"mat-expansion-panel-header",7),v("click",function(){return e.sections.onClick("job_details")}),m(7,"mat-panel-title"),A(8,"mci-accordion-panel-title",8),T(9,"mciTranslate"),f(),I(10,Zt,3,0,"mat-panel-description",9),f(),m(11,"div",10)(12,"div",11)(13,"app-job-details",12,1),v("updateFooterButton",function(){return e.updateFooterButton()})("selectedOrderTypeEmit",function(r){return e.selectedOrderTypeEmit(r)}),f()()()(),A(15,"hr",13),I(16,ti,10,15),m(17,"mat-expansion-panel",6),v("afterCollapse",function(){return e.sections.onCollapse("allocation_details")}),m(18,"mat-expansion-panel-header",7),v("click",function(){return e.sections.onClick("allocation_details")}),m(19,"mat-panel-title"),A(20,"mci-accordion-panel-title",8),T(21,"mciTranslate"),f(),I(22,ii,3,0,"mat-panel-description",9),f(),m(23,"div",10)(24,"div",11)(25,"div",14)(26,"app-common-data-grid",15),T(27,"mciTranslate"),v("cellEdit",function(r){return e.onCellValueChanged(r)})("gridReady",function(r){return e.onGridReady(r)}
1),f()()()(),m(28,"div",16)(29,"div",11)(30,"mci-form-control",17),v("checkboxChangeEvent",function(r){return e.checkboxChangeEvent(r)}),f()()()(),A(31,"hr",13),I(32,ai,10,13),m(33,"mat-expansion-panel",6),v("afterCollapse",function(){return e.sections.onCollapse("comments")}),m(34,"mat-expansion-panel-header",7),v("click",function(){return e.sections.onClick("comments")}),m(35,"mat-panel-title"),A(36,"mci-accordion-panel-title",18),T(37,"mciTranslate"),f()(),m(38,"div",19),A(39,"app-comments",20,2),T(41,"mciTranslate"),f()(),A(42,"hr",13),f()()),i&2){let a=We(40);O(!(e.rowData==null||e.rowData.state==null)&&e.rowData.state.code?0:-1),u(),h("formGroup",e.form),u(),O(!e.isFromAllocated&&!e.isRevoked?2:-1),u(),h("multi",!0),u(2),h("expanded",!0),u(3),h("stepNumber",1)("titleLabel",C(9,52,"L.Job_Details"))("active",e.sections.isActive("job_details"))("done",e.isJobDetailsDone)("required",e.actionType!==e.ACTIONS.VIEW),u(2),O(e.actionType!==e.ACTIONS.VIEW&&e.hasJobDetailsError?10:-1),u(3),h("actionType",e.actionType)("classification",e.ALLOCATIONTYPES.EQUIPMENT)("form",e.form)("isFullscreen",!1)("jobDetailsData",e.allocationData.jobDetailsData)("rowData",e.rowData),u(3),O(e.customFields!=null&&e.customFields.length?16:-1),u(),h("expanded",!0),u(3),h("stepNumber",e.allocationDetailsStepNumber)("titleLabel",C(21,54,"L.Hours"))("active",e.sections.isActive("allocation_details"))("done",e.isAllocationDetailsDone)("required",e.actionType!==e.ACTIONS.VIEW),u(2),O(e.actionType!==e.ACTIONS.VIEW&&e.hasAllocationDetailsError?22:-1),u(4),h("fileName",R(C(27,56,"L.Equipment_Allocated_Hours")))("showCheckboxColumn",!1)("columnDefinition",e.columnDefs)("gridData",e.gridData)("isSliderGrid",!0)("pageSize",20)("showAddButton",!1)("showPaginator",!1),u(4),h("actionType",e.actionType)("checkboxOptions",e.checkboxOptions)("displayLabelName",!1)("displayViewField",!1)("form",e.form)("typeOfControl",e.CONTROL_TYPE.CHECKBOX),u(2),O(e.isAttachmentsVisible?32:-1),u(),h("expanded",!1),u(3),h("stepNumber",e.commentsStepNumber)("titleLabel",C(37,58,"L.Comments"))("active",e.sections.isActive("comments"))("done",!!(!(a==null||a.showComments==null)&&a.showComments.length))("count",(a==null||a.showComments==null?null:a.showComments.length)??0),u(3),h("saveCommentType",R(C(41,60,"L.Equipment_Allocated_Hours")))("actionType",e.actionType)("getCommentTypes",e.commentTypes)("ids",e.allocationIds??Ye(62,Jt))}},dependencies:[Ne,Ze,Qe,Je,Xe,pt,Be,Ct,At,bt,yt,dt,Et,Lt,N,ft,_t,Nt,M,Oe],encapsulation:2})}}return l})();var qe=De(ye());var Ut=(()=>{class l extends pe{constructor(){super(),this.equipmentAllocationService=g(J),this.equipmentActivityService=g(Se),this.masterDataService=g(fe),this.personalInformationService=g(me),this.allocationManagementService=g($),this.orgFilterRequestId=0,this.organizationsFilterList=[],this.agreementsFilterList=[],this.groupsFilterList=[],this.typesFilterList=[],this.uniqueIdsFilterList=[],this.equipmentAssociatedDataByOrg=[],this.equipmentAssociatedDataByAgreement=[],this.equipmentAssociatedDataByGroup=[],this.locationList=[],this.defaultTimeSheetDate=null,this.canViewAcceptance=!1,this.defaultDateRange={id:U.Yesterday},this.showGridDeleteButton=!1,this.showGridAcceptButton=!1,this.isLoadingAcceptButton=!1,this.gridHeight=he,this.gridAggregationSummary=ze(null),this.clickEvents=new Me,this.allExpanded=!1,this.totalRowsSelected=0,this.allowEquipmentFutureDates=!0,this.canViewGLAccount=!1,this.LAST_EDITED_COLUMN_FIELD="lastEdited.date",this.getAgreements=t=>q(this,null,function*(){let i=this.filtersForm?.controls?.organization?.value?.id,e=i?[i]:[];try{let a=yield te(this.commonService.getActiveAgreements(e,[this.defaultLocation]));if(a[0]?.success&&a[0]?.data){let r=this.uiUtilitiesService.getDistinctObjectList(a[0].data);return t||(this.agreementsFilterList=r,this.filterDefinitions[3].inputValues=r,this.filterDefinitions[3].totalRecords=r.length),r}return[]}catch(a){return[]}}),this.getOrganizations=t=>q(this,null,function*(){let i=yield this.commonService.getFilteredOrganizations(t,[this.defaultLocation],["id","name","isactive"]);return t||(this.organizationsFilterList=i.data,this.filterDefinitions[1].inputValues=this.organizationsFilterList,this.filterDefinitions[1].totalRecords=i?.totalcount??0,!this.filtersForm.controls.organization.value&&this.organizationsFilterList?.length>0&&this.filtersForm.controls.organization.setValue(this.organizationsFilterList[0]),this.filterSectionService.updateAppliedFilterIndicator$.next(null),i.data?.length>0&&this.getAgreementsByOrganization(this.filtersForm.controls.organization.value?.id),this.getEquipmentAssociatedData(),this.reloadGridData()),i?.data??[]}),this.uiUtilitiesService.allocationsTabName=X.EQUIPMENT,this.setupFilterAfterInitObservable(this.onFiltersInitialized.bind(this))}ngOnInit(){this.listingPageGridKey="equipmentAllocatedListing",this.uiUtilitiesService.site$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{qe.default.isEmpty(t)||this.loadLocationSettings(t.location_id)}),this.gridInitialize(),this.mciTranslateService.onLangChange.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(()=>{this.gridInitialize(),this.getTranslations(),this.setColumnDefs(),this.gridApi?.refreshHeader()}),this.getTranslations(),this.initializeFilterSection(),this.initializeGrid(D.ALLOCATIONS_FOR_EQUIPMENT),this.filterSectionService.applyFilters$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>this.onApplyFilters(t)),this.filterSectionService.resetFilters$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>this.onResetFilters(t)),this.context={componentParent:this},this.drawerService.reloadTableAfterDrawerAction$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{t!=null&&t===!0&&this.reloadGridData()}),this.drawerService.drawerFooterAction$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{t===c.DELETE&&this.openDeleteDialog([this.selectedRowData])}),this.allocationManagementService.allocationToAcceptChange$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{t.success&&(this.reloadGridData(),this.deselectRows()),this.isLoadingAcceptButton=!1})}loadLocationSettings(t){this.settingsService.getLocationSettings(t).subscribe(i=>{if(i[0].success){let e=i[0].data;
1this.allowEquipmentFutureDates=e?.settings?.acceptance?.allowequipmentfuturedates??!0}})}getTranslations(){this.entity=this.mciTranslateService.getTranslation("L.Allocation"),this.entityPlural=this.mciTranslateService.getTranslation("L.Allocations"),this.addDrawerTitle=this.mciTranslateService.getTranslation("L.Add_Allocations_Title"),this.addDrawerSubtitle=this.mciTranslateService.getTranslation("L.Add_Allocations_Subtitle")}gridInitialize(){this.detailGrid=Bt,this.detailGridParams={clickEvents:this.clickEvents.asObservable(),showCheckBoxForChild:!0,childrenSelected:()=>this.parentRowsSelected(),resourceClicked:(t,i)=>this.resourceClicked(t,i),getPermissions:()=>this.permissions,getCanViewGLAccount:()=>this.canViewGLAccount}}parentRowsSelected(){return q(this,null,function*(){this.totalRowsSelected=0;let t=0;this.gridApi?.forEachNode(i=>{if(!i.isSelected()&&i.data.rowsSelected)i.data.equipmentChildRowsSelected=[],i.data.rowsSelected=0,this.clickEvents.next();else if(i.isSelected()&&i.data.rowsSelected)this.totalRowsSelected+=i.data.rowsSelected;else if(i.isSelected()&&!i.data.rowsSelected){let e=i.data?.childData;e?.length>0&&(i.data.equipmentChildRowsSelected=e||[]),i.data.rowsSelected=i.data.equipmentChildRowsSelected?.length,this.totalRowsSelected+=i.data.rowsSelected,this.clickEvents.next()}t+=i.data.equipmentChildRowsSelected?.length??0}),this.showDeleteButtonOnSelection(),this.gridApi?.refreshCells(),this.gridAggregationSummary.update(i=>i&&ee(d({},i),{selected:t}))})}resourceClicked(t,i){this.contentMenuClick(t,i)}isRejectedOrVoidState(){return this.selectedRowData?.state?.id===b.REJECTED||this.selectedRowData?.state?.id===b.VOIDED}rowHeight(t){if(!t.node.detail)return;let e=t.data?.childData?.length,r=1*141;return e*40+r+24}reloadGridData(t=!1){t&&setTimeout(()=>{this.skeletonLoadingService.startGridSkeletonLoading()},0);let i=this.getRequestPayload();this.equipmentAllocationService.getAllocatedEquipments(i).subscribe({next:e=>{this.checkIfDataIsRestricted(e),e&&e[0].data?this.groupByUniqueID(e[0].data):this.onAPIError()},error:()=>{this.onAPIError()}})}groupByUniqueID(t){let i=[],e=this.groupBy(t,a=>[a.resource?.id,a.workdate,a.activity?.rasid??a.agreement?.id??""]);e&&e.forEach(a=>{let r={};a.forEach(n=>{n.state=n.allocationstate}),r.childData=a,r.state=a[0].activitystatus,r.workdate=a[0].workdate,r.organization=a[0].organization,r.resourcegroup=a[0].resourcegroup,r.type=a[0].type,r.resource=a[0].resource,r.agreement=a[0].agreement,r.activity=a[0].activity,r.currency=a[0].currency,r.exceptions=this.exceptionIconService.mergeExceptionObjectsForParentRow(a?.map(n=>n?.exceptions)),a.forEach(n=>{let y=n.timesheetreference?.replace(/ /g,"").split(",")??[];y.length>1&&(n.timesheetreference=Array.from(new Set(y)).join(","))}),a.forEach(n=>{let y=n.revoketimesheetref?.replace(/ /g,"").split(",")??[];y.length>1&&(n.revoketimesheetref=Array.from(new Set(y)).join(","))}),r.timesheetreference=Array.from(new Set(a?.map(n=>n?.timesheetreference)))?.filter(n=>n),r.revoketimesheetref=Array.from(new Set(a?.map(n=>n?.revoketimesheetref)))?.filter(n=>n),r.ordertype=Array.from(new Set(a.map(n=>this.uiUtilitiesService.getOrderTypeTranslation(n.costobject?.ordertype?.name))))?.filter(n=>n),r.purchaseorder=Array.from(new Set(a.map(n=>n.costobject?.purchaseorder?.name)))?.filter(n=>n),r.poline=Array.from(new Set(a.map(n=>n.costobject?.purchaseorderline?.name)))?.filter(n=>n),r.costobjecttype=Array.from(new Set(a.map(n=>n.costobject?.labelname)))?.filter(n=>n),r.costobjectname=Array.from(new Set(a.map(n=>n.costobject?.name)))?.filter(n=>n),r.operation=Array.from(new Set(a.map(n=>n.costobject?.operation?.name)))?.filter(n=>n),r.suboperation=Array.from(new Set(a.map(n=>n.costobject?.suboperation?.name)))?.filter(n=>n),r.areaid=Array.from(new Set(a.map(n=>n.area?.name)))?.filter(n=>n);let o=a.some(n=>n.state?.id===b.REVOKED)?a.filter(n=>!n.isnegativeallocation):a;r.base=+o.reduce((n,y)=>n+(y.allocated?.hours?.hourly??0),0),r.over=+o.reduce((n,y)=>n+(y.allocated?.hours?.overrate??0),0),r.idle=+o.reduce((n,y)=>n+(y.allocated?.hours?.idle??0),0),r.totalOtherCharge=+o.reduce((n,y)=>n+(y.allocated?.othercharges??0),0),r.totalHours=+o.reduce((n,y)=>n+(y.allocated?.hours?.total??0),0),r.nethours=a[0]?.nethours;let p=a[0]?.activity?.totalHours??0,S=a[0]?.activity?.totalcharges??0;r.hoursAllocated=p>0?r.totalHours/p*100:0,r.otherChargesAllocated=S>0?r.totalOtherCharge/S*100:0,r.lastEdited=a[0]?.lastedited,r.weeklystartdate=a[0]?.weeklystartdate,r.weeklycumulativehours=a[0]?.weeklycumulativehours,r.monthlystartdate=a[0]?.monthlystartdate,r.monthlycumulativebase=a[0]?.monthlycumulativebase,r.baseHrs=a[0]?.activityhourdetails?.BaseHrs>0?a[0]?.activityhourdetails?.BaseHrs:0,r.overHrs=a[0]?.activityhourdetails?.OverHrs>0?a[0]?.activityhourdetails?.OverHrs:0,r.idleHrs=a[0]?.activityhourdetails?.IdleHrs>0?a[0]?.activityhourdetails?.IdleHrs:0,r.otherAllowableCharge=a[0].activity?.totalcharges>0?a[0].activity?.totalcharges:0,a?.length>1&&a.forEach(n=>
1{new Date(r.lastEdited.date)<new Date(n.lastedited.date)&&(r.lastEdited=n.lastedited)});let F=a.find(n=>!!n.timesheetid)?.timesheetid||null;a.forEach(n=>{n.timesheetid=F}),r.timesheetId=F,r.consolidatedattachments=a[0].consolidatedattachments,r.totalFiles=a[0].totalFiles,r.preapproval=a[0].preapproval,r.glaccount=Array.from(new Set(a.map(n=>n.glaccount?.name)))?.filter(n=>n),i.push(r)}),i.sort((a,r)=>{let s=a?.lastEdited?.date?new Date(a.lastEdited.date).getTime():NaN,o=r?.lastEdited?.date?new Date(r.lastEdited.date).getTime():NaN,p=isNaN(s)?-1/0:s;return(isNaN(o)?-1/0:o)-p}),i.forEach((a,r)=>a.id=`${r+1}`),this.gridApi?.setGridOption("rowData",[]),this.gridApi?.setGridOption("rowData",i),this.gridData=i,this.gridAggregationSummary.set({display:!0,shown:0,selected:0,total:i.reduce((a,r)=>a+(r.childData?.length??0),0),entityType:this.entityPlural,entityTypeSingular:this.entity,parentCount:i.length,parentType:this.mciTranslateService.getTranslation("L.Activities"),parentTypeSingular:this.mciTranslateService.getTranslation("L.Activity")})}groupBy(t,i){let e={};return t.forEach(a=>{let r=JSON.stringify(i(a));e[r]=e[r]||[],a.consolidatedattachments=this.uiUtilitiesService.formatStringWithMultipleArray(a.consolidatedattachments),a.totalFiles=a?.consolidatedattachments?.length??0,e[r].push(a)}),Object.keys(e).map(a=>e[a])}getRequestPayload(){if(!this.filtersForm)return null;let t=this.filtersForm.controls.organization?.value?.id??null,i=this.dateTimeService.getDateRangeFromDateShortcut(this.filtersForm,"timesheetDate");return{statecodes:this.filtersForm.controls.state?.value?.map(e=>e?.id)??[],organizationids:t!=null?[t]:[],agreementids:this.filtersForm.controls.agreement?.value?.map(e=>e?.id)??[],groupids:this.filtersForm.controls.group?.value?.map(e=>e?.id)??[],typeids:this.filtersForm.controls.type?.value?.map(e=>e?.id)??[],uniqueids:this.filtersForm.controls.uniqueId?.value?.map(e=>e?.id)??[],startdate:i.startDate,enddate:i.endDate.substring(0,10)}}initializeGrid(t){W({allocationPermissions:this.commonService.getScreenNamePermissions(t),acceptancePermissions:this.commonService.getScreenNamePermissions(D.ACCEPTANCE),lumpSumPerms:this.commonService.getScreenNamePermissions(D.LUMP_SUM),nonBillPerms:this.commonService.getScreenNamePermissions(D.NON_BILLABLE),subConPerms:this.commonService.getScreenNamePermissions(D.SUB_CONTRACTOR),glAccountAllocationsPermissions:this.commonService.getScreenNamePermissions(D.GL_ACCOUNT_ALLOCATIONS)}).subscribe(({allocationPermissions:i,acceptancePermissions:e,nonBillPerms:a,lumpSumPerms:r,subConPerms:s,glAccountAllocationsPermissions:o})=>{this.permissions.canAssign=e[0]?.data?.assign,this.permissions.canUnassign=e[0]?.data?.unassign,this.canViewAcceptance=e[0]?.data?.assign&&this.permissions?.canAssign,this.lumpSumPerms=r[0]?.data,this.nonBillPerms=a[0]?.data,this.subConPerms=s[0]?.data,o[0]?.data?.view&&(this.canViewGLAccount=o[0].data.view),i[0].data.assign=this.permissions?.canAssign,i[0].data.unassign=this.permissions?.canUnassign,this.setPermissionsAndConfigureGrid(i[0]?.data)})}configurePopupOptions(){let t=[{action:c.VIEW,canAct:this.permissions?.canView},{action:c.ACCEPT,canAct:this.canViewAcceptance}];this.popupOptions=t.filter(i=>i.canAct).map(i=>i.action)}setColumnDefs(){let t=[{headerComponent:It,headerComponentParams:{allExpanded:!this.allExpanded,onChange:()=>this.expandRows()},sortable:!0,field:"REC",headerName:"",pinned:"left",lockPinned:!0,lockPosition:!0,cellRenderer:"agGroupCellRenderer",valueGetter:()=>"",maxWidth:50,resizable:!1,filter:!1,suppressMovable:!0,suppressColumnsToolPanel:!0},{headerName:_.CONTEXTMENU,cellRenderer:"materialGridMenu",cellRendererParams:{menuEvent:({type:e,value:a})=>this.contentMenuParentClick(e,a),buttons:this.popupOptions,filterButtons:(e,a)=>{let r=e?.state?.id,s=e?.workdate?new Date(e.workdate):null,o=new Date,p=s&&(s<=o||s>o&&this.allowEquipmentFutureDates),S=r===Te.ALLOCATED||r===Te.AUTHORIZED_UNACCEPTED,F=!e?.exceptions?.isbadgeerror;return!this.canViewAcceptance||!S||!p||!F?a.filter(n=>n!==c.ACCEPT):a}}}],i=[{headerName:this.mciTranslateService.getTranslation(_.EXCEPTION),field:"exceptions",cellRenderer:"exceptionIconCell",context:{excludeExcelExport:!1,isAutoSize:!0},cellRendererParams:e=>({iconClickEvent:a=>
1{this.onExceptionIconClick(a,e.data)}})},{field:"state",headerName:this.mciTranslateService.getTranslation("L.State"),cellRenderer:"globalStatesCellRenderer"},{field:"workdate",headerName:this.mciTranslateService.getTranslation("L.Timesheet_Date"),type:"rightAligned",filter:"agDateColumnFilter",valueGetter:e=>this.dateTimeService.toLocalizedDateFormat(e.data.workdate),filterParams:{comparator:this.dateTimeService.localizedDateFilterComparator},comparator:this.dateTimeService.localizedDateComparator,context:{isAutoSize:!0}},{field:"organization.name",headerName:this.mciTranslateService.getTranslation("L.Organization")},{field:"resourcegroup.name",headerName:this.mciTranslateService.getTranslation("L.Group")},{field:"type.name",headerName:this.mciTranslateService.getTranslation("L.Type")},{field:"resource.name",headerName:this.mciTranslateService.getTranslation("L.Unique_ID"),context:{isAutoSize:!0}},{field:"agreement.name",headerName:this.mciTranslateService.getTranslation("L.Agreement"),context:{isAutoSize:!0}},{field:"ordertype",headerName:this.mciTranslateService.getTranslation("L.Order_Type"),filter:"agTextColumnFilter",comparator:this.compareService.compareNamesArrayWithoutName,filterValueGetter:e=>this.getColumnFilterValueGetter(e.data.ordertype),tooltipComponentParams:{customValueCb:e=>e.value?.join(", ")}},{field:"purchaseorder",headerName:this.mciTranslateService.getTranslation("L.Purchase_Order"),filter:"agTextColumnFilter",comparator:this.compareService.compareNamesArrayWithoutName,filterValueGetter:e=>this.getColumnFilterValueGetter(e.data.purchaseorder),tooltipComponentParams:{customValueCb:e=>e.value?.join(", ")}},{field:"poline",headerName:this.mciTranslateService.getTranslation("L.PO_Line"),filter:"agTextColumnFilter",comparator:this.compareService.compareNamesArrayWithoutName,filterValueGetter:e=>this.getColumnFilterValueGetter(e.data.poline),tooltipComponentParams:{customValueCb:e=>e.value?.join(", ")}},{field:"costobjecttype",headerName:this.mciTranslateService.getTranslation("L.Cost_Object_Type"),filter:"agTextColumnFilter",comparator:this.compareService.compareNamesArrayWithoutName,filterValueGetter:e=>this.getColumnFilterValueGetter(e.data.costobjecttype),tooltipComponentParams:{customValueCb:e=>e.value?.join(", ")}},{field:"costobjectname",headerName:this.mciTranslateService.getTranslation("L.Cost_Object"),filter:"agTextColumnFilter",comparator:this.compareService.compareNamesArrayWithoutName,filterValueGetter:e=>this.getColumnFilterValueGetter(e.data.costobjectname),tooltipComponentParams:{customValueCb:e=>e.value?.join(", ")}},{field:"operation",headerName:this.mciTranslateService.getTranslation("L.Operation_Or_Activity"),filter:"agTextColumnFilter",comparator:this.compareService.compareNamesArrayWithoutName,filterValueGetter:e=>this.getColumnFilterValueGetter(e.data.operation),tooltipComponentParams:{customValueCb:e=>e.value?.join(", ")}},{field:"suboperation",headerName:this.mciTranslateService.getTranslation("L.Sub_Operation_Or_Element"),filter:"agTextColumnFilter",comparator:this.compareService.compareNamesArrayWithoutName,filterValueGetter:e=>this.getColumnFilterValueGetter(e.data.suboperation),tooltipComponentParams:{customValueCb:e=>e.value?.join(", ")}},{field:"areaid",headerName:this.mciTranslateService.getTranslation("L.Area_ID"),filter:"agTextColumnFilter",comparator:this.compareService.compareNamesArrayWithoutName,filterValueGetter:e=>this.getColumnFilterValueGetter(e.data.areaid),tooltipComponentParams:{customValueCb:e=>e.value?.join(", ")},context:{isAutoSize:!0}},{field:"glaccount",headerName:this.mciTranslateService.getTranslation("L.GL_Account"),filter:"agTextColumnFilter",comparator:this.compareService.compareNamesArrayWithoutName,filterValueGetter:e=>this.getColumnFilterValueGetter(e.data.glaccount),cellRenderer:"materialToolTip",cellRendererParams:{showDash:!0},hide:!this.canViewGLAccount},d({field:"base",headerName:this.mciTranslateService.getTranslation("L.Base"),cellRenderer:e=>this.getCellRenderValue(e),valueGetter:e=>this.mathService.roundDisplay(e?.data?.base??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"over",headerName:this.mciTranslateService.getTranslation("L.Over"),cellRenderer:e=>this.getCellRenderValue(e),valueGetter:e=>this.mathService.roundDisplay(e?.data?.over??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"idle",headerName:this.mciTranslateService.getTranslation("L.Idle"),cellRenderer:e=>this.getCellRenderValue(e),valueGetter:e=>this.mathService.roundDisplay(e?.data?.idle??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"totalOtherCharge",headerName:this.mciTranslateService.getTranslation("L.Other_Charge"),cellRenderer:e=>{let a=this.mathService.formatNumber(e?.value),r=e?.data?.currency?.code;return this.mciGridService.cellWithSuffix(a,r)},valueGetter:e=>this.mathService.roundDisplay(e?.data?.totalOtherCharge??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"hoursAllocated",headerName:this.mciTranslateService.getTranslation("L.Hours_Allocated_Percentage"),cellRenderer:e=>this.getCellRenderValue(e,!0),valueGetter:e=>this.mathService.roundDisplay(e?.data?.hoursAllocated??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"otherChargesAllocated",headerName:this.mciTranslateService.getTranslation("L.Other_Charges_Allocated"),cellRenderer:e=>this.getCellRenderValue(e,!0),valueGetter:e=>this.mathService.roundDisplay(e?.data?.otherChargesAllocated??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),{headerName:this.mciTranslateService.getTranslation("L.Attachment"),cellRenderer:"materialGridIcon",headerClass:"ag-center-aligned-header",cellClass:"ag-center-aligned-cell",field:"attachmentsCount",filter:"agNumberColumnFilter",editable:!1,
1cellRendererParams:e=>e?.data?{icon:"attach_file",isDisplayValue:!0,propertyName:"attachmentsCount",displayValueCb:a=>a?.data?.totalFiles,disabled:e?.data?.totalFiles<=0,clickEvent:a=>{if(a?.consolidatedattachments?.length){let r={id:a?.id,attachmentData:a.consolidatedattachments},s=qe.default.clone(this.permissions);s.canDelete=!1,this.modalService.openAttachmentModal(this.viewRef,r,this.mciTranslateService.getTranslation("L.Equipment_Allocated"),this.actionType,s,!1,null,null,!1)}}}:{},comparator:this.compareService.consolidatedAttachmentComparator,context:{isAutoSize:!0},resizable:!1},{field:"timesheetreference",headerName:this.mciTranslateService.getTranslation("L.Timesheet_Num"),context:{displayFieldName:""},filterValueGetter:e=>e.data?.timesheetreference.length?e.data?.timesheetreference:null,tooltipComponentParams:{customValueCb:e=>e.value?.join(", ")}},{field:"revoketimesheetref",headerName:this.mciTranslateService.getTranslation("L.Revoked_Timesheet_Num"),context:{displayFieldName:""},filterValueGetter:e=>e.data?.revoketimesheetref.length?e.data?.revoketimesheetref:null,tooltipComponentParams:{customValueCb:e=>e.value?.join(", ")}},{field:this.LAST_EDITED_COLUMN_FIELD,headerName:this.mciTranslateService.getTranslation("L.Last_Edited"),type:"rightAligned",valueGetter:e=>this.dateTimeService.toLocalizedDateHourMinFormat(e.data.lastEdited.date),filter:"agDateColumnFilter",filterParams:{comparator:this.dateTimeService.localizedDateHourMinFilterComparator},comparator:this.dateTimeService.localizedDateHourMinComparator,context:{isAutoSize:!0}},{field:"lastEdited.user",headerName:this.mciTranslateService.getTranslation("L.Edited_By")}];this.columnDefs=[...t,...i]}onExceptionIconClick(t,i){if(t===Y.REVOKED){let e={exceptionIcon:t,extraData:{resourceId:i?.resource?.id,timesheetDate:i.workdate,organizationId:i.organization.id,timesheetId:i.timesheetId,timesheetRef:i.timesheetreference[0],canViewGLAccount:this.canViewGLAccount}};this.exceptionIconService.onExceptionIconClick(e)}}getColumnFilterValueGetter(t){return t?.length?t:""}getCellRenderValue(t,i=!1){let e=this.mathService.formatNumber(t?.value),a=i?"%":"";return this.mciGridService.cellWithSuffix(e,a)}contentMenuParentClick(t,i){switch(this.actionType=t,t){case this.actionList.VIEW:this.selectedRowData=i,this.openDrawerAndSetForm(t,!1);break;case this.actionList.ACCEPT:this.onAcceptClick([i]);break;default:break}}contentMenuClick(t,i){switch(this.actionType=t,t){case this.actionList.EDIT:case this.actionList.VIEW:this.selectedRowData=i,this.getJobDetailsDataAndOpenDrawer(i,t);break;case this.actionList.ACCEPT:this.onAcceptClick([i]);break;case this.actionList.DELETE:this.openDeleteDialog([i]);break;default:break}}getJobDetailsDataAndOpenDrawer(t,i){let e=this.uiUtilitiesService.site$.value.location_id,a=this.commonUtilitiesService.getTokenData().oid,r={OrganizationId:t.organization?.id,TimesheetDate:this.dateTimeService.toISODateFormat(t.workdate),ResourceId:t.resource?.id,AllocationIds:t?.allocations?.replaceAll('"',"").split(","),RasId:t?.activity?.rasid};W({areaIdPermissions:this.commonService.getScreenNamePermissions(D.ALLOCATIONS_FOR_AREA_ID_CHANGE),orderTypes:this.masterDataService.getOrderTypes(),locationSettings:this.commonService.getLocationSettings(e),areaIds:this.commonService.getRestrictedAreaIdsByLocation(e),resourceInfo:this.allocationManagementService.getEquipmentAllocatedResource(r),allocationInfo:this.allocationManagementService.getEquipmentRejectedAllocation(r),userInfo:this.personalInformationService.getUser(a)}).pipe(le(this.destroyRef)).subscribe(({areaIdPermissions:s,orderTypes:o,locationSettings:p,areaIds:S,resourceInfo:F,allocationInfo:n,userInfo:y})=>{let G;F[0]?.data?.length&&(G=F[0]?.data[0],G&&n&&(G.allocate=n[0].data[0].allocated,G.available=n[0].data[0].available)),this.jobDetailsData={locationSettings:p[0]?.data?.settings,areaIdEditPermission:s[0]?.data?.edit,orderTypes:o[0]?.data,areaIds:S[0]?.data?.map(Q=>({id:Q.AreaId,name:Q.AreaName,areadisplayfield:Q.AreaDisplayField})),selectedResource:G,userOrderType:y[0].data.ordertype},this.openDrawerAndSetForm(i,!0)})}openDrawerAndSetForm(t,i){let e=this.getDrawerHeaderLabels(t,this.selectedRowData?.resource?.name,this.selectedRowData?.organization?.name),a=i?Ge:Vt,r=this.isRejectedOrVoidState(),s={isFromAllocated:i&&!r,allowEquipmentFutureDates:this.allowEquipmentFutureDates,nonBillPerms:this.nonBillPerms,lumpSumPerms:this.lumpSumPerms,subConPerms:this.subConPerms,jobDetailsData:this.jobDetailsData,canViewAcceptance:this.canViewAcceptance,canViewGLAccount:this.canViewGLAccount};this.selectedRowData.timesheetdate=this.selectedRowData?.workdate;let o=new Z(t,this.selectedRowData,this.permissions,s),p=new ue(a,e.title,e.subtitle,null,this.drawerSizesEnum.MEDIUM,null,o);this.drawerService.updateDrawerContent(p),this.drawerService.openDrawer()}onAcceptClick(t){this.isLoadingAcceptButton=!0,this.allocationManagementService.onAcceptance(t,we.accepted,"activitystatus","resource",Fe.EQUIPMENT,"state","resourcegroup")}onMassDelete(){let t=this.getSelectedRows();this.openDeleteDialog(t)}
1getSelectedRows(){let t=[];return this.gridApi?.forEachNode(i=>{i.isSelected()&&i.data?.equipmentChildRowsSelected&&t.push(i.data.equipmentChildRowsSelected)}),t?.flat()}openDeleteDialog(t){let i=(t??[]).map(a=>ee(d({},a),{name:a?.resource?.name??""})),e=this.modalService.openConfirmActionModal(t,this.entity,this.entityPlural,c.DELETE,j.ASYNC_CONFIRM);e.componentInstance.confirmAction$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(a=>{if(a===c.DELETE){let r=this.getDeleteRequestBody(t);this.equipmentAllocationService.deleteEquipmentAllocationsByIds(r).subscribe(s=>{e.close(),this.uiUtilitiesService.handleMassActionResponseMessage(s[0],ce.DELETE,this.entity,this.entityPlural,"",i),s[0].success&&(this.reloadGridData(!0),this.uiUtilitiesService.closeDrawer())})}})}getDeleteRequestBody(t){let i=[],e=1;return t.forEach(a=>{if(a?.allocations){let r=a.allocations.replaceAll('"',"").split(",");i.push({ids:r,groupkey:e,isnegativeallocation:a.isnegativeallocation,isrevoked:a.state?.id===b.REVOKED}),e++}}),{allocations:[...new Set(i)]}}onFiltersInitialized(t){this.filtersForm=t,this.getModelValues(this.uiUtilitiesService.site$.value,!0),this.uiUtilitiesService.site$.pipe(ie(1),this.takeUntilDestroyed(this.destroyRef)).subscribe(i=>{i&&this.getModelValues(i,!1)}),this.filterSectionService.filterChanged$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(i=>this.handleFilterChange(i))}handleFilterChange(t){let i=t.selectedValue!==void 0?t.selectedValue:t.form?.controls?.[t.formControlName]?.value;switch(t.isAdvancedFilter&&t.formControlName&&this.filtersForm?.controls[t.formControlName]&&this.filtersForm.controls[t.formControlName].setValue(i,{emitEvent:!1}),t.formControlName){case"organization":this.onOrganizationChange(i?.id);break;case"agreement":this.onAgreementChange();break;case"group":this.onGroupChange();break;case"type":this.onTypeChange();break;default:break}}getModelValues(t,i){i||(this.filtersForm.controls.state.reset(),this.filtersForm.controls.organization.reset(),this.filtersForm.controls.agreement.reset(),this.filtersForm.controls.type.reset(),this.filtersForm.controls.group.reset(),this.filtersForm.controls.uniqueId.reset()),this.defaultLocation=t?.location_id,this.getOrganizations()}onResetFilters(t){this.filtersForm.reset({filterSort:this.defaultFilterSort,state:[],timesheetDate:this.defaultDateRange,organization:this.organizationsFilterList[0],agreement:[],group:[],type:[],uniqueId:[]}),this.getAgreementsByOrganization(this.organizationsFilterList[0]?.id),this.getEquipmentAssociatedData(),this.filterSectionService.afterReset$.next(null),t&&(this.sortColumnAsc(ot),this.reloadGridData())}initializeFilterSection(){let t=this.commonUtilitiesService.getTokenData().oid,i;this.personalInformationService.getDefaultDateFilter(de.ALLOCATED,t).subscribe(e=>{i=e,i&&i.selectedvalue&&(this.defaultDateRange.id=parseInt(U[i.selectedvalue])),this.filterDefinitions=[{labelName:this.mciTranslateService.getTranslation("L.Timesheet_Date"),controlType:this.CONTROL_TYPE.DATE_SHORTCUT,disableAlphabeticalSorting:!0,isMultiSelect:!1,formControlName:"timesheetDate",inputValueLabel:"name",initialValue:this.defaultDateRange,accordionGroupName:this.mciTranslateService.getTranslation("L.Date_Range"),useSession:!0,sessionKey:z.FORM_SPECIFIC},{labelName:this.mciTranslateService.getTranslation("L.Organization"),isMultiSelect:!1,inputValueLabel:"name",inputValues:this.organizationsFilterList,controlType:this.CONTROL_TYPE.PICKER,formControlName:"organization",useSession:!0,sessionKey:z.ORGANIZATION,placeholder:this.mciTranslateService.getTranslation("L.Select_Organization"),callbackSearch:this.getOrganizations},{labelName:this.mciTranslateService.getTranslation("L.State"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.globalStatesService.getAllocationGlobalStates(),controlType:this.CONTROL_TYPE.PICKER,enableDataLoadingOnScrollOrSearch:!1,formControlName:"state",placeholder:this.mciTranslateService.getTranslation("L.Select_States")},{labelName:this.mciTranslateService.getTranslation("L.Agreement"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.agreementsFilterList,controlType:this.CONTROL_TYPE.PICKER,formControlName:"agreement",placeholder:this.mciTranslateService.getTranslation("L.Select_Agreements"),callbackSearch:this.getAgreements,totalRecords:this.agreementsFilterList?.length??0},{labelName:this.mciTranslateService.getTranslation("L.Group"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.groupsFilterList,controlType:this.CONTROL_TYPE.PICKER,enableDataLoadingOnScrollOrSearch:!1,formControlName:"group",placeholder:this.mciTranslateService.getTranslation("L.Select_Groups")},{labelName:this.mciTranslateService.getTranslation("L.Type"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.typesFilterList,controlType:this.CONTROL_TYPE.PICKER,enableDataLoadingOnScrollOrSearch:!1,formControlName:"type",placeholder:this.mciTranslateService.getTranslation("L.Select_Types")},{labelName:this.mciTranslateService.getTranslation("L.Unique_ID"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.uniqueIdsFilterList,controlType:this.CONTROL_TYPE.PICKER,enableDataLoadingOnScrollOrSearch:!1,formControlName:"uniqueId",placeholder:this.mciTranslateService.getTranslation("L.Select_Unique_IDs")}];let a={filterDefinitions:this.filterDefinitions,showAdvancedFilterButton:!0,associatedGridId:this.listingPageGridKey,alertLargeTimesheetDateFilter:!0};this.filterSectionService.initialize(a)})}getAgreementsByOrganization(t,i){this.orgFilterRequestId++;let e=this.orgFilterRequestId;this.filterDefinitions[3].inlineLoading=!0,qe.default.isEmpty(t)?(this.clearAgreementFilter(),this.filterDefinitions[3].inlineLoading=!1,i?.()):this.commonService.getActiveAgreements([t],[this.defaultLocation]).subscribe({next:a=>{e===this.orgFilterRequestId&&(this.uiUtilitiesService.handleResponse(a
1)?(this.agreementsFilterList=this.uiUtilitiesService.getDistinctObjectList(a[0]?.data??[]),this.filterDefinitions[3].inputValues=this.agreementsFilterList,this.filterDefinitions[3].totalRecords=this.agreementsFilterList.length):this.clearAgreementFilter(),this.filterDefinitions[3].inlineLoading=!1,i?.())},error:()=>{e===this.orgFilterRequestId&&(this.clearAgreementFilter(),this.filterDefinitions[3].inlineLoading=!1,i?.())}})}getEquipmentAssociatedData(){let t=this.filtersForm.controls.organization?.value?.id;if(!t){this.equipmentAssociatedDataByOrg=[],this.equipmentAssociatedDataByAgreement=[],this.equipmentAssociatedDataByGroup=[],this.groupsFilterList=[],this.typesFilterList=[],this.uniqueIdsFilterList=[],this.filterDefinitions[4].inputValues=[],this.filterDefinitions[5].inputValues=[],this.filterDefinitions[6].inputValues=[],this.setChildFilterDropdownInlineLoading(!1);return}let i=this.orgFilterRequestId;this.setChildFilterDropdownInlineLoading(!0);let e=this.dateTimeService.getDateRangeFromDateShortcut(this.filtersForm,"timesheetDate");this.equipmentActivityService.getEquipmentActivityReady({vendorids:[t],agreementids:[],activitystartdate:e.startDate,activityend
1date:e.endDate.substring(0,10)}).subscribe({next:a=>{if(i!==this.orgFilterRequestId)return;this.equipmentAssociatedDataByOrg=a[0]?.data??[];let r=this.filtersForm.controls.agreement?.value?.map(s=>s.id)??[];this.updateChildDropdowns(r),this.setChildFilterDropdownInlineLoading(!1)},error:()=>{i===this.orgFilterRequestId&&this.setChildFilterDropdownInlineLoading(!1)}})}onOrganizationChange(t){this.filtersForm.controls?.group?.reset(),this.filtersForm.controls?.type?.reset(),this.filtersForm.controls?.uniqueId?.setValue([]),this.filterSectionService.resetFormControls$.next(["group","type","uniqueId"]),this.getAgreementsByOrganization(t,()=>{this.pruneAgreementSelections(),this.getEquipmentAssociatedData(),this.filterSectionService.updateFormAdvFilter$.next(this.filtersForm)})}onAgreementChange(){let t=this.filtersForm.controls.agreement?.value?.map(i=>i.id)??[];this.updateChildDropdowns(t),this.filterSectionService.updateFormAdvFilter$.next(this.filtersForm)}onGroupChange(){this.recomputeTypesFromGroups(),this.pruneUniqueIdSelections(),this.filterSectionService.updateFormAdvFilter$.next(this.filtersForm)}onTypeChange(){this.pruneUniqueIdSelections(),this.filterSectionService.updateFormAdvFilter$.next(this.filtersForm)}updateChildDropdowns(t){this.equipmentAssociatedDataByAgreement=this.equipmentAssociatedDataByOrg.filter(a=>t.length>0?t.some(r=>a.agreementid===r):!0);let i=this.equipmentAssociatedDataByAgreement.map(a=>({id:a.groupid,name:a.groupname}));this.groupsFilterList=this.uiUtilitiesService.getDistinctObjectList(i),this.filterDefinitions[4].inputValues=this.groupsFilterList??[];let e=this.filtersForm.controls.group?.value??[];this.filtersForm.controls.group.setValue(e.filter(a=>this.groupsFilterList.some(r=>r.id===a.id))),this.equipmentAssociatedDataByGroup=this.equipmentAssociatedDataByAgreement.filter(a=>this.filtersForm.controls.group?.value?.length>0?this.filtersForm.controls.group.value.some(r=>a.groupid===r.id):!0),this.recomputeTypesFromGroups(),this.pruneUniqueIdSelections()}setChildFilterDropdownInlineLoading(t){this.filterDefinitions[4].inlineLoading=t,this.filterDefinitions[5].inlineLoading=t,this.filterDefinitions[6].inlineLoading=t}recomputeTypesFromGroups(){let t=this.filtersForm.controls.group?.value??[],i=t.length>0?this.equipmentAssociatedDataByAgreement.filter(a=>t.some(r=>a.groupid===r.id)):this.equipmentAssociatedDataByAgreement;this.typesFilterList=this.uiUtilitiesService.getDistinctObjectList(i.map(a=>({id:a.typeid,name:a.typename}))),this.filterDefinitions[5].inputValues=this.typesFilterList??[];let e=this.filtersForm.controls.type?.value??[];this.filtersForm.controls.type.setValue(e.filter(a=>this.typesFilterList.some(r=>r.id===a.id)))}pruneUniqueIdSelections(){let t=this.filtersForm.controls.type?.value??[],i=t.length>0?this.equipmentAssociatedDataByGroup.filter(a=>t.some(r=>a.typeid===r.id)):this.equipmentAssociatedDataByGroup;this.uniqueIdsFilterList=this.uiUtilitiesService.getDistinctObjectList(i.map(a=>({id:a.id,name:a.name}))),this.filterDefinitions[6].inputValues=this.uniqueIdsFilterList??[];let e=this.filtersForm.controls.uniqueId?.value??[];this.filtersForm.controls.uniqueId.setValue(e.filter(a=>this.uniqueIdsFilterList.some(r=>r.id===a.id)))}pruneAgreementSelections(){let t=this.filtersForm.controls.agreement?.value??[];this.filtersForm.controls.agreement.setValue(t.filter(i=>this.agreementsFilterList.some(e=>e.id===i.id)))}clearAgreementFilter(){this.agreementsFilterList=[],this.filterDefinitions[3].inputValues=[],this.filterDefinitions[3].totalRecords=0}onSelectionChanged(t){this.showGridAcceptButton=!1,t.filter(e=>(e?.state?.id===Te.ALLOCATED||e?.state?.id===Te.AUTHORIZED_UNACCEPTED)&&(new Date(e?.workdate)<=new Date||new Date(e?.workdate)>new Date&&this.allowEquipmentFutureDates===!0)?e:null)?.length&&(this.showGridAcceptButton=!0),this.showDeleteButtonOnSelection()}showDeleteButtonOnSelection(){let t=[];this.gridApi?.forEachNode(e=>{if(e.isSelected()&&e.data?.selectedChildRowStates)t.push(...e.data.selectedChildRowStates);else if(e.isSelected()&&!e?.data?.selectedChildRowStates){let a=e.data.childData.map(r=>r?.state?.id);t.push(...a)}}),t?.some(e=>e===b.ALLOCATED||e===b.REJECTED||e===b.VOIDED||e===b.REVOKED)?this.showGridDeleteButton=!0:this.showGridDeleteButton=!1}onRowDataUpdated(t){super.onRowDataUpdated(t),this.updateGridAggregationSummary()}onPaginationChanges(t){this.updateGridAggregationSummary(t.pageIndex)}onSearchEvent(){this.updateGridAggregationSummary()}onFilterChange(){this.updateGridAggregationSummary()}updateGridAggregationSummary(t=0){let i=this.gridApi?.paginationGetPageSize()??50,e=t*i,a=e+i,r=0,s=0,o=0,p=0;this.gridApi?.forEachNodeAfterFilterAndSort(S=>{if(S.data){let F=S.data.childData?.length??0;r+=F,s++,p>=e&&p<a&&(o+=F),p++}}),this.paginator()&&(this.paginator().length=s),this.gridAggregationSummary.update(S=>S&&ee(d({},S),{total:r,parentCount:s,shown:o}))}static{this.\u0275fac=function(i){return new(i||l)}}static{this.\u0275cmp=L({type:l,selectors:[["app-equipment-allocated"]],features:[
1k],decls:5,vars:23,consts:[["associatedGridId","equipmentAllocatedListing",3,"isDataRestrictedChange","isDataRestricted","showLongDateAlertForDataRestriction","formName","totalFilterCount"],[1,"mci-ui-card-flat-border"],[1,"mci-ui-table"],[3,"addClick","filterChanged","gridReady","massAcceptEvent","searchEvent","massDelete","onNodeSelect","onRowSelect","paginatorEvent","rowDataUpdated","columnDefinition","detailCellRenderer","detailCellRendererParams","getRowHeight","getRowIdCB","gridData","gridAggregationSummary","gridHeight","isLoadingAcceptButton","key","masterDetail","showAddButton","showGridAcceptButton","showGridDeleteButton","showGridStatusButton","fileName"]],template:function(i,e){i&1&&(m(0,"app-filter-section",0),ne("isDataRestrictedChange",function(r){return oe(e.isDataRestricted,r)||(e.isDataRestricted=r),r}),f(),m(1,"div",1)(2,"div",2)(3,"app-common-data-grid",3),T(4,"mciTranslate"),v("addClick",function(){return e.contentMenuClick(e.actionList.ADD,null)})("filterChanged",function(){return e.onFilterChange()})("gridReady",function(r){return e.onGridReady(r)})("massAcceptEvent",function(){return e.onAcceptClick(e.gridApi==null?null:e.gridApi.getSelectedRows())})("searchEvent",function(){return e.onSearchEvent()})("massDelete",function(){return e.onMassDelete()})("onNodeSelect",function(){return e.parentRowsSelected()})("onRowSelect",function(r){return e.onSelectionChanged(r)})("paginatorEvent",function(r){return e.onPaginationChanges(r)})("rowDataUpdated",function(r){return e.onRowDataUpdated(r)}),f()()()),i&2&&(se("isDataRestricted",e.isDataRestricted),h("showLongDateAlertForDataRestriction",!0)("formName",e.listingPageGridKey)("totalFilterCount",7),u(3),h("fileName",R(C(4,21,"L.Equipment_Allocated")))("columnDefinition",e.columnDefs)("detailCellRenderer",e.detailGrid)("detailCellRendererParams",e.detailGridParams)("getRowHeight",e.rowHeight)("getRowIdCB",e.getRowIdCallBack)("gridData",e.gridData)("gridAggregationSummary",e.gridAggregationSummary())("gridHeight",e.gridHeight)("isLoadingAcceptButton",e.isLoadingAcceptButton)("key",e.listingPageGridKey)("masterDetail",!0)("showAddButton",!1)("showGridAcceptButton",e.canViewAcceptance&&e.showGridAcceptButton)("showGridDeleteButton",(e.permissions==null?null:e.permissions.canDelete)&&e.showGridDeleteButton)("showGridStatusButton",!1))},dependencies:[ge,N,M],encapsulation:2})}}return l})();var xt=De(ye());var Mt=(()=>{class l extends pe{constructor(){super(),this.equipmentAllocationService=g(J),this.equipmentActivityService=g(Se),this.importService=g(Gt),this.masterDataService=g(fe),this.personalInformationService=g(me),this.organizationsFilterList=[],this.agreementsFilterList=[],this.groupsFilterList=[],this.typesFilterList=[],this.uniqueIdsFilterList=[],this.equipmentAssociatedDataByOrg=[],this.equipmentAssociatedDataByAgreement=[],this.equipmentAssociatedDataByGroup=[],this.locationList=[],this.defaultTimeSheetDate=new Date,this.gridHeight=he,this.showAllocateBtn=!1,this.showApplyOperatorBtn=!1,this.isLoadingApplyOperatorButton=!1,this.isLoadingExportForImportButton=!1,this.defaultDateRange={id:U.Yesterday},this.massAllocateSnapshot=[],this.menuEventCallBack=t=>{t.headerName===_.CONTEXTMENU&&(t.actionType===c.VIEW?this.equipmentActivityService.getResourceActivityById(t.rowData?.id).subscribe(i=>{this.uiUtilitiesService.handleResponse(i)&&(this.allocationRowData=t.rowData,this.contentMenuClick(t.actionType,i[0]?.data[0]))}):this.contentMenuClick(t.actionType,t.rowData))},this.getOrganizations=t=>q(this,null,function*(){let i=yield this.commonService.getFilteredOrganizations(t,[this.defaultLocation],["id","name","isactive"]);return t||(this.organizationsFilterList=i.data,this.filterDefinitions[1].inputValues=this.organizationsFilterList,this.filterDefinitions[1].totalRecords=i?.totalcount??0,!this.filtersForm.controls.organization.value&&this.organizationsFilterList?.length>0&&this.filtersForm.controls.organization.setValue(this.organizationsFilterList[0]),this.filterSectionService.updateAppliedFilterIndicator$.next(null),i.data?.length>0&&this.getAgreementsByOrganization(this.filtersForm.controls.organization.value?.id??""),this.getEquipmentAssociatedData(this.filtersForm.controls.organization.value.id),this.reloadGridData()),i?.data??[]}),this.getAgreements=(t,i)=>q(this,null,function*(){let a=(i??this.filtersForm)?.controls?.organization?.value?.id,r=a?[a]:[];try{let s=yield te(this.commonService.getActiveAgreements(r,[this.defaultLocation]));if(s[0]?.success&&s[0]?.data){let o=s[0].data;return t||(this.agreementsFilterList=o,this.filterDefinitions[2].inputValues=o,this.filterDefinitions[2].totalRecords=o.length),o}return[]}catch(s){return[]}}),this.getExportForImportTemplate=()=>q(this,null,function*(){this.isLoadingExportForImportButton=!0;let t;return this.gridApi?.getSelectedRows()?.length>0?t={selecteddata:!0,data:this.gridApi?.getSelectedRows()}:t={selecteddata:!1,filters:this.getRequestPayload()},new Promise(e=>{this.importService.getExportForImportTemplate(at.ALLOCATE_EQUIPMENT,t).subscribe({next:a=>
1{a[0].data&&this.importService.convertDataAndDownloadExcel(a[0].data,this.mciTranslateService.getTranslation("L.Equipment_Activity_Allocate_FileName")),this.isLoadingExportForImportButton=!1,e(!0)},error:()=>{this.isLoadingExportForImportButton=!1,e(!1)}})})}),this.uiUtilitiesService.allocationsTabName=X.EQUIPMENT,this.setupFilterAfterInitObservable(this.onFiltersInitialized.bind(this))}ngOnInit(){this.listingPageGridKey="equipmentNotAllocatedListing",this.initializeGrid(D.ALLOCATIONS_FOR_EQUIPMENT),this.initializeFilterSection(),this.getTranslations(),this.commonService.getScreenNamePermissions(D.EQUIPMENT_OTHER_CHARGES).pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{this.otherChargesPermissions=t[0]?.data}),this.filterSectionService.applyFilters$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>this.onApplyFilters(t)),this.filterSectionService.resetFilters$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>this.onResetFilters(t)),this.fullscreenFormService.reloadTableAfterDrawerAction$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{t!=null&&t===!0&&(this.deselectRows(),this.reloadGridData())}),this.drawerService.drawerFooterAction$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{t===c.ALLOCATE&&(this.loaderService.show(),this.actionType=c.ALLOCATE,this.selectedRowData=this.allocationRowData,this.massAllocateSnapshot=[],this.getJobDetailsDataAndOpenDrawer(t))})}getTranslations(){this.entity=this.mciTranslateService.getTranslation("L.Allocation"),this.entityPlural=this.mciTranslateService.getTranslation("L.Allocations"),this.addDrawerTitle=this.mciTranslateService.getTranslation("L.Add_Allocations_Title"),this.addDrawerSubtitle=this.mciTranslateService.getTranslation("L.Add_Allocations_Subtitle"),this.editDrawerSubtitle="",this.viewDrawerSubtitle=""}reloadGridData(){let t=this.getRequestPayload();this.equipmentAllocationService.getNotAllocatedEquipmentActivities(t).pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe({next:i=>{this.checkIfDataIsRestricted(i),i&&i[0].data?(this.gridData=i[0].data,this.gridData.forEach((e,a)=>{e.consolidatedattachments=this.uiUtilitiesService.formatStringWithMultipleArray(e.consolidatedattachments),e.totalFiles=e.consolidatedattachments?e.consolidatedattachments?.length:0,e.timesheetdate=e.workdate,e.organization=e.vendor,e.recordid=a+1,e.exceptions&&(e.exceptions.isException=this.exceptionIconService.checkIfHasException(e.exceptions))})):this.onAPIError()},error:()=>{this.onAPIError()}})}getRequestPayload(){if(!this.filtersForm)return null;let t=this.filtersForm.controls.organization?.value?.id,i=this.filtersForm.controls.agreement?.value?.map(o=>o.id),e=this.filtersForm.controls.group?.value?.map(o=>o.id),a=this.filtersForm.controls.type?.value?.map(o=>o.id),r=this.filtersForm.controls.uniqueid?.value?.map(o=>o.id),s=this.dateTimeService.getDateRangeFromDateShortcut(this.filtersForm,"timesheetDate");return{organizationids:t!=null?[t]:[],startdate:s.startDate,enddate:s.endDate.substring(0,10),agreementids:i??[],resourcegroupids:e??[],typeids:a??[],uniqueids:r??[]}}onExceptionIconClick(t,i){let e={exceptionIcon:t,extraData:{resourceId:i?.resource?.id}};t===Y.OPERATOR_AVAILABLE&&this.exceptionIconService.onExceptionIconClick(e)}configurePopupOptions(){let t=[{action:c.VIEW,canAct:this.permissions?.canView},{action:c.ALLOCATE,canAct:this.permissions?.canAdd},{action:c.APPLY_OPERATOR,canAct:this.permissions?.canAdd}];this.popupOptions=t.filter(i=>i.canAct).map(i=>i.action)}onSelectionChanged(t){if(super.onSelectionChanged(t),!t?.length){this.showAllocateBtn=!1,this.showApplyOperatorBtn=!1;return}let i=t[0],e=t.filter(s=>s?.workdate===i?.workdate&&s?.vendor?.id===i?.vendor?.id);this.showAllocateBtn=e.length===t.length;let a=t.filter(s=>s?.exceptions?.hasapplyoperator),r=a[0]?.vendor?.id;this.showApplyOperatorBtn=a.length>0&&a.every(s=>s?.vendor?.id===r)}setColumnDefs(){let t=[{headerName:_.CONTEXTMENU,context:{isMenuEvent:!0},cellRenderer:"materialGridMenu",cellRendererParams:{buttons:this.popupOptions,filterButtons:(e,a)=>e?.exceptions?.hasapplyoperator?a:a?.filter(s=>
1s!==c.APPLY_OPERATOR)}},{colId:"exceptions",headerName:this.mciTranslateService.getTranslation(_.EXCEPTION),field:"exceptions",cellRenderer:"exceptionIconCell",context:{isAutoSize:!0,excludeExcelExport:!1,excludeImportTemplate:!1},cellRendererParams:e=>({iconClickEvent:a=>{this.onExceptionIconClick(a,e.data)},iconSortType:st.ACTIVITY})},{field:"state",headerName:this.mciTranslateService.getTranslation("L.State"),cellRenderer:"globalStatesCellRenderer"},{field:"workdate",type:"rightAligned",headerName:this.mciTranslateService.getTranslation("L.Timesheet_Date"),valueGetter:e=>this.dateTimeService.toLocalizedDateFormat(e.data.workdate),filter:"agDateColumnFilter",filterParams:{comparator:this.dateTimeService.localizedDateFilterComparator},comparator:this.dateTimeService.localizedDateComparator,context:{isAutoSize:!0,excludeImportTemplate:!0}},{field:"vendor.name",headerName:this.mciTranslateService.getTranslation("L.Organization"),context:{appendAsteriskToHeaderNameOnExportForImport:!0},flex:1,minWidth:this.mciGridService.getColumnMinWidthByHeader(this.mciTranslateService.getTranslation("L.Organization"))},{field:"agreement.name",headerName:this.mciTranslateService.getTranslation("L.Agreement"),context:{isAutoSize:!0,appendAsteriskToHeaderNameOnExportForImport:!0}},{field:"group.name",headerName:this.mciTranslateService.getTranslation("L.Group"),cellEditor:"materialInputEditor",filter:"agTextColumnFilter"},{field:"type.name",headerName:this.mciTranslateService.getTranslation("L.Type"),filter:"agMultiColumnFilter"},{field:"VIN",headerName:this.mciTranslateService.getTranslation("L.Unique_ID"),filter:"agTextColumnFilter",context:{isAutoSize:!0,appendAsteriskToHeaderNameOnExportForImport:!0}},d({field:"available.hours",headerName:this.mciTranslateService.getTranslation("L.Base"),context:{overrideHeaderNameOnExportForImport:this.mciTranslateService.getTranslation("L.Base_Hours")},cellRenderer:e=>this.mathService.formatNumber(e.value),valueGetter:e=>this.mathService.roundHours(e?.data?.available?.hours,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"available.overrate",headerName:this.mciTranslateService.getTranslation("L.Over"),context:{overrideHeaderNameOnExportForImport:this.mciTranslateService.getTranslation("L.Over_Hours")},cellRenderer:e=>this.mathService.formatNumber(e.value),valueGetter:e=>this.mathService.roundHours(e?.data?.available?.overrate,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"available.idle",headerName:this.mciTranslateService.getTranslation("L.Idle"),context:{overrideHeaderNameOnExportForImport:this.mciTranslateService.getTranslation("L.Idle_Hours")},cellRenderer:e=>this.mathService.formatNumber(e.value),valueGetter:e=>this.mathService.roundHours(e?.data?.available?.idle,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"available.othercharges",headerName:this.mciTranslateService.getTranslation("L.Other_Charge"),context:{excludeImportTemplate:!0},cellRenderer:e=>{let a=this.mathService.formatNumber(e?.value),r=e?.data?.currencyabbr;return this.mciGridService.cellWithSuffix(a,r)},valueGetter:e=>this.mathService.roundRate(e?.data?.available?.othercharges,!1)},this.mciGridService.getBaseDecimalColumnDefinition())],i=[{headerName:this.mciTranslateService.getTranslation("L.Attachment"),cellRenderer:"materialGridIcon",headerClass:"ag-center-aligned-header",cellClass:"ag-center-aligned-cell",field:"attachmentsdata",filter:"agNumberColumnFilter",editable:!1,cellRendererParams:{icon:"attach_file",isDisplayValue:!0,propertyName:"attachmentdata",displayValueCb:e=>e?.data?.totalFiles,clickEvent:e=>{if(e?.consolidatedattachments?.length){let a={id:e?.id,attachmentData:e?.consolidatedattachments};this.modalService.openAttachmentModal(this.viewRef,a,this.mciTranslateService.getTranslation("L.Equipment_Not_Allocated"),this.actionType,this.attachmentsPermissions,!1)}}},comparator:this.compareService.consolidatedAttachmentComparator,valueGetter:e=>e?.data?.totalFiles,context:{isAutoSize:!0,excludeImportTemplate:!0},resizable:!1}];this.columnDefs=[...t,...i]}contentMenuClick(t,i){switch(this.actionType=t,t){case this.actionList.ADD:this.loaderService.show(),this.selectedRowData=null,this.massAllocateSnapshot=[],this.getJobDetailsDataAndOpenDrawer(t);break;case this.actionList.VIEW:this.selectedRowData=i,this.openDrawerAndSetForm(t);break;case this.actionList.ALLOCATE:this.selectedRowData=i,this.massAllocateSnapshot=[],this.getJobDetailsDataAndOpenDrawer(t);break;case c.APPLY_OPERATOR:this.applyOperatorActivities([i]);break;default:break}}getJobDetailsDataAndOpenDrawer(t){let i=this.uiUtilitiesService.site$.value.location_id,e=this.commonUtilitiesService.getTokenData().oid;W({areaIdPermissions:this.commonService.getScreenNamePermissions(D.ALLOCATIONS_FOR_AREA_ID_CHANGE),orderTypes:this.masterDataService.getOrderTypes(),locationSettings:this.commonService.getLocationSettings(i),areaIds:this.commonService.getRestrictedAreaIdsByLocation(i),userInfo:this.personalInformationService.getUser(e)}).pipe(le(this.destroyRef)).subscribe(({areaIdPermissions:a,orderTypes:r,locationSettings:s,areaIds:o,userInfo:p})=>{this.jobDetailsData={locationSettings:s[0]?.data?.settings,areaIdEditPermission:a[0]?.data?.edit,orderTypes:r[0]?.data,areaIds:o[0]?.data?.map(S=>({id:S.AreaId,name:S.AreaName,areadisplayfield:S.AreaDisplayField})),userOrderType:p[0].data.ordertype},this.openFullscreenFormAndSetForm(t)})}onFiltersInitialized(t){this.filtersForm=t,this.getModelValues(this.uiUtilitiesService.site$.value,!0),this.uiUtilitiesService.site$.pipe(ie(1),this.takeUntilDestroyed(this.destroyRef)).subscribe(i=>{i&&this.getModelValues(i,!1)}),this.filterSectionService.filterChanged$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(i=>{let e=i.form;if(i.formControlName==="organization")this.agreementsFilterList=[],e.controls?.agreement?.reset(),e.controls?.group?.reset(),e.controls?.type?.reset(),e.controls?.uniqueid?.reset(),this.filterDefinitions[2].inputValues=[],this.filterDefinitions[2].totalRecords=0,this.filterSectionService.resetFormControls$.next(["agreement","group","type","uniqueid"]),this.getAgreementsByOrganization(i.selectedValue?.id),this.getEquipmentAssociatedData(i.selectedValue.id,e);else if(i.formControlName==="agreement"){let a=i?.selectedValue?.map(r=>r.id)??[];this.updateChildDropdowns(a,e)}else if(i.formControlName==="group"){let a=i?.selectedValue?.length>0?this.equipmentAssociatedDataByAgreement.filter(o=>i.selectedValue.some(p=>o.groupid===p.id)):this.equipmentAssociatedDataByAgreement;
1this.typesFilterList=this.uiUtilitiesService.getDistinctObjectList(a.map(o=>({id:o.typeid,name:o.typename}))),this.filterDefinitions[4].inputValues=this.typesFilterList??[];let s=(e.controls.type?.value??[]).filter(o=>this.typesFilterList.some(p=>p.id===o.id));e.controls.type.setValue(s),this.pruneUniqueIdSelections(e)}else if(i.formControlName==="type"){let a=i?.selectedValue?.length>0?this.equipmentAssociatedDataByGroup.filter(o=>i.selectedValue.some(p=>o.typeid===p.id)):this.equipmentAssociatedDataByGroup;this.uniqueIdsFilterList=this.uiUtilitiesService.getDistinctObjectList(a.map(o=>({id:o.id,name:o.name}))),this.filterDefinitions[5].inputValues=this.uniqueIdsFilterList??[];let s=(e.controls.uniqueid?.value??[]).filter(o=>this.uniqueIdsFilterList.some(p=>p.id===o.id));e.controls.uniqueid.setValue(s)}})}getModelValues(t,i){i||(this.filtersForm.controls.organization.reset(),this.filtersForm.controls.agreement.reset(),this.filtersForm.controls.group.reset(),this.filtersForm.controls.type.reset(),this.filtersForm.controls.uniqueid.reset()),this.defaultLocation=t?.location_id,this.getOrganizations()}onResetFilters(t){this.filtersForm.reset({filterSort:this.defaultFilterSort,timesheetDate:this.defaultDateRange,organization:this.organizationsFilterList[0],agreement:[],group:[],type:[],uniqueid:[]}),this.getAgreementsByOrganization(this.organizationsFilterList[0]?.id),this.filterSectionService.afterReset$.next(null),t&&this.reloadGridData()}initializeFilterSection(){let t=this.commonUtilitiesService.getTokenData().oid,i;this.personalInformationService.getDefaultDateFilter(de.NOT_ALLOCATED,t).subscribe(e=>{i=e,i&&i.selectedvalue&&(this.defaultDateRange.id=parseInt(U[i.selectedvalue])),this.filterDefinitions=[{labelName:this.mciTranslateService.getTranslation("L.Timesheet_Date"),controlType:this.CONTROL_TYPE.DATE_SHORTCUT,disableAlphabeticalSorting:!0,isMultiSelect:!1,formControlName:"timesheetDate",inputValueLabel:"name",initialValue:this.defaultDateRange,accordionGroupName:this.mciTranslateService.getTranslation("L.Date_Range"),useSession:!0,sessionKey:z.FORM_SPECIFIC},{labelName:this.mciTranslateService.getTranslation("L.Organization"),isMultiSelect:!1,inputValueLabel:"name",inputValues:this.organizationsFilterList,controlType:this.CONTROL_TYPE.PICKER,formControlName:"organization",useSession:!0,sessionKey:z.ORGANIZATION,placeholder:this.mciTranslateService.getTranslation("L.Select_Organizations"),callbackSearch:this.getOrganizations},{labelName:this.mciTranslateService.getTranslation("L.Agreement"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.agreementsFilterList,controlType:this.CONTROL_TYPE.PICKER,formControlName:"agreement",placeholder:this.mciTranslateService.getTranslation("L.Select_Agreements"),callbackSearch:this.getAgreements,totalRecords:this.agreementsFilterList?.length??0},{labelName:this.mciTranslateService.getTranslation("L.Group"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.groupsFilterList,controlType:this.CONTROL_TYPE.PICKER,enableDataLoadingOnScrollOrSearch:!1,formControlName:"group",placeholder:this.mciTranslateService.getTranslation("L.Select_Groups")},{labelName:this.mciTranslateService.getTranslation("L.Type"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.typesFilterList,controlType:this.CONTROL_TYPE.PICKER,enableDataLoadingOnScrollOrSearch:!1,formControlName:"type",placeholder:this.mciTranslateService.getTranslation("L.Select_Types")},{labelName:this.mciTranslateService.getTranslation("L.Unique_ID"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.uniqueIdsFilterList,controlType:this.CONTROL_TYPE.PICKER,enableDataLoadingOnScrollOrSearch:!1,formControlName:"uniqueid",placeholder:this.mciTranslateService.getTranslation("L.Select_Unique_IDs")}];let a={filterDefinitions:this.filterDefinitions,showAdvancedFilterButton:!0,associatedGridId:this.listingPageGridKey,alertLargeTimesheetDateFilter:!0};this.filterSectionService.initialize(a)})}onMassAllocate(){let t=this.gridApi?.getSelectedRows();t?.length&&(this.massAllocateSnapshot=t,this.actionType=c.ALLOCATE,this.selectedRowData=null,this.getJobDetailsDataAndOpenDrawer(c.ADD))}openFullscreenFormAndSetForm(t){let i=this.selectedRowData?.resource?.name,e=this.selectedRowData?.organization?.name;t===c.ALLOCATE&&(i=this.mciTranslateService.getTranslation("L.Add_Allocations_Title"),e=this.mciTranslateService.getTranslation("L.Add_Allocations_Subtitle"));let a=this.getDrawerHeaderLabels(t,i,e),r={filtersForm:this.filtersForm,massAllocateRows:this.massAllocateSnapshot,isFromNotAllocated:!0,isEquipment:!0,isFromOverFlowOrBulk:this.actionType===this.actionList?.ALLOCATE,actionType:this.actionType,jobDetailsData:this.jobDetailsData,listingPageGridKey:this.listingPageGridKey,listingPageTimesheetFilterDate:this.filtersForm?.controls?.timesheetDate?.value?.id,sourceRasId:this.selectedRowData?.id??null},s=new Z(t,this.selectedRowData,this.permissions,r),o=new Dt(Ft,a.title,a.subtitle,s);this.fullscreenFormService.updateDrawerContent(o),this.fullscreenFormService.openDrawer()}openDrawerAndSetForm(t){let i=this.getDrawerHeaderLabels(t,this.selectedRowData?.resource?.name,this.selectedRowData?.organization?.name),e=new Z(t,this.selectedRowData,this.permissions,{equipmentUniqueIdsAddPermissions:!1,equipmentAllocatePermissions:this.permissions.canAdd,otherChargesPermissions:this.otherChargesPermissions,defaultLocation:this.defaultLocation,navFromAllocation:!0}
1),a=new ue(wt,i.title,i.subtitle,null,this.drawerSizesEnum.MEDIUM,null,e);this.drawerService.updateDrawerContent(a),this.drawerService.openDrawer()}getAgreementsByOrganization(t){this.filterDefinitions[2].inlineLoading=!0,xt.default.isEmpty(t)?this.filterDefinitions[2].inlineLoading=!1:this.commonService.getActiveAgreements([t],[this.defaultLocation]).subscribe({next:i=>{this.uiUtilitiesService.handleResponse(i)&&(this.agreementsFilterList=i[0]?.data,this.filterDefinitions[2].inputValues=this.agreementsFilterList??[],this.filterDefinitions[2].totalRecords=this.agreementsFilterList?.length??0,this.agreementsFilterList=this.uiUtilitiesService.getDistinctObjectList(this.agreementsFilterList)),this.filterDefinitions[2].inlineLoading=!1},error:()=>{this.filterDefinitions[2].inlineLoading=!1}})}getEquipmentAssociatedData(t,i){let e=i??this.filtersForm;this.setChildFilterDropdownInlineLoading(!0);let a=this.dateTimeService.getDateRangeFromDateShortcut(e,"timesheetDate");this.equipmentActivityService.getEquipmentActivityReady({vendorids:[t],agreementids:[],activitystartdate:a.startDate,activityend
1date:a.endDate.substring(0,10)}).subscribe({next:r=>{this.equipmentAssociatedDataByOrg=r[0]?.data??[],this.updateChildDropdowns([],e),this.setChildFilterDropdownInlineLoading(!1)},error:()=>{this.setChildFilterDropdownInlineLoading(!1)}})}updateChildDropdowns(t,i){this.equipmentAssociatedDataByAgreement=this.equipmentAssociatedDataByOrg.filter(s=>t.length>0?t.some(o=>s.agreementid===o):!0);let e=this.equipmentAssociatedDataByAgreement.map(s=>({id:s.groupid,name:s.groupname}));this.groupsFilterList=this.uiUtilitiesService.getDistinctObjectList(e),this.filterDefinitions[3].inputValues=this.groupsFilterList??[];let r=(i.controls.group?.value??[]).filter(s=>this.groupsFilterList.some(o=>o.id===s.id));i.controls.group.setValue(r),this.equipmentAssociatedDataByGroup=this.equipmentAssociatedDataByAgreement.filter(s=>i.controls.group?.value?.length>0?i.controls.group.value.some(o=>s.groupid===o.id):!0),this.recomputeTypesFromGroups(i),this.pruneUniqueIdSelections(i)}setChildFilterDropdownInlineLoading(t){this.filterDefinitions[3].inlineLoading=t,this.filterDefinitions[4].inlineLoading=t,this.filterDefinitions[5].inlineLoading=t}recomputeTypesFromGroups(t){let i=t.controls.group?.value??[];if(i.length>0){let r=this.equipmentAssociatedDataByAgreement.filter(s=>i.some(o=>s.groupid===o.id));this.typesFilterList=this.uiUtilitiesService.getDistinctObjectList(r.map(s=>({id:s.typeid,name:s.typename})))}else this.typesFilterList=this.uiUtilitiesService.getDistinctObjectList(this.equipmentAssociatedDataByAgreement.map(r=>({id:r.typeid,name:r.typename})));this.filterDefinitions[4].inputValues=this.typesFilterList??[];let a=(t.controls.type?.value??[]).filter(r=>this.typesFilterList.some(s=>s.id===r.id));t.controls.type.setValue(a)}pruneUniqueIdSelections(t){let i=t.controls.type?.value??[];if(i.length>0){let r=this.equipmentAssociatedDataByGroup.filter(s=>i.some(o=>s.typeid===o.id));this.uniqueIdsFilterList=this.uiUtilitiesService.getDistinctObjectList(r.map(s=>({id:s.id,name:s.name})))}else this.uniqueIdsFilterList=this.uiUtilitiesService.getDistinctObjectList(this.equipmentAssociatedDataByGroup.map(r=>({id:r.id,name:r.name})));this.filterDefinitions[5].inputValues=this.uniqueIdsFilterList??[];let a=(t.controls.uniqueid?.value??[]).filter(r=>this.uniqueIdsFilterList.some(s=>s.id===r.id));t.controls.uniqueid.setValue(a)}onMassApplyOperator(){this.applyOperatorActivities(this.gridApi?.getSelectedRows())}applyOperatorActivities(t){if(!t?.length)return;let i=t.filter(r=>r?.exceptions?.hasapplyoperator);if(!i.length)return;let e=this.uiUtilitiesService.site$.value.location_id,a={organizationid:i[0]?.vendor?.id,locationid:e,resources:i.map(r=>({resourceid:r?.resource?.id,agreementid:r?.agreement?.id,timesheetdate:this.datePipe.transform(new Date(r?.workdate),it.DATE),operatorids:r?.operators?.map(s=>s.id)??[]}))};this.isLoadingApplyOperatorButton=!0,this.equipmentAllocationService.applyOperator(a).pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe({next:r=>{this.isLoadingApplyOperatorButton=!1,this.uiUtilitiesService.handleResponse(r)&&(this.deselectRows(),this.reloadGridData(),this.uiUtilitiesService.handleMassActionResponseMessage(r[0],ce.CREATE,this.entity,this.entityPlural))},error:()=>{this.isLoadingApplyOperatorButton=!1,this.onAPIError()}})}static{this.\u0275fac=function(i){return new(i||l)}}static{this.\u0275cmp=L({type:l,selectors:[["app-equipment-not-allocated"]],features:[k],decls:6,vars:28,consts:[["associatedGridId","equipmentNotAllocatedListing",3,"isDataRestrictedChange","isDataRestricted","showLongDateAlertForDataRestriction","formName","totalFilterCount"],[1,"mci-ui-card-flat-border"],[1,"mci-ui-table"],[3,"addClick","gridReady","massAllocate","massApplyOperator","onRowSelect","columnDefinition","exportForImportCB","gridData","gridHeight","isLoadingExportForImportButton","key","menuEventCB","showAddButton","showExportImportGridMenuOption","showGridAllocateButton","showGridApplyOperatorButton","isLoadingApplyOperatorButton","showGridDeleteButton","showGridExportForImportButton","showGridStatusButton","useNewExportForImportMethod","fileName","templateName"]],template:function(i,e){i&1&&(m(0,"app-filter-section",0),ne("isDataRestrictedChange",function(r){return oe(e.isDataRestricted,r)||(e.isDataRestricted=r),r}),f(),m(1,"div",1)(2,"div",2)(3,"app-common-data-grid",3),T(4,"mciTranslate"),T(5,"mciTranslate"),v("addClick",function(){return e.contentMenuClick(e.actionList.ADD,null)})("gridReady",function(r){return e.onGridReady(r)}
1)("massAllocate",function(){return e.onMassAllocate()})("massApplyOperator",function(){return e.onMassApplyOperator()})("onRowSelect",function(r){return e.onSelectionChanged(r)}),f()()()),i&2&&(se("isDataRestricted",e.isDataRestricted),h("showLongDateAlertForDataRestriction",!0)("formName",e.listingPageGridKey)("totalFilterCount",6),u(3),h("fileName",R(C(4,24,"L.Equipment_Not_Allocated_FileName")))("templateName",R(C(5,26,"L.Equipment_Activity_Allocate_FileName")))("columnDefinition",e.columnDefs)("exportForImportCB",e.getExportForImportTemplate)("gridData",e.gridData)("gridHeight",e.gridHeight)("isLoadingExportForImportButton",e.isLoadingExportForImportButton)("key",e.listingPageGridKey)("menuEventCB",e.menuEventCallBack)("showAddButton",e.permissions==null?null:e.permissions.canAdd)("showExportImportGridMenuOption",!0)("showGridAllocateButton",(e.permissions==null?null:e.permissions.canAdd)&&e.showAllocateBtn)("showGridApplyOperatorButton",(e.permissions==null?null:e.permissions.canAdd)&&e.showApplyOperatorBtn)("isLoadingApplyOperatorButton",e.isLoadingApplyOperatorButton)("showGridDeleteButton",!1)("showGridExportForImportButton",!0)("showGridStatusButton",!1)("useNewExportForImportMethod",!0))},dependencies:[ge,N,M],encapsulation:2})}}return l})();var zt=De(ye());var jt=(()=>{class l extends pe{constructor(){super(),this.personalInformationService=g(me),this.equipmentAllocationService=g(J),this.equipmentActivityService=g(Se),this.allocationManagementService=g($),this.masterDataService=g(fe),this.notificationStateService=g(vt),this.canViewGLAccount=!1,this.gridHeight=he,this.customFields=[],this.organizationsFilterList=[],this.agreementsFilterList=[],this.groupsFilterList=[],this.typesFilterList=[],this.uniqueIdsFilterList=[],this.equipmentAssociatedDataByOrg=[],this.equipmentAssociatedDataByAgreement=[],this.equipmentAssociatedDataByGroup=[],this.allocationsToDelete=[],this.defaultDateRange={id:U.Yesterday},this.getAgreements=(t,i)=>q(this,null,function*(){let a=(i??this.filtersForm)?.controls?.organization?.value?.id,r=a?[a]:[];try{let s=yield te(this.commonService.getActiveAgreements(r,[this.defaultLocation]));if(s[0]?.success&&s[0]?.data){let o=this.uiUtilitiesService.getDistinctObjectList(s[0].data??[]);return t||(this.agreementsFilterList=o,this.filterDefinitions[2].inputValues=o,this.filterDefinitions[2].totalRecords=o.length),o}return[]}catch(s){return[]}}),this.getOrganizations=t=>q(this,null,function*(){let i=yield this.commonService.getFilteredOrganizations(t,[this.defaultLocation],["id","name","isactive"]);return t||(this.organizationsFilterList=i.data,this.filterDefinitions[1].inputValues=this.organizationsFilterList,this.filterDefinitions[1].totalRecords=i?.totalcount??0,!this.filtersForm.controls.organization.value&&this.organizationsFilterList?.length>0&&this.filtersForm.controls.organization.setValue(this.organizationsFilterList[0]),this.filterSectionService.updateAppliedFilterIndicator$.next(null),i.data?.length>0&&this.getAgreementsByOrganization(this.filtersForm.controls.organization.value?.id??""),this.getEquipmentAssociatedData(this.filtersForm.controls.organization.value?.id),this.reloadGridData(!1,!0)),i?.data??[]}),this.setupFilterAfterInitObservable(this.onFiltersInitialized.bind(this))}ngOnInit(){this.listingPageGridKey="equipmentUnresolvedListing",this.initializeGrid(D.ALLOCATIONS_FOR_EQUIPMENT),this.commonService.getScreenNamePermissions(D.GL_ACCOUNT_ALLOCATIONS).subscribe(t=>{t[0]?.data?.view&&(this.canViewGLAccount=!0,this.setColumnDefs())}),this.initializeFilterSection(),this.mciTranslateService.onLangChange.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(()=>{this.getTranslations(),this.setColumnDefs(),this.gridApi?.refreshHeader()}),this.getTranslations(),this.getLumpNonBillSubConPerms(),this.drawerService.reloadTableAfterDrawerAction$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{t!=null&&t===!0&&this.reloadGridData()}),this.drawerService.drawerFooterAction$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>{t===c.DELETE&&this.openDeleteDialog([this.selectedRowData])}),this.mciTranslateService.onLangChange.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(()=>{this.setColumnDefs(),this.gridApi?.refreshHeader()}),this.filterSectionService.applyFilters$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>this.onApplyFilters(t)),this.filterSectionService.resetFilters$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(t=>this.onResetFilters(t))}getTranslations(){this.entity=this.mciTranslateService.getTranslation("L.Allocation"),this.entityPlural=this.mciTranslateService.getTranslation("L.Allocations"),this.fileName=this.mciTranslateService.getTranslation("L.Equipment_Unresolved"),this.addDrawerTitle=this.mciTranslateService.getTranslation("L.Add_Allocations_Title"),this.addDrawerSubtitle=this.mciTranslateService.getTranslation("L.Add_Allocations_Subtitle"),this.editDrawerSubtitle="",this.viewDrawerSubtitle=""}getLumpNonBillSubConPerms(){W({lumpSumPerms:this.commonService.getScreenNamePermissions(D.LUMP_SUM),nonBillPerms:this.commonService.getScreenNamePermissions(D.NON_BILLABLE),subConPerms:this.commonService.getScreenNamePermissions(D.SUB_CONTRACTOR)}).subscribe(({lumpSumPerms:t,nonBillPerms:i,subConPerms:e})=>{this.lumpSumPerms=t[0]?.data,this.nonBillPerms=i[0]?.data,this.subConPerms=e[0]?.data})}reloadGridData(t=!1,i=!1,e=null){t&&this.skeletonLoadingService.startGridSkeletonLoading();let a=this.getRequestPayload();this.equipmentAllocationService.getUnresolvedEquipmentAllocations(a).subscribe({next:r=>{this.checkIfDataIsRestricted(r),r&&r[0].data?(this.gridData=r[0].data,this.gridData.forEach((s,o)=>{s.consolidatedattachments=this.uiUtilitiesService.formatStringWithMultipleArray(s.consolidatedattachments),s.totalFiles=s?.consolidatedattachments?.length??0,s.timesheetdate=s.workdate,s.id=o+1,s?.othercharges===null&&(s.othercharges=0)}),this.customFields=this.mciGridService.prepareDynamicCustomFieldColumnDefs(r[0].data,"name","name","format"),i&&this.route.queryParams.subscribe(s=>{this.applyRouteFilters(s)}),e?.recordId&&(this.selectedRowData=this.gridData.find(s=>s.groupid===e.recordId),this.selectedRowData&&this.getJobDetailsDataAndOpenDrawer(this.selectedRowData,c.VIEW))):this.onAPIError()},error:()=>{this.onAPIError()}})}getRequestPayload(){if(!this.filtersForm)return null;let t=this.filtersForm.controls.organization?.value?.id,i=this.dateTimeService.getDateRangeFromDateShortcut(this.filtersForm,"timesheetDate");return{startdate:i.startDate,enddate:i.endDate.substring(0,10),organizationids:t!=null?[t]:[],agreementids:this.filtersForm.controls.agreement?.value?.map(e=>e?.id)??[],resourcegroupids:this.filtersForm.controls.group?.value?.map(e=>e?.id)??[],typeids:this.filtersForm.controls.type?.value?.map(e=>e?.id)??[],uniqueids:this.filtersForm.controls.uniqueid?.value?.map(e=>e?.id)??[],statecodes:this.filtersForm.controls.state?.value?.map(e=>e?.id)??[]}}setColumnDefs(){let t=[{headerName:_.CONTEXTMENU,cellRenderer:"materialGridMenu",cellRendererParams:{menuEvent:({type:i,value:e})=>this.contentMenuClick(i,e),buttons:this.popupOptions}},{field:"comment",headerName:this.mciTranslateService.getTranslation(_.COMMENT),cellRenderer:"commentCell"},{headerName:this.mciTranslateService.getTranslation(_.EXCEPTION),field:"exceptions",cellRenderer:"exceptionIconCell",context:{excludeExcelExport:!1,excludeImportTemplate:!1,isAutoSize:!0},cellRendererParams:i=>({iconClickEvent:e=>
1{this.onExceptionIconClick(e,i.data)}})},{field:"state",headerName:this.mciTranslateService.getTranslation("L.State"),cellRenderer:"globalStatesCellRenderer"},{field:"workdate",type:"rightAligned",headerName:this.mciTranslateService.getTranslation("L.Timesheet_Date"),valueGetter:i=>this.dateTimeService.toLocalizedDateFormat(i.data.timesheetdate),filter:"agDateColumnFilter",filterParams:{comparator:this.dateTimeService.localizedDateFilterComparator},comparator:this.dateTimeService.localizedDateComparator,context:{isAutoSize:!0}},{field:"organization.name",headerName:this.mciTranslateService.getTranslation("L.Organization"),filter:"agTextColumnFilter"},{field:"agreement.name",headerName:this.mciTranslateService.getTranslation("L.Agreement"),filter:"agTextColumnFilter",context:{isAutoSize:!0}},{field:"resourcegroup.name",headerName:this.mciTranslateService.getTranslation("L.Group"),filter:"agTextColumnFilter"},{field:"type.name",headerName:this.mciTranslateService.getTranslation("L.Type"),filter:"agTextColumnFilter"},{field:"resource.name",headerName:this.mciTranslateService.getTranslation("L.Unique_ID"),filter:"agTextColumnFilter",context:{isAutoSize:!0}},{field:"costobject.ordertype.name",headerName:this.mciTranslateService.getTranslation("L.Order_Type"),filter:"agTextColumnFilter",valueGetter:i=>this.uiUtilitiesService.getOrderTypeTranslation(i?.data?.costobject?.ordertype?.name)},{field:"costobject.purchaseorder.name",headerName:this.mciTranslateService.getTranslation("L.Purchase_Order"),filter:"agTextColumnFilter"},{field:"costobject.purchaseorderline.name",headerName:this.mciTranslateService.getTranslation("L.Purchase_Order_Line"),filter:"agTextColumnFilter"},{field:"costobject.labelname",headerName:this.mciTranslateService.getTranslation("L.Cost_Object_Type"),filter:"agTextColumnFilter"},{field:"costobject.name",headerName:this.mciTranslateService.getTranslation("L.Cost_Object"),filter:"agTextColumnFilter"},{field:"costobject.operation.name",headerName:this.mciTranslateService.getTranslation("L.Operation_Or_Activity"),filter:"agTextColumnFilter"},{field:"costobject.suboperation.name",headerName:this.mciTranslateService.getTranslation("L.Sub_Operation_Or_Element"),filter:"agTextColumnFilter"},{field:"area.name",headerName:this.mciTranslateService.getTranslation("L.Area_ID"),filter:"agTextColumnFilter",context:{isAutoSize:!0}},...this.canViewGLAccount?[{field:"glaccount.name",headerName:this.mciTranslateService.getTranslation("L.GL_Account"),filter:"agTextColumnFilter",sortable:!0,cellRenderer:i=>i.value?i.value:"\u2014",context:{isAutoSize:!0}}]:[],d({field:"hours.base",headerName:this.mciTranslateService.getTranslation("L.Base"),cellRenderer:i=>this.getCellRenderValue(i),valueGetter:i=>this.mathService.roundDisplay(i?.data?.hours?.base??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"hours.over",headerName:this.mciTranslateService.getTranslation("L.Over"),cellRenderer:i=>this.getCellRenderValue(i),valueGetter:i=>this.mathService.roundDisplay(i?.data?.hours?.over??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"hours.idle",headerName:this.mciTranslateService.getTranslation("L.Idle"),cellRenderer:i=>this.getCellRenderValue(i),valueGetter:i=>this.mathService.roundDisplay(i?.data?.hours?.idle??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"othercharges",headerName:this.mciTranslateService.getTranslation("L.Other_Charge"),cellRenderer:i=>this.getCellRenderValue(i,!0),valueGetter:i=>this.mathService.roundDisplay(i?.data?.othercharges??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"hours.total",headerName:this.mciTranslateService.getTranslation("L.Total_Hours"),cellRenderer:i=>this.getCellRenderValue(i),valueGetter:i=>this.mathService.roundDisplay(i?.data?.hours?.total??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),d({field:"cost",headerName:this.mciTranslateService.getTranslation("L.Total_Cost"),cellRenderer:i=>this.getCellRenderValue(i,!0),valueGetter:i=>this.mathService.roundDisplay(i?.data?.cost??0,!1)},this.mciGridService.getBaseDecimalColumnDefinition()),{field:"attachmentdata",headerName:this.mciTranslateService.getTranslation("L.Attachments"),cellRenderer:"materialGridIcon",headerClass:"ag-center-aligned-header",cellClass:"ag-center-aligned-cell",filter:"agNumberColumnFilter",cellRendererParams:i=>i?.data?{icon:"attach_file",isDisplayValue:!0,propertyName:"attachmentdata",displayValueCb:e=>e?.data?.totalFiles,disabled:i?.data?.totalFiles<=0,clickEvent:e=>{if(e?.consolidatedattachments?.length){let a={id:e?.id,attachmentData:e?.consolidatedattachments};this.modalService.openAttachmentModal(this.viewRef,a,this.mciTranslateService.getTranslation("L.Equipment_Unresolved_Allocation"),this.actionType,this.attachmentsPermissions,!1)}}}:{},comparator:this.compareService.consolidatedAttachmentComparator,context:{isAutoSize:!0},resizable:!1}];this.columnDefs=[...t,...this.customFields]}getCellRenderValue(t,i){let e=this.mathService.formatNumber(t?.value),a=i?t.data?.currency?.code:"";return this.mciGridService.cellWithSuffix(e,a)}
1onExceptionIconClick(t,i){if(t===Y.REVOKED){let e={exceptionIcon:t,extraData:{resourceId:i?.resource?.id,timesheetDate:i.workdate,organizationId:i.organization.id,timesheetId:i?.timesheetid,timesheetRef:i?.timesheetreference}};this.exceptionIconService.onExceptionIconClick(e)}}configurePopupOptions(){let t=[{action:c.VIEW,canAct:this.permissions?.canView},{action:c.EDIT,canAct:this.permissions?.canEdit},{action:c.DELETE,canAct:this.permissions?.canDelete}];this.popupOptions=t.filter(i=>i.canAct).map(i=>i.action)}contentMenuClick(t,i){switch(this.actionType=t,t){case this.actionList.EDIT:case this.actionList.VIEW:this.selectedRowData=i,this.getJobDetailsDataAndOpenDrawer(i,t);break;case this.actionList.DELETE:this.onMassDelete([i]);break;default:break}}getJobDetailsDataAndOpenDrawer(t,i){let e=this.uiUtilitiesService.site$.value.location_id,a=this.commonUtilitiesService.getTokenData().oid,r={OrganizationId:t.organization?.id,TimesheetDate:this.dateTimeService.toISODateFormat(t.workdate),ResourceId:t.resource?.id,AllocationIds:t?.allocations?.replaceAll('"',"").split(","),RasId:t?.activity?.rasid};W({areaIdPermissions:this.commonService.getScreenNamePermissions(D.ALLOCATIONS_FOR_AREA_ID_CHANGE),orderTypes:this.masterDataService.getOrderTypes(),locationSettings:this.commonService.getLocationSettings(e),areaIds:this.commonService.getRestrictedAreaIdsByLocation(e),resourceInfo:this.allocationManagementService.getEquipmentAllocatedResource(r),allocationInfo:this.allocationManagementService.getEquipmentRejectedAllocation(r),userInfo:this.personalInformationService.getUser(a)}).pipe(le(this.destroyRef)).subscribe(({areaIdPermissions:s,orderTypes:o,locationSettings:p,areaIds:S,resourceInfo:F,allocationInfo:n,userInfo:y})=>{let G;F[0]?.data?.length&&(G=F[0]?.data[0],G&&n&&(G.allocate=n[0].data[0].allocated,G.available=n[0].data[0].available)),this.jobDetailsData={locationSettings:p[0]?.data?.settings,areaIdEditPermission:s[0]?.data?.edit,orderTypes:o[0]?.data,areaIds:S[0]?.data?.map(Q=>({id:Q.AreaId,name:Q.AreaName,areadisplayfield:Q.AreaDisplayField})),selectedResource:G,userOrderType:y[0].data.ordertype},this.openDrawerAndSetForm(i)})}onMassDelete(t){this.openDeleteDialog(t)}openDeleteDialog(t){let i=(t??[]).map(a=>ee(d({},a),{name:a?.resource?.name??""})),e=this.modalService.openConfirmActionModal(t,this.entity,this.entityPlural,c.DELETE,j.ASYNC_CONFIRM);e.componentInstance.confirmAction$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(a=>{if(a===c.DELETE){let r=this.getDeleteRequestBody(t);this.equipmentAllocationService.deleteEquipmentAllocationsByIds(r).subscribe(s=>{e.close(),this.uiUtilitiesService.handleMassActionResponseMessage(s[0],ce.DELETE,this.entity,this.entityPlural,"",i),s[0].success&&(this.reloadGridData(!0),this.deselectRows(),this.uiUtilitiesService.closeDrawer())})}})}getDeleteRequestBody(t){this.allocationsToDelete=[];let i=1;return t.forEach(e=>{if(this.gridData.splice(e.index,1),e?.allocations){let a=e.allocations.replaceAll('"',"").split(",");this.allocationsToDelete.push({ids:a,groupkey:i,isrevoked:e.state?.id===b.REVOKED}),i++}}),{allocations:[...new Set(this.allocationsToDelete)]}}onFiltersInitialized(t){this.filtersForm=t,this.getModelValues(this.uiUtilitiesService.site$.value,!0),this.uiUtilitiesService.site$.pipe(ie(1),this.takeUntilDestroyed(this.destroyRef)).subscribe(i=>{i&&this.getModelValues(i,!1)}),this.filterSectionService.filterChanged$.pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(i=>{let e=i.selectedValue!==void 0?i.selectedValue:i.form?.controls?.[i.formControlName]?.value;if(i.isAdvancedFilter&&i.formControlName&&this.filtersForm?.controls[i.formControlName]&&this.filtersForm.controls[i.formControlName].setValue(e,{emitEvent:!1}),i.formControlName==="organization")this.agreementsFilterList=[],this.filtersForm.controls?.agreement?.reset([],{emitEvent:!1}),this.filtersForm.controls?.group?.reset([],{emitEvent:!1}),this.filtersForm.controls?.type?.reset([],{emitEvent:!1}),this.filtersForm.controls?.uniqueid?.reset([],{emitEvent:!1}),this.filterDefinitions[2].inputValues=[],this.filterDefinitions[2].totalRecords=0,this.filterSectionService.resetFormControls$.next(["agreement","group","type","uniqueid"]),this.getAgreementsByOrganization(e?.id),this.getEquipmentAssociatedData(e?.id,this.filtersForm),this.filterSectionService.updateFormAdvFilter$.next(this.filtersForm);else if(i.formControlName==="agreement"){let a=e?.map(r=>r.id)??[];this.updateChildDropdowns(a,this.filtersForm),this.filterSectionService.updateFormAdvFilter$.next(this.filtersForm)}else if(i.formControlName==="group"){let a=e?.length>0?this.equipmentAssociatedDataByAgreement.filter(s=>e.some(o=>s.groupid===o.id)):this.equipmentAssociatedDataByAgreement;
1this.typesFilterList=this.uiUtilitiesService.getDistinctObjectList(a.map(s=>({id:s.typeid,name:s.typename}))),this.filterDefinitions[4].inputValues=this.typesFilterList??[];let r=this.filtersForm.controls.type?.value??[];this.filtersForm.controls.type.setValue(r.filter(s=>this.typesFilterList.some(o=>o.id===s.id)),{emitEvent:!1}),this.equipmentAssociatedDataByGroup=a,this.pruneUniqueIdSelections(this.filtersForm),this.filterSectionService.updateFormAdvFilter$.next(this.filtersForm)}else if(i.formControlName==="type"){let a=e?.length>0?this.equipmentAssociatedDataByGroup.filter(s=>e.some(o=>s.typeid===o.id)):this.equipmentAssociatedDataByGroup;this.uniqueIdsFilterList=this.uiUtilitiesService.getDistinctObjectList(a.map(s=>({id:s.id,name:s.name}))),this.filterDefinitions[5].inputValues=this.uniqueIdsFilterList??[];let r=this.filtersForm.controls.uniqueid?.value??[];this.filtersForm.controls.uniqueid.setValue(r.filter(s=>this.uniqueIdsFilterList.some(o=>o.id===s.id)),{emitEvent:!1}),this.filterSectionService.updateFormAdvFilter$.next(this.filtersForm)}})}getModelValues(t,i){i||(this.filtersForm.controls.organization.reset(),this.filtersForm.controls.agreement.reset(),this.filtersForm.controls.group.reset(),this.filtersForm.controls.type.reset(),this.filtersForm.controls.uniqueid?.reset()),this.defaultLocation=t?.location_id,this.getOrganizations()}applyRouteFilters(t){if(t?.locationId&&t?.locationId===this.uiUtilitiesService.site$.value.location_id){t?.startDate&&t?.endDate&&(this.filtersForm.controls.timesheetDate.setValue({id:U.CustomDateRange}),this.filtersForm.controls.customStartDate.setValue(Ae.parseISODateLocal(t.startDate)),this.filtersForm.controls.customEndDate.setValue(Ae.parseISODateLocal(t.endDate))),t?.orgIds&&this.filtersForm.controls.organization.setValue(this.organizationsFilterList.find(e=>t.orgIds.includes(e.id))),this.onApplyFilters(this.filtersForm,t);let i={notificationtypes:[rt.REJECT_ALLOCATION],classifications:[et.EQUIPMENT],enddate:t.endD
1ate};this.notificationStateService.clearTypes(i).pipe(this.takeUntilDestroyed(this.destroyRef)).subscribe(e=>{e||this.notificationBarService.showErrorNotificationMessage(this.mciTranslateService.getTranslation("M.Unable_To_Update_Notifications"))})}}onApplyFilters(t,i=null){this.sortColumnAsc(t?.controls?.[nt]?.value?.id),this.filtersForm=t,this.reloadGridData(!1,!1,i)}onResetFilters(t){this.filtersForm.reset({filterSort:this.defaultFilterSort,timesheetDate:this.defaultDateRange,organization:this.organizationsFilterList[0],agreement:[],group:[],type:[],uniqueid:[],state:[]}),this.getAgreementsByOrganization(this.organizationsFilterList[0]?.id),this.getEquipmentAssociatedData(this.organizationsFilterList[0]?.id),this.filterSectionService.afterReset$.next(null),t&&this.reloadGridData()}initializeFilterSection(){let t=this.commonUtilitiesService.getTokenData().oid,i;this.personalInformationService.getDefaultDateFilter(de.UNRESOLVED,t).subscribe(e=>{i=e,i&&i.selectedvalue&&(this.defaultDateRange.id=parseInt(U[i.selectedvalue])),this.filterDefinitions=[{labelName:this.mciTranslateService.getTranslation("L.Timesheet_Date"),controlType:this.CONTROL_TYPE.DATE_SHORTCUT,disableAlphabeticalSorting:!0,isMultiSelect:!1,formControlName:"timesheetDate",inputValueLabel:"name",initialValue:this.defaultDateRange,accordionGroupName:this.mciTranslateService.getTranslation("L.Date_Range"),useSession:!0,sessionKey:z.FORM_SPECIFIC},{labelName:this.mciTranslateService.getTranslation("L.Organization"),placeholder:this.mciTranslateService.getTranslation("L.Select_Organization"),isMultiSelect:!1,inputValueLabel:"name",inputValues:this.organizationsFilterList,controlType:this.CONTROL_TYPE.PICKER,formControlName:"organization",useSession:!0,sessionKey:z.ORGANIZATION,callbackSearch:this.getOrganizations},{labelName:this.mciTranslateService.getTranslation("L.Agreement"),placeholder:this.mciTranslateService.getTranslation("L.Select_Agreements"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.agreementsFilterList,controlType:this.CONTROL_TYPE.PICKER,formControlName:"agreement",callbackSearch:this.getAgreements,totalRecords:this.agreementsFilterList?.length??0},{labelName:this.mciTranslateService.getTranslation("L.Group"),placeholder:this.mciTranslateService.getTranslation("L.Select_Groups"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.groupsFilterList,controlType:this.CONTROL_TYPE.PICKER,enableDataLoadingOnScrollOrSearch:!1,formControlName:"group"},{labelName:this.mciTranslateService.getTranslation("L.Type"),placeholder:this.mciTranslateService.getTranslation("L.Select_Types"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.typesFilterList,controlType:this.CONTROL_TYPE.PICKER,enableDataLoadingOnScrollOrSearch:!1,formControlName:"type"},{labelName:this.mciTranslateService.getTranslation("L.Unique_ID"),placeholder:this.mciTranslateService.getTranslation("L.Select_Unique_IDs"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.uniqueIdsFilterList,controlType:this.CONTROL_TYPE.PICKER,enableDataLoadingOnScrollOrSearch:!1,formControlName:"uniqueid"},{labelName:this.mciTranslateService.getTranslation("L.State"),placeholder:this.mciTranslateService.getTranslation("L.Select_States"),isMultiSelect:!0,inputValueLabel:"name",inputValues:this.globalStatesService.getAllocationGlobalStates().filter(r=>[w.REJECTED,w.VOIDED,w.REVOKED].includes(r.id)),controlType:this.CONTROL_TYPE.PICKER,enableDataLoadingOnScrollOrSearch:!1,formControlName:"state"}];let a={filterDefinitions:this.filterDefinitions,showAdvancedFilterButton:!0,associatedGridId:this.listingPageGridKey,alertLargeTimesheetDateFilter:!0};this.filterSectionService.initialize(a)})}getAgreementsByOrganization(t){this.filterDefinitions[2].inlineLoading=!0,zt.default.isEmpty(t)?this.filterDefinitions[2].inlineLoading=!1:this.commonService.getActiveAgreements([t],[this.defaultLocation]).subscribe({next:i=>{this.uiUtilitiesService.handleResponse(i)&&(this.agreementsFilterList=this.uiUtilitiesService.getDistinctObjectList(i[0]?.data??[]),this.filterDefinitions[2].inputValues=this.agreementsFilterList,this.filterDefinitions[2].totalRecords=this.agreementsFilterList.length),this.filterDefinitions[2].inlineLoading=!1},error:()=>{this.filterDefinitions[2].inlineLoading=!1}})}getEquipmentAssociatedData(t,i){let e=i??this.filtersForm;this.setChildFilterDropdownInlineLoading(!0);
1let a=this.dateTimeService.getDateRangeFromDateShortcut(e,"timesheetDate");this.equipmentActivityService.getEquipmentActivityReady({vendorids:t?[t]:[],agreementids:[],activitystartdate:a.startDate,activityenddate:a.endDate.substring(0,10)}).subscribe({next:r=>{this.equipmentAssociatedDataByOrg=r[0]?.data??[],this.updateChildDropdowns([],e),this.setChildFilterDropdownInlineLoading(!1),this.filterSectionService.updateFormAdvFilter$.next(this.filtersForm)},error:()=>this.setChildFilterDropdownInlineLoading(!1)})}updateChildDropdowns(t,i){this.equipmentAssociatedDataByAgreement=this.equipmentAssociatedDataByOrg.filter(s=>t.length>0?t.some(o=>s.agreementid===o):!0);let e=this.equipmentAssociatedDataByAgreement.map(s=>({id:s.groupid,name:s.groupname}));this.groupsFilterList=this.uiUtilitiesService.getDistinctObjectList(e),this.filterDefinitions[3].inputValues=this.groupsFilterList??[];let r=(i.controls.group?.value??[]).filter(s=>this.groupsFilterList.some(o=>o.id===s.id));i.controls.group.setValue(r,{emitEvent:!1}),this.equipmentAssociatedDataByGroup=this.equipmentAssociatedDataByAgreement.filter(s=>i.controls.group?.value?.length>0?i.controls.group.value.some(o=>s.groupid===o.id):!0),this.recomputeTypesFromGroups(i),this.pruneUniqueIdSelections(i)}setChildFilterDropdownInlineLoading(t){this.filterDefinitions[3].inlineLoading=t,this.filterDefinitions[4].inlineLoading=t,this.filterDefinitions[5].inlineLoading=t}recomputeTypesFromGroups(t){let i=t.controls.group?.value??[];if(i.length>0){let r=this.equipmentAssociatedDataByAgreement.filter(s=>i.some(o=>s.groupid===o.id));this.typesFilterList=this.uiUtilitiesService.getDistinctObjectList(r.map(s=>({id:s.typeid,name:s.typename})))}else this.typesFilterList=this.uiUtilitiesService.getDistinctObjectList(this.equipmentAssociatedDataByAgreement.map(r=>({id:r.typeid,name:r.typename})));this.filterDefinitions[4].inputValues=this.typesFilterList??[];let a=(t.controls.type?.value??[]).filter(r=>this.typesFilterList.some(s=>s.id===r.id));t.controls.type.setValue(a,{emitEvent:!1})}pruneUniqueIdSelections(t){let i=t.controls.type?.value??[];if(i.length>0){let r=this.equipmentAssociatedDataByGroup.filter(s=>i.some(o=>s.typeid===o.id));this.uniqueIdsFilterList=this.uiUtilitiesService.getDistinctObjectList(r.map(s=>({id:s.id,name:s.name})))}else this.uniqueIdsFilterList=this.uiUtilitiesService.getDistinctObjectList(this.equipmentAssociatedDataByGroup.map(r=>({id:r.id,name:r.name})));this.filterDefinitions[5].inputValues=this.uniqueIdsFilterList??[];let a=(t.controls.uniqueid?.value??[]).filter(r=>this.uniqueIdsFilterList.some(s=>s.id===r.id));t.controls.uniqueid.setValue(a,{emitEvent:!1})}openDrawerAndSetForm(t){let i=this.getDrawerHeaderLabels(t,this.selectedRowData?.resource?.name,this.selectedRowData?.organization?.name),e=new Z(t,this.selectedRowData,this.permissions,{nonBillPerms:this.nonBillPerms,lumpSumPerms:this.lumpSumPerms,subConPerms:this.subConPerms,jobDetailsData:this.jobDetailsData}),a=new ue(Ge,i.title,this.selectedRowData?.organization?.name,null,this.drawerSizesEnum.MEDIUM,null,e);this.drawerService.updateDrawerContent(a),this.drawerService.openDrawer()}static{this.\u0275fac=function(i){return new(i||l)}}static{this.\u0275cmp=L({type:l,selectors:[["app-equipment-unresolved"]],features:[k],decls:4,vars:13,consts:[["associatedGridId","equipmentUnresolvedListing",3,"isDataRestrictedChange","isDataRestricted","showLongDateAlertForDataRestriction","formName","totalFilterCount"],[1,"mci-ui-card-flat-border"],[1,"mci-ui-table"],[3,"addClick","gridReady","massDelete","rowDataUpdated","columnDefinition","fileName","getRowIdCB","gridData","gridHeight","key","showAddButton","showGridDeleteButton","showGridStatusButton"]],template:function(i,e){i&1&&(m(0,"app-filter-section",0),ne("isDataRestrictedChange",function(r){return oe(e.isDataRestricted,r)||(e.isDataRestricted=r),r}),f(),m(1,"div",1)(2,"div",2)(3,"app-common-data-grid",3),v("addClick",function(){return e.contentMenuClick(e.actionList.ADD,null)})("gridReady",function(r){return e.onGridReady(r)})("massDelete",function(){return e.onMassDelete(e.gridApi==null?null:e.gridApi.getSelectedRows())})("rowDataUpdated",function(r){return e.onRowDataUpdated(r)}),f()()()),i&2&&(se("isDataRestricted",e.isDataRestricted),h("showLongDateAlertForDataRestriction",!0)("formName",e.listingPageGridKey)("totalFilterCount",6),u(3),h("columnDefinition",e.columnDefs)("fileName",e.fileName)("getRowIdCB",e.getRowIdCallBack)("gridData",e.gridData)("gridHeight",e.gridHeight)("key",e.listingPageGridKey)("showAddButton",!1)("showGridDeleteButton",e.permissions==null?null:e.permissions.canDelete)("showGridStatusButton",!1))},dependencies:[ge,N],encapsulation:2})}}return l})();var Ir=(()=>{class l{constructor(){this.tabs=[{label:Re.NOT_ALLOCATED,screenName:D.ALLOCATIONS_FOR_EQUIPMENT,component:Mt},{label:Re.ALLOCATED,screenName:D.ALLOCATIONS_FOR_EQUIPMENT,component:Ut},{label:Re.UNRESOLVED,screenName:D.ALLOCATIONS_FOR_EQUIPMENT,component:jt}]}static{this.\u0275fac=function(i){return new(i||l)}}static{this.\u0275cmp=L({type:l,selectors:[["app-equipment-allocation-management"]],decls:1,vars:1,consts:[[3,"tabs"]],template:function(i,e){i&1&&A(0,"mci-tab-group",0),i&2&&h("tabs",e.tabs)},dependencies:[qt],encapsulation:2})}}return l})();export{Ir as EquipmentAllocationManagementComponent};
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.