/**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $input = $request->all();
     Item::where("id", $id)->update($input);
     $item = Item::find($id);
     return response($item);
 }
Beispiel #2
0
 /**
  * @param $id
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function destroy($id)
 {
     $item = Item::find($id);
     //select the book using primary id
     $item->delete();
     return redirect('/');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $item = \App\Item::find($id);
     $item->title = $request->title;
     $item->completed = $request->completed;
     $item->save();
     return $item;
 }
Beispiel #4
0
 public function putItem(Request $request)
 {
     $this->validate($request, ['id' => 'exists:items', 'descripcion' => 'required|min:5']);
     $item = Item::find($request->get('id'));
     $item->descripcion = $request->get('descripcion');
     $item->save();
     return response()->json($item);
 }
 public function sort(Request $itemsOrder)
 {
     $items = explode(',', $itemsOrder->input('list_order'));
     $i = 1;
     foreach ($items as $itemId) {
         $item = Item::find($itemId);
         $item->item_order = $i;
         $item->save();
         $i++;
     }
     return "Order saved";
 }
Beispiel #6
0
 public function testDeleteItem()
 {
     $user = factory(User::class)->create();
     $item = $this->getFakeItem($user->id);
     $itemtest = Item::find($item->id);
     //// TODO: why is user_id -1 in created object???
     print 'user_id: ' . $user->id . ' category_id: ' . $item->category_id;
     print 'Itemtest: user_id: ' . $itemtest->user_id . ' category_id: ' . $itemtest->category_id;
     $item_criteria = ['name' => $item->name, 'category_id' => $item->category_id];
     $this->seeInDatabase('items', $item_criteria);
     //// create new item
     $this->actingAs($user)->delete('/api/items/' . $item->id);
     $this->notSeeInDatabase('items', $item_criteria);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(InventoryRequest $request, $id)
 {
     $items = Item::find($id);
     $items->quantity = $items->quantity + Input::get('in_out_qty');
     $items->save();
     $inventories = new Inventory();
     $inventories->item_id = $id;
     $inventories->user_id = Auth::user()->id;
     $inventories->in_out_qty = Input::get('in_out_qty');
     $inventories->remarks = Input::get('remarks');
     $inventories->save();
     Session::flash('message', 'You have successfully updated item');
     return Redirect::to('inventory/' . $id . '/edit');
 }
 public function show($id)
 {
     //temporarily restore the item
     Item::withTrashed()->where('id', $id)->restore();
     $item = Item::find($id);
     if ($item->user_id == \Auth::user()->id) {
         \Session::flash('flash_message', 'The item has been recovered.');
     } else {
         //delete it again if not authorized
         $item->delete();
         \Session::flash('flash_message', "You aren't authorized to recover this item.");
     }
     return redirect('items');
 }
Beispiel #9
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['category_id' => 'required', 'name' => 'required', 'description' => 'required', 'cost' => 'required']);
     $item = Item::find($id);
     $item->category_id = $request->input('category_id');
     $item->name = $request->input('name');
     $item->description = $request->input('description');
     $item->cost = $request->input('cost');
     if ($request->hasFile('image')) {
         $extension = $request->file('image')->getClientOriginalExtension();
         $item->image_type = $extension;
         $storage = Storage::disk('s3')->put('/items/' . $item->id . '.' . $extension, file_get_contents($request->file('image')->getRealPath()), 'public');
     }
     $item->save();
     return redirect('items')->with('flash_message', 'Item details updated');
 }
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     switch ($this->method()) {
         case 'POST':
             return ['name' => 'required|unique:items', 'unit' => 'required'];
         case 'PATCH':
             $item = Item::find($this->segment(2));
             //this gets the second segment in the url which is the id of the item
             if ($this->get('name') == $item['name']) {
                 return ['name' => 'required|unique:items,id' . $this->get('id'), 'unit' => 'required'];
             } else {
                 return ['name' => 'required|unique:items', 'unit' => 'required'];
             }
         default:
             break;
     }
 }
Beispiel #11
0
 public function postAddToCart(Request $request)
 {
     $this->validate($request, ['item' => 'required|numeric|exists:items,id']);
     $user_id = Auth::user()->id;
     $item_id = Input::get('item');
     $amount = 1;
     $item = Item::find($item_id);
     $total = $amount * $item->price;
     $carts = Cart::with('Items')->where('user_id', $user_id)->get();
     $item_stock = $item->stock;
     if ($item->stock < 1) {
         return redirect('/')->withErrors('Ce produit n\'est plus disponible');
     }
     Cart::create(['user_id' => $user_id, 'item_id' => $item_id, 'amount' => $amount, 'total' => $total]);
     $item->decrement('stock');
     $last_timestamp = Cart::with('Items')->where('user_id', $user_id)->orderBy('created_at', 'desc')->first()->created_at;
     Auth::user()->last_cart_timestamp = $last_timestamp;
     Auth::user()->save();
     return redirect('/');
 }
 public function show($id)
 {
     $edificio_id = Input::get('id');
     $edificio = Edificio::find($edificio_id);
     $administrador = Administrador::find($edificio->admin_id);
     $items = Item::find($id);
     //obtengo el id de la espensa que vien por la url//
     $exp_uri = $_SERVER["REQUEST_URI"];
     $exp_uri = explode('/', $exp_uri);
     $exp_uri = explode('?', $exp_uri[4]);
     $exp_id = $exp_uri[0];
     $expensa = new Expensa();
     $expensa = $expensa::find($exp_id);
     $pisos = DB::table('items')->join('propietarios', 'propietarios.id', '=', 'items.unidad_id')->where('items.expensa_id', '=', $id)->get();
     if (Auth::user()->rol_id == 2) {
         //return View::make('administrador.expensas.show')
         //->with('items', $items)
         //->with('edificio', $edificio)
         //->with('admin', $administrador)
         //->with('pisos', $pisos);
         $view = \View::make('administrador.expensas.show')->with('items', $items)->with('edificio', $edificio)->with('admin', $administrador)->with('pisos', $pisos)->with('expensa', $expensa);
         $pdf = \App::make('dompdf.wrapper');
         $pdf->loadHTML($view);
         return $pdf->stream('Expensa.pdf');
     }
     if (Auth::user()->rol_id == 3) {
         $view = \View::make('propietario.expensas.show')->with('items', $items)->with('edificio', $edificio)->with('admin', $administrador)->with('pisos', $pisos)->with('expensa', $expensa);
         $pdf = \App::make('dompdf.wrapper');
         $pdf->loadHTML($view);
         return $pdf->stream('Expensa.pdf');
         //return View::make('propietario.expensas.index');
     }
     if (Auth::user()->rol_id == 4) {
         $view = \View::make('inquilino.expensas.show')->with('items', $items)->with('edificio', $edificio)->with('admin', $administrador)->with('pisos', $pisos)->with('expensa', $expensa);
         $pdf = \App::make('dompdf.wrapper');
         $pdf->loadHTML($view);
         return $pdf->stream('Expensa.pdf');
         //return View::make('propietario.expensas.index');
     }
 }
Beispiel #13
0
 /**
  * @param Request $request
  * this function is for adding products to the shopping cart
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function add(Request $request)
 {
     if ($request->isMethod('post')) {
         $item_id = $request->get('item_id');
         $has_item = false;
         $item = Item::find($item_id);
         $cat_name = $request->get('catName');
         if (Session::has('items')) {
             foreach ($request->session()->get('items') as $items) {
                 if ($items['id'] == $item_id) {
                     $has_item = true;
                 }
             }
         }
         if (!$has_item) {
             $request->session()->push('items', ['id' => "{$item->itID}", 'quantity' => 1, 'name' => "{$item->itName}", 'price' => "{$item->price}", 'imgpath' => "{$item->imName}"]);
         }
         //$request->session()->flush();
         //retrieve the session array
         $data = $request->session()->get('items');
         return view('pages.cart.cart', compact('data', 'i', 'n', 'cat_name'));
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     $item = Item::find($id);
     $item->delete();
     return;
 }
Beispiel #15
0
 /**
  * Change the pictures of an item
  *
  * @param  int  $id
  * @param  File $picture1
  * @param  File $picture2
  * @param  bool $dp2
  * @return Response
  */
 public function changePictures()
 {
     $item = Item::find(Request::input('id'));
     // Delete the secondary picture first
     if (Request::has('dp2') && Request::input('dp2') == "true" || Request::file('picture2')) {
         File::delete('uploads/' . $item->hash . '_2.jpg');
         $item->picture2 = false;
     }
     if (Request::file('picture1')) {
         $destination = 'uploads';
         // Give it a unique filename
         $extension = Input::file('picture1')->getClientOriginalExtension();
         if (strtolower($extension) != 'jpg') {
             return Response::make("Please upload only .jpg files.", 400);
         } else {
             $filename = $item->hash . "_1." . strtolower($extension);
             File::delete('uploads/' . $item->hash . '_1.jpg');
             Input::file('picture1')->move($destination, $filename);
         }
     }
     if (Request::file('picture2')) {
         $destination = 'uploads';
         // Give it a unique filename
         $extension = Input::file('picture2')->getClientOriginalExtension();
         if (strtolower($extension) != 'jpg') {
             return Response::make("Please upload only .jpg files.", 400);
         } else {
             $filename = $item->hash . "_2." . strtolower($extension);
             Input::file('picture2')->move($destination, $filename);
         }
         $item->picture2 = true;
     }
     $item->save();
     return Response::make("Success", 205);
 }
