示例#1
0
 /**
  * @param User $user
  */
 public static function createAssetAccounts(User $user)
 {
     $assets = ['TestData Checking Account', 'TestData Savings', 'TestData Shared', 'TestData Creditcard', 'Emergencies', 'STE'];
     // first two ibans match test-upload.csv
     $ibans = ['NL11XOLA6707795988', 'NL96DZCO4665940223', 'NL81RCQZ7160379858', 'NL19NRAP2367994221', 'NL40UKBK3619908726', 'NL38SRMN4325934708'];
     $assetMeta = [['accountRole' => 'defaultAsset'], ['accountRole' => 'savingAsset'], ['accountRole' => 'sharedAsset'], ['accountRole' => 'ccAsset', 'ccMonthlyPaymentDate' => '2015-05-27', 'ccType' => 'monthlyFull'], ['accountRole' => 'savingAsset'], ['accountRole' => 'savingAsset']];
     foreach ($assets as $index => $name) {
         // create account:
         $account = Account::create(['user_id' => $user->id, 'account_type_id' => 3, 'name' => $name, 'active' => 1, 'encrypted' => 1, 'iban' => $ibans[$index]]);
         foreach ($assetMeta[$index] as $name => $value) {
             AccountMeta::create(['account_id' => $account->id, 'name' => $name, 'data' => $value]);
         }
     }
 }
 /**
  * @covers FireflyIII\Http\Controllers\Chart\AccountController::all
  */
 public function testAllShared()
 {
     $user = FactoryMuffin::create('FireflyIII\\User');
     $account = FactoryMuffin::create('FireflyIII\\Models\\Account');
     $accounts = new Collection([$account]);
     $date = new Carbon();
     $this->be($user);
     // make it shared:
     AccountMeta::create(['account_id' => $account->id, 'name' => 'accountRole', 'data' => 'sharedAsset']);
     // mock!
     $repository = $this->mock('FireflyIII\\Repositories\\Account\\AccountRepositoryInterface');
     // fake!
     $repository->shouldReceive('getAccounts')->once()->andReturn($accounts);
     $this->call('GET', '/chart/account/month/' . $date->format('Y/m') . '/shared');
     $this->assertResponseOk();
 }
