ProgressBarDone

This commit is contained in:
Mohaimen Hasan 2026-11-30 14:32:23 +06:00
parent 5ecdda0a0f
commit c8c032f86c
2 changed files with 27 additions and 15 deletions

View File

@ -12,7 +12,7 @@ namespace HRM.DA
/// ///
/// The run is split into stages, in the exact order they happen: /// The run is split into stages, in the exact order they happen:
/// Validating -> Preparing calculation (SalaryCalculator ctor, approval check, Process() set-up + Initialize) /// 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 /// 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). /// 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. /// "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 bonus",
"Calculating unauthorized leave deduction", "Calculating unauthorized leave deduction",
"Calculating PF & CPF", "Calculating PF & CPF",
"Calculating on-balance salary",
"Calculating income tax", "Calculating income tax",
"Preparing cost-center data", "Preparing cost-center data",
"Calculating loan installments", "Calculating loan installments",
@ -45,17 +46,20 @@ namespace HRM.DA
"Calculating net income" "Calculating net income"
}; };
// Loops (of one step per salary row) a phase runs; Basic salary also loops for arrears. // Loops (of one step per salary row) a phase runs; Basic salary also loops for arrears. On-balance raises
private static readonly int[] PhaseLoops = { 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; // 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 StageValidating = 0;
private const int StagePreparing = 1; private const int StagePreparing = 1;
private const int StageFirstPhase = 2; // phase p (0..11) -> stage 2 + p private const int StageFirstPhase = 2; // phase p (< LastPhase) -> stage 2 + p
private const int StageSalaryException = 14; private static readonly int StageSalaryException = StageFirstPhase + LastPhase;
private const int StageNetIncome = 15; // phase 12 private static readonly int StageNetIncome = StageSalaryException + 1;
private const int StageSaving = 16; private static readonly int StageSaving = StageNetIncome + 1;
private const int StageCount = 17; private static readonly int StageCount = StageSaving + 1;
private static readonly double[] DefaultWeights = BuildDefaultWeights(); private static readonly double[] DefaultWeights = BuildDefaultWeights();
@ -80,7 +84,7 @@ namespace HRM.DA
private readonly int _employeeCount; private readonly int _employeeCount;
private readonly double[] _stageStart; // percent where each stage begins private readonly double[] _stageStart; // percent where each stage begins
private readonly double[] _stageShare; // percent each stage spans 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 readonly Stopwatch _clock = Stopwatch.StartNew();
private int _stage = -1; private int _stage = -1;
@ -94,6 +98,7 @@ namespace HRM.DA
_progress = progress; _progress = progress;
_payrollTypeId = payrollTypeId; _payrollTypeId = payrollTypeId;
_employeeCount = Math.Max(1, employeeCount); _employeeCount = Math.Max(1, employeeCount);
_secondsSpent = new double[StageCount];
double[] weights = WeightsFor(payrollTypeId, _employeeCount); double[] weights = WeightsFor(payrollTypeId, _employeeCount);
double total = 0; double total = 0;
@ -183,7 +188,7 @@ namespace HRM.DA
_step = 0; _step = 0;
_detail = null; _detail = null;
int phase = Math.Min(_phase, PhaseNames.Length - 1); 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) else if (status == EnumProcessStatus.PerformStep)
{ {
@ -199,7 +204,9 @@ namespace HRM.DA
if (_phase < 0) if (_phase < 0)
return; return;
int phase = Math.Min(_phase, PhaseNames.Length - 1); 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]; int expected = _employeeCount * PhaseLoops[phase];
double inside = Math.Min((double)_step / expected, 0.999); double inside = Math.Min((double)_step / expected, 0.999);
int shown = Math.Min(_step, expected); 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); _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) private void Enter(int stage, string name)
{ {
if (stage == _stage) if (stage == _stage)
@ -253,7 +265,7 @@ namespace HRM.DA
double[] w = new double[StageCount]; double[] w = new double[StageCount];
w[StageValidating] = 2; w[StageValidating] = 2;
w[StagePreparing] = 3; 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[StageSalaryException] = 0.5;
w[StageNetIncome] = 6.5; w[StageNetIncome] = 6.5;
w[StageSaving] = 10; w[StageSaving] = 10;

View File

@ -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;", //"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 //"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;", "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=MasterProjectDBUATBRAC;Persist Security Info=True; User ID=DBuser;Password=ceLEa&e2025;TrustServerCertificate=True;" // Development "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": { "Calendar": {