mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Fix email message for new transactions
This commit is contained in:
@@ -60,8 +60,8 @@ class RequestedReportOnJournals
|
|||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||||
|
|
||||||
/** @var Collection The journals to report on. */
|
/** @var Collection The transaction groups to report on. */
|
||||||
public $journals;
|
public $groups;
|
||||||
/** @var int The ID of the user. */
|
/** @var int The ID of the user. */
|
||||||
public $userId;
|
public $userId;
|
||||||
|
|
||||||
@@ -69,13 +69,13 @@ class RequestedReportOnJournals
|
|||||||
* Create a new event instance.
|
* Create a new event instance.
|
||||||
*
|
*
|
||||||
* @param int $userId
|
* @param int $userId
|
||||||
* @param Collection $journals
|
* @param Collection $groups
|
||||||
*/
|
*/
|
||||||
public function __construct(int $userId, Collection $journals)
|
public function __construct(int $userId, Collection $groups)
|
||||||
{
|
{
|
||||||
Log::debug('In event RequestedReportOnJournals.');
|
Log::debug('In event RequestedReportOnJournals.');
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->journals = $journals;
|
$this->groups = $groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -55,10 +55,10 @@ class AutomationHandler
|
|||||||
/** @var UserRepositoryInterface $repository */
|
/** @var UserRepositoryInterface $repository */
|
||||||
$repository = app(UserRepositoryInterface::class);
|
$repository = app(UserRepositoryInterface::class);
|
||||||
$user = $repository->findNull($event->userId);
|
$user = $repository->findNull($event->userId);
|
||||||
if (null !== $user && 0 !== $event->journals->count()) {
|
if (null !== $user && 0 !== $event->groups->count()) {
|
||||||
try {
|
try {
|
||||||
Log::debug('Trying to mail...');
|
Log::debug('Trying to mail...');
|
||||||
Mail::to($user->email)->send(new ReportNewJournalsMail($user->email, '127.0.0.1', $event->journals));
|
Mail::to($user->email)->send(new ReportNewJournalsMail($user->email, '127.0.0.1', $event->groups));
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::debug('Send message failed! :(');
|
Log::debug('Send message failed! :(');
|
||||||
|
@@ -105,7 +105,6 @@ class HomeController extends Controller
|
|||||||
{
|
{
|
||||||
$types = config('firefly.accountTypesByIdentifier.asset');
|
$types = config('firefly.accountTypesByIdentifier.asset');
|
||||||
$count = $repository->count($types);
|
$count = $repository->count($types);
|
||||||
|
|
||||||
Log::channel('audit')->info('User visits homepage.');
|
Log::channel('audit')->info('User visits homepage.');
|
||||||
|
|
||||||
if (0 === $count) {
|
if (0 === $count) {
|
||||||
@@ -127,7 +126,6 @@ class HomeController extends Controller
|
|||||||
/** @var BillRepositoryInterface $billRepository */
|
/** @var BillRepositoryInterface $billRepository */
|
||||||
$billRepository = app(BillRepositoryInterface::class);
|
$billRepository = app(BillRepositoryInterface::class);
|
||||||
$billCount = $billRepository->getBills()->count();
|
$billCount = $billRepository->getBills()->count();
|
||||||
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
@@ -22,6 +22,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Mail;
|
namespace FireflyIII\Mail;
|
||||||
|
|
||||||
|
use FireflyIII\Models\TransactionGroup;
|
||||||
|
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Mail\Mailable;
|
use Illuminate\Mail\Mailable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
@@ -43,21 +45,24 @@ class ReportNewJournalsMail extends Mailable
|
|||||||
/** @var string IP address of user (if known) */
|
/** @var string IP address of user (if known) */
|
||||||
public $ipAddress;
|
public $ipAddress;
|
||||||
|
|
||||||
/** @var Collection A collection of journals */
|
/** @var Collection A collection of groups */
|
||||||
public $journals;
|
public $groups;
|
||||||
|
|
||||||
|
/** @var array All groups, transformed to array. */
|
||||||
|
public $transformed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConfirmEmailChangeMail constructor.
|
* ConfirmEmailChangeMail constructor.
|
||||||
*
|
*
|
||||||
* @param string $email
|
* @param string $email
|
||||||
* @param string $ipAddress
|
* @param string $ipAddress
|
||||||
* @param Collection $journals
|
* @param Collection $groups
|
||||||
*/
|
*/
|
||||||
public function __construct(string $email, string $ipAddress, Collection $journals)
|
public function __construct(string $email, string $ipAddress, Collection $groups)
|
||||||
{
|
{
|
||||||
$this->email = $email;
|
$this->email = $email;
|
||||||
$this->ipAddress = $ipAddress;
|
$this->ipAddress = $ipAddress;
|
||||||
$this->journals = $journals;
|
$this->groups = $groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,13 +72,25 @@ class ReportNewJournalsMail extends Mailable
|
|||||||
*/
|
*/
|
||||||
public function build(): self
|
public function build(): self
|
||||||
{
|
{
|
||||||
$subject = 1 === $this->journals->count()
|
$subject = 1 === $this->groups->count()
|
||||||
? 'Firefly III has created a new transaction'
|
? 'Firefly III has created a new transaction'
|
||||||
: sprintf(
|
: sprintf(
|
||||||
'Firefly III has created new %d transactions', $this->journals->count()
|
'Firefly III has created new %d transactions', $this->groups->count()
|
||||||
);
|
);
|
||||||
|
$this->transform();
|
||||||
|
|
||||||
return $this->view('emails.report-new-journals-html')->text('emails.report-new-journals-text')
|
return $this->view('emails.report-new-journals-html')->text('emails.report-new-journals-text')
|
||||||
->subject($subject);
|
->subject($subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function transform(): void
|
||||||
|
{
|
||||||
|
/** @var TransactionGroupTransformer $transformer */
|
||||||
|
$transformer = app(TransactionGroupTransformer::class);
|
||||||
|
|
||||||
|
/** @var TransactionGroup $group */
|
||||||
|
foreach ($this->groups as $group) {
|
||||||
|
$this->transformed[] = $transformer->transformObject($group);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,34 +1,83 @@
|
|||||||
{% include 'emails.header-html' %}
|
{% include 'emails.header-html' %}
|
||||||
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
|
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
|
||||||
{% if journals.count == 1 %}
|
{% if transformed|length == 1 %}
|
||||||
Firefly III has created a transaction for you.
|
Firefly III has created a transaction for you. You can find it in your Firefly III installation:
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if journals.count > 1 %}
|
{% if transformed|length > 1 %}
|
||||||
Firefly III has created {{ journals.count }} transactions for you.
|
Firefly III has created {{ groups.count }} transactions for you. You can find them in your Firefly III installation:
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<!-- loop groups -->
|
||||||
|
<ol>
|
||||||
|
{% for group in transformed %}
|
||||||
|
<li>
|
||||||
|
{% set count = group.transactions|length %}
|
||||||
|
<!-- if journals === 1, skip straight to journals. -->
|
||||||
|
{% if 1 == count %}
|
||||||
|
{% set journal = group.transactions[0] %}
|
||||||
|
<a href="{{ route('transactions.show', [group.id]) }}">{{ journal.description }}</a>,
|
||||||
|
<!-- amount -->
|
||||||
|
{% if journal.type == 'deposit' %}
|
||||||
|
<span style="color:#3c763d;">
|
||||||
|
{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}
|
||||||
|
{% if null != journal.foreign_amount*-1 %}
|
||||||
|
({{ formatAmountBySymbol(journal.foreign_amount, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }})
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
{% elseif journal.type == 'transfer' %}
|
||||||
|
<span style="color:#31708f">
|
||||||
|
{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}
|
||||||
|
{% if null != journal.foreign_amount %}
|
||||||
|
({{ formatAmountBySymbol(journal.foreign_amount*-1, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }})
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
{% else %}
|
||||||
|
<span style="color:#a94442">
|
||||||
|
{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}
|
||||||
|
{% if null != journal.foreign_amount %}
|
||||||
|
({{ formatAmountBySymbol(journal.foreign_amount*-1, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }})
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
|
||||||
{% if journals.count == 1 %}
|
{% endif %}
|
||||||
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
|
<!-- / amount -->
|
||||||
You can find it in your Firefly III installation:<br />
|
{% else %}
|
||||||
{% for journal in journals %}
|
<a href="{{ route('transactions.show', [group.id]) }}">{{ group.group_title }}</a>
|
||||||
<a href="{{ route('transactions.show', journal.id) }}">{{ journal.description }}</a> (AMOUNT TODO)
|
<ol>
|
||||||
{% endfor %}
|
{% for journal in group.transactions %}
|
||||||
</p>
|
<li>
|
||||||
{% endif %}
|
{{ journal.description }},
|
||||||
|
<!-- amount -->
|
||||||
|
{% if journal.type == 'deposit' %}
|
||||||
|
<span style="color:#3c763d;">
|
||||||
|
{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}
|
||||||
|
{% if null != journal.foreign_amount*-1 %}
|
||||||
|
({{ formatAmountBySymbol(journal.foreign_amount, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }})
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
{% elseif journal.type == 'transfer' %}
|
||||||
|
<span style="color:#31708f">
|
||||||
|
{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}
|
||||||
|
{% if null != journal.foreign_amount %}
|
||||||
|
({{ formatAmountBySymbol(journal.foreign_amount*-1, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }})
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
{% else %}
|
||||||
|
<span style="color:#a94442">
|
||||||
|
{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}
|
||||||
|
{% if null != journal.foreign_amount %}
|
||||||
|
({{ formatAmountBySymbol(journal.foreign_amount*-1, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }})
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
|
||||||
{% if journals.count > 1 %}
|
{% endif %}
|
||||||
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
|
</li>
|
||||||
You can find them in your Firefly III installation:
|
{% endfor %}
|
||||||
</p>
|
</ol>
|
||||||
<ul>
|
{% endif %}
|
||||||
{% for journal in journals %}
|
</li>
|
||||||
<li>
|
{% endfor %}
|
||||||
<a href="{{ route('transactions.show', journal.id) }}">{{ journal.description }}</a> (AMOUNT TODO)
|
</ol>
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% include 'emails.footer-html' %}
|
{% include 'emails.footer-html' %}
|
||||||
|
@@ -1,25 +1,17 @@
|
|||||||
{% include 'emails.header-text' %}
|
{% include 'emails.header-text' %}
|
||||||
{% if journals.count == 1 %}
|
{% if transformed|length == 1 %}Firefly III has created a transaction for you. You can find it in your Firefly III installation:{% endif %}
|
||||||
Firefly III has created a transaction for you.
|
{% if transformed|length > 1 %}Firefly III has created {{ groups.count }} transactions for you. You can find them in your Firefly III installation:{% endif %}
|
||||||
|
|
||||||
{% endif %}
|
|
||||||
{% if journals.count > 1 %}
|
|
||||||
Firefly III has created {{ journals.count }} transactions for you.
|
|
||||||
{% endif %}
|
|
||||||
{% if journals.count == 1 %}
|
|
||||||
You can find in in your Firefly III installation:
|
|
||||||
|
|
||||||
{% for journal in journals %}
|
{% for group in transformed %}
|
||||||
{{ journal.description }}: {{ route('transactions.show', journal.id) }} (AMOUNT TODO)
|
{% set count = group.transactions|length %}
|
||||||
|
{% if 1 == count %}{% set journal = group.transactions[0] %}
|
||||||
|
- {{ journal.description }}, {% if journal.type == 'deposit' %}{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}{% if null != journal.foreign_amount*-1 %} ({{ formatAmountBySymbol(journal.foreign_amount, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }}){% endif %}{% elseif journal.type == 'transfer' %}{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}{% if null != journal.foreign_amount %} ({{ formatAmountBySymbol(journal.foreign_amount*-1, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }}){% endif %}{% else %}{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}{% if null != journal.foreign_amount %} ({{ formatAmountBySymbol(journal.foreign_amount*-1, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }}){% endif %}{% endif %}
|
||||||
|
|
||||||
|
{% else %}- {{ group.group_title }}
|
||||||
|
{% for journal in group.transactions %}-- {{ journal.description }}, {% if journal.type == 'deposit' %}{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}{% if null != journal.foreign_amount*-1 %} ({{ formatAmountBySymbol(journal.foreign_amount, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }}){% endif %}{% elseif journal.type == 'transfer' %}{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}{% if null != journal.foreign_amount %} ({{ formatAmountBySymbol(journal.foreign_amount*-1, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }}){% endif %}{% else %}{{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places, false) }}{% if null != journal.foreign_amount %} ({{ formatAmountBySymbol(journal.foreign_amount*-1, journal.foreign_currency_symbol, journal.foreign_currency_decimal_places, false) }}){% endif %}{% endif %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if journals.count > 1 %}
|
|
||||||
You can find them in your Firefly III installation:
|
|
||||||
|
|
||||||
{% for journal in journals %}
|
|
||||||
- {{ journal.description }}: {{ route('transactions.show', journal.id) }} (AMOUNT TODO)
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% include 'emails.footer-text' %}
|
{% include 'emails.footer-text' %}
|
||||||
|
Reference in New Issue
Block a user