on ‎2020 Apr 06 5:33 PM
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?
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
Looks good, but I can't reference the CalculationPosService calculationPosService = ServiceFactory.INSTANCE.getOrCreateServiceInstance(CalculationPosService.class, cdbSession);
How to - in which lib is it included?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.