aba file remark from param outside

master
yixian 6 years ago
parent 7dc090209c
commit 375f0a3882

@ -546,8 +546,10 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider
if (settle.getBigDecimal("clearing_amount").compareTo(BigDecimal.ZERO) == 0) {
continue;
}
aba.addSettleMerchant(settle.getString("client_moniker"), settle.getString("bsb_no"), settle.getString("account_no"), settle.getString("account_name"),
settle.getBigDecimal("clearing_amount"));
String clientMoniker = settle.getString("client_moniker");
String remark = "RoyalPay" + DateFormatUtils.format(dt, "MMdd") + clientMoniker;
aba.addSettleMerchant(settle.getString("bsb_no"), settle.getString("account_no"), settle.getString("account_name"),
settle.getBigDecimal("clearing_amount"), remark);
}
return aba;
}

@ -29,8 +29,8 @@ public class ABAFile {
totalSettleAmount = BigDecimal.ZERO;
}
public void addSettleMerchant(String clientMoniker, String bsbNo, String accountNo, String accountName, BigDecimal settleAmount) {
settlements.add(new SettleMerchantInfo(clientMoniker, bsbNo, accountNo, accountName, settleAmount));
public void addSettleMerchant(String bsbNo, String accountNo, String accountName, BigDecimal settleAmount, String remark) {
settlements.add(new SettleMerchantInfo(bsbNo, accountNo, accountName, settleAmount, remark));
totalSettleAmount = totalSettleAmount.add(settleAmount);
}
@ -129,18 +129,18 @@ public class ABAFile {
}
private class SettleMerchantInfo {
private final String clientMoniker;
private final String bsbNo;
private final String accountNo;
private final String accountName;
private final BigDecimal settleAmount;
private final String remark;
public SettleMerchantInfo(String clientMoniker, String bsbNo, String accountNo, String accountName, BigDecimal settleAmount) {
this.clientMoniker = clientMoniker;
public SettleMerchantInfo(String bsbNo, String accountNo, String accountName, BigDecimal settleAmount, String remark) {
this.bsbNo = bsbNo;
this.accountNo = accountNo.replaceAll("\\D", "");
this.accountName = accountName;
this.settleAmount = settleAmount;
this.remark = remark;
}
public String settleLine() {
@ -151,7 +151,7 @@ public class ABAFile {
lineBuilder.replace(18, 20, "50");
lineBuilder.replace(20, 30, getSettleAmount());
lineBuilder.replace(30, 62, getAccountName());
lineBuilder.replace(62, 80, StringUtils.rightPad("RoyalPay" + DateFormatUtils.format(settleDate, "MMdd") + clientMoniker, 18));
lineBuilder.replace(62, 80, StringUtils.rightPad(getRemark(), 18));
lineBuilder.replace(80, 87, bsbNo(base.getBsb()));
lineBuilder.replace(87, 96, StringUtils.leftPad(base.getAccountNo(), 9));
lineBuilder.replace(96, 112, StringUtils.left(StringUtils.rightPad(base.getAccountName(), 16), 16));
@ -159,19 +159,23 @@ public class ABAFile {
return lineBuilder.toString();
}
private String getBsbNo() {
protected String getRemark() {
return remark;
}
protected String getBsbNo() {
return bsbNo(bsbNo);
}
private String getAccountNo() {
protected String getAccountNo() {
return StringUtils.leftPad(StringUtils.right(accountNo, 9), 9);
}
private String getAccountName() {
protected String getAccountName() {
return StringUtils.rightPad(StringUtils.substring(accountName, 0, 32), 32);
}
private String getSettleAmount() {
protected String getSettleAmount() {
Assert.isTrue(settleAmount.compareTo(BigDecimal.ZERO) > 0, "Invalid Settle Amount:" + settleAmount.toPlainString());
return amountString(settleAmount, 10);
}

@ -0,0 +1,66 @@
package au.com.royalpay.payment.manage.process;
import au.com.royalpay.payment.manage.support.abafile.ABAConfig;
import au.com.royalpay.payment.manage.support.abafile.ABAFile;
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.util.ReflectionTestUtils;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* Create by yixian at 2019-01-17 12:47
*/
public class ABAGenerator {
private ABAConfig.ABABase config;
private Logger logger = LoggerFactory.getLogger(getClass());
private String csvFile = "C:\\Users\\yixian\\Documents\\royalpay\\2019\\cemtexaba-template-csv.csv";
@Before
public void prepareEnv() {
PlatformEnvironment env = new PlatformEnvironment();
env.afterInitialize();
ReflectionTestUtils.setField(env, "foreignCurrency", "AUD");
config = new ABAConfig.ABABase()
.setBank("CBA")
.setApca("301500")
.setBsb("063109")
.setAccountNo("11505847")
.setAccountName("Tunnel Show Pty Ltd");
}
@Test
public void generate() {
ABAFile file = config.initFile(new Date());
try (FileReader reader = new FileReader(csvFile)) {
CSVParser parser = new CSVParser(reader, CSVFormat.newFormat(','));
List<CSVRecord> records = parser.getRecords();
for (CSVRecord record : records) {
logger.debug("reading record:{}", record.toString());
String bsb = record.get(0).replace("-", "");
String accountNo = record.get(1);
String accountName = record.get(2);
BigDecimal amount = new BigDecimal(record.get(3));
String remark = record.get(4);
file.addSettleMerchant(bsb, accountNo, accountName, amount, remark);
}
byte[] bytes = file.output(0);
FileUtils.writeByteArrayToFile(new File("C:\\Users\\yixian\\Documents\\royalpay\\2019\\cemtexaba-template.aba"), bytes);
logger.info("output done");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Loading…
Cancel
Save