Resolve "Data archiving" #1687
2 changed files with 64 additions and 35 deletions
|
|
@ -7,6 +7,7 @@ use Doctrine\ORM\QueryBuilder;
|
|||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
|
|
@ -35,7 +36,8 @@ class ItemPricingController extends Controller
|
|||
$item_types = $em->getRepository(ItemType::class)->findBy([], ['name' => 'asc']);
|
||||
|
||||
// get all the items/batteries
|
||||
$items = $this->getAllItems($em);
|
||||
// load only batteries upon initial loading
|
||||
$items = $this->getBatteries($em);
|
||||
|
||||
$params = [
|
||||
'sets' => [
|
||||
|
|
@ -62,21 +64,37 @@ class ItemPricingController extends Controller
|
|||
public function itemPrices(EntityManagerInterface $em, $pt_id, $it_id)
|
||||
{
|
||||
$pt_prices = [];
|
||||
|
||||
// get the item type
|
||||
$it = $em->getRepository(ItemType::class)->find($it_id);
|
||||
|
||||
// check if default prices are needed
|
||||
if ($id != 0)
|
||||
if ($pt_id != 0)
|
||||
{
|
||||
// get the price tier
|
||||
$pt = $em->getRepository(PriceTier::class)->find($id);
|
||||
$pt = $em->getRepository(PriceTier::class)->find($pt_id);
|
||||
|
||||
// get the items under the price tier
|
||||
$pt_items = $pt->getItems();
|
||||
foreach ($pt_items as $pt_item)
|
||||
{
|
||||
// make item price hash
|
||||
$pt_prices[$pt_item->->getID()] = $pt_item->getPrice();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// get the prices from battery
|
||||
// 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']);
|
||||
}
|
||||
}
|
||||
|
||||
$data_items = [];
|
||||
|
|
@ -87,14 +105,11 @@ class ItemPricingController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
protected function getAllItems(EntityManagerInterface $em)
|
||||
protected function getBatteries(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)
|
||||
|
|
@ -107,6 +122,16 @@ class ItemPricingController extends Controller
|
|||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'items' => $batt_set,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getServiceOfferings(EntityeManagerInterface $em)
|
||||
{
|
||||
// get the item type for service offering
|
||||
$service_item_type = $em->getRepository(ItemType::class)->findOneBy(['code' => 'service_offering']);
|
||||
|
||||
// get all service offerings
|
||||
$services = $em->getRepository(ServiceOffering::class)->findBy([], ['name' => 'asc']);
|
||||
$service_set = [];
|
||||
|
|
@ -121,8 +146,7 @@ class ItemPricingController extends Controller
|
|||
}
|
||||
|
||||
return [
|
||||
'batteries' => $batt_set,
|
||||
'services' => $service_set,
|
||||
'items' => $service_set,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@
|
|||
<div class="col-md-3">
|
||||
<div class="m-input-icon m-input-icon--left">
|
||||
<div class="input-group">
|
||||
<select class="form-control m-input" id="price_tier_list" name="price_tier_list">
|
||||
<option value="">Default Price Tier</option>
|
||||
<select class="form-control m-input" id="price-tier-select" name="price_tier_list">
|
||||
<option value="0">Default Price Tier</option>
|
||||
{% for price_tier in sets.price_tiers %}
|
||||
<option value="{{ price_tier.getID }}">{{ price_tier.getName }} </option>
|
||||
{% endfor %}
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
<div class="col-md-3">
|
||||
<div class="m-input-icon m-input-icon--left">
|
||||
<div class="input-group">
|
||||
<select class="form-control m-input" id="item-type-list" name="item_type_list">
|
||||
<select class="form-control m-input" id="item-type-select" name="item_type_list">
|
||||
{% for item_type in sets.item_types %}
|
||||
<option value="{{ item_type.getID }}">{{ item_type.getName }} </option>
|
||||
{% endfor %}
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody id="table-body">
|
||||
{% for id, item in items.batteries %}
|
||||
{% for id, item in items.items %}
|
||||
<tr>
|
||||
<td>{{ id }}</td>
|
||||
<td>{{ item.name }} </td>
|
||||
|
|
@ -74,17 +74,6 @@
|
|||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% for id, item in items.services %}
|
||||
<tr>
|
||||
<td>{{ id }}</td>
|
||||
<td>{{ item.name}} </td>
|
||||
<td hidden> {{ item.item_type_id }} </td>
|
||||
<td>{{ item.item_type}} </td>
|
||||
<td class="py-1">
|
||||
<input name="price[{{ id }}]" class="form-control ca-filter" type="number" value="{{ item.price }}" step="0.01">
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="">
|
||||
|
|
@ -99,21 +88,36 @@
|
|||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block js_end %}
|
||||
{% block scripts %}
|
||||
<script>
|
||||
|
||||
initialize();
|
||||
|
||||
function initialize() {
|
||||
init_dropdown();
|
||||
console.log('initialize');
|
||||
init_price_tier_dropdown();
|
||||
init_item_type_dropdown();
|
||||
}
|
||||
|
||||
function init_dropdown() {
|
||||
var dropdown = document.getElementById('tier-select');
|
||||
dropdown.addEventListener('change', function(e) {
|
||||
set_name(e.target.options[e.target.selectedIndex].text);
|
||||
load_prices(e.target.value);
|
||||
function init_price_tier_dropdown() {
|
||||
var pt_dropdown = document.getElementById('price-tier-select');
|
||||
var it_dropdown = document.getElementById('item-type-select');
|
||||
pt_dropdown.addEventListener('change', function(e) {
|
||||
var it_type = it_dropdown.value;
|
||||
load_prices(e.target.value, it_type);
|
||||
});
|
||||
}
|
||||
|
||||
function load_prices(price_tier_id) {
|
||||
function init_item_type_dropdown() {
|
||||
var it_dropdown = document.getElementById('item-type-select');
|
||||
var pt_dropdown = document.getElementById('price-tier-select');
|
||||
it_dropdown.addEventListener('change', function(e) {
|
||||
var pt_type = pt_dropdown.value;
|
||||
load_prices(pt_type, e.target.value);
|
||||
});
|
||||
}
|
||||
|
||||
function load_prices(price_tier_id, item_type_id) {
|
||||
var req = new XMLHttpRequest();
|
||||
req.onreadystatechange = function() {
|
||||
// process response
|
||||
|
|
@ -126,8 +130,8 @@ function load_prices(price_tier_id) {
|
|||
// console.log('could not load tier prices');
|
||||
}
|
||||
}
|
||||
var url_pattern = '{{ url('item_pricing_prices', {'id': '--id--'}) }}';
|
||||
var url = url_pattern.replace('--id--', price_tier_id);
|
||||
var url_pattern = '{{ url('item_pricing_prices', {'pt_id': '--id--', 'it_id': '--it-id--'}) }}';
|
||||
var url = url_pattern.replace('--id--', price_tier_id).replace('--it-id--', item_type_id);
|
||||
console.log(url);
|
||||
req.open('GET', url, true);
|
||||
req.send();
|
||||
|
|
@ -152,5 +156,6 @@ function update_table(data) {
|
|||
var table_body = document.getElementById('table-body');
|
||||
table_body.innerHTML = item_html;
|
||||
}
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue