mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-09-04 10:14:13 +08:00
Add Contracts Subpanel Implementation
This commit is contained in:
parent
6065c9c22a
commit
a778e0e504
4 changed files with 245 additions and 40 deletions
73
core/legacy/Statistics/SubPanelContractsRenewalDate.php
Normal file
73
core/legacy/Statistics/SubPanelContractsRenewalDate.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace App\Legacy\Statistics;
|
||||
|
||||
use App\Entity\Statistic;
|
||||
use App\Service\StatisticsProviderInterface;
|
||||
use App\Legacy\Data\PresetDataHandlers\SubpanelDataQueryHandler;
|
||||
|
||||
/**
|
||||
* Class SubPanelContractsRenewalDate
|
||||
* @package App\Legacy\Statistics
|
||||
*/
|
||||
class SubPanelContractsRenewalDate extends SubpanelDataQueryHandler implements StatisticsProviderInterface
|
||||
{
|
||||
use StatisticsHandlingTrait;
|
||||
|
||||
public const KEY = 'contracts';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getKey(): string
|
||||
{
|
||||
return self::KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getData(array $query): Statistic
|
||||
{
|
||||
$subpanel = $query['key'];
|
||||
|
||||
[$module, $id] = $this->extractContext($query);
|
||||
if (empty($module) || empty($id)) {
|
||||
return $this->getEmptyResponse(self::KEY);
|
||||
}
|
||||
|
||||
$subpanelName = $query['params']['subpanel'] ?? '';
|
||||
if (!empty($subpanelName)) {
|
||||
$subpanel = $subpanelName;
|
||||
}
|
||||
|
||||
$this->init();
|
||||
$this->startLegacyApp();
|
||||
$dateNow = date("Y-m-d");
|
||||
$contractsWhere = " aos_contracts.`end_date` >= '$dateNow' ";
|
||||
|
||||
$queries = $this->getQueries($module, $id, $subpanel);
|
||||
$parts = $queries[0];
|
||||
$parts['select'] = 'SELECT aos_contracts.`end_date`';
|
||||
if (!empty($parts['where'])) {
|
||||
$contractsWhere = " AND " . $contractsWhere;
|
||||
}
|
||||
$parts['where'] .= $contractsWhere;
|
||||
$parts['order_by'] .= 'ORDER BY aos_contracts.`end_date` ASC LIMIT 1';
|
||||
$dbQuery = $this->joinQueryParts($parts);
|
||||
$result = $this->fetchRow($dbQuery);
|
||||
|
||||
if (empty($result)) {
|
||||
$statistic = $this->getEmptyResponse(self::KEY);
|
||||
$this->close();
|
||||
|
||||
return $statistic;
|
||||
}
|
||||
|
||||
$statistic = $this->buildSingleValueResponse(self::KEY, 'date', ['value' => $result['end_date']]);
|
||||
|
||||
$this->close();
|
||||
|
||||
return $statistic;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Legacy\Statistics;
|
||||
|
||||
use App\Entity\Statistic;
|
||||
use App\Service\StatisticsProviderInterface;
|
||||
|
||||
class SubpanelContractsRenewalDate implements StatisticsProviderInterface
|
||||
{
|
||||
public const KEY = 'contracts';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getKey(): string
|
||||
{
|
||||
return self::KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getData(array $param): Statistic
|
||||
{
|
||||
|
||||
$statistic = new Statistic();
|
||||
$statistic->setId(self::KEY);
|
||||
$statistic->setData([
|
||||
'type' => 'date',
|
||||
'value' => '2021-02-15'
|
||||
]);
|
||||
|
||||
$statistic->setMetadata([
|
||||
'type' => 'single-value-statistic',
|
||||
'dataType' => 'date',
|
||||
]);
|
||||
|
||||
return $statistic;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\_mock\Mock\core\legacy\Statistics;
|
||||
|
||||
use App\Legacy\Statistics\SubPanelContractsRenewalDate;
|
||||
use App\Tests\_mock\Helpers\core\legacy\Data\DBQueryResultsMocking;
|
||||
|
||||
/**
|
||||
* Class SubPanelContractsRenewalDateMock
|
||||
* @package Mock\Core\Legacy\Statistics
|
||||
*/
|
||||
class SubPanelContractsRenewalDateMock extends SubPanelContractsRenewalDate
|
||||
{
|
||||
use DBQueryResultsMocking;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getQueries(string $parentModule, string $parentId, string $subpanel): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'select' => '',
|
||||
'where' => '',
|
||||
'order_by' => '',
|
||||
],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function fetchRow(string $query): array
|
||||
{
|
||||
return $this->getMockQueryResults();
|
||||
}
|
||||
|
||||
protected function startLegacyApp(): void
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\unit\core\legacy\Statistics;
|
||||
|
||||
use App\Legacy\ModuleNameMapperHandler;
|
||||
use App\Tests\_mock\Mock\core\legacy\Statistics\SubPanelContractsRenewalDateMock;
|
||||
use App\Tests\UnitTester;
|
||||
use Codeception\Test\Unit;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Class SubPanelContractsRenewalDateTest
|
||||
* @package App\Tests
|
||||
*/
|
||||
class SubPanelContractsRenewalDateTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @var UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* @var SubPanelContractsRenewalDateMock
|
||||
*/
|
||||
private $handler;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _before(): void
|
||||
{
|
||||
$projectDir = $this->tester->getProjectDir();
|
||||
$legacyDir = $this->tester->getLegacyDir();
|
||||
$legacySessionName = $this->tester->getLegacySessionName();
|
||||
$defaultSessionName = $this->tester->getDefaultSessionName();
|
||||
|
||||
$legacyScope = $this->tester->getLegacyScope();
|
||||
|
||||
$moduleNameMapper = new ModuleNameMapperHandler(
|
||||
$projectDir,
|
||||
$legacyDir,
|
||||
$legacySessionName,
|
||||
$defaultSessionName,
|
||||
$legacyScope
|
||||
);
|
||||
|
||||
|
||||
$this->handler = new SubPanelContractsRenewalDateMock(
|
||||
$projectDir,
|
||||
$legacyDir,
|
||||
$legacySessionName,
|
||||
$defaultSessionName,
|
||||
$legacyScope,
|
||||
$moduleNameMapper
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Unsupported context module
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUnsupportedContextModule(): void
|
||||
{
|
||||
$this->handler->reset();
|
||||
|
||||
$result = $this->handler->getData(
|
||||
[
|
||||
'key' => '',
|
||||
'context' => [
|
||||
'id' => '12345'
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
static::assertNotNull($result);
|
||||
static::assertNotNull($result->getData());
|
||||
static::assertNotNull($result->getMetadata());
|
||||
static::assertIsArray($result->getData());
|
||||
static::assertIsArray($result->getMetadata());
|
||||
static::assertEquals('contracts', $result->getId());
|
||||
static::assertArrayHasKey('type', $result->getMetadata());
|
||||
static::assertEquals('single-value-statistic', $result->getMetadata()['type']);
|
||||
static::assertArrayHasKey('dataType', $result->getMetadata());
|
||||
static::assertEquals('varchar', $result->getMetadata()['dataType']);
|
||||
static::assertArrayHasKey('value', $result->getData());
|
||||
static::assertEquals('-', $result->getData()['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Get Next Renewal Date
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testGetNextRenewalDate(): void
|
||||
{
|
||||
$this->handler->reset();
|
||||
|
||||
$rows = [
|
||||
[
|
||||
'end_date' => '12/12/2019',
|
||||
],
|
||||
];
|
||||
$this->handler->setMockQueryResult($rows);
|
||||
|
||||
$result = $this->handler->getData(
|
||||
[
|
||||
'key' => 'contracts',
|
||||
'context' => [
|
||||
'module' => 'accounts',
|
||||
'id' => '12345',
|
||||
],
|
||||
'params' => [
|
||||
'subpanel' => 'test_contracts'
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
static::assertNotNull($result);
|
||||
static::assertNotNull($result->getData());
|
||||
static::assertNotNull($result->getMetadata());
|
||||
static::assertIsArray($result->getData());
|
||||
static::assertIsArray($result->getMetadata());
|
||||
static::assertArrayHasKey('value', $result->getData());
|
||||
static::assertEquals('12/12/2019', $result->getData()['value']);
|
||||
static::assertEquals('contracts', $result->getId());
|
||||
static::assertArrayHasKey('type', $result->getMetadata());
|
||||
static::assertEquals('single-value-statistic', $result->getMetadata()['type']);
|
||||
static::assertArrayHasKey('dataType', $result->getMetadata());
|
||||
static::assertEquals('date', $result->getMetadata()['dataType']);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue