public function anyEntry(Request $request,$id=null) { \DB::enableQueryLog(); if(isset($id) && $id!=null){ $id_purchaseorder = $id; $purchaseorder = Purchaseorder::find($id_purchaseorder); if($purchaseorder != null){ session(['current_purchaseorder' => $purchaseorder['id']]); }else{ return redirect('purchaseorders'); } }else{ $id_purchaseorder = session('current_purchaseorder') !== null ? session('current_purchaseorder') : 0; if($id_purchaseorder){ $purchaseorder = Purchaseorder::find($id_purchaseorder); session(['current_purchaseorder' => $purchaseorder['id']]); }else{ $purchaseorder = Purchaseorder::get()->last(); if($purchaseorder){ session(['current_purchaseorder' => $purchaseorder['id']]); }else{ $purchaseorder = new Purchaseorder; $purchaseorder->date = date("Y-m-d H:i:s"); $purchaseorder->created_by = \Auth::user()->id; $purchaseorder->save(); session(['current_purchaseorder' => $purchaseorder->id]); Log::create_log(\Auth::user()->id,'App\Purchaseorder','Tạo mới đơn mua hàng số '.$purchaseorder->id); session(['current_purchaseorder' => $purchaseorder->id]); } } } $address = Address::where('module_id','=',$purchaseorder->id) ->where('module_type','=','App\Purchaseorder')->first(); $address_province = isset($address->province_id)?$address->province_id:0; $country_province = Province::addSelect('provinces.name as province_name') ->where('provinces.id','=',$address_province) ->addSelect('countries.name as country_name') ->leftJoin('countries','countries.id','=','provinces.country_id') ->first(); if($country_province){ $country_province->toArray(); $purchaseorder['province_name'] = $country_province['province_name']; $purchaseorder['country_name'] = $country_province['country_name']; }else{ $purchaseorder['province_name'] = ''; $purchaseorder['country_name'] = ''; } if($address){ $address = $address->toArray(); }else{ $address = array(); } $purchaseorder = $purchaseorder->toArray(); //Init array $distributes = array(); $oums = array(); $users = array(); $countries = array(); $list_product = array(); $producttypes = array(); //Get value array $distributes = Company::getDistributeList()->with('address')->get()->toArray(); $oums = Oum::orderBy('name')->get()->toArray(); $users = User::get(); $countries = Country::with('provinces')->get()->toArray(); $producttypes = ProductType::get()->toArray(); $arr_product = MProduct::where('module_type','=','App\Purchaseorder') ->where('module_id','=',$purchaseorder['id']) ->lists('product_id'); Session::forget('product_of_po'.session('current_purchaseorder')); foreach ($arr_product as $key => $value) { Session::put('product_of_po'.session('current_purchaseorder').".".$value , $value); } $view_list_product = self::getListProduct(); $arr_create = Purchaseorder::select('users.name','purchaseorders.created_at') ->leftJoin('users','users.id','=','purchaseorders.created_by') ->where('purchaseorders.id','=',$purchaseorder['id']) ->get()->first()->toArray(); $arr_update = Purchaseorder::select('users.name','purchaseorders.updated_at') ->leftJoin('users','users.id','=','purchaseorders.updated_by') ->where('purchaseorders.id','=',$purchaseorder['id']) ->get()->first()->toArray(); $this->layout->arr_create = $arr_create; $this->layout->arr_update = $arr_update; $this->layout->content=view('purchaseorder.entry',[ 'distributes'=>$distributes, 'users'=>$users, 'countries'=>$countries, 'purchaseorder'=>$purchaseorder, 'address'=>$address, 'oums'=>$oums, 'producttypes'=>$producttypes, 'view_list_product'=>$view_list_product ]); }
public function anyTonDauThang(Request $request){ if($request->has('input-sort')){ $arr_sort = $request->input('input-sort'); $arr_sort =(array) json_decode($arr_sort); }elseif( session('sort_filter_product_ton_dau_thang.arr_sort') !== null){ $arr_sort = session('sort_filter_product_ton_dau_thang.arr_sort'); }else{ $arr_sort=array(); } session('sort_filter_product_ton_dau_thang.arr_sort', $arr_sort); $list_month = ReceiptMonth::select('month','year') ->distinct()->where('month','>',0) ->orderBy('year','ASC') ->orderBy('month','ASC') ->get()->toArray(); if($request->has('input-filter')){ $arr_filter = $request->input('input-filter'); }elseif( session('sort_filter_product_ton_dau_thang.arr_filter') !== null ){ $arr_filter = session('sort_filter_product_ton_dau_thang.arr_filter'); }else{ $arr_filter=[ 'sku'=>'', 'like_name'=>'', 'name'=>'', 'company_id'=>'', 'oum_id'=>'' ]; if(count($list_month)){ $arr_filter['month'] = $list_month[0]['month'].'-'.$list_month[0]['year']; } } session(['sort_filter_product_ton_dau_thang.arr_sort'=>$arr_sort]); session(['sort_filter_product_ton_dau_thang.arr_filter'=> $arr_filter]); $list_all_product = Product::select('sku','name')->orderBy('sku')->get()->toArray(); $list_month = array(); //Init array $distributes = array(); $oums = array(); $producttypes = array(); $list_sku = array(); //Get value array $distributes = Company::getDistributeList()->get()->toArray(); $oums = Oum::orderBy('name')->get()->toArray(); $producttypes = ProductType::get()->toArray(); $list_all_product = Product::select('sku','name')->orderBy('sku')->get()->toArray(); $list_product = TonDauThang::select( 'products.id', 'products.name', 'products.sku', 'ton_dau_thangs.quantity', 'ton_dau_thangs.month', 'ton_dau_thangs.year', 'm_products.oum_id', 'm_products.specification', 'm_products.origin_price', 'companies.name as company_name', 'oums.name as oum_name' ) ->addSelect(DB::raw('product_stocks.in_stock/m_products.specification as real_in_stock')) ->leftJoin('m_products','m_products.id','=','ton_dau_thangs.m_product_id') ->leftJoin('products','products.id','=','m_products.product_id') ->leftJoin('oums','oums.id','=','m_products.oum_id') ->leftJoin('companies','companies.id','=','m_products.company_id') ->leftJoin('product_stocks','m_products.id','=','product_stocks.m_product_id') ->groupBy('products.id','m_products.company_id','m_products.oum_id','m_products.specification','m_products.origin_price') ->where('ton_dau_thangs.quantity','>',0); foreach ($arr_filter as $key => $value) { if($value!=''){ if($arr_filter['sku']!=''){ $list_product->where('products.sku',$arr_filter['sku']); } if($key == 'like_name'){ $list_product->where('products.name','LIKE',"%".$arr_filter['like_name']."%"); $arr_filter['name']=''; } if($key == 'name' && $arr_filter['name']!=''){ $list_product->where('products.name',$arr_filter['name']); } if($key == 'company_id'){ $list_product->where('m_products.company_id',$arr_filter['company_id']); } if($key == 'status'){ $list_product->where('products.status',$arr_filter['status']); } if($key == 'oum_id'){ $list_product->where('m_products.oum_id',$arr_filter['oum_id']); } if($key == 'month' && $arr_filter['month'] !=''){ $month_year = explode('-',$arr_filter['month']); $list_product->where('ton_dau_thangs.month','=',$month_year[0]) ->where('ton_dau_thangs.year','=',$month_year[1]); } } } foreach ($arr_sort as $key => $value) { if($key=='company_id'){ $list_product = $list_product->orderBy('companies.name',$value); }elseif($key=='oum_id'){ $list_product = $list_product->orderBy('oums.name',$value); }elseif($key=='id'){ $list_product = $list_product->orderBy('products.id',$value); }elseif($key=='specification'){ $list_product = $list_product->orderBy('m_products.specification',$value); }elseif($key=='quantity'){ $list_product = $list_product->orderBy('ton_dau_thangs.quantity',$value); }else{ $list_product = $list_product->orderBy($key,$value); } } $list_month = ReceiptMonth::select('month','year') ->distinct()->where('month','>',0) ->orderBy('year','ASC') ->orderBy('month','ASC') ->get()->toArray(); $list_product = $list_product->orderBy('products.id','asc'); \Cache::put('list_product'.\Auth::user()->id, $list_product->get()->toArray(), 30); $sum_invest = 0; foreach ($list_product->get()->toArray() as $key => $value) { $sum_invest += $value['origin_price'] * $value['quantity']; } $list_product = $list_product->paginate(100); $this->layout->content=view('product.list-ton-dau-thang', [ 'distributes' => $distributes, 'oums' => $oums, 'producttypes' => $producttypes, 'list_product' => $list_product, 'list_all_product' => $list_all_product, 'arr_sort' => $arr_sort, 'arr_filter' => $arr_filter, 'sum_invest' => $sum_invest, 'list_month' => $list_month ]); }
/** * Show the application index. * * @return \Illuminate\Http\Response */ public function index() { $types = ProductType::get(); return view('home', array('types' => $types)); }