Also, it seems when there are orphaned records in the so_payments table, the Cash Report somtimes blows up entirely. From what I can tell, this is because the database query does a left join on the orders table, which leaves open the possibility for a non-matching record in the orders table:

Code:
    if ($target == 'payments' || $target == 'both') {
      $payment_query = "SELECT * FROM " . TABLE_SO_PAYMENTS . " p
                        LEFT JOIN " . TABLE_ORDERS . " o
                        ON p.orders_id = o.orders_id
                        WHERE date_posted BETWEEN '" . $sd . "' AND DATE_ADD('" . $ed . "', INTERVAL 1 DAY)
                        AND o.orders_id IS NOT NULL
                        ORDER BY payment_type asc";
      $payment = $db->Execute($payment_query);
The next line makes the rest of the report contingent upon there being a a non-null value for orders_id in the first record (not sure I understand this logic):

Code:
      if (zen_not_null($payment->fields['orders_id'])) {
Anyway, I believe changing the left join to an inner join will both fix the problem of deleted orders showing up, and keep the report from blowing up too, in one fell swoop. Can somebody verify this and/or say whether this might have some unintended consequences?