src/AppBundle/Controller/VehicleController.php line 409

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller;
  3. use mysql_xdevapi\Exception;
  4. use \Pimcore\Controller\FrontendController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use \Pimcore\Model\DataObject;
  9. use AppBundle\Service\UtilService;
  10. use AppBundle\Service\VehicleService;
  11. use Pimcore\Model\DataObject\Data\BlockElement;
  12. use Pimcore\Model\Element\Service;
  13. use Pimcore\Log\ApplicationLogger;
  14. class VehicleController extends FrontendController
  15. {
  16.     /**
  17.      * @Route("/api/getvehicleinfo", methods={"POST","HEAD"})
  18.      */
  19.     public function getVehicleInfoAction(Request $request)
  20.     {
  21.         $requestArr json_decode($request->getContent(),true);
  22.         $lcdvCode $requestArr['lcdv16'];
  23.         $vechiles DataObject\Vehicle::getByLcdv16($lcdvCode);
  24.         $vechileArr = [];
  25.         if($vechiles->getCount() > 0){
  26.             $vechilesData $vechiles->load();
  27.             foreach ($vechilesData as $vehicle){
  28.                 $tmpArr = [];
  29.                 $tmpArr['id'] = $vehicle->getId();
  30.                 $tmpArr['lcdv16'] = $vehicle->getLcdv16();
  31.                 $tmpArr['startDate'] = $vehicle->getStartDate()->toDateString('Y-m-d');
  32.                 $tmpArr['endDate'] = $vehicle->getEndDate()->toDateString('Y-m-d');
  33.                 $additionalInfoData $vehicle->getAdditonalInfoData()->getItems();
  34.                 $tmpArr['additionalLcdvInfo'] = [];
  35.                 foreach($additionalInfoData as $additionalInfo){
  36.                     $tmpAdditionalInfo = [];
  37.                     $charRelData $additionalInfo->getCharacteristics();
  38.                     $tmpAdditionalInfo['characteristicsValue'] = $additionalInfo->getCharacteristicsValue();
  39.                     $tmpAdditionalInfo['charValDesc'] = $additionalInfo->getCharValDesc();
  40.                     $tmpAdditionalInfo['identifier'] = $additionalInfo->getIdentifier();
  41.                     $tmpAdditionalInfo['dependent'] = $additionalInfo->getDependent();
  42.                     $tmpAdditionalInfo['characteristics'] = $charRelData->getCharacteristics();
  43.                     $tmpAdditionalInfo['characteristicsDescription'] = $charRelData->getCharacteristicsDesc();
  44.                     array_push($tmpArr['additionalLcdvInfo'],$tmpAdditionalInfo);
  45.                 }
  46.                 array_push($vechileArr,$tmpArr);
  47.             }
  48.             $response = new Response();
  49.             $response->setContent(json_encode(array('success' => 'true''errors' => [], 'data' => $vechileArr)));
  50.             $response->setStatusCode(200);
  51.             $response->headers->set('Content-Type''application/json');
  52.             return $response;
  53.             //return $response;
  54.         }else{
  55.             $response = new Response();
  56.             $response->setContent(json_encode(array('success' => 'false''errors' => ['Vehicle information not available'], 'data' => [])));
  57.             $response->setStatusCode(404);
  58.             $response->headers->set('Content-Type''application/json');
  59.             return $response;
  60.             //return $response;
  61.         }
  62.     }
  63.     /**
  64.      * @Route("/api/testconnection", methods={"GET","HEAD"})
  65.      */
  66.     public function testConnectionAction(Request $request)
  67.     {
  68.         $response = new Response();
  69.         $response->setContent(json_encode(array('success' => 'true''message' => 'connection successfull')));
  70.         $response->setStatusCode(200);
  71.         $response->headers->set('Content-Type''application/json');
  72.         return $response;
  73.     }
  74.     public function viewVehicleAction(Request $request)
  75.     {
  76.         $vechiles = new DataObject\Vehicle\Listing();
  77.         //$this->view->vehicles = $vechiles->getObjects();
  78.         $vehicleArr = [];
  79.         $vehicleData $vechiles->getObjects();
  80.         foreach ($vehicleData as $vehicle){
  81.             $tmpData['id'] = $vehicle->getId();
  82.             $tmpData['lcdv16'] = $vehicle->getLcdv16();
  83.             $tmpData['startDate'] = $vehicle->getStartDate()->toDateString('Y-m-d');
  84.             $tmpData['endDate'] = $vehicle->getEndDate()->toDateString('Y-m-d');
  85.             $tmpData['lcdv16Info'] = [];
  86.             $lcdvData $vehicle->getLcdv16Data()->getItems();
  87.             foreach($lcdvData as $lcdv){
  88.                 $tmpLcdv16Info = [];
  89.                 $charRelData $lcdv->getCharacteristics();
  90.                 $tmpLcdv16Info['characteristicsValue'] = $lcdv->getCharacteristicsValue();
  91.                 $tmpLcdv16Info['charValDesc'] = $lcdv->getCharValDesc();
  92.                 $tmpLcdv16Info['identifier'] = $lcdv->getIdentifier();
  93.                 $tmpLcdv16Info['dependent'] = $lcdv->getDependent();
  94.                 $tmpLcdv16Info['characteristics'] = $charRelData->getCharacteristics();
  95.                 $tmpLcdv16Info['characteristicsDescription'] = $charRelData->getCharacteristicsDesc();
  96.                 array_push($tmpData['lcdv16Info'],$tmpLcdv16Info);
  97.             }
  98.             $additionalInfoData $vehicle->getAdditonalInfoData()->getItems();
  99.             $tmpData['additionalLcdvInfo'] = [];
  100.             foreach($additionalInfoData as $additionalInfo){
  101.                 $tmpAdditionalInfo = [];
  102.                 $charRelData $additionalInfo->getCharacteristics();
  103.                 $tmpAdditionalInfo['characteristicsValue'] = $additionalInfo->getCharacteristicsValue();
  104.                 $tmpAdditionalInfo['charValDesc'] = $additionalInfo->getCharValDesc();
  105.                 $tmpAdditionalInfo['identifier'] = $additionalInfo->getIdentifier();
  106.                 $tmpAdditionalInfo['dependent'] = $additionalInfo->getDependent();
  107.                 $tmpAdditionalInfo['characteristics'] = $charRelData->getCharacteristics();
  108.                 $tmpAdditionalInfo['characteristicsDescription'] = $charRelData->getCharacteristicsDesc();
  109.                 array_push($tmpData['additionalLcdvInfo'],$tmpAdditionalInfo);
  110.             }
  111.             //Exterior Colors
  112.             $exteriorColorData $vehicle->getExteriorColorCombinations();
  113.             $exteriorColorArr = [];
  114.             foreach($exteriorColorData as $exteriorColor){
  115.                 $exteriorColorArr[] = array("code"=>$exteriorColor[0],"name"=>$exteriorColor[1]);
  116.             }
  117.             $tmpData['exteriorColors'] = $exteriorColorArr;
  118.             //Interior Colors
  119.             $interiorColorData $vehicle->getInteriorColorCombo();
  120.             $interiorColorArr = [];
  121.             foreach($interiorColorData as $interiorColor){
  122.                 $interiorColorArr[] = array("code"=>$interiorColor[0],"name"=>$interiorColor[1]);
  123.             }
  124.             $tmpData['interiorColors'] = $interiorColorArr;
  125.             array_push($vehicleArr$tmpData);
  126.         }
  127.         $this->view->vehicles $vehicleArr;
  128.     }
  129.     /**
  130.      * @Route("/api/receivevehicleprice", methods={"POST","HEAD"})
  131.      */
  132.     public function receiveVehiclePriceAction(Request $request)
  133.     {
  134.         $vehiclePriceData json_decode$request->getContent(), true);
  135.         if(count($vehiclePriceData) > && count($vehiclePriceData['priceMasterItems']) > 0){
  136.             try{
  137.                 $date = new \Carbon\Carbon();
  138.                 $utilService = new UtilService();
  139.                 $storedId = [];
  140.                 foreach($vehiclePriceData['priceMasterItems'] as $price){
  141.                     $priceCheck DataObject\VehiclePrice::getByMaterial($price['MATERIAL']);
  142.                     if($priceCheck->getCount() > 0){
  143.                         $newObject $priceCheck->load()[0];
  144.                     }else {
  145.                         $newObject = new DataObject\VehiclePrice();
  146.                         $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($price['MATERIAL'] . '-' $price['VALID_BEG'], 'object'));
  147.                         $folderId $utilService->createFolderPath('VehiclePrices');
  148.                         $newObject->setParentId($folderId);
  149.                     }
  150.                     $newObject->setCondType($price['COND_TYP']);
  151.                     $newObject->setSaleOrg($price['SALE_ORG']);
  152.                     $newObject->setDistCha($price['DIST_CHA']);
  153.                     $regionObj DataObject\Region::getByCode($price['REGION']);
  154.                     $newObject->setRegion($regionObj->getObjects()[0]);
  155.                     $countryObj DataObject\Country::getByCtr($price['COUNTRY']);
  156.                     $newObject->setCountry($countryObj->getObjects()[0]);
  157.                     $newObject->setCity($price['CITY']);
  158.                     $newObject->setMaterial($price['MATERIAL']);
  159.                     $newObject->setVariant($price['VARIANT']);
  160.                     $date= new \DateTime($price['VALID_END']);
  161.                     $newObject->setValidEnd($date);
  162.                     $startDate= new \DateTime($price['VALID_BEG']);
  163.                     $newObject->setValidStart($startDate);
  164.                     $newObject->setAmount(floatval($price['AMOUNT']));
  165.                     $currencyObj DataObject\Currency::getByCrcy($price['CURRENCY']);
  166.                     $newObject->setCurrency($currencyObj->getObjects()[0]);
  167.                     $newObject->setPublished(true);
  168.                     $newObject->save();
  169.                     array_push($storedId,$newObject->getId());
  170.                 }
  171.                 $response = new Response();
  172.                 $response->setContent(json_encode(array('id'=>$storedId'errors' => [], 'success' => 'true')));
  173.                 $response->setStatusCode(201);
  174.                 $response->headers->set('Content-Type''application/json');
  175.                 return $response;
  176.             }catch (\Exception $e){
  177.                 $response = new Response();
  178.                 $response->setContent(json_encode(array('success' => 'false''errors' => [$e->getMessage()])));
  179.                 $response->setStatusCode(500);
  180.                 $response->headers->set('Content-Type''application/json');
  181.                 return $response;
  182.             }
  183.         }else{
  184.             $response = new Response();
  185.             $response->setContent(json_encode(array('success' => 'false''errors' => ['Unexpected Request Format'])));
  186.             $response->setStatusCode(400);
  187.             $response->headers->set('Content-Type''application/json');
  188.             return $response;
  189.         }
  190.     }
  191.     /**
  192.      * @Route("/api/receivevehiclemasterlcdv24", methods={"POST","HEAD"})
  193.      */
  194.     public function receiveVehicleMasterLcdv24(Request $requestApplicationLogger $logger){
  195.         $utilService = new UtilService();
  196.         $isNew true;
  197.         \Pimcore\Log\Simple::log('vehiclesMasterLCDV24'$request->getContent() . PHP_EOL);
  198.         $logger->info('LCDV24 Data Received',['data'=>$request->getContent()]);
  199.         $vehiclesMasterData json_decode$request->getContent());
  200.         if(!empty($vehiclesMasterData) && count($vehiclesMasterData->DATA) > && count($vehiclesMasterData->DATA[0]->item) > 0){
  201.             $lcdv24Arr $vehiclesMasterData->DATA[0]->item;
  202.             foreach($lcdv24Arr as $lcdv24Item){
  203.                 $vehicleMasterCheck DataObject\VehicleLcdv24::getByLcdv24($lcdv24Item->LCDV24);
  204.                 if($vehicleMasterCheck->getCount() > 0){
  205.                     $newObject $vehicleMasterCheck->load()[0];
  206.                     $isNew false;
  207.                 }else{
  208.                     $newObject = new DataObject\VehicleLcdv24();
  209.                     $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($lcdv24Item->LCDV24'object'));
  210.                     $folderId $utilService->createFolderPath('LCDV24');
  211.                     $newObject->setParentId($folderId);
  212.                 }
  213.                 $startDateData str_split($lcdv24Item->START_Date,4);
  214.                 $startYear =  $startDateData[0];
  215.                 $startMonthData str_split($startDateData[1],2);
  216.                 $date = new \DateTime($startMonthData[1].'.'.$startMonthData[0].'.'.$startYear);
  217.                 $newObject->setStartDate($date);
  218.                 $endDateData str_split($lcdv24Item->END_Date,4);
  219.                 $endYear =  $endDateData[0];
  220.                 $endMonthData str_split($endDateData[1],2);
  221.                 $dateEnd = new \DateTime($endMonthData[1].'.'.$endMonthData[0].'.'.$endYear);
  222.                 $newObject->setEndDate($dateEnd);
  223.                 $newObject->setLcdv24($lcdv24Item->LCDV24);
  224.                 $newObject->setPublished(true);
  225.                 $newObject->save();
  226.             }
  227.             exit;
  228.         }
  229.     }
  230.     /**
  231.      * @Route("/api/receivevehiclemasterinfo", methods={"POST","HEAD"})
  232.      */
  233.     public function receiveVehicleMasterInfoAction(Request $requestApplicationLogger $logger)
  234.     {
  235.         \Pimcore\Log\Simple::log('vehiclesMasterData'$request->getContent() . PHP_EOL);
  236.         $logger->info('Vehicle Data Received',['data'=>$request->getContent()]);
  237.         //$logger->
  238.         $vehiclesMasterData json_decode$request->getContent());
  239.         $vehiclesMasterData $vehiclesMasterData[0]->vehicle;
  240.         $isNew true;
  241.         $utilService = new UtilService();
  242.         $storedId = [];
  243.         // if(count($vehiclesMasterData) > 0){
  244.         if(!empty($vehiclesMasterData)){
  245.             $storedId = [];
  246.             foreach($vehiclesMasterData as $vehicleMasterArr){
  247.                 try{
  248.                    // $vehicleMasterArr = $vehiclesMasterData['vehicle'];
  249.                     $lcdv           $vehicleMasterArr->LCDV;
  250.                     $startDate      $vehicleMasterArr->START;
  251.                     $endDate        $vehicleMasterArr->END;
  252.                     $attributesData     $vehicleMasterArr->ATTRIBUTES->item;
  253.                     $validityDate       $attributesData->VALIDITYSTART;
  254.                     $validityEndDate    $attributesData->VALIDITYEND;
  255.                     $coupletData        $attributesData->COUPLET->item;
  256.                     $vehicleMasterCheck DataObject\VehicleMaster::getByLcdv($lcdv);
  257.                     $vehicleMasterCheck->setUnpublished(true);
  258.                     if($vehicleMasterCheck->getCount() > 0){
  259.                         $newObject $vehicleMasterCheck->load()[0];
  260.                         $isNew false;
  261.                     }else{
  262.                         $newObject = new DataObject\VehicleMaster();
  263.                         $newObject->setKey(\Pimcore\Model\Element\Service::getValidKey($lcdv'object'));
  264.                         $folderId $utilService->createFolderPath('Vehicle Master');
  265.                         $newObject->setParentId($folderId);
  266.                     }
  267.                     $newObject->setLcdv($lcdv);
  268.                     $date = new \DateTime($startDate);
  269.                     $newObject->setStartDate($date);
  270.                     $dateEnd = new \DateTime($endDate);
  271.                     $newObject->setEndDate($dateEnd);
  272.                     $vDate = new \DateTime($validityDate);
  273.                     $newObject->setValidityStart($vDate);
  274.                     $vDateEnd= new \DateTime($validityEndDate);
  275.                     $newObject->setValidityEnd($vDateEnd);
  276.                     foreach ((array)$coupletData as $key => $coupletTypes) {
  277.                         $items = new DataObject\Fieldcollection();
  278.                         $exteriorColorType = [];
  279.                         $exteriorColor = [];
  280.                         $interiorColorType = [];
  281.                         $interiorColor = [];
  282.                         $descriptiveOptions = [];
  283.                         $personalOptions = [];
  284.                         foreach ($coupletTypes->items as  $valueBasic) {
  285.                             $character  $valueBasic->CHARACTER;
  286.                             $charDesc   $valueBasic->CHAR_DESC;
  287.                             $value      $valueBasic->VALUES;
  288.                             $valDesc    $valueBasic->VAL_DESC;
  289.                             $charaCheck DataObject\VehicleCharacteristics::getByCharacteristics($character);
  290.                             if ($charaCheck->getCount() > 0) {
  291.                                 $newChars $charaCheck->load()[0];
  292.                             } else {
  293.                                 $newChars = new DataObject\VehicleCharacteristics();
  294.                                 $newChars->setKey(\Pimcore\Model\Element\Service::getValidKey($character'object'));
  295.                                 $charsFolderId $utilService->createFolderPath('Characteristics');
  296.                                 $newChars->setParentId($charsFolderId);
  297.                                 $newChars->setCharacteristics($character);
  298.                                 $newChars->setCharacteristicsDesc($charDesc);
  299.                                 $newChars->setPublished(true);
  300.                                 $newChars->save();
  301.                             }
  302.                             $item = new DataObject\Fieldcollection\Data\VehicleMasterCharacteristics();
  303.                             $item->setCharacteristics($newChars);
  304.                             $item->setVmValues($value);
  305.                             $item->setVmValDesc($valDesc);
  306.                             if(!empty($valueBasic->Parent)){
  307.                                 $data = [
  308.                                     "condition" => new BlockElement('condition''textarea'json_encode($valueBasic->Parent))
  309.                                 ];
  310.                                 $item->setDependency([$data]);
  311.                             }
  312.                             $items->add($item);
  313.                         }
  314.                         if($key == 'Basic'){
  315.                             $newObject->setBasicInformation($items);
  316.                         }
  317.                         if($key == 'Descriptive'){
  318.                             $newObject->setDescriptiveInformation($items);
  319.                         }
  320.                         if($key == 'Personalization'){
  321.                             $newObject->setPersonalInformation($items);
  322.                         }
  323.                     }
  324.                     $newObject->setPublished(false);
  325.                     $newObject->save();
  326.                     array_push($storedId,$newObject->getId());
  327.                 }catch (\Exception $e){
  328.                     $response = new Response();
  329.                     $response->setContent(json_encode(array('success' => 'false''errors' => [$e->getMessage()])));
  330.                     $response->setStatusCode(500);
  331.                     $response->headers->set('Content-Type''application/json');
  332.                     return $response;
  333.                 }
  334.             }
  335.             $response = new Response();
  336.             $response->setContent(json_encode(array('id'=>$storedId'errors' => [], 'success' => 'true')));
  337.             $response->setStatusCode(201);
  338.             $response->headers->set('Content-Type''application/json');
  339.             return $response;
  340.         }else{
  341.             $response = new Response();
  342.             $response->setContent(json_encode(array('success' => 'false''errors' => ['Unexpected Request Format'])));
  343.             $response->setStatusCode(400);
  344.             $response->headers->set('Content-Type''application/json');
  345.             return $response;
  346.         }
  347.     }
  348.     /**
  349.      * @Route("/api/vehiclepriceinfo", methods={"POST","HEAD"})
  350.      */
  351.     public function vehiclePriceInfoAction(Request $request)
  352.     {
  353.         $vehiclesData json_decode$request->getContent(), true);
  354.         $lcdv16 $vehiclesData['lcdv16'];
  355.         $region $vehiclesData['region'];
  356.         try{
  357.             if(!empty($lcdv16) && !empty($region)){
  358.                 $state 0;
  359.                 $regionObj DataObject\Region::getByCode($region,1);
  360.                 if(!empty($regionObj)){
  361.                     $regionID $regionObj->getID();
  362.                 }else{
  363.                     $state 1;
  364.                 }
  365.                 $lcdv16Obj DataObject\VehicleMaster::getByLcdv($lcdv16,1);
  366.                 if(!empty($lcdv16Obj)){
  367.                     $lcdv16ID $lcdv16Obj->getID();
  368.                 }else{
  369.                     $state 1;
  370.                 }
  371.                 if($state == 0){
  372.                     $vehiclePI = [];
  373.                     $vehiclePriceAttributeObj = new DataObject\VehiclePriceAttribute\Listing();
  374.                     $vehiclePriceAttributeObj->setCondition("lcdv16__id = :lcdv",["lcdv"=>$lcdv16ID]);
  375.                     $vehiclePriceAttributeObj->addConditionParam("customerRegion__id = :regid", ["regid"=>$regionID], "AND");
  376.                     //$vehiclePriceAttributeObj->addConditionParam('validStart >= :date AND validEnd <= :date',['date'=>time()],"AND");
  377.                     $vehiclePriceAttributeData $vehiclePriceAttributeObj->load();
  378.                     if($vehiclePriceAttributeData){
  379.                         foreach ($vehiclePriceAttributeData as $key => $vpaValue) {
  380.                             $vehiclePI['vehiclePriceAttribute'][$key]['codeType'] = $vpaValue->getCondType();
  381.                             $vehiclePI['vehiclePriceAttribute'][$key]['saleOrg'] = $vpaValue->getSaleOrg();
  382.                             $vehiclePI['vehiclePriceAttribute'][$key]['distCha'] = $vpaValue->getDistCha();
  383.                             if($vpaValue->getPlantRegion()){
  384.                                 $plantRegionObj $vpaValue->getPlantRegion();
  385.                                 $vehiclePI['vehiclePriceAttribute'][$key]['plantRegion']['code'] = $plantRegionObj->getCode();
  386.                                 $vehiclePI['vehiclePriceAttribute'][$key]['plantRegion']['name'] = $plantRegionObj->getName();
  387.                             }else{
  388.                                 $vehiclePI['vehiclePriceAttribute']['plantRegion'] = '';
  389.                             }
  390.                             if($vpaValue->getCountry()){
  391.                                 $countryObj $vpaValue->getCountry();
  392.                                 $vehiclePI['vehiclePriceAttribute'][$key]['country']['code'] = $countryObj->getCtr();
  393.                                 $vehiclePI['vehiclePriceAttribute'][$key]['country']['name'] = $countryObj->getName();
  394.                             }else{
  395.                                 $vehiclePI['vehiclePriceAttribute'][$key]['country'] = '';
  396.                             }
  397.                             $vehiclePI['vehiclePriceAttribute'][$key]['City'] = $vpaValue->getCity();
  398.                             $vehiclePI['vehiclePriceAttribute'][$key]['MainAttr'] = $vpaValue->getMainAttr();
  399.                             if($vpaValue->getValidStart()){
  400.                                 $vehiclePI['vehiclePriceAttribute'][$key]['ValidStart'] = $vpaValue->getValidStart()->toDateString('Y-m-d');
  401.                             }else{
  402.                                 $vehiclePI['vehiclePriceAttribute'][$key]['ValidStart'] = '';
  403.                             }
  404.                             if($vpaValue->getValidEnd()){
  405.                                 $vehiclePI['vehiclePriceAttribute'][$key]['ValidEnd'] = $vpaValue->getValidEnd()->toDateString('Y-m-d');
  406.                             }else{
  407.                                 $vehiclePI['vehiclePriceAttribute'][$key]['ValidEnd'] = '';
  408.                             }
  409.                             if($vpaValue->getCurrency()){
  410.                                 $currencyObj $vpaValue->getCurrency();
  411.                                 $vehiclePI['vehiclePriceAttribute'][$key]['Currency']['code'] = $currencyObj->getCrcy();
  412.                                 $vehiclePI['vehiclePriceAttribute'][$key]['Currency']['currency'] = $currencyObj->getCurrency();
  413.                             }else{
  414.                                 $vehiclePI['vehiclePriceAttribute'][$key]['Currency'] = '';
  415.                             }
  416.                             if($vpaValue){
  417.                                 $vehiclePI['vehiclePriceAttribute'][$key]['amount'] = $vpaValue->getAmount();
  418.                             }else{
  419.                                 $vehiclePI['vehiclePriceAttribute'][$key]['amount'] = 'NuLL';
  420.                             }
  421.                             $vehiclePI['vehiclePriceAttribute'][$key]['exgstprice'] = $vpaValue->getExGSTPrice();
  422.                         }
  423.                     }else{
  424.                         $vehiclePI['vehiclePriceAttribute'] = 'NULL';
  425.                     }
  426.                     $vehiclePriceOptionsObj = new DataObject\VehiclePriceOptions\Listing();
  427.                     $vehiclePriceOptionsObj->setCondition("lcdv16__id = :lcdv",["lcdv"=>$lcdv16ID]);
  428.                     $vehiclePriceOptionsObj->addConditionParam("custRegion__id = :regid", ["regid"=>$regionID], "AND");
  429.                     //$vehiclePriceOptionsObj->addConditionParam('validStart >= :date AND validEnd <= :date',['date'=>time()],"AND");
  430.                     $vehiclePriceOptionsData $vehiclePriceOptionsObj->load();
  431.                     if($vehiclePriceOptionsData){
  432.                         foreach ($vehiclePriceOptionsData as $key => $vpovalue) {
  433.                             $vehiclePI['vehiclePriceOptions'][$key]['codeType'] = $vpovalue->getCondType();
  434.                             $vehiclePI['vehiclePriceOptions'][$key]['saleOrg'] = $vpovalue->getSaleOrg();
  435.                             $vehiclePI['vehiclePriceOptions'][$key]['distCha'] = $vpovalue->getDistCha();
  436.                             if($vpovalue->getPlantRegion()){
  437.                                 $plantRegionObj $vpovalue->getPlantRegion();
  438.                                 $vehiclePI['vehiclePriceOptions'][$key]['plantRegion']['code'] = $plantRegionObj->getCode();
  439.                                 $vehiclePI['vehiclePriceOptions'][$key]['plantRegion']['name'] = $plantRegionObj->getName();
  440.                             }else{
  441.                                 $vehiclePI['vehiclePriceOptions'][$key]['plantRegion'] = '';
  442.                             }
  443.                             if($vpovalue->getCountry()){
  444.                                 $countryObj $vpovalue->getCountry();
  445.                                 $vehiclePI['vehiclePriceOptions'][$key]['country']['code'] = $countryObj->getCtr();
  446.                                 $vehiclePI['vehiclePriceOptions'][$key]['country']['name'] = $countryObj->getName();
  447.                             }else{
  448.                                 $vehiclePI['vehiclePriceOptions'][$key]['country'] = '';
  449.                             }
  450.                             $vehiclePI['vehiclePriceOptions'][$key]['City'] = $vpovalue->getCity();
  451.                             $vehiclePI['vehiclePriceOptions'][$key]['MainAttr'] = $vpovalue->getMainAttr();
  452.                             if($vpovalue->getValidStart()){
  453.                                 $vehiclePI['vehiclePriceOptions'][$key]['ValidStart'] = $vpovalue->getValidStart()->toDateString('Y-m-d');
  454.                             }else{
  455.                                 $vehiclePI['vehiclePriceOptions'][$key]['ValidStart'] = '';
  456.                             }
  457.                             if($vpovalue->getValidEnd()){
  458.                                 $vehiclePI['vehiclePriceOptions'][$key]['ValidEnd'] = $vpovalue->getValidEnd()->toDateString('Y-m-d');
  459.                             }else{
  460.                                 $vehiclePI['vehiclePriceOptions'][$key]['ValidEnd'] = '';
  461.                             }
  462.                             if($vpovalue->getCurrency()){
  463.                                 $currencyObj $vpovalue->getCurrency();
  464.                                 $vehiclePI['vehiclePriceOptions'][$key]['Currency']['code'] = $currencyObj->getCrcy();
  465.                                 $vehiclePI['vehiclePriceOptions'][$key]['Currency']['currency'] = $currencyObj->getCurrency();
  466.                             }else{
  467.                                 $vehiclePI['vehiclePriceOptions'][$key]['Currency'] = '';
  468.                             }
  469.                             if($vpovalue){
  470.                                 $vehiclePI['vehiclePriceOptions'][$key]['amount'] = $vpovalue->getAmount();
  471.                             }else{
  472.                                 $vehiclePI['vehiclePriceOptions'][$key]['amount'] = 'NULL';
  473.                             }
  474.                             $vehiclePI['vehiclePriceOptions'][$key]['exgstprice'] = $vpovalue->getExGSTPrice();
  475.                         }
  476.                     }else{
  477.                         $vehiclePI['vehiclePriceOptions'] = 'NULL';
  478.                     }
  479.                     $vehiclePriceObj = new DataObject\VehiclePrice\Listing();
  480.                     $vehiclePriceObj->setCondition("lcdv16__id = :lcdv",["lcdv"=>$lcdv16ID]);
  481.                     $vehiclePriceObj->addConditionParam("customerRegion__id = :regid", ["regid"=>$regionID], "AND");
  482.                     //$vehiclePriceObj->addConditionParam('validStart >= :date AND validEnd <= :date',['date'=>time()],"AND");
  483.                     $vehiclePriceData $vehiclePriceObj->load();
  484.                     if($vehiclePriceData){
  485.                         $vehiclePI['vehiclePrice']['codeType'] = $vehiclePriceData[0]->getCondType();
  486.                         $vehiclePI['vehiclePrice']['saleOrg'] = $vehiclePriceData[0]->getSaleOrg();
  487.                         $vehiclePI['vehiclePrice']['distCha'] = $vehiclePriceData[0]->getDistCha();
  488.                         if($vehiclePriceData[0]->getPlantRegion()){
  489.                             $plantRegionObj $vehiclePriceData[0]->getPlantRegion();
  490.                             $vehiclePI['vehiclePrice']['plantRegion']['code'] = $plantRegionObj->getCode();
  491.                             $vehiclePI['vehiclePrice']['plantRegion']['name'] = $plantRegionObj->getName();
  492.                         }else{
  493.                             $vehiclePI['vehiclePrice']['plantRegion'] = '';
  494.                         }
  495.                         if($vehiclePriceData[0]->getCoutnry()){
  496.                             $countryObj $vehiclePriceData[0]->getCoutnry();
  497.                             $vehiclePI['vehiclePrice']['country']['code'] = $countryObj->getCtr();
  498.                             $vehiclePI['vehiclePrice']['country']['name'] = $countryObj->getName();
  499.                         }else{
  500.                             $vehiclePI['vehiclePrice']['country'] = '';
  501.                         }
  502.                         $vehiclePI['vehiclePrice']['City'] = $vehiclePriceData[0]->getCity();
  503.                         if($vehiclePriceData[0]->getValidStart()){
  504.                             $vehiclePI['vehiclePrice']['ValidStart'] = $vehiclePriceData[0]->getValidStart()->toDateString('Y-m-d');
  505.                         }else{
  506.                             $vehiclePI['vehiclePrice']['ValidStart'] = '';
  507.                         }
  508.                         if($vehiclePriceData[0]->getValidEnd()){
  509.                             $vehiclePI['vehiclePrice']['ValidEnd'] = $vehiclePriceData[0]->getValidEnd()->toDateString('Y-m-d');
  510.                         }else{
  511.                             $vehiclePI['vehiclePrice']['ValidEnd'] = '';
  512.                         }
  513.                         if($vehiclePriceData[0]->getCurrency()){
  514.                             $currencyObj $vehiclePriceData[0]->getCurrency();
  515.                             $vehiclePI['vehiclePrice']['Currency']['code'] = $currencyObj->getCrcy();
  516.                             $vehiclePI['vehiclePrice']['Currency']['currency'] = $currencyObj->getCurrency();
  517.                         }else{
  518.                             $vehiclePI['vehiclePrice']['Currency'] = '';
  519.                         }
  520.                         $vehiclePI['vehiclePrice']['amount'] = $vehiclePriceData[0]->getAmount();
  521.                         $vehiclePI['vehiclePrice']['exgstprice'] = $vehiclePriceData[0]->getExGSTPrice();
  522.                     }else{
  523.                         $vehiclePI['vehiclePrice'] = "NULL";
  524.                     }
  525.                     $vehicleTaxObj = new DataObject\Tax\Listing();
  526.                     $vehicleTaxObj->setCondition('lcdv16__id = ?'$lcdv16ID);
  527.                     $vehicleTaxObj->addConditionParam("custRegion__id = ?",$regionID,'AND');
  528.                     $vehicleTaxData $vehicleTaxObj->load();
  529.                     if($vehicleTaxData){
  530.                         foreach($vehicleTaxData as $key=>$taxData){
  531.                             $vehiclePI['vehicleTax'][$key]['taxType'] = $taxData->getTaxType();
  532.                             $vehiclePI['vehicleTax'][$key]['hsnCode'] = $taxData->getHsnCode();
  533.                             $vehiclePI['vehicleTax'][$key]['percentage'] = $taxData->getPercentage();
  534.                             $vehiclePI['vehicleTax'][$key]['validStart'] = $taxData->getValidStart()->toDateString('Y-m-d');
  535.                             $vehiclePI['vehicleTax'][$key]['validEnd'] = $taxData->getValidEnd()->toDateString('Y-m-d');
  536.                             $vehiclePI['vehicleTax'][$key]['plantRegion'] = $taxData->getPlantRegion()->getCode();
  537.                             $vehiclePI['vehicleTax'][$key]['customerRegion'] = $taxData->getCustRegion()->getCode();
  538.                         }
  539.                     }else{
  540.                         $vehiclePI['vehicleTax'] = [];
  541.                     }
  542.                     $tmpResponse $vehiclePI;
  543.                 }else{
  544.                     $tmpResponse 'LCDV or Region not available.';
  545.                 }
  546.             }else{
  547.                 $tmpResponse 'Invalid Perameters.';
  548.             }
  549.             $response = new Response();
  550.             $response->setContent(json_encode($tmpResponse));
  551.             $response->setStatusCode(201);
  552.             $response->headers->set('Content-Type''application/json');
  553.             return $response;
  554.         }catch (\Exception $e){
  555.             $response = new Response();
  556.             $response->setContent(json_encode(array('success' => 'false''errors' => [$e->getMessage()])));
  557.             $response->setStatusCode(500);
  558.             $response->headers->set('Content-Type''application/json');
  559.             return $response;
  560.         }
  561.     }
  562.     /**
  563.      * @Route("/api/regionlist", methods={"POST","HEAD"})
  564.      */
  565.     public function regionListAction(Request $request)
  566.     {
  567.         $regionObj = new DataObject\Region\Listing();
  568.         $regionData $regionObj->load();
  569.         try{
  570.             $regionDataArr = [];
  571.             foreach ($regionData as $value) {
  572.                 $regionData = [];
  573.                 $regionData['code']   = $value->getCode();
  574.                 $regionData['name']  = $value->getName();
  575.                 $countryData$value->getCountry();
  576.                 $country = [];
  577.                 if($countryData){
  578.                     $country['code'] = $countryData->getCtr();
  579.                     $country['name'] = $countryData->getName();
  580.                 }
  581.                 $regionData['country'] = $country;
  582.                 array_push($regionDataArr$regionData);
  583.             }
  584.             $regionDataJSON json_encode($regionDataArr);
  585.             $response = new Response();
  586.             $response->setContent($regionDataJSON);
  587.             $response->setStatusCode(201);
  588.             $response->headers->set('Content-Type''application/json');
  589.             return $response;
  590.         }catch (\Exception $e){
  591.             $response = new Response();
  592.             $response->setContent(json_encode(array('success' => 'false''errors' => [$e->getMessage()])));
  593.             $response->setStatusCode(500);
  594.             $response->headers->set('Content-Type''application/json');
  595.             return $response;
  596.         }
  597.     }
  598.     /**
  599.      * @Route("/api/minbookingamount", methods={"POST","HEAD"})
  600.      */
  601.     public function minBookingAmountAction(Request $request)
  602.     {
  603.         $vehiclesLcdv json_decode$request->getContent(), true);
  604.         $lcdv16 $vehiclesLcdv['lcdv16'];
  605.         try{
  606.             if($lcdv16){
  607.                 $vehicleMasterCheck DataObject\VehicleMaster::getByLcdv($lcdv16,1);
  608.                 if(!empty($vehicleMasterCheck)){
  609.                     $vehicleId $vehicleMasterCheck->getId();
  610.                     $minBookingAmountObj = new DataObject\minBookingAmount\Listing();
  611.                     $minBookingAmountObj->setCondition("vehicle__id = '$vehicleId'");
  612.                     $minBookingAmountData $minBookingAmountObj->load();
  613.                     $minBookingAmount = [];
  614.                     $preAmount $minBookingAmountData[0]->getPreBookingAmount();
  615.                     if($preAmount){
  616.                         $preAmountVal $preAmount->getValue();
  617.                         $preAmountUnit $preAmount->getUnit()->getLongname();
  618.                         $preBookingAmount $preAmountVal.' '.$preAmountUnit;
  619.                     }else{
  620.                         $preBookingAmount 'NULL';
  621.                     }
  622.                     $bookingAmount $minBookingAmountData[0]->getBookingAmount();
  623.                     if($bookingAmount){
  624.                         $bookingAmountVal $bookingAmount->getValue();
  625.                         $bookingAmountUnit $bookingAmount->getUnit()->getLongname();
  626.                         $bookingAmount $bookingAmountVal.' '.$bookingAmountUnit;
  627.                     }else{
  628.                         $bookingAmount 'NULL';
  629.                     }
  630.                     array_push($minBookingAmount, ['preBookingAmount' => $preBookingAmount'bookingAmount' => $bookingAmount]);
  631.                     $tmpResponse $minBookingAmount;
  632.                 }else{
  633.                     $tmpResponse 'Vehicle not found.';
  634.                 }
  635.             }else{
  636.                 $tmpResponse "Invalid perameters.";
  637.             }
  638.             $response = new Response();
  639.             $response->setContent(json_encode($tmpResponse));
  640.             $response->setStatusCode(201);
  641.             $response->headers->set('Content-Type''application/json');
  642.             return $response;
  643.          }catch (\Exception $e){
  644.             $response = new Response();
  645.             $response->setContent(json_encode(array('success' => 'false''errors' => [$e->getMessage()])));
  646.             $response->setStatusCode(500);
  647.             $response->headers->set('Content-Type''application/json');
  648.             return $response;
  649.         }
  650.     }
  651. }