You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

549 lines
25 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], function (angular, Decimal) {
'use strict';
var colors = ['#00c0ef', '#00a65a', '#ff851b', '#f39c12', '#d81b60', '#605ca8', '#dd4b39', '#008080', '#8B008B', '#D2691E', '#708090'];
var app = angular.module('clearingLogs', ['ui.bootstrap', 'ui.router', 'ngEcharts']);
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('clearingLogs', {
url: '/analysis/clearing_logs',
templateUrl: '/static/analysis/templates/clearing_logs.html',
controller: 'clearingLogsCtrl'
}).state('clearingLogs.rate_warnings', {
url: '/rate_warnings',
template: '<div></div>',
onEnter: ['$uibModal', function ($uibModal) {
$uibModal.open({
templateUrl: '/static/analysis/templates/settle_warnings.html',
controller: 'settleWarningsCtrl',
size: 'lg'
})
}],
controller: ['$state', function ($state) {
$state.go('^')
}]
}).state('clearingLogs.date_setting', {
url: '/date_setting',
template: '<div></div>',
onEnter: ['$uibModal', function ($uibModal) {
$uibModal.open({
templateUrl: '/static/analysis/templates/settle_date_config.html',
controller: 'settleDateConfigCtrl',
size: 'lg'
})
}],
controller: ['$state', function ($state) {
$state.go('^')
}]
}).state('clearingLogs.settlementDetail', {
url: '/settles/{date}',
templateUrl: '/static/analysis/templates/settlement_detail.html',
controller: 'settlementDetailCtrl',
resolve: {
detail: ['$http', '$stateParams', function ($http, $stateParams) {
return $http.get('/sys/settlement/reports/' + $stateParams.date);
}]
}
}).state('clearingLogs.settlementDetail.transactions', {
url: '/transactions/{detailId}',
templateUrl: '/static/analysis/templates/settlement_transactions.html',
controller: 'settlementTransactionsCtrl',
resolve: {
detail: ['$http', '$stateParams', function ($http, $stateParams) {
return $http.get('/sys/settlement/details/' + $stateParams.detailId);
}]
}
})
}]);
app.controller('clearingLogsCtrl', ['$scope', '$http', '$filter', '$timeout', '$uibModal', 'commonDialog', 'chartParser',
function ($scope, $http, $filter, $timeout, $uibModal, commonDialog, chartParser) {
$scope.loadMonthLog = function (month) {
var monthStr = $filter('date')(month, 'yyyyMM');
$http.get('/sys/settlement/month/' + monthStr + '/settled_dates').then(function (resp) {
$scope.settledDates = resp.data;
});
};
$scope.params = {};
$scope.pagination = {};
$scope.today = new Date();
$scope.chooseToday = function () {
$scope.params.begin = $scope.params.end = new Date();
$scope.loadClearingLogs(1);
};
$scope.chooseYesterday = function () {
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
$scope.params.begin = $scope.params.end = yesterday;
$scope.loadClearingLogs(1);
};
$scope.chooseLast7Days = function () {
$scope.params.end = new Date();
var day = new Date();
day.setDate(day.getDate() - 7);
$scope.params.begin = day;
$scope.loadClearingLogs(1);
};
$scope.thisMonth = function () {
$scope.params.end = new Date();
var monthBegin = new Date();
monthBegin.setDate(1);
$scope.params.begin = monthBegin;
$scope.loadClearingLogs(1);
};
$scope.lastMonth = function () {
var monthFinish = new Date();
monthFinish.setDate(0);
$scope.params.end = monthFinish;
var monthBegin = new Date();
monthBegin.setDate(0);
monthBegin.setDate(1);
$scope.params.begin = monthBegin;
$scope.loadClearingLogs(1);
};
$scope.thisYear = function () {
var yearFinish = new Date();
$scope.params.end = yearFinish;
var currentYearFirstDate = new Date(new Date().getFullYear(), 0, 1);
$scope.params.begin = currentYearFirstDate;
$scope.loadClearingLogs(1);
};
if (($scope.currentUser.role & parseInt('1000011', 2)) > 0 && !$scope.currentUser.org_id) {
$scope.showOrg = 'Organization';
$http.get('/sys/orgs', {params: {}}).then(function (resp) {
$scope.orgs = resp.data;
});
}
$scope.chooseOrg = function (org) {
if (org == 'all') {
delete $scope.params.org_id;
$scope.showOrg = 'All'
} else {
$scope.params.org_id = org.org_id;
$scope.showOrg = org.name;
}
$scope.loadClearingLogs();
};
$scope.loadClearingLogs = function (page) {
var params = angular.copy($scope.params);
params.page = page || $scope.pagination.page || 1;
if (params.begin) {
params.begin = $filter('date')(params.begin, 'yyyyMMdd');
}
if (params.end) {
params.end = $filter('date')(params.end, 'yyyyMMdd');
}
$http.get('/sys/clean_logs/clients', {params: params}).then(function (resp) {
$scope.clearing_logs = resp.data.data;
$scope.pagination = resp.data.pagination;
});
analysisLog(params);
};
var analysisLog = function (params) {
$http.get('/sys/clean_logs/analysis', {params: params}).then(function (resp) {
$scope.analysis = resp.data;
})
};
$scope.loadClearingLogs(1);
$scope.loadClearingLogsHistory = function (days) {
var endDate = new Date();
var startDate = new Date();
startDate.setDate(startDate.getDate() - days);
$http.get('/sys/clean_logs/logs', {
params: {
begin: $filter('date')(startDate, 'yyyyMMdd'),
end: $filter('date')(endDate, 'yyyyMMdd')
}
}).then(function (resp) {
handleLogsChart(resp.data);
})
};
$scope.loadClearingLogsHistory(7);
var clearingHistoryConfig = {
chart: {
tooltip: {
trigger: 'axis',
formatter: '{b}:AUD {c}'
},
toolbox: {
show: true,
feature: {
mySeven: {
title: '最近7天',
show: true,
icon: 'path://M3.59-4.07L32.38-4.07L32.38 0.04Q22.25 25.11 17.19 46.34L10.65 46.34Q16.14 26.94 26.19 1.41L3.59 1.41L3.59-4.07Z',
onclick: function () {
$scope.loadClearingLogsHistory(7)
}
},
myThirty: {
title: '最近30天',
show: true,
icon: 'path://M12.52 17.02L16.10 17.02Q20.71 17.02 22.43 15.72Q25.66 13.23 25.66 8.23Q25.66-0.63 17.61-0.63Q10.93-0.63 9.42 6.93L3.73 6.93Q4.50 2.19 7.03-0.91Q10.90-5.51 17.61-5.51Q23.24-5.51 26.89-2.28Q31.22 1.52 31.22 8.02Q31.22 16.78 23.38 19.48Q32.84 23.14 32.84 32.81Q32.84 39.00 29.32 42.97Q25.10 47.79 17.72 47.79Q10.79 47.79 6.68 43.04Q3.66 39.56 3.02 33.44L8.93 33.44Q9.67 42.83 17.72 42.83Q21.45 42.83 23.98 40.72Q27.14 38.01 27.14 32.81Q27.14 21.63 16.10 21.63L12.52 21.63L12.52 17.02ZM54-5.51Q67.99-5.51 67.99 21.14Q67.99 47.79 54 47.79Q40.04 47.79 40.04 21.14Q40.04-5.51 54-5.51M46.97 33.65L59.84 4.30Q57.80-0.55 53.93-0.55Q45.95-0.55 45.95 21.14Q45.95 28.52 46.97 33.65M48.16 37.91Q50.13 42.83 54 42.83Q62.09 42.83 62.09 21.07Q62.09 13.86 61.07 8.66L48.16 37.91Z',
onclick: function () {
$scope.loadClearingLogsHistory(30)
}
}
}
},
yAxis: {
type: 'value',
name: '清算金额AUD',
min: 'auto'
},
color: colors
},
xAxis: {
basic: {
type: 'category',
boundaryGap: false
},
key: 'clear_time'
},
series: [
{
basic: {type: 'line', label: {normal: {show: true}}, showAllSymbols: true, showSymbol: true},
column: {key: 'total'}
}
]
};
function handleLogsChart(logs) {
$scope.clearingHistory = chartParser.parse(clearingHistoryConfig, logs.reverse());
}
}]);
app.controller('settleWarningsCtrl', ['$scope', '$http', '$filter', 'commonDialog', function ($scope, $http, $filter, commonDialog) {
$scope.loadWarnings = function () {
$http.get('/manage/clearing/rate_warnings').then(function (resp) {
$scope.warning = resp.data;
})
};
$scope.loadWarnings();
$scope.generateRate = function (client) {
commonDialog.confirm({title: 'Confirm Required', content: '根据上季度总交易额自动计算下周期费率,确定执行?'}).then(function () {
$http.put('/manage/clearing/clients/' + client.client_moniker + '/auto_rate').then(function (resp) {
var content = 'New Rate value=' + resp.data.rate_value + '; expiry_time=' + $filter('date')(resp.data.expiry_time, 'dd/MMM/yyyy');
commonDialog.alert({
type: 'success',
title: 'New Rate Generated',
content: content
}).then(function () {
$scope.loadWarnings();
});
}, function (resp) {
commonDialog.alert({type: 'error', title: 'Error', content: resp.data.message});
})
})
}
}]);
app.controller('settlementDetailCtrl', ['$scope', '$stateParams', '$http', '$uibModal', '$filter', '$state', 'detail', 'commonDialog',
function ($scope, $stateParams, $http, $uibModal, $filter, $state, detail, commonDialog) {
$scope.detail = detail.data;
$scope.hasSentMail = false;
$scope.sendNotice = false;
$scope.noticeResend = false;
$scope.analysisFilter = {};
$scope.currentAnalysis = $scope.detail;
$scope.pageCtrl = {visible:{}};
function getAnalysisTemplate() {
return [
{settleDays: 1, clients: 0, settleAmount: 0, settles: []},
{settleDays: 2, clients: 0, settleAmount: 0, settles: []},
{settleDays: 3, clients: 0, settleAmount: 0, settles: []}
];
}
$scope.settleAnalysis = getAnalysisTemplate();
$scope.batchAnalysis = {
'All': $scope.settleAnalysis
};
angular.forEach($scope.detail.logs, function (batch) {
$scope.batchAnalysis[batch.clearing_id + ''] = getAnalysisTemplate();
});
$scope.endIndexMap = {};
$scope.initEndIndex = 20;
$scope.more = function(key) {
var endIndex = $scope.endIndexMap[key] + $scope.initEndIndex;
$scope.endIndexMap[key] = endIndex;
if (endIndex > $scope.clientsMap[key].clients) {
$scope.endIndexMap[key] = $scope.clientsMap[key].clients;
}
};
$scope.packup = function(key) {
$scope.endIndexMap[key] = $scope.initEndIndex;
var length = $scope.clientsMap[key].clients;
if (length <= $scope.initEndIndex)
$scope.endIndexMap[key] = length;
};
$scope.displayAll = function (key) {
var length = $scope.clientsMap[key].clients;
$scope.endIndexMap[key] = length;
};
angular.forEach($scope.detail.details, function (settleItem) {
var settleDays = settleItem.clear_days;
attachAnalysis($scope.settleAnalysis[Math.min(settleDays - 1, 2)]);
attachAnalysis($scope.batchAnalysis[settleItem.clearing_id + ''][Math.min(settleDays - 1, 2)]);
function attachAnalysis(analysisItem) {
analysisItem.settles.push(settleItem);
analysisItem.clients++;
analysisItem.settleAmount = Decimal.add(analysisItem.settleAmount, settleItem.clearing_amount).toFixed(2, Decimal.ROUND_FLOOR);
}
});
$scope.clientsMap = $scope.settleAnalysis;
for (var key in $scope.clientsMap) {
$scope.endIndexMap[key] = $scope.initEndIndex;
var length = $scope.clientsMap[key].clients;
if (length <= $scope.initEndIndex)
$scope.endIndexMap[key] = length;
}
var nowStr = $filter('date')(new Date(), "yyyy-MM-dd");
$scope.datePattern = $stateParams.date;
if ($scope.datePattern == nowStr) {
$scope.sendNotice = true;
}
$scope.displaySendCheckCode = function () {
$uibModal.open({
templateUrl: '/static/analysis/templates/settlement_send_check_code.html',
controller: 'settlementSendCheckCodeCtrl',
size: 'sm'
});
};
$scope.switchSettleBatch = function (batch) {
if (batch == null) {
$scope.currentAnalysis = $scope.detail;
$scope.analysisFilter.clearing_id = null;
} else {
$scope.analysisFilter.clearing_id = batch.clearing_id;
$scope.currentAnalysis = batch;
}
};
$scope.getCurrentLog = function () {
return $scope.detail.logs.filter(function (log) {
return log.clearing_id === $scope.analysisFilter.clearing_id
})[0];
};
$http.get('/sys/settlement/reports/' + $stateParams.date + '/send_status/').then(function (resp) {
if (resp.data != null && resp.data.mail_status == 1) {
$scope.hasSentMail = true;
}
});
$scope.$on("sendMailSuccess",
function (event, msg) {
$scope.hasSentMail = true;
});
$scope.confirmSendSettlementMail = function () {
commonDialog.confirm({
title: 'Confirm to send notice',
content: '请确认账户已扣款后再发送清算通知',
choises: [{label: 'Send', className: 'btn-success', key: '1'},
{label: 'Cancel', className: 'btn-danger', key: '2', dismiss: true}]
}).then(function () {
$scope.noticeResend = true;
$http.post('/sys/settlement/settlement_notice').then(function () {
commonDialog.alert({title: 'Success', content: '发送成功', type: 'success'});
$scope.noticeResend = false;
}, function (resp) {
commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'});
$scope.noticeResend = false;
});
})
};
$scope.lockSettleLog = function (clearingId) {
commonDialog.confirm({title: '确认操作', content: '当前操作将标记本批次清算已发送,无法撤回,确认操作?'}).then(function () {
$http.put('/sys/settlement/reports/' + $stateParams.date + '/clearings/' + clearingId + '/lock').then(function () {
$scope.detail.logs.filter(function (log) {
return log.clearing_id === clearingId
}).forEach(function (log) {
log.editable = 0
});
commonDialog.alert({title: 'Success', content: 'Operation success', type: 'success'});
}, function (resp) {
commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'});
})
})
};
$scope.distributeBankDialog = function () {
var log = $scope.getCurrentLog();
$uibModal.open({
templateUrl: '/static/analysis/templates/settlement_bank_distribution_dialog.html',
controller: 'bankDistributionDialogCtrl',
resolve: {
clearingBatch: function () {
return log;
},
banksConfig: ['$http', function ($http) {
return $http.get('/sys/settlement/available_banks')
}],
settleDate: function () {
return $stateParams.date;
}
}
}).result.then(function () {
$state.reload();
})
};
$scope.rollbackSettlement = function () {
var log = $scope.getCurrentLog();
commonDialog.confirm({
title: '确认操作',
content: '回滚当前清算id=' + log.clearing_id + ',确认?'
}).then(function () {
$http.delete('/sys/settlement/reports/' + $stateParams.date + '/clearings/' + log.clearing_id).then(function () {
$state.reload();
}, function (resp) {
commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'});
})
})
}
}]);
app.controller('settlementTransactionsCtrl', ['$scope', '$stateParams', 'detail', function ($scope, $stateParams, detail) {
$scope.ctrl = {channel: null};
$scope.report = detail.data;
}]);
app.controller('bankDistributionDialogCtrl', ['$scope', '$http', 'clearingBatch', 'banksConfig', 'settleDate',
function ($scope, $http, clearingBatch, banksConfig, settleDate) {
$scope.banksConfig = banksConfig.data;
$scope.bankData = [];
angular.forEach($scope.banksConfig.banks, function (bank) {
if (bank !== $scope.banksConfig.remains_to) {
$scope.bankData.push({bank: bank, amount: 0});
}
});
$scope.remainingAmount = function () {
var total = clearingBatch.net_amount;
angular.forEach($scope.bankData, function (config) {
total = Decimal.sub(total, config.amount);
});
return Decimal.max(0, total).toFixed(2, Decimal.ROUND_DOWN);
};
$scope.submitDistribution = function () {
$scope.errmsg = null;
var data = {};
angular.forEach($scope.bankData, function (config) {
data[config.bank] = config.amount;
});
$http.put('/sys/settlement/reports/' + settleDate + '/clearings/' + clearingBatch.clearing_id + '/bank_distribution', data).then(function () {
$scope.$close();
}, function (resp) {
$scope.errmsg = resp.data.message;
})
}
}]);
app.controller('settleDateConfigCtrl', ['$scope', '$http', '$filter', 'commonDialog', function ($scope, $http, $filter, commonDialog) {
$scope.loadMonthPlan = function (mon) {
$http.get('/sysconfig/clear_days/months/' + $filter('date')(mon, 'yyyyMM')).then(function (resp) {
$scope.activeDates = resp.data;
});
$scope.currentMonth = mon;
};
$scope.triggerDate = function (date) {
if (date.getFullYear() != $scope.currentMonth.getFullYear() || date.getMonth() != $scope.currentMonth.getMonth()) {
return;
}
var str = $filter('date')(date, 'yyyy/MM/dd');
var idx = $scope.activeDates.indexOf(str);
if (idx < 0) {
$scope.activeDates.push(str);
} else {
$scope.activeDates.splice(idx, 1);
}
};
$scope.isDateOn = function (date) {
if ($scope.activeDates != null) {
return $scope.activeDates.indexOf($filter('date')(date, 'yyyy/MM/dd')) >= 0
} else {
return false;
}
};
$scope.submitMonthPlan = function () {
$http.put('/sysconfig/clear_days/months/' + $filter('date')($scope.currentMonth, 'yyyyMM'), $scope.activeDates).then(function () {
$scope.loadMonthPlan($scope.currentMonth);
commonDialog.alert({title: 'Success', content: 'Modified plan successful', type: 'success'})
}, function (resp) {
commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'})
})
};
}]);
app.controller('settlementSendCheckCodeCtrl', ['$scope', '$http', '$rootScope', '$stateParams', function ($scope, $http, $rootScope, $stateParams) {
$scope.sendCheckCodeButton = false;
$scope.sendMailButton = false;
$scope.check_code = '';
$scope.sendCheckCode = function () {
$scope.error_msg = '';
$http.get('/sys/settlement/reports/send_checkcode').then(function (resp) {
});
$scope.sendCheckCodeButton = true;
};
$scope.sendSettlementMail = function () {
$scope.error_msg = '正在发送,请稍后。';
if ($scope.check_code == '' || $scope.check_code == null) {
$scope.error_msg = '请输入验证码';
return;
}
$scope.sendMailButton = true;
$http.get('/sys/settlement/reports/' + $stateParams.date + '/send_settlement_xlsx/' + $scope.check_code).then(function (resp) {
$scope.error_msg = resp.data.msg;
$scope.sendMailButton = false;
if (resp.data.result == 0) {
$scope.sendMailButton = true;
$rootScope.$broadcast("sendMailSuccess", '123');
}
});
};
}]);
app.filter('channel_image', function () {
return function (channel) {
switch (channel) {
case 'Alipay':
return '/static/images/alipay_sign_lg.png';
case 'AlipayOnline':
return '/static/images/alipay_online.png';
case 'System':
return '/static/images/royalpay_sign.png';
case 'Bestpay':
return '/static/images/bestpay_sign_lg.png';
case 'Wechat':
return '/static/images/wechatpay_sign_lg.png';
case 'jd':
return '/static/images/jd_sign_lg.png';
case 'hf':
return '/static/images/hf_sign_lg.png';
}
}
});
return app;
});