Skip to content

Instantly share code, notes, and snippets.

@felipefinhane
Last active April 17, 2018 19:26
Show Gist options
  • Save felipefinhane/5952ea6b42689d99e2dd5b3ef1e0778c to your computer and use it in GitHub Desktop.
Save felipefinhane/5952ea6b42689d99e2dd5b3ef1e0778c to your computer and use it in GitHub Desktop.
<?php
public function render()
{
$builder = new StdClass;
$pgto1 = new StdClass;
$pgto1->getIdPagamento = 'pagamentoAutenticacao';
$pgto2 = new StdClass;
$pgto2->getIdPagamento = 'pagamentoTributo';
$pgto3 = new StdClass;
$pgto3->getIdPagamento = 'pagamentoAutenticacao';
$pgto4 = new StdClass;
$pgto4->getIdPagamento = 'pagamentoTributo';
$pgto5 = new StdClass;
$pgto5->getIdPagamento = 'alegacaoSacado';
$pgto6 = new StdClass;
$pgto6->getIdPagamento = 'pagamentoAutenticacao';
$builder->pagamentos = [
$pgto1,
$pgto2,
$pgto3,
$pgto4,
$pgto5,
$pgto6
];
$builderFormated = new StdClass;
$builderFormated->headerFile = 'HEADER FILE';
$builderFormated->lotepagamentoAutenticacao = $this->getLote($builder->pagamentos, 'pagamentoAutenticacao');
$builderFormated->lotepagamentoTributo = $this->getLote($builder->pagamentos, 'pagamentoTributo');
$builderFormated->lotealegacaoSacado = $this->getLote($builder->pagamentos, 'alegacaoSacado');
$builderFormated->trailerFile = 'TRAILER FILE';
dump($builder);
dump($builderFormated);
die();
$this->disponibilidades();
}
private function getLote($arrData, $key)
{
$arrLote = $this->getPgto($arrData, $key);
$arrHeader['nome'] = $key;
$totalRegisters = count($arrLote);
$arrTrailer['totalRegistros'] = $totalRegisters + 2;
array_unshift($arrLote, $arrHeader);
array_push($arrLote, $arrTrailer);
return $arrLote;
}
private function getPgto($arrData, $key)
{
$arrRetorno = [];
foreach ($arrData as $pgto) {
if ($pgto->getIdPagamento == $key) {
$arrRetorno[] = $pgto;
}
}
//INSERE HEADER E TRAILER
return $arrRetorno;
}
@douglaskhubert
Copy link

Legal. Muito útil este trecho de código. Veio em hora certa, estava precisando.

Obrigado!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment