SIMS 7 - Exporting Staff Absences
This code sample shows how staff absences for a period can be exported from SIMS 7.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace SIMSInterface
{
public class StaffAbsenceExport
{
private const string formatter = "<{0}>{1}</{0}>";
private static DateTime _StartDate = DateTime.Now.AddYears(-1);
private static DateTime _EndDate = DateTime.Now;
public static XmlDocument Export(string FileName, DateTime startDate, DateTime endDate, List<string> ExcludeTypes)
{
_StartDate = startDate;
_EndDate = endDate;
return Export(FileName, ExcludeTypes);
}
public static XmlDocument Export(string FileName, List<string> ExcludeTypes)
{
SIMS.Processes.EmployeeCache.Populate();
SIMS.Processes.BrowseEmployee employees = new SIMS.Processes.BrowseEmployee();
employees.Load(SIMS.Processes.EmployeeFilter.All, "%", "%", "%", "%", "%", false, DateTime.Now);
StringBuilder b = new StringBuilder();
b.Append("<Staff>");
b.AppendFormat("<StartDate>{0}</StartDate>", _StartDate.ToShortDateString());
b.AppendFormat("<EndDate>{0}</EndDate>", _EndDate.ToShortDateString());
foreach (SIMS.Entities.EmployeeSummary empSum in employees.Employees)
{
SIMS.Processes.EditEmployee editEmployee = new SIMS.Processes.EditEmployee();
editEmployee.Load(empSum.ID, System.DateTime.Now);
string payNo = editEmployee.Employee.EmployeePayrollNumber;
string NINumber = editEmployee.Employee.NINumber;
if (NINumber == "") // Only checking NI number for Wirral.
{
// Can't be of interest to HR & P - nothing to match on
}
else
{
foreach (SIMS.Entities.Absence empAbsence in editEmployee.Employee.Absences.Value)
{
// Find any absences within the date range and remove them
// HR system is the source of truth
// Ignore non payroll absences which will be exluded from SWC
if (empAbsence.StartDate >= _StartDate)
{
if (!ExcludeTypes.Contains(empAbsence.AbsenceType.Description))
{
if ((empAbsence.EndDate == null || empAbsence.EndDate <= _EndDate))
{
b.Append("<Absence>");
b.AppendFormat(formatter, "NINumber", NINumber);
b.AppendFormat(formatter, "PayrollNumber", payNo);
b.AppendFormat(formatter, "StartDate", empAbsence.StartDateAttribute.Value.Date);
b.AppendFormat(formatter, "ID", empAbsence.ID);
b.AppendFormat(formatter, "EndDate", empAbsence.EndDateAttribute.Value.Date);
b.AppendFormat(formatter, "StartTime", empAbsence.StartTimeAttribute.Value);
b.AppendFormat(formatter, "EndTime", empAbsence.EndTimeAttribute.Value);
b.AppendFormat(formatter, "Days", empAbsence.NumberOfDaysAttribute.Value);
b.AppendFormat(formatter, "Hours", empAbsence.NumberOfHoursAttribute.Value);
b.AppendFormat(formatter, "PayRate", empAbsence.AbsencePayRate.Description);
b.AppendFormat(formatter, "AbsenceType", empAbsence.AbsenceType.Description);
b.Append("</Absence>");
}
}
}
}
}
}
b.Append("</Staff>");
XmlDocument d = new XmlDocument();
string y = b.ToString();
d.InnerXml = b.ToString();
d.Save(FileName);
return d;
}
}
}