Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
32352 amit.gupta 1
$(function () {
2
    $(document).on('click', ".warehouse-create-purchase-order", function () {
3
        loadCreatePurchase("main-content");
4
    });
32145 tejbeer 5
 
32352 amit.gupta 6
    $(document).on('click', ".warehouse-receive-new-invoice", function () {
7
        loadNewReceiveInvoice("main-content");
8
    });
32145 tejbeer 9
 
32192 tejbeer 10
 
32352 amit.gupta 11
    $(document).on('click', ".warehouse-grn-request", function () {
12
        loadGrnRequest("main-content");
13
    });
32192 tejbeer 14
 
32300 tejbeer 15
 
32352 amit.gupta 16
    $(document).on('click', ".warehouse-debit-note", function () {
17
        loadDebitNote("main-content");
18
    });
32192 tejbeer 19
 
20
 
32352 amit.gupta 21
    $(document).on('click', ".warehouse-invoices", function () {
22
        loadWarehouseInvoices("main-content");
23
    });
32256 tejbeer 24
 
32300 tejbeer 25
 
32352 amit.gupta 26
    $(document).on('click', '.dateWiseInvoices', function () {
32300 tejbeer 27
 
32352 amit.gupta 28
        var startDate = getDatesFromPicker('input[name="invoice-duration"]').startDate;
29
        var endDate = getDatesFromPicker('input[name="invoice-duration"]').endDate
32300 tejbeer 30
 
32352 amit.gupta 31
        var vendorId = $('#vendorId').val();
32300 tejbeer 32
 
32352 amit.gupta 33
        doGetAjaxRequestHandler(context + "/getWarehouseInvoicesByVendor?vendorId=" + vendorId + "&startDate=" + startDate + "&endDate=" + endDate, function (response) {
34
            $('.invoicesviewcontainer').html(response);
32300 tejbeer 35
 
32352 amit.gupta 36
        });
32300 tejbeer 37
 
38
 
32352 amit.gupta 39
    });
32300 tejbeer 40
 
41
 
32352 amit.gupta 42
    $(document)
43
        .on(
44
            'input',
45
            '#invoice',
46
            function () {
47
                if (confirm('Document has been selected, Do you want to upload ?')) {
48
                    var fileSelector = $('#invoice')[0];
49
                    if (fileSelector != undefined
50
                        && fileSelector.files[0] != undefined) {
51
                        var url = context + '/document-upload';
32300 tejbeer 52
 
32352 amit.gupta 53
                        console.log(url);
54
                        var file = this.files[0];
55
                        doAjaxUploadRequestHandler(
56
                            url,
57
                            'POST',
58
                            file,
59
                            function (response) {
60
                                console.log(response);
61
                                var documentId = response.response.document_id;
62
                                console.log("documentId : "
63
                                    + documentId);
64
                                localStorage.setItem("invoiceDocument",
65
                                    documentId);
32192 tejbeer 66
 
32295 tejbeer 67
 
32352 amit.gupta 68
                            });
32300 tejbeer 69
 
32352 amit.gupta 70
                    }
71
                } else {
72
                    // Do nothing!
73
                }
74
            });
32192 tejbeer 75
 
32352 amit.gupta 76
    $(document).on('click', ".createReceiveInvoice", function () {
32192 tejbeer 77
 
32352 amit.gupta 78
        var invoiceDate = $('#actualDate').val();
32192 tejbeer 79
 
32352 amit.gupta 80
        var warehouseId = $('#warehouseMap').val();
32192 tejbeer 81
 
32352 amit.gupta 82
        var numItems = $('#numberofItems').val();
32192 tejbeer 83
 
32352 amit.gupta 84
        var supplierId = $('#vendorId').val();
32192 tejbeer 85
 
32352 amit.gupta 86
        var totalValue = $('#totalValue').val();
32192 tejbeer 87
 
32352 amit.gupta 88
        var invoiceNumber = $('#invoiceNumber').val();
32192 tejbeer 89
 
90
 
32352 amit.gupta 91
        var invoiceDoc = localStorage
92
            .getItem("invoiceDocument");
32192 tejbeer 93
 
94
 
32352 amit.gupta 95
        console.log(invoiceDoc)
32192 tejbeer 96
 
97
 
32629 amit.gupta 98
        if (invoiceDate === "" && warehouseId === "" && numItems === "" && supplierId === "" && totalValue === "" && invoiceNumber === "" && invoiceDoc === "") {
32352 amit.gupta 99
            alert("Field can't be empty");
100
            return false;
101
        }
32192 tejbeer 102
 
32629 amit.gupta 103
 
104
        if (invoiceDate === "") {
105
            alert("please select date");
106
            return false;
107
        }
108
        if (warehouseId === "") {
109
            alert("please choose warehouse");
110
            return false;
111
        }
112
 
113
        if (numItems === "") {
114
            alert("please fill number of items.");
115
            return false;
116
        }
117
 
118
 
119
        if (supplierId === "") {
120
            alert("please choose supplier");
121
            return false;
122
        }
123
 
124
 
125
        if (totalValue === "") {
126
            alert("please fill Total Value.");
127
            return false;
128
        }
129
 
130
        if (invoiceNumber === "") {
131
            alert("please fill Invoice Number.");
132
            return false;
133
        }
134
 
135
 
136
        if (invoiceDoc === "") {
137
            alert("please upload invoice.");
138
            return false;
139
        }
32352 amit.gupta 140
        var newReceiveInvoice = {};
32192 tejbeer 141
 
32352 amit.gupta 142
        newReceiveInvoice['invoiceDate'] = invoiceDate;
32629 amit.gupta 143
        newReceiveInvoice['warehouseId'] = warehouseId;
144
        newReceiveInvoice['numItems'] = numItems;
145
        newReceiveInvoice['supplierId'] = supplierId;
146
        newReceiveInvoice['totalValue'] = totalValue;
147
        newReceiveInvoice['invoiceNumber'] = invoiceNumber;
148
        newReceiveInvoice['invoiceDoc'] = invoiceDoc;
32192 tejbeer 149
 
32629 amit.gupta 150
        if (confirm("Are you sure you want to add new Invoice")) {
32192 tejbeer 151
 
32390 amit.gupta 152
            doPostAjaxRequestWithJsonHandler(`${context}/newReceiveInvoice`, JSON
32352 amit.gupta 153
                .stringify(newReceiveInvoice), function (response) {
154
                if (response == 'true') {
155
                    alert("successfully added");
156
                    localStorage.removeItem("invoiceDocument");
157
                    loadNewReceiveInvoice("main-content");
158
                }
159
            });
160
        }
32295 tejbeer 161
 
32192 tejbeer 162
 
32352 amit.gupta 163
    });
32192 tejbeer 164
 
165
 
32352 amit.gupta 166
    var purchaseItemIds;
167
    $(document).on('click', ".purchaseorderitemview", function () {
168
        purchaseItemIds = [];
169
        var vendorId = $('#vendorId').val();
170
        var warehouseId = $('#warehouseMap').val();
32390 amit.gupta 171
        var poDate = $('#poDate').val();
32192 tejbeer 172
 
32352 amit.gupta 173
        console.log(warehouseId);
32192 tejbeer 174
 
32352 amit.gupta 175
        if (warehouseId === null && vendorId === "") {
176
            alert("Field can't be empty");
177
            return;
178
        }
32192 tejbeer 179
 
32390 amit.gupta 180
        if (poDate === '') {
181
            alert("PO Date is required");
182
            return;
183
        }
184
 
185
        if (warehouseId === null && vendorId === "") {
186
            alert("Field can't be empty");
187
            return;
188
        }
189
 
32352 amit.gupta 190
        if (warehouseId === null) {
191
            alert("please select warehouse");
192
            return;
193
        }
194
        if (vendorId === "") {
195
            alert("please select vendor");
196
            return;
197
        }
198
        doGetAjaxRequestHandler(context + "/addPurchaseItemView?warehouseId=" + warehouseId + "&vendorId=" + vendorId, function (response) {
199
            $(".createpurchaseordercontainer").html(response);
200
        });
201
    });
32192 tejbeer 202
 
32145 tejbeer 203
 
32352 amit.gupta 204
    $(document).on('click', ".addRowInPurchaseOrder", function () {
205
        var totalQty = 0;
32145 tejbeer 206
 
32358 amit.gupta 207
        $("table > tbody > tr").each(function () {
32352 amit.gupta 208
            var itemId = $(this).find(".transferPrice").data('itemid');
209
            var qty = $(this).find(".qty").val();
32145 tejbeer 210
 
32352 amit.gupta 211
            console.log(qty);
32145 tejbeer 212
 
32352 amit.gupta 213
            if (qty !== undefined) {
214
                totalQty += parseInt(qty);
215
            }
216
            console.log(totalQty);
32358 amit.gupta 217
        });
32145 tejbeer 218
 
32603 raveendra. 219
        var $html = $(`<tr>
220
        <td>  <input type="text" class="form-control typeaheaditem"   autocomplete="off"  placeholder="Search Model"/> </td>
221
        <td>  <input type="number" class="form-control qty"  name = "qty" placeholder="Quantity"/> </td>
222
        <td>  <input type="number" class="form-control transferPrice"  readonly tabindex="-1" placeholder="Transfer Price"/> </td>
223
        <td>  <input type="number" class="form-control totalValue" tabindex="-1"  readonly placeholder="Total Value"/> </td>
224
        <td> <input class="form-control btn btn-primary removeInPurchaseOrder" tabindex="-1" type="button" value="Remove"></td>
225
        </tr> `);
32192 tejbeer 226
 
32352 amit.gupta 227
        var vendorId = $('#vendorId').val();
32192 tejbeer 228
 
32352 amit.gupta 229
        $('tbody').append($html);
32629 amit.gupta 230
        getVendorItemAheadOptions($('tbody > tr').find('.typeaheaditem'), vendorId, function (
32352 amit.gupta 231
            selectedItem) {
32488 amit.gupta 232
            let poDate = $('#poDate').val();
32352 amit.gupta 233
            var itemId = selectedItem.itemId;
32360 amit.gupta 234
            if (addItem($html, itemId)) {
32488 amit.gupta 235
                doGetAjaxRequestHandler(`${context}/getPricing?vendorId=${vendorId}&itemId=${itemId}&onDate=${poDate}`, function (response) {
32360 amit.gupta 236
                    if (response !== "null") {
237
                        var jsonObj = JSON.parse(response);
238
                        $html.find('.transferPrice').val(jsonObj.transferPrice);
239
                        $html.find('input.qty').focus();
240
                    } else {
241
                        $html.find('.typeaheaditem').val("");
242
                    }
243
                });
244
            } else {
32352 amit.gupta 245
                return false;
246
            }
247
        });
32145 tejbeer 248
 
32352 amit.gupta 249
    });
32145 tejbeer 250
 
32355 amit.gupta 251
    function addItem(container, itemId) {
32361 amit.gupta 252
        oldItemId = container.find('.transferPrice').data('itemid');
32360 amit.gupta 253
        if (typeof (oldItemId) === "undefined") {
254
            let itemIndex = purchaseItemIds.indexOf(itemId);
255
            if (itemIndex >= 0) {
256
                alert("Item already added");
32376 amit.gupta 257
                container.find('.typeaheaditem').val("");
32360 amit.gupta 258
                return false;
259
            } else {
260
                purchaseItemIds.push(itemId);
32361 amit.gupta 261
                container.find('.transferPrice').data('itemid', itemId);
32360 amit.gupta 262
                $('.addRowInPurchaseOrder').click();
263
            }
32352 amit.gupta 264
        } else {
32360 amit.gupta 265
            if (oldItemId !== itemId) {
266
                let oldIndex = purchaseItemIds.indexOf(oldItemId);
267
                if (oldIndex > -1) {
268
                    purchaseItemIds.splice(oldIndex, 1);
269
                }
270
                purchaseItemIds.push(itemId);
32361 amit.gupta 271
                container.find('.transferPrice').data('itemid', itemId);
32358 amit.gupta 272
            } else {
32360 amit.gupta 273
                return false;
32352 amit.gupta 274
            }
275
        }
32360 amit.gupta 276
        return true;
32352 amit.gupta 277
    }
32145 tejbeer 278
 
32352 amit.gupta 279
    $(document).on('click', '.createSendPurchaseOrder', function () {
32145 tejbeer 280
 
32390 amit.gupta 281
        createPO(true);
32145 tejbeer 282
 
32352 amit.gupta 283
    });
32145 tejbeer 284
 
285
 
32352 amit.gupta 286
    $(document).on('click', '.createPurchaseOrder', function () {
32145 tejbeer 287
 
288
 
32390 amit.gupta 289
        createPO(false);
32352 amit.gupta 290
    });
32145 tejbeer 291
 
292
 
32352 amit.gupta 293
    $(document).on('change', '.qty', function () {
32145 tejbeer 294
 
295
 
32352 amit.gupta 296
        var row = $(this).closest("tr");
297
        var qty = $(row).find(".qty").val();
298
        var transferPrice = $(row).find(".transferPrice").val();
32145 tejbeer 299
 
32352 amit.gupta 300
        var totalVal = transferPrice * qty;
32145 tejbeer 301
 
32352 amit.gupta 302
        var totalValue = $(row).find(".totalValue").val(totalVal);
32145 tejbeer 303
 
32352 amit.gupta 304
        var purchaseOrderValue = 0;
32145 tejbeer 305
 
32352 amit.gupta 306
        $("table > tbody > tr").each(function () {
32145 tejbeer 307
 
32352 amit.gupta 308
            var totalValue = $(this).find(".totalValue").val();
32358 amit.gupta 309
            purchaseOrderValue += totalValue;
32145 tejbeer 310
 
32352 amit.gupta 311
        });
32145 tejbeer 312
 
32352 amit.gupta 313
    });
32145 tejbeer 314
 
315
 
32352 amit.gupta 316
    $(document).on('click', '.warehouse-open-purchase-order', function () {
317
        loadOpenPurchase("main-content");
318
    });
32145 tejbeer 319
 
320
 
32352 amit.gupta 321
    $(document).on('click', '.editViewPurchaseOrder', function () {
322
        var purchaseOrderId = $(this).data('poid');
323
        doGetAjaxRequestHandler(context + "/getEditPOByPurchaseId?purchaseId=" + purchaseOrderId, function (response) {
324
            $('#warehouseEditPurchaseContainer .modal-content').html(response);
325
        });
32145 tejbeer 326
 
32352 amit.gupta 327
    });
32145 tejbeer 328
 
32352 amit.gupta 329
    $(document).on('click', '.editPurchaseOrder', function () {
330
        var purchaseOrderId = $(this).data('poid');
32145 tejbeer 331
 
32352 amit.gupta 332
        editPurchase(false, purchaseOrderId);
32145 tejbeer 333
 
32352 amit.gupta 334
    });
32145 tejbeer 335
 
336
 
32352 amit.gupta 337
    $(document).on('click', '.editSendPurchaseOrder', function () {
338
        var purchaseOrderId = $(this).data('poid');
32145 tejbeer 339
 
340
 
32352 amit.gupta 341
        editPurchase(true, purchaseOrderId);
342
    });
32145 tejbeer 343
 
32352 amit.gupta 344
    $(document).on('click', '.closePurchaseOrder', function () {
345
        var purchaseOrderId = $(this).data('poid');
346
        if (confirm("Are you sure you want to close the PO") == true) {
347
            doPostAjaxRequestHandler(context + "/closePuchaseOrder?purchaseId=" + purchaseOrderId,
348
                function (response) {
32145 tejbeer 349
 
32352 amit.gupta 350
                    console.log(response);
351
                    if (response == 'true') {
352
                        alert("successfully closed");
353
                        loadOpenPurchase("main-content")
354
                    }
355
                });
356
        }
357
    });
32145 tejbeer 358
 
359
 
32352 amit.gupta 360
    $(document).on('click', '.warehouse-view-purchase-order', function () {
361
        doGetAjaxRequestHandler(context + "/viewPurchaseOrder", function (response) {
362
            $('#' + 'main-content').html(response);
363
        });
364
    });
32145 tejbeer 365
 
366
 
32352 amit.gupta 367
    $(document).on('click', '.dateWisePo', function () {
32145 tejbeer 368
 
32352 amit.gupta 369
        var startDate = getDatesFromPicker('input[name="duration"]').startDate;
370
        var endDate = getDatesFromPicker('input[name="duration"]').endDate
32145 tejbeer 371
 
372
 
32352 amit.gupta 373
        doGetAjaxRequestHandler(context + "/getPurchaseOrders?startDate=" + startDate + "&endDate=" + endDate, function (response) {
374
            $('.purchaseorderviewcontainer').html(response);
32145 tejbeer 375
 
32352 amit.gupta 376
        });
32145 tejbeer 377
 
378
 
32352 amit.gupta 379
    });
32145 tejbeer 380
 
381
 
32352 amit.gupta 382
    $(document).on('click', '.viewPurchaseOrderlineItem', function () {
383
        var purchaseOrderId = $(this).data('poid');
32145 tejbeer 384
 
32352 amit.gupta 385
        doGetAjaxRequestHandler(context + "/getWarehouseLineItemByPurchaseId?purchaseId=" + purchaseOrderId, function (response) {
386
            $('#warehouseLineItem .modal-content').html(response);
32145 tejbeer 387
 
32352 amit.gupta 388
        });
389
    });
32145 tejbeer 390
 
391
 
32352 amit.gupta 392
    $(document).on("click", '.removeInPurchaseOrder', function () {
393
        var row = $(this).closest("tr");
32361 amit.gupta 394
        let itemId = row.find('.transferPrice').data('itemid');
32360 amit.gupta 395
        let itemIndex = purchaseItemIds.indexOf(itemId);
32352 amit.gupta 396
        if (itemIndex > -1) { // only splice array when item is found
397
            purchaseItemIds.splice(itemIndex, 1); // 2nd parameter means remove one item only
398
        }
399
        row.remove();
400
    });
32192 tejbeer 401
 
402
 
32352 amit.gupta 403
    $(document).on('click', ".addRowForInvoiceItem", function () {
32145 tejbeer 404
 
32352 amit.gupta 405
        var numitems = $(this).data("numitems");
406
        var invoiceId = $(this).data("invoiceid");
407
        var invoiceItemIds = [];
32360 amit.gupta 408
        var totalQty = 0;
32145 tejbeer 409
 
32352 amit.gupta 410
        $("#invoice-order-table > tbody > tr").each(function () {
411
            var itemId = $(this).find(".rate").data('itemid');
412
            var qty = $(this).find(".qty").val();
32145 tejbeer 413
 
32360 amit.gupta 414
            if (qty !== undefined) {
415
                totalQty += qty;
32352 amit.gupta 416
            }
32145 tejbeer 417
 
32360 amit.gupta 418
            if (itemId !== undefined) {
419
                invoiceItemIds.push(itemId);
32352 amit.gupta 420
            }
421
        });
32145 tejbeer 422
 
32352 amit.gupta 423
        var $html = $('<tr>  <td>  <input type="text" class="form-control typeaheaditem"   autocomplete="off"  placeholder="Search Model"/> </td>' +
424
            '<td>  <input type="number" class="form-control qty"  name = "qty" placeholder="Quantity"/> </td>' +
32364 amit.gupta 425
            '<td>  <input type="number" class="form-control rate" placeholder="Rate"/> </td>' +
32352 amit.gupta 426
            '<td> <input class="form-control btn btn-primary removeInInvoiceItem" type="button" value="Remove"></td>  </tr> ');
32145 tejbeer 427
 
428
 
32352 amit.gupta 429
        getItemAheadOptions($html.find('.typeaheaditem'), true, function (
430
            selectedItem) {
431
            var itemId = selectedItem.itemId;
432
            if (invoiceItemIds.indexOf(itemId) > -1) {
433
                alert("Item already added");
434
                $html.find('.typeaheaditem').val("")
32145 tejbeer 435
 
32352 amit.gupta 436
                return false;
437
            }
438
            $html.find('.rate').data('itemid', itemId)
32145 tejbeer 439
 
32352 amit.gupta 440
            $html.find('.removeInInvoiceItem').data('invoiceid', invoiceId)
441
            $html.find('.removeInInvoiceItem').data('itemid', itemId)
32145 tejbeer 442
 
32352 amit.gupta 443
        });
32145 tejbeer 444
 
32192 tejbeer 445
 
32352 amit.gupta 446
        if (totalQty < numitems) {
32192 tejbeer 447
 
32352 amit.gupta 448
            $('#invoice-order-table tbody').append($html);
449
        }
32192 tejbeer 450
 
32352 amit.gupta 451
    });
32256 tejbeer 452
 
32192 tejbeer 453
 
32352 amit.gupta 454
    $(document).on('click', '.saveInvoiceDetail', function () {
32192 tejbeer 455
 
32352 amit.gupta 456
        var numItems = $(this).data("numitems");
457
        var invoiceId = $(this).data("invoiceid");
458
        var warehouseId = $(this).data("warehouseid");
459
        var supplierId = $(this).data("supplierid");
460
        getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, false);
32192 tejbeer 461
 
32352 amit.gupta 462
    });
32192 tejbeer 463
 
464
 
32352 amit.gupta 465
    $(document).on('click', '.validateInvoiceDetail', function () {
466
        var numItems = $(this).data("numitems");
467
        var invoiceId = $(this).data("invoiceid");
468
        var warehouseId = $(this).data("warehouseid");
469
        var supplierId = $(this).data("supplierid");
32192 tejbeer 470
 
32352 amit.gupta 471
        getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, true);
32192 tejbeer 472
 
32352 amit.gupta 473
    });
