Ejemplo n.º 1
0
 public function index()
 {
     $currentPeriodId = Helper::currentPeriodId();
     if ($currentPeriodId) {
         $search = Input::get('q');
         $filter = Input::get('filter');
         $not_updated = Items::select('count(*)')->whereRaw('not exists (select 1 from stock_items where stock_items.stock_period_id = ' . $currentPeriodId . ' and stock_items.item_id = items.id)')->count();
         $items = $search ? Items::where('title', 'LIKE', '%' . $search . '%')->get() : ($filter == 'without_stock' ? Items::select('items.*')->whereRaw('not exists (select 1 from stock_items where stock_items.stock_period_id = ' . $currentPeriodId . ' and stock_items.item_id = items.id)')->get() : Items::all());
         if (count($items) == 1 && $search) {
             return redirect()->action('StockCheckController@edit', ['item_id' => $items->first()->id]);
         }
         $last_period = StockPeriods::where(['number' => StockPeriods::findOrFail($currentPeriodId)->number - 1])->get();
         return view('StockCheck.index')->with(array('title' => $this->title, 'items' => $search ? Items::where('title', 'LIKE', '%' . $search . '%')->take(10)->get() : ($filter == 'without_stock' ? Items::select('items.*')->whereRaw('not exists (select 1 from stock_items where stock_items.stock_period_id = ' . $currentPeriodId . ' and stock_items.item_id = items.id)')->orderBy("updated_at", 'DESC')->get() : Items::orderBy("updated_at", 'DESC')->take(10)->get()), 'item_list' => Items::lists('title'), 'search' => $search, 'period' => $currentPeriodId, 'previous' => count($last_period) > 0 ? $last_period->first()->id : 0, 'filter' => $filter, 'not_updated' => $not_updated));
     } else {
         Session::flash('flash_message', 'You need to start a period first!');
         return Redirect::action('StockPeriodsController@index');
     }
 }
Ejemplo n.º 2
0
 public function exportExcel($stock, $category)
 {
     $data = $this->getData($stock, $category);
     $c = ItemCategories::findOrFail($category);
     $s = StockPeriods::findOrFail($stock);
     $ready = [];
     $total = 0;
     foreach ($data['items'] as $key => $d) {
         $ready[$key] = ['ID' => $key, 'Title' => $d['title'], 'Price per unit (£)' => $d['purchases']['price'] ? $d['purchases']['price'] : 'not set', 'Opening Stock' => $d['last_stock'] . ' ' . $d['units'], 'Purchases' => $d['purchases']['value'] . ' ' . $d['units'], 'Sales' => $d['sales'] . ' ' . $d['units'], 'Wastage' => $d['wastage'] . ' ' . $d['units'], 'Predicted' => $d['must_stock'] . ' ' . $d['units'], 'Closing Stock' => $d['current_stock'] . ' ' . $d['units'], 'Difference' => $d['stock_difference'] . ' ' . $d['units'], 'Variance' => '£ ' . $d['variance']];
         $total += $d['variance'];
     }
     $ready[] = ['ID' => '', 'Title' => '', 'Price per unit (£)' => '', 'Opening Stock' => '', 'Purchases' => '', 'Sales' => '', 'Wastage' => '', 'Predicted' => '', 'Closing Stock' => '', 'Difference' => 'TOTAL', 'Variance' => '£ ' . $total];
     Excel::create($c->title, function ($excel) use($ready, $s, $c) {
         $excel->sheet('Sheetname', function ($sheet) use($ready, $s, $c) {
             $sheet->setAutoSize(true);
             $sheet->mergeCells('A1:K1');
             $sheet->mergeCells('A2:K2');
             //header
             $sheet->setHeight(1, 40);
             $sheet->row(1, function ($row) {
                 $row->setFontSize(30);
             });
             $sheet->row(1, array('Stock#' . $s->number . ' (' . $s->date_from . ' - ' . ($s->date_to ? $s->date_to : 'NOW') . ')'));
             //category
             $sheet->setHeight(2, 30);
             $sheet->row(2, function ($row) {
                 $row->setFontSize(20);
             });
             $sheet->row(2, array('Category: ' . $c->title));
             //table headers
             $sheet->setHeight(3, 20);
             $sheet->row(3, function ($row) {
                 $row->setFontWeight('bold');
             });
             $sheet->cells('C', function ($cells) {
                 $cells->setAlignment('left');
                 $cells->setFontSize(10);
             });
             //table data
             $sheet->setFontSize(10);
             $sheet->fromArray($ready, null, 'A3');
         });
     })->export('xls');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $period = StockPeriods::findOrFail($id);
     $period->delete();
     Session::flash('flash_message', $this->title . ' successfully deleted!');
     return Redirect::action('StockPeriodsController@index');
 }