brokaddr - 11:22 pm on Mar 13, 2012 (gmt 0)
I'm not sure if the miscalculation is my fault, PHP or MySQL's.
$usa_query = tep_db_query("SELECT count(o.orders_id) as totalrecs, sum(round(ot.value,2)) as usatotal FROM ".TABLE_CANCELLED_ORDERS_TOTAL." as ot LEFT JOIN ".TABLE_CANCELLED_ORDERS." as o on(ot.orders_id=o.orders_id) where o.date_purchased LIKE '".$year."-".$month."%' && (o.orders_status='3' || o.orders_status='2099') && (o.delivery_country='United States' || o.delivery_country='Canada') && o.payment_method LIKE '%Credit%' && ot.class='ot_total'");
$usapp = tep_db_fetch_array($usa_query);
$usaamt = $usapp['usatotal']*.025;
$usatotal = $usapp['totalrecs']*0.30;
$usa = $usaamt+$usatotal;
I've checked the numbers from the spreadsheet in Excel, and the numbers generated off the site are always off by a few cents - I assume it has something to do with the decimal calculations, but I can't figure out how to circumvent it.
I've tried to add number_format($usa,2); over every mathematical result and I end up with the same (incorrect) amounts.
Any suggestions as to where my formula might be wrong?