Hey all,
Not at all new to Epicor but definitely fairly new to E10 and C#. I’m learning as I go but will be taking some courses soon. I have a need to calculate LaborHed hours but output into single days (in a csv) within a date range. If the user has a single clock in and out within a day, I’ve got this down and can calculate OT hours and such easily. However, if they clock out and in for lunch, lets say, I get multiple LaborHed records for that employee for that day. Not what they, my employer, wants. I reached out in another developer forum for help and someone got me close, very close. I was wondering if someone here can help me nail the rest down.I will paste my code below. The problem with the code below is that I cannot figure out how to include EmployeeNum in my select along with the ClockInDate which is the Key and the calculated work hours as you will see below. Any help would be oh so appreciated.
foreach (var ttUD06_iterator in (from ttUD06_Row in ttUD06
where ttUD06_Row.Company == Session.CompanyID
select ttUD06_Row))
{
var ttUD06Row = ttUD06_iterator;
Outfile = @"\\localhost\EpicorData\PayrollHours\PayrollHours_TEST_Merc.csv";
/* Write column headers */
OString = "Key,#Last,#First,#ClockInDate,E_Reg_Hours,E_Ovt_Hours,E_DT_Hours,E_TP_Hours,E_Tv O_Hours,E_Tv D_Hours,E_For_Dollars"; //Mercantile Format
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@Outfile, false))
{
file.WriteLine(OString);
}
var empWorkTimes = Db.LaborHed.Where(x => x.ClockInDate >= (DateTime?)ttUD06Row.Date01 && x.ClockInDate <= (DateTime?)ttUD06Row.Date02 && x.EmployeeNum == "2436")
.OrderBy(x => x.EmployeeNum)
.GroupBy(x => x.ClockInDate)
.Select(x => new { ClockInDate = x.Key, EmployeeNum = x.Select(employee => employee.EmployeeNum), WorkHours = x.Sum(l => (l.ClockOutTime - l.ClockInTime) - (l.LunchInTime - l.LunchOutTime)) });
if (empWorkTimes != null)
{
foreach (var WorkDetails in empWorkTimes)
{
strEmpNum = Convert.ToString(WorkDetails.EmployeeNum);
this.PublishInfoMessage(System.Convert.ToString(WorkDetails.EmployeeNum),Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"","");
EmpBasic = (from EmpBasic_Row in Db.EmpBasic
where EmpBasic_Row.EmpID == strEmpNum && EmpBasic_Row.ShopEmployee_c == true
select EmpBasic_Row).FirstOrDefault();
if (EmpBasic != null)
{
this.PublishInfoMessage(System.Convert.ToString(WorkDetails.EmployeeNum),Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"","");
}
}
}
ttUD06Row.CheckBox01 = false;
}