diff --git a/src/Command/GenerateBatteryCompatibilityCommand.php b/src/Command/GenerateBatteryCompatibilityCommand.php index e4ca2d6c..f2cc8940 100644 --- a/src/Command/GenerateBatteryCompatibilityCommand.php +++ b/src/Command/GenerateBatteryCompatibilityCommand.php @@ -47,6 +47,10 @@ class GenerateBatteryCompatibilityCommand extends Command $comp_batt = []; foreach ($batteries as $battery) { + // check if battery is active + if (!($battery->isActive())) + continue; + // set to the first compatible battery found until a more expensive one is found $comp_batt['id'] = $battery->getID(); $comp_batt['name'] = $battery->getModel()->getName() . ' ' . diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 6e4d9ed2..6d7849eb 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -826,20 +826,24 @@ class APIController extends Controller implements LoggedController $batts = $vehicle->getBatteries(); foreach ($batts as $batt) { - // TODO: Add warranty_tnv to battery information - $batt_list[] = [ - 'id' => $batt->getID(), - 'mfg_id' => $batt->getManufacturer()->getID(), - 'mfg_name' => $batt->getManufacturer()->getName(), - 'model_id' => $batt->getModel()->getID(), - 'model_name' => $batt->getModel()->getName(), - 'size_id' => $batt->getSize()->getID(), - 'size_name' => $batt->getSize()->getName(), - 'price' => $batt->getSellingPrice(), - 'wty_private' => $batt->getWarrantyPrivate(), - 'wty_commercial' => $batt->getWarrantyCommercial(), - 'image_url' => $this->getBatteryImageURL($req, $batt), - ]; + // check if battery is active + if ($batt->isActive()) + { + // TODO: Add warranty_tnv to battery information + $batt_list[] = [ + 'id' => $batt->getID(), + 'mfg_id' => $batt->getManufacturer()->getID(), + 'mfg_name' => $batt->getManufacturer()->getName(), + 'model_id' => $batt->getModel()->getID(), + 'model_name' => $batt->getModel()->getName(), + 'size_id' => $batt->getSize()->getID(), + 'size_name' => $batt->getSize()->getName(), + 'price' => $batt->getSellingPrice(), + 'wty_private' => $batt->getWarrantyPrivate(), + 'wty_commercial' => $batt->getWarrantyCommercial(), + 'image_url' => $this->getBatteryImageURL($req, $batt), + ]; + } } // data diff --git a/src/Controller/TAPI/BatteryController.php b/src/Controller/TAPI/BatteryController.php index 7e015fe6..5a2fca50 100644 --- a/src/Controller/TAPI/BatteryController.php +++ b/src/Controller/TAPI/BatteryController.php @@ -48,20 +48,24 @@ class BatteryController extends APIController $batts = $vehicle->getBatteries(); foreach ($batts as $batt) { - // TODO: Add warranty_tnv to battery information - $batt_list[] = [ - 'id' => $batt->getID(), - 'mfg_id' => $batt->getManufacturer()->getID(), - 'mfg_name' => $batt->getManufacturer()->getName(), - 'model_id' => $batt->getModel()->getID(), - 'model_name' => $batt->getModel()->getName(), - 'size_id' => $batt->getSize()->getID(), - 'size_name' => $batt->getSize()->getName(), - 'price' => $batt->getSellingPrice(), - 'wty_private' => $batt->getWarrantyPrivate(), - 'wty_commercial' => $batt->getWarrantyCommercial(), - 'image_url' => $this->getBatteryImageURL($req, $batt), - ]; + // check if battery is active + if ($batt->isActive()) + { + // TODO: Add warranty_tnv to battery information + $batt_list[] = [ + 'id' => $batt->getID(), + 'mfg_id' => $batt->getManufacturer()->getID(), + 'mfg_name' => $batt->getManufacturer()->getName(), + 'model_id' => $batt->getModel()->getID(), + 'model_name' => $batt->getModel()->getName(), + 'size_id' => $batt->getSize()->getID(), + 'size_name' => $batt->getSize()->getName(), + 'price' => $batt->getSellingPrice(), + 'wty_private' => $batt->getWarrantyPrivate(), + 'wty_commercial' => $batt->getWarrantyCommercial(), + 'image_url' => $this->getBatteryImageURL($req, $batt), + ]; + } } // data diff --git a/src/Controller/VehicleController.php b/src/Controller/VehicleController.php index 9397197f..39c386b0 100644 --- a/src/Controller/VehicleController.php +++ b/src/Controller/VehicleController.php @@ -497,17 +497,21 @@ class VehicleController extends Controller // get compatible batteries from selected manufacturer foreach ($vobj->getBatteries() 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; + // need to check if battery is active + if ($battery->isActive()) + { + $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/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/vehicle/form.html.twig b/templates/vehicle/form.html.twig index 09bee95f..764186bf 100644 --- a/templates/vehicle/form.html.twig +++ b/templates/vehicle/form.html.twig @@ -239,7 +239,8 @@ $(function() { manufacturer: "{{ batt.getManufacturer.getName|default('') }} ", model: "{{ batt.getModel.getName|default('') }}", size: "{{ batt.getSize.getName|default('') }}", - sell_price: "{{ batt.getSellingPrice }}" + sell_price: "{{ batt.getSellingPrice }}", + flag_active: "{{ batt.isActive }}" }; battRows.push(trow); @@ -341,6 +342,14 @@ $(function() { layout: { scroll: true }, + rows: { + beforeTemplate: function(row, data, index) { + var is_active = data.flag_active; + if (is_active == false) { + $(row).addClass('hide'); + } + } + }, columns: [ { field: 'id',