Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert show errors #1068

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function toXml(): array
$parser = new Parser($version, $this->baselayout);
try {
$this->xmls[] = $parser->toXml($nota);
} catch (\Exception $e) {
} catch (\Throwable $e) {
if ($errors = $parser->getErrors()) {
throw new ParserException(implode(', ', $errors));
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function toXml(array $nota): ?string
*/
public function getErrors(): array
{
return $this->make->errors;
return $this->make->getErrors();
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/ConvertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace NFePHP\NFe\Tests;

use NFePHP\NFe\Convert;
use NFePHP\NFe\Exception\ParserException;
use PHPUnit\Framework\TestCase;

class ConvertTest extends TestCase
Expand Down Expand Up @@ -30,6 +31,15 @@ public function test_convert()
$this->assertInfoAdicional($nfe);
}

public function test_convert_errors()
{
$this->expectException(ParserException::class);
$this->expectExceptionMessageMatches('/A chave informada está incorreta/');
$txt = file_get_contents(__DIR__ . '/fixtures/txt/nfe_4.00_local_error.txt');
$conv = new Convert($txt);
$conv->toXml();
}

/**
* @param \SimpleXMLElement $nfe
* @return void
Expand Down
70 changes: 70 additions & 0 deletions tests/fixtures/txt/nfe_4.00_local_error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
NOTAFISCAL|1|
A|4.00|NFe3518082502833200010||
B|35|00000501|VENDA MERC.SUB.TRIBUTARIA|55|1|502|2018-08-13T17:28:10-03:00|2018-08-14T09:00:00-03:00|1|1|3550308|1|1|8|1|1|0|3|0|0|3.2.1.1|||
C|GSMMY COMERCIO DE CHOCOLATES LTDA|GSMMY|140950881119||||3|
C02|25028332000105|
C05|RUA CAETEZAL|296||AGUA FRIA|3550308|SAO PAULO|SP|02334130||Brasil|1122813500|
E|SILVANA MARCONI - VL LEOPOLDINA|1|142304338112|||[email protected]|
E02|17812455000295|
E05|R SCHILLING|491||VILA LEOPOLDINA|3550308|SAO PAULO|SP|05302001|1058|BRASIL|1143053063|
H|3||
I|11352|7897112913525|CX DE BOMBOM SORTIDO 105G - 11352|18069000|||5401|CX|10.0000|2.5300|25.30|7897112913525|CX|10.0000|2.5300|||||1||0||
I05c|1700700|||
M|0.00|
N|
N03|0|10|3|25.30|18.00|4.55||||0|||42.27|18.00|3.06||||
O|||0|999|
O07|50|0.12|
O10|25.30|0.00|
Q|
Q02|01|25.30|0.65|0.16|
S|
S02|01|25.30|3.00|0.76|
H|4||
I|14169|SEM GTIN|BOLO MEL BRIGADEIRO 65G CELOFANE E FITA - 14169|19052090|||5401|UN|10.0000|1.1200|11.20|SEM GTIN|UN|10.0000|1.1200|||||1||0||
I05c|1705600|||
M|0.00|
N|
N09|0|70|3|61.11|4.35|18.00|0.78||||0|||7.50|0.00|1.33||||||
O|||0|999|
O08|53|
Q|
Q02|01|11.20|0.65|0.07|
S|
S02|01|11.20|3.00|0.34|
H|2||
I|355|7897112903557|CX PAO DE MEL M/M 430 G - 355|19052090|||5401|CX|2.0000|11.2300|22.46|7897112903557|CX|2.0000|11.2300|||||1||0||
I05c|1705600|||
M|0.00|
N|
N09|0|70|3|61.11|8.73|18.00|1.57||||0|||15.03|0.00|2.67||||||
O|||0|999|
O08|53|
Q|
Q02|01|22.46|0.65|0.15|
S|
S02|01|22.46|3.00|0.67|
H|1||
I|45|7897112900457|CX PAO DE MEL LEITE 430 G - 45|19052090|||5401|CX|4.0000|11.2300|44.92|7897112900457|CX|4.0000|11.2300|||||1||0||
I05c|1705600|||
M|0.00|
N|
N09|0|70|3|61.11|17.46|18.00|3.14||||0|||30.07|0.00|5.33||||||
O|||0|999|
O08|53|
Q|
Q02|01|44.92|0.65|0.29|
S|
S02|01|44.92|3.00|1.35|
W|
W02|55.84|10.04|0.00|0.00|94.87|12.39|0.00|0.00|103.88|0.00|0.00|0.00|0.00|0.12|0.00|0.67|3.12|0.00|116.39|0.00|0.00|0.00|0.00|
X|3|
X03|CARRO PROPRIO -MUNIK|111220540115|R CAITEZAL, 316|SAO PAULO|SP|
X04|47269568000257|
X26|1|VOLUME|MUNIK||4.230|4.230|
Y||
Y02|502|116.39|0.00|116.39|
Y07|001|2018-08-13|116.39|
YA|0|01|116.39||00||0|
Z||BASE DO ICMS REDUZIDA EM 61,11 CF RICMS Pedido 000068|