Browse Source

added column percentage of securities (by sum) in the portfolio

master
Evgeniy Ierusalimov 1 year ago
parent
commit
dbee95941c
1 changed files with 18 additions and 4 deletions
  1. 18
    4
      src/Presentation/PortfolioPresenter.php

+ 18
- 4
src/Presentation/PortfolioPresenter.php View File

10
 class PortfolioPresenter
10
 class PortfolioPresenter
11
 {
11
 {
12
     private const SecurityMapPrint = [
12
     private const SecurityMapPrint = [
13
-        ['RU000A1014L8', '(в пути)'], ['LQDT', '±'],
13
+        ['RU000A1014L8', 'RU000A107UL4', '(в пути)'], ['LQDT', 'T', '±'],
14
     ];
14
     ];
15
 
15
 
16
     private const FONT_SIZE = 12;
16
     private const FONT_SIZE = 12;
48
 
48
 
49
     public function toText(ParsedPortfolio $parsedPortfolio): string
49
     public function toText(ParsedPortfolio $parsedPortfolio): string
50
     {
50
     {
51
+        $total = $this->calcTotalSum($parsedPortfolio);
52
+
51
         $output = new BufferedOutput();
53
         $output = new BufferedOutput();
52
 
54
 
53
         $tableStyle = new TableStyle();
55
         $tableStyle = new TableStyle();
57
         $cellStyle->setPadType(STR_PAD_RIGHT);
59
         $cellStyle->setPadType(STR_PAD_RIGHT);
58
 
60
 
59
         $table = new Table($output);
61
         $table = new Table($output);
60
-        $table->setHeaderTitle("СОСТАВ: {$parsedPortfolio->getHeader()['НачПериода']} - {$parsedPortfolio->getHeader()['КонПериода']}");
62
+        $table->setHeaderTitle("ПОРТФЕЛЬ: {$parsedPortfolio->getHeader()['НачПериода']} - {$parsedPortfolio->getHeader()['КонПериода']}");
61
         $table->setHeaders([
63
         $table->setHeaders([
62
-            'ЦБ', 'Кн', 'Цн', 'Кк', 'Цк', 'Сумм'
64
+            'ЦБ', 'Кн', 'Кк', 'Цн', 'Цк', 'Сумм', '%'
63
         ]);
65
         ]);
64
 
66
 
65
         foreach ($parsedPortfolio->getDetails() as $detail) {
67
         foreach ($parsedPortfolio->getDetails() as $detail) {
66
             $table->addRow([
68
             $table->addRow([
67
                 $this->getPrintableSecurityTitle($detail),
69
                 $this->getPrintableSecurityTitle($detail),
68
                 $detail['КоличествоНО'],
70
                 $detail['КоличествоНО'],
71
+                $detail['КоличествоКО'],
69
                 $detail['НОЦена'],
72
                 $detail['НОЦена'],
70
                 //$detail['СуммаНКДНО'],
73
                 //$detail['СуммаНКДНО'],
71
-                $detail['КоличествоКО'],
72
                 $detail['КОЦена'],
74
                 $detail['КОЦена'],
73
                 round($detail['КОСумма']),
75
                 round($detail['КОСумма']),
76
+                round(100 * $detail['КОСумма'] / $total, 2),
74
             ]);
77
             ]);
75
         }
78
         }
76
 
79
 
103
         return $txt;
106
         return $txt;
104
     }
107
     }
105
 
108
 
109
+    private function calcTotalSum(ParsedPortfolio $parsedPortfolio): float
110
+    {
111
+        $total = 0.0;
112
+
113
+        foreach ($parsedPortfolio->getDetails() as $detail) {
114
+            $total += $detail['КОСумма'];
115
+        }
116
+
117
+        return $total;
118
+    }
119
+
106
     private function getPrintableSecurityTitle(array $security): string
120
     private function getPrintableSecurityTitle(array $security): string
107
     {
121
     {
108
         $security['ЦБ'] = str_replace(self::SecurityMapPrint[0], self::SecurityMapPrint[1], $security['ЦБ']);
122
         $security['ЦБ'] = str_replace(self::SecurityMapPrint[0], self::SecurityMapPrint[1], $security['ЦБ']);

Loading…
Cancel
Save