mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix email message for new transactions
This commit is contained in:
parent
a7b2fbbf10
commit
98cff18efa
@ -60,8 +60,8 @@ class RequestedReportOnJournals
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/** @var Collection The journals to report on. */
|
||||
public $journals;
|
||||
/** @var Collection The transaction groups to report on. */
|
||||
public $groups;
|
||||
/** @var int The ID of the user. */
|
||||
public $userId;
|
||||
|
||||
@ -69,13 +69,13 @@ class RequestedReportOnJournals
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @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.');
|
||||
$this->userId = $userId;
|
||||
$this->journals = $journals;
|
||||
$this->groups = $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,10 +55,10 @@ class AutomationHandler
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
$user = $repository->findNull($event->userId);
|
||||
if (null !== $user && 0 !== $event->journals->count()) {
|
||||
if (null !== $user && 0 !== $event->groups->count()) {
|
||||
try {
|
||||
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
|
||||
} catch (Exception $e) {
|
||||
Log::debug('Send message failed! :(');
|
||||
|
@ -105,7 +105,6 @@ class HomeController extends Controller
|
||||
{
|
||||
$types = config('firefly.accountTypesByIdentifier.asset');
|
||||
$count = $repository->count($types);
|
||||
|
||||
Log::channel('audit')->info('User visits homepage.');
|
||||
|
||||
if (0 === $count) {
|
||||
@ -127,7 +126,6 @@ class HomeController extends Controller
|
||||
/** @var BillRepositoryInterface $billRepository */
|
||||
$billRepository = app(BillRepositoryInterface::class);
|
||||
$billCount = $billRepository->getBills()->count();
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
@ -22,6 +22,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Mail;
|
||||
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
@ -43,21 +45,24 @@ class ReportNewJournalsMail extends Mailable
|
||||
/** @var string IP address of user (if known) */
|
||||
public $ipAddress;
|
||||
|
||||
/** @var Collection A collection of journals */
|
||||
public $journals;
|
||||
/** @var Collection A collection of groups */
|
||||
public $groups;
|
||||
|
||||
/** @var array All groups, transformed to array. */
|
||||
public $transformed;
|
||||
|
||||
/**
|
||||
* ConfirmEmailChangeMail constructor.
|
||||
*
|
||||
* @param string $email
|
||||
* @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->ipAddress = $ipAddress;
|
||||
$this->journals = $journals;
|
||||
$this->groups = $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,13 +72,25 @@ class ReportNewJournalsMail extends Mailable
|
||||
*/
|
||||
public function build(): self
|
||||
{
|
||||
$subject = 1 === $this->journals->count()
|
||||
$subject = 1 === $this->groups->count()
|
||||
? 'Firefly III has created a new transaction'
|
||||
: 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')
|
||||
->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' %}
|
||||
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
|
||||
{% if journals.count == 1 %}
|
||||
Firefly III has created a transaction for you.
|
||||
{% if transformed|length == 1 %}
|
||||
Firefly III has created a transaction for you. You can find it in your Firefly III installation:
|
||||
{% endif %}
|
||||
{% if journals.count > 1 %}
|
||||
Firefly III has created {{ journals.count }} transactions 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 %}
|
||||
</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 %}
|
||||
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
|
||||
You can find it in your Firefly III installation:<br />
|
||||
{% for journal in journals %}
|
||||
<a href="{{ route('transactions.show', journal.id) }}">{{ journal.description }}</a> (AMOUNT TODO)
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<!-- / amount -->
|
||||
{% else %}
|
||||
<a href="{{ route('transactions.show', [group.id]) }}">{{ group.group_title }}</a>
|
||||
<ol>
|
||||
{% for journal in group.transactions %}
|
||||
<li>
|
||||
{{ 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 %}
|
||||
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
|
||||
You can find them in your Firefly III installation:
|
||||
</p>
|
||||
<ul>
|
||||
{% for journal in journals %}
|
||||
<li>
|
||||
<a href="{{ route('transactions.show', journal.id) }}">{{ journal.description }}</a> (AMOUNT TODO)
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ol>
|
||||
|
||||
{% include 'emails.footer-html' %}
|
||||
|
@ -1,25 +1,17 @@
|
||||
{% include 'emails.header-text' %}
|
||||
{% if journals.count == 1 %}
|
||||
Firefly III has created a transaction for you.
|
||||
{% if transformed|length == 1 %}Firefly III has created a transaction for you. You can find it in your Firefly III installation:{% endif %}
|
||||
{% 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 %}
|
||||
{{ journal.description }}: {{ route('transactions.show', journal.id) }} (AMOUNT TODO)
|
||||
{% for group in transformed %}
|
||||
{% 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 %}
|
||||
{% 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 %}
|
||||
{% endif %}
|
||||
|
||||
{% include 'emails.footer-text' %}
|
||||
|
Loading…
Reference in New Issue
Block a user