diff --git a/db/scratch.sql b/db/scratch.sql index 27191ee..17eb6f8 100644 --- a/db/scratch.sql +++ b/db/scratch.sql @@ -135,9 +135,7 @@ FROM pmgr_transactions T -- E.account_id != T.account_id GROUP BY T.id HAVING - (T.type = 'INVOICE' AND Tamt <> T.amount) - OR - (T.type <> 'INVOICE' AND Oamt <> T.amount) + (T.amount <> IF(T.type IN ('INVOICE','TRANSFER','DEPOSIT','PAYMENT'), Tamt, Oamt)) OR (Tamt * -1 <> Oamt) @@ -576,3 +574,105 @@ ORDER BY IF(U.id IS NOT NULL, 1, IF (S.id IS NOT NULL, 3, 4))) ASC, IF (G.id IS NOT NULL, G.rank, 0) ASC ; + + +-- ---------------------------------------------------- +-- Income by Month +SELECT MONTH(SE.effective_date) AS mon, YEAR(SE.effective_date) AS yr, + SE.account_id AS acct, ROUND(SUM(SE.amount)) AS amt +FROM pmgr_statement_entries SE +WHERE SE.type = 'CHARGE' + AND SE.effective_date >= '2009-04-01' AND SE.effective_date <= NOW() +GROUP BY yr, mon, acct WITH ROLLUP + +-- ---------------------------------------------------- +-- Rent Income by Month +SELECT MONTH(SE.effective_date) AS mon, YEAR(SE.effective_date) AS yr, + ROUND(SUM(SE.amount)) AS amt +FROM pmgr_statement_entries SE +WHERE SE.type = 'CHARGE' + AND SE.effective_date >= '2009-04-01' AND SE.effective_date <= NOW() + AND SE.account_id = 13 +GROUP BY yr, mon WITH ROLLUP + +-- ---------------------------------------------------- +-- Occupancy during given month +SELECT COUNT(L.id) FROM pmgr_leases L +WHERE L.movein_date < '2009-10-01' + AND (L.moveout_date IS NULL OR L.moveout_date > '2009-09-01') + +-- ---------------------------------------------------- +-- Move-ins by month +SELECT MONTH(L.movein_date) AS mon, YEAR(L.movein_date) AS yr, COUNT(L.id) +FROM pmgr_leases L +WHERE L.movein_date >= '2009-04-01' +GROUP BY yr, mon + +-- ---------------------------------------------------- +-- Move-outs by month +SELECT MONTH(L.moveout_date) AS mon, YEAR(L.moveout_date) AS yr, COUNT(L.id) +FROM pmgr_leases L +WHERE L.moveout_date >= '2009-04-01' +GROUP BY yr, mon + +-- ---------------------------------------------------- +-- Move-ins/Move-outs by month +SELECT + MONTH(L.movein_date) AS mon, YEAR(L.movein_date) AS yr, + IF(L.movein_date AS mon, YEAR(L.movein_date) AS yr, +FROM pmgr_leases L +WHERE L.movein_date >= '2009-04-01' +GROUP BY yr, mon + + +-- ---------------------------------------------------- +-- Rent charged +SELECT SUM(SE.amount) + FROM pmgr_statement_entries SE + LEFT JOIN pmgr_accounts A ON A.id = SE.account_id +WHERE A.name = 'Rent' +-- AND SE.effective_date >= '2009-04-01' +-- AND SE.effective_date < '2009-12-01' + + + + +-- -------------------------------------------------------------- +-- Merge two customers +SELECT * FROM pmgr_statement_entries WHERE customer_id = 65 +; +UPDATE pmgr_leases SET customer_id=21 WHERE customer_id=65; +UPDATE pmgr_reservations SET customer_id=21 WHERE customer_id=65; +UPDATE pmgr_statement_entries SET customer_id=21 WHERE customer_id=65; +UPDATE pmgr_tenders SET customer_id=21 WHERE customer_id=65; +UPDATE pmgr_transactions SET customer_id=21 WHERE customer_id=65; +-- Make sure to update customer info afterwards + + +-- -------------------------------------------------------------- +-- Determine income from a customer +SELECT NT.name AS 'type', SUM(LE.amount) AS 'total' + FROM pmgr_tenders N + LEFT JOIN pmgr_tender_types NT ON NT.id = N.tender_type_id + LEFT JOIN pmgr_ledger_entries LE ON LE.id = N.ledger_entry_id + LEFT JOIN pmgr_customers C ON C.id = N.customer_id + WHERE + N.customer_id = 49 + AND N.nsf_ledger_entry_id IS NULL + AND (NT.tillable OR NT.auto_deposit) + GROUP BY NT.name WITH ROLLUP + + +-- -------------------------------------------------------------- +-- Determine rent charges by month +SELECT MONTH(SE.effective_date) AS 'mon', + YEAR(SE.effective_date) AS 'yr', + DATE_FORMAT(SE.effective_date, "%m/1/%Y") AS 'date', + SUM(SE.amount) AS 'total' + FROM pmgr_accounts A + LEFT JOIN pmgr_statement_entries SE ON SE.account_id = A.id +WHERE + A.name = 'Rent' + AND SE.effective_date < NOW() +GROUP BY yr, mon -- WITH ROLLUP + diff --git a/todo.notes b/todo.notes index 7214113..b1dabd8 100644 --- a/todo.notes +++ b/todo.notes @@ -1,3 +1,14 @@ +Change the summary text "Balance Owed" to "Customer Credit" +or something similar when there is a negative balance owed. + +Shrink the width of the detail view box so that the detail +and summary both fit on the same page on the Acer Netbook. + +Remove Date from Ledger Entries on the Transaction page +(presuming that the Date is taken directly from the +Transaction and that all Ledger dates are all the same) + +Add Deposit Slip # to the title bar when viewing deposit Reversing a rent charge is not considered as part of the "charged-through" date on the lease. Consequently, the