Subversion Repositories SmartDukaan

Rev

Rev 35965 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
33213 tejus.loha 1
$(function () {
2
    $(document).on('click', ".placement-plan", function () {
3
        loadPlacementPlan("main-content");
4
    });
28005 tejbeer 5
 
33213 tejus.loha 6
    $(document).on('click', ".bulk-order", function () {
7
        loadBulkOrder("main-content");
8
    });
9
    $(document).on('click', ".transaction-approval", function () {
10
        doGetAjaxRequestHandler(context + "/transaction/pendingApprovals", function (response) {
11
            $("#main-content").html(response);
12
        });
13
    });
35965 amit 14
    $(document).on('click', ".bulk-order-approval-report", function () {
15
        doGetAjaxRequestHandler(context + "/transaction/bulkOrderApprovalReport", function (response) {
16
            $("#main-content").html(response);
17
        });
18
    });
19
    $(document).on('click', ".fetch-approval-report", function () {
20
        var startDate = $('#reportStartDate').val();
21
        var endDate = $('#reportEndDate').val();
22
        doGetAjaxRequestHandler(context + "/transaction/bulkOrderApprovalReport?startDate=" + startDate + "&endDate=" + endDate, function (response) {
23
            $("#main-content").html(response);
24
        });
25
    });
33213 tejus.loha 26
    $(document).on('click', ".search-partner-stock",
27
        function () {
36404 amit 28
            var primary = $('.criteria-item-catalogids').val() || [];
29
            var tagged  = $('.criteria-item-tagged-models').val() || [];
30
            var union = Array.from(new Set(primary.concat(tagged)));
33172 tejus.loha 31
 
33213 tejus.loha 32
            var addValue = $('#addRange').val();
33
            var subValue = $('#subNumber').val();
34
            var startDateTime = getDatesFromPicker('input[name="saleDate"]').startDate;
35
            var warehouseId = $('#warehouseMap').val();
28477 tejbeer 36
 
33213 tejus.loha 37
            doGetAjaxRequestHandler(context
38
                + "/getPlacementPlanByCatalogId?catalogItemIds=" +
36404 amit 39
                union.join(",") + "&addValue=" + addValue + "&subValue=" + subValue + "&date=" + startDateTime + "&warehouseId=" + warehouseId,
33213 tejus.loha 40
                function (response) {
41
                    $('.placement-plan-detail').html(response);
42
                });
43
        });
28020 tejbeer 44
 
28005 tejbeer 45
 
33213 tejus.loha 46
    $(document).on('click', ".mk_fetch_plan",
47
        function () {
36404 amit 48
            var primary = $('.criteria-item-catalogids').val() || [];
49
            var tagged  = $('.criteria-item-tagged-models').val() || [];
50
            var union = Array.from(new Set(primary.concat(tagged)));
28005 tejbeer 51
 
33213 tejus.loha 52
            var addValue = $('#addRange').val();
53
            var subValue = $('#subNumber').val();
54
            var startDateTime = getDatesFromPicker('input[name="saleDate"]').startDate;
55
            var warehouseId = $('#warehouseMap').val();
29103 tejbeer 56
 
33213 tejus.loha 57
            window.location.href = context + "/placementPlan/statement?catalogItemIds=" +
36404 amit 58
                union.join(",") + "&addValue=" + addValue + "&subValue=" + subValue + "&date=" + startDateTime + "&warehouseId=" + warehouseId;
33213 tejus.loha 59
        });
29103 tejbeer 60
 
61
 
33213 tejus.loha 62
    $(document).on('click', ".resetValue",
63
        function () {
64
            $('#addRange').val(0);
65
            $('#subNumber').val(0);
66
        });
29103 tejbeer 67
 
33213 tejus.loha 68
    $(document).on('change', 'select.criteria-item-brands', function () {
69
        changed = true;
70
    });
71
    $(document).on('click', 'select.criteria-item-catalogids+div > button', function () {
72
        if (changed) {
73
            let brands = $('.criteria-item-brands').val();
74
            $brandsContainer = $(this);
35487 ranu 75
            var url = `${context}/statusWiseCatalogs?activeOnly=true&brands=${brands.join(",")}&categoryId=3&limit=0`;
36404 amit 76
            var $select = $('.criteria-item-catalogids');
77
            var $taggedSelect = $('.criteria-item-tagged-models');
33213 tejus.loha 78
            $select.html('');
36404 amit 79
            $taggedSelect.html('');
33213 tejus.loha 80
            if (brands.length > 0) {
81
                doGetAjaxRequestHandler(url, function (response) {
36404 amit 82
                    var data = JSON.parse(response);
83
 
84
                    for (var i = 0; i < data.length; i++) {
85
                        var d = data[i];
86
                        var cls = '';
87
                        if (d.monitor_type === 'focused') cls = 'monitor-focused';
88
                        else if (d.monitor_type === 'normal') cls = 'monitor-normal';
89
 
90
                        $select.append(`<option value="${d.catalogId_i}" data-monitor-type="${d.monitor_type || ''}" class="${cls}">${d.title_s}</option>`);
91
 
92
                        if (d.monitor_type === 'focused' || d.monitor_type === 'normal') {
93
                            $taggedSelect.append(
94
                                `<option value="${d.catalogId_i}" data-monitor-type="${d.monitor_type}" class="${cls}">${d.title_s}</option>`
95
                            );
96
                        }
33213 tejus.loha 97
                    }
36404 amit 98
 
33213 tejus.loha 99
                    $select.multiselect('rebuild');
36404 amit 100
                    $taggedSelect.multiselect('rebuild');
101
 
102
                    colorMultiselectRows();
33213 tejus.loha 103
                });
104
            } else {
105
                $select.multiselect('rebuild');
36404 amit 106
                $taggedSelect.multiselect('rebuild');
33213 tejus.loha 107
            }
108
            changed = !changed;
109
        }
110
    });
28020 tejbeer 111
 
36404 amit 112
    // Bootstrap-multiselect renders an <li> per option in a generated dropdown.
113
    // Re-apply the color class to each rendered <li> after rebuild so tagged options stay colored.
114
    function colorMultiselectRows() {
115
        $('.criteria-item-catalogids, .criteria-item-tagged-models').each(function () {
116
            var $sel = $(this);
117
            var $btnGroup = $sel.next('.btn-group');
118
            $btnGroup.find('li').each(function () {
119
                var $li = $(this);
120
                var $cb = $li.find('input[type="checkbox"]');
121
                var val = $cb.val();
122
                if (val == null) return;
123
                var $opt = $sel.find('option[value="' + val + '"]');
124
                var mt = $opt.attr('data-monitor-type');
125
                $li.removeClass('monitor-focused monitor-normal');
126
                if (mt === 'focused') $li.addClass('monitor-focused');
127
                else if (mt === 'normal') $li.addClass('monitor-normal');
128
            });
129
        });
130
    }
131
 
132
    $(document).on('click', '.monitor-type-upload-submit', function () {
133
        var fileInput = document.getElementById('monitorTypeUploadFile');
134
        var $status = $('#monitorTypeUploadStatus');
135
        $status.html('');
136
 
137
        if (!fileInput.files || fileInput.files.length === 0) {
138
            $status.html('<div class="alert alert-warning">Please choose a CSV file.</div>');
139
            return;
140
        }
141
        var fd = new FormData();
142
        fd.append('file', fileInput.files[0]);
143
 
144
        $.ajax({
145
            url: context + '/placementPlan/monitorType/upload',
146
            type: 'POST',
147
            data: fd,
148
            processData: false,
149
            contentType: false,
150
            success: function (resp) {
151
                $status.html('<div class="alert alert-success">Replaced ' + resp.deleted + ' rows, inserted ' + resp.inserted + ' rows.</div>');
152
            },
153
            error: function (xhr) {
154
                var msg = '<div class="alert alert-danger"><strong>Upload failed:</strong><ul>';
155
                try {
156
                    var body = JSON.parse(xhr.responseText);
157
                    if (body && body.errors) {
158
                        body.errors.forEach(function (e) { msg += '<li>' + $('<div>').text(e).html() + '</li>'; });
159
                    } else {
160
                        msg += '<li>' + xhr.statusText + '</li>';
161
                    }
162
                } catch (e) {
163
                    msg += '<li>' + xhr.statusText + '</li>';
164
                }
165
                msg += '</ul></div>';
166
                $status.html(msg);
167
            }
168
        });
169
    });
170
 
33213 tejus.loha 171
    $(document).on('change', '.criteria-item-catalogids', function () {
172
        var value = $('.criteria-item-catalogids ').val();
173
        console.log(value);
28085 tejbeer 174
 
33213 tejus.loha 175
    });
28085 tejbeer 176
 
28474 tejbeer 177
 
28005 tejbeer 178
});
179
 
28020 tejbeer 180
 
28005 tejbeer 181
function loadPlacementPlan(domId) {
33213 tejus.loha 182
    doGetAjaxRequestHandler(context + "/placementPlan",
183
        function (response) {
184
            $('#' + domId).html(response);
185
        });
28005 tejbeer 186
}
187
 
33172 tejus.loha 188
function loadBulkOrder(domId) {
33213 tejus.loha 189
    doGetAjaxRequestHandler(context + "/getBulkOrder",
190
        function (response) {
191
            $('#' + domId).html(response);
192
        });
33172 tejus.loha 193
}
28005 tejbeer 194
function addRange() {
33213 tejus.loha 195
    var addValue = $('#addRange').val();
196
    console.log(addValue);
197
    addValue = parseInt(addValue) + 500;
198
    $('#addRange').val(addValue);
28005 tejbeer 199
 
200
}
201
 
202
function subRange() {
33213 tejus.loha 203
    var subValue = $('#subNumber').val();
204
    console.log(subValue);
205
    subValue = parseInt(subValue) - 500;
206
    $('#subNumber').val(subValue);
28005 tejbeer 207
 
208
}