PrePrintReceiptCopyTrigger POS 365 - Microsoft Dynamics 365 Vietnam

Microsoft Dynamics 365 Vietnam

Song Nghia - Microsoft Dynamics 365 Vietnam

Breaking

Friday, October 9, 2020

PrePrintReceiptCopyTrigger POS 365

 PrePrintReceiptCopyTrigger POS 365

Nghia Song -  Microsoft Dynamics 365 Technical Consultant

Nghia Song

Tel - WhatsApp: +84967324794

Email: songnghia.uit@gmail.com

import * as Triggers from "PosApi/Extend/Triggers/PrintingTriggers";
import { ClientEntities, ProxyEntities } from "PosApi/Entities";
import { ObjectExtensions } from "PosApi/TypeExtensions";
//import ReprintReceiptCache from "../ViewExtensions/ShowJournal/ReprintReceiptCache";
//import { Entities, XZReportDocument } from "../DataService/DataServiceRequests.g";
import { GetHardwareProfileClientRequest, GetHardwareProfileClientResponse } from "PosApi/Consume/Device";
import { GetReceiptsClientRequest, GetReceiptsClientResponse } from "PosApi/Consume/SalesOrders";
import { PrinterPrintRequest, PrinterPrintResponse } from "PosApi/Consume/Peripherals";

export default class PrePrintReceiptCopyTrigger extends Triggers.PrePrintReceiptCopyTrigger {

    public execute(options: Triggers.IPrePrintReceiptCopyTriggerOptions): Promise {

        if (ObjectExtensions.isNullOrUndefined(options)) {

            // This will never happen, but is included to demonstrate how to return a rejected promise when validation fails.
            //ABC
            let error: ClientEntities.ExtensionError
                = new ClientEntities.ExtensionError("The options provided to the PrePrintReceiptCopyTrigger were invalid.");
            return Promise.reject(error);
        } else {
            return this.context.runtime.executeAsync(new GetHardwareProfileClientRequest())
                .then((response: ClientEntities.ICancelableDataResult)
                    : Promise> => {
                    let hardwareProfile: ProxyEntities.HardwareProfile = response.data.result;
                    // Gets the receipts.
                    let salesOrderId: string = options.salesOrder.Id;
                    let receiptRetrievalCriteria: ProxyEntities.ReceiptRetrievalCriteria = {
                        IsCopy: false,
                        IsRemoteTransaction: false,
                        IsPreview: false,
                        QueryBySalesId: true,
                        ReceiptTypeValue: ProxyEntities.ReceiptType.CustomReceipt6,
                        HardwareProfileId: hardwareProfile.ProfileId
                    };
                    let getReceiptsClientRequest: GetReceiptsClientRequest =
                        new GetReceiptsClientRequest(salesOrderId, receiptRetrievalCriteria);
                    return this.context.runtime.executeAsync(getReceiptsClientRequest);
                })
                .then((response: ClientEntities.ICancelableDataResult)
                    : Promise> => {
                    let receipts: ProxyEntities.Receipt[] = response.data.result;
                    // Prints the receipts.
                    let printerPrintRequest: PrinterPrintRequest = new PrinterPrintRequest(receipts);
                    return this.context.runtime.executeAsync(printerPrintRequest);
                })
        }
}

No comments:

Post a Comment