Move updating of warranty to handler. #286

This commit is contained in:
Korina Cordero 2019-12-17 01:05:55 +00:00
parent a02c364c1f
commit 0d3a96e038
2 changed files with 13 additions and 77 deletions

View file

@ -11,6 +11,8 @@ use App\Entity\BatterySize;
use App\Ramcar\WarrantyClass;
use App\Ramcar\WarrantyStatus;
use App\Service\WarrantyHandler;
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
@ -372,13 +374,14 @@ class WarrantyController extends Controller
/**
* @Menu(selected="warranty_list")
*/
public function uploadSubmit(Request $req, EntityManagerInterface $em)
public function uploadSubmit(Request $req, EntityManagerInterface $em,
WarrantyHandler $wh)
{
// retrieve temporary info for file
$file = $req->files->get('csv_file');
// process the csv file
$inv_entries = $this->processWarrantyFile($file, $em);
$inv_entries = $this->processWarrantyFile($file, $em, $wh);
$resp = new StreamedResponse();
$resp->setCallback(function() use($inv_entries) {
@ -422,7 +425,8 @@ class WarrantyController extends Controller
return $resp;
}
protected function processWarrantyFile(UploadedFile $csv_file, EntityManagerInterface $em)
protected function processWarrantyFile(UploadedFile $csv_file, EntityManagerInterface $em,
WarrantyHandler $wh)
{
// attempt to open file
try
@ -530,77 +534,9 @@ class WarrantyController extends Controller
{
foreach($warr_results as $warr)
{
// check if details are complete
//error_log('Updating warranty with serial number ' . $serial . ' and plate number ' . $plate_number);
if (empty($warr->getFirstName()))
{
if (!empty($first_name))
{
$warr->setFirstName($first_name);
}
}
if (empty($warr->getLastName()))
{
if (!empty($last_name))
{
$warr->setLastName($last_name);
}
}
if (empty($warr->getMobileNumber()))
{
if (!empty($mobile_number))
{
$warr->setMobileNumber($mobile_number);
}
}
if ((empty($warr->getBatteryModel())) ||
(empty($warr->getBatterySize())))
{
if (!empty($battery_id))
{
// find battery
$battery = $em->getRepository(Battery::class)->find($battery_id);
if (!empty($battery))
{
// get the battery model and battery size
$model_id = $battery->getModel()->getID();
$size_id = $battery->getSize()->getID();
$bty_model = $em->getRepository(BatteryModel::class)->find($model_id);
$bty_size = $em->getRepository(BatterySize::class)->find($size_id);
if ($bty_model != null)
{
$warr->setBatteryModel($bty_model);
}
if ($bty_size != null)
{
$warr->setBatterySize($bty_size);
}
$sap_code = $battery->getSAPCode();
if (!empty($sap_code))
{
// find sap battery
$sap_batt = $em->getRepository(SAPBattery::class)->find($sap_code);
if (!empty($sap_batt))
{
$warr->setSAPBattery($sap_batt);
}
}
}
}
}
if (empty($warr->getDatePurchase()))
{
if (!empty($date_purchase))
{
$warr->setDatePurchase($date_purchase);
}
}
// TODO: compute expiry date
$em->persist($warr);
$em->flush();
// call service to check if warranty details is incomplete and then update warranty
// using details from csv file
$wh->updateWarranty($warr, $first_name, $last_name, $mobile_number, $battery_id, $date_purchase);
}
}
else

View file

@ -179,17 +179,17 @@ class WarrantyHandler
if ($warranty_class == WarrantyClass::WTY_PRIVATE)
{
$warr_period = $battery->getWarrantyPrivate();
error_log('Warranty Period for Private: ' . $warr_period);
//error_log('Warranty Period for Private: ' . $warr_period);
}
if ($warranty_class == WarrantyClass::WTY_COMMERCIAL)
{
$warr_period = $battery->getWarrantyCommercial();
error_log('Warranty Period for Commercial: ' . $warr_period);
//error_log('Warranty Period for Commercial: ' . $warr_period);
}
if ($warranty_class == WarrantyClass::WTY_TNV)
{
$warr_period = $battery->getWarrantyTnv();
error_log('Warranty Period for TNV: ' . $warr_period);
//error_log('Warranty Period for TNV: ' . $warr_period);
}
if ($least_warranty < 0)