Example #1
0
 /**
  * @test
  * @return void
  */
 public function it_deletes_a_budget()
 {
     $this->logInUser();
     $budget = Budget::forCurrentUser()->first();
     $response = $this->apiCall('DELETE', '/api/budgets/' . $budget->id);
     $this->assertEquals(204, $response->getStatusCode());
     $this->missingFromDatabase('budgets', ['user_id' => $this->user->id, 'name' => $budget->name]);
 }
Example #2
0
 /**
  * For the pie chart
  * GET api/totals/spentOnBudgets
  * @param Request $request
  * @return array
  */
 public function spentOnBudgets(Request $request)
 {
     $budgets = Budget::forCurrentUser()->with('transactions')->get();
     $totals = [];
     foreach ($budgets as $budget) {
         $totals[] = ['id' => $budget->id, 'name' => $budget->name, 'spentInDateRange' => $budget->getSpentInDateRange($request->get('from'), $request->get('to'))];
     }
     return $totals;
 }
Example #3
0
 /**
  * Change to a static constructor or not, up to you
  */
 public function __construct($budgets = NULL)
 {
     $this->type = Budget::TYPE_FLEX;
     $this->budgets = $budgets ?: Budget::forCurrentUser()->whereType(Budget::TYPE_FLEX)->get();
     $this->amount = $this->calculate('amount');
     $this->spentBeforeStartingDate = $this->calculate('spentBeforeStartingDate');
     $this->spentOnOrAfterStartingDate = $this->calculate('spentOnOrAfterStartingDate');
     $this->receivedOnOrAfterStartingDate = $this->calculate('receivedOnOrAfterStartingDate');
     $this->unallocatedAmount = 100 - $this->amount;
     $this->allocatedPlusUnallocatedAmount = 100;
 }
Example #4
0
 /**
  * Change to a static constructor or not, up to you
  * @param null $budgets
  */
 public function __construct($budgets = NULL)
 {
     $this->type = Budget::TYPE_FIXED;
     $this->budgets = $budgets ?: Budget::forCurrentUser()->whereType(Budget::TYPE_FIXED)->get();
     $this->amount = $this->calculate('amount');
     $this->remaining = $this->calculate('remaining');
     $this->cumulative = $this->calculate('cumulative');
     $this->spentBeforeStartingDate = $this->calculate('spentBeforeStartingDate');
     $this->spentOnOrAfterStartingDate = $this->calculate('spentOnOrAfterStartingDate');
     $this->receivedOnOrAfterStartingDate = $this->calculate('receivedOnOrAfterStartingDate');
     //Transform budgets
     $resource = createCollection($this->budgets, new BudgetTransformer());
     $this->budgets = transform($resource);
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     //		$router->model('accounts', Account::class);
     Route::bind('accounts', function ($id) {
         return Account::forCurrentUser()->findOrFail($id);
     });
     Route::bind('budgets', function ($id) {
         return Budget::forCurrentUser()->findOrFail($id);
     });
     Route::bind('transactions', function ($id) {
         return Transaction::forCurrentUser()->findOrFail($id);
     });
     Route::bind('favouriteTransactions', function ($id) {
         return FavouriteTransaction::forCurrentUser()->findOrFail($id);
     });
     Route::bind('savedFilters', function ($id) {
         return SavedFilter::forCurrentUser()->findOrFail($id);
     });
 }
Example #6
0
 /**
  * This method is only for the test at the moment
  * @param Request $request
  * @return Response
  */
 public function index(Request $request)
 {
     if ($request->has('fixed')) {
         $budgets = Budget::forCurrentUser()->whereType('fixed')->orderBy('name', 'asc')->get();
     } else {
         if ($request->has('unassigned')) {
             $budgets = Budget::forCurrentUser()->whereType('unassigned')->orderBy('name', 'asc')->get();
         } else {
             if ($request->has('flex')) {
                 //            $budgets = Budget::forCurrentUser()->whereType('flex')->get();
                 $remainingBalance = app('remaining-balance')->calculate();
                 //            return $remainingBalance->flexBudgetTotals->budgets['data'];
                 $budgets = $remainingBalance->flexBudgetTotals->budgets;
             } else {
                 $budgets = Budget::forCurrentUser()->orderBy('name', 'asc')->get();
             }
         }
     }
     $budgets = $this->transform($this->createCollection($budgets, new BudgetTransformer(['includeExtra' => true])))['data'];
     return response($budgets, Response::HTTP_OK);
 }
 /**
  * Change to a static constructor or not, up to you
  * @param null $budgets
  */
 public function __construct($budgets = NULL)
 {
     $this->type = Budget::TYPE_UNASSIGNED;
     $this->budgets = $budgets ?: Budget::forCurrentUser()->whereType(Budget::TYPE_UNASSIGNED)->get();
 }
Example #8
0
 /**
  * A basic functional test example.
  * @test
  * @return void
  */
 public function it_does_not_update_an_assigned_budget_if_values_are_the_same()
 {
     $this->logInUser();
     $budget = Budget::forCurrentUser()->where('type', '!=', 'unassigned')->first();
     $response = $this->apiCall('PUT', '/api/budgets/' . $budget->id, ['name' => $budget->name, 'amount' => $budget->amount]);
     $this->seeInDatabase('budgets', ['user_id' => $this->user->id, 'name' => $budget->name, 'amount' => $budget->amount]);
     $this->assertEquals(304, $response->getStatusCode());
 }