|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
package au.com.royalpay.payment.manage.surchargeAccount.core.impl;
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.log.ClearingDetailAnalysisMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClearingDistributedSurchargeMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientsSurchargeAccountsMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.FinancialSurchargeAccountDetailMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.surchargeAccount.core.SurchargeAccountService;
|
|
|
|
@ -10,7 +13,9 @@ import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
|
|
|
|
|
import au.com.royalpay.payment.tools.lock.Locker;
|
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
|
import au.com.royalpay.payment.tools.utils.PdfUtils;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
|
|
import org.joda.time.DateTime;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
@ -18,11 +23,14 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.math.RoundingMode;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@ -33,6 +41,10 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService {
|
|
|
|
|
@Resource
|
|
|
|
|
private FinancialSurchargeAccountDetailMapper financialSurchargeAccountDetailMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ClientMapper clientMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private ClearingDetailAnalysisMapper clearingDetailAnalysisMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private Locker locker;
|
|
|
|
|
@Resource
|
|
|
|
|
private ClientsSurchargeAccountsMapper clientsSurchargeAccountsMapper;
|
|
|
|
@ -129,4 +141,75 @@ public class SurchargeAccountServiceImpl implements SurchargeAccountService {
|
|
|
|
|
locker.unlock(detail.getIntValue("client_id") + "_" + detail.getString("settle_month") + "_fill");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void exportInvoicePDF(int clientId, String clearingDetailId,JSONObject manager, HttpServletResponse httpResponse) {
|
|
|
|
|
JSONObject client = clientMapper.findClient(clientId);
|
|
|
|
|
if (client == null) {
|
|
|
|
|
throw new InvalidShortIdException();
|
|
|
|
|
}
|
|
|
|
|
List<JSONObject> distributedDetail = clearingDistributedSurchargeMapper.findByClearingId(clientId, clearingDetailId);
|
|
|
|
|
if (distributedDetail.size() > 1) {
|
|
|
|
|
throw new BadRequestException("此次清算扣款已回滚");
|
|
|
|
|
}
|
|
|
|
|
JSONObject detial = distributedDetail.get(0);
|
|
|
|
|
String date = DateFormatUtils.format(detial.getDate("settle_date"), "dd MMM yyyy", Locale.US);
|
|
|
|
|
httpResponse.setContentType("application/pdf");
|
|
|
|
|
httpResponse.setHeader("content-disposition", "attachment;filename="+ client.getString("client_moniker") + "_Invoice_" + date + ".pdf");
|
|
|
|
|
ServletOutputStream sos = null;
|
|
|
|
|
JSONObject pdfInfo = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
sos = httpResponse.getOutputStream();
|
|
|
|
|
List<JSONObject> clearingAnalysis = clearingDetailAnalysisMapper.listReportChannels(clearingDetailId);
|
|
|
|
|
invoiceChannelAmount(clearingAnalysis, pdfInfo);
|
|
|
|
|
httpResponse.getOutputStream();
|
|
|
|
|
pdfInfo.put("date", date);
|
|
|
|
|
pdfInfo.put("company_name", client.getString("company_name"));
|
|
|
|
|
pdfInfo.put("address", client.getString("address"));
|
|
|
|
|
pdfInfo.put("suburb", client.getString("suburb") +" " + client.getString("state") +" " +client.getString("postcode"));
|
|
|
|
|
pdfInfo.put("country", client.getString("country"));
|
|
|
|
|
PdfUtils pdu = new PdfUtils();
|
|
|
|
|
pdu.setTemplatePdfPath("https://file.royalpay.com.au/open/2019/05/21/1558428021205_9pyF7U1rEloxVOXx2k7bTeRxzJaXi0.pdf");
|
|
|
|
|
pdu.setPdfTemplate(pdfInfo);
|
|
|
|
|
File file = new File(client.getString("client_moniker") + "_Invoice_"+ date + ".pdf");
|
|
|
|
|
ByteArrayOutputStream bos = pdu.templetPdfBos(file);
|
|
|
|
|
sos.write(bos.toByteArray());
|
|
|
|
|
sos.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void invoiceChannelAmount(List<JSONObject> analysis,JSONObject pdfInfo) {
|
|
|
|
|
BigDecimal wechatSurcharge = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal wechatTaxAmount = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal wechatAmount = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal alipaySurcharge = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal alipayTaxAmount = BigDecimal.ZERO;
|
|
|
|
|
BigDecimal alipayAmount = BigDecimal.ZERO;
|
|
|
|
|
for (JSONObject detail : analysis) {
|
|
|
|
|
switch (detail.getString("channel")) {
|
|
|
|
|
case "Wechat":
|
|
|
|
|
wechatSurcharge = detail.getBigDecimal("total_charge");
|
|
|
|
|
wechatTaxAmount = detail.getBigDecimal("tax_amount");
|
|
|
|
|
wechatAmount = detail.getBigDecimal("distributed_surcharge");
|
|
|
|
|
break;
|
|
|
|
|
case "Alipay":
|
|
|
|
|
alipaySurcharge = detail.getBigDecimal("total_charge");
|
|
|
|
|
alipayTaxAmount = detail.getBigDecimal("tax_amount");
|
|
|
|
|
alipayAmount = detail.getBigDecimal("distributed_surcharge");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pdfInfo.put("surcharge_wechat", wechatSurcharge);
|
|
|
|
|
pdfInfo.put("amount_wechat", wechatSurcharge);
|
|
|
|
|
pdfInfo.put("surcharge_alipay", alipaySurcharge);
|
|
|
|
|
pdfInfo.put("amount_alipay", alipaySurcharge);
|
|
|
|
|
pdfInfo.put("amount", wechatSurcharge.add(alipaySurcharge));
|
|
|
|
|
pdfInfo.put("gst", wechatTaxAmount.add(alipayTaxAmount));
|
|
|
|
|
pdfInfo.put("total_amount", (wechatAmount.add(alipayAmount)).setScale(2, RoundingMode.DOWN));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|