code fixes

This commit is contained in:
Dennis Eichhorn 2024-03-15 20:24:39 +00:00
parent 67416e99c1
commit 997ccfec85
5 changed files with 102 additions and 66 deletions

View File

@ -29,6 +29,9 @@ use phpOMS\Stdlib\Base\SmartDateTime;
*/ */
class ClientMapper extends DataMapperFactory class ClientMapper extends DataMapperFactory
{ {
/**
* @todo Re-implement, still in use?
*/
public static function mtdYtdClientAttribute( public static function mtdYtdClientAttribute(
\DateTime $startCurrent, \DateTime $startCurrent,
\DateTime $endCurrent, \DateTime $endCurrent,
@ -36,7 +39,8 @@ class ClientMapper extends DataMapperFactory
\DateTime $endComparison, \DateTime $endComparison,
int $businessStart = 1, int $businessStart = 1,
string $language = 'en' string $language = 'en'
) { ) : array
{
$endCurrentIndex = SmartDateTime::calculateMonthIndex((int) $endCurrent->format('m'), $businessStart); $endCurrentIndex = SmartDateTime::calculateMonthIndex((int) $endCurrent->format('m'), $businessStart);
// @todo this query doesn't return clients that have not segment etc. defined. // @todo this query doesn't return clients that have not segment etc. defined.
@ -81,7 +85,7 @@ class ClientMapper extends DataMapperFactory
MONTH(billing_bill_performance_date) ASC' MONTH(billing_bill_performance_date) ASC'
); );
$results = $query->execute()->fetchAll(\PDO::FETCH_ASSOC); $results = $query->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
$oldIndex = 1; $oldIndex = 1;
$period = 1; $period = 1;

View File

@ -29,13 +29,17 @@ use phpOMS\Stdlib\Base\SmartDateTime;
*/ */
class GeneralMapper extends DataMapperFactory class GeneralMapper extends DataMapperFactory
{ {
/**
* @todo Probably re-implement, still used?
*/
public static function monthlySalesProfit( public static function monthlySalesProfit(
\DateTime $startCurrent, \DateTime $startCurrent,
\DateTime $endCurrent, \DateTime $endCurrent,
\DateTime $startComparison, \DateTime $startComparison,
\DateTime $endComparison, \DateTime $endComparison,
int $businessStart = 1 int $businessStart = 1
) { ) : array
{
$endCurrentIndex = SmartDateTime::calculateMonthIndex((int) $endCurrent->format('m'), $businessStart); $endCurrentIndex = SmartDateTime::calculateMonthIndex((int) $endCurrent->format('m'), $businessStart);
$query = new Builder(self::$db); $query = new Builder(self::$db);
@ -58,7 +62,7 @@ class GeneralMapper extends DataMapperFactory
MONTH(billing_bill_performance_date) ASC' MONTH(billing_bill_performance_date) ASC'
); );
$results = $query->execute()->fetchAll(\PDO::FETCH_ASSOC); $results = $query->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
$oldIndex = 1; $oldIndex = 1;
$period = 1; $period = 1;
@ -123,6 +127,9 @@ class GeneralMapper extends DataMapperFactory
]; ];
} }
/**
* @todo Probably re-implement, still used?
*/
public static function annualSalesProfit( public static function annualSalesProfit(
SmartDateTime $historyStart, SmartDateTime $historyStart,
\DateTime $endCurrent, \DateTime $endCurrent,
@ -148,7 +155,7 @@ class GeneralMapper extends DataMapperFactory
MONTH(billing_bill_performance_date) ASC' MONTH(billing_bill_performance_date) ASC'
); );
$results = $query->execute()->fetchAll(\PDO::FETCH_ASSOC); $results = $query->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
$annualSales = []; $annualSales = [];
for ($i = 1; $i < 11; ++$i) { for ($i = 1; $i < 11; ++$i) {

View File

@ -29,6 +29,9 @@ use phpOMS\Stdlib\Base\SmartDateTime;
*/ */
class ItemMapper extends DataMapperFactory class ItemMapper extends DataMapperFactory
{ {
/**
* @todo Re-implement, still in use?
*/
public static function mtdYtdItemAttribute( public static function mtdYtdItemAttribute(
\DateTime $startCurrent, \DateTime $startCurrent,
\DateTime $endCurrent, \DateTime $endCurrent,
@ -36,7 +39,8 @@ class ItemMapper extends DataMapperFactory
\DateTime $endComparison, \DateTime $endComparison,
int $businessStart = 1, int $businessStart = 1,
string $language = 'en' string $language = 'en'
) { ) : array
{
$endCurrentIndex = SmartDateTime::calculateMonthIndex((int) $endCurrent->format('m'), $businessStart); $endCurrentIndex = SmartDateTime::calculateMonthIndex((int) $endCurrent->format('m'), $businessStart);
// @todo this query doesn't return clients that have not segment etc. defined. // @todo this query doesn't return clients that have not segment etc. defined.
@ -83,7 +87,7 @@ class ItemMapper extends DataMapperFactory
MONTH(billing_bill_performance_date) ASC' MONTH(billing_bill_performance_date) ASC'
); );
$results = $query->execute()->fetchAll(\PDO::FETCH_ASSOC); $results = $query->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
$oldIndex = 1; $oldIndex = 1;
$period = 1; $period = 1;

View File

@ -33,11 +33,15 @@ use phpOMS\Stdlib\Base\SmartDateTime;
*/ */
class RegionMapper extends DataMapperFactory class RegionMapper extends DataMapperFactory
{ {
/**
* @todo Re-implement, still in use?
*/
public static function monthlySalesProfit( public static function monthlySalesProfit(
\DateTime $start, \DateTime $start,
\DateTime $end, \DateTime $end,
int $businessStart = 1 int $businessStart = 1
) { ) : array
{
$endCurrentIndex = SmartDateTime::calculateMonthIndex((int) $end->format('m'), $businessStart); $endCurrentIndex = SmartDateTime::calculateMonthIndex((int) $end->format('m'), $businessStart);
$query = new Builder(self::$db); $query = new Builder(self::$db);
@ -67,7 +71,7 @@ class RegionMapper extends DataMapperFactory
address_country' address_country'
); );
$results = $query->execute()->fetchAll(\PDO::FETCH_ASSOC); $results = $query->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
$monthlySales = []; $monthlySales = [];
@ -113,6 +117,9 @@ class RegionMapper extends DataMapperFactory
return [$mtd, $ytd, $monthlySales]; return [$mtd, $ytd, $monthlySales];
} }
/**
* @todo Re-implement, still in use?
*/
public static function annualCustomerCountry( public static function annualCustomerCountry(
SmartDateTime $historyStart, SmartDateTime $historyStart,
\DateTime $endCurrent, \DateTime $endCurrent,
@ -144,7 +151,7 @@ class RegionMapper extends DataMapperFactory
address_country' address_country'
); );
$results = $query->execute()->fetchAll(\PDO::FETCH_ASSOC); $results = $query->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
$annualCustomer = []; $annualCustomer = [];
@ -186,6 +193,9 @@ class RegionMapper extends DataMapperFactory
return $annualCustomer; return $annualCustomer;
} }
/**
* @todo Re-implement, still in use?
*/
public static function mtdYtdClientCountry( public static function mtdYtdClientCountry(
\DateTime $startCurrent, \DateTime $startCurrent,
\DateTime $endCurrent, \DateTime $endCurrent,
@ -222,7 +232,7 @@ class RegionMapper extends DataMapperFactory
address_country ASC' address_country ASC'
); );
$results = $query->execute()->fetchAll(\PDO::FETCH_ASSOC); $results = $query->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
$oldIndex = 1; $oldIndex = 1;
$period = 1; $period = 1;
@ -293,9 +303,12 @@ class RegionMapper extends DataMapperFactory
// @todo remove businessStart, that should be baked into the historyStart // @todo remove businessStart, that should be baked into the historyStart
// Explanation: in the past I had to compare periods which weren't even business years!!! // Explanation: in the past I had to compare periods which weren't even business years!!!
/**
* @todo Re-implement, still in use?
*/
public static function salesProfitCountry( public static function salesProfitCountry(
SmartDateTime $historyStart, \DateTime $historyStart,
SmartDateTime $historyEnd, \DateTime $historyEnd,
\DateTime $currentStart, \DateTime $currentStart,
\DateTime $currentEnd \DateTime $currentEnd
) : array { ) : array {
@ -322,7 +335,7 @@ class RegionMapper extends DataMapperFactory
address_country' address_country'
); );
$results = $query->execute()->fetchAll(\PDO::FETCH_ASSOC); $results = $query->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
$sales = []; $sales = [];
$period = 0; $period = 0;
@ -354,6 +367,9 @@ class RegionMapper extends DataMapperFactory
return $sales; return $sales;
} }
/**
* @todo Re-implement, still in use?
*/
public static function mtdYtdCountry( public static function mtdYtdCountry(
\DateTime $startCurrent, \DateTime $startCurrent,
\DateTime $endCurrent, \DateTime $endCurrent,
@ -390,7 +406,7 @@ class RegionMapper extends DataMapperFactory
address_country ASC' address_country ASC'
); );
$results = $query->execute()->fetchAll(\PDO::FETCH_ASSOC); $results = $query->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
$oldIndex = 1; $oldIndex = 1;
$period = 1; $period = 1;
@ -464,6 +480,9 @@ class RegionMapper extends DataMapperFactory
]; ];
} }
/**
* @todo Re-implement, still in use?
*/
public static function countryToRegion(array $countries, array $region, array $columns) : array public static function countryToRegion(array $countries, array $region, array $columns) : array
{ {
$tempStruct = []; $tempStruct = [];
@ -472,6 +491,7 @@ class RegionMapper extends DataMapperFactory
} }
$regions = ['Other' => $tempStruct]; $regions = ['Other' => $tempStruct];
$definitions = [];
foreach ($region as $r) { foreach ($region as $r) {
$definitions[$r] = ($temp = ISO3166TwoEnum::getRegion($r)) === [] ? [$r] : $temp; $definitions[$r] = ($temp = ISO3166TwoEnum::getRegion($r)) === [] ? [$r] : $temp;
@ -500,6 +520,9 @@ class RegionMapper extends DataMapperFactory
return $regions; return $regions;
} }
/**
* @todo Re-implement, still in use?
*/
public static function countryIntervalToRegion(array $countries, array $region, array $columns) : array public static function countryIntervalToRegion(array $countries, array $region, array $columns) : array
{ {
if (empty($countries)) { if (empty($countries)) {
@ -517,6 +540,8 @@ class RegionMapper extends DataMapperFactory
'Other' => \array_fill(1, $count, $tempStruct), 'Other' => \array_fill(1, $count, $tempStruct),
]; ];
$definitions = [];
foreach ($region as $r) { foreach ($region as $r) {
$definitions[$r] = ($temp = ISO3166TwoEnum::getRegion($r)) === [] ? [$r] : $temp; $definitions[$r] = ($temp = ISO3166TwoEnum::getRegion($r)) === [] ? [$r] : $temp;
$regions[$r] = \array_fill(1, $count, $tempStruct); $regions[$r] = \array_fill(1, $count, $tempStruct);

View File

@ -13,55 +13,51 @@
declare(strict_types=1); declare(strict_types=1);
return ['SalesAnalysis' => [ return ['SalesAnalysis' => [
'ItemAttribute' => 'Item Attribute', 'ItemAttribute' => 'Item Attribute',
'ClientAttribute' => 'Client Attribute', 'ClientAttribute' => 'Client Attribute',
'Months' => 'Months', 'Months' => 'Months',
'Total' => 'Total', 'Year' => 'Year',
'Year' => 'Year', 'Month' => 'Month',
'Month' => 'Month', 'All' => 'All',
'All' => 'All', 'New' => 'New',
'New' => 'New', 'Lost' => 'Lost',
'Lost' => 'Lost', 'Continent' => 'Continent',
'Continent' => 'Continent', 'SalesPY' => 'Sales PY',
'SalesPY' => 'Sales PY', 'SalesA' => 'Sales A',
'SalesA' => 'Sales A', 'ProfitPY' => 'Profit PY',
'ProfitPY' => 'Profit PY', 'ProfitA' => 'Profit A',
'ProfitA' => 'Profit A', 'DiffPY' => 'Δ PY',
'DiffPY' => 'Δ PY', 'Actual' => 'Actual',
'Data' => 'Data', 'Segment' => 'Segment',
'Actual' => 'Actual', 'Section' => 'Section',
'Segment' => 'Segment', 'Group' => 'Group',
'Section' => 'Section', 'Region' => 'Region',
'Group' => 'Group', 'Filter' => 'Filter',
'Region' => 'Region', 'Country' => 'Country',
'Filter' => 'Filter', 'Category' => 'Category',
'Country' => 'Country', 'General' => 'General',
'Category' => 'Category', 'MTD' => 'MTD',
'General' => 'General', 'YTD' => 'YTD',
'MTD' => 'MTD', 'GrossProfit' => 'Gross Profit',
'YTD' => 'YTD', 'SalesProfit' => 'Sales / Profit',
'GrossProfit' => 'Gross Profit', 'monthly' => 'monthly',
'SalesProfit' => 'Sales / Profit', 'annually' => 'annually',
'monthly' => 'monthly', 'Profit' => 'Profit',
'annually' => 'annually', 'Start' => 'Start',
'Profit' => 'Profit', 'End' => 'End',
'Start' => 'Start', 'Sales' => 'Sales',
'End' => 'End', 'Client' => 'Client',
'Sales' => 'Sales', 'Clients' => 'Clients',
'Client' => 'Client', 'World' => 'World',
'Clients' => 'Clients', 'DomesticExport' => 'Domestic & Export',
'World' => 'World', 'Comparison' => 'Comparison',
'DomesticExport' => 'Domestic & Export', 'Continents' => 'Continents',
'Comparison' => 'Comparison', 'Data' => 'Data',
'Continents' => 'Continents', 'Domestic' => 'Domestic',
'Data' => 'Data', 'Export' => 'Export',
'Domestic' => 'Domestic', 'Current' => 'Current',
'Export' => 'Export', 'Analyze' => 'Analyze',
'Month' => 'Month', 'Regions' => 'Regions',
'Current' => 'Current', 'Total' => 'Total',
'Analyze' => 'Analyze', 'Type' => 'Type',
'Regions' => 'Regions',
'Total' => 'Total',
'Type' => 'Type',
'Year' => 'Year',
]]; ]];