-
Notifications
You must be signed in to change notification settings - Fork 98
/
stock_entry.config.js
87 lines (71 loc) · 2.28 KB
/
stock_entry.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
angular.module('bhima.controllers')
.controller('stock_entryController', StockEntryConfigController);
StockEntryConfigController.$inject = [
'$sce', 'NotifyService', 'BaseReportService', 'AppCache', 'reportData', '$state',
'LanguageService',
];
function StockEntryConfigController($sce, Notify, SavedReports, AppCache, reportData, $state, Languages) {
const vm = this;
const cache = new AppCache('configure_stock_entry_report');
const reportUrl = 'reports/stock/entry';
// default values
vm.reportDetails = {
includePurchaseEntry : 1,
};
vm.previewGenerated = false;
vm.onEntryTypeChange = onEntryTypeChange;
// check cached configuration
checkCachedConfiguration();
// check checked entry type
onEntryTypeChange();
vm.onSelectDepot = depot => {
vm.reportDetails.depotUuid = depot.uuid;
};
vm.clear = key => {
delete vm[key];
};
vm.clearPreview = () => {
vm.previewGenerated = false;
vm.previewResult = null;
};
vm.preview = form => {
if (form.$invalid) {
return 0;
}
if (!vm.hasOneChecked) {
return 0;
}
// update cached configuration
cache.reportDetails = angular.copy(vm.reportDetails);
angular.extend(vm.reportDetails, { lang : Languages.key });
return SavedReports.requestPreview(reportUrl, reportData.id, angular.copy(vm.reportDetails))
.then((result) => {
vm.previewGenerated = true;
vm.previewResult = $sce.trustAsHtml(result);
})
.catch(Notify.handleError);
};
vm.requestSaveAs = function requestSaveAs() {
const options = {
url : reportUrl,
report : reportData,
reportOptions : angular.copy(vm.reportDetails),
};
return SavedReports.saveAsModal(options)
.then(() => {
$state.go('reportsBase.reportsArchive', { key : options.report.report_key });
})
.catch(Notify.handleError);
};
function checkCachedConfiguration() {
vm.reportDetails = angular.copy(cache.reportDetails || {});
}
function onEntryTypeChange() {
// be sure at least one checkbox is checked
const sum = vm.reportDetails.includePurchaseEntry
+ vm.reportDetails.includeIntegrationEntry
+ vm.reportDetails.includeDonationEntry
+ vm.reportDetails.includeTransferEntry;
vm.hasOneChecked = sum > 0;
}
}