File manager - Edit - /var/www/html/portalHomolog/app/Imports/DividaAtiva/DividaAtivaPlanilhaImport.php
Back
<?php namespace App\Imports\DividaAtiva; use App\Http\Controllers\Controller; use App\Models\DividaAtiva\DividaAtivaRegistro; use Maatwebsite\Excel\Concerns\ToModel; use Maatwebsite\Excel\Concerns\WithHeadingRow; use DateTime; class DividaAtivaPlanilhaImport extends Controller implements ToModel, WithHeadingRow { private $isPF = 0; private $cpf = null; private $cnpj = null; private array $registros = []; private function __convertForBoolean($text) { if (strtolower($text) == "sim") { return 1; } return 0; } private function __converterData($data) { $date = DateTime::createFromFormat('d/m/Y', $data); return $date ? $date->format('Y-m-d') : null; } private function __preparaDocumento($documento) { $dcmt = preg_replace('/[^0-9]/', '', (string) $documento); if (strlen($dcmt) === 11) { $this->cpf = $dcmt; $this->cnpj = null; $this->isPF = 1; return (string) $this->cpf; } if (strlen($dcmt) === 14) { $this->cnpj = $dcmt; $this->cpf = null; $this->isPF = 0; return (string) $this->cnpj; } $this->cpf = $this->cnpj = null; $this->isPF = 0; return null; } private function __preparaValorReal($valor) { $valor = str_replace(['R$', '.', ' '], '', $valor); $valor = str_replace(',', '.', $valor); return floatval($valor); } public function model(array $row) { $documento = $row['cpfcnpj'] ?? null; $this->__preparaDocumento($documento); if ($this->cpf != null || $this->cnpj != null) { if ($this->isPF) { if (!$this->validaCPF($this->cpf)) { return null; } } else { if (!$this->validaCNPJ($this->cnpj)) { return null; } } $dados = [ 'numInscricao' => $row['inscricao'] ?? null, 'numImovel' => $row['imovel'] ?? null, 'cpf' => $this->cpf, // definido na função 'cnpj' => $this->cnpj, // idem 'nome' => $row['nome'] ?? null, 'origemDivida' => $row['origem'] ?? null, 'exercicio' => $row['exercicio'] ?? null, 'dividaData' => $this->__converterData($row['datadividaativa'] ?? null), 'numCertidao' => $row['certidao'] ?? null, 'dividaStatus' => $row['status'] ?? null, 'dividaParcelado' => $this->__convertForBoolean($row['parcelado'] ?? null), 'dividaProtestado' => $this->__convertForBoolean($row['protestado'] ?? null), 'dividaAjuizado' => $this->__convertForBoolean($row['ajuizado'] ?? null), 'isPJ' => $this->isPF ? 0 : 1, // 0 = PF, 1 = PJ 'dividaValorTotal' => $this->__preparaValorReal($row['valortotal'] ?? null), 'informacoes' => null, 'status' => "ATIVADO", ]; $model = DividaAtivaRegistro::create($dados); $this->registros[] = $model; return $model; } return null; } public function getRegistros(): array { return $this->registros; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings