/** * Execute the console command. * * @return mixed */ public function handle() { $contribuyentes = Contribuyente::all(); foreach ($contribuyentes as $contr) { $nuevasCanceladas = []; $listSat = ArchivoSat::where(function ($q) use($contr) { $q->where('rfc_emisor', '=', $contr)->orWhere('rfc_receptor', '=', $contr); })->lists('uuid'); $archivosEmpresa = ArchivoEmpresa::where(function ($q) use($contr) { $q->where('rfc_emisor', '=', $contr)->orWhere('rfc_receptor', '=', $contr); })->whereNotIn('uuid', $listSat)->get(); $archivosSat = ArchivoSat::whereIn('uuid', $listSat)->get(); $archivos = $archivosSat->merge($archivosEmpresa); foreach ($archivos as $datos) { $servidorSat = new ConsultarSat($datos->uuid, $datos->rfc_emisor, $datos->rfc_receptor, $datos->total); $servidorSat->hacerPeticion(); if ($servidorSat->fueCanceladaRecientemente()) { $nuevasCanceladas[] = array('uuid' => $datos->uuid, 'contribuyente' => $contr->nombre, 'rfc' => $contr->rfc); } } } }
public function satFiles($text, $isZip = true) { $id = Auth::user()->id; $carga = Cargas::where('user_id', '=', $id)->where('procesado', '=', false)->first(); $error = "No se ha seleccionado ningun contribuyente, regresa al paso 1"; if ($carga->rfc == null) { throw new \ErrorException($error); } $parser = new ParserCFID($text); $parser->parser(); $fecha = $parser->getFecha(); $rfcEmisor = $parser->getRfcEmisor(); $rfcReceptor = $parser->getRfcReceptor(); $uuid = $parser->getUUID(); $total = $parser->getTotal(); $subtotal = $parser->getSubTotal(); $error = "No ha seleccionado una fecha regrese al paso 1 para seleccionarla."; if (!$carga->anio || !$carga->mes) { if ($carga->mes != 0) { throw new \ErrorException($error); } } if ($carga->mes == 0) { $error = "Esta factura no corresponde al año seleccionado."; if ($carga->anio != $fecha->year) { if (!$isZip) { throw new \ErrorException($error); } else { return "no"; } } } elseif ($carga->mes <= 12) { $error = "Esta factura no corresponde a la fecha seleccionada."; if ($carga->mes != $fecha->month || $carga->anio != $fecha->year) { if (!$isZip) { throw new \ErrorException($error); } else { return "no"; } } } else { $error = "Hubo un error en la selección de fecha regrese al paso uno y verifíquelo."; throw new \ErrorException($error); } $rfc = $carga->rfc; $error = "Este rfc no pertence al contribuyente seleccionado"; if ($rfcEmisor != $rfc && $rfcReceptor != $rfc) { if (!$isZip) { throw new \ErrorException($error); } else { return $error; } } $error = "Ya existe el UUID: {$uuid}"; $sat = ArchivoSat::where('uuid', '=', $uuid)->first(); if ($sat) { if (!$isZip) { throw new \ErrorException($error); } else { return $error; } } $tipoEmisor = $parser->getTipoEmisor(); $tipoReceptor = $parser->getTipoReceptor(); ArchivoSat::create(['tipo_id' => 2, 'carga_id' => $carga->id, 'fecha' => $fecha, 'rfc_emisor' => $rfcEmisor, 'rfc_receptor' => $rfcReceptor, 'uuid' => $uuid, 'file' => $text, 'tipo_emisor' => $tipoEmisor, 'tipo_receptor' => $tipoReceptor, 'total' => $total, 'subtotal' => $subtotal]); $archivo = Archivos::where('uuid', '=', $uuid)->first(); if (!$archivo) { Archivos::create(['uuid' => $uuid]); } }