diff --git a/app/database/seeds/DatabaseSeeder.php b/app/database/seeds/DatabaseSeeder.php index f357dfd6ec..9912f3c281 100644 --- a/app/database/seeds/DatabaseSeeder.php +++ b/app/database/seeds/DatabaseSeeder.php @@ -19,7 +19,7 @@ class DatabaseSeeder extends Seeder $this->call('TransactionCurrencySeeder'); $this->call('TransactionTypeSeeder'); - if (App::environment() == 'testing') { + if (App::environment() == 'testing' || App::environment() == 'homestead') { $this->call('TestDataSeeder'); } } diff --git a/app/database/seeds/TestDataSeeder.php b/app/database/seeds/TestDataSeeder.php index fa6cb958d0..6ef7c64842 100644 --- a/app/database/seeds/TestDataSeeder.php +++ b/app/database/seeds/TestDataSeeder.php @@ -6,7 +6,6 @@ use Carbon\Carbon; * @SuppressWarnings("TooManyMethods") // I'm fine with this * @SuppressWarnings("CouplingBetweenObjects") // I'm fine with this * @SuppressWarnings("MethodLength") // I'm fine with this - * * Class TestDataSeeder */ @@ -79,64 +78,99 @@ class TestDataSeeder extends Seeder $user = User::create(['email' => 'thegrumpydictator@gmail.com', 'password' => 'james', 'reset' => null, 'remember_token' => null]); - + Log::debug('Created users.'); // create initial accounts and various other stuff: $this->createAssetAccounts($user); + Log::debug('Created asset accounts.'); $this->createBudgets($user); + Log::debug('Created budgets.'); $this->createCategories($user); + Log::debug('Created categories.'); $this->createPiggyBanks($user); + Log::debug('Created piggy banks.'); $this->createReminders($user); + Log::debug('Created reminders.'); $this->createRecurringTransactions($user); + Log::debug('Created recurring transactions.'); $this->createBills($user); + Log::debug('Created bills.'); $this->createExpenseAccounts($user); + Log::debug('Created expense accounts.'); $this->createRevenueAccounts($user); + Log::debug('Created revenue accounts.'); // get some objects from the database: - $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first(); - $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first(); - $landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first(); - $utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first(); + $checking = Account::whereName('Checking account')->orderBy('id', 'DESC')->first(); + Log::debug('Found checking: ' . json_encode($checking)); + $savings = Account::whereName('Savings account')->orderBy('id', 'DESC')->first(); + Log::debug('Found savings: ' . json_encode($savings)); + $landLord = Account::whereName('Land lord')->orderBy('id', 'DESC')->first(); + Log::debug('Found landlord: ' . json_encode($landLord)); + $utilities = Account::whereName('Utilities company')->orderBy('id', 'DESC')->first(); + Log::debug('Found utilities: ' . json_encode($utilities)); $television = Account::whereName('TV company')->orderBy('id', 'DESC')->first(); - $phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first(); - $employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first(); + Log::debug('Found tv company: ' . json_encode($television)); + $phone = Account::whereName('Phone agency')->orderBy('id', 'DESC')->first(); + Log::debug('Found phone company: ' . json_encode($phone)); + $employer = Account::whereName('Employer')->orderBy('id', 'DESC')->first(); + Log::debug('Found employer: ' . json_encode($employer)); - $bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first(); + $bills = Budget::whereName('Bills')->orderBy('id', 'DESC')->first(); + Log::debug('Found bills budget: ' . json_encode($bills)); $groceries = Budget::whereName('Groceries')->orderBy('id', 'DESC')->first(); + Log::debug('Found groceries budget: ' . json_encode($groceries)); $house = Category::whereName('House')->orderBy('id', 'DESC')->first(); + Log::debug('Found house category: ' . json_encode($checking)); $withdrawal = TransactionType::whereType('Withdrawal')->first(); - $deposit = TransactionType::whereType('Deposit')->first(); - $transfer = TransactionType::whereType('Transfer')->first(); + Log::debug('Found withdrawal: ' . json_encode($withdrawal)); + $deposit = TransactionType::whereType('Deposit')->first(); + Log::debug('Found deposit: ' . json_encode($deposit)); + $transfer = TransactionType::whereType('Transfer')->first(); + Log::debug('Found transfer: ' . json_encode($transfer)); $euro = TransactionCurrency::whereCode('EUR')->first(); + Log::debug('Found euro: ' . json_encode($euro)); $rentBill = Bill::where('name', 'Rent')->first(); + Log::debug('Found bill "rent": ' . json_encode($rentBill)); $current = clone $this->_yearAgoStartOfMonth; while ($current <= $this->_startOfMonth) { $cur = $current->format('Y-m-d'); $formatted = $current->format('F Y'); + Log::debug('Now at: ' . $cur); // create expenses for rent, utilities, TV, phone on the 1st of the month. $this->createTransaction($checking, $landLord, 800, $withdrawal, 'Rent for ' . $formatted, $cur, $euro, $bills, $house, $rentBill); + Log::debug('Created rent.'); $this->createTransaction($checking, $utilities, 150, $withdrawal, 'Utilities for ' . $formatted, $cur, $euro, $bills, $house); + Log::debug('Created utilities.'); $this->createTransaction($checking, $television, 50, $withdrawal, 'TV for ' . $formatted, $cur, $euro, $bills, $house); + Log::debug('Created TV.'); $this->createTransaction($checking, $phone, 50, $withdrawal, 'Phone bill for ' . $formatted, $cur, $euro, $bills, $house); + Log::debug('Created phone bill.'); // two transactions. One without a budget, one without a category. $this->createTransaction($checking, $phone, 10, $withdrawal, 'Extra charges on phone bill for ' . $formatted, $cur, $euro, null, $house); + Log::debug('Created extra charges no budget.'); $this->createTransaction($checking, $television, 5, $withdrawal, 'Extra charges on TV bill for ' . $formatted, $cur, $euro, $bills, null); + Log::debug('Created extra charges no category.'); // income from job: $this->createTransaction($employer, $checking, rand(3500, 4000), $deposit, 'Salary for ' . $formatted, $cur, $euro); + Log::debug('Created income.'); $this->createTransaction($checking, $savings, 2000, $transfer, 'Salary to savings account in ' . $formatted, $cur, $euro); + Log::debug('Created savings.'); $this->createGroceries($current); + Log::debug('Created groceries range.'); $this->createBigExpense(clone $current); + Log::debug('Created big expense.'); echo 'Created test-content for ' . $current->format('F Y') . "\n"; $current->addMonth(); @@ -208,15 +242,24 @@ class TestDataSeeder extends Seeder $user = User::whereEmail('thegrumpydictator@gmail.com')->first(); $billID = is_null($bill) ? null : $bill->id; - + Log::debug('String length of encrypted description ("'.$description.'") is: ' . strlen(Crypt::encrypt($description))); /** @var TransactionJournal $journal */ $journal = TransactionJournal::create( [ - 'user_id' => $user->id, 'transaction_type_id' => $type->id, 'transaction_currency_id' => $currency->id, 'bill_id' => $billID, - 'description' => $description, 'completed' => 1, 'date' => $date + 'user_id' => $user->id, + 'transaction_type_id' => $type->id, + 'transaction_currency_id' => $currency->id, + 'bill_id' => $billID, + 'description' => $description, + 'completed' => 1, + 'date' => $date ] ); + //Log::debug('Journal valid: ' . Steam::boolString($journal->isValid())); + //Log::debug('Journal errors: ' . json_encode($journal->getErrors())); + //Log::debug('Journal created: ' . json_encode($journal)); + Transaction::create(['account_id' => $from->id, 'transaction_journal_id' => $journal->id, 'amount' => $amount * -1]); Transaction::create(['account_id' => $to->id, 'transaction_journal_id' => $journal->id, 'amount' => $amount]); @@ -427,10 +470,10 @@ class TestDataSeeder extends Seeder 'user_id' => $user->id, 'name' => 'Gas licht', 'match' => 'no,match', - 'amount_min' => 500, 'amount_max' => 700, + 'amount_min' => 500, 'amount_max' => 700, 'date' => $this->som, - 'active' => 1, 'automatch' => 1, - 'repeat_freq' => 'monthly', 'skip' => 0, + 'active' => 1, 'automatch' => 1, + 'repeat_freq' => 'monthly', 'skip' => 0, ] ); @@ -552,6 +595,7 @@ class TestDataSeeder extends Seeder ); $group->transactionjournals()->save($one); $group->transactionjournals()->save($two); + $group->save(); } diff --git a/app/lib/FireflyIII/Helper/Related/Related.php b/app/lib/FireflyIII/Helper/Related/Related.php index 0627374e74..1732f638ad 100644 --- a/app/lib/FireflyIII/Helper/Related/Related.php +++ b/app/lib/FireflyIII/Helper/Related/Related.php @@ -56,14 +56,36 @@ class Related implements RelatedInterface } $exclude = array_unique($exclude); - $query = $this->getUser()->transactionjournals() - ->withRelevantData() - ->before($end) - ->after($start) - ->whereNotIn('id', $exclude) - ->where('description', 'LIKE', '%' . $query . '%') - ->get(); + /** @var Collection $collection */ + $collection = $this->getUser()->transactionjournals() + ->withRelevantData() + ->before($end) + ->where('encrypted', 0) + ->after($start) + ->whereNotIn('id', $exclude) + ->where('description', 'LIKE', '%' . $query . '%') + ->get(); - return $query; + // manually search encrypted entries: + /** @var Collection $encryptedCollection */ + $encryptedCollection = $this->getUser()->transactionjournals() + ->withRelevantData() + ->before($end) + ->where('encrypted', 1) + ->after($start) + ->whereNotIn('id', $exclude) + ->get(); + $encrypted = $encryptedCollection->filter( + function (\TransactionJournal $journal) use ($query) { + $strPos = strpos($journal->description, $query); + if ($strPos !== false) { + return $journal; + } + } + ); + $collected = $collection->merge($encrypted); + + + return $collected; } }