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

add article to receipt via plugin in sap customer checkout

RicardoRenteria
Participant
0 Likes
1,219

Hello everyone,

I need to add an article to the receipt. I'm trying to do the following:

CDBSession session = CDBSessionFactory.instance.createSession();
ReceiptManager receiptManager = new ReceiptManager(session);
ReceiptEntity receipt = receiptManager.findOrCreate(UserRegistry.INSTANCE.getCurrentUser(), null, false);
SalesItemEntity sie = new SalesItemEntity(); 
sie.setExternalId("A00004"); 
sie.setPercentageDiscount(true); 
sie.setDiscountManuallyChanged(true); 
sie.setItemDiscountChanged(true); 
sie.setQuantity(new BigDecimal(1)); 
sie.setDescription("articulo ingresado"); 
sie.setTaxRateTypeCode("IVA19"); 
sie.setQuantityTypeCode("Manual"); 
sie.setPriceListId(receipt.getPriceListId());

receiptManager.addSalesItems(receipt, sie, true);
receiptManager.calculate(receipt, EntityActions.Update);
receiptManager.update(receipt);			
UIEventDispatcher.INSTANCE.dispatchAction(CConst.UIEventsIds.RECEIPT_REFRESH, null, receipt);

But the receipt is not showing some fields: article id, unit, unit price, gross amount and therefore the total is not updated

What's wrong or what I need to take in account to achieve that?

Accepted Solutions (1)

Accepted Solutions (1)

R_Zieschang
Active Contributor
0 Likes

Hi ricardo.renteria2 ,

please add a sales item like this:

SalesItemEntity newSalesItem = EntityFactory.INSTANCE.createSalesItemEntity(...);
/...
receiptManager.addSalesItem(newSalesItem);


In your code you are creating an unmanaged sales item entity. Please use the createSalesItemEntity from the EntityFactory class.

Regards

Robert

RicardoRenteria
Participant
0 Likes

Thank you Robert, just in the point!

Answers (1)

Answers (1)

former_member57406
Discoverer
0 Likes

I am having similar issue. I have created a test scenerio for my actual problem. The number of lines if greater than 2 should remove all the lines. if maxval=0 the code runs fine and remove the line from front end. but if the maxval = 1 or greater the front end line items are kept visible while they are not available in the backend. PLEASE HELP.

@PluginAt(pluginClass = IReceiptManager.class, method = "addSalesItems", where = POSITION.AFTER)
public void checkSalesItem_Test(Object proxy, Object[] args, Object ret, StackTraceElement Caller) {
if (args.length == 2) {
CDBSession session = CDBSessionFactory.instance.createSession();
ReceiptManager receiptManager = new ReceiptManager(session);
ReceiptEntity receipt = (ReceiptEntity) args[0];
SalesItemEntity saleseItem = (SalesItemEntity) args[1];

List<SalesItemEntity> receiptItems_All1 = receiptManager.getValidSalesItemList(receipt);
int size1 = receiptItems_All1.size();

int maxval = 2;
if(size1>maxval) {
for (int j = 0; j < size1; j++) {
SalesItemEntity entity = receiptItems_All1.get(j);
receiptManager.deleteSalesItem(receipt, entity);
}
receiptManager.calculate(receipt, EntityActions.UPDATE);
receiptManager.update(receipt);
UIEventDispatcher.INSTANCE.dispatchAction(CConst.UIEventsIds.RECEIPT_REFRESH, null, receipt);
}
}
}

RicardoRenteria
Participant
0 Likes

Hi jmran

what is the context of your problem? why do you need to delete the sales items when size1>maxval? what is maxval? If you can provide a better context and some images of your problem maybe it could be better to understand.