Add saving of prices. #780

This commit is contained in:
Korina Cordero 2024-01-15 17:21:31 +08:00
parent bfe7a5fbf6
commit 022336ad8f
2 changed files with 56 additions and 14 deletions

View file

@ -56,6 +56,48 @@ class ItemPricingController extends Controller
*/ */
public function formSubmit(Request $req, EntityManagerInterface $em) public function formSubmit(Request $req, EntityManagerInterface $em)
{ {
$pt_id = $req->request->get('price_tier_id');
$it_id = $req->request->get('item_type_id');
$prices = $req->request->get('price');
// get the item type
$item_type = $em->getRepository(ItemType::class)->find($it_id);
if ($pt_id == 0)
{
// default price tier, update battery or service offering, depending on item type
// NOTE: battery and service offering prices or fees are stored as decimal.
if ($item_type->getCode() == 'battery')
{
// get batteries
$items = $em->getRepository(Battery::class)->findBy(['flag_active' => true], ['id' => 'asc']);
}
else
{
// get service offerings
$items = $em->getRepository(ServiceOffering::class)->findBy([], ['id' => 'asc']);
}
foreach ($items as $item)
{
$item_id = $item->getID();
if (isset[$prices[$item_id]])
{
// check item type
if ($item_type->getCode() == 'battery')
$item->setSellingPrice($prices[$item_id]);
else
$item->setFee($prices[$item_id]);
}
}
}
else
{
// get the price tier
$price_tier = $em->getRepository(PriceTier::class)->find($pt_id);
// TODO: finish this
}
} }
/** /**
@ -82,19 +124,17 @@ class ItemPricingController extends Controller
$pt_prices[$pt_item->getID()] = $pt_item->getPrice(); $pt_prices[$pt_item->getID()] = $pt_item->getPrice();
} }
} }
// 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], ['id' => 'asc']);
}
else else
{ {
// get the prices from battery or service offering, depending on item type // get service offerings
if ($it->getCode() == 'battery') $items = $em->getRepository(ServiceOffering::class)->findBy([], ['id' => 'asc']);
{
// 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 = [];
@ -146,7 +186,7 @@ class ItemPricingController extends Controller
$batt_item_type = $em->getRepository(ItemType::class)->findOneBy(['code' => 'battery']); $batt_item_type = $em->getRepository(ItemType::class)->findOneBy(['code' => 'battery']);
// 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], ['id' => 'asc']);
foreach ($batts as $batt) foreach ($batts as $batt)
{ {
$batt_set[$batt->getID()] = [ $batt_set[$batt->getID()] = [
@ -168,7 +208,7 @@ class ItemPricingController extends Controller
$service_item_type = $em->getRepository(ItemType::class)->findOneBy(['code' => '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([], ['id' => 'asc']);
$service_set = []; $service_set = [];
foreach ($services as $service) foreach ($services as $service)
{ {

View file

@ -51,6 +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">
<div style="padding-left: 25px; padding-right: 25px;"> <div style="padding-left: 25px; padding-right: 25px;">
<table class="table"> <table class="table">
<thead> <thead>
@ -94,7 +95,6 @@
initialize(); initialize();
function initialize() { function initialize() {
console.log('initialize');
init_price_tier_dropdown(); init_price_tier_dropdown();
init_item_type_dropdown(); init_item_type_dropdown();
} }
@ -126,6 +126,8 @@ function load_prices(price_tier_id, item_type_id) {
update_table(JSON.parse(req.responseText)); update_table(JSON.parse(req.responseText));
var pt_field = document.getElementById('price-tier-id'); var pt_field = document.getElementById('price-tier-id');
pt_field.value = price_tier_id; pt_field.value = price_tier_id;
var it_field = document.getElementById('item-type-id');
it_field.value = item_type_id;
} else { } else {
// console.log('could not load tier prices'); // console.log('could not load tier prices');
} }