Compare commits

..
Author SHA1 Message Date
bence 4dbbb1321c Merge pull request 'feature/RVRNEXT-7-calculate-balance-for-community-members' (!37) from feature/RVRNEXT-7-calculate-balance-for-community-members into master
rvr-nextgen/pipeline/head This commit looks good
Reviewed-on: #37
2023-05-01 22:26:03 +02:00
bence 0a7cfdbb8e RVRNEXT-7 show balances on community home page
rvr-nextgen/pipeline/pr-master This commit looks good
2023-05-01 22:01:11 +02:00
bence 751c1895ca RVRNEXT-7 calculate balances in CommunityController 2023-05-01 22:00:32 +02:00
bence 3fd43b6e41 RVRNEXT-7 add BalanceCalculator class 2023-05-01 22:00:13 +02:00
bence ae3554c365 RVRNEXT-7 layout fine-tuning 2023-05-01 21:59:55 +02:00
bence 5526a55145 RVRNEXT-7 add link for transactions 2023-05-01 19:32:35 +02:00
bence 3e6514a2e5 Merge pull request 'feature/RVRNEXT-6-transactions' (!36) from feature/RVRNEXT-6-transactions into master
rvr-nextgen/pipeline/head This commit looks good
Reviewed-on: #36
2023-05-01 19:28:27 +02:00
bence 8566641459 RVRNEXT-6 add new routes for transactions
rvr-nextgen/pipeline/pr-master This commit looks good
2023-05-01 19:24:24 +02:00
bence 14f7a5b9b5 RVRNEXT-6 add views for transactions 2023-05-01 19:23:48 +02:00
bence 6fb951a01e RVRNEXT-6 add transactioncontroller 2023-05-01 19:23:31 +02:00
bence c7c2df89c5 RVRNEXT-6 add ExchangeRateCalculator 2023-05-01 19:23:19 +02:00
bence 67114211ec RVRNEXT-6 add model and repository for transactions 2023-05-01 19:19:39 +02:00
bence f2d99c4f0f RVRNEXT-6 add migration for transaction db structure 2023-05-01 19:19:10 +02:00
bence 2ed01df331 RVRNEXT-6 layout fine-tuning 2023-05-01 19:18:48 +02:00
bence f89bed25da RVRNEXT-6 update soko-web 2023-05-01 19:15:45 +02:00
bence d707c20ab6 Merge pull request 'feature/update-soko-web-to-0.7' (!35) from feature/update-soko-web-to-0.7 into master
rvr-nextgen/pipeline/head This commit looks good
Reviewed-on: #35
2023-04-30 21:07:16 +02:00
bence 49d72f1d48 adapt $withRelations usage to soko-web 0.7
rvr-nextgen/pipeline/pr-master This commit looks good
2023-04-30 20:25:21 +02:00
bence eabf17cb77 update soko-web to 0.7 2023-04-30 20:24:10 +02:00
bence 7b45069904 Merge pull request 'feature/RVRNEXT-5-main-currency-of-community-should-be-a-general-currency' (!34) from feature/RVRNEXT-5-main-currency-of-community-should-be-a-general-currency into master
rvr-nextgen/pipeline/head This commit looks good
Reviewed-on: #34
2023-04-28 21:44:18 +02:00
bence 49df206ddc RVRNEXT-5 move saveCommunity under getCommunityEdit
rvr-nextgen/pipeline/pr-master This commit looks good
2023-04-28 21:20:08 +02:00
bence e0ea18a6d0 RVRNEXT-5 migration for main_currency_id
rvr-nextgen/pipeline/pr-master This commit looks good
2023-04-28 21:06:36 +02:00
bence 20a850f011 RVRNEXT-5 make community main currency a general currency 2023-04-28 21:06:18 +02:00
bence 157f530ad5 RVRNEXT-5 add withRelations to CommunityMemberRepository getters 2023-04-28 20:59:14 +02:00
bence 0b261b6272 RVRNEXT-5 fix audit logger for non-web access 2023-04-28 20:58:19 +02:00
34 changed files with 945 additions and 100 deletions

No files matched your search

