Subversion Repositories SmartDukaan

Rev

Rev 37823 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37823 Rev 37846
Line 2... Line 2...
2
// round trip. A refused request comes back as a 400 whose text the ajax helpers show as is.
2
// round trip. A refused request comes back as a 400 whose text the ajax helpers show as is.
3
var SellerSetup = (function () {
3
var SellerSetup = (function () {
4
 
4
 
5
    var GSTIN = /^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][0-9A-Z]Z[0-9A-Z]$/;
5
    var GSTIN = /^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][0-9A-Z]Z[0-9A-Z]$/;
6
 
6
 
7
    function loadPage() {
7
    function loadPage(then) {
8
        doGetAjaxRequestHandler(context + "/getAllSeller", function (response) {
8
        doGetAjaxRequestHandler(context + "/getAllSeller", function (response) {
9
            $('#main-content').html(response);
9
            $('#main-content').html(response);
-
 
10
            formatAmounts();
-
 
11
            if (typeof then === 'function') {
-
 
12
                then();
-
 
13
            }
10
        });
14
        });
11
    }
15
    }
12
 
16
 
13
    function loadSeller(sellerId) {
17
    function loadSeller(sellerId) {
14
        doGetAjaxRequestHandler(context + "/getSellerWareHouse?sellerId=" + sellerId, function (response) {
18
        doGetAjaxRequestHandler(context + "/getSellerWareHouse?sellerId=" + sellerId, function (response) {
15
            $('.seller-setup .warehouse-container').html(response);
19
            var container = $('.seller-setup .warehouse-container');
-
 
20
            container.html(response);
-
 
21
            $('html, body').animate({scrollTop: container.offset().top - 60}, 200);
-
 
22
        });
-
 
23
    }
-
 
24
 
-
 
25
    // Reload the page so the overview, counts and an open seller panel all show the change.
-
 
26
    function reload() {
-
 
27
        var sellerId = currentSellerId();
-
 
28
        loadPage(sellerId ? function () {
-
 
29
            loadSeller(sellerId);
-
 
30
        } : null);
-
 
31
    }
-
 
32
 
-
 
33
    function formatAmounts() {
-
 
34
        $('.seller-setup .inr').each(function () {
-
 
35
            var amount = parseInt($(this).text(), 10);
-
 
36
            if (!isNaN(amount)) {
-
 
37
                $(this).text(amount.toLocaleString('en-IN'));
-
 
38
            }
16
        });
39
        });
17
    }
40
    }
18
 
41
 
-
 
42
    var STATUS_EFFECT = {
-
 
43
        ACTIVE: 'It shows on dashboards and in warehouse screens, and partner stores can be assigned to it.',
-
 
44
        SUSPENDED: 'It leaves dashboards and takes no new orders, but stays in warehouse screens so its stock and'
-
 
45
            + ' returns can be cleared. Refused while franchise stores or brand mapping still point at it.',
-
 
46
        INACTIVE: 'It is closed for good: hidden everywhere except the name on old records. Refused while it'
-
 
47
            + ' holds stock, has unshipped orders, or franchise stores or brand mapping still point at it.'
-
 
48
    };
-
 
49
 
19
    function currentSellerId() {
50
    function currentSellerId() {
20
        return $('.seller-warehouses').data('seller-id');
51
        return $('.seller-warehouses').data('seller-id');
21
    }
52
    }
22
 
53
 
23
    // A page or panel reload replaces the modal's markup, so wait until it has closed and its backdrop is gone.
54
    // A page or panel reload replaces the modal's markup, so wait until it has closed and its backdrop is gone.
Line 163... Line 194...
163
                loadSeller(sellerId);
194
                loadSeller(sellerId);
164
            });
195
            });
165
        });
196
        });
166
    }
197
    }
167
 
198
 
-
 
199
    function setStatus(select) {
-
 
200
        var warehouseId = select.data('warehouse-id');
-
 
201
        var current = String(select.data('current'));
-
 
202
        var status = select.val();
-
 
203
        if (status === current) {
-
 
204
            return;
-
 
205
        }
-
 
206
        if (!confirm('Mark warehouse ' + warehouseId + ' ' + status + '?\n\n' + STATUS_EFFECT[status])) {
-
 
207
            select.val(current);
-
 
208
            return;
-
 
209
        }
-
 
210
        // A refusal comes back as a 400 the ajax helper shows; put the dropdown back until the page reloads.
-
 
211
        select.val(current);
-
 
212
        doPostAjaxRequestHandler(context + '/physicalWarehouse/' + warehouseId + '/status?status=' + status, reload);
-
 
213
    }
-
 
214
 
