mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
move gradido to float into view element
This commit is contained in:
parent
a928d7324a
commit
b10886a8d3
@ -268,7 +268,7 @@ class AppRequestsController extends AppController
|
||||
|
||||
public function getBalance($session_id = 0)
|
||||
{
|
||||
|
||||
$this->viewBuilder()->setLayout('ajax');
|
||||
$login_result = $this->requestLogin($session_id, false);
|
||||
if($login_result !== true) {
|
||||
return $this->returnJson($login_result);
|
||||
@ -284,12 +284,13 @@ class AppRequestsController extends AppController
|
||||
return $this->returnJson(['state' => 'success', 'balance' => 0]);
|
||||
}
|
||||
$now = new FrozenTime();
|
||||
return $this->returnJson([
|
||||
$body = [
|
||||
'state' => 'success',
|
||||
'balance' => $state_balance->amount_float,
|
||||
'balance' => $state_balance->amount,
|
||||
'decay' => $state_balance->partDecay($now),
|
||||
'decay_date' => $now
|
||||
]);
|
||||
];
|
||||
$this->set('body', $body);
|
||||
}
|
||||
|
||||
public function listTransactions($page = 1, $count = 25, $orderDirection = 'ASC', $session_id = 0)
|
||||
@ -337,14 +338,29 @@ class AppRequestsController extends AppController
|
||||
$transactions = array_reverse($transactions);
|
||||
}
|
||||
}
|
||||
return $this->returnJson([
|
||||
'state' => 'success',
|
||||
'transactions' => $transactions,
|
||||
'transactionExecutingCount' => $session->read('Transactions.executing'),
|
||||
'count' => count($transactions),
|
||||
'gdtSum' => floatval($gdtSum) / 100.0,
|
||||
'timeUsed' => microtime(true) - $startTime
|
||||
]);
|
||||
|
||||
$state_balance = $stateBalancesTable->find()->where(['state_user_id' => $user['id']])->first();
|
||||
|
||||
$body = [
|
||||
'state' => 'success',
|
||||
'transactions' => $transactions,
|
||||
'transactionExecutingCount' => $session->read('Transactions.executing'),
|
||||
'count' => count($transactions),
|
||||
'gdtSum' => $gdtSum,
|
||||
'timeUsed' => microtime(true) - $startTime
|
||||
];
|
||||
$now = new FrozenTime();
|
||||
$body['decay_date'] = $now;
|
||||
|
||||
if(!$state_balance) {
|
||||
$body['balance'] = 0;
|
||||
$body['decay'] = 0;
|
||||
} else {
|
||||
$body['balance'] = $state_balance->amount;
|
||||
$body['decay'] = $state_balance->partDecay($now);
|
||||
}
|
||||
|
||||
$this->set('body', $body);
|
||||
}
|
||||
|
||||
private function acquireAccessToken($session_id)
|
||||
|
||||
@ -68,12 +68,7 @@ class StateBalance extends Entity
|
||||
return intval($this->amount * pow(0.99999997802044727, $decay_duration));
|
||||
|
||||
}
|
||||
|
||||
protected function _getAmountFloat()
|
||||
{
|
||||
return Number::format(floatval($this->amount) / 10000.0, ['precision' => 2]);
|
||||
}
|
||||
|
||||
|
||||
public function partDecay($target_date)
|
||||
{
|
||||
$decay_duration = intval($this->convertToTimestamp($target_date) - $this->convertToTimestamp($this->record_date));
|
||||
|
||||
@ -122,9 +122,9 @@ class StateUsersTable extends Table
|
||||
// exchange back
|
||||
$involvedUserIds = array_flip($involvedUser_temp);
|
||||
$involvedUser = $this->find('all', [
|
||||
'contain' => false,
|
||||
'contain' => [],
|
||||
'where' => ['id IN' => $involvedUserIds],
|
||||
'fields' => ['id', 'first_name', 'last_name', 'email']
|
||||
'fields' => ['id', 'first_name', 'last_name', 'email'],
|
||||
]);
|
||||
//var_dump($involvedUser->toArray());
|
||||
$involvedUserIndices = [];
|
||||
|
||||
@ -188,7 +188,7 @@ class TransactionsTable extends Table
|
||||
//echo "prev balance: " . $prev->balance . ", diff_amount: $diff_amount, summe: " . (-intval($prev->balance - $diff_amount)) . "<br>";
|
||||
$final_transactions[] = [
|
||||
'type' => 'decay',
|
||||
'balance' => Number::format(floatval(-intval($prev->balance - $diff_amount)) / 10000.0, ['precision' => 2]),
|
||||
'balance' => floatval(-intval($prev->balance - $diff_amount)),
|
||||
'decay_duration' => $interval->format('%a days, %H hours, %I minutes, %S seconds'),
|
||||
'memo' => ''
|
||||
];
|
||||
@ -212,7 +212,7 @@ class TransactionsTable extends Table
|
||||
'type' => 'creation',
|
||||
'transaction_id' => $transaction->id,
|
||||
'date' => $creation->target_date,
|
||||
'balance' => $creation->amount_float,
|
||||
'balance' => $creation->amount,
|
||||
'memo' => $transaction->memo
|
||||
];
|
||||
} else if($su_transaction->transaction_type_id == 2) { // transfer or send coins
|
||||
@ -245,7 +245,7 @@ class TransactionsTable extends Table
|
||||
'type' => $type,
|
||||
'transaction_id' => $sendCoins->transaction_id,
|
||||
'date' => $transaction->received,
|
||||
'balance' => $sendCoins->amount_float,
|
||||
'balance' => $sendCoins->amount,
|
||||
'memo' => $transaction->memo,
|
||||
'pubkey' => $other_user_public
|
||||
];
|
||||
@ -256,7 +256,7 @@ class TransactionsTable extends Table
|
||||
$state_balance->record_date = $su_transaction->balance_date;
|
||||
$final_transactions[] = [
|
||||
'type' => 'decay',
|
||||
'balance' => Number::format(floatval(-intval($su_transaction->balance - $state_balance->decay)) / 10000.0, ['precision' => 2]),
|
||||
'balance' => floatval(-intval($su_transaction->balance - $state_balance->decay)),
|
||||
'decay_duration' => $su_transaction->balance_date->timeAgoInWords(),
|
||||
'memo' => ''
|
||||
];
|
||||
|
||||
11
community_server/src/Template/AppRequests/get_balance.ctp
Normal file
11
community_server/src/Template/AppRequests/get_balance.ctp
Normal file
@ -0,0 +1,11 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
$body['balance'] = $this->element('centToFloat', ['cent' => $body['balance'], 'precision' => 4]);
|
||||
$body['decay'] = $this->element('centToFloat', ['cent' => $body['decay'], 'precision' => 4]);
|
||||
?><?= json_encode($body) ?>
|
||||
@ -0,0 +1,17 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
$body['balance'] = $this->element('centToFloat', ['cent' => $body['balance'], 'precision' => 4]);
|
||||
$body['decay'] = $this->element('centToFloat', ['cent' => $body['decay'], 'precision' => 4]);
|
||||
$body['gdtSum'] = $this->element('centToFloat', ['cent' => $body['gdtSum'], 'precision' => 2]);
|
||||
|
||||
foreach($body['transactions'] as $i => $transaction) {
|
||||
$body['transactions'][$i]['balance'] = $this->element('centToFloat', ['cent' => $transaction['balance'], 'precision' => 4]);
|
||||
}
|
||||
|
||||
?><?= json_encode($body) ?>
|
||||
15
community_server/src/Template/Element/centToFloat.ctp
Normal file
15
community_server/src/Template/Element/centToFloat.ctp
Normal file
@ -0,0 +1,15 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
$cut_places = $precision - 2;
|
||||
$transformAmount = $cent;
|
||||
if($cut_places > 0) {
|
||||
$transformAmount = floor($cent / pow(10, $cut_places));
|
||||
}
|
||||
echo $transformAmount / pow(10, $precision - $cut_places);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user