Subversion Repositories SmartDukaan

Rev

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

Rev 36520 Rev 36532
Line 198... Line 198...
198
            $(".createpurchaseordercontainer").html(response);
198
            $(".createpurchaseordercontainer").html(response);
199
        });
199
        });
200
    });
200
    });
201
 
201
 
202
 
202
 
-
 
203
    $(document).on('change', '#poItemsFile', function () {
-
 
204
        var file = this.files[0];
-
 
205
        if (!file) return;
-
 
206
 
-
 
207
        var vendorId = $('#vendorId').val();
-
 
208
        var poDate = $('#poDate').val();
-
 
209
 
-
 
210
        var formData = new FormData();
-
 
211
        formData.append("file", file);
-
 
212
 
-
 
213
        $.ajax({
-
 
214
            url: context + '/uploadPurchaseOrderItems?vendorId=' + vendorId + '&poDate=' + poDate,
-
 
215
            type: 'POST',
-
 
216
            data: formData,
-
 
217
            dataType: 'json',
-
 
218
            cache: false,
-
 
219
            contentType: false,
-
 
220
            processData: false,
-
 
221
            success: function (items) {
-
 
222
                // Clear existing rows
-
 
223
                $('#purchase-order-table tbody').empty();
-
 
224
                purchaseItemIds = [];
-
 
225
 
-
 
226
                for (var i = 0; i < items.length; i++) {
-
 
227
                    var item = items[i];
-
 
228
                    var $row = $('<tr>' +
-
 
229
                        '<td><input type="text" class="form-control typeaheaditem" autocomplete="off" value="' + item.modelName + '" readonly/></td>' +
-
 
230
                        '<td><input type="number" class="form-control qty" name="qty" value="' + item.amendedQty + '"/></td>' +
-
 
231
                        '<td><input type="number" class="form-control transferPrice" readonly tabindex="-1" value="' + item.transferPrice + '" data-itemid="' + item.itemId + '"/></td>' +
-
 
232
                        '<td><input type="number" class="form-control totalValue" tabindex="-1" readonly value="' + item.totalValue + '"/></td>' +
-
 
233
                        '<td><input class="form-control btn btn-primary removeInPurchaseOrder" tabindex="-1" type="button" value="Remove"></td>' +
-
 
234
                        '</tr>');
-
 
235
                    $('#purchase-order-table tbody').append($row);
-
 
236
                    purchaseItemIds.push(item.itemId);
-
 
237
                }
-
 
238
                updateTotalValue();
-
 
239
                alert("Uploaded " + items.length + " items successfully");
-
 
240
            },
-
 
241
            error: function (xhr) {
-
 
242
                var msg = "Upload failed";
-
 
243
                try {
-
 
244
                    var err = JSON.parse(xhr.responseText);
-
 
245
                    if (err.message) msg = err.message;
-
 
246
                    if (err.code) msg = err.code;
-
 
247
                } catch (e) {}
-
 
248
                alert(msg);
-
 
249
            }
-
 
250
        });
-
 
251
 
-
 
252
        // Reset file input so same file can be re-uploaded
-
 
253
        $(this).val('');
-
 
254
    });
-
 
255
 
203
    $(document).on('click', ".addRowInPurchaseOrder", function () {
256
    $(document).on('click', ".addRowInPurchaseOrder", function () {
204
        var totalQty = 0;
257
        var totalQty = 0;
205
        var totalValue = 0;
258
        var totalValue = 0;
206
 
259
 
207
        $("table > tbody > tr").each(function () {
260
        $("table > tbody > tr").each(function () {