on 12-18-2023 11:21 AM
Hi,
I am developping a CCO plugin to manage Returns. The purpose is to add the ReturnSalesItem directly in the Receipt following some business rules.
I tried to use ReturnSalesItemPosService but I did not succeed.
Here is my code that did not work:
CDBSession session = CDBSessionFactory.instance.createSession();
ReceiptManager receiptManager = new ReceiptManager(session);
ReceiptEntity receipt = receiptManager.findOrCreate(UserRegistry.INSTANCE.getCurrentUser(), null, false);
.
.
.
ReturnSalesItemPosService returnSalesItemPosService = ServiceFactory.INSTANCE.getOrCreateServiceInstance(ReturnSalesItemPosService.class, session);
try {
returnSalesItemPosService.returnSalesItemInSameReceipt(receipt, sie, new BigDecimal(-1), "1", "01", true);
} catch (ValidationException e) {
throw new RuntimeException(e);
}
receiptManager.deleteSalesItem(receipt, sie);
receiptManager.calculate(receipt, BaseEntity.EntityActions.UPDATE);
receiptManager.update(receipt);
BroadcasterHolder.INSTANCE.getBroadcaster().broadcastPluginEventForPath("RECEIPT_REFRESH", null);
Hi haythem.jaidi,
if I understand this correctly you have some kind of purchase at the POS? And this purchase is not based on a prior sale, right?
Why use the ReturnReceiptPosService? The intention of this service is to create receipts (returns) based on a sales receipt.
Use the EntityFactory to create the sales item with negative quantity (adapt to your needs, the material entity can be retrieved with the MaterialManager). Add the sales item with the ReceiptPosService.
ReceiptPosService posService = ServiceFactory.INSTANCE.getOrCreateServiceInstance(ReceiptPosService.class, session);
SalesItemEntity salesItem = EntityFactory.INSTANCE.createSalesItemEntity(material,
"Sales Item Description",
grossAmount,
BigDecimal.valueOf(-1),
"EA");
posService.addSalesItem(receipt, salesItem);
HTH
Robert
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.