Add controller for item pricing. #780

This commit is contained in:
Korina Cordero 2023-12-27 22:15:44 -05:00
parent 58f46fd5bf
commit e4ffcc0c9d
5 changed files with 228 additions and 0 deletions

View file

@ -675,6 +675,11 @@ catalyst_auth:
label: Update label: Update
- id: item.delete - id: item.delete
label: Delete label: Delete
- id: item_pricing
label: Item Pricing
acls:
- id: item_pricing.update
label: Update
api: api:
user_entity: "App\\Entity\\ApiUser" user_entity: "App\\Entity\\ApiUser"

View file

@ -302,6 +302,10 @@ catalyst_menu:
acl: price_tier.list acl: price_tier.list
label: Price Tiers label: Price Tiers
parent: item parent: item
- id: item_pricing
acl: item_pricing.update
label: Item Pricing
parent: item
- id: item_list - id: item_list
acl: item.list acl: item.list
label: Items label: Items

View file

@ -0,0 +1,14 @@
item_pricing:
path: /item-pricing
controller: App\Controller\ItemPricingController::index
methods: [GET]
item_pricing_update:
path: /item-pricing
controller: App\Controller\ItemPricingController::formSubmit
methods: [POST]
item_pricing_prices:
path: /item-pricing/{id}/prices
controller: App\Controller\ItemPricingController::itemPrices
methods: [GET]

View file

@ -0,0 +1,76 @@
<?php
namespace App\Controller;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Catalyst\MenuBundle\Annotation\Menu;
use App\Entity\PriceTier;
use App\Entity\Battery;
class ItemPricingController extends Controller
{
/**
* @Menu(selected="item_pricing")
* @IsGranted("item_pricing.update")
*/
public function index (EntityManagerInterface $em)
{
// get all the price tiers
$price_tiers = $em->getRepository(PriceTier::class)->findAll();
// get all the items/batteries
$items = $em->getRepository(Battery::class)->findBy(['flag_active' => true]);
$params = [
'sets' => [
'price_tiers' => $price_tiers
],
'items' => $items,
];
return $this->render('item-pricing/form.html.twig', $params);
}
/**
* @Menu(selected="item_pricing")
* @IsGranted("item_pricing.update")
*/
public function formSubmit(Request $req, EntityManagerInterface $em)
{
}
/**
* @IsGranted("item_pricing.update")
*/
public function (EntityManagerInterface $em, $id)
{
$pt_prices = [];
// check if default prices are needed
if ($id != 0)
{
// get the price tier prices
}
else
{
// get the prices from battery
}
$data_items = [];
// response
return new JsonResponse([
'items' => $data_items,
]);
}

View file

@ -0,0 +1,129 @@
{% extends 'base.html.twig' %}
{% block body %}
<!-- BEGIN: Subheader -->
<div class="m-subheader">
<div class="d-flex align-items-center">
<div class="mr-auto">
<h3 class="m-subheader__title">Item Pricing</h3>
</div>
</div>
</div>
<!-- END: Subheader -->
<div class="m-content">
<div class="row">
<div class="col-xl-12">
<div class="m-portlet m-portlet--mobile">
<div class="m-portlet__body">
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
<div class="row align-items-center">
<div class="col-xl-12">
<div class="form-group m-form__group row align-items-center">
<div class="col-md-2">
<label>Item Prices for </label>
</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="price_tier_list" name="price_tier_list">
<option value="">Default Price Tier</option>
{% for price_tier in sets.price_tiers %}
<option value="{{ price_tier.getID }}">{{ price_tier.getName }} </option>
{% endfor %}
</select>
</div>
</div>
</div>
</div>
</div>
</div>
</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">
<div style="padding-left: 25px; padding-right: 25px;">
<table class="table">
<thead>
<tr>
<th style="width: 100px">ID</th>
<th>Name</th>
<th style="width: 180px">Price</th>
</tr>
</thead>
<tbody id="table-body">
{% for item in items %}
<tr>
<td>{{ item.getID }}</td>
<td>{{ item.getModel.getName ~ ' ' ~ item.getSize.getName}} </td>
<td class="py-1">
<input name="price[{{ item.getID }}]" class="form-control ca-filter" type="number" value="{{ item.getSellingPrice }}" step="0.01">
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="">
<input type="submit" class="btn btn-primary" value="Update Price">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block js_end %}
<script>
function initialize() {
init_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 load_prices(price_tier_id) {
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
// process response
if (this.readyState == 4 && this.status == 200) {
// update form
update_table(JSON.parse(req.responseText));
var pt_field = document.getElementById('price-tier-id');
pt_field.value = price_tier_id;
} else {
// 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);
console.log(url);
req.open('GET', url, true);
req.send();
}
function update_table(data) {
console.log(data);
var item_html = '';
for (var i in data.items) {
var item = data.items[i];
// console.log(item);
item_html += '<tr>';
item_html += '<td>' + item.id + '</td>';
item_html += '<td>' + item.name + '</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>';
item_html += '</tr>';
}
var table_body = document.getElementById('table-body');
table_body.innerHTML = item_html;
}
</script>
{% endblock %}