From 4e08ca5b3d927291b83db26e607cc14e9b3ee7cd Mon Sep 17 00:00:00 2001 From: giansalex Date: Fri, 6 Oct 2017 10:45:13 -0500 Subject: [PATCH] Add xml utils + unit test --- src/Report/XmlUtils.php | 51 ++++ tests/Report/HtmlReportTest.php | 9 + tests/Report/XmlUtilsTest.php | 40 ++++ .../20505310072-01-F001-00019772.xml | 199 ++++++++++++++++ .../20505310072-03-B001-00000088.xml | 218 ++++++++++++++++++ tests/Resources/qrcode.png | Bin 411 -> 512 bytes 6 files changed, 517 insertions(+) create mode 100644 src/Report/XmlUtils.php create mode 100644 tests/Report/XmlUtilsTest.php create mode 100644 tests/Resources/20505310072-01-F001-00019772.xml create mode 100644 tests/Resources/20505310072-03-B001-00000088.xml diff --git a/src/Report/XmlUtils.php b/src/Report/XmlUtils.php new file mode 100644 index 0000000..58cf2e6 --- /dev/null +++ b/src/Report/XmlUtils.php @@ -0,0 +1,51 @@ +loadXML($xml); + + return self::extractSignFromDoc($doc); + } + + /** + * @param \DOMDocument $document + * @return string + */ + public static function extractSignFromDoc(\DOMDocument $document) + { + $xpt = new \DOMXPath($document); + + $exts = $xpt->query('ext:UBLExtensions/ext:UBLExtension', $document->documentElement); + if ($exts->length == 0) { + return ''; + } + $nodeSign = $exts->item($exts->length - 1); + + $hash = $xpt->query('ext:ExtensionContent/ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue', $nodeSign); + + if ($hash->length == 0) { + return ''; + } + + return $hash->item(0)->nodeValue; + } +} \ No newline at end of file diff --git a/tests/Report/HtmlReportTest.php b/tests/Report/HtmlReportTest.php index e398b61..a0babb2 100644 --- a/tests/Report/HtmlReportTest.php +++ b/tests/Report/HtmlReportTest.php @@ -9,6 +9,8 @@ namespace Tests\Greenter\Report; use Greenter\Model\Client\Client; +use Greenter\Model\Company\Address; +use Greenter\Model\Company\Company; use Greenter\Model\Sale\Invoice; use Greenter\Model\Sale\Legend; use Greenter\Model\Sale\SaleDetail; @@ -31,6 +33,7 @@ public function testGenReport() $html = $report->build($inv, $this->getParamters()); $this->assertNotEmpty($html); + // file_put_contents('file.html', $html); } @@ -63,6 +66,12 @@ private function getInvoice() ->setSumDsctoGlobal(12) ->setMtoDescuentos(23) ->setPerception($perc) + ->setCompany((new Company()) + ->setRuc('20123456789') + ->setNombreComercial('EMPRESA') + ->setRazonSocial('EMPRESA S.A.C') + ->setAddress((new Address()) + ->setDireccion('AV ITALIA 232 - LIMA - LIMA - PERU'))) ->setTipoDoc('01') ->setSerie('F001') ->setCorrelativo('123') diff --git a/tests/Report/XmlUtilsTest.php b/tests/Report/XmlUtilsTest.php new file mode 100644 index 0000000..01c94a8 --- /dev/null +++ b/tests/Report/XmlUtilsTest.php @@ -0,0 +1,40 @@ +assertNotEmpty($hash); + echo basename($filename) . ' => ' . $hash . PHP_EOL; + } + + public function xmlPathProvider() + { + $dir = __DIR__.'/../Resources'; + return [ + [$dir.'/20505310072-01-F001-00019772.xml'], + [$dir.'/20505310072-03-B001-00000088.xml'], + ]; + } +} \ No newline at end of file diff --git a/tests/Resources/20505310072-01-F001-00019772.xml b/tests/Resources/20505310072-01-F001-00019772.xml new file mode 100644 index 0000000..1e0f3fa --- /dev/null +++ b/tests/Resources/20505310072-01-F001-00019772.xml @@ -0,0 +1,199 @@ + + + + + + + + 1001 + 22.88 + + + 1000 + VEINTISIETE CON 00/100 + + + + + + + + + + + + + + + + QopX8PilAQ07gETkbx8SN5NFvng= + + + hL713ARxmxQnzSZyTGi/NzpS80j6MqlUTRQUofca7mYTSQO74SDFJkKOGSZAPTS4LN0/g1wH+oOQ + O/nj8VuOLMI1ZvbZmt7ZoOT0ueghazdPb4zQZ4vw/+UFjEkdZOdvGyWvUS8LQm4YyTCPR5DILaDZ + 5OuowUdiRahVyZ2vEThoRANBw9JetRwXUP7crKQi+EtKZ/WK9Ek4ZtV3dL41JeCahsYPCiRGm6// + l85rR2n0gQ88dmnNioTwyyOp7gleUCxU/0UhXQz/iSjB6GygdnGGKyUdY1vhnlmPQzT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PuLmc3x9lC7f02FWKIvjAVPEXR3eSvu+QylDTJ/iUg1fB+YzBKJ7a6kOVefxNZyTAVcKv+ + bJUv2t4axpJdWDZ1sL4z7VBf/7Fk09iPKT4ZaI+7pShGrbCl1CXWb1SPnNrqJVJ6aDaDe8DCZuFt + Nn1GYuYtzdeTI6JP3byzZMaYrM6sCi8En3fvQ5PniL+jsDs0cfCvc9jk + + + + + + + 2.0 + 1.0 + F001-00019772 + 2016-10-14 + 01 + PEN + + IDSignSP + + + 20505310072 + + + MANGUIFAJAS INDUSTRIALES + + + + + #SignatureSP + + + + + 20505310072 + 6 + + + MANGUIFAJAS INDUSTRIALES + + + 150133 + AV. PANAMERICANA SUR MZA. P1 LOTE. 23 COO. + VIVIENDA AMERICA + LIMA + LIMA + SAN JUAN DE MIRAFLOR + + PE + + + + MANGUIFAJAS INDUSTRIALES S.A.C. + + + + + 20535773425 + 6 + + + ACORSA SOCIEDAD ANONIMA CERRADA - ACORSA S.A.C. + + + + + 4.12 + + 4.12 + + + 1000 + IGV + VAT + + + + + + 27.00 + + + 1 + 3.000 + 12.71 + + + 5.00 + 01 + + + + 2.29 + + 2.29 + + 10 + + 1000 + IGV + VAT + + + + + + AJUARES ABEJITAS MOL BLANCO 1 + + N001-PE000023775 + + + + 4.24 + + + + 2 + 2.000 + 10.17 + + + 6.00 + 01 + + + + 1.83 + + 1.83 + + 10 + + 1000 + IGV + VAT + + + + + + AJUARES ABEJITAS MOL BLANCO 2 + + N001-PE000023776 + + + + 5.08 + + + \ No newline at end of file diff --git a/tests/Resources/20505310072-03-B001-00000088.xml b/tests/Resources/20505310072-03-B001-00000088.xml new file mode 100644 index 0000000..94327b4 --- /dev/null +++ b/tests/Resources/20505310072-03-B001-00000088.xml @@ -0,0 +1,218 @@ + + + + + + + + 1001 + 107.03 + + + 1003 + 6.90 + + + 1000 + CIENTO TREINTA Y TRES CON 20/100 + + + + + + + + + + + + + + + + e8VEaQJV403wQ6SHYaC+F62NO8c= + + + VBlJa4E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A1UECxMcRE5JIDQyODE5OTU3IFJVQyAyMDYwMDY5NTc3MTEZMBcGA1UEAxMQR0lBTkNBUkxPUyBTQUxBU4IQJbrTqETg571KUM7MXSMZIDAJBgUrDgMCHQUAA4IBAQAmvUJBz4PvvQUZ8Q8h/hgxMjZl1oRSOA9syO34F64YnyVL8XVRyy7CQtLbZqTQFuPefElj7em1mOfZHpQaUw1ScjTlEnHXwHNW6IC9sOInUy6DekPh4RESpVidWscuq9uR+8evCouEFkPuLmc3x9lC7f02FWKIvjAVPEXR3eSvu+QylDTJ/iUg1fB+YzBKJ7a6kOVefxNZyTAVcKv+bJUv2t4axpJdWDZ1sL4z7VBf/7Fk09iPKT4ZaI+7pShGrbCl1CXWb1SPnNrqJVJ6aDaDe8DCZuFtNn1GYuYtzdeTI6JP3byzZMaYrM6sCi8En3fvQ5PniL+jsDs0cfCvc9jk + + + + + + + 2.0 + 1.0 + B001-00000088 + 2016-10-14 + 03 + PEN + + IDSignSP + + + 20505310072 + + + MANGUIFAJAS INDUSTRIALES + + + + + #SignatureSP + + + + + 20505310072 + 6 + + + MANGUIFAJAS INDUSTRIALES + + + 150133 + AV. PANAMERICANA SUR MZA. P1 LOTE. 23 COO. + VIVIENDA AMERICA + LIMA + LIMA + SAN JUAN DE MIRAFLOR + + PE + + + + MANGUIFAJAS INDUSTRIALES S.A.C. + + + + + 41992544 + 1 + + + APAZA MAMANI GUILLERMO + + + + + 19.27 + + 19.27 + + + 1000 + IGV + VAT + + + + + + 133.20 + + + 1 + 9.000 + 73.98 + + + 9.70 + 01 + + + + 13.32 + + 13.32 + + 10 + + 1000 + IGV + VAT + + + + + + AJUARES ABEJITAS MOL BLANCO 0 + + N001-PE000023774 + + + + 8.22 + + + + 2 + 6.000 + 33.05 + + + 6.50 + 01 + + + + 5.95 + + 5.95 + + 10 + + 1000 + IGV + VAT + + + + + + AJUARES ABEJITAS MOL BLANCO 1 + + N001-PE000023775 + + + + 5.51 + + + + 3 + 3.000 + 6.90 + + + 2.30 + 01 + + + + 0.00 + + 0.00 + + 20 + + 1000 + IGV + VAT + + + + + + AJUARES ABEJITAS MOL BLANCO 2 + + N001-PE000023776 + + + + 2.30 + + + \ No newline at end of file diff --git a/tests/Resources/qrcode.png b/tests/Resources/qrcode.png index 8db466d1d5eb72894027b7959682a58f801f45ed..17249cde1fdd11c1e82ee297f4d0337e62c943de 100644 GIT binary patch delta 486 zcmVotQK2{>J$Kzo3{z#5tlMS^^<7Mr``=Z6gEGIwl z_Rl%EADAUEKK#n~U8_yw?&&yJe*@d>d-XE7}@Q$6SIg#)8Z(bc)w%c73I43m`L%G9nbQkDuzLfQ7kpo z3=Q{K)TG52gJU_XBhReakhB!1d-U2h?C`-<#=SDdLX0R|c0TLU`uG(>*5Yto#M}5R zbgjim=itchQ-3>cX5_^{|9RHPUKt@`kde;Ba&ZWB^Gb0tSq%(&6=yF&94$)Jzgbv7e7734T5Bw;+{ISEdL56HbK75!q-9%YD$tzD6dD9Di!4V@D==c6J4Nkr|Ck z#G0&~F@)%bs|=XDD1TR{FRmU$auRoI>fo)mJdtbO)Qx- zy`9Z;SraV`n|X=ZV0=?%yYN7qT8}l-WbC}Ji6(B1Mf%!R20dJxsjpL)og|$5w-#=P zg}7yMG}8fCwo$lm+ecpe2BVJwVS2;eu&?Fq;qQ4M78!6