Subversion Repositories SmartDukaan

Rev

Rev 32358 | Rev 32361 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 32358 Rev 32360
Line 215... Line 215...
215
 
215
 
216
        $('tbody').append($html);
216
        $('tbody').append($html);
217
        getVendorItemAheadOptions($html.find('.typeaheaditem'), vendorId, function (
217
        getVendorItemAheadOptions($html.find('.typeaheaditem'), vendorId, function (
218
            selectedItem) {
218
            selectedItem) {
219
            var itemId = selectedItem.itemId;
219
            var itemId = selectedItem.itemId;
220
 
-
 
221
            if (purchaseItemIds.indexOf(itemId) > -1) {
220
            if (addItem($html, itemId)) {
-
 
221
                doGetAjaxRequestHandler(context + "/getPricing?vendorId=" + vendorId + "&itemId=" + itemId, function (response) {
222
                alert("item already added");
222
                    if (response !== "null") {
-
 
223
                        var jsonObj = JSON.parse(response);
-
 
224
                        $html.find('.transferPrice').val(jsonObj.transferPrice);
-
 
225
                        $html.find('input.qty').focus();
-
 
226
                    } else {
223
                $html.find('.typeaheaditem').val("");
227
                        $html.find('.typeaheaditem').val("");
224
 
-
 
-
 
228
                    }
-
 
229
                });
-
 
230
            } else {
225
                return false;
231
                return false;
226
            }
232
            }
227
 
-
 
228
            addItem($html, itemId);
-
 
229
 
-
 
230
 
-
 
231
            doGetAjaxRequestHandler(context + "/getPricing?vendorId=" + vendorId + "&itemId=" + itemId, function (response) {
-
 
232
                if (response !== "null") {
-
 
233
                    var jsonObj = JSON.parse(response);
-
 
234
                    $html.find('.transferPrice').val(jsonObj.transferPrice);
-
 
235
                    $html.find('input.qty').focus();
-
 
236
                } else {
-
 
237
                    $html.find('.typeaheaditem').val("");
-
 
238
                }
-
 
239
            });
-
 
240
 
-
 
241
        });
233
        });
242
 
234
 
243
    });
235
    });
244
 
236
 
245
    function addItem(container, itemId) {
237
    function addItem(container, itemId) {
246
        oldItem = container.find('.transferPrice').data('itemId');
238
        oldItemId = container.find('.transferPrice').data('itemId');
247
        if (typeof (oldItem) === "undefined" || oldItem !== itemId) {
239
        if (typeof (oldItemId) === "undefined") {
-
 
240
            let itemIndex = purchaseItemIds.indexOf(itemId);
-
 
241
            if (itemIndex >= 0) {
-
 
242
                alert("Item already added");
-
 
243
                $html.find('.typeaheaditem').val("");
-
 
244
                return false;
-
 
245
            } else {
248
            purchaseItemIds.push(itemId);
246
                purchaseItemIds.push(itemId);
249
            container.find('.transferPrice').data('itemId', itemId);
247
                container.find('.transferPrice').data('itemId', itemId);
250
            $('.addRowInPurchaseOrder').click();
248
                $('.addRowInPurchaseOrder').click();
-
 
249
            }
251
        } else {
250
        } else {
-
 
251
            if (oldItemId !== itemId) {
252
            let oldIndex = purchaseItemIds.indexOf(oldItem);
252
                let oldIndex = purchaseItemIds.indexOf(oldItemId);
253
            if (oldIndex > -1) {
253
                if (oldIndex > -1) {
254
                purchaseItemIds.splice(oldIndex, 1);
254
                    purchaseItemIds.splice(oldIndex, 1);
-
 
255
                }
-
 
256
                purchaseItemIds.push(itemId);
-
 
257
                container.find('.transferPrice').data('itemId', itemId);
255
            } else {
258
            } else {
256
                alert("Item already added");
259
                return false;
257
            }
260
            }
258
        }
261
        }
-
 
262
        return true;
259
    }
263
    }
260
 
264
 
