import { ROTypeEnum } from '../enums/code-enums'; import { EstimateStatusEnum, LaborStatusEnum, PayTypeEnum, ROStatusEnum } from '../enums/enums'; import { Add, Divide } from '../shared/math-operations'; import { PrintSharedService } from '../shared/shared-print.service'; import { MyDate } from '../utils/my-date'; import { TrUtils } from '../utils/tr-utils'; import { ROTotalsService } from './ro-totals.service'; export class EstPrintService { static GetTaxAmountFromGroup(item: any, taxGroupKey: string, taxCode: string, fallbackKey: string) { const groupedTaxes = item?.[taxGroupKey]; if (Array.isArray(groupedTaxes)) { const matchedTaxes = groupedTaxes.filter((tax: any) => tax?.Code === taxCode); if (matchedTaxes.length !== 0) { return matchedTaxes.reduce((total: number, tax: any) => Add(total, tax?.Amt), 0); } } return TrUtils.SetValueToZeroIfNull(item?.[fallbackKey]); } static GetEstimatePrintInfo(OriginalROData: any, OriginalCustomerData: any, OriginalVehicleData: any, OriginalEntityData: any, image: any, Payee: any, InsCompanyName: any, AsCustomerOnly: boolean, AsInsuranceOnly: boolean, AsCustomerAndInsurance: boolean, AsInsuranceOrCustomer: boolean, TaxCodes: any, OverallEst: boolean, SuppEstIndex: any, AsEstimated: boolean, isInitial: boolean, isReverse: boolean, Consolidate: boolean) { let ROPrintData: any = {}; let argROData = TrUtils.Stringify(OriginalROData); argROData.Comps = TrUtils.IsNull(argROData.Comps) ? [] : argROData.Comps; argROData.Ops = TrUtils.IsNull(argROData.Ops) ? [] : argROData.Ops; argROData.Parts = TrUtils.IsNull(argROData.Parts) ? [] : argROData.Parts; argROData.Colli = TrUtils.IsNull(argROData.Colli) ? [] : argROData.Colli; let IncludeGST: boolean = TrUtils.isTaxable(argROData.Settings.Tax); ROPrintData = this.GetROBasicDetailsForPrint(ROPrintData, argROData, OriginalVehicleData, OverallEst, isInitial); let SType: any; if (!TrUtils.IsNull(OriginalROData.SType)) { SType = OriginalROData.SType } ROPrintData = this.GetPrintConditionsBasedOnInput(ROPrintData, IncludeGST, Payee, AsCustomerOnly, AsInsuranceOnly, AsCustomerAndInsurance, AsInsuranceOrCustomer, SType, Consolidate); ROPrintData.Entity = PrintSharedService.GetFormattedEntityDataForPrint(OriginalEntityData, "Estimate", OriginalROData); ROPrintData = PrintSharedService.GetEntityHeaderStyles(ROPrintData, OriginalEntityData, image); if (Payee === PayTypeEnum.Insurance) { ROPrintData = this.GetInsDetailsForPrint(ROPrintData, InsCompanyName, argROData, AsEstimated); } argROData = this.IfInitialEstimateChangeStatus(argROData, AsEstimated); argROData = this.CheckStatusAndChangeDeclinedItemsToNew(argROData); argROData = this.GetValidItemsForTotals(argROData); if (!OverallEst) { argROData = this.GetItemsBySuppEstIndex(argROData, SuppEstIndex); if (!TrUtils.IsNull(SuppEstIndex)) { let Index: any = argROData.SuppEst.findIndex((supp: any) => { return supp.Id === SuppEstIndex; }) if (Index !== -1 && !TrUtils.IsNull(argROData.SuppEst[Index].Date)) { ROPrintData.CrDate = MyDate.ConvertUTCDateToReadable(argROData.SuppEst[Index].Date); } } } argROData.Ops = this.SeparateROLaborByPType(argROData.Ops, Payee, AsCustomerOnly, AsInsuranceOnly, AsEstimated); argROData.Parts = this.SeparateROPartsByPType(argROData.Parts, Payee, AsCustomerOnly, AsInsuranceOnly, AsEstimated); argROData.Colli = this.SeparateROCollisionsByItems(argROData.Colli, argROData.Ops, argROData.Parts); // argROData = this.ResetDescForPrint(argROData); argROData.Parts = this.ResetQtyAndUoM(argROData.Parts); if (AsInsuranceOnly || AsCustomerAndInsurance || AsInsuranceOrCustomer) { ROPrintData.ShowAccParts = true; } else { ROPrintData.ShowAccParts = this.CheckAndShowItemsAsAR(argROData); } argROData = this.ReverseItemsForROPrint(argROData, isReverse); let finalTotalsData: any = ROTotalsService.GetTotalsValue(argROData, TaxCodes, false, true, true, ROPrintData.Entity.Round, ROPrintData.Entity); finalTotalsData = this.CheckAndGetCombinedTotals(AsCustomerAndInsurance, AsInsuranceOrCustomer, finalTotalsData, ROPrintData.Entity.DecimalsNumber); finalTotalsData.Settings = TrUtils.Stringify(argROData.Settings); if (AsCustomerOnly) { if (ROPrintData.ShowAccParts) { finalTotalsData = this.GetLaborAndPartItemsAfterDisc(finalTotalsData, ROPrintData.Entity.DecimalsNumber); } else { finalTotalsData = this.GetDetailedInfoForItems(finalTotalsData, ROPrintData.Entity.DecimalsNumber); finalTotalsData = this.GetCustTaxInfo(finalTotalsData, IncludeGST, TaxCodes, ROPrintData.Entity.DecimalsNumber); } } if (AsCustomerAndInsurance) { finalTotalsData = this.GetCombinedInfoForItems(finalTotalsData, ROPrintData.Entity.DecimalsNumber); } if (AsInsuranceOrCustomer) { finalTotalsData.Parts = this.GetSplitInfoForParts(finalTotalsData.Parts, ROPrintData.Entity.DecimalsNumber); } if (IncludeGST) { finalTotalsData.ShowDetailedLaborTaxInfo = this.CheckLaborTaxItemIndex(finalTotalsData.Ops) !== -1; finalTotalsData.ShowDetailedPartTaxInfo = this.CheckPartTaxItemIndex(finalTotalsData.Parts) !== -1; } else { finalTotalsData.ShowDetailedLaborTaxInfo = false; finalTotalsData.ShowDetailedPartTaxInfo = false; } ROPrintData = TrUtils.ConcatObjects(ROPrintData, finalTotalsData); if (ROPrintData.ShowAccParts) { ROPrintData = this.ConvertItemsAsAR(ROPrintData, Consolidate, ROPrintData.Entity.DecimalsNumber); } ROPrintData.Colli = this.EmptyInvalidCollisionRepairItems(ROPrintData.Colli); ROPrintData = this.GetLineTotals(ROPrintData, IncludeGST, AsCustomerOnly, AsInsuranceOnly, Consolidate, ROPrintData.Entity.DecimalsNumber); ROPrintData.PrintInfo = this.PrepareFormatForEstPrint(ROPrintData, SuppEstIndex, OverallEst, ROTypeEnum.Estimate, AsEstimated); ROPrintData = this.CheckAndCombineDescMPNForAR(ROPrintData.Entity.MPN, ROPrintData); ROPrintData.Vehicle = PrintSharedService.GetVehicleFromServiceAndFormatData(OriginalVehicleData); ROPrintData.Customer = PrintSharedService.GetCustomerFromServiceAndFormatData(OriginalCustomerData); if ((Payee === PayTypeEnum.Customer || AsCustomerOnly) && !ROPrintData.ConsolidateGST) { // if (PrintSharedService.CheckItemIndexWithDisc(ROPrintData) !== -1) { ROPrintData.ShowDiscountColumn = (ROPrintData.Settings.DiscLvl === 'ITM' || ROPrintData.Settings.DiscLvl === 'RECITM') ? true : false; // } } return ROPrintData; } static GetROBasicDetailsForPrint(ROPrintData: any, argROData: any, Product: any, OverallEst: any, isInitial: boolean) { ROPrintData.CrDate = MyDate.ConvertUTCDateToReadable(argROData.CrDate); if (!isInitial) { ROPrintData.PrDate = MyDate.ConvertUTCDateToReadable(argROData.PrDate); } else { delete ROPrintData.PrDate; } ROPrintData.MIn = Product.MIn; ROPrintData._id = argROData.Code; if (isInitial || TrUtils.IsNull(argROData.SuppEst) || argROData.SuppEst.length === 0 || OverallEst) { ROPrintData.Type = 'Estimate'; ROPrintData.HeaderName = 'Estimate'; } else { ROPrintData.Type = 'Supplementary Estimate'; ROPrintData.HeaderName = 'Supplementary Estimate'; } ROPrintData.SuppEst = argROData.SuppEst; return ROPrintData; } static GetPrintConditionsBasedOnInput(ROPrintData: any, IncludeGST: boolean, Payee: any, AsCustomerOnly: boolean, AsInsuranceOnly: boolean, AsCustomerAndInsurance: boolean, AsInsuranceOrCustomer: boolean, SType: any, Consolidate: boolean) { ROPrintData.Payee = Payee; ROPrintData.AsCustomerOnly = AsCustomerOnly; ROPrintData.AsInsuranceOnly = AsInsuranceOnly; ROPrintData.AsCustomerAndInsurance = AsCustomerAndInsurance; ROPrintData.AsInsuranceOrCustomer = AsInsuranceOrCustomer; ROPrintData.IncludeGST = IncludeGST; ROPrintData.ConsolidateGST = Consolidate; ROPrintData.Consolidate = Consolidate; ROPrintData.ShowIGST = (TrUtils.IsNull(SType) || (SType === 'Intra')) ? false : true; ROPrintData.ShowTaxColumn = (IncludeGST && !Consolidate) ? true : false; // ROPrintData.ShowDiscountColumn = (Payee === PayTypeEnum.Customer || AsCustomerOnly) ? true : false; return ROPrintData; } static GetInsDetailsForPrint(ROPrintData: any, InsCompanyName: any, argROData: any, AsEstimated: boolean) { if (TrUtils.IsNull(argROData.Ins)) { argROData.Ins = this.GetDefualtInsData(); } ROPrintData.InsComp = InsCompanyName; if (!AsEstimated) { ROPrintData.SurName = argROData.Ins.SName; ROPrintData.SurEmail = argROData.Ins.SEmail; ROPrintData.SurPhone = argROData.Ins.SPhone; } ROPrintData.PolType = argROData.Ins.Type; ROPrintData.PolNo = argROData.Ins.PolNo; return ROPrintData; } static GetDefualtInsData() { let ROInsData: any = { SName: '', SEmail: '', SPhone: '', PolNo: '' }; return ROInsData; } static IfInitialEstimateChangeStatus(argROData: any, AsEstimated: boolean) { if (AsEstimated) { argROData.Sts = ROStatusEnum.New; argROData.Ops = this.ChangeLaborStatusToNew(argROData.Ops); argROData.Parts = this.ChangePartStatusToNew(argROData.Parts); argROData.Colli = this.ChangeColliStatusToNew(argROData.Colli); } return argROData; } static ChangeLaborStatusToNew(Operations: any) { Operations.forEach((Labor: any) => { Labor.Sts = LaborStatusEnum.New; }); return Operations; } static ChangePartStatusToNew(Parts: any) { Parts.forEach((Part: any) => { if (!TrUtils.IsNull(Part.CollId)) { Part.Sts = LaborStatusEnum.New; } }); return Parts; } static ChangeColliStatusToNew(Collisions: any) { Collisions.forEach((Collision: any) => { Collision.Sts = LaborStatusEnum.New; }); return Collisions; } static CheckStatusAndChangeDeclinedItemsToNew(argROData: any) { if (argROData.Sts === ROStatusEnum.New || argROData.Sts === ROStatusEnum.WtngForAppr) { argROData = this.ChangeDeclinedStatusToNew(argROData); } return argROData; } static ChangeDeclinedStatusToNew(argROData: any) { argROData.Ops = this.ChangeDeclinedLaborStatusToNew(argROData.Ops); argROData.Parts = this.ChangeDeclinedPartStatusToNew(argROData.Parts); argROData.Colli = this.ChangeDeclinedColliStatusToNew(argROData.Colli); return argROData; } static ChangeDeclinedLaborStatusToNew(Operations: any) { Operations.forEach((Labor: any) => { if (Labor.Sts === LaborStatusEnum.Declined) { Labor.Sts = LaborStatusEnum.New; } }); return Operations; } static ChangeDeclinedPartStatusToNew(Parts: any) { Parts.forEach((Part: any) => { if (!TrUtils.IsNull(Part.CollId) && Part.Sts === LaborStatusEnum.Declined) { Part.Sts = LaborStatusEnum.New; } }); return Parts; } static ChangeDeclinedColliStatusToNew(Collisions: any) { Collisions.forEach((Collision: any) => { if (Collision.Sts === LaborStatusEnum.Declined) { Collision.Sts = LaborStatusEnum.New; } }); return Collisions; } static GetValidItemsForTotals(RecordData: any) { let RecordStatus: string = RecordData.Sts; RecordData.Ops = this.GetLaborByRecordAndLaborStatus(RecordStatus, RecordData.Ops); RecordData.Parts = this.GetPartsByRecordAndPartStatus(RecordStatus, RecordData.Parts); RecordData.Colli = this.GetCollisionByRecordAndColliStatus(RecordStatus, RecordData.Colli); return RecordData; } static GetLaborByRecordAndLaborStatus(RecordStatus: string, Operations: any) { if (RecordStatus === ROStatusEnum.Cancelled || RecordStatus === ROStatusEnum.Declined) { return Operations; } else { return this.GetValidROLaborListByStatus(Operations); } } static GetValidROLaborListByStatus(Operations: any) { let opCodesList: any[] = Operations.filter((Operation: any) => { if (this.CheckOperationHasActiveStatus(Operation.Sts)) { return Operation; } }); return opCodesList; } static CheckOperationHasActiveStatus(Status: string) { return (Status !== LaborStatusEnum.Cancelled && Status !== LaborStatusEnum.Declined) ? true : false; } static GetPartsByRecordAndPartStatus(RecordStatus: any, Parts: any) { if (RecordStatus === ROStatusEnum.Cancelled || RecordStatus === ROStatusEnum.Declined) { return Parts; } else { return this.GetValidROPartsListByStatus(Parts); } } static GetValidROPartsListByStatus(Parts: any) { let PartsList: any[] = Parts.filter((Part: any) => { if (TrUtils.IsNull(Part.CollId)) { return Part; } else { if (this.CheckOperationHasActiveStatus(Part.Sts)) { return Part; } } }); return PartsList; } static GetCollisionByRecordAndColliStatus(RecordStatus: string, Collisions: any) { if (RecordStatus === ROStatusEnum.Cancelled || RecordStatus === ROStatusEnum.Declined) { return Collisions; } else { return this.GetValidROCollisionListByStatus(Collisions); } } static GetValidROCollisionListByStatus(Collisions: any) { let collList: any[] = Collisions.filter((Collision: any) => { if (this.CheckOperationHasActiveStatus(Collision.Sts)) { return Collision; } }); return collList; } static GetItemsBySuppEstIndex(argROData: any, SuppEstIndex: any) { if (TrUtils.IsNull(SuppEstIndex)) { SuppEstIndex = null; } argROData.Ops = argROData.Ops.filter((Labor: any) => { if (TrUtils.IsNull(Labor.SuppEst)) { Labor.SuppEst = null; } return Labor.SuppEst === SuppEstIndex; }); argROData.Parts = argROData.Parts.filter((Part: any) => { if (TrUtils.IsNull(Part.SuppEst)) { Part.SuppEst = null; } return Part.SuppEst === SuppEstIndex; }); argROData.Colli = argROData.Colli.filter((Collision: any) => { if (TrUtils.IsNull(Collision.SuppEst)) { Collision.SuppEst = null; } return Collision.SuppEst === SuppEstIndex; }); return argROData; } static SeparateROLaborByPType(Labors: any, PType: any, CustomerOnly: boolean, InsuranceOnly: boolean, AsEstimated: boolean) { let LaborList: any[] = []; LaborList = Labors.filter((Labor: any) => { if (AsEstimated) { if (PType === PayTypeEnum.Customer) { return Labor.PBy === PayTypeEnum.Customer; } else { return (Labor.PBy === PayTypeEnum.Insurance || Labor.PBy === PayTypeEnum.Shared); } } else { if (PType === PayTypeEnum.Customer) { return Labor.PBy === PType; } else { if (CustomerOnly) { return (Labor.PBy === PayTypeEnum.Shared) && !TrUtils.IsZero(Labor.Pr); } else { if (InsuranceOnly) { return (Labor.PBy === PayTypeEnum.Insurance || Labor.PBy === PayTypeEnum.Shared) && !TrUtils.IsZero(Labor.AssPr); } else { return (Labor.PBy === PayTypeEnum.Insurance || Labor.PBy === PayTypeEnum.Shared); } } } } }); return LaborList; } static SeparateROPartsByPType(Parts: any, PType: any, CustomerOnly: boolean, InsuranceOnly: boolean, AsEstimated: boolean) { let PartsList: any[] = []; PartsList = Parts.filter((Part: any) => { if (AsEstimated) { if (PType === PayTypeEnum.Customer) { return Part.PBy === PType; } else { return (Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared); } } else { if (PType === PayTypeEnum.Customer) { return Part.PBy === PType; } else { if (CustomerOnly) { return (Part.PBy === PayTypeEnum.Shared) && !TrUtils.IsZero(Part.UnPr); } else { if (InsuranceOnly) { return (Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared) && !TrUtils.IsZero(Part.AssPr); } else { return (Part.PBy === PayTypeEnum.Insurance || Part.PBy === PayTypeEnum.Shared); } } } } }); return PartsList; } static SeparateROCollisionsByItems(Collisions: any, Ops: any, Parts: any) { let CollisionList: any[] = Collisions.filter((Collision: any) => { let LaborIndex: any = Ops.findIndex((Labor: any) => { return Labor.CollId === Collision._id; }); let PartIndex: any = Parts.findIndex((Part: any) => { return Part.CollId === Collision._id; }); if (LaborIndex !== -1 || PartIndex !== -1) { return Collision; } }); return CollisionList; } static ResetQtyAndUoM(Parts: any) { Parts.forEach((Item: any) => { if (!TrUtils.IsZero(Item.Qty) && !TrUtils.CheckInvalidSelect(Item.UoM)) { Item.QtyAndUoM = Item.Qty + ' ' + Item.UoM; } }); return Parts; } static CheckAndShowItemsAsAR(argROData: any) { let AccPartsIndex: any = argROData.Parts.findIndex((Part: any) => { return !TrUtils.IsNull((Part.CollId)); }); let InsLaborIndex: any = argROData.Ops.findIndex((Labor: any) => { return !TrUtils.IsNull((Labor.CollId)); }); if (AccPartsIndex !== -1 || InsLaborIndex !== -1) { return true; } else { return false; } } static ConvertItemsAsAR(ROPrintData: any, Consolidate: boolean, DecimalsNumber: number) { ROPrintData.Colli.forEach((Collision: any) => { Collision = this.ResetItemsDataById(Collision, ROPrintData.Ops, ROPrintData.Parts); }); ROPrintData.Ops.forEach((Labor: any) => { // console.log('Labor', Labor); Labor.NetAmt = TrUtils.FixPriceValue(Labor.NetAmt, DecimalsNumber); Labor.CCGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'CTaxes', 'CGST', 'CCGST'), DecimalsNumber); Labor.CSGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'CTaxes', 'SGST', 'CSGST'), DecimalsNumber); Labor.CIGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'CTaxes', 'IGST', 'CIGST'), DecimalsNumber); Labor.Disc = TrUtils.FixPriceValue(Labor.Disc, DecimalsNumber); Labor.AssPr = TrUtils.FixPriceValue(Labor.AssPr, DecimalsNumber); Labor.ACGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'ATaxes', 'CGST', 'ACGST'), DecimalsNumber); Labor.ASGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'ATaxes', 'SGST', 'ASGST'), DecimalsNumber); Labor.AIGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'ATaxes', 'IGST', 'AIGST'), DecimalsNumber); if (Consolidate) { if (Labor.PBy === PayTypeEnum.Customer) { Labor.EstPr = TrUtils.FixPriceValue(Labor.CustAfterTax, DecimalsNumber); Labor.Pr = TrUtils.FixPriceValue(Labor.CustAfterTax, DecimalsNumber); } else { Labor.EstPr = TrUtils.FixPriceValue(Labor.InsAfterTax, DecimalsNumber); Labor.Pr = TrUtils.FixPriceValue(Labor.InsAfterTax, DecimalsNumber); } } else { Labor.EstPr = TrUtils.FixPriceValue(Labor.EstPr, DecimalsNumber); Labor.Pr = TrUtils.FixPriceValue(Labor.Pr, DecimalsNumber); } Labor.ECGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'ETaxes', 'CGST', 'ECGST'), DecimalsNumber); Labor.ESGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'ETaxes', 'SGST', 'ESGST'), DecimalsNumber); Labor.EIGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'ETaxes', 'IGST', 'EIGST'), DecimalsNumber); if (TrUtils.IsNull(Labor.CollId)) { let LaborColli: any = { _id: Labor._id, Desc: Labor.Desc, PBy: Labor.PBy, Op_Id: Labor.Op_Id, Qty: 0, Sts: Labor.Sts }; LaborColli.RRFData = Labor; LaborColli.SuppEst = Labor.SuppEst; ROPrintData.Colli.push(LaborColli); } }); ROPrintData.Parts.forEach((Part: any) => { // console.log('Part', Part); Part.NetAmt = TrUtils.FixPriceValue(Part.NetAmt, DecimalsNumber); Part.UnAmt = TrUtils.FixPriceValue(Part.UnAmt, DecimalsNumber); Part.CCGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Part, 'CTaxes', 'CGST', 'CCGST'), DecimalsNumber); Part.CSGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Part, 'CTaxes', 'SGST', 'CSGST'), DecimalsNumber); Part.CIGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Part, 'CTaxes', 'IGST', 'CIGST'), DecimalsNumber); Part.Disc = TrUtils.FixPriceValue(Part.Disc, DecimalsNumber); Part.AssPr = TrUtils.FixPriceValue(Part.AssPr, DecimalsNumber); Part.AssAmt = TrUtils.FixPriceValue(Part.AssAmt, DecimalsNumber); Part.ACGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Part, 'ATaxes', 'CGST', 'ACGST'), DecimalsNumber); Part.ASGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Part, 'ATaxes', 'SGST', 'ASGST'), DecimalsNumber); Part.AIGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Part, 'ATaxes', 'IGST', 'AIGST'), DecimalsNumber); Part.EstPr = TrUtils.FixPriceValue(Part.EstPr, DecimalsNumber); if (Consolidate) { if (Part.PBy === PayTypeEnum.Customer) { Part.EstPr = TrUtils.FixPriceValue((Part.CustAfterTax / Part.Qty), DecimalsNumber); Part.UnPr = TrUtils.FixPriceValue((Part.CustAfterTax / Part.Qty), DecimalsNumber); } else { Part.EstPr = TrUtils.FixPriceValue((Part.InsAfterTax / Part.Qty), DecimalsNumber); Part.UnPr = TrUtils.FixPriceValue((Part.InsAfterTax / Part.Qty), DecimalsNumber); } } else { Part.EstPr = TrUtils.FixPriceValue(Part.EstPr, DecimalsNumber); Part.UnPr = TrUtils.FixPriceValue(Part.UnPr, DecimalsNumber); } Part.EstAmt = TrUtils.FixPriceValue(Part.EstAmt, DecimalsNumber); Part.ECGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Part, 'ETaxes', 'CGST', 'ECGST'), DecimalsNumber); Part.ESGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Part, 'ETaxes', 'SGST', 'ESGST'), DecimalsNumber); Part.EIGST = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Part, 'ETaxes', 'IGST', 'EIGST'), DecimalsNumber); if (TrUtils.IsNull(Part.CollId)) { let LaborIndex: any = ROPrintData.Ops.findIndex((Labor: any) => { return Labor._id === Part.OpId; }); let OpsStatus: string = ROPrintData.Ops[LaborIndex].Sts; let PartColli: any = { _id: Part._id, Desc: Part.Desc, PBy: Part.PBy, Sts: OpsStatus }; PartColli.PartData = Part; PartColli.SuppEst = Part.SuppEst; ROPrintData.Colli.push(PartColli); } }); ROPrintData.Ops = []; ROPrintData.Parts = []; return ROPrintData; } static ResetItemsDataById(Collision: any, AddedOperations: any[], AddedParts: any[]) { Collision.PartData = TrUtils.IsNull(Collision.PartId) ? null : this.GetPartDataById(Collision.PartId, AddedParts); Collision.RRFData = TrUtils.IsNull(Collision.RRFId) ? null : this.GetLaborDataById(Collision.RRFId, AddedOperations); Collision.PtngData = TrUtils.IsNull(Collision.PainId) ? null : this.GetLaborDataById(Collision.PainId, AddedOperations); Collision.DtngData = TrUtils.IsNull(Collision.RepId) ? null : this.GetLaborDataById(Collision.RepId, AddedOperations); return Collision; } static GetPartDataById(PartId: any, AddedParts: any[]) { let partIndex: any = AddedParts.findIndex((Part: any) => { return Part._id === PartId; }); return (partIndex !== -1) ? AddedParts[partIndex] : null; } static GetLaborDataById(LaborId: any, AddedOperations: any[]) { let laborIndex: any = AddedOperations.findIndex((Labor: any) => { return Labor._id === LaborId; }); return (laborIndex !== -1) ? AddedOperations[laborIndex] : null; } static EmptyInvalidCollisionRepairItems(Colli: any) { Colli.forEach((CollisionItem: any) => { if (!TrUtils.IsNull(CollisionItem.PartData) && !this.CheckOperationHasActiveStatus(CollisionItem.PartData.Sts)) { CollisionItem.PartData.EstPr = null; CollisionItem.PartData.AssPr = null; CollisionItem.PartData.UnPr = null; CollisionItem.PartData.Disc = 0; CollisionItem.PartData.RecDisc = 0; } if (!TrUtils.IsNull(CollisionItem.RRFData) && !this.CheckOperationHasActiveStatus(CollisionItem.RRFData.Sts)) { CollisionItem.RRFData.EstPr = null; CollisionItem.RRFData.AssPr = null; CollisionItem.RRFData.Pr = null; CollisionItem.RRFData.Disc = 0; CollisionItem.RRFData.RecDisc = 0; } if (!TrUtils.IsNull(CollisionItem.DtngData) && !this.CheckOperationHasActiveStatus(CollisionItem.DtngData.Sts)) { CollisionItem.DtngData.EstPr = null; CollisionItem.DtngData.AssPr = null; CollisionItem.DtngData.Pr = null; CollisionItem.DtngData.Disc = 0; CollisionItem.DtngData.RecDisc = 0; } if (!TrUtils.IsNull(CollisionItem.PtngData) && !this.CheckOperationHasActiveStatus(CollisionItem.PtngData.Sts)) { CollisionItem.PtngData.EstPr = null; CollisionItem.PtngData.AssPr = null; CollisionItem.PtngData.Pr = null; CollisionItem.PtngData.Disc = 0; CollisionItem.PtngData.RecDisc = 0; } }); return Colli; } static GetLineTotals(ROPrintData: any, IncludeGST: boolean, AsCustomerOnly: boolean, AsInsuranceOnly: boolean, Consolidate: boolean, DecimalsNumber: number) { ROPrintData.Ops.forEach((Labor: any) => { Labor.LineTotal = this.GetLaborLineTotal(Labor, IncludeGST, AsCustomerOnly, AsInsuranceOnly, Consolidate, DecimalsNumber); }); ROPrintData.Parts.forEach((Part: any) => { Part.LineTotal = this.GetPartLineTotal(Part, IncludeGST, AsCustomerOnly, AsInsuranceOnly, Consolidate, DecimalsNumber); }); ROPrintData.Colli.forEach((Collision: any) => { let LineTotal: number = 0; if (!TrUtils.IsNull(Collision.PartData)) { LineTotal += this.GetCollisionPartLineTotal(Collision.PartData, AsCustomerOnly, AsInsuranceOnly, Consolidate); } if (!TrUtils.IsNull(Collision.RRFData)) { LineTotal += this.GetCollisionLaborLineTotal(Collision.RRFData, AsCustomerOnly, AsInsuranceOnly, Consolidate); } if (!TrUtils.IsNull(Collision.PtngData)) { LineTotal += this.GetCollisionLaborLineTotal(Collision.PtngData, AsCustomerOnly, AsInsuranceOnly, Consolidate); } if (!TrUtils.IsNull(Collision.DtngData)) { LineTotal += this.GetCollisionLaborLineTotal(Collision.DtngData, AsCustomerOnly, AsInsuranceOnly, Consolidate); } Collision.LineTotal = TrUtils.FixPriceValue(LineTotal, DecimalsNumber); }); return ROPrintData; } static GetCollisionPartLineTotal(PartData: any, AsCustomerOnly: boolean, AsInsuranceOnly: boolean, Consolidate: boolean) { let LineTotal: number = 0; if (AsCustomerOnly) { if (Consolidate) { LineTotal = PartData.CustAfterTax; } else { LineTotal = PartData.CustAfterPartDisc; } } else if (AsInsuranceOnly) { if (Consolidate) { LineTotal = PartData.InsAfterTax; } else { LineTotal = PartData.InsAfterPartDisc; } } else { if (Consolidate) { LineTotal = PartData.InsAfterTax + PartData.CustAfterTax; } else { LineTotal = PartData.InsAfterPartDisc + PartData.CustAfterPartDisc; } } return LineTotal; } static GetCollisionLaborLineTotal(LaborData: any, AsCustomerOnly: boolean, AsInsuranceOnly: boolean, Consolidate: boolean) { let LineTotal: number = 0; if (AsCustomerOnly) { if (Consolidate) { LineTotal = LaborData.CustAfterTax; } else { LineTotal = LaborData.CustAfterLaborDisc; } } else if (AsInsuranceOnly) { if (Consolidate) { LineTotal = LaborData.InsAfterTax; } else { LineTotal = LaborData.InsAfterLaborDisc; } } else { if (Consolidate) { LineTotal = LaborData.InsAfterTax + LaborData.CustAfterTax; } else { LineTotal = LaborData.InsAfterLaborDisc + LaborData.CustAfterLaborDisc; } } return LineTotal; } static GetLaborLineTotal(LaborData: any, IncludeGST: boolean, AsCustomerOnly: boolean, AsInsuranceOnly: boolean, Consolidate: boolean, DecimalsNumber: number) { let LineTotal: number = 0; if (AsCustomerOnly) { if (IncludeGST || Consolidate) { LineTotal = LaborData.CustAfterTax; } else { LineTotal = LaborData.CustAfterLaborDisc; } } else if (AsInsuranceOnly) { if (IncludeGST || Consolidate) { LineTotal = LaborData.InsAfterTax; } else { LineTotal = LaborData.InsAfterLaborDisc; } } else { if (IncludeGST || Consolidate) { LineTotal = LaborData.CustAfterTax + LaborData.InsAfterTax; } else { LineTotal = LaborData.InsAfterLaborDisc + LaborData.CustAfterLaborDisc; } } return TrUtils.FixedTo(LineTotal, DecimalsNumber); } static GetPartLineTotal(PartData: any, IncludeGST: boolean, AsCustomerOnly: boolean, AsInsuranceOnly: boolean, Consolidate: boolean, DecimalsNumber: number) { let LineTotal: number = 0; if (AsCustomerOnly) { if (IncludeGST || Consolidate) { LineTotal = PartData.CustAfterTax; } else { LineTotal = PartData.CustAfterPartDisc; } } else if (AsInsuranceOnly) { if (IncludeGST || Consolidate) { LineTotal = PartData.InsAfterTax; } else { LineTotal = PartData.InsAfterPartDisc; } } else { if (IncludeGST || Consolidate) { LineTotal = PartData.InsAfterTax + PartData.CustAfterTax; } else { LineTotal = PartData.InsAfterPartDisc + PartData.CustAfterPartDisc; } } return TrUtils.FixedTo(LineTotal, DecimalsNumber); } static ReverseItemsForROPrint(argROData: any, isReverse: boolean) { if (isReverse) { argROData.Comps = TrUtils.IsNull(argROData.Comps) ? [] : argROData.Comps.reverse(); argROData.Ops = TrUtils.IsNull(argROData.Ops) ? [] : argROData.Ops.reverse(); argROData.Parts = TrUtils.IsNull(argROData.Parts) ? [] : argROData.Parts.reverse(); argROData.Colli = TrUtils.IsNull(argROData.Colli) ? [] : argROData.Colli.reverse(); } else { argROData.Comps = TrUtils.IsNull(argROData.Comps) ? [] : argROData.Comps; argROData.Ops = TrUtils.IsNull(argROData.Ops) ? [] : argROData.Ops; argROData.Parts = TrUtils.IsNull(argROData.Parts) ? [] : argROData.Parts; argROData.Colli = TrUtils.IsNull(argROData.Colli) ? [] : argROData.Colli; } let ReversedLabors: any[] = []; argROData.Comps.forEach((Complaint: any) => { argROData.Ops.forEach((Labor: any) => { if (Labor.CompId === Complaint._id) { ReversedLabors.push(Labor); } }); }); argROData.Ops.forEach((Labor: any) => { if (TrUtils.IsNull(Labor.CompId)) { ReversedLabors.push(Labor); } }); argROData.Ops = ReversedLabors; let ReversedParts: any[] = []; argROData.Ops.forEach((Labor: any) => { argROData.Parts.forEach((Part: any) => { if (TrUtils.IsNull(Part.CollId) && (Part.OpId === Labor._id)) { ReversedParts.push(Part); } }); }); argROData.Parts.forEach((Part: any) => { if (!TrUtils.IsNull(Part.CollId)) { ReversedParts.push(Part); } }); argROData.Parts = ReversedParts; return argROData; } static CheckAndGetCombinedTotals(AsCustomerAndInsurance: boolean, AsInsuranceOrCustomer: boolean, finalTotalsData: any, DecimalsNumber: number) { if (AsCustomerAndInsurance || AsInsuranceOrCustomer) { finalTotalsData.InsLaborTotalBeforeDisc = TrUtils.FixPriceValue((Number(finalTotalsData.CustLaborTotalBeforeDisc) + Number(finalTotalsData.InsLaborTotalBeforeDisc)), DecimalsNumber); finalTotalsData.InsLaborDiscTotal = TrUtils.FixPriceValue((Number(finalTotalsData.CustLaborDiscTotal) + Number(finalTotalsData.InsLaborDiscTotal)), DecimalsNumber); finalTotalsData.InsLaborCGST = TrUtils.FixPriceValue((Number(finalTotalsData.CustLaborCGST) + Number(finalTotalsData.InsLaborCGST)), DecimalsNumber); finalTotalsData.InsLaborSGST = TrUtils.FixPriceValue((Number(finalTotalsData.CustLaborSGST) + Number(finalTotalsData.InsLaborSGST)), DecimalsNumber); finalTotalsData.InsLaborIGST = TrUtils.FixPriceValue((Number(finalTotalsData.CustLaborIGST) + Number(finalTotalsData.InsLaborIGST)), DecimalsNumber); finalTotalsData.InsPartIGST = TrUtils.FixPriceValue((Number(finalTotalsData.CustPartIGST) + Number(finalTotalsData.InsPartIGST)), DecimalsNumber); finalTotalsData.InsPartsTotalBeforeDisc = TrUtils.FixPriceValue((Number(finalTotalsData.CustPartsTotalBeforeDisc) + Number(finalTotalsData.InsPartsTotalBeforeDisc)), DecimalsNumber); finalTotalsData.InsPartsDiscTotal = TrUtils.FixPriceValue((Number(finalTotalsData.CustPartsDiscTotal) + Number(finalTotalsData.InsPartsDiscTotal)), DecimalsNumber); finalTotalsData.InsPartCGST = TrUtils.FixPriceValue((Number(finalTotalsData.CustPartCGST) + Number(finalTotalsData.InsPartCGST)), DecimalsNumber); finalTotalsData.InsPartSGST = TrUtils.FixPriceValue((Number(finalTotalsData.CustPartSGST) + Number(finalTotalsData.InsPartSGST)), DecimalsNumber); finalTotalsData.InsLaborTotalAfterTax = TrUtils.FixPriceValue((Number(finalTotalsData.CustLaborAfterTax) + Number(finalTotalsData.InsLaborTotalAfterTax)), DecimalsNumber); finalTotalsData.InsPartsTotalAfterTax = TrUtils.FixPriceValue((Number(finalTotalsData.CustPartAfterTax) + Number(finalTotalsData.InsPartsTotalAfterTax)), DecimalsNumber); finalTotalsData.FixedInsTotal = TrUtils.FixPriceValue((Number(finalTotalsData.FixedTotal) + Number(finalTotalsData.FixedInsTotal)), DecimalsNumber); finalTotalsData.InsTotalRoundedBy = TrUtils.FixPriceValue((Math.round(Number(finalTotalsData.FixedInsTotal)) - Number(finalTotalsData.FixedInsTotal)), DecimalsNumber); finalTotalsData.InsRoundedTotal = TrUtils.FixPriceValue(Math.round(Number(finalTotalsData.FixedInsTotal)), DecimalsNumber); let InsTaxGroupData: any[] = []; finalTotalsData.InsTaxGroupData.forEach((InsTaxGroup: any) => { let index: any = finalTotalsData.CustTaxGroupData.findIndex((CustTaxGroup: any) => { return CustTaxGroup.HSN === InsTaxGroup.HSN; }); if (index !== -1) { InsTaxGroup.TotalTaxAmount = TrUtils.FixPriceValue((Number(InsTaxGroup.TotalTaxAmount) + Number(finalTotalsData.CustTaxGroupData[index].TotalTaxAmount)), DecimalsNumber); InsTaxGroup.TotalTaxableAmount = TrUtils.FixPriceValue((Number(InsTaxGroup.TotalTaxableAmount) + Number(finalTotalsData.CustTaxGroupData[index].TotalTaxableAmount)), DecimalsNumber); } InsTaxGroupData.push(InsTaxGroup); }); finalTotalsData.InsTaxGroupData = InsTaxGroupData; } return finalTotalsData; } static GetDetailedInfoForItems(ROTotalsData: any, DecimalsNumber: number) { ROTotalsData.Ops = this.GetCustLaborPrintInfo(ROTotalsData.Ops, DecimalsNumber); ROTotalsData.Parts = this.GetCustItemsPrintInfo(ROTotalsData.Parts, ROTotalsData.Ops, DecimalsNumber); return ROTotalsData; } static GetCustLaborPrintInfo(LaborList: any, DecimalsNumber: number) { LaborList.forEach((Labor: any) => { Labor.HSN = Labor.SAC; if (Labor.Sts === LaborStatusEnum.New || Labor.Sts === LaborStatusEnum.WtngForAppr) { Labor.UnPr = TrUtils.FixPriceValue(Labor.EstPr, DecimalsNumber); Labor.Disc = 0; Labor.Perc = ''; } else { Labor.UnPr = TrUtils.FixPriceValue(Labor.Pr, DecimalsNumber); } }); return LaborList; } static GetCustItemsPrintInfo(Items: any, LaborList: any, DecimalsNumber: number) { Items.forEach((Item: any) => { let LaborStatus = TrUtils.IsNull(Item.CollId) ? this.GetPartParentStatus(Item.OpId, LaborList) : Item.Sts; if (LaborStatus === LaborStatusEnum.New || LaborStatus === LaborStatusEnum.WtngForAppr) { Item.UnPr = TrUtils.FixPriceValue(Item.EstPr, DecimalsNumber); Item.Disc = 0; Item.Perc = ''; } else { Item.UnPr = TrUtils.FixPriceValue(Item.UnPr, DecimalsNumber); } }); return Items; } static GetCustTaxInfo(ROTotalsData: any, IncludeGST: boolean, TaxCodes: any[], DecimalsNumber: number) { ROTotalsData.Ops = this.GetCustLaborTaxInfo(ROTotalsData.Ops, IncludeGST, TaxCodes, DecimalsNumber); ROTotalsData.Parts = this.GetCustPartTaxInfo(ROTotalsData.Parts, ROTotalsData.Ops, IncludeGST, TaxCodes, DecimalsNumber); return ROTotalsData; } static GetCustLaborTaxInfo(LaborList: any, IncludeGST: boolean, TaxCodes: any[], DecimalsNumber: number) { LaborList.forEach((Labor: any) => { if (Labor.Sts === LaborStatusEnum.New || Labor.Sts === LaborStatusEnum.WtngForAppr) { if (IncludeGST) { Labor.CGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'ETaxes', 'CGST', 'ECGST'), DecimalsNumber); Labor.SGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'ETaxes', 'SGST', 'ESGST'), DecimalsNumber); Labor.IGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'ETaxes', 'IGST', 'EIGST'), DecimalsNumber); } else { Labor.CGSTAmt = 0; Labor.SGSTAmt = 0; Labor.IGSTAmt = 0; } } else { if (IncludeGST) { Labor.CGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'CTaxes', 'CGST', 'CCGST'), DecimalsNumber); Labor.SGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'CTaxes', 'SGST', 'CSGST'), DecimalsNumber); Labor.IGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Labor, 'CTaxes', 'IGST', 'CIGST'), DecimalsNumber); } else { Labor.CGSTAmt = 0; Labor.SGSTAmt = 0; Labor.IGSTAmt = 0; } } Labor.CGSTPerc = PrintSharedService.GetCGSTValueBasedOnTaxCode(Labor.TCode, TaxCodes); Labor.SGSTPerc = PrintSharedService.GetSGSTValueBasedOnTaxCode(Labor.TCode, TaxCodes); Labor.IGSTPerc = PrintSharedService.GetIGSTValueBasedOnTaxCode(Labor.TCode, TaxCodes); }); return LaborList; } static GetCustPartTaxInfo(Items: any, LaborList: any, IncludeGST: boolean, TaxCodes: any[], DecimalsNumber: number) { Items.forEach((Item: any) => { let LaborStatus = TrUtils.IsNull(Item.CollId) ? this.GetPartParentStatus(Item.OpId, LaborList) : Item.Sts; if (LaborStatus === LaborStatusEnum.New || LaborStatus === LaborStatusEnum.WtngForAppr) { if (IncludeGST) { Item.CGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Item, 'ETaxes', 'CGST', 'ECGST'), DecimalsNumber); Item.SGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Item, 'ETaxes', 'SGST', 'ESGST'), DecimalsNumber); Item.IGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Item, 'ETaxes', 'IGST', 'EIGST'), DecimalsNumber); } else { Item.CGSTAmt = 0; Item.SGSTAmt = 0; Item.IGSTAmt = 0; } } else { if (IncludeGST) { Item.CGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Item, 'CTaxes', 'CGST', 'CCGST'), DecimalsNumber); Item.SGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Item, 'CTaxes', 'SGST', 'CSGST'), DecimalsNumber); Item.IGSTAmt = TrUtils.FixPriceValue(this.GetTaxAmountFromGroup(Item, 'CTaxes', 'IGST', 'CIGST'), DecimalsNumber); } else { Item.CGSTAmt = 0; Item.SGSTAmt = 0; Item.IGSTAmt = 0; } } Item.CGSTPerc = PrintSharedService.GetCGSTValueBasedOnTaxCode(Item.TCode, TaxCodes); Item.SGSTPerc = PrintSharedService.GetSGSTValueBasedOnTaxCode(Item.TCode, TaxCodes); Item.IGSTPerc = PrintSharedService.GetIGSTValueBasedOnTaxCode(Item.TCode, TaxCodes); }); return Items; } static GetLaborAndPartItemsAfterDisc(ROTotalsData: any, DecimalsNumber: number) { ROTotalsData.Ops = this.GetCustLaborAfterDiscPrintInfo(ROTotalsData.Ops, DecimalsNumber); ROTotalsData.Parts = this.GetCustItemsAfterDiscPrintInfo(ROTotalsData.Parts, ROTotalsData.Ops, DecimalsNumber); return ROTotalsData; } static GetCustLaborAfterDiscPrintInfo(LaborList: any, DecimalsNumber: number) { LaborList.forEach((Labor: any) => { Labor.HSN = Labor.SAC; if (Labor.Sts === LaborStatusEnum.New || Labor.Sts === LaborStatusEnum.WtngForAppr) { Labor.UnPr = TrUtils.FixPriceValue(Labor.EstPr, DecimalsNumber); } else { Labor.UnPr = TrUtils.FixPriceValue(Labor.NetAmt, DecimalsNumber); } }); return LaborList; } static GetCustItemsAfterDiscPrintInfo(Items: any, LaborList: any, DecimalsNumber: number) { Items.forEach((Item: any) => { let LaborStatus = TrUtils.IsNull(Item.CollId) ? this.GetPartParentStatus(Item.OpId, LaborList) : Item.Sts; if (LaborStatus === LaborStatusEnum.New || LaborStatus === LaborStatusEnum.WtngForAppr) { Item.UnPr = TrUtils.FixPriceValue(Item.EstPr, DecimalsNumber); } else { Item.UnPr = TrUtils.FixedTo(Divide(Item.NetAmt, Item.Qty), DecimalsNumber); } }); return Items; } static GetPartParentStatus(PartOpId: any, LaborList: any) { let index: number = LaborList.findIndex((Labor: any) => { return Labor._id === PartOpId; }); return LaborList[index].Sts; } static GetCombinedInfoForItems(ROTotalsData: any, DecimalsNumber: number) { ROTotalsData.Ops = this.GetLaborCombinedPrintInfo(ROTotalsData.Ops, DecimalsNumber); ROTotalsData.Parts = this.GetItemsCombinedPrintInfo(ROTotalsData.Parts, DecimalsNumber); return ROTotalsData; } static GetLaborCombinedPrintInfo(LaborList: any, DecimalsNumber: number) { LaborList.forEach((Labor: any) => { Labor.AssPr = TrUtils.FixedTo(Add(Labor.AssPr, Labor.NetAmt), DecimalsNumber); }); return LaborList; } static GetItemsCombinedPrintInfo(Items: any, DecimalsNumber: number) { Items.forEach((Item: any) => { Item.AssPr = TrUtils.FixedTo(Divide(Add(Item.AssAmt, Item.NetAmt), Item.Qty), DecimalsNumber); }); return Items; } static GetSplitInfoForParts(Items: any, DecimalsNumber: number) { Items.forEach((Item: any) => { Item.UnPr = TrUtils.FixedTo(Divide(Item.NetAmt, Item.Qty), DecimalsNumber); }); return Items; } static CheckLaborTaxItemIndex(LaborList: any[]) { let TaxIndex: any = LaborList.findIndex((Labor: any) => { if (!TrUtils.CheckInvalidSelect(Labor.TCode)) { return Labor; } }); return TaxIndex; } static CheckPartTaxItemIndex(PartsList: any[]) { let TaxIndex: any = PartsList.findIndex((Part: any) => { if (!TrUtils.CheckInvalidSelect(Part.TCode)) { return Part; } }); return TaxIndex; } static PrepareFormatForEstPrint(ROPrintData: any, SuppEstCodeValue: any, OverAllEst: boolean, argROType: any, AsEstimated: boolean) { let PrintInfo: any[] = []; if (OverAllEst === true) { let ROLaborParts: any = this.GetFormatForEstPrint(null, null, ROPrintData, argROType, AsEstimated); PrintInfo.push(ROLaborParts); ROPrintData.SuppEst.forEach((SuppEstCode: any, index: any) => { let ROPrintInfo: any = this.GetFormatForEstPrint(SuppEstCode.Id, index, ROPrintData, argROType, AsEstimated); PrintInfo.push(ROPrintInfo); }); } else { let SuppEstIndex: any; if (!TrUtils.IsNull(SuppEstCodeValue)) { SuppEstIndex = ROPrintData.SuppEst.findIndex((SuppEst: any) => { return SuppEst.Id === SuppEstCodeValue; }); if (SuppEstIndex === -1) { SuppEstIndex = null; } } let ROLaborParts: any = this.GetFormatForEstPrint(SuppEstCodeValue, SuppEstIndex, ROPrintData, argROType, AsEstimated); PrintInfo.push(ROLaborParts); } return PrintInfo; } static GetFormatForEstPrint(SuppEstCodeValue: any, SuppEstIndex: any, ROPrintData: any, argROType: any, AsEstimated: boolean) { let ROLaborParts: any = {}; if (!TrUtils.IsNull(SuppEstIndex)) { ROLaborParts.Text = 'Supp.Est -' + (SuppEstIndex + 1); } ROLaborParts.Ops = this.SeparateLaborListByPTypeAndSuppIndex(ROPrintData.Ops, SuppEstCodeValue); ROLaborParts.Parts = this.SeparateOnlyPartsByPTypeAndSuppIndex(ROPrintData.Parts, SuppEstCodeValue); ROLaborParts.Colli = this.SeparateCollisionBySuppIndex(ROPrintData.Colli, SuppEstCodeValue); if (AsEstimated) { ROLaborParts.Sts = EstimateStatusEnum.New; } else { ROLaborParts.Sts = EstimateStatusEnum.Approved; } ROLaborParts.Type = argROType; return ROLaborParts; } static SeparateLaborListByPTypeAndSuppIndex(Operations: any, SuppEstCodeValue: any) { let Ops: any[] = []; Ops = Operations.filter((Operation: any) => { if (TrUtils.IsNull(Operation.SuppEst)) { Operation.SuppEst = null; } return Operation.SuppEst === SuppEstCodeValue; }); return Ops; } static SeparateOnlyPartsByPTypeAndSuppIndex(Parts: any, SuppEstCodeValue: any) { let SParts: any[] = []; SParts = Parts.filter((Part: any) => { if (TrUtils.IsNull(Part.SuppEst)) { Part.SuppEst = null; } return Part.SuppEst === SuppEstCodeValue; }); return SParts; } static SeparateCollisionBySuppIndex(Collisions: any, SuppEstCodeValue: any) { let FilteredCollisions: any[] = []; FilteredCollisions = Collisions.filter((Collision: any) => { if (TrUtils.IsNull(Collision.SuppEst)) { Collision.SuppEst = null; } if (Collision.SuppEst === SuppEstCodeValue) { return Collision; } }); return FilteredCollisions; } static CheckAndCombineDescMPNForAR(PrintPartNo: boolean, ROPrintData: any) { if (PrintPartNo) { ROPrintData.PrintInfo.forEach((PrintData: any) => { PrintData.Colli.forEach((Collision: any) => { if (!TrUtils.IsNull(Collision.PartData) && !TrUtils.IsEmpty(Collision.PartData.MPN)) { Collision.Desc = Collision.Desc + '/' + Collision.PartData.MPN; } }); }); } return ROPrintData; } }