| Line 579... |
Line 579... |
| 579 |
}
|
579 |
}
|
| 580 |
});
|
580 |
});
|
| 581 |
}
|
581 |
}
|
| 582 |
|
582 |
|
| 583 |
function askClosureConfirmation(domId, fofoId, storeCode) {
|
583 |
function askClosureConfirmation(domId, fofoId, storeCode) {
|
| 584 |
var inputCode = prompt("To also PERMANENTLY close this store (cannot be undone), type the store code: " + storeCode + "\n\nPress Cancel to skip.");
|
584 |
if (!confirm("Do you also want to PERMANENTLY close store " + storeCode + "? This cannot be undone.")) {
|
| 585 |
if (inputCode === null) {
|
- |
|
| 586 |
return;
|
585 |
return;
|
| 587 |
}
|
586 |
}
|
| - |
|
587 |
openStoreClosureModal(fofoId, storeCode, function() {
|
| - |
|
588 |
storeInfo(domId);
|
| - |
|
589 |
});
|
| - |
|
590 |
}
|
| - |
|
591 |
|
| - |
|
592 |
var STORE_CLOSURE_REASONS = [
|
| - |
|
593 |
["OUTSIDE_SOURCING", "Outside / GT sourcing"],
|
| - |
|
594 |
["CREDIT_DEFAULT", "SD Credit default"],
|
| - |
|
595 |
["FINANCIAL_STRESS", "Financial stress"],
|
| - |
|
596 |
["NON_PERFORMANCE", "Non-performance / low sales"],
|
| - |
|
597 |
["SERVICE_ISSUES", "Service issues"],
|
| - |
|
598 |
["PERSONAL_RELOCATION", "Partner personal / relocation"],
|
| - |
|
599 |
["AGREEMENT_BREACH", "Agreement breach"],
|
| - |
|
600 |
["OTHER", "Other"]
|
| - |
|
601 |
];
|
| - |
|
602 |
|
| - |
|
603 |
// Permanent closure needs a reason, a remark and the approval mail; the server re-checks all of them
|
| - |
|
604 |
// and mails the closure report with the approval attached.
|
| - |
|
605 |
function openStoreClosureModal(fofoId, storeCode, onClosed) {
|
| - |
|
606 |
$('#store-closure-modal').remove();
|
| - |
|
607 |
var reasonOptions = '<option value="">-- Select reason --</option>';
|
| - |
|
608 |
STORE_CLOSURE_REASONS.forEach(function(reason) {
|
| - |
|
609 |
reasonOptions += '<option value="' + reason[0] + '">' + reason[1] + '</option>';
|
| - |
|
610 |
});
|
| - |
|
611 |
var modal = $(
|
| - |
|
612 |
'<div class="modal fade" id="store-closure-modal" tabindex="-1" role="dialog">' +
|
| - |
|
613 |
'<div class="modal-dialog" role="document"><div class="modal-content">' +
|
| - |
|
614 |
'<div class="modal-header"><button type="button" class="close" data-dismiss="modal">×</button>' +
|
| - |
|
615 |
'<h4 class="modal-title">Permanently close store</h4></div>' +
|
| - |
|
616 |
'<div class="modal-body">' +
|
| - |
|
617 |
'<p class="text-danger">This cannot be undone. A closure report with the approval mail goes to the partner\'s Sales L2, Tarun, Kamini, Finance and you.</p>' +
|
| - |
|
618 |
'<div class="form-group"><label>Reason *</label><select class="form-control closure-reason">' + reasonOptions + '</select></div>' +
|
| - |
|
619 |
'<div class="form-group"><label>Remark *</label><textarea class="form-control closure-remark" rows="3" maxlength="1000"></textarea></div>' +
|
| - |
|
620 |
'<div class="form-group"><label>Approval mail * <small class="text-muted">(PDF or screenshot, max 5 MB)</small></label>' +
|
| - |
|
621 |
'<input type="file" class="form-control closure-approval" accept=".pdf,.png,.jpg,.jpeg"></div>' +
|
| - |
|
622 |
'<div class="form-group"><label>Type the store code <b class="closure-store-code"></b> to confirm *</label>' +
|
| - |
|
623 |
'<input type="text" class="form-control closure-code"></div>' +
|
| - |
|
624 |
'</div>' +
|
| - |
|
625 |
'<div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>' +
|
| - |
|
626 |
'<button type="button" class="btn btn-danger closure-submit">Close Store</button></div>' +
|
| - |
|
627 |
'</div></div></div>');
|
| - |
|
628 |
modal.find('.closure-store-code').text(storeCode);
|
| - |
|
629 |
$('body').append(modal);
|
| - |
|
630 |
modal.modal('show');
|
| - |
|
631 |
|
| - |
|
632 |
modal.find('.closure-submit').on('click', function() {
|
| - |
|
633 |
var reason = modal.find('.closure-reason').val();
|
| - |
|
634 |
var remark = $.trim(modal.find('.closure-remark').val());
|
| - |
|
635 |
var file = modal.find('.closure-approval')[0].files[0];
|
| - |
|
636 |
var code = $.trim(modal.find('.closure-code').val());
|
| - |
|
637 |
if (!reason) {
|
| - |
|
638 |
alert("Please select the reason for closure.");
|
| - |
|
639 |
return;
|
| - |
|
640 |
}
|
| 588 |
if (inputCode.trim() === "") {
|
641 |
if (remark === "") {
|
| 589 |
alert("Store code is required to confirm closure.");
|
642 |
alert("Please enter a remark explaining the closure.");
|
| - |
|
643 |
return;
|
| - |
|
644 |
}
|
| - |
|
645 |
if (!file) {
|
| - |
|
646 |
alert("Please attach the approval mail.");
|
| - |
|
647 |
return;
|
| - |
|
648 |
}
|
| 590 |
askClosureConfirmation(domId, fofoId, storeCode);
|
649 |
var rejection = uploadFileRejectionReason(file);
|
| - |
|
650 |
if (rejection) {
|
| - |
|
651 |
alert(rejection);
|
| 591 |
return;
|
652 |
return;
|
| 592 |
}
|
653 |
}
|
| 593 |
if (inputCode.trim() !== storeCode) {
|
654 |
if (code !== storeCode) {
|
| 594 |
alert("Store code does not match. Closure cancelled.");
|
655 |
alert("Store code does not match. Closure cancelled.");
|
| 595 |
return;
|
656 |
return;
|
| 596 |
}
|
657 |
}
|
| - |
|
658 |
var submitButton = $(this).prop('disabled', true);
|
| 597 |
doPostAjaxRequestHandler(context + "/closeStore?fofoId=" + fofoId + "&storeCode=" + encodeURIComponent(inputCode.trim()),
|
659 |
doAjaxUploadRequestHandler(context + '/document-upload', 'POST', file, function(uploadResponse) {
|
| - |
|
660 |
var params = {
|
| - |
|
661 |
fofoId: fofoId,
|
| 598 |
function(closeResponse) {
|
662 |
storeCode: code,
|
| - |
|
663 |
reason: reason,
|
| - |
|
664 |
remark: remark,
|
| - |
|
665 |
approvalDocumentId: uploadResponse.response.document_id
|
| - |
|
666 |
};
|
| - |
|
667 |
doPostAjaxRequestWithParamsHandler(context + '/closeStore', params, function(closeResponse) {
|
| - |
|
668 |
modal.modal('hide');
|
| 599 |
if (closeResponse == "true") {
|
669 |
if (closeResponse == "true") {
|
| 600 |
alert("Store permanently closed.");
|
670 |
alert("Store permanently closed. Closure report mailed.");
|
| 601 |
}
|
671 |
}
|
| - |
|
672 |
if (typeof onClosed === 'function') {
|
| 602 |
storeInfo(domId);
|
673 |
onClosed();
|
| - |
|
674 |
}
|
| - |
|
675 |
});
|
| - |
|
676 |
submitButton.prop('disabled', false);
|
| - |
|
677 |
}, function(xhr, msg) {
|
| - |
|
678 |
submitButton.prop('disabled', false);
|
| - |
|
679 |
alert("Approval mail upload failed: " + msg);
|
| 603 |
});
|
680 |
});
|
| - |
|
681 |
});
|
| 604 |
}
|
682 |
}
|
| - |
|
683 |
|
| 605 |
function activateStoreForever(domId, fofoId) {
|
684 |
function activateStoreForever(domId, fofoId) {
|
| 606 |
doPostAjaxRequestHandler(context + "/activateStoreForever?fofoId=" + fofoId,
|
685 |
doPostAjaxRequestHandler(context + "/activateStoreForever?fofoId=" + fofoId,
|
| 607 |
function(response) {
|
686 |
function(response) {
|
| 608 |
if (response == "true") {
|
687 |
if (response == "true") {
|
| 609 |
alert("successfully activated!");
|
688 |
alert("successfully activated!");
|