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); return $this->hasMany(Payment::class);
} }
public function deposit()
{
return $this->payments()->oldest('date')->first();
}
public function contact() public function contact()
{ {
return $this->belongsTo(Contact::class)->withTrashed(); return $this->belongsTo(Contact::class)->withTrashed();

View File

@ -45,6 +45,11 @@ class Payment extends Model
return $type == PaymentType::Transaction() ? 'Überweisung' : 'Barzahlung'; return $type == PaymentType::Transaction() ? 'Überweisung' : 'Barzahlung';
} }
public function getTypeTextAttribute()
{
return $this->type == PaymentType::Transaction() ? 'Als Überweisung erhalten' : 'in bar erhalten';
}
public function getDeleteLinkAttribute() public function getDeleteLinkAttribute()
{ {
return route('payments.destroy', [$this->contract->id, $this->id]); return route('payments.destroy', [$this->contract->id, $this->id]);

View File

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