Add page to display trade in prices. #789
This commit is contained in:
parent
4a9dc2a6b2
commit
48058c858d
4 changed files with 104 additions and 42 deletions
|
|
@ -31,37 +31,108 @@ class TradeInPricingController extends Controller
|
||||||
public function index (EntityManagerInterface $em)
|
public function index (EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
// get all the price tiers
|
// get all the price tiers
|
||||||
|
// default price tier so battery sizes data should come from battery size
|
||||||
|
// not from price tier
|
||||||
$price_tiers = $em->getRepository(PriceTier::class)->findAll();
|
$price_tiers = $em->getRepository(PriceTier::class)->findAll();
|
||||||
|
|
||||||
// get all the items/battery sizes
|
// get all the items/battery sizes
|
||||||
$items = $this->getBatterySizes($em);
|
$items = $this->getBatterySizes($em);
|
||||||
|
|
||||||
// get the trade in types
|
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'sets' => [
|
'sets' => [
|
||||||
'price_tiers' => $price_tiers,
|
'price_tiers' => $price_tiers,
|
||||||
'trade_in_types' => TradeInType::getCollection(),
|
|
||||||
],
|
],
|
||||||
'items' => $items,
|
'items' => $items,
|
||||||
];
|
];
|
||||||
|
|
||||||
// TODO: fix display of prices according to trade in type selected
|
|
||||||
// need to set a default trade in type to display? check TradeInType::getCollection
|
|
||||||
return $this->render('trade-in-pricing/form.html.twig', $params);
|
return $this->render('trade-in-pricing/form.html.twig', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @IsGranted("trade_in_pricing.update")
|
||||||
|
*/
|
||||||
|
public function tradeInPrices(EntityManagerInterface $em, $pt_id, $ti_type)
|
||||||
|
{
|
||||||
|
$pt_prices = [];
|
||||||
|
|
||||||
|
// check if default prices are needed
|
||||||
|
if ($pt_id != 0)
|
||||||
|
{
|
||||||
|
// get the price tier
|
||||||
|
$pt = $em->getRepository(PriceTier::class)->find($pt_id);
|
||||||
|
|
||||||
|
// get the trade in prices under the price tier
|
||||||
|
$pt_trade_ins = $pt->getTradeInPrices();
|
||||||
|
|
||||||
|
foreach ($pt_trade_ins as $pt_trade_in)
|
||||||
|
{
|
||||||
|
$meta_info = $pt_trade_in->getAllMetaInfo();
|
||||||
|
|
||||||
|
error_log(print_r($meta_info, true));
|
||||||
|
|
||||||
|
$pt_prices[$pt_trade_in->getItemID()] = $meta_info;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the prices from battery size
|
||||||
|
$bsizes = $em->getRepository(BatterySize::class)->findBy([], ['id' => 'asc']);
|
||||||
|
|
||||||
|
$data_items = [];
|
||||||
|
foreach ($bsizes as $bsize)
|
||||||
|
{
|
||||||
|
$bsize_id = $bsize->getID();
|
||||||
|
$name = $bsize->getName();
|
||||||
|
|
||||||
|
// get the default trade in prices
|
||||||
|
$motolite_tip = $bsize->getTIPriceMotolite();
|
||||||
|
$premium_tip = $bsize->getTIPricePremium();
|
||||||
|
$other_tip = $bsize->getTiPriceOther();
|
||||||
|
|
||||||
|
// check if tier has price for battery size
|
||||||
|
if (isset($pt_prices[$bsize_id]))
|
||||||
|
{
|
||||||
|
$meta_info = $pt_prices[$bsize_id];
|
||||||
|
|
||||||
|
$pt_motolite_tip = $meta_info['motolite'];
|
||||||
|
$pt_premium_tip = $meta_info['premium'];
|
||||||
|
$pt_other_tip = $meta_info['other'];
|
||||||
|
|
||||||
|
// actual prices
|
||||||
|
$motolite_tip = number_format($pt_motolite_tip / 100, 2, '.', '');
|
||||||
|
$premium_tip = number_format($pt_premium_tip / 100, 2, '.', '');
|
||||||
|
$other_tip = number_format($pt_other_tip / 100, 2, '.', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
$actual_motolite_tip = $motolite_tip;
|
||||||
|
$actual_premium_tip = $premium_tip;
|
||||||
|
$actual_other_tip = $other_tip;
|
||||||
|
|
||||||
|
$data_items[] = [
|
||||||
|
'id' => $bsize_id,
|
||||||
|
'name' => $name,
|
||||||
|
'motolite_tip' => $actul_motolite_tip,
|
||||||
|
'premium_tip' => $actual_premium_tip,
|
||||||
|
'other_tip' => $actual_other_tip,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// response
|
||||||
|
return new JsonResponse([
|
||||||
|
'items' => $data_items,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getBatterySizes(EntityManagerInterface $em)
|
protected function getBatterySizes(EntityManagerInterface $em)
|
||||||
{
|
{
|
||||||
// get all battery sizes
|
// get all battery sizes
|
||||||
$b_sizes = $em->getRepository(BatterySize::class)->findBy([], ['name' => 'asc']);
|
$b_sizes = $em->getRepository(BatterySize::class)->findBy([], ['id' => 'asc']);
|
||||||
foreach ($b_sizes as $b_size)
|
foreach ($b_sizes as $b_size)
|
||||||
{
|
{
|
||||||
$b_size_set[$b_size->getID()] = [
|
$b_size_set[$b_size->getID()] = [
|
||||||
'name' => $b_size->getName(),
|
'name' => $b_size->getName(),
|
||||||
'motolite_tiprice' => $b_size->getTIPriceMotolite(),
|
'motolite_tip' => $b_size->getTIPriceMotolite(),
|
||||||
'premium_tiprice' => $b_size->getTIPricePremium(),
|
'premium_tip' => $b_size->getTIPricePremium(),
|
||||||
'other_tiprice' => $b_size->getTIPriceOther(),
|
'other_tip' => $b_size->getTIPriceOther(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,17 @@ class PriceTier
|
||||||
*/
|
*/
|
||||||
protected $item_prices;
|
protected $item_prices;
|
||||||
|
|
||||||
|
// trade in prices under a price tier
|
||||||
|
/**
|
||||||
|
* @ORM\OneToMany(targetEntity="TradeInPrice", mappedBy="price_tier")
|
||||||
|
*/
|
||||||
|
protected $trade_in_prices;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->supported_areas = new ArrayCollection();
|
$this->supported_areas = new ArrayCollection();
|
||||||
$this->items = new ArrayCollection();
|
$this->items = new ArrayCollection();
|
||||||
|
$this->trade_in_prices = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getID()
|
public function getID()
|
||||||
|
|
@ -85,4 +92,9 @@ class PriceTier
|
||||||
return $this->item_prices;
|
return $this->item_prices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTradeInPrices()
|
||||||
|
{
|
||||||
|
return $this->trade_in_prices;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,6 @@ class TradeInPrice
|
||||||
*/
|
*/
|
||||||
protected $price_tier;
|
protected $price_tier;
|
||||||
|
|
||||||
// item type
|
|
||||||
/**
|
|
||||||
* @ORM\ManyToOne(targetEntity="ItemType", inversedBy="items")
|
|
||||||
* @ORM\JoinColumn(name="item_type_id", referencedColumnName="id")
|
|
||||||
*/
|
|
||||||
protected $item_type;
|
|
||||||
|
|
||||||
// battery size id, loosely coupled
|
// battery size id, loosely coupled
|
||||||
/**
|
/**
|
||||||
* @ORM\Column(type="integer")
|
* @ORM\Column(type="integer")
|
||||||
|
|
@ -67,17 +60,6 @@ class TradeInPrice
|
||||||
return $this->price_tier;
|
return $this->price_tier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setItemType(ItemType $item_type)
|
|
||||||
{
|
|
||||||
$this->item_type = $item_type;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getItemType()
|
|
||||||
{
|
|
||||||
return $this->item_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setItemID($item_id)
|
public function setItemID($item_id)
|
||||||
{
|
{
|
||||||
$this->item_id = $item_id;
|
$this->item_id = $item_id;
|
||||||
|
|
|
||||||
|
|
@ -34,17 +34,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</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="trade-in-type-select" name="trade_in_type_list">
|
|
||||||
{% for key, class in sets.trade_in_types %}
|
|
||||||
<option value="{{ key }}">{{ class }} </option>
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -57,7 +46,9 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width: 100px">ID</th>
|
<th style="width: 100px">ID</th>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th style="width: 180px">Price</th>
|
<th style="width: 180px">Motolite</th>
|
||||||
|
<th style="width: 180px">Premium</th>
|
||||||
|
<th style="width: 180px">Other</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="table-body">
|
<tbody id="table-body">
|
||||||
|
|
@ -65,7 +56,15 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ id }}</td>
|
<td>{{ id }}</td>
|
||||||
<td>{{ item.name }} </td>
|
<td>{{ item.name }} </td>
|
||||||
<td></td>
|
<td class="py-1">
|
||||||
|
<input name="motolite_tip[{{ id }}]" class="form-control ca-filter" type="number" value="{{ item.motolite_tip }}" step="0.01">
|
||||||
|
</td>
|
||||||
|
<td class="py-1">
|
||||||
|
<input name="premium_tip[{{ id }}]" class="form-control ca-filter" type="number" value="{{ item.premium_tip }}" step="0.01">
|
||||||
|
</td>
|
||||||
|
<td class="py-1">
|
||||||
|
<input name="other_tip[{{ id }}]" class="form-control ca-filter" type="number" value="{{ item.other_tip }}" step="0.01">
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
@ -89,7 +88,6 @@ initialize();
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
init_price_tier_dropdown();
|
init_price_tier_dropdown();
|
||||||
init_item_type_dropdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function init_price_tier_dropdown() {
|
function init_price_tier_dropdown() {
|
||||||
|
|
@ -128,7 +126,6 @@ function update_table(data) {
|
||||||
item_html += '<tr>';
|
item_html += '<tr>';
|
||||||
item_html += '<td>' + item.id + '</td>';
|
item_html += '<td>' + item.id + '</td>';
|
||||||
item_html += '<td>' + item.name + '</td>';
|
item_html += '<td>' + item.name + '</td>';
|
||||||
item_html += '<td>' + item.item_type + '</td>';
|
|
||||||
item_html += '<td class="py-1">';
|
item_html += '<td class="py-1">';
|
||||||
item_html += '<input name="price[' + item.id + ']" class="form-control ca-filter" type="number" value="' + item.price + '" step="0.01">';
|
item_html += '<input name="price[' + item.id + ']" class="form-control ca-filter" type="number" value="' + item.price + '" step="0.01">';
|
||||||
item_html += '</td>';
|
item_html += '</td>';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue