Merge branch '309-Transaction-details-design' of https://github.com/gradido/gradido into 309-Transaction-details-design

This commit is contained in:
ogerly 2021-07-08 09:28:03 +02:00
commit 7173a9505c
3 changed files with 47 additions and 17 deletions

View File

@ -25,7 +25,7 @@ class AppRequestsController extends AppController
$this->loadComponent('GradidoNumber');
//$this->loadComponent('JsonRpcRequestClient');
//$this->Auth->allow(['add', 'edit']);
$this->Auth->allow(['index', 'sendCoins', 'createCoins', 'getBalance', 'listTransactions']);
$this->Auth->allow(['index', 'sendCoins', 'createCoins', 'getBalance', 'listTransactions', 'getDecayStartBlock']);
}
@ -335,11 +335,21 @@ class AppRequestsController extends AppController
$limit = $count;
$offset = 0;
$skip_first_transaction = false;
if($page == 1) {
$limit--;
} else {
$offset = (( $page - 1 ) * $count) - 1;
}
if($offset && $orderDirection == 'ASC') {
// move cursor one step backwards to able to load one transaction previous last which will be shown for decay calculation
$offset--;
$limit++;
$skip_first_transaction = true;
} else if($orderDirection == 'DESC') {
$limit++;
$skip_first_transaction = true;
}
$stateUserTransactionsQuery = $stateUserTransactionsTable
->find()
@ -362,7 +372,7 @@ class AppRequestsController extends AppController
$transactions_from_db = array_reverse($transactions_from_db);
}
$transactions = $transactionsTable->listTransactionsHumanReadable($transactions_from_db, $user, $decay);
$transactions = $transactionsTable->listTransactionsHumanReadable($transactions_from_db, $user, $decay, $skip_first_transaction);
if($orderDirection == 'DESC') {
$transactions = array_reverse($transactions);

View File

@ -133,11 +133,12 @@ class TransactionsTable extends Table
}
public function listTransactionsHumanReadable($stateUserTransactions, array $user, $decay = true)
public function listTransactionsHumanReadable($stateUserTransactions, array $user, $decay = true, $skip_first_transaction = false)
{
$stateUsersTable = TableRegistry::getTableLocator()->get('StateUsers');
$stateBalancesTable = TableRegistry::getTableLocator()->get('StateBalances');
$transactionsTable = TableRegistry::getTableLocator()->get('Transactions');
$transaction_ids = [];
$involved_user_ids = [];
@ -162,11 +163,15 @@ class TransactionsTable extends Table
$state_balance = $stateBalancesTable->newEntity();
$final_transactions = [];
$decay_start_transaction = $transactionsTable->find()->where(['transaction_type_id' => 9]);
$decay_start_transaction_id = 0;
if($decay_start_transaction->count()) {
$decay_start_transaction_id = $decay_start_transaction->first()->id;
}
$decay_start_time = $stateBalancesTable->getDecayStartDateCached()->getTimestamp();
foreach($stateUserTransactions as $i => $su_transaction)
{
// sender or receiver when user has sended money
// group name if creation
// type: gesendet / empfangen / geschöpft
@ -187,7 +192,8 @@ class TransactionsTable extends Table
}
if($prev)
{
if($prev->balance > 0) {
if($prev->balance > 0)
{
$current = $su_transaction;
$calculated_decay = $stateBalancesTable->calculateDecay($prev->balance, $prev->balance_date, $current->balance_date, true);
$balance = floatval($prev->balance - $calculated_decay['balance']);
@ -199,7 +205,19 @@ class TransactionsTable extends Table
'decay_duration' => $calculated_decay['interval']->format('%a days, %H hours, %I minutes, %S seconds'),
'decay_start' => $calculated_decay['start_date'],
'decay_end' => $calculated_decay['end_date']
];
];
if($prev->transaction_id < $decay_start_transaction_id &&
$current->transaction_id > $decay_start_transaction_id) {
$final_transaction['decay']['decay_start_block'] = $decay_start_time;
}
// hint: use transaction id
/*if($calculated_decay['start_date'] < $decay_start_time && $calculated_decay['end_date'] > $decay_start_time) {
$final_transaction['decay']['decay_start_block'] = $decay_start_time;
} else {
echo "start block: " . $decay_start_time . "<br>";
echo "start date: " . $calculated_decay['start_date'] . "<br>";
echo "end date: " . $calculated_decay['end_date']. "<hr>";
}*/
}
}
}
@ -249,8 +267,9 @@ class TransactionsTable extends Table
$final_transaction['name'] = $otherUser->first_name . ' ' . $otherUser->last_name;
$final_transaction['email'] = $otherUser->email;
}
$final_transactions[] = $final_transaction;
if($i > 0 || !$skip_first_transaction) {
$final_transactions[] = $final_transaction;
}
if($i == $stateUserTransactionsCount-1 && $decay) {
$now = new FrozenTime();

View File

@ -205,11 +205,12 @@ class AppRequestControllerTest extends TestCase
"transaction_id": 7,
"date": "2021-04-14T09:02:28+00:00",
"memo": "test time 3",
"decay": {
"decay": {
"balance": 6,
"decay_duration": "0 days, 00 hours, 00 minutes, 28 seconds",
"decay_start": 1618390920,
"decay_end": 1618390948
"decay_end": 1618390948,
"decay_start_block": 1618390920
},
"balance": 100000,
"type": "receive",
@ -237,7 +238,7 @@ class AppRequestControllerTest extends TestCase
"transaction_id": 9,
"date": "2021-04-14T09:31:28+00:00",
"memo": "test login crash",
"decay": {
"decay": {
"balance": 33,
"decay_duration": "0 days, 00 hours, 02 minutes, 42 seconds",
"decay_start": 1618392526,
@ -251,20 +252,20 @@ class AppRequestControllerTest extends TestCase
},
{
"type": "decay",
"balance": 1222493,
"balance": 1345726,
"decay_duration": "on 14.04.21",
"decay_start": 1618392688,
"decay_end": 1624956464,
"decay_end": 1625673853,
"memo": ""
}
],
"transactionExecutingCount": 0,
"count": 7,
"gdtSum": 180000,
"timeUsed": 0.6441609859466553,
"decay_date": "2021-06-29T08:47:44+00:00",
"timeUsed": 0.44154810905456545,
"decay_date": "2021-07-07T16:04:13+00:00",
"balance": 9099652,
"decay": 7877159
"decay": 7753926
}';
$this->getAndParse('/api/list-transactions/', json_decode($expectedResult, true));
}