| Server IP : 162.214.74.102 / Your IP : 216.73.217.80 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/www/lrsys_apps/imobles/application/autoload/ |
Upload File : |
<?php
/***
* ERP 360
* https://forum.imasters.com.br/topic/490216-leitura-de-arquivos-ofx-com-php/
* https://lr-sys.atlassian.net/browse/ERP-360
* **/
class Ofx {
private $ofxFile;
public function __Construct($ofxFile) {
$this->ofxFile = $ofxFile;
}
public function getOfxAsXML() {
// $content = file_get_contents($this->ofxFile);
//ALTERAÇÃO indicada pelo site nos comentarios
$content = file_get_contents($this->ofxFile);
$content= mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
$content= str_replace("&",'e', $content);
$line = strpos($content, "<OFX>");
$ofx = substr($content, $line - 1);
$buffer = $ofx;
$count = 0;
while ($pos = strpos($buffer, '<')) {
$count++;
$pos2 = strpos($buffer, '>');
$element = substr($buffer, $pos + 1, $pos2 - $pos - 1);
if (substr($element, 0, 1) == '/')
$sla[] = substr($element, 1);
else
$als[] = $element;
$buffer = substr($buffer, $pos2 + 1);
} $adif = array_diff($als, $sla);
$adif = array_unique($adif);
$ofxy = $ofx;
foreach ($adif as $dif) {
$dpos = 0;
while ($dpos = strpos($ofxy, $dif, $dpos + 1)) {
$npos = strpos($ofxy, '<', $dpos + 1);
$ofxy = substr_replace($ofxy, "</$dif>\n<", $npos, 1);
$dpos = $npos + strlen($element) + 3;
}
} $ofxy = str_replace('&', '&', $ofxy);
return $ofxy;
}
/* * Retorna o Saldo da conta na data de exportação do extrato */
public function getBalance() {
$xml = new SimpleXMLElement($this->getOfxAsXML());
$balance = $xml->BANKMSGSRSV1->STMTTRNRS->STMTRS->LEDGERBAL->BALAMT;
$dateOfBalance = $xml->BANKMSGSRSV1->STMTTRNRS->STMTRS->LEDGERBAL->DTASOF;
$date = strtotime(substr($dateOfBalance, 0, 8));
$dateToReturn = date('Y-m-d', $date);
return Array('date' => $dateToReturn, 'balance' => $balance);
}
/* * Retora um array de objetos com as transações * * DTPOSTED => Data da Transação * TRNAMT => Valor da Transação * TRNTYPE => Tipo da Transação (Débito ou Crédito) * MEMO => Descrição da transação */
public function getTransactions() {
$xml = new SimpleXMLElement($this->getOfxAsXML());
$transactions = $xml->BANKMSGSRSV1->STMTTRNRS->STMTRS->BANKTRANLIST->STMTTRN;
return $transactions;
}
//criado para retornar os dados da conta
public function getAccount() {
$xml = new SimpleXMLElement($this->getOfxAsXML());
return $xml->BANKMSGSRSV1->STMTTRNRS->STMTRS->BANKACCTFROM;
}
}