Merge pull request 'FIX: Skip handling import errors' (#49) from fix/add-venta into develop
Reviewed-on: #49
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
namespace Incoviba\Common\Define\Cartola;
|
namespace Incoviba\Common\Define\Cartola;
|
||||||
|
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
use Incoviba\Exception\ServiceAction\Read;
|
||||||
|
|
||||||
interface Banco
|
interface Banco
|
||||||
{
|
{
|
||||||
@ -9,6 +10,7 @@ interface Banco
|
|||||||
* Process bank movements for database inserts
|
* Process bank movements for database inserts
|
||||||
* @param UploadedFileInterface $file
|
* @param UploadedFileInterface $file
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws Read
|
||||||
*/
|
*/
|
||||||
public function process(UploadedFileInterface $file): array;
|
public function process(UploadedFileInterface $file): array;
|
||||||
|
|
||||||
|
@ -3,10 +3,16 @@ namespace Incoviba\Common\Ideal\Cartola;
|
|||||||
|
|
||||||
use Incoviba\Common\Define;
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Common\Ideal\Service;
|
use Incoviba\Common\Ideal\Service;
|
||||||
|
use Incoviba\Exception\ServiceAction\Read;
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
|
||||||
abstract class Banco extends Service implements Define\Cartola\Banco
|
abstract class Banco extends Service implements Define\Cartola\Banco
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param UploadedFileInterface $file
|
||||||
|
* @return array
|
||||||
|
* @throws Read
|
||||||
|
*/
|
||||||
public function process(UploadedFileInterface $file): array
|
public function process(UploadedFileInterface $file): array
|
||||||
{
|
{
|
||||||
$filename = $this->processUploadedFile($file);
|
$filename = $this->processUploadedFile($file);
|
||||||
@ -40,6 +46,7 @@ abstract class Banco extends Service implements Define\Cartola\Banco
|
|||||||
* Process the temp file from getFilename and remove it
|
* Process the temp file from getFilename and remove it
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws Read
|
||||||
*/
|
*/
|
||||||
protected function processFile(string $filename): array
|
protected function processFile(string $filename): array
|
||||||
{
|
{
|
||||||
@ -88,6 +95,7 @@ abstract class Banco extends Service implements Define\Cartola\Banco
|
|||||||
* Translate uploaded file data to database data
|
* Translate uploaded file data to database data
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @return array
|
* @return array
|
||||||
|
* @throws Read
|
||||||
*/
|
*/
|
||||||
abstract protected function parseFile(string $filename): array;
|
abstract protected function parseFile(string $filename): array;
|
||||||
}
|
}
|
||||||
|
@ -338,6 +338,7 @@
|
|||||||
data.errors.forEach(errorData => {
|
data.errors.forEach(errorData => {
|
||||||
console.error(errorData)
|
console.error(errorData)
|
||||||
})
|
})
|
||||||
|
throw Error('Error al importar cartolas')
|
||||||
}
|
}
|
||||||
this.data.movimientos = data.movimientos.map(movimiento => new Movimiento(movimiento))
|
this.data.movimientos = data.movimientos.map(movimiento => new Movimiento(movimiento))
|
||||||
this.draw().movimientos()
|
this.draw().movimientos()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
namespace Incoviba\Controller\API\Contabilidad;
|
namespace Incoviba\Controller\API\Contabilidad;
|
||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
|
use Incoviba\Exception\ServiceAction\Read;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Incoviba\Common\Ideal\Controller;
|
use Incoviba\Common\Ideal\Controller;
|
||||||
@ -128,7 +129,11 @@ class Cartolas extends Controller
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$output['movimientos'] = array_merge($output['movimientos'], $cartolaService->import($body['cuenta_id'][$i], $file));
|
$output['movimientos'] = array_merge($output['movimientos'], $cartolaService->import($body['cuenta_id'][$i], $file));
|
||||||
} catch (EmptyResult) {}
|
} catch (Read $exception) {
|
||||||
|
$output['errors'] []= ['filename' => $file->getClientFilename(),
|
||||||
|
'error' => ['message' => $exception->getMessage(), 'file' => $exception->getFile(),
|
||||||
|
'line' => $exception->getLine()]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $this->withJson($response, $output);
|
return $this->withJson($response, $output);
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,18 @@
|
|||||||
namespace Incoviba\Service\Contabilidad;
|
namespace Incoviba\Service\Contabilidad;
|
||||||
|
|
||||||
use DateMalformedStringException;
|
use DateMalformedStringException;
|
||||||
use Incoviba\Exception\ServiceAction\Read;
|
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Psr\Http\Message\StreamFactoryInterface;
|
use Psr\Http\Message\StreamFactoryInterface;
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use PhpOffice\PhpSpreadsheet;
|
||||||
use Incoviba\Common\Define\Cartola\Banco;
|
use Incoviba\Common\Define\Cartola\Banco;
|
||||||
use Incoviba\Common\Define\Contabilidad\Exporter;
|
use Incoviba\Common\Define\Contabilidad\Exporter;
|
||||||
use Incoviba\Common\Ideal\Service;
|
use Incoviba\Common\Ideal\Service;
|
||||||
use Incoviba\Common\Implement\Exception;
|
use Incoviba\Common\Implement\Exception;
|
||||||
|
use Incoviba\Exception\ServiceAction\Read;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
|
|
||||||
@ -34,6 +35,13 @@ class Cartola extends Service
|
|||||||
$this->bancos[$name] = $banco;
|
$this->bancos[$name] = $banco;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Model\Contabilidad\Banco $banco
|
||||||
|
* @param UploadedFileInterface $file
|
||||||
|
* @return array
|
||||||
|
* @throws Read
|
||||||
|
*/
|
||||||
public function process(Model\Contabilidad\Banco $banco, UploadedFileInterface $file): array
|
public function process(Model\Contabilidad\Banco $banco, UploadedFileInterface $file): array
|
||||||
{
|
{
|
||||||
return $this->bancos[strtolower($banco->nombre)]->process($file);
|
return $this->bancos[strtolower($banco->nombre)]->process($file);
|
||||||
@ -153,6 +161,10 @@ class Cartola extends Service
|
|||||||
$fechas = array_unique(array_map(function($movimiento) {
|
$fechas = array_unique(array_map(function($movimiento) {
|
||||||
return $movimiento['fecha']->format('Y-m-d');
|
return $movimiento['fecha']->format('Y-m-d');
|
||||||
}, $movimientos));
|
}, $movimientos));
|
||||||
|
if (count($fechas) === 0) {
|
||||||
|
throw new Read(__CLASS__);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($fechas as $dia) {
|
foreach ($fechas as $dia) {
|
||||||
try {
|
try {
|
||||||
$dayDate = new DateTimeImmutable($dia);
|
$dayDate = new DateTimeImmutable($dia);
|
||||||
|
@ -3,6 +3,7 @@ namespace Incoviba\Service\Contabilidad\Cartola;
|
|||||||
|
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Incoviba\Common\Ideal\Cartola\Banco;
|
use Incoviba\Common\Ideal\Cartola\Banco;
|
||||||
|
use Incoviba\Exception\ServiceAction\Read;
|
||||||
use PhpOffice\PhpSpreadsheet;
|
use PhpOffice\PhpSpreadsheet;
|
||||||
use Psr\Http\Message\UploadedFileInterface;
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
|
||||||
@ -44,6 +45,12 @@ class Itau extends Banco
|
|||||||
$ext = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION);
|
$ext = pathinfo($uploadedFile->getClientFilename(), PATHINFO_EXTENSION);
|
||||||
return "/tmp/cartola.{$ext}";
|
return "/tmp/cartola.{$ext}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filename
|
||||||
|
* @return array
|
||||||
|
* @throws Read
|
||||||
|
*/
|
||||||
protected function parseFile(string $filename): array
|
protected function parseFile(string $filename): array
|
||||||
{
|
{
|
||||||
$ext = pathinfo($filename, PATHINFO_EXTENSION);
|
$ext = pathinfo($filename, PATHINFO_EXTENSION);
|
||||||
@ -62,7 +69,7 @@ class Itau extends Banco
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (PhpSpreadsheet\Exception $exception) {
|
} catch (PhpSpreadsheet\Exception $exception) {
|
||||||
$this->logger->critical($exception);
|
throw new Read(__CLASS__, $exception);
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
@ -166,6 +173,11 @@ class Itau extends Banco
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PhpSpreadsheet\Worksheet\Worksheet $sheet
|
||||||
|
* @return int
|
||||||
|
* @throws PhpSpreadsheet\Exception
|
||||||
|
*/
|
||||||
protected function identifySheet(PhpSpreadsheet\Worksheet\Worksheet $sheet): int
|
protected function identifySheet(PhpSpreadsheet\Worksheet\Worksheet $sheet): int
|
||||||
{
|
{
|
||||||
foreach ($sheet->getRowIterator(1, 10) as $row) {
|
foreach ($sheet->getRowIterator(1, 10) as $row) {
|
||||||
@ -177,7 +189,7 @@ class Itau extends Banco
|
|||||||
return self::ULTIMOS_MOVIMIENTOS;
|
return self::ULTIMOS_MOVIMIENTOS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new PhpSpreadsheet\Exception();
|
throw new PhpSpreadsheet\Exception('Incorrect type of Worksheet');
|
||||||
}
|
}
|
||||||
protected function getDateRange(PhpSpreadsheet\Worksheet\Row $row): array
|
protected function getDateRange(PhpSpreadsheet\Worksheet\Row $row): array
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user