32192 tejbeer 474
 
475
 
32352 amit.gupta 476
    $(document).on("click", '.removeInInvoiceItem', function () {
32192 tejbeer 477
 
32352 amit.gupta 478
        var row = $(this).closest("tr");
479
        var invoiceId = $(this).data("invoiceid");
480
        var itemId = $(this).data("itemid");
481
        if (invoiceId != undefined && itemId != undefined) {
482
            doDeleteAjaxRequestHandler(context + "/removeInvoiceItem?invoiceId="
483
                + invoiceId + "&itemId=" + itemId, function (response) {
484
                if (response == "true") {
485
                    alert("Item removed successfully");
32192 tejbeer 486
 
32352 amit.gupta 487
                }
488
            });
489
        }
32192 tejbeer 490
 
32352 amit.gupta 491
        row.remove();
32192 tejbeer 492
 
32352 amit.gupta 493
    });
32192 tejbeer 494
 
495
 
32352 amit.gupta 496
    $(document).on('click', '.purchaseGrn', function () {
32192 tejbeer 497
 
32352 amit.gupta 498
        var grnItemArray = [];
32192 tejbeer 499
 
32352 amit.gupta 500
        var invoiceId = $(this).data("invoiceid");
32192 tejbeer 501
 
502
 
32352 amit.gupta 503
        $("#invoice-purchase-validate > tbody > tr").each(function () {
504
            var grnItemJson = {};
32192 tejbeer 505
 
32352 amit.gupta 506
            var itemId = $(this).find(".itemId").text();
507
            var qty = $(this).find(".qty").text();
508
            var poId = $(this).find(".purchaseId").text();
509
            var excessQty = $(this).find(".excessQty").text();
510
            var itemType = $(this).find(".itemType").text();
32192 tejbeer 511
 
32352 amit.gupta 512
            console.log(itemType);
32192 tejbeer 513
 
32352 amit.gupta 514
            if (itemType == "Serialized") {
515
                var serialNumbers = $(this).find(".imeis-to-grn").tagsinput('items');
32366 amit.gupta 516
                grnItemJson['serialNumbers'] = serialNumbers;
32192 tejbeer 517
 
32352 amit.gupta 518
                if (excessQty > 0) {
519
                    var returnSerialNumbers = $(this).find(".imeis-to-grn-return").tagsinput('items');
520
                    grnItemJson['returnSerialNumbers'] = returnSerialNumbers
521
                }
522
            }
32366 amit.gupta 523
            console.log(serialNumbers);
32352 amit.gupta 524
            grnItemJson['itemId'] = itemId;
525
            grnItemJson['serialNumbers'] = serialNumbers
526
            grnItemJson['qty'] = qty
527
            grnItemJson['poId'] = poId
528
            grnItemJson['invoiceId'] = invoiceId
529
            grnItemJson['itemType'] = itemType
530
            grnItemJson['excessQty'] = excessQty
32192 tejbeer 531
 
32352 amit.gupta 532
            grnItemJson['returnSerialNumbers'] = returnSerialNumbers
32192 tejbeer 533
 
32352 amit.gupta 534
            grnItemArray.push(grnItemJson)
32192 tejbeer 535
 
32352 amit.gupta 536
            console.log(grnItemArray)
32192 tejbeer 537
 
32352 amit.gupta 538
        });
32192 tejbeer 539
 
32352 amit.gupta 540
        for (var i = 0; i < grnItemArray.length; i++) {
32366 amit.gupta 541
            var itemType = grnItemArray[i].itemType;
32192 tejbeer 542
 
32352 amit.gupta 543
            if (itemType == "Serialized") {
544
                var excessQty = grnItemArray[i].excessQty
32192 tejbeer 545
 
546
 
32352 amit.gupta 547
                var serialNumbers = grnItemArray[i].serialNumbers.length
548
                var qty = grnItemArray[i].qty
32192 tejbeer 549
 
32352 amit.gupta 550
                if (serialNumbers != qty) {
551
                    alert("serial number is not matched with qty")
552
                    return false;
553
                }
32192 tejbeer 554
 
32352 amit.gupta 555
                if (excessQty > 0) {
32192 tejbeer 556
 
32352 amit.gupta 557
                    var returnSerialNumbers = grnItemArray[i].returnSerialNumbers.length
32192 tejbeer 558
 
32352 amit.gupta 559
                    if (returnSerialNumbers != excessQty) {
560
                        alert("Return serial number is not matched with excess qty")
561
                        return false;
562
                    }
32192 tejbeer 563
 
32352 amit.gupta 564
                }
565
            }
32192 tejbeer 566
 
32352 amit.gupta 567
        }
32192 tejbeer 568
 
569
 
32352 amit.gupta 570
        console.log(JSON.stringify(grnItemArray))
571
        if (confirm("Are you sure you want to grn purchase order") == true) {
32192 tejbeer 572
 
32352 amit.gupta 573
            doPostAjaxRequestWithJsonHandler(context
574
                + "/createGrn", JSON
575
                .stringify(grnItemArray), function (response) {
576
                if (response == 'true') {
577
                    alert("successfully done");
578
                    loadNewReceiveInvoice("main-content");
579
                }
580
            });
581
        }
32192 tejbeer 582
 
583
 
32352 amit.gupta 584
    });
