diff --git a/app/Http/Controllers/Banking/Transactions.php b/app/Http/Controllers/Banking/Transactions.php
index 4a8f72829..083a62e8d 100644
--- a/app/Http/Controllers/Banking/Transactions.php
+++ b/app/Http/Controllers/Banking/Transactions.php
@@ -101,7 +101,7 @@ class Transactions extends Controller
$type = request()->get('type', 'income');
$real_type = $this->getRealTypeTransaction($type);
- $number = $this->getNextTransactionNumber();
+ $number = $this->getNextTransactionNumber($type);
$contact_type = config('type.transaction.' . $type . '.contact_type');
diff --git a/app/Interfaces/Utility/TransactionNumber.php b/app/Interfaces/Utility/TransactionNumber.php
new file mode 100644
index 000000000..95169c686
--- /dev/null
+++ b/app/Interfaces/Utility/TransactionNumber.php
@@ -0,0 +1,12 @@
+subject(trans('notifications.export.completed.title'))
+ ->line(new HtmlString('
'))
->line(trans('notifications.export.completed.description'))
->action(trans('general.download'), $this->download_url);
}
diff --git a/app/Notifications/Common/ExportFailed.php b/app/Notifications/Common/ExportFailed.php
index 36ea8c25a..90eaeed12 100644
--- a/app/Notifications/Common/ExportFailed.php
+++ b/app/Notifications/Common/ExportFailed.php
@@ -6,6 +6,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;
+use Illuminate\Support\HtmlString;
class ExportFailed extends Notification implements ShouldQueue
{
@@ -51,8 +52,11 @@ class ExportFailed extends Notification implements ShouldQueue
{
return (new MailMessage)
->subject(trans('notifications.export.failed.title'))
+ ->line(new HtmlString('
'))
->line(trans('notifications.export.failed.description'))
- ->line($this->message);
+ ->line(new HtmlString('
'))
+ ->line($this->message)
+ ->line(new HtmlString('
'));
}
/**
diff --git a/app/Notifications/Common/ImportCompleted.php b/app/Notifications/Common/ImportCompleted.php
index 155c547f9..fc69db0ef 100644
--- a/app/Notifications/Common/ImportCompleted.php
+++ b/app/Notifications/Common/ImportCompleted.php
@@ -6,6 +6,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;
+use Illuminate\Support\HtmlString;
class ImportCompleted extends Notification implements ShouldQueue
{
@@ -49,6 +50,7 @@ class ImportCompleted extends Notification implements ShouldQueue
return (new MailMessage)
->subject(trans('notifications.import.completed.title'))
+ ->line(new HtmlString('
'))
->line(trans('notifications.import.completed.description'))
->action(trans_choice('general.dashboards', 1), $dashboard_url);
}
diff --git a/app/Notifications/Common/ImportFailed.php b/app/Notifications/Common/ImportFailed.php
index 89939f757..21c9c66f1 100644
--- a/app/Notifications/Common/ImportFailed.php
+++ b/app/Notifications/Common/ImportFailed.php
@@ -6,6 +6,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;
+use Illuminate\Support\HtmlString;
class ImportFailed extends Notification implements ShouldQueue
{
@@ -51,12 +52,16 @@ class ImportFailed extends Notification implements ShouldQueue
{
$message = (new MailMessage)
->subject(trans('notifications.import.failed.title'))
+ ->line(new HtmlString('
'))
->line(trans('notifications.import.failed.description'));
foreach ($this->errors as $error) {
+ $message->line(new HtmlString('
'));
$message->line($error);
}
+ $message->line(new HtmlString('
'));
+
return $message;
}
diff --git a/app/Notifications/Email/InvalidEmail.php b/app/Notifications/Email/InvalidEmail.php
index 8d02e9ef5..759addc21 100644
--- a/app/Notifications/Email/InvalidEmail.php
+++ b/app/Notifications/Email/InvalidEmail.php
@@ -55,11 +55,9 @@ class InvalidEmail extends Notification implements ShouldQueue
return (new MailMessage)
->subject(trans('notifications.email.invalid.title', ['type' => $this->type]))
- ->line(new HtmlString('
'))
- ->line(new HtmlString('
'))
+ ->line(new HtmlString('
'))
->line(trans('notifications.email.invalid.description', ['email' => $this->email]))
- ->line(new HtmlString('
'))
- ->line(new HtmlString('
'))
+ ->line(new HtmlString('
'))
->line(new HtmlString('' . $this->error . ''))
->action(trans_choice('general.dashboards', 1), $dashboard_url);
}
diff --git a/app/Providers/Binding.php b/app/Providers/Binding.php
index 3355ad5d4..3a4d2a05d 100644
--- a/app/Providers/Binding.php
+++ b/app/Providers/Binding.php
@@ -3,7 +3,9 @@
namespace App\Providers;
use App\Interfaces\Utility\DocumentNumber as DocumentNumberInterface;
+use App\Interfaces\Utility\TransactionNumber as TransactionNumberInterface;
use App\Utilities\DocumentNumber;
+use App\Utilities\TransactionNumber;
use Illuminate\Support\ServiceProvider;
class Binding extends ServiceProvider
@@ -15,5 +17,6 @@ class Binding extends ServiceProvider
*/
public array $bindings = [
DocumentNumberInterface::class => DocumentNumber::class,
+ TransactionNumberInterface::class => TransactionNumber::class,
];
}
diff --git a/app/Traits/Transactions.php b/app/Traits/Transactions.php
index ba77a38c3..ec9bf6681 100644
--- a/app/Traits/Transactions.php
+++ b/app/Traits/Transactions.php
@@ -4,6 +4,7 @@ namespace App\Traits;
use App\Events\Banking\TransactionPrinting;
use App\Models\Banking\Transaction;
+use App\Interfaces\Utility\TransactionNumber;
use Illuminate\Support\Str;
trait Transactions
@@ -228,36 +229,13 @@ trait Transactions
return Str::replace('-split', '', $transfer_type);
}
- public function getNextTransactionNumber($suffix = ''): string
+ public function getNextTransactionNumber($type = 'income', $suffix = ''): string
{
- $prefix = setting('transaction' . $suffix . '.number_prefix');
- $next = (string) setting('transaction' . $suffix . '.number_next');
- $digit = (int) setting('transaction' . $suffix . '.number_digit');
-
- $get_number = fn($prefix, $next, $digit) => $prefix . str_pad($next, $digit, '0', STR_PAD_LEFT);
- $number_exists = fn($number) => Transaction::where('number', $number)->exists();
-
- $transaction_number = $get_number($prefix, $next, $digit);
-
- if ($number_exists($transaction_number)) {
- do {
- $next++;
-
- $transaction_number = $get_number($prefix, $next, $digit);
- } while ($number_exists($transaction_number));
-
- setting(['transaction' . $suffix . '.number_next' => $next]);
- setting()->save();
- }
-
- return $transaction_number;
+ return app(TransactionNumber::class)->getNextNumber($type, $suffix, null);
}
- public function increaseNextTransactionNumber($suffix = ''): void
+ public function increaseNextTransactionNumber($type = 'income', $suffix = ''): void
{
- $next = setting('transaction' . $suffix . '.number_next', 1) + 1;
-
- setting(['transaction' . $suffix . '.number_next' => $next]);
- setting()->save();
+ app(TransactionNumber::class)->increaseNextNumber($type, $suffix, null);
}
}
diff --git a/app/Utilities/TransactionNumber.php b/app/Utilities/TransactionNumber.php
new file mode 100644
index 000000000..a60a78e8d
--- /dev/null
+++ b/app/Utilities/TransactionNumber.php
@@ -0,0 +1,44 @@
+ $prefix . str_pad($next, $digit, '0', STR_PAD_LEFT);
+ $number_exists = fn($number) => Transaction::where('number', $number)->exists();
+
+ $transaction_number = $get_number($prefix, $next, $digit);
+
+ if ($number_exists($transaction_number)) {
+ do {
+ $next++;
+
+ $transaction_number = $get_number($prefix, $next, $digit);
+ } while ($number_exists($transaction_number));
+
+ setting(['transaction' . $suffix . '.number_next' => $next]);
+ setting()->save();
+ }
+
+ return $transaction_number;
+
+ }
+
+ public function increaseNextNumber($type, $suffix = '', ?Contact $contact): void
+ {
+ $next = setting('transaction' . $suffix . '.number_next', 1) + 1;
+
+ setting(['transaction' . $suffix . '.number_next' => $next]);
+ setting()->save();
+ }
+}
diff --git a/database/factories/Transaction.php b/database/factories/Transaction.php
index 2ad38084d..525d06c2e 100644
--- a/database/factories/Transaction.php
+++ b/database/factories/Transaction.php
@@ -3,6 +3,7 @@
namespace Database\Factories;
use App\Abstracts\Factory;
+use App\Interfaces\Utility\TransactionNumber;
use App\Models\Banking\Transaction as Model;
use App\Models\Common\Contact;
use App\Traits\Transactions;
@@ -41,7 +42,7 @@ class Transaction extends Factory
return [
'company_id' => $this->company->id,
'type' => $this->type,
- 'number' => $this->getNumber(),
+ 'number' => $this->getNumber($this->type),
'account_id' => setting('default.account'),
'paid_at' => $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s'),
'amount' => $this->faker->randomFloat(2, 1, 1000),
@@ -73,6 +74,7 @@ class Transaction extends Factory
return [
'type' => 'income',
+ 'number' => $this->getNumber('income', '', $contact),
'contact_id' => $contact->id,
'category_id' => $this->company->categories()->income()->get()->random(1)->pluck('id')->first(),
];
@@ -97,6 +99,7 @@ class Transaction extends Factory
return [
'type' => 'expense',
+ 'number' => $this->getNumber('expense', '', $contact),
'contact_id' => $contact->id,
'category_id' => $this->company->categories()->expense()->get()->random(1)->pluck('id')->first(),
];
@@ -110,9 +113,11 @@ class Transaction extends Factory
*/
public function recurring()
{
+ $type = $this->getRawAttribute('type') . '-recurring';
+
return $this->state([
- 'type' => $this->getRawAttribute('type') . '-recurring',
- 'number' => $this->getNumber('-recurring'),
+ 'type' => $type,
+ 'number' => $this->getNumber($type, '-recurring'),
'recurring_started_at' => Date::now()->format('Y-m-d H:i:s'),
'recurring_frequency' => 'daily',
'recurring_custom_frequency' => 'daily',
@@ -129,11 +134,13 @@ class Transaction extends Factory
* Get transaction number
*
*/
- public function getNumber($suffix = '')
+ public function getNumber($type, $suffix = '', $contact = null)
{
- $number = $this->getNextTransactionNumber($suffix);
+ $utility = app(TransactionNumber::class);
- $this->increaseNextTransactionNumber($suffix);
+ $number = $utility->getNextNumber($type, $suffix, $contact);
+
+ $utility->increaseNextNumber($type, $suffix ,$contact);
return $number;
}