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.

318 lines
13 KiB

/**
* balance list on partner client
* Created by yishuqian on 9/9/16.
*/
define(['angular', 'uiBootstrap', 'uiRouter'], function (angular) {
'use strict';
var app = angular.module('balanceReport', ['ui.bootstrap', 'ui.router']);
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('transflow', {
url: '/transflow',
templateUrl: '/static/payment/tradelog/templates/balance_report.html',
controller: 'balanceListCtrl'
})
}]);
app.controller('balanceListCtrl', ['$scope', '$http', '$filter', '$timeout', 'refunder', 'orderService','$sce', function ($scope, $http, $filter, $timeout, refunder,orderService,$sce) {
$scope.params = {textType: 'all'};
$scope.pagination = {};
$scope.subClientPagination = {};
$scope.params.clearing_status = -1;
$scope.params.channel = 'ALL'
$scope.dev_params = {client_type:'sunmi',limit:100};
$scope.device_isAll = true;
$scope.order_device_isAll = true;
$scope.params.trans_type = 0;
$scope.isAll = true;
$scope.more20ChoseSubClient = false;
$scope.clients = [$scope.currentUser.client];
$scope.params.client_ids = [$scope.currentUser.client.client_id];
$scope.showLevel3Clients = false;
$scope.subClientTable1 = [$scope.currentUser.client];
$scope.subClientTable2 = [];
$scope.choseSubClientNow = 'More';
$scope.subSearchText = '';
$scope.today = new Date();
$scope.chooseToday = function () {
$scope.params.datefrom = $scope.params.dateto = new Date();
$scope.loadTradeLogs(1);
};
$scope.chooseYesterday = function () {
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
$scope.params.datefrom = $scope.params.dateto = yesterday;
$scope.loadTradeLogs(1);
};
$scope.chooseLast7Days = function () {
$scope.params.dateto = new Date();
var day = new Date();
day.setDate(day.getDate() - 7);
$scope.params.datefrom = day;
$scope.loadTradeLogs(1);
};
$scope.thisMonth = function () {
$scope.params.dateto = new Date();
var monthBegin = new Date();
monthBegin.setDate(1);
$scope.params.datefrom = monthBegin;
$scope.loadTradeLogs(1);
};
$scope.lastMonth = function () {
var monthFinish = new Date();
monthFinish.setDate(0);
$scope.params.dateto = monthFinish;
var monthBegin = new Date();
monthBegin.setDate(0);
monthBegin.setDate(1);
$scope.params.datefrom = monthBegin;
$scope.loadTradeLogs(1);
};
$scope.listDevices = function () {
var params = angular.copy($scope.dev_params)
if ($scope.isAll) {
delete params.client_ids;
}
$http.get('/client/partner_info/devices', {params: params}).then(function (resp) {
$scope.devices = resp.data.data;
})
};
$scope.listDevicesIds = function () {
var params = angular.copy($scope.params)
if ($scope.isAll) {
delete params.client_ids;
}
$http.get('/client/partner_info/device_ids',{params: params}).then(function (resp) {
$scope.deviceIds = resp.data.data;
})
};
$scope.chooseDevices = function (dev_id) {
if(dev_id == 'all'){
$scope.chooseDevice_id = '';
$scope.params.dev_id = null;
$scope.device_isAll = true;
$scope.loadTradeLogs(1);
}else {
$scope.chooseDevice_id = dev_id;
$scope.params.dev_id = dev_id;
$scope.device_isAll = false;
$scope.order_device_isAll = true;
$scope.loadTradeLogs(1);
}
};
$scope.chooseDeviceIds = function (dev_id) {
if(dev_id == 'all'){
$scope.choose_order_device_id = '';
$scope.params.dev_id = null;
$scope.order_device_isAll = true;
$scope.loadTradeLogs(1);
}else {
$scope.choose_order_device_id = dev_id;
$scope.params.dev_id = dev_id;
$scope.device_isAll = true;
$scope.order_device_isAll = false;
$scope.loadTradeLogs(1);
}
};
$scope.listDevices();
$scope.listDevicesIds();
$scope.searchSubClients = function (subSearchText,page) {
$scope.subClientTable1 = [$scope.currentUser.client];
$scope.subClientTable2 = [];
var params = {};
params.page = page || $scope.subClientPagination.page || 1;
if (subSearchText != '') {
$scope.subSearchText = subSearchText;
params.searchText = subSearchText;
}
$http.get('/client/partner_info/sub_partners/page',{params: params}).then(function (resp) {
var clientList = resp.data.data;
$scope.subClientPagination = resp.data.pagination;
clientList.forEach(function (client) {
if ($scope.subClientTable1.length < 11) {
$scope.subClientTable1.push(client);
}else {
$scope.subClientTable2.push(client);
}
$scope.clients.push(client);
});
});
};
$scope.loadTradeLogs = function (page) {
var params = angular.copy($scope.params);
if ($scope.isAll) {
delete params.client_ids;
}
if (params.datefrom) {
params.datefrom = $filter('date')(params.datefrom, 'yyyyMMdd');
}
if (params.dateto) {
params.dateto = $filter('date')(params.dateto, 'yyyyMMdd');
}
params.page = page || $scope.pagination.page || 1;
$http.get('/client/trans_flow', {params: params}).then(function (resp) {
$scope.tradeLogs = resp.data.data;
$scope.htmlToolst();
$scope.pagination = resp.data.pagination;
$scope.analysis = resp.data.analysis;
$scope.analysis.refund_fee = angular.copy(Math.abs($scope.analysis.refund_fee));
});
};
$scope.chooseClient = function (client) {
if (client == 'all') {
$scope.choseSubClientNow = 'More';
$scope.params.client_ids = angular.copy($scope.clientIds);
$scope.isAll = true;
$scope.chooseClientId = '';
$scope.dev_params.client_ids = angular.copy($scope.clientIds);
$scope.showLevel3Clients = false;
$scope.listDevices();
$scope.listDevicesIds();
} else if (client.level3Clients) {
$scope.chooseClientId = client.client_id;
$scope.showLevel3Clients = true;
$scope.level3Clients = client.level3Clients;
$scope.isAll = false;
$scope.level3ClientIds = [];
$scope.level3ClientIds.push(client.client_id);
client.level3Clients.forEach(function (client) {
$scope.level3ClientIds.push(client.client_id);
});
$scope.chooseLevel3Client("all");
return;
} else {
$scope.chooseClientId = client.client_id;
$scope.params.client_ids = [client.client_id];
$scope.isAll = false;
$scope.dev_params.client_ids = [client.client_id];
$scope.showLevel3Clients = false;
$scope.listDevices();
$scope.listDevicesIds();
}
$scope.loadTradeLogs();
};
$scope.chooseLevel3Client = function (client) {
if (client == 'all') {
$scope.params.client_ids = angular.copy($scope.level3ClientIds);
$scope.isLevel3All = true;
$scope.chooseLevel3ClientId = '';
$scope.dev_params.client_ids = angular.copy($scope.level3ClientIds);
$scope.listDevices();
$scope.listDevicesIds();
} else {
$scope.chooseLevel3ClientId = client.client_id;
$scope.params.client_ids = [client.client_id];
$scope.isLevel3All = false;
$scope.dev_params.client_ids = [client.client_id];
$scope.listDevices();
$scope.listDevicesIds();
}
$scope.loadTradeLogs();
};
$scope.export = function (type,page) {
var url='/client/trans_flow/report/pdf';
if (type=='pdf'){
url = '/client/trans_flow/report/pdf';
}
if (type=='excel'){
url='/client/trans_flow/report/excel';
}
if (type=='excel_detail'){
url='/client/trans_flow/report/excel_detail';
}
if (type=='excel_detail_all'){
url='/client/trans_flow/report/excel_detail_all';
}
var connectSymbol = '?';
var params = angular.copy($scope.params);
if (params.clearing_status) {
url += connectSymbol + 'clearing_status=' + params.clearing_status;
connectSymbol = '&';
}
if (params.trans_type) {
url += connectSymbol + 'trans_type=' + params.trans_type;
connectSymbol = '&';
}
if (params.dev_id) {
url += connectSymbol + 'dev_id=' + params.dev_id;
connectSymbol = '&'
}
if (params.client_ids && !$scope.isAll) {
params.client_ids.forEach(function (i) {
url += connectSymbol + 'client_ids=' + i;
connectSymbol = '&';
});
}
if (params.datefrom) {
params.datefrom = $filter('date')(params.datefrom, 'yyyyMMdd');
url += connectSymbol + 'datefrom=' + params.datefrom;
connectSymbol = '&';
}
if (params.dateto) {
params.dateto = $filter('date')(params.dateto, 'yyyyMMdd');
url += connectSymbol + 'dateto=' + params.dateto;
connectSymbol = '&';
}
params.page = page || $scope.pagination.page || 1;
url += connectSymbol + 'page=' + params.page;
return url;
}
if ($scope.currentUser.client.has_children && !$scope.currentUser.client.hide_sub_mch) {
$scope.searchSubClients('',1);
$scope.params.dateto = new Date();
var day = new Date();
day.setDate(day.getDate() - 7);
$scope.params.datefrom = day;
$scope.chooseClient('all');
}else {
$scope.params.dateto = new Date();
var day = new Date();
day.setDate(day.getDate() - 7);
$scope.params.datefrom = day;
$scope.chooseClient('all');
}
$scope.htmlToolst = function(){
for(var i=0;i< $scope.tradeLogs.length;i++){
var tax_amount = $scope.tradeLogs[i].tax_amount;
var total_surcharge= $scope.tradeLogs[i].total_surcharge;
var incremental_surcharge = $scope.tradeLogs[i].incremental_surcharge;
var channel_surcharge = $scope.tradeLogs[i].channel_surcharge;
var royal_surcharge = $scope.tradeLogs[i].royal_surcharge;
var system_surcharge = (total_surcharge-incremental_surcharge).toFixed(2);
var channel = $scope.tradeLogs[i].source;
var tip = '<div style="width: 180px">' +
'<h5>手续费组成</h5>'+'<div style="background-color: #EFEFF5;height: 1px;margin-bottom: 10px;"></div>'+
'<p>system:'+ system_surcharge +'</p>' +
'<p>'+channel+':'+ incremental_surcharge +'</p>';
if(total_surcharge <= (royal_surcharge+incremental_surcharge+channel_surcharge+tax_amount)){
tip = tip +'<p>tax amount:'+ tax_amount +'</p>';
}
tip = tip + '</div>';
$scope.tradeLogs[i].htmlTooltip = $sce.trustAsHtml(tip);
}
};
$scope.checkSubClientChoseShow = function (client) {
$scope.more20ChoseSubClient = !$scope.more20ChoseSubClient;
if (client != '') {
$scope.choseSubClientNow = client.short_name;
}
}
$scope.clickDisplayChoseDiv = function (event) {
$scope.more20ChoseSubClient = false;
}
$scope.choseDivStopPropagation = function (event) {
event.stopPropagation()
};
}]);
return app;
});