diff --git a/config/routes.php b/config/routes.php index 4f7b5c609..1290ad06e 100644 --- a/config/routes.php +++ b/config/routes.php @@ -76,6 +76,7 @@ Router::scope('/', function (RouteBuilder $routes) { */ //$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); $routes->connect('/', ['controller' => 'Dashboard', 'action' => 'index']); + $routes->connect('/server', ['controller' => 'Dashboard', 'action' => 'serverIndex']); //$routes->connect('/', 'https://gradido2.dario-rekowski.de/account', array('status' => 303)); /** diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php index f7ac266ea..5f7118ef8 100644 --- a/src/Controller/DashboardController.php +++ b/src/Controller/DashboardController.php @@ -45,6 +45,15 @@ class DashboardController extends AppController } + public function serverIndex() + { + $startTime = microtime(true); + $this->viewBuilder()->setLayout('frontend'); + + + $this->set('timeUsed', microtime(true) - $startTime); + } + public function errorHttpRequest() { $startTime = microtime(true); diff --git a/src/Controller/TransactionCreationsController.php b/src/Controller/TransactionCreationsController.php index 8921493cd..a4c9434b0 100644 --- a/src/Controller/TransactionCreationsController.php +++ b/src/Controller/TransactionCreationsController.php @@ -7,6 +7,7 @@ use Cake\Routing\Router; //use Cake\I18n\Number; use Cake\Http\Client; use Cake\Core\Configure; +use Cake\Datasource\ConnectionManager; use App\Form\CreationForm; // protobuf transactions @@ -188,6 +189,84 @@ class TransactionCreationsController extends AppController } } } + + public function createMulti() + { + $startTime = microtime(true); + $this->viewBuilder()->setLayout('frontend'); + $session = $this->getRequest()->getSession(); + $user = $session->read('StateUser'); +// var_dump($user); + if(!$user) { + //return $this->redirect(Router::url('/', true) . 'account/', 303); + $result = $this->requestLogin(); + if($result !== true) { + return $result; + } + $user = $session->read('StateUser'); + } + $stateUserTable = TableRegistry::getTableLocator()->get('StateUsers'); + + $connection = ConnectionManager::get('default'); + $transactionActiveMonth = $connection->execute( + 'SELECT id, received FROM transactions ' + . 'where received >= date_add(curdate(), interval 1 - day(curdate()) day) ' + . 'AND ' + . 'received < date_add(date_add(curdate(), interval 1 - day(curdate()) day), interval 1 month) ' + . 'AND ' + . 'transaction_type_id = 1' + )->fetchAll('assoc'); + $transactionActiveMonthSortedById = []; + foreach($transactionActiveMonth as $t) { + $transactionActiveMonthSortedById[$t['id']] = $t['received']; + } + + $stateUsers = $stateUserTable + ->find('all') + ->select(['id', 'first_name', 'last_name', 'email']) + ->contain(['TransactionCreations' => [ + 'fields' => [ + 'TransactionCreations.amount', + 'TransactionCreations.transaction_id', + 'TransactionCreations.state_user_id' + ] + ]]); + + //var_dump($stateUsers->toArray()); + $possibleReceiver = []; + foreach($stateUsers as $stateUser) { + $sumAmount = 0; + foreach($stateUser->transaction_creations as $transactionCreation) { + //var_dump($transactionCreation); + if(isset($transactionActiveMonthSortedById[$transactionCreation->transaction_id])) { + $sumAmount += $transactionCreation->amount; + } + } + if($sumAmount < 10000000) { + array_push($possibleReceiver, [ + 'name' => $stateUser->first_name . ' ' . $stateUser->last_name, + 'id' => $stateUser->id, + 'email' => $stateUser->email, + 'amount' => $sumAmount + ]); + } + } + //var_dump($possibleReceiver); + $creationForm = new CreationForm(); + + $timeUsed = microtime(true) - $startTime; + $this->set(compact('timeUsed', 'stateUsers', 'creationForm', 'possibleReceiver')); + + $this->set('creationForm', $creationForm); + $this->set('timeUsed', microtime(true) - $startTime); + + if ($this->request->is('post')) { + $requestData = $this->request->getData(); + var_dump($requestData); + } + + + } /** * Add method diff --git a/src/Template/Dashboard/server_index.ctp b/src/Template/Dashboard/server_index.ctp new file mode 100644 index 000000000..552898569 --- /dev/null +++ b/src/Template/Dashboard/server_index.ctp @@ -0,0 +1,26 @@ +assign('title', __('Willkommen')); +?> +

Server Dashboard, nur für Admins

+
+
+

Gradido ...

+ Html->link( + __('einzeln schöpfen'), + ['controller' => 'TransactionCreations', 'action' => 'create'], + ['class' => 'grd-nav-bn grd-nav-bn-large'] + );?> + Html->link( + __('viele schöpfen'), + ['controller' => 'TransactionCreations', 'action' => 'createMulti'], + ['class' => 'grd-nav-bn grd-nav-bn-large'] + );?> +
+
\ No newline at end of file diff --git a/src/Template/TransactionCreations/create.ctp b/src/Template/TransactionCreations/create.ctp index 2a80968cb..82ffe236b 100644 --- a/src/Template/TransactionCreations/create.ctp +++ b/src/Template/TransactionCreations/create.ctp @@ -1,30 +1,31 @@ - $receiver) { - //var_dump($receiver); - array_push($address_options, [ - 'text' => $receiver['name'], - 'value' => $i+1, - 'title' => $receiver['key'] - ]); -} -$this->assign('title', __('Schöpfungstransaktion')); -?> -
- Form->create($creationForm) ?> -
- Form->control('memo'); ?> - Form->control('amount'); ?> - Form->control('receiver', ['options' => $address_options]); ?> - -
- Form->button(__('Transaktion(n) abschließen'), ['name' => 'next', 'class' => 'grd-form-bn grd-form-bn-succeed grd_clickable grd-width-200']) ?> - Form->button(__('Weitere Transaktion erstellen'), ['name' => 'add', 'class' => 'grd-form-bn grd_clickable grd-width-200']) ?> - Form->end() ?> -
+ $receiver) { + //var_dump($receiver); + array_push($address_options, [ + 'text' => $receiver['name'], + 'value' => $i+1, + 'title' => $receiver['key'] + ]); +} +$this->assign('title', __('Schöpfungstransaktion')); +?> +
+ + Form->create($creationForm) ?> +
+ Form->control('memo'); ?> + Form->control('amount'); ?> + Form->control('receiver', ['options' => $address_options]); ?> + +
+ Form->button(__('Transaktion(n) abschließen'), ['name' => 'next', 'class' => 'grd-form-bn grd-form-bn-succeed grd_clickable grd-width-200']) ?> + Form->button(__('Weitere Transaktion erstellen'), ['name' => 'add', 'class' => 'grd-form-bn grd_clickable grd-width-200']) ?> + Form->end() ?> +
diff --git a/src/Template/TransactionCreations/create_multi.ctp b/src/Template/TransactionCreations/create_multi.ctp new file mode 100644 index 000000000..e17e49993 --- /dev/null +++ b/src/Template/TransactionCreations/create_multi.ctp @@ -0,0 +1,60 @@ + $receiver) { + //var_dump($receiver); + array_push($address_options, [ + 'text' => $receiver['name'], + 'value' => $i+1, + 'title' => $receiver['key'] + ]); +}*/ +$this->assign('title', __('Schöpfungstransaktion')); +?> + +
+ + Form->create($creationForm) ?> +
+ Form->control('memo'); ?> + Form->control('amount'); ?> + +
+ Form->checkbox('user[' .$possibleReceiver['id'] . ']', ['hiddenField' => false]); ?> + + + <> +
+ + + In diesem Monat bereits geschöpft: element('printGradido', ['number' => $possibleReceiver['amount']]);?> + +
+
+ + +
+ Form->button(__('Transaktion(n) abschließen'), ['name' => 'next', 'class' => 'grd-form-bn grd-form-bn-succeed grd_clickable grd-width-200']) ?> + Form->button(__('Weitere Transaktion erstellen'), ['name' => 'add', 'class' => 'grd-form-bn grd_clickable grd-width-200']) ?> + Form->end() ?> +