452 lines
19 KiB
JavaScript
452 lines
19 KiB
JavaScript
/*
|
|
2nd level route entry point
|
|
this controller is responsible for Routing Organization LCA , Product LCA with or without PCR selected
|
|
and the stutus of a LCA
|
|
---------------------------------
|
|
*/
|
|
|
|
angular.module('CarbonFootprint')
|
|
.config(function ($locationProvider, $routeProvider, CONSTANTS) {
|
|
$routeProvider.when('/LCA/Report/:LCAID', {
|
|
templateUrl: CONSTANTS.PB + 'LCA-DetailSurveyForm-Report',
|
|
controller: 'LCAReportController'
|
|
})
|
|
})
|
|
.controller('LCAReportController',
|
|
['$scope', '$location', 'LCADetailCacheService', '$routeParams', 'CONSTANTS', '$q', 'MultiLanguageService', '$http', '$timeout',
|
|
function ($scope, $location, LCADetailCacheService, $routeParams, CONSTANTS, $q, MultiLanguageService, $http, $timeout) {
|
|
// Hide sheet header in Detail page
|
|
if ($routeParams.DetailType == 'Detail' ||
|
|
$routeParams.DetailType == 'HighLevelAnalyze' ||
|
|
$routeParams.DetailType == 'ProductUsageStage' ||
|
|
$routeParams.DetailType == 'AbandonedStage') {
|
|
$scope.isHideSheetHeader = true;
|
|
}
|
|
|
|
// set $scope.baseUrl
|
|
var baseUrl = $scope.baseUrl;
|
|
if (typeof (baseUrl) === 'undefined' || baseUrl == null) {
|
|
var arr = window.location.href.split("/");
|
|
if (arr[3].indexOf('app') == 0)
|
|
baseUrl = '';
|
|
else
|
|
baseUrl = '/' + arr[3];
|
|
$scope.baseUrl = baseUrl;
|
|
}
|
|
|
|
var resource;
|
|
MultiLanguageService.getResourceAsync().then(function (result) {
|
|
resource = result;
|
|
$scope.toWaitState = function () {
|
|
if (confirm(resource.DoubleCheckSendToWait))
|
|
LCADetailCacheService.setLCAStatusFromProcessToWaitAsync($routeParams.LCAID, 1);
|
|
}
|
|
});
|
|
// 要從後端取得是否啟用思納捷
|
|
$scope.InsynergerOn = false;
|
|
$http.get($scope.baseUrl+'/api/LCA/InsynergerIsOn')
|
|
.success(function (data, status, header, config) {
|
|
//console.log(data);
|
|
$scope.InsynergerOn = data;
|
|
});
|
|
$scope.toInsynergerHome = function () {
|
|
window.location.href = '/Insynerger';
|
|
}
|
|
|
|
$scope.toProcessState = function () {
|
|
LCADetailCacheService.setLCAStatusFromRejectToProcessAsync($routeParams.LCAID);
|
|
};
|
|
|
|
$scope.toCompleteState = function () {
|
|
LCADetailCacheService.setLCAStatusFromConfirmToCompleteAsync($routeParams.LCAID)
|
|
.then(function () {
|
|
$location.path('/Report/Index');
|
|
});
|
|
};
|
|
|
|
// 產生產品型報表2
|
|
$scope.toGenerateProductReport = function () {
|
|
//產生產品型報表
|
|
LCADetailCacheService.setLCAStatusFromProcessToWaitAsync($routeParams.LCAID, 0)
|
|
.then(res => {
|
|
//console.log('產生產品型報表1', res);
|
|
if (res != null) {
|
|
let arr = res.slice(1, res.length - 1).split(',');
|
|
for (let i = 0; i < arr.length; i++) {
|
|
var url = arr[i];
|
|
var elemIF = document.createElement("iframe");
|
|
elemIF.src = url;
|
|
elemIF.style.display = "none";
|
|
document.body.appendChild(elemIF);
|
|
}
|
|
}
|
|
});
|
|
//.then(function () {
|
|
// $location.path('/Report/Index');
|
|
//});
|
|
};
|
|
// 產生所有報表 CFT-89
|
|
$scope.toGenerateReport = function () {
|
|
LCADetailCacheService.GenerateReport($routeParams.LCAID).then(res => {
|
|
if (res != null) {
|
|
let arr = res.slice(1, res.length-1).split(',');
|
|
for (let i = 0; i < arr.length; i++) {
|
|
var url = arr[i];
|
|
var elemIF = document.createElement("iframe");
|
|
elemIF.src = url;
|
|
elemIF.style.display = "none";
|
|
document.body.appendChild(elemIF);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
// 產生產品型盤查表
|
|
//$scope.toGenerateProductLCAdata = function () {
|
|
// console.log('產生產品型盤查表');
|
|
// 用 toGenerateLCAdataReport 組織型產品型一起
|
|
//};
|
|
// 產生高階分析表
|
|
//$scope.toGenerateHighLevelAnalysis = function () {
|
|
// console.log('產生高階分析表');
|
|
//};
|
|
// 產生敏感性分析表
|
|
$scope.toGenerateSensitivityAnalysis = function () {
|
|
//console.log('產生敏感性分析表');
|
|
LCADetailCacheService.GenerateSensitivityAnalysis($routeParams.LCAID).then(res => {
|
|
//console.log('敏感性分析表',res);
|
|
if (res != null) {
|
|
let arr = res.slice(1, res.length - 1).split(',');
|
|
for (let i = 0; i < arr.length; i++) {
|
|
var url = arr[i];
|
|
var elemIF = document.createElement("iframe");
|
|
elemIF.src = url;
|
|
elemIF.style.display = "none";
|
|
document.body.appendChild(elemIF);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
//產生盤查表
|
|
$scope.toGenerateLCAdataReport = function () {
|
|
//console.log('產生盤查表');
|
|
LCADetailCacheService.GenerateLCAdataReport($routeParams.LCAID).then(res => {
|
|
//console.log('盤查表',res);
|
|
if (res != null) {
|
|
let arr = res.slice(1, res.length - 1).split(',');
|
|
for (let i = 0; i < arr.length; i++) {
|
|
var url = arr[i];
|
|
var elemIF = document.createElement("iframe");
|
|
elemIF.src = url;
|
|
elemIF.style.display = "none";
|
|
document.body.appendChild(elemIF);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
//產生清冊
|
|
$scope.toGenerateLCAlistReport = function () {
|
|
//console.log('產生清冊');
|
|
LCADetailCacheService.GenerateLCAlistReport($routeParams.LCAID).then(res => {
|
|
//console.log('清冊', res);
|
|
if (res != null) {
|
|
let arr = res.slice(1, res.length - 1).split(',');
|
|
for (let i = 0; i < arr.length; i++) {
|
|
var url = arr[i];
|
|
if (url.length >= 3 && url.substring(0, 3) == 'err') {
|
|
alert(decodeURI(url));
|
|
return false;
|
|
}
|
|
var elemIF = document.createElement("iframe");
|
|
elemIF.src = url;
|
|
elemIF.style.display = "none";
|
|
document.body.appendChild(elemIF);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
//產生報告書
|
|
$scope.toGenerateLCAreport = function () {
|
|
LCADetailCacheService.GenerateLCAreport($routeParams.LCAID).then(res => {
|
|
//console.log('產生報告書2', res);
|
|
if (res != null) {
|
|
let arr = res.slice(1, res.length - 1).split(',');
|
|
for (let i = 0; i < arr.length; i++) {
|
|
var url = arr[i];
|
|
var elemIF = document.createElement("iframe");
|
|
elemIF.src = url;
|
|
elemIF.style.display = "none";
|
|
document.body.appendChild(elemIF);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
//產生風險評估報表
|
|
$scope.toGenerateRiskAssessmentReport = function () {
|
|
LCADetailCacheService.GenerateRiskAssessmentReport($routeParams.LCAID).then(res => {
|
|
if (res != null) {
|
|
let arr = res.slice(1, res.length - 1).split(',');
|
|
for (let i = 0; i < arr.length; i++) {
|
|
var url = arr[i];
|
|
if (url.length >= 3 && url.substring(0, 3) == 'err') {
|
|
alert(decodeURI(url));
|
|
return false;
|
|
}
|
|
var elemIF = document.createElement("iframe");
|
|
elemIF.src = url;
|
|
elemIF.style.display = "none";
|
|
document.body.appendChild(elemIF);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
//產生合併清冊
|
|
$scope.toGenerateMergedLCAlistReport = function () {
|
|
LCADetailCacheService.GenerateMergedLCAlistReport($routeParams.LCAID).then(res => {
|
|
if (res != null) {
|
|
let arr = res.slice(1, res.length - 1).split(',');
|
|
for (let i = 0; i < arr.length; i++) {
|
|
var url = arr[i];
|
|
if (url.length >= 3 && url.substring(0, 3) == 'err') {
|
|
alert(decodeURI(url));
|
|
return false;
|
|
}
|
|
var elemIF = document.createElement("iframe");
|
|
elemIF.src = url;
|
|
elemIF.style.display = "none";
|
|
document.body.appendChild(elemIF);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
//產生合併報告書
|
|
$scope.toGenerateMergedLCAreport = function () {
|
|
LCADetailCacheService.GenerateMergedLCAreport($routeParams.LCAID).then(res => {
|
|
if (res != null) {
|
|
let arr = res.slice(1, res.length - 1).split(',');
|
|
for (let i = 0; i < arr.length; i++) {
|
|
var url = arr[i];
|
|
var elemIF = document.createElement("iframe");
|
|
elemIF.src = url;
|
|
elemIF.style.display = "none";
|
|
document.body.appendChild(elemIF);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
$scope.reportUploadOption = {};
|
|
|
|
$scope.uploadZipReport = function (id, isProductLCA) {
|
|
var selectedFiles = {};
|
|
|
|
$scope.reportUploadOption.show = true;
|
|
|
|
let p0 = document.getElementById("upload-file-result-msg");
|
|
if (p0 != null)
|
|
p0.innerHTML = "";
|
|
$scope.reportUploadOption.selectFile = function (files) {
|
|
selectedFiles = files;
|
|
};
|
|
|
|
$scope.uploadZipReportPost = function () {
|
|
var formData = new FormData();
|
|
|
|
formData.append('file', selectedFiles);
|
|
formData.append('lcaId', id);
|
|
|
|
let p0 = document.getElementById("upload-file-result-msg");
|
|
if (p0 != null)
|
|
p0.innerHTML = "";
|
|
// to do: Should refactor
|
|
$http.post($scope.baseUrl+'/api/UploadLcaFiles/' + isProductLCA, formData, {
|
|
transformRequest: angular.identity,
|
|
headers: { 'Content-Type': undefined }
|
|
}).success(function (data) {
|
|
if (data != null) {
|
|
let p = document.getElementById("upload-file-result-msg");
|
|
if (p != null) {
|
|
p.innerHTML = data.Msg != null ? data.Msg : "";
|
|
if (data.Success == true) {
|
|
document.getElementById("upload-file-result-msg").style.color = "green";
|
|
}
|
|
else {
|
|
document.getElementById("upload-file-result-msg").style.color = "red";
|
|
}
|
|
}
|
|
}
|
|
}).error(function (data, status) {
|
|
//console.log(status);
|
|
});
|
|
};
|
|
};
|
|
$scope.downloadZipReport = function (id) {
|
|
LCADetailCacheService.downloadZipReport(id).then(res => {
|
|
if (res != null) {
|
|
let url = res.slice(1, res.length - 1);
|
|
if (url != "") {
|
|
//for (let i = 0; i < arr.length; i++) {
|
|
let a = document.createElement('a');
|
|
a.setAttribute('download', '');
|
|
a.setAttribute('href', url);
|
|
a.click();
|
|
//}
|
|
} else {
|
|
alert('無上傳檔案');
|
|
}
|
|
}
|
|
});
|
|
};
|
|
$scope.downloadZipReplyReport = function (id) {
|
|
LCADetailCacheService.downloadZipReplyReport(id).then(res => {
|
|
if (res != null) {
|
|
let url = res.slice(1, res.length - 1);
|
|
if (url != "") {
|
|
//for (let i = 0; i < arr.length; i++) {
|
|
let a = document.createElement('a');
|
|
a.setAttribute('download', '');
|
|
a.setAttribute('href', url);
|
|
a.click();
|
|
//}
|
|
} else {
|
|
alert('验证单位未回复压缩文档');
|
|
}
|
|
}
|
|
});
|
|
};
|
|
$scope.templateImportOption = {};
|
|
|
|
//End
|
|
|
|
if ($routeParams.SearchText) {
|
|
$scope.searchText = $routeParams.SearchText
|
|
}
|
|
|
|
getAllDataAsync($routeParams.LCAID)
|
|
.then(function (response) {
|
|
var sheetHeader = response.SheetHeader ? response.SheetHeader : {};
|
|
// $scope.sheetHeader is parent's object
|
|
$scope.sheetHeader.SheetFillerName = sheetHeader.SheetFillerName;
|
|
$scope.sheetHeader.Phone = sheetHeader.Phone;
|
|
$scope.sheetHeader.Department = sheetHeader.Department;
|
|
}, function (error) {
|
|
//console.log(error);
|
|
});
|
|
function getAllDataAsync(LCAID) {
|
|
var deferred = $q.defer();
|
|
$http.get($scope.baseUrl+'/api/LCA/GetReportSheetHeaderByLcaId/' + LCAID)
|
|
.success(function (data) {
|
|
deferred.resolve(data);
|
|
})
|
|
.error(function () {
|
|
deferred.resolve(null);
|
|
})
|
|
return deferred.promise;
|
|
}
|
|
|
|
// save sheetHeader
|
|
$scope.saveSheetHeader = function () {
|
|
$scope.isCheckOnce = true;
|
|
if ($scope.headerForm.$invalid) return;
|
|
|
|
$scope.sheetHeaderForm.resultMsg = '';
|
|
|
|
var newSheetHeader = $scope.sheetHeader;
|
|
newSheetHeader.LCAID = $routeParams.LCAID;
|
|
|
|
$http.post($scope.baseUrl+'/api/' + $routeParams.DetailType + '/SaveSheetHeader', newSheetHeader)
|
|
.success(function (data) {
|
|
$scope.sheetHeaderForm.resultMsg = resource['UpdateSuccess'];
|
|
})
|
|
.error(function (error) {
|
|
$scope.cancelEditSheetHeader();
|
|
$scope.sheetHeaderForm.resultMsg = resource['UpdateFail'];
|
|
//console.log(error);
|
|
})
|
|
.finally(function () {
|
|
// set timeout
|
|
$timeout(function () { $scope.sheetHeaderForm.resultMsg = '' }, 3000);
|
|
// switch to uneditable
|
|
$scope.sheetHeaderForm.editable = false;
|
|
});
|
|
}
|
|
// edit sheetheader
|
|
$scope.editSheetHeader = function () {
|
|
$scope.tempSheetHeader = angular.copy($scope.sheetHeader);
|
|
$scope.sheetHeaderForm.editable = true;
|
|
}
|
|
|
|
// canael edit sheetheader
|
|
$scope.cancelEditSheetHeader = function () {
|
|
$scope.headerForm.$setPristine();
|
|
$scope.sheetHeader = angular.copy($scope.tempSheetHeader);
|
|
$scope.sheetHeaderForm.editable = false;
|
|
}
|
|
|
|
const CHARTID1 = 'canvasPie';
|
|
const CHARTID2 = 'canvasPie2';
|
|
var makeChart = function (chartID, labels, data, backgroundColor ) {
|
|
var ctx = document.getElementById(chartID).getContext('2d');
|
|
var pieChart = new Chart(ctx, {
|
|
type: 'pie',
|
|
data: {
|
|
labels: labels,
|
|
datasets: [{
|
|
data: data,
|
|
backgroundColor: backgroundColor,
|
|
}],
|
|
},
|
|
options: {
|
|
plugins: {
|
|
tooltip: {
|
|
callbacks: {
|
|
label: function (context) {
|
|
return `${context.label}: ${context.formattedValue} kgCO2e`
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
return pieChart;
|
|
}
|
|
|
|
var labels1 = ['第一類排放', '第二類排放', '第三類排放', '第四類排放', '第五類排放', '第六類排放'];
|
|
var labels2 = ['固定式燃燒之直接排放', '移動式燃燒之直接排放', '工業製程之直接排放量及移除量', '人為系統中釋放之溫室氣體的直接逸散性排放', '土地使用、土地使用變更和林業的直接排放和移除'];
|
|
var data1 = [10, 10, 10, 10, 10, 10];
|
|
var data2 = [50, 100, 50, 100, 50];
|
|
var backgroundColor1 = ["#DC9EE9", "#92A1F0", "#7283E1", "#2B93BD", "#3C8830", "#99663A"];
|
|
var backgroundColor2 = ["#2B6F25", "#8A9D34", "#376AA4", "#4B37A4", "#BF4640"];
|
|
|
|
|
|
$scope.getChartData = function () {
|
|
$http.get($scope.baseUrl+'/api/LCA/GetChartData/' + $routeParams.LCAID)
|
|
.then(function (ret) {
|
|
//console.log(ret);
|
|
if (typeof (ret) === 'undefined' || ret == null || ret.data==null || ret.data=='null')
|
|
return;
|
|
data1 = ret.data.list;
|
|
data2 = ret.data.lcaDAta;
|
|
for (var i = 5; i >= 0; i--) {
|
|
if (data1[i] == 0) {
|
|
labels1.splice(i, 1);
|
|
data1.splice(i, 1);
|
|
backgroundColor1.splice(i, 1);
|
|
}
|
|
}
|
|
for (var i = 4; i >= 0; i--) {
|
|
if (data2[i] == 0) {
|
|
labels2.splice(i, 1);
|
|
data2.splice(i, 1);
|
|
backgroundColor2.splice(i, 1);
|
|
}
|
|
}
|
|
if (data1.length > 0)
|
|
makeChart(CHARTID1, labels1, data1, backgroundColor1);
|
|
if (data2.length > 0)
|
|
makeChart(CHARTID2, labels2, data2, backgroundColor2);
|
|
});
|
|
}
|
|
|
|
$scope.getChartData();
|
|
|
|
}]);
|