public function addTransaction(&$arr) { # First get the user id //$user_id = \App\User::where('name','=', 'Jill')->pluck('id'); //$user_id = Auth::id(); $response_array = array(); $response_array[0] = $arr[3]; $response_array[1] = $arr[4]; $response_array[2] = $arr[5]; $response_array[3] = $arr[6]; $response_array[4] = $arr[7]; $response_array[5] = $arr[8]; // the following did not work to count boolean values // $count_correct = array_count_values($response_array)[TRUE]; // this removes false values from array and returns count of true // http://stackoverflow.com/questions/16428635/php-count-number-of-true-values-in-a-boolean-array $count_correct = count(array_filter($response_array)); $pct_correct = doubleval($count_correct / 6 * 100); // Code here to enter transaction into the database $transaction = new \App\Transaction(); $transaction->user_id = $arr[0]; $transaction->verb_id = $arr[1]; $transaction->tense_id = $arr[2]; $transaction->response_1ps = $response_array[0]; $transaction->response_2ps = $response_array[1]; $transaction->response_3ps = $response_array[2]; $transaction->response_1pp = $response_array[3]; $transaction->response_2pp = $response_array[4]; $transaction->response_3pp = $response_array[5]; $transaction->pct_correct = $pct_correct; $transaction->created_at = \Carbon\Carbon::now()->toDateTimeString(); $transaction->updated_at = \Carbon\Carbon::now()->toDateTimeString(); $transaction->save(); }
/** * Responds to requests to */ public function getPage($id = null) { // update the public_items table and mark the item as bought $item = \App\PublicItem::where('id', '=', $id)->find($id); //dump($item->toArray()); $price = null; // make sure the item isn't one that is posted by the user $user_id = $item['user_id']; if ($user_id == \Auth::id()) { \Session::flash('flash_message', 'You cannot purchase an item that you posted!'); // fetch the items from the public_items table $items = \App\PublicItem::where('bought', '=', 0)->get(); //dump($items->toArray()); $itemsArray = $items->toArray(); //dump($itemArray->toArray()); // calculate the tax and total return view('pongo.browse_items')->with('items', $itemsArray); } $price = $item['price']; //echo $price; $tax = round($price * 0.1, 2); //echo $tax; $total = $price + $tax; //echo $total; // update the item as bought $item->bought = TRUE; $item->save(); // update the transaction table for the user who buys the product $transactionBuy = new \App\Transaction(); $transactionBuy->transaction_type = "BUY"; $transactionBuy->public_item_id = $id; $transactionBuy->user_id = \Auth::id(); $transactionBuy->tax = $tax; $transactionBuy->total = $total; $transactionBuy->save(); //dump($transactionBuy->toArray()); $transactionBuyObject = (object) $transactionBuy->toArray(); $itemAsArray = $item->toArray(); $itemObject = (object) $itemAsArray; // send an email to the user who made the purchase \Mail::send(['html' => 'pongo.sales_receipt_email'], array('item' => $itemObject, 'transactionBuy' => $transactionBuyObject), function ($message) { $message->to(\Auth::user()->email, \Auth::user()->name)->subject('You made a puchase on Pongo!'); }); // update the transaction table for user who sold the product $transactionSell = new \App\Transaction(); $transactionSell->transaction_type = "SELL"; $transactionSell->public_item_id = $id; $transactionSell->user_id = $user_id; $transactionSell->tax = $tax; $transactionSell->total = $total; $transactionSell->save(); // delete the item from the added_items $addedItem = \App\AddedItem::where('one_line_description', '=', $item->one_line_description)->get(); //dump($publicItem[0]); $addedItem[0]->delete(); \Session::flash('flash_message', 'You successfully purchased the ' . $itemObject->item . '!'); return view('pongo.receipt_details')->with(['item' => $itemObject, 'transactionBuy' => $transactionBuyObject]); }
public function createTransaction() { $data = \Input::all(); $user = \App\User::where('email', '=', $data['email'])->first(); $slots = $user->slots()->where('transaction_id', '=', 0)->get(); $amt = $data['amount'] / 500; $data = \Input::all(); $stat = \App\Status::find(4); $transaction = new \App\Transaction(); $transaction->transaction_number = $data['transaction_number']; $transaction->amount = $data['amount']; $transaction->save(); $stat_id = 4; for ($i = 0; $i < $amt; $i++) { $transaction->slots()->save($slots[$i]); $slots[$i]->status()->detach(); $stat->slots()->attach($slots[$i]); } return redirect('/valence'); }
public function postCreate(Request $request) { $this->validate($request, ['trans_name' => 'required', 'trans_type' => 'required', 'amount' => 'required', 'recipient' => 'required']); $transactions = new \App\Transaction(); $transactions->trans_name = $request->trans_name; $transactions->trans_type = $request->trans_type; $transactions->amount = $request->amount; $transactions->recipient = $request->recipient; $transactions->memo = $request->memo; $transactions->account_id = $request->account_id; if ($transactions->trans_type != 'Deposit/Credit') { $transactions->amount = $transactions->amount * -1; } if (\Input::hasFile('file')) { $file = \Input::file('file'); $file->move('uploads', $file->getClientOriginalName()); $fileurl = 'uploads/' . $file->getClientOriginalName(); $transactions->receipt_url = $fileurl; } $transactions->save(); \Session::flash('flash_message', 'Your transaction was added'); return redirect('/transactions/' . $transactions->account_id); }
public function create() { $data = \Input::all(); if ($data['transaction_number'] != '') { $amount_slot = $data['amount'] / 500; $transaction = new \App\Transaction(); $transaction->transaction_number = $data['transaction_number']; $transaction->amount = $data['amount']; $transaction->save(); $stat_id = 4; } else { $amount_slot = $data['amount'] / 500; $transaction = new \App\Transaction(); $transaction->transaction_number = 'No Payment'; $transaction->amount = 0; $transaction->save(); $stat_id = 2; } $check = \Auth::User()->name . '' . Carbon::now(); $user = \Auth::User(); $limit = $user->limit; // dd($limit); if ($data['num_slots'] > $limit) { for ($i = 0; $i < $limit; $i++) { if ($i < $amount_slot) { $slot = new \App\Slot(); $slot->slot_code = str_random(15); $slot->slot_rank = 0; $slot->user_id = \Auth::User()->id; $transaction->slots()->save($slot); $status = \App\Status::find($stat_id); $status->slots()->attach($slot); $user = \Auth::User(); $user->limit = $user->limit - 1; $user->save(); $tree = new \App\Tree(); $tree->down1 = $slot->id - 1; $tree->down2 = $slot->id - 2; $tree->down3 = $slot->id - 3; $tree->down4 = $slot->id - 4; $tree->down5 = $slot->id - 5; $tree->down6 = $slot->id - 6; $tree->save(); $slot->tree_id = $tree->id; $slot->save(); } else { $slot = new \App\Slot(); $slot->slot_code = str_random(15); $slot->slot_rank = 0; $slot->user_id = \Auth::User()->id; $slot->save(); $status = \App\Status::find(2); $status->slots()->attach($slot); $user = \Auth::User(); $user->limit = $user->limit - 1; $user->save(); $tree = new \App\Tree(); $tree->down1 = $slot->id - 1; $tree->down2 = $slot->id - 2; $tree->down3 = $slot->id - 3; $tree->down4 = $slot->id - 4; $tree->down5 = $slot->id - 5; $tree->down6 = $slot->id - 6; $tree->save(); $slot->tree_id = $tree->id; $slot->save(); } } } else { for ($i = 0; $i < $data['num_slots']; $i++) { if ($i < $amount_slot) { $slot = new \App\Slot(); $slot->slot_code = str_random(15); $slot->slot_rank = 0; $slot->user_id = \Auth::User()->id; $transaction->slots()->save($slot); $status = \App\Status::find($stat_id); $status->slots()->attach($slot); $user = \Auth::User(); $user->limit = $user->limit - 1; $user->save(); $tree = new \App\Tree(); $tree->down1 = $slot->id - 1; $tree->down2 = $slot->id - 2; $tree->down3 = $slot->id - 3; $tree->down4 = $slot->id - 4; $tree->down5 = $slot->id - 5; $tree->down6 = $slot->id - 6; $tree->save(); $slot->tree_id = $tree->id; $slot->save(); } else { $slot = new \App\Slot(); $slot->slot_code = str_random(15); $slot->slot_rank = 0; $slot->user_id = \Auth::User()->id; $slot->save(); $status = \App\Status::find(2); $status->slots()->attach($slot); $user = \Auth::User(); $user->limit = $user->limit - 1; $user->save(); $tree = new \App\Tree(); $tree->down1 = $slot->id + 1; $tree->down2 = $slot->id + 2; $tree->down3 = $slot->id + 3; $tree->down4 = $slot->id + 4; $tree->down5 = $slot->id + 5; $tree->down6 = $slot->id + 6; $tree->save(); $slot->tree_id = $tree->id; $slot->save(); } } } $user = \Auth::User(); $ranks = 0; $slots = $user->slots()->get(); return view('dashboard.user.profile')->with(['slots' => $slots, 'num_slots' => $data['num_slots'], 'limit' => $limit, 'user' => $user, 'ranks' => $ranks]); }