First attempt at an import/migration procedure.

This commit is contained in:
James Cole
2014-07-03 21:31:32 +02:00
parent 35c90a32e9
commit 1836249407
13 changed files with 259 additions and 89 deletions

View File

@@ -11,53 +11,51 @@ class EloquentAccountRepository implements AccountRepositoryInterface
{
}
public function count() {
public function count()
{
return \Auth::user()->accounts()->count();
}
public function store() {
public function storeWithInitialBalance($data, \Carbon\Carbon $date, $amount = 0)
{
$account = $this->store($data);
$initialBalanceAT = \AccountType::where('description', 'Initial balance account')->first();
$initial = new \Account;
$initial->accountType()->associate($initialBalanceAT);
$initial->user()->associate(\Auth::user());
$initial->name = $data['name'] . ' initial balance';
$initial->active = 0;
$initial->save();
// create new transaction journal (and transactions):
/** @var \Firefly\Storage\TransactionJournal\TransactionJournalInterface $transactionJournal */
$transactionJournal = \App::make('Firefly\Storage\TransactionJournal\TransactionJournalInterface');
$transactionJournal->createSimpleJournal(
$initial, $account, 'Initial Balance for ' . $data['name'], $amount, $date
);
$default = \AccountType::where('description','Default account')->first();
$balanceAT = \AccountType::where('description','Initial balance account')->first();
return $account;
$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;
}
$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
}
}
public function store($data)
{
$defaultAT = \AccountType::where('description', 'Default account')->first();
$at = isset($data['account_type']) ? $data['account_type'] : $defaultAT;
$account = new \Account;
$account->accountType()->associate($at);
$account->user()->associate(\Auth::user());
$account->name = $data['name'];
$account->active = isset($data['active']) ? $data['active'] : 1;
$account->save();
return $account;
}
}