Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mpysiak committed Jun 27, 2024
1 parent 9019631 commit ab3141b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/vendor
/var/cache/
/var/logs/
/var/data/*.sqlite
!/var/data/.gitkeep
/var
/composer.lock
/.phpunit.cache
12 changes: 7 additions & 5 deletions src/Command/GmvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
use Sylius\GmvBundle\Validator\InputParametersValidatorInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressIndicator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Webmozart\Assert\Assert;

#[AsCommand(
name: 'sylius:gmv:calculate',
Expand Down Expand Up @@ -61,20 +61,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$periodStart = $input->getArgument('periodStart');
$periodEnd = $input->getArgument('periodEnd');

Assert::string($periodStart);
Assert::string($periodEnd);

if (!$this->validator->validate($periodStart, $periodEnd)) {
if (!is_string($periodStart) || !is_string($periodEnd) || !$this->validator->validate($periodStart, $periodEnd)) {
$output->writeln('<error>Invalid format or start date must be less than end date. Please use MM/YYYY.</error>');

return Command::FAILURE;
}

$progressIndicator = new ProgressIndicator($output);
$progressIndicator->start('Calculating GMV...');

$startDate = $this->dateParser->parseStartOfMonth($periodStart);
$endDate = $this->dateParser->parseEndOfMonth($periodEnd);

$gmvs = $this->gmvProvider->getGmvForPeriod($startDate, $endDate);

$progressIndicator->finish('Finished!');

$output->writeln('<info>GMV Calculation</info>');
$output->writeln(sprintf('<comment>Period Start:</comment> %s', $startDate->format('Y-m-d')));
$output->writeln(sprintf('<comment>Period End:</comment> %s', $endDate->format('Y-m-d')));
Expand Down
6 changes: 3 additions & 3 deletions src/Provider/GmvProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ private function calculateGmvForPeriodAndCurrency(\DateTimeInterface $periodStar
$queryBuilder->andWhere('o.currencyCode = :currencyCode')
->setParameter('currencyCode', $currencyCode);

$totalItemsQuery = (int) $queryBuilder
$totalItems = (int) $queryBuilder
->select('SUM(o.itemsTotal) as totalItems')
->getQuery()
->getSingleScalarResult();

$totalTaxQuery = (int) $queryBuilder
$totalTax = (int) $queryBuilder
->select('SUM(adjustment.amount) as totalTaxes')
->leftJoin('o.items', 'items')
->leftJoin('items.units', 'units')
Expand All @@ -81,7 +81,7 @@ private function calculateGmvForPeriodAndCurrency(\DateTimeInterface $periodStar
->getQuery()
->getSingleScalarResult();

return $totalItemsQuery - $totalTaxQuery;
return $totalItems - $totalTax;
}

private function createCommonQueryBuilder(\DateTimeInterface $periodStart, \DateTimeInterface $periodEnd): QueryBuilder
Expand Down
2 changes: 1 addition & 1 deletion tests/Application/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ framework:
doctrine:
dbal:
driver: pdo_sqlite
path: '%kernel.project_dir%/var/data/test.sqlite'
path: '%kernel.project_dir%/var/test.sqlite'

0 comments on commit ab3141b

Please sign in to comment.