示例#3
0
 /**
  * @param NewUserFormRequest         $request
  * @param AccountRepositoryInterface $repository
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function submit(NewUserFormRequest $request, AccountRepositoryInterface $repository)
 {
     // create normal asset account:
     $assetAccount = ['name' => $request->get('bank_name'), 'iban' => null, 'accountType' => 'asset', 'virtualBalance' => 0, 'active' => true, 'user' => Auth::user()->id, 'accountRole' => 'defaultAsset', 'openingBalance' => round($request->input('bank_balance'), 2), 'openingBalanceDate' => new Carbon(), 'openingBalanceCurrency' => intval($request->input('balance_currency_id'))];
     $repository->store($assetAccount);
     // create savings account
     if (strlen($request->get('savings_balance') > 0)) {
         $savingsAccount = ['name' => $request->get('bank_name') . ' savings account', 'iban' => null, 'accountType' => 'asset', 'virtualBalance' => 0, 'active' => true, 'user' => Auth::user()->id, 'accountRole' => 'savingAsset', 'openingBalance' => round($request->input('savings_balance'), 2), 'openingBalanceDate' => new Carbon(), 'openingBalanceCurrency' => intval($request->input('balance_currency_id'))];
         $repository->store($savingsAccount);
     }
     // create credit card.
     if (strlen($request->get('credit_card_limit') > 0)) {
         $creditAccount = ['name' => 'Credit card', 'iban' => null, 'accountType' => 'asset', 'virtualBalance' => round($request->get('credit_card_limit'), 2), 'active' => true, 'user' => Auth::user()->id, 'accountRole' => 'ccAsset', 'openingBalance' => null, 'openingBalanceDate' => null, 'openingBalanceCurrency' => intval($request->input('balance_currency_id'))];
         $creditCard = $repository->store($creditAccount);
         // store meta for CC:
         AccountMeta::create(['name' => 'ccType', 'data' => 'monthlyFull', 'account_id' => $creditCard->id]);
         AccountMeta::create(['name' => 'ccMonthlyPaymentDate', 'data' => Carbon::now()->year . '-01-01', 'account_id' => $creditCard->id]);
     }
     Session::flash('success', 'New account(s) created!');
     Preferences::mark();
     return redirect(route('index'));
 }
 protected function createAssetAccounts()
 {
     $assets = ['MyBank Checking Account', 'Savings', 'Shared', 'Creditcard', 'Emergencies', 'STE'];
     $ibans = ['NL47JDYU6179706202', 'NL51WGBP5832453599', 'NL81RCQZ7160379858', 'NL19NRAP2367994221', 'NL40UKBK3619908726', 'NL38SRMN4325934708'];
     $assetMeta = [['accountRole' => 'defaultAsset'], ['accountRole' => 'savingAsset'], ['accountRole' => 'sharedAsset'], ['accountRole' => 'ccAsset', 'ccMonthlyPaymentDate' => '2015-05-27', 'ccType' => 'monthlyFull'], ['accountRole' => 'savingAsset'], ['accountRole' => 'savingAsset']];
     foreach ($assets as $index => $name) {
         // create account:
         $account = Account::create(['user_id' => $this->user->id, 'account_type_id' => 3, 'name' => $name, 'active' => 1, 'encrypted' => 1, 'iban' => $ibans[$index]]);
         foreach ($assetMeta[$index] as $name => $value) {
             AccountMeta::create(['account_id' => $account->id, 'name' => $name, 'data' => $value]);
         }
     }
 }
示例#5
0
 /**
  *
  */
 public function createAssetAccounts()
 {
     $user = User::whereEmail('*****@*****.**')->first();
     $assetType = AccountType::whereType('Asset account')->first();
     $ibType = AccountType::whereType('Initial balance account')->first();
     $obType = TransactionType::whereType('Opening balance')->first();
     $euro = TransactionCurrency::whereCode('EUR')->first();
     $acc_a = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Checking account', 'active' => 1]);
     $acc_b = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Savings account', 'active' => 1]);
     $acc_c = Account::create(['user_id' => $user->id, 'account_type_id' => $assetType->id, 'name' => 'Delete me', 'active' => 1, 'virtual_balance' => 123.45]);
     // create account meta:
     AccountMeta::create(['account_id' => $acc_a->id, 'name' => 'accountRole', 'data' => 'defaultAsset']);
     AccountMeta::create(['account_id' => $acc_b->id, 'name' => 'accountRole', 'data' => 'savingAsset']);
     AccountMeta::create(['account_id' => $acc_c->id, 'name' => 'accountRole', 'data' => 'defaultAsset']);
     $acc_d = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Checking account initial balance', 'active' => 0]);
     $acc_e = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Savings account initial balance', 'active' => 0]);
     $acc_f = Account::create(['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Delete me initial balance', 'active' => 0]);
     $this->createJournal(['from' => $acc_d, 'to' => $acc_a, 'amount' => 4000, 'transactionType' => $obType, 'description' => 'Initial Balance for Checking account', 'date' => $this->yasom, 'transactionCurrency' => $euro]);
     $this->createJournal(['from' => $acc_e, 'to' => $acc_b, 'amount' => 10000, 'transactionType' => $obType, 'description' => 'Initial Balance for Savings account', 'date' => $this->yasom, 'transactionCurrency' => $euro]);
     $this->createJournal(['from' => $acc_f, 'to' => $acc_c, 'amount' => 100, 'transactionType' => $obType, 'description' => 'Initial Balance for Delete me', 'date' => $this->yasom, 'transactionCurrency' => $euro]);
 }
