Subversion Repositories SmartDukaan

Rev

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

Rev 37564 Rev 37697
Line 272... Line 272...
272
            }
272
            }
273
        });
273
        });
274
 
274
 
275
        var $html = $(`<tr>
275
        var $html = $(`<tr>
276
        <td><input type="text" class="form-control typeaheaditem" autocomplete="off" placeholder="Search Model"/></td>
276
        <td><input type="text" class="form-control typeaheaditem" autocomplete="off" placeholder="Search Model"/></td>
277
        <td><input type="number" class="form-control qty" name="qty" placeholder="Quantity"/></td>
277
        <td><div class="mv-qty-cell"><input type="number" class="form-control qty" name="qty" placeholder="Quantity"/><span class="mv-avail-icon" style="display:none;" tabindex="0">i</span></div><div class="mv-qty-warn" style="display:none;"></div></td>
278
        <td><input type="number" class="form-control transferPrice" readonly tabindex="-1" placeholder="Transfer Price"/></td>
278
        <td><input type="number" class="form-control transferPrice" readonly tabindex="-1" placeholder="Transfer Price"/></td>
279
        <td><input type="number" class="form-control totalValue" tabindex="-1" readonly placeholder="Total Value"/></td>
279
        <td><input type="number" class="form-control totalValue" tabindex="-1" readonly placeholder="Total Value"/></td>
280
        <td><input class="form-control btn btn-primary removeInPurchaseOrder" tabindex="-1" type="button" value="Remove"></td>
280
        <td><input class="form-control btn btn-primary removeInPurchaseOrder" tabindex="-1" type="button" value="Remove"></td>
281
    </tr>`);
281
    </tr>`);
282
 
282
 
