diff --git a/src/main/java/au/com/royalpay/payment/manage/analysis/web/PartnerCardDashboardController.java b/src/main/java/au/com/royalpay/payment/manage/analysis/web/PartnerCardDashboardController.java index 3b51b69b3..74f41b6e5 100644 --- a/src/main/java/au/com/royalpay/payment/manage/analysis/web/PartnerCardDashboardController.java +++ b/src/main/java/au/com/royalpay/payment/manage/analysis/web/PartnerCardDashboardController.java @@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.text.ParseException; import java.util.List; +import java.util.Map; /** * Created by yishuqian on 20/02/2017. @@ -78,5 +79,11 @@ public class PartnerCardDashboardController { return cleanService.getCleanLogTransactions(detailId, manager); } + @RequestMapping("/settlement_logs/{detailId}/analysis/{channel}") + public Map getDayAndChannelOfAnalysisMap(@PathVariable int detailId, + @PathVariable String channel, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + return cleanService.getDayAndChannelOfAnalysisMap(detailId,channel, manager); + } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java index e646cdc64..f4d0e7a41 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/CleanService.java @@ -11,6 +11,7 @@ import java.io.PrintWriter; import java.io.Writer; import java.util.Date; import java.util.List; +import java.util.Map; /** * Created by davep on 2016-08-29. @@ -31,6 +32,8 @@ public interface CleanService { JSONObject getCleanLogTransactions(int detailId, JSONObject manager); + Map getDayAndChannelOfAnalysisMap(int detailId, String channel,JSONObject manager); + JSONObject getCleanLogTransactions(int client_id, String detailId); void settlementCsv(Date dt, HttpServletResponse resp) throws IOException; @@ -60,6 +63,8 @@ public interface CleanService { JSONObject listClearingTransactions(int client_id, String clearingDetailId, JSONObject partner); + Map channelAndDayOfAnalysis(int client_id, String clearingDetailId, String channel,JSONObject partner); + void exportListClearingTransactions(int client_id, String clearingDetailId, JSONObject partner, HttpServletResponse resp); List getSettlementMonthReport(int year, int monthOfYear); diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java index 8237ba8bf..a7e0060fe 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/CleanServiceImpl.java @@ -83,14 +83,9 @@ import java.math.RoundingMode; import java.net.URISyntaxException; import java.text.DecimalFormat; import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Currency; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.List; -import java.util.Locale; +import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -261,6 +256,19 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider return cleanLog; } + @Override + public Map getDayAndChannelOfAnalysisMap(int detailId,String channel,JSONObject manager) { + JSONObject cleanLog = clearingDetailMapper.findByDetailId(detailId); + if (cleanLog == null) { + throw new NotFoundException(); + } + JSONObject client = clientManager.getClientInfo(cleanLog.getIntValue("client_id")); + Assert.notNull(client, "Client ID invalid"); + checkOrgPermission(manager, client); + + return getDayAnalysisMap(String.valueOf(detailId),channel,client); + } + @Override public JSONObject getCleanLogTransactions(int clientId, String clearingDetailId) { return settlementSupport.listSettlementTransactionsForClient(clientId, clearingDetailId); @@ -642,7 +650,6 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider TimeZoneUtils.switchTimeZone(p, timezone_client, "transaction_time"); }); } - clearClient.put("report", transactions); List channels = clearingDetailAnalysisMapper.listReportChannels(clearClient.getString("clear_detail_id")); JSONObject channelsObj = new JSONObject(); @@ -654,6 +661,66 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider return clearClient; } + @Override + public Map channelAndDayOfAnalysis(int client_id, String clearingDetailId,String channel,JSONObject partner) { + JSONObject client = clientManager.getClientInfo(client_id); + Assert.notNull(client, "Client not exists"); + int parent_client_id = client.getIntValue("parent_client_id"); + + if (client_id != partner.getIntValue("client_id") && parent_client_id != partner.getIntValue("client_id")) { + throw new ForbiddenException("No Permission"); + } + return getDayAnalysisMap(clearingDetailId,channel,client); + } + + private Map getDayAnalysisMap(String clearingDetailId,String channel,JSONObject client){ + List transactions = transactionMapper.listTransactionsOfClearingOrder(Integer.parseInt(clearingDetailId), + new PageBounds(Order.formString("order_id.asc"))); + String timezone_client = client.getString("timezone"); + if(!channel.equals("null")){ + transactions = transactions.stream().filter(t->t.getString("channel").equals(channel)).collect(Collectors.toList()); + } + List dateKeysList = new ArrayList<>(); + dateKeysList.add("transaction_time"); + if (timezone_client != null) { + transactions.parallelStream().forEach(p -> { + TimeZoneUtils.switchTimeZone(p, timezone_client, "transaction_time"); + }); + TimeZoneUtils.switchTimeZoneToString(transactions,timezone_client,TimeZoneUtils.PATTERN_DATE,dateKeysList); + } + + Map> dayTransactionsMap = transactions.stream().collect(Collectors.groupingBy(x -> x.getString("transaction_time").substring(0,10))); + Map dayAnalysisMap = new TreeMap<>(); + for (Map.Entry> entry : dayTransactionsMap.entrySet()){ + JSONObject analysis = new JSONObject(); + List transactionsOfDay = entry.getValue(); + + BigDecimal total_credit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Credit")).filter(t->t.containsKey("clearing_amount")).map(t-> t.getBigDecimal("clearing_amount")).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal total_debit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Debit")).filter(t->t.containsKey("clearing_amount")).map(t-> t.getBigDecimal("clearing_amount")).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal total_charge_credit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Credit")).filter(t->t.containsKey("total_surcharge")).map(t-> t.getBigDecimal("total_surcharge")).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal total_charge_debit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Debit")).filter(t->t.containsKey("total_surcharge")).map(t-> t.getBigDecimal("total_surcharge")).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal net_amount_credit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Credit")).filter(t->t.containsKey("settle_amount")).map(t-> t.getBigDecimal("settle_amount")).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal net_amount_debit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Debit")).filter(t->t.containsKey("settle_amount")).map(t-> t.getBigDecimal("settle_amount")).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal tax_amount_credit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Credit")).filter(t->t.containsKey("tax_amount")).map(t-> t.getBigDecimal("tax_amount")).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal tax_amount_debit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Debit")).filter(t->t.containsKey("tax_amount")).map(t-> t.getBigDecimal("tax_amount")).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal wechat_charge_credit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Credit")).filter(t->t.containsKey("wechat_charge")).map(t-> t.getBigDecimal("wechat_charge")).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal wechat_charge_debit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Debit")).filter(t->t.containsKey("wechat_charge")).map(t-> t.getBigDecimal("wechat_charge")).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal royalpay_charge_credit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Credit")).filter(t->t.containsKey("royal_surcharge")).map(t-> t.getBigDecimal("royal_surcharge")).reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal royalpay_charge_debit = transactionsOfDay.stream().filter(t->t.getString("transaction_type").equals("Debit")).filter(t->t.containsKey("royal_surcharge")).map(t-> t.getBigDecimal("royal_surcharge")).reduce(BigDecimal.ZERO, BigDecimal::add); + + BigDecimal tax_amount = tax_amount_credit.subtract(tax_amount_debit); + analysis.put("total_credit",total_credit.setScale(2,BigDecimal.ROUND_HALF_UP)); + analysis.put("total_debit",total_debit.setScale(2,BigDecimal.ROUND_HALF_UP)); + analysis.put("net_amount",net_amount_credit.subtract(net_amount_debit).setScale(2,BigDecimal.ROUND_HALF_UP)); + analysis.put("tax_amount",tax_amount.setScale(2,BigDecimal.ROUND_HALF_UP)); + analysis.put("total_charge",total_charge_credit.subtract(total_charge_debit).add(tax_amount).setScale(2,BigDecimal.ROUND_HALF_UP)); + analysis.put("gross_amount",total_credit.subtract(total_debit).setScale(2,BigDecimal.ROUND_HALF_UP)); + analysis.put("wechat_charge",wechat_charge_credit.subtract(wechat_charge_debit).setScale(2,BigDecimal.ROUND_HALF_UP)); + analysis.put("royalpay_charge",royalpay_charge_credit.subtract(royalpay_charge_debit).setScale(2,BigDecimal.ROUND_HALF_UP)); + dayAnalysisMap.put(entry.getKey(),analysis); + } + return dayAnalysisMap; + } @Override public void exportListClearingTransactions(int client_id, String clearingDetailId, JSONObject partner, HttpServletResponse resp) { OutputStream ous = null; @@ -815,6 +882,17 @@ public class CleanServiceImpl implements CleanService, ManagerTodoNoticeProvider PageList logs = clearingDetailMapper.listReportsOfSettlementLogs(params, new PageBounds(query.getPage(), query.getLimit(), Order.formString("report_date.desc"))); JSONObject result = PageListUtils.buildPageListResult(logs); + if (query.getPage()==1){ + if (!logs.isEmpty() && logs.size()>0){ + JSONObject sendMailLog = logSettleMailMapper.findByDate(logs.get(0).getDate("clearing_time")); + if (sendMailLog == null) { + result.put("padding",true); + } + if (sendMailLog!=null && sendMailLog.getIntValue("mail_status") != 1) { + result.put("padding",true); + } + } + } return result; } diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/CleanLogClientController.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/CleanLogClientController.java index 712241f7b..2c59a8b13 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/CleanLogClientController.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/CleanLogClientController.java @@ -13,6 +13,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.text.ParseException; import java.util.List; +import java.util.Map; /** * Created by davep on 2016-08-29. @@ -38,6 +39,12 @@ public class CleanLogClientController { return cleanService.listClearingTransactions(client_id, clearingDetailId, partner); } + @RequestMapping("/{client_id}/settlement_logs/{clearingDetailId}/analysis/{channel}") + public Map channelAndDayOfAnalysis(@PathVariable int client_id, @PathVariable String clearingDetailId, + @PathVariable String channel, @ModelAttribute(CommonConsts.PARTNER_STATUS) JSONObject partner) { + return cleanService.channelAndDayOfAnalysis(client_id, clearingDetailId,channel,partner); + } + @PartnerMapping("/{client_id}/settlement_logs/{clearingDetailId}/export") public void exportListClearingTransactions(@PathVariable int client_id, @PathVariable String clearingDetailId, @ModelAttribute(CommonConsts.PARTNER_STATUS) JSONObject partner, HttpServletResponse resp) { diff --git a/src/main/ui/static/analysis/templates/settlement_transactions.html b/src/main/ui/static/analysis/templates/settlement_transactions.html index 277fcf8e3..58ebbf6c4 100644 --- a/src/main/ui/static/analysis/templates/settlement_transactions.html +++ b/src/main/ui/static/analysis/templates/settlement_transactions.html @@ -14,87 +14,39 @@ -
-
Analysis
-
-
-
- Rate - -
-
- Total Credit - -
-
- Total Debit - -
-
- Gross Amount - -
- -
-
-
- Total Charge - -
-
- Channel Charge - -
-
- RoyalPay Charge - -
-
- Net Amount - -
-
-
-
- Tax Amount - -
-
-
-
-
+ +
+ + +
+
+
+ Rate + + +
+
+ Total Credit + + +
+
+ Total Debit + + +
+
+ Gross Amount + + +
+ +
+
+
+ Total Charge + + +
+
+ Channel Charge + + +
+
+ RoyalPay Charge + + + +
+
+ Net Amount + + +
+
+
+
+ Tax Amount + +
+
+
+
+ + +
+
+
+ Total Credit + +
+
+ Total Debit + +
+
+ Gross Amount + +
+
+
+
+ Total Charge + +
+
+ Channel Charge + +
+
+ RoyalPay Charge + +
+
+ Net Amount + +
+
+ Tax Amount + +
+
+
+
+
Credits
@@ -162,7 +252,7 @@ - + {{tr.order_id}} @@ -200,7 +290,7 @@ - + {{tr.order_id}} diff --git a/src/main/ui/static/commons/services/clearingDetailService.js b/src/main/ui/static/commons/services/clearingDetailService.js index af223dfd6..da8d7555b 100644 --- a/src/main/ui/static/commons/services/clearingDetailService.js +++ b/src/main/ui/static/commons/services/clearingDetailService.js @@ -4,7 +4,7 @@ define(['../app','decimal'], function (app,Decimal) { 'use strict'; app.factory('clearingDetailService', ['$uibModal', function ($uibModal) { - function openDetail(url, is_partner) { + function openDetail(url, is_partner,client_id,detailId) { $uibModal.open({ templateUrl: '/static/payment/tradelog/templates/partner_settlement_dialog.html', controller: 'clearingDetailCtrl', @@ -12,7 +12,9 @@ define(['../app','decimal'], function (app,Decimal) { detail: ['$http', function ($http) { return $http.get(url); }], - is_partner: is_partner + is_partner: is_partner, + client_id:client_id, + detailId:detailId }, size: 'lg' }) @@ -20,16 +22,26 @@ define(['../app','decimal'], function (app,Decimal) { return { clientClearingDetail: function (client_id, detailId, is_partner) { - openDetail('/client/clean_logs/' + client_id + '/settlement_logs/' + detailId, is_partner); + openDetail('/client/clean_logs/' + client_id + '/settlement_logs/' + detailId, is_partner,client_id,detailId); } } }]); - app.controller('clearingDetailCtrl', ['$scope', 'detail', 'is_partner', function ($scope, detail, is_partner) { - $scope.ctrl = {channel: null}; + app.controller('clearingDetailCtrl', ['$scope', 'detail', 'is_partner','client_id','detailId','$http', function ($scope, detail, is_partner,client_id,detailId,$http) { + $scope.ctrl = {channel: null,day:null}; $scope.report = detail.data; $scope.report.total_charge = Decimal.add($scope.report.total_charge,$scope.report.tax_amount).toFixed(2); + angular.forEach($scope.report.channels,function (e) { + e.total_charge = Decimal.add(e.total_charge,e.tax_amount).toFixed(2); + }); $scope.is_partner = is_partner; + $scope.channelAndDayOfAnalysis = function () { + $http.get('/client/clean_logs/' + client_id + '/settlement_logs/' + detailId+'/analysis/'+$scope.ctrl.channel).then(function (resp) { + $scope.channelAndDayMap = resp.data; + $scope.index = 0; + }) + } + $scope.channelAndDayOfAnalysis(); }]); app.filter('channel_image', function () { return function (channel) { diff --git a/src/main/ui/static/payment/partner/partner-manage.js b/src/main/ui/static/payment/partner/partner-manage.js index a010088b4..e22cdbef6 100644 --- a/src/main/ui/static/payment/partner/partner-manage.js +++ b/src/main/ui/static/payment/partner/partner-manage.js @@ -2508,27 +2508,41 @@ define(['angular', 'decimal', 'static/commons/commons', 'uiBootstrap', 'uiRouter params.limit = 10; $http.get('/sys/partners/' + clientMoniker + '/lists_settlements', {params: params}).then(function (resp) { $scope.settlementLogs = resp.data.data; + $scope.padding = resp.data.padding; $scope.pagination = resp.data.pagination; }); }; $scope.getClearingTransactions = function (client_id, detail_id) { $uibModal.open({ templateUrl: '/static/analysis/templates/settlement_transactions.html', - controller: 'managerClearingDetailCtrl', + controller: 'managerSettlementDetailCtrl', resolve: { detail: ['$http', '$stateParams', function ($http) { return $http.get('/analysis/partner_card/' + client_id + '/settlement_logs/' + detail_id); - }] + }], + detail_id:detail_id }, size: 'lg' }); }; $scope.chooseLast7Days(); }]); - app.controller('managerClearingDetailCtrl', ['$scope', 'detail', function ($scope, detail) { + app.controller('managerSettlementDetailCtrl', ['$scope', 'detail','detail_id','$http', function ($scope, detail,detail_id,$http) { $scope.ctrl = {channel: null}; + $scope.show = true; $scope.report = detail.data; $scope.report.total_charge = Decimal.add($scope.report.total_charge,$scope.report.tax_amount).toFixed(2); + angular.forEach($scope.report.channels,function (e) { + e.total_charge = Decimal.add(e.tax_amount,e.total_charge).toFixed(2); + }); + + $scope.channelAndDayOfAnalysis = function () { + $http.get('/analysis/partner_card/settlement_logs/' + detail_id+'/analysis/'+$scope.ctrl.channel).then(function (resp) { + $scope.channelAndDayMap = resp.data; + $scope.index = 0; + }) + }; + $scope.channelAndDayOfAnalysis(1); }]); app.controller('productCtrl', ['$scope', '$http', '$uibModal', 'commonDialog', '$state', 'Upload', 'industryMap', function ($scope, $http, $uibModal, commonDialog, $state, Upload, industryMap) { diff --git a/src/main/ui/static/payment/partner/templates/partner_settlement.html b/src/main/ui/static/payment/partner/templates/partner_settlement.html index fbddc060e..dc3fe5cb8 100644 --- a/src/main/ui/static/payment/partner/templates/partner_settlement.html +++ b/src/main/ui/static/payment/partner/templates/partner_settlement.html @@ -76,7 +76,12 @@ - + + {{log.clearing_time|limitTo:10}} +   + + + diff --git a/src/main/ui/static/payment/tradelog/partner-settlement-log.js b/src/main/ui/static/payment/tradelog/partner-settlement-log.js index 226058e06..d7fa5454e 100644 --- a/src/main/ui/static/payment/tradelog/partner-settlement-log.js +++ b/src/main/ui/static/payment/tradelog/partner-settlement-log.js @@ -86,6 +86,7 @@ define(['angular', 'uiBootstrap', 'uiRouter'], function (angular) { $http.get('/client/trans_flow/settlement/log', {params: params}).then(function (resp) { $scope.settlementLogs = resp.data.data; $scope.pagination = resp.data.pagination; + $scope.padding = resp.data.padding; $scope.analysis = resp.data.analysis; }); }; diff --git a/src/main/ui/static/payment/tradelog/templates/partner_settlement_dialog.html b/src/main/ui/static/payment/tradelog/templates/partner_settlement_dialog.html index b82ceaebc..65513aaa8 100644 --- a/src/main/ui/static/payment/tradelog/templates/partner_settlement_dialog.html +++ b/src/main/ui/static/payment/tradelog/templates/partner_settlement_dialog.html @@ -6,122 +6,172 @@
-
-
Analysis
-
-
- - - - -
- Total Credit - -
-
- Total Debit - -
-
- Gross Amount - -
+
+ + +
+
+ + + + +
+ Total Credit + + +
+
+ Total Debit + + +
+
+ Gross Amount + + +
-
-
-
- Total Charge - -
-
- Channel Charge - -
-
- RoyalPay Charge - -
-
- Net Amount - -
-
- Tax Amount - -
-
-
-
-
-
Analysis
-
-
-
- Total Credit - -
-
- Total Debit - -
-
- Gross Amount - +
+
+
+ Total Charge + + +
+
+ Channel Charge + + +
+
+ RoyalPay Charge + + +
+
+ Net Amount + + +
+
+ Tax Amount + +
+
+ + + +
+
+
+ Total Credit + +
+
+ Total Debit + +
+
+ Gross Amount + +
+
+
+
+ Total Charge + +
+
+ Channel Charge + +
+
+ RoyalPay Charge + +
+
+ Net Amount + +
+
+ Tax Amount + +
+
-
-
+ +
Credits
@@ -144,7 +194,7 @@ - + {{tr.order_id}} @@ -180,7 +230,7 @@ - + diff --git a/src/main/ui/static/payment/tradelog/templates/partner_settlement_logs.html b/src/main/ui/static/payment/tradelog/templates/partner_settlement_logs.html index 230620ae7..aeeaf8dbf 100644 --- a/src/main/ui/static/payment/tradelog/templates/partner_settlement_logs.html +++ b/src/main/ui/static/payment/tradelog/templates/partner_settlement_logs.html @@ -120,7 +120,10 @@ - + + {{log.clearing_time|limitTo:10}} +   +