src/Controller/WS/ServicesAndPricesController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\WS;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use App\Util\Util as Utilx;
  6. use App\Util\WS\Util;
  7. use App\Util\WS\PointsUtilPorcessor;
  8. use App\Entity\WebService;
  9. use App\Transformer\LicensorGenericTransformer;
  10. /**
  11.  * Description of ServicesAndPricesController
  12.  * @author zaealan
  13.  */
  14. class ServicesAndPricesController extends ApiController {
  15.     /**
  16.      * Funcion encargada de verificar un servicio y sus marcas (brands)
  17.      * 
  18.      */
  19.     public function verificarServicesAndBrand(Request $request) {
  20.         if ($request->getMethod() === WebService::REQUEST_METHOD_POST) {
  21.             $data json_decode($request->getContent(),true);
  22.             
  23.             if(!isset($data['nickname']) || empty($data['nickname'])) {
  24.                 return $this->errorWrongArgs('Wrong Arguments!'WebService::CODE_WRONG_ARGUMENTS);
  25.             }
  26.             
  27.             $em $this->getDoctrine()->getManager();
  28.             $accountLicenseData $em->getRepository('App\Entity\AccountLicense')->findByAlLicenseUsername($data['nickname']);
  29.             $countResult count($accountLicenseData);
  30.             if ($countResult <= 0) {
  31.                 return $this->setStatusCode(WebService::HTTP_CODE_UNAUTHORIZED)
  32.                 ->respondWithError('Invalid nickname'WebService::CODE_COULD_NOT_AUTHENTICATE);
  33.             }
  34.             $container $this->realContainer;
  35.             $emLic $container->get("doctrine")->getManager();
  36.             $emLic->getConnection()->getConfiguration()->setSQLLogger(null);
  37.             $emLev Util::emLicenseConnection($container$emLic$accountLicenseData[0]);
  38.             $servicesType $emLev->getRepository('App\Structure\OrderServiceTypes')->findBy(["ostStatus" => 1]);
  39.             $typeBrand  $emLev->getRepository('App\Structure\BrandTypeMenu')->findAll(['order' => 'ASC']);
  40.             $services= [];
  41.             if($servicesType) {
  42.                 foreach ($servicesType as $datos) {
  43.                     $array = [
  44.                         "id" => $datos->getOmtSync(),
  45.                         "levelId" => $datos->getId(),
  46.                         "ostType" => $datos->getOstType(),
  47.                         "ostName" => $datos->getOstName(),
  48.                         "ostStatus" => $datos->getOstStatus(),
  49.                         "androidSync" => $datos->getAndroidSync(),
  50.                         "omtSync" => $datos->getOmtSync()
  51.                     ];  
  52.                     array_push($services$array);
  53.                 }                                
  54.             } 
  55.             $brand=[];
  56.             if($typeBrand) {
  57.                 foreach ($typeBrand as $datosBrand) {
  58.                     $array = [
  59.                         "id" => $datosBrand->getId(),
  60.                         "name" => $datosBrand->getName(),
  61.                         "alias" => $datosBrand->getAlias(),
  62.                         "order" => $datosBrand->getOrder(),
  63.                         "status" => $datosBrand->getStatus(),
  64.                         "lastStatus" => $datosBrand->getLastStatus(),
  65.                         "androidSync" => $datosBrand->getAndroidSync(),
  66.                         "omtSync" => $datosBrand->getOmtSync()
  67.                     ];  
  68.                     array_push($brand$array);
  69.                 }  
  70.             } 
  71.             $responseArr['msg'] = 'type services and brand of the restaurant: ' $accountLicenseData[0]->getAlRestaurantName() ;
  72.             $responseArr['status'] = WebService::CODE_SUCCESS;
  73.             $responseArr['servicesType'] = $services;
  74.             $responseArr['brand'] = $brand;
  75.             $responseArr['bigbag'] = true;
  76.             
  77.             $theUrlTrSt = new LicensorGenericTransformer($this->realContainer$responseArr);
  78.             $xxArray $theUrlTrSt->transform();
  79.             $jsonContent json_encode($xxArray);
  80.             
  81.             return $this->respondWithItem($jsonContent$theUrlTrSt);
  82.         }
  83.     }
  84.     public  function searchServicesPrices(Request $request) {
  85.         if ($request->getMethod() === WebService::REQUEST_METHOD_POST) {
  86.             $data json_decode($request->getContent(),true);
  87.             if(!isset($data['nickname']) || empty($data['nickname'])) {                
  88.                 return $this->errorWrongArgs('Wrong Arguments nickname!'WebService::CODE_WRONG_ARGUMENTS);
  89.             }            
  90.             if(!isset($data['brand']) || empty($data['brand'])) {                
  91.                 return $this->errorWrongArgs('Wrong Arguments brand!'WebService::CODE_WRONG_ARGUMENTS);
  92.             }
  93.             $em $this->getDoctrine()->getManager();
  94.             $accountLicenseData $em->getRepository('App\Entity\AccountLicense')->findByAlLicenseUsername($data['nickname']);
  95.             $countResult count($accountLicenseData);
  96.             if ($countResult 0) {
  97.             } else {
  98.                 return $this->setStatusCode(WebService::HTTP_CODE_UNAUTHORIZED)
  99.                 ->respondWithError('Invalid nickname'WebService::CODE_COULD_NOT_AUTHENTICATE);
  100.             }          
  101.             $container $this->realContainer;
  102.             $emLic $container->get("doctrine")->getManager();
  103.             $emLic->getConnection()->getConfiguration()->setSQLLogger(null);
  104.             $emLev Util::emLicenseConnection($container$emLic$accountLicenseData[0]);
  105.             $servicesPrice $emLev->getRepository('App\Structure\ServicePrice')->searchServicePriceByBrand($data);
  106.             
  107.             $price = [];
  108.             if ($servicesPrice) {
  109.                 foreach ($servicesPrice as $datos) {
  110.                     $array = [
  111.                         "id" => $datos->getId(),
  112.                         "ostId" => $datos->getOstId(),
  113.                         "prdtllaId" => $datos->getPrdtllaId(),
  114.                         "brandId" => $datos->getBrandId(),
  115.                         "value" => $datos->getValue(),
  116.                         "status" => $datos->getStatus(),
  117.                         "androidSync" => $datos->getAndroidSync(),
  118.                         "omtSync" => $datos->getOmtSync()
  119.                     ];                
  120.                     array_push($price$array);
  121.                 }  
  122.             } 
  123.             
  124.             $responseArr['msg'] = 'services price of the restaurant: ' $accountLicenseData[0]->getAlRestaurantName() ;
  125.                   
  126.             $responseArr['status'] = WebService::CODE_SUCCESS;
  127.             $responseArr['servicesPrices'] = $price;
  128.             $responseArr['bigbag'] = true;
  129.             
  130.             $theUrlTrSt = new LicensorGenericTransformer($this->realContainer$responseArr);
  131.             $xxArray $theUrlTrSt->transform();
  132.             $jsonContent json_encode($xxArray);
  133.             return $this->respondWithItem($jsonContent$theUrlTrSt);
  134.         }
  135.     }
  136.     /**
  137.      * {post} /changeServicesStatus. Funcion encargada de cambiar el estado de un servicio en level web (DINE IN - PICK UP - DELIVERY)
  138.      * 0.1.0
  139.      * Jose idier Alzate - Noviembre. 21/2024
  140.      *
  141.      */
  142.     public function changeServicesStatus(Request $request) {
  143.         if ($request->getMethod() === WebService::REQUEST_METHOD_POST) {
  144.             
  145.             $data json_decode($request->getContent(),true);
  146.             $data array_values($data)[0];
  147.             // validamos el nickname
  148.             if (!isset($data['nickname']) || empty($data['nickname'])) {                
  149.                 return $this->errorWrongArgs('Wrong Arguments nickname!'WebService::CODE_WRONG_ARGUMENTS);
  150.             }
  151.             // Validamos el estado 
  152.             if (!isset($data['status'])) {
  153.                 return $this->errorWrongArgs('Wrong Arguments status!'WebService::CODE_WRONG_ARGUMENTS);
  154.             }
  155.             // Validamos el servicio
  156.             if (!isset($data['service']) || empty($data['service'])) {
  157.                 return $this->errorWrongArgs('Wrong Arguments service!'WebService::CODE_WRONG_ARGUMENTS);
  158.             }
  159.             $em $this->getDoctrine()->getManager();
  160.             $accountLicenseData $em->getRepository('App\Entity\AccountLicense')->findByAlLicenseUsername($data['nickname']);
  161.             if (count($accountLicenseData) <= 0) {
  162.                 return $this->setStatusCode(WebService::HTTP_CODE_UNAUTHORIZED)
  163.                 ->respondWithError('Invalid nickname'WebService::CODE_COULD_NOT_AUTHENTICATE);
  164.             }
  165.             $container $this->realContainer;
  166.             $emLic $container->get("doctrine")->getManager();
  167.             $emLic->getConnection()->getConfiguration()->setSQLLogger(null);
  168.             $emLev Util::emLicenseConnection($container$emLic$accountLicenseData[0]);
  169.             // ya teniendo la conexion vamos a cambiar el registro que necesitamos
  170.             $setData $emLev->getRepository('App\Structure\OrderServiceTypes')->findOneBy([ 'ostType' => $data['service'] ]);
  171.             if ($setData->getOstStatus() != $data['status'] ) {
  172.                 
  173.                 $setData->setOstStatus($data['status']);
  174.                 $emLev->persist($setData);
  175.                 $emLev->flush();
  176.             }
  177.             $responseArr['msg'] = "Service type status saved successfully";
  178.             $responseArr['status'] = WebService::CODE_SUCCESS;
  179.             $responseArr['bigbag'] = true;
  180.             $theUrlTrSt = new LicensorGenericTransformer($container$responseArr);
  181.             $xxArray $theUrlTrSt->transform();
  182.             $jsonContent json_encode($xxArray);
  183.             return $this->respondWithItem($jsonContent$theUrlTrSt);
  184.         }
  185.     }
  186. }