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.
Hi robertzieschang ,
Thank you for the recommandation and best practices.
The scenario is as following: The customer will get to the Cachier (POS) to sell his Product. The cachier will buy the product: 3 actions to be done:
1/ Suggest a price
2/ Create the product (Article) with the entered information in the form (Plugin with a pop-up)
3/ Add the Article as a ReturnSalesItem in the Receipt.
For the moment is possible to do it manually like below, but I would like to do it in one single action.
Best Regards
Haythem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi haythem.jaidi,
first of all 2 recommendations about your code:
1. don't open CDBSession in that way. In your case, if an exception is thrown before you closed the session, the session will stay open. Use try-with-resources.
try(CDBSession session = CDBSessionFactory.instance.createSession()) {<br>// your code<br>}
With this, Java will automatically close the session, when something in your code breaks.
2. Don't rethrow exceptions like that. Depending on certain situations you can break more than you want. Handle exceptions and log the error message and stacktrace.
Back to topic:
What is it exactly you want to achieve? What is the trigger event of your code? I am not quite sure, if I understood your requirement correctly.
Regards
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.