Fix API output for active subscriptions #799
This commit is contained in:
parent
00697414b0
commit
ef626729c9
1 changed files with 18 additions and 10 deletions
|
|
@ -141,7 +141,7 @@ class VehicleController extends ApiController
|
|||
|
||||
// response
|
||||
return new ApiResponse(true, '', [
|
||||
'vehicle' => $this->generateVehicleInfo($cv, true, true, $paymongo, $params),
|
||||
'vehicle' => $this->generateVehicleInfo($paymongo, $params, $cv, true, true),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ class VehicleController extends ApiController
|
|||
// only get the customer's vehicles whose flag_active is true
|
||||
$cvs = $this->em->getRepository(CustomerVehicle::class)->findBy(['flag_active' => true, 'customer' => $cust]);
|
||||
foreach ($cvs as $cv) {
|
||||
$cv_list[] = $this->generateVehicleInfo($cv, true, true, $paymongo, $params);
|
||||
$cv_list[] = $this->generateVehicleInfo($paymongo, $params, $cv, true, true);
|
||||
}
|
||||
|
||||
// response
|
||||
|
|
@ -422,7 +422,7 @@ class VehicleController extends ApiController
|
|||
];
|
||||
}
|
||||
|
||||
protected function generateVehicleInfo(CustomerVehicle $cv, $include_insurance = false, $include_active_sub = false, PayMongoConnector $paymongo, ParameterBagInterface $params)
|
||||
protected function generateVehicleInfo(PayMongoConnector $paymongo, ParameterBagInterface $params, CustomerVehicle $cv, $include_insurance = false, $include_active_sub = false)
|
||||
{
|
||||
$battery_id = null;
|
||||
if ($cv->getCurrentBattery() != null)
|
||||
|
|
@ -501,6 +501,7 @@ class VehicleController extends ApiController
|
|||
break;
|
||||
}
|
||||
|
||||
// build insurance row
|
||||
$insurance = [
|
||||
'id' => $iobj->getID(),
|
||||
'ext_transaction_id' => $iobj->getExtTransactionId(),
|
||||
|
|
@ -510,12 +511,10 @@ class VehicleController extends ApiController
|
|||
'transaction_status' => $gt->getStatus(),
|
||||
'premium_amount' => (string)bcdiv($gt->getAmount(), 100), // NOTE: hard expressing as string so it's consistent
|
||||
'date_submit' => $iobj->getDateSubmit()->format('Y-m-d H:i:s'),
|
||||
'date_complete' => $date_complete ? $date_complete->format('Y-m-d H:i:s') : null,
|
||||
'date_expire' => $date_expire ? $date_expire->format('Y-m-d H:i:s') : null,
|
||||
'date_complete' => !empty($date_complete) ? $date_complete->format('Y-m-d H:i:s') : null,
|
||||
'date_expire' => !empty($date_expire) ? $date_expire->format('Y-m-d H:i:s') : null,
|
||||
'changelog' => $iobj->getMetadata()['changes'] ?? [],
|
||||
];
|
||||
|
||||
// get information changelog
|
||||
$insurance['changelog'] = $iobj->getMetadata()['changes'] ?? [];
|
||||
}
|
||||
|
||||
$row['latest_insurance'] = $insurance;
|
||||
|
|
@ -525,8 +524,17 @@ class VehicleController extends ApiController
|
|||
if ($include_active_sub) {
|
||||
$active_sub = null;
|
||||
$sobj = $cv->getLatestSubscription();
|
||||
if (!empty($sobj) && $sobj->getStatus() == SubscriptionStatus::ACTIVE) {
|
||||
$active_sub = $sobj;
|
||||
|
||||
if (!empty($sobj)) {
|
||||
$date_cancel = $sobj->getDateCancel();
|
||||
// build subscription row
|
||||
$active_sub = [
|
||||
'email' => $sobj->getEmail(),
|
||||
'date_start' => $sobj->getDateStart()->format('Y-m-d H:i:s'),
|
||||
'date_end' => $sobj->getDateEnd()->format('Y-m-d H:i:s'),
|
||||
'date_cancel' => !empty($date_cancel) ? $date_cancel->format('Y-m-d H:i:s') : null,
|
||||
'status' => $sobj->getStatus(),
|
||||
];
|
||||
}
|
||||
|
||||
$row['active_subscription'] = $active_sub;
|
||||
|
|
|
|||
Loading…
Reference in a new issue