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.
418 lines
18 KiB
418 lines
18 KiB
/**
|
|
* Created by yixian on 2017-02-08.
|
|
*/
|
|
define(['angular', '../../analysis/bd/analysis-bd'], function (angular) {
|
|
'use strict';
|
|
var app = angular.module('bdprize', ['ui.router']);
|
|
app.config(['$stateProvider', function ($stateProvider) {
|
|
$stateProvider.state('analysis_bd.bd_prizes', {
|
|
url: '/bd_prizes',
|
|
templateUrl: '/static/config/bdprize/templates/bd_prize_root.html',
|
|
controller: 'bdPrizeRootCtrl'
|
|
}).state('analysis_bd.bd_prizes.month_report', {
|
|
url: '/{month}',
|
|
templateUrl: '/static/config/bdprize/templates/bd_prize_month_report.html',
|
|
controller: 'bdPrizeMonthReportCtrl',
|
|
resolve: {
|
|
report: ['$http', '$stateParams', function ($http, $stateParams) {
|
|
return $http.get('/sys/bd_prize/records/' + $stateParams.month);
|
|
}]
|
|
}
|
|
}).state('analysis_bd.bd_prizes.month_report.detail', {
|
|
url: '/bd_user/{bdId}',
|
|
templateUrl: '/static/config/bdprize/templates/bd_prize_detail.html',
|
|
controller: 'bdPrizeDetailCtrl',
|
|
resolve: {
|
|
detail: ['$http', '$stateParams', function ($http, $stateParams) {
|
|
return $http.get('/sys/bd_prize/records/' + $stateParams.month + '/bd_users/' + $stateParams.bdId);
|
|
}]
|
|
}
|
|
}).state('analysis_bd.bd_prizes.bd_detail', {
|
|
url: '/{month}/my_report',
|
|
templateUrl: '/static/config/bdprize/templates/bd_prize_detail.html',
|
|
controller: 'bdPrizeDetailCtrl',
|
|
resolve: {
|
|
detail: ['$http', '$stateParams', function ($http, $stateParams) {
|
|
return $http.get('/sys/bd_prize/records/' + $stateParams.month + '/bd_user_detail')
|
|
}]
|
|
}
|
|
})
|
|
}]);
|
|
|
|
app.controller('bdPrizeRootCtrl', ['$scope', '$http', '$uibModal', 'commonDialog','$filter', function ($scope, $http, $uibModal, commonDialog,$filter) {
|
|
$scope.params = {year: new Date().getFullYear()};
|
|
$scope.generate = {};
|
|
$scope.availableYears = [new Date().getFullYear() - 1, new Date().getFullYear()];
|
|
$scope.kpiRanges = [{value: 1, label: '0-50%'}, {value: 2, label: '50%~80%'}, {value: 3, label: '80%~100%'},
|
|
{value: 4, label: '100%-120%'}, {value: 5, label: '>=120%'}];
|
|
$scope.initMonth = function (year) {
|
|
$scope.params.year = year;
|
|
$scope.months = [];
|
|
for (var i = 1; i < 13; i++) {
|
|
var mon = '00' + i;
|
|
mon = mon.substr(mon.length - 2, 2);
|
|
$scope.months.push(year + '-' + mon);
|
|
}
|
|
};
|
|
$scope.hasReport = function (mon) {
|
|
if ($scope.reportMonths != null) {
|
|
var have = false;
|
|
angular.forEach($scope.reportMonths, function (month) {
|
|
if (mon == month.month) {
|
|
have = true;
|
|
}
|
|
});
|
|
return have;
|
|
} else {
|
|
return false;
|
|
}
|
|
};
|
|
$scope.getYearReports = function (year) {
|
|
$scope.initMonth(year);
|
|
$http.get('/sys/bd_prize/records', {params: {year: year}}).then(function (resp) {
|
|
$scope.reportMonths = resp.data.data;
|
|
})
|
|
};
|
|
$scope.getYearReports(new Date().getFullYear());
|
|
$scope.generateReport = function () {
|
|
if (!$scope.generate.month) {
|
|
commonDialog.alert({
|
|
type: 'error', title: 'Error', content: 'Select a month first!'
|
|
});
|
|
return;
|
|
}
|
|
commonDialog.confirm({
|
|
title: 'Warning',
|
|
content: 'This operation will clear the result of last month generated before. Are you sure?'
|
|
}).then(function () {
|
|
$scope.generate.status = {};
|
|
var params = {month: $filter('date')($scope.generate.month, 'yyyy-MM')};
|
|
$http.post('/sys/bd_prize/generate_record/'+params.month, null, {timeout: 60000}).then(function (resp) {
|
|
$scope.generate.status = null;
|
|
commonDialog.alert({title: 'Success', content: 'Generate Finished', type: 'success'});
|
|
$scope.getYearReports($scope.params.year);
|
|
}, function (resp) {
|
|
commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'});
|
|
$scope.generate.status = null;
|
|
})
|
|
})
|
|
};
|
|
$scope.loadRateConfigs = function () {
|
|
$http.get('/sys/bd_prize/config/rates').then(function (resp) {
|
|
$scope.bd_rate_configs = resp.data;
|
|
$scope.kpi_ranges = [];
|
|
var kpiStart = [];
|
|
angular.forEach($scope.bd_rate_configs, function (cfg) {
|
|
if (kpiStart.indexOf(cfg.kpi_range) < 0) {
|
|
kpiStart.push(cfg.kpi_range);
|
|
$scope.kpi_ranges.push(cfg);
|
|
}
|
|
})
|
|
})
|
|
};
|
|
$scope.loadRateConfigs();
|
|
$scope.editRateConfig = function () {
|
|
$uibModal.open({
|
|
templateUrl: '/static/config/bdprize/templates/rate_config_dialog.html',
|
|
controller: 'bdRateConfigCtrl',
|
|
resolve: {
|
|
rates: function () {
|
|
return angular.copy($scope.bd_rate_configs);
|
|
}
|
|
}
|
|
}).result.then(function () {
|
|
$scope.loadRateConfigs();
|
|
})
|
|
};
|
|
$scope.editBDLevels = function () {
|
|
$uibModal.open({
|
|
templateUrl: '/static/config/bdprize/templates/bd_level_config_dialog.html',
|
|
size: 'lg',
|
|
controller: 'bdLevelConfigCtrl'
|
|
})
|
|
};
|
|
$scope.editCommissionConfig = function (monModal) {
|
|
$uibModal.open({
|
|
templateUrl: '/static/config/bdprize/templates/bd_commission_config_dialog.html',
|
|
controller: 'bdCommissionConfigCtrl',
|
|
size: 'lg',
|
|
resolve: {
|
|
monModal: function () {
|
|
return angular.copy(monModal);
|
|
}
|
|
}
|
|
})
|
|
};
|
|
$scope.exportCommission = function (monModal) {
|
|
location.href = '/sys/bd_prize/commission/export/' + monModal;
|
|
};
|
|
|
|
$scope.loadPersonalCommission = function () {
|
|
if (($scope.currentUser.role & parseInt('100', 2)) > 0 && $scope.currentUser.org_id === 1) {
|
|
$http.get('/sys/bd_prize/commission/personal/bd_user').then(function (resp) {
|
|
$scope.personalCommission = resp.data;
|
|
})
|
|
}
|
|
|
|
};
|
|
$scope.loadPersonalCommission();
|
|
}]);
|
|
app.controller('bdRateConfigCtrl', ['$scope', '$http', 'rates', function ($scope, $http, rates) {
|
|
$scope.bdLevels = [{value: 1, label: 'Junior'}, {value: 2, label: 'Intermediate'}, {value: 3, label: 'Senior'}];
|
|
$scope.months = [{value: 1, label: '1-3 Months'}, {value: 2, label: '4-6 Months'}, {
|
|
value: 3,
|
|
label: '>=7 Months'
|
|
}];
|
|
$scope.kpiRanges = [{value: 1, label: '0-50%'}, {value: 2, label: '50%~80%'}, {value: 3, label: '80%~100%'},
|
|
{value: 4, label: '100%-120%'}, {value: 5, label: '>=120%'}];
|
|
$scope.clientRate = [{value: 0.6, label: '0.6-0.79'}, {value: 0.8, label: '0.8-2.0'}];
|
|
$scope.filter = {bd_level: 1,rate_from:0.6};
|
|
$scope.rates = rates;
|
|
$scope.submitRates = function () {
|
|
var validation = null;
|
|
$scope.errmsg = null;
|
|
angular.forEach($scope.rates, function (rate) {
|
|
if (isNaN(rate.prize_rate)) {
|
|
validation = {months: rate.time_range, bd_level: rate.bd_level};
|
|
$scope.errmsg = 'Rate Value is NaN';
|
|
}
|
|
if (rate.prize_rate > 1) {
|
|
validation = {months: rate.time_range, bd_level: rate.bd_level};
|
|
$scope.errmsg = 'Rate value shall no more than 1%';
|
|
}
|
|
if (rate.prize_rate < 0) {
|
|
validation = {months: rate.time_range, bd_level: rate.bd_level};
|
|
$scope.errmsg = 'Rate value shall be a positive value';
|
|
}
|
|
});
|
|
if (!validation) {
|
|
$http.put('/sys/bd_prize/config/rates', $scope.rates).then(function () {
|
|
$scope.$close();
|
|
}, function (resp) {
|
|
$scope.errmsg = resp.data.message;
|
|
})
|
|
}
|
|
}
|
|
}]);
|
|
app.controller('bdLevelConfigCtrl', ['$scope', '$http', function ($scope, $http) {
|
|
$scope.bdtypes = [{id: 1, label: 'BD Manager(Sydney)'}, {id: 2, label: 'KA Manager(Sydney)'},{id: 6, label: 'BD Manager(Melbourne)'}, {id: 7, label: 'KA Manager(Melbourne)'}];
|
|
$scope.getBDGroups = function () {
|
|
$http.get('/sys/manager_accounts/roles/bd_leader').then(function (resp) {
|
|
$scope.bdgroups = resp.data;
|
|
$scope.getBDLevels();
|
|
})
|
|
};
|
|
$scope.getBDGroups();
|
|
$scope.getBDLevels = function () {
|
|
$http.get('/sys/bd_prize/config/bd_levels').then(function (resp) {
|
|
$scope.bds = resp.data;
|
|
})
|
|
};
|
|
|
|
$scope.bdLevels = [{value: 1, label: 'Junior'}, {value: 2, label: 'Intermediate'}, {value: 3, label: 'Senior'}];
|
|
$scope.updateBDLevel = function (bdInfo) {
|
|
$http.put('/sys/bd_prize/config/bd_levels/' + bdInfo.manager_id, bdInfo).then(function () {
|
|
$scope.getBDGroups();
|
|
}, function (resp) {
|
|
$scope.errmsg = resp.data.message;
|
|
})
|
|
};
|
|
}]);
|
|
app.controller('bdCommissionConfigCtrl', ['$scope', '$state', '$http', '$filter', 'monModal', function ($scope, $state, $http, $filter, monModal) {
|
|
$scope.monModal = monModal;
|
|
$scope.params = {year: new Date().getFullYear()};
|
|
$scope.bdtypes = [{id: 1, label: 'BD Manager(Sydney)'}, {id: 2, label: 'KA Manager(Sydney)'}, {id: 6, label: 'BD Manager(Melbourne)'}, {id: 7, label: 'KA Manager(Melbourne)'}];//, {id: 3, label: 'Sydney GM'},{id: 4, label: 'COO'},{id: 5, label: 'NJ Department'}];
|
|
// $scope.bdmon;
|
|
// $scope.newSwitch;
|
|
$scope.initMonth = function (year) {
|
|
$scope.params.year = year;
|
|
$scope.months = [];
|
|
for (var i = 1; i < 13; i++) {
|
|
var mon = '00' + i;
|
|
mon = mon.substr(mon.length - 2, 2);
|
|
$scope.months.push(year + '-' + mon);
|
|
}
|
|
};
|
|
$scope.initMonth(new Date().getFullYear());
|
|
$scope.hasReport = function (mon) {
|
|
var start = '2017-01';//todo change for different country
|
|
var end = $filter('date')(new Date(), 'yyyy-MM');
|
|
return start <= mon && end >= mon
|
|
};
|
|
$scope.getBDLevels = function () {
|
|
$http.get('/sys/bd_prize/config/bd_levels').then(function (resp) {
|
|
$scope.bds = resp.data;
|
|
})
|
|
};
|
|
$scope.getBDLevels();
|
|
$scope.chooseLastConfig = function (mon) {
|
|
var index = $scope.months.indexOf(mon);
|
|
if(index == 0){
|
|
var year = new Date().getFullYear();
|
|
year--;
|
|
mon = year + '-12';
|
|
}else {
|
|
mon = $scope.months[index-1];
|
|
}
|
|
$http.get('/sys/bd_prize/commission/le_ma/' + mon).then(function (resp) {
|
|
$scope.bdlm = [];
|
|
angular.forEach(resp.data,function (e) {
|
|
var bdC = {};
|
|
bdC.commission_start_amount = e.commission_start_amount;
|
|
bdC.commission_end_amount = e.commission_end_amount;
|
|
bdC.bd_commission_rate = e.bd_commission_rate;
|
|
bdC.bd_type = e.bd_type;
|
|
$scope.bdlm.push(bdC);
|
|
});
|
|
$scope.listConfig = true;
|
|
})
|
|
};
|
|
$scope.listCurrentMonBDCommission = function (mon) {
|
|
$http.get('/sys/bd_prize/commission/le_ma/' + mon).then(function (resp) {
|
|
$scope.bdlm = resp.data;
|
|
$scope.bdmon = mon;
|
|
$scope.listConfig = true;
|
|
})
|
|
};
|
|
$scope.listCurrentMonBDCommission($scope.monModal);
|
|
$scope.deleteCommission = function (config) {
|
|
$http.delete('sys/bd_prize/commission/delete/' + config)
|
|
$scope.listCurrentMonBDCommission($scope.monModal);
|
|
$state.reload();
|
|
}
|
|
$scope.submitCommmissionConfig = function (mon, bdlm) {
|
|
$scope.check = true;
|
|
angular.forEach(bdlm, function (data, index) {
|
|
$scope.errmsg = null;
|
|
if (!data.bd_type) {
|
|
$scope.errmsg = "BD Type not be null";
|
|
$scope.check = false;
|
|
return;
|
|
}
|
|
if (!data.bd_commission_rate) {
|
|
$scope.errmsg = "BD Rate not be null";
|
|
$scope.check = false;
|
|
return;
|
|
}
|
|
if (data.bd_commission_rate) {
|
|
if (data.bd_commission_rate > 10) {
|
|
$scope.errmsg = "BD Rate is too big";
|
|
$scope.check = false;
|
|
return;
|
|
}
|
|
}
|
|
if (!data.commission_start_amount && data.commission_start_amount != 0) {
|
|
$scope.errmsg = "Commission Amount not be null";
|
|
$scope.check = false;
|
|
return;
|
|
}
|
|
if (data.commission_end_amount || data.commission_end_amount == 0) {
|
|
if (data.commission_start_amount >= data.commission_end_amount) {
|
|
$scope.errmsg = "Commission Start Amount should less than End Amount";
|
|
$scope.check = false;
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
if ($scope.check) {
|
|
$http.post('/sys/bd_prize/commission/le_ma/update/' + mon, bdlm).then(function (resp) {
|
|
$scope.$close();
|
|
// $scope.bdlm = null;
|
|
// $scope.bdmon;
|
|
// $scope.listConfig = false;
|
|
// $scope.listCurrentMonBDCommission(mon);
|
|
})
|
|
}
|
|
}
|
|
$scope.submitBdCommmissionConfig = function (mon, bds) {
|
|
$scope.check = true;
|
|
$scope.errmsg = null;
|
|
angular.forEach(bds, function (data, index) {
|
|
if(data.get_prize){
|
|
if (!data.kpi_amount) {
|
|
$scope.errmsg = "BD kpi Amount not be null";
|
|
$scope.check = false;
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
if ($scope.check) {
|
|
$http.post('/sys/bd_prize/commission/kpi/update/' + mon, bds).then(function (resp) {
|
|
$scope.$close();
|
|
})
|
|
}
|
|
}
|
|
}]);
|
|
app.controller('bdPrizeMonthReportCtrl', ['$scope', '$http', 'report', function ($scope, $http, report) {
|
|
$scope.report = report.data;
|
|
}]);
|
|
app.controller('bdPrizeDetailCtrl', ['$scope', 'detail', function ($scope, detail) {
|
|
$scope.detail = detail.data;
|
|
}]);
|
|
app.filter('financialBdLevel', function () {
|
|
return function (level) {
|
|
switch (level) {
|
|
case 0:
|
|
return 'Leader';
|
|
case 1:
|
|
return 'Junior';
|
|
case 2:
|
|
return 'Intermediate';
|
|
case 3:
|
|
return 'Senior';
|
|
default:
|
|
return 'Unknown';
|
|
}
|
|
}
|
|
});
|
|
app.filter('financialClientSource', function () {
|
|
return function (source) {
|
|
switch (source) {
|
|
case 1:
|
|
return 'BD';
|
|
case 2:
|
|
return 'Apply';
|
|
case 3:
|
|
return 'Distribute';
|
|
default:
|
|
return 'Unknown';
|
|
}
|
|
}
|
|
});
|
|
app.filter('prizeLogsFilter', [function () {
|
|
return function (arr, filterObj) {
|
|
if (arr == null || filterObj == null) {
|
|
return arr;
|
|
}
|
|
return arr.filter(function (item) {
|
|
return item.prize_type == filterObj
|
|
})
|
|
}
|
|
}]);
|
|
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';
|
|
case 'Rpay':
|
|
return '/static/images/rpayplus_sign_lg.png';
|
|
case 'Yeepay':
|
|
return '/static/images/yeepay_sign_lg.png';
|
|
}
|
|
}
|
|
});
|
|
return app;
|
|
});
|