<?php

/*
# ---------------------------------------------------------
# RECALCULATE ALL INVOICES WITH THE NEW INVOICE TOTALS AND SUBTOTALS
# ---------------------------------------------------------
*/

// This could take a while for installations with large amounts of invoices
@set_time_limit(0);

$query1 = "select invoiceid, sum(price) from invoiceentry group by invoiceid";
$result1 = mysql_query($query1) or die("ERROR in query: $query1");
while (list($invoiceId, $subtotal) = mysql_fetch_row($result1)) {
    $query2 = "update invoice set subtotal=".$subtotal." where id=".$invoiceId;
    $result2 = mysql_query($query2) or die("ERROR in query: $query2");
}

?>