32256 tejbeer 585
 
586
 
32352 amit.gupta 587
    $(document).on('click', '.grnRequest', function () {
32192 tejbeer 588
 
32352 amit.gupta 589
        var grnRequestJson = {};
590
        var grnRequestItemArray = [];
32192 tejbeer 591
 
32352 amit.gupta 592
        var invoiceId = $(this).data("invoiceid");
32192 tejbeer 593
 
594
 
32352 amit.gupta 595
        $("#invoice-purchase-validate > tbody > tr").each(function () {
596
            var grnItemJson = {};
32192 tejbeer 597
 
32352 amit.gupta 598
            var itemId = $.trim($(this).find(".itemId").text());
599
            var poId = $.trim($(this).find(".purchaseId").text());
32192 tejbeer 600
 
32352 amit.gupta 601
            var qty = parseInt($(this).find(".qty").text());
32256 tejbeer 602
 
32352 amit.gupta 603
            var excessQty = parseInt($(this).find(".excessQty").text());
32256 tejbeer 604
 
32352 amit.gupta 605
            var priceMismatch = $.trim($(this).find(".priceMismatch").text());
606
            console.log(priceMismatch)
32256 tejbeer 607
 
608
 
32354 amit.gupta 609
            if (priceMismatch !== "" || excessQty > 0) {
32352 amit.gupta 610
                console.log(typeof priceMismatch)
611
                console.log(excessQty)
612
                grnItemJson['itemId'] = itemId;
613
                grnItemJson['qty'] = qty;
614
                grnItemJson['excessQty'] = excessQty
32376 amit.gupta 615
                if (priceMismatch === '') {
616
                    grnItemJson['mismatch'] = 'QtyMismatch';
617
                } else {
618
                    grnItemJson['mismatch'] = priceMismatch
619
                }
32352 amit.gupta 620
                grnItemJson['poId'] = poId
32192 tejbeer 621
 
32352 amit.gupta 622
                grnRequestItemArray.push(grnItemJson)
623
            }
624
        });
32256 tejbeer 625
 
32352 amit.gupta 626
        console.log(grnRequestItemArray)
32256 tejbeer 627
 
628
 
32352 amit.gupta 629
        grnRequestJson['invoiceId'] = invoiceId;
630
        grnRequestJson['warehousePurchaseModel'] = grnRequestItemArray
32256 tejbeer 631
 
32366 amit.gupta 632
        if (confirm("Are you sure you want to raise grn request")) {
32192 tejbeer 633
 
32352 amit.gupta 634
            doPostAjaxRequestWithJsonHandler(context
635
                + "/grnRequest", JSON
636
                .stringify(grnRequestJson), function (response) {
637
                if (response == 'true') {
638
                    alert("successfully done");
639
                    loadNewReceiveInvoice("main-content");
640
                }
641
            });
642
        }
32192 tejbeer 643
 
644
 
32352 amit.gupta 645
    });
