Hi Experts,
I'm facing a challenge with this customization to sort Labor Items on the Time Card Entry screen. The goal is to default an employee's department-specific labor items to the top of the list, with the remaining items following.
I've written the following code for this purpose, but it doesn't seem to be sorting the items as expected. Interestingly, when I tried using an SQL query, it worked as intended.
Code Snippets.
using PX.Data;
using PX.Objects.IN;
using PX.Objects.PM;
using static PX.Objects.AP.APGenerateIntercompanyBillsFilter;
using static PX.Objects.CR.CRCaseClassLaborMatrix;
namespace PX.Objects.EP
{
[PXNonInstantiatedExtension]
public class EP_TimeCardMaint_EPTimeCardSummaryWithInfo_ExistingColumn : PXCacheExtension<PX.Objects.EP.TimeCardMaint.EPTimeCardSummaryWithInfo>
{
#region LabourItemID
[PMLaborItem(typeof(projectID), typeof(earningType), typeof(Select<EPEmployee, Where<EPEmployee.bAccountID, Equal<Current<EPTimeCard.employeeID>>>>))]
[PXSelector(typeof(Search2<InventoryItem.inventoryID,
LeftJoin<EPDepartment,
On<InventoryItem.cOGSSubID, Equal<EPDepartment.expenseSubID>,
Or<EPDepartment.expenseSubID, NotEqual<InventoryItem.cOGSSubID>>>,
LeftJoin<EPEmployee,
On<EPEmployee.departmentID, Equal<EPDepartment.departmentID>>>>,
Where<InventoryItem.itemType, Equal<INItemTypes.laborItem>,
And<EPEmployee.bAccountID, Equal<Current<EPTimeCard.employeeID>>>>,
OrderBy<Desc<Case<Where<EPDepartment.expenseSubID, Equal<InventoryItem.cOGSSubID>>, EPDepartment.expenseSubID>>>>
),
SubstituteKey = typeof(InventoryItem.inventoryCD),
DescriptionField = typeof(InventoryItem.descr)
)]
[PXCustomizeSelectorColumns(
typeof(PX.Objects.IN.InventoryItem.inventoryCD),
typeof(PX.Objects.IN.InventoryItem.descr),
typeof(PX.Objects.IN.InventoryItem.itemClassID),
typeof(PX.Objects.IN.InventoryItem.itemStatus),
typeof(PX.Objects.IN.InventoryItem.itemType),
typeof(PX.Objects.IN.InventoryItem.baseUnit),
typeof(PX.Objects.IN.InventoryItem.salesUnit),
typeof(PX.Objects.IN.InventoryItem.purchaseUnit),
typeof(PX.Objects.IN.InventoryItem.basePrice))]
public int? LabourItemID { get; set; }
#endregion
}
}
SQL Query I used which Work expected.
SELECT
ii.inventoryID,
ii.inventoryCD AS SubstituteKey,
ii.descr AS DescriptionField,
ii.itemClassID,
ii.itemStatus,
ii.itemType,
ii.baseUnit,
ii.salesUnit,
ii.purchaseUnit,
ii.basePrice
FROM
InventoryItem AS ii
LEFT JOIN
EPDepartment AS dep
ON
(ii.cOGSSubID = dep.expenseSubID OR dep.expenseSubID <> ii.cOGSSubID)
LEFT JOIN
EPEmployee AS emp
ON
emp.departmentID = dep.departmentID
WHERE
ii.itemType = 'L'
AND emp.baccountid =2892
ORDER BY
CASE
WHEN dep.expenseSubID = ii.cOGSSubID THEN dep.expenseSubID
END DESC;
Any help on this will greatly appriciated.
Thank you!!!