/** * Store a newly created savingtransaction in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Savingtransaction::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $date = Input::get('date'); $transAmount = Input::get('amount'); $savingaccount = Savingaccount::findOrFail(Input::get('account_id')); $savingtransaction = new Savingtransaction(); $savingtransaction->date = Input::get('date'); $savingtransaction->savingaccount()->associate($savingaccount); $savingtransaction->amount = Input::get('amount'); $savingtransaction->type = Input::get('type'); $savingtransaction->description = Input::get('description'); $savingtransaction->transacted_by = Input::get('transacted_by'); $savingtransaction->save(); // withdrawal if (Input::get('type') == 'debit') { foreach ($savingaccount->savingproduct->savingpostings as $posting) { if ($posting->transaction == 'withdrawal') { $debit_account = $posting->debit_account; $credit_account = $posting->credit_account; } } $data = array('credit_account' => $credit_account, 'debit_account' => $debit_account, 'date' => Input::get('date'), 'amount' => Input::get('amount'), 'initiated_by' => 'system', 'description' => 'cash withdrawal'); $journal = new Journal(); $journal->journal_entry($data); Savingtransaction::withdrawalCharges($savingaccount, $date, $transAmount); Audit::logAudit(date('Y-m-d'), Confide::user()->username, 'savings withdrawal', 'Savings', Input::get('amount')); } // deposit if (Input::get('type') == 'credit') { foreach ($savingaccount->savingproduct->savingpostings as $posting) { if ($posting->transaction == 'deposit') { $debit_account = $posting->debit_account; $credit_account = $posting->credit_account; } } $data = array('credit_account' => $credit_account, 'debit_account' => $debit_account, 'date' => Input::get('date'), 'amount' => Input::get('amount'), 'initiated_by' => 'system', 'description' => 'cash deposit'); $journal = new Journal(); $journal->journal_entry($data); Audit::logAudit(date('Y-m-d'), Confide::user()->username, 'savings deposit', 'Savings', Input::get('amount')); } return Redirect::to('savingtransactions/show/' . $savingaccount->id); }
public static function creditAccounts($data) { $savingaccount = Savingaccount::findOrFail(array_get($data, 'account_id')); $savingtransaction = new Savingtransaction(); $savingtransaction->date = array_get($data, 'date'); $savingtransaction->savingaccount()->associate($savingaccount); $savingtransaction->amount = array_get($data, 'amount'); $savingtransaction->type = array_get($data, 'type'); $savingtransaction->description = 'savings deposit'; $savingtransaction->save(); // deposit if (array_get($data, 'type') == 'credit') { foreach ($savingaccount->savingproduct->savingpostings as $posting) { if ($posting->transaction == 'deposit') { $debit_account = $posting->debit_account; $credit_account = $posting->credit_account; } } $data = array('credit_account' => $credit_account, 'debit_account' => $debit_account, 'date' => array_get($data, 'date'), 'amount' => array_get($data, 'amount'), 'initiated_by' => 'system', 'description' => 'cash deposit'); $journal = new Journal(); $journal->journal_entry($data); Audit::logAudit(date('Y-m-d'), Confide::user()->username, 'savings deposit', 'Savings', array_get($data, 'amount')); } }