/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $acc = Account::find($id); $ledgers = Ledger::where('account_id', $acc->id)->get(); //dd($ledgers); return view('regular.show', compact('ledgers'), compact('acc')); }
/** * * Description: Save Transaction * Component: AddTransactionFormModal * */ public function saveTransaction(SaveTransactionPostRequest $request) { $account = Account::find($request->input('id')); $transactionType = TransactionType::where('code', $request->input('transactionType'))->first(); if ($transactionType->account_type === 'DR') { $this->validate($request, ['amount' => 'max:' . $account->balance]); } $transaction = Transaction::create(['transactionDate' => Carbon::parse($request->input('transactionDate'))->toDateString(), 'amount' => $request->input('amount'), 'transaction_type_id' => $transactionType->id, 'account_id' => $request->input('id'), 'notes' => $request->input('notes') === '' ? null : $request->input('notes')]); $account->balance = $this->recomputeRunningBalance($account->id); $account->save(); return response()->json(['message' => 'New Transaction Posted.']); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // check if account exists $account = Account::find($id); if ($account === null || $account->user_id != Auth::user()->id) { // stuff to pass into view $title = "Error"; $errmsg = "The account does not exist."; return view('errors.error', compact('errmsg', 'title', 'heading')); } // start database transaction DB::transaction(function () use($account) { // delete account $account->delete(); // get obsolete transfers $transfers = Transfer::whereNull('account_from')->whereNull('account_to')->get(); // delete transfers foreach ($transfers as $transfer) { $transfer->delete(); } }); // flash message session()->flash('flash_message', 'Account deleted successfully.'); // redirect to accounts return redirect()->route('accounts.index'); }
public function attachEntityToAccount($entity, $a) { $account = Account::find($a); $account->entities()->attach($entity); }
public function show($id) { $accounts = Account::find($id); return view('accounts.show', compact('accounts')); }
public function postIndex() { $user = Auth::user(); $id = Input::get('payment'); /* *There is an invisible field called form that tells what form was submitted * */ if (Input::get('form') == 'trans') { $monthNum = substr(Input::get('date'), 0, 2); $month = date('M', mktime(0, 0, 0, $monthNum, 10)); $year = substr(Input::get('date'), -4); $transaction = new Transaction(); $transaction->userID = $user->id; $transaction->date = Input::get('date'); $transaction->amount = Input::get('amount'); $transaction->typeID = Input::get('type'); $transaction->note = Input::get('note'); $transaction->year = $year; $transaction->month = $month; if ($id == 'cash') { $month = Month::where('userID', $user->id)->where('name', $month)->where('year', date("Y"))->first(); $month->cash -= Input::get('amount'); $month->save(); $transaction->accountID = 0; } else { $transaction->accountID = $id; $account = Account::find($id); //add for credit subtract for bank if ($account->accountType == 'c') { $account->balance += Input::get('amount'); } else { $account->balance -= Input::get('amount'); } $account->save(); } $transaction->save(); return redirect('options')->with('message', 'Transaction added successfully.'); } else { if (Input::get('form') == 'type') { $type = new Type(); $type->userID = $user->id; $type->name = Input::get('name'); $type->save(); return redirect('options')->with('message', 'Category added successfully.'); } else { if (Input::get('form') == 'payment') { $monthNum = substr(Input::get('date'), 0, 2); $month = date('M', mktime(0, 0, 0, $monthNum, 10)); $year = substr(Input::get('date'), -4); $amount = Input::get('amount'); $bankID = Input::get('bank'); $ccID = Input::get('payment'); $note = Input::get('note'); $date = Input::get('date'); if ($ccID == 'cash') { $month2 = Month::where('userID', $user->id)->where('name', $month)->first(); $month2->cash = $month2->cash + $amount; $month2->save(); if ($bankID == 'cash') { $month2 = Month::where('userID', $user->id)->where('name', $month)->first(); $month2->cash = $month2->cash - $amount; $month2->save(); } else { $bank = Account::find($bankID); $bank->balance = $bank->balance - $amount; $bank->save(); } $transfer = new Transfer(); $transfer->userID = $user->id; $transfer->creditAccountID = $bankID; $transfer->debitAccountID = 0; $transfer->amount = $amount; $transfer->note = $note; $transfer->date = $date; $transfer->year = $year; $transfer->month = $month; $transfer->save(); } else { $cc = Account::find($ccID); if ($bankID == 'cash') { $month2 = Month::where('userID', $user->id)->where('name', $month)->first(); $month2->cash = $month2->cash - $amount; $month2->save(); } else { $bank = Account::find($bankID); $bank->balance = $bank->balance - $amount; $bank->save(); } if ($cc->accountType == 'b') { //transfer $cc->balance = $cc->balance + $amount; $transfer = new Transfer(); $transfer->userID = $user->id; $transfer->creditAccountID = $bankID; $transfer->debitAccountID = $ccID; $transfer->amount = $amount; $transfer->note = $note; $transfer->date = $date; $transfer->year = $year; $transfer->month = $month; $transfer->save(); } else { //payment $cc->balance = $cc->balance - $amount; $payment = new Payment(); $payment->userID = $user->id; $payment->creditAccountID = $bankID; $payment->debitAccountID = $ccID; $payment->amount = $amount; $payment->note = $note; $payment->date = $date; $payment->year = $year; $payment->month = $month; $payment->save(); } $cc->save(); } return redirect('options')->with('message', 'Payment saved successfully.'); } else { if (Input::get('form') == 'cc') { $cc = new Account(); $cc->userID = $user->id; $cc->name = Input::get('name'); $cc->balance = Input::get('balance'); $cc->creditLimit = Input::get('limit'); $cc->statementDay = Input::get('date'); $cc->accountType = 'c'; $cc->save(); return redirect('options')->with('message', 'Credit Card added successfully.'); } else { if (Input::get('form') == 'bank') { $bank = new Account(); $bank->userID = $user->id; $bank->name = Input::get('name'); $bank->balance = Input::get('balance'); $bank->accountType = 'b'; $bank->save(); return redirect('options')->with('message', 'Bank Account added successfully.'); } else { if (Input::get('form') == 'income') { $date = Input::get('date'); $monthNum = substr($date, 0, 2); $month = date('M', mktime(0, 0, 0, $monthNum, 10)); $amount = Input::get('amount'); $bankID = Input::get('bank'); $year = substr(Input::get('date'), -4); $income = new Income(); $income->userID = $user->id; $income->month = $month; $income->amount = $amount; $income->note = Input::get('note'); $income->date = $date; $income->year = $year; if ($bankID == "cash") { $income->accountID = 0; $month = Month::where('userID', $user->id)->where('name', $month)->first(); $month->cash = $month->cash + $amount; $month->save(); } else { $income->accountID = $bankID; $bank = Account::find($bankID); $bank->balance = $bank->balance + $amount; $bank->save(); } $income->save(); return redirect('options')->with('message', 'Income added successfully.'); } } } } } } }
public function saveEditInputManual(Request $request, $id) { $validator = Validator::make($request->all(), ['tanggal' => 'required|date', 'nominal' => 'required'], ['tanggal.required' => 'Tanggal tidak boleh kosong.', 'tanggal.date' => 'Input harus tanggal.', 'nominal.required' => 'Nominal tidak boleh kosong.']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } $account_id = $request->get('account_id'); $account = Account::find($account_id); $input = $request->all() + ['type' => $account->type]; if (AccountSaldo::find($id)->update($input)) { return redirect('/account/saldo?tanggal=' . $request->get('tanggal'))->with('succcess', 'Sukses ubah saldo.'); } return redirect()->back()->withErrors(['failed' => 'Gagal ubah saldo.']); }
public function addLeadWithSelectedEntity(Request $request) { $lead = new Lead(); $lead->name = $request->name; $lead->activity_setting = $request->setting; $lead->active = 1; $lead->progress = 0; $lead->level = 0; if ($request->next_action) { $lead->next_action = Carbon::createFromFormat('m/d/Y g:i A', $request->next_action)->toDateTimeString(); } else { $lead->next_action = null; } $lead->entity_id = $request->entity_id; $lead->save(); $user = User::find($request->userId); $user->leads()->attach($lead); $account = Account::find($user->account_id); $entity = Entity::find($request->entity_id); $account->entities()->attach($entity); $activity = new Activity(); $activity->lead_id = $lead->id; $activity->user_id = $user->id; $activity->type = 'info'; $activity->status = 'done'; $activity->name = 'Created'; $activity->visible = 1; $activity->note = $request->note; $activity->schedule_time = Carbon::now()->toDateTimeString(); $activity->save(); }
public function getByAccount($id) { $account = Account::find($id); return $account->entities; }
public function incomeDelete($id) { $user = Auth::user(); $date = Input::get('date'); $amount = Input::get('amount'); $bankID = Input::get('bank'); $note = Input::get('note'); $income = Income::where('id', $id)->where('userID', $user->id)->first(); if ($income->accountID == 0) { $month = Month::where('userID', $user->id)->where('name', date('M'))->first(); $month->cash = $month->cash - $income->amount; $month->save(); } else { $origBank = Account::find($income->accountID); //add original transaction value to bank account $origBank->balance = $origBank->balance - $income->amount; $origBank->save(); } $income->forceDelete(); return redirect('home')->with('message', 'Income deleted successfully.'); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(LedgerRequest $request) { $acc = Account::find($request->id); $ledger = new Ledger(); //set default values.. $ledger->account_id = $request->id; $ledger->curDate = date('Y-m-d'); $ledger->particulars = $request->particulars; $ledger->reference = $request->reference; $ledger->penaltyDue = 0.0; $ledger->interestPayed = 0.0; $ledger->penaltyPayed = 0.0; /* removed this part for accepting just payment in updating the ledger. can be restored back to accepting loaning by uncommenting this code and the corresponting code on it's view. */ // if($request->actn=='true'){ // $ledger->avaiment = $request->cash; // $ledger->principal = 0; // $acc->balance += $request->cash; // $ledger->balance = $acc->balance; // } // else{ $interest = 0; //check if due if due give penalty $diff = \Carbon\Carbon::now()->diffInDays($acc->dueDate->copy(), false); if ($diff < 0) { $ledger->penaltyDue = $acc->amountGranted * $acc->loan->penalty * abs($diff) / 360; $ledger->penaltyPayed = $ledger->penaltyDue; } //compute normal interest if (count($acc->ledgers) == 1) { // $interest = ($acc->amountGranted * $acc->loan->intRate * $acc->terms)/360; // $interestDue = $interest*($acc->dateGranted->diffInDays(\Carbon\Carbon::now())); //dd($acc->dateGranted->diffInDays(\Carbon\Carbon::now())); //ditoo $ledger->interestDue = $acc->amountGranted * $acc->loan->intRate * $acc->dateGranted->diffInDays(\Carbon\Carbon::now()) / 360; //dd($ledger->interestDue); //dd($interestDue); } //interest if past due and with partial.. if ($diff < 0 && count($acc->ledgers) > 1) { $ledger->interestDue = $acc->amountGranted * $acc->loan->intRate * $acc->dateGranted->diffInDays(\Carbon\Carbon::now()) / 360; // $interest = ($acc->amountGranted * $acc->loan->intRate * $acc->terms)/360; // $interestDue = $interest*($acc->dueDate->diffInDays(\Carbon\Carbon::now())); } //loan specific actions.. switch ($acc->loan_id - 1) { case 0: if (count($acc->ledgers) == 1) { $ledger->interestDue = $acc->amountGranted * $acc->loan->intRate * $acc->terms / 360; $ledger->interestPayed = $ledger->interestDue; } break; case 1: //by default is already working how it should break; case 2: case 3: case 4: case 5: $half = \Carbon\Carbon::now()->diffInDays($acc->dateGranted->copy()->addDays($acc->terms / 2), false); $ledger->interestDue = 0; if ($half == 0 || $half < 0) { $ledger->interestDue = $acc->amountGranted * $acc->loan->intRate * abs($half) / 360; } break; case 6: $penaltyDue = 0; $penaltyPayed = 0; if ($diff < 0) { $ledger->interestDue = $acc->amountGranted * $acc->loan->intRate * abs($diff) / 360; $ledger->interestPayed = $ledger->interestDue; } break; } $ledger->principal = $request->cash - ($ledger->penaltyDue + $ledger->interestDue); $ledger->avaiment = 0; $acc->balance -= $ledger->principal; $ledger->balance = $acc->balance; $ledger->amountPayed = $request->cash; //} $ledger->save(); $acc->save(); flash()->success('Updated Ledger'); return redirect('admin/accounts/' . $request->id); }
<?php /* |-------------------------------------------------------------------------- | Routes File |-------------------------------------------------------------------------- | | Here is where you will register all of the routes in an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('/', function () { $test = \App\Account::find(4)->logs; dump($test->toArray()); }); Route::get('/test', 'TestController@test'); /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | This route group applies the "web" middleware group to every route | it contains. The "web" middleware group is defined in your HTTP | kernel and includes session state, CSRF protection, and more. | */ Route::group(['middleware' => ['web']], function () { // }); Route::group(['middleware' => 'web'], function () {
public function get($id) { return Account::find($id); }
/** * Show the application dashboard to the user. * * @return Response */ public function index() { //add check for row in month table with correct month //make it if not there. $user = Auth::user(); $month = date("M"); $year = date('Y'); $banks = DB::select('select * from accounts where userID = :id and accountType = "b"', ['id' => $user->id]); $cc = DB::select('select * from accounts where userID = :id and accountType = "c"', ['id' => $user->id]); $credits = DB::select('select * from income where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]); $accounts = DB::select('select * from accounts where userID = :id', ['id' => $user->id]); $debits = DB::select('select * from transactions where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]); $transfers = DB::select('select * from transfers where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]); $payments = DB::select('select * from payments where userID = :id and month = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => $year]); $accountNames = []; foreach ($accounts as $account) { $accountNames = $accountNames + [$account->id => $account->name]; } $income = 0; $spent = 0; //sum up for months profit foreach ($credits as $credit) { $income += $credit->amount; } foreach ($debits as $debit) { if ($debit->accountID == 0 && $debit->month == date("M")) { $spent = $spent + $debit->amount; } else { //check to make sure teh cc id is not a bank if so this is a transfer and doesn't get counted $account2 = Account::find($debit->accountID); if ($account2->accountType == 'b' && $debit->month == date("M")) { //this is a payment on a cc $spent = $spent + $debit->amount; } } } foreach ($payments as $payment) { if ($payment->month == date("M")) { $spent = $spent + $payment->amount; } } $profit = $income - $spent; $monthData = Month::where('userID', $user->id)->where('name', date("M"))->where('year', date("Y"))->first(); $monthData->income = $income; $monthData->profit = $profit; $monthData->save(); //prepare spending amounts for types for the pie chart. $types = DB::select('select * from types where userID = :id order by name ASC', ['id' => $user->id]); $spending = []; $typeNames = []; foreach ($types as $type) { $typeNames = $typeNames + [$type->id => $type->name]; $tmp = DB::select('select * from transactions where userID = :id and month = :month and typeID = :typeID and year = :year', ['id' => $user->id, 'month' => $month, 'typeID' => $type->id, 'year' => $year]); $sum = 0; foreach ($tmp as $i) { $sum = $sum + $i->amount; } if ($sum != 0) { array_push($spending, ["sum" => $sum, "name" => $type->name]); } } arsort($spending); $cash = DB::select('select cash from month where userID = :id and name = :month and year = :year', ['id' => $user->id, 'month' => $month, 'year' => date("Y")]); return view('home')->with('banks', $banks)->with('cc', $cc)->with('income', $income)->with('profit', $profit)->with('spending', $spending)->with('cash', $cash)->with('accountNames', $accountNames)->with('typeNames', $typeNames)->with('transactions', $debits)->with('incomeData', $credits)->with('payments', $payments)->with('transfers', $transfers); }
/** * update. * * @param int $id * @param array $input */ public function update($id, $input) { $model = $this->model->find($id); return $this->savePost($model, $input); }
/** * * Description: Update UserActive * Component: UserActiveComponent * */ public function updateUserActive(Request $request) { $account = Account::find($request->input('id')); $account->user->is_active = !$account->user->is_active; $account->user->save(); return response()->json(['status' => 'success']); }
public function printLedger(Request $request) { $acc = Account::find($request->id); $ledgers = Ledger::where('account_id', $acc->id)->get(); return \PDF::loadHTML(view('reports.ledger', compact('acc', 'ledgers')))->stream('ledger.pdf'); }
/** * Create an account. * @param Request $request * @request string $name * @request string|null $description * @request string|null $type {personal|corporate} * @object Answer * @return {status_code, result:{name, id, type, description, created_at, updated_at}} */ public function create(Request $request) { $item = Account::create($request->all()); try { $item->save(); } catch (\Exception $e) { $this->error[] = $e; return Answer::set(500, Lang::get('api.notEnoughData')); } return Answer::set(200, Account::find($item->id)); }
public function getDelete($id) { $accounts = \App\Account::find($id); if (is_null($accounts)) { \Session::flash('flash_message', 'Account not found.'); return redirect('\\accounts'); } $accounts->delete(); \Session::flash('flash_message', 'Your' . $accounts->name . ' account was deleted.'); return redirect('/accounts'); }