public function run() { DB::table('user_categories')->delete(); User_category::create(['uid' => 1, 'category_name' => 'default fill', 'balance' => 0.0, 'top_limit' => 0.0, 'saved' => 0.0, 'class' => 255, 'rank' => 1000]); }
private function do_the_math($entid, $ucid, $total, $date, $is_add, $is_move = 0, $is_delete = 0, $paid_from = 0, $entry_type = 0) { if ($ucid > 1) { $uc = User_category::find($ucid); if ($is_add) { switch ($uc->class) { case 8: case 10: // Is a CC or Bank Account $uc->balance = $uc->balance + $total; break; case 20: // Is a normal acct if (!$is_delete) { $uc->saved = $uc->saved + $total; } else { // means its in same month; we need to actually reduce the balance if (date('m-Y') == date('m-Y', strtotime($date))) { $uc->balance = $uc->balance - $total; } else { $uc->saved = $uc->saved + $total; } } break; case 30: case 40: // Is a savings or external savings $uc->saved = $uc->saved + $total; //is in current month? if (date('m-Y') == date('m-Y', strtotime($date))) { if ($entry_type == 20) { // its a move if ($is_delete) { $uc->balance = $uc->balance - $total; } else { $uc->balance = $uc->balance + $total; } } } break; } } else { switch ($uc->class) { case 8: case 10: // Is a CC or Bank Account $uc->balance = $uc->balance - $total; break; case 20: // Is a normal acct if ($is_delete) { // wil lhappen } else { $this->save_entry_section($ucid, $entid, 2, $total); if (date('m-Y') == date('m-Y', strtotime($date))) { $uc->balance = $uc->balance + $total; } } break; case 30: case 40: // Is a savings or external savings if ($uc->saved > 0) { if ($uc->saved >= $total) { $uc->saved = $uc->saved - $total; } else { $uc->saved = 0.0; } if (!$is_delete) { $this->save_entry_section($ucid, $entid, 1, $total); } } if (date('m-Y') == date('m-Y', strtotime($date))) { $uc->balance = $uc->balance - $total; } break; } } $uc->save(); } else { // means someone bought something with debit/cash or a withdraw if ($ucid == 0) { $uc = User_category::find($this->bank_info['ucid']); if ($is_add) { $uc->balance = $uc->balance + $total; $uc->save(); } else { // means debit / check / withdraw, so need to reduce the bank balance $uc->balance = $uc->balance - $total; $uc->save(); } } } }
public function convert_savings() { $uc = User_category::find(Input::get('ucid')); if ($uc->uid != $this->user->uid) { return Redirect::to('/budget'); } $saved = $uc->saved; $uc->balance = 0.0; $uc->saved = 0.0; $uc->top_limit = $saved; $uc->class = 20; // setting to normal $uc->save(); return Redirect::to('/home'); }