11import cloneDeep from "lodash/cloneDeep" ;
22import _ from "lodash" ;
33import { WorksService } from "../../elements/Works" ;
4+ import HrmsService from "../../elements/HRMS" ;
45import { convertEpochToDate } from "../../../utils/pt" ;
56
67const createProjectsArray = ( t , project , searchParams , headerLocale ) => {
@@ -129,7 +130,6 @@ const createProjectsArray = (t, project, searchParams, headerLocale) => {
129130 return totalProjects ;
130131}
131132
132-
133133export const WorksSearch = {
134134 searchEstimate : async ( tenantId = "pb.jalandhar" , filters = { } ) => {
135135
@@ -147,51 +147,45 @@ export const WorksSearch = {
147147 const response = await WorksService ?. loiSearch ( { tenantId, filters} )
148148 return response ?. letterOfIndents
149149 } ,
150- viewProjectDetailsScreen : async (
151- t ,
152- tenantId ,
153- searchParams ,
154- filters = { limit : 10 , offset : 0 , includeAncestors : true , includeDescendants : true } ,
155- headerLocale
156- ) => {
150+ viewProjectDetailsScreen : async ( t , tenantId , searchParams , filters = { limit : 10 , offset : 0 , includeAncestors : true , includeDescendants : true } , headerLocale ) => {
157151 const response = await WorksService ?. searchProject ( tenantId , searchParams , filters ) ;
158152
159-
153+ //Categoring the response into an object of searched project and its sub-projects ( if any )
154+ //searched projects will have basic details, project details and financial details
155+ //subprojects will be shown in a table similar to what create project has
160156 let projectDetails = {
161- searchedProject : {
162- basicDetails : { } ,
163- details : {
164- projectDetails : [ ] ,
157+ searchedProject : {
158+ basicDetails : { } ,
159+ details : {
160+ projectDetails : [ ] ,
161+ financialDetails : [ ]
162+ }
165163 } ,
166- } ,
167- } ;
168-
169- if ( response ?. Project ) {
170- let projects = createProjectsArray ( t , response ?. Project , searchParams , headerLocale ) ;
171-
172- //searched Project details
173- projectDetails . searchedProject [ "basicDetails" ] = projects ?. searchedProject ?. basicDetails ;
174- projectDetails . searchedProject [ "details" ] [ "projectDetails" ] = {
175- applicationDetails : [
176- projects ?. searchedProject ?. headerDetails ,
177- projects ?. searchedProject ?. projectDetails ,
178- projects ?. searchedProject ?. locationDetails ,
179- projects ?. searchedProject ?. documentDetails ,
180- ] ,
181- } ; //rest categories will come here
164+ subProjects : [ ]
182165 }
183-
184- return {
185- projectDetails : response ?. Project ? projectDetails : [ ] ,
186- response : response ?. Project ,
187- processInstancesDetails : [ ] ,
188- applicationData : { } ,
189- workflowDetails : [ ] ,
190- applicationData : { } ,
191- isNoDataFound : response ?. Project ?. length === 0 ,
192- } ;
193- } ,
194166
167+ //Upon Search, we will get a response of one Project which will be our Searched Projects
168+ //That project will have descendants, which will be the part of Sub-Projects.
169+
170+ let projects = createProjectsArray ( t , response ?. Projects , searchParams , headerLocale ) ;
171+ //searched Project details
172+ projectDetails . searchedProject [ 'basicDetails' ] = projects ?. searchedProject ?. basicDetails ;
173+ projectDetails . searchedProject [ 'details' ] [ 'projectDetails' ] = { applicationDetails : [ projects ?. searchedProject ?. departmentDetails , projects ?. searchedProject ?. workTypeDetails , projects ?. searchedProject ?. locationDetails , projects ?. searchedProject ?. documentDetails ] } ; //rest categories will come here
174+ projectDetails . searchedProject [ 'details' ] [ 'financialDetails' ] = { applicationDetails : [ projects ?. searchedProject ?. financialDetails ] } ; //rest categories will come here
175+
176+ if ( response ?. Projects ?. [ 0 ] ?. descendants ) {
177+ projects = createProjectsArray ( t , response ?. Projects ?. [ 0 ] ?. descendants , searchParams , headerLocale ) ;
178+ //all details of searched project will come here
179+ projectDetails . subProjects ?. push ( projects ?. subProjects ) ;
180+ }
181+ return {
182+ projectDetails : projectDetails ,
183+ processInstancesDetails : [ ] ,
184+ applicationData : { } ,
185+ workflowDetails : [ ] ,
186+ applicationData :{ }
187+ }
188+ } ,
195189 viewEstimateScreen : async ( t , tenantId , estimateNumber ) => {
196190
197191
0 commit comments