Supplier Ltd Logo Invoice #: 123
Invoice Date: 1 January 2019
Payment Due: 1 February 2019
To:
Company Name Ltd
12345 High Street
London
From:
Supplier Ltd.
John Doe
john@example.com
Payment Method Cheque No
Cheque 1000397
Item Price Qty Total
£ £ 300.00
£ £ 75.00
£ £ 10.00
Total: £ 385.00
View Vue2 Invoice
            
    $('table').on('mouseup keyup', 'input[type=number]', () => calculateTotals());

    $('.btn-add-row').on('click', () => {
        const $lastRow = $('.item:last');
        const $newRow = $lastRow.clone();

        $newRow.find('input').val('');
        $newRow.find('td:last').text('£ 0.00');
        $newRow.insertAfter($lastRow);

        $newRow.find('input:first').focus();
    });

    function calculateTotals() {
        const subtotals = $('.item').map((idx, val) => calculateSubtotal(val)).get();
        const total = subtotals.reduce((a, v) => a + Number(v), 0);
        $('.total td:eq(1)').text(formatAsCurrency(total));
    }

    function calculateSubtotal(row) {
        const $row = $(row);
        const inputs = $row.find('input');
        const subtotal = inputs[1].value * inputs[2].value;

        $row.find('td:last').text(formatAsCurrency(subtotal));

        return subtotal;
    }

    function formatAsCurrency(amount) {
        return '£ ' + amount.toFixed(2);
    }