diff --git a/src/Command/GenerateBatteryCompatibilityCommand.php b/src/Command/GenerateBatteryCompatibilityCommand.php index e4ca2d6c..8c219f67 100644 --- a/src/Command/GenerateBatteryCompatibilityCommand.php +++ b/src/Command/GenerateBatteryCompatibilityCommand.php @@ -43,7 +43,7 @@ class GenerateBatteryCompatibilityCommand extends Command $vehicles = $vm->getVehicles(); foreach ($vehicles as $vehicle) { - $batteries = $vehicle->getBatteries(); + $batteries = $vehicle->getActiveBatteries(); $comp_batt = []; foreach ($batteries as $battery) { diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 6e4d9ed2..05f50243 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -823,7 +823,8 @@ class APIController extends Controller implements LoggedController // batteries $batt_list = []; - $batts = $vehicle->getBatteries(); + // $batts = $vehicle->getBatteries(); + $batts = $vehicle->getActiveBatteries(); foreach ($batts as $batt) { // TODO: Add warranty_tnv to battery information diff --git a/src/Controller/BatteryController.php b/src/Controller/BatteryController.php index e392dd6b..b63e52e9 100644 --- a/src/Controller/BatteryController.php +++ b/src/Controller/BatteryController.php @@ -117,6 +117,7 @@ class BatteryController extends Controller $row['height'] = $orow[0]->getHeight(); $row['total_height'] = $orow[0]->getTotalHeight(); $row['image_file'] = $orow[0]->getImageFile(); + $row['flag_active'] = $orow[0]->isActive(); // add row metadata $row['meta'] = [ @@ -182,7 +183,8 @@ class BatteryController extends Controller ->setHeight($req->request->get('height')) ->setTotalHeight($req->request->get('total_height')) ->setSellingPrice($req->request->get('sell_price')) - ->setImageFile($req->request->get('image_file')); + ->setImageFile($req->request->get('image_file')) + ->setActive($req->request->get('flag_active', false)); // initialize error list $error_array = []; @@ -308,6 +310,7 @@ class BatteryController extends Controller ->setTotalHeight($req->request->get('total_height')) ->setSellingPrice($req->request->get('sell_price')) ->setImageFile($req->request->get('image_file')) + ->setActive($req->request->get('flag_active', false)) ->clearVehicles(); // initialize error list @@ -424,7 +427,7 @@ class BatteryController extends Controller $bmodel_id = $req->query->get('model_id'); $bsize_id = $req->query->get('size_id'); - // find the battery using model and size + // find the battery using model and size and battery must be active $em = $this->getDoctrine()->getManager(); $query = $em->createQuery('SELECT b FROM App\Entity\Battery b JOIN b.model bm @@ -432,7 +435,8 @@ class BatteryController extends Controller JOIN b.manufacturer bmfg WHERE bm.id = :bm_id AND bs.id = :bs_id - AND bmfg.id = :bmfg_id') + AND bmfg.id = :bmfg_id + AND b.flag_active = true') ->setParameter('bmfg_id', $bmfg_id) ->setParameter('bm_id', $bmodel_id) ->setParameter('bs_id', $bsize_id); diff --git a/src/Controller/BatteryManufacturerController.php b/src/Controller/BatteryManufacturerController.php index ad93d3df..c717a678 100644 --- a/src/Controller/BatteryManufacturerController.php +++ b/src/Controller/BatteryManufacturerController.php @@ -270,7 +270,7 @@ class BatteryManufacturerController extends Controller // get row data $em = $this->getDoctrine()->getManager(); - $all_batts = $em->getRepository(Battery::class)->findAll(); + $all_batts = $em->getRepository(Battery::class)->findBy(['flag_active' => true]); foreach ($all_batts as $battery) { diff --git a/src/Controller/CAPI/RiderAppController.php b/src/Controller/CAPI/RiderAppController.php index 1a293058..6a6d3d91 100644 --- a/src/Controller/CAPI/RiderAppController.php +++ b/src/Controller/CAPI/RiderAppController.php @@ -1043,7 +1043,7 @@ class RiderAppController extends APIController if ($rider == null) return new APIResponse(false, 'No rider found.'); - $batts = $em->getRepository(Battery::class)->findAll(); + $batts = $em->getRepository(Battery::class)->findBy(['flag_active' => true]); $models = $em->getRepository(BatteryModel::class)->findAll(); $sizes = $em->getRepository(BatterySize::class)->findAll(); diff --git a/src/Controller/TAPI/BatteryController.php b/src/Controller/TAPI/BatteryController.php index 7e015fe6..0874b792 100644 --- a/src/Controller/TAPI/BatteryController.php +++ b/src/Controller/TAPI/BatteryController.php @@ -45,7 +45,8 @@ class BatteryController extends APIController // batteries $batt_list = []; - $batts = $vehicle->getBatteries(); + // $batts = $vehicle->getBatteries(); + $batts = $vehicle->getActiveBatteries(); foreach ($batts as $batt) { // TODO: Add warranty_tnv to battery information diff --git a/src/Controller/VehicleController.php b/src/Controller/VehicleController.php index 7c388062..afe45fc5 100644 --- a/src/Controller/VehicleController.php +++ b/src/Controller/VehicleController.php @@ -485,7 +485,7 @@ class VehicleController extends Controller // get row data $em = $this->getDoctrine()->getManager(); $vobj = $em->getRepository(Vehicle::class)->find($req->request->get('vehicle_id')); - $all_batts = $em->getRepository(Battery::class)->findAll(); + $all_batts = $em->getRepository(Battery::class)->findBy(['flag_active' => true]); if (empty($vobj)) throw $this->createNotFoundException('The item does not exist'); @@ -495,19 +495,20 @@ class VehicleController extends Controller $battery_index = []; // get compatible batteries from selected manufacturer - foreach ($vobj->getBatteries() as $battery) + // foreach ($vobj->getBatteries() as $battery) + foreach ($vobj->getActiveBatteries() as $battery) { - $batteries[] = [ - 'id' => $battery->getID(), - 'mfg_name' => $battery->getManufacturer()->getName(), - 'model_name' => $battery->getModel()->getName(), - 'size_name' => $battery->getSize()->getName(), - 'prod_code' => $battery->getProductCode(), - 'sell_price' => $battery->getSellingPrice(), - 'warr_private' => $battery->getWarrantyPrivate(), - 'warr_commercial' => $battery->getWarrantyCommercial(), - ]; - $battery_index[$battery->getID()] = 1; + $batteries[] = [ + 'id' => $battery->getID(), + 'mfg_name' => $battery->getManufacturer()->getName(), + 'model_name' => $battery->getModel()->getName(), + 'size_name' => $battery->getSize()->getName(), + 'prod_code' => $battery->getProductCode(), + 'sell_price' => $battery->getSellingPrice(), + 'warr_private' => $battery->getWarrantyPrivate(), + 'warr_commercial' => $battery->getWarrantyCommercial(), + ]; + $battery_index[$battery->getID()] = 1; } // add all other batteries, because they want options diff --git a/src/Entity/Battery.php b/src/Entity/Battery.php index 8adf4f65..89104bcf 100644 --- a/src/Entity/Battery.php +++ b/src/Entity/Battery.php @@ -147,6 +147,12 @@ class Battery */ protected $image_file; + // flag if battery is active + /** + * @ORM\Column(type="boolean", options={"default": true}) + */ + protected $flag_active; + public function __construct() { $this->vehicles = new ArrayCollection(); @@ -159,6 +165,8 @@ class Battery $this->total_height = 0; $this->date_create = new DateTime(); + + $this->flag_active = true; } public function getID() @@ -382,4 +390,15 @@ class Battery { return $this->image_file; } + + public function isActive() + { + return $this->flag_active; + } + + public function setActive($flag_active = true) + { + $this->flag_active = $flag_active; + return $this; + } } diff --git a/src/Entity/Vehicle.php b/src/Entity/Vehicle.php index 61fdcec9..97a35da4 100644 --- a/src/Entity/Vehicle.php +++ b/src/Entity/Vehicle.php @@ -4,6 +4,8 @@ namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Criteria; + use Symfony\Component\Validator\Constraints as Assert; /** @@ -177,4 +179,12 @@ class Vehicle { return $this->cust_vehicles; } + + public function getActiveBatteries() + { + $crit = Criteria::create(); + $crit->where(Criteria::expr()->eq('flag_active', true)); + + return $this->batteries->matching($crit); + } } diff --git a/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php b/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php index 5cc903c9..a543f39d 100644 --- a/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php @@ -714,7 +714,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface if (isset($data['error'])) return $data; - $batts = $this->em->getRepository(Battery::class)->findAll(); + $batts = $this->em->getRepository(Battery::class)->findBy(['flag_active' => true]); $models = $this->em->getRepository(BatteryModel::class)->findAll(); $sizes = $this->em->getRepository(BatterySize::class)->findAll(); diff --git a/templates/battery/form.html.twig b/templates/battery/form.html.twig index 53adb693..4ac05437 100644 --- a/templates/battery/form.html.twig +++ b/templates/battery/form.html.twig @@ -101,6 +101,20 @@
+