|
|
@@ -19,7 +19,8 @@ class PortfolioPresenter implements PortfolioPresenterInterface
|
|
19
|
19
|
{
|
|
20
|
20
|
}
|
|
21
|
21
|
|
|
22
|
|
- public function toText(ParsedPortfolio $parsedPortfolio): string
|
|
|
22
|
+ /** @return array<int, string> */
|
|
|
23
|
+ public function toLines(ParsedPortfolio $parsedPortfolio): array
|
|
23
|
24
|
{
|
|
24
|
25
|
$header = $parsedPortfolio->header;
|
|
25
|
26
|
$periodTitle = $header->startDate->format('d.m.y') . ' - ' . $header->endDate->format('d.m.y');
|
|
|
@@ -27,52 +28,87 @@ class PortfolioPresenter implements PortfolioPresenterInterface
|
|
27
|
28
|
$total = $this->calcTotalSum($parsedPortfolio);
|
|
28
|
29
|
|
|
29
|
30
|
$output = new BufferedOutput();
|
|
|
31
|
+ $cellStyle = $this->createCellStyle();
|
|
30
|
32
|
|
|
31
|
|
- $tableStyle = new TableStyle();
|
|
32
|
|
- $tableStyle->setPadType(STR_PAD_LEFT);
|
|
33
|
|
-
|
|
34
|
|
- $cellStyle = new TableStyle();
|
|
35
|
|
- $cellStyle->setPadType(STR_PAD_RIGHT);
|
|
36
|
|
-
|
|
37
|
|
- $table = new Table($output);
|
|
38
|
|
- $table->setHeaderTitle('ПОРТФЕЛЬ: ' . $periodTitle);
|
|
39
|
|
- $table->setHeaders(['ЦБ', 'Кол-во', 'Цн', 'Цк', 'Сумм', '%']);
|
|
40
|
|
-
|
|
|
33
|
+ $portfolioRows = [];
|
|
41
|
34
|
foreach ($parsedPortfolio->details as $detail) {
|
|
42
|
|
- $table->addRow([
|
|
|
35
|
+ $portfolioRows[] = [
|
|
43
|
36
|
$this->titleResolver->resolve($detail->security, $detail->issuer),
|
|
44
|
37
|
$this->formatQuantity($detail->quantityStart, $detail->quantityEnd),
|
|
45
|
38
|
$detail->priceStart,
|
|
46
|
39
|
$detail->priceEnd,
|
|
47
|
40
|
round((float) $detail->sumTotal),
|
|
48
|
41
|
round(100 * (float) $detail->sumTotal / $total, 2),
|
|
49
|
|
- ]);
|
|
|
42
|
+ ];
|
|
50
|
43
|
}
|
|
|
44
|
+ $lines = $this->renderTable($output, 'ПОРТФЕЛЬ: ' . $periodTitle,
|
|
|
45
|
+ ['ЦБ', 'Кол-во', 'Цн', 'Цк', 'Сумм', '%'],
|
|
|
46
|
+ $portfolioRows, $cellStyle,
|
|
|
47
|
+ );
|
|
51
|
48
|
|
|
52
|
|
- $table->setColumnStyle(0, $cellStyle);
|
|
53
|
|
- $table->setStyle($tableStyle)->render();
|
|
54
|
|
-
|
|
55
|
|
- $txt = $output->fetch();
|
|
56
|
|
-
|
|
57
|
|
- $table = new Table($output);
|
|
58
|
|
- $table->setHeaderTitle('ДВИЖ: ' . $periodTitle);
|
|
59
|
|
- $table->setHeaders(['ЦБ', 'Кн', 'In', 'Out', 'Кк']);
|
|
60
|
|
-
|
|
|
49
|
+ $movementRows = [];
|
|
61
|
50
|
foreach ($parsedPortfolio->movements as $movement) {
|
|
62
|
|
- $table->addRow([
|
|
|
51
|
+ $movementRows[] = [
|
|
63
|
52
|
$this->titleResolver->resolve($movement->security),
|
|
64
|
53
|
$movement->quantityStart,
|
|
65
|
54
|
$movement->quantityIncome > 0 ? '+' . $movement->quantityIncome : $movement->quantityIncome,
|
|
66
|
55
|
$movement->quantityOutcome > 0 ? '-' . $movement->quantityOutcome : $movement->quantityOutcome,
|
|
67
|
56
|
$movement->quantityEnd,
|
|
68
|
|
- ]);
|
|
|
57
|
+ ];
|
|
|
58
|
+ }
|
|
|
59
|
+ $mvLines = $this->renderTable($output, 'ДВИЖ: ' . $periodTitle,
|
|
|
60
|
+ ['ЦБ', 'Кн', 'In', 'Out', 'Кк'],
|
|
|
61
|
+ $movementRows, $cellStyle,
|
|
|
62
|
+ );
|
|
|
63
|
+
|
|
|
64
|
+ $lines[] = '';
|
|
|
65
|
+ foreach ($mvLines as $line) {
|
|
|
66
|
+ $lines[] = $line;
|
|
|
67
|
+ }
|
|
|
68
|
+ $lines[count($lines) - 1] = rtrim($lines[count($lines) - 1]) . self::COPYRIGHT_MARK;
|
|
|
69
|
+
|
|
|
70
|
+ return $lines;
|
|
|
71
|
+ }
|
|
|
72
|
+
|
|
|
73
|
+ public function toText(ParsedPortfolio $parsedPortfolio): string
|
|
|
74
|
+ {
|
|
|
75
|
+ return implode("\n", $this->toLines($parsedPortfolio));
|
|
|
76
|
+ }
|
|
|
77
|
+
|
|
|
78
|
+ /**
|
|
|
79
|
+ * @param array<int, array<string|int>> $rows
|
|
|
80
|
+ * @return array<int, string>
|
|
|
81
|
+ */
|
|
|
82
|
+ private function renderTable(
|
|
|
83
|
+ BufferedOutput $output,
|
|
|
84
|
+ string $title,
|
|
|
85
|
+ array $headers,
|
|
|
86
|
+ array $rows,
|
|
|
87
|
+ TableStyle $cellStyle,
|
|
|
88
|
+ ): array {
|
|
|
89
|
+ $table = new Table($output);
|
|
|
90
|
+ $table->setHeaderTitle($title);
|
|
|
91
|
+ $table->setHeaders($headers);
|
|
|
92
|
+
|
|
|
93
|
+ foreach ($rows as $row) {
|
|
|
94
|
+ $table->addRow($row);
|
|
69
|
95
|
}
|
|
70
|
96
|
|
|
71
|
97
|
$table->setColumnStyle(0, $cellStyle);
|
|
72
|
|
- $table->setStyle($tableStyle)->render();
|
|
73
|
|
- $txt .= PHP_EOL . rtrim($output->fetch()) . self::COPYRIGHT_MARK;
|
|
74
|
98
|
|
|
75
|
|
- return $txt;
|
|
|
99
|
+ $padStyle = new TableStyle();
|
|
|
100
|
+ $padStyle->setPadType(STR_PAD_LEFT);
|
|
|
101
|
+ $table->setStyle($padStyle)->render();
|
|
|
102
|
+
|
|
|
103
|
+ return explode("\n", rtrim($output->fetch()));
|
|
|
104
|
+ }
|
|
|
105
|
+
|
|
|
106
|
+ private function createCellStyle(): TableStyle
|
|
|
107
|
+ {
|
|
|
108
|
+ $style = new TableStyle();
|
|
|
109
|
+ $style->setPadType(STR_PAD_RIGHT);
|
|
|
110
|
+
|
|
|
111
|
+ return $style;
|
|
76
|
112
|
}
|
|
77
|
113
|
|
|
78
|
114
|
private function calcTotalSum(ParsedPortfolio $parsedPortfolio): float
|