Skip to content

Commit

Permalink
Version 2.6.6
Browse files Browse the repository at this point in the history
This is a bugfix from 2.6.5
  • Loading branch information
eclipxe13 committed Oct 5, 2018
1 parent 4f72f00 commit 43f65f2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 43f65f2

Please sign in to comment.