mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
update multi creation transactions
This commit is contained in:
parent
2723c277c9
commit
e02b52cb31
@ -64,13 +64,21 @@ class StateBalancesController extends AppController
|
||||
->contain(['Transactions']);
|
||||
|
||||
$involvedUserIds = [];
|
||||
|
||||
foreach($transferTransactions as $sendCoins) {
|
||||
//var_dump($sendCoins);
|
||||
if($sendCoins->state_user_id != $user['id']) {
|
||||
array_push($involvedUserIds, intval($sendCoins->state_user_id));
|
||||
} else if($sendCoins->receiver_user_id != $user['id']) {
|
||||
array_push($involvedUserIds, intval($sendCoins->receiver_user_id));
|
||||
}
|
||||
}
|
||||
|
||||
/*echo "state user from sendCoins: $sendCoins->state_user_id<br>";
|
||||
echo "receiver user from sendCoins: $sendCoins->receiver_user_id<br>";
|
||||
echo "user id from logged in user: ".$user['id']. '<br>';
|
||||
*/
|
||||
//var_dump($involvedUserIds);
|
||||
// exchange key with values and drop duplicates
|
||||
$involvedUser_temp = array_flip($involvedUserIds);
|
||||
// exchange back
|
||||
@ -81,6 +89,7 @@ class StateBalancesController extends AppController
|
||||
'where' => ['id IN' => $involvedUserIds],
|
||||
'fields' => ['id', 'first_name', 'last_name', 'email']
|
||||
]);
|
||||
//var_dump($involvedUser->toArray());
|
||||
$involvedUserIndices = [];
|
||||
foreach($involvedUser as $involvedUser) {
|
||||
$involvedUserIndices[$involvedUser->id] = $involvedUser;
|
||||
@ -101,7 +110,8 @@ class StateBalancesController extends AppController
|
||||
'type' => 'creation',
|
||||
'transaction_id' => $creation->transaction_id,
|
||||
'date' => $creation->transaction->received,
|
||||
'balance' => $creation->amount
|
||||
'balance' => $creation->amount,
|
||||
'memo' => $creation->transaction->memo
|
||||
]);
|
||||
}
|
||||
|
||||
@ -121,7 +131,8 @@ class StateBalancesController extends AppController
|
||||
'type' => $type,
|
||||
'transaction_id' => $sendCoins->transaction_id,
|
||||
'date' => $sendCoins->transaction->received,
|
||||
'balance' => $sendCoins->amount
|
||||
'balance' => $sendCoins->amount,
|
||||
'memo' => $sendCoins->transaction->memo
|
||||
]);
|
||||
}
|
||||
$this->set('transactions', $transactions);
|
||||
|
||||
@ -127,7 +127,8 @@ class TransactionCreationsController extends AppController
|
||||
$session_id = $session->read('session_id');
|
||||
$response = $http->get($url . '/checkTransaction', [
|
||||
'session_id' => $session_id,
|
||||
'transaction_base64' => base64_encode($builderResult['transactionBody']->serializeToString())
|
||||
'transaction_base64' => base64_encode($builderResult['transactionBody']->serializeToString()),
|
||||
'balance' => $user['balance']
|
||||
]);
|
||||
$json = $response->getJson();
|
||||
if($json['state'] != 'success') {
|
||||
@ -160,7 +161,7 @@ class TransactionCreationsController extends AppController
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->Flash->error(__('No Valid Receiver Public given'));
|
||||
$this->Flash->error(__('Building transaction failed'));
|
||||
}
|
||||
|
||||
// */
|
||||
@ -246,16 +247,86 @@ class TransactionCreationsController extends AppController
|
||||
// amount
|
||||
$memo = $requestData['memo'];
|
||||
$amountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['amount']);
|
||||
$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'];
|
||||
var_dump($users);
|
||||
//var_dump(array_keys($users));
|
||||
$receiverUsers = $stateUserTable
|
||||
->find('all')
|
||||
->where(['id' => array_keys($users)])
|
||||
->select(['public_key', 'email']);
|
||||
//$identHash = TransactionCreation::DRMakeStringHash($receiverProposal[$receiverIndex]['email']);
|
||||
->where(['id IN' => array_keys($users)])
|
||||
->select(['public_key', 'email'])
|
||||
->contain(false);
|
||||
$transactions = [];
|
||||
//var_dump($receiverUsers);
|
||||
foreach($receiverUsers as $receiverUser) {
|
||||
$pubKeyHex = bin2hex(stream_get_contents($receiverUser->public_key));
|
||||
$identHash = TransactionCreation::DRMakeStringHash($receiverUser->email);
|
||||
$builderResult = TransactionCreation::build(
|
||||
$amountCent,
|
||||
$memo,
|
||||
$pubKeyHex,
|
||||
$identHash
|
||||
);
|
||||
if($builderResult['state'] == 'success') {
|
||||
array_push($transactions, base64_encode($builderResult['transactionBody']->serializeToString()));
|
||||
}
|
||||
}
|
||||
$creationTransactionCount = count($transactions);
|
||||
if($creationTransactionCount > 0) {
|
||||
$http = new Client();
|
||||
try {
|
||||
$loginServer = Configure::read('LoginServer');
|
||||
$url = $loginServer['host'] . ':' . $loginServer['port'];
|
||||
$session_id = $session->read('session_id');
|
||||
/*
|
||||
* $response = $http->post($url . '/checkTransaction', json_encode([
|
||||
'session_id' => $session_id,
|
||||
'transaction_base64' => base64_encode($builderResult['transactionBody']->serializeToString()),
|
||||
'balance' => $user['balance']
|
||||
]), ['type' => 'json']);
|
||||
*/
|
||||
$transactionbody = json_encode([
|
||||
'session_id' => $session_id,
|
||||
'transaction_base64' => $transactions,
|
||||
'balance' => $user['balance']
|
||||
]);
|
||||
//die($transactionbody);
|
||||
$response = $http->post($url . '/checkTransaction', $transactionbody, ['type' => 'json']);
|
||||
//var_dump($response->getStringBody());
|
||||
$json = $response->getJson();
|
||||
if($json['state'] != 'success') {
|
||||
if($json['msg'] == 'session not found') {
|
||||
$session->destroy();
|
||||
return $this->redirect(Router::url('/', true) . 'account', 303);
|
||||
//$this->Flash->error(__('session not found, please login again'));
|
||||
} else {
|
||||
$this->Flash->error(__('login server return error: ' . json_encode($json)));
|
||||
}
|
||||
} 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(Router::url('/', true) . 'account/checkTransactions', 303);
|
||||
} else {
|
||||
$this->Flash->success(__('Transaction submitted for review.'));
|
||||
}
|
||||
}
|
||||
|
||||
} catch(\Exception $e) {
|
||||
$msg = $e->getMessage();
|
||||
$this->Flash->error(__('error http request: ') . $msg);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,9 @@ $class = '';
|
||||
//$title = '' . $number;
|
||||
/*if($number == 0) $class = "grd-default-currency";
|
||||
else if($number > 0) $class = "grd-positive-currency";*/
|
||||
if($number < 0) {
|
||||
$class = 'grd-negative-currency';
|
||||
}
|
||||
|
||||
?>
|
||||
<span class="<?php echo $class;?>">
|
||||
|
||||
@ -50,7 +50,7 @@ if(!isset($balance)) {
|
||||
<body>
|
||||
<div class="versionstring dev-info">
|
||||
<p class="grd_small">Community Server in Entwicklung</p>
|
||||
<p class="grd_small">Alpha 0.6.0</p>
|
||||
<p class="grd_small">Alpha 0.9.0</p>
|
||||
</div>
|
||||
<nav class="grd-left-bar expanded" data-topbar role="navigation">
|
||||
<div class="grd-left-bar-section">
|
||||
|
||||
@ -42,7 +42,7 @@ $GLOBALS["self"] = $this;
|
||||
<body class="header-fixed">
|
||||
<div class="versionstring dev-info">
|
||||
<p class="grd_small"><?= __("Community Server in Entwicklung") ?></p>
|
||||
<p class="grd_small">Alpha 0.8.0</p>
|
||||
<p class="grd_small">Alpha 0.9.0</p>
|
||||
</div>
|
||||
<nav class="t-header">
|
||||
<div class="t-header-brand-wrapper">
|
||||
|
||||
@ -29,13 +29,28 @@ $this->assign('title', __('Kontoübersicht'));
|
||||
<thead>
|
||||
<tr class="solid-header">
|
||||
<th colspan="2" class="pl-4"><?= __('Absender') . ' / ' . ('Empfänger') ?></th>
|
||||
<th><?= __('Transaktions Nr.') ?></th>
|
||||
<th><?= __('Verwendungszweck') ?></th>
|
||||
<th><?= __('Datum') ?></th>
|
||||
<th><?= __('Betrag') ?></th>
|
||||
<th title="<?= __('Transaktions Nr.') ?>"><?= __('Nr') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($transactions as $transaction): ?>
|
||||
<?php foreach($transactions as $transaction):
|
||||
$send = $transaction['type'] == 'send';
|
||||
$balance = $transaction['balance'];
|
||||
$memoShort = $transaction['memo'];
|
||||
if(strlen($memoShort) > 30) {
|
||||
$memoShort = substr($memoShort, 0, 30) . '...';
|
||||
}
|
||||
$cellColorClass = 'grd-success-color';
|
||||
if($send) {
|
||||
$balance = -$balance;
|
||||
$cellColorClass = 'grd-alert-color';
|
||||
} else if($transaction['type'] == 'creation') {
|
||||
$cellColorClass = 'grd-orange-color';
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td class="pr-0 pl-4">
|
||||
<?= $this->Html->image('50x50.png', ['class' => 'profile-img img-sm', 'alt' => 'profile image']) ?>
|
||||
@ -48,7 +63,7 @@ $this->assign('title', __('Kontoübersicht'));
|
||||
<?php else : ?>
|
||||
<small class="text-black font-weight-medium d-block"><?= $transaction['name'] ?></small>
|
||||
<?php endif; ?>
|
||||
<span>
|
||||
<span class=" <?= $cellColorClass ?>">
|
||||
<?php if($transaction['type'] == 'creation') : ?>
|
||||
<i class="mdi mdi-creation grd-orange-color"></i> <?= __('Geschöpft')?>
|
||||
<?php elseif($transaction['type'] == 'send') : ?>
|
||||
@ -58,11 +73,17 @@ $this->assign('title', __('Kontoübersicht'));
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
</td>
|
||||
<td><?php if(strlen($transaction['memo']) > 30): ?>
|
||||
<span data-toggle="tooltip" data-placement="bottom" title="<?= $transaction['memo'] ?>"><?= substr($memoShort, 0, 30) . '...' ?></span>
|
||||
<?php else : ?>
|
||||
<?= $transaction['memo'] ?>
|
||||
<?php endif;?>
|
||||
</td>
|
||||
<td> <?= $transaction['date']->nice() ?> </td>
|
||||
<td><?= $this->element('printGradido', ['number' => $balance]) ?></td>
|
||||
<td>
|
||||
<small><?= $transaction['transaction_id'] ?></small>
|
||||
</td>
|
||||
<td> <?= $transaction['date']->nice() ?> </td>
|
||||
<td><?= $this->element('printGradido', ['number' => $transaction['balance']]) ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user