/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { // if ( !( $request->input('cost_average') > 0 ) ) $request->merge( ['cost_average' => $request->input('cost_price')] ); $action = $request->input('nextAction', ''); $this->validate($request, Product::$rules['create']); // Create Product $product = $this->product->create($request->except('quantity_onhand')); // Create stock movement (Initial Stock) $data = ['date' => \Carbon\Carbon::now(), 'document_reference' => '', 'price' => $request->input('price'), 'quantity' => $request->input('quantity_onhand'), 'notes' => '', 'product_id' => $product->id, 'warehouse_id' => $request->input('warehouse_id'), 'movement_type_id' => 10, 'model_name' => '', 'document_id' => 0, 'document_line_id' => 0, 'combination_id' => 0, 'user_id' => \Auth::id()]; $stockmovement = \App\StockMovement::create($data); // Stock movement fulfillment (perform stock movements) $stockmovement->fulfill(); if ($action == 'completeProductData') { return redirect('products/' . $product->id . '/edit')->with('info', l('This record has been successfully created :: (:id) ', ['id' => $product->id], 'layouts') . $request->input('name')); } else { return redirect('products')->with('info', l('This record has been successfully created :: (:id) ', ['id' => $product->id], 'layouts') . $request->input('name')); } }
/** * Bootstrap the application services. * * @return void */ public function boot() { // Currencies view()->composer(array('customers.edit', 'customer_invoices.create', 'companies.edit', 'customer_groups.create', 'customer_groups.edit'), function ($view) { $view->with('currencyList', \App\Currency::lists('name', 'id')); }); // Customer Groups view()->composer(array('customers.edit'), function ($view) { $view->with('customer_groupList', \App\CustomerGroup::lists('name', 'id')); }); // Payment Methods view()->composer(array('customers.edit', 'customer_invoices.create', 'customer_groups.create', 'customer_groups.edit'), function ($view) { $view->with('payment_methodList', \App\PaymentMethod::lists('name', 'id')); }); // Sequences view()->composer(array('customers.edit', 'customer_invoices.create', 'customer_groups.create', 'customer_groups.edit'), function ($view) { $view->with('sequenceList', \App\Sequence::lists('name', 'id')); }); // Invoice Template view()->composer(array('customers.edit', 'customer_invoices.create', 'customer_groups.create', 'customer_groups.edit'), function ($view) { $view->with('customerinvoicetemplateList', \App\Template::where('model_name', '=', 'CustomerInvoice')->lists('name', 'id')); }); // Carriers view()->composer(array('customers.edit', 'customer_invoices.create', 'customer_groups.create', 'customer_groups.edit'), function ($view) { $view->with('carrierList', \App\Carrier::lists('name', 'id')); }); // Sales Representatives view()->composer(array('customers.edit', 'customer_invoices.create'), function ($view) { $view->with('salesrepList', \App\SalesRep::select(DB::raw('concat (firstname," ",lastname) as name, id'))->lists('name', 'id')); }); // Price Lists view()->composer(array('customers.edit', 'customer_groups.create', 'customer_groups.edit'), function ($view) { $view->with('price_listList', \App\PriceList::lists('name', 'id')); }); // Warehouses view()->composer(array('products.create', 'stock_movements.create', 'configurationkeys.key_group_2', 'customer_invoices.create'), function ($view) { $whList = \App\Warehouse::with('address')->get(); $list = []; foreach ($whList as $wh) { $list[$wh->id] = $wh->address->alias; } $view->with('warehouseList', $list); // $view->with('warehouseList', \App\Warehouse::lists('name', 'id')); }); // Taxes view()->composer(array('customer_invoices.create', 'products.create', 'products.edit'), function ($view) { $view->with('taxList', \App\Tax::orderby('percent', 'desc')->lists('name', 'id')); }); view()->composer(array('products.create', 'products.edit', 'customer_invoices.create'), function ($view) { $view->with('taxpercentList', \App\Tax::lists('percent', 'id')); }); // Languages view()->composer(array('users.create', 'users.edit'), function ($view) { $view->with('languageList', \App\Language::lists('name', 'id')); }); // Categories view()->composer(array('products.create', 'products._panel_main_data'), function ($view) { $view->with('categoryList', \App\Category::orderby('name', 'asc')->lists('name', 'id')); }); // Stock Movement Types view()->composer(array('stock_movements.index', 'stock_movements.create'), function ($view) { $view->with('movement_typeList', \App\StockMovement::stockmovementList()); }); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $mvts = StockMovement::with('warehouse')->with('product')->with('combination')->orderBy('created_at', 'ASC')->get(); return View::make('stock_movements.index')->with('stockmovements', $mvts); }