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

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.             foreach ($input["pax"] as $p) {
  444.                 $pax = (new Pax())
  445.                     ->setType($p["type"])
  446.                     ->setFirstName($p["firstName"])
  447.                     ->setLastName($p["lastName"])
  448.                     ->setGender($p["gender"])
  449.                     ->setBirthDay($p["birthday"])
  450.                     ->setIdentifyNumber($p["identifyNumber"])
  451.                     ->setPhone($p["phone"])
  452.                     ->setPassportNumber($p["passportNumber"] ?: '')
  453.                     ->setPassportValidityDate($p["passportValidityDate"] ?: '');
  454.                 $reservationPaxInvoiceSave->addPax($pax);
  455.             }
  456.             if (!empty($input["invoice"])) {
  457.                 $invoice = (new Invoice())
  458.                     ->setType($input["invoice"]["type"])
  459.                     ->setFirstName($input["invoice"]["firstName"])
  460.                     ->setLastName($input["invoice"]["lastName"])
  461.                     ->setCompanyName($input["invoice"]["companyName"])
  462.                     ->setEmail($input["invoice"]["email"])
  463.                     ->setPhone($input["invoice"]["phone"])
  464.                     ->setIdentifyNumber($input["invoice"]["identifyNumber"])
  465.                     ->setTaxOffice($input["invoice"]["taxOffice"])
  466.                     ->setTaxNumber($input["invoice"]["taxNumber"])
  467.                     ->setAddress($input["invoice"]["address"])
  468.                     ->setCity($input["invoice"]["city"] ?? '')
  469.                     ->setDistrict($input["invoice"]["district"] ?? '');
  470.                 $reservationPaxInvoiceSave->setInvoice($invoice);
  471.             }
  472.             if ($response $reservationService->paxInvoiceSave($reservationPaxInvoiceSave)) {
  473.                 $respy->success();
  474.                 $respy->setData($response);
  475.             }
  476.         } catch (Exception $exception) {
  477.             $respy->setError($exception->getMessage());
  478.             $respy->setErrorCode($exception->getCode());
  479.         }
  480.         return new JsonResponse($respy->getResponse());
  481.     }
  482.     /**
  483.      * @Route("/api/reservation/discountcoupon", name="api_reservation_discountcoupon", methods={"POST"})
  484.      *
  485.      * @param RespyService $respy
  486.      * @param ValidatorService $validatorService
  487.      * @param ReservationService $reservationService
  488.      * @return JsonResponse
  489.      */
  490.     public function reservationDiscount(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  491.     {
  492.         $constraints = new Assert\Collection([
  493.             'guid' => [
  494.                 new Assert\NotBlank()
  495.             ],
  496.             'discountCode' => [
  497.                 new Assert\NotBlank()
  498.             ]
  499.         ]);
  500.         try {
  501.             $input $validatorService->validate($constraints);
  502.             $discountCoupon = (new DiscountCoupon())
  503.                 ->setGuid($input["guid"])
  504.                 ->setDiscountCouponCode($input["discountCode"]);
  505.             if ($response $reservationService->discount($discountCoupon)) {
  506.                 $respy->success();
  507.                 $respy->setData($response);
  508.             } else {
  509.                 $respy->setError($this->translator->trans('reservation.couponNotFound'));
  510.             }
  511.         } catch (Exception $exception) {
  512.             $respy->setError($exception->getMessage());
  513.             $respy->setErrorCode($exception->getCode());
  514.         }
  515.         return new JsonResponse($respy->getResponse());
  516.     }
  517.     /**
  518.      * @Route("/api/reservation/packageprofit", name="api_reservation_packageprofit", methods={"POST"})
  519.      *
  520.      * @param RespyService $respy
  521.      * @param ValidatorService $validatorService
  522.      * @param ReservationService $reservationService
  523.      * @return JsonResponse
  524.      */
  525.     public function reservationPackageprofit(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  526.     {
  527.         $constraints = new Assert\Collection([
  528.             'voucher' => [
  529.                 new Assert\NotBlank()
  530.             ],
  531.             'pakageProfitId' => [
  532.                 new Assert\Required()
  533.             ]
  534.         ]);
  535.         try {
  536.             $input $validatorService->validate($constraints);
  537.             $packageProfit = (new PackageProfit())
  538.                 ->setVoucher($input["voucher"])
  539.                 ->setPackageProfitId($input["pakageProfitId"]);
  540.             if ($response $reservationService->packageProfit($packageProfit)) {
  541.                 $respy->success();
  542.                 $respy->setData($response);
  543.             }
  544.         } catch (Exception $exception) {
  545.             $respy->setError($exception->getMessage());
  546.             $respy->setErrorCode($exception->getCode());
  547.         }
  548.         return new JsonResponse($respy->getResponse());
  549.     }
  550.     /**
  551.      * @Route("/api/reservation/hotel-profit", name="api_reservation_hotel_profit", methods={"POST"})
  552.      *
  553.      * @param RespyService $respy
  554.      * @param ValidatorService $validatorService
  555.      * @param ReservationService $reservationService
  556.      * @return JsonResponse
  557.      */
  558.     public function reservationHotelProfit(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  559.     {
  560.         $constraints = new Assert\Collection([
  561.             'voucher' => [
  562.                 new Assert\NotBlank()
  563.             ],
  564.             'hotelProfitId' => [
  565.                 new Assert\Required()
  566.             ]
  567.         ]);
  568.         try {
  569.             $input $validatorService->validate($constraints);
  570.             $hotelProfit = (new HotelProfit())
  571.                 ->setVoucher($input['voucher'])
  572.                 ->setHotelProfitId($input['hotelProfitId']);
  573.             if ($response $reservationService->hotelProfit($hotelProfit)) {
  574.                 $respy->success();
  575.                 $respy->setData($response);
  576.             }
  577.         } catch (Exception $exception) {
  578.             $respy->setError($exception->getMessage());
  579.             $respy->setErrorCode($exception->getCode());
  580.         }
  581.         return new JsonResponse($respy->getResponse());
  582.     }
  583.     /**
  584.      * @Route("/api/reservation/profit", name="api_reservation_profit", methods={"POST"})
  585.      *
  586.      * @param RespyService $respy
  587.      * @param ValidatorService $validatorService
  588.      * @param ReservationService $reservationService
  589.      * @return JsonResponse
  590.      */
  591.     public function reservationProfit(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  592.     {
  593.         $constraints = new Assert\Collection([
  594.             'voucher' => [
  595.                 new Assert\NotBlank()
  596.             ],
  597.             'percent' => [
  598.                 new Assert\Required()
  599.             ]
  600.         ]);
  601.         try {
  602.             $input $validatorService->validate($constraints);
  603.             $profit = (new Profit())
  604.                 ->setVoucher($input["voucher"])
  605.                 ->setPercent($input["percent"]);
  606.             if ($response $reservationService->profit($profit)) {
  607.                 $respy->success();
  608.                 $respy->setData($response);
  609.             }
  610.         } catch (Exception $exception) {
  611.             $respy->setError($exception->getMessage());
  612.             $respy->setErrorCode($exception->getCode());
  613.         }
  614.         return new JsonResponse($respy->getResponse());
  615.     }
  616.     /**
  617.      * @Route("/api/reservation/packageprofitall", name="api_reservation_packageprofit_all", methods={"POST"})
  618.      *
  619.      * @param RespyService $respy
  620.      * @param ValidatorService $validatorService
  621.      * @param ReservationService $reservationService
  622.      * @return JsonResponse
  623.      */
  624.     public function reservationPackageprofitAll(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  625.     {
  626.         $constraints = new Assert\Collection([
  627.             'checkIn' => [
  628.                 new Assert\NotBlank()
  629.             ],
  630.             'checkOut' => [
  631.                 new Assert\NotBlank()
  632.             ]
  633.         ]);
  634.         try {
  635.             $input $validatorService->validate($constraints);
  636.             $packageProfitAll = (new PackageProfitAll())
  637.                 ->setCheckIn($input["checkIn"])
  638.                 ->setCheckOut($input["checkOut"]);
  639.             if ($response $reservationService->packageProfitAll($packageProfitAll)) {
  640.                 $respy->success();
  641.                 $respy->setData($response);
  642.             }
  643.         } catch (Exception $exception) {
  644.             $respy->setError($exception->getMessage());
  645.             $respy->setErrorCode($exception->getCode());
  646.         }
  647.         return new JsonResponse($respy->getResponse());
  648.     }
  649.     /**
  650.      * @Route("/api/reservation/ebinsurance", name="api_reservation_ebinsurance", methods={"POST"})
  651.      *
  652.      * @param RespyService $respy
  653.      * @param ValidatorService $validatorService
  654.      * @param ReservationService $reservationService
  655.      * @return JsonResponse
  656.      */
  657.     public function reservationEbInsurance(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  658.     {
  659.         $constraints = new Assert\Collection([
  660.             'voucher' => [
  661.                 new Assert\NotBlank()
  662.             ],
  663.             'check' => [
  664.                 new Assert\NotBlank(),
  665.                 new Assert\Choice(Parameter::YES_NO)
  666.             ],
  667.         ]);
  668.         try {
  669.             $input $validatorService->validate($constraints);
  670.             $ebInsurance = (new EbInsurance())
  671.                 ->setVoucher($input["voucher"])
  672.                 ->setCheck($input["check"]);
  673.             if ($response $reservationService->ebInsurance($ebInsurance)) {
  674.                 $respy->success();
  675.                 $respy->setData($response);
  676.             }
  677.         } catch (Exception $exception) {
  678.             $respy->setError($exception->getMessage());
  679.             $respy->setErrorCode($exception->getCode());
  680.         }
  681.         return new JsonResponse($respy->getResponse());
  682.     }
  683.     /**
  684.      * @Route("/api/site-reservation-review", name="api_site_reservation_review")
  685.      *
  686.      * @param RespyService $respy
  687.      * @param ValidatorService $validatorService
  688.      * @param ReservationService $reservationService
  689.      * @return JsonResponse
  690.      */
  691.     public function reservationReview(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  692.     {
  693.         $constraints = new Assert\Collection([
  694.             'voucher' => [
  695.                 new Assert\NotBlank(),
  696.             ],
  697.             'pointMeal' => [
  698.                 new Assert\NotBlank(),
  699.                 new Assert\Choice(Parameter::REVIEW_POINT)
  700.             ],
  701.             'pointRoom' => [
  702.                 new Assert\NotBlank(),
  703.                 new Assert\Choice(Parameter::REVIEW_POINT)
  704.             ],
  705.             'pointService' => [
  706.                 new Assert\NotBlank(),
  707.                 new Assert\Choice(Parameter::REVIEW_POINT)
  708.             ],
  709.             'pointOperationUser' => [
  710.                 new Assert\Optional([
  711.                     new Assert\Choice(Parameter::REVIEW_POINT)
  712.                 ]),
  713.             ],
  714.             'description' => [
  715.                 new Assert\NotBlank()
  716.             ],
  717.             'vocationType' => [
  718.                 new Assert\NotBlank(),
  719.                 new Assert\Choice(Parameter::REVIEW_VOCATION_TYPE)
  720.             ],
  721.             'recommend' => [
  722.                 new Assert\NotBlank(),
  723.                 new Assert\Choice(Parameter::REVIEW_RECOMMEND)
  724.             ],
  725.         ]);
  726.         try {
  727.             $input $validatorService->validate($constraints);
  728.             $review = (new Review())
  729.                 ->setVoucher($input["voucher"])
  730.                 ->setPointMeal($input["pointMeal"])
  731.                 ->setPointRoom($input["pointRoom"])
  732.                 ->setPointService($input["pointService"])
  733.                 ->setPointOperationUser($input["pointOperationUser"])
  734.                 ->setDescription($input["description"])
  735.                 ->setVocationType($input["vocationType"])
  736.                 ->setRecommend($input["recommend"]);
  737.             if ($response $reservationService->review($review)) {
  738.                 $respy->success();
  739.                 $respy->setData($response);
  740.             }
  741.         } catch (Exception $exception) {
  742.             $respy->setError($exception->getMessage());
  743.             $respy->setErrorCode($exception->getCode());
  744.         }
  745.         return new JsonResponse($respy->getResponse());
  746.     }
  747.     /**
  748.      * @Route("/api/reservation/request", name="api_reservation_request")
  749.      *
  750.      * @param Request $request
  751.      * @param RespyService $respy
  752.      * @param ValidatorService $validatorService
  753.      * @param ReservationService $reservationService
  754.      * @return JsonResponse
  755.      */
  756.     public function addRequest(Request $requestRespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  757.     {
  758.         $constraints = new Assert\Collection([
  759.             'title' => [
  760.                 new Assert\Required(),
  761.             ],
  762.             'checkIn' => [
  763.                 new Assert\Required(),
  764.                 new Assert\Date()
  765.             ],
  766.             'checkOut' => [
  767.                 new Assert\Required(),
  768.                 new Assert\Date()
  769.             ],
  770.             'adtCount' => [
  771.                 new Assert\Required(),
  772.             ],
  773.             'chdCount' => [
  774.                 new Assert\Required(),
  775.             ],
  776.             'chd1Age' => [
  777.                 new Assert\Required(),
  778.             ],
  779.             'chd2Age' => [
  780.                 new Assert\Required(),
  781.             ],
  782.             'callDate' => [
  783.                 new Assert\NotBlank(),
  784.                 new Assert\Date(),
  785.             ],
  786.             'callTime' => [
  787.                 new Assert\NotBlank(),
  788.                 new Assert\Choice(Parameter::REQUEST_CALLTIME)
  789.             ],
  790.             'firstName' => [
  791.                 new Assert\Required(),
  792.             ],
  793.             'lastName' => [
  794.                 new Assert\Required(),
  795.             ],
  796.             'phone' => [
  797.                 new Assert\NotBlank(),
  798.             ],
  799.             'email' => [
  800.                 new Assert\Required(),
  801.                 new Assert\Email(),
  802.             ],
  803.             'guestNote' => [
  804.                 new Assert\NotBlank(),
  805.             ],
  806.             'pageUrl' => [
  807.                 new Assert\Optional(),
  808.             ],
  809.             'consentContract' => [
  810.                 new Assert\Required(),
  811.                 new Assert\IsTrue(),
  812.             ],
  813.             'hotelId' => [
  814.                 new Assert\Optional(),
  815.             ],
  816.             'tourId' => [
  817.                 new Assert\Optional(),
  818.             ],
  819.             'reservationId' => [
  820.                 new Assert\Optional(),
  821.             ],
  822.         ]);
  823.         $content json_decode($request->getContent(), true);
  824.         try {
  825.             $input $validatorService->validate($constraints);
  826.             $requestData = (new RequestData())
  827.                 ->setHotelId($input['hotelId'] ?? 0)
  828.                 ->setTourId($input['tourId'] ?? 0)
  829.                 ->setReservationId($content['reservationId'] ?? 0)
  830.                 ->setTitle($input['title'])
  831.                 ->setCheckIn($input['checkIn'])
  832.                 ->setCheckOut($input['checkOut'])
  833.                 ->setAdtCount($input['adtCount'])
  834.                 ->setChdCount($input['chdCount'])
  835.                 ->setChd1Age($input['chd1Age'])
  836.                 ->setChd2Age($input['chd2Age'])
  837.                 ->setFirstName($input['firstName'])
  838.                 ->setLastName($input['lastName'])
  839.                 ->setPhone($input['phone'])
  840.                 ->setEmail($input['email'])
  841.                 ->setCallDate($input['callDate'])
  842.                 ->setCallTime($input['callTime'])
  843.                 ->setGuestNote($input['guestNote'])
  844.                 ->setUrl($input['pageUrl'] ?? '')
  845.                 ->setConsentContract($input['consentContract'] ?? false);
  846.             if ($response $reservationService->request($requestData)) {
  847.                 $respy->success();
  848.                 $respy->setData($response);
  849.             }
  850.         } catch (Exception $exception) {
  851.             $respy->setError($exception->getMessage());
  852.             $respy->setErrorCode($exception->getCode());
  853.         }
  854.         return new JsonResponse($respy->getResponse());
  855.     }
  856.     /**
  857.      * @Route("/api/reservation/note", name="api_reservation_note")
  858.      *
  859.      * @param RespyService $respy
  860.      * @param ValidatorService $validatorService
  861.      * @param ReservationService $reservationService
  862.      * @return JsonResponse
  863.      */
  864.     public function addNote(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  865.     {
  866.         $constraints = new Assert\Collection([
  867.             'voucher' => [
  868.                 new Assert\Required(),
  869.                 new Assert\NotBlank(),
  870.             ],
  871.             'note' => [
  872.                 new Assert\Required(),
  873.                 new Assert\NotBlank(),
  874.             ],
  875.         ]);
  876.         try {
  877.             $input $validatorService->validate($constraints);
  878.             $requestData = (new Note())
  879.                 ->setVoucher($input['voucher'] ?? '')
  880.                 ->setNote($input['note'] ?? '');
  881.             if ($response $reservationService->note($requestData)) {
  882.                 $respy->success();
  883.                 $respy->setData($response);
  884.             }
  885.         } catch (Exception $exception) {
  886.             $respy->setError($exception->getMessage());
  887.             $respy->setErrorCode($exception->getCode());
  888.         }
  889.         return new JsonResponse($respy->getResponse());
  890.     }
  891.     /**
  892.      * @Route("/api/reservation/forwarding-notification", name="api_reservation_forwarding_notification")
  893.      *
  894.      * @param RespyService $respy
  895.      * @param ValidatorService $validatorService
  896.      * @param ReservationService $reservationService
  897.      * @return JsonResponse
  898.      */
  899.     public function forwardingNotification(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  900.     {
  901.         $constraints = new Assert\Collection([
  902.             'reservation' => [
  903.                 new Assert\Required(),
  904.                 new Assert\NotBlank(),
  905.             ],
  906.         ]);
  907.         try {
  908.             $input $validatorService->validate($constraints);
  909.             $requestData = (new ForwardingNotification())
  910.                 ->setReservation($input['reservation'] ?? '');
  911.             if ($response $reservationService->forwardingNotification($requestData)) {
  912.                 $respy->success();
  913.                 $respy->setData($response);
  914.             }
  915.         } catch (Exception $exception) {
  916.             $respy->setError($exception->getMessage());
  917.             $respy->setErrorCode($exception->getCode());
  918.         }
  919.         return new JsonResponse($respy->getResponse());
  920.     }
  921.     /**
  922.      * @Route("/api/reservation/hotelextra", name="api_reservation_hotelextra", methods={"POST"})
  923.      *
  924.      * @param RespyService $respy
  925.      * @param ValidatorService $validatorService
  926.      * @param ReservationService $reservationService
  927.      * @return JsonResponse
  928.      */
  929.     public function reservationHotelExtras(RespyService $respyValidatorService $validatorServiceReservationService $reservationService): JsonResponse
  930.     {
  931.         $constraints = new Assert\Collection([
  932.             'voucher' => [
  933.                 new Assert\NotBlank()
  934.             ],
  935.             'code' => [
  936.                 new Assert\NotBlank(),
  937.             ],
  938.         ]);
  939.         try {
  940.             $input $validatorService->validate($constraints);
  941.             $hotelExtra = (new HotelExtra())
  942.                 ->setVoucher($input["voucher"])
  943.                 ->setCode($input["code"]);
  944.             if ($response $reservationService->hotelExtra($hotelExtra)) {
  945.                 $respy->success();
  946.                 $respy->setData($response);
  947.             }
  948.         } catch (Exception $exception) {
  949.             $respy->setError($exception->getMessage());
  950.             $respy->setErrorCode($exception->getCode());
  951.         }
  952.         return new JsonResponse($respy->getResponse());
  953.     }
  954. }