|
|
@@ -13,19 +13,51 @@ class PortfolioPresenter
|
|
13
|
13
|
['RU000A1014L8'], ['LQDT'],
|
|
14
|
14
|
];
|
|
15
|
15
|
|
|
|
16
|
+ private const FONT_SIZE = 12;
|
|
|
17
|
+ private const FONT_NAME = 'droid_sans_mono';
|
|
|
18
|
+ private const COPYRIGHT_MARK = ' ©ЕИ';
|
|
|
19
|
+
|
|
16
|
20
|
private array $MapSecuritiesPrintable = [];
|
|
17
|
21
|
|
|
18
|
|
- public function toPrint(ParsedPortfolio $parsedPortfolio): string
|
|
|
22
|
+ public function toImage(ParsedPortfolio $parsedPortfolio, string $filename): void
|
|
|
23
|
+ {
|
|
|
24
|
+ $im = imagecreatetruecolor(1000, 1000);
|
|
|
25
|
+ $whitey = imagecolorallocate($im, 240, 240, 240);
|
|
|
26
|
+ $grey = imagecolorallocate($im, 48, 48, 48);
|
|
|
27
|
+ imagefill($im, 0, 0, $grey);
|
|
|
28
|
+
|
|
|
29
|
+ putenv('GDFONTPATH=' . realpath('.'));
|
|
|
30
|
+ // Замена пути к шрифту на пользовательский
|
|
|
31
|
+
|
|
|
32
|
+ $lines = explode("\n", $this->toText($parsedPortfolio));
|
|
|
33
|
+ $height = self::FONT_SIZE;
|
|
|
34
|
+ foreach ($lines as $line) {
|
|
|
35
|
+ imagefttext($im, self::FONT_SIZE, 0, 0, $height, $whitey, self::FONT_NAME, $line);
|
|
|
36
|
+ $height += self::FONT_SIZE + round(0.5 * self::FONT_SIZE);
|
|
|
37
|
+ }
|
|
|
38
|
+
|
|
|
39
|
+ $cropped = imagecropauto($im, IMG_CROP_SIDES);
|
|
|
40
|
+ if ($cropped !== false) { // in case a new image object was returned
|
|
|
41
|
+ imagedestroy($im); // we destroy the original image
|
|
|
42
|
+ $im = $cropped; // and assign the cropped image to $im
|
|
|
43
|
+ }
|
|
|
44
|
+
|
|
|
45
|
+ imagepng($im, $filename);
|
|
|
46
|
+ imagedestroy($im);
|
|
|
47
|
+ }
|
|
|
48
|
+
|
|
|
49
|
+ public function toText(ParsedPortfolio $parsedPortfolio): string
|
|
19
|
50
|
{
|
|
20
|
51
|
$output = new BufferedOutput();
|
|
21
|
52
|
|
|
22
|
53
|
$tableStyle = new TableStyle();
|
|
23
|
|
- $tableStyle->setPadType(STR_PAD_BOTH);
|
|
|
54
|
+ $tableStyle->setPadType(STR_PAD_LEFT);
|
|
24
|
55
|
|
|
25
|
|
- $table = new Table($output);
|
|
|
56
|
+ $cellStyle = new TableStyle();
|
|
|
57
|
+ $cellStyle->setPadType(STR_PAD_RIGHT);
|
|
26
|
58
|
|
|
|
59
|
+ $table = new Table($output);
|
|
27
|
60
|
$table->setHeaderTitle("СОСТАВ: {$parsedPortfolio->getHeader()['НачПериода']} - {$parsedPortfolio->getHeader()['КонПериода']}");
|
|
28
|
|
-
|
|
29
|
61
|
$table->setHeaders([
|
|
30
|
62
|
'ЦБ', 'Qн', 'Pн', 'Qк', 'Pк'
|
|
31
|
63
|
]);
|
|
|
@@ -42,15 +74,13 @@ class PortfolioPresenter
|
|
42
|
74
|
]);
|
|
43
|
75
|
}
|
|
44
|
76
|
|
|
|
77
|
+ $table->setColumnStyle(0, $cellStyle);
|
|
45
|
78
|
$table->setStyle($tableStyle)->render();
|
|
46
|
79
|
|
|
47
|
80
|
$txt = $output->fetch();
|
|
48
|
81
|
|
|
49
|
82
|
$table = new Table($output);
|
|
50
|
|
-
|
|
51
|
|
-
|
|
52
|
83
|
$table->setHeaderTitle("ДВИЖ: {$parsedPortfolio->getHeader()['НачПериода']} - {$parsedPortfolio->getHeader()['КонПериода']}");
|
|
53
|
|
-
|
|
54
|
84
|
$table->setHeaders([
|
|
55
|
85
|
'ЦБ', 'Qн', 'In', 'Out', 'Qк'
|
|
56
|
86
|
]);
|
|
|
@@ -66,8 +96,9 @@ class PortfolioPresenter
|
|
66
|
96
|
]);
|
|
67
|
97
|
}
|
|
68
|
98
|
|
|
|
99
|
+ $table->setColumnStyle(0, $cellStyle);
|
|
69
|
100
|
$table->setStyle($tableStyle)->render();
|
|
70
|
|
- $txt .= PHP_EOL . $output->fetch();
|
|
|
101
|
+ $txt .= PHP_EOL . rtrim($output->fetch()) . self::COPYRIGHT_MARK;
|
|
71
|
102
|
|
|
72
|
103
|
return $txt;
|
|
73
|
104
|
}
|