Browse Source

sql schema updated + query optimization + configuration extended

Francesco Arcarese 1 year ago
parent
commit
c683acd29c
44 changed files with 470 additions and 421 deletions
  1. 1
    0
      README.md
  2. 10
    1
      client.ini.dist
  3. 8
    7
      config/app.php
  4. 16
    16
      config/routes.php
  5. 23
    16
      sql/prosume.sql
  6. 7
    7
      src/Controller/ApiController.php
  7. 9
    3
      src/Controller/AppController.php
  8. 19
    19
      src/Controller/MainController.php
  9. 11
    11
      src/Controller/SSPController.php
  10. 8
    8
      src/Controller/UsersController.php
  11. 18
    24
      src/Controller/XhrController.php
  12. 1
    1
      src/Model/Entity/User.php
  13. 9
    9
      src/Template/Element/Eprosume/Views/charts.ctp
  14. 50
    29
      src/Template/Element/Eprosume/Views/datatable.ctp
  15. 4
    4
      src/Template/Element/Eprosume/Views/set_price.ctp
  16. 1
    1
      src/Template/Element/Eprosume/Views/transfer.ctp
  17. 5
    5
      src/Template/Element/Eprosume/dataTableToolbar.ctp
  18. 1
    1
      src/Template/Element/Eprosume/footer.ctp
  19. 1
    1
      src/Template/Element/Eprosume/header.ctp
  20. 11
    13
      src/Template/Element/Eprosume/leftSideColumn.ctp
  21. 4
    5
      src/Template/Element/Eprosume/mainHeader.ctp
  22. 1
    1
      src/Template/Eprosume/standard.ctp
  23. 1
    1
      src/Template/Main/block_i_d.ctp
  24. 1
    2
      src/Template/Main/charts.ctp
  25. 1
    1
      src/Template/Main/history.ctp
  26. 7
    7
      src/Template/Main/history_daily.ctp
  27. 6
    6
      src/Template/Main/history_hgm.ctp
  28. 13
    12
      src/Template/Main/meter.ctp
  29. 11
    10
      src/Template/Main/meter_i_d.ctp
  30. 1
    1
      src/Template/Main/payment.ctp
  31. 1
    1
      src/Template/Main/price_history.ctp
  32. 1
    1
      src/Template/Main/profile.ctp
  33. 2
    2
      src/Template/Main/set_price.ctp
  34. 2
    2
      src/Template/Main/transfer.ctp
  35. 4
    4
      src/Template/Users/add.ctp
  36. 4
    4
      src/Template/Users/edit.ctp
  37. 3
    3
      src/Template/Users/index.ctp
  38. 1
    1
      src/Template/Users/login.ctp
  39. 1
    1
      src/Template/Users/view.ctp
  40. 118
    126
      src/Utility/EprosumeModel.php
  41. 14
    4
      src/Utility/WalletEprosumeModel.php
  42. 0
    0
      tests/Fixture/empty
  43. 25
    27
      webroot/css/eprosume.css
  44. 35
    23
      webroot/readhistory.php

+ 1
- 0
README.md View File

@@ -46,6 +46,7 @@ An example of Nginx configuration could be
46 46
 
47 47
 ## Configuration
48 48
 - `./client.ini.dist` has to be copied as `client.ini` and the 3 variables of the wallet group has to be changed setting the path to the utility account key, the path of configuration file in YAML format and the path of the prosume-cli executable. Change also the databaseb settings in the related group.
49
+If the `charts` value is set to 1, the charts of payment data will be displayed in the balance page of each meter. 
49 50
 - in the database table `conf` change as needed the values accordingly to your needs pointing out the name of the utility account and the settings for the automatic top ups for both PRS and TFT tokens.
50 51
 - `./logs/` and `./tmp` directory must be writable by the user that run the web server.
51 52
 

+ 10
- 1
client.ini.dist View File

@@ -1,5 +1,14 @@
1 1
 ;<?php
2 2
 ;die();
3
+;/*
4
+[app]
5
+charts=0
6
+debug=0
7
+logotype=short_name_of_the_project
8
+name=name_of_the_project
9
+short=name_or_icon_or_html_for_mobile_menu
10
+utility_account=name_of_the_utility_account
11
+[db]
3 12
 charset=utf8mb4
4 13
 host=localhost
5 14
 name=dbname
@@ -10,4 +19,4 @@ account = /path/to/utility_account.txt
10 19
 configuration = /path/to/configuration_file.yaml
11 20
 executable = /path/to/cli_executable
12 21
 ;*/
13
-;?>
22
+;?>

+ 8
- 7
config/app.php View File

@@ -1,10 +1,11 @@
1 1
 <?php
2
-$ini = parse_ini_file(dirname(__FILE__).'/../client.ini', true);
3
-$host = $ini['database']['host'] ?? null;
4
-$db   = $ini['database']['name'] ?? null;
5
-$user = $ini['database']['user'] ?? null;
6
-$pass = $ini['database']['pass'] ?? null;
7
-$charset = $ini['database']['charset'] ?? null;
2
+$conf = parse_ini_file(dirname(__FILE__).'/../client.ini', true);
3
+$debug = (bool)$conf['app']['debug'] ?? false; 
4
+$host = $conf['db']['host'] ?? null;
5
+$db   = $conf['db']['name'] ?? null;
6
+$user = $conf['db']['user'] ?? null;
7
+$pass = $conf['db']['password'] ?? null;
8
+$charset = $conf['db']['charset'] ?? null;
8 9
 
