diff --git a/app/Abstracts/View/Components/TransactionShow.php b/app/Abstracts/View/Components/TransactionShow.php index 2291c17d6..2e4b1111e 100644 --- a/app/Abstracts/View/Components/TransactionShow.php +++ b/app/Abstracts/View/Components/TransactionShow.php @@ -314,6 +314,12 @@ abstract class TransactionShow extends Base /** @var string */ public $classFooterHistories; + /** @var string */ + public $textRecurringType; + + /** @var bool */ + public $hideRecurringMessage; + /** * Create a new component instance. * @@ -346,7 +352,7 @@ abstract class TransactionShow extends Base bool $hideAttachment = false, $attachment = [], bool $hideFooter = false, bool $hideFooterHistories = false, $histories = [], - string $textHistories = '', string $classFooterHistories = '' + string $textHistories = '', string $classFooterHistories = '', string $textRecurringType = '', bool $hideRecurringMessage = false ) { $this->type = $type; $this->transaction = $transaction; @@ -354,6 +360,8 @@ abstract class TransactionShow extends Base $this->logo = $this->getLogo($logo); $this->payment_methods = ($payment_methods) ?: Modules::getPaymentMethods('all'); $this->date_format = $this->getCompanyDateFormat(); + $this->textRecurringType = $this->getTextRecurringType($type, $textRecurringType); + $this->hideRecurringMessage = $hideRecurringMessage; // Navbar Hide $this->hideButtonAddNew = $hideButtonAddNew; @@ -1276,4 +1284,21 @@ abstract class TransactionShow extends Base return 'col-sm-6 col-md-6 col-lg-6 col-xl-6'; } + + protected function getTextRecurringType($type, $textRecurringType) + { + if (!empty($textRecurringType)) { + return $textRecurringType; + } + + $default_key = config('type.' . $type . '.translation.prefix'); + + $translation = $this->getTextFromConfig($type, 'recurring_tye', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'general.revenues'; + } } diff --git a/app/Models/Banking/Transaction.php b/app/Models/Banking/Transaction.php index 701747bf7..a9c351479 100644 --- a/app/Models/Banking/Transaction.php +++ b/app/Models/Banking/Transaction.php @@ -126,6 +126,11 @@ class Transaction extends Model return $this->belongsTo('App\Models\Auth\User', 'contact_id', 'id'); } + public function parent() + { + return $this->belongsTo('App\Models\Banking\Transaction', 'parent_id'); + } + /** * Scope to only include contacts of a given type. * diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php index c8570e3be..5ece9995b 100644 --- a/app/Models/Document/Document.php +++ b/app/Models/Document/Document.php @@ -140,6 +140,11 @@ class Document extends Model return $this->totals()->orderBy('sort_order'); } + public function parent() + { + return $this->belongsTo('App\Models\Document\Document', 'parent_id'); + } + public function scopeLatest(Builder $query) { return $query->orderBy('issued_at', 'desc'); diff --git a/resources/lang/en-GB/recurring.php b/resources/lang/en-GB/recurring.php index 79fefa042..8ce404aca 100644 --- a/resources/lang/en-GB/recurring.php +++ b/resources/lang/en-GB/recurring.php @@ -16,5 +16,6 @@ return [ 'months' => 'Month(s)', 'years' => 'Year(s)', 'message' => 'This is a recurring :type and the next :type will be automatically generated on :date', + 'message_parent' => 'This :type was automatically generated from :link', ]; diff --git a/resources/views/components/documents/show/recurring-message.blade.php b/resources/views/components/documents/show/recurring-message.blade.php index 04e36c01d..cb56d6482 100644 --- a/resources/views/components/documents/show/recurring-message.blade.php +++ b/resources/views/components/documents/show/recurring-message.blade.php @@ -20,4 +20,25 @@ @endif +@if ($document->parent) +
{!! trans('recurring.message_parent', [ + 'type' => mb_strtolower(trans_choice($textRecurringType, 1)), + 'link' => '' . $document->parent->document_number . '' + ]) !!} +
+ @stack('recurring_parent_message_body_end') +{{ trans('recurring.message', [ + 'type' => mb_strtolower(trans_choice($textRecurringType, 1)), + 'date' => $next->format($date_format) + ]) }} +
+ @stack('recurring_message_body_end') +{!! trans('recurring.message_parent', [ + 'type' => mb_strtolower(trans_choice($textRecurringType, 1)), + 'link' => '' . trans_choice($textRecurringType, 1) . '#' . $transaction->parent->id . '' + ]) !!} +
+ @stack('recurring_parent_message_body_end') +