Operation processes on invoices
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Resources;
|
||||
|
||||
use App\Enumerations\InvoiceStatus;
|
||||
use App\Models\CostUnit;
|
||||
use App\Repositories\CostUnitRepository;
|
||||
use App\ValueObjects\Amount;
|
||||
|
||||
class CostUnitResource {
|
||||
@@ -13,13 +15,18 @@ class CostUnitResource {
|
||||
}
|
||||
|
||||
public function toArray($request) {
|
||||
$totalAmount = 0;
|
||||
$donatedAmount = 0;
|
||||
$costUnitRepository = new CostUnitRepository();
|
||||
|
||||
$countNewInvoices = 0;
|
||||
$countApprovedInvoices = 0;
|
||||
$countDonatedInvoices = 0;
|
||||
$countDeniedInvoices = 0;
|
||||
|
||||
$totalAmount = $costUnitRepository->sumupAmounts($this->costUnit)->getAmount();
|
||||
$donatedAmount = $costUnitRepository->sumupAmounts($this->costUnit, true)->getAmount();
|
||||
|
||||
$countInvoices = $costUnitRepository->countInvoices($this->costUnit);
|
||||
|
||||
$countNewInvoices = $countInvoices[InvoiceStatus::INVOICE_STATUS_NEW];
|
||||
$countApprovedInvoices = $countInvoices[InvoiceStatus::INVOICE_STATUS_APPROVED];
|
||||
$countDonatedInvoices = $countInvoices[InvoiceStatus::INVOICE_META_STATUS_DONATED];
|
||||
$countDeniedInvoices = $countInvoices[InvoiceStatus::INVOICE_STATUS_DENIED];
|
||||
|
||||
|
||||
$data = array_merge(
|
||||
@@ -33,7 +40,7 @@ class CostUnitResource {
|
||||
'countApprovedInvoices' => $countApprovedInvoices,
|
||||
'countDonatedInvoices' => $countDonatedInvoices,
|
||||
'countDeniedInvoices' => $countDeniedInvoices,
|
||||
'treasurers' => $this->costUnit->tresurers()->get()->map(fn($user) => new UserResource($user))->toArray(),
|
||||
'treasurers' => $this->costUnit->treasurers()->get()->map(fn($user) => new UserResource($user))->toArray(),
|
||||
]);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user