react-native-sunmi-inner-printer icon indicating copy to clipboard operation
react-native-sunmi-inner-printer copied to clipboard

Text prints out of order

Open zkrige opened this issue 6 years ago • 6 comments

    async _print(text) {
        console.log(text)
        await SunmiInnerPrinter.printOriginalText(text)
    }
            await SunmiInnerPrinter.setAlignment(1)
            await SunmiInnerPrinter.setFontSize(22)
            await this._print('Order Receipt\n')
            await SunmiInnerPrinter.setAlignment(0)
            await this._print('Order Placed : ' + receipt.orderPlaced + '\n')
            await this._print('Order ID : ' + receipt.orderId + '\n')
            await this._print('Order Status : ' + receipt.status + '\n')
            await this._print('Supplier : ' + receipt.supplier + '\n')
            await this._print('Fulfillment : ' + receipt.fulfillment + '\n')
            await this._print('Payment Status : ' + receipt.paymentStatus + '\n')
            await this._print('----------------------------------\n')
            await this._print('PRODUCTS\n')
            await receipt.products.forEach(async ele => {
                let text = ele.detail.name + ' : \n'
                let price = ele.price ? Utils.currencyFormat(ele.price, 15) : "R0.00"
                let quantity = ele.quantity.toLocaleString()
                quantity = _.padEnd(quantity, 17, ' ')
                text = text + 'x ' + quantity + price + '\n'
                await this._print(text)
            });
            await this._print('----------------------------------\n')
            await this._print('Total :            ' + total + '\n')
            await this._print('----------------------------------\n')
            await this._print('\n')
            await this._print('\n')
            await this._print('\n')

Sometimes the dashed line that is meant to be above total prints before the products have printed. this is intermittent. Sometimes it prints in correct order, but about half the time it doesn't.

zkrige avatar Mar 14 '19 08:03 zkrige

Plz be care about the usage of foreach.

发自我的 iPhone

在 2019年3月14日,下午4:31,Zayin Krige [email protected] 写道:

async _print(text) {
    console.log(text)
    await SunmiInnerPrinter.printOriginalText(text)
}
        await SunmiInnerPrinter.setAlignment(1)
        await SunmiInnerPrinter.setFontSize(22)
        await this._print('Order Receipt\n')
        await SunmiInnerPrinter.setAlignment(0)
        await this._print('Order Placed : ' + receipt.orderPlaced + '\n')
        await this._print('Order ID : ' + receipt.orderId + '\n')
        await this._print('Order Status : ' + receipt.status + '\n')
        await this._print('Supplier : ' + receipt.supplier + '\n')
        await this._print('Fulfillment : ' + receipt.fulfillment + '\n')
        await this._print('Payment Status : ' + receipt.paymentStatus + '\n')
        await this._print('----------------------------------\n')
        await this._print('PRODUCTS\n')
        await receipt.products.forEach(async ele => {
            let text = ele.detail.name + ' : \n'
            let price = ele.price ? Utils.currencyFormat(ele.price, 15) : "R0.00"
            let quantity = ele.quantity.toLocaleString()
            quantity = _.padEnd(quantity, 17, ' ')
            text = text + 'x ' + quantity + price + '\n'
            await this._print(text)
        });
        await this._print('----------------------------------\n')
        await this._print('Total :            ' + total + '\n')
        await this._print('----------------------------------\n')
        await this._print('\n')
        await this._print('\n')
        await this._print('\n')

Sometimes the dashed line that is meant to be above total prints before the products have printed. this is intermittent. Sometimes it prints in correct order, but about half the time it doesn't.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

januslo avatar Mar 14 '19 08:03 januslo

I am doing await foreach so it should be ok?

do you recommend some other method?

zkrige avatar Mar 14 '19 08:03 zkrige

You may do some console log to find out the call orders. Foreach may not completely the same as for(;;).

发自我的 iPhone

在 2019年3月14日,下午4:44,Zayin Krige [email protected] 写道:

I am doing await foreach so it should be ok?

do you recommend some other method?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

januslo avatar Mar 14 '19 10:03 januslo

@zkrige how's the thing

januslo avatar Mar 22 '19 13:03 januslo

thanks for checking :)

We've parked this issue for now and will revisit in near future

zkrige avatar Mar 23 '19 07:03 zkrige

I had problems because I did not use await / async in a proper way. All functions for printing text, bitmap are callbacks I think.

mmilos028 avatar Feb 03 '21 15:02 mmilos028