Resolve "Add dealer branch_code to Warranty Details Report" #1528

Merged
korina.cordero merged 4 commits from 597-add-dealer-branch_code-to-warranty-details-report into master-fix 2021-07-23 04:17:36 +00:00
Showing only changes of commit bc80cc91ea - Show all commits

View file

@ -0,0 +1,72 @@
<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Warranty;
use App\Entity\Dealer;
class SetWarrantyBranchCodeCommand extends Command
{
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
parent::__construct();
}
protected function configure()
{
$this->setName('warranty:setbranchcode')
->setDescription('Set branch code for warranty, if any.')
->setHelp('Set branch code for warranty, if any.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->em;
// get all warranties with dealer_name
$query = $em->createQuery('select w from App\Entity\Warranty w where w.dealer_name is not null and w.dealer_name != \'\'');
$result = $query->iterate();
foreach ($result as $row)
{
$warranty = $row[0];
// get dealer name, uppercase it since dealer name is saved in uppercase in db
$dealer_name = strtoupper($warranty->getDealerName());
// error_log('warranty dealer name ' . $dealer_name);
// find dealer using name
$dealer_results = $em->getRepository(Dealer::class)->findBy(['name' => $dealer_name]);
foreach ($dealer_results as $dealer)
{
error_log('Setting branch code for warranty with dealer name ' . $dealer->getName());
// get branch code
$branch_code = $dealer->getBranchCode();
// set warranty branch code
$warranty->setDealerBranchCode($branch_code);
$em->flush();
}
$em->detach($row[0]);
}
$em->clear();
return 0;
}
}