From 3a7ee1a5cb8a567dec6e5d04333e40ceec664fee Mon Sep 17 00:00:00 2001 From: Sander Dorigo Date: Mon, 30 Jun 2014 15:57:05 +0200 Subject: [PATCH] Create new accounts. --- .../Account/EloquentAccountRepository.php | 45 ++++++++++++++++--- app/models/Account.php | 3 +- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php index 5c03c33304..ce88daa031 100644 --- a/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php +++ b/app/lib/Firefly/Storage/Account/EloquentAccountRepository.php @@ -17,14 +17,47 @@ class EloquentAccountRepository implements AccountRepositoryInterface } public function store() { - $account = new \Account; - $account->name = Input::get('name'); - if($account->isValid()) { - + + $default = \AccountType::where('description','Default account')->first(); + $balanceAT = \AccountType::where('description','Initial balance account')->first(); + + $account = new \Account; + $account->active = true; + + $account->user()->associate(\Auth::user()); + $account->name = \Input::get('name'); + $account->accountType()->associate($default); + + if(!$account->isValid()) { + \Log::error('Could not create account: ' . $account->validator->messages()->first()); + $this->validator = $account->validator; + return false; } - $this->validator = $account->validator; - return false; + + $account->save(); + + $balance = floatval(\Input::get('openingbalance')); + if($balance != 0.00) { + // create account + $initial = new \Account; + $account->active = false; + + $account->user()->associate(\Auth::user()); + $account->name = \Input::get('name').' initial balance'; + $account->accountType()->associate($balanceAT); + $account->save(); + + // create journal (access helper!) + + + // create journal + + // create transaction + + // create + } + } } \ No newline at end of file diff --git a/app/models/Account.php b/app/models/Account.php index ffc5863ca9..42102906a1 100644 --- a/app/models/Account.php +++ b/app/models/Account.php @@ -6,7 +6,8 @@ class Account extends Elegant public static $rules = [ - 'name' => 'required|between:100,100', + 'name' => 'required|between:1,100', + 'user_id' => 'required|exists:users,id' ]; public function accountType()