/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $income = new Income(); $income->amount = $request->amount; $income->description = $request->description; $income->frequency = $request->frequency; $income->fk_category_id = $request->fk_category_id; $income->fk_user_id = Auth::user()->id; if ($income->save()) { Flash::success(config('globalvars.flashMessages.dataSaved')); } else { Flash::error(config('globalvars.flashMessages.dataNotSaved')); } return redirect('/income'); }
public static function applyBuildEffect($building, $city) { switch ($building->Name) { case "Farm": $income = Income::find($city->Object_id); $income->food += 0.1; $income->save(); break; case "Quarry": $income = Income::find($city->Object_id); $income->stone += 0.1; $income->save(); break; case "Silversmith": $income = Income::find($city->Object_id); $income->silver += 0.1; $income->save(); break; case "Platinum mine": $income = Income::find($city->Object_id); $income->platinum += 0.1; $income->save(); break; case "Goldsmith": $income = Income::find($city->Object_id); $income->gold += 0.1; $income->save(); break; } }
public function store(BookingRequest $request) { $booking = array('car_type_id' => $request->car_type_id, 'number_of_passengers' => $request->number_of_passengers, 'pickup_time' => $request->pickup_date_part . ' ' . $request->pickup_time_part, 'ip_info' => $request->ip_info); $newBooking = Booking::create($booking); flash()->success('Your booking has been created!')->important(); if (!empty($request->comment1)) { //children comment $comment1 = array('booking_id' => $newBooking->id, 'comment_type_id' => '1', 'role_id' => '1', 'comment' => $request->comment1); Comment::create($comment1); } if (!empty($request->comment2)) { //general comment $comment2 = array('booking_id' => $newBooking->id, 'comment_type_id' => '2', 'role_id' => '1', 'comment' => $request->comment2); Comment::create($comment2); } $change = array('booking_id' => $newBooking->id, 'change_type_id' => '4', 'user_id' => Auth::user()->id, 'from' => null, 'to' => null); Change::create($change); $passenger = User::firstOrNew(['email' => $request->email]); $passenger->name = $request->name; $passenger->phone = $request->phone; $passenger->save(); $role = array('booking_id' => $newBooking->id, 'role_type_id' => '2', 'user_id' => $passenger->id); Role::create($role); $price = array('booking_id' => $newBooking->id, 'income_type_id' => '1', 'amount_eur' => $request->price); Income::create($price); $locationArray = $request->location; foreach ($request->address as $order => $address_id) { $route_point = null; $route_point = array('booking_id' => $newBooking->id, 'location_id' => $locationArray[$order], 'address_id' => $address_id, 'order' => $order); Route_point::create($route_point); } return redirect('bookings'); }
/** * Homepage Method * @method index * @return view The homepage HTML. */ public function index() { // TODO: optimize these queries. // TODO: Decide whether or now to show a monthly earnings, instead of // just a weekly breakdown of the totals. $data['incomes'] = Income::all()->sortByDesc('amount'); $data['expenses'] = Expense::all()->sortByDesc('amount'); $data['totalIncome'] = DB::table('incomes')->sum('amount') / 4; $data['totalExpenses'] = DB::table('expenses')->sum('amount') / 4; $data['weeklyWorth'] = $data['totalIncome'] - $data['totalExpenses']; return view('index', $data); }
/** * Run the database seed for account "Compte joint". * * @return void */ public function runAccount1($date) { Income::create(['envelope_id' => 1, 'amount' => 850, 'date' => $date]); Income::create(['envelope_id' => 2, 'amount' => 200, 'date' => $date]); Income::create(['envelope_id' => 3, 'amount' => 750, 'date' => $date]); Income::create(['envelope_id' => 4, 'amount' => 200, 'date' => $date]); Income::create(['envelope_id' => 5, 'amount' => 100, 'date' => $date]); Income::create(['envelope_id' => 6, 'amount' => 100, 'date' => $date]); Income::create(['envelope_id' => 7, 'amount' => 50, 'date' => $date]); Income::create(['envelope_id' => 8, 'amount' => 50, 'date' => $date]); Income::create(['envelope_id' => 10, 'amount' => 200, 'date' => $date]); }
/** * Get who it's tied to in one shot * * @return array[0] the amount or Carbon date by which this capital is set to begin * @return array[1] the Income or Expense object **/ public function endsWhen() { $ends = (string) $this->end_at . '_end'; $object = FALSE; if ($this->end_at === 'income') { $object = Income::findOrFail($this->income_end_id); } if ($this->end_at === 'expenses') { $object = Expense::findOrFail($this->expenses_end_id); } return array($object, $this->{$ends}); }
/** * Query incomes related to account * @return \Illuminate\Database\Eloquent\Builder Query */ public function incomes() { return Income::whereIn('envelope_id', function (QueryBuilder $query) { $query->select('id')->from('envelopes')->where('account_id', $this->id); })->orderBy('incomes.date'); }
public function store(ReservationRequest $request) { //booking $booking = array('car_type_id' => $request->car_type_id, 'number_of_passengers' => $request->number_of_passengers, 'pickup_time' => $request->pickup_date_part . ' ' . $request->pickup_time_part); $newBooking = Booking::create($booking); // main passenger //user (main passenger) $mainpassenger = new User(); $mainpassenger->name = $request->name; $mainpassenger->phone = $request->phone; $mainpassenger->save(); //role (main passenger) $role = array('booking_id' => $newBooking->id, 'role_type_id' => '2', 'user_id' => $mainpassenger->id); Role::create($role); //email receiver //user (email receiver) $emailreceiver = User::firstOrCreate(['email' => $request->email]); //role (email receiver) $role = array('booking_id' => $newBooking->id, 'role_type_id' => '5', 'user_id' => $emailreceiver->id); Role::create($role); //route points //start $route_point = array('booking_id' => $newBooking->id, 'location_id' => $request->start_location_id, 'sub_location_id' => $request->start_sub_location_id, 'description' => $request->start_description, 'order' => 1); Route_point::create($route_point); //via points $descriptionArray = $request->description; //if via array is not empty if (!empty($request->location_id)) { foreach ($request->location_id as $order => $location_id) { $route_point = null; $route_point = array('booking_id' => $newBooking->id, 'location_id' => $location_id, 'description' => $descriptionArray[$order], 'order' => $order); Route_point::create($route_point); } } //end $route_point = null; $route_point = array('booking_id' => $newBooking->id, 'location_id' => $request->end_location_id, 'description' => $request->end_description, 'order' => 99); Route_point::create($route_point); //general comment if (!empty($request->comment)) { $comment = array('booking_id' => $newBooking->id, 'comment_type_id' => '2', 'role_id' => '1', 'comment' => $request->comment); Comment::create($comment); } //price $price = Income_list::where('car_type_id', $request->car_type_id)->where('direction_id', $request->direction_id)->where('income_type_id', 1)->whereNull('user_id')->first(); $income = array('booking_id' => $newBooking->id, 'income_type_id' => '1', 'amount_eur' => $price->amount_eur); Income::create($income); //cashflow if ($request->payment_type_id == 3) { $receiver_id = 1; //receiver is driver $due_date = $newBooking->pickup_time; //on the day of travel } else { $receiver_id = 4; //receiver is us (admin) $pickup_time = new Carbon($newBooking->pickup_time); $due_date = $pickup_time->subHours(48); //48 hours before trip } $cashflow = array('booking_id' => $newBooking->id, 'payer_id' => 2, 'receiver_id' => $receiver_id, 'payment_type_id' => $request->payment_type_id, 'payment_status_id' => 1, 'amount_eur' => $price->amount_eur, 'due_date' => $due_date); Cashflow::create($cashflow); //log reservation creation $change = array('booking_id' => $newBooking->id, 'change_type_id' => '4', 'user_id' => 1, 'from' => null, 'to' => null); Change::create($change); //send email Mail::queue('emails.reservation', ['passenger' => $mainpassenger], function ($message) use($emailreceiver) { $message->from('*****@*****.**', 'Transfer Praha')->to($emailreceiver->email, null)->subject('Booking confirmation'); }); flash()->success('Your booking has been created!')->important(); return redirect('reservation/confirmation'); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $income = Income::findOrFail($id); $income->delete(); return redirect()->route('incomes.index')->with('message', 'Item deleted successfully.'); }
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.'); } } } } } } }
/** * Deletes an income * * @param $id * * @return array */ public function delete($id) { $income = $this->income->findOrFail($id); $income->delete($id); }
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.'); }
public function destroy($id) { Income::destroy($id); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Income::destroy($id); return redirect('/income'); }