From d4adf6f84dea2cd662e221a7d61d5972b9eb6f0a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 15 Oct 2017 18:54:27 +0200 Subject: [PATCH] Fix minor bugs for full inspections --- Admin/Uninstall.php | 1 + Admin/Update.php | 4 +- Models/CreditorAccount.php | 4 +- Models/DebitorAccount.php | 4 +- Models/temp/Account.php | 97 ----------------------- Models/temp/AccountValue.php | 58 -------------- Models/temp/Balance.php | 5 -- Models/temp/CostCenter.php | 0 Models/temp/Distribution.php | 55 ------------- Models/temp/DistributionKey.php | 41 ---------- Models/temp/Element.php | 74 ----------------- Models/temp/KeyCollection.php | 32 -------- Models/temp/PL.php | 67 ---------------- Models/temp/Position.php | 8 -- Models/temp/StructureElementInterface.php | 7 -- 15 files changed, 8 insertions(+), 449 deletions(-) delete mode 100644 Models/temp/Account.php delete mode 100644 Models/temp/AccountValue.php delete mode 100644 Models/temp/Balance.php delete mode 100644 Models/temp/CostCenter.php delete mode 100644 Models/temp/Distribution.php delete mode 100644 Models/temp/DistributionKey.php delete mode 100644 Models/temp/Element.php delete mode 100644 Models/temp/KeyCollection.php delete mode 100644 Models/temp/PL.php delete mode 100644 Models/temp/Position.php delete mode 100644 Models/temp/StructureElementInterface.php diff --git a/Admin/Uninstall.php b/Admin/Uninstall.php index 1e40db3..8eed9c8 100644 --- a/Admin/Uninstall.php +++ b/Admin/Uninstall.php @@ -17,6 +17,7 @@ namespace Modules\Accounting\Admin; use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\DataStorage\Database\Schema\Builder; use phpOMS\Module\UninstallAbstract; +use phpOMS\Module\InfoManager; /** * Navigation class. diff --git a/Admin/Update.php b/Admin/Update.php index 28e05ec..a827b58 100644 --- a/Admin/Update.php +++ b/Admin/Update.php @@ -17,6 +17,8 @@ namespace Modules\Accounting\Admin; use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\Module\UpdateAbstract; use phpOMS\System\File\Directory; +use phpOMS\Module\InfoManager; + /** * Navigation class. @@ -33,7 +35,7 @@ class Update extends UpdateAbstract /** * {@inheritdoc} */ - public static function update(DatabasePool $dbPool, array $info) + public static function update(DatabasePool $dbPool, InfoManager $info) { Directory::deletePath(__DIR__ . '/Update'); mkdir('Update'); diff --git a/Models/CreditorAccount.php b/Models/CreditorAccount.php index fbbf354..b01ba85 100644 --- a/Models/CreditorAccount.php +++ b/Models/CreditorAccount.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Modules\Accounting\Models; -use Modules\Accounting\Models\PersonalAccount; +use Modules\Accounting\Models\PersonalAccountAbstract; /** * Creditor account class. @@ -25,7 +25,7 @@ use Modules\Accounting\Models\PersonalAccount; * @link http://orange-management.com * @since 1.0.0 */ -abstract class CreditorAccount extends PersonalAccount +abstract class CreditorAccount extends PersonalAccountAbstract { /** diff --git a/Models/DebitorAccount.php b/Models/DebitorAccount.php index c88a896..d183c1b 100644 --- a/Models/DebitorAccount.php +++ b/Models/DebitorAccount.php @@ -14,7 +14,7 @@ declare(strict_types=1); namespace Modules\Accounting\Models; -use Modules\Accounting\Models\PersonalAccount; +use Modules\Accounting\Models\PersonalAccountAbstract; /** * DebitorAccount class. @@ -25,7 +25,7 @@ use Modules\Accounting\Models\PersonalAccount; * @link http://orange-management.com * @since 1.0.0 */ -abstract class DebitorAccount extends PersonalAccount +abstract class DebitorAccount extends PersonalAccountAbstract { /** diff --git a/Models/temp/Account.php b/Models/temp/Account.php deleted file mode 100644 index e2b3f86..0000000 --- a/Models/temp/Account.php +++ /dev/null @@ -1,97 +0,0 @@ -account = $account; - $this->name = $name; - $this->values = []; - - if(!empty($values)) { - $this->isOutdated = true; - } - } - - public function getId() - { - return $this->id; - } - - public function getName() : string - { - return $this->name; - } - - public function addValue(AccountValue $value) - { - $this->values[] = $value; - $this->isOutdated = true; - } - - public function getValues() : array - { - return $this->values; - } - - public function getTotal() : Money - { - if($this->isOutdated) { - $this->parseValues(); - } - - $total = new Money(0); - - foreach($this->total as $costCenter) { - $total->add($costCenter); - } - - return $total; - } - - public function getTotalCostCenter(int $costCenter) : Money - { - if($this->isOutdated) { - $this->parseValues(); - } - - return $this->total[$costCenter] ?? new Money(0); - } - - private function parseValues() : array - { - $this->total = []; - foreach($this->values as $value) { - if(!isset($this->total[$value->getCostCenter()])) { - $this->total[$value->getCostCenter()] = new Money(0); - } - - $this->total[$value->getCostCenter()]->add($value->getValue()); - } - - $this->isOutdated = false; - - return $this->total; - } -} -*/ \ No newline at end of file diff --git a/Models/temp/AccountValue.php b/Models/temp/AccountValue.php deleted file mode 100644 index f0aaecc..0000000 --- a/Models/temp/AccountValue.php +++ /dev/null @@ -1,58 +0,0 @@ -account = $account; - $this->costCenter = $costCenter; - $this->date = $date; - $this->value = $value; - } - - public function getAccount() - { - return $this->account; - } - - public function getCostCenter() - { - return $this->costCenter; - } - - public function getDate() - { - return $this->date; - } - - public function getValue() : Money - { - return $this->value; - } - - public static function group($values) : array - { - $accounts = []; - - foreach($values as $value) { - if(!isset($accounts[$value->getAccount()])) { - $accounts[$value->getAccount()] = []; - } - - if(!isset($accounts[$value->getAccount()][$value->getCostCenter()])) { - $accounts[$value->getAccount()][$value->getCostCenter()] = []; - } - - $accounts[$value->getAccount()][$value->getCostCenter()] = $value; - } - - return $accounts; - } -} diff --git a/Models/temp/Balance.php b/Models/temp/Balance.php deleted file mode 100644 index 0932325..0000000 --- a/Models/temp/Balance.php +++ /dev/null @@ -1,5 +0,0 @@ -normalizeKey($key, $from, $to); - - foreach($keys as $key) { - if(!isset($this->keyCollections[$key->getFromAccount()])) { - $this->keyCollections[$key->getFromAccount()] = new KeyCollection(account here); - } - - $this->keyCollections[$key->getFromAccount()]->addKey($key); - } - } - - public function distribute($from, $to) - { - $accounts = $from->getAccountValues(); - $values = []; - - foreach($accounts as $account => $accountValues) { - $values = array_merge($values, $this->keyCollections[$account]->distribute($accountValues)); - } - - $values = AccountValue::group($values); - $to->setAccountValues($values); - - return $to; - } - - private function normalizeKey(DistributionKey $key, $from, $to) : array - { - $accountsSource = $from->getAccountsById($key->getFromAccount()); - $accountDestination = $to->getAccountsById($key->getToAccount()); - $keys = []; - - foreach($accountsSource as $accountSource) { - foreach($key as $rawKey) { - $keys[$accountSource->getId()] = new DistributionKey( - $accountSource->getId(), - $rawKey->getFromCostCenters(), - $accountDestination, - $rawKey->getToCostCenters() - ); - } - } - - return $keys; - } -} diff --git a/Models/temp/DistributionKey.php b/Models/temp/DistributionKey.php deleted file mode 100644 index f8d2dc1..0000000 --- a/Models/temp/DistributionKey.php +++ /dev/null @@ -1,41 +0,0 @@ -fromAccount = $fromAC; - $this->fromCostCenter = $fromCC; - $this->toAccount = $toAC; - $this->toCostCenter = $toCC; - } - - public function getFromAccount() : int - { - return $this->fromAccount; - } - - public function getFromCostCenter() : int - { - return $this->fromCostCenter; - } - - public function distribute(AccountValue $value) : AccountValue - { - if($value->getAccount() !== $this->fromAccount) { - throw new \Exception('Bad account.'); - } - - if($value->getCostCenter() !== $this->fromCostCenter) { - throw new \Exception('Bad costcenter.'); - } - - return new AccountValue($this->toAccount, $this->toCostCenter, $value->getDate(), $value->getValue() * $this->percentage); - } -} diff --git a/Models/temp/Element.php b/Models/temp/Element.php deleted file mode 100644 index 03f74a2..0000000 --- a/Models/temp/Element.php +++ /dev/null @@ -1,74 +0,0 @@ -id; - } - - public function getName() : string - { - return $this->name; - } - - public function getValues() : array - { - $values = []; - foreach($this->children as $child) { - if($child instanceof Account) { - $values[$child->getAccount()] = $child->getValues(); - } else { - $values += $child->getValues(); - } - } - - return $values; - } - - public function getAccounts() : array - { - $accounts = []; - foreach($this->children as $child) { - if($child instanceof Account) { - $accounts[$child->getAccount()] = $child->getAccount(); - } else { - $accounts += $child->getAccounts(); - } - } - - return $accounts; - } - - public function getTotal() - { - $total = new Money(0); - foreach($this->children as $child) { - $total->add($child->getTotal()); - } - - return $total; - } - - public function getTotalCostCenter(int $costCenter) - { - $total = new Money(0); - foreach($this->children as $child) { - $total->add($child->getTotalCostCenter($costCenter)); - } - - return $total; - } - - public function getChildren() : array - { - return $this->children; - } -} diff --git a/Models/temp/KeyCollection.php b/Models/temp/KeyCollection.php deleted file mode 100644 index 0406352..0000000 --- a/Models/temp/KeyCollection.php +++ /dev/null @@ -1,32 +0,0 @@ -fromAccount = $account; - $this->distributionKeys = $distributionKeys; - } - - public function getAccount() : int - { - return $this->fromAccount; - } - - public function addKey(DistributionKey $key) - { - $this->distributionKeys[$key->getFromCostCenter()] = $key; - } - - public function distribute(array $accountValues) : array - { - $values = []; - foreach($accountValues as $value) { - $values[] = $this->distributionKeys[$value->getCostCenter()]->distribute($value); - } - - return $values; - } -} diff --git a/Models/temp/PL.php b/Models/temp/PL.php deleted file mode 100644 index 2b42732..0000000 --- a/Models/temp/PL.php +++ /dev/null @@ -1,67 +0,0 @@ -= $position) { - $this->structure = array_merge(array_slice($this->structure, 0, $position - 1, false), [$element], array_slice($this->structure, $position-1, count($this->structure) - 1, false)); - } else { - $this->structure[] = $element; - } - } - - public function getStructure() : array - { - return $this->structure; - } - - public function getAccountValues() : array - { - $values = []; - foreach($this->structure as $element) { - $values += $element->getValues(); - } - } - - public function getAccountsById(int $id) : array - { - $accounts = $this->get($id); - - if(!isset($accounts)) { - return []; - } - - if($accounts instanceof Account) { - return [$accounts]; - } - - return $accounts->getAccounts(); - } - - public function get(int $id) - { - if(isset($this->structure[$id])) { - return $this->structure[$id]; - } - - $found = null; - foreach($this->structure as $element) { - $found = $element->get($id); - - if(isset($found)) { - return $found; - } - } - - return $found; - } - - public function getTotal(int $id, int $costCenter = null) : Money - { - return isset($costCenter) ? $this->structure[$id]->getTotalCostCenter($costCenter) : $this->structure[$id]->getTotal(); - } -} diff --git a/Models/temp/Position.php b/Models/temp/Position.php deleted file mode 100644 index 36c2d04..0000000 --- a/Models/temp/Position.php +++ /dev/null @@ -1,8 +0,0 @@ -