diff --git a/community_server/src/Controller/StateBalancesController.php b/community_server/src/Controller/StateBalancesController.php index 4afeabd8b..da2a58e65 100644 --- a/community_server/src/Controller/StateBalancesController.php +++ b/community_server/src/Controller/StateBalancesController.php @@ -39,32 +39,143 @@ class StateBalancesController extends AppController $this->set(compact('stateBalances')); } - private function updateBalances($state_user_id) + private function updateBalances($stateUserId) { - $state_balances = $this->StateBalances->find('all')->where(['state_user_id' => $state_user_id]); - if($state_balances->count() == 1) { - $stateUserTransactionsTable = TableRegistry::getTableLocator()->get('StateUserTransactions'); - $state_user_transactions = $stateUserTransactionsTable + $stateUserTransactionsTable = TableRegistry::getTableLocator()->get('StateUserTransactions'); + $transactionsTable = TableRegistry::getTableLocator()->get('Transactions'); + // info: cakephp use lazy loading, query will be executed later only if needed + $state_balances = $this->StateBalances->find('all')->where(['state_user_id' => $stateUserId]); + $state_user_transactions = $stateUserTransactionsTable ->find('all') - ->where(['state_user_id' => $state_user_id]) + ->where(['state_user_id' => $stateUserId]) ->order(['transaction_id ASC']) - ->contain(['']); - if($state_user_transactions->count() == 0){ - return; - } - $last_state_user_transaction = $state_user_transactions->last(); - $last_transaction = $this->StateBalance->newEntity(); - $last_transaction->amount = $last_state_user_transaction->balance; - $last_transaction->record_date = $last_state_user_transaction->balance_date; - // if entrys are nearly the same, we don't need doing anything - if(abs($last_transaction->decay - $state_balances->decay) < 100) { - return; - } - foreach($state_user_transactions as $state_user_transaction) { - - } - + ->contain(false); + + if(!$state_user_transactions) { + //debug($state_user_transactions); + return true; } + + // first: decide what todo + $create_state_balance = false; + $recalculate_state_user_transactions_balance = false; + $clear_state_balance = false; + $update_state_balance = false; + if($state_balances->count() == 0) { + $create_state_balance = true; + } + if($state_balances->count() > 1) { + $clear_state_balance = true; + $create_state_balance = true; + } + if($state_balances->count() == 1) { + if($state_user_transactions->count() == 0){ + $clear_state_balance = true; + } else { + $last_state_user_transaction = $state_user_transactions->last(); + $last_transaction = $this->StateBalances->newEntity(); + $last_transaction->amount = $last_state_user_transaction->balance; + $last_transaction->record_date = $last_state_user_transaction->balance_date; + // if entrys are nearly the same, we don't need doing anything + if(abs($last_transaction->decay - $state_balances->first()->decay) > 100) { + $recalculate_state_user_transactions_balance = true; + $update_state_balance = true; + } + } + } + + if(!$recalculate_state_user_transactions_balance) { + $last_state_user_transaction = $state_user_transactions->last(); + if($last_state_user_transaction->balance <= 0) { + $recalculate_state_user_transactions_balance = true; + if(!$create_state_balance) { + $update_state_balance = true; + } + } + } + // second: do what is needed + if($clear_state_balance) { + $this->StateBalances->deleteAll(['state_user_id' => $stateUserId]); + } + + $transaction_ids = []; + if($recalculate_state_user_transactions_balance) { + $state_user_transactions_array = $state_user_transactions->toArray(); + foreach($state_user_transactions_array as $i => $state_user_transaction) { + $transaction_ids[$state_user_transaction->transaction_id] = $i; + } + + $transactions = $transactionsTable + ->find('all') + ->where(['id IN' => array_keys($transaction_ids)]) + ->contain(['TransactionCreations', 'TransactionSendCoins']); + + $balance_cursor = $this->StateBalances->newEntity(); + $i = 0; + foreach($transactions as $transaction) { + if($transaction->transaction_type_id > 2) { + continue; + } + $amount_date = null; + $amount = 0; + + if($transaction->transaction_type_id == 1) { + $temp = $transaction->transaction_creations[0]; + + $balance_temp = $this->StateBalances->newEntity(); + $balance_temp->amount = $temp->amount; + $balance_temp->record_date = $temp->target_date; + + $amount = $balance_temp->partDecay($transaction->received); + $amount_date = $transaction->received; + //$amount_date = + } else if($transaction->transaction_type_id == 2) { + $temp = $transaction->transaction_send_coins[0]; + $amount = intval($temp->amount); + // reverse if sender + if($stateUserId == $temp->state_user_id) { + $amount *= -1.0; + } + $amount_date = $transaction->received; + } + if($i == 0) { + $balance_cursor->amount = $amount; + } else { + $balance_cursor->amount = $balance_cursor->partDecay($amount_date) + $amount; + } + $balance_cursor->record_date = $amount_date; + $state_user_transaction_index = $transaction_ids[$transaction->id]; + $state_user_transactions_array[$state_user_transaction_index]->balance = $balance_cursor->amount; + $state_user_transactions_array[$state_user_transaction_index]->balance_date = $balance_cursor->record_date; + $i++; + } + $results = $stateUserTransactionsTable->saveMany($state_user_transactions_array); + $errors = []; + foreach($results as $i => $result) { + if(!$result) { + $errors[$i] = $state_user_transactions_array[$i]->getErrors(); + } + } + if(count($errors)) { + return ['success' => false, 'error' => 'error saving one ore more state user transactions', 'details' => $errors]; + } + } + $state_balance = null; + if($update_state_balance) { + $state_balance = $state_balances->first(); + } + else if($create_state_balance) { + $state_balance = $this->StateBalances->newEntity(); + $state_balance->state_user_id = $stateUserId; + } + if($state_balance) { + $state_balance->amount = $state_user_transactions->last()->balance; + $state_balance->record_date = $state_user_transactions->last()->balance_date; + if(!$this->StateBalances->save($state_balance)) { + return ['success' => false, 'error' => 'error saving state balance', 'details' => $state_balance->getErrors()]; + } + } + return true; } public function overview() @@ -82,7 +193,9 @@ class StateBalancesController extends AppController if ($result !== true) { return $result; } + $user = $session->read('StateUser'); + $this->updateBalances($user['id']); // sendRequestGDT // listPerEmailApi @@ -214,6 +327,7 @@ class StateBalancesController extends AppController } $session = $this->getRequest()->getSession(); $user = $session->read('StateUser'); + $this->updateBalances($user['id']); $public_key_bin = hex2bin($user['public_hex']); $stateUserQuery = $this->StateBalances->StateUsers diff --git a/community_server/src/Controller/StateUsersController.php b/community_server/src/Controller/StateUsersController.php index 9f07fffdb..43c6664c0 100644 --- a/community_server/src/Controller/StateUsersController.php +++ b/community_server/src/Controller/StateUsersController.php @@ -69,14 +69,14 @@ class StateUsersController extends AppController $this->set(compact('stateUsers')); } - public function listIdentHashes() + /*public function listIdentHashes() { $stateUsers = $this->StateUsers->find('all')->toArray(); foreach ($stateUsers as $i => $user) { $stateUsers[$i]->identHash = TransactionCreation::DRMakeStringHash($user->email); } $this->set('stateUsers', $stateUsers); - } + }*/ public function search() { diff --git a/community_server/src/Controller/TransactionCreationsController.php b/community_server/src/Controller/TransactionCreationsController.php index af7b9a018..46a7a37f4 100644 --- a/community_server/src/Controller/TransactionCreationsController.php +++ b/community_server/src/Controller/TransactionCreationsController.php @@ -54,12 +54,12 @@ class TransactionCreationsController extends AppController ]; $transactionCreations = $this->paginate($this->TransactionCreations); $identHashes = []; - foreach ($transactionCreations as $creation) { + /*foreach ($transactionCreations as $creation) { $identHash = TransactionCreation::DRMakeStringHash($creation->state_user->email); $identHashes[$creation->state_user->id] = $identHash; - } + }*/ - $this->set(compact('transactionCreations', 'identHashes')); + //$this->set(compact('transactionCreations', 'identHashes')); } /** @@ -125,7 +125,7 @@ class TransactionCreationsController extends AppController if (count($receiverProposal) > $receiverIndex) { $pubKeyHex = $receiverProposal[$receiverIndex]['key']; - $identHash = TransactionCreation::DRMakeStringHash($receiverProposal[$receiverIndex]['email']); + //$identHash = TransactionCreation::DRMakeStringHash($receiverProposal[$receiverIndex]['email']); } $builderResult = TransactionCreation::build( $amountCent, @@ -369,7 +369,20 @@ class TransactionCreationsController extends AppController $pendings[$id] = $localAmountCent; } $pubKeyHex = bin2hex(stream_get_contents($receiverUser->public_key)); - $identHash = TransactionCreation::DRMakeStringHash($receiverUser->email); + $requestAnswear = $this->JsonRequestClient->sendRequest(json_encode([ + 'session_id' => $session->read('session_id'), + 'email' => $receiverUser->email, + 'ask' => ['user.identHash'] + ]), '/getUserInfos'); + + $identHash = 0; + if('success' == $requestAnswear['state'] && 'success' == $requestAnswear['data']['state']) { + $identHash = $requestAnswear['data']['userData']['identHash']; + } else { + $this->Flash->error(__('Error by requesting LoginServer, please try again')); + } + + //$identHash = TransactionCreation::DRMakeStringHash($receiverUser->email); $localTargetDateFrozen = FrozenDate::now(); $localTargetDateFrozen = $localTargetDateFrozen ->year($localTargetDate['year']) diff --git a/community_server/src/Model/Entity/StateBalance.php b/community_server/src/Model/Entity/StateBalance.php index 871c55bd8..b1c237a3b 100644 --- a/community_server/src/Model/Entity/StateBalance.php +++ b/community_server/src/Model/Entity/StateBalance.php @@ -57,7 +57,8 @@ class StateBalance extends Entity if($decay_duration === 0) { return $this->amount; } - return $this->amount * pow(0.99999997802044727, $decay_duration); + return $this->amount; + //return $this->amount * pow(0.99999997802044727, $decay_duration); } public function partDecay($target_date) @@ -67,7 +68,8 @@ class StateBalance extends Entity if($decay_duration <= 0) { return $this->amount; } - return $this->amount * pow(0.99999997802044727, $decay_duration); + return $this->amount; + //return $this->amount * pow(0.99999997802044727, $decay_duration); } public function decayDuration($target_date) diff --git a/community_server/src/Model/Transactions/TransactionCreation.php b/community_server/src/Model/Transactions/TransactionCreation.php index 71bb7fbf0..aeac73ce8 100644 --- a/community_server/src/Model/Transactions/TransactionCreation.php +++ b/community_server/src/Model/Transactions/TransactionCreation.php @@ -63,24 +63,6 @@ class TransactionCreation extends TransactionBase { return ['state' => 'success', 'transactionBody' => $transactionBody]; } - static protected function DRHashRotateLeft( $hash, $rotateBy ) - { - return ($hash<<$rotateBy)|($hash>>(32-$rotateBy)); - } - - static public function DRMakeStringHash($str) - { - $ret = 0; - - if( $str ) - { - for ($i=0; $i < strlen($str); $i++) - { -// $ret = TransactionCreation::DRHashRotateLeft($ret, 7) + ord($str{$i}); - } - } - return $ret; - } public function getAmount() { return $this->protoTransactionCreation->getReceiverAmount()->getAmount(); @@ -303,7 +285,7 @@ class TransactionCreation extends TransactionBase { // intval //$protoCreation->setIdentHash(intval($identHashBytes)); - $protoCreation->setIdentHash(self::DRMakeStringHash($stateUser->email)); + //$protoCreation->setIdentHash(self::DRMakeStringHash($stateUser->email)); return new TransactionCreation($protoCreation); } } diff --git a/community_server/src/Model/Transactions/TransactionTransfer.php b/community_server/src/Model/Transactions/TransactionTransfer.php index 2c53559d6..b9182c3ba 100644 --- a/community_server/src/Model/Transactions/TransactionTransfer.php +++ b/community_server/src/Model/Transactions/TransactionTransfer.php @@ -75,7 +75,8 @@ class TransactionTransfer extends TransactionBase { foreach($sigPairs as $sigPair) { //echo 'sig Pair: '; var_dump($sigPair); echo "
"; $pubkey = bin2hex($sigPair->getPubKey()); - $hash = TransactionCreation::DRMakeStringHash($pubkey); + //$hash = TransactionCreation::DRMakeStringHash($pubkey); + $hash = $pubkey; if(!isset($sigPubHexs[$hash])) { $sigPubHexs[$hash] = [$pubkey]; } else { @@ -100,7 +101,8 @@ class TransactionTransfer extends TransactionBase { return false; } // check if signature exist for sender - $hash = TransactionCreation::DRMakeStringHash($senderPublicHex); + //$hash = TransactionCreation::DRMakeStringHash($senderPublicHex); + $hash = $senderPublicHex; if(!isset($sigPubHexs[$hash]) || in_array($senderPublicHex, $sigPubHexs[$hash]) === FALSE) { $this->addError($functionName, 'missing signature for sender'); return false; diff --git a/docker-compose.override.yml b/docker-compose.override.yml index e5d5d25c4..51fc7b05c 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -61,6 +61,20 @@ services: - external-net volumes: - /sessions + + ######################################################### + ## skeema for updating dbs if changes happend ########### + ######################################################### + skeema: + build: + context: . + dockerfile: ./skeema/Dockerfile + target: skeema_run + container_name: skeema + depends_on: + - mariadb + networks: + - internal-net volumes: frontend_node_modules: diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 2b0449c88..e11e03d3d 100755 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -39,7 +39,12 @@ export default { //console.log('%cHey %c' + $cookies.get('gdd_u') + '', 'font-weight:bold', 'color: orange') this.$store.commit('session_id', $cookies.get('gdd_session_id')) this.$store.commit('email', $cookies.get('gdd_u')) - this.$store.commit('language', $cookies.get('gdd_lang')) + if ($cookies.get('gdd_lang') != 'de' || $cookies.get('gdd_lang') != 'de') { + this.$store.commit('language', 'de') + } else { + this.$store.commit('language', $cookies.get('gdd_lang')) + } + this.$i18n.locale = $cookies.get('gdd_lang') this.$router.push('overview') } else { diff --git a/frontend/src/views/KontoOverview/GddAddWork.vue b/frontend/src/views/KontoOverview/GddAddWork.vue deleted file mode 100644 index b1be964aa..000000000 --- a/frontend/src/views/KontoOverview/GddAddWork.vue +++ /dev/null @@ -1,210 +0,0 @@ - - - diff --git a/frontend/src/views/KontoOverview/GddAddWork2.vue b/frontend/src/views/KontoOverview/GddAddWork2.vue index fa31c0144..749265b88 100644 --- a/frontend/src/views/KontoOverview/GddAddWork2.vue +++ b/frontend/src/views/KontoOverview/GddAddWork2.vue @@ -17,7 +17,7 @@ class="form-control" v-model="date" :config="config" - style="font-size: xx-large; padding-left: 20px" + style="font-size: x-large; padding-left: 20px" > @@ -33,7 +33,7 @@ -
+
@@ -45,83 +45,9 @@ - - - - - - - - - - - - - - - - - - - - + weiteren Report hinzufügen - - - - Einreichen, absenden - - -
-
Selected date is - {{ date }}
-

{{ days.lastMonth }} Days in {{ names.lastMonth }}

+ -

- Du hast diesen Monat - {{ stundenSumme > 0 ? 'schon ' : 'noch keine' }} - {{ stundenSumme > 0 ? '' + stundenSumme : '' }} - Stunden eingetragen -

-
- - - - - - - - - - - - - - - - - - - - - - -
- -
-
-
-
-
Selected date is - {{ date }}
-

{{ days.beforLastMonth }} Days in {{ names.beforLastMonth }}

-

Du hast noch keine Einträge

-
+ @@ -143,32 +69,6 @@ export default { maxDate: this.$moment().format('DD.MM.YYYY'), mode: 'range', }, - lastConfig: { - altInput: false, - dateFormat: 'd-m-Y', - minDate: this.$moment() - .month(this.$moment().month() - 1) - .startOf('month') - .format('DD.MM.YYYY'), - maxDate: this.$moment() - .month(this.$moment().month() - 1) - .endOf('month') - .format('DD.MM.YYYY'), - mode: 'range', - }, - beforLastConfig: { - altInput: false, - dateFormat: 'd-m-Y', - minDate: this.$moment() - .month(this.$moment().month() - 2) - .startOf('month') - .format('DD.MM.YYYY'), - maxDate: this.$moment() - .month(this.$moment().month() - 2) - .endOf('month') - .format('DD.MM.YYYY'), - mode: 'range', - }, index: 0, form: [], stundenSumme: 0, @@ -192,7 +92,7 @@ export default { .month(this.$moment().month() - 2) .format('MMMM'), }, - formular: null + formular: null, } }, created() {}, @@ -201,24 +101,12 @@ export default { stunden(this.form) }, }, - mounted() { - - }, + mounted() {}, methods: { - getTR(m, i) { - //console.log(m + '-' + i) - }, stunden(hour, i, mon) { let n = 0 - //console.log('stunden(form)=>', hour) - //console.log('stunden(i)=>', i) - //console.log('stunden(mon)=>', mon) - - //console.log('this.stundenSumme start=> ', this.stundenSumme) this.stundenSumme = 0 - //console.log('arr.length => ', this.form.length) for (n; n < this.form.length; n++) { - //console.log('>arr[n]=> ', this.form[n]) if (this.form[n] > 0) { this.stundenSumme += parseInt(this.form[n]) } @@ -232,7 +120,6 @@ export default { TextDecoded: '', }) this.index++ - //console.log('this.stundenSumme ende=> ', this.stundenSumme) }, addNewMessage: function () { this.messages.push({ @@ -241,29 +128,20 @@ export default { }) }, deleteNewMessage: function (event) { - //console.log('deleteNewMessage:event) => ', event) - //console.log("deleteNewMessage:this.events.splice(this.event) => ", this.events.splice(this.event)) this.form.splice(event, null) this.messages.splice(index, 1) this.index-- }, submitForm: function (e) { - //console.log(this.messages) - + //console.log('submitForm') this.messages = [{ DaysNumber: '', TextDecoded: '' }] this.submitted = true }, - submitForm2() { - //console.log('submitForm2 TODO') - }, - submitForm3() { - //console.log('submitForm3 TODO') - }, textFocus() { //console.log('textFocus TODO') }, newWorkForm() { - this.formular = ` + this.formular = ` ` - - console.log('newWorkForm TODO') - const myElement = this.$refs.mydiv - myElement.append(this.formular); - this.$compile(myElement); - this.formular = null - - } - } + // console.log('newWorkForm TODO') + const myElement = this.$refs.mydiv + myElement.append(this.formular) + this.$compile(myElement) + this.formular = null + }, + }, } diff --git a/frontend/src/views/KontoOverview/GddSend.vue b/frontend/src/views/KontoOverview/GddSend.vue index 038aa0f6b..7dc36efc7 100644 --- a/frontend/src/views/KontoOverview/GddSend.vue +++ b/frontend/src/views/KontoOverview/GddSend.vue @@ -7,7 +7,7 @@ Bitte überprüfe alle deine Eingaben sehr genau. Du bist alleine Verantwortlich für deine Entscheidungen. Versendete Gradidos können nicht wieder zurück geholt werden. - + QR Code Scanner @@ -230,10 +230,9 @@ export default { const arr = JSON.parse(decodedString) //console.log('qr-email', arr[0].email) //console.log('qr-amount', arr[0].amount) - - this.$store.state.row_form = false - this.$store.state.row_check = true - this.$store.state.row_thx = false + this.form.email = arr[0].email + this.form.amount = arr[0].amount + this.scan = false }, async onSubmit() { //event.preventDefault() diff --git a/frontend/src/views/KontoOverview/GddStatus.vue b/frontend/src/views/KontoOverview/GddStatus.vue index b22c273fc..53972ddd5 100644 --- a/frontend/src/views/KontoOverview/GddStatus.vue +++ b/frontend/src/views/KontoOverview/GddStatus.vue @@ -2,12 +2,22 @@
- + {{ $n($store.state.user.balance) }} GDD - + {{ $n($store.state.user.balance_gdt) }} GDT diff --git a/frontend/src/views/Pages/UserProfile/EditProfileForm.vue b/frontend/src/views/Pages/UserProfile/EditProfileForm.vue index e8981f8e8..dbf9a3064 100755 --- a/frontend/src/views/Pages/UserProfile/EditProfileForm.vue +++ b/frontend/src/views/Pages/UserProfile/EditProfileForm.vue @@ -1,10 +1,5 @@