+3 -3
View File
@@ -17,9 +17,9 @@ class Container
static SokoWeb\Interfaces\Database\IConnection $dbConnection;
static SokoWeb\Interfaces\Database\IAuditLogger $auditLogger;
static SokoWeb\Interfaces\PersistentData\IPersistentDataManager $persistentDataManager;
static SokoWeb\Interfaces\Routing\IRouteCollection $routeCollection;
static SokoWeb\Interfaces\Session\ISessionHandler $sessionHandler;
static SokoWeb\Interfaces\Request\IRequest $request;
static ?SokoWeb\Interfaces\Routing\IRouteCollection $routeCollection = null;
static ?SokoWeb\Interfaces\Session\ISessionHandler $sessionHandler = null;
static ?SokoWeb\Interfaces\Request\IRequest $request = null;
}
Container::$dbConnection = new SokoWeb\Database\Mysql\Connection($_ENV['DB_HOST'], $_ENV['DB_USER'], $_ENV['DB_PASSWORD'], $_ENV['DB_NAME']);
+1 -1
View File
@@ -10,7 +10,7 @@
}
],
"require": {
"esoko/soko-web": "0.6",
"esoko/soko-web": "0.8",
"firebase/php-jwt": "^6.4"
},
"require-dev": {
Generated
+4 -4
View File
@@ -4,15 +4,15 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "7b9e3854a5b7ef69d360c1dfbac75c17",
"content-hash": "a89a42e04596ab159fc41abbd9390068",
"packages": [
{
"name": "esoko/soko-web",
"version": "0.6",
"version": "v0.8",
"source": {
"type": "git",
"url": "https://git.esoko.eu/esoko/soko-web.git",
"reference": "5e0579463cf0f4203c46e0d4f9c09cd283dbf0b8"
"reference": "219b42f995b8e34432da4dde77e53e24b75d78dd"
},
"require": {
"phpmailer/phpmailer": "^6.8",
@@ -33,7 +33,7 @@
"GNU GPL 3.0"
],
"description": "Lightweight web framework",
"time": "2023-04-19T21:35:03+00:00"
"time": "2023-05-01T17:08:22+00:00"
},
{
"name": "firebase/php-jwt",
@@ -0,0 +1,19 @@
<?php
use RVR\PersistentData\Model\Community;
use RVR\PersistentData\Model\Currency;
use SokoWeb\Database\Query\Select;
$select = new Select(Container::$dbConnection);
$communities = Container::$persistentDataManager->selectMultipleFromDb($select, Community::class);
foreach ($communities as $community) {
$mainCurrency = new Currency();
$mainCurrency->setCommunity($community);
$mainCurrency->setCode($community->getCurrency());
$mainCurrency->setRoundDigits(0);
Container::$persistentDataManager->saveToDb($mainCurrency);
$community->setMainCurrency($mainCurrency);
Container::$persistentDataManager->saveToDb($community);
}
@@ -0,0 +1,4 @@
ALTER TABLE `communities`
ADD `main_currency_id` int(10) unsigned DEFAULT NULL,
ADD KEY `main_currency_id` (`main_currency_id`),
ADD CONSTRAINT `communities_main_currency_id` FOREIGN KEY (`main_currency_id`) REFERENCES `currencies` (`id`);
@@ -0,0 +1,19 @@
CREATE TABLE `transactions` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`community_id` int(10) unsigned NOT NULL,
`currency_id` int(10) unsigned NOT NULL,
`payer_user_id` int(10) unsigned NOT NULL,
`payee_user_id` int(10) unsigned NULL,
`description` varchar(255) NOT NULL,
`sum` decimal(19,9) NOT NULL,
`time` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
KEY `community_id` (`community_id`),
KEY `currency_id` (`currency_id`),
KEY `payer_user_id` (`payer_user_id`),
KEY `payee_user_id` (`payee_user_id`),
CONSTRAINT `transactions_community_id` FOREIGN KEY (`community_id`) REFERENCES `communities` (`id`),
CONSTRAINT `transactions_currency_id` FOREIGN KEY (`currency_id`) REFERENCES `currencies` (`id`),
CONSTRAINT `transactions_payer_user_id` FOREIGN KEY (`payer_user_id`) REFERENCES `users` (`id`),
CONSTRAINT `transactions_payee_user_id` FOREIGN KEY (`payee_user_id`) REFERENCES `users` (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
+64 -5
View File
@@ -31,6 +31,10 @@ main {
color: #ffffff;
}
::placeholder, select > option[value=""], .gray {
color: #8e8e8e;
}
p, h1, h2, h3, input, textarea, select, button, a, table, label {
font-family: 'Oxygen', sans-serif;
}
@@ -63,7 +67,7 @@ p, h2, h3 {
line-height: 150%;
}
p {
p, th, td {
font-weight: 400;
font-size: 16px;
}
@@ -100,10 +104,23 @@ hr {
font-weight: 700;
}
p.small, span.small {
p.small, span.small, td.small {
font-size: 14px;
}
.red {
color: #a80908;
}
.green {
color: #008000;
}
.mono {
font-family: 'Oxygen Mono', mono;
font-weight: 400;
}
.justify {
text-align: justify;
}
@@ -150,6 +167,12 @@ a:hover, a:focus {
text-decoration: underline;
}
a.block {
color: initial;
font-weight: initial;
text-decoration: initial;
}
button, a.button {
cursor: pointer;
font-size: 16px;
@@ -421,7 +444,6 @@ div.buttonContainer>button {
}
div.box {
width: 576px;
background-color: #eeeef4;
border-radius: 3px;
margin: 10px auto;
@@ -429,6 +451,15 @@ div.box {
box-sizing: border-box;
}
div.compactBox {
width: 576px;
}
div.transaction {
display: grid;
grid-template-columns: auto auto;
}
div.gridContainer {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
@@ -451,7 +482,7 @@ table.fullWidth {
}
table th {
font-weight: bold;
font-weight: 700;
}
table th, table td {
@@ -467,6 +498,34 @@ table th:not(:last-child), table td:not(:last-child) {
padding-right: 3px;
}
p.paginateContainer {
font-size: 0;
}
p.paginateContainer > * {
font-size: initial;
background-color: #5e77aa;
border: solid #5e77aa 1px;
color: #ffffff;
font-weight: 700;
padding: 3px 6px;
text-align: center;
display: inline-block;
height: 25px;
line-height: 25px;
width: 25px;
}
p.paginateContainer > a:hover, p.paginateContainer > .selected {
background-color: #3b5998;
border: solid #29457f 1px;
text-decoration: none;
}
p.paginateContainer > *:not(:last-child) {
border-right: solid #869ab9 1px;
}
.choices__inner {
box-sizing: border-box;
}
@@ -501,7 +560,7 @@ table th:not(:last-child), table td:not(:last-child) {
padding-left: 15px;
padding-right: 15px;
}
div.box {
div.compactBox {
width: initial;
}
}
+92 -44
View File
@@ -1,6 +1,7 @@
<?php namespace RVR\Controller;
use DateTime;
use RVR\Finance\BalanceCalculator;
use RVR\PersistentData\Model\Community;
use RVR\PersistentData\Model\CommunityMember;
use RVR\PersistentData\Model\Currency;
@@ -48,11 +49,36 @@ class CommunityController implements IAuthenticationRequired
return null;
}
\Container::$persistentDataManager->loadRelationsFromDb($community, false, ['main_currency']);
$balanceCalculator = new BalanceCalculator($community);
$debts = $balanceCalculator->calculate();
$debtUsers = [];
$debtBalance = 0.0;
$outstandingUsers = [];
$outstandingBalance = 0.0;
foreach ($debts as $debt) {
if ($debt['payer']->getId() === \Container::$request->user()->getUniqueId()) {
$debtBalance += $debt['amount'];
$debtUsers[] = $debt;
}
if ($debt['payee']->getId() === \Container::$request->user()->getUniqueId()) {
$outstandingBalance += $debt['amount'];
$outstandingUsers[] = $debt;
}
}
$balance = $outstandingBalance - $debtBalance;
return new HtmlContent('communities/community', [
'community' => $community,
'members' => $this->getMembers($community),
'currencies' => $this->getCurrencies($community),
'upcomingEvents' => [],
'debtUsers' => $debtUsers,
'debtBalance' => $debtBalance,
'outstandingUsers' => $outstandingUsers,
'outstandingBalance' => $outstandingBalance,
'balance' => $balance,
'editPermission' => $ownCommunityMember->getOwner()
]);
}
@@ -73,6 +99,63 @@ class CommunityController implements IAuthenticationRequired
]);
}
public function saveCommunity(): ?IContent
{
$name = \Container::$request->post('name');
if (strlen($name) === 0) {
return new JsonContent([
'error' => ['errorText' => 'Please fill all required fields!']
]);
}
$communityId = \Container::$request->query('communityId');
if ($communityId){
if (!$this->checkPermission($communityId, true, $community, $ownCommunityMember)) {
return null;
}
} else {
$mainCurrencyCode = \Container::$request->post('main_currency_code');
$mainCurrencyRoundDigits = \Container::$request->post('main_currency_round_digits');
if (strlen($mainCurrencyCode) === 0 || strlen($mainCurrencyCode) > 3 || $mainCurrencyRoundDigits < 0 || $mainCurrencyRoundDigits > 9) {
return new JsonContent([
'error' => ['errorText' => 'Please fill all required fields!']
]);
}
$community = new Community();
$community->setCreatedDate(new DateTime());
}
$community->setName($name);
\Container::$persistentDataManager->saveToDb($community);
if (!$communityId) {
/**
* @var User $user
*/
$user = \Container::$request->user();
$communityMember = new CommunityMember();
$communityMember->setCommunity($community);
$communityMember->setUser($user);
$communityMember->setOwner(true);
\Container::$persistentDataManager->saveToDb($communityMember);
$mainCurrency = new Currency();
$mainCurrency->setCommunity($community);
$mainCurrency->setCode($mainCurrencyCode);
$mainCurrency->setRoundDigits($mainCurrencyRoundDigits);
\Container::$persistentDataManager->saveToDb($mainCurrency);
$community->setMainCurrency($mainCurrency);
\Container::$persistentDataManager->saveToDb($community);
}
return new JsonContent([
'redirect' => ['target' => \Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()])]
]);
}
public function getMembersEdit(): ?IContent
{
if (!$this->checkPermission(\Container::$request->query('communityId'), true, $community, $ownCommunityMember)) {
@@ -185,6 +268,10 @@ class CommunityController implements IAuthenticationRequired
}
$currency = $this->currencyRepository->getById(\Container::$request->query('currency_id'));
if ($currency->getId() === $community->getMainCurrencyId()) {
return null;
}
\Container::$persistentDataManager->deleteFromDb($currency);
return new JsonContent(['success' => true]);
@@ -197,7 +284,7 @@ class CommunityController implements IAuthenticationRequired
}
$currency = $this->currencyRepository->getByCommunityAndCurrencyCode($community, \Container::$request->query('code'));
if ($currency === null) {
if ($currency === null || $currency->getId() === $community->getMainCurrencyId()) {
return null;
}
@@ -261,51 +348,9 @@ class CommunityController implements IAuthenticationRequired
return new JsonContent(['success' => true]);
}
public function saveCommunity(): ?IContent
{
$name = \Container::$request->post('name');
$currency = \Container::$request->post('currency');
if (strlen($name) === 0 || strlen($currency) === 0 || strlen($currency) > 3) {
return new JsonContent([
'error' => ['errorText' => 'Please fill all required fields!']
]);
}
$communityId = \Container::$request->query('communityId');
if ($communityId){
if (!$this->checkPermission($communityId, true, $community, $ownCommunityMember)) {
return null;
}
} else {
$community = new Community();
$community->setCreatedDate(new DateTime());
}
$community->setName($name);
$community->setCurrency($currency);
\Container::$persistentDataManager->saveToDb($community);
if (!$communityId) {
/**
* @var User $user
*/
$user = \Container::$request->user();
$communityMember = new CommunityMember();
$communityMember->setCommunity($community);
$communityMember->setUser($user);
$communityMember->setOwner(true);
\Container::$persistentDataManager->saveToDb($communityMember);
}
return new JsonContent([
'redirect' => ['target' => \Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()])]
]);
}
private function getMembers(Community $community): array
{
$members = iterator_to_array($this->communityMemberRepository->getAllByCommunity($community, true));
$members = iterator_to_array($this->communityMemberRepository->getAllByCommunity($community, true, ['user']));
usort($members, function($a, $b) {
return strnatcmp($a->getUser()->getDisplayName(), $b->getUser()->getDisplayName());
});
@@ -318,6 +363,9 @@ class CommunityController implements IAuthenticationRequired
usort($currencies, function($a, $b) {
return strnatcmp($a->getCode(), $b->getCode());
});
usort($currencies, function($a, $b) use ($community) {
return (int)($b->getId() === $community->getMainCurrencyId()) - (int)($a->getId() === $community->getMainCurrencyId());
});
return $currencies;
}
+2 -1
View File
@@ -1,5 +1,6 @@
<?php namespace RVR\Controller;
use RVR\PersistentData\Model\Community;
use RVR\PersistentData\Model\User;
use RVR\Repository\CommunityMemberRepository;
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
@@ -27,7 +28,7 @@ class HomeController implements IAuthenticationRequired
*/
$user = \Container::$request->user();
$ownCommunityMembers = $this->communityMemberRepository->getAllByUser($user, true);
$ownCommunityMembers = $this->communityMemberRepository->getAllByUser($user, true, ['community']);
$communities = [];
foreach ($ownCommunityMembers as $ownCommunityMember) {
$communities[] = $ownCommunityMember->getCommunity();
+162
View File
@@ -0,0 +1,162 @@
<?php namespace RVR\Controller;
use Container;
use DateTime;
use RVR\Finance\ExchangeRateCalculator;
use RVR\PersistentData\Model\Community;
use RVR\PersistentData\Model\CommunityMember;
use RVR\PersistentData\Model\Transaction;
use RVR\PersistentData\Model\User;
use RVR\Repository\CommunityMemberRepository;
use RVR\Repository\CommunityRepository;
use RVR\Repository\CurrencyRepository;
use RVR\Repository\TransactionRepository;
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
use SokoWeb\Interfaces\Authorization\ISecured;
use SokoWeb\Interfaces\Response\IContent;
use SokoWeb\Response\HtmlContent;
use SokoWeb\Response\JsonContent;
class TransactionController implements IAuthenticationRequired, ISecured
{
private CommunityRepository $communityRepository;
private CommunityMemberRepository $communityMemberRepository;
private CurrencyRepository $currencyRepository;
private TransactionRepository $transactionRepository;
private Community $community;
private CommunityMember $ownCommunityMember;
public function __construct()
{
$this->communityRepository = new CommunityRepository();
$this->communityMemberRepository = new CommunityMemberRepository();
$this->currencyRepository = new CurrencyRepository();
$this->transactionRepository = new TransactionRepository();
}
public function isAuthenticationRequired(): bool
{
return true;
}
public function authorize(): bool
{
$communityId = \Container::$request->query('communityId');
$this->community = $this->communityRepository->getById($communityId);
if ($this->community === null) {
return false;
}
/**
* @var User $user
*/
$user = \Container::$request->user();
$this->ownCommunityMember = $this->communityMemberRepository->getByCommunityAndUser($this->community, $user);
if ($this->ownCommunityMember === null) {
return false;
}
return true;
}
public function getTransactions(): IContent
{
Container::$persistentDataManager->loadRelationsFromDb($this->community, true, ['main_currency']);
$exchangeRateCalculator = new ExchangeRateCalculator($this->community->getMainCurrency());
$itemsPerPage = 50;
$numberOfTransactions = $this->transactionRepository->countAllByCommunity($this->community);
$pages = ceil($numberOfTransactions / $itemsPerPage);
$currentPage = Container::$request->query('page') ?: 0;
$transactions = $this->transactionRepository->getPagedByCommunity(
$this->community,
$currentPage * $itemsPerPage,
$itemsPerPage,
true,
['currency', 'payer_user', 'payee_user']
);
return new HtmlContent('communities/transactions', [
'community' => $this->community,
'exchangeRateCalculator' => $exchangeRateCalculator,
'pages' => $pages,
'currentPage' => $currentPage,
'transactions' => $transactions
]);
}
public function getTransactionEdit(): ?IContent
{
$transactionId = Container::$request->query('transactionId');
if ($transactionId) {
$transaction = $this->transactionRepository->getById($transactionId);
if ($transaction === null) {
return null;
}
} else {
$transaction = null;
}
return new HtmlContent('communities/transaction_edit', [
'community' => $this->community,
'transaction' => $transaction,
'members' => $this->getMembers($this->community),
'currencies' => $this->getCurrencies($this->community)
]);
}
public function saveTransaction(): ?IContent
{
$transactionId = Container::$request->query('transactionId');
if ($transactionId) {
$transaction = $this->transactionRepository->getById($transactionId);
} else {
$transaction = new Transaction();
$transaction->setCommunity($this->community);
}
$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);
return new JsonContent(['success' => true]);
}
public function deleteTransaction(): IContent
{
$transaction = $this->transactionRepository->getById(Container::$request->query('transactionId'));
Container::$persistentDataManager->deleteFromDb($transaction);
return new JsonContent(['success' => true]);
}
private function getMembers(Community $community): array
{
$members = iterator_to_array($this->communityMemberRepository->getAllByCommunity($community, true, ['user']));
usort($members, function($a, $b) {
return strnatcmp($a->getUser()->getDisplayName(), $b->getUser()->getDisplayName());
});
return $members;
}
private function getCurrencies(Community $community): array
{
$currencies = iterator_to_array($this->currencyRepository->getAllByCommunity($community));
usort($currencies, function($a, $b) {
return strnatcmp($a->getCode(), $b->getCode());
});
usort($currencies, function($a, $b) use ($community) {
return (int)($b->getId() === $community->getMainCurrencyId()) - (int)($a->getId() === $community->getMainCurrencyId());
});
return $currencies;
}
}
+3
View File
@@ -6,6 +6,9 @@ class AuditLogger extends AuditLoggerBase
{
protected function getModifierId()
{
if (\Container::$request === null) {
return null;
}
$user = \Container::$request->user();
if ($user === null) {
return null;
+90
View File
@@ -0,0 +1,90 @@
<?php namespace RVR\Finance;
use RVR\PersistentData\Model\Community;
use RVR\Repository\CommunityMemberRepository;
use RVR\Repository\TransactionRepository;
class BalanceCalculator
{
private Community $community;
private TransactionRepository $transactionRepository;
private CommunityMemberRepository $communityMemberRepository;
private ExchangeRateCalculator $exchangeRateCalculator;
private array $members;
private array $payments;
public function __construct(Community $community)
{
$this->community = $community;
$this->transactionRepository = new TransactionRepository();
$this->communityMemberRepository = new CommunityMemberRepository();
$this->exchangeRateCalculator = new ExchangeRateCalculator($this->community->getMainCurrency());
}
public function calculate(): array
{
$this->collectMembers();
$this->createPaymentsMatrix();
$this->sumTransactions();
return $this->calculateActualDebts();
}
private function collectMembers(): void
{
$this->members = [];
foreach ($this->communityMemberRepository->getAllByCommunity($this->community, true, ['user']) as $member) {
$this->members[$member->getUserId()] = $member;
}
}
private function createPaymentsMatrix(): void
{
$this->payments = [];
foreach ($this->members as $payerUserId => $member) {
$this->payments[$payerUserId] = [];
foreach ($this->members as $payeeUserId => $member) {
$this->payments[$payerUserId][$payeeUserId] = 0;
}
}
}
private function sumTransactions(): void
{
$membersCount = count($this->members);
$transactions = $this->transactionRepository->getAllByCommunity($this->community, true, ['currency']);
foreach ($transactions as $transaction) {
$sum = $this->exchangeRateCalculator->calculate($transaction->getSum(), $transaction->getCurrency(), $transaction->getTimeDate());
if ($transaction->getPayeeUserId()) {
$this->payments[$transaction->getPayerUserId()][$transaction->getPayeeUserId()] += $sum;
} else {
foreach ($this->members as $payeeUserId => $member) {
$this->payments[$transaction->getPayerUserId()][$payeeUserId] += $sum / $membersCount;
}
}
}
}
private function calculateActualDebts(): array
{
$actualDebts = [];
foreach ($this->payments as $payerUserId => $paymentsOfPayer) {
foreach ($paymentsOfPayer as $payeeUserId => $sum) {
$actualDebt = $this->payments[$payeeUserId][$payerUserId] - $sum;
if (round($actualDebt, $this->community->getMainCurrency()->getRoundDigits()) > 0.0) {
$actualDebts[] = ['payer' => $this->members[$payerUserId], 'payee' => $this->members[$payeeUserId], 'amount' => $actualDebt];
}
}
}
return $actualDebts;
}
}
+52
View File
@@ -0,0 +1,52 @@
<?php namespace RVR\Finance;
use DateTime;
use RVR\PersistentData\Model\Currency;
use RVR\PersistentData\Model\CurrencyExchangeRate;
use RVR\Repository\CurrencyExchangeRateRepository;
class ExchangeRateCalculator
{
private Currency $mainCurrency;
private CurrencyExchangeRateRepository $currencyExchangeRateRepository;
private array $exchangeRates = [];
public function __construct(Currency $mainCurrency)
{
$this->mainCurrency = $mainCurrency;
$this->currencyExchangeRateRepository = new CurrencyExchangeRateRepository();
}
public function calculate(float $sumInCurrency, Currency $currency, DateTime $time): float
{
if ($currency->getId() === $this->mainCurrency->getId()) {
return $sumInCurrency;
}
$currentExchangeRate = $this->getCurrentExchangeRate($currency, $time);
if ($currentExchangeRate === null) {
return 0.0;
}
return $sumInCurrency * $currentExchangeRate->getExchangeRate();
}
private function getCurrentExchangeRate(Currency $currency, DateTime $time): ?CurrencyExchangeRate
{
if (!isset($this->exchangeRates[$currency->getId()])) {
$this->exchangeRates[$currency->getId()] = iterator_to_array($this->currencyExchangeRateRepository->getAllByCurrency($currency));
}
$currentExchangeRate = null;
foreach ($this->exchangeRates[$currency->getId()] as $exchangeRate) {
if ($exchangeRate->getValidFrom() > $time) {
break;
}
$currentExchangeRate = $exchangeRate;
}
return $currentExchangeRate;
}
}
+27 -1
View File
@@ -7,12 +7,18 @@ class Community extends Model
{
protected static string $table = 'communities';
protected static array $fields = ['name', 'currency', 'created'];
protected static array $fields = ['name', 'currency', 'main_currency_id', 'created'];
protected static array $relations = ['main_currency' => Currency::class];
private string $name = '';
private string $currency = '';
private ?Currency $mainCurrency = null;
private ?int $mainCurrencyId = null;
private DateTime $created;
public function setName(string $name): void
@@ -25,6 +31,16 @@ class Community extends Model
$this->currency = $currency;
}
public function setMainCurrency(Currency $mainCurrency): void
{
$this->mainCurrency = $mainCurrency;
}
public function setMainCurrencyId(int $mainCurrencyId): void
{
$this->mainCurrencyId = $mainCurrencyId;
}
public function setCreatedDate(DateTime $created): void
{
$this->created = $created;
@@ -45,6 +61,16 @@ class Community extends Model
return $this->currency;
}
public function getMainCurrency(): ?Currency
{
return $this->mainCurrency;
}
public function getMainCurrencyId(): ?int
{
return $this->mainCurrencyId;
}
public function getCreatedDate(): DateTime
{
return $this->created;
+160
View File
@@ -0,0 +1,160 @@
<?php namespace RVR\PersistentData\Model;
use DateTime;
use SokoWeb\PersistentData\Model\Model;
class Transaction extends Model
{
protected static string $table = 'transactions';
protected static array $fields = ['community_id', 'currency_id', 'payer_user_id', 'payee_user_id', 'description', 'sum', 'time'];
protected static array $relations = [
'community' => Community::class,
'currency' => Currency::class,
'payer_user' => User::class,
'payee_user' => User::class
];
private ?Community $community = null;
private int $communityId;
private ?Currency $currency = null;
private int $currencyId;
private ?User $payerUser = null;
private int $payerUserId;
private ?User $payeeUser = null;
private ?int $payeeUserId = null;
private string $description = '';
private float $sum = 0.0;
private DateTime $time;
public function setCommunity(Community $community): void
{
$this->community = $community;
}
public function setCommunityId(int $communityId): void
{
$this->communityId = $communityId;
}
public function setCurrency(Currency $currency): void
{
$this->currency = $currency;
}
public function setCurrencyId(int $currencyId): void
{
$this->currencyId = $currencyId;
}
public function setPayerUser(User $payerUser): void
{
$this->payerUser = $payerUser;
}
public function setPayerUserId(int $payerUserId): void
{
$this->payerUserId = $payerUserId;
}
public function setPayeeUser(?User $payeeUser): void
{
$this->payeeUser = $payeeUser;
}
public function setPayeeUserId(?int $payeeUserId): void
{
$this->payeeUserId = $payeeUserId;
}
public function setDescription(string $description): void
{
$this->description = $description;
}
public function setSum(float $sum): void
{
$this->sum = $sum;
}
public function setTimeDate(DateTime $time): void
{
$this->time = $time;
}
public function setTime(string $time): void
{
$this->time = new DateTime($time);
}
public function getCommunity(): ?Community
{
return $this->community;
}
public function getCommunityId(): int
{
return $this->communityId;
}
public function getCurrency(): ?Currency
{
return $this->currency;
}
public function getCurrencyId(): int
{
return $this->currencyId;
}
public function getPayerUser(): ?User
{
return $this->payerUser;
}
public function getPayerUserId(): int
{
return $this->payerUserId;
}
public function getPayeeUser(): ?User
{
return $this->payeeUser;
}
public function getPayeeUserId(): ?int
{
return $this->payeeUserId;
}
public function getDescription(): string
{
return $this->description;
}
public function getSum(): float
{
return $this->sum;
}
public function getTimeDate(): DateTime
{
return $this->time;
}
public function getTime(): string
{
return $this->time->format('Y-m-d H:i:s');
}
}
+4 -4
View File
@@ -13,20 +13,20 @@ class CommunityMemberRepository
return \Container::$persistentDataManager->selectFromDbById($id, CommunityMember::class);
}
public function getAllByCommunity(Community $community, bool $useRelations = false): Generator
public function getAllByCommunity(Community $community, bool $useRelations = false, array $withRelations = []): Generator
{
$select = new Select(\Container::$dbConnection);
$select->where('community_id', '=', $community->getId());
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, CommunityMember::class, $useRelations);
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, CommunityMember::class, $useRelations, $withRelations);
}
public function getAllByUser(User $user, bool $useRelations = false): Generator
public function getAllByUser(User $user, bool $useRelations = false, array $withRelations = []): Generator
{
$select = new Select(\Container::$dbConnection);
$select->where('user_id', '=', $user->getId());
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, CommunityMember::class, $useRelations);
yield from \Container::$persistentDataManager->selectMultipleFromDb($select, CommunityMember::class, $useRelations, $withRelations);
}
public function getByCommunityAndUser(Community $community, User $user) : ?CommunityMember
+44
View File
@@ -0,0 +1,44 @@
<?php namespace RVR\Repository;
use Container;
use Generator;
use RVR\PersistentData\Model\Community;
use RVR\PersistentData\Model\Transaction;
use SokoWeb\Database\Query\Select;
class TransactionRepository
{
public function getById(int $id): ?Transaction
{
return Container::$persistentDataManager->selectFromDbById($id, Transaction::class);
}
public function getAllByCommunity(Community $community, bool $useRelations = false, array $withRelations = []): Generator
{
$select = $this->selectAllByCommunity($community);
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations);
}
public function countAllByCommunity(Community $community): int
{
return $this->selectAllByCommunity($community)->count();
}
public function getPagedByCommunity(Community $community, int $start, int $limit, bool $useRelations = false, array $withRelations = []): Generator
{
$select = new Select(Container::$dbConnection);
$select->where('community_id', '=', $community->getId());
$select->orderBy('time', 'DESC');
$select->limit($limit, $start);
yield from Container::$persistentDataManager->selectMultipleFromDb($select, Transaction::class, $useRelations, $withRelations);
}
private function selectAllByCommunity(Community $community)
{
$select = new Select(Container::$dbConnection, Transaction::getTable());
$select->where('community_id', '=', $community->getId());
return $select;
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
@section(main)
<h2>Account</h2>
<div class="box">
<div class="box compactBox">
<form id="accountForm" action="<?= Container::$routeCollection->getRoute('account-action')->generateLink() ?>" method="post" data-reload-on-success="true" data-observe-inputs="email,username,password_new,password_new_confirm,nickname,phone,id_number">
<?php if ($user['password'] !== null && $user['google_sub'] !== null): ?>
<p class="justify small">Please confirm your identity with your password or with Google to modify your account.</p>
+1 -1
View File
@@ -5,7 +5,7 @@
@section(main)
<h2>Authenticate with Google</h2>
<?php if (!$success): ?>
<div class="box">
<div class="box compactBox">
<p class="error justify">
<?php if (isset($errorText)): ?>
<?= $errorText ?>
+32 -14
View File
@@ -16,14 +16,15 @@
</div>
<div>
<h3 class="marginBottom">Currencies</h3>
<p>Main currency: <b><?= $community->getCurrency() ?></b></p>
<?php if (count($currencies) > 0): ?>
<p>Further currencies: <b>
<?php foreach ($currencies as $currency): ?>
<?php foreach ($currencies as $currency): ?>
<p>
<?php if ($currency->getId() === $community->getMainCurrencyId()): ?>
<b><?= $currency->getCode() ?></b>
<?php else: ?>
<a href="<?= Container::$routeCollection->getRoute('community-currency-exchange-rates')->generateLink(['communityId' => $community->getId(), 'code' => $currency->getCode()]) ?>"><?= $currency->getCode() ?></a>
<?php endforeach; ?>
</b></p>
<?php endif; ?>
<?php endif; ?>
</p>
<?php endforeach; ?>
<?php if ($editPermission): ?>
<hr>
<p><a href="<?= Container::$routeCollection->getRoute('community-currencies')->generateLink(['communityId' => $community->getId()]) ?>">Edit currencies</a></p>
@@ -40,19 +41,36 @@
<?php endif; ?>
</div>
<div>
<?php
$mainCurrencyCode = $community->getMainCurrency()->getCode();
$mainCurrencyRoundDigits = $community->getMainCurrency()->getRoundDigits();
?>
<h3 class="marginBottom">Finances</h3>
<table class="fullWidth">
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId()]) ?>">Transactions</a>
<table class="fullWidth marginTop">
<tr>
<td>You owe</td>
<td style="text-align: right; color: red;">0 <?= $community->getCurrency() ?></td>
<td class="bold">You owe</td>
<td class="mono red" style="text-align: right;"><?= number_format($debtBalance, $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td>
</tr>
<?php foreach ($debtUsers as $owe): ?>
<tr>
<td class="small"><?= $owe['payee']->getUser()->getDisplayName() ?></td>
<td class="small mono red" style="text-align: right;"><?= number_format($owe['amount'], $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td>
</tr>
<?php endforeach; ?>
<tr>
<td>You're owed</td>
<td style="text-align: right; color: green;">0 <?= $community->getCurrency() ?></td>
<td class="bold">You're owed</td>
<td class="mono green" style="text-align: right;"><?= number_format($outstandingBalance, $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td>
</tr>
<?php foreach ($outstandingUsers as $owe): ?>
<tr>
<td class="small"><?= $owe['payer']->getUser()->getDisplayName() ?></td>
<td class="small mono green" style="text-align: right;"><?= number_format($owe['amount'], $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td>
</tr>
<?php endforeach; ?>
<tr>
<td>Your balance</td>
<td style="text-align: right;">0 <?= $community->getCurrency() ?></td>
<td class="bold">Your balance</td>
<td class="mono <?= $balance < 0 ? 'red' : ($balance > 0 ? 'green' : '') ?>" style="text-align: right;;"><?= number_format($balance, $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td>
</tr>
</table>
</div>
+10 -5
View File
@@ -1,8 +1,11 @@
@extends(templates/layout_normal)
@section(main)
<h2><a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> - Edit currencies</h2>
<div class="box">
<h2>
<a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> »
Edit currencies
</h2>
<div class="box compactBox">
<table class="fullWidth">
<thead>
<tr>
@@ -21,9 +24,11 @@
<td>
<input type="number" form="editCurrency_<?= $currency->getId() ?>" class="text fullWidth" name="round_digits" value="<?= $currency->getRoundDigits() ?>" min="0" max="9" required>
</td>
<td style="text-align: right;">
<button type="submit" form="editCurrency_<?= $currency->getId() ?>" name="submit" class="small marginRight" disabled>Save</button><!--
--><button type="submit" form="deleteCurrency_<?= $currency->getId() ?>" class="small red">Delete</button>
<td style="text-align: right; font-size: 0;">
<button type="submit" form="editCurrency_<?= $currency->getId() ?>" name="submit" class="small" disabled>Save</button>
<?php if ($currency->getId() !== $community->getMainCurrencyId()): ?>
<button type="submit" form="deleteCurrency_<?= $currency->getId() ?>" class="small red marginLeft">Delete</button>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
+7 -3
View File
@@ -3,12 +3,13 @@
@section(main)
<h2>
<?php if (isset($community)): ?>
<a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> - Edit
<a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> »
Edit
<?php else: ?>
New community
<?php endif; ?>
</h2>
<div class="box">
<div class="box compactBox">
<?php
$formAction = isset($community) ?
Container::$routeCollection->getRoute('community-edit-action')->generateLink(['communityId' => $community->getId()]) :
@@ -16,7 +17,10 @@
?>
<form id="communityForm" action="<?= $formAction ?>" method="post" data-redirect-on-success="true">
<input type="text" class="text big fullWidth" name="name" placeholder="Name" value="<?= isset($community) ? $community->getName() : '' ?>" required>
<input type="text" class="text big fullWidth marginTop" name="currency" value="<?= isset($community) ? $community->getCurrency() : '' ?>" placeholder="Default currency" maxlength="3" required>
<?php if (!isset($community)): ?>
<input type="text" class="text big fullWidth marginTop" name="main_currency_code" placeholder="Main currency" maxlength="3" required>
<input type="number" class="text big fullWidth marginTop" name="main_currency_round_digits" placeholder="Main currency round digits" min="0" max="9" required>
<?php endif; ?>
<p id="communityFormError" class="formError justify marginTop"></p>
<div class="right marginTop">
<button type="submit" name="submit"><?= isset($community) ? 'Save' : 'Create' ?></button>
+5 -2
View File
@@ -5,8 +5,11 @@
@extends(templates/layout_normal)
@section(main)
<h2><a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> - Edit members</h2>
<div class="box">
<h2>
<a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> »
Edit members
</h2>
<div class="box compactBox">
<table class="fullWidth">
<thead>
<tr>
@@ -1,8 +1,11 @@
@extends(templates/layout_normal)
@section(main)
<h2><a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> - Exchange rates for <?= $currency->getCode() ?></h2>
<div class="box">
<h2>
<a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> »
Exchange rates for <?= $currency->getCode() ?>
</h2>
<div class="box compactBox">
<table class="fullWidth">
<thead>
<tr>
+53
View File
@@ -0,0 +1,53 @@
@extends(templates/layout_normal)
@section(main)
<h2>
<a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> »
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId()]) ?>">Transactions</a> »
<?php if (isset($transaction)): ?>
Edit transaction
<?php else: ?>
New transaction
<?php endif; ?>
</h2>
<div class="box compactBox">
<?php
$formAction = isset($transaction) ?
Container::$routeCollection->getRoute('community.transactions.edit-action')->generateLink(['communityId' => $community->getId(), 'transactionId' => $transaction->getId()]) :
Container::$routeCollection->getRoute('community.transactions.new-action')->generateLink(['communityId' => $community->getId()]);
?>
<form id="transactionForm" action="<?= $formAction ?>" method="post" data-redirect-on-success="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId()]) ?>">
<select class="big fullWidth" name="payer_user_id" required>
<option value="" hidden>[Payer]</option>
<?php foreach ($members as $member): ?>
<option value="<?= $member->getUser()->getId() ?>" <?= isset($transaction) && $transaction->getPayerUserId() === $member->getUser()->getId() ? 'selected' : '' ?>><?= $member->getUser()->getDisplayName() ?></option>
<?php endforeach; ?>
</select>
<select class="big fullWidth marginTop" name="payee_user_id">
<option value="">[Payee]</option>
<?php foreach ($members as $member): ?>
<option value="<?= $member->getUser()->getId() ?>" <?= isset($transaction) && $transaction->getPayeeUserId() === $member->getUser()->getId() ? 'selected' : '' ?>><?= $member->getUser()->getDisplayName() ?></option>
<?php endforeach; ?>
</select>
<input type="text" class="text big fullWidth marginTop" name="description" placeholder="Description" value="<?= isset($transaction) ? $transaction->getDescription() : '' ?>" required>
<input type="number" class="text big fullWidth marginTop" name="sum" placeholder="Sum" value="<?= isset($transaction) ? $transaction->getSum() : '' ?>" min="0" step="0.000000001" required>
<select class="big fullWidth marginTop" name="currency_id" required>
<option value="" hidden>[Currency]</option>
<?php foreach ($currencies as $currency): ?>
<option value="<?= $currency->getId() ?>" <?= isset($transaction) && $transaction->getCurrencyId() === $currency->getId() ? 'selected' : '' ?>><?= $currency->getCode() ?></option>
<?php endforeach; ?>
</select>
<input type="datetime-local" class="text big fullWidth marginTop" name="time" placeholder="Time" value="<?= isset($transaction) ? $transaction->getTimeDate()->format('Y-m-d\TH:i') : (new DateTime())->format('Y-m-d\TH:i') ?>" required>
<p class="formError justify marginTop"></p>
<div class="right marginTop" style="font-size: 0;">
<?php if (isset($transaction)): ?>
<button type="submit" form="deleteTransaction" class="red marginRight">Delete</button>
<?php endif; ?>
<button type="submit" name="submit"><?= isset($transaction) ? 'Save' : 'Create' ?></button>
</div>
</form>
<?php if (isset($transaction)): ?>
<form id="deleteTransaction" action="<?= Container::$routeCollection->getRoute('community.transactions.delete')->generateLink(['communityId' => $community->getId(), 'transactionId' => $transaction->getId()]) ?>" method="post" data-redirect-on-success="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId()]) ?>"></form>
<?php endif; ?>
</div>
@endsection
+62
View File
@@ -0,0 +1,62 @@
@extends(templates/layout_normal)
@section(main)
<h2>
<a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> »
Transactions
</h2>
<p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.transactions.new')->generateLink(['communityId' => $community->getId()]) ?>">New transaction</a></p>
<?php if ($pages > 1): ?>
<p class="paginateContainer marginTop">
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => 0]) ?>">«</a>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), '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(['communityId' => $community->getId(), 'page' => $i]) ?>"><?= $i + 1 ?></a>
<?php endif; ?>
<?php endfor; ?>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => min($pages - 1, $currentPage + 1)]) ?>">›</a>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => $pages - 1]) ?>">»</a>
</p>
<?php endif; ?>
<?php foreach ($transactions as $transaction): ?>
<a class="block" href="<?= Container::$routeCollection->getRoute('community.transactions.edit')->generateLink(['communityId' => $community->getId(), 'transactionId' => $transaction->getId()]) ?>">
<div class="box transaction">
<div>
<p style="font-weight: bold;"><?= $transaction->getDescription() ?></p>
<p class="small"><?= $transaction->getPayerUser()->getDisplayName() ?> ► <?= $transaction->getPayeeUser() ? $transaction->getPayeeUser()->getDisplayName() : '[common]' ?></p>
<p class="small"><?= $transaction->getTimeDate()->format('Y-m-d H:i') ?></p>
</div>
<div style="text-align: right;">
<h3><?= number_format($exchangeRateCalculator->calculate($transaction->getSum(), $transaction->getCurrency(), $transaction->getTimeDate()), $community->getMainCurrency()->getRoundDigits()) ?> <?= $community->getMainCurrency()->getCode() ?></h3>
<?php if ($community->getMainCurrencyId() !== $transaction->getCurrencyId()): ?>
<p style="color: #8e8e8e; font-weight: bold;"><?= number_format($transaction->getSum(), $transaction->getCurrency()->getRoundDigits()) ?> <?= $transaction->getCurrency()->getCode() ?></p>
<?php endif; ?>
</div>
</div>
</a>
<?php endforeach; ?>
<?php if ($pages > 1): ?>
<p class="paginateContainer marginTop">
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => 0]) ?>">«</a>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), '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(['communityId' => $community->getId(), 'page' => $i]) ?>"><?= $i + 1 ?></a>
<?php endif; ?>
<?php endfor; ?>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => min($pages - 1, $currentPage + 1)]) ?>">›</a>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => $pages - 1]) ?>">»</a>
</p>
<?php endif; ?>
<p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.transactions.new')->generateLink(['communityId' => $community->getId()]) ?>">New transaction</a></p>
@endsection
+1 -1
View File
@@ -2,7 +2,7 @@
@section(main)
<h2>Login up with Google</h2>
<div class="box">
<div class="box compactBox">
<p class="error justify"><?= $error ?></p>
</div>
@endsection
+1 -1
View File
@@ -2,7 +2,7 @@
@section(main)
<h2>Login</h2>
<div class="box">
<div class="box compactBox">
<form id="loginForm" action="<?= Container::$routeCollection->getRoute('login-action')->generateLink() ?>" method="post" data-redirect-on-success="<?= $redirectUrl ?>">
<input type="text" class="text big fullWidth" name="email" placeholder="Email address / Username" required autofocus>
<input type="password" class="text big fullWidth marginTop" name="password" placeholder="Password" required minlength="6">
+1 -1
View File
@@ -4,7 +4,7 @@
@section(main)
<h2>Request password reset</h2>
<div class="box">
<div class="box compactBox">
<form id="passwordResetForm" action="<?= Container::$routeCollection->getRoute('password-requestReset-action')->generateLink() ?>" method="post" data-redirect-on-success="<?= Container::$routeCollection->getRoute('password-requestReset.success')->generateLink() ?>">
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" value="<?= isset($email) ? $email : '' ?>" required autofocus>
<?php if (!empty($_ENV['RECAPTCHA_SITEKEY'])): ?>
@@ -2,7 +2,7 @@
@section(main)
<h2>Request password reset</h2>
<div class="box">
<div class="box compactBox">
<p class="justify">Password reset was successfully requested. Please check your email and click on the link to reset your password!</p>
</div>
@endsection
+1 -1
View File
@@ -2,7 +2,7 @@
@section(main)
<h2>Reset password</h2>
<div class="box">
<div class="box compactBox">
<?php if ($success) : ?>
<form id="resetPasswordForm" action="<?= Container::$routeCollection->getRoute('password-reset.action')->generateLink(['token' => $token]) ?>"" method="post" data-redirect-on-success="<?= $redirectUrl ?>">
<input type="email" class="text big fullWidth" name="email" placeholder="Email address" value="<?= $email ?>" disabled>
+1 -1
View File
@@ -2,7 +2,7 @@
@section(main)
<h2>OAuth error</h2>
<div class="box">
<div class="box compactBox">
<p class="error justify"><?= $error ?></p>
</div>
@endsection
+4 -3
View File
@@ -9,13 +9,14 @@
<?php if (preg_match('/^(http(s)?:)?\/\//', $_ENV['STATIC_ROOT']) === 1): ?>
<link href="<?= $_ENV['STATIC_ROOT'] ?>" rel="preconnect">
<?php endif; ?>
<link href="https://fonts.gstatic.com" rel="preconnect">
<link href="https://fonts.googleapis.com" rel="preconnect">
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
<?php if (!empty($_ENV['GOOGLE_ANALITICS_ID'])): ?>
<link href="https://www.googletagmanager.com" rel="preconnect">
<link href="https://www.google-analytics.com" rel="preconnect">
<?php endif; ?>
<link href="https://fonts.googleapis.com/css2?family=Oxygen:wght@400;700&amp;display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Oxygen+Mono:wght@400&amp;display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Oxygen:wght@400;700&amp;display=block" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Oxygen+Mono:wght@400&amp;display=block" rel="stylesheet">
<link href="<?= $_ENV['STATIC_ROOT'] ?>/css/rvr.css?rev=<?= REVISION ?>" rel="stylesheet">
@yields('externalCss')
@yields('inlineCss')
+9
View File
@@ -11,6 +11,7 @@ use RVR\Controller\OAuthController;
use RVR\Controller\UserController;
use RVR\Controller\UserSearchController;
use RVR\Controller\CommunityController;
use RVR\Controller\TransactionController;
use RVR\Repository\UserRepository;
require 'app.php';
@@ -76,6 +77,14 @@ Container::$routeCollection->group('communities', function (RouteCollection $rou
$routeCollection->post('community-currency-exchange-rates-edit', '{code}/edit', [CommunityController::class, 'saveCurrencyExchangeRate']);
$routeCollection->post('community-currency-exchange-rates-delete', '{code}/delete', [CommunityController::class, 'deleteCurrencyExchangeRate']);
});
$routeCollection->group('transactions', function (RouteCollection $routeCollection) {
$routeCollection->get('community.transactions', '', [TransactionController::class, 'getTransactions']);
$routeCollection->get('community.transactions.new', 'new', [TransactionController::class, 'getTransactionEdit']);
$routeCollection->post('community.transactions.new-action', 'new', [TransactionController::class, 'saveTransaction']);
$routeCollection->get('community.transactions.edit', '{transactionId}', [TransactionController::class, 'getTransactionEdit']);
$routeCollection->post('community.transactions.edit-action', '{transactionId}', [TransactionController::class, 'saveTransaction']);
$routeCollection->post('community.transactions.delete', '{transactionId}/delete', [TransactionController::class, 'deleteTransaction']);
});
});
});