Stok Sayım
Stok Sayım Script
const awaitIf = async (fn, ms = 100) => {
await new Promise(async (resolve, reject) => {
let result = false;
try {
result = fn();
} catch (e) {
console.error(e);
}
if (result) {
resolve(true);
} else {
await rxjs.timer(ms).toPromise();
resolve(await awaitIf(fn));
}
});
};
(async () => {
console.log('StockLow başlangıç1', this);
this.recordService.formGroup.controls.CUSTOMSTOREID.disable();
await awaitIf(
() =>
this.recordService.grids['stock-count-detail']?.grid?.agGrid?.api &&
this.recordService.grids['stock-count-detail'].grid?.agGridReady
);
this.recordService.formGroup.controls.CUSTOMSTOREID.enable();
this.recordService.formGroup.controls.CUSTOMSTOREID.valueChanges.subscribe(
(store) => {
let filterModels = this.recordService.grids[
'stock-count-detail'
].grid.agGrid.api.getFilterModel();
if (store > 0) {
filterModels.STOREID = {
filter: +store,
filterTo: null,
filterType: 'number',
type: 'equals',
};
this.recordService.grids[
'stock-count-detail'
].grid.agGrid.api.setFilterModel(filterModels);
} else {
delete filterModels.STOREID;
this.recordService.grids[
'stock-count-detail'
].grid.agGrid.api.setFilterModel(filterModels);
}
}
);
console.log('StockLow üzerinde', this);
if (angus.permissionService.isAuthorized(['StockLow'])) {
console.log('StockLow içinde', this);
debugger;
this.recordService.children.P2.component.tabGroupService.children[1].componentRef.instance.hide = true; //alt gruptaki indirimler tabının gizlenmesi
this.recordService.children.P2.component.updateTabs();
let defs = this.recordService.grids[
'stock-count-detail'
]?.grid.agGrid.columnApi
.getAllColumns()
.map((col) => col.getColDef(
));
defs = defs.filter((x) => x.field != 'BALANCE_AMOUNT');
defs = defs.filter((x) => x.field != 'AVG_UNITPRICE');
defs = defs.filter((x) => x.field != 'DIFFERENCE_AMOUNT2');
this.recordService.grids[
'stock-count-detail'
]?.grid.agGrid.api.setColumnDefs([]);
setTimeout(() => {
this.recordService.grids[
'stock-count-detail'
]?.grid.agGrid.api.setColumnDefs(defs);
}, 10);
}
})();
const recordClass = '.ang-record-' + this.recordService.component.recordID;
this.recordService.formGroup.controls.ID.valueChanges
.pipe(rxjs.startWith(this.recordService.formGroup.controls.ID.value))
.subscribe((v) => {
if (v) {
this.recordService.formGroup.controls.BRANCHID_NAME.disable();
} else {
this.recordService.formGroup.controls.BRANCHID_NAME.enable();
}
});
this.recordService.formGroup.controls.STATEID.valueChanges
.pipe(rxjs.startWith(this.recordService.formGroup.controls.STATEID.value))
.subscribe((v) => {
if (v == 255) {
document.querySelector(recordClass + ' #calculate').disabled = true;
document.querySelector(recordClass + ' #stockCount').disabled = true;
this.allGrids[
'stock-count-details-excel'
].grid.config.buttons.addButton = false;
this.allGrids[
'stock-count-details-excel'
].grid.config.buttons.deleteButton = false;
console.log('asd', document.querySelector(recordClass + ' #stockCount'));
} else {
document.querySelector(recordClass + ' #calculate').disabled = false;
document.querySelector(recordClass + ' #stockCount').disabled = false;
this.allGrids[
'stock-count-details-excel'
].grid.config.buttons.addButton = true;
this.allGrids[
'stock-count-details-excel'
].grid.config.buttons.deleteButton = true;
console.log(
'elseasd',
document.querySelector(recordClass + ' #stockCount')
);
}
});
setTimeout(() => {
this.recordService.formGroup.controls.STATEID.valueChanges
.pipe(rxjs.startWith(this.recordService.formGroup.controls.STATEID.value))
.subscribe((x) => {
Object.values(this.recordService.component.allGrids).forEach(
(gridContainer) => {
const grid = gridContainer.grid;
if (x == 255) {
grid.buttonsForTemplate.addButton = false;
grid.buttonsForTemplate.deleteButton = false;
grid.buttonsForTemplate.editButton = false;
grid.buttonsForTemplate.saveButton = false;
grid.agGrid.defaultColDef.editable = false;
const defs = grid.agGrid.columnApi
.getAllColumns()
.map((col) => col.getColDef());
for (const def of defs) {
def.editable = false;
}
grid.agGrid.api.setColumnDefs([]);
setTimeout(() => {
grid.agGrid.api.setColumnDefs(defs);
}, 10);
} else {
const o = grid.permissions.processObj(grid.config.buttons);
grid.buttonsForTemplate.addButton = o.addButton;
grid.buttonsForTemplate.deleteButton = o.deleteButton;
grid.buttonsForTemplate.editButton = o.editButton;
grid.buttonsForTemplate.saveButton = o.saveButton;
grid.agGrid.defaultColDef.editable = true;
const defs = grid.agGrid.columnApi
.getAllColumns()
.map((col) => col.getColDef());
for (const def of defs) {
def.editable = true;
}
grid.agGrid.api.setColumnDefs([]);
setTimeout(() => {
grid.agGrid.api.setColumnDefs(defs);
}, 10);
}
}
);
});
}, 2000);
Last updated