Fix issues found during saving of item prices. #780

This commit is contained in:
Korina Cordero 2024-01-17 14:25:28 +08:00
parent 6d7c8c5b53
commit 9de6fa7999
3 changed files with 14 additions and 7 deletions

View file

@ -20,6 +20,7 @@ use App\Entity\PriceTier;
use App\Entity\Battery; use App\Entity\Battery;
use App\Entity\ServiceOffering; use App\Entity\ServiceOffering;
use App\Entity\ItemType; use App\Entity\ItemType;
use App\Entity\ItemPrice;
class ItemPricingController extends Controller class ItemPricingController extends Controller
{ {
@ -39,12 +40,16 @@ class ItemPricingController extends Controller
// load only batteries upon initial loading // load only batteries upon initial loading
$items = $this->getBatteries($em); $items = $this->getBatteries($em);
// set the default item type to battery
$default_it = $em->getRepository(ItemType::class)->findOneBy(['code' => 'battery']);
$params = [ $params = [
'sets' => [ 'sets' => [
'price_tiers' => $price_tiers, 'price_tiers' => $price_tiers,
'item_types' => $item_types, 'item_types' => $item_types,
], ],
'items' => $items, 'items' => $items,
'default_item_type_id' => $default_it->getID(),
]; ];
return $this->render('item-pricing/form.html.twig', $params); return $this->render('item-pricing/form.html.twig', $params);
@ -97,7 +102,7 @@ class ItemPricingController extends Controller
// get the price tier // get the price tier
$price_tier = $em->getRepository(PriceTier::class)->find($pt_id); $price_tier = $em->getRepository(PriceTier::class)->find($pt_id);
$item_prices = $price_tier->getItems(); $item_prices = $price_tier->getItemPrices();
// clear the tier's item prices // clear the tier's item prices
foreach ($item_prices as $ip) foreach ($item_prices as $ip)
@ -118,7 +123,7 @@ class ItemPricingController extends Controller
if (isset($prices[$item_id])) if (isset($prices[$item_id]))
{ {
$item_price->setPrice($price[$item_id] * 100); $item_price->setPrice($prices[$item_id] * 100);
} }
else else
{ {
@ -153,10 +158,11 @@ class ItemPricingController extends Controller
// get the items under the price tier // get the items under the price tier
$pt_items = $pt->getItemPrices(); $pt_items = $pt->getItemPrices();
foreach ($pt_items as $pt_item) foreach ($pt_items as $pt_item)
{ {
// make item price hash // make item price hash
$pt_prices[$pt_item->getID()] = $pt_item->getPrice(); $pt_prices[$pt_item->getItemID()] = $pt_item->getPrice();
} }
} }
@ -192,10 +198,10 @@ class ItemPricingController extends Controller
// check if tier has price for item // check if tier has price for item
if (isset($pt_prices[$item_id])) if (isset($pt_prices[$item_id]))
{ {
$price = $pt_prices[$item_id]; $pt_price = $pt_prices[$item_id];
// actual price // actual price
$actual_price = number_format($price / 100, 2, '.', ''); $price = number_format($pt_price / 100, 2, '.', '');
} }
$actual_price = $price; $actual_price = $price;

View file

@ -6,7 +6,7 @@ use Doctrine\ORM\Mapping as ORM;
/** /**
* @ORM\Entity * @ORM\Entity
* @ORM\Table(name="item") * @ORM\Table(name="item_price")
*/ */
class ItemPrice class ItemPrice

View file

@ -51,7 +51,7 @@
</div> </div>
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ url('item_pricing_update') }}"> <form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ url('item_pricing_update') }}">
<input id="price-tier-id" type="hidden" name="price_tier_id" value="0"> <input id="price-tier-id" type="hidden" name="price_tier_id" value="0">
<input id="item-type-id" type="hidden" name="item_type_id" value="0"> <input id="item-type-id" type="hidden" name="item_type_id" value="{{ default_item_type_id }}">
<div style="padding-left: 25px; padding-right: 25px;"> <div style="padding-left: 25px; padding-right: 25px;">
<table class="table"> <table class="table">
<thead> <thead>
@ -118,6 +118,7 @@ function init_item_type_dropdown() {
} }
function load_prices(price_tier_id, item_type_id) { function load_prices(price_tier_id, item_type_id) {
console.log('loading prices');
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.onreadystatechange = function() { req.onreadystatechange = function() {
// process response // process response