From 45cb165d2038bc32f5ac046ccd895d563bd868ad Mon Sep 17 00:00:00 2001 From: Nadim Salloum Date: Sat, 19 Jun 2021 19:05:07 +0300 Subject: [PATCH] show latest payment on contract --- app/Models/Contract.php | 5 +++++ app/Models/Payment.php | 5 +++++ resources/views/contract.blade.php | 28 +++++++++++++++------------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/Models/Contract.php b/app/Models/Contract.php index 0487dac..54ebed4 100644 --- a/app/Models/Contract.php +++ b/app/Models/Contract.php @@ -104,6 +104,11 @@ class Contract extends Model return $this->hasMany(Payment::class); } + public function deposit() + { + return $this->payments()->oldest('date')->first(); + } + public function contact() { return $this->belongsTo(Contact::class)->withTrashed(); diff --git a/app/Models/Payment.php b/app/Models/Payment.php index 11d2a0c..72fba6c 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -45,6 +45,11 @@ class Payment extends Model return $type == PaymentType::Transaction() ? 'Überweisung' : 'Barzahlung'; } + public function getTypeTextAttribute() + { + return $this->type == PaymentType::Transaction() ? 'Als Überweisung erhalten' : 'in bar erhalten'; + } + public function getDeleteLinkAttribute() { return route('payments.destroy', [$this->contract->id, $this->id]); diff --git a/resources/views/contract.blade.php b/resources/views/contract.blade.php index 1ee91f1..fc74710 100644 --- a/resources/views/contract.blade.php +++ b/resources/views/contract.blade.php @@ -208,18 +208,20 @@ Mündliche Vereinbarungen sind ungültig.



- - - - - - - - - - - - -
QuittungDen Betrag vonin bar erhalten
 
 
Datum:  
+ @if ($contract->deposit()) + + + + + + + + + + + + +
QuittungDen Betrag von {{ $contract->deposit()->amount->format() }}{{ $contract->deposit()->type_text }}
 
 
Datum:  
+ @endif \ No newline at end of file