-
Notifications
You must be signed in to change notification settings - Fork 1
/
iikoOlapRequest.php
100 lines (75 loc) · 2.33 KB
/
iikoOlapRequest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace iikoExchangeBundle\Library\Request;
use iikoExchangeBundle\Contract\Extensions\WithPeriodExtensionInterface;
use iikoExchangeBundle\Contract\Request\ExchangeRequestInterface;
use iikoExchangeBundle\Contract\Request\IikoRequestInterface;
use iikoExchangeBundle\ExtensionTrait\ExchangeNodeTrait;
use iikoExchangeBundle\ExtensionTrait\WithPeriodExtensionTrait;
use iikoExchangeBundle\Library\Request\iiko\Report\iikoReportFilter;
abstract class iikoOlapRequest implements IikoRequestInterface, WithPeriodExtensionInterface, ExchangeRequestInterface
{
public function __construct(string $code)
{
$this->code = $code;
}
use ExchangeNodeTrait;
use WithPeriodExtensionTrait;
const TYPE_SALES = 'SALES';
const TYPE_TRANSACTIONS = 'TRANSACTIONS';
const TYPE_DELIVERIES = 'DELIVERIES';
abstract protected function getType(): string;
public final function getPath(): string
{
return "/resto/api/v2/reports/olap";
}
public final function getMethod(): string
{
return 'POST';
}
public function getQuery(): string
{
return "";
}
public final function getBody(): array
{
return [
"reportType" => $this->getType(),
"buildSummary" => false,
"filters" => array_merge($this->getPeriodFilter(), $this->getFilters()),
"groupByRowFields" => $this->getGroupFields(),
"aggregateFields" => $this->getAggregateFields()
];
}
/**
* @return string[]
* @link
*/
abstract protected function getGroupFields(): array;
abstract protected function getAggregateFields(): array;
protected function getPeriodFilter(): array
{
return [
($this->getType() === self::TYPE_TRANSACTIONS ? \iikoExchangeBundle\Library\Request\iiko\Report\Transactions\GroupFields::DateTimeOperDayFilter : \iikoExchangeBundle\Library\Request\iiko\Report\Sales\GroupFields::OpenDateTyped) =>
iikoReportFilter::dateRange(
$this->getPeriod()->getDateFrom()->setTime(0, 0, 0)->getTimestamp(),
$this->getPeriod()->getDateTo()->modify('+1 day')->setTime(0, 0, 0)->getTimestamp(),
true, false, true)
];
}
protected function getFilters(): array
{
return [];
}
public function getHeaders(): array
{
return [
'Content-Type' => "application/json",
'Accept' => "application/json,text/plain",
'Accept-Encoding' => "gzip"
];
}
public function processResponse($data)
{
return json_decode($data, true)['data'];
}
}