示例#1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Budget();
     $model->attributes = $_POST;
     $result = $model->save();
     $this->sendAjaxResponse($model);
 }
示例#2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('cs_budgets')->delete();
     $amount = array("10-100", "100-200", "200-500", "500-1000", "1000-2000", "> 2000");
     foreach ($amount as $price) {
         $bg = new Budget();
         $bg->price = $price;
         $bg->save();
     }
 }
示例#3
0
 public function doOldImport()
 {
     DB::delete('DELETE FROM `cache`');
     // delete old data:
     foreach (Auth::user()->accounts()->get() as $acc) {
         $acc->delete();
     }
     foreach (Auth::user()->budgets()->get() as $b) {
         $b->delete();
     }
     foreach (Auth::user()->categories()->get() as $b) {
         $b->delete();
     }
     foreach (Auth::user()->beneficiaries()->get() as $b) {
         $b->delete();
     }
     foreach (Icon::get() as $icon) {
         $icon->delete();
     }
     $data = file_get_contents('http://commondatastorage.googleapis.com/nder/import.json');
     $json = json_decode($data);
     $map = array();
     $map['accounts'] = array();
     $map['icons'] = array();
     // all accounts:
     foreach ($json->accounts as $account) {
         $newAccount = new Account();
         $newAccount->name = Crypt::encrypt($account->name);
         $newAccount->balance = floatval($account->balance);
         $newAccount->fireflyuser_id = Auth::user()->id;
         $newAccount->date = $account->date;
         $newAccount->save();
         $map['accounts'][$account->id] = $newAccount->id;
     }
     // all icons:
     foreach ($json->icons as $icon) {
         $newIcon = new Icon();
         $newIcon->file = $icon->file;
         $newIcon->save();
         $map['icons'][intval($icon->id)] = $newIcon->id;
     }
     // all beneficiaries:
     foreach ($json->beneficiaries as $ben) {
         $nb = new Beneficiary();
         $nb->fireflyuser_id = Auth::user()->id;
         $nb->name = Crypt::encrypt($ben->name);
         $nb->save();
         $map['beneficiaries'][$ben->id] = $nb->id;
     }
     // all budgets
     foreach ($json->budgets as $bd) {
         $nbg = new Budget();
         $nbg->fireflyuser_id = Auth::user()->id;
         $nbg->name = Crypt::encrypt($bd->name);
         $nbg->date = $bd->date;
         $nbg->amount = floatval($bd->amount);
         $nbg->save();
         $map['budgets'][$bd->id] = $nbg->id;
     }
     // all categories:
     foreach ($json->categories as $c) {
         $nc = new Category();
         $nc->fireflyuser_id = Auth::user()->id;
         $nc->icon_id = intval($map['icons'][intval($c->icon_id)]);
         $nc->name = Crypt::encrypt($c->name);
         $nc->showtrend = intval($c->showtrend);
         $nc->save();
         $map['categories'][$c->id] = $nc->id;
     }
     foreach ($json->targets as $t) {
         $nt = new Target();
         $nt->fireflyuser_id = Auth::user()->id;
         $nt->account_id = $map['accounts'][$t->account_id];
         $nt->description = Crypt::encrypt($t->description);
         $nt->amount = floatval($t->amount);
         $nt->duedate = $t->duedate;
         $nt->startdate = $t->startdate;
         $nt->save();
         $map['targets'][$t->id] = $nt->id;
     }
     foreach ($json->transactions as $t) {
         $nt = new Transaction();
         $nt->fireflyuser_id = Auth::user()->id;
         $nt->account_id = $map['accounts'][$t->account_id];
         $nt->budget_id = is_null($t->budget_id) ? NULL : intval($map['budgets'][$t->budget_id]);
         $nt->category_id = is_null($t->category_id) ? NULL : $map['categories'][$t->category_id];
         $nt->beneficiary_id = is_null($t->beneficiary_id) ? NULL : $map['beneficiaries'][$t->beneficiary_id];
         $nt->description = Crypt::encrypt($t->description);
         $nt->amount = floatval($t->amount);
         $nt->date = $t->date;
         $nt->onetime = intval($t->onetime);
         $nt->save();
         $map['transactions'][$t->id] = $nt->id;
     }
     foreach ($json->transfers as $t) {
         $nt = new Transfer();
         $nt->fireflyuser_id = Auth::user()->id;
         $nt->account_from = $map['accounts'][$t->account_from];
         $nt->account_to = $map['accounts'][$t->account_to];
         $nt->category_id = is_null($t->category_id) ? NULL : $map['categories'][$t->category_id];
         $nt->budget_id = is_null($t->budget_id) ? NULL : intval($map['budgets'][$t->budget_id]);
         $nt->target_id = is_null($t->target_id) ? NULL : intval($map['targets'][$t->target_id]);
         $nt->description = Crypt::encrypt($t->description);
         $nt->amount = floatval($t->amount);
         $nt->date = $t->date;
         $nt->save();
         $map['targets'][$t->id] = $nt->id;
     }
     //
     //var_dump($data);
     // create everything from this file.
     // we map the old id's to the new one to save problems.
     return 'Old data successfully imported.';
 }
