/** * {@inheritDoc} */ public function getHistory(Account $account, $count = 15) { if (!$this->logged) { throw new \RuntimeException('Call login() first'); } $browser = $this->getBrowser(); $browser->setUri($this->scheme . '://' . $this->site . $account->getLink())->request(); $browser->setUri($this->scheme . '://' . $this->site . '/accounting/showMoreAccountOperations')->request(); $browser->setUri($this->scheme . '://' . $this->site . '/accounting/showMoreAccountOperations')->request(); $browser->setUri($this->scheme . '://' . $this->site . '/accounting/showMoreAccountOperations')->request(); $response = $browser->setUri($this->scheme . '://' . $this->site . '/accounting/showMoreAccountOperations')->request()->getBody(); $dom = new \DomDocument(); @$dom->loadHTML($response); $xpath = new \DomXPath($dom); $lignes = $xpath->query("//table[@class='tb']/tr"); $operations = array(); $cpt = 0; foreach ($lignes as $idx => $ligne) { $tds = $xpath->query('td', $ligne); $date = trim($tds->item(0)->textContent); $dateTime = \DateTime::createFromFormat('d/m', $date, new \DateTimeZone('Europe/Paris')); if (!$dateTime || $cpt >= $count) { continue; } $operation = new Operation(); $operation->setAccount($account); $operation->setDate($dateTime->setTime(0, 0, 0)); $operation->setLabel($tds->item(1)->textContent); $amount = $this->_cleanBalance($tds->item(2)->textContent); $operation->setAmount($amount); $cpt++; $operations[] = $operation; } return $operations; }
/** * {@inheritDoc} */ public function getHistory(Account $account, $limit = 15) { // We need to be logged for this if (!$this->logged) { throw new \RuntimeException('Call login() first'); } $browser = $this->getBrowser(); // Tweak the account link to retrieve the maximum operations $link = preg_replace('/typeRecherche=(\\d){0,2}/', 'typeRecherche=10', $account->getLink()); $crawler = $browser->request('GET', $link); // Prepare operations array $operations = array(); // Loop on each row $xmlOperations = $crawler->filter('#mouvements tbody tr'); foreach ($xmlOperations as $idx => $operation) { // Break loop if limit is reached if ($limit > 0 && $idx >= $limit) { break; } // Clean and restart the crawler $crawler->clear(); $crawler->add($operation); // Build an operation $operation = new Operation(); $operation->setAccount($account); // operation date $date = $crawler->filter('td')->first()->text(); $dateTime = \DateTime::createFromFormat('d/m/Y', $date, new \DateTimeZone('Europe/Paris')); $dateTime->setTime(0, 0, 0); $operation->setDate($dateTime); // operation title $label = $crawler->filter('td')->eq(1)->each(function ($node, $i) { $innerHTML = ''; foreach ($node->childNodes as $child) { $innerHTML .= $child->ownerDocument->saveXml($child); } return $innerHTML; }); $label = strip_tags($label[0], '<br>'); $label = preg_replace("#<br ?/>#", "\n", $label); $label = trim($label); $operation->setLabel($label); // operation amount $amounts = $crawler->filter('td.num.bdrL'); $debit = $this->parseAmount($amounts->first()->text()); $credit = $this->parseAmount($amounts->eq(1)->text()); $amount = $credit === 0 ? $debit : $credit; $operation->setAmount($amount); $operations[] = $operation; } return $operations; }