diff --git a/src/Controller/ItemPricingController.php b/src/Controller/ItemPricingController.php index 537ae2a6..158d3787 100644 --- a/src/Controller/ItemPricingController.php +++ b/src/Controller/ItemPricingController.php @@ -7,6 +7,7 @@ use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -35,7 +36,8 @@ class ItemPricingController extends Controller $item_types = $em->getRepository(ItemType::class)->findBy([], ['name' => 'asc']); // get all the items/batteries - $items = $this->getAllItems($em); + // load only batteries upon initial loading + $items = $this->getBatteries($em); $params = [ 'sets' => [ @@ -62,21 +64,37 @@ class ItemPricingController extends Controller public function itemPrices(EntityManagerInterface $em, $pt_id, $it_id) { $pt_prices = []; + + // get the item type + $it = $em->getRepository(ItemType::class)->find($it_id); + // check if default prices are needed - if ($id != 0) + if ($pt_id != 0) { // 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 $pt_items = $pt->getItems(); foreach ($pt_items as $pt_item) { + // make item price hash + $pt_prices[$pt_item->->getID()] = $pt_item->getPrice(); } } 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 = []; @@ -87,14 +105,11 @@ class ItemPricingController extends Controller ]); } - protected function getAllItems(EntityManagerInterface $em) + protected function getBatteries(EntityManagerInterface $em) { // get the item type for 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 $batts = $em->getRepository(Battery::class)->findBy(['flag_active' => true]); 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 $services = $em->getRepository(ServiceOffering::class)->findBy([], ['name' => 'asc']); $service_set = []; @@ -121,8 +146,7 @@ class ItemPricingController extends Controller } return [ - 'batteries' => $batt_set, - 'services' => $service_set, + 'items' => $service_set, ]; } } diff --git a/templates/item-pricing/form.html.twig b/templates/item-pricing/form.html.twig index d9387dac..ed41d9e3 100644 --- a/templates/item-pricing/form.html.twig +++ b/templates/item-pricing/form.html.twig @@ -25,8 +25,8 @@
- + {% for price_tier in sets.price_tiers %} {% endfor %} @@ -37,7 +37,7 @@
- {% for item_type in sets.item_types %} {% endfor %} @@ -63,7 +63,7 @@ - {% for id, item in items.batteries %} + {% for id, item in items.items %} {{ id }} {{ item.name }} @@ -74,17 +74,6 @@ {% endfor %} - {% for id, item in items.services %} - - {{ id }} - {{ item.name}} - {{ item.item_type_id }} - {{ item.item_type}} - - - - - {% endfor %}
@@ -99,21 +88,36 @@
{% endblock %} -{% block js_end %} +{% block scripts %} {% endblock %}