32192 tejbeer 646
 
32256 tejbeer 647
 
32352 amit.gupta 648
    $(document).on('click', '.resolvedPriceMismatchRequest', function () {
649
        var id = $(this).data("id");
32256 tejbeer 650
 
32352 amit.gupta 651
        var invoiceId = $(this).data("invoiceid");
32256 tejbeer 652
 
32352 amit.gupta 653
        var requestId = $(this).data("requestid");
32256 tejbeer 654
 
32352 amit.gupta 655
        var mismatch = $(this).data("mismatch");
32256 tejbeer 656
 
32352 amit.gupta 657
        if (mismatch == "InvoiceMismatch") {
32485 amit.gupta 658
            if (confirm("Are you sure you want to resolve invoice mismatch")) {
32352 amit.gupta 659
                doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id, function (response) {
660
                    if (response == 'true') {
661
                        getGrnRequestItems(requestId, invoiceId)
662
                    }
663
                });
32256 tejbeer 664
 
32352 amit.gupta 665
            }
666
        } else if (mismatch == "PoMismatch") {
667
            if (confirm("Are you sure you want to resolve Po Mismatch. Discard the current PoLineItem new Po will generate on the invoice date.") == true) {
32256 tejbeer 668
 
32352 amit.gupta 669
                doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id, function (response) {
670
                    if (response == 'true') {
671
                        getGrnRequestItems(requestId, invoiceId)
672
                    }
673
                });
32256 tejbeer 674
 
32352 amit.gupta 675
            }
676
        }
