✏️ 正在编辑: Santander.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/library/Core/Banco/Remessa/Santander.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use Core_Banco_Service_Remessa as Service; use Core_Banco_Remessa_Config_Santander as Config; class Core_Banco_Remessa_Santander extends Core_Banco_Remessa { /** @var Zend_Db_Table_Row_Abstract|null */ protected $empresa; /** @var Zend_Db_Table_Row */ protected $conta; /** @var string */ protected $bancoId; /** @var int|null */ protected $codigoRemessa; /** @var array */ protected $pagamentos = array(); /** @var string|null */ protected $dataPagamento = null; /** @var string|null */ protected $tipoTransferencia = 'DOC'; /** @var Service */ private $service; /** @var float */ protected $valorTotal; /** @var int */ protected $lotes; /** @var int */ protected $registros; /** @var array */ protected $arquivo; /** * @param array|null $lancamentos * @param Zend_Db_Table_Row $conta * @param string|null $tipoTransferencia * @param string|null $dataPagamento * @param int|null $codigoRemessa * @throws Zend_Date_Exception * @throws Zend_Db_Table_Row_Exception */ public function __construct( ?array $lancamentos, Zend_Db_Table_Row $conta, ?string $tipoTransferencia, ?string $dataPagamento = null, ?int $codigoRemessa = 1 ) { $this->service = new Service(); $this->empresa = $conta->findParentRow('Model_DbTable_Empresa'); $this->conta = $conta; $this->bancoId = $conta->banco_id; $this->codigoRemessa = $codigoRemessa; $this->tipoTransferencia = $tipoTransferencia; $this->pagamentos = (new Model_ProtocoloPagamento) ->listarProtocolosParaQuitar(['protocolo_pagamento_id' => $lancamentos]); $this->dataPagamento = empty($dataPagamento) ? Zend_Date::now()->get('ddMMyyyy') : (new Zend_Date($dataPagamento))->get('ddMMyyyy') ; $this->setFileName("santander"); $this->setExtensao("rem"); } /** * @return string */ protected function gerarHeaderArquivo(): string { $this->incrementRegistro(); return $this->formatarNew( Config::headerArquivo(), [ '06.0' => $this->empresa->cnpj, '07.0' => $this->conta->convenio, '08.0' => $this->conta->agencia, '09.0' => $this->conta->agencia_dv, '10.0' => $this->conta->conta, '11.0' => $this->conta->conta_dv, '12.0' => $this->conta->agencia_dv, '13.0' => $this->empresa->razao_social, '17.0' => (Zend_Date::now())->get('ddMMYYYY'), '18.0' => (Zend_Date::now())->get('HHmmss'), '19.0' => $this->numero, ] ); } /** * @return string */ protected function gerarTrailerArquivo(): string { return $this->formatarNew( Config::traillerArquivo(), [ '06.9' => $this->incrementRegistro() ] ); } /** * @return string */ protected function gerarTraillerLote(): string { $this->incrementLote(); $this->incrementRegistro(); return $this->formatarNew( Config::trailerLote(), [ '05.5' => $this->lotes, '06.5' => Service::formatFloat($this->valorTotal) ] ); } /** * @return string */ protected function gerarHeaderLote(): string { $this->incrementRegistro(); return $this->formatarNew( Config::headerLote(), [ '06.1' => '03', '09.1' => '2', '10.1' => $this->empresa->cnpj, '11.1' => $this->conta->convenio, '12.1' => $this->conta->agencia, '13.1' => $this->conta->agencia_dv, '14.1' => $this->conta->conta, '15.1' => $this->conta->conta_dv, '16.1' => $this->conta->agencia_dv, '17.1' => $this->empresa->razao_social, '19.1' => $this->empresa->endereco, '20.1' => $this->empresa->numero, '21.1' => $this->empresa->complemento, '22.1' => $this->empresa->cidade, '23.1' => substr($this->empresa->cep, 0, 5), '24.1' => substr($this->empresa->cep, 5, 3), '25.1' => $this->empresa->uf, ] ); } /** * @param $pagamento * @return string */ protected function gerarSegmentoA($pagamento): string { $this->incrementRegistro(); $valorPagamento = $this->getValorPagamento($pagamento); return $this->formatarNew( Config::segmentoA(), [ '04.3A' => $this->incrementLote(), '09.3A' => $pagamento['banco'], '10.3A' => $pagamento['agencia'], '12.3A' => substr($pagamento['conta'], 0, strlen($pagamento['conta'])-1), '13.3A' => substr($pagamento['conta'], strlen($pagamento['conta'])-1, 1), '15.3A' => $pagamento['titular'], '16.3A' => $pagamento['id'], '17.3A' => Zend_Date::now()->get('ddMMyyyy'), '20.3A' => $valorPagamento, '22.3A' => $this->dataPagamento, '23.3A' => $valorPagamento, '24.3A' => "Yuppie - Protocolo {$pagamento['id']}", '25.3A' => $this->getTipoConta($pagamento), '26.3A' => '10' ] ); } /** * @param $pagamento * @return string */ protected function gerarSegmentoB($pagamento): string { $this->incrementRegistro(); $corretor = (new Model_Corretor())->exibir($pagamento['corretor_id']); return $this->formatarNew( Config::segmentoB(), [ '04.3B' => $this->incrementLote(), '07.3B' => strlen($pagamento['cpf_titular']) > 11 ? 2 : 1, '08.3B' => $pagamento['cpf_titular'], '09.3B' => $corretor->endereco, '10.3B' => $corretor->numero, //numero endereço '11.3B' => $corretor->complemento, '12.3B' => $corretor->bairro, '13.3B' => $corretor->cidade, '14.3B' => $corretor->cep, '15.3B' => $corretor->uf, '16.3B' => new Zend_Date($this->dataPagamento, 'ddMMyyyy'), '17.3B' => $this->getValorPagamento($pagamento), ] ); } /** * @param array $pagamento * @return float */ protected function getValorPagamento(array $pagamento): string { $taxaTransferencia = Service::getTaxaTransferencia($pagamento); $valorComissao = $pagamento['total_comissao']; return Service::formatFloat( $valorComissao + $pagamento['acrescimo'] - $pagamento['desconto'] - $taxaTransferencia - $pagamento['recuperado'] ); } /** * @return string */ public function gerar(): string { $this->service->validarPagamentos($this->pagamentos); $this->numero = $this->service->saveRemessa($this->empresa->id, $this->bancoId); $this->gerarLinhas(); return implode("\r\n", $this->arquivo) . "\r\n"; } public function gerarLinhas(): void { $this->arquivo[] = $this->gerarHeaderArquivo(); $this->arquivo[] = $this->gerarHeaderLote(); $this->gerarSegmentoAB(); $this->arquivo[] = $this->gerarTraillerLote(); $this->arquivo[] = $this->gerarTrailerArquivo(); } public function gerarSegmentoAB(): void { foreach ($this->pagamentos as $pagamento) { $pagamento['codigo_remessa'] = $this->getCodigoRemessa($pagamento); $this->arquivo[] = $this->gerarSegmentoA($pagamento); $this->arquivo[] = $this->gerarSegmentoB($pagamento); $this->incrementValorTotal($pagamento); $this->service->updateProtocoloPagamento($pagamento, $this->numero); } } /** * @param array $pagamento * @return int|null */ public function getCodigoRemessa(array $pagamento): ?int { return !empty($pagamento['codigo_remessa']) ? $pagamento['codigo_remessa'] : $this->codigoRemessa ; } /** * @param array $pagamento * @return string */ public function getTipoConta(array $pagamento): string { if ($this->tipoTransferencia === 'CC') { return ''; } if ($pagamento['tipo_conta'] === 'CP') { return '11'; } return '01'; } /** * @param array $pagamento */ public function incrementValorTotal(array $pagamento): void { $this->valorTotal += $this->getValorPagamento($pagamento); } /** * @return int */ public function incrementLote(): int { if (!$this->lotes) { $this->lotes = 1; } return $this->lotes++; } /** * @return int */ public function incrementRegistro(): int { if (!$this->registros) { $this->registros = 1; } return $this->registros++; } }
💾 保存文件
← 返回文件管理器