2023-11-25 00:56:18 -03:00
|
|
|
<?php
|
|
|
|
namespace Incoviba\Command\Money;
|
|
|
|
|
|
|
|
use DateTimeImmutable;
|
2025-05-16 14:44:48 -04:00
|
|
|
use DateTimeZone;
|
2023-11-25 00:56:18 -03:00
|
|
|
use Symfony\Component\Console;
|
2023-11-25 21:38:00 -03:00
|
|
|
use Incoviba\Common\Alias\Command;
|
2023-11-25 00:56:18 -03:00
|
|
|
|
|
|
|
#[Console\Attribute\AsCommand(
|
2024-08-27 14:51:06 -04:00
|
|
|
name: 'money:uf',
|
|
|
|
description: 'Get the UF value for today'
|
2023-11-25 00:56:18 -03:00
|
|
|
)]
|
2023-11-25 21:38:00 -03:00
|
|
|
class UF extends Command
|
2023-11-25 00:56:18 -03:00
|
|
|
{
|
2025-05-12 18:07:14 -04:00
|
|
|
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
|
2023-11-25 00:56:18 -03:00
|
|
|
{
|
2023-11-25 21:38:00 -03:00
|
|
|
$this->logger->debug("Running {$this->getName()}");
|
2025-05-16 14:44:48 -04:00
|
|
|
$now = new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago'));
|
2023-11-29 20:09:08 -03:00
|
|
|
$uri = '/api/money/uf';
|
2023-11-25 00:56:18 -03:00
|
|
|
$data = [
|
|
|
|
'fecha' => $now->format('Y-m-d')
|
|
|
|
];
|
|
|
|
$output->writeln("POST {$uri}");
|
|
|
|
$response = $this->client->post($uri, [
|
|
|
|
'body' => http_build_query($data),
|
|
|
|
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded']
|
|
|
|
]);
|
|
|
|
$output->writeln("Response Code: {$response->getStatusCode()}");
|
|
|
|
return Console\Command\Command::SUCCESS;
|
|
|
|
}
|
|
|
|
}
|