<?php
namespace App\Controller;
use App\Config;
use App\Entity\Tune\AdvertiserAccountManager;
use App\Entity\Tune\AffiliateAccountManager;
use App\Entity\AppInfo;
use App\Entity\Tune\AdvertiserInfo;
use App\Entity\AppRetentionReport;
use App\Entity\DeductionControl;
use App\Entity\HyperAffiliateData;
use App\Entity\MmpMobileApps;
use App\Entity\MmpOffers;
use App\Entity\MmpPartnerRules;
use App\Entity\MmpReports;
use App\Entity\Tune\OfferInfo;
use App\Entity\NewsletterBuilder;
use App\Entity\OfferGeoRelationship;
use App\Entity\RevenueControl;
use App\Entity\RevenueTotal;
use App\Entity\SkadNetworkManualPostbackMapping;
use App\Entity\SkadNetworkPostbackLogs;
use App\Entity\Tag;
use App\Services\AffiliateHasofferAPI;
use App\Services\Alerts;
use App\Services\Aws\ElasticCache;
use App\Services\Aws\S3;
use App\Services\BrandHasofferAPI;
use App\Services\Common;
use App\Services\FinancialToolsComponents;
use App\Services\ImpressionsApis;
use App\Services\Metrics24APICalls;
use App\Services\MmpComponents;
use App\Services\MysqlQueries;
use App\Services\MafoFinancialToolsComponents;
use App\Services\UsersComponents;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Mmoreram\GearmanBundle\Service\GearmanClientInterface;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use function GuzzleHttp\json_encode;
use Psr\Log\LoggerInterface;
/**
*
* Reports related routes with endpoint /api/reports/{route}
*
* @Route("/api/reports", name="reports_", host="%main_subdomain%")
*/
class ReportsController extends AbstractController
{
private $commonCalls;
private $doctrine;
private $mysqlQueries;
private $financialToolsComponents;
private $alerts;
private $brandHasofferApi;
private $mmpComponents;
private $affiliateHasofferAPI;
private $usersComponents;
private $elasticCache;
private $projectDir;
private $s3;
private $impressionsApis;
private $metrics24APICalls;
private $gearmanClientInterface;
private $entityManager;
private $mafoFinancialToolsComponents;
public function __construct(
Common $commonCalls,
ManagerRegistry $doctrine,
MysqlQueries $mysqlQueries,
FinancialToolsComponents $financialToolsComponents,
Alerts $alerts,
BrandHasofferApi $brandHasofferApi,
MmpComponents $mmpComponents,
AffiliateHasofferAPI $affiliateHasofferAPI,
UsersComponents $usersComponents,
ElasticCache $elasticCache,
S3 $s3,
ImpressionsApis $impressionsApis,
Metrics24APICalls $metrics24APICalls,
GearmanClientInterface $gearmanClientInterface,
string $projectDir,
EntityManagerInterface $entityManager,
MafoFinancialToolsComponents $mafoFinancialToolsComponents
) {
$this->commonCalls = $commonCalls;
$this->doctrine = $doctrine;
$this->mysqlQueries = $mysqlQueries;
$this->financialToolsComponents = $financialToolsComponents;
$this->alerts = $alerts;
$this->brandHasofferApi = $brandHasofferApi;
$this->mmpComponents = $mmpComponents;
$this->affiliateHasofferAPI = $affiliateHasofferAPI;
$this->usersComponents = $usersComponents;
$this->elasticCache = $elasticCache;
$this->s3 = $s3;
$this->impressionsApis = $impressionsApis;
$this->metrics24APICalls = $metrics24APICalls;
$this->gearmanClientInterface = $gearmanClientInterface;
$this->projectDir = $projectDir;
$this->entityManager = $entityManager;
$this->mafoFinancialToolsComponents = $mafoFinancialToolsComponents;
}
/**
* @Route("/advertiser-roi-report", name="get_advertiser_roi_report", methods={"GET"})
*/
public function getAdvertiserRoiReportAction(Request $request)
{
$filtersSelected = $request->query->get('filters');
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters');
$filters = [];
$excludedFiltersFlags = [];
if (isset($filtersSelected)) {
foreach ($filtersSelected as $key => $value) {
$key === 'MULTISELECT_TUNE_OFFERS' ? $filters['offerId'] = $value : false;
$key === 'MULTISELECT_TUNE_ACCOUNTS' ? $filters['tuneAccount'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $filters['advertiserId'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $filters['affiliateId'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $filters['affiliateCategory'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_SOURCE ? $filters['source'] = $value : false;
}
}
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$value = (int)$value;
$key === 'MULTISELECT_TUNE_OFFERS' ? $excludedFiltersFlags['offerId'] = $value : false;
$key === 'MULTISELECT_TUNE_ACCOUNTS' ? $excludedFiltersFlags['tuneAccount'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $excludedFiltersFlags['advertiserId'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $excludedFiltersFlags['affiliateId'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $excludedFiltersFlags['affiliateCategory'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_SOURCE ? $excludedFiltersFlags['source'] = $value : false;
}
}
$dateStart = date('Y-m-d', strtotime($request->query->get('startDate')));
$dateEnd = date('Y-m-d', strtotime($request->query->get('endDate')));
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1 ? true : false;
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_MMP_REPORT_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$page = $request->query->get('currentPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$limit = $request->query->get('perPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$data = [];
$apiPage = 1;
$apiLimit = 100000;
$report = [];
foreach (Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS as $tuneAccount) {
if (isset($filters['tuneAccount']) && !in_array($tuneAccount, $filters['tuneAccount'])) {
continue;
}
$data = [];
$hoApiResponse = $this->brandHasofferApi->getStatsForAdvertiserRoiReport([], [], [], [], $dateStart, $dateEnd, $apiLimit, $apiPage, $tuneAccount);
while ($hoApiResponse['response']['data']['data']) {
$data = array_values(array_merge($data, $hoApiResponse['response']['data']['data']));
$apiPage += 1;
$hoApiResponse = $this->brandHasofferApi->getStatsForAdvertiserRoiReport([], [], [], [], $dateStart, $dateEnd, $apiLimit, $apiPage, $tuneAccount);
}
$affiliateCategoriesByAffiliateId = $this->commonCalls->getAffiliateCategoryByAffiliateId($tuneAccount);
$distinctOfferIds = [];
foreach ($data as $key => $value) {
$index = md5($value['Stat']['affiliate_id'] . '#' . $value['Stat']['offer_id'] . '#' . $value['Stat']['source'] . '#' . $value['ConversionsMobile']['adv_sub4'] . '#' . $tuneAccount);
if (!array_key_exists($index, $report)) {
$report[$index] = [
'affiliateId' => $value['Stat']['affiliate_id'],
'affiliateName' => '',
'affiliateCategory' => array_key_Exists($value['Stat']['affiliate_id'], $affiliateCategoriesByAffiliateId) ? $affiliateCategoriesByAffiliateId[$value['Stat']['affiliate_id']]['category'] : Config::HASOFFER_AFFILIATE_CATEGORY_UNCATEGORISED_TAG_NAME,
'offerId' => $value['Stat']['offer_id'],
'offerName' => '',
'source' => $value['Stat']['source'],
'advertiserId' => $value['Stat']['advertiser_id'],
'advertiserName' => '',
'goalConversions' => 0,
'advertiserRevenue' => 0,
'mobuppsRevenue' => 0,
'advertiserRevenueCurrency' => $value['ConversionsMobile']['adv_sub4'],
'roiPercentage' => 0,
];
!in_array($value['Stat']['offer_id'], $distinctOfferIds) ? array_push($distinctOfferIds, $value['Stat']['offer_id']) : false;
}
foreach ($filters as $k => $v) {
if (
array_key_exists($k, $report[$index]) &&
(
(
in_array($report[$index][$k], $v) &&
$excludedFiltersFlags[$k]
) ||
(
!in_array($report[$index][$k], $v) &&
!$excludedFiltersFlags[$k]
)
)
) {
unset($report[$index]);
continue 2;
}
}
$report[$index]['advertiserRevenue'] += $value['ConversionsMobile']['adv_sub5'];
$report[$index]['goalConversions'] += 1;
$report[$index]['tuneAccount'] = $tuneAccount;
}
$offerInfo = [];
$distinctOfferIds ? $offerInfo = $this->commonCalls->getOfferInfoByKey($distinctOfferIds, $tuneAccount) : false;
$advertiserList = $this->commonCalls->getAdvertisersListByStatusWithKeys([
'tuneAccount' => $tuneAccount
]);
$affiliateList = $this->commonCalls->getAffiliateListByStatusWithKeys($tuneAccount);
foreach ($report as $key => $value) {
array_key_exists($value['advertiserId'], $advertiserList) ? $report[$key]['advertiserName'] = $advertiserList[$value['advertiserId']]['name'] : false;
array_key_exists($value['affiliateId'], $affiliateList) ? $report[$key]['affiliateName'] = $affiliateList[$value['affiliateId']]['name'] : false;
if (array_key_exists($value['offerId'], $offerInfo)) {
$report[$key]['offerName'] = $offerInfo[$value['offerId']]['name'];
$mobuppsRevenue = $offerInfo[$value['offerId']]['maxPayout'] * $value['goalConversions'];
if ($mobuppsRevenue > 0) {
$report[$key]['roiPercentage'] = round(((($value['advertiserRevenue'] - $mobuppsRevenue) / $mobuppsRevenue) * 100), 2);
$report[$key]['mobuppsRevenue'] = $mobuppsRevenue;
}
}
$report[$key]['advertiserRevenue'] = round($value['advertiserRevenue'], 2);
}
}
$tableColumns = $this->commonCalls->getDataFromJsonFile(Config::TABLE_COLUMNS_WITH_JSON_FILE[Config::ADVERTISER_ROI_REPORT]);
$finalArr = $this->commonCalls->getReportsRowWiseDataByAggregation($tableColumns, $selectedColumns, $report);
if ($downloadDataAsCSV) {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'Advertiser ROI Report ' . $dateStart . '_' . $dateEnd);
} else {
return new JsonResponse($this->commonCalls->getPaginatedResponseForReports($finalArr, $tableColumns, $selectedColumns, $sortBy, $sortType, $limit, $page));
}
}
/**
* @Route("/retention-report", name="get_retention_report", methods={"GET"})
*/
public function getRetentionReportAction(Request $request)
{
$filtersSelected = $request->query->get('filters');
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters');
$filters = [];
$excludedFiltersFlags = [];
$finalArr = [];
if ($filtersSelected) {
foreach ($filtersSelected as $key => $value) {
$key === Config::MULTISELECT_MMP_STATISTICS_APP ? $filters['appIds'] = $value : false;
$key === Config::MULTISELECT_MAFO_ADVERTISERS ? $filters['advertiserId'] = $value : false;
$key === Config::MULTISELECT_MAFO_AFFILIATES ? $filters['publisher'] = $value : false;
$key === Config::MULTISELECT_COHORT_TYPE ? $filters['cohort_type'] = $value : false;
$key === Config::MULTISELECT_GEO ? $filters['geo'] = $value : false;
}
}
if ($excludedFlagForFilters) {
foreach ($excludedFlagForFilters as $key => $value) {
$value = (int) $value;
$key === Config::MULTISELECT_MAFO_ADVERTISERS ? $excludedFiltersFlags['advertiserId'] = $value : false;
$key === Config::MULTISELECT_MAFO_AFFILIATES ? $excludedFiltersFlags['publisher'] = $value : false;
$key === Config::MULTISELECT_COHORT_TYPE ? $excludedFiltersFlags['cohort_type'] = $value : false;
$key === Config::MULTISELECT_GEO ? $excludedFiltersFlags['geo'] = $value : false;
$key === Config::MULTISELECT_MMP_STATISTICS_APP ? $excludedFiltersFlags['appIds'] = $value : false;
}
}
$dateStart = date('Y-m-d', strtotime($request->query->get('startDate')));
// For retention reports, endDate should be startDate + 29 days (to cover D1-D30 retention)
// This ensures we capture the full 30-day retention window for conversions in the selected range
$dateEnd = date('Y-m-d', strtotime($dateStart . ' +29 days'));
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1;
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_MMP_REPORT_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$page = $request->query->get('currentPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$limit = $request->query->get('perPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$selectedColumns = $request->query->get('data') ?: [];
$filterFields = ['publisherID', 'publisher', 'advertiserId', 'advertiserName', 'appId', 'appName', 'mmpOfferId', 'mmpOffer', 'appsflyerAccount', 'cohortType', 'geo', 'eventsName', 'clicks', 'installs', 'events', 'sevents'];
$fieldsData = [];
$fieldsName = [];
foreach ($filterFields as $field) {
if (!empty($selectedColumns[$field])) {
$fieldsData[$field] = $selectedColumns[$field];
$fieldsName[] = $field;
}
}
$selectedColumnsData = $fieldsData;
$fieldsNameData = $fieldsName;
$tableColumns = $this->commonCalls->getDataFromJsonFile(
Config::TABLE_COLUMNS_WITH_JSON_FILE[Config::RETENTION_REPORT_HEADER]
);
$columnConfig = $this->commonCalls->getDataFromJsonFile(
Config::TABLE_COLUMNS_WITH_JSON_FILE[Config::RETENTION_REPORT]
);
$newTopRow = [];
foreach ($selectedColumnsData as $key => $val) {
if (array_key_exists($key, $columnConfig)) {
$newTopRow[$key] = $columnConfig[$key];
}
}
$tableColumnsData = $newTopRow + $tableColumns;
$data = [];
$transactionIds = [];
$retentionReportRepository = $this->doctrine->getRepository(AppRetentionReport::class);
ini_set('memory_limit', '-1');
$retentionReportData = $retentionReportRepository->getRevenueGroupedByMediaSourceForLast30Days($selectedColumnsData, $filtersSelected, $dateStart, $dateEnd);
$retentionReportData = $retentionReportData ?? [];
$groupedData = [];
foreach ($retentionReportData as $value) {
$conversionDay = $value['conversion_day'] ?? null;
$mediaSource = $value['media_source'] ?? '';
$dayNumber = isset($value['day_number']) ? (int)$value['day_number'] : null;
$dayLabel = $value['day_label'] ?? '';
$eventCount = isset($value['event_count']) ? (int)$value['event_count'] : 0;
$uniqueUsers = isset($value['unique_users']) ? (int)$value['unique_users'] : 0;
// conversion_day may be a comma-separated string from GROUP_CONCAT, or a single date
$conversionDayString = null;
if ($conversionDay) {
if (is_string($conversionDay) && strpos($conversionDay, ',') !== false) {
// Multiple conversion dates - split and process each
$conversionDays = explode(',', $conversionDay);
$conversionDayString = !empty($conversionDays) ? trim($conversionDays[0]) : null;
} else {
$conversionDayString = $conversionDay instanceof \DateTime ? $conversionDay->format('Y-m-d') : (string)$conversionDay;
}
}
// Group ONLY by media_source - selected columns are for display only, not for grouping
// This ensures each media_source appears only once in the final report
$groupKeyParts = [$mediaSource];
// DO NOT add any selected columns to groupKey - they are display-only fields
// All rows with the same media_source should be aggregated together regardless of other field values
$groupKey = md5(implode('|', $groupKeyParts));
if (!isset($groupedData[$groupKey])) {
$groupedData[$groupKey] = [
'media_source' => $mediaSource,
'total_events' => 0,
'total_unique_users' => 0,
'total_attributions' => 0,
'total_installs' => 0,
'total_clicks' => 0,
'day_data' => [],
'base_data' => $value,
'conversion_dates' => []
];
}
if ($dayNumber === null || $dayNumber < 1 || $dayNumber > 30) {
continue;
}
// Handle conversion_day which may be comma-separated from GROUP_CONCAT
if ($conversionDay) {
$conversionDaysToAdd = [];
if (is_string($conversionDay) && strpos($conversionDay, ',') !== false) {
// Split comma-separated dates
$conversionDaysToAdd = array_map('trim', explode(',', $conversionDay));
} else {
$conversionDayStr = $conversionDay instanceof \DateTime ? $conversionDay->format('Y-m-d') : (string)$conversionDay;
if ($conversionDayStr) {
$conversionDaysToAdd = [$conversionDayStr];
}
}
// Add unique conversion dates to the array
foreach ($conversionDaysToAdd as $cd) {
if ($cd && is_array($groupedData[$groupKey]['conversion_dates']) && !in_array($cd, $groupedData[$groupKey]['conversion_dates'])) {
$groupedData[$groupKey]['conversion_dates'][] = $cd;
}
}
}
$groupedData[$groupKey]['total_events'] += $eventCount;
$groupedData[$groupKey]['total_unique_users'] += $uniqueUsers;
if (isset($value['clicks_count'])) {
$groupedData[$groupKey]['total_clicks'] += (int)$value['clicks_count'];
} elseif (isset($value['attributedTouchType']) && strtolower($value['attributedTouchType']) === 'click') {
$groupedData[$groupKey]['total_clicks'] += 1;
}
if (isset($value['installs_count'])) {
$groupedData[$groupKey]['total_installs'] += (int)$value['installs_count'];
} elseif (isset($value['conversionType']) && $value['conversionType'] === 'install') {
$groupedData[$groupKey]['total_installs'] += 1;
}
if (!isset($groupedData[$groupKey]['day_data'][$dayNumber])) {
$groupedData[$groupKey]['day_data'][$dayNumber] = [
'users' => 0,
'events' => 0
];
}
$groupedData[$groupKey]['day_data'][$dayNumber]['users'] += $uniqueUsers;
$groupedData[$groupKey]['day_data'][$dayNumber]['events'] += $eventCount;
$groupedData[$groupKey]['base_data'] = array_merge($groupedData[$groupKey]['base_data'], $value);
}
foreach ($groupedData as $key => $value) {
$index = md5($key);
$totalEvents = $value['total_events'];
$dayValues = [];
for ($i = 1; $i <= 30; $i++) {
$userCount = isset($value['day_data'][$i]) ? $value['day_data'][$i]['users'] : 0;
$dayValues["D" . $i] = "{$userCount}";
}
$baseData = [];
$baseValue = $value['base_data'];
$conversionDates = $value['conversion_dates'] ?? [];
$conversionDates = is_array($conversionDates) ? $conversionDates : [];
$dateRange = '';
if (!empty($conversionDates) && is_array($conversionDates)) {
$dateCount = count($conversionDates);
$dateRange = $dateCount > 1 ?
min($conversionDates) . ' to ' . max($conversionDates) :
(string)$conversionDates[0];
} else {
$dateRange = $dateStart . ' to ' . $dateEnd;
}
if (!empty($selectedColumns['publisherID'])) {
$baseData['publisherID'] = $baseValue['mmpPartnerSource'] ?? '';
}
if (!empty($selectedColumns['publisher'])) {
$baseData['publisher'] = $baseValue['publisherName'] ?? '';
}
if (!empty($selectedColumns['advertiserId'])) {
$baseData['advertiserId'] = $baseValue['advertiserId'] ?? '';
}
if (!empty($selectedColumns['advertiserName'])) {
$baseData['advertiserName'] = $baseValue['advertiserName'] ?? '';
}
if (!empty($selectedColumns['appId'])) {
$baseData['appId'] = $baseValue['appId'] ?? '';
}
if (!empty($selectedColumns['appName'])) {
$baseData['appName'] = $baseValue['author'] ?? '';
}
if (!empty($selectedColumns['mmpOfferId'])) {
$baseData['mmpOfferId'] = $baseValue['mmpOfferId'] ?? '';
}
if (!empty($selectedColumns['mmpOffer'])) {
$baseData['mmpOffer'] = $baseValue['mmpOffer'] ?? '';
}
if (!empty($selectedColumns['appsflyerAccount'])) {
$baseData['appsflyerAccount'] = $baseValue['appsflyerAccount'] ?? '';
}
if (!empty($selectedColumns['cohortType'])) {
$baseData['cohortType'] = $baseValue['report_name'] ?? '';
}
if (!empty($selectedColumns['geo'])) {
$baseData['geo'] = $baseValue['geo'] ?? '';
}
if (!empty($selectedColumns['eventsName'])) {
$baseData['eventsName'] = $baseValue['event_name'] ?? '';
}
if (!empty($selectedColumns['clicks'])) {
$baseData['clicks'] = $value['total_clicks'] ?? 0;
}
if (!empty($selectedColumns['installs'])) {
$baseData['installs'] = $value['total_installs'] ?? 0;
}
if (!empty($selectedColumns['events'])) {
$baseData['events'] = $value['total_events'];
}
$baseData['mediaSource'] = $value['media_source'] ?? '';
$baseData['conversionDate'] = $dateRange;
$baseData['attributions'] = $value['total_attributions'];
$baseData['cost'] = 'N/A';
$baseData['AverageeCPI'] = 'N/A';
$finalArr[$index] = array_merge($baseData, $dayValues);
}
if ($downloadDataAsCSV) {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'Retention Report ' . $dateStart . '_' . $dateEnd);
} else {
$data = $this->getPaginatedResponseForRetentionReports(
$finalArr,
$tableColumnsData,
$selectedColumnsData,
$sortBy,
$sortType,
$limit,
$page
);
return new JsonResponse($data);
}
}
public function getPaginatedResponseForRetentionReports($reportData, $tableColumns, $selectedColumns, $sortBy, $sortType, $limit, $page)
{
$reportData = array_values($reportData);
if (sizeof($reportData)) {
$entity = $reportData[0];
if (array_key_exists($sortBy, $entity)) {
$sortFlag = 3;
if ($sortType == Config::SORT_TYPE_ASC) {
$sortFlag = 4;
}
array_multisort(array_column($reportData, $sortBy), $sortFlag, $reportData);
}
}
$offset = $limit * ($page - 1);
$totalRecordCount = sizeof($reportData);
$noOfPages = ceil($totalRecordCount / $limit);
foreach ($tableColumns as $key => $value) {
if (isset($value['aggregate'])) {
if ($value['aggregate'] == 'sum') {
$tableColumns[$key]['Footer'] = number_format(round(array_sum(array_column($reportData, $value['accessor'])), 2));
}
if ($value['aggregate'] == 'average' && count($reportData) > 0) {
$tableColumns[$key]['Footer'] = number_format(round(array_sum(array_column($reportData, $value['accessor'])) / count($reportData), 2));
}
}
}
return [
'response' => [
'success' => true,
'httpStatus' => Config::HTTP_STATUS_CODE_OK,
'data' => [
'tableColumns' => array_values($tableColumns),
'data' => array_slice($reportData, $offset, $limit),
'metaData' => [
'total' => $totalRecordCount,
'limit' => (int)$limit,
'page' => (int)$page,
'pages' => (int)$noOfPages,
]
],
'error' => null
]
];
}
/**
* @Route("/retention-report-old", name="get_retention_report_old", methods={"GET"})
*/
public function getRetentionReportOldAction(Request $request)
{
$filtersSelected = $request->query->get('filters');
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters');
$filters = [];
$excludedFiltersFlags = [];
if (isset($filtersSelected)) {
foreach ($filtersSelected as $key => $value) {
$key === 'MULTISELECT_TUNE_OFFERS' ? $filters['offerId'] = $value : false;
$key === 'MULTISELECT_TUNE_ACCOUNTS' ? $filters['tuneAccount'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $filters['advertiserId'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $filters['affiliateId'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $filters['affiliateCategory'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_SOURCE ? $filters['source'] = $value : false;
}
}
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$value = (int)$value;
$key === 'MULTISELECT_TUNE_OFFERS' ? $excludedFiltersFlags['offerId'] = $value : false;
$key === 'MULTISELECT_TUNE_ACCOUNTS' ? $excludedFiltersFlags['tuneAccount'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $excludedFiltersFlags['advertiserId'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $excludedFiltersFlags['affiliateId'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $excludedFiltersFlags['affiliateCategory'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_SOURCE ? $excludedFiltersFlags['source'] = $value : false;
}
}
$dateStart = date('Y-m-d', strtotime($request->query->get('startDate')));
$dateEnd = date('Y-m-d', strtotime($request->query->get('endDate')));
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1 ? true : false;
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_MMP_REPORT_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$page = $request->query->get('currentPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$limit = $request->query->get('perPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$data = [];
$transactionIds = [];
if (!isset($filters['offerId'])) {
return new JsonResponse([]);
}
$apiPage = 1;
$apiLimit = 100000;
foreach (Config::MAFO_SYSTEM_IDENTIFIER_TUNE_ACCOUNTS as $tuneAccount) {
if (isset($filters['tuneAccount']) && !in_array($tuneAccount, $filters['tuneAccount'])) {
continue;
}
$data = [];
$hoApiResponse = $this->brandHasofferApi->getStatsForRetentionReport([], [], $filters['offerId'], [], [], true, $dateStart, $dateEnd, $apiPage, $apiLimit, $filters['tuneAccount']);
while ($hoApiResponse['response']['data']['data']) {
$data = array_values(array_merge($data, $hoApiResponse['response']['data']['data']));
$apiPage += 1;
$hoApiResponse = $this->brandHasofferApi->getStatsForRetentionReport([], [], $filters['offerId'], [], [], true, $dateStart, $dateEnd, $apiPage, $apiLimit, $filters['tuneAccount']);
}
$distinctOfferIds = [];
$affiliateCategoriesByAffiliateId = $this->commonCalls->getAffiliateCategoryByAffiliateId();
$retentionReportData = [];
$finalArr = [];
foreach ($data as $key => $value) {
if (
$value['Stat']['goal_id'] == Config::INSTALL_GOAL_ID
) {
$index = md5($value['Stat']['affiliate_id'] . '#' . $value['Stat']['offer_id'] . '#' . $value['Stat']['source'] . '#' . $value['Stat']['ad_id']);
if (!array_key_exists($index, $retentionReportData)) {
$retentionReportData[$index] = [
'affiliateId' => $value['Stat']['affiliate_id'],
'affiliateName' => '',
'offerId' => $value['Stat']['offer_id'],
'offerName' => '',
'source' => $value['Stat']['source'],
'advertiserId' => $value['Stat']['advertiser_id'],
'advertiserName' => '',
'transactionId' => $value['Stat']['ad_id'],
'installConversions' => 0,
'goalConversions' => 0,
'retentionPercentage' => 0,
'goalInfo' => []
];
}
!in_array($value['Stat']['ad_id'], $transactionIds) ? array_push($transactionIds, $value['Stat']['ad_id']) : false;
$retentionReportData[$index]['installConversions'] += 1;
!in_array($value['Stat']['offer_id'], $distinctOfferIds) ? array_push($distinctOfferIds, $value['Stat']['offer_id']) : false;
}
}
foreach ($data as $key => $value) {
$index = md5($value['Stat']['affiliate_id'] . '#' . $value['Stat']['offer_id'] . '#' . $value['Stat']['source'] . '#' . $value['Stat']['ad_id'] . '#' . $tuneAccount);
if (array_key_exists($index, $retentionReportData) && $value['Stat']['goal_id'] != Config::INSTALL_GOAL_ID) {
$retentionReportData[$index]['goalInfo'][] = [
'transactionId' => $value['Stat']['ad_id'],
'goalId' => $value['Stat']['goal_id'],
'goalName' => $value['Goal']['name'] ?? '',
];
$retentionReportData[$index]['goalConversions'] += 1;
}
}
foreach ($retentionReportData as $key => $value) {
$index = md5($value['affiliateId'] . '#' . $value['offerId'] . '#' . $value['advertiserId'] . '#' . $tuneAccount);
if (!array_key_exists($index, $finalArr)) {
$finalArr[$index] = [
'affiliateId' => $value['affiliateId'],
'affiliateName' => '',
'affiliateCategory' => array_key_Exists($value['affiliateId'], $affiliateCategoriesByAffiliateId) ? $affiliateCategoriesByAffiliateId[$value['affiliateId']]['category'] : Config::HASOFFER_AFFILIATE_CATEGORY_UNCATEGORISED_TAG_NAME,
'offerId' => $value['offerId'],
'offerName' => '',
'source' => $value['source'],
'advertiserId' => $value['advertiserId'],
'advertiserName' => '',
'installConversions' => 0,
'goalConversions' => 0,
'retentionPercentage' => 0,
'goalInfo' => []
];
foreach ($filters as $k => $v) {
if (
array_key_exists($k, $finalArr[$index]) &&
(
(
in_array($finalArr[$index][$k], $v) &&
$excludedFiltersFlags[$k]
) ||
(
!in_array($finalArr[$index][$k], $v) &&
!$excludedFiltersFlags[$k]
)
)
) {
unset($finalArr[$index]);
continue 2;
}
}
}
$finalArr[$index]['installConversions'] += $value['installConversions'];
$finalArr[$index]['goalConversions'] += $value['goalConversions'];
$finalArr[$index]['tuneAccount'] = $value['tuneAccount'];
// foreach ($value['goalInfo'] as $k => $v) {
//
// if (!array_key_exists($v['goalId'], $finalArr[$index]['goalInfo'])) {
// $finalArr[$index]['goalInfo'][$v['goalId']] = [
// 'goalId' => $v['goalId'],
// 'goalName' => $v['goalName'],
// 'conversions' => 0,
// ];
// }
//
// $finalArr[$index]['goalInfo'][$v['goalId']]['conversions'] += 1;
// }
}
$offerInfo = [];
$distinctOfferIds ? $offerInfo = $this->commonCalls->getOfferInfoByKey($distinctOfferIds) : false;
$advertiserList = $this->commonCalls->getAdvertisersListByStatusWithKeys([
'tuneAccount' => $tuneAccount
]);
$affiliateList = $this->commonCalls->getAffiliateListByStatusWithKeys($tuneAccount);
foreach ($finalArr as $key => $value) {
array_key_exists($value['offerId'], $offerInfo) ? $finalArr[$key]['offerName'] = $offerInfo[$value['offerId']]['name'] : false;
array_key_exists($value['advertiserId'], $advertiserList) ? $finalArr[$key]['advertiserName'] = $advertiserList[$value['advertiserId']]['name'] : false;
array_key_exists($value['affiliateId'], $affiliateList) ? $finalArr[$key]['affiliateName'] = $affiliateList[$value['affiliateId']]['name'] : false;
$finalArr[$key]['goalInfo'] = array_values($value['goalInfo']);
$value['goalConversions'] > 0 && $value['installConversions'] > 0 ? $finalArr[$key]['retentionPercentage'] = round((($value['goalConversions'] / $value['installConversions']) * 100), 2) : false;
}
}
// echo json_encode($finalArr);die;
$tableColumns = $this->commonCalls->getDataFromJsonFile(Config::TABLE_COLUMNS_WITH_JSON_FILE[Config::RETENTION_REPORT]);
$finalArr = $this->commonCalls->getReportsRowWiseDataByAggregation($tableColumns, $selectedColumns, $finalArr);
if ($downloadDataAsCSV) {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'Retention Report ' . $dateStart . '_' . $dateEnd);
} else {
return new JsonResponse($this->commonCalls->getPaginatedResponseForReports($finalArr, $tableColumns, $selectedColumns, $sortBy, $sortType, $limit, $page));
}
}
/**
* @Route("/am-side-fraud-report", name="get_fraud_report_am_side", methods={"GET"})
*/
public function getFraudReportAmSideAction(Request $request)
{
$filtersSelected = $request->query->get('filters');
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters');
$filters = [];
$excludedFiltersFlags = [];
if (isset($filtersSelected)) {
foreach ($filtersSelected as $key => $value) {
$key === Config::MULTISELECT_MMP_TUNE_OFFERS ? $filters['offerId'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $filters['advertiserId'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $filters['affiliateId'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $filters['affiliateCategory'] = $value : false;
}
}
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$value = (int)$value;
$key === Config::MULTISELECT_MMP_TUNE_OFFERS ? $excludedFiltersFlags['offerId'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $excludedFiltersFlags['advertiserId'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $excludedFiltersFlags['affiliateId'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $excludedFiltersFlags['affiliateCategory'] = $value : false;
}
}
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$groupedColumns = $request->query->get('groups') != '' ? $request->query->get('groups') : [];
$dateStart = date('Y-m-d', strtotime($request->query->get('startDate')));
$dateEnd = date('Y-m-d', strtotime($request->query->get('endDate')));
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_MMP_REPORT_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$page = $request->query->get('currentPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$limit = $request->query->get('perPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1 ? true : false;
$affiliateCategoriesByAffiliateId = $this->commonCalls->getAffiliateCategoryByAffiliateId();
$groups = ['partner', 'affiliate', 'product'];
$data = $this->metrics24APICalls->getFraudReport($groups, [], [], [], [], [], $dateStart, $dateEnd);
$distinctOfferIds = [];
$hoConversionData = [];
$fraudData = [];
foreach ($data as $key => $value) {
$index = $value['product'] . '#' . $value['affiliate'];
if (!array_key_exists($index, $fraudData)) {
$fraudData[$index] = [
'offerId' => $value['product'],
'offerName' => $value['product_label'],
'affiliateId' => $value['affiliate'],
'affiliateName' => $value['affiliate_label'],
'affiliateCategory' => array_key_Exists($value['affiliate'], $affiliateCategoriesByAffiliateId) ? $affiliateCategoriesByAffiliateId[$value['affiliate']]['category'] : Config::HASOFFER_AFFILIATE_CATEGORY_UNCATEGORISED_TAG_NAME,
'advertiserId' => $value['partner'],
'advertiserName' => $value['partner_label'],
'totalConversions' => 0,
'approvedConversions' => 0,
'rejectedConversions' => 0,
'rejectionRate' => 0,
'approvalRate' => 0,
'tuneTotalConversions' => 0,
'nonEmptyAdvSub1' => 0
];
}
foreach ($filters as $k => $v) {
if (
array_key_exists($k, $fraudData[$index]) &&
(
(
in_array($fraudData[$index][$k], $v) &&
$excludedFiltersFlags[$k]
) ||
(
!in_array($fraudData[$index][$k], $v) &&
!$excludedFiltersFlags[$k]
)
)
) {
unset($fraudData[$index]);
continue 2;
}
}
$fraudData[$index]['totalConversions'] += $value['conversion'];
$fraudData[$index]['approvedConversions'] += $value['approved'];
$fraudData[$index]['rejectedConversions'] += $value['rejected'];
!in_array($value['product'], $distinctOfferIds) ? array_push($distinctOfferIds, $value['product']) : false;
}
if ($distinctOfferIds) {
$apiPage = 1;
$apiLimit = 100000;
$hoApiResponse = $this->brandHasofferApi->getStatsForFraudReport([], $distinctOfferIds, $dateStart, $dateEnd, $apiPage, $apiLimit);
while ($hoApiResponse['response']['data']['data']) {
foreach ($hoApiResponse['response']['data']['data'] as $key => $value) {
$index = $value['Stat']['offer_id'] . '#' . $value['Stat']['affiliate_id'];
if (array_key_exists($index, $fraudData)) {
$fraudData[$index]['tuneTotalConversions'] += 1;
if ($value['Stat']['advertiser_info'] != '') {
$fraudData[$index]['nonEmptyAdvSub1'] += 1;
}
}
}
$apiPage += 1;
$hoApiResponse = $this->brandHasofferApi->getStatsForFraudReport([], $distinctOfferIds, $dateStart, $dateEnd, $apiPage, $apiLimit);
}
}
$tableColumns = $this->commonCalls->getDataFromJsonFile(Config::TABLE_COLUMNS_WITH_JSON_FILE[Config::AM_SIDE_FRAUD_REPORT]);
$finalArr = $this->commonCalls->getReportsRowWiseDataByAggregation($tableColumns, $selectedColumns, $fraudData);
foreach ($finalArr as $key => $value) {
if ($value['totalConversions'] > 0) {
$finalArr[$key]['rejectionPercentage'] = round((($value['rejectedConversions'] / $value['totalConversions']) * 100), 2);
$finalArr[$key]['approvalPercentage'] = round((($value['approvedConversions'] / $value['totalConversions']) * 100), 2);
}
}
if ($downloadDataAsCSV) {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'AM Side Fraud Report ' . $dateStart . '_' . $dateEnd);
} else {
return new JsonResponse($this->commonCalls->getPaginatedResponseForReports($finalArr, $tableColumns, $selectedColumns, $sortBy, $sortType, $limit, $page));
}
}
/**
* @Route("/pm-side-fraud-report", name="get_fraud_report_pm_side", methods={"GET"})
*/
public function getFraudReportPmSideAction(Request $request)
{
$filtersSelected = $request->query->get('filters');
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters');
$filters = [];
$excludedFiltersFlags = [];
if (isset($filtersSelected)) {
foreach ($filtersSelected as $key => $value) {
$key === Config::MULTISELECT_MMP_OFFERS ? $filters['offerId'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $filters['affiliateId'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $filters['affiliateCategory'] = $value : false;
}
}
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$value = (int)$value;
$key === Config::MULTISELECT_MMP_OFFERS ? $excludedFiltersFlags['offerId'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $excludedFiltersFlags['affiliateId'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $excludedFiltersFlags['affiliateCategory'] = $value : false;
}
}
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$groupedColumns = $request->query->get('groups') != '' ? $request->query->get('groups') : [];
$dateStart = date('Y-m-d', strtotime($request->query->get('startDate')));
$dateEnd = date('Y-m-d', strtotime($request->query->get('endDate')));
$eventTimestampFrom = strtotime($dateStart);
$eventTimeStampTo = strtotime($dateEnd);
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_MMP_REPORT_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$page = $request->query->get('currentPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$limit = $request->query->get('perPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$subIds = $request->query->get('subIds') != '' ? $request->query->get('subIds') : [];
$offerIds = $request->query->get('offerIds') != '' ? $request->query->get('offerIds') : [];
$affiliateIds = $request->query->get('affiliateIds') != '' ? $request->query->get('affiliateIds') : [];
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1 ? true : false;
$groups = ['sub_id', 'affiliate', 'product'];
$data = $this->metrics24APICalls->getFraudReport($groups, $affiliateIds, $subIds, [], $offerIds, [], $dateStart, $dateEnd);
$affiliateCategoriesByAffiliateId = $this->commonCalls->getAffiliateCategoryByAffiliateId();
$fraudData = [];
$distinctOfferIds = [];
$hoConversionData = [];
foreach ($data as $key => $value) {
$index = $value['product'] . '#' . $value['affiliate'] . '#' . $value['sub_id'];
if (!array_key_exists($index, $fraudData)) {
$fraudData[$index] = [
'offerId' => $value['product'],
'offerName' => $value['product_label'],
'affiliateId' => $value['affiliate'],
'affiliateName' => $value['affiliate_label'],
'affiliateCategory' => array_key_Exists($value['affiliate'], $affiliateCategoriesByAffiliateId) ? $affiliateCategoriesByAffiliateId[$value['affiliate']]['category'] : Config::HASOFFER_AFFILIATE_CATEGORY_UNCATEGORISED_TAG_NAME,
'source' => $value['sub_id'],
'totalConversions' => 0,
'approvedConversions' => 0,
'rejectedConversions' => 0,
'rejectionPercentage' => 0,
'approvalPercentage' => 0,
'tuneTotalConversions' => 0,
'nonEmptyAdvSub1' => 0,
];
}
foreach ($filters as $k => $v) {
if (
array_key_exists($k, $fraudData[$index]) &&
(
(
in_array($fraudData[$index][$k], $v) &&
$excludedFlagForFilters[$k]
) ||
(
!in_array($fraudData[$index][$k], $v) &&
!$excludedFlagForFilters[$k]
)
)
) {
unset($fraudData[$index]);
continue 2;
}
}
$fraudData[$index]['totalConversions'] += $value['conversion'];
$fraudData[$index]['approvedConversions'] += $value['approved'];
$fraudData[$index]['rejectedConversions'] += $value['rejected'];
!in_array($value['product'], $distinctOfferIds) ? array_push($distinctOfferIds, $value['product']) : false;
}
if ($distinctOfferIds) {
$apiPage = 1;
$apiLimit = 100000;
$hoApiResponse = $this->brandHasofferApi->getStatsForFraudReport([], $distinctOfferIds, $dateStart, $dateEnd, $apiPage, $apiLimit);
while ($hoApiResponse['response']['data']['data']) {
foreach ($hoApiResponse['response']['data']['data'] as $key => $value) {
$index = $value['Stat']['offer_id'] . '#' . $value['Stat']['affiliate_id'] . '#' . $value['Stat']['source'];
if (array_key_exists($index, $fraudData)) {
$fraudData[$index]['tuneTotalConversions'] += 1;
if ($value['Stat']['advertiser_info'] != '') {
$fraudData[$index]['nonEmptyAdvSub1'] += 1;
}
}
}
$apiPage += 1;
$hoApiResponse = $this->brandHasofferApi->getStatsForFraudReport([], $distinctOfferIds, $dateStart, $dateEnd, $apiPage, $apiLimit);
}
}
$tableColumns = $this->commonCalls->getDataFromJsonFile(Config::TABLE_COLUMNS_WITH_JSON_FILE[Config::PM_SIDE_FRAUD_REPORT]);
$finalArr = $this->commonCalls->getReportsRowWiseDataByAggregation($tableColumns, $selectedColumns, $fraudData);
foreach ($fraudData as $key => $value) {
if ($value['totalConversions'] > 0) {
$fraudData[$key]['rejectionPercentage'] = round((($value['rejectedConversions'] / $value['totalConversions']) * 100), 2);
$fraudData[$key]['approvalPercentage'] = round((($value['approvedConversions'] / $value['totalConversions']) * 100), 2);
}
}
if ($downloadDataAsCSV) {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'PM Side Fraud Report ' . $dateStart . '_' . $dateEnd);
} else {
return new JsonResponse($this->commonCalls->getPaginatedResponseForReports($finalArr, $tableColumns, $selectedColumns, $sortBy, $sortType, $limit, $page));
}
}
/**
* @Route("/skad-conversions", name="get_skad_conversions", methods={"GET"})
*/
public function getSkadConversionsAction(Request $request)
{
$dateStart = date('Y-m-d', strtotime($request->query->get('dateStart')));
$dateEnd = date('Y-m-d', strtotime($request->query->get('dateEnd')));
$advertiserIds = $request->query->get('advertiserIds') != '' ? $request->query->get('advertiserIds') : [];
$offerIds = $request->query->get('offerIds') != '' ? $request->query->get('offerIds') : [];
$affiliateIds = $request->query->get('affiliateIds') != '' ? $request->query->get('affiliateIds') : [];
$subIds = $request->query->get('subIds') != '' ? $request->query->get('subIds') : [];
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1 ? true : false;
$data = [];
$page = 1;
$limit = 100000;
$hoApiResponse = $this->brandHasofferApi->getStatsForSkadConversions($affiliateIds, $advertiserIds, $offerIds, $subIds, $dateStart, $dateEnd, $limit, $page);
while ($hoApiResponse['response']['data']['data']) {
$data = array_values(array_merge($data, $hoApiResponse['response']['data']['data']));
$page += 1;
$hoApiResponse = $this->brandHasofferApi->getStatsForSkadConversions($affiliateIds, $advertiserIds, $offerIds, $subIds, $dateStart, $dateEnd, $limit, $page);
}
$skadAppIds = [];
$skadNetworkPostbackData = $this->doctrine->getRepository('App\Entity\SkadNetworkPostbackLogs')->getSkadNetworkPostbackData();
foreach ($skadNetworkPostbackData as $key => $value) {
if (!in_array($value['appId'], $skadAppIds)) {
array_push($skadAppIds, $value['appId']);
}
}
$distinctOfferIds = $report = [];
foreach ($data as $key => $value) {
if ($value['Stat']['affiliate_info5'] !== '' && in_array($skadAppIds, $value['Stat']['affiliate_info5'])) {
$index = md5($value['Stat']['affiliate_id'] . '#' . $value['Stat']['offer_id'] . '#' . $value['Stat']['source']);
if (!array_key_exists($index, $report)) {
$report[$index] = [
'affiliateId' => $value['Stat']['affiliate_id'],
'affiliateName' => '',
'offerId' => $value['Stat']['offer_id'],
'offerName' => '',
'source' => $value['Stat']['source'],
'advertiserId' => $value['Stat']['advertiser_id'],
'advertiserName' => '',
'conversions' => 0,
'clicks' => 0,
];
!in_array($value['Stat']['offer_id'], $distinctOfferIds) ? array_push($distinctOfferIds, $value['Stat']['offer_id']) : false;
}
$report[$index]['conversions'] += $value['Stat']['conversions'];
$report[$index]['clicks'] += $value['Stat']['clicks'];
}
}
$offerInfo = [];
$distinctOfferIds ? $offerInfo = $this->commonCalls->getOfferInfoByKey($distinctOfferIds) : false;
$advertiserList = $this->commonCalls->getAdvertisersListByStatusWithKeys();
$affiliateList = $this->commonCalls->getAffiliateListByStatusWithKeys();
foreach ($report as $key => $value) {
array_key_exists($value['advertiserId'], $advertiserList) ? $report[$key]['advertiserName'] = $advertiserList[$value['advertiserId']]['name'] : false;
array_key_exists($value['affiliateId'], $affiliateList) ? $report[$key]['affiliateName'] = $affiliateList[$value['affiliateId']]['name'] : false;
if (array_key_exists($value['offerId'], $offerInfo)) {
$report[$key]['offerName'] = $offerInfo[$value['offerId']]['name'];
}
}
$report = array_values($report);
array_multisort(array_column($report, 'conversions'), SORT_DESC, $report);
if ($downloadDataAsCSV) {
$header = [
'Offer Id',
'Offer Name',
'Advertiser Id',
'Advertiser Name',
'Affiliate Id',
'Affiliate Name',
'Source',
'Conversions',
'Clicks',
];
$rows = [$header];
foreach ($report as $key => $value) {
$rows[] = [
$value['offerId'],
$value['offerName'],
$value['advertiserId'],
$value['advertiserName'],
$value['affiliateId'],
$value['affiliateName'],
$value['source'],
$value['conversions'],
$value['clicks'],
];
}
$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()->setCreator('MAFO')
->setLastModifiedBy('MAFO')
->setTitle('SKAD Conversions Report')
->setSubject('SKAD Conversions Report')
->setDescription('SKAD Conversions Report');
$spreadsheet->getActiveSheet()
->fromArray(
$rows,
NULL,
'A1'
);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="skad-conversions-report' . $dateStart . '_' . $dateEnd . '.xls"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('php://output');
exit;
} else {
return new JsonResponse($report);
}
}
/**
* @Route("/mmp-report", name="get_mmp_report", methods={"GET"})
*/
public function getMmpReportAction(Request $request)
{
// ini_set('max_execution_time', '300');
// ini_set('max_input_time', '300');
// ini_set('default_socket_timeout', '300');
$filtersSelected = $request->query->get('filters');
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters');
$filters = [];
$excludedFiltersFlags = [];
if (isset($filtersSelected)) {
foreach ($filtersSelected as $key => $value) {
$key === Config::MULTISELECT_MMP_STATISTICS_APP ? $filters['appIds'] = $value : false;
$key === Config::MULTISELECT_MMP_OFFERS ? $filters['offers'] = $value : false;
$key === Config::MULTISELECT_MMP_SOURCE_GLOBAL_NETWORK_REPORT ? $filters['mmpSource'] = $value : false;
$key === Config::MULTISELECT_MMP_PARTNERS ? $filters['affiliates'] = $value : false;
$key === Config::MULTISELECT_MMP_MAKER_OF_OFFER_RULE_IN_MMP_OFFERS ? $filters['users'] = $value : false;
$key === Config::MULTISELECT_GEO ? $filters['geos'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $filters['advertiserIds'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $filters['hoAffiliateIds'] = $value : false;
$key === Config::MULTISELECT_MMP_EVENTS ? $filters['events'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_OFFERS ? $filters['hoOfferIds'] = $value : false;
$key === Config::MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS ? $filters['advertiserManagerEmailIds'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS ? $filters['affiliateManagerEmailIds'] = $value : false;
$key === Config::MULTISELECT_ADVERTISER_MOBUPPS_TEAM ? $filters['advertiserMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MOBUPPS_TEAM ? $filters['affiliateMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $filters['affiliateCategories'] = $value : false;
}
}
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$value = (int)$value;
$key === Config::MULTISELECT_MMP_STATISTICS_APP ? $excludedFiltersFlags['appIds'] = $value : false;
$key === Config::MULTISELECT_MMP_OFFERS ? $excludedFiltersFlags['offers'] = $value : false;
$key === Config::MULTISELECT_MMP_SOURCE_GLOBAL_NETWORK_REPORT ? $excludedFiltersFlags['mmpSource'] = $value : false;
$key === Config::MULTISELECT_MMP_PARTNERS_FOR_MMP_REPORT ? $excludedFiltersFlags['affiliates'] = $value : false;
$key === Config::MULTISELECT_MMP_MAKER_OF_OFFER_RULE_IN_MMP_OFFERS ? $excludedFiltersFlags['users'] = $value : false;
$key === Config::MULTISELECT_GEO ? $excludedFiltersFlags['geos'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $excludedFiltersFlags['advertiserIds'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $excludedFiltersFlags['hoAffiliateIds'] = $value : false;
$key === Config::MULTISELECT_MMP_EVENTS ? $excludedFiltersFlags['events'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_OFFERS ? $excludedFiltersFlags['hoOfferIds'] = $value : false;
$key === Config::MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS ? $excludedFiltersFlags['advertiserManagerEmailIds'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS ? $excludedFiltersFlags['affiliateManagerEmailIds'] = $value : false;
$key === Config::MULTISELECT_ADVERTISER_MOBUPPS_TEAM ? $excludedFiltersFlags['advertiserMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MOBUPPS_TEAM ? $excludedFiltersFlags['affiliateMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $excludedFiltersFlags['affiliateCategories'] = $value : false;
}
}
if ($request->query->get('reportName') && $request->query->get('reportName') === Config::MMP_REPORT) {
if (!isset($filters['mmpSource'])) {
$filters['mmpSource'] = [...Config::ACTIVE_APPSFLYER_ACCOUNTS, Config::MMP_TRACKING_SYSTEM_ADJUST];
}
if (isset($excludedFiltersFlags['mmpSource']) && $excludedFiltersFlags['mmpSource']) {
$filters['mmpSource'][] = Config::MMP_TRACKING_SYSTEM_TUNE;
}
}
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$groupedColumns = $request->query->get('groups') != '' ? $request->query->get('groups') : [];
$dateStart = $request->query->get('startDate');
$dateEnd = $request->query->get('endDate');
$eventTimestampFrom = strtotime($dateStart);
$eventTimeStampTo = strtotime($dateEnd);
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_MMP_REPORT_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$page = $request->query->get('currentPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$limit = $request->query->get('perPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1;
$finalReportData = [];
if ($eventTimeStampTo - $eventTimestampFrom < 45 * 24 * 60 * 60) {
$finalReportData = $this->mmpComponents->getMmpCumulativeData($filters, $excludedFiltersFlags, $eventTimestampFrom, $eventTimeStampTo, $selectedColumns, $groupedColumns);
}
$totalPayout = 0;
$totalRevenue = 0;
$totalProfit = 0;
foreach ($finalReportData as $key => $value) {
isset($value['totalPayout']) ? $totalPayout += $value['totalPayout'] : false;
isset($value['profit']) ? $totalProfit += $value['profit'] : false;
}
$totalPayout = round($totalPayout, 2);
$totalRevenue = round($totalRevenue, 2);
$totalProfit = round($totalProfit, 2);
$footerArr = [
'totalPayout' => $totalPayout,
'profit' => $totalProfit,
];
$showFraudData = sizeof(
array_intersect(
array_values(
array_diff(
array_column($this->commonCalls->getDataFromJsonFile(Config::TABLE_COLUMNS_WITH_JSON_FILE[Config::MMP_FRAUD_REPORT]), 'accessor'),
array_column(array_values(Config::REPORT_COLUMN_MAPPING[Config::REPORT_MMP_MACRO]), 'accessor')
)
),
array_keys($selectedColumns)
)
);
$tableColumns = Config::REPORT_MMP_STATISTICS_COLUMNS;
if ($showFraudData) {
$tableColumns = $this->commonCalls->getDataFromJsonFile(Config::TABLE_COLUMNS_WITH_JSON_FILE[Config::MMP_FRAUD_REPORT]);
}
foreach ($tableColumns as $key => $value) {
$tableColumns[$key]['show'] = false;
foreach ($selectedColumns as $k => $v) {
if ($value['accessor'] === $k && $v !== 'undefined') {
$tableColumns[$key]['show'] = $v == '0' ? false : true;
break;
}
}
foreach ($groupedColumns as $k => $v) {
if ($value['accessor'] === $k && $v !== 'undefined') {
$tableColumns[$key]['groupBy'] = !($v == '0');
!($v == '0') ? $tableColumns[$key]['show'] = true : null;
break;
}
}
if (in_array($value['accessor'], array_keys($footerArr))) {
$tableColumns[$key]['Footer'] = $footerArr[$value['accessor']];
}
}
if ($downloadDataAsCSV) {
$header = [];
foreach ($tableColumns as $key => $value) {
if ($value['show'] == 1) {
array_push($header, $value['header']);
}
}
$rows = [$header];
foreach ($finalReportData as $key => $value) {
$row = [];
foreach ($tableColumns as $k => $v) {
if ($v['show'] == 1) {
array_push($row, $value[$v['accessor']]);
}
}
$rows[] = $row;
}
$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()->setCreator('MAFO')->setLastModifiedBy('MAFO')->setTitle('Mmp Statistics Report')->setSubject('Mmp Statistics')->setDescription('Mmp Statistics');
$spreadsheet->getActiveSheet()->fromArray($rows, null, 'A1');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="mmp statistics ' . $dateStart . '_' . $dateEnd . '.xls"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('php://output');
exit;
} else {
$finalReportData = array_values($finalReportData);
if (sizeof($finalReportData)) {
$entity = $finalReportData[0];
if (array_key_exists($sortBy, $entity)) {
$sortFlag = 3;
if ($sortType == Config::SORT_TYPE_ASC) {
$sortFlag = 4;
}
array_multisort(array_column($finalReportData, $sortBy), $sortFlag, $finalReportData);
}
}
$offset = $limit * ($page - 1);
$totalRecordCount = sizeof($finalReportData);
$noOfPages = ceil($totalRecordCount / $limit);
return new JsonResponse([
'response' => [
'success' => true,
'httpStatus' => Config::HTTP_STATUS_CODE_OK,
'data' => [
'tableColumns' => $tableColumns,
'data' => array_slice($finalReportData, $offset, $limit),
'metaData' => [
'total' => $totalRecordCount,
'limit' => (int)$limit,
'page' => (int)$page,
'pages' => (int)$noOfPages,
]
],
'error' => null
]
], Config::HTTP_STATUS_CODE_OK);
}
}
/**
* @Route("/advertiser-report", name="get_advertiser_report", methods={"GET"})
*/
public function getAdvertiserReportAction(Request $request)
{
$fields = $filters = [];
$sortBy = $request->query->get('sortBy') ?? 'Stat##clicks';
$sortType = $request->query->get('sortType') ?? Config::DATABASE_OFFERS_DEFAULT_SORT_TYPE;
$page = $request->query->get('currentPage') ?? Config::DATABASE_OFFERS_DEFAULT_PAGE_NUMBER;
$limit = $request->query->get('perPage') ?? Config::DATABASE_OFFERS_DEFAULT_PAGE_SIZE;
$fieldsRaw = $request->query->get('data') ?? [];
$filtersRaw = $request->query->get('filters') ?? [];
$hourOffset = $this->commonCalls->getHourOffsetFromTimezoneString($request->query->get('timezone'));
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters') ?? [];
$startDate = date('Y-m-d', strtotime($request->query->get('startDate')));
$endDate = date('Y-m-d', strtotime($request->query->get('endDate')));
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1 ? true : false;
foreach ($fieldsRaw as $key => $value) {
if ($value == 1) {
array_push($fields, str_replace(Config::REPORT_ADVERTISER_ACCESSOR_SEPARATOR, '.', $key));
}
}
foreach ($filtersRaw as $key => $value) {
$filters[$key] = [
'conditional' => array_key_exists($key, $excludedFlagForFilters) ? $excludedFlagForFilters[$key] == 1 ? 'NOT_EQUAL_TO' : 'EQUAL_TO' : 'EQUAL_TO',
'values' => str_replace(Config::REPORT_ADVERTISER_ACCESSOR_SEPARATOR, '.', $value),
];
}
$filters['Stat.date'] = [
'conditional' => 'BETWEEN',
'values' => [$startDate, $endDate]
];
$sort = [str_replace(Config::REPORT_ADVERTISER_ACCESSOR_SEPARATOR, '.', $sortBy) => $sortType];
$hoStatsData = $this->brandHasofferApi->getStatsForAdvertiserReport($fields, $filters, $startDate, $endDate, $limit, $page, $sort, $hourOffset);
$error = null;
$statsData = $metaData = $col = [];
$savedCols = Config::REPORT_ADVERTISER_COLUMNS;
foreach ($savedCols as $key => $value) {
$value['accessor'] = str_replace(".", '##', $value['accessor']);
$col[] = $value;
}
if ($hoStatsData['response']['status'] === 1) {
$metaData = [
'total' => $hoStatsData['response']['data']['count'],
'limit' => $hoStatsData['response']['data']['current'],
'page' => $hoStatsData['response']['data']['page'],
'pages' => $hoStatsData['response']['data']['pageCount'],
];
$hoStatsData = $hoStatsData['response']['data']['data'];
foreach ($hoStatsData as $key => $value) {
$temp = [];
foreach ($value as $kk => $vv) {
foreach ($vv as $k => $v) {
if ($this->commonCalls->checkForString($k, '@')) {
$k = explode('@', $k)[0];
}
if (array_key_exists('decimal', $savedCols[$kk . '.' . $k])) {
$v = round($v, $savedCols[$kk . '.' . $k]['decimal']);
}
$temp[$kk . '##' . $k] = $v;
}
}
if ($temp) {
$statsData[] = $temp;
}
}
} else {
$error = $hoStatsData['response']['errorMessage'];
}
foreach ($col as $key => $value) {
$col[$key]['show'] = false;
foreach ($fieldsRaw as $k => $v) {
if ($value['accessor'] === $k && $v !== 'undefined') {
$col[$key]['show'] = $v == '0' ? false : true;
break;
}
}
}
if ($downloadDataAsCSV) {
$header = [];
foreach ($col as $key => $value) {
if ($value['show'] === true) {
$header[$value['accessor']] = $value['Header'];
// array_push($header, $value['Header']);
}
}
$rows = [array_values($header)];
foreach ($statsData as $key => $value) {
$temp = [];
foreach ($header as $k => $v) {
$temp[$k] = $value[$k];
}
$rows[] = array_values($temp);
}
$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()->setCreator('MAFO')
->setLastModifiedBy('MAFO')->setTitle('Advertiser Report')->setSubject('Advertiser Report')->setDescription('Advertiser Report');
$spreadsheet->getActiveSheet()->fromArray($rows, null, 'A1');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="advertiser-report ' . $startDate . '_' . $endDate . '.xls"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('php://output');
exit;
} else {
return new JsonResponse([
'response' => [
'success' => true,
'httpStatus' => Config::HTTP_STATUS_CODE_OK,
'data' => [
'tableColumns' => $col,
'data' => $statsData,
'metaData' => $metaData
],
'error' => $error
]
], Config::HTTP_STATUS_CODE_OK);
}
}
/**
* @Route("/deduction-insights", name="get_deduction_insights", methods={"GET"})
*/
public function getDeductionInsightsAction(Request $request)
{
$filters = $request->query->get('filters') ?? [];
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters') ?? [];
$startDate = date('Y-m-1', strtotime('-0 month', strtotime($request->query->get('startDate'))));
$endDate = date('Y-m-1', strtotime('+0 month ', strtotime($request->query->get('endDate'))));
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$groupedColumns = $request->query->get('groups') != '' ? $request->query->get('groups') : [];
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1;
$affiliateIds = $affiliateManagerIds = $activitySources = $statuses = $affiliateCategories = [];
if (isset($filters)) {
foreach ($filters as $key => $value) {
$key === Config::MULTISELECT_AFFILIATES ? $affiliateIds = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MANAGERS ? $affiliateManagerIds = $value : false;
$key === Config::MULTISELECT_DEDUCTION_CONTROL_ACTIVITY_SOURCE ? $activitySources = $value : false;
$key === Config::MULTISELECT_DEDUCTION_CONTROL_STATUSES ? $statuses = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $affiliateCategories = $value : false;
}
}
$affiliateIdsExcluded = $affiliateManagerIdsExcluded = $activitySourcesExcluded = $statusesExcluded = $affiliateCategoriesExcluded = false;
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$key === Config::MULTISELECT_AFFILIATES ? $affiliateIdsExcluded = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MANAGERS ? $affiliateManagerIdsExcluded = $value : false;
$key === Config::MULTISELECT_DEDUCTION_CONTROL_ACTIVITY_SOURCE ? $activitySourcesExcluded = $value : false;
$key === Config::MULTISELECT_DEDUCTION_CONTROL_STATUSES ? $statusesExcluded = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $affiliateCategoriesExcluded = $value : false;
}
}
$tempAffiliateIds = [];
if ($affiliateManagerIds) {
$accountManagerData = $this->doctrine->getRepository(AffiliateAccountManager::class)->getAccountManagerDataByIdsWithExcludedCondition($affiliateManagerIds, $affiliateManagerIdsExcluded);
foreach ($accountManagerData as $key => $value) {
$tempAffiliateIds[] = $value['affiliateId'];
}
}
if ($tempAffiliateIds && $affiliateIds) {
$tempAffiliateIds = array_values(array_unique($tempAffiliateIds));
$affiliateIds = array_values(array_intersect($affiliateIds, $tempAffiliateIds));
} elseif ($tempAffiliateIds && !$affiliateIds) {
$affiliateIds = $tempAffiliateIds;
}
$affiliateList = $this->commonCalls->getAffiliateListByStatusWithKeys();
$hyperAffiliateDataRaw = $this->doctrine->getRepository(HyperAffiliateData::class)->getHyperAffiliateData($affiliateIds, $affiliateIdsExcluded, $statuses, $statusesExcluded, $affiliateCategories, $affiliateCategoriesExcluded, $startDate, $endDate);
$distinctAffiliateIds = $hyperAffiliateData = [];
foreach ($hyperAffiliateDataRaw as $key => $value) {
!in_array($value['affiliateId'], $distinctAffiliateIds) ? array_push($distinctAffiliateIds, $value['affiliateId']) : false;
$md5 = md5($value['affiliateId'] . '#' . $value['month']->format('Y-m-d'));
$hyperAffiliateData[$md5] = $value;
}
$deductionControlDataRaw = $deductionControlData = $accountManagersByAffiliateId = [];
if ($distinctAffiliateIds) {
$accountManagersByAffiliateId = $this->commonCalls->getAccountManagerInfoByAffiliateIdArrWithKeys($distinctAffiliateIds);
$deductionControlDataRaw = $this->doctrine->getRepository(DeductionControl::class)->getDeductionsByAffiliateGrouping($distinctAffiliateIds, $affiliateIdsExcluded, $activitySources, $activitySourcesExcluded, $startDate, $endDate, 0);
}
foreach ($deductionControlDataRaw as $key => $value) {
$md5 = md5($value['affiliateId'] . '#' . $value['deductionPeriod']->format('Y-m-d'));
$deductionControlData[$md5][$value['activitySource']] = $value;
}
$data = [];
foreach ($hyperAffiliateData as $key => $value) {
$deductedPercentage = $deductionValue = $activitySource = null;
if (array_key_exists($key, $deductionControlData)) {
foreach ($deductionControlData[$key] as $k => $v) {
$activitySource = $deductionControlData[$key][$k]['activitySource'];
$deductionValue = $deductionControlData[$key][$k]['deductionValue'];
$value['newCost'] > 0 ? $deductedPercentage = round(($deductionValue / $value['newCost'] * 100), 2) : false;
}
}
$value['affiliate'] = array_key_exists($value['affiliateId'], $affiliateList) ? $affiliateList[$value['affiliateId']]['name'] : '';
$value['affiliateManager'] = array_key_exists($value['affiliateId'], $accountManagersByAffiliateId) ? $accountManagersByAffiliateId[$value['affiliateId']]['name'] : '';
$value['deductedPercentage'] = $deductedPercentage;
$value['deductionValue'] = round($deductionValue, 2);
$value['activitySource'] = $activitySource;
$value['monthlyReportCost'] = $value['newCost'];
$value['year'] = $value['month']->format('Y');
$value['date'] = $value['month']->format('Y-m-d');
$value['week'] = $value['month']->format('Y') . $value['month']->format('W');
$value['month'] = $value['month']->format('m');
$data[] = $value;
}
$tableColumns = $this->commonCalls->changeColumnVisibilityForTable(Config::REPORT_DEDUCTION_INSIGHTS_COLUMNS, $selectedColumns, $groupedColumns);
if ($downloadDataAsCSV) {
$this->commonCalls->downloadCSV($tableColumns, $data, 'DEDUCTION INSIGHTS ' . $startDate . '_' . $endDate);
} else {
return new JsonResponse([
'response' => [
'success' => true,
'httpStatus' => Config::HTTP_STATUS_CODE_OK,
'data' => [
'tableColumns' => $tableColumns,
'data' => $data,
'metaData' => []
],
'error' => null
]
], Config::HTTP_STATUS_CODE_OK);
}
}
/**
* @Route("/skad-postbacks", name="get_skad_postbacks", methods={"GET"})
*/
public function getSkadPostbacksAction(Request $request)
{
$fields = $filters = [];
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$page = $request->query->get('currentPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$limit = $request->query->get('perPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$filters = $request->query->get('filters') ?? [];
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters') ?? [];
$appIds = $campaignIds = $endpoints = 0;
if (isset($filters)) {
foreach ($filters as $key => $value) {
$key === Config::MULTISELECT_SKAD_POSTBACKS_APP_IDS ? $appIds = $value : false;
$key === Config::MULTISELECT_SKAD_POSTBACKS_CAMPAIGN_IDS ? $campaignIds = $value : false;
$key === Config::MULTISELECT_SKAD_POSTBACKS_ENDPOINTS ? $endpoints = $value : false;
}
}
$excludedFlagForAppIds = $excludedFlagForCampaignIds = $excludedFlagForEndpoints = false;
if (isset($filters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$key === Config::MULTISELECT_SKAD_POSTBACKS_APP_IDS ? $excludedFlagForAppIds = $value : false;
$key === Config::MULTISELECT_SKAD_POSTBACKS_CAMPAIGN_IDS ? $excludedFlagForCampaignIds = $value : false;
$key === Config::MULTISELECT_SKAD_POSTBACKS_ENDPOINTS ? $excludedFlagForEndpoints = $value : false;
}
}
$startDate = date('Y-m-d', strtotime($request->query->get('startDate')));
$endDate = date('Y-m-d', (strtotime($request->query->get('endDate')) + 24 * 60 * 60));
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$groupedColumns = $request->query->get('groups') != '' ? $request->query->get('groups') : [];
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1;
$checkValuesFromArr['appId'] = ['excluded' => $excludedFlagForAppIds, 'ids' => $appIds,];
$checkValuesFromArr['campaignId'] = ['excluded' => $excludedFlagForCampaignIds, 'ids' => $campaignIds];
$checkValuesFromArr['endpoint'] = ['excluded' => $excludedFlagForEndpoints, 'ids' => $endpoints];
$postbackLogsData = $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->getSkadPostbackDataForReport($startDate, $endDate, $checkValuesFromArr, $limit, $page, in_array($sortBy, ['hoOfferId', 'hoAffiliateId']) ? Config::REPORTS_PAGINATION_DEFAULT_SORT_BY : $sortBy, $sortType);
$finalArr = [];
$distinctAppIds = [];
$distinctEndpoints = [];
$distinctCampaignIds = [];
foreach ($postbackLogsData as $key => $value) {
$isPostbackAcknowledgedFromMmp = $value['isPostbackAcknowledgedFromAppsflyer'] || $value['branchPostbackId'] !== null;
if (array_key_exists($value['transactionId'], $finalArr) && $finalArr[$value['transactionId']]['isPostbackAcknowledgedFromMmp'] == 'YES') {
continue;
}
!in_array($value['appId'], $distinctAppIds) ? $distinctAppIds[] = $value['appId'] : false;
!in_array($value['campaignId'], $distinctCampaignIds) ? $distinctCampaignIds[] = $value['campaignId'] : false;
!in_array($value['endpoint'], $distinctEndpoints) ? $distinctEndpoints[] = $value['endpoint'] : false;
$temp = [
'mappingIndex' => md5($value['appId'] . '#' . $value['campaignId'] . '#' . $value['endpoint']),
'appId' => 'id' . $value['appId'],
'campaignId' => $value['campaignId'],
'redownload' => $value['redownload'] ? 'YES' : 'NO',
'hoOfferName' => null,
'hoOfferId' => null,
'mmpSource' => null,
'hoAffiliateId' => null,
'hoAffiliateName' => null,
'transactionId' => $value['transactionId'],
'endpoint' => $value['endpoint'],
'isPostbackScheduledForMmp' => $value['isPostbackScheduledForMmp'] ? 'NO' : 'YES',
'isPostbackAcknowledgedFromMmp' => $isPostbackAcknowledgedFromMmp ? 'YES' : 'NO',
'dateInserted' => $value['dateInserted']->format('Y-m-d H:i:s'),
'date' => $value['dateInserted']->format('Y-m-d'),
'week' => $value['dateInserted']->format('Y') . $value['dateInserted']->format('W'),
'month' => $value['dateInserted']->format('m'),
'year' => $value['dateInserted']->format('Y'),
'hour' => $value['dateInserted']->format('h'),
];
$finalArr[$value['transactionId']] = $temp;
}
$finalArr = array_values($finalArr);
$skadNetworkManualPostbackMapping = $this->doctrine->getRepository(SkadNetworkManualPostbackMapping::class)->getDataForSkadPostbacksReport([
'appId' => $distinctAppIds,
'campaignId' => $distinctAppIds,
'endpoint' => $distinctEndpoints,
]);
$mappedData = [];
foreach ($skadNetworkManualPostbackMapping as $key => $value) {
$mappedData[md5($value['appId'] . '#' . $value['campaignId'] . '#' . $value['endpoint'])] = [
'offerId' => $value['offerId'],
'affiliateId' => $value['affiliateId']
];
}
$affiliateList = $this->commonCalls->getAffiliateListByStatusWithKeys();
$offerDetailsByOfferId = [];
foreach ($finalArr as $key => $value) {
if (array_key_exists($value['mappingIndex'], $mappedData)) {
if (!array_key_exists($mappedData[$value['mappingIndex']]['offerId'], $offerDetailsByOfferId)) {
$offerInfo = $this->doctrine->getRepository(OfferInfo::class)->findOneBy(['offerId' => $mappedData[$value['mappingIndex']]['offerId']]);
if ($offerInfo) {
$offerDetailsByOfferId[$mappedData[$value['mappingIndex']]['offerId']] = [
'mmpSource' => strtoupper($offerInfo->getSkadNetworkMmp()),
'offerName' => $offerInfo->getName()
];
}
}
$finalArr[$key]['hoOfferName'] = array_key_exists($mappedData[$value['mappingIndex']]['offerId'], $offerDetailsByOfferId) ? $offerDetailsByOfferId[$mappedData[$value['mappingIndex']]['offerId']]['offerName'] : '';
$finalArr[$key]['mmpSource'] = array_key_exists($mappedData[$value['mappingIndex']]['offerId'], $offerDetailsByOfferId) ? $offerDetailsByOfferId[$mappedData[$value['mappingIndex']]['offerId']]['mmpSource'] : '';
$finalArr[$key]['hoOfferId'] = $mappedData[$value['mappingIndex']]['offerId'];
$finalArr[$key]['hoAffiliateId'] = $mappedData[$value['mappingIndex']]['affiliateId'];
$finalArr[$key]['hoAffiliateName'] = array_key_exists($mappedData[$value['mappingIndex']]['affiliateId'], $affiliateList) ? $affiliateList[$mappedData[$value['mappingIndex']]['affiliateId']]['name'] : '';
}
unset($finalArr[$key]['mappingIndex']);
}
$tableColumns = $this->commonCalls->changeColumnVisibilityForTable(Config::REPORT_SKAD_POSTBACKS_COLUMNS, $selectedColumns, $groupedColumns);
if ($downloadDataAsCSV) {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'SKAD POSTBACKS ' . $startDate . '_' . $endDate);
} else {
$totalRecordCount = $this->doctrine->getRepository(SkadNetworkPostbackLogs::class)->getSkadPostbackRecordsForReport($startDate, $endDate, []);
$noOfPages = ceil($totalRecordCount / $limit);
return new JsonResponse([
'response' => [
'success' => true,
'httpStatus' => Config::HTTP_STATUS_CODE_OK,
'data' => [
'tableColumns' => $tableColumns,
'data' => $finalArr,
'metaData' => [
'total' => (int)$totalRecordCount,
'limit' => (int)$limit,
'page' => (int)$page,
'pages' => (int)$noOfPages,
]
],
'error' => null
]
], Config::HTTP_STATUS_CODE_OK);
}
}
public function downloadCSV($tableColumns, $data, $reportNamePretty)
{
$reportName = str_replace(" ", "-", strtolower($reportNamePretty));
$header = [];
foreach ($tableColumns as $key => $value) {
if ($value['show'] == 1) {
array_push($header, $value['Header']);
}
}
$rows = [$header];
foreach ($data as $key => $value) {
$row = [];
foreach ($tableColumns as $k => $v) {
if ($v['show'] == 1) {
array_push($row, $value[$v['accessor']]);
}
}
$rows[] = $row;
}
$spreadsheet = new Spreadsheet();
$spreadsheet->getProperties()->setCreator('MAFO')->setLastModifiedBy('MAFO')->setTitle($reportNamePretty . ' Report')->setSubject($reportNamePretty)->setDescription($reportNamePretty);
$spreadsheet->getActiveSheet()->fromArray($rows, null, 'A1');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $reportName . '.xls"');
header('Cache-Control: max-age=0');
$writer = IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('php://output');
exit;
}
/**
* @Route("/revenue-report", name="get_revenue_report", methods={"GET"})
*/
public function getRevenueReportAction(Request $request)
{
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$filters = $request->query->get('filters') ?? [];
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters') ?? [];
$limit = $request->query->get('limit') ? $request->query->get('limit') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$page = $request->query->get('page') ? $request->query->get('page') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$filtersToProcess = [];
if (isset($filters)) {
foreach ($filters as $key => $value) {
$key === 'MULTISELECT_TUNE_ADVERTISERS' ? $filtersToProcess['advertiserIds'] = $value : false;
$key === 'MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS' ? $filtersToProcess['advertiserManagerEmailIds'] = $value : false;
$key === 'MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS' ? $filtersToProcess['hyperStatuses'] = $value : false;
$key === 'MULTISELECT_MOBUPPS_TEAMS' ? $filtersToProcess['mobuppsTeamIds'] = $value : false;
$key === 'MULTISELECT_TUNE_ACCOUNTS' ? $filtersToProcess['advertiserTuneAccounts'] = $value : false;
}
}
$excludedFlagsToProcess = [];
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$key === 'MULTISELECT_TUNE_ADVERTISERS' ? $excludedFlagsToProcess['excludeAdvertiserIds'] = $value : false;
$key === 'MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS' ? $excludedFlagsToProcess['excludeAdvertiserManagerEmailIds'] = $value : false;
$key === 'MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS' ? $excludedFlagsToProcess['excludeHyperStatus'] = $value : false;
$key === 'MULTISELECT_MOBUPPS_TEAMS' ? $excludedFlagsToProcess['excludeMobuppsTeamIds'] = $value : false;
$key === 'MULTISELECT_TUNE_ACCOUNTS' ? $excludedFlagsToProcess['advertiserTuneAccountsExcluded'] = $value : false;
}
}
$dateStart = date('Y-m-1', strtotime('-0 month', strtotime($request->query->get('startDate'))));
$dateEnd = date('Y-m-1', strtotime('+0 month ', strtotime($request->query->get('endDate'))));
if ($request->query->get('downloadCSV') == 1) {
$limit = Config::REPORTS_PAGINATION_DEFAULT_CSV_PAGE_SIZE;
$page = Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
}
$finalArr = $this->financialToolsComponents->getRevenueTotalAggregatedData($dateStart, $dateEnd, $filtersToProcess, $excludedFlagsToProcess, $selectedColumns, $this->getUser()->getEmail());
$tableColumns = $this->commonCalls->changeColumnVisibilityForTable(array_values($this->commonCalls->getDataFromJsonFile(Config::JSON_FILE_REPORTS_REVENUE_REPORT)), $selectedColumns, []);
if ($request->query->get('downloadCSV') == 1) {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'Revenue Report ' . $dateStart . '_' . $dateEnd);
}
return new JsonResponse($this->commonCalls->getReportResponse($finalArr, $tableColumns, $limit, $page, $sortBy, $sortType));
}
/**
* @Route("/mafo-revenue-report", name="get_mafo_revenue_report", methods={"GET"})
*/
public function getMafoRevenueReportAction(Request $request)
{
ini_set('memory_limit', '1024M');
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$filters = $request->query->get('filters') ?? [];
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters') ?? [];
$limit = $request->query->get('limit') ? $request->query->get('limit') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$page = $request->query->get('page') ? $request->query->get('page') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$filtersToProcess = [];
if (isset($filters)) {
foreach ($filters as $key => $value) {
$key === 'MULTISELECT_MAFO_ADVERTISERS' ? $filtersToProcess['advertiserIds'] = $value : false;
$key === 'MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS' ? $filtersToProcess['advertiserManagerEmailIds'] = $value : false;
$key === 'MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS' ? $filtersToProcess['hyperStatuses'] = $value : false;
$key === 'MULTISELECT_MOBUPPS_TEAMS' ? $filtersToProcess['advertiserManagerTeamIds'] = $value : false;
$key === 'MULTISELECT_TUNE_ACCOUNTS' ? $filtersToProcess['advertiserTuneAccounts'] = $value : false;
}
}
$excludedFlagsToProcess = [];
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$key === 'MULTISELECT_MAFO_ADVERTISERS' ? $excludedFlagsToProcess['excludeAdvertiserIds'] = $value : false;
$key === 'MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS' ? $excludedFlagsToProcess['excludeAdvertiserManagerEmailIds'] = $value : false;
$key === 'MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS' ? $excludedFlagsToProcess['excludeHyperStatus'] = $value : false;
$key === 'MULTISELECT_MOBUPPS_TEAMS' ? $excludedFlagsToProcess['excludeAdvertiserManagerTeamIds'] = $value : false;
$key === 'MULTISELECT_TUNE_ACCOUNTS' ? $excludedFlagsToProcess['advertiserTuneAccountsExcluded'] = $value : false;
}
}
$dateStart = date('Y-m-1', strtotime('-0 month', strtotime($request->query->get('startDate'))));
$dateEnd = date('Y-m-1', strtotime('+0 month ', strtotime($request->query->get('endDate'))));
if ($request->query->get('downloadCSV') == 1) {
$limit = Config::REPORTS_PAGINATION_DEFAULT_CSV_PAGE_SIZE;
$page = Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
}
$finalArr = $this->mafoFinancialToolsComponents->getRevenueTotalAggregatedData($dateStart, $dateEnd, $filtersToProcess, $excludedFlagsToProcess, $selectedColumns, $this->getUser()->getEmail());
$tableColumns = $this->commonCalls->changeColumnVisibilityForTable(array_values($this->commonCalls->getDataFromJsonFile(Config::JSON_FILE_REPORTS_MAFO_REVENUE_REPORT)), $selectedColumns, []);
if ($request->query->get('downloadCSV') == 1) {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'Revenue Report ' . $dateStart . '_' . $dateEnd);
}
return new JsonResponse($this->commonCalls->getReportResponse($finalArr, $tableColumns, $limit, $page, $sortBy, $sortType));
}
/**
* @Route("/payout-report", name="get_payout_report", methods={"GET"})
*/
public function getPayoutReportAction(Request $request)
{
ini_set('memory_limit', '1024M');
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$filters = $request->query->get('filters') ?? [];
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters') ?? [];
$limit = $request->query->get('perPage') ? $request->query->get('perPage') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$page = $request->query->get('currentPage') ? $request->query->get('currentPage') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$filtersToProcess = [];
if (isset($filters)) {
foreach ($filters as $key => $value) {
$key === 'MULTISELECT_AFFILIATES' ? $filtersToProcess['affiliateIds'] = $value : false;
$key === 'MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS' ? $filtersToProcess['affiliateManagerEmailArr'] = $value : false;
$key === 'MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS' ? $filtersToProcess['hyperStatuses'] = $value : false;
$key === 'MULTISELECT_ADDED_BY_FROM_MAFO_USERS' ? $filtersToProcess['addedByEmailIds'] = $value : false;
$key === 'MULTISELECT_MOBUPPS_TEAMS' ? $filtersToProcess['mobuppsTeamIds'] = $value : false;
$key === 'MULTISELECT_AFFILIATE_TUNE_ACCOUNTS' ? $filtersToProcess['affiliateTuneAccounts'] = $value : false;
}
}
$excludedFlagsToProcess = [];
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$key === 'MULTISELECT_AFFILIATES' ? $excludedFlagsToProcess['excludeAffiliateIds'] = $value : false;
$key === 'MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS' ? $excludedFlagsToProcess['excludeAffiliateManagerEmailArr'] = $value : false;
$key === 'MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS' ? $excludedFlagsToProcess['excludeHyperStatus'] = $value : false;
$key === 'MULTISELECT_ADDED_BY_FROM_MAFO_USERS' ? $excludedFlagsToProcess['excludeAddedByEmailIds'] = $value : false;
$key === 'MULTISELECT_MOBUPPS_TEAMS' ? $excludedFlagsToProcess['excludeMobuppsTeamIds'] = $value : false;
$key === 'MULTISELECT_AFFILIATE_TUNE_ACCOUNTS' ? $excludedFlagsToProcess['affiliateTuneAccountsExcluded'] = $value : false;
}
}
$dateStart = date('Y-m-1', strtotime('-0 month', strtotime($request->query->get('startDate'))));
$dateEnd = date('Y-m-1', strtotime('+0 month ', strtotime($request->query->get('endDate'))));
if ($request->query->get('downloadCSV') == 1) {
$limit = Config::REPORTS_PAGINATION_DEFAULT_CSV_PAGE_SIZE;
$page = Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
}
$finalArr = $this->financialToolsComponents->getPayoutTotalAggregatedData($dateStart, $dateEnd, $filtersToProcess, $excludedFlagsToProcess, $selectedColumns, $this->getUser()->getEmail());
$tableColumns = $this->commonCalls->changeColumnVisibilityForTable(array_values($this->commonCalls->getDataFromJsonFile(Config::JSON_FILE_REPORTS_PAYOUT_REPORT)), $selectedColumns, []);
if ($request->query->get('downloadCSV') == 1) {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'Payout Report ' . $dateStart . '_' . $dateEnd);
}
return new JsonResponse($this->commonCalls->getReportResponse($finalArr, $tableColumns, $limit, $page, $sortBy, $sortType));
}
/**
* @Route("/mafo-payout-report", name="get_mafo_payout_report", methods={"GET"})
*/
public function getMafoPayoutReportAction(Request $request)
{
ini_set('memory_limit', '1024M');
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$filters = $request->query->get('filters') ?? [];
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters') ?? [];
$limit = $request->query->get('perPage') ? $request->query->get('perPage') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$page = $request->query->get('currentPage') ? $request->query->get('currentPage') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$filtersToProcess = [];
if (isset($filters)) {
foreach ($filters as $key => $value) {
$key === 'MULTISELECT_MAFO_AFFILIATES' ? $filtersToProcess['affiliateIds'] = $value : false;
$key === 'MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS' ? $filtersToProcess['affiliateManagerEmailArr'] = $value : false;
$key === 'MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS' ? $filtersToProcess['hyperStatuses'] = $value : false;
$key === 'MULTISELECT_MOBUPPS_TEAMS' ? $filtersToProcess['mobuppsTeamIds'] = $value : false;
}
}
$excludedFlagsToProcess = [];
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$key === 'MULTISELECT_AFFILIATES' ? $excludedFlagsToProcess['excludeAffiliateIds'] = $value : false;
$key === 'MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS' ? $excludedFlagsToProcess['excludeAffiliateManagerEmailArr'] = $value : false;
$key === 'MULTISELECT_FINANCIAL_TOOLS_HYPER_STATUS' ? $excludedFlagsToProcess['excludeHyperStatus'] = $value : false;
$key === 'MULTISELECT_ADDED_BY_FROM_MAFO_USERS' ? $excludedFlagsToProcess['excludeAddedByEmailIds'] = $value : false;
$key === 'MULTISELECT_MOBUPPS_TEAMS' ? $excludedFlagsToProcess['excludeMobuppsTeamIds'] = $value : false;
$key === 'MULTISELECT_AFFILIATE_TUNE_ACCOUNTS' ? $excludedFlagsToProcess['affiliateTuneAccountsExcluded'] = $value : false;
}
}
$dateStart = date('Y-m-1', strtotime('-0 month', strtotime($request->query->get('startDate'))));
$dateEnd = date('Y-m-1', strtotime('+0 month ', strtotime($request->query->get('endDate'))));
if ($request->query->get('downloadCSV') == 1) {
$limit = Config::REPORTS_PAGINATION_DEFAULT_CSV_PAGE_SIZE;
$page = Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
}
$finalArr = $this->mafoFinancialToolsComponents->getPayoutTotalAggregatedData($dateStart, $dateEnd, $filtersToProcess, $excludedFlagsToProcess, $selectedColumns, $this->getUser()->getEmail());
$tableColumns = $this->commonCalls->changeColumnVisibilityForTable(array_values($this->commonCalls->getDataFromJsonFile(Config::JSON_FILE_REPORTS_MAFO_PAYOUT_REPORT)), $selectedColumns, []);
if ($request->query->get('downloadCSV') == 1) {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'Payout Report ' . $dateStart . '_' . $dateEnd);
}
return new JsonResponse($this->commonCalls->getReportResponse($finalArr, $tableColumns, $limit, $page, $sortBy, $sortType));
}
/**
* @Route("/global-network-report", methods={"GET"})
*/
public function getGlobalNetworkReport(Request $request)
{
ini_set('memory_limit', '512M');
$filtersSelected = $request->query->get('filters');
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters');
$filters = [];
$excludedFiltersFlags = [];
if (isset($filtersSelected)) {
foreach ($filtersSelected as $key => $value) {
$key === Config::MULTISELECT_MMP_STATISTICS_APP ? $filters['appIds'] = $value : false;
$key === Config::MULTISELECT_MMP_OFFERS ? $filters['offers'] = $value : false;
$key === Config::MULTISELECT_MMP_SOURCE_GLOBAL_NETWORK_REPORT ? $filters['mmpSource'] = $value : false;
$key === Config::MULTISELECT_MMP_PARTNERS ? $filters['affiliates'] = $value : false;
$key === Config::MULTISELECT_MMP_MAKER_OF_OFFER_RULE_IN_MMP_OFFERS ? $filters['users'] = $value : false;
$key === Config::MULTISELECT_GEO ? $filters['geos'] = $value : false;
// $key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $filters['advertiserIds'] = $value : false;
$key === Config::MULTISELECT_MAFO_ADVERTISERS ? $filters['mafoAdvertiserIds'] = $value : false;
// $key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $filters['hoAffiliateIds'] = $value : false;
$key === Config::MULTISELECT_MAFO_AFFILIATES ? $filters['mafoAffiliateIds'] = $value : false;
$key === Config::MULTISELECT_MMP_EVENTS ? $filters['events'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_OFFERS ? $filters['hoOfferIds'] = $value : false;
$key === Config::MULTISELECT_MAFO_OFFERS ? $filters['mafoOfferIds'] = $value : false;
$key === Config::MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS ? $filters['advertiserManagerEmailIds'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS ? $filters['affiliateManagerEmailIds'] = $value : false;
$key === Config::MULTISELECT_ADVERTISER_MOBUPPS_TEAM ? $filters['advertiserMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MOBUPPS_TEAM ? $filters['affiliateMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $filters['affiliateCategories'] = $value : false;
$key === Config::MULTISELECT_TUNE_PIDS ? $filters['tunePids'] = $value : false;
$key === Config::MULTISELECT_GLOBAL_REPORT_EXCLUDE_ZERO_VALUES ? $filters['excludeResultsWithZeroValues'] = $value : false;
$key === Config::MULTISELECT_MMP_IS_RETARGETED ? $filters['isRetargeted'] = $value : false;
$key === Config::MULTISELECT_SCRAPER_SITE_ID ? $filters['siteIds'] = $value : false;
$key === Config::MULTISELECT_OFFER_TYPE ? $filters['offerType'] = $value : false;
}
}
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$value = (int)$value;
$key === Config::MULTISELECT_MMP_STATISTICS_APP ? $excludedFiltersFlags['appIds'] = $value : false;
$key === Config::MULTISELECT_MMP_OFFERS ? $excludedFiltersFlags['offers'] = $value : false;
$key === Config::MULTISELECT_MMP_SOURCE_GLOBAL_NETWORK_REPORT ? $excludedFiltersFlags['mmpSource'] = $value : false;
$key === Config::MULTISELECT_MMP_PARTNERS ? $excludedFiltersFlags['affiliates'] = $value : false;
$key === Config::MULTISELECT_MMP_MAKER_OF_OFFER_RULE_IN_MMP_OFFERS ? $excludedFiltersFlags['users'] = $value : false;
$key === Config::MULTISELECT_GEO ? $excludedFiltersFlags['geos'] = $value : false;
// $key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS ? $excludedFiltersFlags['advertiserIds'] = $value : false;
$key === Config::MULTISELECT_MAFO_ADVERTISERS ? $excludedFiltersFlags['mafoAdvertiserIds'] = $value : false;
// $key === Config::MULTISELECT_MMP_TUNE_AFFILIATES ? $excludedFiltersFlags['hoAffiliateIds'] = $value : false;
$key === Config::MULTISELECT_MAFO_AFFILIATES ? $excludedFiltersFlags['mafoAffiliateIds'] = $value : false;
$key === Config::MULTISELECT_MMP_EVENTS ? $excludedFiltersFlags['events'] = $value : false;
$key === Config::MULTISELECT_MMP_TUNE_OFFERS ? $excludedFiltersFlags['hoOfferIds'] = $value : false;
$key === Config::MULTISELECT_MAFO_OFFERS ? $excludedFiltersFlags['mafoOfferIds'] = $value : false;
$key === Config::MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS ? $excludedFiltersFlags['advertiserManagerEmailIds'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MANAGER_FROM_MAFO_USERS ? $excludedFiltersFlags['affiliateManagerEmailIds'] = $value : false;
$key === Config::MULTISELECT_ADVERTISER_MOBUPPS_TEAM ? $excludedFiltersFlags['advertiserMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_MOBUPPS_TEAM ? $excludedFiltersFlags['affiliateMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_AFFILIATE_CATEGORIES ? $excludedFiltersFlags['affiliateCategories'] = $value : false;
$key === Config::MULTISELECT_TUNE_PIDS ? $excludedFiltersFlags['tunePids'] = $value : false;
$key === Config::MULTISELECT_GLOBAL_REPORT_EXCLUDE_ZERO_VALUES ? $excludedFiltersFlags['excludeResultsWithZeroValues'] = $value : false;
$key === Config::MULTISELECT_SCRAPER_SITE_ID ? $excludedFiltersFlags['siteIds'] = $value : false;
$key === Config::MULTISELECT_OFFER_TYPE ? $excludedFiltersFlags['offerType'] = $value : false;
}
}
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$groupedColumns = $request->query->get('groups') != '' ? $request->query->get('groups') : [];
$dateStart = date('Y-m-d', strtotime($request->query->get('startDate')));
$dateEnd = date('Y-m-d', strtotime($request->query->get('endDate')));
$eventTimestampFrom = strtotime($dateStart);
$eventTimeStampTo = strtotime($dateEnd);
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_MMP_REPORT_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$page = $request->query->get('currentPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$limit = $request->query->get('perPage') ?? Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1;
$ajaxRequestTimeout = $request->query->get('ajaxRequestTimeout') == 1;
$tableColumns = $this->commonCalls->changeColumnVisibilityForTable(
array_values($this->commonCalls->getDataFromJsonFile(Config::JSON_FILE_GLOBAL_NETWORK_REPORT)),
$selectedColumns,
[]
);
$finalReportData = [];
if ($ajaxRequestTimeout) {
$this->gearmanClientInterface->doBackgroundJob('AppWorkersMmpReportsWorker~generateGlobalReportAndSendMail', json_encode([
'reportParams' => [
$filters,
$excludedFiltersFlags,
$eventTimestampFrom,
$eventTimeStampTo,
$selectedColumns,
$groupedColumns
],
'tableColumns' => $tableColumns,
'sendMailTo' => $this->getUser()->getEmail(),
'dateStart' => $dateStart,
'dateEnd' => $dateEnd,
'requestedAt' => date('Y-m-d H:i:s', strtotime('now'))
]));
return new JsonResponse([
'response' => [
'success' => true,
'httpStatus' => Config::HTTP_STATUS_CODE_OK,
'data' => [
'tableColumns' => $tableColumns,
'data' => [],
'metaData' => [
'total' => 0,
'limit' => (int)$limit,
'page' => (int)$page,
'pages' => 1,
]
],
'error' => null
]
], Config::HTTP_STATUS_CODE_OK);
} elseif (
strtotime(date('m', strtotime($request->query->get('startDate'))))
>= strtotime(date(
'm',
strtotime("-" . Config::MMP_REPORTS_TABLE_DATA_MONTH_LIMIT . " months")
))
) {
ini_set('mysqlnd.net_read_timeout', '1');
$finalReportData = $this->mmpComponents->getMmpCumulativeData(
$filters,
$excludedFiltersFlags,
$eventTimestampFrom,
$eventTimeStampTo,
$selectedColumns,
$groupedColumns
);
}
foreach ($tableColumns as $key => $value) {
if (isset($value['aggregate']) && $value['aggregate'] == 'sum') {
$num = round(array_sum(array_column($finalReportData, $value['accessor'])), 2);
if ($value['category'] == 'statistics') {
$tableColumns[$key]['Footer'] = number_format($num);
} else {
$tableColumns[$key]['Footer'] = number_format($num, 2);
}
}
}
if ($downloadDataAsCSV) {
$this->commonCalls->downloadCSV($tableColumns, $finalReportData, 'Global Network Report ' . $dateStart . '_' . $dateEnd);
} else {
$finalReportData = array_values($finalReportData);
if (sizeof($finalReportData)) {
$entity = $finalReportData[0];
if (array_key_exists($sortBy, $entity)) {
$sortFlag = 3;
if ($sortType == Config::SORT_TYPE_ASC) {
$sortFlag = 4;
}
array_multisort(array_column($finalReportData, $sortBy), $sortFlag, $finalReportData);
}
}
$offset = $limit * ($page - 1);
$totalRecordCount = sizeof($finalReportData);
$noOfPages = ceil($totalRecordCount / $limit);
return new JsonResponse([
'response' => [
'success' => true,
'httpStatus' => Config::HTTP_STATUS_CODE_OK,
'data' => [
'tableColumns' => $tableColumns,
'data' => array_slice($finalReportData, $offset, $limit),
'metaData' => [
'total' => $totalRecordCount,
'limit' => (int)$limit,
'page' => (int)$page,
'pages' => (int)$noOfPages,
]
],
'error' => null
]
], Config::HTTP_STATUS_CODE_OK);
}
}
/**
* @Route("/sales-report", name="get_sales_report", methods={"GET"})
*/
public function getSalesReportAction(Request $request, LoggerInterface $logger)
{
$selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$groupedColumns = $request->query->get('groups') != '' ? $request->query->get('groups') : [];
$filtersSelected = $request->query->get('filters') ?? [];
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters') ?? [];
$limit = $request->query->get('perPage') ? $request->query->get('perPage') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$page = $request->query->get('currentPage') ? $request->query->get('currentPage') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$filtersToProcess = [];
if (isset($filtersSelected)) {
foreach ($filtersSelected as $key => $value) {
$key === Config::MULTISELECT_MMP_TUNE_OFFERS ? $filtersToProcess['offers'] = $value : false;
if ($key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS) continue;
$key === 'MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS' ? $filtersToProcess['advertiserManagerEmailIds'] = $value : false;
$key === 'MULTISELECT_MOBUPPS_TEAMS' ? $filtersToProcess['advertiserMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_MMP_STATISTICS_APP ? $filtersToProcess['appIds'] = $value : false;
}
}
$adFilter = $filtersSelected[Config::MULTISELECT_MMP_TUNE_ADVERTISERS] ?? [];
$exFilter = $excludedFlagForFilters[Config::MULTISELECT_MMP_TUNE_ADVERTISERS] ?? false;
$filtersToProcess['advertiserIds'] = $this->getAdvertiserTagIds(
$adFilter,
$exFilter
);
$excludedFlagsToProcess = [];
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$key === Config::MULTISELECT_MMP_TUNE_OFFERS ? $excludedFlagsToProcess['offers'] = $value : false;
if ($key === Config::MULTISELECT_MMP_TUNE_ADVERTISERS) continue;
$key === 'MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS' ? $excludedFlagsToProcess['advertiserManagerEmailIds'] = $value : false;
$key === 'MULTISELECT_MOBUPPS_TEAMS' ? $excludedFlagsToProcess['advertiserMobuppsTeam'] = $value : false;
$key === Config::MULTISELECT_MMP_STATISTICS_APP ? $excludedFlagsToProcess['appIds'] = $value : false;
}
}
$dateStart = date('Y-m-d', strtotime($request->query->get('startDate')));
$dateEnd = date('Y-m-d', strtotime($request->query->get('endDate')));
if ($request->query->get('downloadCSV') == 1) {
$limit = Config::REPORTS_PAGINATION_DEFAULT_CSV_PAGE_SIZE;
$page = Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
}
$eventTimestampFrom = strtotime($dateStart);
$eventTimeStampTo = strtotime($dateEnd);
ini_set('mysqlnd.net_read_timeout', '1');
$finalArr = $this->mmpComponents->getMmpCumulativeData(
$filtersToProcess,
$excludedFlagsToProcess,
$eventTimestampFrom,
$eventTimeStampTo,
$selectedColumns,
$groupedColumns
);
$tableColumns = $this->commonCalls->changeColumnVisibilityForTable(
array_values($this->commonCalls->getDataFromJsonFile(Config::JSON_FILE_REPORTS_SALES_REPORT)),
$selectedColumns,
[]
);
foreach ($tableColumns as $key => $value) {
if (isset($value['aggregate']) && $value['aggregate'] == 'sum') {
$num = round(array_sum(array_column($finalArr, $value['accessor'])), 2);
if ($value['category'] == 'statistics') {
$tableColumns[$key]['Footer'] = number_format($num);
} else {
$tableColumns[$key]['Footer'] = number_format($num, 2);
}
}
}
if ($request->query->get('downloadCSV') == 1) {
$this->commonCalls->downloadCSV(
$tableColumns,
$finalArr,
'Sales Report ' . $dateStart . '_' . $dateEnd
);
}
return new JsonResponse($this->commonCalls->getReportResponse($finalArr, $tableColumns, $limit, $page, $sortBy, $sortType));
}
public function getAdvertiserTagIds($filterIds, $flag)
{
$tagId = $this->doctrine
->getRepository(Tag::class)
->getTagIdByTagName(Config::SALES_REPORT_ADVERTISER_TAG);
$advTagRepo = $this->doctrine->getRepository(AdvertiserTagRelationship::class);
$advArr = $advTagRepo->getAdvertiserTagRelationshipByTagId($tagId);
$advIds = [];
foreach ($advArr as $advId) {
$advIds[] = $advId['advertiserId'];
}
if (is_array($filterIds)) {
$newAdvIds = [];
foreach ($filterIds as $key => $val) {
if (in_array($val, $advIds)) {
if ($flag) {
unset($advIds[array_search($val, $advIds)]);
} else {
$newAdvIds[] = $val;
}
}
}
if (count($newAdvIds) > 0) {
$advIds = $newAdvIds;
}
}
return $advIds;
}
/**
* @Route("/offers-report", name="get_offers_report", methods={"GET"})
*/
public function getOffersReportAction(Request $request, LoggerInterface $logger)
{
$columnsForGlobalReport = $selectedColumns = $request->query->get('data') != '' ? $request->query->get('data') : [];
$groupedColumns = $request->query->get('groups') != '' ? $request->query->get('groups') : [];
$filtersSelected = $request->query->get('filters') ?? [];
$excludedFlagForFilters = $request->query->get('excludedFlagForFilters') ?? [];
$limit = $request->query->get('perPage') ? $request->query->get('perPage') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_SIZE;
$page = $request->query->get('currentPage') ? $request->query->get('currentPage') : Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
$sortBy = $request->query->get('sortBy') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_BY;
$sortType = $request->query->get('sortType') ?? Config::REPORTS_PAGINATION_DEFAULT_SORT_TYPE;
$dateStart = date('Y-m-d', strtotime($request->query->get('startDate')));
$dateEnd = date('Y-m-d', strtotime($request->query->get('endDate')));
$downloadDataAsCSV = $request->query->get('downloadCSV') == 1 ? true : false;
$filtersToProcess = [];
if (isset($filtersSelected)) {
foreach ($filtersSelected as $key => $value) {
$key === 'MULTISELECT_MAFO_OFFERS' ? $filtersToProcess['mafoOfferIds'] = $value : false;
$key === 'MULTISELECT_MAFO_ADVERTISERS' ? $filtersToProcess['mafoAdvertiserIds'] = $value : false;
$key === 'MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS' ? $filtersToProcess['advertiserManagerEmailIds'] = $value : false;
$key === 'MULTISELECT_MMP_SOURCE_GLOBAL_NETWORK_REPORT' ? $filtersToProcess['mmpSources'] = $value : false;
$key === 'MULTISELECT_GEO' ? $filtersToProcess['geos'] = $value : false;
$key === 'MULTISELECT_MMP_STATISTICS_APP' ? $filtersToProcess['appIds'] = $value : false;
$key === 'MULTISELECT_MMP_SYSTEM_OFFER_ID' ? $filtersToProcess['mmpSystemOfferIds'] = $value : false;
$key === 'MULTISELECT_MMP_SYSTEM_ADVERTISER_ID' ? $filtersToProcess['mmpSystemAdvertiserIds'] = $value : false;
}
}
$excludedFlagsToProcess = [];
if (isset($excludedFlagForFilters)) {
foreach ($excludedFlagForFilters as $key => $value) {
$key === 'MULTISELECT_MAFO_OFFERS' ? $excludedFlagsToProcess['mafoOfferIds'] = $value : false;
$key === 'MULTISELECT_MAFO_ADVERTISERS' ? $excludedFlagsToProcess['mafoAdvertiserIds'] = $value : false;
$key === 'MULTISELECT_ADVERTISER_MANAGER_FROM_MAFO_USERS' ? $excludedFlagsToProcess['advertiserManagerEmailIds'] = $value : false;
$key === 'MULTISELECT_MMP_SOURCE_GLOBAL_NETWORK_REPORT' ? $excludedFlagsToProcess['mmpSources'] = $value : false;
$key === 'MULTISELECT_GEO' ? $excludedFlagsToProcess['geos'] = $value : false;
$key === 'MULTISELECT_MMP_STATISTICS_APP' ? $excludedFlagsToProcess['appIds'] = $value : false;
$key === 'MULTISELECT_MMP_SYSTEM_OFFER_ID' ? $excludedFlagsToProcess['mmpSystemOfferIds'] = $value : false;
$key === 'MULTISELECT_MMP_SYSTEM_ADVERTISER_ID' ? $excludedFlagsToProcess['mmpSystemAdvertiserIds'] = $value : false;
}
}
if ($request->query->get('downloadCSV') == 1) {
$limit = Config::REPORTS_PAGINATION_DEFAULT_CSV_PAGE_SIZE;
$page = Config::REPORTS_PAGINATION_DEFAULT_PAGE_NUMBER;
}
$eventTimestampFrom = strtotime($dateStart);
$eventTimeStampTo = strtotime($dateEnd);
// if (isset($selectedColumns["offersReportEvent"])) {
// $columnsForGlobalReport["defaultRevenueModel"] = "1";
// $columnsForGlobalReport["defaultRevenue"] = "1";
// $columnsForGlobalReport["defaultRevenueEvent"] = "1";
// }
// if (isset($selectedColumns["appId"]) || isset($selectedColumns["appName"])) {
// $columnsForGlobalReport["appUrl"] = "1";
// }
// if (isset($columnsForGlobalReport["offersReportEvent"])) {
// $columnsForGlobalReport["event"] = $columnsForGlobalReport["offersReportEvent"];
// unset($columnsForGlobalReport["offersReportEvent"]);
// }
$finalArr = $this->mmpComponents->getOffersReportCumulativeData(
$filtersToProcess,
$excludedFlagsToProcess,
$eventTimestampFrom,
$eventTimeStampTo,
$columnsForGlobalReport
);
$tableColumns = $this->commonCalls->getDataFromJsonFile(Config::TABLE_COLUMNS_WITH_JSON_FILE[Config::REPORTS_OFFERS_REPORT]);
if ($downloadDataAsCSV) {
$this->commonCalls->downloadCSV($tableColumns, $finalArr, 'Offers Report ' . $dateStart . '_' . $dateEnd);
} else {
return new JsonResponse($this->commonCalls->getPaginatedResponseForReports($finalArr, $tableColumns, $selectedColumns, $sortBy, $sortType, $limit, $page));
}
}
}