From f65ca190107f7bb70052cdce0ae65671257d2e6d Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 9 Jan 2024 17:39:29 +0800 Subject: [PATCH] Load service offering into Item Pricing page. #780 --- config/routes/item_pricing.yaml | 2 +- src/Controller/ItemController.php | 54 ++++++++++++++++++++ src/Controller/ItemPricingController.php | 57 ++++++++++++++++++--- templates/item-pricing/form.html.twig | 37 ++++++++++++-- templates/item/form.html.twig | 65 ++++++++++++++++++------ 5 files changed, 188 insertions(+), 27 deletions(-) diff --git a/config/routes/item_pricing.yaml b/config/routes/item_pricing.yaml index df289902..a557a1ec 100644 --- a/config/routes/item_pricing.yaml +++ b/config/routes/item_pricing.yaml @@ -9,6 +9,6 @@ item_pricing_update: methods: [POST] item_pricing_prices: - path: /item-pricing/{id}/prices + path: /item-pricing/{pt_id}/{it_id}/prices controller: App\Controller\ItemPricingController::itemPrices methods: [GET] diff --git a/src/Controller/ItemController.php b/src/Controller/ItemController.php index 88cc769c..7e9cd277 100644 --- a/src/Controller/ItemController.php +++ b/src/Controller/ItemController.php @@ -122,6 +122,60 @@ class ItemController extends Controller ]); } + /** + * @Menu(selected="item.list") + * @IsGranted("item.add") + */ + public function addForm(EntityManagerInterface $em) + { + $item = new Item(); + + // get the sets for the dropdowns + $sets = $this->generateFormSets($em); + + $params = [ + 'obj' => $item, + 'sets' => $sets, + 'mode' => 'create', + ]; + + // response + return $this->render('item/form.html.twig', $params); + } + + protected function generateFormSets(EntityManagerInterface $em) + { + // item types + $item_types = $em->getRepository(ItemType::class)->findby([], ['name' => 'asc']); + $item_type_set = []; + foreach ($item_types as $it) + { + $item_type_set[$it->getID()] = $it->getName(); + } + + // batteries + $batts = $em->getRepository(Battery::class)->findAll(); + $batt_set = []; + foreach ($batts as $batt) + { + $batt_set[$batt->getID()] = $batt->getModel()->getName() . ' ' . $batt->getSize()->getName(); + } + + // service offerings + $services = $em->getRepository(ServiceOffering::class)->findBy([],['name' => 'asc']); + $service_set = []; + foreach ($services as $service) + { + $service_set[$service->getID()] = $service->getName(); + } + + return [ + 'item_types' => $item_type_set, + 'batteries' => $batt_set, + 'services' => $service_set, + ]; + } + protected function setQueryFilters($datatable, QueryBuilder $query) { // TODO: add filter for item type. diff --git a/src/Controller/ItemPricingController.php b/src/Controller/ItemPricingController.php index ddfd60bf..537ae2a6 100644 --- a/src/Controller/ItemPricingController.php +++ b/src/Controller/ItemPricingController.php @@ -17,6 +17,8 @@ use Catalyst\MenuBundle\Annotation\Menu; use App\Entity\PriceTier; use App\Entity\Battery; +use App\Entity\ServiceOffering; +use App\Entity\ItemType; class ItemPricingController extends Controller { @@ -29,12 +31,16 @@ class ItemPricingController extends Controller // get all the price tiers $price_tiers = $em->getRepository(PriceTier::class)->findAll(); + // get all item types + $item_types = $em->getRepository(ItemType::class)->findBy([], ['name' => 'asc']); + // get all the items/batteries - $items = $em->getRepository(Battery::class)->findBy(['flag_active' => true]); + $items = $this->getAllItems($em); $params = [ 'sets' => [ - 'price_tiers' => $price_tiers + 'price_tiers' => $price_tiers, + 'item_types' => $item_types, ], 'items' => $items, ]; @@ -53,7 +59,7 @@ class ItemPricingController extends Controller /** * @IsGranted("item_pricing.update") */ - public function itemPrices(EntityManagerInterface $em, $id) + public function itemPrices(EntityManagerInterface $em, $pt_id, $it_id) { $pt_prices = []; // check if default prices are needed @@ -62,9 +68,9 @@ class ItemPricingController extends Controller // get the price tier $pt = $em->getRepository(PriceTier::class)->find($id); - // get the item prices under the price tier - $pt_item_prices = $pt->getItemPrices(); - foreach ($pt_item_prices as $pt_item_price) + // get the items under the price tier + $pt_items = $pt->getItems(); + foreach ($pt_items as $pt_item) { } } @@ -80,4 +86,43 @@ class ItemPricingController extends Controller 'items' => $data_items, ]); } + + protected function getAllItems(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) + { + $batt_set[$batt->getID()] = [ + 'name' => $batt->getModel()->getName() . ' ' . $batt->getSize()->getName(), + 'item_type_id' => $batt_item_type->getID(), + 'item_type' => $batt_item_type->getName(), + 'price' => $batt->getSellingPrice(), + ]; + } + + // get all service offerings + $services = $em->getRepository(ServiceOffering::class)->findBy([], ['name' => 'asc']); + $service_set = []; + foreach ($services as $service) + { + $service_set[$service->getID()] = [ + 'name' => $service->getName(), + 'item_type_id' => $service_item_type->getID(), + 'item_type' => $service_item_type->getName(), + 'price' => $service->getFee(), + ]; + } + + return [ + 'batteries' => $batt_set, + 'services' => $service_set, + ]; + } } diff --git a/templates/item-pricing/form.html.twig b/templates/item-pricing/form.html.twig index cde71ae6..d9387dac 100644 --- a/templates/item-pricing/form.html.twig +++ b/templates/item-pricing/form.html.twig @@ -34,6 +34,17 @@ +
+
+
+ +
+
+
@@ -46,19 +57,34 @@ ID Name + Item Type ID + Item Type Price - {% for item in items %} + {% for id, item in items.batteries %} - {{ item.getID }} - {{ item.getModel.getName ~ ' ' ~ item.getSize.getName}} + {{ id }} + {{ item.name }} + {{ item.item_type_id }} + {{ item.item_type }} - + - {% endfor %} + {% endfor %} + {% for id, item in items.services %} + + {{ id }} + {{ item.name}} + {{ item.item_type_id }} + {{ item.item_type}} + + + + + {% endfor %}
@@ -116,6 +142,7 @@ function update_table(data) { item_html += ''; item_html += '' + item.id + ''; item_html += '' + item.name + ''; + item_html += '' + item.item_type_id + ''; item_html += ''; item_html += ''; item_html += ''; diff --git a/templates/item/form.html.twig b/templates/item/form.html.twig index 97d0d9ec..f7a76ce1 100644 --- a/templates/item/form.html.twig +++ b/templates/item/form.html.twig @@ -5,7 +5,7 @@
-

Item Types

+

Items

@@ -23,33 +23,53 @@

{% if mode == 'update' %} - Edit Item Type + Edit Item {{ obj.getName() }} {% else %} - New Item Type + New Item {% endif %}

-
+
-
-
-
@@ -58,7 +78,7 @@
- Back + Back
@@ -90,7 +110,7 @@ $(function() { text: 'Your changes have been saved!', type: 'success', onClose: function() { - window.location.href = "{{ url('item_type_list') }}"; + window.location.href = "{{ url('item_list') }}"; } }); }).fail(function(response) { @@ -138,5 +158,20 @@ $(function() { $(".form-control-feedback[data-field]").addClass('hide'); } }); + +$('#item-type').change(function(e) { + console.log('item type change ' + e.target.value); + if (e.target.value === '1') { + // display battery row + $('#battery-row').removeClass("hide"); + + // hide service offering rows + } else { + // display service offering row + + // hide battery row + $('#battery-row').addClass("hide"); + } +}) {% endblock %}