class MMS121B1_ManualAllocate1 {
private controller: IInstanceController;
private log: IScriptLog;
private args: string;
private stockZone = "";
gStockZoneColumnName = "SLTP";
gAllocateNetColumnName = "ALQT";
gAllocateQuantityColumnName = "MMS12105";
gControlsAdded = false;
constructor(scriptArgs: IScriptArgs) {
this.controller = scriptArgs.controller;
this.log = scriptArgs.log;
this.args = scriptArgs.args;
}
/**
* Script initialization function.
*/
public static Init(args: IScriptArgs): void {
new MMS121B1_ManualAllocate1(args).run();
}
private run(): void {
this.addButton();
}
private addButton(): void {
const buttonElement = new ButtonElement();
buttonElement.Name = "Man Allocate";
buttonElement.Value = "Man Allocate";
buttonElement.Position = new PositionElement();
buttonElement.Position.Top = 2;
buttonElement.Position.Left = 10;
buttonElement.Position.Width = 5;
const contentElement = this.controller.GetContentElement();
const button = contentElement.AddElement(buttonElement);
button.click(() => {
this.getDetails();
});
}
private getDetails(): void {
let mySortingOrder = this.controller.GetSortingOrder();
var grid = this.controller.GetGrid();
var data = grid.getData().getItems();
let selected = ListControl.ListView.SelectedItem();
let stockZoneColumnIndex = ListControl.GetColumnIndexByName(this.gStockZoneColumnName);
let allocateNetColumnIndex = ListControl.GetColumnIndexByName(this.gAllocateNetColumnName);
let allocateQuantityColumnIndex = ListControl.GetColumnIndexByName(this.gAllocateQuantityColumnName);
for (var i = 0; i < selected.length; i++) {
console.log("In for1 loop" + i)
var selectedIndex = selected[i]; // will get the index of the selected row here
console.log("In selected loop" + selectedIndex)
this.stockZone= data[selectedIndex].C1;
console.log("stock", this.stockZone)
if (null != selected && selected.length > 0) {
if (-1 != ListControl.GetColumnIndexByName(this.gStockZoneColumnName)) {
this.stockZone = (ListControl.ListView.GetValueByColumnName(this.gStockZoneColumnName))[0];
}
let allocationNet = Number((ListControl.ListView.GetValueByColumnName(this.gAllocateNetColumnName))[i]);
let controller: any = this.controller;
let grid : any = this.controller.GetGrid();
//let items = grid.getData().getItems();
//for (let i = 0; i < grid.getData().getItems().length; i++) {
console.log("in for2 loop" + i);
console.log(" +------- Grid item count: " + grid.getData().getItems().length);
let currentItem = grid.getData().getItem(i);
console.log("currentitem" , currentItem);
//if (null != currentItem && undefined != currentItem) {
// allocationNet = Number(currentItem[`C${(allocateNetColumnIndex + 1)}`]);
console.log("alloc net" , allocationNet);
let currentStockZone = null;
if (stockZoneColumnIndex != -1) {
currentStockZone = currentItem[`C${(stockZoneColumnIndex + 1)}`];
}
if (Number.NaN != allocationNet && allocationNet > 0) {
console.log("inupdate");
// we need to set the allocate quantity
//$("body").css("cursor", "default");
//break;
$("body").css("cursor", "progress");
setTimeout(() => {
console.log("intimeout");
controller.UpdateCell(`R${(i+1)}C${(allocateQuantityColumnIndex + 1)}`, allocationNet);
console.log("updatecell" , controller.UpdateCell(`R${(i+1)}C${(allocateQuantityColumnIndex + 1)}`, allocationNet));
}, 3000);
}
// }
//}
}
else {
this.controller.ShowMessage("No rows selected");
}
}
}
}