mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-06 01:45:22 +00:00
Auto commit for release 'develop' on 2025-01-19
This commit is contained in:
@@ -234,7 +234,7 @@ abstract class Controller extends BaseController
|
||||
final protected function jsonApiList(string $key, LengthAwarePaginator $paginator, AbstractTransformer $transformer): array
|
||||
{
|
||||
$manager = new Manager();
|
||||
$baseUrl = sprintf('%s/api/v1/',request()->getSchemeAndHttpHost());
|
||||
$baseUrl = sprintf('%s/api/v1/', request()->getSchemeAndHttpHost());
|
||||
|
||||
// TODO add stuff to path?
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ class ShowController extends Controller
|
||||
|
||||
return response()
|
||||
->api($this->jsonApiObject(self::RESOURCE_KEY, $userGroup, $transformer))
|
||||
->header('Content-Type', self::CONTENT_TYPE);
|
||||
->header('Content-Type', self::CONTENT_TYPE)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* UpdateController.php
|
||||
* Copyright (c) 2025 james@firefly-iii.org.
|
||||
@@ -51,20 +52,20 @@ class UpdateController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
public function update(UpdateRequest $request, UserGroup $userGroup): JsonResponse {
|
||||
public function update(UpdateRequest $request, UserGroup $userGroup): JsonResponse
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
$data = $request->getData();
|
||||
$userGroup = $this->repository->update($userGroup, $data);
|
||||
$data = $request->getData();
|
||||
$userGroup = $this->repository->update($userGroup, $data);
|
||||
$userGroup->refresh();
|
||||
app('preferences')->mark();
|
||||
|
||||
$transformer = new UserGroupTransformer();
|
||||
$transformer = new UserGroupTransformer();
|
||||
$transformer->setParameters($this->parameters);
|
||||
|
||||
return response()
|
||||
->api($this->jsonApiObject(self::RESOURCE_KEY, $userGroup, $transformer))
|
||||
->header('Content-Type', self::CONTENT_TYPE)
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class DateRequest extends FormRequest
|
||||
return [
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'date' => $this->getCarbonDate('date'),
|
||||
'date' => $this->getCarbonDate('date'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Api\V1\Requests\Models\UserGroup;
|
||||
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\Rules\UserGroup\UniqueTitle;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
@@ -41,7 +40,7 @@ class UpdateRequest extends FormRequest
|
||||
public function getData(): array
|
||||
{
|
||||
$fields = [
|
||||
'title' => ['title', 'convertString'],
|
||||
'title' => ['title', 'convertString'],
|
||||
'native_currency_id' => ['native_currency_id', 'convertInteger'],
|
||||
'native_currency_code' => ['native_currency_code', 'convertString'],
|
||||
];
|
||||
@@ -58,7 +57,7 @@ class UpdateRequest extends FormRequest
|
||||
$userGroup = $this->route()->parameter('userGroup');
|
||||
|
||||
return [
|
||||
'title' => ['required','min:1','max:255'],
|
||||
'title' => ['required', 'min:1', 'max:255'],
|
||||
'native_currency_id' => 'exists:transaction_currencies,id',
|
||||
'native_currency_code' => 'exists:transaction_currencies,code',
|
||||
];
|
||||
|
||||
@@ -66,7 +66,7 @@ class ShowController extends Controller
|
||||
$default = 1 === $group->pivot->group_default;
|
||||
}
|
||||
$currency->userGroupEnabled = $enabled;
|
||||
$currency->userGroupNative = $default;
|
||||
$currency->userGroupNative = $default;
|
||||
|
||||
|
||||
$transformer = new CurrencyTransformer();
|
||||
|
||||
@@ -74,7 +74,7 @@ class IndexController extends Controller
|
||||
// order so default and enabled are on top:
|
||||
$collection = $collection->sortBy(
|
||||
static function (TransactionCurrency $currency) {
|
||||
$native = true === $currency->userGroupNative ? 0 : 1;
|
||||
$native = true === $currency->userGroupNative ? 0 : 1;
|
||||
$enabled = true === $currency->userGroupEnabled ? 0 : 1;
|
||||
|
||||
return sprintf('%s-%s-%s', $native, $enabled, $currency->code);
|
||||
|
||||
@@ -93,6 +93,7 @@ class InterestingMessage
|
||||
|
||||
return null !== $transactionGroupId && null !== $message;
|
||||
}
|
||||
|
||||
private function userGroupMessage(Request $request): bool
|
||||
{
|
||||
// get parameters from request.
|
||||
@@ -153,23 +154,24 @@ class InterestingMessage
|
||||
{
|
||||
// get parameters from request.
|
||||
$userGroupId = $request->get('user_group_id');
|
||||
$message = $request->get('message');
|
||||
$message = $request->get('message');
|
||||
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$user = auth()->user();
|
||||
|
||||
$userGroup = UserGroup::find($userGroupId);
|
||||
$valid = false;
|
||||
$userGroup = UserGroup::find($userGroupId);
|
||||
$valid = false;
|
||||
$memberships = $user->groupMemberships()->get();
|
||||
|
||||
/** @var GroupMembership $membership */
|
||||
foreach($memberships as $membership) {
|
||||
if($membership->userGroup->id === $userGroup->id) {
|
||||
foreach ($memberships as $membership) {
|
||||
if ($membership->userGroup->id === $userGroup->id) {
|
||||
$valid = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(false === $valid) {
|
||||
if (false === $valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class TransactionCurrency extends Model
|
||||
use ReturnsIntegerIdTrait;
|
||||
use SoftDeletes;
|
||||
|
||||
public ?bool $userGroupNative = null;
|
||||
public ?bool $userGroupNative = null;
|
||||
public ?bool $userGroupEnabled = null;
|
||||
protected $casts
|
||||
= [
|
||||
@@ -73,8 +73,8 @@ class TransactionCurrency extends Model
|
||||
public function refreshForUser(User $user): void
|
||||
{
|
||||
$current = $user->userGroup->currencies()->where('transaction_currencies.id', $this->id)->first();
|
||||
$native = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
|
||||
$this->userGroupNative = $native->id === $this->id;
|
||||
$native = app('amount')->getDefaultCurrencyByUserGroup($user->userGroup);
|
||||
$this->userGroupNative = $native->id === $this->id;
|
||||
$this->userGroupEnabled = null !== $current;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
/** @var GroupMembership $membership */
|
||||
foreach ($memberships as $membership) {
|
||||
/** @var null|User $user */
|
||||
$user = $membership->user()->first();
|
||||
$user = $membership->user()->first();
|
||||
if (null === $user) {
|
||||
continue;
|
||||
}
|
||||
@@ -79,8 +79,8 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
// all users are now moved away from user group.
|
||||
// time to DESTROY all objects.
|
||||
// we have to do this one by one to trigger the necessary observers :(
|
||||
$objects = ['availableBudgets', 'bills', 'budgets', 'categories', 'currencyExchangeRates', 'objectGroups',
|
||||
'recurrences', 'rules', 'ruleGroups', 'tags', 'transactionGroups', 'transactionJournals', 'piggyBanks', 'accounts', 'webhooks',
|
||||
$objects = ['availableBudgets', 'bills', 'budgets', 'categories', 'currencyExchangeRates', 'objectGroups',
|
||||
'recurrences', 'rules', 'ruleGroups', 'tags', 'transactionGroups', 'transactionJournals', 'piggyBanks', 'accounts', 'webhooks',
|
||||
];
|
||||
foreach ($objects as $object) {
|
||||
foreach ($userGroup->{$object}()->get() as $item) { // @phpstan-ignore-line
|
||||
@@ -107,7 +107,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
/** @var null|UserGroup $group */
|
||||
$group = $membership->userGroup()->first();
|
||||
if (null !== $group) {
|
||||
$groupId = $group->id;
|
||||
$groupId = $group->id;
|
||||
if (in_array($groupId, array_keys($set), true)) {
|
||||
continue;
|
||||
}
|
||||
@@ -132,14 +132,14 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
while ($exists && $loop < 10) {
|
||||
$existingGroup = $this->findByName($groupName);
|
||||
if (null === $existingGroup) {
|
||||
$exists = false;
|
||||
$exists = false;
|
||||
|
||||
/** @var null|UserGroup $existingGroup */
|
||||
$existingGroup = $this->store(['user' => $user, 'title' => $groupName]);
|
||||
}
|
||||
if (null !== $existingGroup) {
|
||||
// group already exists
|
||||
$groupName = sprintf('%s-%s', $user->email, substr(sha1(rand(1000, 9999) . microtime()), 0, 4));
|
||||
$groupName = sprintf('%s-%s', $user->email, substr(sha1(rand(1000, 9999).microtime()), 0, 4));
|
||||
}
|
||||
++$loop;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
$data['user'] = $this->user;
|
||||
|
||||
/** @var UserGroupFactory $factory */
|
||||
$factory = app(UserGroupFactory::class);
|
||||
$factory = app(UserGroupFactory::class);
|
||||
|
||||
return $factory->create($data);
|
||||
}
|
||||
@@ -187,7 +187,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
return $this->user->groupMemberships()->where('user_group_id', $groupId)->get();
|
||||
}
|
||||
|
||||
public function setUser(null | Authenticatable | User $user): void
|
||||
public function setUser(null|Authenticatable|User $user): void
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__));
|
||||
if ($user instanceof User) {
|
||||
@@ -199,9 +199,10 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
{
|
||||
$userGroup->title = $data['title'];
|
||||
$userGroup->save();
|
||||
$currency = null;
|
||||
$currency = null;
|
||||
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
|
||||
if (array_key_exists('native_currency_code', $data)) {
|
||||
$repository->setUser($this->user);
|
||||
@@ -227,11 +228,11 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
*/
|
||||
public function updateMembership(UserGroup $userGroup, array $data): UserGroup
|
||||
{
|
||||
$owner = UserRole::whereTitle(UserRoleEnum::OWNER)->first();
|
||||
$owner = UserRole::whereTitle(UserRoleEnum::OWNER)->first();
|
||||
app('log')->debug('in update membership');
|
||||
|
||||
/** @var null|User $user */
|
||||
$user = null;
|
||||
$user = null;
|
||||
if (array_key_exists('id', $data)) {
|
||||
/** @var null|User $user */
|
||||
$user = User::find($data['id']);
|
||||
@@ -270,8 +271,9 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
if ($membershipCount > 1) {
|
||||
// group has multiple members. How many are owner, except the user we're editing now?
|
||||
$ownerCount = $userGroup->groupMemberships()
|
||||
->where('user_role_id', $owner->id)
|
||||
->where('user_id', '!=', $user->id)->count();
|
||||
->where('user_role_id', $owner->id)
|
||||
->where('user_id', '!=', $user->id)->count()
|
||||
;
|
||||
// if there are no other owners and the current users does not get or keep the owner role, refuse.
|
||||
if (
|
||||
0 === $ownerCount
|
||||
|
||||
@@ -180,11 +180,11 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
$hasId = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
return $entry->id === $current->id;
|
||||
});
|
||||
$isNative = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
$isNative = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
return 1 === (int) $entry->pivot->group_default && $entry->id === $current->id;
|
||||
});
|
||||
$current->userGroupEnabled = $hasId;
|
||||
$current->userGroupNative = $isNative;
|
||||
$current->userGroupNative = $isNative;
|
||||
|
||||
return $current;
|
||||
});
|
||||
@@ -195,7 +195,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
$all = $this->userGroup->currencies()->orderBy('code', 'ASC')->withPivot(['group_default'])->get();
|
||||
$all->map(static function (TransactionCurrency $current) { // @phpstan-ignore-line
|
||||
$current->userGroupEnabled = true;
|
||||
$current->userGroupNative = 1 === (int) $current->pivot->group_default;
|
||||
$current->userGroupNative = 1 === (int) $current->pivot->group_default;
|
||||
|
||||
return $current;
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ class CurrencyUpdateService
|
||||
$currency->decimal_places = $data['decimal_places'];
|
||||
}
|
||||
$currency->userGroupEnabled = null;
|
||||
$currency->userGroupNative = null;
|
||||
$currency->userGroupNative = null;
|
||||
$currency->save();
|
||||
|
||||
return $currency;
|
||||
|
||||
@@ -175,9 +175,10 @@ class Amount
|
||||
{
|
||||
return $this->getNativeCurrencyByUserGroup($userGroup);
|
||||
}
|
||||
|
||||
public function getNativeCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('getNativeCurrencyByGroup');
|
||||
$cache->addProperty($userGroup->id);
|
||||
if ($cache->has()) {
|
||||
|
||||
@@ -86,8 +86,8 @@ class ExportDataGenerator
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->accounts = new Collection();
|
||||
$this->start = today(config('app.timezone'));
|
||||
$this->accounts = new Collection();
|
||||
$this->start = today(config('app.timezone'));
|
||||
$this->start->subYear();
|
||||
$this->end = today(config('app.timezone'));
|
||||
$this->exportTransactions = false;
|
||||
@@ -145,7 +145,7 @@ class ExportDataGenerator
|
||||
*/
|
||||
private function exportAccounts(): string
|
||||
{
|
||||
$header = [
|
||||
$header = [
|
||||
'user_id',
|
||||
'account_id',
|
||||
'created_at',
|
||||
@@ -166,7 +166,7 @@ class ExportDataGenerator
|
||||
];
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$allAccounts = $repository->getAccountsByType([]);
|
||||
$records = [];
|
||||
@@ -196,7 +196,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -234,8 +234,8 @@ class ExportDataGenerator
|
||||
/** @var BillRepositoryInterface $repository */
|
||||
$repository = app(BillRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
$bills = $repository->getBills();
|
||||
$header = [
|
||||
$bills = $repository->getBills();
|
||||
$header = [
|
||||
'user_id',
|
||||
'bill_id',
|
||||
'created_at',
|
||||
@@ -249,7 +249,7 @@ class ExportDataGenerator
|
||||
'skip',
|
||||
'active',
|
||||
];
|
||||
$records = [];
|
||||
$records = [];
|
||||
|
||||
/** @var Bill $bill */
|
||||
foreach ($bills as $bill) {
|
||||
@@ -270,7 +270,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -300,7 +300,7 @@ class ExportDataGenerator
|
||||
*/
|
||||
private function exportBudgets(): string
|
||||
{
|
||||
$header = [
|
||||
$header = [
|
||||
'user_id',
|
||||
'budget_id',
|
||||
'name',
|
||||
@@ -314,9 +314,9 @@ class ExportDataGenerator
|
||||
|
||||
$budgetRepos = app(BudgetRepositoryInterface::class);
|
||||
$budgetRepos->setUser($this->user);
|
||||
$limitRepos = app(BudgetLimitRepositoryInterface::class);
|
||||
$budgets = $budgetRepos->getBudgets();
|
||||
$records = [];
|
||||
$limitRepos = app(BudgetLimitRepositoryInterface::class);
|
||||
$budgets = $budgetRepos->getBudgets();
|
||||
$records = [];
|
||||
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
@@ -339,7 +339,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -369,10 +369,10 @@ class ExportDataGenerator
|
||||
*/
|
||||
private function exportCategories(): string
|
||||
{
|
||||
$header = ['user_id', 'category_id', 'created_at', 'updated_at', 'name'];
|
||||
$header = ['user_id', 'category_id', 'created_at', 'updated_at', 'name'];
|
||||
|
||||
/** @var CategoryRepositoryInterface $catRepos */
|
||||
$catRepos = app(CategoryRepositoryInterface::class);
|
||||
$catRepos = app(CategoryRepositoryInterface::class);
|
||||
$catRepos->setUser($this->user);
|
||||
|
||||
$records = [];
|
||||
@@ -390,7 +390,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -421,14 +421,14 @@ class ExportDataGenerator
|
||||
private function exportPiggies(): string
|
||||
{
|
||||
/** @var PiggyBankRepositoryInterface $piggyRepos */
|
||||
$piggyRepos = app(PiggyBankRepositoryInterface::class);
|
||||
$piggyRepos = app(PiggyBankRepositoryInterface::class);
|
||||
$piggyRepos->setUser($this->user);
|
||||
|
||||
/** @var AccountRepositoryInterface $accountRepos */
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
$accountRepos->setUser($this->user);
|
||||
|
||||
$header = [
|
||||
$header = [
|
||||
'user_id',
|
||||
'piggy_bank_id',
|
||||
'created_at',
|
||||
@@ -444,8 +444,8 @@ class ExportDataGenerator
|
||||
'order',
|
||||
'active',
|
||||
];
|
||||
$records = [];
|
||||
$piggies = $piggyRepos->getPiggyBanks();
|
||||
$records = [];
|
||||
$piggies = $piggyRepos->getPiggyBanks();
|
||||
|
||||
/** @var PiggyBank $piggy */
|
||||
foreach ($piggies as $piggy) {
|
||||
@@ -470,7 +470,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -503,7 +503,7 @@ class ExportDataGenerator
|
||||
/** @var RecurringRepositoryInterface $recurringRepos */
|
||||
$recurringRepos = app(RecurringRepositoryInterface::class);
|
||||
$recurringRepos->setUser($this->user);
|
||||
$header = [
|
||||
$header = [
|
||||
// recurrence:
|
||||
'user_id', 'recurrence_id', 'row_contains', 'created_at', 'updated_at', 'type', 'title', 'description', 'first_date', 'repeat_until', 'latest_date', 'repetitions', 'apply_rules', 'active',
|
||||
|
||||
@@ -512,8 +512,8 @@ class ExportDataGenerator
|
||||
// transactions + meta:
|
||||
'currency_code', 'foreign_currency_code', 'source_name', 'source_type', 'destination_name', 'destination_type', 'amount', 'foreign_amount', 'category', 'budget', 'piggy_bank', 'tags',
|
||||
];
|
||||
$records = [];
|
||||
$recurrences = $recurringRepos->getAll();
|
||||
$records = [];
|
||||
$recurrences = $recurringRepos->getAll();
|
||||
|
||||
/** @var Recurrence $recurrence */
|
||||
foreach ($recurrences as $recurrence) {
|
||||
@@ -546,7 +546,7 @@ class ExportDataGenerator
|
||||
$piggyBankId = $recurringRepos->getPiggyBank($transaction);
|
||||
$tags = $recurringRepos->getTags($transaction);
|
||||
|
||||
$records[] = [
|
||||
$records[] = [
|
||||
// recurrence
|
||||
$this->user->id,
|
||||
$recurrence->id,
|
||||
@@ -562,7 +562,7 @@ class ExportDataGenerator
|
||||
}
|
||||
}
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -599,8 +599,8 @@ class ExportDataGenerator
|
||||
'action_type', 'action_value', 'action_order', 'action_active', 'action_stop_processing'];
|
||||
$ruleRepos = app(RuleRepositoryInterface::class);
|
||||
$ruleRepos->setUser($this->user);
|
||||
$rules = $ruleRepos->getAll();
|
||||
$records = [];
|
||||
$rules = $ruleRepos->getAll();
|
||||
$records = [];
|
||||
|
||||
/** @var Rule $rule */
|
||||
foreach ($rules as $rule) {
|
||||
@@ -639,7 +639,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -669,12 +669,12 @@ class ExportDataGenerator
|
||||
*/
|
||||
private function exportTags(): string
|
||||
{
|
||||
$header = ['user_id', 'tag_id', 'created_at', 'updated_at', 'tag', 'date', 'description', 'latitude', 'longitude', 'zoom_level'];
|
||||
$header = ['user_id', 'tag_id', 'created_at', 'updated_at', 'tag', 'date', 'description', 'latitude', 'longitude', 'zoom_level'];
|
||||
|
||||
$tagRepos = app(TagRepositoryInterface::class);
|
||||
$tagRepos->setUser($this->user);
|
||||
$tags = $tagRepos->get();
|
||||
$records = [];
|
||||
$tags = $tagRepos->get();
|
||||
$records = [];
|
||||
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
@@ -693,7 +693,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
@@ -732,26 +732,26 @@ class ExportDataGenerator
|
||||
private function exportTransactions(): string
|
||||
{
|
||||
// TODO better place for keys?
|
||||
$header = ['user_id', 'group_id', 'journal_id', 'created_at', 'updated_at', 'group_title', 'type', 'currency_code', 'amount', 'foreign_currency_code', 'foreign_amount', 'native_currency_code', 'native_amount', 'native_foreign_amount', 'description', 'date', 'source_name', 'source_iban', 'source_type', 'destination_name', 'destination_iban', 'destination_type', 'reconciled', 'category', 'budget', 'bill', 'tags', 'notes'];
|
||||
$header = ['user_id', 'group_id', 'journal_id', 'created_at', 'updated_at', 'group_title', 'type', 'currency_code', 'amount', 'foreign_currency_code', 'foreign_amount', 'native_currency_code', 'native_amount', 'native_foreign_amount', 'description', 'date', 'source_name', 'source_iban', 'source_type', 'destination_name', 'destination_iban', 'destination_type', 'reconciled', 'category', 'budget', 'bill', 'tags', 'notes'];
|
||||
|
||||
$metaFields = config('firefly.journal_meta_fields');
|
||||
$header = array_merge($header, $metaFields);
|
||||
$default = Amount::getDefaultCurrency();
|
||||
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($this->start, $this->end)->withAccountInformation()->withCategoryInformation()->withBillInformation()->withBudgetInformation()->withTagInformation()->withNotes();
|
||||
if (0 !== $this->accounts->count()) {
|
||||
$collector->setAccounts($this->accounts);
|
||||
}
|
||||
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
// get repository for meta data:
|
||||
$repository = app(TransactionGroupRepositoryInterface::class);
|
||||
$repository->setUser($this->user);
|
||||
|
||||
$records = [];
|
||||
$records = [];
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
@@ -776,7 +776,7 @@ class ExportDataGenerator
|
||||
$nativeForeignAmount = null === $journal['native_foreign_amount'] ? null : Steam::bcround(Steam::negative($journal['native_foreign_amount'], $default->decimal_places));
|
||||
}
|
||||
|
||||
$records[] = [
|
||||
$records[] = [
|
||||
$journal['user_id'], $journal['transaction_group_id'], $journal['transaction_journal_id'], $journal['created_at']->toAtomString(), $journal['updated_at']->toAtomString(), $journal['transaction_group_title'], $journal['transaction_type_type'],
|
||||
// amounts and currencies
|
||||
$journal['currency_code'], $amount, $journal['foreign_currency_code'], $foreignAmount, $default->code, $nativeAmount, $nativeForeignAmount,
|
||||
@@ -801,7 +801,7 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
// load the CSV document from a string
|
||||
$csv = Writer::createFromString();
|
||||
$csv = Writer::createFromString();
|
||||
|
||||
// insert the header
|
||||
try {
|
||||
|
||||
@@ -82,7 +82,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
[$openingBalance, $nativeOpeningBalance, $openingBalanceDate] = $this->getOpeningBalance($account, $accountType, $convertToNative);
|
||||
[$interest, $interestPeriod] = $this->getInterest($account, $accountType);
|
||||
|
||||
$default = $this->default;
|
||||
$default = $this->default;
|
||||
if (!$this->convertToNative) {
|
||||
// reset default currency to NULL, not interesting.
|
||||
$default = null;
|
||||
|
||||
@@ -62,8 +62,8 @@ class AvailableBudgetTransformer extends AbstractTransformer
|
||||
$this->repository->setUser($availableBudget->user);
|
||||
|
||||
$currency = $availableBudget->transactionCurrency;
|
||||
$default = $this->default;
|
||||
if(!$this->convertToNative) {
|
||||
$default = $this->default;
|
||||
if (!$this->convertToNative) {
|
||||
$default = null;
|
||||
}
|
||||
$data = [
|
||||
@@ -87,7 +87,7 @@ class AvailableBudgetTransformer extends AbstractTransformer
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/available_budgets/' . $availableBudget->id,
|
||||
'uri' => '/available_budgets/'.$availableBudget->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -64,23 +64,23 @@ class BillTransformer extends AbstractTransformer
|
||||
*/
|
||||
public function transform(Bill $bill): array
|
||||
{
|
||||
$default = $this->parameters->get('defaultCurrency') ?? $this->default;
|
||||
$default = $this->parameters->get('defaultCurrency') ?? $this->default;
|
||||
|
||||
$paidData = $this->paidData($bill);
|
||||
$lastPaidDate = $this->getLastPaidDate($paidData);
|
||||
$start = $this->parameters->get('start') ?? today()->subYears(10);
|
||||
$end = $this->parameters->get('end') ?? today()->addYears(10);
|
||||
$payDates = $this->calculator->getPayDates($start, $end, $bill->date, $bill->repeat_freq, $bill->skip, $lastPaidDate);
|
||||
$currency = $bill->transactionCurrency;
|
||||
$notes = $this->repository->getNoteText($bill);
|
||||
$notes = '' === $notes ? null : $notes;
|
||||
$objectGroupId = null;
|
||||
$objectGroupOrder = null;
|
||||
$objectGroupTitle = null;
|
||||
$paidData = $this->paidData($bill);
|
||||
$lastPaidDate = $this->getLastPaidDate($paidData);
|
||||
$start = $this->parameters->get('start') ?? today()->subYears(10);
|
||||
$end = $this->parameters->get('end') ?? today()->addYears(10);
|
||||
$payDates = $this->calculator->getPayDates($start, $end, $bill->date, $bill->repeat_freq, $bill->skip, $lastPaidDate);
|
||||
$currency = $bill->transactionCurrency;
|
||||
$notes = $this->repository->getNoteText($bill);
|
||||
$notes = '' === $notes ? null : $notes;
|
||||
$objectGroupId = null;
|
||||
$objectGroupOrder = null;
|
||||
$objectGroupTitle = null;
|
||||
$this->repository->setUser($bill->user);
|
||||
|
||||
/** @var null|ObjectGroup $objectGroup */
|
||||
$objectGroup = $bill->objectGroups->first();
|
||||
$objectGroup = $bill->objectGroups->first();
|
||||
if (null !== $objectGroup) {
|
||||
$objectGroupId = $objectGroup->id;
|
||||
$objectGroupOrder = $objectGroup->order;
|
||||
@@ -90,7 +90,7 @@ class BillTransformer extends AbstractTransformer
|
||||
$paidDataFormatted = [];
|
||||
$payDatesFormatted = [];
|
||||
foreach ($paidData as $object) {
|
||||
$date = Carbon::createFromFormat('!Y-m-d', $object['date'], config('app.timezone'));
|
||||
$date = Carbon::createFromFormat('!Y-m-d', $object['date'], config('app.timezone'));
|
||||
if (null === $date) {
|
||||
$date = today(config('app.timezone'));
|
||||
}
|
||||
@@ -99,24 +99,24 @@ class BillTransformer extends AbstractTransformer
|
||||
}
|
||||
|
||||
foreach ($payDates as $string) {
|
||||
$date = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone'));
|
||||
$date = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone'));
|
||||
if (null === $date) {
|
||||
$date = today(config('app.timezone'));
|
||||
}
|
||||
$payDatesFormatted[] = $date->toAtomString();
|
||||
}
|
||||
// next expected match
|
||||
$nem = null;
|
||||
$nemDate = null;
|
||||
$nemDiff = trans('firefly.not_expected_period');
|
||||
$firstPayDate = $payDates[0] ?? null;
|
||||
$nem = null;
|
||||
$nemDate = null;
|
||||
$nemDiff = trans('firefly.not_expected_period');
|
||||
$firstPayDate = $payDates[0] ?? null;
|
||||
|
||||
if (null !== $firstPayDate) {
|
||||
$nemDate = Carbon::createFromFormat('!Y-m-d', $firstPayDate, config('app.timezone'));
|
||||
if (null === $nemDate) {
|
||||
$nemDate = today(config('app.timezone'));
|
||||
}
|
||||
$nem = $nemDate->toAtomString();
|
||||
$nem = $nemDate->toAtomString();
|
||||
|
||||
// nullify again when it's outside the current view range.
|
||||
if (
|
||||
@@ -137,7 +137,7 @@ class BillTransformer extends AbstractTransformer
|
||||
|
||||
$current = $payDatesFormatted[0] ?? null;
|
||||
if (null !== $current && !$nemDate->isToday()) {
|
||||
$temp2 = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
|
||||
$temp2 = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
|
||||
if (null === $temp2) {
|
||||
$temp2 = today(config('app.timezone'));
|
||||
}
|
||||
@@ -158,32 +158,32 @@ class BillTransformer extends AbstractTransformer
|
||||
'native_currency_code' => $default?->code,
|
||||
'native_currency_symbol' => $default?->symbol,
|
||||
'native_currency_decimal_places' => $default?->decimal_places,
|
||||
'name' => $bill->name,
|
||||
'amount_min' => app('steam')->bcround($bill->amount_min, $currency->decimal_places),
|
||||
'amount_max' => app('steam')->bcround($bill->amount_max, $currency->decimal_places),
|
||||
'native_amount_min' => $this->convertToNative ? app('steam')->bcround($bill->native_amount_min, $default->decimal_places) : null,
|
||||
'native_amount_max' => $this->convertToNative ? app('steam')->bcround($bill->native_amount_max, $default->decimal_places) : null,
|
||||
'date' => $bill->date->toAtomString(),
|
||||
'end_date' => $bill->end_date?->toAtomString(),
|
||||
'extension_date' => $bill->extension_date?->toAtomString(),
|
||||
'repeat_freq' => $bill->repeat_freq,
|
||||
'skip' => $bill->skip,
|
||||
'active' => $bill->active,
|
||||
'order' => $bill->order,
|
||||
'notes' => $notes,
|
||||
'object_group_id' => null !== $objectGroupId ? (string) $objectGroupId : null,
|
||||
'object_group_order' => $objectGroupOrder,
|
||||
'object_group_title' => $objectGroupTitle,
|
||||
'name' => $bill->name,
|
||||
'amount_min' => app('steam')->bcround($bill->amount_min, $currency->decimal_places),
|
||||
'amount_max' => app('steam')->bcround($bill->amount_max, $currency->decimal_places),
|
||||
'native_amount_min' => $this->convertToNative ? app('steam')->bcround($bill->native_amount_min, $default->decimal_places) : null,
|
||||
'native_amount_max' => $this->convertToNative ? app('steam')->bcround($bill->native_amount_max, $default->decimal_places) : null,
|
||||
'date' => $bill->date->toAtomString(),
|
||||
'end_date' => $bill->end_date?->toAtomString(),
|
||||
'extension_date' => $bill->extension_date?->toAtomString(),
|
||||
'repeat_freq' => $bill->repeat_freq,
|
||||
'skip' => $bill->skip,
|
||||
'active' => $bill->active,
|
||||
'order' => $bill->order,
|
||||
'notes' => $notes,
|
||||
'object_group_id' => null !== $objectGroupId ? (string) $objectGroupId : null,
|
||||
'object_group_order' => $objectGroupOrder,
|
||||
'object_group_title' => $objectGroupTitle,
|
||||
|
||||
// these fields need work:
|
||||
'next_expected_match' => $nem,
|
||||
'next_expected_match_diff' => $nemDiff,
|
||||
'pay_dates' => $payDatesFormatted,
|
||||
'paid_dates' => $paidDataFormatted,
|
||||
'links' => [
|
||||
'next_expected_match' => $nem,
|
||||
'next_expected_match_diff' => $nemDiff,
|
||||
'pay_dates' => $payDatesFormatted,
|
||||
'paid_dates' => $paidDataFormatted,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/bills/' . $bill->id,
|
||||
'uri' => '/bills/'.$bill->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -205,13 +205,13 @@ class BillTransformer extends AbstractTransformer
|
||||
// 2023-07-18 this particular date is used to search for the last paid date.
|
||||
// 2023-07-18 the cloned $searchDate is used to grab the correct transactions.
|
||||
/** @var Carbon $start */
|
||||
$start = clone $this->parameters->get('start');
|
||||
$searchStart = clone $start;
|
||||
$start = clone $this->parameters->get('start');
|
||||
$searchStart = clone $start;
|
||||
$start->subDay();
|
||||
|
||||
/** @var Carbon $end */
|
||||
$end = clone $this->parameters->get('end');
|
||||
$searchEnd = clone $end;
|
||||
$end = clone $this->parameters->get('end');
|
||||
$searchEnd = clone $end;
|
||||
|
||||
// move the search dates to the start of the day.
|
||||
$searchStart->startOfDay();
|
||||
@@ -221,7 +221,7 @@ class BillTransformer extends AbstractTransformer
|
||||
app('log')->debug(sprintf('Search parameters are: start: %s', $searchStart->format('Y-m-d')));
|
||||
|
||||
// Get from database when bill was paid.
|
||||
$set = $this->repository->getPaidDatesInRange($bill, $searchStart, $searchEnd);
|
||||
$set = $this->repository->getPaidDatesInRange($bill, $searchStart, $searchEnd);
|
||||
app('log')->debug(sprintf('Count %d entries in getPaidDatesInRange()', $set->count()));
|
||||
|
||||
// Grab from array the most recent payment. If none exist, fall back to the start date and pretend *that* was the last paid date.
|
||||
@@ -230,7 +230,7 @@ class BillTransformer extends AbstractTransformer
|
||||
app('log')->debug(sprintf('Result of lastPaidDate is %s', $lastPaidDate->format('Y-m-d')));
|
||||
|
||||
// At this point the "next match" is exactly after the last time the bill was paid.
|
||||
$result = [];
|
||||
$result = [];
|
||||
foreach ($set as $entry) {
|
||||
$result[] = [
|
||||
'transaction_group_id' => (string) $entry->transaction_group_id,
|
||||
|
||||
@@ -66,8 +66,8 @@ class BudgetLimitTransformer extends AbstractTransformer
|
||||
*/
|
||||
public function transform(BudgetLimit $budgetLimit): array
|
||||
{
|
||||
$repository = app(OperationsRepository::class);
|
||||
$limitRepos = app(BudgetLimitRepositoryInterface::class);
|
||||
$repository = app(OperationsRepository::class);
|
||||
$limitRepos = app(BudgetLimitRepositoryInterface::class);
|
||||
$repository->setUser($budgetLimit->budget->user);
|
||||
$limitRepos->setUser($budgetLimit->budget->user);
|
||||
$expenses = $repository->sumExpenses(
|
||||
@@ -93,8 +93,8 @@ class BudgetLimitTransformer extends AbstractTransformer
|
||||
$currencySymbol = $currency->symbol;
|
||||
$currencyDecimalPlaces = $currency->decimal_places;
|
||||
}
|
||||
$amount = app('steam')->bcround($amount, $currencyDecimalPlaces);
|
||||
$default = $this->default;
|
||||
$amount = app('steam')->bcround($amount, $currencyDecimalPlaces);
|
||||
$default = $this->default;
|
||||
if (!$this->convertToNative) {
|
||||
$default = null;
|
||||
}
|
||||
@@ -124,7 +124,7 @@ class BudgetLimitTransformer extends AbstractTransformer
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/budgets/limits/' . $budgetLimit->id,
|
||||
'uri' => '/budgets/limits/'.$budgetLimit->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -70,23 +70,23 @@ class BudgetTransformer extends AbstractTransformer
|
||||
}
|
||||
|
||||
// info for auto budget.
|
||||
$abType = null;
|
||||
$abAmount = null;
|
||||
$abNative = null;
|
||||
$abPeriod = null;
|
||||
$notes = $this->repository->getNoteText($budget);
|
||||
$abType = null;
|
||||
$abAmount = null;
|
||||
$abNative = null;
|
||||
$abPeriod = null;
|
||||
$notes = $this->repository->getNoteText($budget);
|
||||
|
||||
$types = [
|
||||
$types = [
|
||||
AutoBudgetType::AUTO_BUDGET_RESET->value => 'reset',
|
||||
AutoBudgetType::AUTO_BUDGET_ROLLOVER->value => 'rollover',
|
||||
AutoBudgetType::AUTO_BUDGET_ADJUSTED->value => 'adjusted',
|
||||
];
|
||||
$currency = $autoBudget?->transactionCurrency;
|
||||
$default = $this->default;
|
||||
$currency = $autoBudget?->transactionCurrency;
|
||||
$default = $this->default;
|
||||
if (!$this->convertToNative) {
|
||||
$default = null;
|
||||
}
|
||||
if(null === $autoBudget) {
|
||||
if (null === $autoBudget) {
|
||||
$currency = $default;
|
||||
}
|
||||
if (null !== $autoBudget) {
|
||||
@@ -97,15 +97,15 @@ class BudgetTransformer extends AbstractTransformer
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (string) $budget->id,
|
||||
'created_at' => $budget->created_at->toAtomString(),
|
||||
'updated_at' => $budget->updated_at->toAtomString(),
|
||||
'active' => $budget->active,
|
||||
'name' => $budget->name,
|
||||
'order' => $budget->order,
|
||||
'notes' => $notes,
|
||||
'auto_budget_type' => $abType,
|
||||
'auto_budget_period' => $abPeriod,
|
||||
'id' => (string) $budget->id,
|
||||
'created_at' => $budget->created_at->toAtomString(),
|
||||
'updated_at' => $budget->updated_at->toAtomString(),
|
||||
'active' => $budget->active,
|
||||
'name' => $budget->name,
|
||||
'order' => $budget->order,
|
||||
'notes' => $notes,
|
||||
'auto_budget_type' => $abType,
|
||||
'auto_budget_period' => $abPeriod,
|
||||
|
||||
'currency_id' => null === $autoBudget ? null : (string) $autoBudget->transactionCurrency->id,
|
||||
'currency_code' => $autoBudget?->transactionCurrency->code,
|
||||
@@ -125,7 +125,7 @@ class BudgetTransformer extends AbstractTransformer
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/budgets/' . $budget->id,
|
||||
'uri' => '/budgets/'.$budget->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -60,10 +60,10 @@ class CategoryTransformer extends AbstractTransformer
|
||||
$this->opsRepository->setUser($category->user);
|
||||
$this->repository->setUser($category->user);
|
||||
|
||||
$spent = [];
|
||||
$earned = [];
|
||||
$start = $this->parameters->get('start');
|
||||
$end = $this->parameters->get('end');
|
||||
$spent = [];
|
||||
$earned = [];
|
||||
$start = $this->parameters->get('start');
|
||||
$end = $this->parameters->get('end');
|
||||
if (null !== $start && null !== $end) {
|
||||
$earned = $this->beautify($this->opsRepository->sumIncome($start, $end, null, new Collection([$category])));
|
||||
$spent = $this->beautify($this->opsRepository->sumExpenses($start, $end, null, new Collection([$category])));
|
||||
@@ -72,7 +72,7 @@ class CategoryTransformer extends AbstractTransformer
|
||||
if (!$this->convertToNative) {
|
||||
$default = null;
|
||||
}
|
||||
$notes = $this->repository->getNoteText($category);
|
||||
$notes = $this->repository->getNoteText($category);
|
||||
|
||||
return [
|
||||
'id' => $category->id,
|
||||
@@ -89,7 +89,7 @@ class CategoryTransformer extends AbstractTransformer
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/categories/' . $category->id,
|
||||
'uri' => '/categories/'.$category->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -40,7 +40,7 @@ class CurrencyTransformer extends AbstractTransformer
|
||||
'id' => $currency->id,
|
||||
'created_at' => $currency->created_at->toAtomString(),
|
||||
'updated_at' => $currency->updated_at->toAtomString(),
|
||||
'native' => $currency->userGroupNative,
|
||||
'native' => $currency->userGroupNative,
|
||||
'enabled' => $currency->userGroupEnabled,
|
||||
'name' => $currency->name,
|
||||
'code' => $currency->code,
|
||||
|
||||
@@ -83,13 +83,13 @@ class UserGroupTransformer extends AbstractTransformer
|
||||
|
||||
private function mergeMemberships(): void
|
||||
{
|
||||
$new = [];
|
||||
$new = [];
|
||||
foreach ($this->memberships as $groupId => $members) {
|
||||
$new[$groupId] ??= [];
|
||||
|
||||
foreach ($members as $member) {
|
||||
$mail = $member['user_email'];
|
||||
$new[$groupId][$mail] ??= [
|
||||
$new[$groupId][$mail] ??= [
|
||||
'user_id' => $member['user_id'],
|
||||
'user_email' => $member['user_email'],
|
||||
'you' => $member['you'],
|
||||
@@ -107,6 +107,7 @@ class UserGroupTransformer extends AbstractTransformer
|
||||
public function transform(UserGroup $userGroup): array
|
||||
{
|
||||
$currency = Amount::getDefaultCurrencyByUserGroup($userGroup);
|
||||
|
||||
return [
|
||||
'id' => $userGroup->id,
|
||||
'created_at' => $userGroup->created_at->toAtomString(),
|
||||
|
||||
@@ -46,7 +46,7 @@ class CurrencyTransformer extends AbstractTransformer
|
||||
'id' => $currency->id,
|
||||
'created_at' => $currency->created_at->toAtomString(),
|
||||
'updated_at' => $currency->updated_at->toAtomString(),
|
||||
'native' => $currency->userGroupNative,
|
||||
'native' => $currency->userGroupNative,
|
||||
'enabled' => $currency->userGroupEnabled,
|
||||
'name' => $currency->name,
|
||||
'code' => $currency->code,
|
||||
|
||||
Reference in New Issue
Block a user