add 后清算手续费Invoice模板

master
luoyang 6 years ago
parent 336b1101f4
commit 16d2138bae

@ -13,7 +13,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jib-maven-plugin.version>1.1.2</jib-maven-plugin.version>
<docker-image.version>1.0.6</docker-image.version>
<docker-image.version>1.0.7</docker-image.version>
</properties>
<dependencies>

@ -22,6 +22,9 @@ public interface ClearingDistributedSurchargeMapper {
@AutoSql(type = SqlType.INSERT)
void save(JSONObject transactions);
@AutoSql(type = SqlType.SELECT)
JSONObject findByClearingId(@Param("client_id") int clientId, @Param("clearing_detail_id") String clearingDetailId);
List<JSONObject> getMonthDetailByClientId(@Param("datefrom") Date datefrom, @Param("dateto") Date dateto);
List<JSONObject> findSurchargeTransactionsByDetailId(@Param("client_id") int clientId, @Param("detailId") String detailId);

@ -2,6 +2,7 @@ package au.com.royalpay.payment.manage.surchargeAccount.core;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
public interface SurchargeAccountService {
@ -12,4 +13,5 @@ public interface SurchargeAccountService {
void fillMothsSurcharge(JSONObject manager, String detailId);
void exportInvoicePDF(int clientId, String clearingDetailIdJSONObject,JSONObject manager, HttpServletResponse httpResponse);
}

@ -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,6 +141,71 @@ 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();
}
JSONObject distributedDetail = clearingDistributedSurchargeMapper.findByClearingId(clientId, clearingDetailId);
String date = DateFormatUtils.format(distributedDetail.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));
}
}

@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@RequestMapping("/sys/surcharge_account")
@ -26,4 +27,10 @@ public class SurchargeAccountController {
public void fillMothsSurcharge(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, @PathVariable String detailId) {
surchargeAccountService.fillMothsSurcharge(manager, detailId);
}
@ManagerMapping(value = "/{clientId}/settlement_logs/{clearingDetailId}/export", role = {ManagerRole.ADMIN, ManagerRole.OPERATOR, ManagerRole.FINANCIAL_STAFF}, method = RequestMethod.GET)
public void exportInvoicePDF(@PathVariable int clientId, @PathVariable String clearingDetailId,
@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, HttpServletResponse httpResponse) throws Exception {
surchargeAccountService.exportInvoicePDF(clientId, clearingDetailId, manager, httpResponse);
}
}

@ -2404,13 +2404,12 @@ define(['angular', 'decimal', 'static/commons/commons', 'uiBootstrap', 'uiRouter
}]);
app.controller('surchargeAccountDetailCtrl', ['$scope', '$http', 'balance', 'partner', 'transactions', 'commonDialog', function ($scope, $http, balance, partner, transactions, commonDialog) {
$scope.surcharge = angular.copy(balance);
$scope.transactions = angular.copy(transactions.data);
$scope.surchargeDetailData = angular.copy(transactions.data);
$scope.partner = angular.copy(partner);
$scope.canAddDetail = false;
$scope.params = {};
$scope.getBalance = function () {
if ($scope.partner.surcharge_mode != undefined && $scope.partner.surcharge_mode == "distributed") {
$http.get('/sys/partners/' + $scope.partner.client_moniker + '/surcharge_account').then(function (resp) {
$scope.surcharge = resp.data;
@ -2421,7 +2420,7 @@ define(['angular', 'decimal', 'static/commons/commons', 'uiBootstrap', 'uiRouter
$scope.getTransactions = function () {
$http.get('/sys/partners/' + $scope.partner.client_moniker + '/account/transactions').then(function (resp) {
$scope.transactions = resp.data;
$scope.surchargeDetailData = resp.data;
});
}

@ -315,7 +315,7 @@
</div>
</div>
<div class="form-group col-sm-6">
<label class="control-label col-sm-4">Counrty</label>
<label class="control-label col-sm-4">Country</label>
<div class="col-sm-8">
<p class="form-control-static" ng-bind="partner.country"></p>

@ -708,7 +708,7 @@
</div>
</div>
<div class="form-group col-sm-6">
<label class="control-label col-sm-4">Counrty</label>
<label class="control-label col-sm-4">Country</label>
<div class="col-sm-8">
<p class="form-control-static" ng-bind="partner.country"></p>

@ -49,7 +49,7 @@
<td ng-bind="surcharge.tax_amount|currency:'AUD'"></td>
<td>
{{surcharge.remark}}
<a ng-href="/sys/clean_logs/{{surcharge.client_id}}/settlement_logs/{{surcharge.clearing_detail_id}}/export"
<a ng-href="/sys/surcharge_account/{{surcharge.client_id}}/settlement_logs/{{surcharge.clearing_detail_id}}/export"
target="_blank" title="Download">
<i class="fa fa-download"></i>
</a>

@ -51,7 +51,7 @@
<td ng-bind="surcharge.tax_amount|currency:'AUD'"></td>
<td ng-bind="surcharge.remark"></td>
<td>
<a ng-href="/sys/clean_logs/{{surcharge.client_id}}/settlement_logs/{{surcharge.clearing_detail_id}}/export"
<a ng-href="/sys/surcharge_account/{{surcharge.client_id}}/settlement_logs/{{surcharge.clearing_detail_id}}/export"
target="_blank" title="Download">
<i class="fa fa-download"></i>
</a>

Loading…
Cancel
Save