diff --git a/HRM.BO/Bonus/Bonus.cs b/HRM.BO/Bonus/Bonus.cs index 5fd7184..bfe9b38 100644 --- a/HRM.BO/Bonus/Bonus.cs +++ b/HRM.BO/Bonus/Bonus.cs @@ -72,6 +72,17 @@ namespace HRM.BO #endregion + #region ReligionIDs / ReligionNames : string (BonusReligion, not Bonus columns) + + // Comma-separated ReligionIDs of this bonus (table BonusReligion). + // null = not loaded: Save leaves the BonusReligion rows untouched. + public string ReligionIDs { get; set; } + + // Comma-separated religion names, for display only. + public string ReligionNames { get; set; } + + #endregion + //#region Service Factory IBonusService : IBonusService diff --git a/HRM.DA/DA/Bonus/BonusDA.cs b/HRM.DA/DA/Bonus/BonusDA.cs index 1083cae..c731dd3 100644 --- a/HRM.DA/DA/Bonus/BonusDA.cs +++ b/HRM.DA/DA/Bonus/BonusDA.cs @@ -121,6 +121,36 @@ namespace HRM.DA #endregion + #region BonusReligion + + internal static void InsertReligion(TransactionContext tc, int bonusReligionID, int bonusID, int religionID) + { + tc.ExecuteNonQuery("INSERT INTO BonusReligion(BonusReligionID, BonusID, ReligionID) VALUES(%n, %n, %n)", + bonusReligionID, bonusID, religionID); + } + + internal static void DeleteReligions(TransactionContext tc, int bonusID) + { + tc.ExecuteNonQuery("DELETE FROM BonusReligion WHERE BonusID=%n", bonusID); + } + + internal static IDataReader GetReligions(TransactionContext tc, int bonusID) + { + return tc.ExecuteReader( + "SELECT br.BonusID, br.ReligionID, r.Name FROM BonusReligion br INNER JOIN Religion r ON r.ReligionID = br.ReligionID" + + " WHERE br.BonusID=%n ORDER BY r.SequenceNo, r.Name", bonusID); + } + + internal static IDataReader GetReligionsByPayrollType(TransactionContext tc, int payrollTypeID) + { + return tc.ExecuteReader( + "SELECT br.BonusID, br.ReligionID, r.Name FROM BonusReligion br INNER JOIN Religion r ON r.ReligionID = br.ReligionID" + + " INNER JOIN Bonus b ON b.BonusID = br.BonusID WHERE b.PayrollTypeID=%n ORDER BY br.BonusID, r.SequenceNo, r.Name", + payrollTypeID); + } + + #endregion + #region CC Wise Bonus Summary internal static DataSet GetCCWiseBonusSummary(TransactionContext tc, DateTime bMonthDate, string bonus) { diff --git a/HRM.DA/Service/Bonus/BonusService.cs b/HRM.DA/Service/Bonus/BonusService.cs index c9443e0..632bac2 100644 --- a/HRM.DA/Service/Bonus/BonusService.cs +++ b/HRM.DA/Service/Bonus/BonusService.cs @@ -51,6 +51,76 @@ namespace HRM.DA return oBonus; } + #region BonusReligion + + // Replaces the bonus's BonusReligion rows with oBonus.ReligionIDs ("1,3"; "" = none). + private void SaveReligions(TransactionContext tc, Bonus oBonus) + { + BonusDA.DeleteReligions(tc, oBonus.ID); + + List religionIDs = new List(); + foreach (string part in oBonus.ReligionIDs.Split(',')) + { + int religionID; + if (int.TryParse(part.Trim(), out religionID) && religionID > 0 && !religionIDs.Contains(religionID)) + religionIDs.Add(religionID); + } + + foreach (int religionID in religionIDs) + { + int id = tc.GenerateID("BonusReligion", "BonusReligionID"); + BonusDA.InsertReligion(tc, id, oBonus.ID, religionID); + } + + FillReligions(tc, oBonus); + } + + private void FillReligions(TransactionContext tc, Bonus oBonus) + { + List ids = new List(); + List names = new List(); + DataReader dr = new DataReader(BonusDA.GetReligions(tc, oBonus.ID)); + while (dr.Read()) + { + ids.Add(dr.GetInt32("ReligionID").Value.ToString()); + names.Add(dr.GetString("Name")); + } + dr.Close(); + + oBonus.ReligionIDs = string.Join(",", ids); + oBonus.ReligionNames = string.Join(", ", names); + } + + private void FillReligions(TransactionContext tc, List bonuses, int payrollTypeID) + { + if (bonuses == null || bonuses.Count == 0) + return; + + Dictionary> ids = new Dictionary>(); + Dictionary> names = new Dictionary>(); + DataReader dr = new DataReader(BonusDA.GetReligionsByPayrollType(tc, payrollTypeID)); + while (dr.Read()) + { + int bonusID = dr.GetInt32("BonusID").Value; + if (!ids.ContainsKey(bonusID)) + { + ids.Add(bonusID, new List()); + names.Add(bonusID, new List()); + } + ids[bonusID].Add(dr.GetInt32("ReligionID").Value.ToString()); + names[bonusID].Add(dr.GetString("Name")); + } + dr.Close(); + + foreach (Bonus oBonus in bonuses) + { + oBonus.ReligionIDs = ids.ContainsKey(oBonus.ID) ? string.Join(",", ids[oBonus.ID]) : string.Empty; + oBonus.ReligionNames = names.ContainsKey(oBonus.ID) ? string.Join(", ", names[oBonus.ID]) : string.Empty; + } + } + + #endregion + #region Service implementation public Bonus Get(int id) @@ -68,6 +138,8 @@ namespace HRM.DA } oreader.Close(); + if (!oBonus.IsNew) + FillReligions(tc, oBonus); tc.End(); } catch (Exception e) @@ -97,6 +169,8 @@ namespace HRM.DA } oreader.Close(); + if (!oBonus.IsNew) + FillReligions(tc, oBonus); } catch (Exception e) { @@ -125,6 +199,7 @@ namespace HRM.DA DataReader dr = new DataReader(BonusDA.Get(tc, status, payrollTypeID)); bonuss = this.CreateObjects(dr); dr.Close(); + FillReligions(tc, bonuss, payrollTypeID); tc.End(); } @@ -224,6 +299,9 @@ namespace HRM.DA BonusDA.Update(tc, oBonus); } + if (oBonus.ReligionIDs != null) + SaveReligions(tc, oBonus); + tc.End(); return oBonus.ID; } @@ -246,6 +324,7 @@ namespace HRM.DA try { tc = TransactionContext.Begin(true); + BonusDA.DeleteReligions(tc, id); BonusDA.Delete(tc, id); tc.End(); } diff --git a/HRM.UI/ClientApp/src/app/ess/component-uploader/component-uploader.component.ts b/HRM.UI/ClientApp/src/app/ess/component-uploader/component-uploader.component.ts index 3696387..8dc4c70 100644 --- a/HRM.UI/ClientApp/src/app/ess/component-uploader/component-uploader.component.ts +++ b/HRM.UI/ClientApp/src/app/ess/component-uploader/component-uploader.component.ts @@ -105,7 +105,7 @@ export class EssComponentUploaderComponent implements OnInit { private loadUploadDeadline(): void { this.basicService.getComponentUploadDeadline().subscribe( (resp: any) => { - //this.deadlinePassed = !!resp && resp.allowed === false; + this.deadlinePassed = !!resp && resp.allowed === false; this.uploadDeadline = (resp && resp.deadline) ? new Date(resp.deadline) : null; if (resp && resp.salaryMonth) { this.salaryMonth = new Date(resp.salaryMonth); } }, diff --git a/HRM.UI/ClientApp/src/app/form-builder/Basic-Entry-Form-Control.component.ts b/HRM.UI/ClientApp/src/app/form-builder/Basic-Entry-Form-Control.component.ts index fe5591d..efbfee3 100644 --- a/HRM.UI/ClientApp/src/app/form-builder/Basic-Entry-Form-Control.component.ts +++ b/HRM.UI/ClientApp/src/app/form-builder/Basic-Entry-Form-Control.component.ts @@ -41,6 +41,15 @@ export class BasicEntryControlComponent implements OnInit { //basiccontrol: BasicEntryFormControl; applyBanglaFont: boolean = false; get isValid() { return this.form.controls[this.basiccontrol.controlID].valid; } + // the control's own placeholder, else "Select