relsi

Leitura de Arquivo de Retorno CEF/CNAB240

Jun 14th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. <?php
  2. /*
  3. Script para ler o arquivo de retorno da CEF/CNAB240
  4. */
  5. ?>
  6. <html>
  7. <body>
  8.     <table border="1">
  9.         <thead>
  10.             <tr>
  11.                 <th>Numero</th>
  12.                 <th>Data Vcto</th>
  13.                 <th>Data Pgto</th>
  14.                 <th>Valor do Boleto</th>
  15.                 <th>Juros/Multa</th>
  16.                 <th>Descontos</th>
  17.                 <th>Abatimento</th>
  18.                 <th>Valor Pago</th>
  19.                 <th>Valor Liquido</th>
  20.             </tr>
  21.         </thead>   
  22.         <?php
  23.         $arquivo_ret = @fopen("RETORNOCEF.RET","r");
  24.         if (!$arquivo_ret){
  25.             echo "Erro ao abrir o arquivo.";
  26.             exit;
  27.         }
  28.         $i = 0;
  29.         while (!feof($arquivo_ret)){
  30.             $i++;
  31.             $linha = fgets($arquivo_ret,9999);
  32.             $t_u_segmento = substr($linha,13,1);
  33.             if($t_u_segmento == 'T'){
  34.                 $num_fatura = substr($linha,58,11);
  35.                 $data_vencimento = substr($linha,73,8);
  36.                 $valor_boleto = substr($linha,81,13);
  37.             }
  38.             if($t_u_segmento == 'U'){
  39.                 $valor_juros_multa = substr($linha,17,15);
  40.                 $valor_desconto = substr($linha,32,15);
  41.                 $valor_abatimento = substr($linha,47,15);
  42.                 $valor_pago = substr($linha,77,15);
  43.                 $valor_liquido = substr($linha,92,15);
  44.                 $data_pagamento = substr($linha,137,8);
  45.             }
  46.         ?>
  47.         <tbody>
  48.             <tr>
  49.                 <td><?php echo $num_fatura;?></td>
  50.                 <td><?php echo $data_vencimento;?></td>
  51.                 <td><?php echo $data_pagamento;?></td>
  52.                 <td><?php echo $valor_boleto;?></td>
  53.                 <td><?php echo $valor_juros_multa;?></td>
  54.                 <td><?php echo $valor_desconto;?></td>
  55.                 <td><?php echo $valor_abatimento;?></td>
  56.                 <td><?php echo $valor_pago;?></td>
  57.                 <td><?php echo $valor_liquido;?></td>
  58.             </tr>
  59.         </tbody>
  60.         <?php } fclose($arquivo_ret); ?>
  61.     </table>
Advertisement
Add Comment
Please, Sign In to add comment