示例#6
0
 /**
  * @covers FireflyIII\Helpers\Report\ReportQuery::incomeInPeriodCorrected
  * @covers FireflyIII\Helpers\Report\ReportQuery::queryJournalsWithTransactions
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testIncomeInPeriodCorrectedShared()
 {
     $start = new Carbon('2015-01-01');
     $end = new Carbon('2015-02-01');
     $user = FactoryMuffin::create('FireflyIII\\User');
     FactoryMuffin::create('FireflyIII\\Models\\TransactionType');
     $type = FactoryMuffin::create('FireflyIII\\Models\\TransactionType');
     $expense = FactoryMuffin::create('FireflyIII\\Models\\AccountType');
     $asset = FactoryMuffin::create('FireflyIII\\Models\\AccountType');
     $date = new Carbon('2015-01-12');
     for ($i = 0; $i < 10; $i++) {
         $journal = FactoryMuffin::create('FireflyIII\\Models\\TransactionJournal');
         $journal->date = $date;
         $journal->user_id = $user->id;
         $journal->transaction_type_id = $type->id;
         $journal->save();
         // two transactions:
         $account1 = FactoryMuffin::create('FireflyIII\\Models\\Account');
         $account2 = FactoryMuffin::create('FireflyIII\\Models\\Account');
         $account1->account_type_id = $asset->id;
         $account1->user_id = $user->id;
         $account2->account_type_id = $expense->id;
         $account2->user_id = $user->id;
         $account1->save();
         $account2->save();
         AccountMeta::create(['account_id' => $account1->id, 'name' => 'accountRole', 'data' => 'defaultAsset']);
         $amount = 100;
         if ($i == 8) {
             $amount = 0;
             // at least one "empty" journal.
         }
         // update both transactions
         $journal->transactions[0]->account_id = $account1->id;
         $journal->transactions[0]->amount = $amount * -1;
         $journal->transactions[0]->save();
         $journal->transactions[1]->account_id = $account2->id;
         $journal->transactions[1]->amount = $amount;
         $journal->transactions[1]->save();
     }
     $this->be($user);
     $set = $this->object->incomeInPeriodCorrected($start, $end, true);
     $this->assertCount(9, $set);
 }
示例#7
0
 /**
  * @covers FireflyIII\Helpers\Report\ReportHelper::getIncomeReport
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetIncomeReport()
 {
     // factory!
     $user = FactoryMuffin::create('FireflyIII\\User');
     $this->be($user);
     FactoryMuffin::create('FireflyIII\\Models\\TransactionType');
     $type = FactoryMuffin::create('FireflyIII\\Models\\TransactionType');
     // create five journals in this month for the report:
     $date = Carbon::now()->startOfMonth()->addDay();
     $left = FactoryMuffin::create('FireflyIII\\Models\\Account');
     $right = FactoryMuffin::create('FireflyIII\\Models\\Account');
     $asset = FactoryMuffin::create('FireflyIII\\Models\\AccountType');
     $left->account_type_id = $asset->id;
     $right->account_type_id = $asset->id;
     // save meta for account:
     AccountMeta::create(['account_id' => $left->id, 'name' => 'accountRole', 'data' => 'defaultAsset']);
     AccountMeta::create(['account_id' => $right->id, 'name' => 'accountRole', 'data' => 'defaultAsset']);
     $right->save();
     $left->save();
     for ($i = 0; $i < 5; $i++) {
         $journal = FactoryMuffin::create('FireflyIII\\Models\\TransactionJournal');
         $journal->date = $date;
         $journal->transaction_type_id = $type->id;
         $journal->user_id = $user->id;
         $journal->save();
     }
     // test!
     $object = $this->object->getIncomeReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), true);
     $this->assertCount(5, $object->getIncomes());
 }
 /**
  * @param $attribute
  * @param $value
  * @param $parameters
  *
  * @return bool
  */
 public function validateUniqueAccountNumberForUser($attribute, $value, $parameters) : bool
 {
     $accountId = $this->data['id'] ?? 0;
     $query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')->where('accounts.user_id', auth()->user()->id)->where('account_meta.name', 'accountNumber');
     if (intval($accountId) > 0) {
         // exclude current account from check.
         $query->where('account_meta.account_id', '!=', intval($accountId));
     }
     $set = $query->get(['account_meta.*']);
     /** @var AccountMeta $entry */
     foreach ($set as $entry) {
         if ($entry->data == $value) {
             return false;
         }
     }
     return true;
 }
示例#9
0
 /**
  * @param Account $account
  * @param array   $data
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function updateMetadata(Account $account, array $data)
 {
     $validFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType'];
     foreach ($validFields as $field) {
         $entry = $account->accountMeta()->where('name', $field)->first();
         // update if new data is present:
         if ($entry && isset($data[$field])) {
             $entry->data = $data[$field];
             $entry->save();
         }
         // no entry but data present?
         if (!$entry && isset($data[$field])) {
             $metaData = new AccountMeta(['account_id' => $account->id, 'name' => $field, 'data' => $data[$field]]);
             $metaData->save();
         }
     }
 }
示例#10
0
 /**
  * @covers FireflyIII\Http\Controllers\ReportController::year
  */
 public function testYear()
 {
     $user = FactoryMuffin::create('FireflyIII\\User');
     $journal = FactoryMuffin::create('FireflyIII\\Models\\TransactionJournal');
     $currency = FactoryMuffin::create('FireflyIII\\Models\\TransactionCurrency');
     $account = FactoryMuffin::create('FireflyIII\\Models\\Account');
     // make shared:
     AccountMeta::create(['account_id' => $account->id, 'name' => 'accountRole', 'data' => 'sharedAsset']);
     new Collection([$journal]);
     $this->be($user);
     $helper = $this->mock('FireflyIII\\Helpers\\Report\\ReportHelperInterface');
     $helper->shouldReceive('getAccountReport')->once()->withAnyArgs()->andReturn([]);
     $helper->shouldReceive('getIncomeReport')->once()->withAnyArgs()->andReturn([]);
     $helper->shouldReceive('getExpenseReport')->once()->withAnyArgs()->andReturn([]);
     // mock stuff!
     Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
     Amount::shouldReceive('getAllCurrencies')->andReturn([$currency]);
     Amount::shouldReceive('getCurrencyCode')->andReturn('X');
     Amount::shouldReceive('getCurrencySymbol')->andReturn('X');
     Amount::shouldReceive('format')->andReturn('X');
     $this->call('GET', '/reports/2015/shared');
     $this->assertResponseOk();
 }
示例#11
0
 /**
  * @covers FireflyIII\Repositories\Account\AccountRepository::getSavingsAccounts
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetSavingsAccounts()
 {
     // create three accounts:
     FactoryMuffin::create('FireflyIII\\Models\\AccountType');
     FactoryMuffin::create('FireflyIII\\Models\\AccountType');
     $type = FactoryMuffin::create('FireflyIII\\Models\\AccountType');
     $account1 = FactoryMuffin::create('FireflyIII\\Models\\Account');
     $account1->account_type_id = $type->id;
     $account2 = FactoryMuffin::create('FireflyIII\\Models\\Account');
     $account2->account_type_id = $type->id;
     $account3 = FactoryMuffin::create('FireflyIII\\Models\\Account');
     $account3->account_type_id = $type->id;
     // make them savings accounts:
     $meta = new AccountMeta();
     $meta->name = 'accountRole';
     $meta->data = 'savingAsset';
     $meta->account_id = $account1->id;
     $meta->save();
     $meta = new AccountMeta();
     $meta->name = 'accountRole';
     $meta->data = 'savingAsset';
     $meta->account_id = $account2->id;
     $meta->save();
     $meta = new AccountMeta();
     $meta->name = 'accountRole';
     $meta->data = 'savingAsset';
     $meta->account_id = $account3->id;
     $meta->save();
     // assign to the same user:
     $account2->user_id = $account1->user_id;
     $account3->user_id = $account1->user_id;
     $account1->save();
     $account2->save();
     $account3->save();
     $this->be($account1->user);
     // mock steam balance:
     Steam::shouldReceive('balance')->andReturn(0, 0, 1, 2, 4, 3);
     // get the result from the method:
     $result = $this->object->getSavingsAccounts();
     $this->assertEquals(0, $result->get(0)->difference);
     $this->assertEquals(1, $result->get(1)->difference);
     $this->assertEquals(-1, $result->get(2)->difference);
     $this->assertEquals(100, $result->get(0)->percentage);
     $this->assertEquals(100, $result->get(1)->percentage);
     $this->assertEquals(25, $result->get(2)->percentage);
 }
示例#12
0
 /**
  * @param Account $account
  * @param array   $data
  *
  */
 protected function updateMetadata(Account $account, array $data)
 {
     foreach ($this->validFields as $field) {
         $entry = $account->accountMeta()->where('name', $field)->first();
         if (isset($data[$field])) {
             // update if new data is present:
             if (!is_null($entry)) {
                 $entry->data = $data[$field];
                 $entry->save();
                 continue;
             }
             $metaData = new AccountMeta(['account_id' => $account->id, 'name' => $field, 'data' => $data[$field]]);
             $metaData->save();
         }
     }
 }