Beispiel #16
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     //
     $this->validate($request, ['schedule' => 'required', 'category' => 'required', 'type' => 'required']);
     $data = Item::find($id);
     $data->ticket_no = $request->ticket_no;
     $data->category_id = $request->category;
     $data->type_id = $request->type;
     $data->price = $request->price;
     $data->description = $request->description;
     $data->save();
     $destinationPath = 'images/' . Auth::user()->id . '/' . $request->ticket_no;
     foreach ($request->file('image') as $key => $photo) {
         if ($photo) {
             if ($photo->isValid()) {
                 // original
                 $filename_original = 'image_' . $key . '_original.jpg';
                 Image_::make($photo->getRealPath())->save($destinationPath . '/' . $filename_original);
                 // for grid view
                 $filename = $destinationPath . '/' . 'image_' . $key . '_349x200.jpg';
                 ph::resize_image($destinationPath . '/' . $filename_original, 349, 200, $filename);
                 // for view page (big)
                 $filename = $destinationPath . '/' . 'image_' . $key . '_725x483.jpg';
                 ph::resize_image($destinationPath . '/' . $filename_original, 725, 483, $filename);
                 // for view page (thumbnail)
                 $filename = $destinationPath . '/' . 'image_' . $key . '_173x126.jpg';
                 ph::resize_image($destinationPath . '/' . $filename_original, 173, 126, $filename);
             } else {
                 Session::flash('message', 'uploaded file is not valid');
                 return redirect('/item');
             }
         }
     }
     Session::flash('message', 'Item with ticket #' . $request->ticket_no . ' was successfully updated');
     return redirect('/item');
 }
 public function generate()
 {
     $input = Request::all();
     $counter = 1;
     $reportType = $input['report_type'];
     $salesCounter = 0;
     $counterClientBreakdown = 0;
     $counterClientLabel = 0;
     $counterClientData = 0;
     if ($reportType == "sales") {
         $monthStart = $input['select_monthFrom'];
         $monthEnd = $input['select_monthTo'];
         $yearStart = $input['yearFrom'];
         $yearEnd = $input['yearTo'];
         $monthStartName = date("F", mktime(0, 0, 0, $monthStart, 10));
         $monthEndName = date("F", mktime(0, 0, 0, $monthEnd, 10));
         $results = DB::select("SELECT SUM(total_amount) as 'total' FROM sales_invoices si\n                                    WHERE MONTH(si.date) >= '{$monthStart}' AND MONTH(si.date) <= '{$monthEnd}'\n                                    AND YEAR(si.date) >= '{$yearStart}' AND YEAR(si.date) <= '{$yearEnd}'");
         $resultsClient = DB::select("SELECT name, SUM(total_amount) as 'total'  FROM clients c\n                                        JOIN sales_invoices si ON si.client_id = c.id\n                                        WHERE MONTH(si.date) >= '{$monthStart}' AND MONTH(si.date) <= '{$monthEnd}'\n                                        AND YEAR(si.date) >= '{$yearStart}' AND YEAR(si.date) <= '{$yearEnd}' GROUP BY c.id");
         $resultsSales = DB::select("SELECT username, SUM(total_amount) as 'total'  FROM users u\n                                        JOIN clients c ON c.user_id = u.id\n                                        JOIN sales_invoices si ON si.client_id = c.id \n                                        WHERE MONTH(si.date) >= '{$monthStart}' AND MONTH(si.date) <= '{$monthEnd}'\n                                        AND YEAR(si.date) >= '{$yearStart}' AND YEAR(si.date) <= '{$yearEnd}' GROUP BY u.id");
         Excel::create('Sales Report ' . \Carbon\Carbon::today()->format('m-d-y'), function ($excel) use($results, $resultsClient, $resultsSales, $counter, $monthStartName, $monthEndName, $salesCounter, $counterClientBreakdown, $counterClientLabel, $counterClientData, $yearStart, $yearEnd) {
             $excel->sheet('Data', function ($sheet) use($results, $resultsClient, $resultsSales, $counter, $monthEndName, $monthStartName, $salesCounter, $counterClientBreakdown, $counterClientLabel, $counterClientData, $yearStart, $yearEnd) {
                 $sheet->row($counter, array('Sales Report'));
                 $counter++;
                 $sheet->row($counter, array('For ' . $monthStartName . ' ' . $yearStart . ' To ' . $monthEndName . ' ' . $yearEnd));
                 $counter++;
                 $sheet->row($counter, array('Total Sales: ', 'P' . $results[0]->total));
                 $counter++;
                 $counter++;
                 $sheet->row($counter, array('Sale Employee Breakdown:'));
                 //styling for 'Sales Employee Breakdown'
                 $sheet->cells('A5', function ($cells) {
                     $cells->setFontSize(14);
                     $cells->setFontWeight('bold');
                 });
                 $counter++;
                 $sheet->row($counter, array('Username', 'Total Amount'));
                 $counter++;
                 foreach ($resultsSales as $sales) {
                     $sheet->row($counter, array($sales->username, $sales->total));
                     $counter++;
                 }
                 $salesCounter = $counter - 1;
                 $counter += 10;
                 $sheet->row($counter, array('Client Breakdown: '));
                 $counterClientBreakdown = $counter;
                 $counter++;
                 $sheet->row($counter, array('Client Name', 'Total Amount'));
                 $counterClientLabel = $counter;
                 //$counter++;
                 $counterClientData = $counter + 1;
                 foreach ($resultsClient as $client) {
                     $counter++;
                     $sheet->row($counter, array($client->name, $client->total));
                     //$counter++;
                 }
                 //styling 'Sales Report' -> bold
                 $sheet->mergeCells('A1:B1');
                 $sheet->cells('A1', function ($cells) {
                     $cells->setFontSize(16);
                     $cells->setFontWeight('bold');
                 });
                 //styling for total sales
                 $sheet->cells('A3:B3', function ($cells) {
                     $cells->setFontSize(14);
                     $cells->setFontWeight('bold');
                 });
                 //styling for 'Client Breakdown'
                 $sheet->cells('A' . $counterClientBreakdown, function ($cells) {
                     $cells->setFontSize(14);
                     $cells->setFontWeight('bold');
                 });
                 //create Sales Employee chart
                 if (Count($resultsSales) > 0) {
                     //Data Series Label
                     $dsl = array(new \PHPExcel_Chart_DataSeriesValues('String', 'Data!$B$6', NULL, 1));
                     $xal = array(new \PHPExcel_Chart_DataSeriesValues('String', 'Data!$A$7:$A$' . $salesCounter, NULL, count($resultsSales)));
                     $dsv = array(new \PHPExcel_Chart_DataSeriesValues('Number', 'Data!$B$7:$B$' . $salesCounter, NULL, count($resultsSales)));
                     $ds = new \PHPExcel_Chart_DataSeries(\PHPExcel_Chart_DataSeries::TYPE_BARCHART, \PHPExcel_Chart_DataSeries::GROUPING_STANDARD, range(0, count($dsv) - 1), $dsl, $xal, $dsv);
                     $pa = new \PHPExcel_Chart_PlotArea(NULL, array($ds));
                     $legend = new \PHPExcel_Chart_Legend(\PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
                     $title = new \PHPExcel_Chart_Title('Sales by Employee');
                     $chart = new \PHPExcel_Chart('chart1', $title, $legend, $pa, true, 0, NULL, NULL);
                     $chart->setTopLeftPosition('E5');
                     $chart->setBottomRightPosition('L16');
                     $sheet->addChart($chart);
                 }
                 //create Client Breakdown chart
                 if (Count($resultsClient) > 0) {
                     //Data Series Label
                     $dsl2 = array(new \PHPExcel_Chart_DataSeriesValues('String', 'Data!$B$' . $counterClientLabel, NULL, 1));
                     $xal2 = array(new \PHPExcel_Chart_DataSeriesValues('String', 'Data!$A$' . $counterClientData . ':$A$' . $counter, NULL, count($resultsClient)));
                     $dsv2 = array(new \PHPExcel_Chart_DataSeriesValues('Number', 'Data!$B$' . $counterClientData . ':$B$' . $counter, NULL, count($resultsClient)));
                     $ds2 = new \PHPExcel_Chart_DataSeries(\PHPExcel_Chart_DataSeries::TYPE_BARCHART, \PHPExcel_Chart_DataSeries::GROUPING_STANDARD, range(0, count($dsv2) - 1), $dsl2, $xal2, $dsv2);
                     $pa2 = new \PHPExcel_Chart_PlotArea(NULL, array($ds2));
                     $legend2 = new \PHPExcel_Chart_Legend(\PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
                     $title2 = new \PHPExcel_Chart_Title('Sales by Client');
                     $chart = new \PHPExcel_Chart('chart2', $title2, $legend2, $pa2, true, 0, NULL, NULL);
                     $chart->setTopLeftPosition('E19');
                     $chart->setBottomRightPosition('L30');
                     $sheet->addChart($chart);
                 }
             });
         })->export('xlsx');
     } else {
         if ($reportType == "collection") {
             $monthStart = $input['select_monthFrom'];
             $monthEnd = $input['select_monthTo'];
             $yearStart = $input['yearFrom'];
             $yearEnd = $input['yearTo'];
             $monthStartName = date("F", mktime(0, 0, 0, $monthStart, 10));
             $monthEndName = date("F", mktime(0, 0, 0, $monthEnd, 10));
             $counter = 1;
             $results = DB::select("SELECT sum(total_amount) as 'total', count(*) as 'numCount' FROM sales_invoices si\n                                    WHERE (si.status = 'delivered' OR si.status = 'overdue')\n                                    AND MONTH(si.due_date) >= '{$monthStart}' AND MONTH(si.due_date) <= '{$monthEnd}'\n                                    AND YEAR(si.due_date) >= '{$yearStart}' AND YEAR(si.date) <= '{$yearEnd}'");
             $resultsCollected = DB::select("SELECT sum(total_amount) as 'total', count(*) as 'numCount' FROM sales_invoices si\n                                                WHERE si.status = 'collected'\n                                                AND MONTH(si.due_date) >= '{$monthStart}' AND MONTH(si.due_date) <= '{$monthEnd}'\n                                                AND YEAR(si.due_date) >= '{$yearStart}' AND YEAR(si.date) <= '{$yearEnd}'");
             $resultsInvoices = DB::select("SELECT name, si_no, date, due_date, total_amount, si.status FROM sales_invoices si\n                                            JOIN clients c ON si.client_id = c.id\n                                            WHERE MONTH(si.due_date) >= '{$monthStart}' AND MONTH(si.due_date) <= '{$monthEnd}'\n                                            AND YEAR(si.due_date) >= '{$yearStart}' AND YEAR(si.date) <= '{$yearEnd}' ORDER BY name, si.status");
             Excel::create('Collection Report ' . \Carbon\Carbon::today()->format('m-d-y'), function ($excel) use($results, $counter, $monthStartName, $monthEndName, $yearStart, $yearEnd, $resultsCollected, $resultsInvoices) {
                 $excel->sheet('Data', function ($sheet) use($results, $counter, $monthStartName, $monthEndName, $yearStart, $yearEnd, $resultsCollected, $resultsInvoices) {
                     $sheet->row($counter, array('Collection Report'));
                     $counter++;
                     $sheet->row($counter, array('For ' . $monthStartName . ' ' . $yearStart . ' To ' . $monthEndName . ' ' . $yearEnd));
                     $counter++;
                     $sheet->row($counter, array('Total Amount Collected: ', $resultsCollected[0]->total));
                     $counter++;
                     $sheet->row($counter, array('Total Collectibles: ', $results[0]->total));
                     $counter += 2;
                     $sheet->row($counter, array('List of Collectibles: '));
                     $counter++;
                     $sheet->row($counter, array('Client Name', 'Sales Invoice Number', 'Date', 'Due Date', 'Total Amount', 'Status'));
                     $counter++;
                     foreach ($resultsInvoices as $result) {
                         $sheet->row($counter, array($result->name, $result->si_no, $result->date, $result->due_date, $result->total_amount, $result->status));
                         $counter++;
                     }
                     // foreach($results as $result)
                     // {
                     //     $sheet->row($counter, array('Total Collectibles: ', $result->total));
                     // }
                     //style
                     //style for item name
                     $sheet->mergeCells('A1:B1');
                     $sheet->cells('A1', function ($cells) {
                         $cells->setFontSize(14);
                         $cells->setFontWeight('bold');
                     });
                     //style for total amount  collected
                     $sheet->cells('A3:B3', function ($cells) {
                         $cells->setFontSize(12);
                         $cells->setFontWeight('bold');
                     });
                     //style for total collectibles
                     $sheet->cells('A4:B4', function ($cells) {
                         $cells->setFontSize(12);
                         $cells->setFontWeight('bold');
                     });
                 });
             })->export('xlsx');
         } else {
             if ($reportType == "item") {
                 $itemID = $input['item'];
                 $item = Item::find($itemID);
                 $itemName = $item->name;
                 $monthStart = $input['select_monthFrom'];
                 $monthEnd = $input['select_monthTo'];
                 $yearStart = $input['yearFrom'];
                 $yearEnd = $input['yearTo'];
                 $monthStartName = date("F", mktime(0, 0, 0, $monthStart, 10));
                 $monthEndName = date("F", mktime(0, 0, 0, $monthEnd, 10));
                 $counterLabel = 0;
                 $counterData = 0;
                 $results = DB::select("SELECT name, supplier_id FROM price_logs pl\n                JOIN suppliers s ON pl.supplier_id = s.id \n                WHERE item_id = '{$itemID}' AND MONTH(pl.date) >= '{$monthStart}' \n                AND MONTH(pl.date) <= '{$monthEnd}' AND YEAR(pl.date) >= '{$yearStart}' AND YEAR(pl.date) <= '{$yearEnd}'\n                GROUP BY pl.supplier_id");
                 $itemResults = DB::select("SELECT name, sum(quantity) as 'totalSold', sum(total_price) as 'totalAmount' FROM invoice_items ii\n                                        JOIN items i ON ii.item_id = i.id\n                                        WHERE ii.item_id = '{$itemID}'");
                 Excel::create('Item Report-' . $itemName . ' ' . \Carbon\Carbon::today()->format('m-d-y'), function ($excel) use($results, $counter, $itemID, $monthStart, $monthStartName, $monthEnd, $monthEndName, $yearStart, $yearEnd, $itemResults, $itemName, $counterLabel, $counterData) {
                     $excel->sheet('Data', function ($sheet) use($results, $counter, $itemID, $monthStart, $monthStartName, $monthEnd, $monthEndName, $yearStart, $yearEnd, $itemResults, $itemName, $counterLabel, $counterData) {
                         $sheet->row($counter, array('Item Report'));
                         //style for Item Report Title
                         $sheet->cells('A1', function ($cells) {
                             $cells->setFontSize(16);
                             $cells->setFontWeight('bold');
                         });
                         $counter++;
                         $sheet->row($counter, array('For ' . $monthStartName . ' ' . $yearStart . ' To ' . $monthEndName . ' ' . $yearEnd));
                         $counter++;
                         $sheet->row($counter, array('Item Name: ' . $itemName));
                         //style for item name
                         $sheet->mergeCells('A1:B1');
                         $sheet->cells('A' . $counter, function ($cells) {
                             $cells->setFontSize(14);
                             $cells->setFontWeight('bold');
                         });
                         $counter++;
                         $sheet->row($counter, array('Total Quantity Sold: ', $itemResults[0]->totalSold));
                         //style for quantity sold
                         $sheet->cells('A' . $counter . ':B' . $counter, function ($cells) {
                             $cells->setFontSize(12);
                             $cells->setFontWeight('bold');
                         });
                         $counter++;
                         $sheet->row($counter, array('Total Revenue Generated: ', 'P' . $itemResults[0]->totalAmount));
                         //style for revenue generated
                         $sheet->cells('A' . $counter . ':B' . $counter, function ($cells) {
                             $cells->setFontSize(12);
                             $cells->setFontWeight('bold');
                         });
                         $counter += 2;
                         foreach ($results as $result) {
                             $sheet->row($counter, array($result->name));
                             //style for quantity sold
                             $sheet->cells('A' . $counter, function ($cells) {
                                 $cells->setFontWeight('bold');
                             });
                             $counter++;
                             $sheet->row($counter, array('Date', 'Unit Price'));
                             $counterLabel = $counter;
                             $counterData = $counter + 1;
                             $logs = DB::select("SELECT date, price FROM price_logs pl \n                                            WHERE item_id = '{$itemID}' AND supplier_id = '{$result->supplier_id}'\n                                            AND MONTH(pl.date) >= '{$monthStart}' \n                                            AND MONTH(pl.date) <= '{$monthEnd}' AND YEAR(pl.date) >= '{$yearStart}' AND YEAR(pl.date) <= '{$yearEnd}'");
                             foreach ($logs as $log) {
                                 $counter++;
                                 $sheet->row($counter, array($log->date, $log->price));
                             }
                             //Create chart
                             if (count($logs) > 0) {
                                 //Data Series Label
                                 $dsl = array(new \PHPExcel_Chart_DataSeriesValues('String', 'Data!$B$' . $counterLabel, NULL, 1));
                                 $xal = array(new \PHPExcel_Chart_DataSeriesValues('String', 'Data!$A$' . $counterData . ':$A$' . $counter, NULL, count($logs)));
                                 $dsv = array(new \PHPExcel_Chart_DataSeriesValues('Number', 'Data!$B$' . $counterData . ':$B$' . $counter, NULL, count($logs)));
                                 $ds = new \PHPExcel_Chart_DataSeries(\PHPExcel_Chart_DataSeries::TYPE_LINECHART, \PHPExcel_Chart_DataSeries::GROUPING_STANDARD, range(0, count($dsv) - 1), $dsl, $xal, $dsv);
                                 $pa = new \PHPExcel_Chart_PlotArea(NULL, array($ds));
                                 $legend = new \PHPExcel_Chart_Legend(\PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
                                 $title = new \PHPExcel_Chart_Title('Price History');
                                 $chart = new \PHPExcel_Chart('chart1', $title, $legend, $pa, true, 0, NULL, NULL);
                                 $counter += 5;
                                 $chart->setTopLeftPosition('E' . $counterLabel);
                                 $chart->setBottomRightPosition('K' . $counter);
                                 $sheet->addChart($chart);
                             }
                             $counter += 2;
                         }
                     });
                 })->export('xlsx');
             } else {
                 if ($reportType == "client") {
                     //$client = Client::all();
                     $clientid = $input['client'];
                     $clientName = Client::find($clientid)->name;
                     $results = DB::select("SELECT c.name AS 'clientName', i.name, SUM(quantity) AS 'total' FROM invoice_items ii\n                                    JOIN items i on ii.item_id = i.id \n                                    JOIN sales_invoices si ON ii.sales_invoice_id = si.id\n                                    JOIN clients c ON si.client_id = c.id\n                                    WHERE c.id = '{$clientid}'\n                                    GROUP BY item_id ORDER BY sum(quantity) DESC LIMIT 3");
                     //$client = DB::table('clients')->get();
                     Excel::create('Client Report ' . \Carbon\Carbon::today()->format('m-d-y'), function ($excel) use($results, $counter, $clientName) {
                         $excel->sheet('Data', function ($sheet) use($results, $counter, $clientName) {
                             $sheet->row($counter, array('Client Report'));
                             $counter++;
                             //$sheet->row($counter, array('Client Name', $results[0]->clientName));
                             $sheet->row($counter, array('Client Name', $clientName));
                             $counter++;
                             $counter++;
                             //add space
                             $sheet->row($counter, array('Most Bought Items:'));
                             $counter++;
                             $sheet->row($counter, array('Item Name', 'Total Quantity'));
                             $counter++;
                             foreach ($results as $result) {
                                 $sheet->row($counter, array($result->name, $result->total));
                                 $counter++;
                             }
                             //Add the styling
                             $sheet->mergeCells('A1:B1');
                             $sheet->cells('A1', function ($cells) {
                                 $cells->setFontSize(16);
                                 $cells->setFontWeight('bold');
                             });
                             $sheet->cells('A2:B2', function ($cells) {
                                 $cells->setFontSize(16);
                             });
                             $sheet->cells('A4', function ($cells) {
                                 $cells->setFontWeight('bold');
                             });
                             //Create chart
                             if (count($results) > 0) {
                                 //Data Series Label
                                 $dsl = array(new \PHPExcel_Chart_DataSeriesValues('String', 'Data!$B$5', NULL, 1));
                                 $xal = array(new \PHPExcel_Chart_DataSeriesValues('String', 'Data!$A$6:$A$' . $counter, NULL, 3));
                                 $dsv = array(new \PHPExcel_Chart_DataSeriesValues('Number', 'Data!$B$6:$B$' . $counter, NULL, 3));
                                 $ds = new \PHPExcel_Chart_DataSeries(\PHPExcel_Chart_DataSeries::TYPE_BARCHART, \PHPExcel_Chart_DataSeries::GROUPING_STANDARD, range(0, count($dsv) - 1), $dsl, $xal, $dsv);
                                 $pa = new \PHPExcel_Chart_PlotArea(NULL, array($ds));
                                 $legend = new \PHPExcel_Chart_Legend(\PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
                                 $title = new \PHPExcel_Chart_Title('Most Bought');
                                 $chart = new \PHPExcel_Chart('chart1', $title, $legend, $pa, true, 0, NULL, NULL);
                                 $chart->setTopLeftPosition('A10');
                                 $chart->setBottomRightPosition('C25');
                                 $sheet->addChart($chart);
                             }
                         });
                     })->export('xlsx');
                 }
             }
         }
     }
 }
Beispiel #18
0
 public function getDoDelete($item_id)
 {
     $item = \App\Item::find($item_id);
     if (is_null($item)) {
         \Session::flash('flash_message', 'Item not found.');
         return redirect('/items');
     }
     if ($item->stores()) {
         //remove any tags associated with this book
         $item->stores()->detach();
     }
     $item->delete();
     \Session::flash('flash_message', $item->name . ' was deleted.');
     return redirect('/items');
 }
Beispiel #19
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $item = Item::find($id);
     $item->delete();
     return redirect()->route('items.index');
 }
Beispiel #20
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(SaleRequest $request)
 {
     $sales = new Sale();
     $sales->customer_id = Input::get('customer_id');
     $sales->user_id = Auth::user()->id;
     $sales->payment_type = Input::get('payment_type');
     $sales->comments = Input::get('comments');
     $sales->save();
     // process sale items
     $saleItems = SaleTemp::all();
     foreach ($saleItems as $value) {
         $saleItemsData = new SaleItem();
         $saleItemsData->sale_id = $sales->id;
         $saleItemsData->item_id = $value->item_id;
         $saleItemsData->cost_price = $value->cost_price;
         $saleItemsData->selling_price = $value->selling_price;
         $saleItemsData->quantity = $value->quantity;
         $saleItemsData->total_cost = $value->total_cost;
         $saleItemsData->total_selling = $value->total_selling;
         $saleItemsData->save();
         //process inventory
         $items = Item::find($value->item_id);
         if ($items->type == 1) {
             $inventories = new Inventory();
             $inventories->item_id = $value->item_id;
             $inventories->user_id = Auth::user()->id;
             $inventories->in_out_qty = -$value->quantity;
             $inventories->remarks = 'SALE' . $sales->id;
             $inventories->save();
             //process item quantity
             $items->quantity = $items->quantity - $value->quantity;
             $items->save();
         } else {
             $itemkits = ItemKitItem::where('item_kit_id', $value->item_id)->get();
             foreach ($itemkits as $item_kit_value) {
                 $inventories = new Inventory();
                 $inventories->item_id = $item_kit_value->item_id;
                 $inventories->user_id = Auth::user()->id;
                 $inventories->in_out_qty = -($item_kit_value->quantity * $value->quantity);
                 $inventories->remarks = 'SALE' . $sales->id;
                 $inventories->save();
                 //process item quantity
                 $item_quantity = Item::find($item_kit_value->item_id);
                 $item_quantity->quantity = $item_quantity->quantity - $item_kit_value->quantity * $value->quantity;
                 $item_quantity->save();
             }
         }
     }
     //delete all data on SaleTemp model
     SaleTemp::truncate();
     $itemssale = SaleItem::where('sale_id', $saleItemsData->sale_id)->get();
     Session::flash('message', 'You have successfully added sales');
     //return Redirect::to('receivings');
     return view('sale.complete')->with('sales', $sales)->with('saleItemsData', $saleItemsData)->with('saleItems', $itemssale);
 }
 static function reserveItem($item_id)
 {
     $item = \App\Item::find($item_id);
     $item->reserved_by = auth()->user()->id;
     $item->save();
 }
Beispiel #22
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $item = Item::find($id);
     $item->Delete('set null');
     return redirect()->action('ItemsController@index');
 }
Beispiel #23
0
 public function review()
 {
     $rules = array('name' => 'required|min:5', 'email' => 'required|email', 'address1' => 'required|min:5', 'city' => 'required', 'postcode' => 'required|min:3', 'country' => 'required|max:2', 'payment_method' => 'required|max:6');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator->errors())->withInput();
     } else {
         $addressinfo = Input::except('_token', 'page', 'cartjson');
         $order = Order::create($addressinfo);
         $order->ordernumber = "LEAF-" . mt_rand(100000, 999999);
         $cart = json_decode(Input::get('cartjson'));
         $totalamount = 0;
         foreach ($cart->items as $cartitem) {
             $item = Item::find($cartitem->itemid);
             if ($item->id == Item::SHIPPING) {
                 $shipping = $this->calculateShipping($order);
                 $orderitem = OrderItem::create(["item_id" => $item->id, "order_id" => $order->id, "itemprice" => $shipping, "amount" => 1]);
                 $totalamount += $shipping;
             } else {
                 $orderitem = OrderItem::create(["item_id" => $item->id, "order_id" => $order->id, "itemprice" => $item->price, "amount" => $cartitem->itemamount]);
                 $totalamount += $item->price * $orderitem->amount;
             }
             $orderitem->save();
         }
         $order->totalamount = $totalamount;
         $order->save();
         return view('review', ["order" => $order]);
     }
 }
 public function edit($id)
 {
     $item = Item::find($id);
     return view('pages.items.edit', compact('item'));
 }
