2018-02-27 05:16:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Repository;
|
2018-02-27 05:16:12 +08:00
|
|
|
use App\Models\Expense;
|
2018-03-02 06:20:13 +08:00
|
|
|
use Illuminate\Support\Collection;
|
2018-02-27 05:16:12 +08:00
|
|
|
use Prettus\Repository\Contracts\CacheableInterface;
|
|
|
|
use Prettus\Repository\Traits\CacheableRepository;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ExpenseRepository
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class ExpenseRepository extends Repository implements CacheableInterface
|
2018-02-27 05:16:12 +08:00
|
|
|
{
|
|
|
|
use CacheableRepository;
|
|
|
|
|
|
|
|
public function model()
|
|
|
|
{
|
|
|
|
return Expense::class;
|
|
|
|
}
|
2018-03-02 06:20:13 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all of the expenses for a given type, and also
|
|
|
|
* include expenses for a given airline ID
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param $type
|
2018-03-06 11:24:49 +08:00
|
|
|
* @param null $airline_id
|
2018-04-02 03:32:01 +08:00
|
|
|
* @param null $ref_model
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-02 06:20:13 +08:00
|
|
|
* @return Collection
|
|
|
|
*/
|
2018-04-02 03:32:01 +08:00
|
|
|
public function getAllForType($type, $airline_id = null, $ref_model = null)
|
2018-03-02 06:20:13 +08:00
|
|
|
{
|
2018-03-06 11:24:49 +08:00
|
|
|
$where = [
|
2018-03-02 06:20:13 +08:00
|
|
|
'type' => $type,
|
2018-08-27 00:40:04 +08:00
|
|
|
['airline_id', '=', null],
|
2018-03-06 11:24:49 +08:00
|
|
|
];
|
|
|
|
|
2018-04-02 03:32:01 +08:00
|
|
|
if ($ref_model) {
|
2018-04-02 11:26:20 +08:00
|
|
|
if (\is_object($ref_model)) {
|
|
|
|
$ref_model_type = \get_class($ref_model);
|
|
|
|
} else {
|
|
|
|
$ref_model_type = $ref_model;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($ref_model) {
|
|
|
|
$where['ref_model'] = $ref_model_type;
|
|
|
|
}
|
2018-03-06 11:24:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$expenses = $this->findWhere($where);
|
2018-03-02 06:20:13 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($airline_id) {
|
2018-03-06 11:24:49 +08:00
|
|
|
$where = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'type' => $type,
|
2018-08-27 00:40:04 +08:00
|
|
|
'airline_id' => $airline_id,
|
2018-03-06 11:24:49 +08:00
|
|
|
];
|
|
|
|
|
2018-04-02 03:32:01 +08:00
|
|
|
if ($ref_model) {
|
2018-04-02 11:26:20 +08:00
|
|
|
$where['ref_model'] = $ref_model_type;
|
2018-03-06 11:24:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$airline_expenses = $this->findWhere($where);
|
2018-03-02 06:20:13 +08:00
|
|
|
$expenses = $expenses->concat($airline_expenses);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $expenses;
|
|
|
|
}
|
2018-02-27 05:16:12 +08:00
|
|
|
}
|