Add item type dropdown to form. #780
This commit is contained in:
parent
f65ca19010
commit
7f4675a8a2
2 changed files with 64 additions and 35 deletions
|
|
@ -7,6 +7,7 @@ use Doctrine\ORM\QueryBuilder;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
|
||||||
|
|
@ -35,7 +36,8 @@ class ItemPricingController extends Controller
|
||||||
$item_types = $em->getRepository(ItemType::class)->findBy([], ['name' => 'asc']);
|
$item_types = $em->getRepository(ItemType::class)->findBy([], ['name' => 'asc']);
|
||||||
|
|
||||||
// get all the items/batteries
|
// get all the items/batteries
|
||||||
$items = $this->getAllItems($em);
|
// load only batteries upon initial loading
|
||||||
|
$items = $this->getBatteries($em);
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'sets' => [
|
'sets' => [
|
||||||
|
|
@ -62,21 +64,37 @@ class ItemPricingController extends Controller
|
||||||
public function itemPrices(EntityManagerInterface $em, $pt_id, $it_id)
|
public function itemPrices(EntityManagerInterface $em, $pt_id, $it_id)
|
||||||
{
|
{
|
||||||
$pt_prices = [];
|
$pt_prices = [];
|
||||||
|
|
||||||
|
// get the item type
|
||||||
|
$it = $em->getRepository(ItemType::class)->find($it_id);
|
||||||
|
|
||||||
// check if default prices are needed
|
// check if default prices are needed
|
||||||
if ($id != 0)
|
if ($pt_id != 0)
|
||||||
{
|
{
|
||||||
// get the price tier
|
// get the price tier
|
||||||
$pt = $em->getRepository(PriceTier::class)->find($id);
|
$pt = $em->getRepository(PriceTier::class)->find($pt_id);
|
||||||
|
|
||||||
// get the items under the price tier
|
// get the items under the price tier
|
||||||
$pt_items = $pt->getItems();
|
$pt_items = $pt->getItems();
|
||||||
foreach ($pt_items as $pt_item)
|
foreach ($pt_items as $pt_item)
|
||||||
{
|
{
|
||||||
|
// make item price hash
|
||||||
|
$pt_prices[$pt_item->->getID()] = $pt_item->getPrice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// get the prices from battery
|
// get the prices from battery or service offering, depending on item type
|
||||||
|
if ($it->getCode() == 'battery')
|
||||||
|
{
|
||||||
|
// get batteries
|
||||||
|
$items = $em->getRepository(Battery::class)->findBy(['flag_active' => true]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// get service offerings
|
||||||
|
$items = $em->getRepository(ServiceOffering::class)->findBy([], ['name' => 'asc']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$data_items = [];
|
$data_items = [];
|
||||||
|
|
@ -87,14 +105,11 @@ class ItemPricingController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAllItems(EntityManagerInterface $em)
|
protected function getBatteries(EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
// get the item type for battery
|
// get the item type for battery
|
||||||
$batt_item_type = $em->getRepository(ItemType::class)->findOneBy(['code' => 'battery']);
|
$batt_item_type = $em->getRepository(ItemType::class)->findOneBy(['code' => 'battery']);
|
||||||
|
|
||||||
// get the item type for service offering
|
|
||||||
$service_item_type = $em->getRepository(ItemType::class)->findOneBy(['code' => 'service_offering']);
|
|
||||||
|
|
||||||
// get all active batteries
|
// get all active batteries
|
||||||
$batts = $em->getRepository(Battery::class)->findBy(['flag_active' => true]);
|
$batts = $em->getRepository(Battery::class)->findBy(['flag_active' => true]);
|
||||||
foreach ($batts as $batt)
|
foreach ($batts as $batt)
|
||||||
|
|
@ -107,6 +122,16 @@ class ItemPricingController extends Controller
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'items' => $batt_set,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getServiceOfferings(EntityeManagerInterface $em)
|
||||||
|
{
|
||||||
|
// get the item type for service offering
|
||||||
|
$service_item_type = $em->getRepository(ItemType::class)->findOneBy(['code' => 'service_offering']);
|
||||||
|
|
||||||
// get all service offerings
|
// get all service offerings
|
||||||
$services = $em->getRepository(ServiceOffering::class)->findBy([], ['name' => 'asc']);
|
$services = $em->getRepository(ServiceOffering::class)->findBy([], ['name' => 'asc']);
|
||||||
$service_set = [];
|
$service_set = [];
|
||||||
|
|
@ -121,8 +146,7 @@ class ItemPricingController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'batteries' => $batt_set,
|
'items' => $service_set,
|
||||||
'services' => $service_set,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="m-input-icon m-input-icon--left">
|
<div class="m-input-icon m-input-icon--left">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<select class="form-control m-input" id="price_tier_list" name="price_tier_list">
|
<select class="form-control m-input" id="price-tier-select" name="price_tier_list">
|
||||||
<option value="">Default Price Tier</option>
|
<option value="0">Default Price Tier</option>
|
||||||
{% for price_tier in sets.price_tiers %}
|
{% for price_tier in sets.price_tiers %}
|
||||||
<option value="{{ price_tier.getID }}">{{ price_tier.getName }} </option>
|
<option value="{{ price_tier.getID }}">{{ price_tier.getName }} </option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<div class="m-input-icon m-input-icon--left">
|
<div class="m-input-icon m-input-icon--left">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<select class="form-control m-input" id="item-type-list" name="item_type_list">
|
<select class="form-control m-input" id="item-type-select" name="item_type_list">
|
||||||
{% for item_type in sets.item_types %}
|
{% for item_type in sets.item_types %}
|
||||||
<option value="{{ item_type.getID }}">{{ item_type.getName }} </option>
|
<option value="{{ item_type.getID }}">{{ item_type.getName }} </option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
@ -63,7 +63,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="table-body">
|
<tbody id="table-body">
|
||||||
{% for id, item in items.batteries %}
|
{% for id, item in items.items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ id }}</td>
|
<td>{{ id }}</td>
|
||||||
<td>{{ item.name }} </td>
|
<td>{{ item.name }} </td>
|
||||||
|
|
@ -74,17 +74,6 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for id, item in items.services %}
|
|
||||||
<tr>
|
|
||||||
<td>{{ id }}</td>
|
|
||||||
<td>{{ item.name}} </td>
|
|
||||||
<td hidden> {{ item.item_type_id }} </td>
|
|
||||||
<td>{{ item.item_type}} </td>
|
|
||||||
<td class="py-1">
|
|
||||||
<input name="price[{{ id }}]" class="form-control ca-filter" type="number" value="{{ item.price }}" step="0.01">
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div class="">
|
<div class="">
|
||||||
|
|
@ -99,21 +88,36 @@
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block js_end %}
|
{% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
init_dropdown();
|
console.log('initialize');
|
||||||
|
init_price_tier_dropdown();
|
||||||
|
init_item_type_dropdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
function init_dropdown() {
|
function init_price_tier_dropdown() {
|
||||||
var dropdown = document.getElementById('tier-select');
|
var pt_dropdown = document.getElementById('price-tier-select');
|
||||||
dropdown.addEventListener('change', function(e) {
|
var it_dropdown = document.getElementById('item-type-select');
|
||||||
set_name(e.target.options[e.target.selectedIndex].text);
|
pt_dropdown.addEventListener('change', function(e) {
|
||||||
load_prices(e.target.value);
|
var it_type = it_dropdown.value;
|
||||||
|
load_prices(e.target.value, it_type);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function load_prices(price_tier_id) {
|
function init_item_type_dropdown() {
|
||||||
|
var it_dropdown = document.getElementById('item-type-select');
|
||||||
|
var pt_dropdown = document.getElementById('price-tier-select');
|
||||||
|
it_dropdown.addEventListener('change', function(e) {
|
||||||
|
var pt_type = pt_dropdown.value;
|
||||||
|
load_prices(pt_type, e.target.value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function load_prices(price_tier_id, item_type_id) {
|
||||||
var req = new XMLHttpRequest();
|
var req = new XMLHttpRequest();
|
||||||
req.onreadystatechange = function() {
|
req.onreadystatechange = function() {
|
||||||
// process response
|
// process response
|
||||||
|
|
@ -126,8 +130,8 @@ function load_prices(price_tier_id) {
|
||||||
// console.log('could not load tier prices');
|
// console.log('could not load tier prices');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var url_pattern = '{{ url('item_pricing_prices', {'id': '--id--'}) }}';
|
var url_pattern = '{{ url('item_pricing_prices', {'pt_id': '--id--', 'it_id': '--it-id--'}) }}';
|
||||||
var url = url_pattern.replace('--id--', price_tier_id);
|
var url = url_pattern.replace('--id--', price_tier_id).replace('--it-id--', item_type_id);
|
||||||
console.log(url);
|
console.log(url);
|
||||||
req.open('GET', url, true);
|
req.open('GET', url, true);
|
||||||
req.send();
|
req.send();
|
||||||
|
|
@ -152,5 +156,6 @@ function update_table(data) {
|
||||||
var table_body = document.getElementById('table-body');
|
var table_body = document.getElementById('table-body');
|
||||||
table_body.innerHTML = item_html;
|
table_body.innerHTML = item_html;
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue