Пример #1
0
 public function __construct($codigo_banco, $layout_versao = null)
 {
     $this->codigo_banco = $codigo_banco;
     $this->layout_versao = $layout_versao;
     $this->banco = \Cnab\Banco::getBanco($this->codigo_banco);
     //$this->data_gravacao = date('dmY');
 }
Пример #2
0
 public function configure(array $params)
 {
     $banco = \Cnab\Banco::getBanco($this->codigo_banco);
     $campos = array('data_geracao', 'data_gravacao', 'nome_fantasia', 'razao_social', 'cnpj', 'logradouro', 'numero', 'bairro', 'cidade', 'uf', 'cep');
     if ($this->codigo_banco == \Cnab\Banco::CEF) {
         $campos[] = 'agencia';
         $campos[] = 'agencia_dv';
         $campos[] = 'conta';
         $campos[] = 'operacao';
         $campos[] = 'codigo_cedente';
         $campos[] = 'numero_sequencial_arquivo';
     }
     foreach ($campos as $campo) {
         if (array_key_exists($campo, $params)) {
             if (strpos($campo, 'data_') === 0 && !$params[$campo] instanceof \DateTime) {
                 throw new \Exception("config '{$campo}' need to be instance of DateTime");
             }
             $this->configuracao[$campo] = $params[$campo];
         } else {
             throw new \Exception('Configuração "' . $campo . '" need to be set');
         }
     }
     foreach ($campos as $key) {
         if (!array_key_exists($key, $params)) {
             throw new Exception('Configuração "' . $key . '" dont exists');
         }
     }
     $this->data_geracao = $this->configuracao['data_geracao'];
     $this->data_gravacao = $this->configuracao['data_gravacao'];
     $this->headerArquivo = new HeaderArquivo($this);
     $this->headerLote = new HeaderLote($this);
     $this->trailerLote = new TrailerLote($this);
     $this->trailerArquivo = new TrailerArquivo($this);
     $this->headerArquivo->codigo_banco = $this->banco['codigo_do_banco'];
     $this->headerArquivo->codigo_inscricao = 2;
     $this->headerArquivo->numero_inscricao = $this->prepareText($this->configuracao['cnpj'], '.-/');
     $this->headerArquivo->agencia = $this->configuracao['agencia'];
     $this->headerArquivo->agencia_dv = $this->configuracao['agencia_dv'];
     $this->headerArquivo->codigo_cedente = $this->configuracao['codigo_cedente'];
     $this->headerArquivo->nome_empresa = $this->configuracao['nome_fantasia'];
     $this->headerArquivo->nome_banco = $banco['nome_do_banco'];
     $this->headerArquivo->codigo_remessa_retorno = 1;
     $this->headerArquivo->data_geracao = $this->configuracao['data_geracao'];
     $this->headerArquivo->hora_geracao = $this->configuracao['data_geracao'];
     $this->headerArquivo->numero_sequencial_arquivo = $this->configuracao['numero_sequencial_arquivo'];
     if ($this->codigo_banco == \Cnab\Banco::CEF) {
         $codigoConvenio = sprintf('%04d%03d%08d', $params['agencia'], $params['operacao'], $params['conta']);
         $codigoConvenio .= $this->mod11($codigoConvenio);
         $this->headerArquivo->codigo_convenio = $codigoConvenio;
     }
     $this->headerLote->codigo_banco = $this->headerArquivo->codigo_banco;
     $this->headerLote->lote_servico = 1;
     $this->headerLote->tipo_operacao = 'R';
     $this->headerLote->codigo_inscricao = $this->headerArquivo->codigo_inscricao;
     $this->headerLote->numero_inscricao = $this->headerArquivo->numero_inscricao;
     $this->headerLote->agencia = $this->headerArquivo->agencia;
     $this->headerLote->agencia_dv = $this->headerArquivo->agencia_dv;
     $this->headerLote->codigo_convenio = $this->headerArquivo->codigo_cedente;
     $this->headerLote->codigo_cedente = $this->headerArquivo->codigo_cedente;
     $this->headerLote->nome_empresa = $this->headerArquivo->nome_empresa;
     $this->headerLote->numero_sequencial_arquivo = $this->headerArquivo->numero_sequencial_arquivo;
     $this->headerLote->data_geracao = $this->headerArquivo->data_geracao;
     if ($this->codigo_banco == \Cnab\Banco::CEF) {
         $this->headerLote->tipo_servico = 2;
     }
     $this->trailerLote->codigo_banco = $this->headerArquivo->codigo_banco;
     $this->trailerLote->lote_servico = $this->headerLote->lote_servico;
     $this->trailerArquivo->codigo_banco = $this->headerArquivo->codigo_banco;
 }