Finish command to compute expiration date for existing warranties. #280
This commit is contained in:
parent
6daba0d305
commit
243d238ad7
3 changed files with 53 additions and 26 deletions
|
|
@ -10,6 +10,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Doctrine\Common\Persistence\ObjectManager;
|
use Doctrine\Common\Persistence\ObjectManager;
|
||||||
|
|
||||||
use App\Entity\Warranty;
|
use App\Entity\Warranty;
|
||||||
|
use App\Entity\Battery;
|
||||||
|
|
||||||
use App\Ramcar\WarrantyClass;
|
use App\Ramcar\WarrantyClass;
|
||||||
|
|
||||||
|
|
@ -31,7 +32,7 @@ class ComputeWarrantyExpiryDateCommand extends Command
|
||||||
{
|
{
|
||||||
$this->setName('warranty:computeexpirydate')
|
$this->setName('warranty:computeexpirydate')
|
||||||
->setDescription('Compute expiry date for existing warranties.')
|
->setDescription('Compute expiry date for existing warranties.')
|
||||||
->setHelp('Comput expiry date for existing warranties.');
|
->setHelp('Compute expiry date for existing warranties.');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
|
|
@ -50,9 +51,18 @@ class ComputeWarrantyExpiryDateCommand extends Command
|
||||||
if ($warr_period != null)
|
if ($warr_period != null)
|
||||||
{
|
{
|
||||||
$expiry_date = $this->computeDateExpire($date_purchase, $warr_period);
|
$expiry_date = $this->computeDateExpire($date_purchase, $warr_period);
|
||||||
|
|
||||||
// save expiry date
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$expiry_date = $date_purchase;
|
||||||
|
}
|
||||||
|
|
||||||
|
// save expiry date
|
||||||
|
$warr->setDateExpire($expiry_date);
|
||||||
|
|
||||||
|
$this->em->persist($warr);
|
||||||
|
$this->em->flush();
|
||||||
|
$this->em->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -60,38 +70,53 @@ class ComputeWarrantyExpiryDateCommand extends Command
|
||||||
protected function getWarrantyPeriod($warr)
|
protected function getWarrantyPeriod($warr)
|
||||||
{
|
{
|
||||||
$batt_model = $warr->getBatteryModel();
|
$batt_model = $warr->getBatteryModel();
|
||||||
|
$batt_size = $warr->getBatterySize();
|
||||||
|
|
||||||
$warranty_class = $warr->getWarrantyClass();
|
$warranty_class = $warr->getWarrantyClass();
|
||||||
$warr_period = '';
|
$warr_period = 0;
|
||||||
|
|
||||||
if (($batt_model == null) ||
|
|
||||||
(empty($warranty_class)))
|
|
||||||
|
|
||||||
|
if ($batt_model == null)
|
||||||
{
|
{
|
||||||
|
error_log('Battery model is null for warranty id ' . $warr->getID());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ($batt_size == null)
|
||||||
|
{
|
||||||
|
error_log('Battery size is null for warranty id ' . $warr->getID());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (empty($warranty_class))
|
||||||
|
{
|
||||||
|
error_log('Warranty class is empty for warranty id ' . $warr->getID());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($batt_model != null)
|
// find batttery using model and size
|
||||||
|
$batteries = $this->em->getRepository(Battery::class)->findBy(['model' => $batt_model, 'size' => $batt_size]);
|
||||||
|
|
||||||
|
if (empty($batteries))
|
||||||
{
|
{
|
||||||
$batteries = $batt_model->getBatteries();
|
error_log('Battery not found for warranty id ' . $warr->getID());
|
||||||
foreach($batteries as $battery)
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($batteries as $battery)
|
||||||
|
{
|
||||||
|
// check warranty class to get warranty period
|
||||||
|
if ($warranty_class == WarrantyClass::WTY_PRIVATE)
|
||||||
{
|
{
|
||||||
// check warranty class to get warranty period
|
$warr_period = $battery->getWarrantyPrivate();
|
||||||
if ($warranty_class == WarrantyClass::WTY_PRIVATE)
|
error_log('Warranty Period for Private: ' . $warr_period);
|
||||||
{
|
}
|
||||||
$warr_period = $battery->getWarrantyPrivate();
|
if ($warranty_class == WarrantyClass::WTY_COMMERCIAL)
|
||||||
error_log('Warranty Period for Private: ' . $warr_period);
|
{
|
||||||
}
|
$warr_period = $battery->getWarrantyCommercial();
|
||||||
if ($warranty_class == WarrantyClass::WTY_COMMERCIAL)
|
error_log('Warranty Period for Commercial: ' . $warr_period);
|
||||||
{
|
}
|
||||||
$warr_period = $battery->getWarrantyCommercial();
|
if ($warranty_class == WarrantyClass::WTY_TNV)
|
||||||
error_log('Warranty Period for Commercial: ' . $warr_period);
|
{
|
||||||
}
|
$warr_period = $battery->getWarrantyTnv();
|
||||||
if ($warranty_class == WarrantyClass::WTY_TNV)
|
error_log('Warranty Period for TNV: ' . $warr_period);
|
||||||
{
|
|
||||||
$warr_period = $battery->getWarrantyTnv();
|
|
||||||
error_log('Warranty Period for TNV: ' . $warr_period);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ class BatteryModel
|
||||||
|
|
||||||
public function getBatteries()
|
public function getBatteries()
|
||||||
{
|
{
|
||||||
|
// TODO: fix this to be a proper getter function
|
||||||
// has to return set of strings because symfony is trying to move away from role objects
|
// has to return set of strings because symfony is trying to move away from role objects
|
||||||
$str_batteries = [];
|
$str_batteries = [];
|
||||||
foreach ($this->batteries as $battery)
|
foreach ($this->batteries as $battery)
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ class BatterySize
|
||||||
|
|
||||||
public function getBatteries()
|
public function getBatteries()
|
||||||
{
|
{
|
||||||
|
// TODO: fix this to be a proper getter function
|
||||||
// has to return set of strings because symfony is trying to move away from role objects
|
// has to return set of strings because symfony is trying to move away from role objects
|
||||||
$str_batteries = [];
|
$str_batteries = [];
|
||||||
foreach ($this->batteries as $battery)
|
foreach ($this->batteries as $battery)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue