Subversion Repositories SmartDukaan

Rev

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

Rev 32912 Rev 33727
Line 195... Line 195...
195
    });
195
    });
196
 
196
 
197
 
197
 
198
    $(document).on('click', ".addRowInPurchaseOrder", function () {
198
    $(document).on('click', ".addRowInPurchaseOrder", function () {
199
        var totalQty = 0;
199
        var totalQty = 0;
-
 
200
        var totalValue = 0;
200
 
201
 
201
        $("table > tbody > tr").each(function () {
202
        $("table > tbody > tr").each(function () {
202
            var itemId = $(this).find(".transferPrice").data('itemid');
203
            var itemId = $(this).find(".transferPrice").data('itemid');
203
            var qty = $(this).find(".qty").val();
204
            var qty = $(this).find(".qty").val();
-
 
205
            var transferPrice = $(this).find(".transferPrice").val();
204
 
206
 
205
            console.log(qty);
207
            if (qty !== undefined && qty !== "") {
206
 
-
 
207
            if (qty !== undefined) {
208
                qty = parseInt(qty);
208
                totalQty += parseInt(qty);
209
                totalQty += qty;
-
 
210
                if (transferPrice !== undefined && transferPrice !== "") {
-
 
211
                    transferPrice = parseFloat(transferPrice);
-
 
212
                    totalValue += qty * transferPrice;
-
 
213
                }
209
            }
214
            }
210
            console.log(totalQty);
-
 
211
        });
215
        });
212
 
216
 
213
        var $html = $(`<tr>
217
        var $html = $(`<tr>
214
        <td>  <input type="text" class="form-control typeaheaditem"   autocomplete="off"  placeholder="Search Model"/> </td>
218
        <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>
219
        <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>
220
        <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>
221
        <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>
222
        <td><input class="form-control btn btn-primary removeInPurchaseOrder" tabindex="-1" type="button" value="Remove"></td>
219
        </tr> `);
223
    </tr>`);
220
 
224
 
221
        var vendorId = $('#vendorId').val();
225
        var vendorId = $('#vendorId').val();
222
 
226
 
223
        $('tbody').append($html);
227
        $('tbody').append($html);
224
        getVendorItemAheadOptions($('tbody > tr').find('.typeaheaditem'), vendorId, function (
228
        getVendorItemAheadOptions($html.find('.typeaheaditem'), vendorId, function (selectedItem) {
225
            selectedItem) {
-
 
226
            let poDate = $('#poDate').val();
229
            let poDate = $('#poDate').val();
227
            var itemId = selectedItem.itemId;
230
            var itemId = selectedItem.itemId;
228
            if (addItem($html, itemId)) {
231
            if (addItem($html, itemId)) {
229
                doGetAjaxRequestHandler(`${context}/getPricing?vendorId=${vendorId}&itemId=${itemId}&onDate=${poDate}`, function (response) {
232
                doGetAjaxRequestHandler(`${context}/getPricing?vendorId=${vendorId}&itemId=${itemId}&onDate=${poDate}`, function (response) {
230
                    if (response !== "null") {
233
                    if (response !== "null") {
231
                        var jsonObj = JSON.parse(response);
234
                        var jsonObj = JSON.parse(response);
232
                        $html.find('.transferPrice').val(jsonObj.transferPrice);
235
                        $html.find('.transferPrice').val(jsonObj.transferPrice);
233
                        $html.find('input.qty').focus();
236
                        $html.find('input.qty').focus();
-
 
237
 
-
 
238
                        // Update the total value for this row
-
 
239
                        let qty = $html.find('.qty').val();
-
 
240
                        let transferPrice = jsonObj.transferPrice;
-
 
241
                        if (qty && transferPrice) {
-
 
242
                            let total = qty * transferPrice;
-
 
243
                            $html.find('.totalValue').val(total);
-
 
244
                            updateTotalValue();
-
 
245
                        }
234
                    } else {
246
                    } else {
235
                        $html.find('.typeaheaditem').val("");
247
                        $html.find('.typeaheaditem').val("");
236
                    }
248
                    }
237
                });
249
                });
238
            } else {
250
            } else {
239
                return false;
251
                return false;
240
            }
252
            }
241
        });
253
        });
-
 
254
    });
242
 
255
 
-
 
256
    $(document).on('input', '.qty', function () {
-
 
257
        var $row = $(this).closest('tr');
-
 
258
        var qty = parseInt($(this).val());
-
 
259
        var transferPrice = parseFloat($row.find('.transferPrice').val());
-
 
260
        if (!isNaN(qty) && !isNaN(transferPrice)) {
-
 
261
            let total = qty * transferPrice;
-
 
262
            $row.find('.totalValue').val(total);
-
 
263
        }
-
 
264
        updateTotalValue();
243
    });
265
    });
244
 
266
 
-
 
267
    function updateTotalValue() {
-
 
268
        var grandTotal = 0;
-
 
269
        $('tbody > tr').each(function () {
-
 
270
            var rowTotal = parseFloat($(this).find('.totalValue').val());
-
 
271
            if (!isNaN(rowTotal)) {
-
 
272
                grandTotal += rowTotal;
-
 
273
            }
-
 
274
        });
-
 
275
        $('#grandTotal').text(grandTotal.toFixed(2));
-
 
276
    }
-
 
277
 
245
    function addItem(container, itemId) {
278
    function addItem(container, itemId) {
246
        oldItemId = container.find('.transferPrice').data('itemid');
279
        oldItemId = container.find('.transferPrice').data('itemid');
247
        if (typeof (oldItemId) === "undefined") {
280
        if (typeof (oldItemId) === "undefined") {
248
            let itemIndex = purchaseItemIds.indexOf(itemId);
281
            let itemIndex = purchaseItemIds.indexOf(itemId);
249
            if (itemIndex >= 0) {
282
            if (itemIndex >= 0) {
Line 268... Line 301...
268
            }
301
            }
269
        }
302
        }
270
        return true;
303
        return true;
271
    }
304
    }
272
 
305
 
-
 
306
 
273
    $(document).on('click', '.createSendPurchaseOrder', function () {
307
    $(document).on('click', '.createSendPurchaseOrder', function () {
274
 
308
 
275
        createPO(true);
309
        createPO(true);
276
 
310
 
277
    });
311
    });