From c8c032f86ce6efbc2687e7ac15af8badc16cd113 Mon Sep 17 00:00:00 2001 From: Mohaimen Hasan Date: Mon, 30 Nov 2026 14:32:23 +0600 Subject: [PATCH] ProgressBarDone --- .../Service/Salary/SalaryProcessProgress.cs | 38 ++++++++++++------- HRM.UI/appsettings.json | 4 +- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/HRM.DA/Service/Salary/SalaryProcessProgress.cs b/HRM.DA/Service/Salary/SalaryProcessProgress.cs index 2b42a9e..670ef71 100644 --- a/HRM.DA/Service/Salary/SalaryProcessProgress.cs +++ b/HRM.DA/Service/Salary/SalaryProcessProgress.cs @@ -12,7 +12,7 @@ namespace HRM.DA /// /// The run is split into stages, in the exact order they happen: /// Validating -> Preparing calculation (SalaryCalculator ctor, approval check, Process() set-up + Initialize) - /// -> the 12 first calculation phases -> Salary exception -> Net income -> Saving. + /// -> the calculation phases up to leave days -> Salary exception -> Net income -> Saving. /// A calculation phase starts with the ProgressStatus Start event (its first statement in SalaryCalculator) and /// moves one step per PerformStep (one per employee / salary row; Basic salary has two such loops). /// "Salary exception" has no events of its own: it is recognised by the status message Process() already sends. @@ -37,6 +37,7 @@ namespace HRM.DA "Calculating bonus", "Calculating unauthorized leave deduction", "Calculating PF & CPF", + "Calculating on-balance salary", "Calculating income tax", "Preparing cost-center data", "Calculating loan installments", @@ -45,17 +46,20 @@ namespace HRM.DA "Calculating net income" }; - // Loops (of one step per salary row) a phase runs; Basic salary also loops for arrears. - private static readonly int[] PhaseLoops = { 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; + // Loops (of one step per salary row) a phase runs; Basic salary also loops for arrears. On-balance raises + // no steps (it only gets its Start), so its slice fills when the next phase starts. + private static readonly int[] PhaseLoops = { 1, 2, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 }; - // Stages = Validating, Preparing, phases 0..11, Salary exception, phase 12 (net income), Saving. + // Stages = Validating, Preparing, every phase but the last, Salary exception, the last phase (net income), Saving. + // Salary exception runs between leave days and net income and has no Start event of its own. + private static readonly int LastPhase = PhaseNames.Length - 1; // net income private const int StageValidating = 0; private const int StagePreparing = 1; - private const int StageFirstPhase = 2; // phase p (0..11) -> stage 2 + p - private const int StageSalaryException = 14; - private const int StageNetIncome = 15; // phase 12 - private const int StageSaving = 16; - private const int StageCount = 17; + private const int StageFirstPhase = 2; // phase p (< LastPhase) -> stage 2 + p + private static readonly int StageSalaryException = StageFirstPhase + LastPhase; + private static readonly int StageNetIncome = StageSalaryException + 1; + private static readonly int StageSaving = StageNetIncome + 1; + private static readonly int StageCount = StageSaving + 1; private static readonly double[] DefaultWeights = BuildDefaultWeights(); @@ -80,7 +84,7 @@ namespace HRM.DA private readonly int _employeeCount; private readonly double[] _stageStart; // percent where each stage begins private readonly double[] _stageShare; // percent each stage spans - private readonly double[] _secondsSpent = new double[StageCount]; + private readonly double[] _secondsSpent; private readonly Stopwatch _clock = Stopwatch.StartNew(); private int _stage = -1; @@ -94,6 +98,7 @@ namespace HRM.DA _progress = progress; _payrollTypeId = payrollTypeId; _employeeCount = Math.Max(1, employeeCount); + _secondsSpent = new double[StageCount]; double[] weights = WeightsFor(payrollTypeId, _employeeCount); double total = 0; @@ -183,7 +188,7 @@ namespace HRM.DA _step = 0; _detail = null; int phase = Math.Min(_phase, PhaseNames.Length - 1); - Enter(phase < 12 ? StageFirstPhase + phase : StageNetIncome, PhaseNames[phase]); + Enter(StageOf(phase), PhaseNames[phase]); } else if (status == EnumProcessStatus.PerformStep) { @@ -199,7 +204,9 @@ namespace HRM.DA if (_phase < 0) return; int phase = Math.Min(_phase, PhaseNames.Length - 1); - int stage = phase < 12 ? StageFirstPhase + phase : StageNetIncome; + if (PhaseLoops[phase] == 0) + return; // a phase without steps stays at its start until the next stage + int stage = StageOf(phase); int expected = _employeeCount * PhaseLoops[phase]; double inside = Math.Min((double)_step / expected, 0.999); int shown = Math.Min(_step, expected); @@ -208,6 +215,11 @@ namespace HRM.DA _progress.Report(_stageStart[stage] + _stageShare[stage] * inside, PhaseNames[phase], _detail, employeesDone, _employeeCount); } + private static int StageOf(int phase) + { + return phase < LastPhase ? StageFirstPhase + phase : StageNetIncome; + } + private void Enter(int stage, string name) { if (stage == _stage) @@ -253,7 +265,7 @@ namespace HRM.DA double[] w = new double[StageCount]; w[StageValidating] = 2; w[StagePreparing] = 3; - for (int p = 0; p < 12; p++) w[StageFirstPhase + p] = 6.5; + for (int p = 0; p < LastPhase; p++) w[StageFirstPhase + p] = 6.5; w[StageSalaryException] = 0.5; w[StageNetIncome] = 6.5; w[StageSaving] = 10; diff --git a/HRM.UI/appsettings.json b/HRM.UI/appsettings.json index b164580..fadd8ef 100644 --- a/HRM.UI/appsettings.json +++ b/HRM.UI/appsettings.json @@ -52,8 +52,8 @@ //"Default": "provider=sql;sqlSyntax=SQL;server=103.197.204.164,1718;Database=MasterProjectDB;User Id=DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;", //"SqlCommandConnection": "Data Source=103.197.204.164,1718;Initial Catalog=autocrop;Persist Security Info=True; User ID=DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;", // Development - "Default": "provider=sql;sqlSyntax=SQL;server=103.197.204.164,1718;Database=MasterProjectDBUATBRAC;User Id= DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;", - "SqlCommandConnection": "Data Source=103.197.204.164,1718;Initial Catalog=MasterProjectDBUATBRAC;Persist Security Info=True; User ID=DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;" // Development + "Default": "provider=sql;sqlSyntax=SQL;server=103.197.204.164,1718;Database=MasterProjectDBBRAC;User Id= DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;", + "SqlCommandConnection": "Data Source=103.197.204.164,1718;Initial Catalog=MasterProjectDBBRAC;Persist Security Info=True; User ID=DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;" // Development }, "Calendar": {