32256 tejbeer 677
 
32352 amit.gupta 678
    });
32256 tejbeer 679
 
680
 
32352 amit.gupta 681
    $(document).on('click', '.resolvedQtyMismatchRequest', function () {
682
        var id = $(this).data("id");
32256 tejbeer 683
 
32352 amit.gupta 684
        var invoiceId = $(this).data("invoiceid");
32256 tejbeer 685
 
32352 amit.gupta 686
        var requestId = $(this).data("requestid");
687
        var requestId = $(this).data("requestid");
32256 tejbeer 688
 
689
 
32352 amit.gupta 690
        var mismatch = $(this).data("mismatch");
32256 tejbeer 691
 
32352 amit.gupta 692
        var $row = $(this).closest("tr");
693
        var requiredQty = $row.find(".requiredQty").val();
32256 tejbeer 694
 
32352 amit.gupta 695
        console.log(requiredQty);
32256 tejbeer 696
 
32352 amit.gupta 697
        if (mismatch == "QtyMismatch") {
698
            if (confirm("Are you sure you want to resolve qty mismatch") == true) {
32256 tejbeer 699
 
32352 amit.gupta 700
                doGetAjaxRequestHandler(context + "/resolvedMismatchRequest?id=" + id + "&requiredQty=" + requiredQty, function (response) {
701
                    if (response == 'true') {
702
                        getGrnRequestItems(requestId, invoiceId)
703
                    }
704
                });
32256 tejbeer 705
 
32352 amit.gupta 706
            }
707
        }
32256 tejbeer 708
 
32352 amit.gupta 709
    });
