show latest payment on contract

shift-build-2464
Nadim Salloum 2021-06-19 19:05:07 +03:00
parent 97e389bf90
commit 45cb165d20
3 changed files with 25 additions and 13 deletions

View File

@ -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();

View File

@ -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]);

View File

@ -208,18 +208,20 @@ Mündliche Vereinbarungen sind ungültig.
</tr>
</table>
<br><br><br><br>
<table width="100%" style="padding-top: 5px; border-top: 1px solid black;">
<tr>
<td width="20%"><b>Quittung</b></td>
<td width="30%">Den Betrag von</td>
<td>in bar erhalten</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td>Datum: </td>
<td>&nbsp;</td>
</tr>
</table>
@if ($contract->deposit())
<table width="100%" style="padding-top: 5px; border-top: 1px solid black;">
<tr>
<td width="20%"><b>Quittung</b></td>
<td width="30%">Den Betrag von {{ $contract->deposit()->amount->format() }}</td>
<td>{{ $contract->deposit()->type_text }}</td>
</tr>
<tr><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td>Datum: </td>
<td>&nbsp;</td>
</tr>
</table>
@endif
</body>
</html>