cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Update properties of a salesitem, at run time using JAVA?

former_member333938
Participant
0 Likes
637

Hello all.

I am interested in knowing how I can update properties of a salesItem of a receipt on the screen, for example update the gross price.

I want to do this without having to create the receipt and catch the ReceiptPosService event. I have tried to use the receiptManager, but I have not found the solution.

anyone know how to do this?

Accepted Solutions (1)

Accepted Solutions (1)

R_Zieschang
Active Contributor
0 Likes

Hi josehrmatos ,

I think there is no other way than using the ReceiptPosService.

So to set e.g. the unitGrossAmount to 1.00 for every salesItem in the receipt...

Get the ReceiptPosService.
Get the current Receipt.
Get the CalculationPosService.
Set the unitGrossAmount.
Set the SalesItem as changed (UnitPriceChanged and MarkChanged).
Recalculate the receipt.
Update the Receipt in the backend.
Update the Receipt in the UI via a UI Event.

try (CDBSession cdbSession = CDBSessionFactory.instance.createSession()) {
    ReceiptPosService receiptPosService = ServiceFactory.INSTANCE.getOrCreateServiceInstance(ReceiptPosService.class, cdbSession);
    ReceiptEntity receipt = receiptPosService.findOrCreate(UserRegistry.INSTANCE.getCurrentUser(), null, true);
    CalculationPosService calculationPosService = ServiceFactory.INSTANCE.getOrCreateServiceInstance(CalculationPosService.class, cdbSession);


    receipt.getSalesItems()
            .stream()
            .forEach(salesItem -> {
                salesItem.setUnitGrossAmount(BigDecimal.ONE);
                salesItem.setUnitPriceChanged(true);
                salesItem.setMarkChanged(true);
            });

    calculationPosService.recalculateReceipt(receipt);
    receiptPosService.updateReceipt(receipt, true);
    BroadcasterHolder.INSTANCE.getBroadcaster().broadcastPluginEventForPath("RECEIPT_REFRESH", null);

} catch (InconsistentReceiptStateException e) {
    log.severe(e.getLocalizedMessage());
    log.fine(ExceptionUtils.getFullStackTrace(e));
}

Tested with 2.9.

hth

Robert

former_member333938
Participant
0 Likes

Thanks for your answer Robert,

I tried it and it worked well. But I have a doubt, when I implement it on a normal receipt it works perfectly. but when i try to implement it in a return receipt the UnitGrossAmount are not changed. I don't know if it is because the amounts are negative.

do you know why this?

Answers (3)

Answers (3)

ruediger_linhart
Explorer
0 Likes

Looks good, but I can't reference the CalculationPosService calculationPosService = ServiceFactory.INSTANCE.getOrCreateServiceInstance(CalculationPosService.class, cdbSession);

How to - in which lib is it included?

R_Zieschang
Active Contributor
0 Likes

Hi josehrmatos ,

it is still not clear to me, what you want to achieve. Do you want to update the masterdata of a salesitem or the salesitem within a receipt?

Because you mentioned, you don't want to use the ReceiptPosService and you dont want to create a receipt.

Bit confused. Sorry.

Regards

Robert

former_member333938
Participant
0 Likes

Sorry if I confused you,

I want to change the price or other property of the salesitem within the receipt that I am creating.

I hope you can understand me better.

xsalgadog
Participant
0 Likes

Hello,

because when I update the price of the item, the same item with the same characteristics is not in the same line,

I have the Always split sales items option disabled.

thank you very much.

R_Zieschang
Active Contributor
0 Likes

Hi josehrmatos,

do you want to change the masterdata of the salesitem so that every receipt after your update will have the salesitem with the new gross price?

Regards

Robert

former_member333938
Participant
0 Likes

Hi rzieschang ,

I want to update the gross price only for the receipt that I decide before creating the receipt so that the user can see that price change., but this price is not permanently affected in the master data for future use.

former_member333938
Participant
0 Likes

Hi rzieschang ,

Have you been able to know anything about this?.

thanks in advance,