32256 tejbeer 710
 
32192 tejbeer 711
 
32145 tejbeer 712
});
713
 
714
function loadCreatePurchase(domId) {
32352 amit.gupta 715
    doGetAjaxRequestHandler(context + "/warehousePurchaseOrder", function (response) {
716
        $('#' + domId).html(response);
717
    });
32145 tejbeer 718
}
719
 
32192 tejbeer 720
 
32145 tejbeer 721
function loadOpenPurchase(domId) {
722
 
32352 amit.gupta 723
    doGetAjaxRequestHandler(context + "/getOpenPurchaseOrder", function (response) {
724
        $('#' + domId).html(response);
725
    });
32145 tejbeer 726
}
727
 
32192 tejbeer 728
function loadNewReceiveInvoice(domId) {
32352 amit.gupta 729
    doGetAjaxRequestHandler(context + "/newReceiveInvoice", function (response) {
730
        $('#' + domId).html(response);
731
    });
32192 tejbeer 732
}
733
 
32256 tejbeer 734
 
735
function loadGrnRequest(domId) {
32352 amit.gupta 736
    doGetAjaxRequestHandler(context + "/grnRequest", function (response) {
737
        $('#' + domId).html(response);
738
    });
32256 tejbeer 739
}
740
 
741
function loadDebitNote(domId) {
32352 amit.gupta 742
    doGetAjaxRequestHandler(context + "/getDebitNote", function (response) {
743
        $('#' + domId).html(response);
744
    });
32256 tejbeer 745
}
746
 
32300 tejbeer 747
function loadWarehouseInvoices(domId) {
32352 amit.gupta 748
    doGetAjaxRequestHandler(context + "/getWarehouseInvoices", function (response) {
749
        $('#' + domId).html(response);
750
    });
32300 tejbeer 751
}
752
 
