Im am learning C# and am making a Payroll Add-On for SAP Business One.
I have completed the payroll process that calculates netpay, gross pay, PAYE, earnings, deductions etc. These calculations for each employee are entered into a temporary process data table.
I now want to do a monthly rollover (close the current month). To do so, I have to do some validation to make sure that the calculations were done correctly before removing contents from the temp process data table to a permanent one.
I want to do this by comparing two lists.
The 1st is drawn from Employee Master Data in SAP and it contains employee IDs, names, telephones, salary units etc. I have selected employeeIDs only.
The 2nd is drawn from Process_Data_Temp and it contains employee IDs, net pay (U_PD_code = SYS001) etc.
I want to match this list by making sure that all the empIDs in 1st are contained in the 2nd (exactly) and that the net pay in the 2nd list is not null ie (U_PD_code where == SYS001 is not null or empty) etc. .
I want to do three comparisons based on salary unit ie. Monthly = M, SemiMonthly =S and Weekly = W.
Right now I’m interested in Monthly.
The field salary unit is in Employee master data but not in the process data temp table so I’m not sure how I will get distinct empIDs that are on monthly pay in the temp table in order to do the comparison. I am comparing monthly employees first.
Process_Data_Temp fields
Code Name, U_Tax_year, U_Employee_ID, U_Process_month, U_PD_code U_Amount, U_Balance,
U_Employer_cont_amnt
How does one do this?
My Code So Far
private void DoMonthEndRollover()
{
// Get service instances needed
var getAllEmployees = Program.Kernel.Get<IEmployeeService>().GetAllEmployees().Where(x => x.salaryUnit.ToString() == "M");
var tempProcessData = Program.Kernel.Get<IProcessDataTempService>().GetAllProcessDataTemps();
// Get all employee IDs from first list
var employeeIdList = (from el in getAllEmployees select el.empID).Distinct();
// Get information from second list
var tempList = (from tl in tempProcessData orderby tl.U_Employee_ID select tl).Distinct(); ......not finished
// Check if all Employee IDs have net pay (Contained in Process Data Temporary table)
}
NB: The Process Data Temporary table contains calculations of all employees whether monthly, semimonthly or weekly.
I hope I am clear enough
Assuming that
employeeIDListandtempListare both lists of integers you can useIEnumerable.Intersectto find elements that are in both lists.If the output list is is the same length as your input list then they are identical.
However, in the first instance check that your two lists are the same length. If they aren’t then the process has failed. Only do the
Intersectcheck if both lists are the same length.There is also
IEnumerable.Exceptmethod that: