Files
portal-api/app/Repositories/Invoice/InvoiceCachedRepository.php
T

85 lines
3.1 KiB
PHP

<?php
namespace App\Repositories\Invoice;
use App\Repositories\BaseCachedRepository;
use Illuminate\Support\Facades\Cache;
class InvoiceCachedRepository extends BaseCachedRepository implements InvoiceRepositoryInterface
{
public function __construct(
public InvoiceRepository $invoiceRepository
) {
parent::__construct();
}
public function getModel()
{
return $this->invoiceRepository->getModel();
}
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'], bool $returnQuery = false)
{
if ($returnQuery) {
return $this->invoiceRepository->filter($data, $relationships, $withCount, $select, $returnQuery);
}
$cacheKey = $this->getCacheKey(md5(json_encode([
'filterItem' => [
'data' => $data,
'relationships' => $relationships,
'select' => $select,
'withCount' => $withCount
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount) {
return $this->invoiceRepository->filter($data, $relationships, $withCount, $select);
});
}
public function get_billing_year(int $year = 0)
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'get_billing_year' => [
'year' => $year
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($year) {
return $this->invoiceRepository->get_billing_year($year);
});
}
public function get_billing_month(int $month = 0)
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'get_billing_month' => [
'month' => $month
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($month) {
return $this->invoiceRepository->get_billing_month($month);
});
}
public function get_billing_day(int|string $day = '')
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'get_billing_day' => [
'day' => $day
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($day) {
return $this->invoiceRepository->get_billing_day($day);
});
}
public function findWithRelationships(string $ordernum = '', array $relationships = [], array $withCount = [], array $withSum = [])
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'findWithRelationships' => [
'ordernum' => $ordernum,
'relationships' => $relationships,
'withCount' => $withCount,
'withSum' => $withSum
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($ordernum, $relationships, $withCount, $withSum) {
return $this->invoiceRepository->findWithRelationships($ordernum, $relationships, $withCount, $withSum);
});
}
}