mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
User Search in create-multi
This commit is contained in:
parent
b34eb8d9ef
commit
c216103520
@ -201,7 +201,7 @@ class AppController extends Controller
|
||||
if ($stateUser->first_name != $json['user']['first_name'] ||
|
||||
$stateUser->last_name != $json['user']['last_name'] ||
|
||||
//$stateUser->username != $json['user']['username'] ||
|
||||
// -> throws erro
|
||||
// -> throws error
|
||||
$stateUser->email != $json['user']['email']) {
|
||||
$stateUser->first_name = $json['user']['first_name'];
|
||||
$stateUser->last_name = $json['user']['last_name'];
|
||||
|
||||
@ -53,9 +53,9 @@ class TransactionCreationsController extends AppController
|
||||
];
|
||||
$transactionCreations = $this->paginate($this->TransactionCreations);
|
||||
$identHashes = [];
|
||||
foreach($transactionCreations as $creation) {
|
||||
$identHash = TransactionCreation::DRMakeStringHash($creation->state_user->email);
|
||||
$identHashes[$creation->state_user->id] = $identHash;
|
||||
foreach ($transactionCreations as $creation) {
|
||||
$identHash = TransactionCreation::DRMakeStringHash($creation->state_user->email);
|
||||
$identHashes[$creation->state_user->id] = $identHash;
|
||||
}
|
||||
|
||||
$this->set(compact('transactionCreations', 'identHashes'));
|
||||
@ -83,14 +83,12 @@ class TransactionCreationsController extends AppController
|
||||
$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');
|
||||
if (!$user) {
|
||||
$result = $this->requestLogin();
|
||||
if ($result !== true) {
|
||||
return $result;
|
||||
}
|
||||
$user = $session->read('StateUser');
|
||||
}
|
||||
$creationForm = new CreationForm();
|
||||
$transactionCreation = $this->TransactionCreations->newEntity();
|
||||
@ -100,93 +98,90 @@ class TransactionCreationsController extends AppController
|
||||
$stateUserTable = TableRegistry::getTableLocator()->get('StateUsers');
|
||||
$stateUsers = $stateUserTable->find('all')->contain(false);
|
||||
$receiverProposal = [];
|
||||
foreach($stateUsers as $stateUser) {
|
||||
$name = $stateUser->email;
|
||||
$keyHex = bin2hex(stream_get_contents($stateUser->public_key));
|
||||
if($name === NULL) {
|
||||
$name = $stateUser->first_name . ' ' . $stateUser->last_name;
|
||||
}
|
||||
array_push($receiverProposal, ['name' => $name, 'key' => $keyHex, 'email' => $stateUser->email]);
|
||||
foreach ($stateUsers as $stateUser) {
|
||||
$name = $stateUser->email;
|
||||
$keyHex = bin2hex(stream_get_contents($stateUser->public_key));
|
||||
if ($name === null) {
|
||||
$name = $stateUser->first_name . ' ' . $stateUser->last_name;
|
||||
}
|
||||
array_push($receiverProposal, ['name' => $name, 'key' => $keyHex, 'email' => $stateUser->email]);
|
||||
//$stateUser->public_key
|
||||
}
|
||||
$timeUsed = microtime(true) - $startTime;
|
||||
$this->set(compact('transactionCreation', 'timeUsed', 'receiverProposal', 'creationForm'));
|
||||
|
||||
if ($this->request->is('post')) {
|
||||
$requestData = $this->request->getData();
|
||||
$mode = 'next';
|
||||
if(isset($requestData['add'])) {$mode = 'add'; }
|
||||
if($creationForm->validate($requestData)) {
|
||||
|
||||
$pubKeyHex = '';
|
||||
$identHash = '';
|
||||
$amountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['amount']);
|
||||
$receiverIndex = intval($requestData['receiver'])-1;
|
||||
|
||||
if(count($receiverProposal) > $receiverIndex) {
|
||||
$pubKeyHex = $receiverProposal[$receiverIndex]['key'];
|
||||
$identHash = TransactionCreation::DRMakeStringHash($receiverProposal[$receiverIndex]['email']);
|
||||
//echo "identHash: $identHash for " . $receiverProposal[$receiverIndex]['email'];
|
||||
$requestData = $this->request->getData();
|
||||
$mode = 'next';
|
||||
if (isset($requestData['add'])) {
|
||||
$mode = 'add';
|
||||
}
|
||||
$builderResult = TransactionCreation::build(
|
||||
if ($creationForm->validate($requestData)) {
|
||||
$pubKeyHex = '';
|
||||
$identHash = '';
|
||||
$amountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['amount']);
|
||||
$receiverIndex = intval($requestData['receiver'])-1;
|
||||
|
||||
if (count($receiverProposal) > $receiverIndex) {
|
||||
$pubKeyHex = $receiverProposal[$receiverIndex]['key'];
|
||||
$identHash = TransactionCreation::DRMakeStringHash($receiverProposal[$receiverIndex]['email']);
|
||||
}
|
||||
$builderResult = TransactionCreation::build(
|
||||
$amountCent,
|
||||
$requestData['memo'],
|
||||
$pubKeyHex,
|
||||
$identHash
|
||||
);
|
||||
// echo "builder result state: " . $builderResult['state'] . '<br>';
|
||||
if($builderResult['state'] == 'success') {
|
||||
|
||||
$user_balance = 0;
|
||||
if(isset($user['balance'])) {
|
||||
$user_balance = $user['balance'];
|
||||
}
|
||||
// $session_id, $base64Message, $user_balance = 0
|
||||
$requestResult = $this->JsonRequestClient->sendTransaction(
|
||||
$session->read('session_id'),
|
||||
base64_encode($builderResult['transactionBody']->serializeToString()),
|
||||
$user_balance
|
||||
);
|
||||
if($requestResult['state'] != 'success') {
|
||||
$this->addAdminError('TransactionCreations', 'create', $requestResult, $user['id']);
|
||||
if($requestResult['type'] == 'request error') {
|
||||
$this->Flash->error(__('Error by requesting LoginServer, please try again'));
|
||||
);
|
||||
if ($builderResult['state'] == 'success') {
|
||||
$user_balance = 0;
|
||||
if (isset($user['balance'])) {
|
||||
$user_balance = $user['balance'];
|
||||
}
|
||||
// $session_id, $base64Message, $user_balance = 0
|
||||
$requestResult = $this->JsonRequestClient->sendTransaction(
|
||||
$session->read('session_id'),
|
||||
base64_encode($builderResult['transactionBody']->serializeToString()),
|
||||
$user_balance
|
||||
);
|
||||
if ($requestResult['state'] != 'success') {
|
||||
$this->addAdminError('TransactionCreations', 'create', $requestResult, $user['id']);
|
||||
if ($requestResult['type'] == 'request error') {
|
||||
$this->Flash->error(__('Error by requesting LoginServer, please try again'));
|
||||
} else {
|
||||
$this->Flash->error(__('Error, please wait for the admin to fix it'));
|
||||
}
|
||||
} else {
|
||||
$json = $requestResult['data'];
|
||||
if ($json['state'] != 'success') {
|
||||
if ($json['msg'] == 'session not found') {
|
||||
$session->destroy();
|
||||
return $this->redirect($this->loginServerUrl . 'account', 303);
|
||||
} else {
|
||||
$this->addAdminError('TransactionCreations', 'create', $json, $user['id']);
|
||||
$this->Flash->error(__('Login Server Error, please wait for the admin to fix it'));
|
||||
}
|
||||
} else {
|
||||
$pendingTransactionCount = $session->read('Transactions.pending');
|
||||
if ($pendingTransactionCount == null) {
|
||||
$pendingTransactionCount = 1;
|
||||
} else {
|
||||
$pendingTransactionCount++;
|
||||
}
|
||||
$session->write('Transactions.pending', $pendingTransactionCount);
|
||||
if ($mode === 'next') {
|
||||
return $this->redirect($this->loginServerUrl . 'account/checkTransactions', 303);
|
||||
} else {
|
||||
$this->Flash->success(__('Transaction submitted for review.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->Flash->error(__('Error, please wait for the admin to fix it'));
|
||||
$this->Flash->error(__('Building transaction failed'));
|
||||
}
|
||||
} else {
|
||||
$json = $requestResult['data'];
|
||||
if($json['state'] != 'success') {
|
||||
if($json['msg'] == 'session not found') {
|
||||
$session->destroy();
|
||||
return $this->redirect($this->loginServerUrl . 'account', 303);
|
||||
} else {
|
||||
$this->addAdminError('TransactionCreations', 'create', $json, $user['id']);
|
||||
$this->Flash->error(__('Login Server Error, please wait for the admin to fix it'));
|
||||
}
|
||||
} else {
|
||||
$pendingTransactionCount = $session->read('Transactions.pending');
|
||||
if($pendingTransactionCount == null) {
|
||||
$pendingTransactionCount = 1;
|
||||
} else {
|
||||
$pendingTransactionCount++;
|
||||
}
|
||||
$session->write('Transactions.pending', $pendingTransactionCount);
|
||||
//echo "pending: " . $pendingTransactionCount;
|
||||
if($mode === 'next') {
|
||||
return $this->redirect($this->loginServerUrl . 'account/checkTransactions', 303);
|
||||
} else {
|
||||
$this->Flash->success(__('Transaction submitted for review.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
// */
|
||||
} else {
|
||||
$this->Flash->error(__('Building transaction failed'));
|
||||
$this->Flash->error(__('Something was invalid, please try again!'));
|
||||
}
|
||||
// */
|
||||
} else {
|
||||
$this->Flash->error(__('Something was invalid, please try again!'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,8 +192,8 @@ class TransactionCreationsController extends AppController
|
||||
$session = $this->getRequest()->getSession();
|
||||
$result = $this->requestLogin();
|
||||
$limit = 200;
|
||||
if($result !== true) {
|
||||
return $result;
|
||||
if ($result !== true) {
|
||||
return $result;
|
||||
}
|
||||
$user = $session->read('StateUser');
|
||||
|
||||
@ -206,7 +201,7 @@ class TransactionCreationsController extends AppController
|
||||
|
||||
$connection = ConnectionManager::get('default');
|
||||
$transactionActiveMonth = $connection->execute(
|
||||
'SELECT id, received FROM transactions '
|
||||
'SELECT id, received FROM transactions '
|
||||
. 'where received >= date_sub(date_add(curdate(), interval 1 - day(curdate()) day), interval 2 month) '
|
||||
. 'AND '
|
||||
. 'received < date_add(date_add(curdate(), interval 1 - day(curdate()) day), interval 2 month) '
|
||||
@ -214,8 +209,8 @@ class TransactionCreationsController extends AppController
|
||||
. 'transaction_type_id = 1'
|
||||
)->fetchAll('assoc');
|
||||
$transactionActiveMonthSortedById = [];
|
||||
foreach($transactionActiveMonth as $t) {
|
||||
$transactionActiveMonthSortedById[$t['id']] = $t['received'];
|
||||
foreach ($transactionActiveMonth as $t) {
|
||||
$transactionActiveMonthSortedById[$t['id']] = $t['received'];
|
||||
}
|
||||
$firstDayLastMonth = new FrozenDate();
|
||||
$firstDayLastMonth = $firstDayLastMonth->day(1)->subMonth(1);
|
||||
@ -231,14 +226,27 @@ class TransactionCreationsController extends AppController
|
||||
]);
|
||||
|
||||
$transactionsLastMonthTargetDateSortedByStateUserId = [];
|
||||
foreach($transactionsLastMonthTargeDate as $transactionCreation) {
|
||||
$transactionsLastMonthTargetDateSortedByStateUserId[$transactionCreation->state_user_id] = $transactionCreation->sum_amount;
|
||||
foreach ($transactionsLastMonthTargeDate as $transactionCreation) {
|
||||
$transactionsLastMonthTargetDateSortedByStateUserId[$transactionCreation->state_user_id] = $transactionCreation->sum_amount;
|
||||
}
|
||||
|
||||
$stateUsers = $stateUserTable
|
||||
$requestData = $this->request->getData();
|
||||
if ($this->request->is('post') &&
|
||||
isset($requestData['searchButton']) &&
|
||||
isset($requestData['searchText']) &&
|
||||
!empty($requestData['searchText'])
|
||||
) {
|
||||
$mode = 'search';
|
||||
$this->log("search for text: ".$requestData['searchText'], 'debug');
|
||||
$stateUsers = $stateUserTable
|
||||
->find('all')
|
||||
->select(['id', 'first_name', 'last_name', 'email'])
|
||||
->order(['id'])
|
||||
->order(['first_name', 'last_name'])
|
||||
->where(['OR' => [
|
||||
'LOWER(first_name)' => strtolower($requestData['searchText']),
|
||||
'LOWER(last_name)' => strtolower($requestData['searchText']),
|
||||
'LOWER(email)' => strtolower($requestData['searchText'])
|
||||
]])
|
||||
->contain(['TransactionCreations' => [
|
||||
'fields' => [
|
||||
'TransactionCreations.amount',
|
||||
@ -246,30 +254,44 @@ class TransactionCreationsController extends AppController
|
||||
'TransactionCreations.state_user_id'
|
||||
]
|
||||
]]);
|
||||
$this->log("search query: ".$stateUsers, 'debug');
|
||||
} else {
|
||||
$stateUsers = $stateUserTable
|
||||
->find('all')
|
||||
->select(['id', 'first_name', 'last_name', 'email'])
|
||||
//->order(['id'])
|
||||
->order(['first_name', 'last_name'])
|
||||
->contain(['TransactionCreations' => [
|
||||
'fields' => [
|
||||
'TransactionCreations.amount',
|
||||
'TransactionCreations.transaction_id',
|
||||
'TransactionCreations.state_user_id'
|
||||
]
|
||||
]]);
|
||||
}
|
||||
|
||||
//var_dump($stateUsers->toArray());
|
||||
$possibleReceiver = [];
|
||||
$possibleReceivers = [];
|
||||
$countUsers = 0;
|
||||
foreach($stateUsers as $i => $stateUser) {
|
||||
$countUsers++;
|
||||
if($i < $page * $limit || $i >= ($page + 1) * $limit) {
|
||||
continue;
|
||||
}
|
||||
$sumAmount = 0;
|
||||
$sumAmount2 = 0;
|
||||
if(isset($transactionsLastMonthTargetDateSortedByStateUserId[$stateUser->id])) {
|
||||
$sumAmount2 = $transactionsLastMonthTargetDateSortedByStateUserId[$stateUser->id];
|
||||
}
|
||||
foreach($stateUser->transaction_creations as $transactionCreation) {
|
||||
//var_dump($transactionCreation);
|
||||
if(isset($transactionActiveMonthSortedById[$transactionCreation->transaction_id])) {
|
||||
$sumAmount += $transactionCreation->amount;
|
||||
foreach ($stateUsers as $i => $stateUser) {
|
||||
$countUsers++;
|
||||
if ($i < $page * $limit || $i >= ($page + 1) * $limit) {
|
||||
continue;
|
||||
}
|
||||
$sumAmount = 0;
|
||||
$sumAmount2 = 0;
|
||||
if (isset($transactionsLastMonthTargetDateSortedByStateUserId[$stateUser->id])) {
|
||||
$sumAmount2 = $transactionsLastMonthTargetDateSortedByStateUserId[$stateUser->id];
|
||||
}
|
||||
foreach ($stateUser->transaction_creations as $transactionCreation) {
|
||||
//var_dump($transactionCreation);
|
||||
if (isset($transactionActiveMonthSortedById[$transactionCreation->transaction_id])) {
|
||||
$sumAmount += $transactionCreation->amount;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//if($sumAmount < 20000000) {
|
||||
array_push($possibleReceiver, [
|
||||
array_push($possibleReceivers, [
|
||||
'name' => $stateUser->first_name . ' ' . $stateUser->last_name,
|
||||
'id' => $stateUser->id,
|
||||
'email' => $stateUser->email,
|
||||
@ -280,14 +302,14 @@ class TransactionCreationsController extends AppController
|
||||
$this->Flash->error(__('Creation above 2.000 GDD for 2 last two month'));
|
||||
}*/
|
||||
}
|
||||
usort($possibleReceiver, function($a, $b) {
|
||||
return (strtolower ($a['name']) <=> strtolower ($b['name']));
|
||||
});
|
||||
//var_dump($possibleReceiver);
|
||||
// usort($possibleReceivers, function ($a, $b) {
|
||||
// return (strtolower($a['name']) <=> strtolower($b['name']));
|
||||
// });
|
||||
// -> replaced by SQL "order by" above
|
||||
$creationForm = new CreationForm();
|
||||
|
||||
$timeUsed = microtime(true) - $startTime;
|
||||
$this->set(compact('timeUsed', 'stateUsers', 'creationForm', 'possibleReceiver'));
|
||||
$this->set(compact('timeUsed', 'stateUsers', 'creationForm', 'possibleReceivers'));
|
||||
|
||||
$this->set('firstDayLastMonth', $firstDayLastMonth);
|
||||
$this->set('activeUser', $user);
|
||||
@ -298,131 +320,122 @@ class TransactionCreationsController extends AppController
|
||||
$this->set('limit', $limit);
|
||||
$this->set('page', $page);
|
||||
|
||||
if ($this->request->is('post')) {
|
||||
$requestData = $this->request->getData();
|
||||
//var_dump($requestData);
|
||||
//var_dump($this->request->getData('user'));
|
||||
//die("miau");
|
||||
// memo
|
||||
// amount
|
||||
$memo = $requestData['memo'];
|
||||
$amountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['amount']);
|
||||
$targetDate = $requestData['target_date'];
|
||||
$mode = 'next';
|
||||
if(isset($requestData['add'])) {$mode = 'add'; }
|
||||
|
||||
if(!isset($requestData['user']) || count($requestData['user']) == 0) {
|
||||
$this->Flash->error(__('no user choosen'));
|
||||
} else {
|
||||
$users = $requestData['user'];
|
||||
if(isset($requestData['user_pending'])) {
|
||||
$pendings = $requestData['user_pending'];
|
||||
if ($this->request->is('post') && (!isset($mode) || !($mode === 'search'))) {
|
||||
$this->log("real POST", 'debug');
|
||||
$mode = 'next';
|
||||
if (isset($requestData['add'])) {
|
||||
$mode = 'add';
|
||||
}
|
||||
$memo = $requestData['memo'];
|
||||
$amountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['amount']);
|
||||
//$targetDate = $requestData['target_date'];
|
||||
if (!isset($requestData['user']) || count($requestData['user']) == 0) {
|
||||
$this->Flash->error(__('No user selected'));
|
||||
} else {
|
||||
$pendings = [];
|
||||
}
|
||||
//var_dump(array_keys($users));
|
||||
$receiverUsers = $stateUserTable
|
||||
->find('all')
|
||||
->where(['id IN' => array_keys($users)])
|
||||
->select(['public_key', 'email', 'id'])
|
||||
->contain(false);
|
||||
$transactions = [];
|
||||
//var_dump($receiverUsers);
|
||||
foreach($receiverUsers as $receiverUser) {
|
||||
$localAmountCent = $amountCent;
|
||||
$localTargetDate = $targetDate;
|
||||
$id = $receiverUser->id;
|
||||
if($requestData['user_amount'][$id] != '') {
|
||||
$localAmountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['user_amount'][$id]);
|
||||
}
|
||||
if(isset($requestData['user_target_date']) && isset($requestData['user_target_date'][$id])) {
|
||||
$localTargetDate = $requestData['user_target_date'][$id];
|
||||
}
|
||||
if(isset($pendings[$id])) {
|
||||
$pendings[$id] += $localAmountCent;
|
||||
} else {
|
||||
$pendings[$id] = $localAmountCent;
|
||||
}
|
||||
$pubKeyHex = bin2hex(stream_get_contents($receiverUser->public_key));
|
||||
$identHash = TransactionCreation::DRMakeStringHash($receiverUser->email);
|
||||
//var_dump($localTargetDate);
|
||||
//die('a');
|
||||
$localTargetDateFrozen = FrozenDate::now();
|
||||
$localTargetDateFrozen = $localTargetDateFrozen
|
||||
->year($localTargetDate['year'])
|
||||
->month($localTargetDate['month'])
|
||||
->day($localTargetDate['day']);
|
||||
//echo "input: "; var_dump($localTargetDate);echo "<br>";
|
||||
//echo "output: "; var_dump($localTargetDateFrozen);
|
||||
//die('a');
|
||||
$builderResult = TransactionCreation::build(
|
||||
$localAmountCent,
|
||||
$memo,
|
||||
$pubKeyHex,
|
||||
$identHash,
|
||||
$localTargetDateFrozen
|
||||
);
|
||||
if($builderResult['state'] == 'success') {
|
||||
array_push($transactions, base64_encode($builderResult['transactionBody']->serializeToString()));
|
||||
}
|
||||
}
|
||||
/*echo "pendings: ";
|
||||
var_dump($pendings);
|
||||
echo "<br>";*/
|
||||
foreach($possibleReceiver as $i => $_possibleReceiver) {
|
||||
$id = $_possibleReceiver['id'];
|
||||
if(isset($pendings[$id])) {
|
||||
$possibleReceiver[$i]['pending'] = $pendings[$id];
|
||||
}
|
||||
}
|
||||
$this->set('possibleReceiver', $possibleReceiver);
|
||||
$creationTransactionCount = count($transactions);
|
||||
if($creationTransactionCount > 0) {
|
||||
$user_balance = 0;
|
||||
if(isset($user['balance'])) {
|
||||
$user_balance = $user['balance'];
|
||||
}
|
||||
// $session_id, $base64Message, $user_balance = 0
|
||||
$requestResult = $this->JsonRequestClient->sendTransaction(
|
||||
$session->read('session_id'),
|
||||
$transactions,
|
||||
$user_balance
|
||||
);
|
||||
if($requestResult['state'] != 'success') {
|
||||
$this->addAdminError('TransactionCreations', 'createMulti', $requestResult, $user['id']);
|
||||
if($requestResult['type'] == 'request error') {
|
||||
$this->Flash->error(__('Error by requesting LoginServer, please try again'));
|
||||
$users = $requestData['user'];
|
||||
if (isset($requestData['user_pending'])) {
|
||||
$pendings = $requestData['user_pending'];
|
||||
} else {
|
||||
$this->Flash->error(__('Error, please wait for the admin to fix it'));
|
||||
$pendings = [];
|
||||
}
|
||||
} else {
|
||||
$json = $requestResult['data'];
|
||||
if($json['state'] != 'success') {
|
||||
if($json['msg'] == 'session not found') {
|
||||
$session->destroy();
|
||||
return $this->redirect($this->loginServerUrl . 'account', 303);
|
||||
} else {
|
||||
$this->addAdminError('TransactionCreations', 'createMulti', $json, $user['id']);
|
||||
$this->Flash->error(__('Login Server Error, please wait for the admin to fix it'));
|
||||
}
|
||||
} else {
|
||||
$pendingTransactionCount = $session->read('Transactions.pending');
|
||||
if($pendingTransactionCount == null) {
|
||||
$pendingTransactionCount = $creationTransactionCount;
|
||||
} else {
|
||||
$pendingTransactionCount += $creationTransactionCount;
|
||||
}
|
||||
$session->write('Transactions.pending', $pendingTransactionCount);
|
||||
//echo "pending: " . $pendingTransactionCount;
|
||||
if($mode === 'next') {
|
||||
return $this->redirect($this->loginServerUrl . 'account/checkTransactions', 303);
|
||||
} else {
|
||||
$this->Flash->success(__('Transaction submitted for review.'));
|
||||
}
|
||||
$receiverUsers = $stateUserTable
|
||||
->find('all')
|
||||
->where(['id IN' => array_keys($users)])
|
||||
->select(['public_key', 'email', 'id'])
|
||||
->contain(false);
|
||||
$transactions = [];
|
||||
foreach ($receiverUsers as $receiverUser) {
|
||||
$localAmountCent = $amountCent;
|
||||
//$localTargetDate = $targetDate;
|
||||
$id = $receiverUser->id;
|
||||
if ($requestData['user_amount'][$id] != '') {
|
||||
$localAmountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['user_amount'][$id]);
|
||||
}
|
||||
if (isset($requestData['user_target_date']) && isset($requestData['user_target_date'][$id])) {
|
||||
$localTargetDate = $requestData['user_target_date'][$id];
|
||||
}
|
||||
if (isset($pendings[$id])) {
|
||||
$pendings[$id] += $localAmountCent;
|
||||
} else {
|
||||
$pendings[$id] = $localAmountCent;
|
||||
}
|
||||
$pubKeyHex = bin2hex(stream_get_contents($receiverUser->public_key));
|
||||
$identHash = TransactionCreation::DRMakeStringHash($receiverUser->email);
|
||||
$localTargetDateFrozen = FrozenDate::now();
|
||||
$localTargetDateFrozen = $localTargetDateFrozen
|
||||
->year($localTargetDate['year'])
|
||||
->month($localTargetDate['month'])
|
||||
->day($localTargetDate['day']);
|
||||
//echo "input: "; var_dump($localTargetDate);echo "<br>";
|
||||
//echo "output: "; var_dump($localTargetDateFrozen);
|
||||
//die('a');
|
||||
$builderResult = TransactionCreation::build(
|
||||
$localAmountCent,
|
||||
$memo,
|
||||
$pubKeyHex,
|
||||
$identHash,
|
||||
$localTargetDateFrozen
|
||||
);
|
||||
if ($builderResult['state'] == 'success') {
|
||||
array_push($transactions, base64_encode($builderResult['transactionBody']->serializeToString()));
|
||||
}
|
||||
}
|
||||
echo "pendings: ";
|
||||
var_dump($pendings);
|
||||
echo "<br>";
|
||||
foreach ($possibleReceivers as $i => $possibleReceiver) {
|
||||
$id = $possibleReceiver['id'];
|
||||
if (isset($pendings[$id])) {
|
||||
$possibleReceivers[$i]['pending'] = $pendings[$id];
|
||||
}
|
||||
}
|
||||
$this->set('possibleReceivers', $possibleReceivers);
|
||||
$creationTransactionCount = count($transactions);
|
||||
if ($creationTransactionCount > 0) {
|
||||
$user_balance = 0;
|
||||
if (isset($user['balance'])) {
|
||||
$user_balance = $user['balance'];
|
||||
}
|
||||
// $session_id, $base64Message, $user_balance = 0
|
||||
$requestResult = $this->JsonRequestClient->sendTransaction(
|
||||
$session->read('session_id'),
|
||||
$transactions,
|
||||
$user_balance
|
||||
);
|
||||
if ($requestResult['state'] != 'success') {
|
||||
$this->addAdminError('TransactionCreations', 'createMulti', $requestResult, $user['id']);
|
||||
if ($requestResult['type'] == 'request error') {
|
||||
$this->Flash->error(__('Error by requesting LoginServer, please try again'));
|
||||
} else {
|
||||
$this->Flash->error(__('Error, please wait for the admin to fix it'));
|
||||
}
|
||||
} else {
|
||||
$json = $requestResult['data'];
|
||||
if ($json['state'] != 'success') {
|
||||
if ($json['msg'] == 'session not found') {
|
||||
$session->destroy();
|
||||
return $this->redirect($this->loginServerUrl . 'account', 303);
|
||||
} else {
|
||||
$this->addAdminError('TransactionCreations', 'createMulti', $json, $user['id']);
|
||||
$this->Flash->error(__('Login Server Error, please wait for the admin to fix it'));
|
||||
}
|
||||
} else {
|
||||
$pendingTransactionCount = $session->read('Transactions.pending');
|
||||
if ($pendingTransactionCount == null) {
|
||||
$pendingTransactionCount = $creationTransactionCount;
|
||||
} else {
|
||||
$pendingTransactionCount += $creationTransactionCount;
|
||||
}
|
||||
$session->write('Transactions.pending', $pendingTransactionCount);
|
||||
if ($mode === 'next') {
|
||||
return $this->redirect($this->loginServerUrl . 'account/checkTransactions', 303);
|
||||
} else {
|
||||
$this->Flash->success(__('Transaction submitted for review.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// in src/Form/ContactForm.php
|
||||
<?php
|
||||
// in src/Form/TransferForm.php
|
||||
namespace App\Form;
|
||||
|
||||
use Cake\Form\Form;
|
||||
@ -19,7 +19,7 @@ class TransferForm extends Form
|
||||
|
||||
function validationDefault(Validator $validator)
|
||||
{
|
||||
$validator->setProvider('custom', 'App\Model\Validation\TransactionValidation');
|
||||
$validator->setProvider('custom', 'App\Model\Validation\TransactionValidation');
|
||||
/*
|
||||
$validator->add('receiver_pubkey_hex', 'length', [
|
||||
'rule' => ['length', 64],
|
||||
@ -54,7 +54,7 @@ class TransferForm extends Form
|
||||
->allowEmptyString('receiver_pubkey_hex', null, 'create')*/
|
||||
->add('amount', 'custom', [
|
||||
'rule' => 'amount',
|
||||
'provider' => 'custom',
|
||||
'provider' => 'custom',
|
||||
'message' => __('Please give a valid positive number with maximal 2 decimal places')
|
||||
]);
|
||||
return $validator;
|
||||
@ -72,4 +72,4 @@ class TransferForm extends Form
|
||||
// Send an email.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -344,7 +344,7 @@ msgid "Building transaction failed"
|
||||
msgstr ""
|
||||
|
||||
#: Controller/TransactionCreationsController.php:262
|
||||
msgid "no user choosen"
|
||||
msgid "No user selected"
|
||||
msgstr ""
|
||||
|
||||
#: Controller/TransactionCreationsController.php:373
|
||||
|
||||
@ -347,7 +347,7 @@ msgid "Building transaction failed"
|
||||
msgstr ""
|
||||
|
||||
#: Controller/TransactionCreationsController.php:267
|
||||
msgid "no user choosen"
|
||||
msgid "No user selected"
|
||||
msgstr ""
|
||||
|
||||
#: Controller/TransactionCreationsController.php:378
|
||||
|
||||
@ -55,7 +55,7 @@ $this->assign(
|
||||
<i class="material-icons-outlined">redeem</i>
|
||||
<!-- insights / redeem -->
|
||||
<?= $this->Html->link(
|
||||
__('viele schöpfen'),
|
||||
__('schöpfen'),
|
||||
['controller' => 'TransactionCreations', 'action' => 'createMulti'],
|
||||
['class' => 'action-button-link']
|
||||
);?>
|
||||
|
||||
@ -15,123 +15,99 @@ foreach($receiverProposal as $i => $receiver) {
|
||||
]);
|
||||
}*/
|
||||
$this->assign('title', __('Schöpfungstransaktion'));
|
||||
$this->loadHelper('Form', [
|
||||
'templates' => 'horizontal_form',
|
||||
]);
|
||||
|
||||
use Cake\I18n\FrozenTime;
|
||||
|
||||
?>
|
||||
<style type="text/css">
|
||||
input[type='checkbox'] {
|
||||
width:25px;
|
||||
}
|
||||
|
||||
.grd_big_checkbox {
|
||||
border:1px dotted black;
|
||||
padding:4px;
|
||||
margin-bottom:5px;
|
||||
}
|
||||
|
||||
.grd_margin-bottom_50 {
|
||||
margin-bottom:50px;
|
||||
}
|
||||
|
||||
.grd_margin-bottom_100 {
|
||||
margin-bottom:100px;
|
||||
}
|
||||
|
||||
.grd_margin-bottom_120 {
|
||||
margin-bottom:120px;
|
||||
}
|
||||
|
||||
.grd_smaller {
|
||||
font-size:smaller;
|
||||
color:blue;
|
||||
}
|
||||
|
||||
.color-orange {
|
||||
color:#6400d9;
|
||||
}
|
||||
|
||||
.flowing-bottom {
|
||||
position:fixed;
|
||||
bottom:0px;
|
||||
padding-left:20px;
|
||||
padding-right:20px;
|
||||
padding-top:10px;
|
||||
padding-bottom:10px;
|
||||
background-color:rgba(255,255,255,0.5);
|
||||
}
|
||||
|
||||
</style>
|
||||
<div class="action-form">
|
||||
<p class="form-header">Schöpfen</p>
|
||||
<button type="button" onclick="checkAll()" >Alle auswählen</button>
|
||||
<button type="button" onclick="uncheckAll()">Alle abwählen</button>
|
||||
<div style="margin-bottom:5px"></div>
|
||||
<div class="form-body">
|
||||
<?= $this->Form->create($creationForm) ?>
|
||||
<?php if($transactionExecutingCount > 0) : ?>
|
||||
<div id="transaction-execute-display"></div>
|
||||
<?php endif; ?>
|
||||
<fieldset>
|
||||
<?= $this->Form->control('memo'); ?>
|
||||
<?= $this->Form->control('amount', ['required' => false]); ?>
|
||||
<?php if($transactionExecutingCount > 0) : ?>
|
||||
<div id="transaction-execute-display"></div>
|
||||
<?php endif; ?>
|
||||
<div class="form-full-width">
|
||||
<div class="grid-row justify-end">
|
||||
<?= $this->Form->control('searchText', ['label' => __('Suche'), 'placeholder' => 'Email/Name']); ?>
|
||||
<?= $this->Form->button(__('Suchen'), ['name' => 'searchButton', 'class' => 'form-button']) ?>
|
||||
</div>
|
||||
</div>
|
||||
<?= $this->Form->control('memo', ['label' => __('Memo'), 'placeholder' => 'Memo']); ?>
|
||||
<?= $this->Form->control('amount', ['label' => __('Betrag in GDD'), 'required' => false]); ?>
|
||||
<?php
|
||||
$firstDayLastMonth = new FrozenTime();
|
||||
$firstDayLastMonth = $firstDayLastMonth->day(1)->subMonth(1);
|
||||
?>
|
||||
<?= $this->Form->control('target_date', ['value' => $firstDayLastMonth]); ?>
|
||||
<?php foreach($possibleReceiver as $possibleReceiver) :
|
||||
<!--<div class="form-full-width">
|
||||
<div>
|
||||
<?= $this->Form->control('target_date', ['label' => __('Zieldatum'), 'value' => $firstDayLastMonth]); ?>
|
||||
</div>
|
||||
</div>--> <!-- onchange: change all dates accordingly.... nice to have -->
|
||||
<div class="form-full-width">
|
||||
<div>
|
||||
<button type="button" class="form-button" onclick="checkAll()" >Alle auswählen</button>
|
||||
<button type="button" class="form-button" onclick="uncheckAll()">Alle abwählen</button>
|
||||
</div>
|
||||
</div>
|
||||
<?php foreach($possibleReceivers as $possibleReceiver) :
|
||||
$disable = null;
|
||||
if($activeUser['id'] == $possibleReceiver['id'] || $possibleReceiver['amount'] > 30000000) {
|
||||
//$disable = 'disabled';
|
||||
}
|
||||
?>
|
||||
<div class="grd_big_checkbox">
|
||||
<?php if(isset($possibleReceiver['pending'])) : ?>
|
||||
<?= $this->Form->hidden('user_pending[' . $possibleReceiver['id'] . ']', ['value' => $possibleReceiver['pending']] ) ?>
|
||||
<?php endif; ?>
|
||||
<?= $this->Form->checkbox('user[' .$possibleReceiver['id'] . ']', ['value' => $possibleReceiver['id'], 'hiddenField' => false, $disable]); ?>
|
||||
<?php if($disable != null) : ?>
|
||||
<span style="color:grey" title="Du kannst leider nicht für dich selbst schöpfen.">
|
||||
<?php endif; ?>
|
||||
<a style="color:black;text-decoration: none;" target="_blank" href="/state-users/view/<?= $possibleReceiver['id'] ?>">
|
||||
<?= $possibleReceiver['name'] ?>
|
||||
<?php if($possibleReceiver['email'] != '') : ?>
|
||||
<<?= $possibleReceiver['email'] ?>>
|
||||
<?php endif; ?></a><br>
|
||||
<div class="input number grd-padding-top-bottom-5">
|
||||
<?= $this->Form->text('user_amount[' . $possibleReceiver['id'] . ']', ['placeholder' => __('Für benutzerdefinierten Betrag'), 'class' => 'user_amount', 'type' => 'number', 'step' => '0.01', $disable]); ?> GDD
|
||||
</div>
|
||||
<div class="input date grd-padding-top-bottom-5">
|
||||
<?= $this->Form->date('user_target_date[' . $possibleReceiver['id'] . ']', ['value' => $firstDayLastMonth]) ?>
|
||||
</div>
|
||||
<div class="form-full-width">
|
||||
<?php if(isset($possibleReceiver['pending'])) : ?>
|
||||
<span class="grd_smaller color-orange">
|
||||
Bereits als Transaktion angelegt: <?= $this->element('printGradido', ['number' => $possibleReceiver['pending']]);?>
|
||||
</span>
|
||||
<br>
|
||||
<?= $this->Form->hidden('user_pending[' . $possibleReceiver['id'] . ']', ['value' => $possibleReceiver['pending']] ) ?>
|
||||
<?php endif; ?>
|
||||
<div class="form-row">
|
||||
<div class="cell cell-dense c1">
|
||||
<?= $this->Form->checkbox('user[' .$possibleReceiver['id'] . ']', ['value' => $possibleReceiver['id'], 'hiddenField' => false, $disable]); ?>
|
||||
</div>
|
||||
<div class="cell cell-dense c0">
|
||||
<?php if($disable != null) : ?>
|
||||
<span title="Du kannst leider nicht für dich selbst schöpfen."></span>
|
||||
<?php endif; ?>
|
||||
<a target="_blank" href="/state-users/view/<?= $possibleReceiver['id'] ?>">
|
||||
<?= $possibleReceiver['name'] ?>
|
||||
<?php if($possibleReceiver['email'] != '') : ?>
|
||||
<<?= $possibleReceiver['email'] ?>>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
</div>
|
||||
<div class="cell cell-dense c6">
|
||||
<?= $this->Form->text('user_amount[' . $possibleReceiver['id'] . ']', ['placeholder' => __('Für benutzerdefinierten Betrag'), 'class' => 'user_amount', 'type' => 'number', 'step' => '0.01', $disable]); ?> GDD
|
||||
</div>
|
||||
<div class="cell cell-dense c5">
|
||||
<?= $this->Form->date('user_target_date[' . $possibleReceiver['id'] . ']', ['value' => $firstDayLastMonth]) ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid-row">
|
||||
<?php if(isset($possibleReceiver['pending'])) : ?>
|
||||
<span class="note-smaller orange-color">
|
||||
Bereits als Transaktion angelegt: <?= $this->element('printGradido', ['number' => $possibleReceiver['pending']]);?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if($possibleReceiver['amount'] != 0) : ?>
|
||||
<span class="grd_smaller">
|
||||
<span class="note-smaller blue-color">
|
||||
In diesen und den letzten 2 Monaten bereits geschöpft (alte Berechnung): <?= $this->element('printGradido', ['number' => $possibleReceiver['amount']]);?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if($possibleReceiver['amount2'] > 0) : ?>
|
||||
<span class="grd_smaller">
|
||||
<span class="note-smaller blue-color">
|
||||
Im letzten Monat geschöpft (neue Berechnung): <?= $this->element('printGradido', ['number' => $possibleReceiver['amount2']]) ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if($disable != null) : ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<br>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<!--<?= $this->Form->control('receiver_pubkey_hex', []) ?>-->
|
||||
</fieldset>
|
||||
<div class="flowing-bottom">
|
||||
<?php if($countUsers > $limit) :
|
||||
?><p><?= $countUsers ?> Benutzer insgesamt</p>
|
||||
<p>Seiten:
|
||||
<?php endforeach; ?>
|
||||
<!--<?= $this->Form->control('receiver_pubkey_hex', []) ?>-->
|
||||
<div class="form-full-width">
|
||||
<?php if($countUsers > $limit) : ?>
|
||||
<p><?= $countUsers ?> Benutzer insgesamt</p>
|
||||
<p>Seiten:
|
||||
<?php for($i = 0; $i < ceil($countUsers/$limit); $i++) {
|
||||
if($i > 0) echo ', ';
|
||||
if($i != $page) {
|
||||
@ -141,11 +117,17 @@ use Cake\I18n\FrozenTime;
|
||||
}
|
||||
}
|
||||
?>
|
||||
</p><?php endif ?>
|
||||
<?= $this->Form->button(__('Transaktion(en) 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']) ?>
|
||||
</p>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<div class="form-full-width">
|
||||
<div>
|
||||
<?= $this->Form->button(__('Transaktion(en) abschließen'), ['name' => 'next', 'class' => 'form-button' ]) ?>
|
||||
<?= $this->Form->button(__('Weitere Transaktion erstellen'), ['name' => 'add', 'class' => 'form-button']) ?>
|
||||
</div>
|
||||
</div>
|
||||
<?= $this->Form->end() ?>
|
||||
</div>
|
||||
</div>
|
||||
<?= $this->Html->script('basic'); ?>
|
||||
<script type="text/javascript">
|
||||
@ -187,9 +169,6 @@ use Cake\I18n\FrozenTime;
|
||||
}
|
||||
});
|
||||
})(document, window, domIsReady);
|
||||
|
||||
//
|
||||
|
||||
</script>
|
||||
<?php if($transactionExecutingCount > 0) : ?>
|
||||
<script type="text/javascript">
|
||||
@ -207,7 +186,7 @@ use Cake\I18n\FrozenTime;
|
||||
display.innerHTML += "<?= __('Laufende Transaktionen') ?>";
|
||||
}
|
||||
} else {
|
||||
display.innerHTML = '<?= __('Alle Transaktionen abgeschlossen!') ?> <button class="grd-form-bn grd_clickable" onclick="location.reload()">Seite neuladen</button>';
|
||||
display.innerHTML = '<?= __('Alle Transaktionen abgeschlossen!') ?> <button class="form-button" onclick="location.reload()">Seite neuladen</button>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -713,6 +713,7 @@ and open the template in the editor.
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
list-style-type: none;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.nav-bottom p {
|
||||
font-size: 0.9em;
|
||||
@ -1611,6 +1612,7 @@ and open the template in the editor.
|
||||
grid-column: 0.5;
|
||||
font-weight: 400;
|
||||
text-align: right;
|
||||
padding-right: 0.5em;
|
||||
}
|
||||
.form-control {
|
||||
grid-column: 0.66666667;
|
||||
@ -1618,6 +1620,7 @@ and open the template in the editor.
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
margin: 0;
|
||||
margin-right: 0.5em;
|
||||
color: rgba(16, 16, 16, 0.8);
|
||||
display: block;
|
||||
font-size: 1rem;
|
||||
@ -1683,6 +1686,7 @@ and open the template in the editor.
|
||||
height: 35px;
|
||||
max-height: 35px;
|
||||
padding: 4px 15px;
|
||||
margin-right: 0.5em;
|
||||
box-shadow: 0 0 2px 0 rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
.form-button:hover {
|
||||
@ -1734,6 +1738,9 @@ and open the template in the editor.
|
||||
-webkit-transition-duration: 0.5s;
|
||||
transition-duration: 0.5s;
|
||||
}
|
||||
.justify-end {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.form-row {
|
||||
border-top: 1px solid #f2f4f9;
|
||||
}
|
||||
@ -1743,7 +1750,7 @@ and open the template in the editor.
|
||||
/* CENTER FORM SPECIFICS */
|
||||
.form-body form {
|
||||
display: grid;
|
||||
grid-template-columns: 200px 1fr;
|
||||
grid-template-columns: 220px 1fr;
|
||||
margin: 36px 75px;
|
||||
grid-gap: 1em;
|
||||
}
|
||||
|
||||
@ -386,6 +386,7 @@
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
list-style-type: none;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.nav-bottom p {
|
||||
|
||||
@ -38,6 +38,7 @@ and open the template in the editor.
|
||||
grid-column: 1 / 2;
|
||||
font-weight: 400;
|
||||
text-align: right;
|
||||
padding-right: .5em;
|
||||
}
|
||||
|
||||
.form-control {
|
||||
@ -47,6 +48,7 @@ and open the template in the editor.
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
margin: 0;
|
||||
margin-right: .5em;
|
||||
color: rgba(16, 16, 16, .8);
|
||||
display: block;
|
||||
font-size: 1rem;
|
||||
@ -119,6 +121,7 @@ and open the template in the editor.
|
||||
height: 35px;
|
||||
max-height: 35px;
|
||||
padding: 4px 15px;
|
||||
margin-right: .5em;
|
||||
box-shadow: 0 0 2px 0 rgba(0, 0, 0, .2);
|
||||
}
|
||||
|
||||
@ -180,6 +183,10 @@ and open the template in the editor.
|
||||
transition-duration: .5s;
|
||||
}
|
||||
|
||||
.justify-end {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
@media @tablet-down {
|
||||
.grid-row {
|
||||
flex-direction: column;
|
||||
@ -198,7 +205,7 @@ and open the template in the editor.
|
||||
/* CENTER FORM SPECIFICS */
|
||||
.form-body form {
|
||||
display: grid;
|
||||
grid-template-columns: 200px 1fr;
|
||||
grid-template-columns: 220px 1fr;
|
||||
margin: 36px 75px;
|
||||
grid-gap: 1em;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user