@Override public Reconciliation create(String logstr, Reconciliation entity) { // TODO Auto-generated method stub logger.debug(logstr + "create reconcialtion entry " + entity.fetchLogDetails()); Reconciliation reconciliation = reconciliationRepository.save(entity); logger.debug(logstr + "created reconcialtion entry " + entity.fetchLogDetails()); return reconciliation; }
@Override public Reconciliation update(String logstr, Reconciliation tobemerged) throws Exception { // TODO Auto-generated method stub logger.debug(logstr + "update reconciliation entry" + tobemerged.fetchLogDetails()); Reconciliation reconciliationOrig = reconciliationRepository.findOne(tobemerged.getId()); if (reconciliationOrig == null) { logger.debug(logstr + "Reconciliation record does not exist"); throw new Exception(); } Reconciliation reconciliation = reconciliationRepository.save(reconciliationOrig.mergeUpdates(tobemerged)); logger.debug(logstr + "updated reconciliation entry " + reconciliation.fetchLogDetails()); return reconciliation; }
// calculate amount public Reconciliation calculateamt(String logstr, ReconciliationDto tobemerged) throws Exception { // TODO Auto-generated method stub int qty; double fprice, amt = 0; Date date = new Date(); // if (tobemerged.getOrderid() == null) // throw new ReconcileException("Order item list is empty"); // Finding all order to the perticular user List<OrderItem> orderRecords = orderItemRepository.findByUidAndOid(tobemerged.getUserid(), tobemerged.getOrderid()); if (orderRecords == null) { logger.debug(logstr + "Reconciliation record does not exist according to oid and uid"); throw new Exception(); } for (OrderItem orderItem : orderRecords) { FoodItem foodItem = foodItemRepository.findOne(orderItem.getItem_id()); amt = amt + orderItem.getQty() * foodItem.getPrice(); } // Create Reconcile entity Reconciliation reconciliation = new Reconciliation(); logger.debug(logstr + "create reconciliation entry" + reconciliation.fetchLogDetails()); // reconciliation.setDate(getDate); reconciliation.setOrderid(tobemerged.getOrderid()); reconciliation.setOrdercost(amt); reconciliation.setAmountpaid(tobemerged.getAmtpaid()); reconciliation.setUserid(tobemerged.getUserid()); reconciliation.setStatus("processed"); reconciliation.setDate(date); // new update for another update by same user Reconciliation recRecords = reconciliationRepository.findByUseridAndOrderid( tobemerged.getUserid(), tobemerged.getOrderid()); if (recRecords != null) { reconciliation.setId(recRecords.getId()); reconciliation.setAmountpaid(tobemerged.getAmtpaid() + recRecords.getAmountpaid()); update(logstr, reconciliation); } else { reconciliation = reconciliationRepository.save(reconciliation); } logger.debug(logstr + "created reconciliation entry " + reconciliation.fetchLogDetails()); return reconciliation; }