Add processing of trade in items from rider app. #783
This commit is contained in:
parent
c9057b9617
commit
8ca7292a25
4 changed files with 45 additions and 18 deletions
|
|
@ -23,6 +23,7 @@ use App\Entity\BatterySize;
|
||||||
use App\Entity\RiderAPISession;
|
use App\Entity\RiderAPISession;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use App\Entity\ApiUser as APIUser;
|
use App\Entity\ApiUser as APIUser;
|
||||||
|
use App\Entity\JobOrder;
|
||||||
|
|
||||||
use App\Service\RedisClientProvider;
|
use App\Service\RedisClientProvider;
|
||||||
use App\Service\RiderCache;
|
use App\Service\RiderCache;
|
||||||
|
|
@ -1205,10 +1206,9 @@ class RiderAppController extends ApiController
|
||||||
// need to get the existing invoice items using jo id and invoice id
|
// need to get the existing invoice items using jo id and invoice id
|
||||||
$existing_ii = $this->getInvoiceItems($em, $jo_id);
|
$existing_ii = $this->getInvoiceItems($em, $jo_id);
|
||||||
|
|
||||||
// $this->generateUpdatedInvoice($em, $jo_id, $existing_ii, $trade_in_items);
|
$this->generateUpdatedInvoice($em, $ic, $jo_id, $existing_ii, $ti_items);
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
return new APIResponse(true, 'Job order updated.', $data);
|
return new APIResponse(true, 'Job order updated.', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1354,7 +1354,7 @@ class RiderAppController extends ApiController
|
||||||
return new APIResponse(true, 'Job order service changed.', $data);
|
return new APIResponse(true, 'Job order service changed.', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function generateUpdatedInvoice(EntityManagerInterface $em, $jo_id, $existing_ii, $trade_in_items)
|
protected function generateUpdatedInvoice(EntityManagerInterface $em, InvoiceGeneratorInterface $ic, $jo_id, $existing_ii, $trade_in_items)
|
||||||
{
|
{
|
||||||
// get the job order since we need info in the JO for the invoice criteria
|
// get the job order since we need info in the JO for the invoice criteria
|
||||||
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
|
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
|
||||||
|
|
@ -1370,7 +1370,7 @@ class RiderAppController extends ApiController
|
||||||
|
|
||||||
// get the promo id from existing invoice item
|
// get the promo id from existing invoice item
|
||||||
$promo_id = $existing_ii['promo_id'];
|
$promo_id = $existing_ii['promo_id'];
|
||||||
if ($promo_id = null)
|
if ($promo_id == null)
|
||||||
$promo = null;
|
$promo = null;
|
||||||
else
|
else
|
||||||
$promo = $em->getRepository(Promo::class)->find($promo_id);
|
$promo = $em->getRepository(Promo::class)->find($promo_id);
|
||||||
|
|
@ -1404,8 +1404,13 @@ class RiderAppController extends ApiController
|
||||||
// add the trade in items to the criteria
|
// add the trade in items to the criteria
|
||||||
foreach ($trade_in_items as $ti_item)
|
foreach ($trade_in_items as $ti_item)
|
||||||
{
|
{
|
||||||
// TODO: need to discuss how to store since what we have is battery size
|
$batt_size_id = $ti_item['battery_size_id'];
|
||||||
// and we're supposed to store battery
|
$qty = $ti_item['qty'];
|
||||||
|
$trade_in_type = $ti_item['trade_in_type'];
|
||||||
|
|
||||||
|
$batt_size = $em->getRepository(BatterySize::class)->find($batt_size_id);
|
||||||
|
|
||||||
|
$icrit->addTradeInEntry($batt_size, $trade_in_type, $qty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// call generateInvoice
|
// call generateInvoice
|
||||||
|
|
|
||||||
|
|
@ -36,18 +36,21 @@ class BatterySales implements InvoiceRuleInterface
|
||||||
$entries = $criteria->getEntries();
|
$entries = $criteria->getEntries();
|
||||||
foreach($entries as $entry)
|
foreach($entries as $entry)
|
||||||
{
|
{
|
||||||
$batt = $entry['battery'];
|
|
||||||
$qty = $entry['qty'];
|
$qty = $entry['qty'];
|
||||||
$trade_in = null;
|
$trade_in = null;
|
||||||
|
|
||||||
|
// check if entry is for trade in
|
||||||
if (isset($entry['trade_in']))
|
if (isset($entry['trade_in']))
|
||||||
$trade_in = $entry['trade_in'];
|
$trade_in = $entry['trade_in'];
|
||||||
|
|
||||||
$size = $batt->getSize();
|
// entry is a battery purchase
|
||||||
|
|
||||||
if ($trade_in == null)
|
if ($trade_in == null)
|
||||||
{
|
{
|
||||||
// battery purchase
|
// safe to get entry with battery key since CRM and apps
|
||||||
|
// will set this for a battery purchase and trade_in will
|
||||||
|
// will not be set
|
||||||
|
$batt = $entry['battery'];
|
||||||
|
|
||||||
$price = $batt->getSellingPrice();
|
$price = $batt->getSellingPrice();
|
||||||
|
|
||||||
$items[] = [
|
$items[] = [
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ class TradeIn implements InvoiceRuleInterface
|
||||||
$entries = $criteria->getEntries();
|
$entries = $criteria->getEntries();
|
||||||
foreach($entries as $entry)
|
foreach($entries as $entry)
|
||||||
{
|
{
|
||||||
$batt = $entry['battery'];
|
|
||||||
$qty = $entry['qty'];
|
$qty = $entry['qty'];
|
||||||
$trade_in_type = null;
|
$trade_in_type = null;
|
||||||
|
|
||||||
|
|
@ -30,7 +29,18 @@ class TradeIn implements InvoiceRuleInterface
|
||||||
|
|
||||||
if ($trade_in_type != null)
|
if ($trade_in_type != null)
|
||||||
{
|
{
|
||||||
$ti_rate = $this->getTradeInRate($batt, $trade_in_type);
|
// at this point, entry is a trade in
|
||||||
|
// 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);
|
||||||
|
|
||||||
$qty_ti = bcmul($ti_rate, $qty, 2);
|
$qty_ti = bcmul($ti_rate, $qty, 2);
|
||||||
|
|
||||||
|
|
@ -41,7 +51,7 @@ class TradeIn implements InvoiceRuleInterface
|
||||||
|
|
||||||
$items[] = [
|
$items[] = [
|
||||||
'qty' => $qty,
|
'qty' => $qty,
|
||||||
'title' => $this->getTitle($batt, $trade_in_type),
|
'title' => $this->getTitle($batt_size, $trade_in_type),
|
||||||
'price' => $price,
|
'price' => $price,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
@ -60,10 +70,8 @@ class TradeIn implements InvoiceRuleInterface
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTradeInRate($battery, $trade_in_type)
|
protected function getTradeInRate($size, $trade_in_type)
|
||||||
{
|
{
|
||||||
$size = $battery->getSize();
|
|
||||||
|
|
||||||
switch ($trade_in_type)
|
switch ($trade_in_type)
|
||||||
{
|
{
|
||||||
case TradeInType::MOTOLITE:
|
case TradeInType::MOTOLITE:
|
||||||
|
|
@ -77,9 +85,9 @@ class TradeIn implements InvoiceRuleInterface
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTitle($battery, $trade_in_type)
|
protected function getTitle($battery_size, $trade_in_type)
|
||||||
{
|
{
|
||||||
$title = 'Trade-in ' . TradeInType::getName($trade_in_type) . ' ' . $battery->getSize()->getName() . ' battery';
|
$title = 'Trade-in ' . TradeInType::getName($trade_in_type) . ' ' . $battery_size->getName() . ' battery';
|
||||||
|
|
||||||
return $title;
|
return $title;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,17 @@ class InvoiceCriteria
|
||||||
$this->entries[] = $entry;
|
$this->entries[] = $entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addTradeInEntry($battery_size, $trade_in, $qty)
|
||||||
|
{
|
||||||
|
$entry = [
|
||||||
|
'battery_size' => $battery_size,
|
||||||
|
'trade_in' => $trade_in,
|
||||||
|
'qty' => $qty
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->entries[] = $entry;
|
||||||
|
}
|
||||||
|
|
||||||
public function getEntries()
|
public function getEntries()
|
||||||
{
|
{
|
||||||
return $this->entries;
|
return $this->entries;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue