Subversion Repositories SmartDukaan

Rev

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