32390 amit.gupta 753
function createPO(sendPo) {
32352 amit.gupta 754
    var purchaseOrder = {};
32145 tejbeer 755
 
32352 amit.gupta 756
    var vendorId = $('#vendorId').val();
32145 tejbeer 757
 
32352 amit.gupta 758
    var warehouseId = $('#warehouseMap').val();
32145 tejbeer 759
 
32390 amit.gupta 760
    var poDate = $('#poDate').val();
32145 tejbeer 761
 
32390 amit.gupta 762
 
32352 amit.gupta 763
    var items = []
764
    $("table > tbody > tr").each(function () {
765
        var purchaseOrderJson = {};
32145 tejbeer 766
 
32352 amit.gupta 767
        var itemId = $(this).find(".transferPrice").data('itemid');
768
        var qty = $(this).find(".qty").val();
769
        var transferPrice = $(this).find(".transferPrice").val();
770
        var totalValue = $(this).find(".totalValue").val();
32145 tejbeer 771
 
772
 
32352 amit.gupta 773
        purchaseOrderJson['itemId'] = itemId;
774
        purchaseOrderJson['amendedQty'] = qty
775
        purchaseOrderJson['totalValue'] = totalValue
776
        purchaseOrderJson['transferPrice'] = transferPrice
32145 tejbeer 777
 
32352 amit.gupta 778
        items.push(purchaseOrderJson)
779
    });
32145 tejbeer 780
 
781
 
32352 amit.gupta 782
    for (var i = 0; i < items.length; i++) {
783
        console.log(items[i])
32145 tejbeer 784
 
32352 amit.gupta 785
        var itemId = items[i].itemId
786
        var qty = items[i].amendedQty
787
        var transferPrice = items[i].transferPrice
788
        var totalValue = items[i].totalValue
32145 tejbeer 789
 
32352 amit.gupta 790
        if (itemId === "" && qty === "" && transferPrice === "" && totalValue === "") {
791
            alert("Field can't be empty");
792
            return false;
793
        }
32145 tejbeer 794
 
795
 
32352 amit.gupta 796
        if (itemId === "") {
797
            alert("please select item");
798
            return false;
799
        }
800
        if (qty === "") {
801
            alert("please choose qty");
802
            return false;
803
        }
32145 tejbeer 804
 
32352 amit.gupta 805
        if (transferPrice === "") {
806
            alert("Transfer Price can't be empty");
807
            return false;
808
        }
809
        if (totalValue === "") {
810
            alert("Total value can't be empty");
811
            return false;
812
        }
32145 tejbeer 813
 
32352 amit.gupta 814
        if (qty <= 0) {
815
            alert("Please fill Qty");
816
            return false;
817
        }
32145 tejbeer 818
 
819
 
32352 amit.gupta 820
    }
32261 tejbeer 821
 
32352 amit.gupta 822
    purchaseOrder['vendorId'] = vendorId;
823
    purchaseOrder['warehouseId'] = warehouseId
824
    purchaseOrder['sendPo'] = sendPo
32390 amit.gupta 825
    purchaseOrder['poDate'] = poDate;
32352 amit.gupta 826
    purchaseOrder['items'] = items
32145 tejbeer 827
 
32352 amit.gupta 828
    console.log(purchaseOrder)
32145 tejbeer 829
 
830
 
32352 amit.gupta 831
    if (confirm("Are you sure you want to create purchase order") == true) {
32145 tejbeer 832
 
32352 amit.gupta 833
        doPostAjaxRequestWithJsonHandler(context
834
            + "/createPurchaseOrder", JSON
835
            .stringify(purchaseOrder), function (response) {
836
            if (response == 'true') {
837
                alert("successfully created");
838
                loadCreatePurchase("main-content");
839
            }
840
        });
841
    }
32145 tejbeer 842
 
843
}
844
 
845
 
846
function editPurchase(sendPo, poid) {
32352 amit.gupta 847
    var editpurchaseOrder = {}
848
    var items = []
849
    $("#purchase-edit-lineitem > tbody > tr").each(function () {
850
        var purchaseOrderJson = {};
851
        var itemId = $(this).find("td:eq(0)").text();
32145 tejbeer 852
 
32352 amit.gupta 853
        var qty = $(this).find("td:eq(2)").text();
32145 tejbeer 854
 
32352 amit.gupta 855
        var amendedQty = $(this).find(".editqty").val();
32256 tejbeer 856
 
32352 amit.gupta 857
        var transferPrice = $.trim($(this).find(".transferPrice").html());
32256 tejbeer 858
 
859
 
32352 amit.gupta 860
        purchaseOrderJson['itemId'] = itemId;
861
        purchaseOrderJson['amendedQty'] = parseInt(amendedQty)
862
        purchaseOrderJson['qty'] = parseInt(qty)
863
        purchaseOrderJson['transferPrice'] = transferPrice
32145 tejbeer 864
 
32352 amit.gupta 865
        items.push(purchaseOrderJson)
866
    });
32145 tejbeer 867
 
868
 
32352 amit.gupta 869
    for (var i = 0; i < items.length; i++) {
870
        console.log(items[i])
32145 tejbeer 871
 
32352 amit.gupta 872
        var amendedQty = items[i].amendedQty
873
        var qty = items[i].qty
32145 tejbeer 874
 
32256 tejbeer 875
 
32352 amit.gupta 876
        if (amendedQty === "") {
877
            alert("please choose qty");
878
            return false;
879
        }
32145 tejbeer 880
 
32352 amit.gupta 881
        if (amendedQty < qty) {
882
            alert("Quantity should be greater than existing qty");
883
            return false;
884
        }
32145 tejbeer 885
 
886
 
32352 amit.gupta 887
    }
32145 tejbeer 888
 
32352 amit.gupta 889
    editpurchaseOrder['purchaseOrderId'] = poid;
890
    editpurchaseOrder['sendPo'] = sendPo
891
    editpurchaseOrder['items'] = items
32145 tejbeer 892
 
893
 
32352 amit.gupta 894
    if (confirm("Are you sure you want to edit purchase order") == true) {
32145 tejbeer 895
 
32352 amit.gupta 896
        doPostAjaxRequestWithJsonHandler(context
897
            + "/editPurchaseOrder", JSON
898
            .stringify(editpurchaseOrder), function (response) {
899
            if (response == 'true') {
900
                alert("successfully created");
901
                $('#warehouseEditPurchaseContainer').modal('hide');
902
                $('.modal-backdrop').remove();
32295 tejbeer 903
 
32352 amit.gupta 904
                loadOpenPurchase("main-content")
905
            }
906
        });
907
    }
32145 tejbeer 908
 
909
}
910
 
