When creating project quotation, there is a field that we can fill called WorkerSalesTaker. This field accepts workers that have a valid employment date.
So what I did, is first i looked for users email who have a person (to make sure email is unique)
Then i looked for workers in general even if they don't have a user, because project quotation allow adding a worker that doesn't have an email (i know that the system allows more than worker to have the same email, but there is nothing more to do, that's why I checked the user's person at first)
How can I simplify this or is what i did good?
private void setWorkerSalesResponsible(LogisticsElectronicAddressLocator _email, SalesQuotationTable _salesQuotationTable) { HcmWorker hcmWorker; LogisticsElectronicAddress logisticsElectronicAddress; Logisticslocation logisticslocation; DirPartyLocation dirPartyLocation; DirPerson dirPerson; DirPersonUser dirPersonUser; userInfo userInfo; select userInfo where userInfo.networkAlias == _email join RecId from dirPersonUser where dirPersonUser.User == userInfo.id join RecId from hcmWorker where hcmWorker.Person == dirPersonUser.PersonParty; if(userInfo) { _salesQuotationTable.WorkerSalesResponsible = hcmWorker.RecId; } else { select firstonly RecId from logisticsElectronicAddress where logisticsElectronicAddress.Locator == _email && logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Email join RecId from logisticslocation where logisticslocation.RecId == logisticsElectronicAddress.Location join RecId from dirPartyLocation where dirPartyLocation.Location == logisticslocation.RecId join RecId from dirPerson where dirPerson.RecId == dirPartyLocation.Party join RecId from hcmWorker where hcmworker.Person == dirPerson.RecId; if(hcmWorker) { _salesQuotationTable.WorkerSalesResponsible = hcmWorker.RecId; } } }
Also DirPersonUserEntity has this where condition but I don't know from where it came as there are no ranges in the entity. And not sure if i should handle this in my above code