"Add capability to deactivate a battery" #1658
13 changed files with 89 additions and 24 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -101,6 +101,20 @@
|
|||
<div class="form-control-feedback hide" data-field="size"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-4">
|
||||
<span class="m-switch m-switch--icon block-switch">
|
||||
<label>
|
||||
<input type="checkbox" name="flag_active" id="flag_active" value="1"{{ obj.isActive() ? ' checked' }}>
|
||||
<label class="switch-label">Active</label>
|
||||
<span></span>
|
||||
</label>
|
||||
</span>
|
||||
<div class="form-control-feedback hide" data-field="flag_active"></div>
|
||||
</div>
|
||||
<div class="col-lg-8">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group m-form__group row">
|
||||
<div class="col-lg-6">
|
||||
<label data-field="image_file">
|
||||
|
|
|
|||
|
|
@ -111,6 +111,21 @@
|
|||
title: 'Brand',
|
||||
width: 120
|
||||
},
|
||||
{
|
||||
field: 'flag_active',
|
||||
title: 'Active',
|
||||
template: function (row, index, datatable) {
|
||||
var tag = '';
|
||||
|
||||
if (row.flag_active === true) {
|
||||
tag = '<span class="m-badge m-badge--success m-badge--wide">Yes</span>';
|
||||
} else {
|
||||
tag = '<span class="m-badge m-badge--danger m-badge--wide">No</span>';
|
||||
}
|
||||
|
||||
return tag;
|
||||
}
|
||||
},
|
||||
/*
|
||||
{
|
||||
field: 'prod_code',
|
||||
|
|
|
|||
|
|
@ -233,13 +233,13 @@ $(function() {
|
|||
var batteryIds = [];
|
||||
var battMfgModelSize = []
|
||||
|
||||
{% for batt in obj.getBatteries %}
|
||||
{% for batt in obj.getActiveBatteries %}
|
||||
trow = {
|
||||
id: "{{ batt.getID }}",
|
||||
manufacturer: "{{ batt.getManufacturer.getName|default('') }} ",
|
||||
model: "{{ batt.getModel.getName|default('') }}",
|
||||
size: "{{ batt.getSize.getName|default('') }}",
|
||||
sell_price: "{{ batt.getSellingPrice }}"
|
||||
sell_price: "{{ batt.getSellingPrice }}",
|
||||
};
|
||||
|
||||
battRows.push(trow);
|
||||
|
|
|
|||
Loading…
Reference in a new issue