src/Controller/Api/Reservation/ReservationController.php line 60

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api\Reservation;
  3. use App\Enum\Parameter;
  4. use App\Message\PuzzleReservationMessage;
  5. use App\Service\Filter\Reservation\DataModels\ReservationFilter;
  6. use App\Service\Filter\Reservation\Method\ReservationListService;
  7. use App\Service\Reservation\AutoComplate\Paramerter\PackageProfitAll;
  8. use App\Service\Reservation\Reservation\Paramerter\DiscountCoupon;
  9. use App\Service\Reservation\Reservation\Paramerter\EbInsurance;
  10. use App\Service\Reservation\Reservation\Paramerter\ForwardingNotification;
  11. use App\Service\Reservation\Reservation\Paramerter\HotelProfit;
  12. use App\Service\Reservation\Reservation\Paramerter\Invoice;
  13. use App\Service\Reservation\Reservation\Paramerter\Note;
  14. use App\Service\Reservation\Reservation\Paramerter\HotelExtra;
  15. use App\Service\Reservation\Reservation\Paramerter\PackageProfit;
  16. use App\Service\Reservation\Reservation\Paramerter\Pax;
  17. use App\Service\Reservation\Reservation\Paramerter\Profit;
  18. use App\Service\Reservation\Reservation\Paramerter\ReservationDetail;
  19. use App\Service\Reservation\Reservation\Paramerter\ReservationPaxInvoiceSave;
  20. use App\Service\Reservation\Reservation\Paramerter\ReservationUserSave;
  21. use App\Service\Reservation\Reservation\Paramerter\Review;
  22. use App\Service\Reservation\Reservation\Paramerter\RequestData;
  23. use App\Service\Reservation\Reservation\ReservationService;
  24. use App\Service\Respy\RespyService;
  25. use App\Service\Validator\ValidatorService;
  26. use Exception;
  27. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  28. use Symfony\Component\HttpFoundation\JsonResponse;
  29. use Symfony\Component\Messenger\MessageBusInterface;
  30. use Symfony\Component\Routing\Annotation\Route;
  31. use Symfony\Component\Validator\Constraints as Assert;
  32. use Symfony\Component\HttpFoundation\Request;
  33. use Symfony\Contracts\Translation\TranslatorInterface;
  34. /**
  35.  * Class ReservationController
  36.  * @package App\Controller\Admin
  37.  */
  38. class ReservationController extends AbstractController
  39. {
  40.     /**
  41.      * @param TranslatorInterface $translator
  42.      */
  43.     public function __construct(
  44.         protected TranslatorInterface $translator,
  45.     )
  46.     {
  47.     }
  48.     /**
  49.      * @Route("/api/integration/reservation", name="api_integration_reservation", methods={"POST"})
  50.      *
  51.      * @param RespyService $respy
  52.      * @param ValidatorService $validatorService
  53.      * @param MessageBusInterface $bus
  54.      * @return JsonResponse
  55.      */
  56.     public function reservationUpdate(RespyService $respyValidatorService $validatorServiceMessageBusInterface $bus): JsonResponse
  57.     {
  58.         $constraints = new Assert\Collection([
  59.             'reservationCode' => [
  60.                 new Assert\Required(),
  61.             ],
  62.             'voucher' => [
  63.                 new Assert\Optional(),
  64.             ],
  65.         ]);
  66.         try {
  67.             $input $validatorService->validate($constraints);
  68.             $bus->dispatch(new PuzzleReservationMessage($input['reservationCode']));
  69.             $respy->success();
  70.         } catch (Exception $exception) {
  71.             $respy->setError($exception->getMessage());
  72.             $respy->setErrorCode($exception->getCode());
  73.         }
  74.         return new JsonResponse($respy->getResponse());
  75.     }
  76.     /**
  77.      * @Route("/api/reservation/user/save", name="api_reservation_user_save", methods={"POST"})
  78.      *
  79.      * @param RespyService $respy
  80.      * @param ValidatorService $validatorService
  81.      * @param ReservationService $reservationService
  82.      * @return JsonResponse
  83.      */
  84.     public function reservationUserSave(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  85.     {
  86.         $constraints = new Assert\Collection([
  87.             'guid' => [
  88.                 new Assert\Required()
  89.             ],
  90.             'userId' => [
  91.                 new Assert\NotBlank()
  92.             ]
  93.         ]);
  94.         try {
  95.             $input $validatorService->validate($constraints);
  96.             $reservationUserSave = (new ReservationUserSave())
  97.                 ->setGuid($input["guid"])
  98.                 ->setUserId($input["userId"]);
  99.             if ($response $reservationService->userSave($reservationUserSave)) {
  100.                 $respy->success();
  101.                 $respy->setData($response);
  102.             }
  103.         } catch (Exception $exception) {
  104.             $respy->setError($exception->getMessage());
  105.             $respy->setErrorCode($exception->getCode());
  106.         }
  107.         return new JsonResponse($respy->getResponse());
  108.     }
  109.     /**
  110.      * @Route("/api/reservation/user/details", name="api_reservation_user_details", methods={"POST"})
  111.      *
  112.      * @param RespyService $respy
  113.      * @param ValidatorService $validatorService
  114.      * @param ReservationService $reservationService
  115.      * @return JsonResponse
  116.      */
  117.     public function reservationUserDetails(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  118.     {
  119.         $constraints = new Assert\Collection([
  120.             'user' => [
  121.                 new Assert\Required(),
  122.                 new Assert\NotBlank(),
  123.             ]
  124.         ]);
  125.         try {
  126.             $input $validatorService->validate($constraints);
  127.             $reservationDetail = (new ReservationDetail())
  128.                 ->setUser($input["user"]);
  129.             $response $reservationService->userDetails($reservationDetail);
  130.             $respy->success();
  131.             $respy->setData($response);
  132.         } catch (Exception $exception) {
  133.             $respy->setError($exception->getMessage());
  134.             $respy->setErrorCode($exception->getCode());
  135.         }
  136.         return new JsonResponse($respy->getResponse());
  137.     }
  138.     /**
  139.      * @Route("/api/reservation/puzzle-booking/user/details", name="api_reservation_puzzle_booking_user_details", methods={"POST"})
  140.      *
  141.      * @param RespyService $respy
  142.      * @param ValidatorService $validatorService
  143.      * @param ReservationListService $reservationListService
  144.      * @return JsonResponse
  145.      */
  146.     public function reservationPuzzleBookingUserDetails(RespyService $respyValidatorService $validatorServiceReservationListService $reservationListService): JsonResponse
  147.     {
  148.         $constraints = new Assert\Collection([
  149.             'processFrom' => [
  150.                 new Assert\Required(),
  151.             ],
  152.             'processTo' => [
  153.                 new Assert\Required(),
  154.             ],
  155.             'checkInFrom' => [
  156.                 new Assert\Required(),
  157.             ],
  158.             'checkInTo' => [
  159.                 new Assert\Required(),
  160.             ],
  161.             'checkOutFrom' => [
  162.                 new Assert\Required(),
  163.             ],
  164.             'checkOutTo' => [
  165.                 new Assert\Required(),
  166.             ],
  167.             'firstName' => [
  168.                 new Assert\Required(),
  169.             ],
  170.             'lastName' => [
  171.                 new Assert\Required(),
  172.             ],
  173.             'voucher' => [
  174.                 new Assert\Required(),
  175.             ],
  176.             'pnr' => [
  177.                 new Assert\Required(),
  178.             ],
  179.             'hotelId' => [
  180.                 new Assert\Required(),
  181.             ],
  182.             'agencyId' => [
  183.                 new Assert\Required(),
  184.                 new Assert\NotBlank(),
  185.             ],
  186.             'status' => [
  187.                 new Assert\Required(),
  188.             ],
  189.             'page' => [
  190.                 new Assert\NotBlank(),
  191.             ],
  192.             'pageCount' => [
  193.                 new Assert\NotBlank(),
  194.             ],
  195.             'category' => [
  196.                 new Assert\Required(),
  197.             ]
  198.         ]);
  199.         try {
  200.             $input $validatorService->validate($constraints);
  201.             $agency $this->getUser()?->getAgency()?->getId();
  202.             if (!$agency) {
  203.                 $agency $input["agencyId"];
  204.             }
  205.             $reservationFilter = (new ReservationFilter())
  206.                 ->setProcessFrom($input["processFrom"])
  207.                 ->setProcessTo($input["processTo"])
  208.                 ->setCheckInFrom($input["checkInFrom"])
  209.                 ->setCheckInTo($input["checkInTo"])
  210.                 ->setCheckOutFrom($input["checkOutFrom"])
  211.                 ->setCheckOutTo($input["checkOutTo"])
  212.                 ->setFirstName($input["firstName"])
  213.                 ->setLastName($input["lastName"])
  214.                 ->setVoucher($input["voucher"])
  215.                 ->setPnr($input["pnr"])
  216.                 ->setHotelId($input["hotelId"])
  217.                 ->setAgencyId($agency)
  218.                 ->setType(0)
  219.                 ->setCategory($input["category"])
  220.                 ->setStatus($input["status"])
  221.                 ->setVariable('search')
  222.                 ->setPaymentTransferNo('');
  223.             $response $reservationListService->handle($reservationFilter$input['page'] ?? 1$input['pageCount'] ?? 50false);
  224.             $respy->success();
  225.             $respy->setData($response);
  226.             $sales 0;
  227.             $cost 0;
  228.             $remaining 0;
  229.             foreach ($response->reservations as $resp) {
  230.                 $sales += $resp->getTotalPrice();
  231.                 $cost += $resp->getTotalCost();
  232.                 $remaining += $resp->getRemainingPrice();
  233.             }
  234.             $respy->setParams([
  235.                 'sales' => (float)number_format($sales2'.'''),
  236.                 'cost' => (float)number_format($cost2'.'''),
  237.                 'profit' => (float)number_format($sales $cost2'.'''),
  238.                 'remaining' => (float)number_format($remaining2'.'''),
  239.             ]);
  240.         } catch (Exception $exception) {
  241.             $respy->setError($exception->getMessage());
  242.             $respy->setErrorCode($exception->getCode());
  243.         }
  244.         return new JsonResponse($respy->getResponse());
  245.     }
  246.     /**
  247.      * @Route("/api/reservation/user/status", name="api_reservation_user_status", methods={"POST"})
  248.      *
  249.      * @param RespyService $respy
  250.      * @return JsonResponse
  251.      */
  252.     public function reservationStatus(RespyService $respy): JsonResponse
  253.     {
  254.         $response Parameter::RESERVATION_STATUS_API;
  255.         $respy->success();
  256.         $respy->setData($response);
  257.         return new JsonResponse($respy->getResponse());
  258.     }
  259.     /**
  260.      * @Route("/api/reservation/detail", name="api_reservation_detail", methods={"POST"})
  261.      *
  262.      * @param RespyService $respy
  263.      * @param ValidatorService $validatorService
  264.      * @param ReservationService $reservationService
  265.      * @return JsonResponse
  266.      */
  267.     public function reservationDetail(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  268.     {
  269.         $constraints = new Assert\Collection([
  270.             'guid' => [
  271.                 new Assert\Optional()
  272.             ],
  273.             'voucherNo' => [
  274.                 new Assert\Optional(),
  275.             ],
  276.             'surname' => [
  277.                 new Assert\Optional(),
  278.             ],
  279.         ]);
  280.         try {
  281.             $input $validatorService->validate($constraints);
  282.             $reservationDetail = (new ReservationDetail())
  283.                 ->setGuid($input["guid"])
  284.                 ->setSurname($input["surname"])
  285.                 ->setVoucherNo($input["voucherNo"]);
  286.             if ($response $reservationService->detail($reservationDetailtrue)) {
  287.                 $respy->success();
  288.                 $respy->setData($response);
  289.             }
  290.         } catch (Exception $exception) {
  291.             $respy->setError($exception->getMessage());
  292.             $respy->setErrorCode($exception->getCode());
  293.         }
  294.         return new JsonResponse($respy->getResponse());
  295.     }
  296.     /**
  297.      * @Route("/api/reservation/pax-invoice/save", name="api_reservation_pax_invoice_save", methods={"POST"})
  298.      *
  299.      * @param RespyService $respy
  300.      * @param ValidatorService $validatorService
  301.      * @param ReservationService $reservationService
  302.      * @return JsonResponse
  303.      */
  304.     public function reservationPaxInvoiceSave(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  305.     {
  306.         $constraints = new Assert\Collection([
  307.             'guid' => [
  308.                 new Assert\Required()
  309.             ],
  310.             'pax' => [
  311.                 new Assert\Optional([
  312.                     new Assert\Type('array'),
  313.                     new Assert\Count(['min' => 1]),
  314.                     new Assert\All([
  315.                         new Assert\Collection([
  316.                             'type' => [
  317.                                 new Assert\NotBlank([
  318.                                     'message' => $this->translator->trans('reservation.nameRequired'),
  319.                                 ]),
  320.                                 new Assert\Choice(Parameter::RESERVATION_PAX_TYPE)
  321.                             ],
  322.                             'firstName' => [
  323.                                 new Assert\NotBlank(),
  324.                                 new Assert\Type(['type' => 'string']),
  325.                             ],
  326.                             'lastName' => [
  327.                                 new Assert\NotBlank([
  328.                                     'message' => $this->translator->trans('reservation.lastNameRequired'),
  329.                                 ]),
  330.                                 new Assert\Type(['type' => 'string']),
  331.                             ],
  332.                             'gender' => [
  333.                                 new Assert\NotBlank([
  334.                                     'message' => $this->translator->trans('reservation.genderRequired'),
  335.                                 ]),
  336.                                 new Assert\Choice(Parameter::RESERVATION_PAX_GENDER)
  337.                             ],
  338.                             'birthday' => [
  339.                                 new Assert\NotBlank([
  340.                                     'message' => $this->translator->trans('reservation.birthdayRequired'),
  341.                                 ]),
  342.                                 new Assert\Date([
  343.                                     'message' => $this->translator->trans('reservation.birthdayDateFormatNotCorrect'),
  344.                                 ])
  345.                             ],
  346.                             'identifyNumber' => [
  347.                                 new Assert\NotBlank([
  348.                                     'message' => $this->translator->trans('reservation.identifyNumberRequired'),
  349.                                 ])
  350.                             ],
  351.                             'phone' => [
  352.                                 new Assert\NotBlank([
  353.                                     'message' => $this->translator->trans('reservation.phoneRequired'),
  354.                                 ])
  355.                             ],
  356.                             'passportNumber' => [
  357.                                 new Assert\Required(),
  358.                             ],
  359.                             'passportValidityDate' => [
  360.                                 new Assert\Date([
  361.                                     'message' => $this->translator->trans('reservation.passportDateFormatNotCorrect'),
  362.                                 ]),
  363.                             ],
  364.                         ]),
  365.                     ]),
  366.                 ]),
  367.             ],
  368.             'invoice' => [
  369.                 new Assert\Optional(
  370.                     new Assert\Collection([
  371.                         'type' => [
  372.                             new Assert\NotBlank([
  373.                                 'message' => $this->translator->trans('reservation.typeRequired'),
  374.                             ]),
  375.                             new Assert\Choice(Parameter::RESERVATION_INVOICE_TYPE)
  376.                         ],
  377.                         'firstName' => [
  378.                             new Assert\Required(),
  379.                             new Assert\Type(['type' => 'string']),
  380.                         ],
  381.                         'lastName' => [
  382.                             new Assert\Required(),
  383.                             new Assert\Type(['type' => 'string']),
  384.                         ],
  385.                         'companyName' => [
  386.                             new Assert\Required(),
  387.                             new Assert\Type(['type' => 'string']),
  388.                         ],
  389.                         'email' => [
  390.                             new Assert\NotBlank([
  391.                                 'message' => $this->translator->trans('reservation.emailRequired'),
  392.                             ]),
  393.                             new Assert\Type(['type' => 'string']),
  394.                         ],
  395.                         'identifyNumber' => [
  396.                             new Assert\Required()
  397.                         ],
  398.                         'phone' => [
  399.                             new Assert\Required(),
  400.                         ],
  401.                         'address' => [
  402.                             new Assert\Required(),
  403.                         ],
  404.                         'taxOffice' => [
  405.                             new Assert\Required()
  406.                         ],
  407.                         'taxNumber' => [
  408.                             new Assert\Required()
  409.                         ],
  410.                         'city' => [
  411.                             new Assert\Optional()
  412.                         ],
  413.                         'district' => [
  414.                             new Assert\Optional()
  415.                         ],
  416.                     ])),
  417.             ],
  418.             'guestNote' => [
  419.                 new Assert\Required(),
  420.             ],
  421.             'kvkkConsentContract' => [
  422.                 new Assert\Required(),
  423.             ],
  424.             'kvkkLightingContract' => [
  425.                 new Assert\Required(),
  426.             ],
  427.             'consentContract' => [
  428.                 new Assert\Optional(),
  429.             ],
  430.             'agencyVoucherNo' => [
  431.                 new Assert\Optional(),
  432.             ],
  433.         ]);
  434.         try {
  435.             $input $validatorService->validateWithoutError($constraints);
  436.             $reservationPaxInvoiceSave = (new ReservationPaxInvoiceSave())
  437.                 ->setGuid($input['guid'])
  438.                 ->setGuestNote($input['guestNote'])
  439.                 ->setKvkkConsentContract($input['kvkkConsentContract'] ?? false)
  440.                 ->setKvkkLightingContract($input['kvkkLightingContract'] ?? false)
  441.                 ->setConsentContract($input['consentContract'] ?? false)
  442.                 ->setAgencyVoucherNo($input['agencyVoucherNo'] ?? false);
  443.             $phone '';
  444.             foreach ($input["pax"] as $p) {
  445.                 $pax = (new Pax())
  446.                     ->setType($p["type"])
  447.                     ->setFirstName($p["firstName"])
  448.                     ->setLastName($p["lastName"])
  449.                     ->setGender($p["gender"])
  450.                     ->setBirthDay($p["birthday"])
  451.                     ->setIdentifyNumber($p["identifyNumber"])
  452.                     ->setPhone($p["phone"])
  453.                     ->setPassportNumber($p["passportNumber"] ?: '')
  454.                     ->setPassportValidityDate($p["passportValidityDate"] ?: '');
  455.                 if ($p["phone"]) {
  456.                     $phone $p["phone"];
  457.                 }
  458.                 $reservationPaxInvoiceSave->addPax($pax);
  459.             }
  460.             if (!empty($input["invoice"])) {
  461.                 $invoice = (new Invoice())
  462.                     ->setType($input["invoice"]["type"])
  463.                     ->setFirstName($input["invoice"]["firstName"])
  464.                     ->setLastName($input["invoice"]["lastName"])
  465.                     ->setCompanyName($input["invoice"]["companyName"])
  466.                     ->setEmail($input["invoice"]["email"])
  467.                     ->setPhone($input["invoice"]["phone"] ?: $phone)
  468.                     ->setIdentifyNumber($input["invoice"]["identifyNumber"])
  469.                     ->setTaxOffice($input["invoice"]["taxOffice"])
  470.                     ->setTaxNumber($input["invoice"]["taxNumber"])
  471.                     ->setAddress($input["invoice"]["address"])
  472.                     ->setCity($input["invoice"]["city"] ?? '')
  473.                     ->setDistrict($input["invoice"]["district"] ?? '');
  474.                 $reservationPaxInvoiceSave->setInvoice($invoice);
  475.             }
  476.             if ($response $reservationService->paxInvoiceSave($reservationPaxInvoiceSave)) {
  477.                 $respy->success();
  478.                 $respy->setData($response);
  479.             }
  480.         } catch (Exception $exception) {
  481.             $respy->setError($exception->getMessage());
  482.             $respy->setErrorCode($exception->getCode());
  483.         }
  484.         return new JsonResponse($respy->getResponse());
  485.     }
  486.     /**
  487.      * @Route("/api/reservation/discountcoupon", name="api_reservation_discountcoupon", methods={"POST"})
  488.      *
  489.      * @param RespyService $respy
  490.      * @param ValidatorService $validatorService
  491.      * @param ReservationService $reservationService
  492.      * @return JsonResponse
  493.      */
  494.     public function reservationDiscount(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  495.     {
  496.         $constraints = new Assert\Collection([
  497.             'guid' => [
  498.                 new Assert\NotBlank()
  499.             ],
  500.             'discountCode' => [
  501.                 new Assert\NotBlank()
  502.             ]
  503.         ]);
  504.         try {
  505.             $input $validatorService->validate($constraints);
  506.             $discountCoupon = (new DiscountCoupon())
  507.                 ->setGuid($input["guid"])
  508.                 ->setDiscountCouponCode($input["discountCode"]);
  509.             if ($response $reservationService->discount($discountCoupon)) {
  510.                 $respy->success();
  511.                 $respy->setData($response);
  512.             } else {
  513.                 $respy->setError($this->translator->trans('reservation.couponNotFound'));
  514.             }
  515.         } catch (Exception $exception) {
  516.             $respy->setError($exception->getMessage());
  517.             $respy->setErrorCode($exception->getCode());
  518.         }
  519.         return new JsonResponse($respy->getResponse());
  520.     }
  521.     /**
  522.      * @Route("/api/reservation/packageprofit", name="api_reservation_packageprofit", methods={"POST"})
  523.      *
  524.      * @param RespyService $respy
  525.      * @param ValidatorService $validatorService
  526.      * @param ReservationService $reservationService
  527.      * @return JsonResponse
  528.      */
  529.     public function reservationPackageprofit(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  530.     {
  531.         $constraints = new Assert\Collection([
  532.             'voucher' => [
  533.                 new Assert\NotBlank()
  534.             ],
  535.             'pakageProfitId' => [
  536.                 new Assert\Required()
  537.             ]
  538.         ]);
  539.         try {
  540.             $input $validatorService->validate($constraints);
  541.             $packageProfit = (new PackageProfit())
  542.                 ->setVoucher($input["voucher"])
  543.                 ->setPackageProfitId($input["pakageProfitId"]);
  544.             if ($response $reservationService->packageProfit($packageProfit)) {
  545.                 $respy->success();
  546.                 $respy->setData($response);
  547.             }
  548.         } catch (Exception $exception) {
  549.             $respy->setError($exception->getMessage());
  550.             $respy->setErrorCode($exception->getCode());
  551.         }
  552.         return new JsonResponse($respy->getResponse());
  553.     }
  554.     /**
  555.      * @Route("/api/reservation/hotel-profit", name="api_reservation_hotel_profit", methods={"POST"})
  556.      *
  557.      * @param RespyService $respy
  558.      * @param ValidatorService $validatorService
  559.      * @param ReservationService $reservationService
  560.      * @return JsonResponse
  561.      */
  562.     public function reservationHotelProfit(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  563.     {
  564.         $constraints = new Assert\Collection([
  565.             'voucher' => [
  566.                 new Assert\NotBlank()
  567.             ],
  568.             'hotelProfitId' => [
  569.                 new Assert\Required()
  570.             ]
  571.         ]);
  572.         try {
  573.             $input $validatorService->validate($constraints);
  574.             $hotelProfit = (new HotelProfit())
  575.                 ->setVoucher($input['voucher'])
  576.                 ->setHotelProfitId($input['hotelProfitId']);
  577.             if ($response $reservationService->hotelProfit($hotelProfit)) {
  578.                 $respy->success();
  579.                 $respy->setData($response);
  580.             }
  581.         } catch (Exception $exception) {
  582.             $respy->setError($exception->getMessage());
  583.             $respy->setErrorCode($exception->getCode());
  584.         }
  585.         return new JsonResponse($respy->getResponse());
  586.     }
  587.     /**
  588.      * @Route("/api/reservation/profit", name="api_reservation_profit", methods={"POST"})
  589.      *
  590.      * @param RespyService $respy
  591.      * @param ValidatorService $validatorService
  592.      * @param ReservationService $reservationService
  593.      * @return JsonResponse
  594.      */
  595.     public function reservationProfit(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  596.     {
  597.         $constraints = new Assert\Collection([
  598.             'voucher' => [
  599.                 new Assert\NotBlank()
  600.             ],
  601.             'percent' => [
  602.                 new Assert\Required()
  603.             ]
  604.         ]);
  605.         try {
  606.             $input $validatorService->validate($constraints);
  607.             $profit = (new Profit())
  608.                 ->setVoucher($input["voucher"])
  609.                 ->setPercent($input["percent"]);
  610.             if ($response $reservationService->profit($profit)) {
  611.                 $respy->success();
  612.                 $respy->setData($response);
  613.             }
  614.         } catch (Exception $exception) {
  615.             $respy->setError($exception->getMessage());
  616.             $respy->setErrorCode($exception->getCode());
  617.         }
  618.         return new JsonResponse($respy->getResponse());
  619.     }
  620.     /**
  621.      * @Route("/api/reservation/packageprofitall", name="api_reservation_packageprofit_all", methods={"POST"})
  622.      *
  623.      * @param RespyService $respy
  624.      * @param ValidatorService $validatorService
  625.      * @param ReservationService $reservationService
  626.      * @return JsonResponse
  627.      */
  628.     public function reservationPackageprofitAll(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  629.     {
  630.         $constraints = new Assert\Collection([
  631.             'checkIn' => [
  632.                 new Assert\NotBlank()
  633.             ],
  634.             'checkOut' => [
  635.                 new Assert\NotBlank()
  636.             ]
  637.         ]);
  638.         try {
  639.             $input $validatorService->validate($constraints);
  640.             $packageProfitAll = (new PackageProfitAll())
  641.                 ->setCheckIn($input["checkIn"])
  642.                 ->setCheckOut($input["checkOut"]);
  643.             if ($response $reservationService->packageProfitAll($packageProfitAll)) {
  644.                 $respy->success();
  645.                 $respy->setData($response);
  646.             }
  647.         } catch (Exception $exception) {
  648.             $respy->setError($exception->getMessage());
  649.             $respy->setErrorCode($exception->getCode());
  650.         }
  651.         return new JsonResponse($respy->getResponse());
  652.     }
  653.     /**
  654.      * @Route("/api/reservation/ebinsurance", name="api_reservation_ebinsurance", methods={"POST"})
  655.      *
  656.      * @param RespyService $respy
  657.      * @param ValidatorService $validatorService
  658.      * @param ReservationService $reservationService
  659.      * @return JsonResponse
  660.      */
  661.     public function reservationEbInsurance(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  662.     {
  663.         $constraints = new Assert\Collection([
  664.             'voucher' => [
  665.                 new Assert\NotBlank()
  666.             ],
  667.             'check' => [
  668.                 new Assert\NotBlank(),
  669.                 new Assert\Choice(Parameter::YES_NO)
  670.             ],
  671.         ]);
  672.         try {
  673.             $input $validatorService->validate($constraints);
  674.             $ebInsurance = (new EbInsurance())
  675.                 ->setVoucher($input["voucher"])
  676.                 ->setCheck($input["check"]);
  677.             if ($response $reservationService->ebInsurance($ebInsurance)) {
  678.                 $respy->success();
  679.                 $respy->setData($response);
  680.             }
  681.         } catch (Exception $exception) {
  682.             $respy->setError($exception->getMessage());
  683.             $respy->setErrorCode($exception->getCode());
  684.         }
  685.         return new JsonResponse($respy->getResponse());
  686.     }
  687.     /**
  688.      * @Route("/api/site-reservation-review", name="api_site_reservation_review")
  689.      *
  690.      * @param RespyService $respy
  691.      * @param ValidatorService $validatorService
  692.      * @param ReservationService $reservationService
  693.      * @return JsonResponse
  694.      */
  695.     public function reservationReview(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  696.     {
  697.         $constraints = new Assert\Collection([
  698.             'voucher' => [
  699.                 new Assert\NotBlank(),
  700.             ],
  701.             'pointMeal' => [
  702.                 new Assert\NotBlank(),
  703.                 new Assert\Choice(Parameter::REVIEW_POINT)
  704.             ],
  705.             'pointRoom' => [
  706.                 new Assert\NotBlank(),
  707.                 new Assert\Choice(Parameter::REVIEW_POINT)
  708.             ],
  709.             'pointService' => [
  710.                 new Assert\NotBlank(),
  711.                 new Assert\Choice(Parameter::REVIEW_POINT)
  712.             ],
  713.             'pointOperationUser' => [
  714.                 new Assert\Optional([
  715.                     new Assert\Choice(Parameter::REVIEW_POINT)
  716.                 ]),
  717.             ],
  718.             'description' => [
  719.                 new Assert\NotBlank()
  720.             ],
  721.             'vocationType' => [
  722.                 new Assert\NotBlank(),
  723.                 new Assert\Choice(Parameter::REVIEW_VOCATION_TYPE)
  724.             ],
  725.             'recommend' => [
  726.                 new Assert\NotBlank(),
  727.                 new Assert\Choice(Parameter::REVIEW_RECOMMEND)
  728.             ],
  729.         ]);
  730.         try {
  731.             $input $validatorService->validate($constraints);
  732.             $review = (new Review())
  733.                 ->setVoucher($input["voucher"])
  734.                 ->setPointMeal($input["pointMeal"])
  735.                 ->setPointRoom($input["pointRoom"])
  736.                 ->setPointService($input["pointService"])
  737.                 ->setPointOperationUser($input["pointOperationUser"])
  738.                 ->setDescription($input["description"])
  739.                 ->setVocationType($input["vocationType"])
  740.                 ->setRecommend($input["recommend"]);
  741.             if ($response $reservationService->review($review)) {
  742.                 $respy->success();
  743.                 $respy->setData($response);
  744.             }
  745.         } catch (Exception $exception) {
  746.             $respy->setError($exception->getMessage());
  747.             $respy->setErrorCode($exception->getCode());
  748.         }
  749.         return new JsonResponse($respy->getResponse());
  750.     }
  751.     /**
  752.      * @Route("/api/reservation/request", name="api_reservation_request")
  753.      *
  754.      * @param Request $request
  755.      * @param RespyService $respy
  756.      * @param ValidatorService $validatorService
  757.      * @param ReservationService $reservationService
  758.      * @return JsonResponse
  759.      */
  760.     public function addRequest(Request $requestRespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  761.     {
  762.         $constraints = new Assert\Collection([
  763.             'title' => [
  764.                 new Assert\Required(),
  765.             ],
  766.             'checkIn' => [
  767.                 new Assert\Required(),
  768.                 new Assert\Date()
  769.             ],
  770.             'checkOut' => [
  771.                 new Assert\Required(),
  772.                 new Assert\Date()
  773.             ],
  774.             'adtCount' => [
  775.                 new Assert\Required(),
  776.             ],
  777.             'chdCount' => [
  778.                 new Assert\Required(),
  779.             ],
  780.             'chd1Age' => [
  781.                 new Assert\Required(),
  782.             ],
  783.             'chd2Age' => [
  784.                 new Assert\Required(),
  785.             ],
  786.             'callDate' => [
  787.                 new Assert\NotBlank(),
  788.                 new Assert\Date(),
  789.             ],
  790.             'callTime' => [
  791.                 new Assert\NotBlank(),
  792.                 new Assert\Choice(Parameter::REQUEST_CALLTIME)
  793.             ],
  794.             'firstName' => [
  795.                 new Assert\Required(),
  796.             ],
  797.             'lastName' => [
  798.                 new Assert\Required(),
  799.             ],
  800.             'phone' => [
  801.                 new Assert\NotBlank(),
  802.             ],
  803.             'email' => [
  804.                 new Assert\Required(),
  805.                 new Assert\Email(),
  806.             ],
  807.             'guestNote' => [
  808.                 new Assert\NotBlank(),
  809.             ],
  810.             'pageUrl' => [
  811.                 new Assert\Optional(),
  812.             ],
  813.             'consentContract' => [
  814.                 new Assert\Required(),
  815.                 new Assert\IsTrue(),
  816.             ],
  817.             'hotelId' => [
  818.                 new Assert\Optional(),
  819.             ],
  820.             'tourId' => [
  821.                 new Assert\Optional(),
  822.             ],
  823.             'reservationId' => [
  824.                 new Assert\Optional(),
  825.             ],
  826.         ]);
  827.         $content json_decode($request->getContent(), true);
  828.         try {
  829.             $input $validatorService->validate($constraints);
  830.             $requestData = (new RequestData())
  831.                 ->setHotelId($input['hotelId'] ?? 0)
  832.                 ->setTourId($input['tourId'] ?? 0)
  833.                 ->setReservationId($content['reservationId'] ?? 0)
  834.                 ->setTitle($input['title'])
  835.                 ->setCheckIn($input['checkIn'])
  836.                 ->setCheckOut($input['checkOut'])
  837.                 ->setAdtCount($input['adtCount'])
  838.                 ->setChdCount($input['chdCount'])
  839.                 ->setChd1Age($input['chd1Age'])
  840.                 ->setChd2Age($input['chd2Age'])
  841.                 ->setFirstName($input['firstName'])
  842.                 ->setLastName($input['lastName'])
  843.                 ->setPhone($input['phone'])
  844.                 ->setEmail($input['email'])
  845.                 ->setCallDate($input['callDate'])
  846.                 ->setCallTime($input['callTime'])
  847.                 ->setGuestNote($input['guestNote'])
  848.                 ->setUrl($input['pageUrl'] ?? '')
  849.                 ->setConsentContract($input['consentContract'] ?? false);
  850.             if ($response $reservationService->request($requestData)) {
  851.                 $respy->success();
  852.                 $respy->setData($response);
  853.             }
  854.         } catch (Exception $exception) {
  855.             $respy->setError($exception->getMessage());
  856.             $respy->setErrorCode($exception->getCode());
  857.         }
  858.         return new JsonResponse($respy->getResponse());
  859.     }
  860.     /**
  861.      * @Route("/api/reservation/note", name="api_reservation_note")
  862.      *
  863.      * @param RespyService $respy
  864.      * @param ValidatorService $validatorService
  865.      * @param ReservationService $reservationService
  866.      * @return JsonResponse
  867.      */
  868.     public function addNote(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  869.     {
  870.         $constraints = new Assert\Collection([
  871.             'voucher' => [
  872.                 new Assert\Required(),
  873.                 new Assert\NotBlank(),
  874.             ],
  875.             'note' => [
  876.                 new Assert\Required(),
  877.                 new Assert\NotBlank(),
  878.             ],
  879.         ]);
  880.         try {
  881.             $input $validatorService->validate($constraints);
  882.             $requestData = (new Note())
  883.                 ->setVoucher($input['voucher'] ?? '')
  884.                 ->setNote($input['note'] ?? '');
  885.             if ($response $reservationService->note($requestData)) {
  886.                 $respy->success();
  887.                 $respy->setData($response);
  888.             }
  889.         } catch (Exception $exception) {
  890.             $respy->setError($exception->getMessage());
  891.             $respy->setErrorCode($exception->getCode());
  892.         }
  893.         return new JsonResponse($respy->getResponse());
  894.     }
  895.     /**
  896.      * @Route("/api/reservation/forwarding-notification", name="api_reservation_forwarding_notification")
  897.      *
  898.      * @param RespyService $respy
  899.      * @param ValidatorService $validatorService
  900.      * @param ReservationService $reservationService
  901.      * @return JsonResponse
  902.      */
  903.     public function forwardingNotification(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  904.     {
  905.         $constraints = new Assert\Collection([
  906.             'reservation' => [
  907.                 new Assert\Required(),
  908.                 new Assert\NotBlank(),
  909.             ],
  910.         ]);
  911.         try {
  912.             $input $validatorService->validate($constraints);
  913.             $requestData = (new ForwardingNotification())
  914.                 ->setReservation($input['reservation'] ?? '');
  915.             if ($response $reservationService->forwardingNotification($requestData)) {
  916.                 $respy->success();
  917.                 $respy->setData($response);
  918.             }
  919.         } catch (Exception $exception) {
  920.             $respy->setError($exception->getMessage());
  921.             $respy->setErrorCode($exception->getCode());
  922.         }
  923.         return new JsonResponse($respy->getResponse());
  924.     }
  925.     /**
  926.      * @Route("/api/reservation/hotelextra", name="api_reservation_hotelextra", methods={"POST"})
  927.      *
  928.      * @param RespyService $respy
  929.      * @param ValidatorService $validatorService
  930.      * @param ReservationService $reservationService
  931.      * @return JsonResponse
  932.      */
  933.     public function reservationHotelExtras(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  934.     {
  935.         $constraints = new Assert\Collection([
  936.             'voucher' => [
  937.                 new Assert\NotBlank()
  938.             ],
  939.             'code' => [
  940.                 new Assert\NotBlank(),
  941.             ],
  942.         ]);
  943.         try {
  944.             $input $validatorService->validate($constraints);
  945.             $hotelExtra = (new HotelExtra())
  946.                 ->setVoucher($input["voucher"])
  947.                 ->setCode($input["code"]);
  948.             if ($response $reservationService->hotelExtra($hotelExtra)) {
  949.                 $respy->success();
  950.                 $respy->setData($response);
  951.             }
  952.         } catch (Exception $exception) {
  953.             $respy->setError($exception->getMessage());
  954.             $respy->setErrorCode($exception->getCode());
  955.         }
  956.         return new JsonResponse($respy->getResponse());
  957.     }
  958. }