示例#4
0
 public function update($id)
 {
     try {
         if (!Session::uid()) {
             throw new Exception('Not enough rights');
         }
         if (!$id || !isset($_POST['reason']) || !isset($_POST['notes'])) {
             throw new Exception('Invalid parameters');
         }
         $budget = new Budget();
         if (!$budget->loadById($id)) {
             throw new Exception('Invalid budget');
         }
         $budget->reason = $_POST['reason'];
         $budget->notes = $_POST['notes'];
         $budget->save('id');
         return $this->setOutput(array('success' => true, 'message' => 'Budget updated'));
     } catch (Exception $e) {
         return $this->setOutput(array('success' => false, 'message' => $e->getMessage()));
     }
 }
 public function createBudget($data)
 {
     $budget = new Budget();
     $budget->code = $data->code;
     $budget->dipa_id = $data->dipa_id;
     $budget->budget_year = $data->budget_year;
     $budget->satker_code = $data->satker_code;
     $budget->activity_code = $data->activity_code;
     $budget->output_code = $data->output_code;
     $budget->suboutput_code = $data->suboutput_code;
     $budget->component_code = $data->component_code;
     $budget->subcomponent_code = $data->subcomponent_code;
     $budget->account_code = $data->account_code;
     $budget->total_budget_limit = $data->total_budget_limit;
     $budget->save();
 }
示例#6
0
 public function updateBudget($amount, $budget_id = 0, $budgetDepletedMessage = true)
 {
     $budgetDepletedSent = false;
     if ($budget_id > 0) {
         $budget = new Budget();
         if ($budget->loadById($budget_id)) {
             $remainingFunds = $budget->getRemainingFunds();
             $budget->remaining = $remainingFunds;
             $budget->save("id");
             if ($remainingFunds <= 0 && $budgetDepletedMessage == true) {
                 $runnerNickname = $this->getNickname();
                 $subject = "Depleted - Budget " . $budget_id . " (For " . $budget->reason . ")";
                 $link = SECURE_SERVER_URL . "team?showUser="******"&tab=tabBudgetHistory";
                 $body = '<p>Hi ' . $runnerNickname . '</p>';
                 $body .= "<p>Budget " . $budget_id . " for " . $budget->reason . "<br/> is now depleted.</p>";
                 $body .= '<p>If your budget has gone under 0.00, you will need to ask the user who ' . 'granted you the Budget to close out this budget for you.</p>';
                 $body .= '<p>To go to the Team Page, click <a href="' . $link . '">here</a></p>';
                 $body .= '<p>- Worklist.net</p>';
                 $plain = 'Hi ' . $runnerNickname . '\\n\\n';
                 $plain .= "Budget " . $budget_id . " for " . $budget->reason . "\n is now depleted.\n\n";
                 $plain .= 'If your budget has gone under 0.00, you will need to ask the user who ' . 'granted you the Budget to close out this budget for you.\\n\\n';
                 $plain .= 'To go to the Team Page, click ' . $link . "\n\n";
                 $plain .= '- Worklist.net\\n\\n';
                 if (!Utils::send_email($this->getUsername(), $subject, $body, $plain)) {
                     error_log("User.class.php: Utils::send_email failed on depleted Runner warning");
                 }
                 $budgetDepletedSent = true;
             }
         } else {
             error_log("User.class.php: Utils::send_email failed on depleted budget Runner warning - invalid budget id:" . $budget_id);
         }
     }
     $this->setBudget($this->setRemainingFunds());
     $this->save();
 }