Move getCustomerVehicleInfo to the customer handler service. #270
This commit is contained in:
parent
8f875f1e31
commit
174f0142c9
4 changed files with 136 additions and 69 deletions
|
|
@ -6,23 +6,12 @@ use App\Ramcar\CrudException;
|
|||
|
||||
use App\Service\CustomerHandlerInterface;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\CustomerVehicle;
|
||||
use App\Entity\MobileNumber;
|
||||
use App\Entity\Vehicle;
|
||||
use App\Entity\VehicleManufacturer;
|
||||
use App\Entity\Battery;
|
||||
use App\Entity\BatteryManufacturer;
|
||||
|
||||
use Doctrine\ORM\Query;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
use Catalyst\MenuBundle\Annotation\Menu;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
|
||||
|
|
@ -209,73 +198,26 @@ class CustomerController extends Controller
|
|||
]);
|
||||
}
|
||||
|
||||
public function getCustomerVehicleInfo(Request $req)
|
||||
public function getCustomerVehicleInfo(Request $req, CustomerHandlerInterface $cust_handler)
|
||||
{
|
||||
$this->denyAccessUnlessGranted('jo_in.list', null, 'No access.');
|
||||
|
||||
// get id
|
||||
$id = $req->query->get('id');
|
||||
$result = $cust_handler->getCustomerVehicleInfo($req);
|
||||
|
||||
// get row data
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$obj = $em->getRepository(CustomerVehicle::class)->find($id);
|
||||
|
||||
// make sure this row exists
|
||||
if (empty($obj)) {
|
||||
if ($result == null)
|
||||
{
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'error' => 'The item does not exist'
|
||||
]);
|
||||
}
|
||||
|
||||
$customer = $obj->getCustomer();
|
||||
$vehicle = $obj->getVehicle();
|
||||
$battery = $obj->getCurrentBattery();
|
||||
|
||||
// build response
|
||||
$row = [
|
||||
'customer' => [
|
||||
'id' => $customer->getID(),
|
||||
'first_name' => $customer->getFirstName(),
|
||||
'last_name' => $customer->getLastName(),
|
||||
'customer_notes' => $customer->getCustomerNotes(),
|
||||
'phone_mobile' => $customer->getPhoneMobile(),
|
||||
'phone_landline' => $customer->getPhoneLandline(),
|
||||
'phone_office' => $customer->getPhoneOffice(),
|
||||
'phone_fax' => $customer->getPhoneFax(),
|
||||
],
|
||||
'vehicle' => [
|
||||
'id' => $vehicle->getID(),
|
||||
'mfg_name' => $vehicle->getManufacturer()->getName(),
|
||||
'make' => $vehicle->getMake(),
|
||||
'model_year_from' => $vehicle->getModelYearFrom(),
|
||||
'model_year_to' => $vehicle->getModelYearTo(),
|
||||
'model_year' => $obj->getModelYear(),
|
||||
'color' => $obj->getColor(),
|
||||
'plate_number' => $obj->getPlateNumber(),
|
||||
//'fuel_type' => $obj->getFuelType(),
|
||||
//'status_condition' => $obj->getStatusCondition(),
|
||||
]
|
||||
];
|
||||
|
||||
if (!empty($battery)) {
|
||||
$row['battery'] = [
|
||||
'id' => $battery->getID(),
|
||||
'mfg_name' => $battery->getManufacturer()->getName(),
|
||||
'model_name' => $battery->getModel()->getName(),
|
||||
'size_name' => $battery->getSize()->getName(),
|
||||
'prod_code' => $battery->getProductCode(),
|
||||
'warranty_code' => $obj->getWarrantyCode(),
|
||||
'warranty_expiration' => $obj->getWarrantyExpiration() ? $obj->getWarrantyExpiration()->format("d M Y") : "",
|
||||
'has_motolite_battery' => $obj->hasMotoliteBattery(),
|
||||
'is_active' => $obj->isActive()
|
||||
];
|
||||
else
|
||||
{
|
||||
// response
|
||||
return $this->json([
|
||||
'success' => true,
|
||||
'data' => $result
|
||||
]);
|
||||
}
|
||||
|
||||
// response
|
||||
return $this->json([
|
||||
'success' => true,
|
||||
'data' => $row
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -479,6 +479,66 @@ class CMBCustomerHandler implements CustomerHandlerInterface
|
|||
return $results;
|
||||
}
|
||||
|
||||
// get customer vehicle info
|
||||
public function getCustomerVehicleInfo(Request $req)
|
||||
{
|
||||
// get id
|
||||
$id = $req->query->get('id');
|
||||
|
||||
// get row data
|
||||
$em = $this->em;
|
||||
$obj = $em->getRepository(CustomerVehicle::class)->find($id);
|
||||
|
||||
// make sure this row exists
|
||||
if (empty($obj)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$customer = $obj->getCustomer();
|
||||
$vehicle = $obj->getVehicle();
|
||||
$battery = $obj->getCurrentBattery();
|
||||
|
||||
// build response
|
||||
$row = [
|
||||
'customer' => [
|
||||
'id' => $customer->getID(),
|
||||
'first_name' => $customer->getFirstName(),
|
||||
'last_name' => $customer->getLastName(),
|
||||
'customer_notes' => $customer->getCustomerNotes(),
|
||||
'phone_mobile' => $customer->getPhoneMobile(),
|
||||
'phone_landline' => $customer->getPhoneLandline(),
|
||||
'phone_office' => $customer->getPhoneOffice(),
|
||||
'phone_fax' => $customer->getPhoneFax(),
|
||||
],
|
||||
'vehicle' => [
|
||||
'id' => $vehicle->getID(),
|
||||
'mfg_name' => $vehicle->getManufacturer()->getName(),
|
||||
'make' => $vehicle->getMake(),
|
||||
'model_year_from' => $vehicle->getModelYearFrom(),
|
||||
'model_year_to' => $vehicle->getModelYearTo(),
|
||||
'model_year' => $obj->getModelYear(),
|
||||
'color' => $obj->getColor(),
|
||||
'plate_number' => $obj->getPlateNumber(),
|
||||
]
|
||||
];
|
||||
|
||||
if (!empty($battery)) {
|
||||
$row['battery'] = [
|
||||
'id' => $battery->getID(),
|
||||
'mfg_name' => $battery->getManufacturer()->getName(),
|
||||
'model_name' => $battery->getModel()->getName(),
|
||||
'size_name' => $battery->getSize()->getName(),
|
||||
'prod_code' => $battery->getProductCode(),
|
||||
'warranty_code' => $obj->getWarrantyCode(),
|
||||
'warranty_expiration' => $obj->getWarrantyExpiration() ? $obj->getWarrantyExpiration()->format("d M Y") : "",
|
||||
'has_motolite_battery' => $obj->hasMotoliteBattery(),
|
||||
'is_active' => $obj->isActive()
|
||||
];
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
protected function getTwigTemplate($id)
|
||||
{
|
||||
if (isset($this->template_hash[$id]))
|
||||
|
|
|
|||
|
|
@ -477,6 +477,68 @@ class ResqCustomerHandler implements CustomerHandlerInterface
|
|||
return $results;
|
||||
}
|
||||
|
||||
// get customer vehicle info
|
||||
public function getCustomerVehicleInfo(Request $req)
|
||||
{
|
||||
// get id
|
||||
$id = $req->query->get('id');
|
||||
|
||||
// get row data
|
||||
$em = $this->em;
|
||||
$obj = $em->getRepository(CustomerVehicle::class)->find($id);
|
||||
|
||||
// make sure this row exists
|
||||
if (empty($obj)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$customer = $obj->getCustomer();
|
||||
$vehicle = $obj->getVehicle();
|
||||
$battery = $obj->getCurrentBattery();
|
||||
|
||||
// build response
|
||||
$row = [
|
||||
'customer' => [
|
||||
'id' => $customer->getID(),
|
||||
'first_name' => $customer->getFirstName(),
|
||||
'last_name' => $customer->getLastName(),
|
||||
'customer_notes' => $customer->getCustomerNotes(),
|
||||
'phone_mobile' => $customer->getPhoneMobile(),
|
||||
'phone_landline' => $customer->getPhoneLandline(),
|
||||
'phone_office' => $customer->getPhoneOffice(),
|
||||
'phone_fax' => $customer->getPhoneFax(),
|
||||
],
|
||||
'vehicle' => [
|
||||
'id' => $vehicle->getID(),
|
||||
'mfg_name' => $vehicle->getManufacturer()->getName(),
|
||||
'make' => $vehicle->getMake(),
|
||||
'model_year_from' => $vehicle->getModelYearFrom(),
|
||||
'model_year_to' => $vehicle->getModelYearTo(),
|
||||
'model_year' => $obj->getModelYear(),
|
||||
'color' => $obj->getColor(),
|
||||
'plate_number' => $obj->getPlateNumber(),
|
||||
'fuel_type' => $obj->getFuelType(),
|
||||
'status_condition' => $obj->getStatusCondition(),
|
||||
]
|
||||
];
|
||||
|
||||
if (!empty($battery)) {
|
||||
$row['battery'] = [
|
||||
'id' => $battery->getID(),
|
||||
'mfg_name' => $battery->getManufacturer()->getName(),
|
||||
'model_name' => $battery->getModel()->getName(),
|
||||
'size_name' => $battery->getSize()->getName(),
|
||||
'prod_code' => $battery->getProductCode(),
|
||||
'warranty_code' => $obj->getWarrantyCode(),
|
||||
'warranty_expiration' => $obj->getWarrantyExpiration() ? $obj->getWarrantyExpiration()->format("d M Y") : "",
|
||||
'has_motolite_battery' => $obj->hasMotoliteBattery(),
|
||||
'is_active' => $obj->isActive()
|
||||
];
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
protected function getTwigTemplate($id)
|
||||
{
|
||||
if (isset($this->template_hash[$id]))
|
||||
|
|
|
|||
|
|
@ -29,4 +29,7 @@ interface CustomerHandlerInterface
|
|||
|
||||
// get customer vehicles
|
||||
public function getCustomerVehicles(Request $req);
|
||||
|
||||
// get customer vehicle info
|
||||
public function getCustomerVehicleInfo(Request $req);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue