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 @@ +