911
 
32192 tejbeer 912
function getInvoiceItemData(numItems, invoiceId, warehouseId, supplierId, validate) {
913
 
32352 amit.gupta 914
    var invoiceJson = {};
915
    console.log(numItems)
916
    var totalQty = 0;
917
    var invoiceItems = []
918
    $("#invoice-order-table > tbody > tr").each(function () {
919
        var invoiceItemJson = {};
920
        var itemId = $(this).find(".rate").data('itemid');
921
        var qty = $(this).find(".qty").val();
32192 tejbeer 922
 
32352 amit.gupta 923
        if (qty != undefined) {
924
            totalQty += parseInt(qty)
925
        }
926
        var rate = $(this).find(".rate").val();
927
        invoiceItemJson['itemId'] = itemId;
928
        invoiceItemJson['qty'] = qty
929
        invoiceItemJson['rate'] = rate
930
        invoiceItems.push(invoiceItemJson)
931
    });
32192 tejbeer 932
 
933
 
32352 amit.gupta 934
    for (var i = 0; i < invoiceItems.length; i++) {
32192 tejbeer 935
 
32352 amit.gupta 936
        var itemId = invoiceItems[i].itemId
937
        var qty = invoiceItems[i].qty
938
        var rate = invoiceItems[i].rate
939
        if (itemId === "" && qty === "" && rate === "") {
940
            alert("Field can't be empty");
941
            return false;
942
        }
32192 tejbeer 943
 
32352 amit.gupta 944
        if (itemId === "") {
945
            alert("please select item");
946
            return false;
947
        }
948
        if (qty === "") {
949
            alert("please choose qty");
950
            return false;
951
        }
32192 tejbeer 952
 
32352 amit.gupta 953
        if (rate === "") {
954
            alert("Rate can't be empty");
955
            return false;
956
        }
32192 tejbeer 957
 
32352 amit.gupta 958
    }
32192 tejbeer 959
 
32352 amit.gupta 960
    console.log(totalQty)
32192 tejbeer 961
 
32352 amit.gupta 962
    if (totalQty > numItems) {
963
        alert("Qty Should not be more than  Invoice items");
964
        return false;
965
    }
32192 tejbeer 966
 
32352 amit.gupta 967
    if (validate) {
32192 tejbeer 968
 
32352 amit.gupta 969
        if (totalQty != numItems) {
970
            alert("Qty Should not match with Invoice items");
971
            return false;
972
        }
973
    }
32192 tejbeer 974
 
975
 
32352 amit.gupta 976
    invoiceJson['invoiceId'] = invoiceId;
977
    invoiceJson['warehouseId'] = warehouseId;
978
    invoiceJson['supplierId'] = supplierId;
979
    invoiceJson['invoiceItems'] = invoiceItems
980
    if (validate) {
981
        validateInvoiceItems(invoiceJson);
982
    } else {
983
        saveInvoiceItems(invoiceJson)
984
    }
32192 tejbeer 985
}
986
 
987
 
988
function saveInvoiceItems(invoiceJson) {
989
 
990
 
32352 amit.gupta 991
    if (confirm("Are you sure you want to save invoice item") == true) {
32192 tejbeer 992
 
32352 amit.gupta 993
        doPostAjaxRequestWithJsonHandler(context
994
            + "/invoiceItemDetail", JSON
995
            .stringify(invoiceJson), function (response) {
996
            if (response == 'true') {
997
                getInvoiceItems(invoiceJson.invoiceId);
998
            }
999
        });
1000
    }
32192 tejbeer 1001
 
1002
}
1003
 
1004
 
1005
function validateInvoiceItems(invoiceJson) {
1006
 
1007
 
32352 amit.gupta 1008
    if (confirm("Are you sure you want to validate invoice item") == true) {
32192 tejbeer 1009
 
32352 amit.gupta 1010
        doPostAjaxRequestWithJsonHandler(context
1011
            + "/validateInvoiceItemDetail", JSON
1012
            .stringify(invoiceJson), function (response) {
1013
            $('.invoiceadditemcontainer').html(response);
32192 tejbeer 1014
 
32352 amit.gupta 1015
        });
1016
    }
32192 tejbeer 1017
 
1018
}
1019
 
1020
function getOpenPOFromWarehouse() {
1021
 
32352 amit.gupta 1022
    var warehouseId = $('#warehouseMap').val();
1023
    doGetAjaxRequestHandler(context + "/getOpenPurchaseOrderByWarehouseId?warehouseId=" + warehouseId, function (response) {
1024
        $('#warehouseManagePuchaseContainer').html(response);
1025
    });
32192 tejbeer 1026
 
1027
 
1028
}
1029
 
1030
function getPurchaseLineitem(poId) {
1031
 
1032
 
32352 amit.gupta 1033
    doGetAjaxRequestHandler(context + "/getPurchaseOrderItemByPoId?poId=" + poId, function (response) {
1034
        $('#warehouseManagePuchaseItemContainer').html(response);
1035
        $('#warehousepurchaseitemgrn').hide()
1036
    });
32192 tejbeer 1037
 
1038
 
1039
}
1040
 
1041
 
1042
function getInvoiceItems(invoiceId) {
1043
 
32352 amit.gupta 1044
    doGetAjaxRequestHandler(context + "/getInvoiceItems?invoiceId=" + invoiceId, function (response) {
1045
        $('.invoiceadditemcontainer').html(response);
32192 tejbeer 1046
 
32352 amit.gupta 1047
    });
32192 tejbeer 1048
}
1049
 
1050
 
32256 tejbeer 1051
function getGrnRequestItems(requestId, invoiceId) {
32352 amit.gupta 1052
    doGetAjaxRequestHandler(context + "/grnRequestItem?requestId=" + requestId + "&invoiceId=" + invoiceId, function (response) {
1053
        $('.grnRequestItemContainer').html(response);
32256 tejbeer 1054
 
32352 amit.gupta 1055
    });
32256 tejbeer 1056
}
1057
 
1058