Exemple #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $count = 0;
     $pdo = DB::connection()->getPdo();
     $query = "SELECT * FROM archivos_sat;";
     $stmt = $pdo->prepare($query);
     $stmt->execute();
     while ($row = $stmt->fetchObject()) {
         $count++;
         if ($count % 100 == 0) {
             $this->comment("arch sat: " . $count);
         }
         $archivo = ArchivoSat::find($row->id);
         $parser = new ParserCFID($archivo->file);
         $parser->parser();
         $archivo->fecha = $parser->getFecha();
         $archivo->save();
     }
     $count = 0;
     $pdo = DB::connection()->getPdo();
     $query = "SELECT * FROM archivos_empresa;";
     $stmt = $pdo->prepare($query);
     $stmt->execute();
     while ($row = $stmt->fetchObject()) {
         $count++;
         if ($count % 100 == 0) {
             $this->comment("arch emp: " . $count);
         }
         $archivo = ArchivoEmpresa::find($row->id);
         $parser = new ParserCFID($archivo->file);
         $parser->parser();
         $archivo->fecha = $parser->getFecha();
         $archivo->save();
     }
 }
Exemple #2
0
 /**
  * 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 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 procesarFinal(Cargas $carga, $nombreCarga)
 {
     $pdo = DB::connection()->getPdo();
     $query = "select id from `archivos_sat` where `archivos_sat`.`carga_id` = {$carga->id} and `archivos_sat`.`carga_id` is not null ";
     $stmt = $pdo->prepare($query);
     $stmt->execute();
     $sats = 0;
     while ($row = $stmt->fetchObject()) {
         $sats++;
         $sat = ArchivoSat::find($row->id);
         $empresa = $sat->empresa;
         if ($empresa) {
             $parserSat = new ParserCFID($sat->file);
             $parserEmpresa = new ParserCFID($empresa->file);
             $parserSat->parser();
             $parserEmpresa->parser();
             $diff = $parserSat->comparar($parserEmpresa);
             if (count($diff) > 0) {
                 foreach ($diff as $key => $val) {
                     if (Str::contains($key, 'Addenda')) {
                         continue;
                     }
                     $diffModel = Diferencias::create(['sat_id' => $sat->id, 'empresa_id' => $empresa->id, 'campo' => $key, 'sat' => $val[0], 'empresa' => $val[1]]);
                 }
             }
             $sat->procesado = true;
             $sat->save();
             $empresa->procesado = true;
             $empresa->save();
         } else {
             //Cuando el sat no tiene una empresa con el mismo nombre
             $diffModel = Diferencias::create(['sat_id' => $sat->id, 'empresa_id' => 0, 'falta' => true, 'lado' => $this->empFalta]);
             $sat->procesado = true;
             $sat->save();
         }
     }
     $pdo = DB::connection()->getPdo();
     $query = "select id from `archivos_empresa` where `archivos_empresa`.`carga_id` = {$carga->id} and `archivos_empresa`.`carga_id` is not null and `procesado` = 0";
     $stmt = $pdo->prepare($query);
     $stmt->execute();
     $empresas = 0;
     while ($row = $stmt->fetchObject()) {
         $empresas++;
         $empresa = ArchivoEmpresa::find($row->id);
         $diffModel = Diferencias::create(['sat_id' => 0, 'empresa_id' => $empresa->id, 'falta' => true, 'lado' => $this->satFalta]);
         $empresa->procesado = true;
         $empresa->save();
     }
     //Ahora se buscan las empresas que quedaron si procesar, estas quiere decir que no tienen ningun archivo asociado
     $carga->procesado = true;
     $carga->nombre = $nombreCarga;
     $carga->save();
     $nombre = session('name');
     $numFact = $sats + $empresas;
     $notification = new NotHelper(session('id'), "{$nombre} ha cargado y procesado {$numFact} facturas nuevas para el contribuyente {$carga->rfc}", 0, url('cargas'));
     $notification->toMoreLevelThan(session('level'));
     return "yes";
 }