Also test attachments.

This commit is contained in:
James Cole
2021-03-13 14:33:48 +01:00
parent bd040c80b2
commit bdb298740a
19 changed files with 446 additions and 99 deletions
+24 -3
View File
@@ -596,10 +596,12 @@ class AccountRepository implements AccountRepositoryInterface
[AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION],
];
foreach ($sets as $set) {
Log::debug('Now in resetAccountOrder', $set);
$list = $this->getAccountsByType($set);
$index = 1;
foreach ($list as $account) {
if ($index !== $account->order) {
if ($index !== (int)$account->order) {
Log::debug(sprintf('Account #%d ("%s"): order should %d be but is %d.', $account->id, $account->name, $index, $account->order));
$account->order = $index;
$account->save();
}
@@ -766,8 +768,27 @@ class AccountRepository implements AccountRepositoryInterface
/**
* @inheritDoc
*/
public function maxOrder(array $types): int
public function maxOrder(string $type): int
{
return (int)$this->getAccountsByType($types)->max('order');
$sets = [
AccountType::ASSET => [AccountType::DEFAULT, AccountType::ASSET],
AccountType::EXPENSE => [AccountType::EXPENSE, AccountType::BENEFICIARY],
AccountType::REVENUE => [AccountType::REVENUE],
AccountType::LOAN => [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE],
AccountType::DEBT => [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE],
AccountType::MORTGAGE => [AccountType::LOAN, AccountType::DEBT, AccountType::CREDITCARD, AccountType::MORTGAGE],
];
if (array_key_exists(ucfirst($type), $sets)) {
$order = (int)$this->getAccountsByType($sets[ucfirst($type)])->max('order');
Log::debug(sprintf('Return max order of "%s" set: %d', $type, $order));
return $order;
}
$specials = [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION];
$order = (int)$this->getAccountsByType($specials)->max('order');
Log::debug(sprintf('Return max order of "%s" set (specials!): %d', $type, $order));
return $order;
}
}
@@ -48,11 +48,11 @@ interface AccountRepositoryInterface
public function count(array $types): int;
/**
* @param array $types
* @param string $type
*
* @return int
*/
public function maxOrder(array $types): int;
public function maxOrder(string $type): int;
/**
* Moved here from account CRUD.
@@ -170,14 +170,19 @@ class AttachmentRepository implements AttachmentRepositoryInterface
*/
public function update(Attachment $attachment, array $data): Attachment
{
$attachment->title = $data['title'];
if (array_key_exists('title', $data)) {
$attachment->title = $data['title'];
}
// update filename, if present and different:
if (isset($data['filename']) && '' !== $data['filename'] && $data['filename'] !== $attachment->filename) {
$attachment->filename = $data['filename'];
if (array_key_exists('filename', $data)) {
if ('' !== (string)$data['filename'] && $data['filename'] !== $attachment->filename) {
$attachment->filename = $data['filename'];
}
}
$attachment->save();
$this->updateNote($attachment, $data['notes'] ?? '');
if (array_key_exists('notes', $data)) {
$this->updateNote($attachment, (string)$data['notes']);
}
return $attachment;
}