|
|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
package com.mfsys.uco.service;
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.mfsys.comm.util.MapValueExtractorUtil;
|
|
|
|
|
import com.mfsys.uco.UCOURI;
|
|
|
|
|
import com.mfsys.uco.dto.*;
|
|
|
|
|
@ -17,6 +20,10 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static com.itextpdf.styledxmlparser.jsoup.select.Collector.collect;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@Data
|
|
|
|
|
@ -50,6 +57,8 @@ public class TransactionService {
|
|
|
|
|
.cmpCustcode(transactionRequest.getCmpCustcode())
|
|
|
|
|
.drPcrCurrcode(transactionRequest.getDrPcrCurrcode())
|
|
|
|
|
.crMbmBkmstitle(transactionRequest.getCrMbmBkmstitle())
|
|
|
|
|
.drSgtGntramt(BigDecimal.valueOf(convertToPKR(transactionRequest.getDrPcrCurrcode(),transactionRequest.getSgtGntramtfc(), transactionRequest.getPorOrgacode())))
|
|
|
|
|
.crSgtGntramt(null)
|
|
|
|
|
.crPcrCurrdesc(transactionRequest.getCrPcrCurrdesc())
|
|
|
|
|
.crPcrCurrcode(transactionRequest.getCrPcrCurrcode())
|
|
|
|
|
.crPcrCurrshort(transactionRequest.getCrPcrCurrshort())
|
|
|
|
|
@ -63,10 +72,12 @@ public class TransactionService {
|
|
|
|
|
|
|
|
|
|
CoreCashInTransaction coreCashInTransaction = CoreCashInTransaction.builder()
|
|
|
|
|
.drMbmBkmsnumber(transactionRequest.getDrMbmBkmsnumber())
|
|
|
|
|
.drPcrCurrcode("123")
|
|
|
|
|
.sgtGntramtfc(transactionRequest.getSgtGntramtfc())
|
|
|
|
|
.drPcrCurrcode(transactionTrail.getDrPcrCurrcode())
|
|
|
|
|
.accSgtGntramtfc(transactionRequest.getSgtGntramtfc())
|
|
|
|
|
.sgtGntramtfc(transactionTrail.getCrSgtGntramt())
|
|
|
|
|
.otdTrancomment(transactionRequest.getOtdTrancomment())
|
|
|
|
|
.porOrgacode(transactionRequest.getPorOrgacode())
|
|
|
|
|
.pcaGlaccode("A01011003")
|
|
|
|
|
.build();
|
|
|
|
|
Map<String, Object> response = (Map<String, Object>) webClientDepositService.postTransaction(coreCashInTransaction, UCOURI.BANKING_CASH_IN, transactionRequest.getPorOrgacode());
|
|
|
|
|
Map<String, Object> transactionId = (Map<String, Object>) response.get("FuncReturnDetail");
|
|
|
|
|
@ -100,13 +111,15 @@ public class TransactionService {
|
|
|
|
|
Map<String, Object> response = new HashMap<>();
|
|
|
|
|
Optional<TransactionTrail> transactionTrail = transactionTrailRepository.findById(Math.toIntExact(cashOutTransactionRequest.getId()));
|
|
|
|
|
if (transactionTrail.isPresent()) {
|
|
|
|
|
|
|
|
|
|
transactionTrail.get().setCrSgtGntramt(BigDecimal.valueOf(convertFromPKR(transactionTrail.get().getCrPcrCurrcode(),Double.valueOf(String.valueOf(transactionTrail.get().getDrSgtGntramt())),transactionTrail.get().getPorOrgacode())));;
|
|
|
|
|
CoreCashOutTransaction cashOutTransaction = CoreCashOutTransaction.builder()
|
|
|
|
|
.crPcrCurrcode(transactionTrail.get().getCrPcrCurrcode())
|
|
|
|
|
.crMbmBkmsnumber(transactionTrail.get().getCrMbmBkmsnumber())
|
|
|
|
|
.porOrgacode(cashOutTransactionRequest.getPorOrgacode())
|
|
|
|
|
.otdTrancomment(cashOutTransactionRequest.getId() + "_Received")
|
|
|
|
|
.sgtGntramtfc(transactionTrail.get().getSgtGntramt())
|
|
|
|
|
.sgtGntramtfc(transactionTrail.get().getDrSgtGntramt())
|
|
|
|
|
.accSgtGntramtfc(transactionTrail.get().getCrSgtGntramt())
|
|
|
|
|
.pcaGlaccode("A01011003")
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
response = (Map<String, Object>) webClientDepositService.postTransaction(cashOutTransaction, UCOURI.BANKING_CASH_OUT, transactionTrail.get().getPorOrgacode());
|
|
|
|
|
@ -177,4 +190,49 @@ public class TransactionService {
|
|
|
|
|
return amountInTargetCurrency;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public double convertToPKR(String fromcrCurrcode, double amount, String porOrgacode) {
|
|
|
|
|
// List<Map<String, Object>> exchangeRateList = (List<Map<String, Object>>) ucoAccountService.fetchExchangeRate(porOrgacode); // Changed to List<Map>
|
|
|
|
|
|
|
|
|
|
List<ExchangeRateModel> exchangeRateModelList = fetchExchangeRate(porOrgacode);
|
|
|
|
|
String baseCurrencyCode = exchangeRateModelList.stream()
|
|
|
|
|
.filter(ExchangeRateModel::isPcrCurrbase)
|
|
|
|
|
.findFirst()
|
|
|
|
|
.map(ExchangeRateModel::getPcrCurrcode)
|
|
|
|
|
.orElse(null);
|
|
|
|
|
if (fromcrCurrcode.equals(baseCurrencyCode)) {
|
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return exchangeRateModelList.stream()
|
|
|
|
|
.filter(k -> k.getPcrCurrcode().equals(fromcrCurrcode))
|
|
|
|
|
.findFirst()
|
|
|
|
|
.map(k -> amount * k.getPerEratrateact())
|
|
|
|
|
.orElse(0.0);
|
|
|
|
|
}
|
|
|
|
|
public List<ExchangeRateModel> fetchExchangeRate(String porOrgacode) {
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
return objectMapper.convertValue(ucoAccountService.fetchExchangeRate(porOrgacode),
|
|
|
|
|
new TypeReference<List<ExchangeRateModel>>() {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
public double convertFromPKR(String todrCurrcode, double amount,String porOrgacode) {
|
|
|
|
|
List<ExchangeRateModel> exchangeRateModelList = fetchExchangeRate(porOrgacode);
|
|
|
|
|
|
|
|
|
|
String baseCurrencyCode = exchangeRateModelList.stream()
|
|
|
|
|
.filter(ExchangeRateModel::isPcrCurrbase)
|
|
|
|
|
.findFirst()
|
|
|
|
|
.map(ExchangeRateModel::getPcrCurrcode)
|
|
|
|
|
.orElse(null);
|
|
|
|
|
if (todrCurrcode.equals(baseCurrencyCode)) {
|
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return exchangeRateModelList.stream()
|
|
|
|
|
.filter(k -> k.getPcrCurrcode().equals(todrCurrcode))
|
|
|
|
|
.findFirst()
|
|
|
|
|
.map(k -> amount / k.getPerEratrateact())
|
|
|
|
|
.orElseThrow(() -> new RuntimeException("Product Not Found"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|