168
    function toggleWarehouse(button) {
215
    function rename(button) {
169
        var warehouseId = button.data('warehouse-id');
216
        var warehouseId = button.data('warehouse-id');
170
        var activate = String(button.data('active')) !== 'true';
217
        var label = prompt('Label for warehouse ' + warehouseId + ' (shown on dashboards, dropdowns and reports)',
171
        if (!activate && !confirm('Deactivate warehouse ' + warehouseId + '? It stops being offered as an active'
218
            button.data('display-name') || '');
172
            + ' physical warehouse. Stock, billing and history are not touched.')) {
219
        if (label === null || $.trim(label) === '' || $.trim(label) === String(button.data('display-name'))) {
173
            return;
220
            return;
174
        }
221
        }
-
 
222
        doPostAjaxRequestHandler(context + '/physicalWarehouse/' + warehouseId + '/displayName?displayName='
-
 
223
            + encodeURIComponent($.trim(label)), reload);
-
 
224
    }
-
 
225
 
-
 
226
    function filterStatus(button) {
175
        var sellerId = currentSellerId();
227
        var status = button.data('status');
-
 
228
        button.addClass('active').siblings().removeClass('active');
-
 
229
        $('.warehouse-overview tbody tr').each(function () {
-
 
230
            $(this).toggle(!status || $(this).data('status') === status);
-
 
231
        });
-
 
232
    }
-
 
233
 
-
 
234
    function sendStockAlert() {
176
        doPostAjaxRequestHandler(context + '/physicalWarehouse/' + warehouseId + '/active?active=' + activate,
235
        if (!confirm('Mail logistics, finance and leadership the stock lying in suspended or inactive warehouses'
177
            function () {
236
            + ' now?')) {
-
 
237
            return;
-
 
238
        }
-
 
239
        doPostAjaxRequestHandler(context + '/warehouseStockAlert/send', function (response) {
-
 
240
            var result = typeof response === 'string' ? JSON.parse(response) : response;
178
                loadSeller(sellerId);
241
            alert(result.summary || 'Done');
179
            });
242
        });
180
    }
243
    }
181
 
244
 
182
    function remapAddress() {
245
    function remapAddress() {
183
        var sellerId = currentSellerId();
246
        var sellerId = currentSellerId();
184
        var warehouseId = $('#remap-address-modal').data('warehouse-id');
247
        var warehouseId = $('#remap-address-modal').data('warehouse-id');
Line 215... Line 278...
215
        renderAddressPreview: renderAddressPreview,
278
        renderAddressPreview: renderAddressPreview,
216
        renderGstinHint: renderGstinHint,
279
        renderGstinHint: renderGstinHint,
217
        createAddress: createAddress,
280
        createAddress: createAddress,
218
        createSeller: createSeller,
281
        createSeller: createSeller,
219
        createWarehouse: createWarehouse,
282
        createWarehouse: createWarehouse,
-
 
283
        setStatus: setStatus,
-
 
284
        rename: rename,
220
        toggleWarehouse: toggleWarehouse,
285
        filterStatus: filterStatus,
-
 
286
        sendStockAlert: sendStockAlert,
221
        remapAddress: remapAddress,
287
        remapAddress: remapAddress,
222
        toggleAddress: toggleAddress
288
        toggleAddress: toggleAddress
223
    };
289
    };
224
})();
290
})();
225
 
291
 
Line 242... Line 308...
242
    SellerSetup.createSeller();
308
    SellerSetup.createSeller();
243
});
309
});
244
$(document).on('click', '#new-warehouse-submit', function () {
310
$(document).on('click', '#new-warehouse-submit', function () {
245
    SellerSetup.createWarehouse();
311
    SellerSetup.createWarehouse();
246
});
312
});
-
 
313
$(document).on('change', '.seller-setup .warehouse-status', function () {
-
 
314
    SellerSetup.setStatus($(this));
-
 
315
});
247
$(document).on('click', '.seller-setup .warehouse-active-toggle', function () {
316
$(document).on('click', '.seller-setup .warehouse-rename', function () {
-
 
317
    SellerSetup.rename($(this));
-
 
318
});
-
 
319
$(document).on('click', '.seller-setup .warehouse-status-filter .btn', function () {
248
    SellerSetup.toggleWarehouse($(this));
320
    SellerSetup.filterStatus($(this));
-
 
321
});
-
 
322
$(document).on('click', '.seller-setup .warehouse-stock-alert', function () {
-
 
323
    SellerSetup.sendStockAlert();
249
});
324
});
250
$(document).on('click', '.seller-setup .address-active-toggle', function () {
325
$(document).on('click', '.seller-setup .address-active-toggle', function () {
251
    SellerSetup.toggleAddress($(this));
326
    SellerSetup.toggleAddress($(this));
252
});
327
});
253
$(document).on('click', '.seller-setup .warehouse-remap-open', function () {
328
$(document).on('click', '.seller-setup .warehouse-remap-open', function () {