/** * 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)); }
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)); }