diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index 4994824..8672d64 100644 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -421,6 +421,25 @@ class CustomersController extends AppController { } + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: refund + * - Refunds customer charges + */ + + function refund() { + $entries = $this->Customer->LedgerEntry->find + ('all', array + ('contain' => false, + 'conditions' => array('LedgerEntry.id' => array(199,200,201)), + )); + pr(compact('entries')); + + $this->Customer->LedgerEntry->refund($entries); + } + + /************************************************************************** ************************************************************************** ************************************************************************** diff --git a/models/ledger_entry.php b/models/ledger_entry.php index 41179ea..ab82b17 100644 --- a/models/ledger_entry.php +++ b/models/ledger_entry.php @@ -375,6 +375,114 @@ class LedgerEntry extends AppModel { } + /************************************************************************** + ************************************************************************** + ************************************************************************** + * function: refund + * - Flags the given items as refunded + * + * SAMPLE MOVE IN w/ PRE PAYMENT + * DEPOSIT RENT A/R RECEIPT CHECK PETTY BANK + * ------- ------- ------- ------- ------- ------- ------- + * |25 | 25| | | | | + * | |20 20| | | | | + * | |20 20| | | | | + * | |20 20| | | | | + * | | |25 25| | | | + * | | |20 20| | | | + * | | |20 20| | | | + * | | |20 20| | | | + * | | | |85 85| | | + * | | | | |85 | 85| + + * MOVE OUT and REFUND FINAL MONTH + * DEPOSIT RENT C/P RECEIPT CHECK PETTY BANK + * ------- ------- ------- ------- ------- ------- ------- + * 25| | |25 | | | | t20 e20a + * | 20| |20 | | | | t20 e20b + + * -ONE REFUND CHECK- + * | | 25| |25 | | | t30 e30a + * | | 20| |20 | | | t30 e30b + * | | | 45| | | |45 t40 e40 + * -OR MULTIPLE- + * | | 15| |15 | | | t50a e50a + * | | | 15| | |15 | t60a e60a + * | | 30| |30 | | | t50b e50b + * | | | 30| | | |30 t60b e60b + * | | | | | | | + + +OPTION 1 + * |-25 | -25| | | | | + * | |-20 -20| | | | | + * | | |-25 -25| | | | + * | | |-20 -20| | | | + +OPTION 2 + * |-25 | | -25| | | | + * | |-20 | -20| | | | + * | | | |-15 | -15| | + * | | | |-30 | | -30| + * | | | | | | | + * + */ + function refund($ledger_entries, $stamp = null) { + pr(array('LedgerEntry::refund', + compact('ledger_entries', 'stamp'))); + + $A = new Account(); + + $cp_account_id = $A->creditPayableAccountID(); + $cp_account_id = $A->accountReceivableAccountID(); + $receipt_account_id = $A->receiptAccountID(); + + $transaction_id = null; + foreach ($ledger_entries AS $entry) { + $entry = $entry['LedgerEntry']; + $amount = $entry['amount']; + + if (isset($entry['credit_account_id'])) + $refund_account_id = $entry['credit_account_id']; + elseif (isset($entry['CreditLedger']['Account']['id'])) + $refund_account_id = $entry['CreditLedger']['Account']['id']; + elseif (isset($entry['credit_ledger_id'])) + $refund_account_id = $this->Ledger->accountID($entry['credit_ledger_id']); + else + return null; + + // post new refund in the income account + $ids = $A->postLedgerEntry + (array('transaction_id' => $transaction_id), + null, + array('debit_ledger_id' => $A->currentLedgerID($refund_account_id), + 'credit_ledger_id' => $A->currentLedgerID($cp_account_id), + 'effective_date' => $entry['effective_date'], + 'through_date' => $entry['through_date'], + 'amount' => $amount, + 'lease_id' => $entry['lease_id'], + 'customer_id' => $entry['customer_id'], + 'comment' => "Refund; Entry #{$entry['id']}", + ), + array('debit' => array + (array('LedgerEntry' => + array('id' => $entry['id'], + 'amount' => $amount))), + ) + ); + + if ($ids['error']) + return null; + $transaction_id = $ids['transaction_id']; + + pr(array('checkpoint' => 'Posted Refund Ledger Entry', + compact('ids', 'amount', 'refund_account_id', 'cp_account_id'))); + } + + return true; + } + + /************************************************************************** ************************************************************************** **************************************************************************