Even with all the effort put into getting the counts right on the customers grid, it still didn't work right. The root of the problem is the join to CurrentLease, which can result in multiple rows for the same customer. I can revisit this in the future to put some clever solution back in, but in the meantime, it was easiest just to add fields to the customers table, and simply update it whenever the customer lease situation changes. I don't like it... but it just made life much simpler.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@481 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-04 19:25:39 +00:00
parent 4d4e96fe1c
commit 0ff91bf4d8
6 changed files with 66 additions and 30 deletions

View File

@@ -1530,6 +1530,21 @@ $query = "UPDATE pmgr_units U, pmgr_leases L
WHERE L.unit_id = U.id AND L.close_date IS NULL";
query($db_handle, $query);
# All current_lease_counts will be zero at the moment, since
# everything was just created. This will update any customers
# that have ever leased anything.
$query = "UPDATE pmgr_customers C,
(SELECT L.customer_id,
SUM(IF(L.close_date IS NULL, 1, 0)) AS current,
SUM(IF(L.close_date IS NULL, 0, 1)) AS closed
FROM pmgr_leases L
GROUP BY L.customer_id) AS X
SET C.`lease_count` = X.current + X.closed,
C.`current_lease_count` = X.current,
C.`past_lease_count` = X.closed
WHERE X.customer_id = C.id";
query($db_handle, $query);
######################################################################
## Invoice/Receipt totals