public function reports_type(Request $request){ $group_id = $request['group_id']; $category_id = $request['category_id']; $subcategory_id = $request['subcategory_id']; $period = $request['period']; $date_start = $request['date_start']; $date_end = $request['date_end']; $month_start = $request['month_start']; $month_end = $request['month_end']; $user_id = $request['user_id']; $d_start = null; $d_end = null; $type_box = $request['type_box']; $establishment_id = $request['establishment_id']; switch ($period) { case 'month': $d_start = Carbon::parse($month_start.'-01')->format('Y-m-d'); $d_end = Carbon::parse($month_end.'-01')->endOfMonth()->format('Y-m-d'); break; case 'between_months': $d_start = Carbon::parse($month_start.'-01')->format('Y-m-d'); $d_end = Carbon::parse($month_end.'-01')->endOfMonth()->format('Y-m-d'); break; case 'date': $d_start = $date_start; $d_end = $date_end; break; case 'between_dates': $d_start = $date_start; $d_end = $date_end; break; } $with_relations = [ 'medic', 'patient', 'quotation.medic', 'quotation.patient', 'quotation.specialty', 'quotation.treatment', 'sale_note.medic', 'sale_note.patient', 'treatment', 'specialty', 'establishment', 'document.customer', 'user' ]; $data_ingresos = Box::with($with_relations) ->whereBetween('date', [$d_start, $d_end]) ->where('amount', '>', "0.00") ->whereType('1') ->orderBy('date', 'desc') ->orderBy('type') ->latest(); $data_egresos = Box::with($with_relations) ->whereBetween('date', [$d_start, $d_end]) ->where('amount', '>', "0.00") ->whereType('2') ->orderBy('date', 'desc') ->orderBy('type') ->latest(); if ($user_id) { $data_ingresos = $data_ingresos->where('user_id', $user_id); $data_egresos = $data_egresos->where('user_id', $user_id); } if ($establishment_id) { $data_ingresos = $data_ingresos->where('establishment_id', $establishment_id); $data_egresos = $data_egresos->where('establishment_id', $establishment_id); } $boxes_report_ingresos = collect(new BoxCollection($data_ingresos->get())); $boxes_report_egresos = collect(new BoxCollection($data_egresos->get())); $company = Company::first(); $auth = Auth::user(); $establishment = ($establishment_id != null) ? Establishment::findOrFail($establishment_id) : Establishment::findOrFail($auth->establishment_id); if ($request['type'] == "pdf") { $pdf = PDF::loadView('reports.boxes.report_pdf', compact( "boxes_report_ingresos", "boxes_report_egresos", "establishment", "date_start", "date_end", "company", "type_box", "auth" ))->setPaper('a4', 'landscape'); return $pdf->stream('Reporte_Ventas_'.date('YmdHis').'.pdf'); } }