示例#1
0
 /**
  * @return Budget
  */
 public function convert()
 {
     // is mapped? Then it's easy!
     if (isset($this->mapped[$this->index][$this->value])) {
         $budget = Auth::user()->budgets()->find($this->mapped[$this->index][$this->value]);
     } else {
         $budget = Budget::firstOrCreateEncrypted(['name' => $this->value, 'user_id' => Auth::user()->id, 'active' => true]);
     }
     return $budget;
 }
示例#2
0
 /**
  * @param $user
  */
 private function createBudgets($user)
 {
     $set = [Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]), Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id])];
     $current = new Carbon();
     /** @var Budget $budget */
     foreach ($set as $budget) {
         // some budget limits:
         $start = clone $current;
         $end = clone $current;
         $start->startOfMonth();
         $end->endOfMonth();
         BudgetLimit::create(['budget_id' => $budget->id, 'startdate' => $start->format('Y-m-d'), 'amount' => 500, 'repeats' => 0, 'repeat_freq' => 'monthly']);
     }
 }
 /**
  * @param Carbon $date
  */
 protected function createDrinksAndOthers(Carbon $date)
 {
     $start = clone $date;
     $end = clone $date;
     $today = new Carbon();
     $start->startOfMonth();
     $end->endOfMonth();
     $current = clone $start;
     while ($current < $end && $current < $today) {
         // weekly drink:
         $thisDate = clone $current;
         $thisDate->addDay();
         $fromAccount = $this->findAccount('MyBank Checking Account');
         $toAccount = $this->findAccount('Cafe Central');
         $category = Category::firstOrCreateEncrypted(['name' => 'Drinks', 'user_id' => $this->user->id]);
         $budget = Budget::firstOrCreateEncrypted(['name' => 'Going out', 'user_id' => $this->user->id]);
         $amount = rand(1500, 3600) / 100;
         $journal = TransactionJournal::create(['user_id' => $this->user->id, 'transaction_type_id' => 1, 'transaction_currency_id' => 1, 'description' => 'Going out for drinks', 'completed' => 1, 'date' => $thisDate]);
         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);
         // shopping at some (online) shop:
         $current->addWeek();
     }
 }
 /**
  * @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;
 }