Changed the input for trade in items to battery size. #03
This commit is contained in:
parent
2f9ee4ec67
commit
4ccdd29ae6
5 changed files with 47 additions and 54 deletions
|
|
@ -103,21 +103,21 @@ class BatterySales implements InvoiceRuleInterface
|
||||||
// check if this is a valid battery
|
// check if this is a valid battery
|
||||||
foreach ($invoice_items as $item)
|
foreach ($invoice_items as $item)
|
||||||
{
|
{
|
||||||
$battery = $this->em->getRepository(Battery::class)->find($item['battery']);
|
if (isset($item['battery']))
|
||||||
|
|
||||||
if (empty($battery))
|
|
||||||
{
|
{
|
||||||
$error = 'Invalid battery specified.';
|
$battery = $this->em->getRepository(Battery::class)->find($item['battery']);
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// quantity
|
if (empty($battery))
|
||||||
$qty = $item['quantity'];
|
{
|
||||||
if ($qty < 1)
|
$error = 'Invalid battery specified.';
|
||||||
continue;
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
// quantity
|
||||||
|
$qty = $item['quantity'];
|
||||||
|
if ($qty < 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (empty($item['trade_in']))
|
|
||||||
{
|
|
||||||
$trade_in = null;
|
$trade_in = null;
|
||||||
$criteria->addEntry($battery, $trade_in, $qty);
|
$criteria->addEntry($battery, $trade_in, $qty);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use App\InvoiceRuleInterface;
|
||||||
use App\Ramcar\TradeInType;
|
use App\Ramcar\TradeInType;
|
||||||
use App\Ramcar\ServiceType;
|
use App\Ramcar\ServiceType;
|
||||||
|
|
||||||
use App\Entity\Battery;
|
use App\Entity\BatterySize;
|
||||||
|
|
||||||
class TradeIn implements InvoiceRuleInterface
|
class TradeIn implements InvoiceRuleInterface
|
||||||
{
|
{
|
||||||
|
|
@ -41,16 +41,7 @@ class TradeIn implements InvoiceRuleInterface
|
||||||
|
|
||||||
if ($trade_in_type != null)
|
if ($trade_in_type != null)
|
||||||
{
|
{
|
||||||
// at this point, entry is a trade in
|
$batt_size = $entry['battery_size'];
|
||||||
// need to check if battery (coming from CRM) is set
|
|
||||||
// or battery_size is set (coming from rider app)
|
|
||||||
//if (isset($entry['battery']))
|
|
||||||
//{
|
|
||||||
// $battery = $entry['battery'];
|
|
||||||
// $batt_size = $battery->getSize();
|
|
||||||
//}
|
|
||||||
//else
|
|
||||||
$batt_size = $entry['battery_size'];
|
|
||||||
|
|
||||||
$ti_rate = $this->getTradeInRate($batt_size, $trade_in_type);
|
$ti_rate = $this->getTradeInRate($batt_size, $trade_in_type);
|
||||||
|
|
||||||
|
|
@ -80,8 +71,7 @@ class TradeIn implements InvoiceRuleInterface
|
||||||
|
|
||||||
public function validateInvoiceItems($criteria, $invoice_items)
|
public function validateInvoiceItems($criteria, $invoice_items)
|
||||||
{
|
{
|
||||||
// check service type. Only battery sales and battery warranty should have invoice items. Since this is the battery sales
|
// check service type. Only battery sales and battery warranty should have invoice items.
|
||||||
// rule, we only check for battery sales.
|
|
||||||
$stype = $criteria->getServiceType();
|
$stype = $criteria->getServiceType();
|
||||||
if ($stype != ServiceType::BATTERY_REPLACEMENT_NEW)
|
if ($stype != ServiceType::BATTERY_REPLACEMENT_NEW)
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -92,25 +82,27 @@ class TradeIn implements InvoiceRuleInterface
|
||||||
// check if this is a valid battery
|
// check if this is a valid battery
|
||||||
foreach ($invoice_items as $item)
|
foreach ($invoice_items as $item)
|
||||||
{
|
{
|
||||||
$battery = $this->em->getRepository(Battery::class)->find($item['battery']);
|
if (isset($item['battery_size']))
|
||||||
|
|
||||||
if (empty($battery))
|
|
||||||
{
|
{
|
||||||
$error = 'Invalid battery specified.';
|
$battery_size = $this->em->getRepository(BatterySize::class)->find($item['battery_size']);
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// quantity
|
if (empty($battery_size))
|
||||||
$qty = $item['quantity'];
|
{
|
||||||
if ($qty < 1)
|
$error = 'Invalid battery size specified.';
|
||||||
continue;
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
// if this is a trade in, add trade in
|
// quantity
|
||||||
if (!empty($item['trade_in']) && TradeInType::validate($item['trade_in']))
|
$qty = $item['quantity'];
|
||||||
{
|
if ($qty < 1)
|
||||||
$trade_in = $item['trade_in'];
|
continue;
|
||||||
$battery_size = $battery->getSize();
|
|
||||||
$criteria->addTradeInEntry($battery_size, $trade_in, $qty);
|
// check if trade in is set and if trade in type if valid
|
||||||
|
if (!empty($item['trade_in']) && TradeInType::validate($item['trade_in']))
|
||||||
|
{
|
||||||
|
$trade_in = $item['trade_in'];
|
||||||
|
$criteria->addTradeInEntry($battery_size, $trade_in, $qty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ use App\Entity\EmergencyType;
|
||||||
use App\Entity\OwnershipType;
|
use App\Entity\OwnershipType;
|
||||||
use App\Entity\CustomerLocation;
|
use App\Entity\CustomerLocation;
|
||||||
use App\Entity\Battery;
|
use App\Entity\Battery;
|
||||||
|
use App\Entity\BatterySize;
|
||||||
|
|
||||||
use App\Ramcar\ServiceType;
|
use App\Ramcar\ServiceType;
|
||||||
use App\Ramcar\TradeInType;
|
use App\Ramcar\TradeInType;
|
||||||
|
|
@ -3560,15 +3561,15 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface
|
||||||
$params['trade_in_bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll();
|
$params['trade_in_bmfgs'] = $em->getRepository(BatteryManufacturer::class)->findAll();
|
||||||
$params['promos'] = $em->getRepository(Promo::class)->findAll();
|
$params['promos'] = $em->getRepository(Promo::class)->findAll();
|
||||||
|
|
||||||
// list of batteries for trade-in
|
// list of battery sizes for trade-in
|
||||||
$ti_batteries = $em->getRepository(Battery::class)->findAll();
|
$ti_batt_sizes = $em->getRepository(BatterySize::class)->findAll();
|
||||||
$trade_in_batteries = [];
|
$trade_in_batt_sizes = [];
|
||||||
foreach ($ti_batteries as $ti_battery)
|
foreach ($ti_batt_sizes as $ti_batt_size)
|
||||||
{
|
{
|
||||||
$battery_name = $ti_battery->getModel()->getName() . ' ' . $ti_battery->getSize()->getName();
|
$batt_size_name = $ti_batt_size->getName();
|
||||||
$trade_in_batteries[$ti_battery->getID()] = $battery_name;
|
$trade_in_batt_sizes[$ti_batt_size->getID()] = $batt_size_name;
|
||||||
}
|
}
|
||||||
$params['trade_in_batteries'] = $trade_in_batteries;
|
$params['trade_in_batt_sizes'] = $trade_in_batt_sizes;
|
||||||
|
|
||||||
// list of emergency types
|
// list of emergency types
|
||||||
$e_types = $em->getRepository(EmergencyType::class)->findBy([], ['name' => 'ASC']);
|
$e_types = $em->getRepository(EmergencyType::class)->findBy([], ['name' => 'ASC']);
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-3">
|
<div class="col-lg-3">
|
||||||
<label for="invoice-trade-in-battery">Battery For Trade In</label>
|
<label for="invoice-trade-in-battery-size">Battery Size For Trade In</label>
|
||||||
<select class="form-control m-input" id="invoice-trade-in-battery" data-value="">
|
<select class="form-control m-input" id="invoice-trade-in-battery-size" data-value="">
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
{% for id, battery_name in trade_in_batteries %}
|
{% for id, batt_size_name in trade_in_batt_sizes %}
|
||||||
<option value="{{ id }}">{{ battery_name }}</option>
|
<option value="{{ id }}">{{ batt_size_name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
// add trade in battery to invoice
|
// add trade in battery to invoice
|
||||||
$('#btn-add-trade-in-to-invoice').click(function() {
|
$('#btn-add-trade-in-to-invoice').click(function() {
|
||||||
var bmfg = $("#invoice-trade-in-bmfg").val();
|
var bmfg = $("#invoice-trade-in-bmfg").val();
|
||||||
var battery = $("#invoice-trade-in-battery").val();
|
var battery_size = $("#invoice-trade-in-battery-size").val();
|
||||||
var tradeIn = $("#invoice-trade-in-type").val();
|
var tradeIn = $("#invoice-trade-in-type").val();
|
||||||
var qty = $("#invoice-trade-in-quantity").val();
|
var qty = $("#invoice-trade-in-quantity").val();
|
||||||
|
|
||||||
// add to invoice array
|
// add to invoice array
|
||||||
invoiceItems.push({
|
invoiceItems.push({
|
||||||
battery: battery,
|
battery_size: battery_size,
|
||||||
quantity: qty,
|
quantity: qty,
|
||||||
trade_in: tradeIn,
|
trade_in: tradeIn,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue