Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61eb2404a2
|
||
|
|
e199dfccc7
|
||
|
|
1d0a2b09d5
|
||
|
|
1886257b63
|
||
|
|
eda1415e86
|
||
|
|
4e9c7f8c3c
|
||
|
|
eebf4aff00
|
||
|
|
6dae33507f
|
||
|
|
96d5aa2219
|
||
|
|
6c326b89e2
|
||
|
|
6c821d41b4
|
||
|
|
ade02f4736
|
||
|
|
bb5b510315
|
||
|
|
1267cb3d95
|
||
|
|
c7641b85e7
|
||
|
|
ee4b8e9d65
|
||
|
|
58d4f982e9
|
||
|
|
ad06cfaa58
|
||
|
|
aa2e0e9b4a
|
||
|
|
d1c926541a
|
||
|
|
9929e00a3f
|
||
|
|
bf415a2a46
|
||
|
|
c0bfa5b334
|
||
|
|
e122248a97
|
||
|
|
d2bb1d4936
|
No files matched your search
+1
-1
@@ -10,7 +10,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"esoko/soko-web": "0.12.1",
|
||||
"esoko/soko-web": "0.13",
|
||||
"firebase/php-jwt": "^6.4"
|
||||
},
|
||||
"require-dev": {
|
||||
|
||||
Generated
+4
-4
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "a6f50b31b14027eec094629b13cc4097",
|
||||
"content-hash": "707bad5bd796500db300c5384f2ce378",
|
||||
"packages": [
|
||||
{
|
||||
"name": "cocur/slugify",
|
||||
@@ -82,11 +82,11 @@
|
||||
},
|
||||
{
|
||||
"name": "esoko/soko-web",
|
||||
"version": "v0.12.1",
|
||||
"version": "v0.13",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://git.esoko.eu/esoko/soko-web.git",
|
||||
"reference": "bda12177ebc201f04fdad5493b93039676a983ca"
|
||||
"reference": "4283bc9bb15d17914393b4ba3463d83717487c53"
|
||||
},
|
||||
"require": {
|
||||
"cocur/slugify": "^4.3",
|
||||
@@ -108,7 +108,7 @@
|
||||
"GNU GPL 3.0"
|
||||
],
|
||||
"description": "Lightweight web framework",
|
||||
"time": "2023-05-28T13:56:14+00:00"
|
||||
"time": "2023-06-17T12:32:56+00:00"
|
||||
},
|
||||
{
|
||||
"name": "firebase/php-jwt",
|
||||
|
||||
@@ -11,8 +11,3 @@ CREATE TABLE `events` (
|
||||
UNIQUE KEY `slug` (`slug`),
|
||||
CONSTRAINT `events_community_id` FOREIGN KEY (`community_id`) REFERENCES `communities` (`id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
||||
|
||||
ALTER TABLE `transactions`
|
||||
ADD `event_id` int(10) unsigned NULL,
|
||||
ADD KEY `event_id` (`event_id`) AFTER `community_id`,
|
||||
ADD CONSTRAINT `transactions_event_id` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`);
|
||||
@@ -0,0 +1,4 @@
|
||||
ALTER TABLE `transactions`
|
||||
ADD `event_id` int(10) unsigned NULL AFTER `community_id`,
|
||||
ADD KEY `event_id` (`event_id`),
|
||||
ADD CONSTRAINT `transactions_event_id` FOREIGN KEY (`event_id`) REFERENCES `events` (`id`);
|
||||
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE `transaction_payees` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`transaction_id` int(10) unsigned NOT NULL,
|
||||
`user_id` int(10) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `unique_user_for_transaction` (`transaction_id`, `user_id`),
|
||||
KEY `transaction_id` (`transaction_id`),
|
||||
KEY `user_id` (`user_id`),
|
||||
CONSTRAINT `transaction_payees_transaction_id` FOREIGN KEY (`transaction_id`) REFERENCES `transactions` (`id`),
|
||||
CONSTRAINT `transaction_payees_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
||||
@@ -176,6 +176,43 @@ class CommunityController implements IAuthenticationRequired
|
||||
]);
|
||||
}
|
||||
|
||||
public function deleteCommunity(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->transactionRepository->countAllByCommunity($community) > 0) {
|
||||
return new JsonContent([
|
||||
'error' => ['errorText' => 'There are transactions for this community!']
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->eventRepository->countAllByCommunity($community) > 0) {
|
||||
return new JsonContent([
|
||||
'error' => ['errorText' => 'There are events for this community!']
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($this->communityMemberRepository->getAllByCommunity($community) as $communityMember) {
|
||||
\Container::$persistentDataManager->deleteFromDb($communityMember);
|
||||
}
|
||||
|
||||
$community->setMainCurrencyId(null);
|
||||
\Container::$persistentDataManager->saveToDb($community);
|
||||
|
||||
foreach ($this->currencyRepository->getAllByCommunity($community) as $currency) {
|
||||
foreach ($this->currencyExchangeRatesRepository->getAllByCurrency($currency) as $currencyExchangeRate) {
|
||||
\Container::$persistentDataManager->deleteFromDb($currencyExchangeRate);
|
||||
}
|
||||
\Container::$persistentDataManager->deleteFromDb($currency);
|
||||
}
|
||||
|
||||
\Container::$persistentDataManager->deleteFromDb($community);
|
||||
|
||||
return new JsonContent(['success' => true]);
|
||||
}
|
||||
|
||||
public function getMembersEdit(): ?IContent
|
||||
{
|
||||
if (!$this->checkPermission(\Container::$request->query('communitySlug'), true, $community, $ownCommunityMember)) {
|
||||
|
||||
@@ -68,17 +68,16 @@ class EventController implements IAuthenticationRequired, ISecured
|
||||
{
|
||||
$itemsPerPage = 10;
|
||||
$numberOfEvents = $this->eventRepository->countAllByCommunity($this->community);
|
||||
$pages = ceil($numberOfEvents / $itemsPerPage);
|
||||
$currentPage = Container::$request->query('page') ?: 0;
|
||||
$currentPage = Container::$request->query('page') ?: 1;
|
||||
$events = $this->eventRepository->getPagedByCommunity(
|
||||
$this->community,
|
||||
$currentPage * $itemsPerPage,
|
||||
$currentPage,
|
||||
$itemsPerPage
|
||||
);
|
||||
|
||||
return new HtmlContent('events/events', [
|
||||
'community' => $this->community,
|
||||
'pages' => $pages,
|
||||
'pages' => ceil($numberOfEvents / $itemsPerPage),
|
||||
'currentPage' => $currentPage,
|
||||
'numberOfEvents' => $numberOfEvents,
|
||||
'events' => $events
|
||||
|
||||
@@ -6,11 +6,13 @@ use RVR\Finance\ExchangeRateCalculator;
|
||||
use RVR\PersistentData\Model\Community;
|
||||
use RVR\PersistentData\Model\CommunityMember;
|
||||
use RVR\PersistentData\Model\Transaction;
|
||||
use RVR\PersistentData\Model\TransactionPayee;
|
||||
use RVR\PersistentData\Model\User;
|
||||
use RVR\Repository\CommunityMemberRepository;
|
||||
use RVR\Repository\CommunityRepository;
|
||||
use RVR\Repository\CurrencyRepository;
|
||||
use RVR\Repository\TransactionRepository;
|
||||
use RVR\Repository\TransactionPayeeRepository;
|
||||
use RVR\Repository\EventRepository;
|
||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||
use SokoWeb\Interfaces\Authorization\ISecured;
|
||||
@@ -28,6 +30,8 @@ class TransactionController implements IAuthenticationRequired, ISecured
|
||||
|
||||
private TransactionRepository $transactionRepository;
|
||||
|
||||
private TransactionPayeeRepository $transactionPayeeRepository;
|
||||
|
||||
private EventRepository $eventRepository;
|
||||
|
||||
private ?Community $community;
|
||||
@@ -40,6 +44,7 @@ class TransactionController implements IAuthenticationRequired, ISecured
|
||||
$this->communityMemberRepository = new CommunityMemberRepository();
|
||||
$this->currencyRepository = new CurrencyRepository();
|
||||
$this->transactionRepository = new TransactionRepository();
|
||||
$this->transactionPayeeRepository = new TransactionPayeeRepository();
|
||||
$this->eventRepository = new EventRepository();
|
||||
}
|
||||
|
||||
@@ -84,32 +89,35 @@ class TransactionController implements IAuthenticationRequired, ISecured
|
||||
$numberOfTransactions = $event ?
|
||||
$this->transactionRepository->countAllByEvent($event) :
|
||||
$this->transactionRepository->countAllByCommunity($this->community);
|
||||
$pages = ceil($numberOfTransactions / $itemsPerPage);
|
||||
$currentPage = Container::$request->query('page') ?: 0;
|
||||
$currentPage = Container::$request->query('page') ?: 1;
|
||||
$transactions = $event ?
|
||||
$this->transactionRepository->getPagedByEvent(
|
||||
$event,
|
||||
$currentPage * $itemsPerPage,
|
||||
$currentPage,
|
||||
$itemsPerPage,
|
||||
true,
|
||||
['currency', 'payer_user', 'payee_user']
|
||||
['currency', 'payer_user']
|
||||
) :
|
||||
$this->transactionRepository->getPagedByCommunity(
|
||||
$this->community,
|
||||
$currentPage * $itemsPerPage,
|
||||
$currentPage,
|
||||
$itemsPerPage,
|
||||
true,
|
||||
['event', 'currency', 'payer_user', 'payee_user']
|
||||
['event', 'currency', 'payer_user']
|
||||
);
|
||||
|
||||
$transactions = iterator_to_array($transactions);
|
||||
Container::$persistentDataManager->loadMultiRelationsFromDb($transactions, 'payees', true, ['user']);
|
||||
|
||||
return new HtmlContent('communities/transactions', [
|
||||
'community' => $this->community,
|
||||
'event' => $event,
|
||||
'exchangeRateCalculator' => $exchangeRateCalculator,
|
||||
'pages' => $pages,
|
||||
'pages' => ceil($numberOfTransactions / $itemsPerPage),
|
||||
'currentPage' => $currentPage,
|
||||
'numberOfTransactions' => $numberOfTransactions,
|
||||
'transactions' => $transactions
|
||||
'transactions' => $transactions,
|
||||
'members' => $this->getMembers($this->community)
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -123,6 +131,10 @@ class TransactionController implements IAuthenticationRequired, ISecured
|
||||
}
|
||||
Container::$persistentDataManager->loadRelationsFromDb($transaction, false, ['event']);
|
||||
$event = $transaction->getEvent();
|
||||
$payeeUserIds = [];
|
||||
foreach ($this->transactionPayeeRepository->getAllByTransaction($transaction) as $payee) {
|
||||
$payeeUserIds[] = $payee->getUserId();
|
||||
}
|
||||
} else {
|
||||
$transaction = null;
|
||||
$eventSlug = Container::$request->query('event');
|
||||
@@ -131,11 +143,13 @@ class TransactionController implements IAuthenticationRequired, ISecured
|
||||
} else {
|
||||
$event = null;
|
||||
}
|
||||
$payeeUserIds = [];
|
||||
}
|
||||
|
||||
return new HtmlContent('communities/transaction_edit', [
|
||||
'community' => $this->community,
|
||||
'transaction' => $transaction,
|
||||
'payeeUserIds' => $payeeUserIds,
|
||||
'event' => $event,
|
||||
'members' => $this->getMembers($this->community),
|
||||
'currencies' => $this->getCurrencies($this->community)
|
||||
@@ -155,18 +169,48 @@ class TransactionController implements IAuthenticationRequired, ISecured
|
||||
$transaction->setEventId(Container::$request->post('event_id') ?: null);
|
||||
$transaction->setCurrencyId(Container::$request->post('currency_id'));
|
||||
$transaction->setPayerUserId(Container::$request->post('payer_user_id'));
|
||||
$transaction->setPayeeUserId(Container::$request->post('payee_user_id') ?: null);
|
||||
$transaction->setDescription(Container::$request->post('description'));
|
||||
$transaction->setSum(Container::$request->post('sum'));
|
||||
$transaction->setTimeDate(new DateTime(Container::$request->post('time')));
|
||||
Container::$persistentDataManager->saveToDb($transaction);
|
||||
|
||||
$payeeUserIds = array_unique(Container::$request->post('payee_user_ids'));
|
||||
if (count($payeeUserIds) === $this->communityMemberRepository->countAllByCommunity($this->community)) {
|
||||
$payeeUserIds = [];
|
||||
}
|
||||
|
||||
$currentPayees = [];
|
||||
foreach ($payeeUserIds as $payeeUserId) {
|
||||
$payee = new TransactionPayee();
|
||||
$payee->setTransaction($transaction);
|
||||
$payee->setUserId((int)$payeeUserId);
|
||||
$currentPayees[(int)$payeeUserId] = $payee;
|
||||
}
|
||||
$existingPayees = [];
|
||||
if ($transactionId) {
|
||||
foreach ($this->transactionPayeeRepository->getAllByTransaction($transaction) as $payee) {
|
||||
$existingPayees[$payee->getUserId()] = $payee;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (array_diff_key($currentPayees, $existingPayees) as $newPayee) {
|
||||
Container::$persistentDataManager->saveToDb($newPayee);
|
||||
}
|
||||
foreach (array_diff_key($existingPayees, $currentPayees) as $deletedPayee) {
|
||||
Container::$persistentDataManager->deleteFromDb($deletedPayee);
|
||||
}
|
||||
|
||||
return new JsonContent(['success' => true]);
|
||||
}
|
||||
|
||||
public function deleteTransaction(): IContent
|
||||
{
|
||||
$transaction = $this->transactionRepository->getById(Container::$request->query('transactionId'));
|
||||
|
||||
foreach ($this->transactionPayeeRepository->getAllByTransaction($transaction) as $payee) {
|
||||
Container::$persistentDataManager->deleteFromDb($payee);
|
||||
}
|
||||
|
||||
Container::$persistentDataManager->deleteFromDb($transaction);
|
||||
|
||||
return new JsonContent(['success' => true]);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php namespace RVR\Finance;
|
||||
|
||||
use Container;
|
||||
use RVR\PersistentData\Model\Community;
|
||||
use RVR\Repository\CommunityMemberRepository;
|
||||
use RVR\Repository\TransactionRepository;
|
||||
@@ -56,13 +57,18 @@ class BalanceCalculator
|
||||
private function sumTransactions(): void
|
||||
{
|
||||
$membersCount = count($this->members);
|
||||
$transactions = $this->transactionRepository->getAllByCommunity($this->community, true, ['currency']);
|
||||
$transactions = iterator_to_array($this->transactionRepository->getAllByCommunity($this->community, true, ['currency']));
|
||||
Container::$persistentDataManager->loadMultiRelationsFromDb($transactions, 'payees');
|
||||
|
||||
foreach ($transactions as $transaction) {
|
||||
$sum = $this->exchangeRateCalculator->calculate($transaction->getSum(), $transaction->getCurrency(), $transaction->getTimeDate());
|
||||
$payees = $transaction->getPayees();
|
||||
$payeeCount = count($payees);
|
||||
|
||||
if ($transaction->getPayeeUserId()) {
|
||||
$this->payments[$transaction->getPayerUserId()][$transaction->getPayeeUserId()] += $sum;
|
||||
if ($payeeCount > 0) {
|
||||
foreach ($payees as $payee) {
|
||||
$this->payments[$transaction->getPayerUserId()][$payee->getUserId()] += $sum / $payeeCount;
|
||||
}
|
||||
} else {
|
||||
foreach ($this->members as $payeeUserId => $member) {
|
||||
$this->payments[$transaction->getPayerUserId()][$payeeUserId] += $sum / $membersCount;
|
||||
|
||||
@@ -33,12 +33,12 @@ class Community extends ModelWithSlug
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
public function setMainCurrency(Currency $mainCurrency): void
|
||||
public function setMainCurrency(?Currency $mainCurrency): void
|
||||
{
|
||||
$this->mainCurrency = $mainCurrency;
|
||||
}
|
||||
|
||||
public function setMainCurrencyId(int $mainCurrencyId): void
|
||||
public function setMainCurrencyId(?int $mainCurrencyId): void
|
||||
{
|
||||
$this->mainCurrencyId = $mainCurrencyId;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ class Transaction extends Model
|
||||
'payee_user' => User::class
|
||||
];
|
||||
|
||||
protected static array $multiRelations = [
|
||||
'payees' => [TransactionPayee::class, 'transaction']
|
||||
];
|
||||
|
||||
private ?Community $community = null;
|
||||
|
||||
private int $communityId;
|
||||
@@ -37,6 +41,8 @@ class Transaction extends Model
|
||||
|
||||
private ?int $payeeUserId = null;
|
||||
|
||||
private ?array $payees = null;
|
||||
|
||||
private string $description = '';
|
||||
|
||||
private float $sum = 0.0;
|
||||
@@ -93,6 +99,11 @@ class Transaction extends Model
|
||||
$this->payeeUserId = $payeeUserId;
|
||||
}
|
||||
|
||||
public function setPayees(array $payees): void
|
||||
{
|
||||
$this->payees = $payees;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): void
|
||||
{
|
||||
$this->description = $description;
|
||||
@@ -163,6 +174,11 @@ class Transaction extends Model
|
||||
return $this->payeeUserId;
|
||||
}
|
||||
|
||||
public function getPayees(): ?array
|
||||
{
|
||||
return $this->payees;
|
||||
}
|
||||
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php namespace RVR\PersistentData\Model;
|
||||
|
||||
use SokoWeb\PersistentData\Model\Model;
|
||||
|
||||
class TransactionPayee extends Model
|
||||
{
|
||||
protected static string $table = 'transaction_payees';
|
||||
|
||||
protected static array $fields = ['transaction_id', 'user_id'];
|
||||
|
||||
protected static array $relations = ['transaction' => Transaction::class, 'user' => User::class];
|
||||
|
||||
private ?Transaction $transaction = null;
|
||||
|
||||
private ?int $transactionId = null;
|
||||
|
||||
private ?User $user = null;
|
||||
|
||||
private ?int $userId = null;
|
||||
|
||||
public function setTransaction(Transaction $transaction): void
|
||||
{
|
||||
$this->transaction = $transaction;
|
||||
}
|
||||
|
||||
public function setTransactionId(int $transactionId): void
|
||||
{
|
||||
$this->transactionId = $transactionId;
|
||||
}
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function setUserId(int $userId): void
|
||||
{
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
public function getTransaction(): ?Transaction
|
||||
{
|
||||
return $this->transaction;
|
||||
}
|
||||
|
||||
public function getTransactionId(): ?int
|
||||
{
|
||||
return $this->transactionId;
|
||||
}
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getUserId(): ?int
|
||||
{
|
||||
return $this->userId;
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,16 @@ class CommunityMemberRepository
|
||||
|
||||
public function getAllByCommunity(Community $community, bool $useRelations = false, array $withRelations = []): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
$select->where('community_id', '=', $community->getId());
|
||||
$select = $this->selectAllByCommunity($community);
|
||||
|
||||
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, CommunityMember::class, $useRelations, $withRelations);
|
||||
}
|
||||
|
||||
public function countAllByCommunity(Community $community): int
|
||||
{
|
||||
return $this->selectAllByCommunity($community)->count();
|
||||
}
|
||||
|
||||
public function getAllByUser(User $user, bool $useRelations = false, array $withRelations = []): Generator
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection);
|
||||
@@ -37,4 +41,11 @@ class CommunityMemberRepository
|
||||
|
||||
return \Container::$persistentDataManager->selectFromDb($select, CommunityMember::class);
|
||||
}
|
||||
|
||||
private function selectAllByCommunity(Community $community): Select
|
||||
{
|
||||
$select = new Select(\Container::$dbConnection, CommunityMember::getTable());
|
||||
$select->where('community_id', '=', $community->getId());
|
||||
return $select;
|
||||
}
|
||||
}
|
||||
@@ -52,11 +52,11 @@ class EventRepository
|
||||
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations);
|
||||
}
|
||||
|
||||
public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
||||
public function getPagedByCommunity(Community $community, int $page, int $itemsPerPage, bool $useRelations = false, array $withRelations = []): Generator
|
||||
{
|
||||
$select = $this->selectAllByCommunity($community);
|
||||
$select->orderBy('start', 'DESC');
|
||||
$select->limit($limit, $start);
|
||||
$select->paginate($page, $itemsPerPage);
|
||||
|
||||
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Event::class, $useRelations, $withRelations);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php namespace RVR\Repository;
|
||||
|
||||
use Container;
|
||||
use Generator;
|
||||
use RVR\PersistentData\Model\Transaction;
|
||||
use RVR\PersistentData\Model\TransactionPayee;
|
||||
use SokoWeb\Database\Query\Select;
|
||||
|
||||
class TransactionPayeeRepository
|
||||
{
|
||||
public function getById(int $id): ?TransactionPayee
|
||||
{
|
||||
return Container::$persistentDataManager->selectFromDbById($id, TransactionPayee::class);
|
||||
}
|
||||
|
||||
public function getAllByTransaction(Transaction $transaction, bool $useRelations = false, array $withRelations = []): Generator
|
||||
{
|
||||
$select = new Select(Container::$dbConnection);
|
||||
$select->where('transaction_id', '=', $transaction->getId());
|
||||
|
||||
yield from Container::$persistentDataManager->selectMultipleFromDb($select, TransactionPayee::class, $useRelations, $withRelations);
|
||||
}
|
||||
}
|
||||
@@ -66,20 +66,20 @@ class TransactionRepository
|
||||
return $select->count() > 0;
|
||||
}
|
||||
|
||||
public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
||||
public function getPagedByCommunity(Community $community, int $page, int $itemsPerPage, bool $useRelations = false, array $withRelations = []): Generator
|
||||
{
|
||||
$select = $this->selectAllByCommunity($community);
|
||||
$select->orderBy('time', 'DESC');
|
||||
$select->limit($limit, $start);
|
||||
$select->paginate($page, $itemsPerPage);
|
||||
|
||||
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations);
|
||||
}
|
||||
|
||||
public function getPagedByEvent(Event $event, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator
|
||||
public function getPagedByEvent(Event $event, int $page, int $itemsPerPage, bool $useRelations = false, array $withRelations = []): Generator
|
||||
{
|
||||
$select = $this->selectAllByEvent($event);
|
||||
$select->orderBy('time', 'DESC');
|
||||
$select->limit($limit, $start);
|
||||
$select->paginate($page, $itemsPerPage);
|
||||
|
||||
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations);
|
||||
}
|
||||
|
||||
@@ -25,9 +25,15 @@
|
||||
<input type="number" class="text big fullWidth" name="main_currency_round_digits" min="0" max="9" required>
|
||||
<?php endif; ?>
|
||||
<p id="communityFormError" class="formError justify marginTop"></p>
|
||||
<div class="right marginTop">
|
||||
<div class="right marginTop" style="font-size: 0;">
|
||||
<button type="submit" name="submit_button"><?= isset($community) ? '<i class="fa-regular fa-floppy-disk"></i> Save' : '<i class="fa-regular fa-plus"></i> Create' ?></button>
|
||||
<?php if (isset($community)): ?>
|
||||
<button type="submit" form="deleteCommunity" name="submit_button" data-confirmation="Are you sure you want to delete this community?" class="red marginLeft"><i class="fa-regular fa-trash-can"></i> Delete</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</form>
|
||||
<?php if (isset($community)): ?>
|
||||
<form id="deleteCommunity" action="<?= Container::$routeCollection->getRoute('community.delete-action')->generateLink(['communitySlug' => $community->getSlug()]) ?>" method="post" data-redirect-on-success="<?= Container::$routeCollection->getRoute('home')->generateLink() ?>"></form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -1,5 +1,5 @@
|
||||
@css(/static/node_modules/tom-select/dist/css/tom-select.min.css)
|
||||
@js(/static/node_modules/tom-select/dist/js/tom-select.base.min.js)
|
||||
@css(node_modules/tom-select/dist/css/tom-select.min.css)
|
||||
@js(node_modules/tom-select/dist/js/tom-select.base.min.js)
|
||||
@js(js/communities/community_members.js)
|
||||
|
||||
@extends(templates/layout_normal)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@css(/static/node_modules/tom-select/dist/css/tom-select.min.css)
|
||||
@js(/static/node_modules/tom-select/dist/js/tom-select.base.min.js)
|
||||
@css(node_modules/tom-select/dist/css/tom-select.min.css)
|
||||
@js(node_modules/tom-select/dist/js/tom-select.base.min.js)
|
||||
@js(js/communities/transaction.js)
|
||||
|
||||
@extends(templates/layout_normal)
|
||||
@@ -39,13 +39,15 @@
|
||||
<option value="<?= $member->getUser()->getId() ?>" <?= isset($transaction) && $transaction->getPayerUserId() === $member->getUser()->getId() ? 'selected' : '' ?>><?= $member->getUser()->getDisplayName() ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<p class="formLabel marginTop">Payee</p>
|
||||
<select class="big fullWidth" name="payee_user_id">
|
||||
<option value="">[common]</option>
|
||||
<p class="formLabel marginTop">Payee(s)</p>
|
||||
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); grid-gap: 10px;">
|
||||
<?php foreach ($members as $member): ?>
|
||||
<option value="<?= $member->getUser()->getId() ?>" <?= isset($transaction) && $transaction->getPayeeUserId() === $member->getUser()->getId() ? 'selected' : '' ?>><?= $member->getUser()->getDisplayName() ?></option>
|
||||
<div style="text-align: center;">
|
||||
<input id="payee_<?= $member->getUserId() ?>" type="checkbox" name="payee_user_ids[]" value="<?= $member->getUserId() ?>" <?= !isset($transaction) || count($payeeUserIds) === 0 || in_array($member->getUserId(), $payeeUserIds) ? 'checked' : '' ?>><!--
|
||||
--><label for="payee_<?= $member->getUserId() ?>"><?= $member->getUser()->getDisplayName() ?></label>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<p class="formLabel marginTop">Description</p>
|
||||
<input type="text" class="text big fullWidth" name="description" value="<?= isset($transaction) ? $transaction->getDescription() : '' ?>" required>
|
||||
<p class="formLabel marginTop">Sum</p>
|
||||
|
||||
@@ -13,20 +13,13 @@
|
||||
<p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.transactions.new')->generateLink(['communitySlug' => $community->getSlug(), 'event' => isset($event) ? $event->getSlug() : null]) ?>">New transaction</a></p>
|
||||
|
||||
<?php if ($numberOfTransactions > 0): ?>
|
||||
<?php
|
||||
$paginationRouteId = 'community.transactions';
|
||||
$paginationRouteParams = ['communitySlug' => $community->getSlug()];
|
||||
?>
|
||||
|
||||
<?php if ($pages > 1): ?>
|
||||
<p class="paginateContainer marginTop">
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communitySlug' => $community->getSlug(), 'page' => 0]) ?>">«</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communitySlug' => $community->getSlug(), 'page' => max(0, $currentPage - 1)]) ?>">‹</a>
|
||||
<?php for ($i = 0; $i < $pages; $i++): ?>
|
||||
<?php if ($currentPage == $i): ?>
|
||||
<span class="selected"><?= $i + 1 ?></span>
|
||||
<?php else: ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communitySlug' => $community->getSlug(), 'page' => $i]) ?>"><?= $i + 1 ?></a>
|
||||
<?php endif; ?>
|
||||
<?php endfor; ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communitySlug' => $community->getSlug(), 'page' => min($pages - 1, $currentPage + 1)]) ?>">›</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communitySlug' => $community->getSlug(), 'page' => $pages - 1]) ?>">»</a>
|
||||
</p>
|
||||
@include(templates/pagination)
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ($transactions as $transaction): ?>
|
||||
@@ -37,7 +30,29 @@
|
||||
<p><span class="label"><?= $transaction->getEvent()->getTitle() ?></span></p>
|
||||
<?php endif; ?>
|
||||
<p style="font-weight: bold;"><?= $transaction->getDescription() ?></p>
|
||||
<p class="small"><?= $transaction->getPayerUser()->getDisplayName() ?> <i class="fa-solid fa-caret-right"></i> <?= $transaction->getPayeeUser() ? $transaction->getPayeeUser()->getDisplayName() : '[common]' ?></p>
|
||||
<p class="small">
|
||||
<?= $transaction->getPayerUser()->getDisplayName() ?>
|
||||
<i class="fa-solid fa-caret-right"></i>
|
||||
<?php foreach ($members as $member): ?>
|
||||
<?php
|
||||
if (count($transaction->getPayees()) > 0) {
|
||||
$found = false;
|
||||
foreach ($transaction->getPayees() as $payee) {
|
||||
if ($member->getUserId() === $payee->getUserId()) {
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$found = true;
|
||||
}
|
||||
?>
|
||||
<?php if ($found): ?>
|
||||
<?= $member->getUser()->getDisplayName() ?>
|
||||
<?php else: ?>
|
||||
<span class="gray" style="text-decoration: line-through;"><?= $member->getUser()->getDisplayName() ?></span>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
</p>
|
||||
<p class="small"><?= $transaction->getTimeDate()->format('Y-m-d H:i') ?></p>
|
||||
</div>
|
||||
<div style="text-align: right;">
|
||||
@@ -51,19 +66,7 @@
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ($pages > 1): ?>
|
||||
<p class="paginateContainer marginTop">
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communitySlug' => $community->getSlug(), 'page' => 0]) ?>">«</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communitySlug' => $community->getSlug(), 'page' => max(0, $currentPage - 1)]) ?>">‹</a>
|
||||
<?php for ($i = 0; $i < $pages; $i++): ?>
|
||||
<?php if ($currentPage == $i): ?>
|
||||
<span class="selected"><?= $i + 1 ?></span>
|
||||
<?php else: ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communitySlug' => $community->getSlug(), 'page' => $i]) ?>"><?= $i + 1 ?></a>
|
||||
<?php endif; ?>
|
||||
<?php endfor; ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communitySlug' => $community->getSlug(), 'page' => min($pages - 1, $currentPage + 1)]) ?>">›</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communitySlug' => $community->getSlug(), 'page' => $pages - 1]) ?>">»</a>
|
||||
</p>
|
||||
@include(templates/pagination)
|
||||
<?php endif; ?>
|
||||
|
||||
<p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.transactions.new')->generateLink(['communitySlug' => $community->getSlug(), 'event' => isset($event) ? $event->getSlug() : null]) ?>">New transaction</a></p>
|
||||
|
||||
+7
-26
@@ -9,20 +9,13 @@
|
||||
<p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.events.new')->generateLink(['communitySlug' => $community->getSlug()]) ?>">New event</a></p>
|
||||
|
||||
<?php if ($numberOfEvents > 0): ?>
|
||||
<?php
|
||||
$paginationRouteId = 'community.events';
|
||||
$paginationRouteParams = ['communitySlug' => $community->getSlug()];
|
||||
?>
|
||||
|
||||
<?php if ($pages > 1): ?>
|
||||
<p class="paginateContainer marginTop">
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.events')->generateLink(['communitySlug' => $community->getSlug(), 'page' => 0]) ?>">«</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.events')->generateLink(['communitySlug' => $community->getSlug(), 'page' => max(0, $currentPage - 1)]) ?>">‹</a>
|
||||
<?php for ($i = 0; $i < $pages; $i++): ?>
|
||||
<?php if ($currentPage == $i): ?>
|
||||
<span class="selected"><?= $i + 1 ?></span>
|
||||
<?php else: ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.events')->generateLink(['communitySlug' => $community->getSlug(), 'page' => $i]) ?>"><?= $i + 1 ?></a>
|
||||
<?php endif; ?>
|
||||
<?php endfor; ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.events')->generateLink(['communitySlug' => $community->getSlug(), 'page' => min($pages - 1, $currentPage + 1)]) ?>">›</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.events')->generateLink(['communitySlug' => $community->getSlug(), 'page' => $pages - 1]) ?>">»</a>
|
||||
</p>
|
||||
@include(templates/pagination)
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ($events as $event): ?>
|
||||
@@ -36,19 +29,7 @@
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ($pages > 1): ?>
|
||||
<p class="paginateContainer marginTop">
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.events')->generateLink(['communitySlug' => $community->getSlug(), 'page' => 0]) ?>">«</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.events')->generateLink(['communitySlug' => $community->getSlug(), 'page' => max(0, $currentPage - 1)]) ?>">‹</a>
|
||||
<?php for ($i = 0; $i < $pages; $i++): ?>
|
||||
<?php if ($currentPage == $i): ?>
|
||||
<span class="selected"><?= $i + 1 ?></span>
|
||||
<?php else: ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.events')->generateLink(['communitySlug' => $community->getSlug(), 'page' => $i]) ?>"><?= $i + 1 ?></a>
|
||||
<?php endif; ?>
|
||||
<?php endfor; ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.events')->generateLink(['communitySlug' => $community->getSlug(), 'page' => min($pages - 1, $currentPage + 1)]) ?>">›</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute('community.events')->generateLink(['communitySlug' => $community->getSlug(), 'page' => $pages - 1]) ?>">»</a>
|
||||
</p>
|
||||
@include(templates/pagination)
|
||||
<?php endif; ?>
|
||||
|
||||
<p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.events.new')->generateLink(['communitySlug' => $community->getSlug()]) ?>">New event</a></p>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<p class="paginateContainer marginTop">
|
||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => 1])) ?>">«</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => max(1, $currentPage - 1)])) ?>">‹</a>
|
||||
<?php
|
||||
$maxPages = 7;
|
||||
if ($pages <= $maxPages) {
|
||||
$start = 1;
|
||||
$end = $pages;
|
||||
} else {
|
||||
$maxAdditionalPages = $maxPages - 1;
|
||||
$maxAdditionalPagesHalf = ceil($maxAdditionalPages / 2);
|
||||
$start = $currentPage - $maxAdditionalPagesHalf > 1 ?
|
||||
($currentPage - $maxAdditionalPagesHalf < $pages - $maxAdditionalPages ?
|
||||
$currentPage - $maxAdditionalPagesHalf :
|
||||
$pages - $maxAdditionalPages) :
|
||||
1;
|
||||
$end = $start + $maxAdditionalPages < $pages ?
|
||||
$start + $maxAdditionalPages :
|
||||
$pages;
|
||||
}
|
||||
?>
|
||||
<?php for ($i = $start; $i <= $end; $i++): ?>
|
||||
<?php if ($currentPage == $i): ?>
|
||||
<span class="selected"><?= $i ?></span>
|
||||
<?php else: ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => $i])) ?>"><?= $i ?></a>
|
||||
<?php endif; ?>
|
||||
<?php endfor; ?>
|
||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => min($pages, $currentPage + 1)])) ?>">›</a>
|
||||
<a href="<?= Container::$routeCollection->getRoute($paginationRouteId)->generateLink(array_merge($paginationRouteParams, ['page' => $pages])) ?>">»</a>
|
||||
</p>
|
||||
@@ -70,6 +70,7 @@ Container::$routeCollection->group('communities', function (RouteCollection $rou
|
||||
$routeCollection->get('community.settings', 'settings', [CommunityController::class, 'getCommunitySettings']);
|
||||
$routeCollection->get('community.edit', 'edit', [CommunityController::class, 'getCommunityEdit']);
|
||||
$routeCollection->post('community.edit-action', 'edit', [CommunityController::class, 'saveCommunity']);
|
||||
$routeCollection->post('community.delete-action', 'delete', [CommunityController::class, 'deleteCommunity']);
|
||||
$routeCollection->get('community.members', 'members', [CommunityController::class, 'getMembersEdit']);
|
||||
$routeCollection->post('community.members.new-action', 'members/new', [CommunityController::class, 'saveMember']);
|
||||
$routeCollection->post('community.members.edit-action', 'members/edit', [CommunityController::class, 'saveMember']);
|
||||
|
||||
Reference in new issue
Block a user