<?php
namespace App\Controller\AppBundle\Controller;
use App\Controller\AppBundle\Connector\Awacs\AwacsCreateDocumentRequest;
use App\Controller\AppBundle\Connector\Awacs\AwacsResponse;
use App\Controller\AppBundle\Connector\Awacs\AwacsUpdateAPIRequest;
use App\Controller\AppBundle\Connector\Awacs\AwacsUpdateRequest;
use App\Controller\AppBundle\Connector\Awacs\AwacsViewRequest;
use App\Controller\AppBundle\Connector\Awacs\Collection;
use App\Controller\AppBundle\Connector\Awacs\FieldLabel;
use App\Controller\AppBundle\Connector\Awacs\FieldPrimary;
use App\Controller\AppBundle\Connector\Awacs\Filter;
use App\Controller\AppBundle\Connector\FasterForward\FasterForwardHelper;
use App\Controller\AppBundle\Connector\FasterForward\FasterForwardUpdateSchadeverzekeringRequest;
use App\Controller\AppBundle\Connector\FasterForward\Helpers\FFManualInputOvervoerHelper;
use App\Controller\AppBundle\Connector\VPI\VPIHelper;
use App\Controller\AppBundle\Connector\VPI\VPIMapping;
use App\Controller\AppBundle\Connector\VPI\VPIMappingNew;
use App\Controller\AppBundle\Connector\VPI\VPIRequest;
use App\Controller\AppBundle\Helpers\AccessHelper;
use App\Controller\AppBundle\Interact\RelationSearch;
use App\Entity\Slotvraag;
use App\Repository\GIMCacheRepository;
use Httpful\Http;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use App\Controller\AppBundle\Connector\RollsVehicleInformation\ConnectorVehicle;
use App\Controller\AppBundle\Entity\PolisInformation;
use App\Controller\AppBundle\Helpers\Admin\ConsultantHelper;
use App\Controller\AppBundle\Helpers\ConsultantCompare\ProcessCar;
use App\Controller\AppBundle\Helpers\FormValidator;
use App\Controller\AppBundle\Helpers\TestHelper;
use App\Controller\AppBundle\Interact\Compare\CartSessionHelper;
use App\Controller\AppBundle\Interact\Compare\PolisResult;
use App\Controller\AppBundle\Interact\Compare\RequestBuilderCar;
use App\Controller\AppBundle\Interact\CreateRelation;
use App\Controller\AppBundle\Interact\UserInformationANVA;
use App\Entity\CartContainer;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Brick\VarExporter\VarExporter;
class APIController extends AbstractController
{
/**
* @Route("/shoot/{datasource}/{processSource}", name="shoot")
*/
public function test2(EntityManagerInterface $em, SessionInterface $session, $datasource, $processSource, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$entities = json_decode($request->getContent());
$update = new AwacsUpdateAPIRequest($entities);
$response = $update->sendAndRequest($datasource, null, null, $processSource);
$request = $response[1];
$response = $response[0];
$keys = [];
$errorById = [];
if ($response->getErrors() === []) {
$output = $response->xml()->RESULT->EXECUTE;
try {
foreach ($response->xml()->RESULT->EXECUTE->children() as $name => $xml) {
$keys[strtolower($name)][] = (string)$xml->PK;
}
} catch (\Exception $e) {}
} else {
$volgnums = [];
$i = 0;
try {
foreach ($response->xml()->RESULT->RELATIES->RELATIE->PAKKETTEN->PAKKET as $pakket) {
foreach ($pakket->POLISSEN->POLIS as $polis) {
$volgnums[(string)$polis->TRANSACTION_VOLGNR] = $i;
$i = $i + 1;
}
}
} catch (\Exception $e) {}
$i = 0;
if (count($errorById) != 0) {
foreach ($response->xml()->RESULT->EXECUTE->ERROR as $error) {
$errorById[$volgnums[(string)$error->TRANSACTION_VOLGNR]] = $response->getErrors()[array_keys($response->getErrors())[$i]];
$i = $i + 1;
}
} else {
foreach ($response->xml()->RESULT->EXECUTE->ERROR as $error) {
$errorById[] = (string)$error->MESSAGE;
$i = $i + 1;
}
}
}
return new JsonResponse([
'hasErrors' => $response->getErrors() !== [],
'errors' => $response->getErrors(),
'request' => $request,
'keys' => $keys,
'errorsById' => $errorById,
]);
}
/**
* @Route("/insertDocument/{datasource}", name="shootDocument")
*/
public function apiCallDocument(EntityManagerInterface $em, SessionInterface $session, $datasource, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$entities = json_decode($request->getContent());
$result = '';
foreach ($entities->data as $key => $value) {
$result .= "$key: $value\n"; // Concatenate key-value pairs into the result string
}
# Get 16 till 20 position of entities['polisKey']
$polisKeySubset = substr($entities->polisKey, 15, 5);
# Get 21 position onwards
$polisKeySubset2 = substr($entities->polisKey, 20);
$request = new AwacsCreateDocumentRequest($result, 'OvervoerVKGExtranetData.txt', 'OvervoerVKG Data ' . $entities->data->{'Overzicht->Polisnummer'}, $entities->relatieKey, true, false, false, $polisKeySubset, $polisKeySubset2);
$response = $request->sendAndRequest($datasource);
$request = $response[1];
$response = $response[0];
$keys = [];
$errorById = [];
if ($response->getErrors() === []) {
$output = $response->xml()->RESULT->EXECUTE;
try {
foreach ($response->xml()->RESULT->EXECUTE->children() as $name => $xml) {
$keys[strtolower($name)][] = (string)$xml->PK;
}
} catch (\Exception $e) {}
} else {
$volgnums = [];
$i = 0;
try {
foreach ($response->xml()->RESULT->RELATIES->RELATIE->PAKKETTEN->PAKKET as $pakket) {
foreach ($pakket->POLISSEN->POLIS as $polis) {
$volgnums[(string)$polis->TRANSACTION_VOLGNR] = $i;
$i = $i + 1;
}
}
} catch (\Exception $e) {}
$i = 0;
if (count($errorById) != 0) {
foreach ($response->xml()->RESULT->EXECUTE->ERROR as $error) {
$errorById[$volgnums[(string)$error->TRANSACTION_VOLGNR]] = $response->getErrors()[array_keys($response->getErrors())[$i]];
$i = $i + 1;
}
} else {
foreach ($response->xml()->RESULT->EXECUTE->ERROR as $error) {
$errorById[] = (string)$error->MESSAGE;
$i = $i + 1;
}
}
}
return new JsonResponse([
'hasErrors' => $response->getErrors() !== [],
'errors' => $response->getErrors(),
'request' => $request,
'keys' => $keys,
'errorsById' => $errorById,
]);
}
/**
* @Route("/getPremie/{datasource}", name="getPremieAPI")
*/
public function test3(EntityManagerInterface $em, SessionInterface $session, $datasource, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$key = json_decode($request->getContent());
# Make length of key 25 by cutting of the right
if (!str_contains($key, 'WACBES_')) {
$key = substr($key, 0, 25);
}
$prefix = '';
// If key contains WACBES_
if (strpos($key, 'WACBES_') !== false) {
$prefix = 'wacht';
}
$collection = new Collection($prefix . 'polissen');
$collection->addField(FieldLabel::name('polis', 'incassobedrag'));
$collection->addField(FieldLabel::name('polis', 'acceptatie'));
$collection->addField(FieldLabel::name('polis', 'prolongatiekosten'));
$collection->addField(FieldLabel::name('polis', 'termijn'));
$collection->addFilter(new Filter(new FieldPrimary(), $key, '='));
$request = new AwacsViewRequest($collection);
$res = $request->send($datasource);
if (count($res->entities()) == 0) {
return new JsonResponse([
'found' => false,
]);
}
return new JsonResponse([
'found' => true,
'incassobedrag' => $res->entities()[0]->field('incassobedrag')->value(),
'acceptatie' => $res->entities()[0]->field('acceptatie')->value(),
'prolongatiekosten' => $res->entities()[0]->field('prolongatiekosten')->value(),
'termijn' => $res->entities()[0]->field('termijn')->value()
]);
}
/**
* @Route("/getStatus/{datasource}", name="getStatusAPI")
*/
public function test11(EntityManagerInterface $em, SessionInterface $session, $datasource, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$key = json_decode($request->getContent());
# Make length of key 25 by cutting of the right
if (!str_contains($key, 'WACBES_')) {
$key = substr($key, 0, 25);
}
$prefix = '';
// If key contains WACBES_
if (strpos($key, 'WACBES_') !== false) {
$prefix = 'wacht';
}
$collection = new Collection($prefix . 'polissen');
$collection->addField(FieldLabel::name('polis', 'incassobedrag'));
$collection->addField(FieldLabel::name('polis', 'acceptatie'));
$collection->addField(FieldLabel::name('polis', 'prolongatiekosten'));
$collection->addField(FieldLabel::name('polis', 'termijn'));
$collection->addField(FieldLabel::name('polis', 'wijzigingsreden'));
$collection->addFilter(new Filter(new FieldPrimary(), $key, '='));
$request = new AwacsViewRequest($collection);
$res = $request->send($datasource);
if (count($res->entities()) == 0) {
return new JsonResponse([
'found' => false,
]);
}
$isGeroyeerd = ((int)$res->entities()[0]->field('wijzigingsreden')->value()) >= 40 && ((int)$res->entities()[0]->field('wijzigingsreden')->value()) < 50;
$isNietProlongerend = ((int)$res->entities()[0]->field('wijzigingsreden')->value()) >= 14 && ((int)$res->entities()[0]->field('wijzigingsreden')->value()) < 30;
return new JsonResponse([
'found' => true,
'incassobedrag' => $res->entities()[0]->field('incassobedrag')->value(),
'acceptatie' => $res->entities()[0]->field('acceptatie')->value(),
'prolongatiekosten' => $res->entities()[0]->field('prolongatiekosten')->value(),
'termijn' => $res->entities()[0]->field('termijn')->value(),
'isGeroyeerd' => $isGeroyeerd,
'isNietProlongerend' => $isNietProlongerend,
'wijzigingsreden' => $res->entities()[0]->field('wijzigingsreden')->value()
]);
}
/**
* @Route("/getDekkingen/{datasource}", name="getDekkingenAPI")
*/
public function test6(EntityManagerInterface $em, SessionInterface $session, $datasource, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$key = json_decode($request->getContent());
$prefix = '';
// If key contains WACBES_
if (strpos($key, 'WACBES_') !== false) {
$prefix = 'wacht';
} else {
$key = substr($key, 0, 25);
}
$collection = new Collection($prefix .'polissen');
$collection->addFilter(new Filter(new FieldPrimary(), $key, '='));
$collectionDekkingen = new Collection($prefix .'dekkingen');
$collectionDekkingen->addField(new FieldPrimary());
$collection->addCollection($collectionDekkingen);
$request = new AwacsViewRequest($collection);
$res = $request->send($datasource);
$dekkingIds = [];
foreach ($res->entities()[0]->collection($prefix .'dekkingen') as $dekking) {
$dekkingIds[] = $dekking->key;
}
return new JsonResponse([
'keys' => $dekkingIds,
]);
}
/**
* @Route("/getPolisIds/{datasource}", name="getPolisIdsAPI")
*/
public function test6547(EntityManagerInterface $em, SessionInterface $session, $datasource, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$key = json_decode($request->getContent());
$key = substr($key, 0, 16);
// if (strpos($key, 'NAWBES_') !== false) {
// $key = str_replace('NAWBES_', '', $key);
// }
$collection = new Collection('relaties');
$collection->addFilter(new Filter(new FieldPrimary(), $key, '='));
$collectionPakketten = new Collection('pakketten');
$collectionPakketten->addField(new FieldPrimary());
$collectionPolissen = new Collection('polissen');
$collectionPolissen->addField(new FieldPrimary());
$collectionPolissen->addField(FieldLabel::name('polis', 'wijzigingsreden'));
$collectionPolissen->addField(FieldLabel::name('polis', 'collectiviteit'));
$collectionPolissen->addField(FieldLabel::name('polis', 'polisnummer_oud'));
$collectionPolissen->addField(FieldLabel::name('polis', 'incassobedrag'));
$collectionPolissen->addField(FieldLabel::name('polis', 'termijn'));
$collectionPolissen->addField(FieldLabel::name('polis', 'wijzigingsreden'));
$collectionPolissen->addField(FieldLabel::name('polis', 'ingangsdatum'));
$collectionPolissen->addFilter(new Filter(new FieldLabel('10095'), '12', '='));
$collectionPakketten->addCollection($collectionPolissen);
$collectionPolissen = new Collection('wachtpolissen');
$collectionPolissen->addField(new FieldPrimary());
$collectionPolissen->addField(FieldLabel::name('polis', 'wijzigingsreden'));
$collectionPolissen->addField(FieldLabel::name('polis', 'collectiviteit'));
$collectionPolissen->addField(FieldLabel::name('polis', 'polisnummer_oud'));
$collectionPolissen->addField(FieldLabel::name('polis', 'incassobedrag'));
$collectionPolissen->addField(FieldLabel::name('polis', 'termijn'));
$collectionPolissen->addField(FieldLabel::name('polis', 'wijzigingsreden'));
$collectionPolissen->addField(FieldLabel::name('polis', 'ingangsdatum'));
$collectionPolissen->addFilter(new Filter(new FieldLabel('10095'), '12', '='));
$collectionPakketten->addCollection($collectionPolissen);
$collection->addCollection($collectionPakketten);
$request = new AwacsViewRequest($collection);
$res = $request->send($datasource);
$result = [];
$resultWacht = [];
foreach ($res->entities()[0]->collection('pakketten') as $pakket) {
foreach ($pakket->collection('polissen') as $polis) {
if ($polis->field('collectiviteit')->value() != '') {
$resPolis = [];
$resPolis['wijzigingsreden'] = $polis->field('wijzigingsreden')->value();
$resPolis['collectiviteit'] = $polis->field('collectiviteit')->value();
$resPolis['polisnummer_oud'] = $polis->field('polisnummer_oud')->value();
$resPolis['incassobedrag'] = $polis->field('incassobedrag')->value();
$resPolis['termijn'] = $polis->field('termijn')->value();
$resPolis['wijzigingsreden'] = $polis->field('wijzigingsreden')->value();
$resPolis['ingangsdatum'] = $polis->field('ingangsdatum')->value();
$resPolis['pakketkey'] = $pakket->key();
$resPolis['key'] = $polis->key();
$result[] = $resPolis;
}
}
foreach ($pakket->collection('wachtpolissen') as $polis) {
if ($polis->field('collectiviteit')->value() != '') {
$resPolis = [];
$resPolis['wijzigingsreden'] = $polis->field('wijzigingsreden')->value();
$resPolis['collectiviteit'] = $polis->field('collectiviteit')->value();
$resPolis['polisnummer_oud'] = $polis->field('polisnummer_oud')->value();
$resPolis['incassobedrag'] = $polis->field('incassobedrag')->value();
$resPolis['termijn'] = $polis->field('termijn')->value();
$resPolis['wijzigingsreden'] = $polis->field('wijzigingsreden')->value();
$resPolis['ingangsdatum'] = $polis->field('ingangsdatum')->value();
$resPolis['pakketkey'] = $pakket->key();
$resPolis['key'] = $polis->key();
$resultWacht[] = $resPolis;
}
}
}
return new JsonResponse([
'keys' => $result,
'keysWacht' => $resultWacht,
]);
}
/**
* @Route("/getDekkingenPremies/{datasource}", name="getDekkingenAndPremiesAPI")
*/
public function test7(EntityManagerInterface $em, SessionInterface $session, $datasource, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$key = json_decode($request->getContent());
$prefix = '';
// If key contains WACBES_
if (strpos($key, 'WACBES_') !== false) {
$prefix = 'wacht';
} else {
$key = substr($key, 0, 25);
}
$collection = new Collection($prefix .'polissen');
$collection->addFilter(new Filter(new FieldPrimary(), $key, '='));
$collectionDekkingen = new Collection($prefix .'dekkingen');
$collectionDekkingen->addField(new FieldPrimary());
$collectionDekkingen->addField(new FieldLabel('*'));
$collectionDekkingen->addField(new FieldLabel('10020'));
$collection->addCollection($collectionDekkingen);
$request = new AwacsViewRequest($collection);
$res = $request->send($datasource);
if (count($res->entities()) == 0) {
return new JsonResponse([
'found' => false,
]);
}
$dekkingIds = [];
foreach ($res->entities()[0]->collection($prefix .'dekkingen') as $dekking) {
$dekkingIds[$dekking->key] = [
'incassobedrag' => floatval($dekking->field('incassobedrag')->value()),
'code' => $dekking->field('dekking')->value(),
'brutopremie' => floatval($dekking->field('bruto_premie_dekking')->value()),
'toeslag_percentage_dekking' => floatval($dekking->field('toeslag_percentage_dekking')->value()),
'toeslag_absoluut_dekking' => floatval($dekking->field('toeslag_absoluut_dekking')->value()),
'verzekerdbedrag' => floatval($dekking->field('verzekerdbedrag')->value()),
'provisiepercentage' => floatval($dekking->field('provisiepercentage')->value()),
];
}
return new JsonResponse([
'keys' => $dekkingIds,
]);
}
/**
* @Route("/shootElements", name="shootElements")
*/
public function test4(EntityManagerInterface $em, SessionInterface $session, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$entities = json_decode($request->getContent());
$list = FFManualInputOvervoerHelper::processAPICall($entities);
return new JsonResponse([
$list
]);
}
/**
* @Route("/api/elements", name="elements")
*/
public function apiElements(EntityManagerInterface $em, SessionInterface $session, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$entities = json_decode($request->getContent());
$request = new FasterForwardUpdateSchadeverzekeringRequest();
$request->path = $entities->url;
$request->requestData = json_decode(json_encode($entities->requestData), true);
$request->urlOnly = json_decode(json_encode($entities->urlOnly), true);
switch (json_decode(json_encode($entities->method), true)) {
case 'POST':
$request->method = Http::POST;
break;
case 'PUT':
$request->method = Http::PUT;
break;
case 'DELETE':
$request->method = Http::DELETE;
break;
case 'GET':
$request->method = Http::GET;
break;
case 'PATCH':
$request->method = Http::PATCH;
break;
}
$res = $request->send();
$headers = $res->headers;
$dossiernummer = -1;
if ($res->code == 201){
$exp = explode('/', $headers['location']);
# get last of exp
$dossiernummer = intval($exp[count($exp) - 1]);
}
return new JsonResponse([
'responseData' => $res->raw_body,
'responseCode' => $res->code,
'success' => $res->code == 201,
'nummer' => $dossiernummer
]);
}
/**
* @Route("/api/elements/getdefaultids/{dossierId}", name="elementsGetDefaultIds")
*/
public function apiElementsGetDefaultIds(EntityManagerInterface $em, SessionInterface $session, Request $request, $dossierId) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$relation = FasterForwardHelper::getRelation($dossierId);
return new JsonResponse([
'persoonId' => $relation->id,
'adresId' => $relation->adres_id,
]);
}
/**
* @Route("/api/elementsProduct", name="elementsProduct")
*/
public function apiElementsProduct(EntityManagerInterface $em, SessionInterface $session, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$entities = json_decode($request->getContent());
$request = new FasterForwardUpdateSchadeverzekeringRequest();
$request->path = $entities->url;
$request->requestData = json_decode(json_encode($entities->requestData), true);
$request->urlOnly = json_decode(json_encode($entities->urlOnly), true);
switch (json_decode(json_encode($entities->method), true)) {
case 'POST':
$request->method = Http::POST;
break;
case 'PUT':
$request->method = Http::PUT;
break;
case 'DELETE':
$request->method = Http::DELETE;
break;
case 'GET':
$request->method = Http::GET;
break;
case 'PATCH':
$request->method = Http::PATCH;
break;
}
$res = $request->send();
$headers = $res->headers;
$dossiernummer = -1;
if ($res->code == 201){
$exp = explode('/', $headers['location']);
# get last of exp
$dossiernummer = intval($exp[count($exp) - 1]);
}
return new JsonResponse([
'responseData' => $res->raw_body,
'responseCode' => $res->code,
'success' => $res->code == 201,
'nummer' => $dossiernummer
]);
}
public function getRelation($relations, $input) {
$matches = [];
foreach ($relations as $relation) {
if ($relation->field('email')->value() != '' && isset($input->{'email'}) && $input->{'email'} != '' && $input->{'email'} != '-') {
if ($relation->field('email')->value() != $input->{'email'}) {
continue;
}
}
if ($relation->field('postcode')->value() != '' && isset($input->{'postcode'})&& $input->{'postcode'} != '-') {
if ($relation->field('postcode')->value() != $input->{'postcode'}) {
continue;
}
}
if ($relation->field('iban')->value() != '' && isset($input->{'iban'}) && $input->{'iban'} != '-' && $input->{'iban'} != '') {
if ($relation->field('iban')->value() != $input->{'iban'}) {
continue;
}
}
if ($relation->field('achternaam')->value() != '' && isset($input->{'achternaam'})&& $input->{'achternaam'} != '-' && $input->{'achternaam'} != '') {
if (strtolower($relation->field('achternaam')->value()) != strtolower($input->{'achternaam'})) {
continue;
}
}
if ($relation->field('voorletters')->value() != '' && isset($input->{'voorletters'})&& $input->{'voorletters'} != '-' && $input->{'voorletters'} != '') {
if (str_replace(' ', '', str_replace( '.', '', $relation->field('voorletters')->value())) != str_replace(' ', '', str_replace( '.', '', $input->voorletters))) {
continue;
}
}
if ($relation->field('geboortedatum')->value() != '') {
$reformat = \DateTime::createFromFormat('Ymd', $relation->field('geboortedatum')->value())->format('d-m-Y');
if ($input->{'geboortedatum'} != '' && $reformat != $input->{'geboortedatum'}) {
continue;
}
}
$matches[] = $relation;
}
return $matches;
}
/**
* @Route("/api/findRelation/{datasource}", name="apiFindRelation")
*/
public function test5(EntityManagerInterface $em, SessionInterface $session, Request $request, $datasource) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$entities = json_decode($request->getContent());
$relations = RelationSearch::byNAW([
'postcode' => $entities->{'postcode'},
'huisnummer' => $entities->{'huisnummer'}
], $datasource);
$res = $this->getRelation($relations, $entities);
$output = [];
foreach ($res as $result) {
$wijziginsreden = intval($result->field('wijzigingsreden')->value());
if (empty($wijziginsreden)) {
$vervallen = false;
} else {
$vervallen = ($wijziginsreden >= 40 && $wijziginsreden < 50);
}
if ($vervallen) {
continue;
}
// $isHollandia = RelationSearch::byActiveHollandia($result->field('relatienummer')->value(), $datasource);
// if ($isHollandia) {
$output[] = [
'relatienummer' => $result->field('relatienummer')->value(),
'achternaam' => $result->field('achternaam')->value(),
'agent' => $result->field('agent')->value(),
'kantoor' => $result->field('kantoorcode')->value(),
];
// }
}
return new JsonResponse($output);
}
/**
* @Route("/api/findAbbo/{datasource}", name="apiFindAbonnement")
*/
public function testPakketAbonnement(EntityManagerInterface $em, SessionInterface $session, Request $request, $datasource)
{
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$entities = json_decode($request->getContent());
$poliskey = $entities->{'key'};
$collection = new Collection('polissen');
foreach ($entities->{'fields'} as $field) {
$collection->addField(new FieldLabel($field));
}
$collection->addField(FieldLabel::name('polis', 'wijzigingsreden'));
$collection->addField(FieldLabel::name('polis', 'wijzigingsdatum'));
$collection->addField(new FieldPrimary());
$collectionDekkingen = new Collection('dekkingen');
$collectionDekkingen->addField(FieldLabel::name('dekking', 'dekking'));
$collectionDekkingen->addField(FieldLabel::name('dekking', 'toeslag_percentage_dekking'));
$collectionDekkingen->addField(FieldLabel::name('dekking', 'toeslag_absoluut_dekking'));
$collectionDekkingen->addField(FieldLabel::name('dekking', 'toeslag_absoluut_dekking'));
$collectionDekkingen->addField(FieldLabel::name('dekking', 'incassobedrag'));
$collection->addCollection($collectionDekkingen);
$collection
->addFilter(new Filter(FieldLabel::name('polis', 'polisnummer'), $poliskey))
->addFilter(new Filter(FieldLabel::name('polis', 'maatschappij'), 'V201'));
$request = new AwacsViewRequest($collection);
$request->setDisplayOption('display');
if (isset($datasource)) {
$response = $request->send($datasource);
} else {
$response = $request->send();
}
$ret = [];
$i = 0;
foreach ($response->entities() as $entity) {
$ret[$i]['fields'] = [];
$ret[$i]['dekkingen'] = [];
foreach ($entity->fields as $field => $value) {
$ret[$i]['fields'][$field] = $value->value();
}
foreach ($entity->collection('dekkingen') as $fieldS => $entity) {
$ret[$i]['dekkingen'][$fieldS] = [];
foreach ($entity->fields as $field => $value) {
$ret[$i]['dekkingen'][$fieldS][$field] = $value->value();
}
$ret[$i]['key'] = $entity->key();
$i = $i + 1;
}
return new JsonResponse($ret);
}
}
/**
* @Route("/api/findPolis/{datasource}", name="apiFindPolis")
*/
public function test8(EntityManagerInterface $em, SessionInterface $session, Request $request, $datasource) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$entities = json_decode($request->getContent());
$poliskey = $entities->{'key'};
$collection = new Collection('polissen');
foreach ($entities->{'fields'} as $field) {
$collection->addField(new FieldLabel($field));
}
$collection
->addFilter(new Filter(new FieldPrimary(), $poliskey, '='));
$request = new AwacsViewRequest($collection);
$request->setDisplayOption('display');
if (isset($datasource)) {
$response = $request->send($datasource);
} else {
$response = $request->send();
}
$ret = [];
foreach ($response->entities()[0]->fields as $field => $value) {
$ret[$field] = $value->value();
}
return new JsonResponse($ret);
return new JsonResponse($output);
}
/**
* @Route("/api/findAgendas/{datasource}", name="apiFindAgendas")
*/
public function test24(EntityManagerInterface $em, SessionInterface $session, Request $request, $datasource) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$entities = json_decode($request->getContent());
$poliskey = $entities->{'key'};
$collectionAgenda = new Collection('agendaas');
$collectionAgenda->addField(new FieldLabel('*'));
$collectionAgenda
->addFilter(new Filter(new FieldPrimary(), 'AGENDA_P'. $poliskey . "*", '='));
$request = new AwacsViewRequest($collectionAgenda);
$request->setDisplayOption('display');
if (isset($datasource)) {
$response = $request->send($datasource);
} else {
$response = $request->send();
}
$out = [];
foreach ($response->entities() as $entity) {
$ret = [];
foreach ($entity->fields as $field => $value) {
$ret[$field] = $value->value();
}
$ret['pk'] = $response->entities()[0]->key();
$out[] = $ret;
}
return new JsonResponse($out);
return new JsonResponse($output);
}
public function responseToJson(AwacsResponse $response) {
$polis = $response->entities()[0];
$output = [
'fields' => [],
'dekkingen' => [],
];
foreach ($polis->fields as $field => $value) {
$output['fields'][$field] = $value->value();
}
foreach ($polis->collection('dekkingen') as $field => $dekking) {
$res = [];
foreach ($dekking->fields as $fieldD => $value) {
$res[$fieldD] = $value->value();
}
$output['dekkingen'][$dekking->field('dekking')->value()] = $res;
}
return $output;
}
/**
* @Route("/api/fieldsSjabloon/{datasource}", name="apiFieldsSjabloon")
*/
public function test9(EntityManagerInterface $em, SessionInterface $session, Request $request, $datasource) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$entities = json_decode($request->getContent());
$poliskey = $entities->{'key'};
$productId = $entities->{'productId'};
$contextId = $entities->{'contextId'};
$functieId = $entities->{'functieId'};
$maatschappij = $entities->{'maatschappij'};
$projdir = $this->getParameter('kernel.project_dir');
switch ($maatschappij) {
case 'V059':
$maatschappij = 'asr';
break;
case 'N200':
$maatschappij = 'nn';
break;
}
$data = VPIRequest::templateEmpty('', $productId, $contextId, $functieId, 'geefSjabloon');
$result = VPIRequest::sendRequestVPI($data, $maatschappij, $projdir, true);
$collection = new Collection('polissen');
$collection->addField(new FieldLabel('*'));
$collectionDekkingen = new Collection('dekkingen');
$collectionDekkingen->addField(new FieldLabel('*'));
$collection->addCollection($collectionDekkingen);
$collection
->addFilter(new Filter(new FieldPrimary(), $poliskey, '='));
$request = new AwacsViewRequest($collection);
$request->setDisplayOption('display');
if (isset($datasource)) {
$response = $request->send($datasource);
} else {
$response = $request->send();
}
return new JsonResponse([
'sjabloon' => $result,
'polisinfo' => self::responseToJson($response),
]);
}
/**
* @Route("/api/vpiAcceptatie", name="apiVPIAcceptatie")
*/
public function test10(EntityManagerInterface $em, SessionInterface $session, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
$entities = json_decode($request->getContent());
$poliskey = $entities->{'key'};
$productId = $entities->{'productId'};
$contextId = $entities->{'contextId'};
$functieId = $entities->{'functieId'};
$maatschappij = $entities->{'maatschappij'};
$data = $entities->{'requestData'};
$projdir = $this->getParameter('kernel.project_dir');
switch ($maatschappij) {
case 'V059':
$maatschappij = 'asr';
break;
case 'N200':
$maatschappij = 'nn';
break;
}
$data = VPIRequest::templateEmpty($data, $productId, $contextId, $functieId, 'doeFunctie');
$result = VPIRequest::sendRequestVPI($data, $maatschappij, $projdir);
return new JsonResponse($result);
}
/**
* @Route("/api/vpi/auto", name="apiVPIAuto")
*/
public function apiVPIAuto(EntityManagerInterface $em, SessionInterface $session, Request $request) {
if (!AccessHelper::ownIP($request->getClientIp())) {
return new JsonResponse(['access' => False]);
}
if ($request->getMethod() === 'OPTIONS') {
$response = new JsonResponse();
$response->headers->set('Access-Control-Allow-Origin', 'https://chat.pivotwise.nl');
$response->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS');
$response->headers->set('Access-Control-Allow-Headers', 'Content-Type');
return $response;
}
error_log($request->getContent());
$premiebepalendeGegevens = json_decode($request->getContent());
error_log($request->getContent());
$process = new ProcessCar();
$process->svj = $premiebepalendeGegevens->schadevrijeJaren;
$process->geboortedatum = $premiebepalendeGegevens->geboortedatum;
$process->postcode = $premiebepalendeGegevens->postcode;
$process->huisnummer = $premiebepalendeGegevens->huisnummer;
$process->kilometers = str_replace('km_', '', $premiebepalendeGegevens->kilometrage);
$process->toevoeging = '';
$process->relatieGeboortedatum = $premiebepalendeGegevens->geboortedatum;
$process->relatiePostcode = $premiebepalendeGegevens->postcode;
$process->relatieHuisnummer = $premiebepalendeGegevens->huisnummer;
$process->relatieToevoeging = '';
$process->dekking = $premiebepalendeGegevens->dekking;
$process->termijn = 'maand';
$process->kenteken = $premiebepalendeGegevens->kenteken;
$process->mutationIngangsdatum = new \DateTime();
$process->ingangsdatum = new \DateTime();
$projdir = $this->getParameter('kernel.project_dir');
$productId = 'VPI_NN_PersP2024ExclBM';
$maatschappij = VPIMappingNew::getMaatschappijByProductId($productId);
$dummyTemplate = VPIRequest::template('', $productId, $process, false);
$gimCache = VPIRequest::getSjabloonStdClass($em, $projdir, $maatschappij, $productId, $dummyTemplate['doeFunctieVraag']['procesInfo']['functie']['contextId'], $dummyTemplate['doeFunctieVraag']['procesInfo']['functie']['functieId']);
$data = VPIMapping::transform($process, $productId, ['vc'], $gimCache, null);
if ($data === false) {
return false;
}
$responseBin = new \stdClass();
$response = VPIRequest::sendVPI($projdir, $data, $maatschappij, $productId, $process, $responseBin);
if ($response !== null) {
$policies = VPIHelper::parsePolis($response, $productId, 'Autoverzekering', $data, $process, $responseBin, ['vc']);
if ($policies !== null) {
foreach ($policies as $policy) {
$process->results[] = $policy;
}
}
}
$res = new JsonResponse($process->results);
$res->headers->set('Access-Control-Allow-Origin', 'https://chat.pivotwise.nl');
$res->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS');
$res->headers->set('Access-Control-Allow-Headers', 'Content-Type');
// Add your data to the response if necessary, e.g., $response->setData([...]);
return $res;
}
}