コード例 #1
0
 public function planes(Request $request)
 {
     $planes = Plan::orderBy('nombre')->get();
     $enterprises = new Enterprise();
     $order = $request->input('order') == 'asc' ? 'ASC' : 'DESC';
     if ($request->input('sort') == 'razon_social') {
         $enterprises = Enterprise::orderBy('razon_social', $order);
     } elseif ($request->input('sort') == 'created_at') {
         $enterprises = Enterprise::orderBy('created_at', $order);
     } elseif ($request->input('sort') == 'plan') {
         $enterprises = Enterprise::select('enterprises.*', 'planes.created_at AS created_date', 'planes.id AS plan_id')->leftJoin('planes', 'planes.id', '=', 'enterprises.plan_id')->orderBy('planes.nombre', $order);
     } elseif ($request->input('sort') == 'totals') {
         $enterprises = Enterprise::select('enterprises.*', 'planes.created_at AS created_date', 'planes.id AS plan_id', \DB::raw('(select SUM(so.total) from sale_orders as so where so.enterprise_id = enterprises.id) AS total_sales'))->leftJoin('planes', 'planes.id', '=', 'enterprises.plan_id')->orderBy('total_sales', $order);
     }
     //Filters
     $filtros = array();
     $monto_plan = $planObj = null;
     if ($request->input('tipo_plan')) {
         $enterprises = $enterprises->where('plan_id', $request->input('tipo_plan'));
         $filtros['tipo_plan'] = $request->input('tipo_plan');
         $planObj = Plan::find($request->input('tipo_plan'));
         $monto_plan = Enterprise::select(\DB::raw('SUM(payment_orders.monto) AS total_sales'))->where('plan_id', $request->input('tipo_plan'))->leftJoin('payment_orders', 'payment_orders.enterprise_id', '=', 'enterprises.id')->first();
     }
     if ($request->input('fecha_inic') != '' && $request->input('fecha_fin') != '') {
         $inic_arr = explode('/', $request->input('fecha_inic'));
         $inic = $inic_arr[2] . "-" . $inic_arr[1] . "-" . $inic_arr[0] . " 00:00:00";
         $fin_arr = explode('/', $request->input('fecha_fin'));
         $fin = $fin_arr[2] . "-" . $fin_arr[1] . "-" . $fin_arr[0] . " 11:59:59";
         $enterprises = $enterprises->whereBetween('created_at', [$inic, $fin]);
         $filtros['fecha_inic'] = $request->input('fecha_inic');
         $filtros['fecha_fin'] = $request->input('fecha_fin');
     } elseif ($request->input('fecha_inic') != '' && $request->input('fecha_fin') == '') {
         $inic_arr = explode('/', $request->input('fecha_inic'));
         $inic = $inic_arr[2] . "-" . $inic_arr[1] . "-" . $inic_arr[0] . " 00:00:00";
         $enterprises = $enterprises->where('created_at', '>', $inic);
         $filtros['fecha_fin'] = $request->input('fecha_fin');
     } elseif ($request->input('fecha_inic') == '' && $request->input('fecha_fin') != '') {
         $fin_arr = explode('/', $request->input('fecha_fin'));
         $fin = $fin_arr[2] . "-" . $fin_arr[1] . "-" . $fin_arr[0] . " 11:59:59";
         $enterprises = $enterprises->where('created_at', '<', $fin);
         $filtros['fecha_inic'] = $request->input('fecha_inic');
     }
     $enterprises = $enterprises->paginate(10);
     //Log::info($lastQuery);
     $order_colunm = $order == 'ASC' ? 'desc' : 'asc';
     $param_nombre = array_merge(['sort' => 'razon_social', 'order' => $order_colunm], $filtros);
     $param_date = array_merge(['sort' => 'created_at', 'order' => $order_colunm], $filtros);
     $param_plan = array_merge(['sort' => 'plan', 'order' => $order_colunm], $filtros);
     $param_total = array_merge(['sort' => 'totals', 'order' => $order_colunm], $filtros);
     return view('report.index', compact('enterprises', 'order_colunm', 'planes', 'filtros', 'param_nombre', 'param_date', 'param_plan', 'param_total', 'monto_plan', 'planObj'));
 }
コード例 #2
0
ファイル: PlanController.php プロジェクト: abada/telesistemas
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $planes = Plan::orderBy('nombre')->paginate(10);
     return view('plan.index', compact('planes'));
 }
コード例 #3
0
 public function showPlans()
 {
     $plans = Plan::orderBy('created_at', 'asc')->get();
     return view('navigation/plans', ['plans' => $plans]);
 }