From 43f65f285673a54590028f161b0c068cdcb93c2e Mon Sep 17 00:00:00 2001 From: Carlos C Soto Date: Thu, 4 Oct 2018 21:53:25 -0500 Subject: [PATCH] Version 2.6.6 This is a bugfix from 2.6.5 --- docs/CHANGELOG.md | 6 +++ .../MontoBetweenIntervalSumOfDocuments.php | 6 ++- ...MontoBetweenIntervalSumOfDocumentsTest.php | 47 ++++++++++++++++++- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fbe85724..8857a0b3 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -12,6 +12,12 @@ - Remove `trigger_error` on `\CfdiUtils\Elements\Cfdi33\Comprobante::getCfdiRelacionados` when called with arguments. +## Version 2.6.6 2018-10-04 + +- After previous update on validation `PAGO09` and more testing found that it requires to round lower and upper limits. +- Create more 1 case with specific data and 1 test with 20 cases with random data. + + ## Version 2.6.5 2018-10-04 - Fix validation `PAGO09`: diff --git a/src/CfdiUtils/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocuments.php b/src/CfdiUtils/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocuments.php index 0a1d86ec..94d2beb0 100644 --- a/src/CfdiUtils/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocuments.php +++ b/src/CfdiUtils/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocuments.php @@ -2,6 +2,7 @@ namespace CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos; use CfdiUtils\Nodes\NodeInterface; +use CfdiUtils\Utils\CurrencyDecimals; use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Helpers\CalculateDocumentAmountTrait; /** @@ -20,8 +21,9 @@ public function validatePago(NodeInterface $pago): bool { $pagoAmount = floatval($pago['Monto']); $bounds = $this->calculateDocumentsAmountBounds($pago); - $lower = $bounds['lower']; - $upper = $bounds['upper']; + $currencyDecimals = CurrencyDecimals::newFromKnownCurrencies($pago['MonedaP'], 2); + $lower = $currencyDecimals->round($bounds['lower']); + $upper = $currencyDecimals->round($bounds['upper']); if ($pagoAmount < $lower || $pagoAmount > $upper) { throw new ValidatePagoException( sprintf('Monto del pago: "%s", Suma mínima: "%s", Suma máxima: "%s"', $pagoAmount, $lower, $upper) diff --git a/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocumentsTest.php b/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocumentsTest.php index ec023a86..1db308d2 100644 --- a/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocumentsTest.php +++ b/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocumentsTest.php @@ -27,8 +27,8 @@ public function testValid() /** * This is testing lower bound (122.94) and upper bound (123.97) * @param string $monto - * @testWith ["122.94"] - * ["123.97"] + * @testWith ["122.93"] + * ["123.98"] */ public function testInvalids(string $monto) { @@ -66,4 +66,47 @@ public function testValidWithSeveralDecimals() $validator = new MontoBetweenIntervalSumOfDocuments(); $this->assertTrue($validator->validatePago($pago)); } + + public function testValidWithMultiDocuments() + { + $pago = new Pago([ + 'MonedaP' => 'MXN', + 'Monto' => '21588.07', + ]); + $pago->multiDoctoRelacionado(...[ + ['MonedaDR' => 'MXN', 'ImpPagado' => '6826.60'], + ['MonedaDR' => 'MXN', 'ImpPagado' => '2114.52'], + ['MonedaDR' => 'MXN', 'ImpPagado' => '11245.04'], + ['MonedaDR' => 'MXN', 'ImpPagado' => '1401.91'], + ]); + $validator = new MontoBetweenIntervalSumOfDocuments(); + $this->assertTrue($validator->validatePago($pago)); + } + + public function providerValidWithRandomAmounts(): array + { + $randomValues = []; + for ($i = 0; $i < 20; $i++) { + $randomValues[] = [rand(1, 99999999) / 100]; + } + return $randomValues; + } + + /** + * @param float $amount + * @dataProvider providerValidWithRandomAmounts + */ + public function testValidWithRandomAmounts(float $amount) + { + $pago = new Pago([ + 'MonedaP' => 'MXN', + 'Monto' => number_format($amount, 2, '.', ''), + ]); + $pago->multiDoctoRelacionado(...[ + ['MonedaDR' => 'MXN', 'ImpPagado' => number_format(1 * $amount / 3, 2, '.', '')], + ['MonedaDR' => 'MXN', 'ImpPagado' => number_format(2 * $amount / 3, 2, '.', '')], + ]); + $validator = new MontoBetweenIntervalSumOfDocuments(); + $this->assertTrue($validator->validatePago($pago)); + } }