adding multi creation transaction interface

This commit is contained in:
Dario Rekowski on RockPI 2019-11-29 16:18:34 +00:00
parent b3f4342d52
commit 1b1b0da7f0
6 changed files with 206 additions and 30 deletions

View File

@ -76,6 +76,7 @@ Router::scope('/', function (RouteBuilder $routes) {
*/ */
//$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); //$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
$routes->connect('/', ['controller' => 'Dashboard', 'action' => 'index']); $routes->connect('/', ['controller' => 'Dashboard', 'action' => 'index']);
$routes->connect('/server', ['controller' => 'Dashboard', 'action' => 'serverIndex']);
//$routes->connect('/', 'https://gradido2.dario-rekowski.de/account', array('status' => 303)); //$routes->connect('/', 'https://gradido2.dario-rekowski.de/account', array('status' => 303));
/** /**

View File

@ -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() public function errorHttpRequest()
{ {
$startTime = microtime(true); $startTime = microtime(true);

View File

@ -7,6 +7,7 @@ use Cake\Routing\Router;
//use Cake\I18n\Number; //use Cake\I18n\Number;
use Cake\Http\Client; use Cake\Http\Client;
use Cake\Core\Configure; use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;
use App\Form\CreationForm; use App\Form\CreationForm;
// protobuf transactions // 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 . '&nbsp;' . $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 * Add method

View File

@ -0,0 +1,26 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
$this->assign('title', __('Willkommen'));
?>
<h1>Server Dashboard, nur für Admins</h1>
<div class="grd_container_small">
<fieldset>
<h3>Gradido ...</h3>
<?= $this->Html->link(
__('einzeln schöpfen'),
['controller' => 'TransactionCreations', 'action' => 'create'],
['class' => 'grd-nav-bn grd-nav-bn-large']
);?>
<?= $this->Html->link(
__('viele schöpfen'),
['controller' => 'TransactionCreations', 'action' => 'createMulti'],
['class' => 'grd-nav-bn grd-nav-bn-large']
);?>
</fieldset>
</div>

View File

@ -1,30 +1,31 @@
<?php <?php
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template in the editor.
*/ */
$address_options = [];//__('Selbst eingeben:')]; $address_options = [];//__('Selbst eingeben:')];
foreach($receiverProposal as $i => $receiver) { foreach($receiverProposal as $i => $receiver) {
//var_dump($receiver); //var_dump($receiver);
array_push($address_options, [ array_push($address_options, [
'text' => $receiver['name'], 'text' => $receiver['name'],
'value' => $i+1, 'value' => $i+1,
'title' => $receiver['key'] 'title' => $receiver['key']
]); ]);
} }
$this->assign('title', __('Schöpfungstransaktion')); $this->assign('title', __('Schöpfungstransaktion'));
?> ?>
<div class="grd_container_small"> <div class="grd_container_small">
<?= $this->Form->create($creationForm) ?>
<fieldset> <?= $this->Form->create($creationForm) ?>
<?= $this->Form->control('memo'); ?> <fieldset>
<?= $this->Form->control('amount'); ?> <?= $this->Form->control('memo'); ?>
<?= $this->Form->control('receiver', ['options' => $address_options]); ?> <?= $this->Form->control('amount'); ?>
<!--<?= $this->Form->control('receiver_pubkey_hex', []) ?>--> <?= $this->Form->control('receiver', ['options' => $address_options]); ?>
</fieldset> <!--<?= $this->Form->control('receiver_pubkey_hex', []) ?>-->
<?= $this->Form->button(__('Transaktion(n) abschließen'), ['name' => 'next', 'class' => 'grd-form-bn grd-form-bn-succeed grd_clickable grd-width-200']) ?> </fieldset>
<?= $this->Form->button(__('Weitere Transaktion erstellen'), ['name' => 'add', 'class' => 'grd-form-bn grd_clickable grd-width-200']) ?> <?= $this->Form->button(__('Transaktion(n) abschließen'), ['name' => 'next', 'class' => 'grd-form-bn grd-form-bn-succeed grd_clickable grd-width-200']) ?>
<?= $this->Form->end() ?> <?= $this->Form->button(__('Weitere Transaktion erstellen'), ['name' => 'add', 'class' => 'grd-form-bn grd_clickable grd-width-200']) ?>
</div> <?= $this->Form->end() ?>
</div>

View File

@ -0,0 +1,60 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*$address_options = [];//__('Selbst eingeben:')];
foreach($receiverProposal as $i => $receiver) {
//var_dump($receiver);
array_push($address_options, [
'text' => $receiver['name'],
'value' => $i+1,
'title' => $receiver['key']
]);
}*/
$this->assign('title', __('Schöpfungstransaktion'));
?>
<style type="text/css">
input[type='checkbox'] {
width:25px;
}
.grd_big_checkbox {
border:1px dotted grey;
margin-bottom:5px;
}
.grd_smaller {
font-size:smaller;
color:blue;
}
</style>
<div class="grd_container_small">
<?= $this->Form->create($creationForm) ?>
<fieldset>
<?= $this->Form->control('memo'); ?>
<?= $this->Form->control('amount'); ?>
<?php foreach($possibleReceiver as $possibleReceiver) : ?>
<div class="grd_big_checkbox">
<?= $this->Form->checkbox('user[' .$possibleReceiver['id'] . ']', ['hiddenField' => false]); ?>
<?= $possibleReceiver['name'] ?>
<?php if($possibleReceiver['email'] != '') : ?>
&lt;<?= $possibleReceiver['email'] ?>&gt;
<?php endif; ?><br>
<?php if($possibleReceiver['amount'] != 0) : ?>
<span class="grd_smaller">
In diesem Monat bereits geschöpft: <?= $this->element('printGradido', ['number' => $possibleReceiver['amount']]);?></span>
<?php endif; ?>
<br>
</div>
<?php endforeach; ?>
<!--<?= $this->Form->control('receiver_pubkey_hex', []) ?>-->
</fieldset>
<?= $this->Form->button(__('Transaktion(n) abschließen'), ['name' => 'next', 'class' => 'grd-form-bn grd-form-bn-succeed grd_clickable grd-width-200']) ?>
<?= $this->Form->button(__('Weitere Transaktion erstellen'), ['name' => 'add', 'class' => 'grd-form-bn grd_clickable grd-width-200']) ?>
<?= $this->Form->end() ?>
</div>