I have a custom control that is on the transaction page. It needs to show the name of the person that is logged in.
I saw in FiscalizationManager.ts which triggers to use. The StaffID I pass in has a value and I can confirm that it is the ID I logged in with, but it returns a null for the Employee record.
Here is my typescript file:
***
import {
CartViewCustomControlBase,
ICartViewCustomControlState,
ICartViewCustomControlContext,
CartChangedData
} from "PosApi/Extend/Views/CartView";
import {
GetLoggedOnEmployeeClientRequest, GetLoggedOnEmployeeClientResponse
} from "PosApi/Consume/Employees";
import { IExtensionContext } from "PosApi/Framework/ExtensionContext";
import { IRuntime } from "PosApi/Framework/Runtime";
import { ObjectExtensions } from "PosApi/TypeExtensions";
import { StringExtensions } from "PosApi/TypeExtensions";
import { ProxyEntities, ClientEntities } from "PosApi/Entities";
export default class CartCustDetailsControl extends CartViewCustomControlBase {
private extensionContext: IExtensionContext;
/* ExtCartCustDetailControl is the script ID in CartCustDetailsControl.html */
private static readonly TEMPLATE_ID: string = "ExtCartCustDetailControl";
public readonly isCustomerSelected: Computed<boolean>;
public readonly cGrpHolder: Computed<string>;
public readonly pGrpHolder: Computed<string>;
public readonly salesTakerHolder: Computed<string>;
private readonly _customer: Observable<ProxyEntities.Customer>;
private readonly _employee: Observable<ProxyEntities.Employee>;
public readonly title: Observable<string>;
constructor(id: string, context: ICartViewCustomControlContext) {
super(id, context);
this.extensionContext = context;
this._customer = ko.observable(null);
this._employee = ko.observable(null);
this.isCustomerSelected = ko.computed(() => !ObjectExtensions.isNullOrUndefined(this._customer()));
//this.isVisible = true;
this.title = ko.observable("Details");
this.cGrpHolder = ko.computed(() => {
if (this.isCustomerSelected()) {
return this._customer().CustomerGroup;
}
return StringExtensions.EMPTY;
});
this.pGrpHolder = ko.computed(() => {
if (this.isCustomerSelected()) {
return this._customer().PriceGroup;
}
return StringExtensions.EMPTY;
});
this.salesTakerHolder = ko.computed(() =>{
return ObjectExtensions.isNullOrUndefined(this._employee()) ? StringExtensions.EMPTY : this._employee().Name;
});
this.cartChangedHandler = (data: CartChangedData) => {
this._customer(data.customer);
};
}
public init(state: ICartViewCustomControlState): void {
this._customer(state.customer);
this._employee(this.GetEmployee(state.cart.StaffId)[0]);
}
public onReady(element: HTMLElement): void {
ko.applyBindingsToNode(element, {
template: {
name: CartCustDetailsControl.TEMPLATE_ID,
data: this
}
});
}
// Retrieve the employee record for the passed in staffId
private GetEmployee(_StaffId: string): Promise <ProxyEntities.Employee[]>{
let runtime: IRuntime = this.extensionContext.runtime;
return runtime.executeAsync(new GetLoggedOnEmployeeClientRequest(_StaffId))
.then((response: ClientEntities.ICancelableDataResult<GetLoggedOnEmployeeClientResponse>): ProxyEntities.Employee => {
return response.data.result;
})
.catch(() => {
return null;
});
}
}
***
Can anybody help me figure out why GetEmployee is returning a null employee record instead of the actual record?
Any help is much appreciated