/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $disk = Storage::disk('database');
     $env = App::environment();
     Log::debug('Environment is ' . $env);
     $fileName = 'seed.' . $env . '.json';
     if ($disk->exists($fileName)) {
         Log::debug('Now seeding ' . $fileName);
         $file = json_decode($disk->get($fileName), true);
         if (is_array($file)) {
             // run the file:
             TestData::run($file);
             return;
         }
         Log::error('No valid data found (' . $fileName . ') for environment ' . $env);
         return;
     }
     Log::info('No seed file (' . $fileName . ') for environment ' . $env);
 }
 /**
  * @param        $description
  * @param Carbon $date
  * @param        $amount
  *
  * @return TransactionJournal
  */
 protected function createWater($description, Carbon $date, $amount)
 {
     $date = new Carbon($date->format('Y-m') . '-10');
     // paid on 10th
     $fromAccount = TestData::findAccount($this->user, 'TestData Checking Account');
     $toAccount = TestData::findAccount($this->user, 'Vitens');
     $category = Category::firstOrCreateEncrypted(['name' => 'House', 'user_id' => $this->user->id]);
     $budget = Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $this->user->id]);
     $journal = TransactionJournal::create(['user_id' => $this->user->id, 'transaction_type_id' => 1, 'transaction_currency_id' => 1, 'description' => $description, 'completed' => 1, 'date' => $date]);
     Transaction::create(['account_id' => $fromAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $amount * -1]);
     Transaction::create(['account_id' => $toAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $amount]);
     $journal->categories()->save($category);
     $journal->budgets()->save($budget);
     return $journal;
 }
Example #3
0
 /**
  * @param array $data
  */
 public static function run(array $data)
 {
     $seeder = new TestData($data);
     $seeder->go();
 }
Example #4
0
 /**
  * @param User $user
  */
 private function openingBalanceSavings(User $user)
 {
     // opposing account for opening balance:
     $opposing = Account::create(['user_id' => $user->id, 'account_type_id' => 6, 'name' => 'Opposing for savings', 'active' => 1, 'encrypted' => 1]);
     // savings
     $savings = TestData::findAccount($user, 'TestData Savings');
     $journal = TransactionJournal::create(['user_id' => $user->id, 'transaction_type_id' => 4, 'transaction_currency_id' => 1, 'description' => 'Opening balance for savings account', 'completed' => 1, 'date' => $this->start->format('Y-m-d')]);
     // transactions
     Transaction::create(['account_id' => $opposing->id, 'transaction_journal_id' => $journal->id, 'amount' => -10000]);
     Transaction::create(['account_id' => $savings->id, 'transaction_journal_id' => $journal->id, 'amount' => 10000]);
 }