Subversion Repositories SmartDukaan

Rev

Rev 34149 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
34149 tejus.loha 1
$(document).on('click', '.mk-brand-commitment-panal', function () {
2
    doGetAjaxRequestHandler(`${context}/brand-commitment-panel`, function (response) {
3
        $(`#main-content`).html(response);
4
    });
5
});
6
 
7
$(document).on('change', '#commitBrand', function () {
8
    let retailerId = $('#partnerId').val();
9
    let brand = $('#commitBrand').val();
10
    doGetAjaxRequestHandler(`${context}/partner-brand-commitment?retailerId=${retailerId}&brand=${brand}`, function (response) {
11
        console.log("brand commit response ", response);
12
        let docStatus = response.docStatus;
13
        let partnerBrandCommitmentModel = response.partnerBrandCommitmentModel;
14
        $('input[name="commitmentAmount"]').val(partnerBrandCommitmentModel.commitment);
15
        $('input[name="nocDocId"]').val(partnerBrandCommitmentModel.noc);
16
        $('#CommitmentIsActive').prop('checked', partnerBrandCommitmentModel.active);
17
        updateValue();
18
 
19
        const selectElement = document.getElementById('nocRequired');
20
        selectElement.innerHTML = '<option selected disabled>Select Status</option>';
21
        docStatus.forEach(status => {
22
            const option = document.createElement('option');
23
            option.value = status;
24
            option.textContent = status;
25
            if (status == partnerBrandCommitmentModel.docStatus) {
26
                option.selected = true;
27
            }
28
            selectElement.appendChild(option);
29
        });
30
    });
31
});
32
 
33
$(document).on('input', '#noc-doc-file', function () {
34
    if (confirm('Confirm file upload ?')) {
35
        var file = this.files[0];
36
        uploadDocument(file, function (documentId) {
37
            $('#noc-doc-id').val(documentId);
38
        });
39
    }
40
});
41
 
42
$(document).on('click', '#mk-submit-commitment', function () {
43
    let retailerId = $('#partnerId').val();
44
    let brand = $('#commitBrand').val();
45
    let commitment = $('input[name="commitmentAmount"]').val();
46
    let nocDoc = $('input[name="nocDocId"]').val();
47
    let docStatus = $('#nocRequired').val();
48
    let commitIsActive = $('#CommitmentIsActive').val();
49
    if (docStatus == "RECEIVED") {
50
        if (!nocDoc) {
51
            alert("Please upload Document");
52
            return;
53
        }
54
    }
55
    if (confirm("Are you sure to submit Commitment")) {
56
        doPostAjaxRequestHandler(`${context}/submit-commitment?retailerId=${retailerId}&brand=${brand}&commitment=${commitment}&nocDoc=${nocDoc}&docStatus=${docStatus}&active=${commitIsActive}`, function (response) {
57
            if (response) {
58
                alert("Commitment submit successfully");
59
                getAllCommitments(retailerId, function (commitment) {
60
                    resetField();
61
                    $('#brand-commitments-report').empty();
62
                    $('#brand-commitments-report').html(commitment);
63
                });
64
            } else {
65
                alert("Commitment not submit, Please try again.");
66
            }
67
        });
68
    }
69
});
70
 
34168 tejus.loha 71
function getAllCommitments(retailerIdOrStoreCode, callback) {
72
    doGetAjaxRequestHandler(`${context}/partner-commitments?retailerIdOrStoreCode=${retailerIdOrStoreCode}`, function (commitment) {
34149 tejus.loha 73
        callback(commitment);
74
    });
75
}
76
 
77
function resetField() {
78
    $('#commitBrand').prop('selectedIndex', 0);
79
    $('input[name="commitmentAmount"]').val('');
80
    $('#noc-doc-id').val('');
81
    $('#noc-doc-file').val('');
82
    $('#nocRequired').prop('selectedIndex', 0);
83
    $('#CommitmentIsActive').prop('checked', false);
84
}
85
 
86
function updateValue() {
87
    const checkbox = document.getElementById('CommitmentIsActive');
88
    let value = checkbox.checked ? 'True' : 'False';
89
    $('#CommitmentIsActive').val(value);
90
}
91