| Line 150... |
Line 150... |
| 150 |
$(document).on('click', ".schemes-update", function() {
|
150 |
$(document).on('click', ".schemes-update", function() {
|
| 151 |
loadSchemeUpdatePage("main-content");
|
151 |
loadSchemeUpdatePage("main-content");
|
| 152 |
});
|
152 |
});
|
| 153 |
|
153 |
|
| 154 |
$(document).on('click', ".add-item", function() {
|
154 |
$(document).on('click', ".add-item", function() {
|
| 155 |
|
- |
|
| 156 |
schemeIds = $("#schemeids").val();
|
155 |
var schemeIds = $("#schemeids").val();
|
| - |
|
156 |
// Read from modal model multi-select if available, else fall back to text input
|
| - |
|
157 |
var selectedModels = $(".modalCatalogItems").val();
|
| - |
|
158 |
var catalogIds;
|
| - |
|
159 |
if (selectedModels && selectedModels.length > 0) {
|
| - |
|
160 |
catalogIds = selectedModels.join(",");
|
| - |
|
161 |
} else {
|
| 157 |
itemIds = $("#catalogids").val();
|
162 |
catalogIds = $("#catalogids").val();
|
| - |
|
163 |
}
|
| 158 |
if (confirm("Are you sure you want to Add Model to Scheme!") == true) {
|
164 |
if (!schemeIds || !catalogIds || catalogIds.trim().length === 0) {
|
| - |
|
165 |
alert("Scheme ID and at least one Model are required");
|
| - |
|
166 |
return;
|
| - |
|
167 |
}
|
| - |
|
168 |
// Filter out catalogs that already exist in the scheme
|
| - |
|
169 |
var existingCatalogs = [];
|
| - |
|
170 |
$('#scheme-details-container tr[data-catalogid]').each(function() {
|
| 159 |
if (catalogIds.trim().length === 0 || schemeIds.trim().length === 0) {
|
171 |
existingCatalogs.push(String($(this).data('catalogid')));
|
| - |
|
172 |
});
|
| 160 |
alert("fields shouldn't be blank");
|
173 |
var requestedIds = catalogIds.split(",");
|
| - |
|
174 |
var duplicates = requestedIds.filter(function(id) { return existingCatalogs.indexOf(id.trim()) >= 0; });
|
| - |
|
175 |
var newIds = requestedIds.filter(function(id) { return existingCatalogs.indexOf(id.trim()) < 0; });
|
| - |
|
176 |
if (newIds.length === 0) {
|
| - |
|
177 |
alert("All selected models already exist in this scheme");
|
| 161 |
return;
|
178 |
return;
|
| - |
|
179 |
}
|
| - |
|
180 |
if (duplicates.length > 0) {
|
| - |
|
181 |
alert("Skipping already existing catalog IDs: " + duplicates.join(", "));
|
| 162 |
}
|
182 |
}
|
| - |
|
183 |
catalogIds = newIds.join(",");
|
| - |
|
184 |
if (confirm("Add " + newIds.length + " model(s) to Scheme?")) {
|
| 163 |
updateSingleScheme(schemeIds, catalogIds);
|
185 |
updateSingleScheme(schemeIds, catalogIds);
|
| 164 |
}
|
186 |
}
|
| 165 |
});
|
187 |
});
|
| 166 |
$(document).on('click', ".add-schemes", function() {
|
188 |
$(document).on('click', ".add-schemes", function() {
|
| 167 |
|
189 |
|
| Line 493... |
Line 515... |
| 493 |
response) {
|
515 |
response) {
|
| 494 |
$('.imei-wise-income-container').html(response);
|
516 |
$('.imei-wise-income-container').html(response);
|
| 495 |
});
|
517 |
});
|
| 496 |
}
|
518 |
}
|
| 497 |
|
519 |
|
| - |
|
520 |
function toIsoDateTime(ddmmyyyy, endOfDay) {
|
| - |
|
521 |
var parts = ddmmyyyy.split('/');
|
| - |
|
522 |
if (parts.length !== 3) return ddmmyyyy;
|
| - |
|
523 |
var isoDate = parts[2] + '-' + parts[1] + '-' + parts[0];
|
| - |
|
524 |
return isoDate + (endOfDay ? 'T23:59:59' : 'T00:00:00');
|
| - |
|
525 |
}
|
| - |
|
526 |
|
| 498 |
function updateSingleScheme(shcemeIds, catalogIds) {
|
527 |
function updateSingleScheme(schemeIds, catalogIds) {
|
| - |
|
528 |
var payload = {
|
| - |
|
529 |
"catalogIds": catalogIds.split(",").map(Number),
|
| - |
|
530 |
"schemeIds": schemeIds.split(",").map(Number)
|
| - |
|
531 |
};
|
| - |
|
532 |
var startDate = $('#addItemStartDate').val();
|
| - |
|
533 |
var endDate = $('#addItemEndDate').val();
|
| - |
|
534 |
if (startDate) payload.startDate = toIsoDateTime(startDate, false);
|
| - |
|
535 |
if (endDate) payload.endDate = toIsoDateTime(endDate, true);
|
| 499 |
doPostAjaxRequestWithJsonHandler(context + '/addItemToScheme', JSON
|
536 |
doPostAjaxRequestWithJsonHandler(context + '/addItemToScheme', JSON
|
| 500 |
.stringify({
|
- |
|
| 501 |
"catalogIds": catalogIds.split(",").map(Number),
|
- |
|
| 502 |
"schemeIds": schemeIds.split(",").map(Number)
|
- |
|
| 503 |
}), function(response) {
|
537 |
.stringify(payload), function(response) {
|
| 504 |
if (response == 'true') {
|
- |
|
| 505 |
alert("Item Added to scheme successfully");
|
- |
|
| 506 |
// $('#newItemToSchemeModal').modal('hide');
|
538 |
$('#newItemToSchemeModal').modal('hide');
|
| 507 |
loadSchemeDetails(shcemeIds, "scheme-details-container");
|
- |
|
| 508 |
} else {
|
- |
|
| 509 |
alert("Item already present");
|
539 |
alert("Item Added to scheme successfully");
|
| 510 |
loadSchemeDetails(shcemeIds, "scheme-details-container");
|
540 |
loadSchemeDetails(schemeIds, "scheme-details-container");
|
| 511 |
}
|
- |
|
| 512 |
});
|
541 |
});
|
| 513 |
}
|
542 |
}
|
| 514 |
|
543 |
|
| 515 |
function updateSchemes(schemeIds, catalogIds) {
|
544 |
function updateSchemes(schemeIds, catalogIds) {
|
| 516 |
doPostAjaxRequestWithJsonHandler(context + '/schemes/update', JSON
|
545 |
doPostAjaxRequestWithJsonHandler(context + '/schemes/update', JSON
|