mirror of
https://github.com/Karaka-Management/oms-Accounting.git
synced 2026-02-13 11:08:41 +00:00
Adding temporary pl/distribution draft
This commit is contained in:
parent
abaa447a7b
commit
1831dc83c6
96
Models/temp/Account.php
Normal file
96
Models/temp/Account.php
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Account implements StructureElementInterface {
|
||||||
|
private $id = 0;
|
||||||
|
private $name = '';
|
||||||
|
private $account = 0;
|
||||||
|
private $values = [];
|
||||||
|
private $total = [];
|
||||||
|
|
||||||
|
private $type = 0; // GUV/Bilanz
|
||||||
|
private $assigned = 0; // Ertrags/Aufwandskonto | active/passive
|
||||||
|
private $currency = 0; // Currency type
|
||||||
|
private $tax = 0;
|
||||||
|
private $hasOP = false;
|
||||||
|
private $activity = true;
|
||||||
|
private $hasCostCenter = true;
|
||||||
|
private $hasCostObject = true;
|
||||||
|
private $defaultCostCenter = 0;
|
||||||
|
private $isFixedCostCenter = false;
|
||||||
|
private $isVirtual = false;
|
||||||
|
private $isCashback = false;
|
||||||
|
|
||||||
|
private $isOutdated = false;
|
||||||
|
|
||||||
|
public function __construct(int $account, string $name, array $values = [])
|
||||||
|
{
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
58
Models/temp/AccountValue.php
Normal file
58
Models/temp/AccountValue.php
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class AccountValue {
|
||||||
|
private $account = 0;
|
||||||
|
private $costCenter = 0;
|
||||||
|
private $date = null;
|
||||||
|
private $value = null;
|
||||||
|
private $contraAccount = 0;
|
||||||
|
private $text = '';
|
||||||
|
private $postingId = 0;
|
||||||
|
|
||||||
|
public function __construct($account, $costCenter, \DateTime $date, Money $value)
|
||||||
|
{
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
5
Models/temp/Balance.php
Normal file
5
Models/temp/Balance.php
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Balance {
|
||||||
|
|
||||||
|
}
|
||||||
0
Models/temp/CostCenter.php
Normal file
0
Models/temp/CostCenter.php
Normal file
55
Models/temp/Distribution.php
Normal file
55
Models/temp/Distribution.php
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Distribution {
|
||||||
|
private $keyCollections = [];
|
||||||
|
|
||||||
|
public function __construct() {}
|
||||||
|
|
||||||
|
public function addKey(DistributionKey $key, $from, $to)
|
||||||
|
{
|
||||||
|
$keys = $this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
41
Models/temp/DistributionKey.php
Normal file
41
Models/temp/DistributionKey.php
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class DistributionKey {
|
||||||
|
private $fromAccount = 0;
|
||||||
|
private $fromCostCenter = 0;
|
||||||
|
|
||||||
|
private $toAccount = 0;
|
||||||
|
private $toCostCenter = 0;
|
||||||
|
|
||||||
|
private $percentage = 1.0;
|
||||||
|
|
||||||
|
public function __construct(int $fromAC, int $fromCC, int $toAC, int $toCC) {
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
74
Models/temp/Element.php
Normal file
74
Models/temp/Element.php
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Element extends StructureElementAbstract {
|
||||||
|
private $id = 0;
|
||||||
|
private $name = '';
|
||||||
|
private $type = 0;
|
||||||
|
|
||||||
|
private $action = '';
|
||||||
|
|
||||||
|
private $children = [];
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
32
Models/temp/KeyCollection.php
Normal file
32
Models/temp/KeyCollection.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class KeyCollection {
|
||||||
|
private $fromAccount = 0;
|
||||||
|
|
||||||
|
private $distributionKeys = [];
|
||||||
|
|
||||||
|
public function __construct(int $account, array $distributionKeys = []) {
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
67
Models/temp/PL.php
Normal file
67
Models/temp/PL.php
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class PL {
|
||||||
|
private $name = '';
|
||||||
|
|
||||||
|
private $structure = [];
|
||||||
|
|
||||||
|
public function addStructureElement(StructureElementInterface $element, int $position = -1)
|
||||||
|
{
|
||||||
|
if(count($structure) >= $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();
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Models/temp/Position.php
Normal file
8
Models/temp/Position.php
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Position {
|
||||||
|
private $accounts = [];
|
||||||
|
|
||||||
|
private $color = [];
|
||||||
|
|
||||||
|
}
|
||||||
7
Models/temp/StructureElementInterface.php
Normal file
7
Models/temp/StructureElementInterface.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
interface StructureElementInterface {
|
||||||
|
public function getId() : int;
|
||||||
|
public function getName() : string;
|
||||||
|
public function getValues() : array;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user