Sub Banco for the Cartola Services
This commit is contained in:
36
app/src/Service/Contabilidad/Cartola/withSubBancos.php
Normal file
36
app/src/Service/Contabilidad/Cartola/withSubBancos.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
namespace Incoviba\Service\Contabilidad\Cartola;
|
||||||
|
|
||||||
|
use Incoviba\Common\Ideal\Cartola\Banco;
|
||||||
|
use Psr\Http\Message\UploadedFileInterface;
|
||||||
|
|
||||||
|
trait withSubBancos
|
||||||
|
{
|
||||||
|
protected array $subBancos;
|
||||||
|
public function registerSub(Banco $sub): self
|
||||||
|
{
|
||||||
|
$this->subBancos []= $sub;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function getSubBanco(string $filename): Banco
|
||||||
|
{
|
||||||
|
foreach ($this->subBancos as $subBanco) {
|
||||||
|
if ($subBanco->is($filename)) {
|
||||||
|
return $subBanco;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
public function process(UploadedFileInterface $file): array
|
||||||
|
{
|
||||||
|
$filename = $this->processUploadedFile($file);
|
||||||
|
try {
|
||||||
|
$subBanco = $this->getSubBanco($filename);
|
||||||
|
$data = $subBanco->processFile($filename);
|
||||||
|
return $subBanco->mapColumns($data);
|
||||||
|
} catch (InvalidArgumentException) {
|
||||||
|
$data = parent::processFile($filename);
|
||||||
|
return $this->mapColumns($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user