Add saving of prices. #780
This commit is contained in:
parent
bfe7a5fbf6
commit
022336ad8f
2 changed files with 56 additions and 14 deletions
|
|
@ -56,6 +56,48 @@ class ItemPricingController extends Controller
|
|||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
// 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']);
|
||||
}
|
||||
// get service offerings
|
||||
$items = $em->getRepository(ServiceOffering::class)->findBy([], ['id' => 'asc']);
|
||||
}
|
||||
|
||||
$data_items = [];
|
||||
|
|
@ -146,7 +186,7 @@ class ItemPricingController extends Controller
|
|||
$batt_item_type = $em->getRepository(ItemType::class)->findOneBy(['code' => 'battery']);
|
||||
|
||||
// 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)
|
||||
{
|
||||
$batt_set[$batt->getID()] = [
|
||||
|
|
@ -168,7 +208,7 @@ class ItemPricingController extends Controller
|
|||
$service_item_type = $em->getRepository(ItemType::class)->findOneBy(['code' => 'service_offering']);
|
||||
|
||||
// get all service offerings
|
||||
$services = $em->getRepository(ServiceOffering::class)->findBy([], ['name' => 'asc']);
|
||||
$services = $em->getRepository(ServiceOffering::class)->findBy([], ['id' => 'asc']);
|
||||
$service_set = [];
|
||||
foreach ($services as $service)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@
|
|||
</div>
|
||||
<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="item-type-id" type="hidden" name="item_type_id" value="0">
|
||||
<div style="padding-left: 25px; padding-right: 25px;">
|
||||
<table class="table">
|
||||
<thead>
|
||||
|
|
@ -94,7 +95,6 @@
|
|||
initialize();
|
||||
|
||||
function initialize() {
|
||||
console.log('initialize');
|
||||
init_price_tier_dropdown();
|
||||
init_item_type_dropdown();
|
||||
}
|
||||
|
|
@ -126,6 +126,8 @@ function load_prices(price_tier_id, item_type_id) {
|
|||
update_table(JSON.parse(req.responseText));
|
||||
var pt_field = document.getElementById('price-tier-id');
|
||||
pt_field.value = price_tier_id;
|
||||
var it_field = document.getElementById('item-type-id');
|
||||
it_field.value = item_type_id;
|
||||
} else {
|
||||
// console.log('could not load tier prices');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue