Simple Invoices logo
    • CommentAuthorFrank
    • CommentTimeJan 23rd 2008 edited
     permalink
    If I'm correct, the sub total (total without tax) is still missing.
    Please add the following line into the sql_queries.php file:
    $invoice['subtotal'] = number_format(getInvoiceTotal($invoice['id'],'false'),2);
    on line 487 right after:
    $invoice['total'] = getInvoiceTotal($invoice['id']);

    This gives people the option to show the total without tax.
    • CommentAuthorFrank
    • CommentTimeJan 23rd 2008 edited
     permalink
    I missed the change in the getInvoiceTotal function:
    function getInvoiceTotal($invoice_id, $tax='true') {
    global $LANG;

    if ($tax=='true') {
    $sql ="SELECT SUM(total) AS total FROM ".TB_PREFIX."invoice_items WHERE invoice_id = $invoice_id";
    $query = mysqlQuery($sql);
    $res = mysql_fetch_array($query);
    } else {
    $sql ="SELECT SUM(total) AS total, SUM(tax_amount) AS total_tax FROM ".TB_PREFIX."invoice_items WHERE invoice_id = $invoice_id";
    $query = mysqlQuery($sql);
    $res = mysql_fetch_array($query);
    $res['total'] = $res['total'] - $res['total_tax'];
    }


    //echo "TOTAL".$res['total'];
    return $res['total'];
    }
    • CommentAuthorFrank
    • CommentTimeJan 25th 2008 edited
     permalink
    Herewith the two updated functions of the sql_queries.php

    getInvoices
    function getInvoice($id) {

    global $config;

    $sql = "SELECT * FROM ".TB_PREFIX."invoices WHERE id = $id";
    //echo $sql;

    $query = mysqlQuery($sql) or die(mysql_error());

    //print_r($query);
    $invoice = mysql_fetch_array($query);

    //print_r($invoice);
    //exit();

    $invoice['date'] = date( $config['date_format'], strtotime( $invoice['date'] ) );
    $invoice['calc_date'] = date('Y-m-d', strtotime( $invoice['date'] ) );
    $invoice['total'] = getInvoiceTotal($invoice['id']);
    $invoice['subtotal'] = getInvoiceTotal($invoice['id'],'false');
    $invoice['total_format'] = round($invoice['total'],2);
    $invoice['paid'] = calc_invoice_paid($invoice['id']);
    $invoice['paid_format'] = round($invoice['paid'],2);
    $invoice['owing'] = $invoice['total'] - $invoice['paid'];
    $invoice['total_tax'] = $invoice['total'] - $invoice['subtotal'];

    return $invoice;
    }

    I cleaned the total tax calculation also, this saves a query again. Good for the speed! ;)

    getInvoiceTotal
    function getInvoiceTotal($invoice_id, $tax='true') {
    global $LANG;

    if ($tax=='true') {
    $sql ="SELECT SUM(total) AS total FROM ".TB_PREFIX."invoice_items WHERE invoice_id = $invoice_id";
    $query = mysqlQuery($sql);
    $res = mysql_fetch_array($query);
    } else {
    $sql ="SELECT SUM(total) AS total, SUM(tax_amount) AS total_tax FROM ".TB_PREFIX."invoice_items WHERE invoice_id = $invoice_id";
    $query = mysqlQuery($sql);
    $res = mysql_fetch_array($query);
    $res['total'] = $res['total'] - $res['total_tax'];
    }

    //echo "TOTAL".$res['total'];
    return $res['total'];
    }
    • CommentAuthorjustin
    • CommentTimeJan 30th 2008 edited
     permalink