Skip to content

Commit 43f65f2

Browse files
committed
Version 2.6.6
This is a bugfix from 2.6.5
1 parent 4f72f00 commit 43f65f2

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

docs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
- Remove `trigger_error` on `\CfdiUtils\Elements\Cfdi33\Comprobante::getCfdiRelacionados` when called with arguments.
1313

1414

15+
## Version 2.6.6 2018-10-04
16+
17+
- After previous update on validation `PAGO09` and more testing found that it requires to round lower and upper limits.
18+
- Create more 1 case with specific data and 1 test with 20 cases with random data.
19+
20+
1521
## Version 2.6.5 2018-10-04
1622

1723
- Fix validation `PAGO09`:

src/CfdiUtils/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocuments.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos;
33

44
use CfdiUtils\Nodes\NodeInterface;
5+
use CfdiUtils\Utils\CurrencyDecimals;
56
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Helpers\CalculateDocumentAmountTrait;
67

78
/**
@@ -20,8 +21,9 @@ public function validatePago(NodeInterface $pago): bool
2021
{
2122
$pagoAmount = floatval($pago['Monto']);
2223
$bounds = $this->calculateDocumentsAmountBounds($pago);
23-
$lower = $bounds['lower'];
24-
$upper = $bounds['upper'];
24+
$currencyDecimals = CurrencyDecimals::newFromKnownCurrencies($pago['MonedaP'], 2);
25+
$lower = $currencyDecimals->round($bounds['lower']);
26+
$upper = $currencyDecimals->round($bounds['upper']);
2527
if ($pagoAmount < $lower || $pagoAmount > $upper) {
2628
throw new ValidatePagoException(
2729
sprintf('Monto del pago: "%s", Suma mínima: "%s", Suma máxima: "%s"', $pagoAmount, $lower, $upper)

tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocumentsTest.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public function testValid()
2727
/**
2828
* This is testing lower bound (122.94) and upper bound (123.97)
2929
* @param string $monto
30-
* @testWith ["122.94"]
31-
* ["123.97"]
30+
* @testWith ["122.93"]
31+
* ["123.98"]
3232
*/
3333
public function testInvalids(string $monto)
3434
{
@@ -66,4 +66,47 @@ public function testValidWithSeveralDecimals()
6666
$validator = new MontoBetweenIntervalSumOfDocuments();
6767
$this->assertTrue($validator->validatePago($pago));
6868
}
69+
70+
public function testValidWithMultiDocuments()
71+
{
72+
$pago = new Pago([
73+
'MonedaP' => 'MXN',
74+
'Monto' => '21588.07',
75+
]);
76+
$pago->multiDoctoRelacionado(...[
77+
['MonedaDR' => 'MXN', 'ImpPagado' => '6826.60'],
78+
['MonedaDR' => 'MXN', 'ImpPagado' => '2114.52'],
79+
['MonedaDR' => 'MXN', 'ImpPagado' => '11245.04'],
80+
['MonedaDR' => 'MXN', 'ImpPagado' => '1401.91'],
81+
]);
82+
$validator = new MontoBetweenIntervalSumOfDocuments();
83+
$this->assertTrue($validator->validatePago($pago));
84+
}
85+
86+
public function providerValidWithRandomAmounts(): array
87+
{
88+
$randomValues = [];
89+
for ($i = 0; $i < 20; $i++) {
90+
$randomValues[] = [rand(1, 99999999) / 100];
91+
}
92+
return $randomValues;
93+
}
94+
95+
/**
96+
* @param float $amount
97+
* @dataProvider providerValidWithRandomAmounts
98+
*/
99+
public function testValidWithRandomAmounts(float $amount)
100+
{
101+
$pago = new Pago([
102+
'MonedaP' => 'MXN',
103+
'Monto' => number_format($amount, 2, '.', ''),
104+
]);
105+
$pago->multiDoctoRelacionado(...[
106+
['MonedaDR' => 'MXN', 'ImpPagado' => number_format(1 * $amount / 3, 2, '.', '')],
107+
['MonedaDR' => 'MXN', 'ImpPagado' => number_format(2 * $amount / 3, 2, '.', '')],
108+
]);
109+
$validator = new MontoBetweenIntervalSumOfDocuments();
110+
$this->assertTrue($validator->validatePago($pago));
111+
}
69112
}

0 commit comments

Comments
 (0)