/** * Show the form for creating a new resource. * * @return Response */ public function create() { $currentPeriodId = Helper::defaultPeriodId(); $periods = StockPeriods::all(); $period_list = array(); foreach ($periods as $period) { $period_list[$period->id] = 'Stock #' . $period->number . ' (' . $period->date_from . ' - ' . ($period->id == $currentPeriodId ? 'NOW' : $period->date_to) . ')'; } if (Input::has('stock_period')) { $currentPeriodId = Input::get('stock_period'); } return view('Sales.create')->with(array('title' => $this->title, 'period' => $currentPeriodId, 'stocks_list' => $period_list)); }
public static function getDefaultPeriod() { if (\Illuminate\Support\Facades\Session::has('period')) { $p = \App\Models\StockPeriods::where(['id' => \Illuminate\Support\Facades\Session::get('period')])->get(); $period = count($p) > 0 ? $p->first() : 0; } else { $current = \App\Models\StockPeriods::whereNull('date_to')->get(); if (count($current) > 0) { $number = $current->first()->number - 1; $p = \App\Models\StockPeriods::where(['number' => $number])->get(); } $period = count($p) > 0 ? $p->first() : 0; } return $period; }
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'); }
function getData() { $currentPeriodId = Helper::defaultPeriodId(); $periods = StockPeriods::all(); $period_list = array(); $period_dates = array(); foreach ($periods as $period) { $period_list[$period->id] = 'Stock #' . $period->number . ' (' . $period->date_from . ' - ' . ($period->date_to ? $period->date_to : 'NOW') . ')'; $period_dates[$period->id] = ['from' => date('Y-m-d', strtotime($period->date_from)), 'to' => date('Y-m-d', strtotime($period->date_to))]; } if (Input::has('stock_period')) { $currentPeriodId = Input::get('stock_period'); } $date_from = Input::has('date_from') ? Input::get('date_from') : $period_dates[$currentPeriodId]['from']; $date_to = Input::has('date_to') ? Input::get('date_to') : ($period_dates[$currentPeriodId]['to'] ? $period_dates[$currentPeriodId]['to'] : date('Y-m-d', time())); $purchases_list = Purchases::where('date_created', '>=', $date_from)->where('date_created', '<=', $date_to)->orderBy('date_created', 'DESC')->get(); $purchases = array(); foreach ($purchases_list as $purchase) { $NET = round($purchase->purchases()->sum('price'), 2); $VAT = round($purchase->purchases()->sum('vat'), 2); $purchases['items'][$purchase->id] = ['number' => $purchase->number, 'date_created' => $purchase->date_created, 'vat_date' => $purchase->vat_date, 'supplier' => $purchase->supplier()->first() ? $purchase->supplier()->first()->title : '', 'category' => $purchase->category()->first() ? $purchase->category()->first()->title : '', 'NET' => $NET, 'VAT' => $VAT, 'GROSS' => $NET + $VAT, 'status' => $purchase->status ? 'PAID' : 'PENDING']; } $purchases['from'] = $date_from; $purchases['to'] = $date_to; return $purchases; }
public function edit($id) { $item = Items::findOrFail($id); $other = $item->units()->where(['default' => 0])->first(); $actions = ['add' => 'Add', 'reduce' => 'Reduce by', 'change' => 'Change to']; $other_units = []; if ($other) { foreach ($item->units()->where(['default' => 0])->get() as $unit) { $other_units[$unit->id] = $unit->unit()->first()->title; } } $currentPeriodId = Helper::periodAfterId(Helper::defaultPeriodId()); $periods = StockPeriods::all(); $period_list = array(); foreach ($periods as $period) { $period_list[$period->id] = 'Stock #' . $period->number . ' (' . $period->date_from . ' - ' . ($period->id == $currentPeriodId ? 'NOW' : $period->date_to) . ')'; } if (Input::has('stock_period')) { $currentPeriodId = Input::get('stock_period'); } return view('StockCheck.edit')->with(array('title' => $this->title, 'item' => $item, 'default' => $item->units()->where(['default' => 1])->first(), 'other' => $other, 'actions' => $actions, 'other_units' => $other_units, 'period' => $currentPeriodId, 'stock' => StockCheck::select(['stock_items.*', 'stock_checks.*'])->join('stock_items', 'stock_checks.stock_item_id', '=', 'stock_items.id')->where(['stock_checks.item_id' => $id, 'stock_items.stock_period_id' => $currentPeriodId])->orderBy('stock_checks.created_at', 'DESC')->get(), 'stocks_list' => $period_list)); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $waste = Wastes::findOrFail($id); $currentPeriodId = Helper::defaultPeriodId(); $periods = StockPeriods::all(); $period_list = array(); foreach ($periods as $period) { $period_list[$period->id] = 'Stock #' . $period->number . ' (' . $period->date_from . ' - ' . ($period->id == $currentPeriodId ? 'NOW' : $period->date_to) . ')'; } if (Input::has('stock_period')) { $currentPeriodId = Input::get('stock_period'); } $select_recipes = Recipes::orderBy('title', 'ASC')->lists('title', 'id'); $items = ItemUnits::orderBy('default', 'DESC')->get(); $items_units = []; foreach ($items as $item) { $items_units['list'][$item->item()->first()->id][] = ['id' => $item->id, 'title' => $item->unit()->first()->title]; $items_units['php_list'][$item->item()->first()->id][$item->id] = $item->unit()->first()->title; $items_units['factors'][$item->id] = $item->factor; } $select_items = Items::orderBy('title', 'ASC')->lists('title', 'id'); $select_menus = Menu::orderBy('title', 'ASC')->lists('title', 'id'); $select_reasons = WasteReasons::orderBy('reason', 'ASC')->lists('reason', 'id'); return view('Wastes.edit')->with(array('title' => $this->title, 'recipes' => $select_recipes, 'items' => $select_items, 'items_units' => $items_units, 'menus' => $select_menus, 'period' => $currentPeriodId, 'stocks_list' => $period_list, 'reasons' => $select_reasons, 'waste' => $waste)); }