1373 lines
63 KiB
C#
1373 lines
63 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Linq;
|
||
|
||
namespace HRM.BO
|
||
{
|
||
#region EnumBulkUploadColumnKind
|
||
|
||
/// <summary>
|
||
/// What a bulk-upload column holds. Drives the number format and the dropdown in the
|
||
/// generated workbook, and (later) how the uploaded value is parsed and validated.
|
||
/// </summary>
|
||
public enum EnumBulkUploadColumnKind
|
||
{
|
||
Text = 1,
|
||
Date = 2,
|
||
Integer = 3,
|
||
Decimal = 4,
|
||
Percentage = 5,
|
||
Email = 6,
|
||
Gender = 7,
|
||
MaritalStatus = 8,
|
||
SponsoredType = 10,
|
||
TaxCircle = 11,
|
||
|
||
/// <summary>A dropdown of the blood groups the Employee Profile lists (A+ … AB-).</summary>
|
||
BloodGroup = 12,
|
||
|
||
/// <summary>A Bangladesh mobile number, as the Employee Profile accepts it.</summary>
|
||
Mobile = 13
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region EnumBulkUploadMasterData
|
||
|
||
/// <summary>
|
||
/// The DB table a bulk-upload column's value must exist in — each member is named after its
|
||
/// table. The validator loads that table and matches the cell against it — by Employee No for
|
||
/// Employee, by name / description for the rest.
|
||
/// </summary>
|
||
public enum EnumBulkUploadMasterData
|
||
{
|
||
None = 0,
|
||
Category = 1,
|
||
Religion = 2,
|
||
Grades = 3,
|
||
Occupation = 4,
|
||
District = 5,
|
||
Thana = 6,
|
||
PersonRelation = 7,
|
||
EducationType = 8,
|
||
EducationLevel = 9,
|
||
Institution = 10,
|
||
Discipline = 11,
|
||
ResultType = 12,
|
||
NominationPurpose = 13,
|
||
TrainingType = 14,
|
||
NatureOfTraining = 15,
|
||
Country = 16,
|
||
Employee = 17,
|
||
|
||
/// <summary>No column uses it: the Division a new District is added under.</summary>
|
||
Division = 18,
|
||
|
||
Nationality = 19
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region EmployeeBulkUploadColumn
|
||
|
||
/// <summary>One column of the Employee Bulk Upload sheet (one cell of header row 3).</summary>
|
||
public class EmployeeBulkUploadColumn
|
||
{
|
||
public EmployeeBulkUploadColumn(string label, bool isMandatory = false,
|
||
EnumBulkUploadColumnKind kind = EnumBulkUploadColumnKind.Text, double width = 0,
|
||
EnumBulkUploadMasterData masterData = EnumBulkUploadMasterData.None, string dependsOn = null)
|
||
{
|
||
Label = label;
|
||
IsMandatory = isMandatory;
|
||
Kind = kind;
|
||
MasterData = masterData;
|
||
DependsOn = dependsOn;
|
||
// An explicit width, else sized to the label — but never narrower than the heading,
|
||
// so the heading row stays one line high and nothing wraps.
|
||
double baseWidth = width > 0 ? width : Math.Max(12, Math.Min(26, label.Length + 4));
|
||
Width = Math.Max(baseWidth, Math.Ceiling(Heading.Length * 1.15) + 2);
|
||
}
|
||
|
||
public string Label { get; set; }
|
||
public bool IsMandatory { get; set; }
|
||
public EnumBulkUploadColumnKind Kind { get; set; }
|
||
public double Width { get; set; }
|
||
|
||
/// <summary>The table this column's value must exist in; None for free values.</summary>
|
||
public EnumBulkUploadMasterData MasterData { get; set; }
|
||
|
||
/// <summary>
|
||
/// Label of the column in the same sub-group this value belongs under — Thana under
|
||
/// District, Education Level under Education Platform. Null when it stands alone.
|
||
/// </summary>
|
||
public string DependsOn { get; set; }
|
||
|
||
public bool IsMasterData
|
||
{
|
||
get { return MasterData != EnumBulkUploadMasterData.None; }
|
||
}
|
||
|
||
/// <summary>True when the cell holds the record's code (Employee No), not its name.</summary>
|
||
public bool MatchesByCode
|
||
{
|
||
get { return MasterData == EnumBulkUploadMasterData.Employee; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// The column of the <see cref="MasterData"/> table the cell is matched against — its name
|
||
/// column, or its code column when <see cref="MatchesByCode"/>. Null when not master data.
|
||
/// </summary>
|
||
public string MasterDataColumn
|
||
{
|
||
get
|
||
{
|
||
switch (MasterData)
|
||
{
|
||
case EnumBulkUploadMasterData.Category: return "DESCRIPTION";
|
||
case EnumBulkUploadMasterData.Religion: return "NAME";
|
||
case EnumBulkUploadMasterData.Nationality: return "DESCRIPTION";
|
||
case EnumBulkUploadMasterData.Grades: return "DESCRIPTION";
|
||
case EnumBulkUploadMasterData.Occupation: return "DESCRIPTION";
|
||
case EnumBulkUploadMasterData.District: return "NAME";
|
||
case EnumBulkUploadMasterData.Thana: return "NAME";
|
||
case EnumBulkUploadMasterData.PersonRelation: return "DESCRIPTION";
|
||
case EnumBulkUploadMasterData.EducationType: return "DESCRIPTION";
|
||
case EnumBulkUploadMasterData.EducationLevel: return "DESCRIPTION";
|
||
case EnumBulkUploadMasterData.Institution: return "NAME";
|
||
case EnumBulkUploadMasterData.Discipline: return "DESCRIPTION";
|
||
case EnumBulkUploadMasterData.ResultType: return "DESCRIPTION";
|
||
case EnumBulkUploadMasterData.NominationPurpose: return "DESCRIPTION";
|
||
case EnumBulkUploadMasterData.TrainingType: return "NAME";
|
||
case EnumBulkUploadMasterData.NatureOfTraining: return "NAME";
|
||
case EnumBulkUploadMasterData.Country: return "NAME";
|
||
case EnumBulkUploadMasterData.Employee: return "EMPLOYEENO";
|
||
default: return null;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Unique field name of this column across the whole layout, e.g. "children01_birthdate".
|
||
/// Set by EmployeeBulkUploadTemplate.GetGroups(); an uploaded row's values are keyed by it.
|
||
/// </summary>
|
||
public string Key { get; set; }
|
||
|
||
/// <summary>The heading as it is written into the sheet; mandatory columns carry a " *".</summary>
|
||
public string Heading
|
||
{
|
||
get { return IsMandatory ? Label + " *" : Label; }
|
||
}
|
||
|
||
/// <summary>The blood groups in EnumBloodGroup order (A+ = 1 … AB- = 8).</summary>
|
||
public const string BloodGroups = "A+,A-,B+,B-,O+,O-,AB+,AB-";
|
||
|
||
/// <summary>The inline dropdown list for this column, or null when it is free text.</summary>
|
||
public string DropdownList
|
||
{
|
||
get
|
||
{
|
||
switch (Kind)
|
||
{
|
||
case EnumBulkUploadColumnKind.Gender: return "Male,Female,Other";
|
||
case EnumBulkUploadColumnKind.MaritalStatus: return "Married,UnMarried,Divorced,Widow";
|
||
// The EnumTaxCircle names.
|
||
case EnumBulkUploadColumnKind.TaxCircle: return "CityCorporation,Municipal,Union";
|
||
// As the Employee Profile lists them; saved as EnumBloodGroup 1-8 in this order.
|
||
case EnumBulkUploadColumnKind.BloodGroup: return BloodGroups;
|
||
// The EnumSponsoredType names, as the ESS profile-update page lists them.
|
||
case EnumBulkUploadColumnKind.SponsoredType:
|
||
return "TrainingBeforeJoining,TrainingConductedByCompany,SelfInitiatedTraining,TrainingBeforeJoiningButAtCompany";
|
||
default: return null;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>The Excel number format for this column, or null to leave it General.</summary>
|
||
public string NumberFormat
|
||
{
|
||
get
|
||
{
|
||
switch (Kind)
|
||
{
|
||
// "@" = Text: digit strings (NID, TIN, mobile, account no) keep their leading
|
||
// zeros and never turn into 1.23E+16.
|
||
case EnumBulkUploadColumnKind.Text:
|
||
case EnumBulkUploadColumnKind.Mobile:
|
||
case EnumBulkUploadColumnKind.Email: return "@";
|
||
case EnumBulkUploadColumnKind.Date: return "DD-MMM-YYYY";
|
||
case EnumBulkUploadColumnKind.Integer: return "0";
|
||
case EnumBulkUploadColumnKind.Decimal: return "#,##0.00";
|
||
case EnumBulkUploadColumnKind.Percentage: return "0.00";
|
||
default: return null;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region EmployeeBulkUploadSubGroup
|
||
|
||
/// <summary>
|
||
/// One band of header row 2, such as "Children 01". Name is null for a group that has no
|
||
/// second band — such a group merges rows 1 and 2.
|
||
/// </summary>
|
||
public class EmployeeBulkUploadSubGroup
|
||
{
|
||
public EmployeeBulkUploadSubGroup(string name, List<EmployeeBulkUploadColumn> columns,
|
||
bool isRepeatBlock = false)
|
||
{
|
||
Name = name;
|
||
Columns = columns ?? new List<EmployeeBulkUploadColumn>();
|
||
IsRepeatBlock = isRepeatBlock;
|
||
}
|
||
|
||
public string Name { get; set; }
|
||
public List<EmployeeBulkUploadColumn> Columns { get; set; }
|
||
|
||
/// <summary>
|
||
/// One of several numbered copies (Children 01, Children 02, ...). An employee may have
|
||
/// fewer records than copies, so a block left wholly empty in a row means "no record" and
|
||
/// its mandatory columns apply only once the block holds any value.
|
||
/// </summary>
|
||
public bool IsRepeatBlock { get; set; }
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region EmployeeBulkUploadGroup
|
||
|
||
/// <summary>One band of header row 1, with its colour and its sub-bands.</summary>
|
||
public class EmployeeBulkUploadGroup
|
||
{
|
||
public EmployeeBulkUploadGroup(string name, string bandColor, string subBandColor,
|
||
string headerColor, string textColor, List<EmployeeBulkUploadSubGroup> subGroups)
|
||
{
|
||
Name = name;
|
||
BandColor = bandColor;
|
||
SubBandColor = subBandColor;
|
||
HeaderColor = headerColor;
|
||
TextColor = textColor;
|
||
SubGroups = subGroups ?? new List<EmployeeBulkUploadSubGroup>();
|
||
}
|
||
|
||
public string Name { get; set; }
|
||
public string BandColor { get; set; } // header row 1
|
||
public string SubBandColor { get; set; } // header row 2
|
||
public string HeaderColor { get; set; } // header row 3
|
||
public string TextColor { get; set; }
|
||
public List<EmployeeBulkUploadSubGroup> SubGroups { get; set; }
|
||
|
||
public int ColumnCount
|
||
{
|
||
get { return SubGroups.Sum(x => x.Columns.Count); }
|
||
}
|
||
|
||
/// <summary>True when row 2 carries its own bands, so row 1 is not merged downwards.</summary>
|
||
public bool HasSubBands
|
||
{
|
||
get { return SubGroups.Any(x => !string.IsNullOrEmpty(x.Name)); }
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region EmployeeBulkUploadTemplate
|
||
|
||
/// <summary>
|
||
/// The layout of the Employee Bulk Upload workbook — one row per employee, with the employee's
|
||
/// children, spouse, education, nominee, experience and training in that same row.
|
||
///
|
||
/// This is the single source of truth: EmployeeBulkUploadService renders the downloadable
|
||
/// template from it, and the upload validator is meant to read the uploaded file against it,
|
||
/// so the template and the validation can never drift apart.
|
||
///
|
||
/// Every sub-group carries exactly the fields of the matching screen — no extra columns:
|
||
/// Basic Information follows the core-hr Employee Profile (General, Extended Personal
|
||
/// Information and the Contact tab), the other groups the ESS profile-update forms.
|
||
///
|
||
/// The user picks which sub-groups go into the downloaded file (Employee is always in), so a
|
||
/// file holds a subset of this layout: the uploader must locate each sub-group by its row-2
|
||
/// band name and each column by its row-3 heading, never by absolute column position.
|
||
/// Within a sub-group, column order and headings are fixed.
|
||
/// Adding a column means appending it inside its group, never inserting in the middle.
|
||
/// </summary>
|
||
public static class EmployeeBulkUploadTemplate
|
||
{
|
||
#region Sheet constants
|
||
|
||
public const string FileName = "Employee-Bulk-Upload-Template.xlsx";
|
||
public const string SheetName = "Employee Data";
|
||
public const string ContentType =
|
||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||
|
||
public const int GroupBandRow = 1;
|
||
public const int SubBandRow = 2;
|
||
public const int HeadingRow = 3;
|
||
public const int FirstDataRow = 4;
|
||
|
||
/// <summary>Data rows given an explicit number format in the generated file.</summary>
|
||
public const int FormattedDataRows = 200;
|
||
|
||
/// <summary>Data rows covered by the dropdown validations.</summary>
|
||
public const int ValidatedDataRows = 997;
|
||
|
||
/// <summary>Largest upload accepted, in MB.</summary>
|
||
public const int MaxUploadMegabytes = 10;
|
||
|
||
/// <summary>Most employee rows read from one file.</summary>
|
||
public const int MaxUploadRows = 2000;
|
||
|
||
/// <summary>
|
||
/// The sub-group that is always in the file, whatever the user picks: Employee No and
|
||
/// Employee Name, which tie every row to an employee. Every other sub-group is optional.
|
||
/// </summary>
|
||
public const string AlwaysIncludedSubGroup = "Employee";
|
||
|
||
/// <summary>
|
||
/// A master-data value this alike (or more) to exactly one record is taken as that record;
|
||
/// below it the value counts as missing.
|
||
/// </summary>
|
||
public const int CloseMatchPercent = 90;
|
||
|
||
public const string MandatoryTextColor = "#B23B3B";
|
||
public const string OptionalTextColor = "#1F2933";
|
||
public const string BorderColor = "#7B8794";
|
||
|
||
#endregion
|
||
|
||
#region Column definitions
|
||
|
||
/// <summary>The key of every row — always in the file, first, and frozen while scrolling.</summary>
|
||
private static List<EmployeeBulkUploadColumn> EmployeeColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("Employee No", true),
|
||
new EmployeeBulkUploadColumn("Employee Name", true, EnumBulkUploadColumnKind.Text, 24),
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// The employee's core record — the "General" band of Basic Information. Follows the
|
||
/// core-hr Employee Profile "Personal Information" form, with its mandatory fields; the
|
||
/// saved Name is First + Middle + Last Name, as the form saves it.
|
||
/// </summary>
|
||
private static List<EmployeeBulkUploadColumn> GeneralColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("First Name", true),
|
||
new EmployeeBulkUploadColumn("Middle Name"),
|
||
new EmployeeBulkUploadColumn("Last Name", true),
|
||
new EmployeeBulkUploadColumn("Name (Ban)", false, EnumBulkUploadColumnKind.Text, 24),
|
||
new EmployeeBulkUploadColumn("Date of Birth", true, EnumBulkUploadColumnKind.Date),
|
||
new EmployeeBulkUploadColumn("Gender", true, EnumBulkUploadColumnKind.Gender),
|
||
new EmployeeBulkUploadColumn("Mobile No", true, EnumBulkUploadColumnKind.Mobile, 16),
|
||
new EmployeeBulkUploadColumn("Email", true, EnumBulkUploadColumnKind.Email, 26),
|
||
new EmployeeBulkUploadColumn("Date of Joining", true, EnumBulkUploadColumnKind.Date),
|
||
new EmployeeBulkUploadColumn("Blood Group", true, EnumBulkUploadColumnKind.BloodGroup),
|
||
new EmployeeBulkUploadColumn("Marital Status", true, EnumBulkUploadColumnKind.MaritalStatus),
|
||
new EmployeeBulkUploadColumn("Religion Name", true, masterData: EnumBulkUploadMasterData.Religion),
|
||
new EmployeeBulkUploadColumn("Nationality", masterData: EnumBulkUploadMasterData.Nationality),
|
||
new EmployeeBulkUploadColumn("Category Name", true, masterData: EnumBulkUploadMasterData.Category),
|
||
new EmployeeBulkUploadColumn("Tax Circle", false, EnumBulkUploadColumnKind.TaxCircle, 20),
|
||
new EmployeeBulkUploadColumn("Grade Code", true, masterData: EnumBulkUploadMasterData.Grades),
|
||
new EmployeeBulkUploadColumn("Confirmation Date", false, EnumBulkUploadColumnKind.Date),
|
||
new EmployeeBulkUploadColumn("Line Manager ID", masterData: EnumBulkUploadMasterData.Employee),
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// The core-hr Employee Profile "Extended Personal Information" fields, except Spouse Name
|
||
/// (the Spouse group carries it) and the Signature upload.
|
||
/// </summary>
|
||
private static List<EmployeeBulkUploadColumn> ExtendedPersonalColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("Global Emp ID"),
|
||
new EmployeeBulkUploadColumn("National ID No", false, EnumBulkUploadColumnKind.Text, 20),
|
||
new EmployeeBulkUploadColumn("TIN No"),
|
||
new EmployeeBulkUploadColumn("Passport No"),
|
||
new EmployeeBulkUploadColumn("Passport Issued Date", false, EnumBulkUploadColumnKind.Date),
|
||
new EmployeeBulkUploadColumn("Passport Expiry Date", false, EnumBulkUploadColumnKind.Date),
|
||
new EmployeeBulkUploadColumn("Driving License No", false, EnumBulkUploadColumnKind.Text, 20),
|
||
new EmployeeBulkUploadColumn("Father's Name", false, EnumBulkUploadColumnKind.Text, 24),
|
||
new EmployeeBulkUploadColumn("Father's Name (Ban)", false, EnumBulkUploadColumnKind.Text, 24),
|
||
new EmployeeBulkUploadColumn("Father's Occupation", false, EnumBulkUploadColumnKind.Text, 20, masterData: EnumBulkUploadMasterData.Occupation),
|
||
new EmployeeBulkUploadColumn("Mother's Name", false, EnumBulkUploadColumnKind.Text, 24),
|
||
new EmployeeBulkUploadColumn("Mother's Name (Ban)", false, EnumBulkUploadColumnKind.Text, 24),
|
||
new EmployeeBulkUploadColumn("Mother's Occupation", false, EnumBulkUploadColumnKind.Text, 20, masterData: EnumBulkUploadMasterData.Occupation),
|
||
new EmployeeBulkUploadColumn("Birth Place"),
|
||
new EmployeeBulkUploadColumn("Height (Cm)"),
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// One address block of the core-hr Employee Profile "Contact" tab — Present and Permanent
|
||
/// Address share the same fields.
|
||
/// </summary>
|
||
private static List<EmployeeBulkUploadColumn> AddressColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("Address", false, EnumBulkUploadColumnKind.Text, 34),
|
||
new EmployeeBulkUploadColumn("Address (Bn)", false, EnumBulkUploadColumnKind.Text, 34),
|
||
new EmployeeBulkUploadColumn("District", masterData: EnumBulkUploadMasterData.District),
|
||
new EmployeeBulkUploadColumn("Thana", masterData: EnumBulkUploadMasterData.Thana, dependsOn: "District"),
|
||
new EmployeeBulkUploadColumn("Land Phone No"),
|
||
new EmployeeBulkUploadColumn("Post Office Name (Bn)", false, EnumBulkUploadColumnKind.Text, 22),
|
||
new EmployeeBulkUploadColumn("Mobile No"),
|
||
new EmployeeBulkUploadColumn("Postal Code"),
|
||
};
|
||
}
|
||
|
||
/// <summary>The "Contact Details" block of the Employee Profile "Contact" tab.</summary>
|
||
private static List<EmployeeBulkUploadColumn> ContactDetailsColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("Land Phone No"),
|
||
new EmployeeBulkUploadColumn("Mobile No"),
|
||
new EmployeeBulkUploadColumn("Personal Email", false, EnumBulkUploadColumnKind.Email, 24),
|
||
new EmployeeBulkUploadColumn("Fax"),
|
||
};
|
||
}
|
||
|
||
/// <summary>The "Emergency Contact Details" block of the Employee Profile "Contact" tab.</summary>
|
||
private static List<EmployeeBulkUploadColumn> EmergencyContactColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("Contact Person", false, EnumBulkUploadColumnKind.Text, 22),
|
||
new EmployeeBulkUploadColumn("Address", false, EnumBulkUploadColumnKind.Text, 34),
|
||
new EmployeeBulkUploadColumn("Relation", masterData: EnumBulkUploadMasterData.PersonRelation),
|
||
new EmployeeBulkUploadColumn("Mobile No"),
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// The fields of the ESS profile-update "Children Information" form. Its passport fields
|
||
/// are commented out on that form, so they are not collected here either.
|
||
/// </summary>
|
||
private static List<EmployeeBulkUploadColumn> ChildrenColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("Name", true, EnumBulkUploadColumnKind.Text, 22),
|
||
new EmployeeBulkUploadColumn("Gender", true, EnumBulkUploadColumnKind.Gender),
|
||
new EmployeeBulkUploadColumn("Birth Date", true, EnumBulkUploadColumnKind.Date),
|
||
new EmployeeBulkUploadColumn("Occupation", masterData: EnumBulkUploadMasterData.Occupation),
|
||
new EmployeeBulkUploadColumn("Marital Status", true, EnumBulkUploadColumnKind.MaritalStatus),
|
||
};
|
||
}
|
||
|
||
/// <summary>The fields of the ESS profile-update "Spouse Information" form.</summary>
|
||
private static List<EmployeeBulkUploadColumn> SpouseColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("Name", true, EnumBulkUploadColumnKind.Text, 22),
|
||
new EmployeeBulkUploadColumn("Level of Education", false, EnumBulkUploadColumnKind.Text, 20, masterData: EnumBulkUploadMasterData.EducationLevel),
|
||
new EmployeeBulkUploadColumn("Occupation", masterData: EnumBulkUploadMasterData.Occupation),
|
||
new EmployeeBulkUploadColumn("Birth Date", false, EnumBulkUploadColumnKind.Date),
|
||
new EmployeeBulkUploadColumn("Marriage Date", false, EnumBulkUploadColumnKind.Date),
|
||
};
|
||
}
|
||
|
||
/// <summary>The fields of the ESS profile-update "Educational Information" form; its file attachment is left out.</summary>
|
||
private static List<EmployeeBulkUploadColumn> EducationColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("Education Platform", true, EnumBulkUploadColumnKind.Text, 20, masterData: EnumBulkUploadMasterData.EducationType),
|
||
new EmployeeBulkUploadColumn("Education Level", true, EnumBulkUploadColumnKind.Text, 20, masterData: EnumBulkUploadMasterData.EducationLevel, dependsOn: "Education Platform"),
|
||
new EmployeeBulkUploadColumn("University / Board", false, EnumBulkUploadColumnKind.Text, 24, masterData: EnumBulkUploadMasterData.Institution),
|
||
new EmployeeBulkUploadColumn("Discipline", false, EnumBulkUploadColumnKind.Text, 20, masterData: EnumBulkUploadMasterData.Discipline),
|
||
new EmployeeBulkUploadColumn("Institute Name", false, EnumBulkUploadColumnKind.Text, 26),
|
||
new EmployeeBulkUploadColumn("Exam Year", false, EnumBulkUploadColumnKind.Integer),
|
||
new EmployeeBulkUploadColumn("Passing Year", true, EnumBulkUploadColumnKind.Integer),
|
||
new EmployeeBulkUploadColumn("Result Standard", false, EnumBulkUploadColumnKind.Text, 18, masterData: EnumBulkUploadMasterData.ResultType),
|
||
new EmployeeBulkUploadColumn("GPA / Marks", false, EnumBulkUploadColumnKind.Decimal),
|
||
new EmployeeBulkUploadColumn("Out of", false, EnumBulkUploadColumnKind.Decimal),
|
||
};
|
||
}
|
||
|
||
/// <summary>The fields of the ESS profile-update "Nominee Information" form; its file attachment is left out.</summary>
|
||
private static List<EmployeeBulkUploadColumn> NomineeColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("Nomination Purpose", true, EnumBulkUploadColumnKind.Text, 22, masterData: EnumBulkUploadMasterData.NominationPurpose),
|
||
new EmployeeBulkUploadColumn("Nominee Name", true, EnumBulkUploadColumnKind.Text, 22),
|
||
new EmployeeBulkUploadColumn("Relation", true, masterData: EnumBulkUploadMasterData.PersonRelation),
|
||
new EmployeeBulkUploadColumn("Percentage", true, EnumBulkUploadColumnKind.Percentage),
|
||
new EmployeeBulkUploadColumn("Birth Date", false, EnumBulkUploadColumnKind.Date),
|
||
new EmployeeBulkUploadColumn("Occupation", masterData: EnumBulkUploadMasterData.Occupation),
|
||
new EmployeeBulkUploadColumn("Address", false, EnumBulkUploadColumnKind.Text, 34),
|
||
new EmployeeBulkUploadColumn("Telephone"),
|
||
new EmployeeBulkUploadColumn("Email", false, EnumBulkUploadColumnKind.Email, 24),
|
||
};
|
||
}
|
||
|
||
/// <summary>The fields of the ESS profile-update "Experience Information" form; its file attachment is left out.</summary>
|
||
private static List<EmployeeBulkUploadColumn> ExperienceColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("Employer", true, EnumBulkUploadColumnKind.Text, 24),
|
||
new EmployeeBulkUploadColumn("Business Type", false, EnumBulkUploadColumnKind.Text, 20),
|
||
new EmployeeBulkUploadColumn("Employer Contact Person", false, EnumBulkUploadColumnKind.Text, 24),
|
||
new EmployeeBulkUploadColumn("Designation", true, EnumBulkUploadColumnKind.Text, 20),
|
||
new EmployeeBulkUploadColumn("Address", false, EnumBulkUploadColumnKind.Text, 34),
|
||
new EmployeeBulkUploadColumn("Role Definition", false, EnumBulkUploadColumnKind.Text, 30),
|
||
new EmployeeBulkUploadColumn("Telephone No"),
|
||
new EmployeeBulkUploadColumn("From Date", true, EnumBulkUploadColumnKind.Date),
|
||
new EmployeeBulkUploadColumn("To Date", false, EnumBulkUploadColumnKind.Date),
|
||
};
|
||
}
|
||
|
||
/// <summary>
|
||
/// The fields of the ESS profile-update "Training Information" form, in the form's order.
|
||
/// The certificate attachment has no place in a sheet and is left out.
|
||
/// </summary>
|
||
private static List<EmployeeBulkUploadColumn> TrainingColumns()
|
||
{
|
||
return new List<EmployeeBulkUploadColumn>
|
||
{
|
||
new EmployeeBulkUploadColumn("Training Type", true, EnumBulkUploadColumnKind.Text, 20, masterData: EnumBulkUploadMasterData.TrainingType),
|
||
new EmployeeBulkUploadColumn("Nature of Training", true, EnumBulkUploadColumnKind.Text, 20, masterData: EnumBulkUploadMasterData.NatureOfTraining),
|
||
new EmployeeBulkUploadColumn("Training Title", true, EnumBulkUploadColumnKind.Text, 26),
|
||
new EmployeeBulkUploadColumn("Description", false, EnumBulkUploadColumnKind.Text, 30),
|
||
new EmployeeBulkUploadColumn("Institution", true, EnumBulkUploadColumnKind.Text, 24, masterData: EnumBulkUploadMasterData.Institution),
|
||
new EmployeeBulkUploadColumn("Institute Place", false, EnumBulkUploadColumnKind.Text, 20),
|
||
new EmployeeBulkUploadColumn("Country", masterData: EnumBulkUploadMasterData.Country),
|
||
new EmployeeBulkUploadColumn("Achievement", false, EnumBulkUploadColumnKind.Text, 20),
|
||
new EmployeeBulkUploadColumn("From Date", false, EnumBulkUploadColumnKind.Date),
|
||
new EmployeeBulkUploadColumn("To Date", false, EnumBulkUploadColumnKind.Date),
|
||
new EmployeeBulkUploadColumn("Sponsor Type", false, EnumBulkUploadColumnKind.SponsoredType, 30),
|
||
new EmployeeBulkUploadColumn("Months", false, EnumBulkUploadColumnKind.Integer),
|
||
new EmployeeBulkUploadColumn("Days", false, EnumBulkUploadColumnKind.Integer),
|
||
new EmployeeBulkUploadColumn("Hours", false, EnumBulkUploadColumnKind.Integer),
|
||
new EmployeeBulkUploadColumn("Training Fees", false, EnumBulkUploadColumnKind.Decimal),
|
||
new EmployeeBulkUploadColumn("Other Costs", false, EnumBulkUploadColumnKind.Decimal),
|
||
};
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Layout
|
||
|
||
/// <summary>
|
||
/// The seven header-row-1 groups, left to right. Built fresh on each call so a caller
|
||
/// cannot mutate the layout for everybody else.
|
||
/// </summary>
|
||
public static List<EmployeeBulkUploadGroup> GetGroups()
|
||
{
|
||
List<EmployeeBulkUploadGroup> groups = new List<EmployeeBulkUploadGroup>
|
||
{
|
||
new EmployeeBulkUploadGroup("Basic Information",
|
||
"#D8E4F0", "#E9F0F8", "#F4F8FC", "#2C4A6B",
|
||
new List<EmployeeBulkUploadSubGroup>
|
||
{
|
||
new EmployeeBulkUploadSubGroup(AlwaysIncludedSubGroup, EmployeeColumns()),
|
||
new EmployeeBulkUploadSubGroup("General", GeneralColumns()),
|
||
new EmployeeBulkUploadSubGroup("Extended Personal Information", ExtendedPersonalColumns()),
|
||
new EmployeeBulkUploadSubGroup("Present Address", AddressColumns()),
|
||
new EmployeeBulkUploadSubGroup("Permanent Address", AddressColumns()),
|
||
new EmployeeBulkUploadSubGroup("Contact Details", ContactDetailsColumns()),
|
||
new EmployeeBulkUploadSubGroup("Emergency Contact Details", EmergencyContactColumns())
|
||
}),
|
||
|
||
new EmployeeBulkUploadGroup("Children",
|
||
"#DCEBD8", "#EDF5EB", "#F6FAF5", "#3D5A36",
|
||
new List<EmployeeBulkUploadSubGroup>
|
||
{
|
||
new EmployeeBulkUploadSubGroup("Children 01", ChildrenColumns(), true),
|
||
new EmployeeBulkUploadSubGroup("Children 02", ChildrenColumns(), true)
|
||
}),
|
||
|
||
new EmployeeBulkUploadGroup("Spouse",
|
||
"#E6DCEC", "#F1EBF4", "#F8F5FA", "#55415E",
|
||
new List<EmployeeBulkUploadSubGroup>
|
||
{
|
||
new EmployeeBulkUploadSubGroup("Spouse 01", SpouseColumns(), true),
|
||
new EmployeeBulkUploadSubGroup("Spouse 02", SpouseColumns(), true)
|
||
}),
|
||
|
||
new EmployeeBulkUploadGroup("Academic / Education",
|
||
"#F2E2D3", "#F8EFE7", "#FCF7F3", "#70503A",
|
||
new List<EmployeeBulkUploadSubGroup>
|
||
{
|
||
new EmployeeBulkUploadSubGroup("Education 01", EducationColumns(), true),
|
||
new EmployeeBulkUploadSubGroup("Education 02", EducationColumns(), true)
|
||
}),
|
||
|
||
new EmployeeBulkUploadGroup("Nominee",
|
||
"#D7EAE5", "#E9F4F1", "#F4FAF8", "#35584F",
|
||
new List<EmployeeBulkUploadSubGroup>
|
||
{
|
||
new EmployeeBulkUploadSubGroup("Nominee 01", NomineeColumns(), true),
|
||
new EmployeeBulkUploadSubGroup("Nominee 02", NomineeColumns(), true)
|
||
}),
|
||
|
||
new EmployeeBulkUploadGroup("Experience",
|
||
"#F2DEDB", "#F8ECEA", "#FCF6F5", "#6E4340",
|
||
new List<EmployeeBulkUploadSubGroup>
|
||
{
|
||
new EmployeeBulkUploadSubGroup("Experience 01", ExperienceColumns(), true),
|
||
new EmployeeBulkUploadSubGroup("Experience 02", ExperienceColumns(), true)
|
||
}),
|
||
|
||
new EmployeeBulkUploadGroup("Training",
|
||
"#EDE6C9", "#F6F1DF", "#FBF9F0", "#5E5230",
|
||
new List<EmployeeBulkUploadSubGroup>
|
||
{
|
||
new EmployeeBulkUploadSubGroup("Training 01", TrainingColumns(), true),
|
||
new EmployeeBulkUploadSubGroup("Training 02", TrainingColumns(), true),
|
||
new EmployeeBulkUploadSubGroup("Training 03", TrainingColumns(), true)
|
||
}),
|
||
};
|
||
|
||
foreach (EmployeeBulkUploadSubGroup subGroup in groups.SelectMany(g => g.SubGroups))
|
||
{
|
||
foreach (EmployeeBulkUploadColumn column in subGroup.Columns)
|
||
{
|
||
column.Key = ToKey(subGroup.Name) + "_" + ToKey(column.Label);
|
||
|
||
if (column.DependsOn != null && !subGroup.Columns.Any(x => x.Label == column.DependsOn))
|
||
{
|
||
throw new InvalidOperationException("Column \"" + column.Label + "\" of \"" + subGroup.Name
|
||
+ "\" depends on \"" + column.DependsOn + "\", which that sub-group does not have.");
|
||
}
|
||
}
|
||
}
|
||
|
||
return groups;
|
||
}
|
||
|
||
/// <summary>Letters and digits only, lower case: "Children 01" → "children01".</summary>
|
||
private static string ToKey(string text)
|
||
{
|
||
return new string((text ?? string.Empty).Where(char.IsLetterOrDigit).ToArray()).ToLowerInvariant();
|
||
}
|
||
|
||
/// <summary>
|
||
/// A heading as the uploader compares it: no mandatory " *", single spaces, any case.
|
||
/// </summary>
|
||
public static string NormalizeHeading(string heading)
|
||
{
|
||
string text = (heading ?? string.Empty).Trim().TrimEnd('*').Trim();
|
||
return string.Join(" ", text.Split((char[])null, StringSplitOptions.RemoveEmptyEntries))
|
||
.ToLowerInvariant();
|
||
}
|
||
|
||
/// <summary>
|
||
/// The layout cut down to the chosen sub-groups (by row-2 band name, e.g. "Children 01").
|
||
/// Null or empty means everything. General is always kept, and a group left with no
|
||
/// sub-group is dropped.
|
||
/// </summary>
|
||
public static List<EmployeeBulkUploadGroup> GetGroups(IEnumerable<string> subGroupNames)
|
||
{
|
||
List<EmployeeBulkUploadGroup> groups = GetGroups();
|
||
if (subGroupNames == null || !subGroupNames.Any())
|
||
{
|
||
return groups;
|
||
}
|
||
|
||
HashSet<string> chosen = new HashSet<string>(subGroupNames, StringComparer.OrdinalIgnoreCase);
|
||
chosen.Add(AlwaysIncludedSubGroup);
|
||
|
||
foreach (EmployeeBulkUploadGroup group in groups)
|
||
{
|
||
group.SubGroups = group.SubGroups.Where(s => chosen.Contains(s.Name)).ToList();
|
||
}
|
||
|
||
return groups.Where(g => g.SubGroups.Count > 0).ToList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// A user's section selection as template band names, in template order, always starting
|
||
/// with <see cref="AlwaysIncludedSubGroup"/>. Names that are not template sections are
|
||
/// returned in <paramref name="unknown"/> and left out.
|
||
/// </summary>
|
||
public static List<string> ResolveSelection(IEnumerable<string> subGroupNames, out List<string> unknown)
|
||
{
|
||
List<string> requested = (subGroupNames ?? Enumerable.Empty<string>())
|
||
.Where(x => !string.IsNullOrWhiteSpace(x))
|
||
.Select(x => x.Trim())
|
||
.ToList();
|
||
List<string> known = GetSubGroupNames();
|
||
|
||
unknown = requested
|
||
.Where(x => !known.Contains(x, StringComparer.OrdinalIgnoreCase))
|
||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||
.ToList();
|
||
|
||
return known
|
||
.Where(x => x == AlwaysIncludedSubGroup || requested.Contains(x, StringComparer.OrdinalIgnoreCase))
|
||
.ToList();
|
||
}
|
||
|
||
/// <summary>Every row-2 band name, left to right — the values a selection may contain.</summary>
|
||
public static List<string> GetSubGroupNames()
|
||
{
|
||
return GetGroups()
|
||
.SelectMany(g => g.SubGroups)
|
||
.Select(s => s.Name)
|
||
.ToList();
|
||
}
|
||
|
||
/// <summary>All columns left to right, flattened — the order of the sheet.</summary>
|
||
public static List<EmployeeBulkUploadColumn> GetColumns()
|
||
{
|
||
return GetColumns(GetGroups());
|
||
}
|
||
|
||
public static List<EmployeeBulkUploadColumn> GetColumns(List<EmployeeBulkUploadGroup> groups)
|
||
{
|
||
return groups
|
||
.SelectMany(g => g.SubGroups)
|
||
.SelectMany(s => s.Columns)
|
||
.ToList();
|
||
}
|
||
|
||
public static int TotalColumnCount
|
||
{
|
||
get { return GetColumns().Count; }
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Upload read result
|
||
|
||
public enum EnumBulkUploadCheckStatus
|
||
{
|
||
NotChecked = 0, // did not run: an earlier check or layer it depends on failed
|
||
Passed = 1,
|
||
Failed = 2
|
||
}
|
||
|
||
/// <summary>
|
||
/// One validation check of an upload. Every check of a layer is listed even when it passes,
|
||
/// so the user sees what was checked; a failed one says what is wrong (Message), where
|
||
/// (Details — one line per section, column, ...) and how to put it right (Fix).
|
||
/// </summary>
|
||
public class EmployeeBulkUploadCheck
|
||
{
|
||
public EmployeeBulkUploadCheck(string code, string title)
|
||
{
|
||
Code = code;
|
||
Title = title;
|
||
Status = EnumBulkUploadCheckStatus.NotChecked;
|
||
Details = new List<string>();
|
||
}
|
||
|
||
/// <summary>Stable name of the check, e.g. "SelectedInFile".</summary>
|
||
public string Code { get; set; }
|
||
|
||
/// <summary>What is checked, phrased as the rule, e.g. "Every ticked section is in the file".</summary>
|
||
public string Title { get; set; }
|
||
|
||
public EnumBulkUploadCheckStatus Status { get; set; }
|
||
public string Message { get; set; }
|
||
public List<string> Details { get; set; }
|
||
public string Fix { get; set; }
|
||
|
||
public bool IsPassed
|
||
{
|
||
get { return Status == EnumBulkUploadCheckStatus.Passed; }
|
||
}
|
||
|
||
public void Pass()
|
||
{
|
||
Status = EnumBulkUploadCheckStatus.Passed;
|
||
}
|
||
|
||
public void Fail(string message, IEnumerable<string> details, string fix)
|
||
{
|
||
Status = EnumBulkUploadCheckStatus.Failed;
|
||
Message = message;
|
||
Details = details == null ? new List<string>() : details.ToList();
|
||
Fix = fix;
|
||
}
|
||
|
||
/// <summary>Leaves the check not run; <paramref name="reason"/> says which earlier check stopped it.</summary>
|
||
public void Skip(string reason)
|
||
{
|
||
Status = EnumBulkUploadCheckStatus.NotChecked;
|
||
Message = reason;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// A layer of validation. All checks of a layer run (as far as their own prerequisites
|
||
/// allow) and are reported together; the next layer runs only when this one has passed.
|
||
/// </summary>
|
||
public class EmployeeBulkUploadLayer
|
||
{
|
||
public EmployeeBulkUploadLayer(int layerNo, string name, string description)
|
||
{
|
||
LayerNo = layerNo;
|
||
Name = name;
|
||
Description = description;
|
||
Checks = new List<EmployeeBulkUploadCheck>();
|
||
}
|
||
|
||
public int LayerNo { get; set; }
|
||
public string Name { get; set; }
|
||
public string Description { get; set; }
|
||
public List<EmployeeBulkUploadCheck> Checks { get; set; }
|
||
|
||
/// <summary>Failed if any check failed, Passed if every check passed, otherwise NotChecked.</summary>
|
||
public EnumBulkUploadCheckStatus Status
|
||
{
|
||
get
|
||
{
|
||
if (Checks.Any(x => x.Status == EnumBulkUploadCheckStatus.Failed))
|
||
{
|
||
return EnumBulkUploadCheckStatus.Failed;
|
||
}
|
||
return Checks.Count > 0 && Checks.All(x => x.IsPassed)
|
||
? EnumBulkUploadCheckStatus.Passed
|
||
: EnumBulkUploadCheckStatus.NotChecked;
|
||
}
|
||
}
|
||
|
||
public EmployeeBulkUploadCheck AddCheck(string code, string title)
|
||
{
|
||
EmployeeBulkUploadCheck check = new EmployeeBulkUploadCheck(code, title);
|
||
Checks.Add(check);
|
||
return check;
|
||
}
|
||
|
||
/// <summary>Marks every check still not run with <paramref name="reason"/>.</summary>
|
||
public void SkipRemaining(string reason)
|
||
{
|
||
foreach (EmployeeBulkUploadCheck check in Checks.Where(x => x.Status == EnumBulkUploadCheckStatus.NotChecked))
|
||
{
|
||
check.Skip(reason);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// One problem in one cell of an employee row — shown in the page's Problems table so the
|
||
/// user can go straight to the cell. Severity is "error" or "warning".
|
||
/// </summary>
|
||
public class EmployeeBulkUploadIssue
|
||
{
|
||
public const string Error = "error";
|
||
public const string Warning = "warning";
|
||
|
||
public string Severity { get; set; }
|
||
|
||
/// <summary>The Excel row number.</summary>
|
||
public int RowNo { get; set; }
|
||
|
||
public string EmployeeNo { get; set; }
|
||
public string EmployeeName { get; set; }
|
||
|
||
/// <summary>Header row 1, e.g. "Basic Information".</summary>
|
||
public string Group { get; set; }
|
||
|
||
/// <summary>Header row 2, e.g. "Present Address".</summary>
|
||
public string SubGroup { get; set; }
|
||
|
||
/// <summary>Header row 3 label, e.g. "District".</summary>
|
||
public string Column { get; set; }
|
||
|
||
/// <summary>The Excel cell, e.g. "AB12" — where to find the value in the file.</summary>
|
||
public string Cell { get; set; }
|
||
|
||
/// <summary>What the cell held; empty for a missing value.</summary>
|
||
public string Value { get; set; }
|
||
|
||
/// <summary>What is wrong and how to put it right.</summary>
|
||
public string Message { get; set; }
|
||
}
|
||
|
||
/// <summary>One employee row of the uploaded sheet; only non-empty cells are carried.</summary>
|
||
public class EmployeeBulkUploadRow
|
||
{
|
||
public EmployeeBulkUploadRow()
|
||
{
|
||
Values = new Dictionary<string, string>();
|
||
Parsed = new Dictionary<string, object>();
|
||
MasterIDs = new Dictionary<string, int>();
|
||
}
|
||
|
||
/// <summary>The Excel row number, so a problem can be traced back to the sheet.</summary>
|
||
public int RowNo { get; set; }
|
||
|
||
/// <summary>Cell text keyed by <see cref="EmployeeBulkUploadColumn.Key"/>.</summary>
|
||
public Dictionary<string, string> Values { get; set; }
|
||
|
||
/// <summary>
|
||
/// The typed value of each filled cell (DateTime, decimal, or the text / listed value),
|
||
/// set by the data-type layer and used by the save. Server-side only.
|
||
/// </summary>
|
||
[Newtonsoft.Json.JsonIgnore]
|
||
public Dictionary<string, object> Parsed { get; set; }
|
||
|
||
/// <summary>The record ID each master-data cell resolved to (exactly or by a close match). Server-side only.</summary>
|
||
[Newtonsoft.Json.JsonIgnore]
|
||
public Dictionary<string, int> MasterIDs { get; set; }
|
||
|
||
/// <summary>The existing employee this row updates; 0 when the row creates a new employee.</summary>
|
||
[Newtonsoft.Json.JsonIgnore]
|
||
public int EmployeeID { get; set; }
|
||
|
||
/// <summary>
|
||
/// What the row's Employee No is in the system — <see cref="EmployeeStates"/>: "new" (not in
|
||
/// any payroll type: the row creates an employee), "existing" (an active employee of the
|
||
/// current payroll type), "otherPayroll", "inactive"; empty when it could not be looked up.
|
||
/// The page marks new employees with it.
|
||
/// </summary>
|
||
public string EmployeeState { get; set; }
|
||
}
|
||
|
||
/// <summary>The values of <see cref="EmployeeBulkUploadRow.EmployeeState"/>.</summary>
|
||
public static class EmployeeStates
|
||
{
|
||
public const string New = "new";
|
||
public const string Existing = "existing";
|
||
public const string OtherPayroll = "otherPayroll";
|
||
public const string Inactive = "inactive";
|
||
}
|
||
|
||
/// <summary>
|
||
/// A master-data value that is not an exact match but at least
|
||
/// <see cref="EmployeeBulkUploadTemplate.CloseMatchPercent"/>% alike to one record, and is
|
||
/// taken as that record. Shown to the user, who confirms it before saving.
|
||
/// </summary>
|
||
public class EmployeeBulkUploadCloseMatch
|
||
{
|
||
public EmployeeBulkUploadCloseMatch()
|
||
{
|
||
UsedIn = new List<string>();
|
||
RowNos = new List<int>();
|
||
}
|
||
|
||
public EnumBulkUploadMasterData MasterData { get; set; }
|
||
public string MasterName { get; set; }
|
||
|
||
/// <summary>The value as the file has it.</summary>
|
||
public string Value { get; set; }
|
||
|
||
/// <summary>The record it is taken as.</summary>
|
||
public string MatchedName { get; set; }
|
||
public int MatchedID { get; set; }
|
||
|
||
/// <summary>How alike the two are, 90–99.</summary>
|
||
public int Percent { get; set; }
|
||
|
||
/// <summary>The parent from the same block (District of a Thana, ...), as the file has it; null when none.</summary>
|
||
public string ParentValue { get; set; }
|
||
|
||
/// <summary>
|
||
/// The parent record that value resolved to (exactly or closely); 0 when there is no parent
|
||
/// in the file. Used when the user adds the file's value as a new record instead.
|
||
/// </summary>
|
||
public int ParentID { get; set; }
|
||
public EnumBulkUploadMasterData ParentMasterData { get; set; }
|
||
public string ParentMasterName { get; set; }
|
||
|
||
/// <summary>Institution only: the type its uses suggest — 1 Academic, 2 Institutional, 3 both.</summary>
|
||
public int SuggestedInstituteType { get; set; }
|
||
|
||
public List<string> UsedIn { get; set; }
|
||
public List<int> RowNos { get; set; }
|
||
}
|
||
|
||
/// <summary>What a save did — or, when nothing was saved, why.</summary>
|
||
public class EmployeeBulkUploadSaveResult
|
||
{
|
||
public EmployeeBulkUploadSaveResult()
|
||
{
|
||
Lines = new List<string>();
|
||
}
|
||
|
||
public bool Saved { get; set; }
|
||
public string Message { get; set; }
|
||
public int CreatedCount { get; set; }
|
||
public int UpdatedCount { get; set; }
|
||
|
||
/// <summary>One line per employee: what was created or updated.</summary>
|
||
public List<string> Lines { get; set; }
|
||
|
||
/// <summary>The validation the save ran first; set when the file no longer passes it.</summary>
|
||
public EmployeeBulkUploadReadResult Validation { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// What was read from an uploaded file: the sections the user declared (Template sections),
|
||
/// the validation layers in the order they ran, every problem (cell-level and file-level),
|
||
/// and — whenever the file could be read — the sections it holds (in template order) and its
|
||
/// employee rows, problems or not.
|
||
/// </summary>
|
||
public class EmployeeBulkUploadReadResult
|
||
{
|
||
public EmployeeBulkUploadReadResult()
|
||
{
|
||
Groups = new List<EmployeeBulkUploadGroup>();
|
||
Rows = new List<EmployeeBulkUploadRow>();
|
||
Layers = new List<EmployeeBulkUploadLayer>();
|
||
Issues = new List<EmployeeBulkUploadIssue>();
|
||
MissingMasterData = new List<EmployeeBulkUploadMissingMaster>();
|
||
CloseMatches = new List<EmployeeBulkUploadCloseMatch>();
|
||
ExactMatches = new List<EmployeeBulkUploadCloseMatch>();
|
||
RowLabels = new Dictionary<int, string>();
|
||
SheetColumns = new Dictionary<string, int>();
|
||
SelectedSubGroups = new List<string>();
|
||
ReplacedCells = new List<EmployeeBulkUploadReplacedCell>();
|
||
}
|
||
|
||
public string FileName { get; set; }
|
||
|
||
/// <summary>
|
||
/// The cells whose master-data value was replaced by an existing record chosen in the
|
||
/// master-data dialog (see <see cref="EmployeeBulkUploadReplacement"/>) — the rows already
|
||
/// hold the new value; this says what the file had.
|
||
/// </summary>
|
||
public List<EmployeeBulkUploadReplacedCell> ReplacedCells { get; set; }
|
||
|
||
/// <summary>
|
||
/// The sections the user said this upload holds, as resolved band names (Employee first).
|
||
/// This — not the file — is what the later steps (validation, save) act on.
|
||
/// </summary>
|
||
public List<string> SelectedSubGroups { get; set; }
|
||
|
||
public List<EmployeeBulkUploadGroup> Groups { get; set; }
|
||
public List<EmployeeBulkUploadRow> Rows { get; set; }
|
||
public List<EmployeeBulkUploadLayer> Layers { get; set; }
|
||
|
||
/// <summary>Cell-level problems found by the value layers, in row order.</summary>
|
||
public List<EmployeeBulkUploadIssue> Issues { get; set; }
|
||
|
||
/// <summary>
|
||
/// How many employee rows the file holds — kept even when a later layer fails and
|
||
/// <see cref="Rows"/> is cleared; 0 when the rows were never read.
|
||
/// </summary>
|
||
public int RowCount { get; set; }
|
||
|
||
/// <summary>The first layer that failed; 0 when every layer passed.</summary>
|
||
public int FailedLayerNo
|
||
{
|
||
get
|
||
{
|
||
EmployeeBulkUploadLayer failed = Layers
|
||
.FirstOrDefault(x => x.Status == EnumBulkUploadCheckStatus.Failed);
|
||
return failed == null ? 0 : failed.LayerNo;
|
||
}
|
||
}
|
||
|
||
public EmployeeBulkUploadLayer AddLayer(int layerNo, string name, string description)
|
||
{
|
||
EmployeeBulkUploadLayer layer = new EmployeeBulkUploadLayer(layerNo, name, description);
|
||
Layers.Add(layer);
|
||
return layer;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Master-data values the file uses that the system does not have (filled by the master
|
||
/// data layer) — one entry per distinct value (and parent), whether or not it can be
|
||
/// added from the upload page.
|
||
/// </summary>
|
||
public List<EmployeeBulkUploadMissingMaster> MissingMasterData { get; set; }
|
||
|
||
/// <summary>Master-data values taken as a close (not exact) match — the user confirms them before saving.</summary>
|
||
public List<EmployeeBulkUploadCloseMatch> CloseMatches { get; set; }
|
||
|
||
/// <summary>Master-data values that match a record exactly (Percent 100) — shown in the master-data dialog.</summary>
|
||
public List<EmployeeBulkUploadCloseMatch> ExactMatches { get; set; }
|
||
|
||
/// <summary>"E001 Rahim" per Excel row — how check details name the employee of a row. Server-side only.</summary>
|
||
[Newtonsoft.Json.JsonIgnore]
|
||
public Dictionary<int, string> RowLabels { get; set; }
|
||
|
||
/// <summary>Sheet column number of each template column (by column key), for the issues' cell addresses. Server-side only.</summary>
|
||
[Newtonsoft.Json.JsonIgnore]
|
||
public Dictionary<string, int> SheetColumns { get; set; }
|
||
|
||
/// <summary>Rows whose Employee No is not in the current payroll type yet — saved as new employees.</summary>
|
||
public int NewEmployeeCount { get; set; }
|
||
|
||
/// <summary>Rows whose Employee No is in the current payroll type — saved as updates.</summary>
|
||
public int ExistingEmployeeCount { get; set; }
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Master data
|
||
|
||
/// <summary>
|
||
/// What the bulk upload knows about each master table: its display name, the parent it
|
||
/// belongs under, and whether a missing value may be added from the upload page.
|
||
/// </summary>
|
||
public static class EmployeeBulkUploadMasterInfo
|
||
{
|
||
/// <summary>The order the add dialog lists (and so adds) tables in: parents before children.</summary>
|
||
public static readonly EnumBulkUploadMasterData[] AddOrder =
|
||
{
|
||
EnumBulkUploadMasterData.Category,
|
||
EnumBulkUploadMasterData.Religion,
|
||
EnumBulkUploadMasterData.Nationality,
|
||
EnumBulkUploadMasterData.Occupation,
|
||
EnumBulkUploadMasterData.PersonRelation,
|
||
EnumBulkUploadMasterData.District,
|
||
EnumBulkUploadMasterData.Thana,
|
||
EnumBulkUploadMasterData.Country,
|
||
EnumBulkUploadMasterData.EducationType,
|
||
EnumBulkUploadMasterData.EducationLevel,
|
||
EnumBulkUploadMasterData.Discipline,
|
||
EnumBulkUploadMasterData.Institution,
|
||
EnumBulkUploadMasterData.ResultType,
|
||
EnumBulkUploadMasterData.NominationPurpose,
|
||
EnumBulkUploadMasterData.TrainingType,
|
||
EnumBulkUploadMasterData.NatureOfTraining,
|
||
EnumBulkUploadMasterData.Grades,
|
||
EnumBulkUploadMasterData.Employee
|
||
};
|
||
|
||
public static string DisplayName(EnumBulkUploadMasterData masterData)
|
||
{
|
||
switch (masterData)
|
||
{
|
||
case EnumBulkUploadMasterData.Grades: return "Grade";
|
||
case EnumBulkUploadMasterData.PersonRelation: return "Relation";
|
||
case EnumBulkUploadMasterData.EducationType: return "Education Platform";
|
||
case EnumBulkUploadMasterData.EducationLevel: return "Education Level";
|
||
case EnumBulkUploadMasterData.ResultType: return "Result Type";
|
||
case EnumBulkUploadMasterData.NominationPurpose: return "Nomination Purpose";
|
||
case EnumBulkUploadMasterData.TrainingType: return "Training Type";
|
||
case EnumBulkUploadMasterData.NatureOfTraining: return "Nature of Training";
|
||
case EnumBulkUploadMasterData.Employee: return "Line Manager";
|
||
default: return masterData.ToString();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// The table a record of <paramref name="masterData"/> belongs under — the District of a
|
||
/// Thana, the Education Platform of an Education Level, the Education Level of a
|
||
/// Discipline, the Division of a District — or None.
|
||
/// </summary>
|
||
public static EnumBulkUploadMasterData ParentOf(EnumBulkUploadMasterData masterData)
|
||
{
|
||
switch (masterData)
|
||
{
|
||
case EnumBulkUploadMasterData.Thana: return EnumBulkUploadMasterData.District;
|
||
case EnumBulkUploadMasterData.EducationLevel: return EnumBulkUploadMasterData.EducationType;
|
||
case EnumBulkUploadMasterData.Discipline: return EnumBulkUploadMasterData.EducationLevel;
|
||
default: return EnumBulkUploadMasterData.None;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Null when a missing value of this table may be added from the upload page; otherwise
|
||
/// why not. A Grade carries payroll settings (basic range, basic % of gross, pay scale)
|
||
/// that cannot be guessed from a name, and a Line Manager must be a real employee.
|
||
/// </summary>
|
||
public static string CannotAddReason(EnumBulkUploadMasterData masterData)
|
||
{
|
||
switch (masterData)
|
||
{
|
||
case EnumBulkUploadMasterData.Grades:
|
||
return "A Grade carries payroll settings (basic range, basic % of gross) that cannot be taken "
|
||
+ "from a name. Create it in the Grade screen, or correct the value in the file.";
|
||
case EnumBulkUploadMasterData.Employee:
|
||
return "A Line Manager must be an existing, live employee of this payroll type. Correct the "
|
||
+ "Employee No in the file.";
|
||
default:
|
||
return null;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>A master-data value the file uses that the system does not have.</summary>
|
||
public class EmployeeBulkUploadMissingMaster
|
||
{
|
||
public EmployeeBulkUploadMissingMaster()
|
||
{
|
||
UsedIn = new List<string>();
|
||
RowNos = new List<int>();
|
||
}
|
||
|
||
public EnumBulkUploadMasterData MasterData { get; set; }
|
||
public string MasterName { get; set; }
|
||
|
||
/// <summary>The value as the file spells it (its first occurrence).</summary>
|
||
public string Value { get; set; }
|
||
|
||
/// <summary>The parent value from the same row block (e.g. the District of a Thana); null when none.</summary>
|
||
public string ParentValue { get; set; }
|
||
public EnumBulkUploadMasterData ParentMasterData { get; set; }
|
||
public string ParentMasterName { get; set; }
|
||
|
||
/// <summary>The parent record's ID when the parent value exists; 0 otherwise.</summary>
|
||
public int ParentID { get; set; }
|
||
|
||
/// <summary>True when the parent value is itself missing — it has to be added first.</summary>
|
||
public bool ParentIsMissing { get; set; }
|
||
|
||
public bool CanAdd { get; set; }
|
||
public string CannotAddReason { get; set; }
|
||
|
||
/// <summary>Where the value is used, e.g. "Present Address — District".</summary>
|
||
public List<string> UsedIn { get; set; }
|
||
public List<int> RowNos { get; set; }
|
||
|
||
/// <summary>Institution only: the type its uses suggest — 1 Academic, 2 Institutional, 3 both.</summary>
|
||
public int SuggestedInstituteType { get; set; }
|
||
}
|
||
|
||
/// <summary>A request to add missing values to one master table.</summary>
|
||
public class EmployeeBulkUploadMasterAddRequest
|
||
{
|
||
public EmployeeBulkUploadMasterAddRequest()
|
||
{
|
||
Items = new List<EmployeeBulkUploadMasterAddItem>();
|
||
}
|
||
|
||
public EnumBulkUploadMasterData MasterData { get; set; }
|
||
|
||
/// <summary>The page's current payroll type — used only when the login token has none.</summary>
|
||
public int PayrollTypeID { get; set; }
|
||
|
||
public List<EmployeeBulkUploadMasterAddItem> Items { get; set; }
|
||
}
|
||
|
||
/// <summary>One value to add, with what that table needs besides the name.</summary>
|
||
public class EmployeeBulkUploadMasterAddItem
|
||
{
|
||
public string Value { get; set; }
|
||
|
||
/// <summary>Thana / Education Level / Discipline: the parent's name from the file, or …</summary>
|
||
public string ParentValue { get; set; }
|
||
|
||
/// <summary>… the parent picked in the dialog when the file has none. Also the Division of a District.</summary>
|
||
public int ParentID { get; set; }
|
||
|
||
/// <summary>Education Level, Institution: true = Board Required, false = Fixed Subject (exactly one applies).</summary>
|
||
public bool? BoardRequired { get; set; }
|
||
|
||
/// <summary>Institution: 1 Academic, 2 Institutional, 3 Academic and Institutional.</summary>
|
||
public int InstituteType { get; set; }
|
||
|
||
/// <summary>Result Type: 1 GPA/CGPA, 2 Marks, 3 Pass/Fail.</summary>
|
||
public int ResultType { get; set; }
|
||
}
|
||
|
||
public class EmployeeBulkUploadMasterAddResult
|
||
{
|
||
public string Value { get; set; }
|
||
public string ParentValue { get; set; }
|
||
public bool Saved { get; set; }
|
||
public bool AlreadyExisted { get; set; }
|
||
public int ID { get; set; }
|
||
public string Message { get; set; }
|
||
}
|
||
|
||
public class EmployeeBulkUploadMasterOption
|
||
{
|
||
public int ID { get; set; }
|
||
public string Name { get; set; }
|
||
|
||
/// <summary>The District of a Thana, the Education Platform of an Education Level, ...; 0 when none.</summary>
|
||
public int ParentID { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// "Use this existing record instead": a master-data value of the file (not found, or only a
|
||
/// partial match) is replaced, in every cell of that table that holds it, by the record the
|
||
/// user picked in the master-data dialog. The file itself is not changed — the replacements
|
||
/// travel with every read and with the save, so both see the same values.
|
||
/// </summary>
|
||
public class EmployeeBulkUploadReplacement
|
||
{
|
||
public EnumBulkUploadMasterData MasterData { get; set; }
|
||
|
||
/// <summary>The value as the file holds it (matched ignoring case and extra spaces).</summary>
|
||
public string Value { get; set; }
|
||
|
||
/// <summary>
|
||
/// For a table matched within its parent (Thana, Education Level): the parent value of the
|
||
/// same block, so only the cells under that parent are replaced. Null for any other table.
|
||
/// </summary>
|
||
public string ParentValue { get; set; }
|
||
|
||
/// <summary>The existing record to use instead.</summary>
|
||
public int ReplacementID { get; set; }
|
||
}
|
||
|
||
/// <summary>One cell whose value was replaced by an <see cref="EmployeeBulkUploadReplacement"/>.</summary>
|
||
public class EmployeeBulkUploadReplacedCell
|
||
{
|
||
public int RowNo { get; set; }
|
||
public string ColumnKey { get; set; }
|
||
public string SubGroup { get; set; }
|
||
public string Column { get; set; }
|
||
public EnumBulkUploadMasterData MasterData { get; set; }
|
||
|
||
/// <summary>What the file had.</summary>
|
||
public string From { get; set; }
|
||
|
||
/// <summary>The chosen record's name, now in the row.</summary>
|
||
public string To { get; set; }
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region IEmployeeBulkUploadService
|
||
|
||
public interface IEmployeeBulkUploadService
|
||
{
|
||
/// <summary>The empty Employee Bulk Upload workbook, as .xlsx bytes.</summary>
|
||
byte[] GetTemplate();
|
||
|
||
/// <summary>
|
||
/// The workbook holding only the chosen sub-groups (row-2 band names); null or empty
|
||
/// means all of them. Employee (Employee No, Employee Name) is always included.
|
||
/// </summary>
|
||
byte[] GetTemplate(List<string> subGroupNames);
|
||
|
||
/// <summary>
|
||
/// Validates an uploaded workbook layer by layer and, when every layer passes, returns
|
||
/// its sections and employee rows. <paramref name="stream"/> may be null (no file
|
||
/// received); <paramref name="requestedSubGroups"/> is the Template sections selection
|
||
/// as posted, unresolved. Every validation problem is reported in the result's layers —
|
||
/// only an unexpected failure throws.
|
||
/// </summary>
|
||
EmployeeBulkUploadReadResult ReadUpload(Stream stream, string fileName, long fileLength,
|
||
List<string> requestedSubGroups, int payrollTypeID, List<EmployeeBulkUploadReplacement> replacements = null);
|
||
|
||
/// <summary>
|
||
/// Adds missing values to ONE master table, one record at a time through that table's own
|
||
/// service Save — each record in its own transaction, so one failure does not undo the
|
||
/// others. A value that exists by now is reported, not added again.
|
||
/// </summary>
|
||
List<EmployeeBulkUploadMasterAddResult> AddMasterData(EmployeeBulkUploadMasterAddRequest request,
|
||
int payrollTypeID, int userID);
|
||
|
||
/// <summary>The active records of a master table, for the add dialog's pickers.</summary>
|
||
List<EmployeeBulkUploadMasterOption> GetMasterOptions(EnumBulkUploadMasterData masterData, int payrollTypeID);
|
||
|
||
/// <summary>
|
||
/// Validates the file again (every layer) and, when it passes, saves every row in ONE
|
||
/// transaction — all rows or none. A row whose Employee No is in the current payroll
|
||
/// type updates that employee (only the cells the file fills); any other row creates a
|
||
/// new employee. Repeat sections add records, or update the matching one. Close matches
|
||
/// must have been confirmed (<paramref name="closeMatchesConfirmed"/>).
|
||
/// </summary>
|
||
EmployeeBulkUploadSaveResult SaveUpload(Stream stream, string fileName, long fileLength,
|
||
List<string> requestedSubGroups, int payrollTypeID, int userID, bool closeMatchesConfirmed,
|
||
List<EmployeeBulkUploadReplacement> replacements = null);
|
||
}
|
||
|
||
#endregion
|
||
} |