<?php
// src/Controller/LuckyController.php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use Doctrine\ORM\EntityManagerInterface;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use App\Annotations\IgnoreFilter;
use App\Entity\Esim;
use App\Entity\TugeEsim;
use App\Entity\MovistarEsim;
use App\Entity\AiraloEsim;
use App\Entity\SimPackage;
use App\Entity\Region;
use App\Entity\MovistarEsimCapacity;
use App\Form\EsimType;
use App\Form\MovistarEsimUploadType;
use App\Form\MovistarEsimType;
use App\Logic\TugeLogic;
use App\Logic\AiraloLogic;
class EsimController extends AbstractController
{
protected $em;
public function __construct(EntityManagerInterface $em){
$this->em = $em;
}
/**
* @Route({
* "en": "/my-esims",
* "es": "/esims",
* "de": "/meine-esims",
* "fr": "/mes-esims",
* "it": "/i-miei-esims",
* "pt": "/meus-esims",
* "cn": "/my-esims_cn",
* "cn2": "/my-esims_cn2",
* }, name="esims_list")
* @QueryParam(name="history", requirements="true|false", default="false", description="History.")
* @IsGranted("ROLE_USER")
*/
public function index(ParamFetcherInterface $paramFetcher)
{
// parameters
$history = $paramFetcher->get('history') === "true";
$limit = !$history;
$repo = $this->em->getRepository(Esim::class);
$repoTugeEsim = $this->em->getRepository(TugeEsim::class);
$repoMovistarEsim = $this->em->getRepository(MovistarEsim::class);
$repoAiraloEsim = $this->em->getRepository(AiraloEsim::class);
$esims = $repo->findByUser($this->getUser(), $limit);
$tugeEsims = $repoTugeEsim->findByUser($this->getUser(), $limit);
$movistarEsims = $repoMovistarEsim->findByUser($this->getUser(), $limit);
$airaloEsims = $repoAiraloEsim->findByUser($this->getUser(), $limit);
// $esims = $repo->includeDeleted(fn ($repo) => $repo->findByUser($this->getUser()));
$allEsims = array_merge($esims, $tugeEsims, $movistarEsims, $airaloEsims);
usort($allEsims, function($a, $b) {
return $a->getPurchaseTransaction()->getTransactedAt() < $b->getPurchaseTransaction()->getTransactedAt();
});
// * @IsGranted("ROLE_USER")
return $this->render('jelly/esims/index.html.twig', [
'esims' => $allEsims,
'history' => $history
]);
}
/**
* @Route("/esim/{esimId}", name="esim_detail")
* @IsGranted("ROLE_USER")
*/
public function detail(int $esimId)
{
$repoEsim = $this->em->getRepository(Esim::class);
$repo = $this->em->getRepository(SimPackage::class);
$esim = $repoEsim->find($esimId);
if(!$esim)
throw $this->createNotFoundException('Esim not found');
if( count($esim->getTransactions()) == 0 || $esim->getTransactions()->first()->getUser()->getId() != $this->getUser()->getId() )
throw $this->createAccessDeniedException('Esim does not belong to user');
$simPackages = $repo->findByEsim($esim);
return $this->render('jelly/esims/detail.html.twig', [
'simPackages' => $simPackages,
]);
}
/**
* @Route({
* "en": "/esim/instructions/{esimId}",
* "es": "/esim/instrucciones/{esimId}",
* "de": "/esim/anweisungen/{esimId}",
* "fr": "/esim/instructions_fr/{esimId}",
* "it": "/esim/istruzioni/{esimId}",
* "pt": "/esim/instrucoes/{esimId}",
* "cn": "/esim/instructions_cn/{esimId}",
* "cn2": "/esim/instructions_cn2/{esimId}",
* }, name="esim_instructions")
*/
public function instructions(Request $request, int $esimId)
{
$repoEsim = $this->em->getRepository(Esim::class);
$repo = $this->em->getRepository(SimPackage::class);
$esim = $repoEsim->find($esimId);
if(!$esim) {
$repoEsim = $this->em->getRepository(TugeEsim::class);
$esim = $repoEsim->find($esimId);
if ($esim) return $this->redirectToRoute("esim_tuge_instructions", ['esimId' => $esim->getId(), '_locale' => $request->getLocale() ]);
$repoEsim = $this->em->getRepository(MovistarEsim::class);
$esim = $repoEsim->find($esimId);
if ($esim) return $this->redirectToRoute("esim_movistar_instructions", ['esimId' => $esim->getId(), '_locale' => $request->getLocale()]);
$repoEsim = $this->em->getRepository(AiraloEsim::class);
$esim = $repoEsim->find($esimId);
if ($esim) return $this->redirectToRoute("esim_airalo_instructions", ['esimId' => $esim->getId(), '_locale' => $request->getLocale()]);
throw $this->createNotFoundException('Esim not found');
}
if( count($esim->getTransactions()) == 0 || $esim->getTransactions()->first()->getUser()->getId() != $this->getUser()->getId() )
throw $this->createAccessDeniedException('Esim does not belong to user');
return $this->render('jelly/esims/instructions.html.twig', [
'transaction' => $esim->getPurchaseTransaction(),
]);
}
/**
* @Route({
* "en": "/esim/instructions2/{esimId}",
* "es": "/esim/instrucciones2/{esimId}",
* "de": "/esim/anweisungen2/{esimId}",
* "fr": "/esim/instructions2_fr/{esimId}",
* "it": "/esim/istruzioni2/{esimId}",
* "pt": "/esim/instrucoes2/{esimId}",
* "cn": "/esim/instructions2_cn/{esimId}",
* "cn2": "/esim/instructions2_cn2/{esimId}",
* }, name="esim_tuge_instructions")
*/
public function instructions2(int $esimId)
{
$repoEsim = $this->em->getRepository(TugeEsim::class);
$repo = $this->em->getRepository(SimPackage::class);
$esim = $repoEsim->find($esimId);
if(!$esim)
throw $this->createNotFoundException('Esim not found');
if( !$esim->getPurchaseTransaction() )
throw $this->createAccessDeniedException('Esim does not belong to user');
return $this->render('jelly/esims/instructions.html.twig', [
'transaction' => $esim->getPurchaseTransaction(),
]);
}
/**
* @Route({
* "en": "/esim/instructions3/{esimId}",
* "es": "/esim/instrucciones3/{esimId}",
* "de": "/esim/anweisungen3/{esimId}",
* "fr": "/esim/instructions3_fr/{esimId}",
* "it": "/esim/istruzioni3/{esimId}",
* "pt": "/esim/instrucoes3/{esimId}",
* "cn": "/esim/instructions3_cn/{esimId}",
* "cn2": "/esim/instructions3_cn2/{esimId}",
* }, name="esim_movistar_instructions")
*/
public function instructions3(int $esimId)
{
$repoEsim = $this->em->getRepository(MovistarEsim::class);
$esim = $repoEsim->find($esimId);
if(!$esim)
throw $this->createNotFoundException('Esim not found');
if( !$esim->getPurchaseTransaction() )
throw $this->createAccessDeniedException('Esim does not belong to user');
return $this->render('jelly/esims/instructions.html.twig', [
'transaction' => $esim->getPurchaseTransaction(),
]);
}
/**
* @Route({
* "en": "/esim/instructions4/{esimId}",
* "es": "/esim/instrucciones4/{esimId}",
* "de": "/esim/anweisungen4/{esimId}",
* "fr": "/esim/instructions4_fr/{esimId}",
* "it": "/esim/istruzioni4/{esimId}",
* "pt": "/esim/instrucoes4/{esimId}",
* "cn": "/esim/instructions4_cn/{esimId}",
* "cn2": "/esim/instructions4_cn2/{esimId}",
* }, name="esim_airalo_instructions")
*/
public function instructions4(int $esimId)
{
$repoEsim = $this->em->getRepository(AiraloEsim::class);
$esim = $repoEsim->find($esimId);
if(!$esim)
throw $this->createNotFoundException('Esim not found');
if( !$esim->getPurchaseTransaction() )
throw $this->createAccessDeniedException('Esim does not belong to user');
return $this->render('jelly/esims/instructions.html.twig', [
'transaction' => $esim->getPurchaseTransaction(),
]);
}
/**
* @Route("/admin/esims", name="esims_admin_list")
* @QueryParam(name="page", requirements="\d+", default=1, description="Page number.")
* @QueryParam(name="sort", requirements="e.iccid|u.lastName|r.descriptionEs|e.createdAt", description="Sort.")
* @QueryParam(name="dir", requirements="asc|desc", default="asc", description="Sort direction.")
* @QueryParam(name="iccid", requirements=".*", default="", nullable=true, description="Iccid.")
* @IsGranted("ROLE_ADMIN")
*/
public function adminIndex(Request $request, ParamFetcherInterface $paramFetcher)
{
// parameters
$page = $paramFetcher->get('page');
$sort = $paramFetcher->get('sort');
$dir = $paramFetcher->get('dir');
$iccid = $paramFetcher->get('iccid');
$download = $request->query->get('download');
// query
$results_per_page = $this->getParameter('app.results_per_page');
// filters
$currentFilters = [];
if($sort){
$currentFilters['sort'] = $sort;
$currentFilters['dir'] = $dir;
}
if($iccid){
$currentFilters['iccid'] = $iccid;
}
$repo = $this->em->getRepository(Esim::class);
$form = $this->createForm(EsimType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$region = $form->get('region')->getData();
$file = $form->get('file')->get('file')->getData();
if ($file) {
$this->uploadExcel($region, $file->getRealPath());
}
}
$esims = $repo->getList($sort, $dir, $page, $results_per_page, $iccid, $download);
if($download == '1')
return $this->downloadExcel($esims);
$totalPages = ceil(count($esims) / $results_per_page);
// * @IsGranted("ROLE_USER")
return $this->render('angle/esims/index.html.twig', [
'esims' => $esims,
'page' => $page,
'totalPages' => $totalPages,
'totalResults' => count($esims),
'currentFilters' => $currentFilters,
'results_per_page' => $results_per_page,
'iccid' => $iccid,
'form' => $form->createView(),
'regions' => $this->em->getRepository(Region::class)->findBy([], ['descriptionEs' => 'ASC']),
]);
}
/**
* @Route("/admin/tuge-esims", name="esims_tuge_admin_list")
* @QueryParam(name="page", requirements="\d+", default=1, description="Page number.")
* @QueryParam(name="sort", requirements="e.iccid|u.lastName|r.descriptionEs|e.createdAt|e.bytesConsumed", description="Sort.")
* @QueryParam(name="dir", requirements="asc|desc", default="asc", description="Sort direction.")
* @QueryParam(name="iccid", requirements=".*", default="", nullable=true, description="Iccid.")
* @IsGranted("ROLE_AGENT")
* @IgnoreFilter(filter="softdeleteable", forClasses={"App\Entity\User"})*
*/
public function adminTugeIndex(Request $request, ParamFetcherInterface $paramFetcher)
{
// parameters
$page = $paramFetcher->get('page');
$sort = $paramFetcher->get('sort');
$dir = $paramFetcher->get('dir');
$iccid = $paramFetcher->get('iccid');
$download = $request->query->get('download');
// query
$results_per_page = $this->getParameter('app.results_per_page');
// filters
$currentFilters = [];
if($sort){
$currentFilters['sort'] = $sort;
$currentFilters['dir'] = $dir;
}
if($iccid){
$currentFilters['iccid'] = $iccid;
}
$repo = $this->em->getRepository(TugeEsim::class);
$esims = $repo->getList($sort, $dir, $page, $results_per_page, $iccid, $download);
if($download == '1')
return $this->downloadExcel($esims);
$totalPages = ceil(count($esims) / $results_per_page);
// * @IsGranted("ROLE_USER")
return $this->render('angle/esims/index_tuge.html.twig', [
'esims' => $esims,
'page' => $page,
'totalPages' => $totalPages,
'totalResults' => count($esims),
'currentFilters' => $currentFilters,
'results_per_page' => $results_per_page,
'iccid' => $iccid,
]);
}
/**
* @Route("/admin/movistar-esims", name="esims_movistar_admin_list")
* @QueryParam(name="page", requirements="\d+", default=1, description="Page number.")
* @QueryParam(name="sort", requirements="mec.amountGb|u.lastName|e.createdAt|t.createdAt", description="Sort.")
* @QueryParam(name="dir", requirements="asc|desc", default="asc", description="Sort direction.")
* @IsGranted("ROLE_ADMIN")
* @IgnoreFilter(filter="softdeleteable", forClasses={"App\Entity\User"})*
*/
public function adminMovistarIndex(Request $request, ParamFetcherInterface $paramFetcher)
{
// parameters
$page = $paramFetcher->get('page');
$sort = $paramFetcher->get('sort');
$dir = $paramFetcher->get('dir');
$download = $request->query->get('download');
// query
$results_per_page = $this->getParameter('app.results_per_page');
// filters
$currentFilters = [];
if($sort){
$currentFilters['sort'] = $sort;
$currentFilters['dir'] = $dir;
}
$download = $request->query->get('download');
$repo = $this->em->getRepository(MovistarEsim::class);
$form = $this->createForm(MovistarEsimUploadType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$region = $form->get('region')->getData();
$file = $form->get('file')->get('file')->getData();
if ($file) {
$this->uploadExcel2($region, $file->getRealPath());
}
}
$esims = $repo->getList($sort, $dir, $page, $results_per_page, $download);
if($download == '1')
return $this->downloadExcel2($esims);
$totalPages = ceil(count($esims) / $results_per_page);
// * @IsGranted("ROLE_USER")
return $this->render('angle/esims/index_movistar.html.twig', [
'esims' => $esims,
'page' => $page,
'totalPages' => $totalPages,
'totalResults' => count($esims),
'currentFilters' => $currentFilters,
'results_per_page' => $results_per_page,
'form' => $form->createView(),
]);
}
/**
* @Route("/admin/movistar-esim/{esimId}", name="esims_movistar_admin_detail")
* @IsGranted("ROLE_ADMIN")
* @IgnoreFilter(filter="softdeleteable", forClasses={"App\Entity\User"})*
*/
public function adminMovistarDetail(Request $request, string $esimId)
{
$repo = $this->em->getRepository(MovistarEsim::class);
$esim = $repo->find($esimId);
if(!$esim)
throw $this->createNotFoundException('Esim not found');
$form = $this->createForm(MovistarEsimType::class, $esim);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$esim = $form->getData();
$this->em->persist($esim);
$this->em->flush();
return $this->redirectToRoute('esims_movistar_admin_list');
}
return $this->render('angle/esims/detail_movistar.html.twig', [
'esim' => $esim,
'form' => $form->createView(),
]);
}
/**
* @Route("/admin/airalo-esims", name="esims_airalo_admin_list")
* @QueryParam(name="page", requirements="\d+", default=1, description="Page number.")
* @QueryParam(name="sort", requirements="e.iccid|u.lastName|r.descriptionEs|e.createdAt|e.bytesConsumed", description="Sort.")
* @QueryParam(name="dir", requirements="asc|desc", default="asc", description="Sort direction.")
* @QueryParam(name="iccid", requirements=".*", default="", nullable=true, description="Iccid.")
* @IsGranted("ROLE_AGENT")
* @IgnoreFilter(filter="softdeleteable", forClasses={"App\Entity\User"})*
*/
public function adminAiraloIndex(Request $request, ParamFetcherInterface $paramFetcher)
{
// parameters
$page = $paramFetcher->get('page');
$sort = $paramFetcher->get('sort');
$dir = $paramFetcher->get('dir');
$iccid = $paramFetcher->get('iccid');
$download = $request->query->get('download');
// query
$results_per_page = $this->getParameter('app.results_per_page');
// filters
$currentFilters = [];
if($sort){
$currentFilters['sort'] = $sort;
$currentFilters['dir'] = $dir;
}
if($iccid){
$currentFilters['iccid'] = $iccid;
}
$repo = $this->em->getRepository(AiraloEsim::class);
$esims = $repo->getList($sort, $dir, $page, $results_per_page, $iccid, $download);
if($download == '1')
return $this->downloadExcel($esims);
$totalPages = ceil(count($esims) / $results_per_page);
// * @IsGranted("ROLE_USER")
return $this->render('angle/esims/index_airalo.html.twig', [
'esims' => $esims,
'page' => $page,
'totalPages' => $totalPages,
'totalResults' => count($esims),
'currentFilters' => $currentFilters,
'results_per_page' => $results_per_page,
'iccid' => $iccid,
]);
}
/**
* @IsGranted("ROLE_ADMIN")
* @Route(
* "/services/esim/assign_region.{_format}",
* name="esim_region_assign",
* requirements={
* "_format": "json"
* },
* methods={"GET"}
* )
*/
public function assignRegion(Request $request)
{
$repo = $this->getDoctrine()->getRepository(Region::class);
$repoEsims = $this->getDoctrine()->getRepository(Esim::class);
$ids = $request->query->get('id');
$regionId = urldecode($request->query->get('region_id'));
$region = $repo->find($regionId);
$idsArray = explode(",", $ids);
foreach($idsArray as $id) if($id){
if ($esim = $repoEsims->findOneById($id) ){
$esim->setRegion($region);
$this->em->flush();
}
}
return ['ok' => true];
}
private function uploadExcel($region, $filename){
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository(Esim::class);
$spreadsheet = IOFactory::load($filename);
$sheet = $spreadsheet->getActiveSheet();
$rowCount = 2;
while (!empty($sheet->getCell("A$rowCount")->getValue())) {
$iccid = trim((string) $sheet->getCell("A$rowCount")->getValue());
$qrCode = trim((string) $sheet->getCell("D$rowCount")->getValue());
$existingDevice = $repo->findOneBy(['iccid' => $iccid]);
if($existingDevice){
$rowCount++;
continue;
}
$esim = new Esim();
$esim->setRegion($region);
$esim->setIccid($iccid);
$esim->setQrCode($qrCode);
$em->persist($esim);
$rowCount++;
}
$em->flush();
}
private function uploadExcel2($region, $filename){
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository(MovistarEsim::class);
$repoCapacity = $em->getRepository(MovistarEsimCapacity::class);
$spreadsheet = IOFactory::load($filename);
$sheet = $spreadsheet->getActiveSheet();
$rowCount = 2;
while (!empty($sheet->getCell("A$rowCount")->getValue())) {
$phoneNumber = trim((string) $sheet->getCell("A$rowCount")->getValue());
$amountGb = trim((string) $sheet->getCell("B$rowCount")->getValue());
$qrCode = trim((string) $sheet->getCell("C$rowCount")->getValue());
$existingDevice = $repo->findOneBy(['phoneNumber' => $phoneNumber]);
if($existingDevice){
$rowCount++;
continue;
}
$capacity = $repoCapacity->findOneBy(['amountGb' => $amountGb]);
if(!$capacity){
$rowCount++;
continue;
}
$esim = new MovistarEsim();
$esim->setRegion($region);
$esim->setPhoneNumber($phoneNumber);
$esim->setMovistarEsimCapacity($capacity);
$esim->setQrCode($qrCode);
$em->persist($esim);
$rowCount++;
}
$em->flush();
}
private $col = -1;
private function getCell($row, $forward = true) {
$cols = [ 'A' , 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI',' AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ'];
if( $forward )
$this->col++;
return (String) ($cols[$this->col] . $row);
}
private function getColumnindex($forward = true) {
if( $forward )
$this->col++;
return $this->col;
}
private function resetCol() {
$this->col = -1;
}
private function downloadExcel($stats){
ini_set('memory_limit', '512M');
set_time_limit(0);
$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()
->setCreator("Blink+")
->setLastModifiedBy("Blink+")
->setTitle("beconnected esims")
->setSubject("beconnected esims")
->setDescription(
"beconnected esims"
);
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue($this->getCell(1, true), 'Esim');
$sheet->setCellValue($this->getCell(1, true), 'Nombre');
$sheet->setCellValue($this->getCell(1, true), 'Fecha creación');
$row = 2;
foreach($stats as $stat){
$this->resetCol();
$sheet->setCellValue($this->getCell($row, true), $stat->getIccid());
$sheet->setCellValue($this->getCell($row, true), $stat->getPurchaseTransaction() ? ( $stat->getPurchaseTransaction()->getUser()->getFirstName() . " " . $stat->getPurchaseTransaction()->getUser()->getLastName() ) : "" );
$sheet->setCellValue($this->getCell($row, true), $stat->getCreatedAt());
$row++;
}
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="'. urlencode("beconnected.xlsx").'"');
$writer->save('php://output');
die();
return;
}
private function downloadExcel2($stats){
ini_set('memory_limit', '512M');
set_time_limit(0);
$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()
->setCreator("Blink+")
->setLastModifiedBy("Blink+")
->setTitle("beconnected movistar esims")
->setSubject("beconnected movistar esims")
->setDescription(
"beconnected movistar esims"
);
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue($this->getCell(1, true), 'Número');
$sheet->setCellValue($this->getCell(1, true), 'Capacidad');
$sheet->setCellValue($this->getCell(1, true), 'Nombre');
$sheet->setCellValue($this->getCell(1, true), 'Fecha creación');
$sheet->setCellValue($this->getCell(1, true), 'Fecha compra');
$sheet->setCellValue($this->getCell(1, true), 'Fecha deshabilitación');
$row = 2;
foreach($stats as $stat){
$this->resetCol();
$sheet->setCellValue($this->getCell($row, true), $stat->getPhoneNumber());
$sheet->setCellValue($this->getCell($row, true), $stat->getMovistarEsimCapacity()->getAmountGb());
$sheet->setCellValue($this->getCell($row, true), $stat->getPurchaseTransaction() ? ( $stat->getPurchaseTransaction()->getUser()->getFirstName() . " " . $stat->getPurchaseTransaction()->getUser()->getLastName() ) : "" );
$sheet->setCellValue($this->getCell($row, true), $stat->getCreatedAt());
$sheet->setCellValue($this->getCell($row, true), $stat->getPurchaseTransaction() ? $stat->getPurchaseTransaction()->getCreatedAt() : "" );
$sheet->setCellValue($this->getCell($row, true), $stat->getDeactivatedAt());
$row++;
}
$writer = new Xlsx($spreadsheet);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="'. urlencode("beconnected.xlsx").'"');
$writer->save('php://output');
die();
return;
}
/**
* @IsGranted("ROLE_AGENT")
* @Route(
* "/services/tuge_esim.{_format}",
* name="service_tuge_esim",
* requirements={
* "_format": "json"
* },
* methods={"GET"}
* )
*/
public function tugeEsim(Request $request, TugeLogic $tugeLogic)
{
$repository = $this->getDoctrine()->getRepository(TugeEsim::class);
$id = $request->query->get('id');
if($id){
$entity = $repository->findOneById($id);
if($entity)
$data = $tugeLogic->queryOrder($entity->getIccid());
else
return ['ok' => false];
return ['ok' => true, 'order_status' => $data[0]->orderStatus, 'start_date' => $data[0]->startDate , 'end_date' => $data[0]->endDate, 'iccid' => $entity->getIccid() ] ;
}
return ['ok' => false];
}
/**
* @IsGranted("ROLE_ADMIN")
* @Route(
* "/services/tuge_esim_refund.{_format}",
* name="service_tuge_esim_refund",
* requirements={
* "_format": "json"
* },
* methods={"POST"}
* )
*/
public function tugeEsimRefund(Request $request)
{
$repository = $this->getDoctrine()->getRepository(TugeEsim::class);
$id = $request->query->get('id');
if($id){
$entity = $repository->findOneById($id);
if($entity){
$entity->setIsRefunded(true);
$this->em->flush();
}
return true;
}
return ['ok' => false];
}
/**
* @IsGranted("ROLE_ADMIN")
* @Route(
* "/services/movistar_esim_deactivate.{_format}",
* name="service_movistar_esim_deactivate",
* requirements={
* "_format": "json"
* },
* methods={"POST"}
* )
*/
public function movistarEsimDeactivate(Request $request)
{
$repository = $this->getDoctrine()->getRepository(MovistarEsim::class);
$id = $request->query->get('id');
if($id){
$entity = $repository->findOneById($id);
if($entity){
$entity->setDeactivatedAt(new \DateTimeImmutable);
$this->em->flush();
}
return true;
}
return ['ok' => false];
}
/**
* @IsGranted("ROLE_AGENT")
* @Route(
* "/services/airalo_esim.{_format}",
* name="service_airalo_esim",
* requirements={
* "_format": "json"
* },
* methods={"GET"}
* )
*/
public function airaloEsim(Request $request, AiraloLogic $airaloLogic)
{
$repository = $this->getDoctrine()->getRepository(AiraloEsim::class);
$id = $request->query->get('id');
if($id){
$entity = $repository->findOneById($id);
if($entity)
$data = $airaloLogic->fetchDataUsage($entity);
else
return ['ok' => false];
return ['ok' => true, 'data' => $data['data'] ] ;
}
return ['ok' => false];
}
}