commit Usend urecieve

Nabeel-DG-BS
Raja Nabeel 1 year ago
parent c8b90452cc
commit 653ad3f3c1

@ -5,6 +5,8 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
@Data
@Builder
@AllArgsConstructor
@ -12,7 +14,9 @@ import lombok.NoArgsConstructor;
public class CoreCashInTransaction {
private String porOrgacode;
private String drMbmBkmsnumber;
private double sgtGntramtfc;
private BigDecimal sgtGntramtfc;
private double accSgtGntramtfc;
private String drPcrCurrcode;
private String otdTrancomment;
private String pcaGlaccode;
}

@ -17,4 +17,7 @@ public class CoreCashOutTransaction {
private BigDecimal sgtGntramtfc;
private String crPcrCurrcode;
private String otdTrancomment;
private String pcaGlaccode;
private BigDecimal accSgtGntramtfc;
}

@ -0,0 +1,22 @@
package com.mfsys.uco.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ExchangeRateModel {
private String pcrCurrshort;
private String pcrCurrcode;
private String perEratdate;
private String petExrtcode;
private String porOrgacode;
private double perEratrateact;
private String pcrCurrdesc;
private String petExrtdesc;
private boolean pcrCurrbase;
}

@ -44,6 +44,10 @@ public class TransactionTrail {
protected LocalDate crSgtGntrdate;
@Column(name = "SGT_GNTRAMT", nullable = false, updatable = false, columnDefinition = FieldNameLength.AMOUNT_REAL)
protected BigDecimal sgtGntramt = BigDecimal.ZERO;
@Column(name = "DR_SGT_GNTRAMT", nullable = false, updatable = false, columnDefinition = FieldNameLength.AMOUNT_REAL)
protected BigDecimal drSgtGntramt = BigDecimal.ZERO;
@Column(name = "CR_SGT_GNTRAMT", nullable = true, updatable = false, columnDefinition = FieldNameLength.AMOUNT_REAL)
protected BigDecimal crSgtGntramt = BigDecimal.ZERO;
@Column(name = "BAT_ACNTTRANSENT", nullable = false, columnDefinition = FieldNameLength.BOOLEAN_BIT)
protected boolean batAcnttranSend;
@Column(name = "BAT_ACNTTRANRECEIVED", nullable = true, columnDefinition = FieldNameLength.BOOLEAN_BIT)

@ -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"));
}
}

Loading…
Cancel
Save