diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c943ecd9..8af5505e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,129 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [1.0.1](https://github.com/gradido/gradido/compare/0.9.4...1.0.1) + +- Send button only click [`#427`](https://github.com/gradido/gradido/pull/427) +- use new function for balance overview in old frontend, update balance… [`#422`](https://github.com/gradido/gradido/pull/422) +- thx.vue coloured background removed. design adapted to app [`#426`](https://github.com/gradido/gradido/pull/426) +- translation password rules in Register.vue and ResetPasswort.vue fixed [`#424`](https://github.com/gradido/gradido/pull/424) +- 06x style [`#419`](https://github.com/gradido/gradido/pull/419) +- feat: Dash is Shown When Balance is Loading [`#396`](https://github.com/gradido/gradido/pull/396) +- refactor: Split GddSend into Components [`#415`](https://github.com/gradido/gradido/pull/415) +- fix: Set Maximum Transactions Loaded to 1000 [`#395`](https://github.com/gradido/gradido/pull/395) +- BUG : preRELEASE : thx transaction false [`#394`](https://github.com/gradido/gradido/pull/394) +- feat: Validation of Input Fields of GddSend [`#386`](https://github.com/gradido/gradido/pull/386) +- add validation, check if user has tried to send themself gradidos [`#277`](https://github.com/gradido/gradido/pull/277) +- fix link generation [`#347`](https://github.com/gradido/gradido/pull/347) +- Community start decay [`#387`](https://github.com/gradido/gradido/pull/387) +- transaction error message, translations [`#388`](https://github.com/gradido/gradido/pull/388) +- docu: locales schöpfen-mysql befehl [`#392`](https://github.com/gradido/gradido/pull/392) +- Fix: QR Scanner Hide [`#380`](https://github.com/gradido/gradido/pull/380) +- change design- dark-blue of text-ligth [`#381`](https://github.com/gradido/gradido/pull/381) +- spelling & translation [`#385`](https://github.com/gradido/gradido/pull/385) +- 350 6 login [`#383`](https://github.com/gradido/gradido/pull/383) +- fix: breakout error [`#375`](https://github.com/gradido/gradido/pull/375) +- 233-Support-Button fix, and col error fix [`#343`](https://github.com/gradido/gradido/pull/343) +- fix: membersarea open in a new tap [`#370`](https://github.com/gradido/gradido/pull/370) +- 00x table footer componente [`#345`](https://github.com/gradido/gradido/pull/345) +- clickevent from icon to button [`#364`](https://github.com/gradido/gradido/pull/364) +- 404 link to login page fix [`#366`](https://github.com/gradido/gradido/pull/366) +- bug: session_id vs sessionId [`#365`](https://github.com/gradido/gradido/pull/365) +- eslint rule standard [`#344`](https://github.com/gradido/gradido/pull/344) +- don't show decays smaller than 0,01 GDD [`#329`](https://github.com/gradido/gradido/pull/329) +- 338 - mt-5 margin top 5 eingebunden [`#341`](https://github.com/gradido/gradido/pull/341) +- feat: Update Transactions When GddTable Is Rendered [`#339`](https://github.com/gradido/gradido/pull/339) +- my profile auskommentiert [`#337`](https://github.com/gradido/gradido/pull/337) +- give balance as float value in GDD (not longer GDD cent) [`#273`](https://github.com/gradido/gradido/pull/273) +- fix error with password reset email [`#276`](https://github.com/gradido/gradido/pull/276) +- transaction.show_all in en.json hinzugefügt [`#335`](https://github.com/gradido/gradido/pull/335) +- refactor: Add Paramerts to ListTransactions API Call [`#332`](https://github.com/gradido/gradido/pull/332) +- css abstände vom rand in mobilen style [`#272`](https://github.com/gradido/gradido/pull/272) +- error messages are displayed [`#304`](https://github.com/gradido/gradido/pull/304) +- cancel to reset, form rest event added [`#334`](https://github.com/gradido/gradido/pull/334) +- remove from error messages because its no longer exist [`#330`](https://github.com/gradido/gradido/pull/330) +- xx deleted [`#333`](https://github.com/gradido/gradido/pull/333) +- fix bug on Login group add host [`#274`](https://github.com/gradido/gradido/pull/274) +- transactionslist load and icon [`#324`](https://github.com/gradido/gradido/pull/324) +- THX changed to Thank you [`#305`](https://github.com/gradido/gradido/pull/305) +- fix_bug_template [`#284`](https://github.com/gradido/gradido/pull/284) +- feat: Restructure Overview [`#271`](https://github.com/gradido/gradido/pull/271) +- fix: Dynamic Balance in User Profile [`#278`](https://github.com/gradido/gradido/pull/278) +- refactor: Test and Clean Up Store [`#270`](https://github.com/gradido/gradido/pull/270) +- remove links to not work [`#267`](https://github.com/gradido/gradido/pull/267) +- change order of session_id [`#269`](https://github.com/gradido/gradido/pull/269) +- bug: Dynamic Balance [`#260`](https://github.com/gradido/gradido/pull/260) +- Fix problems with transactions in docker environment [`#261`](https://github.com/gradido/gradido/pull/261) +- update skeema call to allow also for unsafe db updates [`#250`](https://github.com/gradido/gradido/pull/250) +- turn registration on and off [`#266`](https://github.com/gradido/gradido/pull/266) +- 243 vue loader component - varante 2 [`#257`](https://github.com/gradido/gradido/pull/257) +- fix_issue_templates [`#262`](https://github.com/gradido/gradido/pull/262) +- fix_nginx_docker [`#253`](https://github.com/gradido/gradido/pull/253) +- 13_coverage [`#255`](https://github.com/gradido/gradido/pull/255) +- add language as fields which will be returned with user-object [`#244`](https://github.com/gradido/gradido/pull/244) +- add short description for target date in creation transaction [`#252`](https://github.com/gradido/gradido/pull/252) +- fix error "Integrity constraint violation: 1052 Column 'id' in where … [`#251`](https://github.com/gradido/gradido/pull/251) +- Clicks on button [`#246`](https://github.com/gradido/gradido/pull/246) +- Change css [`#231`](https://github.com/gradido/gradido/pull/231) +- feat: Reset Password [`#212`](https://github.com/gradido/gradido/pull/212) +- fix bug #221 [`#228`](https://github.com/gradido/gradido/pull/228) +- fix empty reply by empty group_id [`#227`](https://github.com/gradido/gradido/pull/227) +- Bugfix 22 04 21 [`#226`](https://github.com/gradido/gradido/pull/226) +- Rollback use prebuild dependencies [`#225`](https://github.com/gradido/gradido/pull/225) +- Docu [`#199`](https://github.com/gradido/gradido/pull/199) +- update login-server build [`#222`](https://github.com/gradido/gradido/pull/222) +- Login add language [`#220`](https://github.com/gradido/gradido/pull/220) +- User Object on Json Login [`#219`](https://github.com/gradido/gradido/pull/219) +- refactor: Remove loginAPI Call from Store [`#215`](https://github.com/gradido/gradido/pull/215) +- fix: Remove Rules for Password on Login [`#214`](https://github.com/gradido/gradido/pull/214) +- Community 15 04 2021 [`#198`](https://github.com/gradido/gradido/pull/198) +- refactor: Remove Right Menu [`#204`](https://github.com/gradido/gradido/pull/204) +- feat: Raise Frontend Test Coverage to 12% [`#206`](https://github.com/gradido/gradido/pull/206) +- refactor: Remove Cookies [`#202`](https://github.com/gradido/gradido/pull/202) +- fix_docker_compose [`#205`](https://github.com/gradido/gradido/pull/205) +- 62 pwd reset [`#203`](https://github.com/gradido/gradido/pull/203) +- workflows_refactor [`#200`](https://github.com/gradido/gradido/pull/200) +- feat: Link to Whitepaper in Content-Footer [`#196`](https://github.com/gradido/gradido/pull/196) +- update code which produce error which last fix (._.); [`#197`](https://github.com/gradido/gradido/pull/197) +- refactor: Redirects and Misuse of Children in Router [`#194`](https://github.com/gradido/gradido/pull/194) +- fix: Gradido-Akademie in Footer Links to gradido.net [`#170`](https://github.com/gradido/gradido/pull/170) +- fix register [`#160`](https://github.com/gradido/gradido/pull/160) +- Login 14.04.21 [`#175`](https://github.com/gradido/gradido/pull/175) +- coverage_no_report [`#176`](https://github.com/gradido/gradido/pull/176) +- Community 14.04.21 [`#174`](https://github.com/gradido/gradido/pull/174) +- feat: Add Coverage Check To GitHub Workflow [`#158`](https://github.com/gradido/gradido/pull/158) +- Stage2 [`#49`](https://github.com/gradido/gradido/pull/49) +- feat: Unit Test for KontoOverview [`#169`](https://github.com/gradido/gradido/pull/169) +- fix: Remove Hashtag From Route [`#167`](https://github.com/gradido/gradido/pull/167) +- documentation for reset password [`#166`](https://github.com/gradido/gradido/pull/166) +- 90 show release version in frontend [`#153`](https://github.com/gradido/gradido/pull/153) +- docu frontend menu page structur [`#159`](https://github.com/gradido/gradido/pull/159) +- userstorry_button.txt example [`#157`](https://github.com/gradido/gradido/pull/157) +- fix getBalance API call [`#147`](https://github.com/gradido/gradido/pull/147) +- Locale clear list merge master [`#119`](https://github.com/gradido/gradido/pull/119) +- fix-125-link-to-community [`#152`](https://github.com/gradido/gradido/pull/152) +- feat: Test Dashboard Layout [`#154`](https://github.com/gradido/gradido/pull/154) +- feat: Activate Coverage Report For Unit Tests In Frontend [`#156`](https://github.com/gradido/gradido/pull/156) +- Docu [`#120`](https://github.com/gradido/gradido/pull/120) +- Fix compose bug [`#138`](https://github.com/gradido/gradido/pull/138) +- feat: Test Login Form [`#113`](https://github.com/gradido/gradido/pull/113) +- at last, fix email-bug [`#134`](https://github.com/gradido/gradido/pull/134) +- Api password reset [`#82`](https://github.com/gradido/gradido/pull/82) +- Optimize login server build [`#101`](https://github.com/gradido/gradido/pull/101) +- markdown of login server api [`#111`](https://github.com/gradido/gradido/pull/111) +- Fix lineendings [`#112`](https://github.com/gradido/gradido/pull/112) +- Background color change [`#117`](https://github.com/gradido/gradido/pull/117) +- Delete unused files [`#116`](https://github.com/gradido/gradido/pull/116) +- store aufräumen teil 1 [`#115`](https://github.com/gradido/gradido/pull/115) +- add migrations table for automatic table data migration [`40a9a8c`](https://github.com/gradido/gradido/commit/40a9a8c2b587f5bef0fcc54136ed7bd13dd91b2b) +- update yarn.lock after running yarn install [`7f38c80`](https://github.com/gradido/gradido/commit/7f38c801213ad886e9d34a8d43b00ae423f5f2a0) +- use new function for balance overview in old frontend, update balance in session on every php-request [`97c570c`](https://github.com/gradido/gradido/commit/97c570c08cc51ed17a69eb8be8d987f95f3c2ce0) + #### [0.9.4](https://github.com/gradido/gradido/compare/0.9.3...0.9.4) +> 30 March 2021 + +- Vue with nginx [`#84`](https://github.com/gradido/gradido/pull/84) - Build on run [`#103`](https://github.com/gradido/gradido/pull/103) - update debug docker to use dependencies container pushed to docker hub [`1f002f4`](https://github.com/gradido/gradido/commit/1f002f4ed0b12d4b2bf63efceabe546d0c5b58ea) - removed email tasks complete [`8a143be`](https://github.com/gradido/gradido/commit/8a143be8423d7bd894d4f512848895df8b9694b0) diff --git a/community_server/src/Controller/AppController.php b/community_server/src/Controller/AppController.php index 9f577d77a..a1416678f 100644 --- a/community_server/src/Controller/AppController.php +++ b/community_server/src/Controller/AppController.php @@ -21,7 +21,7 @@ use Cake\Routing\Router; use Cake\ORM\TableRegistry; use Cake\Core\Configure; use Cake\I18n\Time; -use Cake\I18n\I18n; +use Cake\I18n\FrozenTime; /** * Application Controller @@ -174,6 +174,7 @@ class AppController extends Controller protected function requestLogin($sessionId = 0, $redirect = true) { $this->checkForMigration($redirect); + $stateBalancesTable = TableRegistry::getTableLocator()->get('StateBalances'); $session = $this->getRequest()->getSession(); // check login // disable encryption for cookies @@ -206,12 +207,15 @@ class AppController extends Controller $transactionPendings = $session->read('Transactions.pending'); $transactionExecutings = $session->read('Transactions.executing'); $transaction_can_signed = $session->read('Transactions.can_signed'); + + if ($session->read('session_id') != $session_id || ( $userStored && (!isset($userStored['id']) || !$userStored['email_checked'])) || intval($transactionPendings) > 0 || intval($transactionExecutings) > 0 || - intval($transaction_can_signed > 0)) { + intval($transaction_can_signed > 0)) + { $http = new Client(); try { @@ -242,6 +246,7 @@ class AppController extends Controller $session->write('Transactions.can_signed', $transaction_can_signed); $session->write('session_id', $session_id); $stateUserTable = TableRegistry::getTableLocator()->get('StateUsers'); + if (isset($json['user']['public_hex']) && $json['user']['public_hex'] != '') { $public_key_bin = hex2bin($json['user']['public_hex']); @@ -270,11 +275,6 @@ class AppController extends Controller $this->Flash->error(__('error updating state user ' . json_encode($stateUser->errors()))); } } - //var_dump($stateUser); - if (count($stateUser->state_balances) > 0) { - - $session->write('StateUser.balance', $stateUser->state_balances[0]->decay); - } $session->write('StateUser.id', $stateUser->id); //echo $stateUser['id']; } else { @@ -326,6 +326,11 @@ class AppController extends Controller //continue; } } + $state_balance = $stateBalancesTable->find()->where(['state_user_id' => $session->read('StateUser.id')])->first(); + if ($state_balance) { + $now = new FrozenTime; + $session->write('StateUser.balance', $stateBalancesTable->calculateDecay($state_balance->amount, $state_balance->record_date, $now)); + } } else { // no login //die("no login"); diff --git a/community_server/src/Controller/AppRequestsController.php b/community_server/src/Controller/AppRequestsController.php index 1993e3559..9d8459ddf 100644 --- a/community_server/src/Controller/AppRequestsController.php +++ b/community_server/src/Controller/AppRequestsController.php @@ -360,7 +360,7 @@ class AppRequestsController extends AppController $body['decay'] = 0.0; } else { $body['balance'] = $state_balance->amount; - $body['decay'] = $state_balance->partDecay($now); + $body['decay'] = $stateBalancesTable->calculateDecay($state_balance->amount, $state_balance->record_date, $now); } $this->set('body', $body); diff --git a/community_server/src/Controller/MigrationsController.php b/community_server/src/Controller/MigrationsController.php index 31fa41001..97481aff5 100644 --- a/community_server/src/Controller/MigrationsController.php +++ b/community_server/src/Controller/MigrationsController.php @@ -64,6 +64,7 @@ class MigrationsController extends AppController $commands = [ [$blockchainTypesTable, 'fillWithDefault'], [$transactionTypesTable, 'fillWithDefault'], + [$stateBalancesTable, 'truncate'], [$transactionsTable, 'fillStateUserTransactions'], [$stateBalancesTable, 'updateAllBalances'] ]; diff --git a/community_server/src/Controller/StateBalancesController.php b/community_server/src/Controller/StateBalancesController.php index 655dbc026..0dc9b672d 100644 --- a/community_server/src/Controller/StateBalancesController.php +++ b/community_server/src/Controller/StateBalancesController.php @@ -2,7 +2,7 @@ namespace App\Controller; use Cake\ORM\TableRegistry; -use Cake\I18n\Time; +use Cake\I18n\FrozenTime; use Model\Navigation\NaviHierarchy; use Model\Navigation\NaviHierarchyEntry; @@ -65,6 +65,7 @@ class StateBalancesController extends AppController if($update_balance_result['success'] !== true) { $this->addAdminError('StateBalances', 'overview', $update_balance_result, $user['id']); } + // sendRequestGDT // listPerEmailApi @@ -84,200 +85,68 @@ class StateBalancesController extends AppController //} // // + $stateBalancesTable = TableRegistry::getTableLocator()->get('StateBalances'); $stateUserTransactionsTable = TableRegistry::getTableLocator()->get('StateUserTransactions'); - - $creationsTable = TableRegistry::getTableLocator()->get('TransactionCreations'); - $creationTransactions = $creationsTable - ->find('all') - ->where(['state_user_id' => $user['id']]) - ->contain(['Transactions']); - - $transferTable = TableRegistry::getTableLocator()->get('TransactionSendCoins'); - $transferTransactions = $transferTable - ->find('all') - ->where(['OR' => ['state_user_id' => $user['id'], 'receiver_user_id' => $user['id']]]) - ->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)); - } elseif ($sendCoins->receiver_user_id != $user['id']) { - array_push($involvedUserIds, intval($sendCoins->receiver_user_id)); - } - } - - /*echo "state user from sendCoins: $sendCoins->state_user_id
"; - echo "receiver user from sendCoins: $sendCoins->receiver_user_id
"; - echo "user id from logged in user: ".$user['id']. '
'; - */ - //var_dump($involvedUserIds); - // exchange key with values and drop duplicates - $involvedUser_temp = array_flip($involvedUserIds); - // exchange back - $involvedUserIds = array_flip($involvedUser_temp); - $userTable = TableRegistry::getTableLocator()->get('StateUsers'); - $involvedUser = $userTable->find('all', [ - 'contain' => false, - 'where' => ['id IN' => $involvedUserIds], - 'fields' => ['id', 'first_name', 'last_name', 'email'] - ]); - //var_dump($involvedUser->toArray()); - $involvedUserIndices = []; - foreach ($involvedUser as $involvedUser) { - $involvedUserIndices[$involvedUser->id] = $involvedUser; - } - - // sender or receiver when user has sended money - // group name if creation - // type: gesendet / empfangen / geschöpft - // transaktion nr / id - // date - // balance - - $transactions = []; - foreach ($creationTransactions as $creation) { - //var_dump($creation); - array_push($transactions, [ - 'name' => 'Gradido Akademie', - 'type' => 'creation', - 'transaction_id' => $creation->transaction_id, - 'date' => $creation->target_date, - 'balance' => $creation->amount, - 'memo' => $creation->transaction->memo - ]); - } - - foreach ($transferTransactions as $sendCoins) { - $type = ''; - $otherUser = null; - $other_user_public = ''; - if ($sendCoins->state_user_id == $user['id']) { - $type = 'send'; - - if(isset($involvedUserIndices[$sendCoins->receiver_user_id])) { - $otherUser = $involvedUserIndices[$sendCoins->receiver_user_id]; - } - $other_user_public = bin2hex(stream_get_contents($sendCoins->receiver_public_key)); - } else if ($sendCoins->receiver_user_id == $user['id']) { - $type = 'receive'; - if(isset($involvedUserIndices[$sendCoins->state_user_id])) { - $otherUser = $involvedUserIndices[$sendCoins->state_user_id]; - } - if($sendCoins->sender_public_key) { - $other_user_public = bin2hex(stream_get_contents($sendCoins->sender_public_key)); - } - } - if(null == $otherUser) { - $otherUser = $this->StateBalances->StateUsers->newEntity(); - } - array_push($transactions, [ - 'name' => $otherUser->first_name . ' ' . $otherUser->last_name, - 'email' => $otherUser->email, - 'type' => $type, - 'transaction_id' => $sendCoins->transaction_id, - 'date' => $sendCoins->transaction->received, - 'balance' => $sendCoins->amount, - 'memo' => $sendCoins->transaction->memo, - 'pubkey' => $other_user_public - ]); - } - uasort($transactions, array($this, 'sortTransactions')); + $transactionsTable = TableRegistry::getTableLocator()->get('Transactions'); - // add decay transactions - $month_start_state_balance = null; - $current_state_balance = null; - $cursor = 0; - $transactions_reversed = array_reverse($transactions); - $decay_transactions = []; - $maxI = count($transactions_reversed); + + $stateBalancesTable->updateBalances($user['id']); - foreach($transactions_reversed as $i => $transaction) { - if(!isset($transaction['transaction_id'])) { - //echo "missing transaction
"; - continue; - } - $transaction_id = $transaction['transaction_id']; - //echo "transaction id: $transaction_id
"; - $decay_transaction = NULL; - $state_balance = $this->StateBalances->newEntity(); - - if($i > 0 && isset($transactions_reversed[$i-1]['transaction_id'])) { - $prev_transaction = $transactions_reversed[$i-1]; - $stateUserTransactions = $stateUserTransactionsTable - ->find() - ->where([ - 'transaction_id IN' => [$transaction_id, $prev_transaction['transaction_id']], - 'state_user_id' => $user['id'] - ]) - ->order(['balance_date ASC']) - ->toArray(); - - $prev = $stateUserTransactions[0]; - if($prev->balance > 0) { - // var_dump($stateUserTransactions); - $current = $stateUserTransactions[1]; - //echo "decay between " . $prev->transaction_id . " and " . $current->transaction_id . "
"; - $interval = $current->balance_date->diff($prev->balance_date); - $state_balance->amount = $prev->balance; - $state_balance->record_date = $prev->balance_date; - $diff_amount = $state_balance->partDecay($current->balance_date); - - //echo $interval->format('%R%a days'); - //echo "prev balance: " . $prev->balance . ", diff_amount: $diff_amount, summe: " . (-intval($prev->balance - $diff_amount)) . "
"; - $decay_transaction = [ - 'type' => 'decay', - 'balance' => -intval($prev->balance - $diff_amount), - 'decay_duration' => $interval->format('%a days, %H hours, %I minutes, %S seconds'), - 'memo' => '' - ]; - } - } - - if($decay_transaction) { - $decay_transactions[] = $decay_transaction; - //array_splice($transactions_reversed, $i + $cursor, 0, [$decay_transaction]); - //$cursor++; - } - if($i == $maxI-1) { - $stateUserTransaction = $stateUserTransactionsTable - ->find() - ->where(['transaction_id' => $transaction_id, 'state_user_id' => $user['id']]) - ->order(['transaction_id ASC'])->first(); - //var_dump($stateUserTransaction); - $state_balance->amount = $stateUserTransaction->balance; - $state_balance->record_date = $stateUserTransaction->balance_date; - $decay_transactions[] = [ - //$transactions_reversed[] = [ - 'type' => 'decay', - 'balance' => -intval($stateUserTransaction->balance - $state_balance->decay), - 'decay_duration' => $stateUserTransaction->balance_date->timeAgoInWords(), - 'memo' => '' - ]; - - } + $gdtSum = 0; + $gdtEntries = $this->JsonRequestClient->sendRequestGDT(['email' => $user['email']], 'GdtEntries' . DS . 'sumPerEmailApi'); + + if('success' == $gdtEntries['state'] && 'success' == $gdtEntries['data']['state']) { + $gdtSum = intval($gdtEntries['data']['sum']); + } else { + $this->addAdminError('StateBalancesController', 'overview', $gdtEntries, $user['id'] ? $user['id'] : 0); } - $final_transactions = []; - foreach($transactions_reversed as $i => $transaction) { - $final_transactions[] = $transaction; - $final_transactions[] = $decay_transactions[$i]; + + + $stateUserTransactionsQuery = $stateUserTransactionsTable + ->find() + ->where(['state_user_id' => $user['id']]) + ->order(['balance_date' => 'ASC']) + ->contain([]) + ; + $decay = true; + $transactions = []; + if($stateUserTransactionsQuery->count() > 0) { + $transactions = $transactionsTable->listTransactionsHumanReadable($stateUserTransactionsQuery->toArray(), $user, $decay); + } + + $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) { + $balance = 0.0; + } else { + $balance = $stateBalancesTable->calculateDecay($state_balance->amount, $state_balance->record_date, $now); + //$balance = $state_balance->partDecay($now); } - // for debugging $calculated_balance = 0; - foreach($final_transactions as $tr) { - if($tr['type'] == 'send') { - $calculated_balance -= intval($tr['balance']); + foreach($transactions as $transaction) { + if($transaction['type'] == 'decay' || $transaction['type'] == 'send') { + $calculated_balance -= $transaction['balance']; } else { - $calculated_balance += intval($tr['balance']); + $calculated_balance += $transaction['balance']; } } + $this->set('calculated_balance', $calculated_balance); - $this->set('transactions', array_reverse($final_transactions)); + $this->set('transactions', array_reverse($transactions)); $this->set('transactionExecutingCount', $session->read('Transactions.executing')); - $this->set('balance', $session->read('StateUser.balance')); + $this->set('balance', $balance); $this->set('timeUsed', microtime(true) - $startTime); $this->set('gdtSum', $gdtSum); } @@ -301,151 +170,16 @@ class StateBalancesController extends AppController if(!$state_balance) { return $this->returnJson(['state' => 'success', 'balance' => 0]); } + $now = new FrozenTime(); return $this->returnJson([ 'state' => 'success', 'balance' => $state_balance->amount, - 'decay' => $state_balance->decay + 'decay' => $this->StateBalances->calculateDecay($state_balance->amount, $state_balance->record_date, $now), + 'decay_date' => $now ]); } - - public function ajaxListTransactions($session_id, $page=1, $count=25) - { - if(!$session_id) { - return $this->returnJson(['state' => 'error', 'msg' => 'invalid session id']); - } - - $startTime = microtime(true); - $login_result = $this->requestLogin($session_id, false); - if($login_result !== true) { - return $this->returnJson($login_result); - } - $session = $this->getRequest()->getSession(); - $user = $session->read('StateUser'); - - $this->StateBalances->updateBalances($user['id']); - - $gdtSum = 0; - $gdtEntries = $this->JsonRequestClient->sendRequestGDT(['email' => $user['email']], 'GdtEntries' . DS . 'sumPerEmailApi'); - - if('success' == $gdtEntries['state'] && 'success' == $gdtEntries['data']['state']) { - $gdtSum = intval($gdtEntries['data']['sum']); - } else { - if($user) { - $this->addAdminError('StateBalancesController', 'overview', $gdtEntries, $user['id']); - } else { - $this->addAdminError('StateBalancesController', 'overview', $gdtEntries, 0); - } - } - - $creationsTable = TableRegistry::getTableLocator()->get('TransactionCreations'); - $creationTransactions = $creationsTable - ->find('all') - ->where(['state_user_id' => $user['id']]) - ->contain(['Transactions']); - - $transferTable = TableRegistry::getTableLocator()->get('TransactionSendCoins'); - $transferTransactions = $transferTable - ->find('all') - ->where(['OR' => ['state_user_id' => $user['id'], 'receiver_user_id' => $user['id']]]) - ->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)); - } elseif ($sendCoins->receiver_user_id != $user['id']) { - array_push($involvedUserIds, intval($sendCoins->receiver_user_id)); - } - } - - /*echo "state user from sendCoins: $sendCoins->state_user_id
"; - echo "receiver user from sendCoins: $sendCoins->receiver_user_id
"; - echo "user id from logged in user: ".$user['id']. '
'; - */ - //var_dump($involvedUserIds); - // exchange key with values and drop duplicates - $involvedUser_temp = array_flip($involvedUserIds); - // exchange back - $involvedUserIds = array_flip($involvedUser_temp); - $userTable = TableRegistry::getTableLocator()->get('StateUsers'); - $involvedUser = $userTable->find('all', [ - 'contain' => false, - 'where' => ['id IN' => $involvedUserIds], - 'fields' => ['id', 'first_name', 'last_name', 'email'] - ]); - //var_dump($involvedUser->toArray()); - $involvedUserIndices = []; - foreach ($involvedUser as $involvedUser) { - $involvedUserIndices[$involvedUser->id] = $involvedUser; - } - - // sender or receiver when user has sended money - // group name if creation - // type: gesendet / empfangen / geschöpft - // transaktion nr / id - // date - // balance - - $transactions = []; - foreach ($creationTransactions as $creation) { - //var_dump($creation); - array_push($transactions, [ - 'name' => 'Gradido Akademie', - 'type' => 'creation', - 'transaction_id' => $creation->transaction_id, - 'date' => $creation->transaction->received, - 'balance' => $creation->amount, - 'memo' => $creation->transaction->memo - ]); - } - - foreach ($transferTransactions as $sendCoins) { - $type = ''; - $otherUser = null; - if ($sendCoins->state_user_id == $user['id']) { - $type = 'send'; - - if(isset($involvedUserIndices[$sendCoins->receiver_user_id])) { - $otherUser = $involvedUserIndices[$sendCoins->receiver_user_id]; - } - } else if ($sendCoins->receiver_user_id == $user['id']) { - $type = 'receive'; - if(isset($involvedUserIndices[$sendCoins->state_user_id])) { - $otherUser = $involvedUserIndices[$sendCoins->state_user_id]; - } - } - if(null == $otherUser) { - $otherUser = $this->StateBalances->StateUsers->newEntity(); - } - array_push($transactions, [ - 'name' => $otherUser->first_name . ' ' . $otherUser->last_name, - 'email' => $otherUser->email, - 'type' => $type, - 'transaction_id' => $sendCoins->transaction_id, - 'date' => $sendCoins->transaction->received, - 'balance' => $sendCoins->amount, - 'memo' => $sendCoins->transaction->memo - ]); - } - uasort($transactions, array($this, 'sortTransactions')); - if($sort == 'DESC') { - $transactions = array_reverse($transactions); - } - return $this->returnJson([ - 'state' => 'success', - 'transactions' => $transactions, - 'transactionExecutingCount' => $session->read('Transactions.executing'), - 'count' => count($transactions), - 'gdtSum' => $gdtSum, - 'timeUsed' => microtime(true) - $startTime - ]); - } - - public function ajaxGdtOverview() { diff --git a/community_server/src/Model/Table/AppTable.php b/community_server/src/Model/Table/AppTable.php index 138a7f949..a0758c97a 100644 --- a/community_server/src/Model/Table/AppTable.php +++ b/community_server/src/Model/Table/AppTable.php @@ -22,6 +22,7 @@ class AppTable extends Table $this->getConnection()->query($truncateCommand); } $this->getConnection()->query('ALTER TABLE ' . $this->getSchema()->name() . ' AUTO_INCREMENT=1'); + return ['success' => true]; } public function saveManyWithErrors($entities) { diff --git a/community_server/src/Model/Table/StateBalancesTable.php b/community_server/src/Model/Table/StateBalancesTable.php index 7e5f96be9..25d588f30 100644 --- a/community_server/src/Model/Table/StateBalancesTable.php +++ b/community_server/src/Model/Table/StateBalancesTable.php @@ -24,7 +24,7 @@ use Cake\I18n\FrozenTime; * * @mixin \Cake\ORM\Behavior\TimestampBehavior */ -class StateBalancesTable extends Table +class StateBalancesTable extends AppTable { private static $startDecayDate = null; /** diff --git a/community_server/src/Model/Table/TransactionsTable.php b/community_server/src/Model/Table/TransactionsTable.php index 742ce7882..f2bf1437f 100644 --- a/community_server/src/Model/Table/TransactionsTable.php +++ b/community_server/src/Model/Table/TransactionsTable.php @@ -426,6 +426,9 @@ class TransactionsTable extends Table } } } + if(count($state_user_ids) < 1) { + return ['success' => true]; + } //var_dump($entities); $stateUsersTable = TableRegistry::getTableLocator()->get('StateUsers'); $existingStateUsers = $stateUsersTable->find('all')->select(['id'])->where(['id IN' => $state_user_ids])->order(['id'])->all(); diff --git a/frontend/package.json b/frontend/package.json index 53e5fdbcb..21b02ee2e 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-vue-gradido-wallet", - "version": "0.9.4", + "version": "1.0.1", "private": true, "scripts": { "start": "node run/server.js", diff --git a/frontend/src/App.vue b/frontend/src/App.vue index b47b9caf0..d44d64ab3 100755 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,20 +1,5 @@ @@ -102,7 +100,7 @@ export default { name: 'GddTable', props: { transactions: { default: [] }, - max: { type: Number, default: 25 }, + max: { type: Number, default: 1000 }, timestamp: { type: Number, default: 0 }, transactionCount: { type: Number, default: 0 }, }, diff --git a/frontend/src/views/Pages/Register.vue b/frontend/src/views/Pages/Register.vue index 42761ec99..30ab578a2 100755 --- a/frontend/src/views/Pages/Register.vue +++ b/frontend/src/views/Pages/Register.vue @@ -97,7 +97,6 @@

-
diff --git a/frontend/src/views/Pages/thx.vue b/frontend/src/views/Pages/thx.vue index 1a5a7112b..db0b967d6 100644 --- a/frontend/src/views/Pages/thx.vue +++ b/frontend/src/views/Pages/thx.vue @@ -1,7 +1,7 @@