Invoice Widgets completed
This commit is contained in:
37
app/Repositories/InvoiceRepository.php
Normal file
37
app/Repositories/InvoiceRepository.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Enumerations\InvoiceStatus;
|
||||
use App\Models\Invoice;
|
||||
use App\ValueObjects\Amount;
|
||||
|
||||
class InvoiceRepository {
|
||||
public function getMyInvoicesWidget() : array {
|
||||
$invoices = [
|
||||
InvoiceStatus::INVOICE_STATUS_NEW => ['slug' => 'new', 'title' => 'Neue Abrechnungen', 'count' => 0, 'amount' => Amount::fromString('0')->toString()],
|
||||
InvoiceStatus::INVOICE_STATUS_APPROVED => ['slug' => 'approved', 'title' => 'Freigegebene Abrechnungen', 'count' => 0, 'amount' => Amount::fromString('0')->toString()],
|
||||
InvoiceStatus::INVOICE_STATUS_DENIED => ['slug' => 'declined', 'title' => 'Abgelehnte Abrechnungen', 'count' => 0, 'amount' => Amount::fromString('0')->toString()]
|
||||
];
|
||||
|
||||
|
||||
$user = auth()->user();
|
||||
if (null === $user) {
|
||||
return $invoices;
|
||||
}
|
||||
|
||||
foreach ([InvoiceStatus::INVOICE_STATUS_NEW, InvoiceStatus::INVOICE_STATUS_APPROVED, InvoiceStatus::INVOICE_STATUS_DENIED] as $status) {
|
||||
$amount = 0;
|
||||
$count = 0;
|
||||
foreach (Invoice::where(['user_id' => $user->id, 'status' => $status])->get() as $stack) {
|
||||
$count++;
|
||||
$amount += $stack->amount;
|
||||
}
|
||||
|
||||
$invoices[$status]['count'] = $count;
|
||||
$invoices[$status]['amount'] = Amount::fromString($amount)->toString();
|
||||
}
|
||||
|
||||
return $invoices;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user