Exemple #1
0
 public function info($id)
 {
     try {
         $user = User::find(Session::uid());
         if (!$user->getId()) {
             throw new Exception('You have to be logged in to access user info!');
         }
         $budget = new Budget();
         $budget->loadById((int) $id);
         if (!$budget->id) {
             throw new Exception('Invalid budget id');
         }
         $sources = $budget->loadSources();
         $budgetClosed = !$budget->active;
         $allocated = $budget->getAllocatedFunds();
         $submitted = $budget->getSubmittedFunds();
         $paid = $budget->getPaidFunds();
         $transfered = $budget->getTransferedFunds();
         $remaining = $budget->amount - $allocated - $submitted - $paid - $transfered;
         $data = array('amount' => (double) $budget->amount, 'closed' => $budgetClosed, 'reason' => $budget->reason, 'req_user_authorized' => strpos(BUDGET_AUTHORIZED_USERS, "," . $user->getId() . ",") !== false, 'seed' => (int) $budget->seed, 'sources' => $sources, 'notes' => $budget->notes, 'remaining' => (double) $remaining, 'allocated' => (double) $allocated, 'submitted' => (double) $submitted, 'paid' => (double) $paid, 'transferred' => (double) $transfered, 'receiver_id' => $budget->receiver_id);
         return $this->setOutput(array('success' => true, 'data' => $data));
     } catch (Exception $e) {
         return $this->setOutput(array('success' => true, 'message' => $e->getMessage()));
     }
 }