| 26053 |
amit.gupta |
1 |
$(document).on('click', 'a.list-group-item', function() {
|
| 26054 |
amit.gupta |
2 |
startDate=undefined;
|
|
|
3 |
endDate=undefined;
|
| 26063 |
amit.gupta |
4 |
reportTitle = $(this).find('h4').html();
|
|
|
5 |
reportUrl = this.href;
|
| 26054 |
amit.gupta |
6 |
$reportModal = $('#report-modal');
|
| 26063 |
amit.gupta |
7 |
$reportModal.find('h4.modal-title').html(reportTitle);
|
| 26053 |
amit.gupta |
8 |
if($(this).data("paramslist") == undefined) {
|
| 26054 |
amit.gupta |
9 |
return true;
|
| 26053 |
amit.gupta |
10 |
} else {
|
|
|
11 |
var paramsList = $(this).data("paramslist");
|
|
|
12 |
paramsMap = {};
|
|
|
13 |
renderInputDialog(paramsList);
|
|
|
14 |
$reportModal.modal('show');
|
|
|
15 |
return false;
|
|
|
16 |
}
|
|
|
17 |
});
|
| 26063 |
amit.gupta |
18 |
$(document).on('click', 'button.download-report', function(){
|
| 26054 |
amit.gupta |
19 |
var reportParams = {};
|
| 26089 |
amit.gupta |
20 |
$inputContainer.find("input,select").each(function(idx, inputElement) {
|
| 26054 |
amit.gupta |
21 |
var inputName = $(inputElement).attr("name");
|
| 26089 |
amit.gupta |
22 |
if(typeof inputName === "undefined" || !(inputName in paramsMap)) {
|
|
|
23 |
console.log(inputName);
|
|
|
24 |
return;
|
|
|
25 |
}
|
|
|
26 |
param = paramsMap[inputName];
|
| 26054 |
amit.gupta |
27 |
if($(inputElement).val()=="") {
|
| 26089 |
amit.gupta |
28 |
bootbox.alert(`${param.displayName} is required`);
|
|
|
29 |
return;
|
| 26054 |
amit.gupta |
30 |
}
|
|
|
31 |
if(param.type=='DATE') {
|
|
|
32 |
reportParams[`MANUAL_${inputName}`] = startDate;
|
|
|
33 |
} else if(param.type=='DATE_RANGE') {
|
|
|
34 |
reportParams[`MANUAL_${inputName}_FROMDATE`] = startDate;
|
|
|
35 |
reportParams[`MANUAL_${inputName}_TODATE`] = endDate;
|
|
|
36 |
} else {
|
| 26118 |
amit.gupta |
37 |
if(param.name in ['code', 'warehouseId']) {
|
| 26089 |
amit.gupta |
38 |
reportParams[`MANUAL_${inputName}`] = $(inputElement).val().join(",");
|
| 26116 |
amit.gupta |
39 |
|
| 26089 |
amit.gupta |
40 |
} else {
|
|
|
41 |
reportParams[`MANUAL_${inputName}`] = $(inputElement).val();
|
|
|
42 |
}
|
| 26054 |
amit.gupta |
43 |
}
|
|
|
44 |
});
|
| 26063 |
amit.gupta |
45 |
var jsonParams = JSON.stringify(reportParams);
|
|
|
46 |
doAjaxPostDownload(reportUrl, jsonParams, `${reportTitle}.csv`);
|
|
|
47 |
|
| 26054 |
amit.gupta |
48 |
});
|
| 26053 |
amit.gupta |
49 |
function renderInputDialog(paramsList) {
|
| 26054 |
amit.gupta |
50 |
$reportModal = $('div#report-modal');
|
|
|
51 |
$inputContainer = $reportModal.find('div.modal-body');
|
|
|
52 |
//Clear container first
|
|
|
53 |
$inputContainer.html('');
|
| 26053 |
amit.gupta |
54 |
paramsList.forEach(function(value) {
|
|
|
55 |
paramsMap[value.name] = value;
|
|
|
56 |
renderInput($inputContainer, value);
|
|
|
57 |
});
|
|
|
58 |
}
|
|
|
59 |
|
| 26054 |
amit.gupta |
60 |
function renderInput($inputContainer, param) {
|
|
|
61 |
console.log(param.type);
|
| 26053 |
amit.gupta |
62 |
switch (param.type) {
|
|
|
63 |
case "DATE": {
|
| 26054 |
amit.gupta |
64 |
$inputContainer.append(`<div class="form-group">
|
| 26053 |
amit.gupta |
65 |
<label>${param.displayText}</label>
|
|
|
66 |
<input name="${param.name}" type="text" value="" class="form-control input-sm">
|
|
|
67 |
</div>`);
|
| 26063 |
amit.gupta |
68 |
$inputContainer.find(`input[name="${param.name}"]`).daterangepicker(getSingleDatePicker(),reporticoDRCallback);
|
|
|
69 |
reporticoDRCallback(moment(), moment());
|
| 26054 |
amit.gupta |
70 |
return;
|
| 26053 |
amit.gupta |
71 |
}
|
|
|
72 |
case "DATE_RANGE" : {
|
| 26054 |
amit.gupta |
73 |
$inputContainer.append(`<div class="form-group">
|
| 26053 |
amit.gupta |
74 |
<label>${param.displayText}</label>
|
|
|
75 |
<input name="${param.name}" type="text" value="" class="form-control input-sm">
|
|
|
76 |
</div>`);
|
| 26063 |
amit.gupta |
77 |
$inputContainer.find(`input[name="${param.name}"]`).daterangepicker(getRangedDatePicker(true),reporticoDRCallback);
|
|
|
78 |
reporticoDRCallback(moment(), moment());
|
| 26054 |
amit.gupta |
79 |
return;
|
| 26053 |
amit.gupta |
80 |
}
|
|
|
81 |
case "STRING": {
|
| 26054 |
amit.gupta |
82 |
$inputContainer.append(`<div class="form-group">
|
| 26053 |
amit.gupta |
83 |
<label>${param.displayText}</label>
|
|
|
84 |
<input name="${param.name}" type="text" value="" class="form-control input-sm">
|
|
|
85 |
</div>`);
|
| 26054 |
amit.gupta |
86 |
return;
|
| 26053 |
amit.gupta |
87 |
}
|
|
|
88 |
case "LIST" : {
|
| 26089 |
amit.gupta |
89 |
if(param.name == "code"){
|
|
|
90 |
var arr = [];
|
|
|
91 |
for(var i in retailers) {
|
|
|
92 |
arr.push(`<option value="${retailers[i].code}">${retailers[i].displayName}-${retailers[i].code}</option>`);
|
|
|
93 |
}
|
|
|
94 |
var options = arr.join("");
|
|
|
95 |
$inputContainer.append(`<div class="col-lg-2 form-group">
|
|
|
96 |
<label>${param.displayText}</label>
|
|
|
97 |
<select class="form-control input-sm" id="code" multiple="multiple" name="${param.name}">
|
|
|
98 |
<option value="" disabled selected>Select Franchisee</option>
|
|
|
99 |
${options}
|
|
|
100 |
</select>
|
|
|
101 |
</div>`);
|
|
|
102 |
|
|
|
103 |
$('#code').multiselect({
|
|
|
104 |
includeSelectAllOption: true,
|
|
|
105 |
multiple:true,
|
|
|
106 |
maxHeight: 200,
|
|
|
107 |
buttonWidth: '180px',
|
|
|
108 |
numberDisplayed: 1,
|
|
|
109 |
nonSelectedText: 'Franchisee',
|
|
|
110 |
nSelectedText: ' - Franchisees Selected',
|
|
|
111 |
allSelectedText: 'All Franchisees',
|
|
|
112 |
enableFiltering: true,
|
|
|
113 |
enableCaseInsensitiveFiltering : true
|
|
|
114 |
});
|
| 26116 |
amit.gupta |
115 |
} else if(param.name == "warehouseId"){
|
|
|
116 |
var arr = [];
|
|
|
117 |
for(var i in warehouses) {
|
|
|
118 |
arr.push(`<option value="${i}">${warehouses[i]}</option>`);
|
|
|
119 |
}
|
|
|
120 |
var options = arr.join("");
|
|
|
121 |
$inputContainer.append(`<div class="col-lg-2 form-group">
|
|
|
122 |
<label>${param.displayText}</label>
|
|
|
123 |
<select class="form-control input-sm" id="code" multiple="multiple" name="${param.name}">
|
|
|
124 |
<option value="" disabled selected>Select Warehouses</option>
|
|
|
125 |
${options}
|
|
|
126 |
</select>
|
|
|
127 |
</div>`);
|
|
|
128 |
|
|
|
129 |
$('#code').multiselect({
|
|
|
130 |
includeSelectAllOption: true,
|
|
|
131 |
multiple:true,
|
|
|
132 |
maxHeight: 200,
|
|
|
133 |
buttonWidth: '180px',
|
|
|
134 |
numberDisplayed: 1,
|
|
|
135 |
nonSelectedText: 'Warehouses',
|
|
|
136 |
nSelectedText: ' - Warehouse Selected',
|
|
|
137 |
allSelectedText: 'All Warehouses',
|
|
|
138 |
enableFiltering: true,
|
|
|
139 |
enableCaseInsensitiveFiltering : true
|
|
|
140 |
});
|
|
|
141 |
} else {
|
| 26089 |
amit.gupta |
142 |
$inputContainer.append(`<div class="form-group">
|
|
|
143 |
<label>${param.displayText}(Comma Separated)</label>
|
|
|
144 |
<input name="${param.name}" type="text" value="" class="form-control input-sm">
|
|
|
145 |
</div>`);
|
|
|
146 |
}
|
| 26054 |
amit.gupta |
147 |
return;
|
| 26053 |
amit.gupta |
148 |
}
|
|
|
149 |
}
|
|
|
150 |
}
|