Subversion Repositories SmartDukaan

Rev

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