src/Controller/AppBundle/Controller/APIController.php line 52

Open in your IDE?
  1. <?php
  2. namespace App\Controller\AppBundle\Controller;
  3. use App\Controller\AppBundle\Connector\Awacs\AwacsCreateDocumentRequest;
  4. use App\Controller\AppBundle\Connector\Awacs\AwacsResponse;
  5. use App\Controller\AppBundle\Connector\Awacs\AwacsUpdateAPIRequest;
  6. use App\Controller\AppBundle\Connector\Awacs\AwacsUpdateRequest;
  7. use App\Controller\AppBundle\Connector\Awacs\AwacsViewRequest;
  8. use App\Controller\AppBundle\Connector\Awacs\Collection;
  9. use App\Controller\AppBundle\Connector\Awacs\FieldLabel;
  10. use App\Controller\AppBundle\Connector\Awacs\FieldPrimary;
  11. use App\Controller\AppBundle\Connector\Awacs\Filter;
  12. use App\Controller\AppBundle\Connector\FasterForward\FasterForwardHelper;
  13. use App\Controller\AppBundle\Connector\FasterForward\FasterForwardUpdateSchadeverzekeringRequest;
  14. use App\Controller\AppBundle\Connector\FasterForward\Helpers\FFManualInputOvervoerHelper;
  15. use App\Controller\AppBundle\Connector\VPI\VPIHelper;
  16. use App\Controller\AppBundle\Connector\VPI\VPIMapping;
  17. use App\Controller\AppBundle\Connector\VPI\VPIMappingNew;
  18. use App\Controller\AppBundle\Connector\VPI\VPIRequest;
  19. use App\Controller\AppBundle\Helpers\AccessHelper;
  20. use App\Controller\AppBundle\Interact\RelationSearch;
  21. use App\Entity\Slotvraag;
  22. use App\Repository\GIMCacheRepository;
  23. use Httpful\Http;
  24. use Symfony\Component\HttpFoundation\JsonResponse;
  25. use Symfony\Component\Routing\Annotation\Route;
  26. use App\Controller\AppBundle\Connector\RollsVehicleInformation\ConnectorVehicle;
  27. use App\Controller\AppBundle\Entity\PolisInformation;
  28. use App\Controller\AppBundle\Helpers\Admin\ConsultantHelper;
  29. use App\Controller\AppBundle\Helpers\ConsultantCompare\ProcessCar;
  30. use App\Controller\AppBundle\Helpers\FormValidator;
  31. use App\Controller\AppBundle\Helpers\TestHelper;
  32. use App\Controller\AppBundle\Interact\Compare\CartSessionHelper;
  33. use App\Controller\AppBundle\Interact\Compare\PolisResult;
  34. use App\Controller\AppBundle\Interact\Compare\RequestBuilderCar;
  35. use App\Controller\AppBundle\Interact\CreateRelation;
  36. use App\Controller\AppBundle\Interact\UserInformationANVA;
  37. use App\Entity\CartContainer;
  38. use App\Entity\User;
  39. use Doctrine\ORM\EntityManagerInterface;
  40. use Psr\Log\LoggerInterface;
  41. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  42. use Symfony\Component\HttpFoundation\Request;
  43. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  44. use Brick\VarExporter\VarExporter;
  45. class APIController extends AbstractController
  46. {
  47.     /**
  48.      * @Route("/shoot/{datasource}/{processSource}", name="shoot")
  49.      */
  50.     public function test2(EntityManagerInterface $emSessionInterface $session$datasource$processSourceRequest $request) {
  51.         if (!AccessHelper::ownIP($request->getClientIp())) {
  52.             return new JsonResponse(['access' => False]);
  53.         }
  54.         $entities json_decode($request->getContent());
  55.         $update = new AwacsUpdateAPIRequest($entities);
  56.         $response $update->sendAndRequest($datasourcenullnull$processSource);
  57.         $request $response[1];
  58.         $response $response[0];
  59.         $keys = [];
  60.         $errorById = [];
  61.         if ($response->getErrors() === []) {
  62.             $output $response->xml()->RESULT->EXECUTE;
  63.             try {
  64.                 foreach ($response->xml()->RESULT->EXECUTE->children() as $name => $xml) {
  65.                     $keys[strtolower($name)][] = (string)$xml->PK;
  66.                 }
  67.             } catch (\Exception $e) {}
  68.         } else {
  69.             $volgnums = [];
  70.             $i 0;
  71.             try {
  72.                 foreach ($response->xml()->RESULT->RELATIES->RELATIE->PAKKETTEN->PAKKET as $pakket) {
  73.                     foreach ($pakket->POLISSEN->POLIS as $polis) {
  74.                         $volgnums[(string)$polis->TRANSACTION_VOLGNR] = $i;
  75.                         $i $i 1;
  76.                     }
  77.                 }
  78.             } catch (\Exception $e) {}
  79.             $i 0;
  80.             if (count($errorById) != 0) {
  81.                 foreach ($response->xml()->RESULT->EXECUTE->ERROR as $error) {
  82.                     $errorById[$volgnums[(string)$error->TRANSACTION_VOLGNR]] = $response->getErrors()[array_keys($response->getErrors())[$i]];
  83.                     $i $i 1;
  84.                 }
  85.             } else {
  86.                 foreach ($response->xml()->RESULT->EXECUTE->ERROR as $error) {
  87.                     $errorById[] = (string)$error->MESSAGE;
  88.                     $i $i 1;
  89.                 }
  90.             }
  91.         }
  92.         return new JsonResponse([
  93.             'hasErrors' => $response->getErrors() !== [],
  94.             'errors' => $response->getErrors(),
  95.             'request' => $request,
  96.             'keys' => $keys,
  97.             'errorsById' => $errorById,
  98.         ]);
  99.     }
  100.     /**
  101.      * @Route("/insertDocument/{datasource}", name="shootDocument")
  102.      */
  103.     public function apiCallDocument(EntityManagerInterface $emSessionInterface $session$datasourceRequest $request) {
  104.         if (!AccessHelper::ownIP($request->getClientIp())) {
  105.             return new JsonResponse(['access' => False]);
  106.         }
  107.         $entities json_decode($request->getContent());
  108.         $result '';
  109.         foreach ($entities->data as $key => $value) {
  110.             $result .= "$key$value\n"// Concatenate key-value pairs into the result string
  111.         }
  112.         # Get 16 till 20 position of entities['polisKey']
  113.         $polisKeySubset substr($entities->polisKey155);
  114.         # Get 21 position onwards
  115.         $polisKeySubset2 substr($entities->polisKey20);
  116.         $request = new AwacsCreateDocumentRequest($result'OvervoerVKGExtranetData.txt''OvervoerVKG Data ' $entities->data->{'Overzicht->Polisnummer'}, $entities->relatieKeytruefalsefalse$polisKeySubset$polisKeySubset2);
  117.         $response $request->sendAndRequest($datasource);
  118.         $request $response[1];
  119.         $response $response[0];
  120.         $keys = [];
  121.         $errorById = [];
  122.         if ($response->getErrors() === []) {
  123.             $output $response->xml()->RESULT->EXECUTE;
  124.             try {
  125.                 foreach ($response->xml()->RESULT->EXECUTE->children() as $name => $xml) {
  126.                     $keys[strtolower($name)][] = (string)$xml->PK;
  127.                 }
  128.             } catch (\Exception $e) {}
  129.         } else {
  130.             $volgnums = [];
  131.             $i 0;
  132.             try {
  133.                 foreach ($response->xml()->RESULT->RELATIES->RELATIE->PAKKETTEN->PAKKET as $pakket) {
  134.                     foreach ($pakket->POLISSEN->POLIS as $polis) {
  135.                         $volgnums[(string)$polis->TRANSACTION_VOLGNR] = $i;
  136.                         $i $i 1;
  137.                     }
  138.                 }
  139.             } catch (\Exception $e) {}
  140.             $i 0;
  141.             if (count($errorById) != 0) {
  142.                 foreach ($response->xml()->RESULT->EXECUTE->ERROR as $error) {
  143.                     $errorById[$volgnums[(string)$error->TRANSACTION_VOLGNR]] = $response->getErrors()[array_keys($response->getErrors())[$i]];
  144.                     $i $i 1;
  145.                 }
  146.             } else {
  147.                 foreach ($response->xml()->RESULT->EXECUTE->ERROR as $error) {
  148.                     $errorById[] = (string)$error->MESSAGE;
  149.                     $i $i 1;
  150.                 }
  151.             }
  152.         }
  153.         return new JsonResponse([
  154.             'hasErrors' => $response->getErrors() !== [],
  155.             'errors' => $response->getErrors(),
  156.             'request' => $request,
  157.             'keys' => $keys,
  158.             'errorsById' => $errorById,
  159.         ]);
  160.     }
  161.     /**
  162.      * @Route("/getPremie/{datasource}", name="getPremieAPI")
  163.      */
  164.     public function test3(EntityManagerInterface $emSessionInterface $session$datasourceRequest $request) {
  165.         if (!AccessHelper::ownIP($request->getClientIp())) {
  166.             return new JsonResponse(['access' => False]);
  167.         }
  168.         $key json_decode($request->getContent());
  169.         # Make length of key 25 by cutting of the right
  170.         if (!str_contains($key'WACBES_')) {
  171.             $key substr($key025);
  172.         }
  173.         $prefix '';
  174.         // If key contains WACBES_
  175.         if (strpos($key'WACBES_') !== false) {
  176.             $prefix 'wacht';
  177.         }
  178.         $collection = new Collection($prefix 'polissen');
  179.         $collection->addField(FieldLabel::name('polis''incassobedrag'));
  180.         $collection->addField(FieldLabel::name('polis''acceptatie'));
  181.         $collection->addField(FieldLabel::name('polis''prolongatiekosten'));
  182.         $collection->addField(FieldLabel::name('polis''termijn'));
  183.         $collection->addFilter(new Filter(new FieldPrimary(), $key'='));
  184.         $request = new AwacsViewRequest($collection);
  185.         $res $request->send($datasource);
  186.         if (count($res->entities()) == 0) {
  187.             return new JsonResponse([
  188.                 'found' => false,
  189.             ]);
  190.         }
  191.         return new JsonResponse([
  192.             'found' => true,
  193.             'incassobedrag' => $res->entities()[0]->field('incassobedrag')->value(),
  194.             'acceptatie' => $res->entities()[0]->field('acceptatie')->value(),
  195.             'prolongatiekosten' => $res->entities()[0]->field('prolongatiekosten')->value(),
  196.             'termijn' => $res->entities()[0]->field('termijn')->value()
  197.         ]);
  198.     }
  199.     /**
  200.      * @Route("/getStatus/{datasource}", name="getStatusAPI")
  201.      */
  202.     public function test11(EntityManagerInterface $emSessionInterface $session$datasourceRequest $request) {
  203.         if (!AccessHelper::ownIP($request->getClientIp())) {
  204.             return new JsonResponse(['access' => False]);
  205.         }
  206.         $key json_decode($request->getContent());
  207.         # Make length of key 25 by cutting of the right
  208.         if (!str_contains($key'WACBES_')) {
  209.             $key substr($key025);
  210.         }
  211.         $prefix '';
  212.         // If key contains WACBES_
  213.         if (strpos($key'WACBES_') !== false) {
  214.             $prefix 'wacht';
  215.         }
  216.         $collection = new Collection($prefix 'polissen');
  217.         $collection->addField(FieldLabel::name('polis''incassobedrag'));
  218.         $collection->addField(FieldLabel::name('polis''acceptatie'));
  219.         $collection->addField(FieldLabel::name('polis''prolongatiekosten'));
  220.         $collection->addField(FieldLabel::name('polis''termijn'));
  221.         $collection->addField(FieldLabel::name('polis''wijzigingsreden'));
  222.         $collection->addFilter(new Filter(new FieldPrimary(), $key'='));
  223.         $request = new AwacsViewRequest($collection);
  224.         $res $request->send($datasource);
  225.         if (count($res->entities()) == 0) {
  226.             return new JsonResponse([
  227.                 'found' => false,
  228.             ]);
  229.         }
  230.         $isGeroyeerd = ((int)$res->entities()[0]->field('wijzigingsreden')->value()) >= 40 && ((int)$res->entities()[0]->field('wijzigingsreden')->value()) < 50;
  231.         $isNietProlongerend = ((int)$res->entities()[0]->field('wijzigingsreden')->value()) >= 14 && ((int)$res->entities()[0]->field('wijzigingsreden')->value()) < 30;
  232.         return new JsonResponse([
  233.             'found' => true,
  234.             'incassobedrag' => $res->entities()[0]->field('incassobedrag')->value(),
  235.             'acceptatie' => $res->entities()[0]->field('acceptatie')->value(),
  236.             'prolongatiekosten' => $res->entities()[0]->field('prolongatiekosten')->value(),
  237.             'termijn' => $res->entities()[0]->field('termijn')->value(),
  238.             'isGeroyeerd' => $isGeroyeerd,
  239.             'isNietProlongerend' => $isNietProlongerend,
  240.             'wijzigingsreden' => $res->entities()[0]->field('wijzigingsreden')->value()
  241.         ]);
  242.     }
  243.     /**
  244.      * @Route("/getDekkingen/{datasource}", name="getDekkingenAPI")
  245.      */
  246.     public function test6(EntityManagerInterface $emSessionInterface $session$datasourceRequest $request) {
  247.         if (!AccessHelper::ownIP($request->getClientIp())) {
  248.             return new JsonResponse(['access' => False]);
  249.         }
  250.         $key json_decode($request->getContent());
  251.         $prefix '';
  252.         // If key contains WACBES_
  253.         if (strpos($key'WACBES_') !== false) {
  254.             $prefix 'wacht';
  255.         } else {
  256.             $key substr($key025);
  257.         }
  258.         $collection = new Collection($prefix .'polissen');
  259.         $collection->addFilter(new Filter(new FieldPrimary(), $key'='));
  260.         $collectionDekkingen = new Collection($prefix .'dekkingen');
  261.         $collectionDekkingen->addField(new FieldPrimary());
  262.         $collection->addCollection($collectionDekkingen);
  263.         $request = new AwacsViewRequest($collection);
  264.         $res $request->send($datasource);
  265.         $dekkingIds = [];
  266.         foreach ($res->entities()[0]->collection($prefix .'dekkingen') as $dekking) {
  267.             $dekkingIds[] = $dekking->key;
  268.         }
  269.         return new JsonResponse([
  270.             'keys' => $dekkingIds,
  271.         ]);
  272.     }
  273.     /**
  274.      * @Route("/getPolisIds/{datasource}", name="getPolisIdsAPI")
  275.      */
  276.     public function test6547(EntityManagerInterface $emSessionInterface $session$datasourceRequest $request) {
  277.         if (!AccessHelper::ownIP($request->getClientIp())) {
  278.             return new JsonResponse(['access' => False]);
  279.         }
  280.         $key json_decode($request->getContent());
  281.         $key substr($key016);
  282. //        if (strpos($key, 'NAWBES_') !== false) {
  283. //            $key = str_replace('NAWBES_', '', $key);
  284. //        }
  285.         $collection = new Collection('relaties');
  286.         $collection->addFilter(new Filter(new FieldPrimary(), $key'='));
  287.         $collectionPakketten = new Collection('pakketten');
  288.         $collectionPakketten->addField(new FieldPrimary());
  289.         $collectionPolissen = new Collection('polissen');
  290.         $collectionPolissen->addField(new FieldPrimary());
  291.         $collectionPolissen->addField(FieldLabel::name('polis''wijzigingsreden'));
  292.         $collectionPolissen->addField(FieldLabel::name('polis''collectiviteit'));
  293.         $collectionPolissen->addField(FieldLabel::name('polis''polisnummer_oud'));
  294.         $collectionPolissen->addField(FieldLabel::name('polis''incassobedrag'));
  295.         $collectionPolissen->addField(FieldLabel::name('polis''termijn'));
  296.         $collectionPolissen->addField(FieldLabel::name('polis''wijzigingsreden'));
  297.         $collectionPolissen->addField(FieldLabel::name('polis''ingangsdatum'));
  298.         $collectionPolissen->addFilter(new Filter(new FieldLabel('10095'), '12''='));
  299.         $collectionPakketten->addCollection($collectionPolissen);
  300.         $collectionPolissen = new Collection('wachtpolissen');
  301.         $collectionPolissen->addField(new FieldPrimary());
  302.         $collectionPolissen->addField(FieldLabel::name('polis''wijzigingsreden'));
  303.         $collectionPolissen->addField(FieldLabel::name('polis''collectiviteit'));
  304.         $collectionPolissen->addField(FieldLabel::name('polis''polisnummer_oud'));
  305.         $collectionPolissen->addField(FieldLabel::name('polis''incassobedrag'));
  306.         $collectionPolissen->addField(FieldLabel::name('polis''termijn'));
  307.         $collectionPolissen->addField(FieldLabel::name('polis''wijzigingsreden'));
  308.         $collectionPolissen->addField(FieldLabel::name('polis''ingangsdatum'));
  309.         $collectionPolissen->addFilter(new Filter(new FieldLabel('10095'), '12''='));
  310.         $collectionPakketten->addCollection($collectionPolissen);
  311.         $collection->addCollection($collectionPakketten);
  312.         $request = new AwacsViewRequest($collection);
  313.         $res $request->send($datasource);
  314.         $result = [];
  315.         $resultWacht = [];
  316.         foreach ($res->entities()[0]->collection('pakketten') as $pakket) {
  317.             foreach ($pakket->collection('polissen') as $polis) {
  318.                 if ($polis->field('collectiviteit')->value() != '') {
  319.                     $resPolis = [];
  320.                     $resPolis['wijzigingsreden'] = $polis->field('wijzigingsreden')->value();
  321.                     $resPolis['collectiviteit'] = $polis->field('collectiviteit')->value();
  322.                     $resPolis['polisnummer_oud'] = $polis->field('polisnummer_oud')->value();
  323.                     $resPolis['incassobedrag'] = $polis->field('incassobedrag')->value();
  324.                     $resPolis['termijn'] = $polis->field('termijn')->value();
  325.                     $resPolis['wijzigingsreden'] = $polis->field('wijzigingsreden')->value();
  326.                     $resPolis['ingangsdatum'] = $polis->field('ingangsdatum')->value();
  327.                     $resPolis['pakketkey'] = $pakket->key();
  328.                     $resPolis['key'] = $polis->key();
  329.                     $result[] = $resPolis;
  330.                 }
  331.             }
  332.             foreach ($pakket->collection('wachtpolissen') as $polis) {
  333.                 if ($polis->field('collectiviteit')->value() != '') {
  334.                     $resPolis = [];
  335.                     $resPolis['wijzigingsreden'] = $polis->field('wijzigingsreden')->value();
  336.                     $resPolis['collectiviteit'] = $polis->field('collectiviteit')->value();
  337.                     $resPolis['polisnummer_oud'] = $polis->field('polisnummer_oud')->value();
  338.                     $resPolis['incassobedrag'] = $polis->field('incassobedrag')->value();
  339.                     $resPolis['termijn'] = $polis->field('termijn')->value();
  340.                     $resPolis['wijzigingsreden'] = $polis->field('wijzigingsreden')->value();
  341.                     $resPolis['ingangsdatum'] = $polis->field('ingangsdatum')->value();
  342.                     $resPolis['pakketkey'] = $pakket->key();
  343.                     $resPolis['key'] = $polis->key();
  344.                     $resultWacht[] = $resPolis;
  345.                 }
  346.             }
  347.         }
  348.         return new JsonResponse([
  349.             'keys' => $result,
  350.             'keysWacht' => $resultWacht,
  351.         ]);
  352.     }
  353.     /**
  354.      * @Route("/getDekkingenPremies/{datasource}", name="getDekkingenAndPremiesAPI")
  355.      */
  356.     public function test7(EntityManagerInterface $emSessionInterface $session$datasourceRequest $request) {
  357.         if (!AccessHelper::ownIP($request->getClientIp())) {
  358.             return new JsonResponse(['access' => False]);
  359.         }
  360.         $key json_decode($request->getContent());
  361.         $prefix '';
  362.         // If key contains WACBES_
  363.         if (strpos($key'WACBES_') !== false) {
  364.             $prefix 'wacht';
  365.         } else {
  366.             $key substr($key025);
  367.         }
  368.         $collection = new Collection($prefix .'polissen');
  369.         $collection->addFilter(new Filter(new FieldPrimary(), $key'='));
  370.         $collectionDekkingen = new Collection($prefix .'dekkingen');
  371.         $collectionDekkingen->addField(new FieldPrimary());
  372.         $collectionDekkingen->addField(new FieldLabel('*'));
  373.         $collectionDekkingen->addField(new FieldLabel('10020'));
  374.         $collection->addCollection($collectionDekkingen);
  375.         $request = new AwacsViewRequest($collection);
  376.         $res $request->send($datasource);
  377.         if (count($res->entities()) == 0) {
  378.             return new JsonResponse([
  379.                 'found' => false,
  380.             ]);
  381.         }
  382.         $dekkingIds = [];
  383.         foreach ($res->entities()[0]->collection($prefix .'dekkingen') as $dekking) {
  384.             $dekkingIds[$dekking->key] = [
  385.                 'incassobedrag' => floatval($dekking->field('incassobedrag')->value()),
  386.                 'code' => $dekking->field('dekking')->value(),
  387.                 'brutopremie' => floatval($dekking->field('bruto_premie_dekking')->value()),
  388.                 'toeslag_percentage_dekking' => floatval($dekking->field('toeslag_percentage_dekking')->value()),
  389.                 'toeslag_absoluut_dekking' => floatval($dekking->field('toeslag_absoluut_dekking')->value()),
  390.                 'verzekerdbedrag' => floatval($dekking->field('verzekerdbedrag')->value()),
  391.                 'provisiepercentage' => floatval($dekking->field('provisiepercentage')->value()),
  392.             ];
  393.         }
  394.         return new JsonResponse([
  395.             'keys' => $dekkingIds,
  396.         ]);
  397.     }
  398.     /**
  399.      * @Route("/shootElements", name="shootElements")
  400.      */
  401.     public function test4(EntityManagerInterface $emSessionInterface $sessionRequest $request) {
  402.         if (!AccessHelper::ownIP($request->getClientIp())) {
  403.             return new JsonResponse(['access' => False]);
  404.         }
  405.         $entities json_decode($request->getContent());
  406.         $list FFManualInputOvervoerHelper::processAPICall($entities);
  407.         return new JsonResponse([
  408.             $list
  409.         ]);
  410.     }
  411.     /**
  412.      * @Route("/api/elements", name="elements")
  413.      */
  414.     public function apiElements(EntityManagerInterface $emSessionInterface $sessionRequest $request) {
  415.         if (!AccessHelper::ownIP($request->getClientIp())) {
  416.             return new JsonResponse(['access' => False]);
  417.         }
  418.         $entities json_decode($request->getContent());
  419.         $request = new FasterForwardUpdateSchadeverzekeringRequest();
  420.         $request->path $entities->url;
  421.         $request->requestData json_decode(json_encode($entities->requestData), true);
  422.         $request->urlOnly json_decode(json_encode($entities->urlOnly), true);
  423.         switch (json_decode(json_encode($entities->method), true)) {
  424.             case 'POST':
  425.                 $request->method Http::POST;
  426.                 break;
  427.             case 'PUT':
  428.                 $request->method Http::PUT;
  429.                 break;
  430.             case 'DELETE':
  431.                 $request->method Http::DELETE;
  432.                 break;
  433.             case 'GET':
  434.                 $request->method Http::GET;
  435.                 break;
  436.             case 'PATCH':
  437.                 $request->method Http::PATCH;
  438.                 break;
  439.         }
  440.         $res $request->send();
  441.         $headers $res->headers;
  442.         $dossiernummer = -1;
  443.         if ($res->code == 201){
  444.             $exp explode('/'$headers['location']);
  445.             # get last of exp
  446.             $dossiernummer intval($exp[count($exp) - 1]);
  447.         }
  448.         return new JsonResponse([
  449.             'responseData' => $res->raw_body,
  450.             'responseCode' => $res->code,
  451.             'success' => $res->code == 201,
  452.             'nummer' => $dossiernummer
  453.         ]);
  454.     }
  455.     /**
  456.      * @Route("/api/elements/getdefaultids/{dossierId}", name="elementsGetDefaultIds")
  457.      */
  458.     public function apiElementsGetDefaultIds(EntityManagerInterface $emSessionInterface $sessionRequest $request$dossierId) {
  459.         if (!AccessHelper::ownIP($request->getClientIp())) {
  460.             return new JsonResponse(['access' => False]);
  461.         }
  462.         $relation =  FasterForwardHelper::getRelation($dossierId);
  463.         return new JsonResponse([
  464.             'persoonId' => $relation->id,
  465.             'adresId' => $relation->adres_id,
  466.         ]);
  467.     }
  468.     /**
  469.      * @Route("/api/elementsProduct", name="elementsProduct")
  470.      */
  471.     public function apiElementsProduct(EntityManagerInterface $emSessionInterface $sessionRequest $request) {
  472.         if (!AccessHelper::ownIP($request->getClientIp())) {
  473.             return new JsonResponse(['access' => False]);
  474.         }
  475.         $entities json_decode($request->getContent());
  476.         $request = new FasterForwardUpdateSchadeverzekeringRequest();
  477.         $request->path $entities->url;
  478.         $request->requestData json_decode(json_encode($entities->requestData), true);
  479.         $request->urlOnly json_decode(json_encode($entities->urlOnly), true);
  480.         switch (json_decode(json_encode($entities->method), true)) {
  481.             case 'POST':
  482.                 $request->method Http::POST;
  483.                 break;
  484.             case 'PUT':
  485.                 $request->method Http::PUT;
  486.                 break;
  487.             case 'DELETE':
  488.                 $request->method Http::DELETE;
  489.                 break;
  490.             case 'GET':
  491.                 $request->method Http::GET;
  492.                 break;
  493.             case 'PATCH':
  494.                 $request->method Http::PATCH;
  495.                 break;
  496.         }
  497.         $res $request->send();
  498.         $headers $res->headers;
  499.         $dossiernummer = -1;
  500.         if ($res->code == 201){
  501.             $exp explode('/'$headers['location']);
  502.             # get last of exp
  503.             $dossiernummer intval($exp[count($exp) - 1]);
  504.         }
  505.         return new JsonResponse([
  506.             'responseData' => $res->raw_body,
  507.             'responseCode' => $res->code,
  508.             'success' => $res->code == 201,
  509.             'nummer' => $dossiernummer
  510.         ]);
  511.     }
  512.     public function getRelation($relations$input) {
  513.         $matches = [];
  514.         foreach ($relations as $relation) {
  515.             if ($relation->field('email')->value() != '' && isset($input->{'email'}) && $input->{'email'} != '' && $input->{'email'} != '-') {
  516.                 if ($relation->field('email')->value() != $input->{'email'}) {
  517.                     continue;
  518.                 }
  519.             }
  520.             if ($relation->field('postcode')->value() != '' && isset($input->{'postcode'})&& $input->{'postcode'} != '-') {
  521.                 if ($relation->field('postcode')->value() != $input->{'postcode'}) {
  522.                     continue;
  523.                 }
  524.             }
  525.             if ($relation->field('iban')->value() != '' && isset($input->{'iban'}) && $input->{'iban'} != '-' && $input->{'iban'} != '') {
  526.                 if ($relation->field('iban')->value() != $input->{'iban'}) {
  527.                     continue;
  528.                 }
  529.             }
  530.             if ($relation->field('achternaam')->value() != '' && isset($input->{'achternaam'})&& $input->{'achternaam'} != '-' && $input->{'achternaam'} != '') {
  531.                 if (strtolower($relation->field('achternaam')->value()) != strtolower($input->{'achternaam'})) {
  532.                     continue;
  533.                 }
  534.             }
  535.             if ($relation->field('voorletters')->value() != '' && isset($input->{'voorletters'})&& $input->{'voorletters'} != '-' && $input->{'voorletters'} != '') {
  536.                 if (str_replace(' '''str_replace'.'''$relation->field('voorletters')->value())) != str_replace(' '''str_replace'.'''$input->voorletters))) {
  537.                     continue;
  538.                 }
  539.             }
  540.             if ($relation->field('geboortedatum')->value() != '') {
  541.                 $reformat \DateTime::createFromFormat('Ymd'$relation->field('geboortedatum')->value())->format('d-m-Y');
  542.                 if ($input->{'geboortedatum'} != '' && $reformat != $input->{'geboortedatum'}) {
  543.                     continue;
  544.                 }
  545.             }
  546.             $matches[] = $relation;
  547.         }
  548.         return $matches;
  549.     }
  550.     /**
  551.      * @Route("/api/findRelation/{datasource}", name="apiFindRelation")
  552.      */
  553.     public function test5(EntityManagerInterface $emSessionInterface $sessionRequest $request$datasource) {
  554.         if (!AccessHelper::ownIP($request->getClientIp())) {
  555.             return new JsonResponse(['access' => False]);
  556.         }
  557.         $entities json_decode($request->getContent());
  558.         $relations RelationSearch::byNAW([
  559.             'postcode' => $entities->{'postcode'},
  560.             'huisnummer' => $entities->{'huisnummer'}
  561.         ], $datasource);
  562.         $res $this->getRelation($relations$entities);
  563.         $output = [];
  564.         foreach ($res as $result) {
  565.             $wijziginsreden intval($result->field('wijzigingsreden')->value());
  566.             if (empty($wijziginsreden)) {
  567.                 $vervallen false;
  568.             } else {
  569.                 $vervallen = ($wijziginsreden >= 40 && $wijziginsreden 50);
  570.             }
  571.             if ($vervallen) {
  572.                 continue;
  573.             }
  574. //            $isHollandia = RelationSearch::byActiveHollandia($result->field('relatienummer')->value(), $datasource);
  575. //            if ($isHollandia) {
  576.             $output[] = [
  577.                 'relatienummer' => $result->field('relatienummer')->value(),
  578.                 'achternaam' => $result->field('achternaam')->value(),
  579.                 'agent' => $result->field('agent')->value(),
  580.                 'kantoor' => $result->field('kantoorcode')->value(),
  581.             ];
  582. //            }
  583.         }
  584.         return new JsonResponse($output);
  585.     }
  586.     /**
  587.      * @Route("/api/findAbbo/{datasource}", name="apiFindAbonnement")
  588.      */
  589.     public function testPakketAbonnement(EntityManagerInterface $emSessionInterface $sessionRequest $request$datasource)
  590.     {
  591.         if (!AccessHelper::ownIP($request->getClientIp())) {
  592.             return new JsonResponse(['access' => False]);
  593.         }
  594.         $entities json_decode($request->getContent());
  595.         $poliskey $entities->{'key'};
  596.         $collection = new Collection('polissen');
  597.         foreach ($entities->{'fields'} as $field) {
  598.             $collection->addField(new FieldLabel($field));
  599.         }
  600.         $collection->addField(FieldLabel::name('polis''wijzigingsreden'));
  601.         $collection->addField(FieldLabel::name('polis''wijzigingsdatum'));
  602.         $collection->addField(new FieldPrimary());
  603.         $collectionDekkingen = new Collection('dekkingen');
  604.         $collectionDekkingen->addField(FieldLabel::name('dekking''dekking'));
  605.         $collectionDekkingen->addField(FieldLabel::name('dekking''toeslag_percentage_dekking'));
  606.         $collectionDekkingen->addField(FieldLabel::name('dekking''toeslag_absoluut_dekking'));
  607.         $collectionDekkingen->addField(FieldLabel::name('dekking''toeslag_absoluut_dekking'));
  608.         $collectionDekkingen->addField(FieldLabel::name('dekking''incassobedrag'));
  609.         $collection->addCollection($collectionDekkingen);
  610.         $collection
  611.             ->addFilter(new Filter(FieldLabel::name('polis''polisnummer'), $poliskey))
  612.             ->addFilter(new Filter(FieldLabel::name('polis''maatschappij'), 'V201'));
  613.         $request = new AwacsViewRequest($collection);
  614.         $request->setDisplayOption('display');
  615.         if (isset($datasource)) {
  616.             $response $request->send($datasource);
  617.         } else {
  618.             $response $request->send();
  619.         }
  620.         $ret = [];
  621.         $i 0;
  622.         foreach ($response->entities() as $entity) {
  623.             $ret[$i]['fields'] = [];
  624.             $ret[$i]['dekkingen'] = [];
  625.             foreach ($entity->fields as $field => $value) {
  626.                 $ret[$i]['fields'][$field] = $value->value();
  627.             }
  628.             foreach ($entity->collection('dekkingen') as $fieldS => $entity) {
  629.                 $ret[$i]['dekkingen'][$fieldS] = [];
  630.                 foreach ($entity->fields as $field => $value) {
  631.                     $ret[$i]['dekkingen'][$fieldS][$field] = $value->value();
  632.                 }
  633.                 $ret[$i]['key'] = $entity->key();
  634.                 $i $i 1;
  635.             }
  636.             return new JsonResponse($ret);
  637.         }
  638.     }
  639.     /**
  640.      * @Route("/api/findPolis/{datasource}", name="apiFindPolis")
  641.      */
  642.     public function test8(EntityManagerInterface $emSessionInterface $sessionRequest $request$datasource) {
  643.         if (!AccessHelper::ownIP($request->getClientIp())) {
  644.             return new JsonResponse(['access' => False]);
  645.         }
  646.         $entities json_decode($request->getContent());
  647.         $poliskey $entities->{'key'};
  648.         $collection = new Collection('polissen');
  649.         foreach ($entities->{'fields'} as $field) {
  650.             $collection->addField(new FieldLabel($field));
  651.         }
  652.         $collection
  653.             ->addFilter(new Filter(new FieldPrimary(), $poliskey'='));
  654.         $request = new AwacsViewRequest($collection);
  655.         $request->setDisplayOption('display');
  656.         if (isset($datasource)) {
  657.             $response $request->send($datasource);
  658.         } else {
  659.             $response $request->send();
  660.         }
  661.         $ret = [];
  662.         foreach ($response->entities()[0]->fields as $field => $value) {
  663.             $ret[$field] = $value->value();
  664.         }
  665.         return new JsonResponse($ret);
  666.         return new JsonResponse($output);
  667.     }
  668.     /**
  669.      * @Route("/api/findAgendas/{datasource}", name="apiFindAgendas")
  670.      */
  671.     public function test24(EntityManagerInterface $emSessionInterface $sessionRequest $request$datasource) {
  672.         if (!AccessHelper::ownIP($request->getClientIp())) {
  673.             return new JsonResponse(['access' => False]);
  674.         }
  675.         $entities json_decode($request->getContent());
  676.         $poliskey $entities->{'key'};
  677.         $collectionAgenda = new Collection('agendaas');
  678.         $collectionAgenda->addField(new FieldLabel('*'));
  679.         $collectionAgenda
  680.             ->addFilter(new Filter(new FieldPrimary(), 'AGENDA_P'$poliskey "*"'='));
  681.         $request = new AwacsViewRequest($collectionAgenda);
  682.         $request->setDisplayOption('display');
  683.         if (isset($datasource)) {
  684.             $response $request->send($datasource);
  685.         } else {
  686.             $response $request->send();
  687.         }
  688.         $out = [];
  689.         foreach ($response->entities() as $entity) {
  690.             $ret = [];
  691.             foreach ($entity->fields as $field => $value) {
  692.                 $ret[$field] = $value->value();
  693.             }
  694.             $ret['pk'] = $response->entities()[0]->key();
  695.             $out[] = $ret;
  696.         }
  697.         return new JsonResponse($out);
  698.         return new JsonResponse($output);
  699.     }
  700.     public function responseToJson(AwacsResponse $response) {
  701.         $polis $response->entities()[0];
  702.         $output = [
  703.             'fields' => [],
  704.             'dekkingen' => [],
  705.         ];
  706.         foreach ($polis->fields as $field => $value) {
  707.             $output['fields'][$field] = $value->value();
  708.         }
  709.         foreach ($polis->collection('dekkingen') as $field => $dekking) {
  710.             $res = [];
  711.             foreach ($dekking->fields as $fieldD => $value) {
  712.                 $res[$fieldD] = $value->value();
  713.             }
  714.             $output['dekkingen'][$dekking->field('dekking')->value()] = $res;
  715.         }
  716.         return $output;
  717.     }
  718.     /**
  719.      * @Route("/api/fieldsSjabloon/{datasource}", name="apiFieldsSjabloon")
  720.      */
  721.     public function test9(EntityManagerInterface $emSessionInterface $sessionRequest $request$datasource) {
  722.         if (!AccessHelper::ownIP($request->getClientIp())) {
  723.             return new JsonResponse(['access' => False]);
  724.         }
  725.         $entities json_decode($request->getContent());
  726.         $poliskey $entities->{'key'};
  727.         $productId $entities->{'productId'};
  728.         $contextId $entities->{'contextId'};
  729.         $functieId $entities->{'functieId'};
  730.         $maatschappij $entities->{'maatschappij'};
  731.         $projdir $this->getParameter('kernel.project_dir');
  732.         switch ($maatschappij) {
  733.             case 'V059':
  734.                 $maatschappij 'asr';
  735.                 break;
  736.             case 'N200':
  737.                 $maatschappij 'nn';
  738.                 break;
  739.         }
  740.         $data VPIRequest::templateEmpty(''$productId$contextId$functieId'geefSjabloon');
  741.         $result VPIRequest::sendRequestVPI($data$maatschappij$projdirtrue);
  742.         $collection = new Collection('polissen');
  743.         $collection->addField(new FieldLabel('*'));
  744.         $collectionDekkingen = new Collection('dekkingen');
  745.         $collectionDekkingen->addField(new FieldLabel('*'));
  746.         $collection->addCollection($collectionDekkingen);
  747.         $collection
  748.             ->addFilter(new Filter(new FieldPrimary(), $poliskey'='));
  749.         $request = new AwacsViewRequest($collection);
  750.         $request->setDisplayOption('display');
  751.         if (isset($datasource)) {
  752.             $response $request->send($datasource);
  753.         } else {
  754.             $response $request->send();
  755.         }
  756.         return new JsonResponse([
  757.             'sjabloon' => $result,
  758.             'polisinfo' => self::responseToJson($response),
  759.         ]);
  760.     }
  761.     /**
  762.      * @Route("/api/vpiAcceptatie", name="apiVPIAcceptatie")
  763.      */
  764.     public function test10(EntityManagerInterface $emSessionInterface $sessionRequest $request) {
  765.         if (!AccessHelper::ownIP($request->getClientIp())) {
  766.             return new JsonResponse(['access' => False]);
  767.         }
  768.         $entities json_decode($request->getContent());
  769.         $poliskey $entities->{'key'};
  770.         $productId $entities->{'productId'};
  771.         $contextId $entities->{'contextId'};
  772.         $functieId $entities->{'functieId'};
  773.         $maatschappij $entities->{'maatschappij'};
  774.         $data $entities->{'requestData'};
  775.         $projdir $this->getParameter('kernel.project_dir');
  776.         switch ($maatschappij) {
  777.             case 'V059':
  778.                 $maatschappij 'asr';
  779.                 break;
  780.             case 'N200':
  781.                 $maatschappij 'nn';
  782.                 break;
  783.         }
  784.         $data VPIRequest::templateEmpty($data$productId$contextId$functieId'doeFunctie');
  785.         $result VPIRequest::sendRequestVPI($data$maatschappij$projdir);
  786.         return new JsonResponse($result);
  787.     }
  788.     /**
  789.      * @Route("/api/vpi/auto", name="apiVPIAuto")
  790.      */
  791.     public function apiVPIAuto(EntityManagerInterface $emSessionInterface $sessionRequest $request) {
  792.         if (!AccessHelper::ownIP($request->getClientIp())) {
  793.             return new JsonResponse(['access' => False]);
  794.         }
  795.         if ($request->getMethod() === 'OPTIONS') {
  796.             $response = new JsonResponse();
  797.             $response->headers->set('Access-Control-Allow-Origin''https://chat.pivotwise.nl');
  798.             $response->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS');
  799.             $response->headers->set('Access-Control-Allow-Headers''Content-Type');
  800.             return $response;
  801.         }
  802.         error_log($request->getContent());
  803.         $premiebepalendeGegevens json_decode($request->getContent());
  804.         error_log($request->getContent());
  805.         $process = new ProcessCar();
  806.         $process->svj $premiebepalendeGegevens->schadevrijeJaren;
  807.         $process->geboortedatum $premiebepalendeGegevens->geboortedatum;
  808.         $process->postcode $premiebepalendeGegevens->postcode;
  809.         $process->huisnummer $premiebepalendeGegevens->huisnummer;
  810.         $process->kilometers str_replace('km_'''$premiebepalendeGegevens->kilometrage);
  811.         $process->toevoeging '';
  812.         $process->relatieGeboortedatum $premiebepalendeGegevens->geboortedatum;
  813.         $process->relatiePostcode $premiebepalendeGegevens->postcode;
  814.         $process->relatieHuisnummer $premiebepalendeGegevens->huisnummer;
  815.         $process->relatieToevoeging '';
  816.         $process->dekking $premiebepalendeGegevens->dekking;
  817.         $process->termijn 'maand';
  818.         $process->kenteken $premiebepalendeGegevens->kenteken;
  819.         $process->mutationIngangsdatum = new \DateTime();
  820.         $process->ingangsdatum = new \DateTime();
  821.         $projdir $this->getParameter('kernel.project_dir');
  822.         $productId 'VPI_NN_PersP2024ExclBM';
  823.         $maatschappij VPIMappingNew::getMaatschappijByProductId($productId);
  824.         $dummyTemplate VPIRequest::template(''$productId$processfalse);
  825.         $gimCache VPIRequest::getSjabloonStdClass($em$projdir$maatschappij$productId$dummyTemplate['doeFunctieVraag']['procesInfo']['functie']['contextId'], $dummyTemplate['doeFunctieVraag']['procesInfo']['functie']['functieId']);
  826.         $data VPIMapping::transform($process$productId, ['vc'], $gimCachenull);
  827.         if ($data === false) {
  828.             return false;
  829.         }
  830.         $responseBin = new \stdClass();
  831.         $response VPIRequest::sendVPI($projdir$data$maatschappij$productId$process$responseBin);
  832.         if ($response !== null) {
  833.             $policies VPIHelper::parsePolis($response$productId'Autoverzekering'$data$process$responseBin, ['vc']);
  834.             if ($policies !== null) {
  835.                 foreach ($policies as $policy) {
  836.                     $process->results[] = $policy;
  837.                 }
  838.             }
  839.         }
  840.         $res = new JsonResponse($process->results);
  841.         $res->headers->set('Access-Control-Allow-Origin''https://chat.pivotwise.nl');
  842.         $res->headers->set('Access-Control-Allow-Methods''POST, GET, OPTIONS');
  843.         $res->headers->set('Access-Control-Allow-Headers''Content-Type');
  844.         // Add your data to the response if necessary, e.g., $response->setData([...]);
  845.         return $res;
  846.     }
  847. }