Beispiel #25
0
 public function delete($id)
 {
     $item = Item::find($id);
     $item->delete();
     return redirect()->back()->with('message_content', '删除成功!')->with('message_type', 'info');
 }
Beispiel #26
0
 public function getItemChecked($id = null)
 {
     //get item from item id
     $item = \App\Item::find($id);
     //check if item marked as checked
     $itemChecked = $item->checked;
     //toggle the value
     if (!$itemChecked) {
         $item->checked = true;
     } else {
         $item->checked = false;
     }
     $item->save();
     //\Session::flash('flash_message', 'Item detail updated.');
     return redirect('/store/' . $item->store_id . '/items');
 }
Beispiel #27
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $items = Item::find($id);
     $items->delete();
     Session::flash('message', 'You have successfully deleted item');
     return Redirect::to('items');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($list_id, $item_id)
 {
     // Detach the item from the list
     $list = App\RatingList::find($list_id);
     $list->items()->detach($item_id);
     // Create a success notification
     $item = App\Item::find($item_id);
     flash()->success('Success!', 'You have removed <strong>' . e($item->name) . '</strong> from your list.');
     // Redirect to the lists page
     return redirect()->action('ListsController@show', $list_id);
 }
Beispiel #29
0
 protected function itemStoreUpdate(Request $request, $id = null)
 {
     if (Auth::check()) {
         if ($id) {
             $item = Item::find($id);
         } else {
             $item = new Item();
         }
         /*['name', 'region', 'platform', 'category', 'type', 'catalog_number', 'isbn', 'sku', 'role', 'directed', 'kojima_team', 'release_date', 'year'];*/
         $item->collection_id = $request->input('collection_id');
         $item->name = $request->input('name');
         $item->region = $request->input('region');
         $item->platform = $request->input('platform');
         $item->category = $request->input('category');
         $item->type = $request->input('type');
         $item->catalog_number = $request->input('catalog_number');
         $item->isbn = $request->input('isbn');
         $item->sku = $request->input('sku');
         $item->role = $request->input('role');
         $item->directed = $request->input('directed');
         $item->kojima_team = $request->input('kojima_team');
         $item->release_date = date("Y-m-d H:i:s", strtotime($request->input('release_date')));
         $item->year = $request->input('year');
         $item->slug = str_slug($request->input('name'), "-");
         try {
             $item->save();
             return redirect('/home/items');
         } catch (\Illuminate\Database\QueryException $e) {
             var_dump($e->getMessage());
             die;
         }
     } else {
         return 'No auth';
     }
 }
 public function manage($id)
 {
     $item = Item::find($id);
     return view('admin.items.manage', ['item' => $item]);
 }