Reparaciones con Prueba

This commit is contained in:
Juan Pablo Vial
2025-05-05 19:01:15 -04:00
parent 167d8e1ab7
commit 186cd0f5b8
2 changed files with 72 additions and 6 deletions

View File

@ -61,7 +61,11 @@ class SII implements Define\Money\Provider
throw new EmptyResponse($request_uri);
}
$body = $response->getBody();
$domHandler = HTMLDocument::createFromString($body->getContents());
$contents = $body->getContents();
if (trim($contents) === '') {
throw new EmptyResponse($request_uri);
}
$domHandler = HTMLDocument::createFromString($contents);
$table = $domHandler->querySelector('div#mes_all');
$tbody = $table->querySelector('tbody');
$trs = $tbody->querySelectorAll('tr');
@ -70,17 +74,17 @@ class SII implements Define\Money\Provider
* [th 1, td #, #, #, #, #, #, #, #, #, #, #, #]
*/
$year = [];
$trim = mb_chr(160);
foreach ($trs as $i => $tr) {
$tds = $tr->querySelectorAll('td');
foreach ($tds as $j => $td) {
$value = $td->nodeValue;
if (trim($value) === '') {
$value = $td->textContent;
if (trim($value, "{$trim} ") === '') {
continue;
}
$d = str_pad($j + 1, 2, '0', STR_PAD_LEFT);
$m = str_pad($i, 2, '0', STR_PAD_LEFT);
$m = str_pad($j + 1, 2, '0', STR_PAD_LEFT);
$d = str_pad($i + 1, 2, '0', STR_PAD_LEFT);
$date = "{$dateTime->format('Y')}-{$m}-{$d}";
trigger_error($date);
$value = $this->valorService->clean($value);
$year[$date] = $value;
}