Hi Ahmed,
Yes, I am able to get the details in the GetReceiptServiceResponse.
Error: OLE has sent a request and is waiting for a reply.
Exactly, I have written code in the PostEndTransactions to print additional receipts.
By debugging I am able to get response from the CRT to PosExtension. After that it is not printing the receipt.
As I am developing this in my dev server, for the testing purpose I am using PDF to save the receipt.
One interesting thing is that if I am making the sales receipt as Do no print then the custom receipts is working. For multiple printing it is not working. At a time only one receipt I am able to print. Whether I want to print 3-4 receipts at a time.
Please check my TypeScript Code:
--------------------------------------------------------------------------
import * as Triggers from "PosApi/Extend/Triggers/TransactionTriggers";
import { ObjectExtensions } from "PosApi/TypeExtensions";
import { ClientEntities, ProxyEntities } from "PosApi/Entities";
import { PrinterPrintRequest, PrinterPrintResponse } from "PosApi/Consume/Peripherals";
import { GetHardwareProfileClientRequest, GetHardwareProfileClientResponse } from "PosApi/Consume/Device";
import { GetReceiptsClientRequest, GetReceiptsClientResponse } from "PosApi/Consume/SalesOrders";
export default class PostEndTransactionTrigger extends Triggers.PostEndTransactionTrigger {
/**
* Executes the trigger functionality.
* @param {Triggers.IPostSuspendTransactionTriggerOptions} options The options provided to the trigger.
*/
public execute(options: Triggers.IPostEndTransactionTriggerOptions): Promise<void> {
this.context.logger.logVerbose("Executing PostEndTransactionTrigger with options " + JSON.stringify(options) + ".");
if (ObjectExtensions.isNullOrUndefined(options) || ObjectExtensions.isNullOrUndefined(options.receipts)) {
// This will never happen, but is included to demonstrate how to return a rejected promise when validation fails.
let error: ClientEntities.ExtensionError
= new ClientEntities.ExtensionError("The options provided to the PostEndTransactionTrigger were invalid.");
return Promise.reject(error);
} else {
let hardwareProfileCommon: ProxyEntities.HardwareProfile = null;
return this.context.runtime.executeAsync(new GetHardwareProfileClientRequest())
.then((response: ClientEntities.ICancelableDataResult<GetHardwareProfileClientResponse>)
: Promise<ClientEntities.ICancelableDataResult<GetReceiptsClientResponse>> => {
let hardwareProfile: ProxyEntities.HardwareProfile = response.data.result;
hardwareProfileCommon = response.data.result;
// Gets the receipts.
let salesOrderId: string = options.receipts[0].TransactionId;
let receiptRetrievalCriteria: ProxyEntities.ReceiptRetrievalCriteria = {
IsCopy: false,
IsRemoteTransaction: false,
IsPreview: false,
QueryBySalesId: true,
ReceiptTypeValue: ProxyEntities.ReceiptType.CustomReceipt6,
HardwareProfileId: hardwareProfile.ProfileId
};
let getReceiptsClientRequest: GetReceiptsClientRequest<GetReceiptsClientResponse> =
new GetReceiptsClientRequest(salesOrderId, receiptRetrievalCriteria);
return this.context.runtime.executeAsync(getReceiptsClientRequest);
})
.then((response: ClientEntities.ICancelableDataResult<GetReceiptsClientResponse>)
: Promise<ClientEntities.ICancelableDataResult<PrinterPrintResponse>> => {
let receipts: ProxyEntities.Receipt[] = response.data.result;
// Prints the receipts.
let printerPrintRequest: PrinterPrintRequest<PrinterPrintResponse> = new PrinterPrintRequest(receipts);
return this.context.runtime.executeAsync(printerPrintRequest);
})
.then((response: ClientEntities.ICancelableDataResult<GetReceiptsClientResponse>)
: Promise<ClientEntities.ICancelableDataResult<GetReceiptsClientResponse>> => {
//let hardwareProfile: ProxyEntities.HardwareProfile = response.data.result;
// Gets the receipts.
let salesOrderId: string = options.receipts[0].TransactionId;
let receiptRetrievalCriteriaForCircleLoyalty: ProxyEntities.ReceiptRetrievalCriteria = {
IsCopy: false,
IsRemoteTransaction: false,
IsPreview: false,
QueryBySalesId: true,
ReceiptTypeValue: ProxyEntities.ReceiptType.CustomReceipt7,
HardwareProfileId: hardwareProfileCommon.ProfileId
};
let getReceiptsClientRequestCircleLoyalty: GetReceiptsClientRequest<GetReceiptsClientResponse> =
new GetReceiptsClientRequest(salesOrderId, receiptRetrievalCriteriaForCircleLoyalty);
return this.context.runtime.executeAsync(getReceiptsClientRequestCircleLoyalty);
})
.then((response: ClientEntities.ICancelableDataResult<GetReceiptsClientResponse>)
: Promise<ClientEntities.ICancelableDataResult<PrinterPrintResponse>> => {
let receipts: ProxyEntities.Receipt[] = response.data.result;
// Prints the receipts.
let printerPrintRequest: PrinterPrintRequest<PrinterPrintResponse> = new PrinterPrintRequest(receipts);
return this.context.runtime.executeAsync(printerPrintRequest);
})
.then((): Promise<void> => {
// Resolves to a void result when fulfilled.
return Promise.resolve();
}).catch((reason: any): Promise<void> => {
// Resolves to a void result when rejected. This matches existing POS printing behavior.
this.context.logger.logError("PostEndTransactionTrigger execute error: " + JSON.stringify(reason));
return Promise.resolve();
});
}
}
}