9 10
 return [
10 11
     /**
@@ -16,7 +17,7 @@ return [
16 17
      * Development Mode:
17 18
      * true: Errors and warnings shown.
18 19
      */
19
-    'debug' => filter_var(env('DEBUG', false), FILTER_VALIDATE_BOOLEAN),
20
+    'debug' => filter_var(env('DEBUG', $debug), FILTER_VALIDATE_BOOLEAN),
20 21
 
21 22
     /**
22 23
      * Configure basic information about the application.

+ 16
- 16
config/routes.php View File

@@ -60,30 +60,30 @@ Router::scope('/', function (RouteBuilder $routes) {
60 60
     // $routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
61 61
 
62 62
     $routes->connect('/', ['controller' => 'Main', 'action' => 'history']);
63
-    $routes->scope('/gridability', function ($routes) {
63
+    $routes->scope('/web', function ($routes) {
64 64
         $routes->applyMiddleware('csrf');
65 65
         $routes->connect('/', ['controller' => 'Main', 'action' => 'history']);
66 66
         $routes->connect('/history', ['controller' => 'Main', 'action' => 'history']);
67
-        $routes->connect('/history/:hgm_id', ['controller' => 'Main', 'action' => 'historyHgm']
68
-            ,['pass' =>['hgm_id']]);
67
+        $routes->connect('/history/:meter_id', ['controller' => 'Main', 'action' => 'historyMeter']
68
+            ,['pass' =>['meter_id']]);
69 69
 
70 70
         $routes->connect('/history/daily', ['controller' => 'Main', 'action' => 'historyDaily']);
71
-        $routes->connect('/history/daily/:hgm_id', ['controller' => 'Main', 'action' => 'historyHgmDaily']
72
-            ,['pass' =>['hgm_id']]);
71
+        $routes->connect('/history/daily/:meter_id', ['controller' => 'Main', 'action' => 'historyMeterDaily']
72
+            ,['pass' =>['meter_id']]);
73 73
 
74 74
         $routes->connect('/history/monthly', ['controller' => 'Main', 'action' => 'historyMonthly']);
75
-        $routes->connect('/history/monthly/:hgm_id', ['controller' => 'Main', 'action' => 'historyHgmMonthly']
76
-            ,['pass' =>['hgm_id']]);
75
+        $routes->connect('/history/monthly/:meter_id', ['controller' => 'Main', 'action' => 'historyMeterMonthly']
76
+            ,['pass' =>['meter_id']]);
77 77
 
78
-        $routes->connect('/balance', ['controller' => 'Main', 'action' => 'hgm']);
79
-        $routes->connect('/balance/:hgm_id', ['controller' => 'Main', 'action' => 'hgmID']
80
-            ,['pass' =>['hgm_id']]);
78
+        $routes->connect('/meter', ['controller' => 'Main', 'action' => 'meter']);
79
+        $routes->connect('/meter/:meter_id', ['controller' => 'Main', 'action' => 'meterID']
80
+            ,['pass' =>['meter_id']]);
81 81
 
82 82
         $routes->connect('/block/:block_id', ['controller' => 'Main', 'action' => 'blockID']
83 83
             ,['pass' =>['block_id']]);
84 84
 
85 85
         $routes->connect('/history/price', ['controller' => 'Main', 'action' => 'priceHistory']);
86
-        $routes->connect('/history/price/:hgm_id', ['controller' => 'Main', 'action' => 'priceHistoryHGM'],['pass' =>['hgm_id']]);
86
+        $routes->connect('/history/price/:meter_id', ['controller' => 'Main', 'action' => 'priceHistoryMeter'],['pass' =>['meter_id']]);
87 87
 
88 88
         $routes->connect('/payment', ['controller' => 'Main', 'action' => 'payment']);
89 89
 
@@ -112,8 +112,8 @@ Router::scope('/', function (RouteBuilder $routes) {
112 112
 
113 113
         $routes->connect('balances', ['controller' => 'Xhr', 'action' => 'balances']);
114 114
 
115
-        $routes->connect('charts/payments/:hgm_name', ['controller' => 'Xhr', 'action' => 'chartsPayments']
116
-            ,['pass' =>['hgm_name']]);
115
+        $routes->connect('charts/payments/:meter_name', ['controller' => 'Xhr', 'action' => 'chartsPayments']
116
+            ,['pass' =>['meter_name']]);
117 117
 
118 118
     });
119 119
 
@@ -131,9 +131,9 @@ Router::scope('/', function (RouteBuilder $routes) {
131 131
         $routes->connect('/block/:block_id', ['controller' => 'Api', 'action' => 'blockID']
132 132
         ,['pass' =>['block_id']]);
133 133
     
134
-        $routes->connect('balance', ['controller' => 'Api', 'action' => 'hgm']);
135
-        $routes->connect('balance/:hgm_id', ['controller' => 'Api', 'action' => 'hgmID']
136
-            ,['pass' =>['hgm_id']]);
134
+        $routes->connect('meter', ['controller' => 'Api', 'action' => 'meter']);
135
+        $routes->connect('meter/:meter_id', ['controller' => 'Api', 'action' => 'meterID']
136
+            ,['pass' =>['meter_id']]);
137 137
 
138 138
         $routes->connect('balances', ['controller' => 'Api', 'action' => 'balances']);
139 139
     });

+ 23
- 16
sql/prosume.sql View File

@@ -19,12 +19,11 @@ DROP TABLE IF EXISTS `balances`;
19 19
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
20 20
 /*!40101 SET character_set_client = utf8 */;
21 21
 CREATE TABLE `balances` (
22
-  `hgm_id` int(11) NOT NULL,
22
+  `meter_id` int(11) NOT NULL,
23 23
   `prs` double DEFAULT NULL,
24 24
   `tft` double DEFAULT NULL,
25
-  `timestamp` datetime NOT NULL DEFAULT current_timestamp(),
26
-  KEY `hgm_id` (`hgm_id`),
27
-  CONSTRAINT `balances_ibfk_1` FOREIGN KEY (`hgm_id`) REFERENCES `hgm` (`id`)
25
+  `timestamp` datetime NOT NULL,
26
+  KEY `meter_id` (`meter_id`)
28 27
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
29 28
 /*!40101 SET character_set_client = @saved_cs_client */;
30 29
 
@@ -32,9 +31,6 @@ CREATE TABLE `balances` (
32 31
 -- Table structure for table `blocks`
33 32
 --
34 33
 
35
-DROP TABLE IF EXISTS `blocks`;
36
-/*!40101 SET @saved_cs_client     = @@character_set_client */;
37
-/*!40101 SET character_set_client = utf8 */;
38 34
 CREATE TABLE `blocks` (
39 35
   `id` int(11) NOT NULL AUTO_INCREMENT,
40 36
   `blocknumber` int(11) DEFAULT NULL,
@@ -46,15 +42,24 @@ CREATE TABLE `blocks` (
46 42
   `timestamp` datetime DEFAULT NULL,
47 43
   `memo_hash` char(32) DEFAULT NULL,
48 44
   `tx_id` char(32) DEFAULT NULL,
49
-  `type` enum('measure','payment','transfer') DEFAULT NULL,
45
+  `type` enum('measure','payment','transfer','update_price') DEFAULT NULL,
50 46
   `purchased_sold` double DEFAULT NULL,
51 47
   `buy_price` double DEFAULT NULL,
52 48
   `sell_price` double DEFAULT NULL,
49
+  `day` date GENERATED ALWAYS AS (cast(`timestamp` as date)) STORED,
50
+  `mon` tinyint(4) unsigned GENERATED ALWAYS AS (month(`timestamp`)) STORED,
51
+  `yea` smallint(5) unsigned GENERATED ALWAYS AS (year(`timestamp`)) STORED,
53 52
   PRIMARY KEY (`id`),
54
-  KEY `blocknumber_timestamp_asset_wallet_from_wallet_to` (`blocknumber`,`timestamp`,`asset`,`wallet_from`,`wallet_to`,`memo_hash`)
55
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
56
-/*!40101 SET character_set_client = @saved_cs_client */;
57
-
53
+  KEY `ts` (`timestamp`),
54
+  KEY `txid` (`tx_id`),
55
+  KEY `day` (`day`),
56
+  KEY `idx1` (`day`,`wallet_from`,`wallet_to`,`asset`,`type`),
57
+  KEY `mon` (`mon`),
58
+  KEY `yea` (`yea`),
59
+  KEY `idx2` (`yea`,`mon`,`wallet_from`,`wallet_to`,`asset`,`type`),
60
+  KEY `idx3` (`type`),
61
+  KEY `idx4` (`wallet_from`,`wallet_to`)
62
+) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
58 63
 --
59 64
 -- Table structure for table `conf`
60 65
 --
@@ -78,22 +83,23 @@ INSERT INTO `conf` VALUES
78 83
 ('topup_tft_memo','Automatic TFT top up');
79 84
 
80 85
 --
86
+-- Table structure for table `meter`
81 87
 --
82 88
 
83
-DROP TABLE IF EXISTS `hgm`;
89
+DROP TABLE IF EXISTS `meter`;
84 90
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
85 91
 /*!40101 SET character_set_client = utf8 */;
86
-CREATE TABLE `hgm` (
92
+CREATE TABLE `meter` (
87 93
   `id` int(11) NOT NULL AUTO_INCREMENT,
88 94
   `name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
95
+  `location` varchar(255) COLLATE utf8mb4_unicode_ci NULL,
89 96
   `status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'ACTIVE' COMMENT 'Possible status are ACTIVE HIDDEN DELETED SUSPENDED',
90 97
   `subid` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
91 98
   `buy` double DEFAULT 0.1,
92 99
   `sell` double DEFAULT 0.1,
93 100
   `prs` double DEFAULT NULL,
94 101
   `tft` double DEFAULT NULL,
95
-  `timestamp` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
102
+  `timestamp` datetime DEFAULT current_timestamp(),
96 103
   PRIMARY KEY (`id`),
97 104
   UNIQUE KEY `name` (`name`)
98 105
 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
@@ -145,7 +151,7 @@ CREATE TABLE `users` (
145 151
   `role` varchar(20) DEFAULT NULL,
146 152
   `created` datetime DEFAULT NULL,
147 153
   `modified` datetime DEFAULT NULL,
148
-  `hgm_id` int(11) DEFAULT NULL,
154
+  `meter_id` int(11) DEFAULT NULL,
149 155
   PRIMARY KEY (`id`)
150 156
 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
151 157
 

+ 7
- 7
src/Controller/ApiController.php View File

@@ -73,7 +73,7 @@ class ApiController extends SSPController
73 73
             ;
74 74
     }
75 75
 
76
-    public function hgm()
76
+    public function meter()
77 77
     {
78 78
         return $this->response
79 79
             ->withStatus(200)
@@ -82,7 +82,7 @@ class ApiController extends SSPController
82 82
                 json_encode(
83 83
                     array_values(
84 84
                         array_replace_recursive(
85
-                            $this->EprosumeModel->hgmList(),
85
+                            $this->EprosumeModel->meterList(),
86 86
                             $this->EprosumeModel->actualPrice([])
87 87
                         )    
88 88
                     )    
@@ -91,7 +91,7 @@ class ApiController extends SSPController
91 91
         ;        
92 92
     }
93 93
 
94
-    public function hgmID($hgm_id)
94
+    public function meterID($meter_id)
95 95
     {
96 96
         return $this->response
97 97
             ->withStatus(200)
@@ -99,8 +99,8 @@ class ApiController extends SSPController
99 99
             ->withStringBody(
100 100
                 json_encode(
101 101
                     array_merge(
102
-                        $this->EprosumeModel->balanceHGM($hgm_id),
103
-                        $this->EprosumeModel->actualPrice($hgm_id)[$hgm_id] ?? []
102
+                        $this->EprosumeModel->balanceMeter($meter_id),
103
+                        $this->EprosumeModel->actualPrice($meter_id)[$meter_id] ?? []
104 104
                     )
105 105
                 )
106 106
             )
@@ -112,7 +112,7 @@ class ApiController extends SSPController
112 112
         if( $this->request->getEnv('REQUEST_METHOD') == "POST") {
113 113
             $request = $this->getRequestInput();
114 114
             return $this->doTransfer(
115
-                $request["hgm"] ?? null, 
115
+                $request["meter"] ?? null, 
116 116
                 $request["amount"] ?? null, 
117 117
                 $request["asset"] ?? null, 
118 118
                 $request["memo"] ?? null
@@ -127,7 +127,7 @@ class ApiController extends SSPController
127 127
         if( $this->request->getEnv('REQUEST_METHOD') == "POST") {
128 128
             $request = $this->getRequestInput();
129 129
             return $this->doSetPrice(
130
-                $request["hgm"] ?? null, 
130
+                $request["meter"] ?? null, 
131 131
                 $request["buyPrice"] ?? null, 
132 132
                 $request["sellPrice"] ?? null
133 133
             );

+ 9
- 3
src/Controller/AppController.php View File

@@ -58,6 +58,12 @@ class AppController extends Controller
58 58
                 'action' => 'login'
59 59
             ]
60 60
         ]);
61
+        $conf = parse_ini_file(dirname(__FILE__).'/../../client.ini', true);
62
+        $this->set('app_charts', ((bool)$conf['app']['charts'] ?? false));
63
+        $this->set('app_logotype', ($conf['app']['logotype'] ?? null));
64
+        $this->set('app_name', ($conf['app']['name'] ?? null));
65
+        $this->set('app_short', ($conf['app']['short'] ?? null));
66
+        $this->set('utility_account', ($conf['app']['utility_account'] ?? null));
61 67
 
62 68
         /*
63 69
          * Enable the following component for recommended CakePHP security settings.
@@ -68,13 +74,13 @@ class AppController extends Controller
68 74
 
69 75
     public function beforeFilter(Event $event)
70 76
     {
71
-        $this->Auth->allow(['login', 'logout', 'history', 'payment', 'hgm', 'priceHistory', 'blockID', 'hgmID', 'chartsPayments']);
77
+        $this->Auth->allow(['login', 'logout']);
72 78
     }
73 79
 
74 80
     public function beforeRender(Event $event)
75 81
     {
76
-        $this->set('role', $this->Auth->user()['role'] ?? false);
77
-        $this->set('user_hgm_id', $this->Auth->user()['hgm_id'] ?? 0);
82
+	$this->set('role', $this->Auth->user()['role'] ?? false);
83
+        $this->set('user_meter_id', $this->Auth->user()['meter_id'] ?? 0);
78 84
     }
79 85
 
80 86
     public function isAuthorized($user)

+ 19
- 19
src/Controller/MainController.php View File

@@ -27,7 +27,7 @@ class MainController extends AppController
27 27
     {
28 28
         $user = $this->Auth->user();
29 29
         $this->set(['blocks' => []]);
30
-        $this->set(['prosumers' => $this->WalletEprosumeModel->getProsumers(false, $user["hgm_id"])]); 
30
+        $this->set(['prosumers' => $this->WalletEprosumeModel->getProsumers(false, $user["meter_id"])]); 
31 31
     }
32 32
 
33 33
     public function historyDaily()
@@ -37,15 +37,15 @@ class MainController extends AppController
37 37
         );
38 38
     }
39 39
 
40
-    public function hgm()
40
+    public function meter()
41 41
     {
42 42
         $user = $this->Auth->user();
43 43
         $role = $user["role"] ?? null;
44 44
         if($role && $role != "admin") {
45
-            $_ = $this->EprosumeModel->hgmList($user["hgm_id"]);
46
-            return $this->redirect( (($_["name"] ?? null) ? '/gridability/balance/'.$_["name"] : '/' ) );
45
+            $_ = $this->EprosumeModel->meterList($user["meter_id"]);
46
+            return $this->redirect( (($_["name"] ?? null) ? '/web/balance/'.$_["name"] : '/' ) );
47 47
         }
48
-        $this->set(['hgmList' => $this->EprosumeModel->hgmList()]);
48
+        $this->set(['meterList' => $this->EprosumeModel->meterList()]);
49 49
         $this->set(['prices' => $this->EprosumeModel->actualPrice([])]);
50 50
     }
51 51
 
@@ -54,37 +54,37 @@ class MainController extends AppController
54 54
         $this->history();
55 55
     }
56 56
 
57
-    public function payment($hgm_id = null)
57
+    public function payment($meter_id = null)
58 58
     {
59 59
         $user = $this->Auth->user();
60 60
         $this->set(['blocks' => []]);
61
-        $this->set(['hgm_id' => $hgm_id]);
62
-        $this->set(['prosumers' => $this->WalletEprosumeModel->getProsumers(false, $user["hgm_id"])]); 
61
+        $this->set(['meter_id' => $meter_id]);
62
+        $this->set(['prosumers' => $this->WalletEprosumeModel->getProsumers(false, $user["meter_id"])]); 
63 63
     }
64 64
 
65
-    public function historyHgm($hgm_id)
65
+    public function historyMeter($meter_id)
66 66
     {
67
-        $this->history(['wallet' => $hgm_id]);
68
-        $this->set(['hgm_id' => $hgm_id]);
67
+        $this->history(['wallet' => $meter_id]);
68
+        $this->set(['meter_id' => $meter_id]);
69 69
     }
70 70
 
71 71
     public function blockID($block_id) {
72 72
         $this->set(['block' => $this->EprosumeModel->blocksList(['id' => $block_id])->current()]);
73 73
     }
74 74
 
75
-    public function hgmID($hgm_id)
75
+    public function meterID($meter_id)
76 76
     {
77 77
         $user = $this->Auth->user();
78 78
         $role = $user["role"] ?? null;
79 79
         if($role && $role != "admin") {
80
-            $_ = $this->EprosumeModel->hgmList($user["hgm_id"]);
81
-            if(($_["name"] ?? null) != $hgm_id) {
80
+            $_ = $this->EprosumeModel->meterList($user["meter_id"]);
81
+            if(($_["name"] ?? null) != $meter_id) {
82 82
                 return $this->redirect('/');
83 83
             }
84 84
         }
85
-        $this->set(['balance' => $this->EprosumeModel->balanceHGM($hgm_id)]);
85
+        $this->set(['balance' => $this->EprosumeModel->balanceMeter($meter_id)]);
86 86
         $this->set(['prices' => $this->EprosumeModel->actualPrice([])]);
87
-        $this->set(['hgm_id' => $hgm_id]);
87
+        $this->set(['meter_id' => $meter_id]);
88 88
         $this->set(['utility_account' => $this->EprosumeModel->getUtilityAccount()]);
89 89
     }
90 90
 
@@ -135,15 +135,15 @@ class MainController extends AppController
135 135
     {
136 136
         $user = $this->Auth->user();
137 137
         $role = $user['role'] ?? null;
138
-        $user_hgm_id = $user["hgm_id"] ?? null;
139
-        if(!$role || !$user_hgm_id) {
138
+        $user_meter_id = $user["meter_id"] ?? null;
139
+        if(!$role || !$user_meter_id) {
140 140
             return $this->redirect('/');
141 141
         }
142 142
         $this->set(
143 143
             [
144 144
                 'assets' => $this->EprosumeModel->getAssetsType(),
145 145
                 'prosumers' => (function() use($user) {
146
-                    $_ = $this->WalletEprosumeModel->getProsumers(false, $user["hgm_id"]); 
146
+                    $_ = $this->WalletEprosumeModel->getProsumers(false, $user["meter_id"]); 
147 147
                     $prosumers = array_combine(
148 148
                         array_values($_),
149 149
                         $_

+ 11
- 11
src/Controller/SSPController.php View File

@@ -82,15 +82,15 @@ abstract class SSPController extends AppController
82 82
         $asset = $qs["asset"] ?? null;
83 83
         $date_from = $qs["from"] ?? (new \DateTime())->sub(new \DateInterval("P1D"))->format("Y-m-d H:i:s");
84 84
         $date_to = $qs["to"] ?? (new \DateTime())->format("Y-m-d H:i:s");
85
-        $hgm = $qs["hgm"] ?? null; 
85
+        $meter = $qs["meter"] ?? null; 
86 86
         $filters = [
87 87
             'date_from' => $date_from,
88 88
             'date_to' => $date_to,
89
-            'hgm' => $hgm,
89
+            'meter' => $meter,
90 90
             'asset' => $asset,
91 91
         ];
92 92
         $asset && $filters['asset'] = $asset;
93
-        $hgm && $filters['hgm'] = $hgm;
93
+        $meter && $filters['meter'] = $meter;
94 94
 
95 95
         $blocks = $this->EprosumeModel->blocksList(
96 96
             $filters
@@ -115,9 +115,9 @@ abstract class SSPController extends AppController
115 115
         $qs = $this->request->getAttribute('params')["?"] ?? [];
116 116
         $date_from = $qs["from"] ?? (new \DateTime())->sub(new \DateInterval("P1D"))->format("Y-m-d H:i:s");
117 117
         $date_to = $qs["to"] ?? (new \DateTime())->format("Y-m-d H:i:s");
118
-        $hgm = $qs["hgm"] ?? null; 
118
+        $meter = $qs["meter"] ?? null; 
119 119
 
120
-        $balances = $this->EprosumeModel->balanceHistory($date_from, $date_to, $hgm);
120
+        $balances = $this->EprosumeModel->balanceHistory($date_from, $date_to, $meter);
121 121
         return $balances
122 122
             ? $this->response
123 123
                 ->withStatus(200)
@@ -134,12 +134,12 @@ abstract class SSPController extends AppController
134 134
             ;
135 135
     }
136 136
 
137
-    public function charts($type, $hgm_name) {
137
+    public function charts($type, $meter_name) {
138 138
         $qs = $this->request->getAttribute('params')["?"] ?? $queryString; 
139 139
         $period = $qs['period'] ?? 0;
140 140
         $from = $qs['from'] ?? null;
141 141
         $to = $qs['to'] ?? null;
142
-        $data = $this->EprosumeModel->charts($type, $hgm_name, $from, $to, $period);
142
+        $data = $this->EprosumeModel->charts($type, $meter_name, $from, $to, $period);
143 143
         return $data
144 144
             ? $this->response
145 145
                 ->withStatus(200)
@@ -156,7 +156,7 @@ abstract class SSPController extends AppController
156 156
             ;
157 157
     }
158 158
 
159
-    protected function SSPResponse($dataset, $user_hgm_id=null, array $queryString = [])
159
+    protected function SSPResponse($dataset, $user_meter_id=null, array $queryString = [])
160 160
     {
161 161
         $this->autoRender = false;
162 162
         $qs = $this->request->getAttribute('params')["?"] ?? $queryString; 
@@ -167,17 +167,17 @@ abstract class SSPController extends AppController
167 167
             unset($qs["start"], $qs["length"]);
168 168
         }
169 169
 
170
-        $qs["user_hgm_id"] = $user_hgm_id;
170
+        $qs["user_meter_id"] = $user_meter_id;
171 171
         $results = $this->EprosumeModel->dataTableSSP(
172 172
             $dataset, 
173
-            $qs["user_hgm_id"],
173
+            $qs["user_meter_id"],
174 174
             ($qs["draw"] ?? 1), 
175 175
             ($qs["columns"] ?? [["data"=>"timestamp"]]),
176 176
             ($qs["order"] ?? [["column"=>0,"dir"=>"desc"]]),
177 177
             ($qs["start"] ?? null), 
178 178
             ($qs["length"] ?? null),
179 179
             ($qs["search"] ?? null),
180
-            ($qs["hgm"] ?? null),
180
+            ($qs["meter"] ?? null),
181 181
             ($qs["txid"] ?? null),
182 182
             ($qs["from"] ?? null),
183 183
             ($qs["to"] ?? null),

+ 8
- 8
src/Controller/UsersController.php View File

@@ -26,7 +26,7 @@ class UsersController extends AppController
26 26
         $users = $this->paginate($this->Users);
27 27
 
28 28
         $this->set(compact('users'));
29
-        $this->set(['hgmList' => $this->getHgmList()]);
29
+        $this->set(['meterList' => $this->getMeterList()]);
30 30
     }
31 31
 
32 32
     /**
@@ -63,7 +63,7 @@ class UsersController extends AppController
63 63
             $this->Flash->error(__('The user could not be saved. Please, try again.'));
64 64
         }
65 65
         $this->set(compact('user'));
66
-        $this->set(['hgmList' => $this->getHgmList()]);
66
+        $this->set(['meterList' => $this->getMeterList()]);
67 67
     }
68 68
 
69 69
     /**
@@ -88,7 +88,7 @@ class UsersController extends AppController
88 88
             $this->Flash->error(__('The user could not be saved. Please, try again.'));
89 89
         }
90 90
         $this->set(compact('user'));
91
-        $this->set(['hgmList' => $this->getHgmList()]);
91
+        $this->set(['meterList' => $this->getMeterList()]);
92 92
     }
93 93
 
94 94
     /**
@@ -141,19 +141,19 @@ class UsersController extends AppController
141 141
             || $user["role"] === "admin";
142 142
     }
143 143
 
144
-    private function getHgmList() {
144
+    private function getMeterList() {
145 145
         $EprosumeModel = new EprosumeModel();
146
-        $hgmList = $EprosumeModel->hgmList();
146
+        $meterList = $EprosumeModel->meterList();
147 147
         return array_combine(
148 148
             array_map(
149 149
                 function($el) { 
150 150
                     return $el["id"];
151
-                },  $hgmList
151
+                },  $meterList
152 152
             ),
153 153
             array_map(
154 154
                 function($el) { 
155
-                    return $el["hgm"];
156
-                },  $hgmList
155
+                    return $el["meter"];
156
+                },  $meterList
157 157
             )
158 158
         );
159 159
     }

+ 18
- 24
src/Controller/XhrController.php View File

@@ -14,15 +14,15 @@ class XhrController extends SSPController
14 14
                 return $this->response
15 15
                     ->withStatus(401);
16 16
             }
17
-            $_ = $this->EprosumeModel->hgmList($user["hgm_id"]);
17
+            $_ = $this->EprosumeModel->meterList($user["meter_id"]);
18 18
 	    $role = $user["role"] ?? null;
19
-            $hgm_name = $_["name"] ?? null;
20
-            if(!$hgm_name) {
19
+            $meter_name = $_["name"] ?? null;
20
+            if(!$meter_name) {
21 21
                 return $this->response
22 22
                 ->withStatus(403);
23 23
             }
24 24
             return $this->doTransfer(
25
-                $hgm_name,
25
+                $meter_name,
26 26
                 $request["prosumer"] ?? null, 
27 27
                 $request["amount"] ?? null, 
28 28
                 $request["asset"] ?? null, 
@@ -74,38 +74,32 @@ class XhrController extends SSPController
74 74
 
75 75
     public function setResponse($SSPResponse)
76 76
     {
77
-        /*
78 77
         if(!$user = $this->Auth->user())
79 78
         {
80 79
             return $this->response
81 80
                 ->withStatus(401);
82 81
         }
83
-        */
84
-        if( $this->request->is('ajax') ) {
85
-            $hgm_id = $user["hgm_id"] ?? 1;
86
-            $_ = $this->EprosumeModel->hgmList($hgm_id);
87
-            $role = $user["role"] ?? null;
88
-            if($role == "admin") {
89
-                $hgm_name = null;    
90
-            } else {
91
-                $hgm_name = $_["name"] ?? $this->EprosumeModel->getUtilityAccount();
92
-                if(!$hgm_name) {
93
-                    return $this->response
94
-                    ->withStatus(403);
95
-                }
96
-            }
97
-            return $this->SSPResponse($SSPResponse, $hgm_name);
82
+        $_ = $this->EprosumeModel->meterList($user["meter_id"]);
83
+        $role = $user["role"] ?? null;
84
+        if($role == "admin") {
85
+            $meter_name = null;    
98 86
         } else {
99
-            return null;
87
+            $meter_name = $_["name"] ?? null;
88
+            if(!$meter_name) {
89
+                return $this->response
90
+                ->withStatus(403);
91
+            }
100 92
         }
93
+        return $this->SSPResponse($SSPResponse, $meter_name);
101 94
     }
102 95
 
103
-    public function chartsPayments($hgm_name)
96
+    public function chartsPayments($meter_name)
104 97
     {
105 98
         if( $this->request->is('ajax') ) {
106
-            return $this->charts('payments', $hgm_name);        
99
+            return $this->charts('payments', $meter_name);        
107 100
         } else {
108 101
             return null;
109 102
         }
110 103
     }
111
-}
104
+
105
+}

+ 1
- 1
src/Model/Entity/User.php View File

@@ -32,7 +32,7 @@ class User extends Entity
32 32
         'password' => true,
33 33
         'emailaddress' => true,
34 34
         'role' => true,
35
-        'hgm_id' => true,
35
+        'meter_id' => true,
36 36
         'created' => true,
37 37
         'modified' => true
38 38
     ];

+ 9
- 9
src/Template/Element/Eprosume/Views/charts.ctp View File

@@ -48,13 +48,13 @@
48 48
     var colorSelfConsumption = '#25bc39';
49 49
     var colorPurchased = '#d32626';
50 50
     var colorSold = '#4177d3';
51
-    var hgmSelect;
51
+    var meterSelect;
52 52
     var pickerElement;
53 53
 
54 54
     $(document).ready(function() {    
55
-        // hgmSelect element and event listener
56
-        hgmSelect = $('#hgmSelect'); 
57
-        hgmSelect.change( function() {
55
+        // meterSelect element and event listener
56
+        meterSelect = $('#meterSelect'); 
57
+        meterSelect.change( function() {
58 58
             drawCharts();
59 59
         });
60 60
 
@@ -82,10 +82,10 @@
82 82
                     drawCharts();
83 83
                 }
84 84
             });
85
-            $('#hgmReset').click( function() {
86
-                hgmSelect.find("option:selected").prop("selected", false);
87
-                hgmSelect.find("option:first").prop("selected", "selected");
88
-                hgmSelect.val(hgmSelect.find("option:first").val()).change();
85
+            $('#meterReset').click( function() {
86
+                meterSelect.find("option:selected").prop("selected", false);
87
+                meterSelect.find("option:first").prop("selected", "selected");
88
+                meterSelect.val(meterSelect.find("option:first").val()).change();
89 89
                 clearCharts();
90 90
             });
91 91
             $('#pickerReset').click( function() {
@@ -178,7 +178,7 @@
178 178
 
179 179
     function drawCharts() {
180 180
         var input = {};
181
-        input.hgm = hgmSelect.val();
181
+        input.meter = meterSelect.val();
182 182
         input.from = pickerElement.getAttribute("data-from");
183 183
         input.to = pickerElement.getAttribute("data-to");
184 184
         input.asset = "TFT";

+ 50
- 29
src/Template/Element/Eprosume/Views/datatable.ctp View File

@@ -5,7 +5,7 @@
5 5
     var exportButton;
6 6
     var searchInput;
7 7
     var searchReset;
8
-    var hgmSelect;
8
+    var meterSelect;
9 9
     var pickerElement;
10 10
     var pickerCallback;
11 11
     var periodRadio;
@@ -20,7 +20,7 @@
20 20
             "sEmptyTable":     "No records found",
21 21
             "sInfo":           "Viewing records from _START_ to _END_ of _TOTAL_",
22 22
             "sInfoEmpty":      "Viewing from 0 to 0 of 0 records",
23
-            "sInfoFiltered":   "(filtered _MAX_ records)",
23
+//          "sInfoFiltered":   "(filtered _MAX_ records)",
24 24
             "sInfoPostFix":    "",
25 25
             "sInfoThousands":  ".",
26 26
             "sLengthMenu":     "Viewing _MENU_ records",
@@ -52,7 +52,7 @@
52 52
         "ajax": {
53 53
             url : "/xhr/history",
54 54
             data: function(data) {
55
-                data.hgm = hgmSelect.val();
55
+                data.meter = meterSelect.val();
56 56
                 data.txid = searchInput.val();
57 57
                 data.from = pickerElement.getAttribute("data-from");
58 58
                 data.to = pickerElement.getAttribute("data-to");
@@ -66,10 +66,10 @@
66 66
             dataType : "json"
67 67
         },
68 68
         "columns": [
69
-            { "data": "timestamp", "render": function (data, type, row) { return row.id == null ? data : '<a href="/gridability/block/'+row.id+'">'+data+'</a>'; } },
69
+            { "data": "timestamp", "render": function (data, type, row) { return row.id == null ? data : '<a href="/web/block/'+row.id+'">'+data+'</a>'; } },
70 70
             { "data": "txID", "className": "cell-fixed", "render": function (data) { return '<div class="cell-clip">'+(data == null ? '' : data)+'</div>'; } },
71
-            { "data": "wallet_from", "render": function (data) { return '<a href="/gridability/balance/'+data+'">'+data+'</a>'; } },
72
-            { "data": "wallet_to", "render": function (data) { return '<a href="/gridability/balance/'+data+'">'+data+'</a>'; } },
71
+            { "data": "wallet_from", "render": function (data) { return '<a href="/web/meter/'+data+'">'+data+'</a>'; } },
72
+            { "data": "wallet_to", "render": function (data) { return '<a href="/web/meter/'+data+'">'+data+'</a>'; } },
73 73
             { "data": "asset" },
74 74
             { "data": "type" },
75 75
             { "name": "Value", "data": "amount", "type": "number", "render": function (data) { return data == null ? '-' : data % 1 == 0 ? parseInt(data) : data;} },
@@ -87,7 +87,7 @@
87 87
         "ajax": {
88 88
             url : "/xhr/payment",
89 89
             data: function(data) {
90
-                data.hgm = hgmSelect.val();
90
+                data.meter = meterSelect.val();
91 91
                 data.from = pickerElement.getAttribute("data-from");
92 92
                 data.to = pickerElement.getAttribute("data-to");
93 93
                 data.period = $('input[name=periodRadio]:checked').val();
@@ -100,9 +100,9 @@
100 100
             dataType : "json"
101 101
         },
102 102
         "columns": [
103
-            { "data": "timestamp", "render": function (data, type, row) { return row.id == null ? data : '<a href="/gridability/block/'+row.id+'">'+data+'</a>'; } },
104
-            { "data": "wallet_from", "render": function (data) { return '<a href="/gridability/balance/'+data+'">'+data+'</a>'; } },
105
-            { "data": "wallet_to", "render": function (data) { return '<a href="/gridability/balance/'+data+'">'+data+'</a>'; } },
103
+            { "data": "timestamp", "render": function (data, type, row) { return row.id == null ? data : '<a href="/web/block/'+row.id+'">'+data+'</a>'; } },
104
+            { "data": "wallet_from", "render": function (data) { return '<a href="/web/meter/'+data+'">'+data+'</a>'; } },
105
+            { "data": "wallet_to", "render": function (data) { return '<a href="/web/meter/'+data+'">'+data+'</a>'; } },
106 106
             { "data": "amount", "type": "number", "render": function (data) { return data == null ? '-' : data % 1 == 0 ? parseInt(data) : data;} },
107 107
             { "data": "asset" }
108 108
         ]
@@ -117,7 +117,7 @@
117 117
         "ajax": {
118 118
             url : "/xhr/price/history",
119 119
             data: function(data) {
120
-                data.hgm = hgmSelect.val();
120
+                data.meter = meterSelect.val();
121 121
                 data.from = pickerElement.getAttribute("data-from");
122 122
                 data.to = pickerElement.getAttribute("data-to");
123 123
             },
@@ -129,9 +129,9 @@
129 129
             dataType : "json"
130 130
         },
131 131
         "columns": [
132
-            { "data": "timestamp", "render": function (data, type, row) { return row.id == null ? data : '<a href="/gridability/block/'+row.id+'">'+data+'</a>'; } },
133
-            { "data": "wallet_from", "render": function (data) { return '<a href="/gridability/balance/'+data+'">'+data+'</a>'; } },
134
-            { "data": "wallet_to", "render": function (data) { return '<a href="/gridability/balance/'+data+'">'+data+'</a>'; } },
132
+            { "data": "timestamp", "render": function (data, type, row) { return row.id == null ? data : '<a href="/web/block/'+row.id+'">'+data+'</a>'; } },
133
+            { "data": "wallet_from", "render": function (data) { return '<a href="/web/meter/'+data+'">'+data+'</a>'; } },
134
+            { "data": "wallet_to", "render": function (data) { return '<a href="/web/meter/'+data+'">'+data+'</a>'; } },
135 135
             { "data": "buyPrice", "type": "number", "render": function (data) { return data == null ? '-' : data % 1 == 0 ? parseInt(data) : data;} },
136 136
             { "data": "sellPrice", "type": "number", "render": function (data) { return data == null ? '-' : data % 1 == 0 ? parseInt(data) : data;} }
137 137
        ]
@@ -152,7 +152,7 @@
152 152
         "ajax": {
153 153
             url : "/xhr/historyTransfer",
154 154
             data: function(data) {
155
-                data.hgm = hgmSelect.val();
155
+                data.meter = meterSelect.val();
156 156
                 data.txid = searchInput.val();
157 157
                 data.from = pickerElement.getAttribute("data-from");
158 158
                 data.to = pickerElement.getAttribute("data-to");
@@ -166,9 +166,9 @@
166 166
             dataType : "json"
167 167
         },
168 168
         "columns": [
169
-            { "data": "timestamp", "render": function (data, type, row) { return row.id == null ? data : '<a href="/gridability/block/'+row.id+'">'+data+'</a>'; } },
170
-            { "data": "wallet_from", "render": function (data) { return '<a href="/gridability/balance/'+data+'">'+data+'</a>'; } },
171
-            { "data": "wallet_to", "render": function (data) { return '<a href="/gridability/balance/'+data+'">'+data+'</a>'; } },
169
+            { "data": "timestamp", "render": function (data, type, row) { return row.id == null ? data : '<a href="/web/block/'+row.id+'">'+data+'</a>'; } },
170
+            { "data": "wallet_from", "render": function (data) { return '<a href="/web/balance/'+data+'">'+data+'</a>'; } },
171
+            { "data": "wallet_to", "render": function (data) { return '<a href="/web/balance/'+data+'">'+data+'</a>'; } },
172 172
             { "data": "asset" },
173 173
             { "name": "Value", "data": "amount", "type": "number", "render": function (data) { return data == null ? '-' : data % 1 == 0 ? parseInt(data) : data;} },
174 174
             { "data": "mv", "width": "30%" },
@@ -189,9 +189,9 @@
189 189
             searchInput.val("");
190 190
             dataTable.search("").draw();
191 191
         });
192
-        // hgmSelect event listener
193
-        hgmSelect = $('#hgmSelect'); 
194
-        hgmSelect.change( function() {
192
+        // meterSelect event listener
193
+        meterSelect = $('#meterSelect'); 
194
+        meterSelect.change( function() {
195 195
             dataTable.draw();
196 196
         });
197 197
         // periodRadio event listener
@@ -208,36 +208,57 @@
208 208
         // pickerSelect element and event listener
209 209
         pickerElement = document.getElementById('pickerSelect');
210 210
         pickerCallback = function() { dataTable.draw(); };
211
+        var _ = getDate();
212
+        _.setHours(23);_.setMinutes(59);
213
+        var defaultDate = getDateString(_);
214
+        var _min = getDate();
215
+        _min.setDate(_min.getDate() - 60);
211 216
         if(pickerElement != null) {
212
-            var defaultDate = getDateString(getDate());
217
+            pickerElement.setAttribute("data-from", getDateString(_min));
218
+            pickerElement.setAttribute("data-to", defaultDate);
213 219
             var picker = flatpickr(pickerElement, {
214
-                enableTime: true,
220
+                enableTime: false,
215 221
                 maxDate: defaultDate,
216 222
                 mode: 'range',
217 223
                 time_24hr: true,
224
+                defaultDate: [getDateString(_min), defaultDate],
218 225
                 onClose: function(selectedDates) {
219 226
                     let dates = selectedDates.map(d => getDate(d));
220 227
                     dates[0] == null && dates.push(defaultDate);
221 228
                     dates[1] == null && dates.push(dates[0]);
229
+                    if((Math.round(dates[1].getTime() / 1000)) - (Math.round(dates[0].getTime() / 1000)) > 5184000) {
230
+                        alert("Max date range is 60 days, please select a different period");
231
+                        return;
232
+                    }
233
+                    dates[1].setHours(23);dates[1].setMinutes(59);
222 234
                     pickerElement.setAttribute("data-from", getDateString(dates[0]));
223 235
                     pickerElement.setAttribute("data-to", getDateString(dates[1]));
224 236
                     pickerCallback();
225 237
                 }
226 238
             });
227
-            $('#hgmReset').click( function() {
228
-                hgmSelect.find("option:selected").prop("selected", false);
229
-                hgmSelect.find("option:first").prop("selected", "selected");
230
-                hgmSelect.val(hgmSelect.find("option:first").val()).change();
239
+            $('#meterReset').click( function() {
240
+                meterSelect.find("option:selected").prop("selected", false);
241
+                meterSelect.find("option:first").prop("selected", "selected");
242
+                meterSelect.val(meterSelect.find("option:first").val()).change();
231 243
             });
232 244
             $('#pickerReset').click( function() {
233 245
                 picker.clear();
234
-                pickerElement.setAttribute("data-from", "");
235
-                pickerElement.setAttribute("data-to", "");
246
+                picker.setDate([getDateString(_min), defaultDate]),
247
+                pickerElement.setAttribute("data-from", getDateString(_min));
248
+                pickerElement.setAttribute("data-to", defaultDate);
236 249
                 dataTable.draw();
237 250
             });
238 251
         }
239 252
         // datatable init
240 253
         objShallowMerge(dataTableConfiguration, <?php echo isset($dataTableConfiguration) ? $dataTableConfiguration : "{}"; ?>)
241 254
         dataTable = $('#valueTable').DataTable(dataTableConfiguration);
255
+        dataTable.on('processing.dt', function (e, settings, processing) {
256
+            var overlay = $("#eprosume_overlay");
257
+            if (processing) {
258
+                overlay.show();
259
+            } else {
260
+                overlay.hide();
261
+            }
262
+        });
242 263
     });
243 264
 </script>

+ 4
- 4
src/Template/Element/Eprosume/Views/set_price.ctp View File

@@ -52,9 +52,9 @@
52 52
                                 outcome.html("Prices have been successfully set. It may take some time to register this change. Redirecting...");
53 53
                                 $('#submitButton').addClass("hidden");
54 54
                                 outcome.removeClass("hidden");
55
-                                var hgm = prosumerSelect.val();
56
-                                prices[hgm].buyPrice = buyPriceInput.val();
57
-                                prices[hgm].sellPrice = sellPriceInput.val();
55
+                                var meter = prosumerSelect.val();
56
+                                prices[meter].buyPrice = buyPriceInput.val();
57
+                                prices[meter].sellPrice = sellPriceInput.val();
58 58
                                 setTimeout(
59 59
                                     () => { window.location.reload(); },
60 60
                                     5000
@@ -66,7 +66,7 @@
66 66
                         error: function() { }
67 67
                     });
68 68
                 } else {
69
-                    errors.html("Select a Prosumer");
69
+                    errors.html("Select a Meter");
70 70
                     errors.removeClass("hidden");
71 71
                 }
72 72
             });

+ 1
- 1
src/Template/Element/Eprosume/Views/transfer.ctp View File

@@ -15,7 +15,7 @@
15 15
                 outcome.addClass("hidden");
16 16
                 e.preventDefault();
17 17
                 if(prosumerSelect.val() == 0) {
18
-                    errors.html("Select a Prosumer");
18
+                    errors.html("Select a Meter");
19 19
                     errors.removeClass("hidden");
20 20
                     return;
21 21
                 }

+ 5
- 5
src/Template/Element/Eprosume/dataTableToolbar.ctp View File

@@ -1,21 +1,21 @@
1 1
                 <div class="row eprosume_toolbar">
2 2
                     <div class="col-sm-6">
3
-                        <div id="hgmSelectWrapper" class="dataTables_length">
4
-                            <label for="hgmSelect">Prosumer</label>
5
-                            <select id="hgmSelect" aria-controls="valueTable" class="form-control input-sm" data-column="<?php echo $column; ?>">
3
+                        <div id="meterSelectWrapper" class="dataTables_length">
4
+                            <label for="meterSelect">Meter</label>
5
+                            <select id="meterSelect" aria-controls="valueTable" class="form-control input-sm" data-column="<?php echo $column; ?>">
6 6
                                 <option></option>
7 7
                                 <?php foreach($prosumers as $prosumer): ?>
8 8
                                 <option value="<?= $prosumer ?>"><?= $prosumer ?></option>
9 9
                                 <?php endforeach; ?>
10 10
                             </select>
11
-                            <button id="hgmReset" class="btn btn-info">Reset</button>
11
+                            <button id="meterReset" class="btn btn-info">Reset</button>
12 12
                         </div>
13 13
                     </div>
14 14
                     <div class="col-sm-6 text-right">
15 15
                         <div id="pickerSelectWrapper" class="dataTables_length">
16 16
                             <label for="pickerSelect">Dates range</label> 
17 17
                             <input type="text" autocomplete="off" id="pickerSelect" aria-controls="valueTable" class="form-control input-sm" data-column="<?php echo $columnTimestamp === null ? "" : $columnTimestamp; ?>" data-from="" data-to="">
18
-                            <button id="pickerReset" class="btn btn-info">Reset</button>                            
18
+                            <button id="pickerReset" class="btn btn-info">Reset</button>
19 19
                         </div>
20 20
                     </div>
21 21
                     <div class="col-sm-6">

+ 1
- 1
src/Template/Element/Eprosume/footer.ctp View File

@@ -1,6 +1,6 @@
1 1
 <footer class="main-footer">
2 2
     <div class="pull-right hidden-xs">
3
-        <b>Version</b> 1.2
3
+        <b>Version</b> 1.0
4 4
     </div>
5 5
     Copyright &copy; 2019. <strong><a href="https://prosume.io" target="_blank">Prosume S.r.l.</a></strong>
6 6
 </footer>

+ 1
- 1
src/Template/Element/Eprosume/header.ctp View File

@@ -1,7 +1,7 @@
1 1
 <head>
2 2
     <meta charset="utf-8">
3 3
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
4
-    <title>GridAbility</title>
4
+    <title>eProsume</title>
5 5
     <!-- Tell the browser to be responsive to screen width -->
6 6
     <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
7 7
     <!-- Bootstrap 3.3.7 -->

+ 11
- 13
src/Template/Element/Eprosume/leftSideColumn.ctp View File

@@ -3,31 +3,29 @@
3 3
     <section class="sidebar">
4 4
         <!-- sidebar menu: : style can be found in sidebar.less -->
5 5
         <ul class="sidebar-menu" data-widget="tree">
6
+        <?php if($role): ?>
6 7
             <li>
7
-                <a href="/gridability"><i class="fa fa-files-o"></i><span>History</span></a>
8
-                <a href="/gridability/payment"><i class="fa fa-credit-card"></i><span>Payment</span></a>
9
-                <a href="/gridability/balance"><i class="fa fa-balance-scale"></i><span>Balance</span></a>
10
-                <a href="/gridability/history/price"><i class="fa fa-money"></i><span>Price</span></a>
11
-                <?php if($role === "admin" && $user_hgm_id == 1): ?>
8
+                <a href="/web"><i class="fa fa-files-o"></i><span>History</span></a>
9
+                <a href="/web/payment"><i class="fa fa-credit-card"></i><span>Payment</span></a>
10
+                <a href="/web/meter"><i class="fa fa-balance-scale"></i><span>Balance</span></a>
11
+                <a href="/web/history/price"><i class="fa fa-money"></i><span>Price</span></a>
12
+                <?php if($role === "admin" && $user_meter_id == 1): ?>
12 13
                 <hr>
13
-                <a href="/gridability/setprice"><i class="fa fa-cogs"></i><span>Set Price</span></a>
14
+                <a href="/web/setprice"><i class="fa fa-cogs"></i><span>Set Price</span></a>
14 15
                 <?php endif ?>
15
-                <?php if($user_hgm_id > 0): ?>
16
+                <?php if($user_meter_id > 0): ?>
16 17
                 <hr>
17
-                <a href="/gridability/transfer"><i class="fa fa-exchange"></i><span>Transfer</span></a>
18
+                <a href="/web/transfer"><i class="fa fa-exchange"></i><span>Transfer</span></a>
18 19
                 <?php endif ?>
19 20
                 <hr>
20 21
                 <?php if($role === "admin"): ?>
21 22
                 <a href="/users"><i class="fa fa-users"></i><span>Users</span></a>
22 23
                 <hr>
23 24
                 <?php endif ?>
24
-                <?php if($role): ?>
25
-                <a href="/gridability/profile"><i class="fa fa-user"></i><span>Profile settings</span></a>
25
+                <a href="/web/profile"><i class="fa fa-user"></i><span>Profile settings</span></a>
26 26
                 <a href="/users/logout"><i class="fa fa-sign-out"></i><span>Logout</span></a>
27
-                <?php else: ?>
28
-                <a href="/users/login"><i class="fa fa-sign-in"></i><span>Login</span></a>
29
-                <?php endif ?>
30 27
             </li>
28
+        <?php endif ?>
31 29
         </ul>
32 30
     </section>
33 31
     <!-- /.sidebar -->

+ 4
- 5
src/Template/Element/Eprosume/mainHeader.ctp View File

@@ -1,11 +1,11 @@
1
-<div id="eprosume_overlay"><div class="eprosume_lds-dual-ring"></div></div>
1
+<div id="eprosume_overlay"><div class="eprosume_loader"></div></div>
2 2
 <header class="main-header">
3 3
     <!-- Logo -->
4
-    <a href="/gridability" class="logo">
4
+    <a href="/web" class="logo">
5 5
         <!-- mini logo for sidebar mini 50x50 pixels -->
6
-        <span class="logo-mini"><img src="/img/logo.png" /></span>
6
+        <span class="logo-mini"><?= $app_short ?></span>
7 7
         <!-- logo for regular state and mobile devices -->
8
-        <span class="logo-lg">GridAbility</span>
8
+        <span class="logo-lg"><?= $app_logotype ?></span>
9 9
     </a>
10 10
     <!-- Header Navbar: style can be found in header.less -->
11 11
     <nav class="navbar navbar-static-top">
@@ -16,6 +16,5 @@
16 16
             <span class="icon-bar"></span>
17 17
             <span class="icon-bar"></span>
18 18
         </a>
19
-
20 19
     </nav>
21 20
 </header>

+ 1
- 1
src/Template/Eprosume/standard.ctp View File

@@ -21,7 +21,7 @@ $this->layout = false;
21 21
                 <small></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
24
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25 25
                 <li class="active"><a href="/history">History</a></li>
26 26
             </ol>
27 27
         </section>

+ 1
- 1
src/Template/Main/block_i_d.ctp View File

@@ -21,7 +21,7 @@ $this->layout = false;
21 21
                 <small></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/gridability"><i class="fa fa-dashboard"></i> GridAbility</a></li>
24
+                <li><a href="/web"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25 25
                 <li class="active">block <?= $block['blocknumber']; ?></li>
26 26
             </ol>
27 27
         </section>

+ 1
- 2
src/Template/Main/charts.ctp View File

@@ -21,7 +21,7 @@ $this->layout = false;
21 21
                 <small></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
24
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25 25
                 <li class="active">Charts</li>
26 26
             </ol>
27 27
         </section>
@@ -61,6 +61,5 @@ $this->layout = false;
61 61
 </div>
62 62
 <!-- ./wrapper -->
63 63
 <?= $this->element('Eprosume/scripts') ?>
64
-<?= $this->element('Eprosume/Views/charts') ?>
65 64
 </body>
66 65
 </html>

+ 1
- 1
src/Template/Main/history.ctp View File

@@ -21,7 +21,7 @@ $this->layout = false;
21 21
                 <small></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
24
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25 25
                 <li class="active"><a href="/history">History</a></li>
26 26
             </ol>
27 27
         </section>

+ 7
- 7
src/Template/Main/history_daily.ctp View File

@@ -21,7 +21,7 @@ $this->layout = false;
21 21
                 <small></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
24
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25 25
                 <li class="active"><a href="/history/daily">Daily History</a></li>
26 26
             </ol>
27 27
         </section>
@@ -55,13 +55,13 @@ $this->layout = false;
55 55
                                     if ($block['asset'] == 'PRS') { ?>
56 56
                                         <tr class="blockRow" name="<?= $block['id']; ?>">
57 57
                                             <td>
58
-                                                <a href="/gridability/block/<?= $block['id']; ?>"><?= $block['timestamp']; ?></a>
58
+                                                <a href="/web/block/<?= $block['id']; ?>"><?= $block['timestamp']; ?></a>
59 59
                                             </td>
60 60
                                             <td>
61
-                                                <a href="/gridability/balance/<?= $block['wallet_from']; ?>"><?= $block['wallet_from']; ?></a>
61
+                                                <a href="/web/meter/<?= $block['wallet_from']; ?>"><?= $block['wallet_from']; ?></a>
62 62
                                             </td>
63 63
                                             <td>
64
-                                                <a href="/gridability/balance/<?= $block['wallet_to']; ?>"><?= $block['wallet_to']; ?></a>
64
+                                                <a href="/web/meter/<?= $block['wallet_to']; ?>"><?= $block['wallet_to']; ?></a>
65 65
                                             </td>
66 66
                                             <td><?= $block['asset']; ?></td>
67 67
                                             <td><?= @number_format($block['amount'], 2, ',', '.'); ?></td>
@@ -72,13 +72,13 @@ $this->layout = false;
72 72
                                     <?php } else { ?>
73 73
                                         <tr class="blockRow" name="<?= $block['id']; ?>">
74 74
                                             <td>
75
-                                                <a href="/gridability/block/<?= $block['id']; ?>"><?= $block['timestamp']; ?></a>
75
+                                                <a href="/web/block/<?= $block['id']; ?>"><?= $block['timestamp']; ?></a>
76 76
                                             </td>
77 77
                                             <td>
78
-                                                <a href="/gridability/balance/<?= $block['wallet_from']; ?>"><?= $block['wallet_from']; ?></a>
78
+                                                <a href="/web/meter/<?= $block['wallet_from']; ?>"><?= $block['wallet_from']; ?></a>
79 79
                                             </td>
80 80
                                             <td>
81
-                                                <a href="/gridability/balance/<?= $block['wallet_to']; ?>"><?= $block['wallet_to']; ?></a>
81
+                                                <a href="/web/meter/<?= $block['wallet_to']; ?>"><?= $block['wallet_to']; ?></a>
82 82
                                             </td>
83 83
                                             <td><?= $block['asset']; ?></td>
84 84
                                             <td><?= @number_format($block['amount'], 2, ',', '.'); ?></td>

+ 6
- 6
src/Template/Main/history_hgm.ctp View File

@@ -18,12 +18,12 @@ $this->layout = false;
18 18
         <section class="content-header">
19 19
             <h1>
20 20
                 History Meter
21
-                <small><?= $hgm_id; ?></small>
21
+                <small><?= $meter_id; ?></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/gridability"><i class="fa fa-dashboard"></i> GridAbility</a></li>
25
-                <li><a href="/gridability/history">History</a></li>
26
-                <li class="active"><a href="/<?= $hgm_id; ?>"><?= $hgm_id; ?></a></li>
24
+                <li><a href="/web"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25
+                <li><a href="/web/history">History</a></li>
26
+                <li class="active"><a href="/<?= $meter_id; ?>"><?= $meter_id; ?></a></li>
27 27
             </ol>
28 28
         </section>
29 29
 
@@ -59,8 +59,8 @@ $this->layout = false;
59 59
                                     ?>
60 60
                                     <tr>
61 61
                                         <td><?= $block['timestamp']; ?></td>
62
-                                        <td><a href="/gridability/balance/<?= $block['wallet_from']; ?>"><?= $block['wallet_from']; ?></a></td>
63
-                                        <td><a href="/gridability/balance/<?= $block['wallet_to']; ?>"><?= $block['wallet_to']; ?></a></td>
62
+                                        <td><a href="/web/meter/<?= $block['wallet_from']; ?>"><?= $block['wallet_from']; ?></a></td>
63
+                                        <td><a href="/web/meter/<?= $block['wallet_to']; ?>"><?= $block['wallet_to']; ?></a></td>
64 64
                                         <td><?= @number_format($block['memo']['consumedEnergy'],2,',','.'); ?></td>
65 65
                                         <td><?= @number_format($block['memo']['purchasedEnergy'],2,',','.'); ?></td>
66 66
                                         <td><?= @number_format($block['memo']['producedEnergy'],2,',','.'); ?></td>

src/Template/Main/hgm.ctp → src/Template/Main/meter.ctp View File

@@ -17,12 +17,12 @@ $this->layout = false;
17 17
         <!-- Content Header (Page header) -->
18 18
         <section class="content-header">
19 19
             <h1>
20
-                Balance
20
+                Meter
21 21
                 <small></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/gridability"><i class="fa fa-dashboard"></i> GridAbility</a></li>
25
-                <li>balance</li>
24
+                <li><a href="/web"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25
+                <li>meter</li>
26 26
             </ol>
27 27
         </section>
28 28
 
@@ -36,7 +36,8 @@ $this->layout = false;
36 36
                             <table id="tabella" class="table">
37 37
                                 <thead>
38 38
                                 <tr>
39
-                                    <th width="20%">Meter</th>
39
+                                    <th>Meter</th>
40
+                                    <th>Location</th>
40 41
                                     <th>PRS</th>
41 42
                                     <th>TFT</th>
42 43
                                     <th>Buy Price</th>
@@ -46,17 +47,17 @@ $this->layout = false;
46 47
                                 </thead>
47 48
                                 <tbody>
48 49
                                 <?php
49
-                                foreach ($hgmList as $hgm_id => $hgm) {
50
+                                foreach ($meterList as $meter_id => $meter) {
50 51
                                     echo '<tr>';
51
-                                    printf('<td><a href="/gridability/balance/%s">%s</a></td>',$hgm_id,$hgm_id);
52
-                                    printf('<td>%s</td>',$hgm['balance']['PRS']);
53
-                                    printf('<td>%s</td>',$hgm['balance']['TFT']);
54
-                                    @printf('<td>%s</td>',$prices[$hgm_id]['buyPrice']);
55
-                                    @printf('<td>%s</td>',$prices[$hgm_id]['sellPrice']);
56
-                                    printf('<td>%s</td>',$hgm['balance']['timestamp']);
52
+                                    printf('<td><a href="/web/meter/%s">%s</a></td>',$meter_id,$meter_id);
53
+                                    printf('<td>%s</td>',$meter['location']);
54
+                                    printf('<td>%s</td>',$meter['balance']['PRS']);
55
+                                    printf('<td>%s</td>',$meter['balance']['TFT']);
56
+                                    @printf('<td>%s</td>',$prices[$meter_id]['buyPrice']);
57
+                                    @printf('<td>%s</td>',$prices[$meter_id]['sellPrice']);
58
+                                    printf('<td>%s</td>',$meter['balance']['timestamp']);
57 59
                                     echo '</tr>';
58 60
                                 }
59
-
60 61
                                 ?>
61 62
                                 </tbody>
62 63
                             </table>

src/Template/Main/hgm_i_d.ctp → src/Template/Main/meter_i_d.ctp View File

@@ -17,13 +17,14 @@ $this->layout = false;
17 17
         <!-- Content Header (Page header) -->
18 18
         <section class="content-header">
19 19
             <h1>
20
-                Balance <?= $hgm_id ?>
21
-                <small></small>
20
+                Balance <?= $meter_id ?>
21
+                <br />
22
+                <small><?= $balance['location'] ?></small>
22 23
             </h1>
23 24
             <ol class="breadcrumb">
24
-                <li><a href="/gridability"><i class="fa fa-dashboard"></i> GridAbility</a></li>
25
-                <li><a href="/gridability/balance">balance</a></li>
26
-                <li class="active"><?= $hgm_id; ?></li>
25
+                <li><a href="/web"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
26
+                <li><a href="/web/meter">balance</a></li>
27
+                <li class="active"><?= $meter_id; ?></li>
27 28
             </ol>
28 29
         </section>
29 30
 
@@ -65,7 +66,7 @@ $this->layout = false;
65 66
 
66 67
                         <div class="info-box-content">
67 68
                             <span class="info-box-text">BuyPrice</span>
68
-                            <span class="info-box-number"><?= @$prices[$hgm_id]['buyPrice'] ?></span>
69
+                            <span class="info-box-number"><?= @$prices[$meter_id]['buyPrice'] ?></span>
69 70
                         </div>
70 71
                         <!-- /.info-box-content -->
71 72
                     </div>
@@ -77,7 +78,7 @@ $this->layout = false;
77 78
 
78 79
                         <div class="info-box-content">
79 80
                             <span class="info-box-text">SellPrice</span>
80
-                            <span class="info-box-number"><?= @$prices[$hgm_id]['sellPrice'] ?></span>
81
+                            <span class="info-box-number"><?= @$prices[$meter_id]['sellPrice'] ?></span>
81 82
                         </div>
82 83
                         <!-- /.info-box-content -->
83 84
                     </div>
@@ -94,7 +95,7 @@ $this->layout = false;
94 95
         </section>
95 96
         <!-- /.content -->
96 97
         <!-- Main content -->
97
-        <?php if($hgm_id != $utility_account): ?>
98
+        <?php if($meter_id != $utility_account && $app_charts): ?>
98 99
         <section class="content">
99 100
             <div class="box">
100 101
                 <div class="box-body">
@@ -121,7 +122,7 @@ $this->layout = false;
121 122
     $('tr.blockRow').on('click touch',function(){
122 123
     })
123 124
 </script>
124
-<?php if($hgm_id != $utility_account): ?>
125
+<?php if($meter_id != $utility_account && $app_charts): ?>
125 126
 
126 127
 <script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
127 128
 <script>
@@ -305,7 +306,7 @@ $this->layout = false;
305 306
                 dataType : "json"
306 307
             };
307 308
             var promise = $.ajax(
308
-                '/xhr/charts/payments/' + '<?= $hgm_id; ?>?'+qs,
309
+                '/xhr/charts/payments/' + '<?= $meter_id; ?>?'+qs,
309 310
                 settings
310 311
             ).then(function(data) {
311 312
                 var series = {

+ 1
- 1
src/Template/Main/payment.ctp View File

@@ -21,7 +21,7 @@ $this->layout = false;
21 21
                 <small></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
24
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25 25
                 <li class="active">Payment</li>
26 26
             </ol>
27 27
         </section>

+ 1
- 1
src/Template/Main/price_history.ctp View File

@@ -21,7 +21,7 @@ $this->layout = false;
21 21
                 <small></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
24
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25 25
                 <li class="active"><a href="/history">History</a></li>
26 26
             </ol>
27 27
         </section>

+ 1
- 1
src/Template/Main/profile.ctp View File

@@ -21,7 +21,7 @@ $this->layout = false;
21 21
                 <small></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
24
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25 25
                 <li class="active">Profile Settings</li>
26 26
             </ol>
27 27
         </section>

+ 2
- 2
src/Template/Main/set_price.ctp View File

@@ -21,7 +21,7 @@ $this->layout = false;
21 21
                 <small></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
24
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25 25
                 <li class="active">Set Price</li>
26 26
             </ol>
27 27
         </section>
@@ -39,7 +39,7 @@ $this->layout = false;
39 39
                                             <div class="row">
40 40
                                                 <div class="col-lg-4 col-sm-4">
41 41
                                                     <div class="input-group">
42
-                                                        <span class="input-group-addon">Prosumer</span>
42
+                                                        <span class="input-group-addon">Meter</span>
43 43
                                                         <select id="prosumerSelect" class="form-control" autocomplete="off" required>
44 44
                                                             <option value="0"></option>
45 45
                                                             <?php 

+ 2
- 2
src/Template/Main/transfer.ctp View File

@@ -21,7 +21,7 @@ $this->layout = false;
21 21
                 <small></small>
22 22
             </h1>
23 23
             <ol class="breadcrumb">
24
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
24
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
25 25
                 <li class="active">Transfer</li>
26 26
             </ol>
27 27
         </section>
@@ -39,7 +39,7 @@ $this->layout = false;
39 39
                                             <div class="row">
40 40
                                                 <div class="col-lg-4 col-sm-4">
41 41
                                                     <div class="input-group">
42
-                                                        <span class="input-group-addon">Prosumer</span>
42
+                                                        <span class="input-group-addon">Meter</span>
43 43
                                                         <select id="prosumerSelect" class="form-control" autocomplete="off" required>
44 44
                                                             <option value="0"></option>
45 45
                                                             <?php 

+ 4
- 4
src/Template/Users/add.ctp View File

@@ -25,7 +25,7 @@ $this->layout = false;
25 25
                 <small></small>
26 26
             </h1>
27 27
             <ol class="breadcrumb">
28
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
28
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
29 29
                 <li><a href="/users">Users</a></li>
30 30
                 <li class="active">New User</li>
31 31
             </ol>
@@ -57,11 +57,11 @@ $this->layout = false;
57 57
                                             "options" => ['admin'=>'admin', 'reader'=>'reader'],
58 58
                                             'value' => $user->role
59 59
                                         ]);
60
-                                        echo $this->Form->control('hgm_id', [
60
+                                        echo $this->Form->control('meter_id', [
61 61
                                             "label" => "Associated meter",
62 62
                                             "type" => "select",
63
-                                            "options" => $hgmList,
64
-                                            'value' => $user->hgm_id
63
+                                            "options" => $meterList,
64
+                                            'value' => $user->meter_id
65 65
                                         ]);
66 66
                                     ?>
67 67
                                 </fieldset>

+ 4
- 4
src/Template/Users/edit.ctp View File

@@ -25,7 +25,7 @@ $this->layout = false;
25 25
                 <small></small>
26 26
             </h1>
27 27
             <ol class="breadcrumb">
28
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
28
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
29 29
                 <li><a href="/users">Users</a></li>
30 30
                 <li class="active"><?= h($user->username) ?></li>
31 31
             </ol>
@@ -64,11 +64,11 @@ $this->layout = false;
64 64
                                             "options" => ['admin'=>'admin', 'reader'=>'reader'],
65 65
                                             'value' => $user->role
66 66
                                         ]);
67
-                                        echo $this->Form->control('hgm_id', [
67
+                                        echo $this->Form->control('meter_id', [
68 68
                                             "label" => "Associated meter",
69 69
                                             "type" => "select",
70
-                                            "options" => $hgmList,
71
-                                            'value' => $user->hgm_id
70
+                                            "options" => $meterList,
71
+                                            'value' => $user->meter_id
72 72
                                         ]);
73 73
                                     ?>
74 74
                                 </fieldset>

+ 3
- 3
src/Template/Users/index.ctp View File

@@ -25,7 +25,7 @@ $this->layout = false;
25 25
                 <small></small>
26 26
             </h1>
27 27
             <ol class="breadcrumb">
28
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
28
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
29 29
                 <li class="active">Users</li>
30 30
             </ol>
31 31
         </section>
@@ -52,7 +52,7 @@ $this->layout = false;
52 52
                                             <th scope="col"><?= $this->Paginator->sort('username') ?></th>
53 53
                                             <th scope="col"><?= $this->Paginator->sort('emailaddress', 'Email') ?></th>
54 54
                                             <th scope="col"><?= $this->Paginator->sort('role') ?></th>
55
-                                            <th scope="col"><?= $this->Paginator->sort('hgm_id', 'Associated meter') ?></th>
55
+                                            <th scope="col"><?= $this->Paginator->sort('meter_id', 'Associated meter') ?></th>
56 56
                                             <th scope="col"><?= $this->Paginator->sort('created') ?></th>
57 57
                                             <th scope="col"><?= $this->Paginator->sort('modified') ?></th>
58 58
                                             <th scope="col" class="actions"><?= __('Actions') ?></th>
@@ -65,7 +65,7 @@ $this->layout = false;
65 65
                                             <td><?= h($user->username) ?></td>
66 66
                                             <td><?= h($user->emailaddress) ?></td>
67 67
                                             <td><?= h($user->role) ?></td>
68
-                                            <td><?= h($hgmList[$user->hgm_id] ?? "-") ?></td>
68
+                                            <td><?= h($meterList[$user->meter_id] ?? "-") ?></td>
69 69
                                             <td><?= h($user->created) ?></td>
70 70
                                             <td><?= h($user->modified) ?></td>
71 71
                                             <td class="actions">

+ 1
- 1
src/Template/Users/login.ctp View File

@@ -17,7 +17,7 @@ $this->layout = false;
17 17
         <!-- Content Header (Page header) -->
18 18
         <section class="content-header">
19 19
             <h1>
20
-                Welcome to GridAbility
20
+                Welcome to <?= $app_name ?>
21 21
                 <small></small>
22 22
             </h1>
23 23
         </section>

+ 1
- 1
src/Template/Users/view.ctp View File

@@ -25,7 +25,7 @@ $this->layout = false;
25 25
                 <small></small>
26 26
             </h1>
27 27
             <ol class="breadcrumb">
28
-                <li><a href="/"><i class="fa fa-dashboard"></i> GridAbility</a></li>
28
+                <li><a href="/"><i class="fa fa-dashboard"></i> <?= $app_name ?></a></li>
29 29
                 <li><a href="/users">Users</a></li>
30 30
                 <li class="active"><?= h($user->username) ?></li>
31 31
             </ol>

+ 118
- 126
src/Utility/EprosumeModel.php View File

@@ -26,7 +26,7 @@ class EprosumeModel
26 26
             'to' => ' AND wallet_to = :to ',
27 27
             'from' => ' AND wallet_from = :from ',
28 28
             'wallet' => ' AND ( wallet_to = :wallet or wallet_from = :wallet ) ',
29
-            'hgm' => ' AND wallet_from = :hgm ',
29
+            'meter' => ' AND wallet_from = :meter ',
30 30
             'date_from' => ' AND timestamp >= :date_from ',
31 31
             'date_to' => ' AND timestamp <= :date_to ',
32 32
             'asset' => ' AND asset = :asset ',
@@ -73,20 +73,21 @@ class EprosumeModel
73 73
         return $memo;
74 74
     }
75 75
 
76
-    public function hgmList($hgm_id = null)
76
+    public function meterList($meter_id = null)
77 77
     {
78
-        $hgmList = [];
79
-        $and = $hgm_id ? " WHERE h.id = ".((int)$hgm_id) : ""; 
78
+        $meterList = [];
79
+        $and = $meter_id ? " WHERE h.id = ".((int)$meter_id) : ""; 
80 80
         $sql = <<<SQL
81
-SELECT h.id, h.prs AS PRS, h.tft AS TFT, h.timestamp, h.name, h.buy, h.sell FROM hgm h
81
+SELECT h.id, h.prs AS PRS, h.tft AS TFT, h.timestamp, h.name, h.buy, h.sell, h.location FROM meter h
82 82
 SQL;
83 83
         $sql.= $and;
84 84
         $data = ($this->connection->execute($sql))->fetchAll(\PDO::FETCH_ASSOC);
85 85
         foreach ($data as $v) {
86
-            $hgmList[$v['name']] = [
87
-                'hgm' => $v['name'],
86
+            $meterList[$v['name']] = [
87
+                'meter' => $v['name'],
88 88
                 'name' => $v['name'],
89 89
                 'id' => $v['id'],
90
+                'location' => $v['location'],
90 91
                 'balance' => [
91 92
                     'PRS' => $v['PRS'],
92 93
                     'TFT' => $v['TFT'],
@@ -96,28 +97,28 @@ SQL;
96 97
         }
97 98
         if(!empty($and)) {
98 99
             $result = null;
99
-            foreach($hgmList as $k=>$v) {
100
-                $result = $hgmList[$k];
100
+            foreach($meterList as $k=>$v) {
101
+                $result = $meterList[$k];
101 102
                 break;
102 103
             }
103
-            $hgmList = $result;
104
+            $meterList = $result;
104 105
         }
105
-        return $hgmList;
106
+        return $meterList;
106 107
     }
107 108
 
108
-    public function balanceHGM($hgm_id)
109
+    public function balanceMeter($meter_id)
109 110
     {
110 111
         $sql = <<<SQL
111
-select h.name, h.id, (select b.timestamp from balances b where b.hgm_id = h.id order by b.timestamp desc limit 1) as timestamp, (select b.prs from balances b where b.hgm_id = h.id order by b.timestamp desc limit 1) as PRS, (select b.tft from balances b where b.hgm_id = h.id order by b.timestamp desc limit 1) as TFT from hgm h where h.name = :hgm_name;
112
+select h.name, h.id, h.location, (select b.timestamp from balances b where b.meter_id = h.id order by b.timestamp desc limit 1) as timestamp, (select b.prs from balances b where b.meter_id = h.id order by b.timestamp desc limit 1) as PRS, (select b.tft from balances b where b.meter_id = h.id order by b.timestamp desc limit 1) as TFT from meter h where h.name = :meter_name;
112 113
 SQL;
113
-        return ($this->connection->execute($sql, [ "hgm_name" => $hgm_id ] ))->fetch(\PDO::FETCH_ASSOC);
114
+        return ($this->connection->execute($sql, [ "meter_name" => $meter_id ] ))->fetch(\PDO::FETCH_ASSOC);
114 115
     }
115 116
 
116
-    public function balanceHistory($date_from, $date_to, $hgm)
117
+    public function balanceHistory($date_from, $date_to, $meter)
117 118
     {
118 119
         $sql = <<<SQL
119
-SELECT h.id, h.subid, h.name, b.TFT, b.PRS, DATE_FORMAT(timestamp, "%%Y-%%m-%%d %%H:%%i") AS timestamp FROM hgm h
120
-LEFT JOIN balances b ON b.hgm_id = h.id
120
+SELECT h.id, h.subid, h.name, h.location, b.TFT, b.PRS, DATE_FORMAT(timestamp, "%%Y-%%m-%%d %%H:%%i") AS timestamp FROM meter h
121
+LEFT JOIN balances b ON b.meter_id = h.id
121 122
 WHERE 1
122 123
 %s
123 124
 AND h.status = 'ACTIVE'
@@ -128,10 +129,10 @@ SQL;
128 129
             "date_from" => $date_from, 
129 130
             "date_to" => $date_to, 
130 131
         ];
131
-        $hgm && $values['hgm'] = $hgm;
132
+        $meter && $values['meter'] = $meter;
132 133
 
133 134
         return ($this->connection->execute(
134
-            sprintf($sql, ($hgm ? "AND h.name = :hgm" : ""))
135
+            sprintf($sql, ($meter ? "AND h.name = :meter" : ""))
135 136
             ,
136 137
             $values
137 138
         ))->fetchAll(\PDO::FETCH_ASSOC);        
@@ -142,49 +143,34 @@ SQL;
142 143
         $this->blocksList(['id' => $block_id]);
143 144
     }
144 145
 
145
-    public function actualPrice($hgm_id = null)
146
+    public function actualPrice($meter_id = null)
146 147
     {
147 148
         $prices = [];
148 149
         $sql = <<<SQL
149
-SELECT * FROM hgm 
150
+SELECT * FROM meter 
150 151
 SQL;
151
-        if($hgm_id) {
152
-            $sql.= " WHERE id = ".$hgm_id;
152
+        if($meter_id) {
153
+            $sql.= " WHERE id = ".$meter_id;
153 154
         }
154
-        $hgms = $this->connection->execute($sql)->fetchAll(\PDO::FETCH_ASSOC);
155
-        foreach($hgms as $hgm) {
156
-            $prices[$hgm['name']] = [
157
-                'buyPrice' => $hgm['buy'],
158
-                'sellPrice' => $hgm['sell'],
155
+        $meters = $this->connection->execute($sql)->fetchAll(\PDO::FETCH_ASSOC);
156
+        foreach($meters as $meter) {
157
+            $prices[$meter['name']] = [
158
+                'buyPrice' => $meter['buy'],
159
+                'sellPrice' => $meter['sell'],
159 160
             ];
160 161
         }
161 162
 
162
-        /*
163
-        $filter = ($hgm_id) ? ['wallet' => $hgm_id] : [];
164
-        foreach ($this->blocksList($filter) as $block) {
165
-            if (
166
-                (empty($block['memo']['purchasedEnergy']))
167
-                && !(empty($block['memo']['buyPrice']))
168
-                && empty($prices[$block['wallet_to']])
169
-            ) {
170
-                $prices[$block['wallet_to']] = [
171
-                    'buyPrice' => $block['memo']['buyPrice'],
172
-                    'sellPrice' => $block['memo']['sellPrice'],
173
-                ];
174
-            }
175
-        }
176
-        */
177 163
         return $prices;
178 164
     }
179 165
 
180
-    public function paymentsList($hgm_id = null)
166
+    public function paymentsList($meter_id = null)
181 167
     {
182 168
         $where = 'true';
183 169
         $values = [];
184 170
 
185
-        if ($hgm_id) {
186
-            $where .= ' AND ( wallet_from=:hgm_id or wallet_to=:hgm_id )';
187
-            $values['hgm_id'] = $hgm_id;
171
+        if ($meter_id) {
172
+            $where .= ' AND ( wallet_from=:meter_id or wallet_to=:meter_id )';
173
+            $values['meter_id'] = $meter_id;
188 174
         }
189 175
 
190 176
         $order = ' ORDER BY timestamp DESC ';
@@ -195,7 +181,7 @@ SQL;
195 181
         }
196 182
     }
197 183
 
198
-    public function dataTableSSP($dataset, $user_hgm_id, $draw, $columns, array $order, $start, $length, array $search = null, $hgm = null, $txid=null, $from=null, $to=null, $period=null) {
184
+    public function dataTableSSP($dataset, $user_meter_id, $draw, $columns, array $order, $start, $length, array $search = null, $meter = null, $txid=null, $from=null, $to=null, $period=null) {
199 185
         $filterString = "";
200 186
         $groupString = "";
201 187
         $params = [];
@@ -210,18 +196,18 @@ SQL;
210 196
             case 'historyTransfer':
211 197
                 if($period) {
212 198
                     if($period == 1) {
213
-                        $timeString = "DATE(b.timestamp)";
214
-                        $groupTimeString = "DATE(b.timestamp)";
199
+                        $timeString = "b.day";
200
+                        $groupTimeString = "b.day";
215 201
                     } else {
216
-                        $timeString = 'CONCAT(YEAR(b.timestamp),"-",LPAD(MONTH(b.timestamp),2,"0"))';
217
-                        $groupTimeString = "YEAR(b.timestamp), MONTH(timestamp)";
202
+                        $timeString = "CONCAT(b.yea, '-', b.mon)";
203
+                        $groupTimeString = "b.yea, b.mon";
218 204
                     }
219 205
                     $selectString = <<<SQL
220 206
 SELECT $timeString AS timestamp, 
221
-b.tx_id AS txID, 
207
+null AS txID, 
222 208
 b.wallet_from, b.wallet_to, b.asset, b.type,
223 209
 SUM(b.amount+0) AS amount,
224
-b.purchased_sold AS energyDiff, 
210
+SUM(b.purchased_sold+0) AS energyDiff, 
225 211
 NULL as mv
226 212
 FROM blocks b
227 213
 SQL;
@@ -230,7 +216,6 @@ GROUP BY $groupTimeString, b.wallet_from, b.wallet_to, b.asset, b.type
230 216
 SQL;
231 217
                 } else {
232 218
                     $derivedSelect = $dataset == "historyTransfer" ? "m3.memo_value AS mv" : "NULL as mv";
233
-
234 219
                     $selectString = <<<SQL
235 220
 SELECT b.id, b.timestamp, b.wallet_from, b.wallet_to, b.asset, b.type,
236 221
 b.tx_id AS txID,
@@ -243,18 +228,15 @@ SQL;
243 228
                 $joinString = <<<SQL
244 229
 SQL;
245 230
                 $countString = <<<SQL
246
-SELECT COUNT(b.id)
231
+SELECT COUNT(*)
247 232
 FROM blocks b
248 233
 SQL;
249 234
 
250 235
                 $clauseString = <<<SQL
251
-WHERE b.type IS NOT NULL
236
+WHERE (b.type = 'measure' OR b.type = 'payment')
252 237
 SQL;
253 238
 
254 239
                 $utility_account = $this->conf['utility_account'] ?? null;
255
-                if($utility_account) {
256
-                    $clauseString.= " AND NOT (b.asset = 'TFT' AND b.tx_id IS NULL AND b.wallet_from = '$utility_account')";
257
-                }
258 240
 
259 241
                 if($dataset == "historyTransfer") {
260 242
                     $clauseString = ' WHERE b.type = "transfer"';
@@ -263,20 +245,19 @@ SQL;
263 245
 
264 246
                 if($txid) {
265 247
                     $filterString.= <<<SQL
266
-
267
-AND b.tx_id LIKE :txid
248
+AND b.tx_id = :txid
268 249
 SQL;
269
-                    $params["txid"] = "%$txid%";
250
+                    $params["txid"] = $txid;
270 251
                 }
271 252
                 break;
272 253
             case 'payment':
273 254
                 if($period) {
274 255
                     if($period == 1) {
275
-                        $timeString = "DATE(b.timestamp)";
276
-                        $groupTimeString = "DATE(b.timestamp)";
256
+                        $timeString = "b.day";
257
+                        $groupTimeString = "b.day";
277 258
                     } else {
278
-                        $timeString = 'CONCAT(YEAR(b.timestamp),"-",LPAD(MONTH(b.timestamp),2,"0"))';
279
-                        $groupTimeString = "YEAR(b.timestamp), MONTH(timestamp)";
259
+                        $timeString = "CONCAT(b.yea, '-', b.mon)";
260
+                        $groupTimeString = "b.yea, b.mon";
280 261
                     }
281 262
                     $selectString = <<<SQL
282 263
 SELECT $timeString AS timestamp, b.wallet_from, b.wallet_to, 
@@ -310,7 +291,7 @@ SQL;
310 291
                 $clauseString = <<<SQL
311 292
 WHERE 1
312 293
 AND b.asset = "TFT"
313
-AND b.type IS NULL
294
+AND b.type = "update_price"
314 295
 SQL;
315 296
 
316 297
                 $countString = <<<SQL
@@ -322,29 +303,36 @@ SQL;
322 303
             default:
323 304
                 return $response;
324 305
         }
325
-        if($user_hgm_id) {
326
-            $user_hgm_id_clause = <<<SQL
306
+        if($user_meter_id) {
307
+            $user_meter_id_clause = <<<SQL
327 308
 
328
-AND (b.wallet_from = '$user_hgm_id' OR b.wallet_to = '$user_hgm_id')
309
+AND (b.wallet_from = '$user_meter_id' OR b.wallet_to = '$user_meter_id')
329 310
 SQL;
330 311
 
331
-            $clauseString.= $user_hgm_id_clause;
332
-            //$filterString.= $user_hgm_id_clause;
312
+            $clauseString.= $user_meter_id_clause;
333 313
         }
334
-        if($hgm) {
314
+        if($meter) {
335 315
             $filterString.= <<<SQL
336 316
 
337
-AND (wallet_from = :hgm OR wallet_to = :hgm)
317
+AND (wallet_from = :meter OR wallet_to = :meter)
338 318
 SQL;
339
-            $params["hgm"] = $hgm;
319
+            $params["meter"] = $meter;
340 320
         }
341
-        if($from && $to) {
342
-            $filterString.= <<<SQL
343
-
321
+        if(!$txid) {
322
+            if($from && $to) {
323
+                $params["from"] = $from;
324
+                $params["to"] = $to;
325
+                $filterString.= <<<SQL
344 326
 AND timestamp BETWEEN :from AND :to
345 327
 SQL;
346
-            $params["from"] = $from;
347
-            $params["to"] = $to;
328
+            } else {
329
+                /*
330
+                $now = new \DateTime();
331
+                $params["to"] = $now->format('Y-m-d H:i:s');
332
+                $now->sub(new \DateInterval('P30D'));
333
+                $params["from"] = $now->format('Y-m-d H:i:s');
334
+                */
335
+            }            
348 336
         }
349 337
         $orderString = empty($order)
350 338
             ? ""
@@ -407,6 +395,7 @@ SQL;
407 395
                 $clauseString
408 396
             ];    
409 397
         }
398
+        /*
410 399
         if(empty($groupString)) {
411 400
             $recordsTotalQuery = implode(PHP_EOL, $queryComposition);
412 401
             $recordsTotalResults = $this->connection->execute($recordsTotalQuery)->fetch();
@@ -418,8 +407,10 @@ SQL;
418 407
             $response["recordsTotal"] = count($recordsTotalResults);
419 408
             array_pop($queryComposition);
420 409
         }
421
-
422
-        $queryComposition[] = $filterString ?? null;
410
+        */
411
+        if($filterString) {
412
+            $queryComposition[] = $filterString;
413
+        }
423 414
         if(empty($groupString)) {
424 415
             $recordsFilteredQuery = implode(PHP_EOL, $queryComposition);
425 416
             $recordsFilteredResults = $this->connection->execute($recordsFilteredQuery, $params)->fetch();
@@ -430,6 +421,7 @@ SQL;
430 421
             $recordsFilteredResults = $this->connection->execute($recordsFilteredQuery, $params)->fetchAll();
431 422
             $response["recordsFiltered"] = count($recordsFilteredResults);
432 423
         }
424
+        $response["recordsTotal"] = $response["recordsFiltered"];
433 425
         return $response;
434 426
     }
435 427
 
@@ -446,58 +438,58 @@ SQL;
446 438
         return $this->conf['utility_account'];
447 439
     }
448 440
 
449
-    public function charts($type, $hgm_name, $from, $to, $period) {
450
-            $sql = null;
451
-            switch($type) {
452
-                case 'payments':
453
-                    break;
454
-            }
455
-            if($period > 0) {
456
-                $clause = '';
457
-                $amount = '(SUM(amount))';
458
-                $groupby = ' GROUP BY YEAR(timestamp), MONTH(timestamp)';
459
-                if($period == 1) {
460
-                    $groupby.= ', DAY(timestamp)';
461
-                }
462
-            } else if($from && $to) {
463
-                $amount = '(amount)';
464
-                $clause = " AND timestamp BETWEEN '$from' AND '$to'";
465
-                $groupby = '';
466
-            } else {
467
-                $clause = null;
468
-                $groupby = null;
469
-            }
470
-            if($clause == null && $groupby == null) {
471
-                return [];
441
+    public function charts($type, $meter_name, $from, $to, $period) {
442
+        $sql = null;
443
+        switch($type) {
444
+            case 'payments':
445
+                break;
446
+        }
447
+        if($period > 0) {
448
+            $clause = '';
449
+            $amount = '(SUM(amount))';
450
+            $groupby = ' GROUP BY mon';
451
+            if($period == 1) {
452
+                $groupby.= ', day';
472 453
             }
473
-            $sql = <<<SQL
474
-SELECT timestamp, CONCAT('[',UNIX_TIMESTAMP(timestamp), ',', $amount, ']') AS data FROM blocks WHERE (wallet_from = :hgm_name AND wallet_to = :utility_account) AND type = 'payment' $clause $groupby
454
+        } else if($from && $to) {
455
+            $amount = '(amount)';
456
+            $clause = " AND timestamp BETWEEN '$from' AND '$to'";
457
+            $groupby = '';
458
+        } else {
459
+            $clause = null;
460
+            $groupby = null;
461
+        }
462
+        if($clause == null && $groupby == null) {
463
+            return [];
464
+        }
465
+        $sql = <<<SQL
466
+SELECT timestamp, CONCAT('[',UNIX_TIMESTAMP(timestamp), ',', $amount, ']') AS data FROM blocks WHERE (wallet_from = :meter_name AND wallet_to = :utility_account) AND type = 'payment' $clause $groupby
475 467
 UNION
476
-SELECT timestamp, CONCAT('[',UNIX_TIMESTAMP(timestamp), ',', ($amount*-1), ']') AS data FROM blocks WHERE (wallet_from = :utility_account AND wallet_to = :hgm_name) AND type = 'payment' $clause $groupby
468
+SELECT timestamp, CONCAT('[',UNIX_TIMESTAMP(timestamp), ',', ($amount*-1), ']') AS data FROM blocks WHERE (wallet_from = :utility_account AND wallet_to = :meter_name) AND type = 'payment' $clause $groupby
477 469
 ORDER BY timestamp ASC
478 470
 SQL;
479
-            $values = [
480
-                'hgm_name' => $hgm_name,
481
-                'utility_account' => $this->conf['utility_account']
482
-            ];
483
-            if($sql) {
484
-                $data = [];
485
-                $rows = ($this->connection->execute($sql,$values))->fetchAll(\PDO::FETCH_ASSOC);
486
-                foreach($rows as $row) {
487
-                    $data[] = json_decode($row['data']);
488
-                }
489
-                return $data;
490
-            } else {
491
-                return [];
471
+        $values = [
472
+            'meter_name' => $meter_name,
473
+            'utility_account' => $this->conf['utility_account']
474
+        ];
475
+        if($sql) {
476
+            $data = [];
477
+            $rows = ($this->connection->execute($sql,$values))->fetchAll(\PDO::FETCH_ASSOC);
478
+            foreach($rows as $row) {
479
+                $data[] = json_decode($row['data']);
492 480
             }
481
+            return $data;
482
+        } else {
483
+            return [];
493 484
         }
494
-    
495
-        public function setPrice($hgm_name, $buyPrice, $sellPrice) {
485
+    }
486
+
487
+    public function setPrice($meter_name, $buyPrice, $sellPrice) {
496 488
             $sql = <<<SQL
497
-UPDATE hgm SET buy = :buyPrice, sell = :sellPrice WHERE name = :hgm_name; 
489
+UPDATE meter SET buy = :buyPrice, sell = :sellPrice WHERE name = :meter_name; 
498 490
 SQL;
499 491
             $values = [
500
-                'hgm_name' => $hgm_name,
492
+                'meter_name' => $meter_name,
501 493
                 'buyPrice' => $buyPrice,
502 494
                 'sellPrice' => $sellPrice
503 495
             ];

+ 14
- 4
src/Utility/WalletEprosumeModel.php View File

@@ -26,13 +26,21 @@ class WalletEprosumeModel
26 26
         $this->walletAccountFolder = dirname($ini['wallet']['account']) ?? null;
27 27
     }
28 28
 
29
-    public function balance($hgm)
29
+    public function balance($meter)
30 30
     {
31
-        $walletExec = "$this->walletExecutable $this->walletCommandBalance $hgm --config $this->walletConfiguration " .
32
-            "--accounts-file $this->walletAccountFolder$hgm.txt 2>/dev/null";
31
+        $walletExec = "$this->walletExecutable $this->walletCommandBalance $meter --config $this->walletConfiguration " .
32
+            "--accounts-file $this->walletAccountFolder$meter.txt 2>/dev/null";
33 33
 
34 34
         exec($walletExec, $arrayOutput);
35 35
 
36
+        /*******
37
+         * Asset: PRS
38
+         * Balance: 263338
39
+         *
40
+         * ----------
41
+         * Asset: TFT
42
+         * Balance: 72864
43
+         */
36 44
         $balance = [];
37 45
         $asset = null;
38 46
         foreach ($arrayOutput as $line) {
@@ -140,6 +148,8 @@ class WalletEprosumeModel
140 148
                         }
141 149
                     }
142 150
                 }
151
+
152
+                print_r($block);
143 153
             }
144 154
         }
145 155
     }
@@ -158,7 +168,7 @@ class WalletEprosumeModel
158 168
                             : $v["name"]
159 169
                         ; 
160 170
                 }, 
161
-                ($this->connection->execute('select id, subid, name from hgm where `status` = "ACTIVE"'))->fetchAll(\PDO::FETCH_ASSOC)
171
+                ($this->connection->execute('select id, subid, name from meter where `status` = "ACTIVE"'))->fetchAll(\PDO::FETCH_ASSOC)
162 172
             )
163 173
         );
164 174
     }

+ 0
- 0
tests/Fixture/empty View File


+ 25
- 27
webroot/css/eprosume.css View File

@@ -21,33 +21,6 @@
21 21
   flex-grow: 0;
22 22
   margin: 0.25em !important;
23 23
 }
24
-.eprosume_lds-dual-ring {
25
-  display: block;
26
-  position: absolute;
27
-  top: 40%;
28
-  left: 50%;
29
-  width: 92px;
30
-  height: 92px;
31
-}
32
-.eprosume_lds-dual-ring:after {
33
-  content: " ";
34
-  display: block;
35
-  width: 92px;
36
-  height: 92px;
37
-  margin: 1px;
38
-  border-radius: 50%;
39
-  border: 5px solid #fff;
40
-  border-color: #fff transparent #fff transparent;
41
-  animation: lds-dual-ring 1.2s linear infinite;
42
-}
43
-@keyframes lds-dual-ring {
44
-  0% {
45
-    transform: rotate(0deg);
46
-  }
47
-  100% {
48
-    transform: rotate(360deg);
49
-  }
50
-}
51 24
 
52 25
 .eprosume_error {
53 26
   color: #cc0000;
@@ -65,7 +38,28 @@
65 38
   z-index: 9999;
66 39
   cursor: pointer;
67 40
 }
41
+.eprosume_loader {
42
+  position: absolute;
43
+  top: 10%;
44
+  left: 50%;
45
+  transform: translate(-50%,-50%);
46
+  width: 60px;
47
+  height: 60px;
48
+  border-radius: 50%;
49
+  border: 4px solid #009ed2;
50
+  border-right-color: transparent;
51
+  transform-origin: center;
52
+  animation: rotate 1s linear infinite;
53
+}
68 54
 
55
+@keyframes rotate {
56
+  from {
57
+    transform: rotate(0);
58
+  }
59
+  to {
60
+    transform: rotate(360deg);
61
+  }
62
+}
69 63
 .m-top-3 {
70 64
   margin-top: 3em;
71 65
 }
@@ -182,3 +176,7 @@
182 176
   height: 100%;
183 177
   width: 100%;
184 178
 }
179
+
180
+.sidebar-menu .border-top {
181
+  border-top: 1px solid white;
182
+}

+ 35
- 23
webroot/readhistory.php View File

@@ -1,4 +1,9 @@
1 1
 <?php
2
+/**
3
+ * Copyright: Mangrovia Blockchain Solutions S.r.l.
4
+ * Date: 04/01/2019
5
+ */
6
+
2 7
 error_reporting(E_ALL);
3 8
 ini_set('display_errors', 1);
4 9
 
@@ -8,14 +13,12 @@ if (! flock($fp, LOCK_EX | LOCK_NB)) {
8 13
     exit(-1);
9 14
 }
10 15
 
11
-$ini = parse_ini_file(dirname(__FILE__).'/../client.ini', true);
12
-$host = $ini['database']['host'] ?? null;
13
-$db   = $ini['database']['name'] ?? null;
14
-$user = $ini['database']['user'] ?? null;
15
-$pass = $ini['database']['pass'] ?? null;
16
-$charset = $ini['database']['charset'] ?? null;
17
-$conf = $ini['wallet'] ?? [];
18
-
16
+$conf = parse_ini_file(dirname(__FILE__).'/../client.ini', true);
17
+$host = $conf['db']['host'] ?? null;
18
+$db   = $conf['db']['name'] ?? null;
19
+$user = $conf['db']['user'] ?? null;
20
+$pass = $conf['db']['password'] ?? null;
21
+$charset = $conf['db']['charset'] ?? null;
19 22
 $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
20 23
 $options = [
21 24
 PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
@@ -30,9 +33,8 @@ try {
30 33
 
31 34
 $wallet = new WalletEprosume($pdo, $conf);
32 35
 
33
-
34 36
 // fetch accounts registered in the db
35
-$stmt = $pdo->prepare('select id,name,sell,buy from hgm');
37
+$stmt = $pdo->prepare('select id,name,sell,buy from meter');
36 38
 $stmt->execute();
37 39
 $accounts = $stmt->fetchAll();
38 40
 
@@ -57,11 +59,11 @@ class WalletEprosume
57 59
 
58 60
     private $conf = [];
59 61
 
60
-    public function __construct($pdo, $conf) {
61
-        $this->walletExecutable = $$conf['executable'] ?? null;
62
-        $this->walletConfiguration = $$conf['configuration'] ?? null;
63
-        $this->walletAccount = $$conf['account'] ?? null;
64
-        $this->walletAccountDirectory = dirname($$conf['account']) ?? null;
62
+    public function __construct($pdo=null, $conf) {
63
+        $this->walletExecutable = $conf['wallet']['executable'] ?? null;
64
+        $this->walletConfiguration = $conf['wallet']['configuration'] ?? null;
65
+        $this->walletAccount = $conf['wallet']['account'] ?? null;
66
+        $this->walletAccountDirectory = dirname($conf['wallet']['account']) ?? null;
65 67
         if($pdo) {
66 68
             // fetch configuration
67 69
             $stmt = $pdo->prepare('select conf_key, conf_value from conf');
@@ -80,7 +82,7 @@ class WalletEprosume
80 82
         $walletExec = "$this->walletExecutable $this->walletCommandBalance --config $this->walletConfiguration " .
81 83
             "--accounts-file $this->walletAccount --of $username 2>/dev/null";
82 84
         $type = "";
83
-        $values = ['HGM' => $id, 'PRS' => '' , 'TFT' => ''];
85
+        $values = ['Meter' => $id, 'PRS' => '' , 'TFT' => ''];
84 86
         exec($walletExec, $arrayOutput);
85 87
         foreach ($arrayOutput as $line) {
86 88
             $parameter = explode(': ', $line);
@@ -96,14 +98,13 @@ class WalletEprosume
96 98
             }
97 99
         }
98 100
         // check if the last registered balance is changed
99
-        $stmt = $pdo->prepare('select * from balances where hgm_id = :id order by timestamp desc limit 1');
101
+        $stmt = $pdo->prepare('select * from balances where meter_id = :id order by timestamp desc limit 1');
100 102
         $stmt->execute(['id'=>$id]);
101 103
         $result = $stmt->fetch();
102 104
         if(empty($result) || $result['prs'] != $values['PRS'] || $result['tft'] != $values['TFT']) {
103
-            $stmt = $pdo->prepare('insert into balances ( hgm_id, prs, tft) ' .
104
-            ' values ( :HGM, :PRS, :TFT ) ');
105
+            $stmt = $pdo->prepare('insert into balances ( meter_id, prs, tft) values ( :Meter, :PRS, :TFT ) ');
105 106
             $stmt->execute($values);
106
-            $stmt2 = $pdo->prepare('update hgm set prs = :PRS, tft = :TFT where id = :HGM');
107
+            $stmt2 = $pdo->prepare('update meter set prs = :PRS, tft = :TFT where id = :Meter');
107 108
             $stmt2->execute($values);
108 109
         }
109 110
 
@@ -117,6 +118,7 @@ class WalletEprosume
117 118
                 continue;
118 119
             }
119 120
             if($values[strtoupper($v)] < (int)$limit) {
121
+                var_dump("TRANSFER $from, ".$account['name'].", $transfer, $v, $memo");
120 122
                 $this->transfer($from, $account['name'], $transfer, $v, $memo);
121 123
             }
122 124
         }
@@ -178,12 +180,14 @@ class WalletEprosume
178 180
                 switch ($key) {
179 181
                     case '--------HistoryEnd--------':
180 182
                     case '--------------------':
183
+                        // Qui devi salvare i record
181 184
                         array_push($history, $transaction);
185
+
182 186
                         // check if there is a setPrice in history
183 187
                         if($setPriceFlag && isset($transaction['Asset']) && $transaction['Asset'] == 'TFT' && isset($transaction['Memo']) && count($transaction['Memo']) == 2) {
184 188
                             if(isset($transaction['Memo']['sellPrice']) && isset($transaction['Memo']['buyPrice']) && isset($transaction['To'])) {
185 189
                                     if($account['sell'] != $transaction['Memo']['sellPrice'] || $account['buy'] != $transaction['Memo']['buyPrice']) {
186
-                                        $stmt2 = $pdo->prepare("UPDATE hgm SET sell = ".$transaction['Memo']['sellPrice'].", buy = ".$transaction['Memo']['buyPrice']." WHERE name = '".$transaction['To']."'");
190
+                                        $stmt2 = $pdo->prepare("UPDATE meter SET sell = ".$transaction['Memo']['sellPrice'].", buy = ".$transaction['Memo']['buyPrice']." WHERE name = '".$transaction['To']."'");
187 191
                                         $stmt2->execute();    
188 192
                                     }
189 193
                             }
@@ -237,7 +241,7 @@ class WalletEprosume
237 241
             if(empty($entry)) {
238 242
                 /* memo keys in block table */
239 243
                 $block_tx_id = null;
240
-                $block_type = null;
244
+                $block_type = 'update_price';
241 245
                 $block_purchased_sold = null;
242 246
                 $block_buy_price = null;
243 247
                 $block_sell_price = null;
@@ -253,7 +257,7 @@ class WalletEprosume
253 257
                             $block_type = 'transfer';
254 258
                         } else if(count($block['Memo']) > 2) {
255 259
                             $block_type = 'measure';
256
-                        };
260
+                        }
257 261
                     }
258 262
                 }
259 263
                 $stmt = $pdo->prepare('insert into blocks (id, blocknumber,wallet_type,wallet_from,wallet_to,asset,amount,timestamp,memo_hash,tx_id,type,purchased_sold,buy_price,sell_price) ' .
@@ -283,6 +287,8 @@ class WalletEprosume
283 287
                 $stmt->execute($values);
284 288
                 $block_id = $pdo->lastInsertId();
285 289
 
290
+//                print_r($block);
291
+
286 292
                 if (($block_id) && (!empty($block['Memo']))) {
287 293
                     /* automatic payments */
288 294
                     $autopay_operation = null;
@@ -322,16 +328,19 @@ class WalletEprosume
322 328
                         switch($autopay_operation) {
323 329
                             case 'delete':
324 330
                                 $sql = 'delete from pending_payments where tx_id = "'.$autopay_txid.'"';
331
+                                var_dump($sql);
325 332
                                 $stmt = $pdo->prepare($sql);
326 333
                                 $stmt->execute();
327 334
                                 break;
328 335
                             case 'pay':
329 336
                                 $sql = 'select * from memo where memo_key = "txID" and memo_value = "'.$autopay_txid.'" and block_id != "'.$block_id.'"';
337
+                                var_dump($sql);
330 338
                                 $stmt = $pdo->prepare($sql);
331 339
                                 $stmt->execute();
332 340
                                 $memo_rows = $stmt->fetchAll();
333 341
                                 if(!$memo_rows || empty($memo_rows)) {
334 342
                                     $sql = 'select * from pending_payments where tx_id = "'.$autopay_txid.'"';
343
+                                    var_dump($sql);
335 344
                                     $stmt = $pdo->prepare($sql);
336 345
                                     $stmt->execute();
337 346
                                     $pending_payments_rows = $stmt->fetchAll();
@@ -347,6 +356,7 @@ class WalletEprosume
347 356
                                         $autopay = $this->transfer($from, $to, $amount, $asset, $memo);
348 357
                                         if($autopay) {
349 358
                                             $sql = 'insert into pending_payments(tx_id) values("'.$autopay_txid.'")';
359
+                                            var_dump($sql);
350 360
                                             $stmt = $pdo->prepare($sql);
351 361
                                             $stmt->execute();
352 362
                                         }
@@ -376,6 +386,7 @@ class WalletEprosume
376 386
             $asset = strtoupper($asset);
377 387
             $memo = str_replace("'", "\'", html_entity_decode($memo, ENT_QUOTES));
378 388
             $walletExec = "$this->walletExecutable $this->walletCommandTransfer --accounts-file $accountFile --to $to --asset $asset --amount $amount --memo '$memo' --config $this->walletConfiguration 2>&1";
389
+            var_dump($walletExec);
379 390
             $output = system($walletExec);
380 391
             return strpos($output, 'Assets correctly transferred', 0) !== false;
381 392
         }
@@ -387,6 +398,7 @@ class WalletEprosume
387 398
             return false;
388 399
         } else {
389 400
             $walletExec = "$this->walletExecutable $this->walletCommandUpdatePrices --accounts-file $this->walletAccount -b $buyPrice -s $sellPrice -u $user --config $this->walletConfiguration 2>&1";
401
+            var_dump($walletExec);
390 402
             $output = system($walletExec);
391 403
             return strpos($output, 'Assets correctly transferred', 0) !== false;
392 404
         }