261
    $(document).on('click', '.createSendPurchaseOrder', function () {
265
    $(document).on('click', '.createSendPurchaseOrder', function () {
262
 
266
 
263
        createPurchase(true);
267
        createPurchase(true);
Line 370... Line 374...
370
        });
374
        });
371
    });
375
    });
372
 
376
 
373
 
377
 
374
    $(document).on("click", '.removeInPurchaseOrder', function () {
378
    $(document).on("click", '.removeInPurchaseOrder', function () {
375
 
-
 
376
        var row = $(this).closest("tr");
379
        var row = $(this).closest("tr");
-
 
380
        let itemId = row.find('.transferPrice').data('itemId');
377
        let itemIndex = purchaseItemIds.indexOf();
381
        let itemIndex = purchaseItemIds.indexOf(itemId);
378
        if (itemIndex > -1) { // only splice array when item is found
382
        if (itemIndex > -1) { // only splice array when item is found
379
            purchaseItemIds.splice(itemIndex, 1); // 2nd parameter means remove one item only
383
            purchaseItemIds.splice(itemIndex, 1); // 2nd parameter means remove one item only
380
        }
384
        }
381
        row.remove();
385
        row.remove();
382
    });
386
    });
Line 385... Line 389...
385
    $(document).on('click', ".addRowForInvoiceItem", function () {
389
    $(document).on('click', ".addRowForInvoiceItem", function () {
386
 
390
 
387
        var numitems = $(this).data("numitems");
391
        var numitems = $(this).data("numitems");
388
        var invoiceId = $(this).data("invoiceid");
392
        var invoiceId = $(this).data("invoiceid");
389
        var invoiceItemIds = [];
393
        var invoiceItemIds = [];
390
        var totalQty = 0
394
        var totalQty = 0;
391
 
395
 
392
        $("#invoice-order-table > tbody > tr").each(function () {
396
        $("#invoice-order-table > tbody > tr").each(function () {
393
            var itemId = $(this).find(".rate").data('itemid');
397
            var itemId = $(this).find(".rate").data('itemid');
394
            var qty = $(this).find(".qty").val();
398
            var qty = $(this).find(".qty").val();
395
 
399
 
396
            if (qty != undefined) {
400
            if (qty !== undefined) {
397
                totalQty += qty
401
                totalQty += qty;
398
            }
402
            }
399
 
403
 
400
            if (itemId != undefined) {
404
            if (itemId !== undefined) {
401
                invoiceItemIds.push(itemId)
405
                invoiceItemIds.push(itemId);
402
            }
406
            }
403
        });
407
        });
404
 
408
 
405
        var $html = $('<tr>  <td>  <input type="text" class="form-control typeaheaditem"   autocomplete="off"  placeholder="Search Model"/> </td>' +
409
        var $html = $('<tr>  <td>  <input type="text" class="form-control typeaheaditem"   autocomplete="off"  placeholder="Search Model"/> </td>' +
406
            '<td>  <input type="number" class="form-control qty"  name = "qty" placeholder="Quantity"/> </td>' +
410
            '<td>  <input type="number" class="form-control qty"  name = "qty" placeholder="Quantity"/> </td>' +
Line 409... Line 413...
409
 
413
 
410
 
414
 
411
        getItemAheadOptions($html.find('.typeaheaditem'), true, function (
415
        getItemAheadOptions($html.find('.typeaheaditem'), true, function (
412
            selectedItem) {
416
            selectedItem) {
413
            var itemId = selectedItem.itemId;
417
            var itemId = selectedItem.itemId;
414
 
-
 
415
 
-
 
416
            console.log(invoiceItemIds)
-
 
417
 
-
 
418
            if (invoiceItemIds.indexOf(itemId) > -1) {
418
            if (invoiceItemIds.indexOf(itemId) > -1) {
419
                alert("Item already added");
419
                alert("Item already added");
420
                $html.find('.typeaheaditem').val("")
420
                $html.find('.typeaheaditem').val("")
421
 
421
 
422
                return false;
422
                return false;