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

Loading…
Cancel
Save