Bonus Process

This commit is contained in:
Mohaimen Hasan 2026-11-11 15:54:19 +06:00
parent 9944262dd1
commit a458cdba4c
4 changed files with 154 additions and 63 deletions

View File

@ -212,17 +212,54 @@ namespace HRM.DA
DataSet oIncomeTaxs = new DataSet();
try
{
string sql = SQLParser.MakeSQL(@"select salarytax.EMPLOYEENO,salarytax.Name,salarytax.EMPLOYEEID, salarytax.TaxAmount SalaryData, st.thisyeartotal TaxData from
// The employee IDs used to be spliced in twice as "in(1,2,3,...)". With 10k+ employees
// SQL Server cannot build a plan for that ("The query processor ran out of internal
// resources", error 8623). Now they go in as ONE varchar(max) parameter, land in a temp
// table with a primary key, and both parts of the UNION read "in (SELECT ID FROM #tdrEmpIds)".
// The query itself (columns, conditions, result) is unchanged. Needs SQL Server 2016+ (STRING_SPLIT).
List<string> ids = new List<string>();
foreach (string part in (empids ?? string.Empty).Split(','))
{
string id = part.Trim();
if (id.Length == 0) continue;
if (!int.TryParse(id, out int empId))
throw new ArgumentException("Invalid employee id: " + id);
ids.Add(empId.ToString());
}
//string sql = SQLParser.MakeSQL(@"select salarytax.EMPLOYEENO,salarytax.Name,salarytax.EMPLOYEEID, salarytax.TaxAmount SalaryData, st.thisyeartotal TaxData from
// (Select tab.EMPLOYEENO,tab.Name,tab.EMPLOYEEID,sum(tab.TaxAmount) TaxAmount from
// (Select e.EMPLOYEENO,e.Name,e.EMPLOYEEID,sd.CHANGEDAMOUNT TaxAmount,s.salarymonth from SALARYMONTHLYDETAIL sd, SALARYMONTHLY s,Employee e where s.EMPLOYEEID=e.EMPLOYEEID and sd.SALARYMONTHLYID=s.SALARYMONTHLYID and s.SALARYMONTH
// between %d and %d and ITEMCODE=-129 and ITEMID=-129 and s.EMPLOYEEID in(%q)
// union
// Select e.EMPLOYEENO,e.Name,e.EMPLOYEEID,s.CHANGETAXAMOUNT TaxAmount,s.DISBURSEDATE salarymonth from BONUSPROCESSDETAIL s,Employee e where e.EMPLOYEEID=s.EMPLOYEEID and s.DISBURSEDATE between %d and %d and s.EMPLOYEEID in (%q)
// ) tab group by tab.EMPLOYEENO,tab.Name,tab.EMPLOYEEID) salarytax
// left join
// %q st on salarytax.Employeeid=st.employeeid and st.itemcode=-212 and st.itemid=-212",
//fromdate, toDate, empids, fromdate, toDate, empids, GetTableName(dataFrom));
string sql = SQLParser.MakeSQL(@"SET NOCOUNT ON;
IF OBJECT_ID('tempdb..#tdrEmpIds') IS NOT NULL DROP TABLE #tdrEmpIds;
CREATE TABLE #tdrEmpIds (ID int NOT NULL PRIMARY KEY);
INSERT INTO #tdrEmpIds (ID) SELECT DISTINCT CONVERT(int, value) FROM STRING_SPLIT(@empIds, ',') WHERE value <> '';
select salarytax.EMPLOYEENO,salarytax.Name,salarytax.EMPLOYEEID, salarytax.TaxAmount SalaryData, st.thisyeartotal TaxData from
(Select tab.EMPLOYEENO,tab.Name,tab.EMPLOYEEID,sum(tab.TaxAmount) TaxAmount from
(Select e.EMPLOYEENO,e.Name,e.EMPLOYEEID,sd.CHANGEDAMOUNT TaxAmount,s.salarymonth from SALARYMONTHLYDETAIL sd, SALARYMONTHLY s,Employee e where s.EMPLOYEEID=e.EMPLOYEEID and sd.SALARYMONTHLYID=s.SALARYMONTHLYID and s.SALARYMONTH
between %d and %d and ITEMCODE=-129 and ITEMID=-129 and s.EMPLOYEEID in(%q)
between %d and %d and ITEMCODE=-129 and ITEMID=-129 and s.EMPLOYEEID in (SELECT ID FROM #tdrEmpIds)
union
Select e.EMPLOYEENO,e.Name,e.EMPLOYEEID,s.CHANGETAXAMOUNT TaxAmount,s.DISBURSEDATE salarymonth from BONUSPROCESSDETAIL s,Employee e where e.EMPLOYEEID=s.EMPLOYEEID and s.DISBURSEDATE between %d and %d and s.EMPLOYEEID in (%q)
Select e.EMPLOYEENO,e.Name,e.EMPLOYEEID,s.CHANGETAXAMOUNT TaxAmount,s.DISBURSEDATE salarymonth from BONUSPROCESSDETAIL s,Employee e where e.EMPLOYEEID=s.EMPLOYEEID and s.DISBURSEDATE between %d and %d and s.EMPLOYEEID in (SELECT ID FROM #tdrEmpIds)
) tab group by tab.EMPLOYEENO,tab.Name,tab.EMPLOYEEID) salarytax
left join
%q st on salarytax.Employeeid=st.employeeid and st.itemcode=-212 and st.itemid=-212",
fromdate, toDate, empids, fromdate, toDate, empids, GetTableName(dataFrom));
oIncomeTaxs = tc.ExecuteDataSet(sql);
%q st on salarytax.Employeeid=st.employeeid and st.itemcode=-212 and st.itemid=-212;
DROP TABLE #tdrEmpIds;",
fromdate, toDate, fromdate, toDate, GetTableName(dataFrom));
// must be a Microsoft.Data.SqlClient.SqlParameter[]: Ease.Core casts the array to that type
Microsoft.Data.SqlClient.SqlParameter[] parameters =
{
Ease.Core.DataAccess.SQL.SqlHelperExtension.CreateInParam("@empIds", SqlDbType.VarChar, string.Join(",", ids), -1) // varchar(max)
};
oIncomeTaxs = tc.ExecuteDataSet(CommandType.Text, sql, parameters);
}
catch (Exception ex)
{

View File

@ -860,8 +860,7 @@ namespace HRM.DA
else
{
BonusProcessDA.Update(tc, oBonusProcess);
BonusProcessDA.DeleteProcessDetailByProcessID(tc, oBonusProcess.BonusID, oBonusProcess.ID,
oBonusProcess.PayrollTypeID);
BonusProcessDA.DeleteProcessDetailByProcessID(tc, oBonusProcess.BonusID, oBonusProcess.ID, oBonusProcess.PayrollTypeID);
BonusProcessDA.DeleteEmpCostCenter(tc, oBonusProcess.ID);
}
List<IncomeTax> incometaxes = new List<IncomeTax>();

View File

@ -192,7 +192,7 @@
{{(dataItem.changeBonusAmount - dataItem.changeTaxAmount) | number:'1.2-2'}}
</ng-template>
</kendo-grid-column>
<kendo-grid-command-column title="Remove" width="8%" style="height:98%;">
<kendo-grid-command-column title="Remove" width="8%">
<ng-template kendoGridCellTemplate let-dataItem let-rowIndex="rowIndex">
<button (click)="removefromList(rowIndex)" class="kt-delete" kendoButton [svgIcon]="apiService.KendoSVGIcon['delete']">
</button>

View File

@ -97,7 +97,6 @@ export class BonusProcessComponent implements OnInit {
() => {
this.loadingPanelService.ShowLoadingPanel = false;
});
this.authSerivce.GetPayrollTypeByLoginID().subscribe(
(x) => {
this.payrollType = x;
@ -111,7 +110,6 @@ export class BonusProcessComponent implements OnInit {
this.cuttofDate = new Date(this.payrollType.nextPayProcessDate);
});
}
public GetSelectedEmployee(searchEmp: SearchEmployee[]) {
this.processCompleted = false;
this.selectedEmps = searchEmp;
@ -127,7 +125,6 @@ export class BonusProcessComponent implements OnInit {
this.returnMessage = err.error;
},
() => {
debugger;
this.loadingPanelService.ShowLoadingPanel = false;
this.RefreshDefaultGrid();
}
@ -136,7 +133,6 @@ export class BonusProcessComponent implements OnInit {
this.RefreshDefaultGrid();
}
}
RefreshDefaultGrid() {
if (this.selectedEmps != undefined && this.bonusProcessDetails != undefined) {
if (this.bonusProcess == undefined) {
@ -203,35 +199,24 @@ export class BonusProcessComponent implements OnInit {
}
}
}
onPopUpClose() {
this.showModal = false;
this.showBonusUpload = false;
}
showBonusUploadPopUp() {
this.showBonusUpload = true;
}
currentlyProcess($event) {
}
remainingBasic($event) {
}
search() {
}
process() {
if (this.bonusProcess == undefined || this.bonusProcess.bonusProcessDetails.length == 0) {
this.notificationService.showWarning('Please select employee for the proces');
return;
}
var isApproved = false;
this.loadingPanelService.ShowLoadingPanel = true;
this.bonusService.IsBonusApproved(this.selectedbonusID, this.payrollType.nextPayProcessDate).subscribe(
@ -250,13 +235,10 @@ export class BonusProcessComponent implements OnInit {
this.returnMessage = 'selected Bonus is already process and Approved';
return;
}
var returnID: number;
this.processRequest = [];
var index: number = 0;
this.bonusProcess.bonusProcessDetails.forEach(x => {
this.processRequest.push({
'bonusid': this.selectedbonusID,
'basicMonth': this.basicDate,
@ -267,7 +249,6 @@ export class BonusProcessComponent implements OnInit {
'isTaxProcess': this.isTaxProcess,
'empid': x.employeeID
});
});
this.errorOrSucessList = [];
this.bonusService.BonusProcess(this.processRequest).subscribe(
@ -286,22 +267,17 @@ export class BonusProcessComponent implements OnInit {
this.notificationService.showSuccess('Bonus processed successfully');
this.returnMessage = 'Bonus processed successfully';
});
}
);
}
public BonusvalueChange(value: any): void {
this.alreadyProcessesList = [];
this.bonusProcess = new BonusProcess();
this.bonusProcess.bonusProcessDetails = [];
this.selectedEmps = [];
this.processCompleted = false;
this.pbuttonEnalble = false;
}
this.bonusProcess = new BonusProcess();
this.bonusProcess.bonusProcessDetails = [];
this.selectedEmps = [];
this.processCompleted = false;
this.pbuttonEnalble = false;
}
TaxRecalculate() {
this.loadingPanelService.ShowLoadingPanel = true;
@ -324,13 +300,9 @@ export class BonusProcessComponent implements OnInit {
this.pbuttonEnalble = false;
this.notificationService.showSuccess('Tax Recalculated processed successfully');
this.returnMessage = 'Tax Recalculated processed successfully';
});
}
uploadBonusFile(event: any): void {
debugger;
let tempResponse: any;
this.selectedFiles = event.target.files;
if (this.selectedFiles.length > 0) {
@ -376,41 +348,28 @@ export class BonusProcessComponent implements OnInit {
this.notificationService.showWarning('please select a file');
}
}
refresh() {
}
edit() {
}
clearAll() {
}
remove() {
}
save() {
if (this.processCompleted == false) {
this.notificationService.showWarning('Please process the Bonus first');
return;
}
if (this.bonusProcess == undefined || this.bonusProcess?.bonusProcessDetails.length == 0) {
this.notificationService.showWarning('There are no data to save');
return;
}
if (this.isTaxProcess == true && (this.bonusProcess.bonusProcessDetails[0].incomeTaxcoll == undefined
|| this.bonusProcess.bonusProcessDetails[0].incomeTaxcoll.length == 0)) {
this.notificationService.showWarning('Tax Calculation not yet done');
return;
}
if (this.isTaxProcess == true) {
var mitem: TaxMergeMaster = undefined;
this.taxService.getTaxMergeMaster(EnumTaxMergeType.Bonus, this.selectedbonusID).subscribe(
@ -424,18 +383,14 @@ export class BonusProcessComponent implements OnInit {
() => {
if (mitem != undefined) {
console.log(mitem);
this.bonusProcess.bonusProcessDetails.every(x => {
//console.log(x.incomeTaxcoll);
var item = x.incomeTaxcoll.find(y => y.itemGroup == mitem.itemGroup && y.itemID == mitem.itemID);
if (item != undefined) {
item.thisMonthAmount = x.changeBonusAmount;
} else {
this.notificationService.showWarning('Income tax amount not found in the collection');
return;
}
item = x.incomeTaxcoll.find(y => y.itemGroup == EnumIncomeTaxItemGroup.Tax_Deducted);
if (item != undefined) {
item.thisMonthAmount = x.changeTaxAmount;
@ -448,17 +403,117 @@ export class BonusProcessComponent implements OnInit {
}
}
);
} else {
this.saveData();
}
}
private logSavePayloadSize() {
try {
const enc = new TextEncoder();
const bytes = (v: any): number => { const s = JSON.stringify(v); return s === undefined ? 0 : enc.encode(s).length; };
const MB = (b: number) => (b / 1024 / 1024).toFixed(2) + ' MB';
const KB = (b: number) => (b / 1024).toFixed(2) + ' KB';
const LIMIT = 30000000; // IIS / ASP.NET Core default request body limit (bytes)
// size of every field over a list of objects (bytes of "key":value, per field), biggest first
const fieldTable = (objs: any[], total: number, top = 999) => {
const sum: { [k: string]: { b: number, nulls: number, objs: number } } = {};
objs.forEach(o => {
if (o == null || typeof o !== 'object') return;
Object.keys(o).forEach(k => {
const v = o[k];
const e = sum[k] || (sum[k] = { b: 0, nulls: 0, objs: 0 });
if (v === undefined) return;
e.b += enc.encode(JSON.stringify(k)).length + 2 + bytes(v);
if (v === null) e.nulls++;
else if (typeof v === 'object') e.objs++;
});
});
return Object.keys(sum)
.map(k => ({ field: k, size: MB(sum[k].b), percent: (total ? (sum[k].b * 100 / total) : 0).toFixed(1) + '%', nullRows: sum[k].nulls, objectRows: sum[k].objs, _b: sum[k].b }))
.sort((a, b) => b._b - a._b)
.slice(0, top)
.map(({ _b, ...r }) => r);
};
const stats = (counts: number[]) => {
if (counts.length == 0) return { total: 0, min: 0, max: 0, avg: '0' };
let total = 0, min = counts[0], max = counts[0];
counts.forEach(c => { total += c; if (c < min) min = c; if (c > max) max = c; });
return { total, min, max, avg: (total / counts.length).toFixed(1) };
};
const d: any[] = this.bonusProcess?.bonusProcessDetails ?? [];
// 1. Overview
const t0 = performance.now();
const totalBytes = bytes(this.bonusProcess);
const stringifyMs = Math.round(performance.now() - t0);
const header = { ...this.bonusProcess, bonusProcessDetails: undefined };
console.log('%c[SAVE SIZE] 1. Overview', 'font-weight:bold');
console.table({
rows: d.length,
totalRequest: MB(totalBytes),
serverLimit: MB(LIMIT),
overLimitBy: totalBytes > LIMIT ? MB(totalBytes - LIMIT) + ' (' + (totalBytes / LIMIT).toFixed(1) + 'x the limit)' : 'within the limit',
header_withoutDetails: KB(bytes(header)),
averagePerRow: d.length ? KB(totalBytes / d.length) : '0',
jsonStringifyTime: stringifyMs + ' ms',
});
// 2. Every field of a BonusProcessDetail (employee / bonus / incomeTaxcoll are fields too)
console.log('%c[SAVE SIZE] 2. Fields of each detail row (all rows together)', 'font-weight:bold');
console.table(fieldTable(d, totalBytes));
// 3. employee
const emps = d.map(x => x.employee).filter(x => x != null);
const empBytes = bytes(emps);
console.log('%c[SAVE SIZE] 3. employee — ' + MB(empBytes) + ', ' + emps.length + ' objects, ' + new Set(emps).size + ' distinct; top 25 fields', 'font-weight:bold');
console.table(fieldTable(emps, empBytes, 25));
// 4. bonus
const bonuses = d.map(x => x.bonus).filter(x => x != null);
const bonusBytes = bytes(bonuses);
console.log('%c[SAVE SIZE] 4. bonus — ' + MB(bonusBytes) + ', ' + bonuses.length + ' objects, ' + new Set(bonuses).size
+ ' distinct (' + new Set(bonuses.map(b => b?.id)).size + ' distinct ids); one copy = ' + KB(bytes(bonuses[0])), 'font-weight:bold');
if (bonuses.length) console.table(fieldTable(bonuses, bonusBytes, 25));
// 5. incomeTaxcoll
const taxCounts = d.map(x => (x.incomeTaxcoll ?? []).length);
const taxItems = ([] as any[]).concat(...d.map(x => x.incomeTaxcoll ?? []));
const taxBytes = bytes(taxItems);
console.log('%c[SAVE SIZE] 5. incomeTaxcoll — ' + MB(taxBytes) + '; items per row:', 'font-weight:bold', stats(taxCounts),
'; rows with no items:', taxCounts.filter(c => c == 0).length, '; one item ≈', taxItems.length ? (taxBytes / taxItems.length).toFixed(0) + ' bytes' : '-');
if (taxItems.length) console.table(fieldTable(taxItems, taxBytes));
// 6. bonusEmpCostCenters
const ccCounts = d.map(x => (x.bonusEmpCostCenters ?? []).length);
const ccItems = ([] as any[]).concat(...d.map(x => x.bonusEmpCostCenters ?? []));
console.log('%c[SAVE SIZE] 6. bonusEmpCostCenters — ' + MB(bytes(ccItems)) + '; items per row:', 'font-weight:bold', stats(ccCounts));
// 7. What the server actually saves: BonusProcessDA.Insert (detail) + IncomeTaxService.SaveBulk (tax)
const pick = (o: any, keys: string[]) => { const r: any = {}; keys.forEach(k => { if (o?.[k] !== undefined) r[k] = o[k]; }); return r; };
const detailKeys = ['employeeID', 'bonusID', 'bonusMonth', 'bonusAmount', 'grossSalary', 'basicSalary', 'changeBonusAmount', 'changeTaxAmount',
'changeAdjustAmount', 'changeSalaryItemAmount', 'calculatedAdjustAmount', 'calculatedSalaryItemAmount', 'taxAmount'];
const taxKeys = ['employeeID', 'itemGroup', 'itemID', 'description', 'totalAmount', 'previousAmount', 'thisMonthAmount', 'projectedAmount',
'side', 'position', 'isChanged', 'taxParameterID'];
const minimal = {
...header,
bonusProcessDetails: d.map(x => ({ ...pick(x, detailKeys), incomeTaxcoll: (x.incomeTaxcoll ?? []).map((t: any) => pick(t, taxKeys)) })),
};
const minimalBytes = bytes(minimal);
console.log('%c[SAVE SIZE] 7. Only the fields the server saves', 'font-weight:bold');
console.table({
minimalRequest: MB(minimalBytes),
ofWhichTax: MB(bytes(minimal.bonusProcessDetails.map(x => x.incomeTaxcoll))),
smallerBy: minimalBytes ? (totalBytes / minimalBytes).toFixed(1) + 'x' : '-',
fitsInLimit: minimalBytes <= LIMIT ? 'yes' : 'NO',
});
} catch (e) {
console.log('[SAVE SIZE] could not measure:', e);
}
}
saveData() {
debugger;
this.loadingPanelService.ShowLoadingPanel = true;
this.bonusProcess.disburseDate = this.payDate;
this.bonusProcess.isTaxProcess = this.isTaxProcess;