int64 shardNum = 1;
+ */
+ private $shardNum = 0;
+ /**
+ * The realm number (nonnegative)
+ *
+ * Generated from protobuf field int64 realmNum = 2;
+ */
+ private $realmNum = 0;
+ /**
+ * Unique topic identifier within a realm (nonnegative).
+ *
+ * Generated from protobuf field int64 topicNum = 3;
+ */
+ private $topicNum = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param array $data {
+ * Optional. Data for populating the Message object.
+ *
+ * @type int|string $shardNum
+ * The shard number (nonnegative)
+ * @type int|string $realmNum
+ * The realm number (nonnegative)
+ * @type int|string $topicNum
+ * Unique topic identifier within a realm (nonnegative).
+ * }
+ */
+ public function __construct($data = NULL) {
+ \GPBMetadata\Gradido\BasicTypes::initOnce();
+ parent::__construct($data);
+ }
+
+ /**
+ * The shard number (nonnegative)
+ *
+ * Generated from protobuf field int64 shardNum = 1;
+ * @return int|string
+ */
+ public function getShardNum()
+ {
+ return $this->shardNum;
+ }
+
+ /**
+ * The shard number (nonnegative)
+ *
+ * Generated from protobuf field int64 shardNum = 1;
+ * @param int|string $var
+ * @return $this
+ */
+ public function setShardNum($var)
+ {
+ GPBUtil::checkInt64($var);
+ $this->shardNum = $var;
+
+ return $this;
+ }
+
+ /**
+ * The realm number (nonnegative)
+ *
+ * Generated from protobuf field int64 realmNum = 2;
+ * @return int|string
+ */
+ public function getRealmNum()
+ {
+ return $this->realmNum;
+ }
+
+ /**
+ * The realm number (nonnegative)
+ *
+ * Generated from protobuf field int64 realmNum = 2;
+ * @param int|string $var
+ * @return $this
+ */
+ public function setRealmNum($var)
+ {
+ GPBUtil::checkInt64($var);
+ $this->realmNum = $var;
+
+ return $this;
+ }
+
+ /**
+ * Unique topic identifier within a realm (nonnegative).
+ *
+ * Generated from protobuf field int64 topicNum = 3;
+ * @return int|string
+ */
+ public function getTopicNum()
+ {
+ return $this->topicNum;
+ }
+
+ /**
+ * Unique topic identifier within a realm (nonnegative).
+ *
+ * Generated from protobuf field int64 topicNum = 3;
+ * @param int|string $var
+ * @return $this
+ */
+ public function setTopicNum($var)
+ {
+ GPBUtil::checkInt64($var);
+ $this->topicNum = $var;
+
+ return $this;
+ }
+
+}
+
diff --git a/community_server/src/Model/Messages/Proto/Gradido/ManageNodeBody.php b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeBody.php
new file mode 100644
index 000000000..eed599868
--- /dev/null
+++ b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeBody.php
@@ -0,0 +1,90 @@
+proto.gradido.ManageNodeBody
+ */
+class ManageNodeBody extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * Generated from protobuf field uint64 version_number = 1;
+ */
+ private $version_number = 0;
+ protected $data;
+
+ /**
+ * Constructor.
+ *
+ * @param array $data {
+ * Optional. Data for populating the Message object.
+ *
+ * @type int|string $version_number
+ * @type \Proto\Gradido\ManageNodeGroupAdd $group_add
+ * }
+ */
+ public function __construct($data = NULL) {
+ \GPBMetadata\Gradido\ManageNodeBody::initOnce();
+ parent::__construct($data);
+ }
+
+ /**
+ * Generated from protobuf field uint64 version_number = 1;
+ * @return int|string
+ */
+ public function getVersionNumber()
+ {
+ return $this->version_number;
+ }
+
+ /**
+ * Generated from protobuf field uint64 version_number = 1;
+ * @param int|string $var
+ * @return $this
+ */
+ public function setVersionNumber($var)
+ {
+ GPBUtil::checkUint64($var);
+ $this->version_number = $var;
+
+ return $this;
+ }
+
+ /**
+ * Generated from protobuf field .proto.gradido.ManageNodeGroupAdd group_add = 3;
+ * @return \Proto\Gradido\ManageNodeGroupAdd
+ */
+ public function getGroupAdd()
+ {
+ return $this->readOneof(3);
+ }
+
+ /**
+ * Generated from protobuf field .proto.gradido.ManageNodeGroupAdd group_add = 3;
+ * @param \Proto\Gradido\ManageNodeGroupAdd $var
+ * @return $this
+ */
+ public function setGroupAdd($var)
+ {
+ GPBUtil::checkMessage($var, \Proto\Gradido\ManageNodeGroupAdd::class);
+ $this->writeOneof(3, $var);
+
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getData()
+ {
+ return $this->whichOneof("data");
+ }
+
+}
+
diff --git a/community_server/src/Model/Messages/Proto/Gradido/ManageNodeGroupAdd.php b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeGroupAdd.php
new file mode 100644
index 000000000..777075066
--- /dev/null
+++ b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeGroupAdd.php
@@ -0,0 +1,119 @@
+proto.gradido.ManageNodeGroupAdd
+ */
+class ManageNodeGroupAdd extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * Generated from protobuf field string group_name = 1;
+ */
+ private $group_name = '';
+ /**
+ * Generated from protobuf field string group_alias = 2;
+ */
+ private $group_alias = '';
+ /**
+ *string parent_group_alias = 4;
+ *
+ * Generated from protobuf field .proto.gradido.HederaID hedera_topic_id = 3;
+ */
+ private $hedera_topic_id = null;
+
+ /**
+ * Constructor.
+ *
+ * @param array $data {
+ * Optional. Data for populating the Message object.
+ *
+ * @type string $group_name
+ * @type string $group_alias
+ * @type \Proto\Gradido\HederaID $hedera_topic_id
+ * string parent_group_alias = 4;
+ * }
+ */
+ public function __construct($data = NULL) {
+ \GPBMetadata\Gradido\ManageNodeGroupAdd::initOnce();
+ parent::__construct($data);
+ }
+
+ /**
+ * Generated from protobuf field string group_name = 1;
+ * @return string
+ */
+ public function getGroupName()
+ {
+ return $this->group_name;
+ }
+
+ /**
+ * Generated from protobuf field string group_name = 1;
+ * @param string $var
+ * @return $this
+ */
+ public function setGroupName($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->group_name = $var;
+
+ return $this;
+ }
+
+ /**
+ * Generated from protobuf field string group_alias = 2;
+ * @return string
+ */
+ public function getGroupAlias()
+ {
+ return $this->group_alias;
+ }
+
+ /**
+ * Generated from protobuf field string group_alias = 2;
+ * @param string $var
+ * @return $this
+ */
+ public function setGroupAlias($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->group_alias = $var;
+
+ return $this;
+ }
+
+ /**
+ *string parent_group_alias = 4;
+ *
+ * Generated from protobuf field .proto.gradido.HederaID hedera_topic_id = 3;
+ * @return \Proto\Gradido\HederaID
+ */
+ public function getHederaTopicId()
+ {
+ return $this->hedera_topic_id;
+ }
+
+ /**
+ *string parent_group_alias = 4;
+ *
+ * Generated from protobuf field .proto.gradido.HederaID hedera_topic_id = 3;
+ * @param \Proto\Gradido\HederaID $var
+ * @return $this
+ */
+ public function setHederaTopicId($var)
+ {
+ GPBUtil::checkMessage($var, \Proto\Gradido\HederaID::class);
+ $this->hedera_topic_id = $var;
+
+ return $this;
+ }
+
+}
+
diff --git a/community_server/src/Model/Messages/Proto/Gradido/ManageNodeRequest.php b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeRequest.php
new file mode 100644
index 000000000..6699b98c5
--- /dev/null
+++ b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeRequest.php
@@ -0,0 +1,92 @@
+proto.gradido.ManageNodeRequest
+ */
+class ManageNodeRequest extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * Generated from protobuf field .proto.gradido.SignatureMap sig_map = 1;
+ */
+ private $sig_map = null;
+ /**
+ * ManageNodeBody
+ *
+ * Generated from protobuf field bytes body_bytes = 2;
+ */
+ private $body_bytes = '';
+
+ /**
+ * Constructor.
+ *
+ * @param array $data {
+ * Optional. Data for populating the Message object.
+ *
+ * @type \Proto\Gradido\SignatureMap $sig_map
+ * @type string $body_bytes
+ * ManageNodeBody
+ * }
+ */
+ public function __construct($data = NULL) {
+ \GPBMetadata\Gradido\ManageNodeRequest::initOnce();
+ parent::__construct($data);
+ }
+
+ /**
+ * Generated from protobuf field .proto.gradido.SignatureMap sig_map = 1;
+ * @return \Proto\Gradido\SignatureMap
+ */
+ public function getSigMap()
+ {
+ return $this->sig_map;
+ }
+
+ /**
+ * Generated from protobuf field .proto.gradido.SignatureMap sig_map = 1;
+ * @param \Proto\Gradido\SignatureMap $var
+ * @return $this
+ */
+ public function setSigMap($var)
+ {
+ GPBUtil::checkMessage($var, \Proto\Gradido\SignatureMap::class);
+ $this->sig_map = $var;
+
+ return $this;
+ }
+
+ /**
+ * ManageNodeBody
+ *
+ * Generated from protobuf field bytes body_bytes = 2;
+ * @return string
+ */
+ public function getBodyBytes()
+ {
+ return $this->body_bytes;
+ }
+
+ /**
+ * ManageNodeBody
+ *
+ * Generated from protobuf field bytes body_bytes = 2;
+ * @param string $var
+ * @return $this
+ */
+ public function setBodyBytes($var)
+ {
+ GPBUtil::checkString($var, False);
+ $this->body_bytes = $var;
+
+ return $this;
+ }
+
+}
+
diff --git a/community_server/src/Model/Messages/Proto/Gradido/ManageNodeResponse.php b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeResponse.php
new file mode 100644
index 000000000..c7a4f80a5
--- /dev/null
+++ b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeResponse.php
@@ -0,0 +1,85 @@
+proto.gradido.ManageNodeResponse
+ */
+class ManageNodeResponse extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * Generated from protobuf field bool success = 1;
+ */
+ private $success = false;
+ /**
+ * Generated from protobuf field .proto.gradido.ManageNodeResponse.ErrorCode error = 2;
+ */
+ private $error = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param array $data {
+ * Optional. Data for populating the Message object.
+ *
+ * @type bool $success
+ * @type int $error
+ * }
+ */
+ public function __construct($data = NULL) {
+ \GPBMetadata\Gradido\ManageNodeRequest::initOnce();
+ parent::__construct($data);
+ }
+
+ /**
+ * Generated from protobuf field bool success = 1;
+ * @return bool
+ */
+ public function getSuccess()
+ {
+ return $this->success;
+ }
+
+ /**
+ * Generated from protobuf field bool success = 1;
+ * @param bool $var
+ * @return $this
+ */
+ public function setSuccess($var)
+ {
+ GPBUtil::checkBool($var);
+ $this->success = $var;
+
+ return $this;
+ }
+
+ /**
+ * Generated from protobuf field .proto.gradido.ManageNodeResponse.ErrorCode error = 2;
+ * @return int
+ */
+ public function getError()
+ {
+ return $this->error;
+ }
+
+ /**
+ * Generated from protobuf field .proto.gradido.ManageNodeResponse.ErrorCode error = 2;
+ * @param int $var
+ * @return $this
+ */
+ public function setError($var)
+ {
+ GPBUtil::checkEnum($var, \Proto\Gradido\ManageNodeResponse_ErrorCode::class);
+ $this->error = $var;
+
+ return $this;
+ }
+
+}
+
diff --git a/community_server/src/Model/Messages/Proto/Gradido/ManageNodeResponse/ErrorCode.php b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeResponse/ErrorCode.php
new file mode 100644
index 000000000..ab352829e
--- /dev/null
+++ b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeResponse/ErrorCode.php
@@ -0,0 +1,61 @@
+proto.gradido.ManageNodeResponse.ErrorCode
+ */
+class ErrorCode
+{
+ /**
+ * Generated from protobuf enum INVALID_BODY = 0;
+ */
+ const INVALID_BODY = 0;
+ /**
+ * Generated from protobuf enum INVALID_SIGNATURE = 1;
+ */
+ const INVALID_SIGNATURE = 1;
+ /**
+ * Generated from protobuf enum SIGNER_NOT_KNOWN = 2;
+ */
+ const SIGNER_NOT_KNOWN = 2;
+ /**
+ * Generated from protobuf enum GROUP_ALIAS_ALREADY_EXIST = 3;
+ */
+ const GROUP_ALIAS_ALREADY_EXIST = 3;
+
+ private static $valueToName = [
+ self::INVALID_BODY => 'INVALID_BODY',
+ self::INVALID_SIGNATURE => 'INVALID_SIGNATURE',
+ self::SIGNER_NOT_KNOWN => 'SIGNER_NOT_KNOWN',
+ self::GROUP_ALIAS_ALREADY_EXIST => 'GROUP_ALIAS_ALREADY_EXIST',
+ ];
+
+ public static function name($value)
+ {
+ if (!isset(self::$valueToName[$value])) {
+ throw new UnexpectedValueException(sprintf(
+ 'Enum %s has no name defined for value %s', __CLASS__, $value));
+ }
+ return self::$valueToName[$value];
+ }
+
+
+ public static function value($name)
+ {
+ $const = __CLASS__ . '::' . strtoupper($name);
+ if (!defined($const)) {
+ throw new UnexpectedValueException(sprintf(
+ 'Enum %s has no value defined for name %s', __CLASS__, $name));
+ }
+ return constant($const);
+ }
+}
+
+// Adding a class alias for backwards compatibility with the previous class name.
+class_alias(ErrorCode::class, \Proto\Gradido\ManageNodeResponse_ErrorCode::class);
+
diff --git a/community_server/src/Model/Messages/Proto/Gradido/ManageNodeResponse_ErrorCode.php b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeResponse_ErrorCode.php
new file mode 100644
index 000000000..8a7db7515
--- /dev/null
+++ b/community_server/src/Model/Messages/Proto/Gradido/ManageNodeResponse_ErrorCode.php
@@ -0,0 +1,16 @@
+newEntity();
- $entity->state_user_id = $previousStateBalance->state_user_id;
- $newDate = $previousStateBalance->record_date;
- $newDate->day(1);
- if($newDate->month <= 12) {
- $newDate->month($newDate->month + 1);
- } else {
- $newDate->month(1);
- $newDate->year($newDate->year + 1);
- }
- $entity->record_date = $newDate;
- $entity->amount = $previousStateBalance->partDecay($newDate);
- if($this->save($entity)) {
- return $entity;
- }
- return ['state' => 'error', 'msg' => 'couldn\'t save', 'details' => $entity->getErrors()];
- }
+
public function sortTransactions($a, $b)
{
@@ -113,240 +91,178 @@ class StateBalancesTable extends Table
}
return ($a['date'] > $b['date']) ? -1 : 1;
}
- /*
- * calculate balance at end of month
- * work only if state balance at begin of month exist
- * use transaction_send_coins and transaction_creations
- */
- public function updateLastStateBalanceOfMonth($month, $year, $state_user_id)
+
+
+ public function updateBalances($stateUserId)
{
- $first_of_month = new Time("$year-$month-01 00:00");
- $last_of_month = new Time($first_of_month);
- $last_of_month->addMonth(1);
- $last_of_month->subSecond(1);
- $query = $this->find('all')
- ->where(['AND' => [
- 'state_user_id' => $state_user_id,
- 'record_date >=' => $first_of_month,
- 'record_date <=' => $last_of_month
- ]])
- ->order(['record_date' => 'ASC']);
- if($query->isEmpty()) {
- return [
- 'state' => 'error',
- 'msg' => 'no state balance in this month found',
- 'details' => [
- 'month' => $month,
- 'year' => $year,
- 'state_user_id' => $state_user_id
- ]
- ];
- }
- // get transactions from this month
- $balance_changes = [];
- $transactionCreationsTable = TableRegistry::getTableLocator()->get('TransactionCreations');
- $transactionTransfersTable = TableRegistry::getTableLocator()->get('TransactionSendCoins');
- $relevant_creations = $transactionCreationsTable
- ->find('all')
- ->where(['AND' => [
- 'state_user_id' => $state_user_id,
- 'target_date >=' => $first_of_month,
- 'target_date <=' => $last_of_month
- ]])->contain(false);
- foreach($relevant_creations as $creation) {
- $balance_changes[] = ['amount' => $creation->amount, 'date' => $creation->target_date];
- }
- $relevant_transfers = $transactionTransfersTable
- ->find('all')
- ->where(['AND' => [
- 'OR' => [
- 'state_user_id' => $state_user_id,
- 'receiver_user_id' => $state_user_id
- ],
- 'transaction.received >= ' => $first_of_month,
- 'transaction.received <=' => $last_of_month
- ]])->contain(['Transactions']);
- debug($relevant_transfers);
- foreach($relevant_transfers as $transfer) {
- $amount = $transfer->amount;
- // if it is a send transaction, negate the value
- if($transfer->state_user_id == $state_user_id) {
- $amount *= -1.0;
- }
- $balance_changes[] = ['amount' => $amount, 'date' => $transfer->transaction->received];
- }
- uasort($balance_changes, array($this, 'sortTransactions'));
- $current_state_balance = null;
- if($query->count() == 1) {
- $current_state_balance = $this->newEntity();
- $current_state_balance->amount = $query->first()->amount;
- $current_state_balance->state_user_id = $state_user_id;
- $current_state_balance->record_date = $query->first()->record_date;
- } else if($query->count() == 2) {
- $array = $query->toArray();
- $current_state_balance = $array[1];
- } else {
- throw new Exception('Should\'n occure, never');
+ $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->find('all')->where(['state_user_id' => $stateUserId]);
+ $state_user_transactions = $stateUserTransactionsTable
+ ->find()
+ ->where(['state_user_id' => $stateUserId])
+ ->order(['balance_date ASC'])
+ //->contain(false);
+ ;
+
+ if(!$state_user_transactions || !$state_user_transactions->count()) {
+ return true;
}
- foreach($balance_changes as $change) {
- $current_state_balance->amount = $current_state_balance->getDecay($change['date']);
- $current_state_balance->amount += $change['amount'];
- $current_state_balance->record_date = $change['date'];
+ // 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;
+ $recalculate_state_user_transactions_balance = true;
}
- if(!$this->save($current_state_balance)) {
- return ['state' => 'error', 'msg' => 'couldn\'t save', 'details' => $current_state_balance->getErrors()];
+ if($state_balances->count() > 1) {
+ $clear_state_balance = true;
+ $create_state_balance = true;
+ $recalculate_state_user_transactions_balance = true;
}
- return $current_state_balance;
- }
-
- /*
- * getting start balance for month
- * create and create all missing state_balances before if not exist
- * in while loop
- */
-
- public function chooseForMonthAndUser($month, $year, $state_user_id)
- {
- $first_of_month = new Time("$year-$month-01 00:00");
- $last_of_month = new Time($first_of_month);
- $last_of_month->addMonth(1);
- $last_of_month->subSecond(1);
- //echo "first of month: " . $first_of_month->i18nFormat() . ", last of month: " . $last_of_month->i18nFormat() . "