Line 291... Line 291...
291
                doGetAjaxRequestHandler(`${context}/getPricing?vendorId=${vendorId}&itemId=${itemId}&onDate=${poDate}`, function (response) {
291
                doGetAjaxRequestHandler(`${context}/getPricing?vendorId=${vendorId}&itemId=${itemId}&onDate=${poDate}`, function (response) {
292
                    if (response !== "null") {
292
                    if (response !== "null") {
293
                        if (response !== 'false') {
293
                        if (response !== 'false') {
294
                            var jsonObj = JSON.parse(response);
294
                            var jsonObj = JSON.parse(response);
295
                            $html.find('.transferPrice').val(jsonObj.transferPrice);
295
                            $html.find('.transferPrice').val(jsonObj.transferPrice);
-
 
296
                            renderMovementAvailability($html, jsonObj);
296
                            $html.find('input.qty').focus();
297
                            $html.find('input.qty').focus();
297
 
298
 
298
                            // Update the total value for this row
299
                            // Update the total value for this row
299
                            let qty = $html.find('.qty').val();
300
                            let qty = $html.find('.qty').val();
300
                            let transferPrice = jsonObj.transferPrice;
301
                            let transferPrice = jsonObj.transferPrice;
Line 321... Line 322...
321
    });
322
    });
322
 
323
 
323
    $(document).on('input', '.qty', function () {
324
    $(document).on('input', '.qty', function () {
324
        var $row = $(this).closest('tr');
325
        var $row = $(this).closest('tr');
325
        var qty = parseInt($(this).val());
326
        var qty = parseInt($(this).val());
-
 
327
        checkMovableQty($row, qty);
326
        var transferPrice = parseFloat($row.find('.transferPrice').val());
328
        var transferPrice = parseFloat($row.find('.transferPrice').val());
327
        if (!isNaN(qty) && !isNaN(transferPrice)) {
329
        if (!isNaN(qty) && !isNaN(transferPrice)) {
328
            let total = qty * transferPrice;
330
            let total = qty * transferPrice;
329
            $row.find('.totalValue').val(total);
331
            $row.find('.totalValue').val(total);
330
        }
332
        }
Line 1359... Line 1361...
1359
        $('.grnCorrectionRequestDetailContainer').html(response);
1361
        $('.grnCorrectionRequestDetailContainer').html(response);
1360
    });
1362
    });
1361
}
1363
}
1362
 
1364
 
1363
 
1365
 
-
 
1366
 
-
 
1367
/**
-
 
1368
 * Shows what the sending warehouse can actually release of an item, on the row where a quantity is being typed.
-
 
1369
 *
-
 
1370
 * Only our own warehouses answer with this; an outside vendor's pricing response carries no availability, and its row
-
 
1371
 * is left exactly as it was. Stock that is entirely promised is shown as zero with the orders holding it named, which
-
 
1372
 * is what lets someone chase those orders instead of only seeing a smaller number.
-
 
1373
 */
-
 
1374
function renderMovementAvailability($row, pricing) {
-
 
1375
    var $icon = $row.find('.mv-avail-icon');
-
 
1376
    if (!pricing || typeof pricing.movableOnThisPo === 'undefined') {
-
 
1377
        $icon.hide();
-
 
1378
        $row.removeData('movableOnThisPo');
-
 
1379
        return;
-
 
1380
    }
-
 
1381
 
-
 
1382
    var cap = pricing.movableOnThisPo;
-
 
1383
    $row.data('movableOnThisPo', cap);
-
 
1384
 
-
 
1385
    var rows = mvAvailLine('In stock', pricing.inStock);
-
 
1386
    if (pricing.promisedTotal > 0) {
-
 
1387
        rows += mvAvailLine('Promised on open orders', pricing.promisedTotal);
-
 
1388
        $.each(pricing.promised || [], function (i, po) {
-
 
1389
            rows += '<tr class="mv-po"><td>' + mvEscape(po.poNumber) + ' &middot; ' + mvEscape(po.poDate)
-
 
1390
                + (po.destination ? ' &rarr; ' + mvEscape(po.destination) : '')
-
 
1391
                + '</td><td>' + po.qty + '</td></tr>';
-
 
1392
        });
-
 
1393
    }
-
 
1394
    if (pricing.inbound > 0) {
-
 
1395
        rows += mvAvailLine('On the way in (not yet received)', pricing.inbound);
-
 
1396
    }
-
 
1397
    rows += '<tr class="mv-total"><td>Can move on this PO</td><td>' + cap + '</td></tr>';
-
 
1398
 
-
 
1399
    var note = '';
-
 
1400
    if (pricing.costSplit) {
-
 
1401
        note += '<div class="mv-note">' + (pricing.movableAltogether - cap)
-
 
1402
            + ' more came in at a different cost &mdash; raise a separate PO for those.</div>';
-
 
1403
    }
-
 
1404
    if (cap === 0) {
-
 
1405
        note += '<div class="mv-note">Nothing can move until one of the orders above is completed or closed.</div>';
-
 
1406
    }
-
 
1407
 
-
 
1408
    $icon.attr('data-mv-content', '<table class="mv-avail">' + rows + '</table>' + note);
-
 
1409
    $icon.removeClass('mv-none mv-part');
-
 
1410
    if (cap === 0) {
-
 
1411
        $icon.addClass('mv-none');
-
 
1412
    } else if (pricing.promisedTotal > 0) {
-
 
1413
        $icon.addClass('mv-part');
-
 
1414
    }
-
 
1415
    $icon.show();
-
 
1416
 
-
 
1417
    $icon.popover('destroy');
-
 
1418
    $icon.popover({
-
 
1419
        html: true,
-
 
1420
        container: 'body',
-
 
1421
        placement: 'left',
-
 
1422
        trigger: 'hover focus',
-
 
1423
        title: 'Stock at ' + mvEscape(pricing.sourceName),
-
 
1424
        content: function () {
-
 
1425
            return $(this).attr('data-mv-content');
-
 
1426
        }
-
 
1427
    });
-
 
1428
 
-
 
1429
    checkMovableQty($row, parseInt($row.find('.qty').val()));
-
 
1430
}
-
 
1431
 
-
 
1432
/** Flags a quantity that the order cannot take, while it is being typed rather than on submit. */
-
 
1433
function checkMovableQty($row, qty) {
-
 
1434
    var cap = $row.data('movableOnThisPo');
-
 
1435
    var $qty = $row.find('.qty');
-
 
1436
    var $warn = $row.find('.mv-qty-warn');
-
 
1437
 
-
 
1438
    if (typeof cap === 'undefined' || isNaN(qty)) {
-
 
1439
        $qty.removeClass('mv-over');
-
 
1440
        $warn.hide().empty();
-
 
1441
        return;
-
 
1442
    }
-
 
1443
 
-
 
1444
    if (qty > cap) {
-
 
1445
        $qty.addClass('mv-over');
-
 
1446
        $warn.text(cap === 0 ? 'None can move right now' : 'Only ' + cap + ' can move on this PO').show();
-
 
1447
    } else {
-
 
1448
        $qty.removeClass('mv-over');
-
 
1449
        $warn.hide().empty();
-
 
1450
    }
-
 
1451
}
-
 
1452
 
-
 
1453
function mvAvailLine(label, value) {
-
 
1454
    return '<tr><td>' + label + '</td><td>' + value + '</td></tr>';
-
 
1455
}
-
 
1456
 
-
 
1457
/** Values here are warehouse and order names out of the database, so they are escaped before going into the popover. */
-
 
1458
function mvEscape(value) {
-
 
1459
    return $('<div/>').text(value === null || typeof value === 'undefined' ? '' : value).html();
-
 
1460
}