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']);
|
->contain(['Transactions']);
|
||||||
|
|
||||||
$involvedUserIds = [];
|
$involvedUserIds = [];
|
||||||
|
|
||||||
foreach($transferTransactions as $sendCoins) {
|
foreach($transferTransactions as $sendCoins) {
|
||||||
|
//var_dump($sendCoins);
|
||||||
if($sendCoins->state_user_id != $user['id']) {
|
if($sendCoins->state_user_id != $user['id']) {
|
||||||
array_push($involvedUserIds, intval($sendCoins->state_user_id));
|
array_push($involvedUserIds, intval($sendCoins->state_user_id));
|
||||||
} else if($sendCoins->receiver_user_id != $user['id']) {
|
} else if($sendCoins->receiver_user_id != $user['id']) {
|
||||||
array_push($involvedUserIds, intval($sendCoins->receiver_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
|
// exchange key with values and drop duplicates
|
||||||
$involvedUser_temp = array_flip($involvedUserIds);
|
$involvedUser_temp = array_flip($involvedUserIds);
|
||||||
// exchange back
|
// exchange back
|
||||||
@ -81,6 +89,7 @@ class StateBalancesController extends AppController
|
|||||||
'where' => ['id IN' => $involvedUserIds],
|
'where' => ['id IN' => $involvedUserIds],
|
||||||
'fields' => ['id', 'first_name', 'last_name', 'email']
|
'fields' => ['id', 'first_name', 'last_name', 'email']
|
||||||
]);
|
]);
|
||||||
|
//var_dump($involvedUser->toArray());
|
||||||
$involvedUserIndices = [];
|
$involvedUserIndices = [];
|
||||||
foreach($involvedUser as $involvedUser) {
|
foreach($involvedUser as $involvedUser) {
|
||||||
$involvedUserIndices[$involvedUser->id] = $involvedUser;
|
$involvedUserIndices[$involvedUser->id] = $involvedUser;
|
||||||
@ -101,7 +110,8 @@ class StateBalancesController extends AppController
|
|||||||
'type' => 'creation',
|
'type' => 'creation',
|
||||||
'transaction_id' => $creation->transaction_id,
|
'transaction_id' => $creation->transaction_id,
|
||||||
'date' => $creation->transaction->received,
|
'date' => $creation->transaction->received,
|
||||||
'balance' => $creation->amount
|
'balance' => $creation->amount,
|
||||||
|
'memo' => $creation->transaction->memo
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +131,8 @@ class StateBalancesController extends AppController
|
|||||||
'type' => $type,
|
'type' => $type,
|
||||||
'transaction_id' => $sendCoins->transaction_id,
|
'transaction_id' => $sendCoins->transaction_id,
|
||||||
'date' => $sendCoins->transaction->received,
|
'date' => $sendCoins->transaction->received,
|
||||||
'balance' => $sendCoins->amount
|
'balance' => $sendCoins->amount,
|
||||||
|
'memo' => $sendCoins->transaction->memo
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$this->set('transactions', $transactions);
|
$this->set('transactions', $transactions);
|
||||||
|
|||||||
@ -127,7 +127,8 @@ class TransactionCreationsController extends AppController
|
|||||||
$session_id = $session->read('session_id');
|
$session_id = $session->read('session_id');
|
||||||
$response = $http->get($url . '/checkTransaction', [
|
$response = $http->get($url . '/checkTransaction', [
|
||||||
'session_id' => $session_id,
|
'session_id' => $session_id,
|
||||||
'transaction_base64' => base64_encode($builderResult['transactionBody']->serializeToString())
|
'transaction_base64' => base64_encode($builderResult['transactionBody']->serializeToString()),
|
||||||
|
'balance' => $user['balance']
|
||||||
]);
|
]);
|
||||||
$json = $response->getJson();
|
$json = $response->getJson();
|
||||||
if($json['state'] != 'success') {
|
if($json['state'] != 'success') {
|
||||||
@ -160,7 +161,7 @@ class TransactionCreationsController extends AppController
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->Flash->error(__('No Valid Receiver Public given'));
|
$this->Flash->error(__('Building transaction failed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// */
|
// */
|
||||||
@ -246,16 +247,86 @@ class TransactionCreationsController extends AppController
|
|||||||
// amount
|
// amount
|
||||||
$memo = $requestData['memo'];
|
$memo = $requestData['memo'];
|
||||||
$amountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['amount']);
|
$amountCent = $this->GradidoNumber->parseInputNumberToCentNumber($requestData['amount']);
|
||||||
|
$mode = 'next';
|
||||||
|
if(isset($requestData['add'])) {$mode = 'add'; }
|
||||||
|
|
||||||
if(!isset($requestData['user']) || count($requestData['user']) == 0) {
|
if(!isset($requestData['user']) || count($requestData['user']) == 0) {
|
||||||
$this->Flash->error(__('no user choosen'));
|
$this->Flash->error(__('no user choosen'));
|
||||||
} else {
|
} else {
|
||||||
$users = $requestData['user'];
|
$users = $requestData['user'];
|
||||||
var_dump($users);
|
//var_dump(array_keys($users));
|
||||||
$receiverUsers = $stateUserTable
|
$receiverUsers = $stateUserTable
|
||||||
->find('all')
|
->find('all')
|
||||||
->where(['id' => array_keys($users)])
|
->where(['id IN' => array_keys($users)])
|
||||||
->select(['public_key', 'email']);
|
->select(['public_key', 'email'])
|
||||||
//$identHash = TransactionCreation::DRMakeStringHash($receiverProposal[$receiverIndex]['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;
|
//$title = '' . $number;
|
||||||
/*if($number == 0) $class = "grd-default-currency";
|
/*if($number == 0) $class = "grd-default-currency";
|
||||||
else if($number > 0) $class = "grd-positive-currency";*/
|
else if($number > 0) $class = "grd-positive-currency";*/
|
||||||
|
if($number < 0) {
|
||||||
|
$class = 'grd-negative-currency';
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<span class="<?php echo $class;?>">
|
<span class="<?php echo $class;?>">
|
||||||
|
|||||||
@ -50,7 +50,7 @@ if(!isset($balance)) {
|
|||||||
<body>
|
<body>
|
||||||
<div class="versionstring dev-info">
|
<div class="versionstring dev-info">
|
||||||
<p class="grd_small">Community Server in Entwicklung</p>
|
<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>
|
</div>
|
||||||
<nav class="grd-left-bar expanded" data-topbar role="navigation">
|
<nav class="grd-left-bar expanded" data-topbar role="navigation">
|
||||||
<div class="grd-left-bar-section">
|
<div class="grd-left-bar-section">
|
||||||
|
|||||||
@ -42,7 +42,7 @@ $GLOBALS["self"] = $this;
|
|||||||
<body class="header-fixed">
|
<body class="header-fixed">
|
||||||
<div class="versionstring dev-info">
|
<div class="versionstring dev-info">
|
||||||
<p class="grd_small"><?= __("Community Server in Entwicklung") ?></p>
|
<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>
|
</div>
|
||||||
<nav class="t-header">
|
<nav class="t-header">
|
||||||
<div class="t-header-brand-wrapper">
|
<div class="t-header-brand-wrapper">
|
||||||
|
|||||||
@ -1,74 +1,95 @@
|
|||||||
<?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.
|
||||||
*/
|
*/
|
||||||
$this->assign('title', __('Kontoübersicht'));
|
$this->assign('title', __('Kontoübersicht'));
|
||||||
//var_dump($transactions);
|
//var_dump($transactions);
|
||||||
?>
|
?>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-8 equel-grid">
|
<div class="col-md-8 equel-grid">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="grid-body py-3">
|
<div class="grid-body py-3">
|
||||||
<h3><?= __('Aktueller Kontostand: ') ?></h3>
|
<h3><?= __('Aktueller Kontostand: ') ?></h3>
|
||||||
<h2><?= $this->element('printGradido', ['number' => $balance]) ?></h2>
|
<h2><?= $this->element('printGradido', ['number' => $balance]) ?></h2>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-10 equel-grid">
|
<div class="col-md-10 equel-grid">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="grid-body py-3">
|
<div class="grid-body py-3">
|
||||||
<p class="card-title ml-n1">Überweisungen</p>
|
<p class="card-title ml-n1">Überweisungen</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-hover table-sm">
|
<table class="table table-hover table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="solid-header">
|
<tr class="solid-header">
|
||||||
<th colspan="2" class="pl-4"><?= __('Absender') . ' / ' . ('Empfänger') ?></th>
|
<th colspan="2" class="pl-4"><?= __('Absender') . ' / ' . ('Empfänger') ?></th>
|
||||||
<th><?= __('Transaktions Nr.') ?></th>
|
<th><?= __('Verwendungszweck') ?></th>
|
||||||
<th><?= __('Datum') ?></th>
|
<th><?= __('Datum') ?></th>
|
||||||
<th><?= __('Betrag') ?></th>
|
<th><?= __('Betrag') ?></th>
|
||||||
</tr>
|
<th title="<?= __('Transaktions Nr.') ?>"><?= __('Nr') ?></th>
|
||||||
</thead>
|
</tr>
|
||||||
<tbody>
|
</thead>
|
||||||
<?php foreach($transactions as $transaction): ?>
|
<tbody>
|
||||||
<tr>
|
<?php foreach($transactions as $transaction):
|
||||||
<td class="pr-0 pl-4">
|
$send = $transaction['type'] == 'send';
|
||||||
<?= $this->Html->image('50x50.png', ['class' => 'profile-img img-sm', 'alt' => 'profile image']) ?>
|
$balance = $transaction['balance'];
|
||||||
</td>
|
$memoShort = $transaction['memo'];
|
||||||
<td class="pl-md-0">
|
if(strlen($memoShort) > 30) {
|
||||||
<?php if(isset($transaction['email']) && $transaction['email'] != ''): ?>
|
$memoShort = substr($memoShort, 0, 30) . '...';
|
||||||
<a href="mailto:<?= $transaction['email'] ?>" title="<?= $transaction['email'] ?>">
|
}
|
||||||
<small class="text-black font-weight-medium d-block"><?= $transaction['name'] ?></small>
|
$cellColorClass = 'grd-success-color';
|
||||||
</a>
|
if($send) {
|
||||||
<?php else : ?>
|
$balance = -$balance;
|
||||||
<small class="text-black font-weight-medium d-block"><?= $transaction['name'] ?></small>
|
$cellColorClass = 'grd-alert-color';
|
||||||
<?php endif; ?>
|
} else if($transaction['type'] == 'creation') {
|
||||||
<span>
|
$cellColorClass = 'grd-orange-color';
|
||||||
<?php if($transaction['type'] == 'creation') : ?>
|
}
|
||||||
<i class="mdi mdi-creation grd-orange-color"></i> <?= __('Geschöpft')?>
|
?>
|
||||||
<?php elseif($transaction['type'] == 'send') : ?>
|
<tr>
|
||||||
<i class="mdi mdi-arrow-right-bold"></i> <?= __('Gesendet') ?>
|
<td class="pr-0 pl-4">
|
||||||
<?php elseif($transaction['type'] == 'receive') : ?>
|
<?= $this->Html->image('50x50.png', ['class' => 'profile-img img-sm', 'alt' => 'profile image']) ?>
|
||||||
<i class="mdi mdi-arrow-left-bold"></i> <?= __('Empfangen') ?>
|
</td>
|
||||||
<?php endif; ?>
|
<td class="pl-md-0">
|
||||||
</span>
|
<?php if(isset($transaction['email']) && $transaction['email'] != ''): ?>
|
||||||
</td>
|
<a href="mailto:<?= $transaction['email'] ?>" title="<?= $transaction['email'] ?>">
|
||||||
<td>
|
<small class="text-black font-weight-medium d-block"><?= $transaction['name'] ?></small>
|
||||||
<small><?= $transaction['transaction_id'] ?></small>
|
</a>
|
||||||
</td>
|
<?php else : ?>
|
||||||
<td> <?= $transaction['date']->nice() ?> </td>
|
<small class="text-black font-weight-medium d-block"><?= $transaction['name'] ?></small>
|
||||||
<td><?= $this->element('printGradido', ['number' => $transaction['balance']]) ?></td>
|
<?php endif; ?>
|
||||||
</tr>
|
<span class=" <?= $cellColorClass ?>">
|
||||||
<?php endforeach; ?>
|
<?php if($transaction['type'] == 'creation') : ?>
|
||||||
</tbody>
|
<i class="mdi mdi-creation grd-orange-color"></i> <?= __('Geschöpft')?>
|
||||||
</table>
|
<?php elseif($transaction['type'] == 'send') : ?>
|
||||||
</div>
|
<i class="mdi mdi-arrow-right-bold"></i> <?= __('Gesendet') ?>
|
||||||
<!--<a class="border-top px-3 py-2 d-block text-gray" href="#"><small class="font-weight-medium"><i class="mdi mdi-chevron-down mr-2"></i>View All Order History</small></a>-->
|
<?php elseif($transaction['type'] == 'receive') : ?>
|
||||||
</div>
|
<i class="mdi mdi-arrow-left-bold"></i> <?= __('Empfangen') ?>
|
||||||
</div>
|
<?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>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<!--<a class="border-top px-3 py-2 d-block text-gray" href="#"><small class="font-weight-medium"><i class="mdi mdi-chevron-down mr-2"></i>View All Order History</small></a>-->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
Loading…
x
Reference in New Issue
Block a user