Load service offering into Item Pricing page. #780

This commit is contained in:
Korina Cordero 2024-01-09 17:39:29 +08:00
parent c17be92f0a
commit f65ca19010
5 changed files with 188 additions and 27 deletions

View file

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

View file

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

View file

@ -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,
];
}
}

View file

@ -34,6 +34,17 @@
</div>
</div>
</div>
<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">
{% for item_type in sets.item_types %}
<option value="{{ item_type.getID }}">{{ item_type.getName }} </option>
{% endfor %}
</select>
</div>
</div>
</div>
</div>
</div>
</div>
@ -46,19 +57,34 @@
<tr>
<th style="width: 100px">ID</th>
<th>Name</th>
<th hidden> Item Type ID </th>
<th>Item Type</th>
<th style="width: 180px">Price</th>
</tr>
</thead>
<tbody id="table-body">
{% for item in items %}
{% for id, item in items.batteries %}
<tr>
<td>{{ item.getID }}</td>
<td>{{ item.getModel.getName ~ ' ' ~ item.getSize.getName}} </td>
<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[{{ item.getID }}]" class="form-control ca-filter" type="number" value="{{ item.getSellingPrice }}" step="0.01">
<input name="price[{{ id }}]" class="form-control ca-filter" type="number" value="{{ item.price }}" step="0.01">
</td>
</tr>
{% endfor %}
{% 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="">
@ -116,6 +142,7 @@ function update_table(data) {
item_html += '<tr>';
item_html += '<td>' + item.id + '</td>';
item_html += '<td>' + item.name + '</td>';
item_html += '<td hidden>' + item.item_type_id + '</td>';
item_html += '<td class="py-1">';
item_html += '<input name="price[' + item.id + ']" class="form-control ca-filter" type="number" value="' + item.sell_price + '" step="0.01">';
item_html += '</td>';

View file

@ -5,7 +5,7 @@
<div class="m-subheader">
<div class="d-flex align-items-center">
<div class="mr-auto">
<h3 class="m-subheader__title">Item Types</h3>
<h3 class="m-subheader__title">Items</h3>
</div>
</div>
</div>
@ -23,33 +23,53 @@
</span>
<h3 class="m-portlet__head-text">
{% if mode == 'update' %}
Edit Item Type
Edit Item
<small>{{ obj.getName() }}</small>
{% else %}
New Item Type
New Item
{% endif %}
</h3>
</div>
</div>
</div>
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ mode == 'update' ? url('item_type_update_submit', {'id': obj.getId()}) : url('item_type_add_submit') }}">
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ mode == 'update' ? url('item_type_update_submit', {'id': obj.getId()}) : url('item_add_submit') }}">
<div class="m-portlet__body">
<div class="form-group m-form__group row no-border">
<label class="col-lg-3 col-form-label" data-field="name">
Name:
<label class="col-lg-3 col-form-label" data-field="item_type">
Item Type:
</label>
<div class="col-lg-9">
<input type="text" name="name" class="form-control m-input" value="{{ obj.getName() }}">
<div class="form-control-feedback hide" data-field="name"></div>
<select class="form-control m-input" id="item-type" name="item_type">
{% for id, label in sets.item_types %}
{% if obj.getItemType %}
<option value="{{ id }}"{{ obj.getItemType.getID == id ? ' selected' }}>{{ label }}</option>
{% else %}
<option value="{{ id }}">{{ label }}</option>
{% endif %}
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="item_type"></div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<label class="col-lg-3 col-form-label" data-field="code">
Code:
<div class="form-group m-form__group row no-border
{% if obj.getItemType %}
{% if obj.getItemType.getCode is not same as ('battery') %}
hide
{% endif %}
{% else %}
hide
{% endif %}
" id="battery-row">
<label class="col-lg-3 col-form-label" data-field="battery">
Battery:
</label>
<div class="col-lg-9">
<input type="text" name="code" class="form-control m-input" value="{{ obj.getCode() }}">
<div class="form-control-feedback hide" data-field="code"></div>
<select class="form-control m-input" id="item-type" name="battery">
{% for id, label in sets.batteries %}
<option value="{{ id }}"{{ obj.getItemID == id ? ' selected' }}>{{ label }}</option>
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="battery"></div>
</div>
</div>
</div>
@ -58,7 +78,7 @@
<div class="row">
<div class="col-lg-12">
<button type="submit" class="btn btn-success">Submit</button>
<a href="{{ url('item_type_list') }}" class="btn btn-secondary">Back</a>
<a href="{{ url('item_list') }}" class="btn btn-secondary">Back</a>
</div>
</div>
</div>
@ -90,7 +110,7 @@ $(function() {
text: 'Your changes have been saved!',
type: 'success',
onClose: function() {
window.location.href = "{{ url('item_type_list') }}";
window.location.href = "{{ url('item_list') }}";
}
});
}).fail(function(response) {
@ -138,5 +158,20 @@ $(function() {
$(".form-control-feedback[data-field]").addClass('hide');
}
});
$('#item-type').change(function(e) {
console.log('item type change ' + e.target.value);
if (e.target.value === '1') {
// display battery row
$('#battery-row').removeClass("hide");
// hide service offering rows
} else {
// display service offering row
// hide battery row
$('#battery-row').addClass("hide");
}
})
</script>
{% endblock %}