mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-08-03 06:16:14 -04:00
49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\StaffPayroll\Repositories;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\StaffPayroll\Entities\Invoice;
|
|
|
|
|
|
class InvoiceRepository
|
|
{
|
|
public function __construct(
|
|
private Invoice $invoice
|
|
) {
|
|
}
|
|
|
|
public function getLatestInvoice(User $user): Invoice | null
|
|
{
|
|
return Invoice::query()
|
|
->where('user_id', $user->id)
|
|
->latest()
|
|
->first();
|
|
}
|
|
|
|
public function getInvoiceOfMonth(User $user, int $latestInvoiceNumber): Invoice
|
|
{
|
|
return Invoice::query()
|
|
->thisMonth()
|
|
->firstOrCreate(
|
|
[
|
|
'user_id' => $user->id,
|
|
],
|
|
[
|
|
'invoice_number' => $latestInvoiceNumber,
|
|
'issue_date' => now()->toDateString(),
|
|
'created_by' => Auth::check() ? auth()->id() : null,
|
|
]
|
|
);
|
|
}
|
|
|
|
public function getInvoiceByPublishedDate($year,$month): Invoice
|
|
{
|
|
return Invoice::whereYear('created_at', '=', $year)
|
|
->whereMonth('created_at', '=', $month)
|
|
->first();
|
|
}
|
|
}
|