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 GET /verbs */ public function getDashboard() { $user_id = \Auth::user()->id; $transactionModel = new \App\Transaction(); $transaction_array = $transactionModel->userQuizStats($user_id); //dump($transaction_array); return view('quiz.dashboard')->with('transaction_array', $transaction_array); }
/** * 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 save($id, SaveTransactionRequest $request) { $transaction = $this->transactionRepository->getById($id); if ($transaction && Gate::denies('save', $transaction)) { return $this->json->error('You cannot alter other\'s Transactions ...'); } if (!$transaction) { $transaction = new \App\Transaction(); } $transaction->fill($request->except(['customer_id'])); \App\Customer::find($request->get('customer_id'))->transactions()->save($transaction); return $this->json->success(); }
public function run() { // Uncomment the below to wipe the table clean before populating DB::table('transactions')->delete(); $delivered = App\Shipment::delivered()->get(); foreach ($delivered as $delivery) { $order = $delivery->order; App\Transaction::create(['order_id' => $order->id, 'amount' => $order->orderItems->sum('price')]); } }
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); }
/** * Responds to requests to POST /quiz/query * Processes and returns validated form. */ public function postQuizQuery(Request $request) { $this->validate($request, ['p1' => 'required|min:1', 'p2' => 'required|min:1', 'p3' => 'required|min:1', 'p4' => 'required|min:1', 'p5' => 'required|min:1', 'p6' => 'required|min:1']); $request_conj_array = array(); $request_conj_array[1] = $request->p1; $request_conj_array[2] = $request->p2; $request_conj_array[3] = $request->p3; $request_conj_array[4] = $request->p4; $request_conj_array[5] = $request->p5; $request_conj_array[6] = $request->p6; //dump($request_conj_array); $verb = $request->infinitive_it; $infinitive_it = $request->infinitive_it; $tense = $request->tense; //dump($verb); //dump($tense); $verbModel = new \App\Verb(); $verbs_for_dropdown = $verbModel->getVerbsFullyConjugated(); //dump($verbs_for_dropdown); $tenseModel = new \App\Tense(); $tenses_for_dropdown = $tenseModel->getTensesForDropdown(); $conjugationModel = new \App\Verb(); $conjugations = \App\Conjugation::where('verb_id', '=', $verb)->where('tense_id', '=', $tense)->get(); //dump($conjugations); $conjugation_array = array(); foreach ($conjugations as $conjugation) { $conjugation_array[1] = $conjugation->first_p_singular; $conjugation_array[2] = $conjugation->second_p_singular; $conjugation_array[3] = $conjugation->third_p_singular; $conjugation_array[4] = $conjugation->first_p_plural; $conjugation_array[5] = $conjugation->second_p_plural; $conjugation_array[6] = $conjugation->third_p_plural; } //dump($conjugation_array); # returns an array of all persons (i.e. "first person singular" etc.) $formModel = new \App\Form(); $person_array = $formModel->getPersonArray(); # multi-dimensional array used to store response and validation class $response_class_array = array(); # needed to start at 1 to avoid offset error since tense array begins at 1 for ($i = 1; $i < 7; $i++) { if ($conjugation_array[$i] == $request_conj_array[$i]) { # Bootstrap class that puts green "success" border around form field $response_class_array[0][$i] = 'form-group has-success has-feedback'; # Boostrap class that puts green checkmark in text box $response_class_array[1][$i] = 'glyphicon-ok'; # used for user statistics $response_class_array[2][$i] = TRUE; } else { # Bootstrap class that puts red "error" border around form field $response_class_array[0][$i] = 'form-group has-error has-feedback'; # Boostrap class that puts red "x" in text box $response_class_array[1][$i] = 'glyphicon-remove'; # used for user statistics $response_class_array[2][$i] = FALSE; } } $user_id = \Auth::id(); //dump($user_id); $params_for_transaction = array(); $params_for_transaction[0] = $user_id; $params_for_transaction[1] = $verb; $params_for_transaction[2] = $tense; $params_for_transaction[3] = $response_class_array[2][1]; $params_for_transaction[4] = $response_class_array[2][2]; $params_for_transaction[5] = $response_class_array[2][3]; $params_for_transaction[6] = $response_class_array[2][4]; $params_for_transaction[7] = $response_class_array[2][5]; $params_for_transaction[8] = $response_class_array[2][6]; $transactionModel = new \App\Transaction(); $transactionModel->addTransaction($params_for_transaction); // # returns an array of all persons (i.e. "first person singular" etc.) // $formModel = new \App\Form(); // $person_array = $formModel->getPersonArray(); // // //for testing purposes // //dump($tenses_for_dropdown); // // dump($response_class_array); // dump($person_array); $ptext = array('p0', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6'); $p = array(); for ($i = 1; $i < 7; $i++) { $p[$i] = $request->{$ptext}[$i]; } //$request->p1; //dump($p); //dump($request); return view('quiz.query')->with(['verbs_for_dropdown' => $verbs_for_dropdown, 'tenses_for_dropdown' => $tenses_for_dropdown, 'response_class_array' => $response_class_array, 'person_array' => $person_array, 'p' => $p, 'infinitive_it' => $infinitive_it, 'Request' => $request]); }
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]); }