<?php
namespace App\Controller;
use App\Controller\DefaultValuesController;
use App\Document\DataFeed;
use App\Document\Product;
use App\Document\SchedulerJob;
use App\Entity\AllegroCategory;
use App\Entity\Model;
use App\Entity\ProcessQueue;
use App\Entity\StanMag;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* @Route("/")
*/
class DefaultController extends AbstractController
{
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public static function getName($translator)
{
return $translator->trans("Home");
}
public static function getAdminName()
{
return "default";
}
/**
* @Route("/", name="admin_default", methods={"GET"})
* @param ManagerRegistry $managerRegistry
* @return Response
*/
public function adminDefault(ManagerRegistry $managerRegistry): Response
{
/** @var EntityManager $dm */
$dm = $managerRegistry->getManager();
$data = [
'stanmag' => [
// 'bySource' => DefaultValuesController::getGenericStats(
// $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when kod_lokalizacji = '12' then 'WAW' when kod_lokalizacji = '6' then 'GRU' else 'OTHER' end as label, count(*) as total from stanmag group by 1"), 'label', 'total'
// ),
'bySource' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when kod_lokalizacji = '12' then 'WAW' when kod_lokalizacji = '6' then 'GRU' else 'OTHER' end as label, count(*) as total from stanmag group by 1"), 'label', 'total'
),
'byMake' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select m.name as label, count(*) as total from stanmag s, ak_make m where s.id_marki_fk = m.id group by 1 order by 2 desc "), 'label', 'total'
),
'byNrOem' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when TRIM(nr_oem) = '' then 'NO' when nr_oem is null then 'NULL' else 'YES' end as label, count(*) as total from stanmag group by 1"), 'label', 'total'
),
// 'bySoldStatus' => DefaultValuesController::getGenericStats(
// $dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when data_sprzedazy_allegro is not null then 'ALLEGRO' when data_sprzedazy_allegro is not null then 'ACTIVE' else 'OTHER' end as label, count(distinct nr_etykiety) as total from stanmag group by 1"), 'label', 'total'
// ),
'bySoldStatus' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when ilosc = '1' then 'ACTIVE' when ilosc = '0' then 'SOLD' else 'OTHER' end as label, count(distinct nr_etykiety) as total from stanmag group by 1"), 'label', 'total'
),
'byAllegroStatus' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when a.status is null then 'NOT ON ALLEGRO' else a.status end as label , count(distinct s.nr_etykiety) as total from stanmag s left join allegro_offer a on s.nr_etykiety = a.external group by 1;"), 'label', 'total'
),
'noCatalog' => $dm->getRepository(StanMag::class)->getStanMagNoCatalog(),
'noCatalogAll' => $dm->getRepository(StanMag::class)->getStanMagNoCatalog(true),
'noModel' => $dm->getRepository(StanMag::class)->getStanMagNoModel(),
],
'model' => [
'noMake' => $dm->getRepository(Model::class)->getModelNoMake(),
'noMakeAll' => $dm->getRepository(Model::class)->getModelNoMake(true),
],
'allegroCategories' => [
'byLeaf' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when is_leaf = false then 'NO' when is_leaf = true then 'YES' end as label, count(*) as total from allegro_category group by 1"), 'label', 'total'
),
'byStatus' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when is_active = false then 'NO' when is_active = true then 'YES' end as label, count(*) as total from allegro_category group by 1"), 'label', 'total'
),
'byProduct' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when is_products_enabled = false then 'NO' when is_products_enabled = true then 'YES' end as label, count(*) as total from allegro_category group by 1"), 'label', 'total'
),
'byMapping' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when cm.allegro_category_id is null then 'NO' else 'YES' end as label, count(*) as total from allegro_category c left join ak_catalog_mapping cm on c.id=cm.allegro_category_id group by 1"), 'label', 'total'
),
],
'opencartCategories' => [
'byMapping' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when cm.opencart_category_id is null then 'NO' else 'YES' end as label, count(*) as total from opencart_category c left join ak_catalog_mapping cm on c.id=cm.opencart_category_id group by 1"), 'label', 'total'
),
],
'catalog' => [
'byMappingOpencart' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when cm.opencart_category_id is null then 'NO' else 'YES' end as label, count(*) as total from ak_catalog_mapping cm left join opencart_category c on c.id=cm.category_id group by 1"), 'label', 'total'
),
'byMappingAllegro' => DefaultValuesController::getGenericStats(
$dm->getRepository(AllegroCategory::class)->getStatsCategoryBySQL("select case when cm.allegro_category_id is null then 'NO' else 'YES' end as label, count(*) as total from ak_catalog_mapping cm left join allegro_category c on c.id=cm.allegro_category_id group by 1"), 'label', 'total'
),
],
'processQueue' => [
//'byActionStatus' => $dm->getRepository(ProcessQueue::class)->getStatsByActionStatus(),
'byActionStatus' => DefaultValuesController::getGenericStats(
$dm->getRepository(ProcessQueue::class)->getStatsBySQL("select action as label, count(*) as total from process_queue where status not in ('COMPLETED','FAILED') group by 1"), 'label', 'total'
),
'byTriggerStatus' => DefaultValuesController::getGenericStats(
$dm->getRepository(ProcessQueue::class)->getStatsBySQL("select trigger_item as label, count(*) as total from process_queue where status not in ('COMPLETED','FAILED') group by 1"), 'label', 'total'
),
'byStatus' => DefaultValuesController::getGenericStats(
$dm->getRepository(ProcessQueue::class)->getStatsBySQL("select status as label, count(*) as total from process_queue where 1=1 group by 1"), 'label', 'total'
),
// 'completedByStatus' => DefaultValuesController::getGenericStats(
// $dm->getRepository(ProcessQueue::class)->getStatsBySQL("select action as label, count(*) as total from process_queue where 1=1 and status in ('COMPLETED') group by 1"), 'label', 'total'
// ),
'noMakeAll' => $dm->getRepository(Model::class)->getModelNoMake(true),
],
];
// {# last Varlink product pull (date, status, link)#}
// {# last Website product sync (date, status, link)#}
// {# last Website update (date, status, link)#}
// {# number of products in Prod and Stage (group by in Valink Feed or not)#}
// {# number of products in Varlink Feed#}
return $this->render('app/dashboard/index.html.twig', [
'jobs' => [],
'buckets' => [],
'data' => $data,
'debug_str' => print_r($data,1),
'breadcrumbTitle' => DefaultValuesController::getBreadcrumbTitle(),
'categoryTitle' => self::getName($this->translator),
'adminMenu' => self::getAdminName(),
// 'appName' => DefaultValuesController::getAppName($dm),
]);
}
}