Yaşlandırma Analizi
Yaşlandırma Analizi Script
const awaitIf = async (fn, ms = 100) => {
await new Promise(async (resolve, reject) => {
if (fn()) {
resolve(true);
} else {
await rxjs.timer(ms).toPromise();
resolve(await awaitIf(fn));
}
});
};
const record = this;
const arraySum = (array, fields) => {
const result = [];
fields.forEach(() => {
result.push(0);
});
array.forEach((row, rowIndex) => {
fields.forEach((field, fieldIndex) => {
result[fieldIndex] += +row[field] || 0;
});
});
return result;
};
const round2 = (x) => numeral(x).format('0,0.00');
const round2Percent = (x) => numeral(x).format('0,0.00%');
const round3Percent = (x) => numeral(x).format('0.00');
this.recordService._data$ = new rxjs.Subject();
rxjs
.combineLatest([
this.recordService._data$,
this.recordService.formGroup.controls.PERIODTYPEID.valueChanges.pipe(
rxjs.startWith(this.recordService.formGroup.controls.PERIODTYPEID.value)
),
])
.subscribe(async ([result, periodType]) => {
console.log('result:', result);
try {
const data = result[0];
console.log('dataaa:', data);
const today = record.allFormControls['ASOFDATE'].value;
const getDay = (number) =>
moment(today).add(number, 'days').format('DD MMM');
const beforeMsg = angus.languageService.dynamicTranslator.translate(
'{{}} and Before'
);
const afterMsg = angus.languageService.dynamicTranslator.translate(
'{{}} and After'
);
let twoWeeklyColumns = [
{
column: 'PAST-∞←91',
title: beforeMsg.replace('{{1}}', getDay(-91)),
},
{
column: 'PAST-90←61',
title: getDay(-90) + '←' + getDay(-61),
},
{
column: 'PAST-60←46',
title: getDay(-60) + '←' + getDay(-46),
},
{
column: 'PAST-45←31',
title: getDay(-45) + '←' + getDay(-31),
},
{
column: 'PAST-30←16',
title: getDay(-30) + '←' + getDay(-16),
},
{
column: 'PAST-15←0',
title: getDay(-15) + '←' + getDay(0),
},
{
column: 'FUTURE+1→15',
title: getDay(1) + '→' + getDay(15),
},
{
column: 'FUTURE+16→30',
title: getDay(16) + '→' + getDay(30),
},
{
column: 'FUTURE+31→45',
title: getDay(31) + '→' + getDay(45),
},
{
column: 'FUTURE+46→60',
title: getDay(46) + '→' + getDay(60),
},
{
column: 'FUTURE+61→90',
title: getDay(61) + '→' + getDay(90),
},
{
column: 'FUTURE+91→∞',
title: afterMsg.replace('{{1}}', getDay(91)),
},
];
let weeklyColumns = [
{
column: 'PAST-∞←91',
title: beforeMsg.replace('{{1}}', getDay(-91)),
},
{
column: 'PAST-90←61',
title: getDay(-90) + '←' + getDay(-61),
},
{
column: 'PAST-60←29',
title: getDay(-60) + '←' + getDay(-29),
},
{
column: 'PAST-28←22',
title: getDay(-28) + '←' + getDay(-22),
},
{
column: 'PAST-21←15',
title: getDay(-21) + '←' + getDay(-15),
},
{
column: 'PAST-14←8',
title: getDay(-14) + '←' + getDay(8),
},
{
column: 'PAST-7←0',
title: getDay(-7) + '←' + getDay(0),
},
{
column: 'FUTURE+1→7',
title: getDay(1) + '→' + getDay(7),
},
{
column: 'FUTURE+8→14',
title: getDay(8) + '→' + getDay(14),
},
{
column: 'FUTURE+15→21',
title: getDay(15) + '→' + getDay(21),
},
{
column: 'FUTURE+22→28',
title: getDay(22) + '→' + getDay(28),
},
{
column: 'FUTURE+29→60',
title: getDay(29) + '→' + getDay(60),
},
{
column: 'FUTURE+61→90',
title: getDay(61) + '→' + getDay(90),
},
{
column: 'FUTURE+91→∞',
title: afterMsg.replace('{{1}}', getDay(91)),
},
];
let monthlyColumns = [
{
column: 'PAST-∞←91',
title: beforeMsg.replace('{{1}}', getDay(-91)),
},
{
column: 'PAST-90←61',
title: getDay(-90) + '←' + getDay(-61),
},
{
column: 'PAST-60←31',
title: getDay(-60) + '←' + getDay(-31),
},
{
column: 'PAST-30←0',
title: getDay(-30) + '←' + getDay(0),
},
{
column: 'FUTURE+1→30',
title: getDay(1) + '→' + getDay(30),
},
{
column: 'FUTURE+31→60',
title: getDay(31) + '→' + getDay(60),
},
{
column: 'FUTURE+61→90',
title: getDay(61) + '→' + getDay(90),
},
{
column: 'FUTURE+91→∞',
title: afterMsg.replace('{{1}}', getDay(91)),
},
];
let chartData;
let groupData;
if (periodType == 1) {
groupData = data.reduce(
(acc, val) => {
weeklyColumns
.map((x) => x.column)
.forEach((column) => {
const value = val[column] || 0;
acc[91][column] =
(acc[91][column] || 0) + (value < 0 ? Math.abs(value) : 0);
acc[92][column] =
(acc[92][column] || 0) + (value >= 0 ? value : 0);
});
return acc;
},
{ 91: {}, 92: {} }
);
chartData = weeklyColumns.map((column) => {
return {
ALICI: groupData[91][column.column],
SATICI: groupData[92][column.column],
COLUMN: column.title,
};
});
} else if (periodType == 2) {
groupData = data.reduce(
(acc, val) => {
twoWeeklyColumns
.map((x) => x.column)
.forEach((column) => {
const value = val[column] || 0;
acc[91][column] =
(acc[91][column] || 0) + (value < 0 ? Math.abs(value) : 0);
acc[92][column] =
(acc[92][column] || 0) + (value >= 0 ? value : 0);
});
return acc;
},
{ 91: {}, 92: {} }
);
chartData = twoWeeklyColumns.map((column) => {
return {
ALICI: groupData[91][column.column],
SATICI: groupData[92][column.column],
COLUMN: column.title,
};
});
} else if (periodType == 3) {
groupData = data.reduce(
(acc, val) => {
monthlyColumns
.map((x) => x.column)
.forEach((column) => {
const value = val[column] || 0;
acc[91][column] =
(acc[91][column] || 0) + (value < 0 ? Math.abs(value) : 0);
acc[92][column] =
(acc[92][column] || 0) + (value >= 0 ? value : 0);
});
return acc;
},
{ 91: {}, 92: {} }
);
chartData = monthlyColumns.map((column) => {
return {
ALICI: groupData[91][column.column],
SATICI: groupData[92][column.column],
COLUMN: column.title,
};
});
}
Object.values(record.recordService.charts).forEach((chart) =>
chart.onDraw(chartData)
);
for (let recordGrid of Object.values(record.recordService.grids)) {
await awaitIf(() => recordGrid?.grid?.config);
const gridComponent = recordGrid.grid;
if (this.recordService.formGroup.controls.CURRENCYMODE.value) {
gridComponent.isSubTotalOpen = false;
} else {
gridComponent.isSubTotalOpen = true;
}
gridComponent.config.clientSide = true;
gridComponent.config.floatingFilter = false;
gridComponent.config.inlineEdit = false;
gridComponent.config.buttons.menuButtons.refreshButton = false;
gridComponent.config.buttons.menuButtons.groupButton = false;
gridComponent.config.buttons.addButton = false;
gridComponent.config.buttons.deleteButton = false;
gridComponent.config.buttons.menuButtons.logButton = false;
gridComponent.config.buttons.editButton = false;
gridComponent.config.buttons.saveButton = false;
gridComponent.config.tabs = [];
gridComponent.config.filterPanel = undefined;
gridComponent.config.autoLoad = false;
gridComponent.showLoadDataBtn = false;
setTimeout(() => {
gridComponent.agGrid.api.setRowData(data);
if (this.recordService.formGroup.controls.CURRENCYMODE.value) {
} else {
gridComponent.agGrid.api.expandAll();
}
}, 1000);
gridComponent.isGridDataLoaded = true;
gridComponent.gridShareds.onRowLoad.next(true);
gridComponent.showLoadDataBtn = false;
}
const [
totalDebit,
totalCredit,
totalBalance,
past91,
past9061,
past6046,
past4531,
past3016,
past150,
pastDebit,
future115,
future1630,
future3145,
future4660,
future6190,
future91,
futureDebit,
past6029,
past2822,
past2115,
past148,
past70,
future17,
future814,
future1521,
future2228,
future2960,
past6031,
past300,
future130,
future3160,
] = arraySum(data, [
'TOTALDEBIT',
'TOTALCREDIT',
'TOTALBALANCE',
'PAST-∞←91',
'PAST-90←61',
'PAST-60←46',
'PAST-45←31',
'PAST-30←16',
'PAST-15←0',
'PASTDEBIT',
'FUTURE+1→15',
'FUTURE+16→30',
'FUTURE+31→45',
'FUTURE+46→60',
'FUTURE+61→90',
'FUTURE+91→∞',
'FUTUREDEBIT',
'PAST-60←29',
'PAST-28←22',
'PAST-21←15',
'PAST-14←8',
'PAST-7←0',
'FUTURE+1→7',
'FUTURE+8→14',
'FUTURE+15→21',
'FUTURE+22→28',
'FUTURE+29→60',
'PAST-60←31',
'PAST-30←0',
'FUTURE+1→30',
'FUTURE+31→60',
]);
this.recordService.formGroup.controls.TOTALDEBIT.setValue(totalDebit);
this.recordService.formGroup.controls.FUTUREDEBIT.setValue(futureDebit);
this.recordService.formGroup.controls.TOTALCREDIT.setValue(totalCredit);
this.recordService.formGroup.controls.TOTALBALANCE.setValue(totalBalance);
if (totalBalance < 0) {
let creditBalanceText = angus.languageService.dynamicTranslator.translate(
'Credit Balance'
);
record
.querySelector('.ang-field-TOTALBALANCE')
.querySelector('mat-label').innerText = creditBalanceText;
} else if (totalBalance > 0) {
let debitBalanceText = angus.languageService.dynamicTranslator.translate(
'Debit Balance'
);
record
.querySelector('.ang-field-TOTALBALANCE')
.querySelector('mat-label').innerText = debitBalanceText;
}
this.recordService.formGroup.controls.PAST6029.setValue(past6029);
this.recordService.formGroup.controls.PAST2822.setValue(past2822);
this.recordService.formGroup.controls.PAST2115.setValue(past2115);
this.recordService.formGroup.controls.PAST148.setValue(past148);
this.recordService.formGroup.controls.PAST70.setValue(past70);
this.recordService.formGroup.controls.FUTURE17.setValue(future17);
this.recordService.formGroup.controls.FUTURE814.setValue(future814);
this.recordService.formGroup.controls.FUTURE1521.setValue(future1521);
this.recordService.formGroup.controls.FUTURE2228.setValue(future2228);
this.recordService.formGroup.controls.FUTURE2960.setValue(future2960);
this.recordService.formGroup.controls.PAST91.setValue(past91);
this.recordService.formGroup.controls.WEEKLYPAST91.setValue(past91);
this.recordService.formGroup.controls.MONTHLYPAST91.setValue(past91);
this.recordService.formGroup.controls.PAST9061.setValue(past9061);
this.recordService.formGroup.controls.WEEKLYPAST9061.setValue(past9061);
this.recordService.formGroup.controls.MONTHLYPAST9061.setValue(past9061);
this.recordService.formGroup.controls.PAST6046.setValue(past6046);
this.recordService.formGroup.controls.PAST4531.setValue(past4531);
this.recordService.formGroup.controls.PAST3016.setValue(past3016);
this.recordService.formGroup.controls.PAST150.setValue(past150);
this.recordService.formGroup.controls.PASTDEBIT.setValue(pastDebit);
this.recordService.formGroup.controls.FUTURE115.setValue(future115);
this.recordService.formGroup.controls.FUTURE1630.setValue(future1630);
this.recordService.formGroup.controls.FUTURE3145.setValue(future3145);
this.recordService.formGroup.controls.FUTURE4660.setValue(future4660);
this.recordService.formGroup.controls.FUTURE6190.setValue(future6190);
this.recordService.formGroup.controls.WEEKLYFUTURE6190.setValue(
future6190
);
this.recordService.formGroup.controls.MONTHLYFUTURE6190.setValue(
future6190
);
this.recordService.formGroup.controls.FUTURE91.setValue(future91);
this.recordService.formGroup.controls.WEEKLYFUTURE91.setValue(future91);
this.recordService.formGroup.controls.MONTHLYFUTURE91.setValue(future91);
this.recordService.formGroup.controls.PAST6031.setValue(past6031);
this.recordService.formGroup.controls.PAST300.setValue(past300);
this.recordService.formGroup.controls.FUTURE130.setValue(future130);
this.recordService.formGroup.controls.FUTURE3160.setValue(future3160);
(async () => {
const weeklyColumns = [
'PAST-60←29',
'PAST-28←22',
'PAST-21←15',
'PAST-14←8',
'PAST-7←0',
'FUTURE+1→7',
'FUTURE+8→14',
'FUTURE+15→21',
'FUTURE+22→28',
'FUTURE+29→60',
];
let twoWeeklyColumns = [
'PAST-60←46',
'PAST-45←31',
'PAST-30←16',
'PAST-15←0',
'FUTURE+1→15',
'FUTURE+16→30',
'FUTURE+31→45',
'FUTURE+46→60',
];
let monthlyColumns = [
'PAST-60←31',
'PAST-30←0',
'FUTURE+1→30',
'FUTURE+31→60',
];
await awaitIf(
() => this.recordService.grids['account-aging-chart']?.grid?.agGrid
);
const agGrid = this.recordService.grids['account-aging-chart'].grid
.agGrid;
setTimeout(() => {
if (periodType == 1) {
agGrid.columnApi.setColumnsVisible(weeklyColumns, true);
agGrid.columnApi.setColumnsVisible(twoWeeklyColumns, false);
agGrid.columnApi.setColumnsVisible(monthlyColumns, false);
} else if (periodType == 2) {
agGrid.columnApi.setColumnsVisible(weeklyColumns, false);
agGrid.columnApi.setColumnsVisible(twoWeeklyColumns, true);
agGrid.columnApi.setColumnsVisible(monthlyColumns, false);
} else {
agGrid.columnApi.setColumnsVisible(weeklyColumns, false);
agGrid.columnApi.setColumnsVisible(twoWeeklyColumns, false);
agGrid.columnApi.setColumnsVisible(monthlyColumns, true);
}
if (periodType === 1) {
record.querySelector('div.group.ang-group-W2').style.display =
'none';
record.querySelector('div.group.ang-group-W22').style.display =
'none';
record.querySelector('div.group.ang-group-W1').style.display =
'grid';
record.querySelector('div.group.ang-group-W11').style.display =
'grid';
record.querySelector('div.group.ang-group-M1').style.display =
'none';
}
else if (periodType === 2) {
record.querySelector('div.group.ang-group-W2').style.display =
'grid';
record.querySelector('div.group.ang-group-W22').style.display =
'grid';
record.querySelector('div.group.ang-group-W1').style.display =
'none';
record.querySelector('div.group.ang-group-W11').style.display =
'none';
record.querySelector('div.group.ang-group-M1').style.display =
'none';
}
else if (periodType === 3) {
record.querySelector('div.group.ang-group-W1').style.display =
'none';
record.querySelector('div.group.ang-group-W11').style.display =
'none';
record.querySelector('div.group.ang-group-W2').style.display =
'none';
record.querySelector('div.group.ang-group-W22').style.display =
'none';
record.querySelector('div.group.ang-group-M1').style.display =
'grid';
}
}, 200);
})();
} catch (e) {
console.error(e);
}
});
Last updated