Esempio n. 1
0
 /**
  * Responds to requests to
  */
 public function getPage($id = null)
 {
     if ($id != null) {
         // find the item in the added_items table
         $item = \App\AddedItem::where('id', '=', $id)->find($id);
         $itemAsArray = $item->toArray();
         // update the added_items table
         if ($itemAsArray) {
             $item->make_public = TRUE;
             // save changes
             $item->save();
             \Session::flash('flash_message', 'You successfully made ' . $item->item . ' public for sale!');
         }
         // add the item to the public_items table
         $publicItem = new \App\PublicItem();
         $publicItem->item = $itemAsArray['item'];
         $publicItem->category = $itemAsArray['category'];
         $publicItem->one_line_description = $itemAsArray['one_line_description'];
         $publicItem->price = $itemAsArray['price'];
         $publicItem->detailed_description = $itemAsArray['detailed_description'];
         $publicItem->user_id = \Auth::id();
         $publicItem->save();
     }
     // fetch the items from the public_items table
     $items = \App\PublicItem::where('bought', '=', 0)->get();
     //dump($items->toArray());
     $itemsArray = $items->toArray();
     //dump($itemsArray);
     return view('pongo.browse_items')->with('items', $itemsArray);
 }
 /**
  * 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]);
 }
Esempio n. 3
0
 /**
  * Responds to requests to
  */
 public function getPage($id = null)
 {
     // get the item
     $item = \App\AddedItem::where('id', '=', $id)->get();
     $itemAsArray = $item->toArray();
     //dump($itemAsArray[0]);
     $itemObject = (object) $itemAsArray[0];
     //$addedItemsArray = $addedItems->toArray();
     return view('pongo.item_details')->with('item', $itemObject);
 }
Esempio n. 4
0
 /**
  * Responds to requests to
  */
 public function getPage($id = null)
 {
     // find the item to delete
     $item = \App\AddedItem::find($id);
     //dump($item);
     $item->delete();
     //dump($item->make_public);
     // if it was made public, delete it from the public_items table
     if ($item->make_public) {
         $publicItem = \App\PublicItem::where('one_line_description', '=', $item->one_line_description)->get();
         //dump($publicItem[0]);
         $publicItem[0]->delete();
     }
     \Session::flash('flash_message', $item->item . ' was deleted.');
     return redirect('/myspace');
 }
Esempio n. 5
0
 /**
  * Responds to requests to
  */
 public function getPage()
 {
     // get all the items added by the user
     $addedItems = \App\AddedItem::where('user_id', '=', \Auth::id())->get();
     //dump($addedItems);
     $addedItemsArray = $addedItems->toArray();
     // get all the transactions of the user
     $transactions = \App\Transaction::where('user_id', '=', \Auth::id())->get();
     //dump($transactions);
     $transactionArrays = array();
     foreach ($transactions as $transaction) {
         $transactionArray = $transaction->public_item->toArray();
         //dump($transactionArray);
         $transactionArray["transaction_type"] = $transaction->transaction_type;
         $transactionArray["transaction_date"] = $transaction->created_at->timezone('America/New_York')->format('m/d/Y h:i A');
         array_push($transactionArrays, $transactionArray);
     }
     //dump($transactionArrays);
     return view('pongo.myspace')->with(['addedItems' => $addedItemsArray, 'transactions' => $transactionArrays]);
 }