Add getActiveBatteries function. #733

This commit is contained in:
Korina Cordero 2023-02-06 10:39:30 +00:00
parent 6e9e56b1be
commit 765b3a99b9
5 changed files with 56 additions and 64 deletions

View file

@ -823,27 +823,24 @@ class APIController extends Controller implements LoggedController
// batteries // batteries
$batt_list = []; $batt_list = [];
$batts = $vehicle->getBatteries(); // $batts = $vehicle->getBatteries();
$batts = $vehicle->getActiveBatteries();
foreach ($batts as $batt) foreach ($batts as $batt)
{ {
// check if battery is active // TODO: Add warranty_tnv to battery information
if ($batt->isActive()) $batt_list[] = [
{ 'id' => $batt->getID(),
// TODO: Add warranty_tnv to battery information 'mfg_id' => $batt->getManufacturer()->getID(),
$batt_list[] = [ 'mfg_name' => $batt->getManufacturer()->getName(),
'id' => $batt->getID(), 'model_id' => $batt->getModel()->getID(),
'mfg_id' => $batt->getManufacturer()->getID(), 'model_name' => $batt->getModel()->getName(),
'mfg_name' => $batt->getManufacturer()->getName(), 'size_id' => $batt->getSize()->getID(),
'model_id' => $batt->getModel()->getID(), 'size_name' => $batt->getSize()->getName(),
'model_name' => $batt->getModel()->getName(), 'price' => $batt->getSellingPrice(),
'size_id' => $batt->getSize()->getID(), 'wty_private' => $batt->getWarrantyPrivate(),
'size_name' => $batt->getSize()->getName(), 'wty_commercial' => $batt->getWarrantyCommercial(),
'price' => $batt->getSellingPrice(), 'image_url' => $this->getBatteryImageURL($req, $batt),
'wty_private' => $batt->getWarrantyPrivate(), ];
'wty_commercial' => $batt->getWarrantyCommercial(),
'image_url' => $this->getBatteryImageURL($req, $batt),
];
}
} }
// data // data

View file

@ -45,27 +45,24 @@ class BatteryController extends APIController
// batteries // batteries
$batt_list = []; $batt_list = [];
$batts = $vehicle->getBatteries(); // $batts = $vehicle->getBatteries();
$batts = $vehicle->getActiveBatteries();
foreach ($batts as $batt) foreach ($batts as $batt)
{ {
// check if battery is active // TODO: Add warranty_tnv to battery information
if ($batt->isActive()) $batt_list[] = [
{ 'id' => $batt->getID(),
// TODO: Add warranty_tnv to battery information 'mfg_id' => $batt->getManufacturer()->getID(),
$batt_list[] = [ 'mfg_name' => $batt->getManufacturer()->getName(),
'id' => $batt->getID(), 'model_id' => $batt->getModel()->getID(),
'mfg_id' => $batt->getManufacturer()->getID(), 'model_name' => $batt->getModel()->getName(),
'mfg_name' => $batt->getManufacturer()->getName(), 'size_id' => $batt->getSize()->getID(),
'model_id' => $batt->getModel()->getID(), 'size_name' => $batt->getSize()->getName(),
'model_name' => $batt->getModel()->getName(), 'price' => $batt->getSellingPrice(),
'size_id' => $batt->getSize()->getID(), 'wty_private' => $batt->getWarrantyPrivate(),
'size_name' => $batt->getSize()->getName(), 'wty_commercial' => $batt->getWarrantyCommercial(),
'price' => $batt->getSellingPrice(), 'image_url' => $this->getBatteryImageURL($req, $batt),
'wty_private' => $batt->getWarrantyPrivate(), ];
'wty_commercial' => $batt->getWarrantyCommercial(),
'image_url' => $this->getBatteryImageURL($req, $batt),
];
}
} }
// data // data

View file

@ -495,23 +495,20 @@ class VehicleController extends Controller
$battery_index = []; $battery_index = [];
// get compatible batteries from selected manufacturer // get compatible batteries from selected manufacturer
foreach ($vobj->getBatteries() as $battery) // foreach ($vobj->getBatteries() as $battery)
foreach ($vobj->getActiveBatteries() as $battery)
{ {
// need to check if battery is active $batteries[] = [
if ($battery->isActive()) 'id' => $battery->getID(),
{ 'mfg_name' => $battery->getManufacturer()->getName(),
$batteries[] = [ 'model_name' => $battery->getModel()->getName(),
'id' => $battery->getID(), 'size_name' => $battery->getSize()->getName(),
'mfg_name' => $battery->getManufacturer()->getName(), 'prod_code' => $battery->getProductCode(),
'model_name' => $battery->getModel()->getName(), 'sell_price' => $battery->getSellingPrice(),
'size_name' => $battery->getSize()->getName(), 'warr_private' => $battery->getWarrantyPrivate(),
'prod_code' => $battery->getProductCode(), 'warr_commercial' => $battery->getWarrantyCommercial(),
'sell_price' => $battery->getSellingPrice(), ];
'warr_private' => $battery->getWarrantyPrivate(), $battery_index[$battery->getID()] = 1;
'warr_commercial' => $battery->getWarrantyCommercial(),
];
$battery_index[$battery->getID()] = 1;
}
} }
// add all other batteries, because they want options // add all other batteries, because they want options

View file

@ -4,6 +4,8 @@ namespace App\Entity;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
/** /**
@ -177,4 +179,12 @@ class Vehicle
{ {
return $this->cust_vehicles; return $this->cust_vehicles;
} }
public function getActiveBatteries()
{
$crit = Criteria::create();
$crit->where(Criteria::expr()->eq('flag_active', true));
return $this->batteries->matching($crit);
}
} }

View file

@ -233,14 +233,13 @@ $(function() {
var batteryIds = []; var batteryIds = [];
var battMfgModelSize = [] var battMfgModelSize = []
{% for batt in obj.getBatteries %} {% for batt in obj.getActiveBatteries %}
trow = { trow = {
id: "{{ batt.getID }}", id: "{{ batt.getID }}",
manufacturer: "{{ batt.getManufacturer.getName|default('') }} ", manufacturer: "{{ batt.getManufacturer.getName|default('') }} ",
model: "{{ batt.getModel.getName|default('') }}", model: "{{ batt.getModel.getName|default('') }}",
size: "{{ batt.getSize.getName|default('') }}", size: "{{ batt.getSize.getName|default('') }}",
sell_price: "{{ batt.getSellingPrice }}", sell_price: "{{ batt.getSellingPrice }}",
flag_active: "{{ batt.isActive }}"
}; };
battRows.push(trow); battRows.push(trow);
@ -342,14 +341,6 @@ $(function() {
layout: { layout: {
scroll: true scroll: true
}, },
rows: {
beforeTemplate: function(row, data, index) {
var is_active = data.flag_active;
if (is_active == false) {
$(row).addClass('hide');
}
}
},
columns: [ columns: [
{ {
field: 'id', field: 'id',