Subversion Repositories SmartDukaan

Rev

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