public function getIngresos(Request $request) { try { $contr = $request->cont; $desde = Carbon::createFromFormat('Y-m-d', $request->desde)->startOfDay(); $hasta = Carbon::createFromFormat('Y-m-d', $request->hasta)->endOfDay(); } catch (\Exception $e) { return view('vacio'); } $sat = ArchivoSat::whereBetween('fecha', array($desde, $hasta))->where(function ($q) use($contr) { $q->where('rfc_emisor', '=', $contr)->orWhere('rfc_receptor', '=', $contr); })->get(); $empresa = ArchivoEmpresa::whereBetween('fecha', array($desde, $hasta))->where(function ($q) use($contr) { $q->where('rfc_emisor', '=', $contr)->orWhere('rfc_receptor', '=', $contr); })->get(); $todos = $sat->count() + $empresa->count(); if ($todos == 0) { return view('vacio'); } $diff = new DiferenciasCFID($sat, $empresa, $contr); $ingresos = $diff->getIngresos(); $contr = Contribuyente::where('rfc', '=', $contr)->first(); $array = ['nombre' => $contr->nombre, 'rfc' => $contr->rfc, 'ingresos' => $ingresos]; Excel::create('Ingresos', function ($excel) use($array) { $excel->sheet('New sheet', function ($sheet) use($array) { $sheet->loadView('descargas.reporte-ingresos', $array); }); })->download('xlsx'); }
public function mesesPorCarga(Cargas $cargas, $anio) { $meses = []; for ($i = 1; $i <= 12; $i++) { $fecha = Carbon::createFromFormat('Y-m', "{$anio}-{$i}"); $dia_ini = $fecha->firstOfMonth()->copy(); $dia_fin = $fecha->endOfMonth()->copy(); $satCount = ArchivoSat::whereBetween('fecha', array($dia_ini, $dia_fin))->where('carga_id', '=', $cargas->id)->count(); $empCount = ArchivoEmpresa::whereBetween('fecha', array($dia_ini, $dia_fin))->where('carga_id', '=', $cargas->id)->count(); if ($empCount > 0 || $satCount > 0) { $meses[] = $i; } } return $meses; }