Update invoices
This commit is contained in:
@ -4,6 +4,7 @@ namespace Incoviba\Service\Venta\MediosPago\Toku;
|
|||||||
use DateMalformedStringException;
|
use DateMalformedStringException;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateTimeZone;
|
use DateTimeZone;
|
||||||
|
use PDO;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use Psr\Http\Client\ClientInterface;
|
use Psr\Http\Client\ClientInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@ -199,6 +200,41 @@ class Invoice extends AbstractEndPoint
|
|||||||
return $this->pagoService->depositar($invoice->cuota->pago, $date);
|
return $this->pagoService->depositar($invoice->cuota->pago, $date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $idsData
|
||||||
|
* @return array
|
||||||
|
* @throws EmptyResult
|
||||||
|
*/
|
||||||
|
public function updateAll(array $idsData): array
|
||||||
|
{
|
||||||
|
$tokuIds = array_column($idsData, 'toku_id');
|
||||||
|
$oldIds = array_column($idsData, 'product_id');
|
||||||
|
|
||||||
|
$placeholders = array_map(fn($id) => "id{$id}", array_keys($oldIds));
|
||||||
|
$placeholdersString = implode(', ', array_map(fn($id) => ":{$id}", $placeholders));
|
||||||
|
$query = $this->pagoService->getRepository()->getConnection()->getQueryBuilder()
|
||||||
|
->select('pago.id, CONCAT_WS("-", unidad.descripcion, CONCAT_WS("-", propietario.rut, propietario.dv)) AS old_pid')
|
||||||
|
->from('pago')
|
||||||
|
->joined('JOIN cuota ON cuota.pago = pago.id')
|
||||||
|
->joined('JOIN venta ON venta.pie = cuota.pie')
|
||||||
|
->joined('JOIN propietario ON propietario.rut = venta.propietario')
|
||||||
|
->joined('JOIN propiedad_unidad pu ON pu.propiedad = venta.propiedad')
|
||||||
|
->joined('JOIN unidad ON pu.unidad = unidad.id')
|
||||||
|
->having("old_pid IN ({$placeholdersString})");
|
||||||
|
$values = array_combine($placeholders, $oldIds);
|
||||||
|
try {
|
||||||
|
$statement = $this->pagoService->getRepository()->getConnection()->execute($query, $values);
|
||||||
|
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
} catch (PDOException $exception) {
|
||||||
|
$this->logger->error($exception);
|
||||||
|
throw new EmptyResult($query, $exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
$ids = array_column($results, 'pago.id');
|
||||||
|
$newIds = array_combine($ids, $tokuIds);
|
||||||
|
return array_map(fn($id) => ['product_id' => $id, 'toku_id' => $newIds[$id]], $ids);
|
||||||
|
}
|
||||||
|
|
||||||
public function save(array $data): bool
|
public function save(array $data): bool
|
||||||
{
|
{
|
||||||
return $this->doSave($this->invoiceRepository, $data);
|
return $this->doSave($this->invoiceRepository, $data);
|
||||||
@ -215,7 +251,7 @@ class Invoice extends AbstractEndPoint
|
|||||||
{
|
{
|
||||||
$paramsMap = [
|
$paramsMap = [
|
||||||
'customer' => 'customer',
|
'customer' => 'customer',
|
||||||
'product_id' => 'product_id',
|
'product_id' => 'cuota_id',
|
||||||
'due_date' => 'fecha',
|
'due_date' => 'fecha',
|
||||||
'subscription' => 'subscription',
|
'subscription' => 'subscription',
|
||||||
'amount' => 'valor',
|
'amount' => 'valor',
|
||||||
|
@ -4,25 +4,37 @@ namespace Incoviba\Service\Venta;
|
|||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use DateMalformedStringException;
|
use DateMalformedStringException;
|
||||||
|
use Incoviba\Common\Define;
|
||||||
use Incoviba\Exception\ServiceAction\Create;
|
use Incoviba\Exception\ServiceAction\Create;
|
||||||
use Incoviba\Exception\ServiceAction\Read;
|
use Incoviba\Exception\ServiceAction\Read;
|
||||||
use Incoviba\Exception\ServiceAction\Update;
|
use Incoviba\Exception\ServiceAction\Update;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
|
use Incoviba\Common\Ideal;
|
||||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||||
use Incoviba\Repository;
|
use Incoviba\Repository;
|
||||||
use Incoviba\Model;
|
use Incoviba\Model;
|
||||||
use Incoviba\Service;
|
use Incoviba\Service;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Pago
|
class Pago extends Ideal\Service\Repository
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
LoggerInterface $logger,
|
||||||
protected Repository\Venta\Pago $pagoRepository,
|
protected Repository\Venta\Pago $pagoRepository,
|
||||||
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
protected Repository\Venta\EstadoPago $estadoPagoRepository,
|
||||||
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
protected Repository\Venta\TipoEstadoPago $tipoEstadoPagoRepository,
|
||||||
protected Service\UF $ufService,
|
protected Service\UF $ufService,
|
||||||
protected Service\Valor $valorService,
|
protected Service\Valor $valorService,
|
||||||
protected Service\Queue $queueService
|
protected Service\Queue $queueService
|
||||||
) {}
|
)
|
||||||
|
{
|
||||||
|
parent::__construct($logger);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRepository(): Define\Repository
|
||||||
|
{
|
||||||
|
return $this->pagoRepository;
|
||||||
|
}
|
||||||
|
|
||||||
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
public function depositar(Model\Venta\Pago $pago, DateTimeInterface $fecha): bool
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user