Exemplo n.º 1
0
 /**
  * Display a listing of the resource.
  * @param  int  $id
  * @return Response
  */
 public function index($id)
 {
     $currentPeriodId = Helper::currentPeriodId();
     if (Input::has('stock_period')) {
         $currentPeriodId = Input::get('stock_period');
     }
     return view('SaleItems.index')->with(array('title' => $this->title, 'items' => SaleItems::where(['sale_id' => $id])->get(), 'period' => $currentPeriodId));
 }
Exemplo n.º 2
0
 public function uploadMenu(Request $request)
 {
     $data = $this->postUpload($request);
     if (is_array($data)) {
         $before = Menu::count();
         $sale = Sales::create(['stock_period_id' => $request->get('stock_period_id')]);
         foreach ($data as $item) {
             $menu = Menu::updateOrCreate(['number' => $item['number']], ['number' => $item['number'], 'title' => $item['title'], 'price' => $item['price']]);
             $data = ['quantity' => $item['quantity'], 'menu_id' => $menu->id, 'sale_id' => $sale->id, 'price' => $item['price'], 'total_price' => round($item['price'] * $item['quantity'], 2)];
             SaleItems::create($data);
         }
         $difference = Menu::count() - $before;
         Helper::add('', 'uploaded ' . $difference . ' menu items import file on import sales action');
         Session::flash('flash_message', 'Sale uploaded successfully with ' . $difference . ' new items added to menu.');
         return Redirect::action('SalesController@index', ['stock_period' => $request->get('stock_period_id')]);
     } else {
         return $data;
     }
 }