2018-02-27 05:16:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\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
|
|
|
|
* @package App\Repositories
|
|
|
|
*/
|
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-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-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-03-03 07:48:36 +08:00
|
|
|
['airline_id', '=', null]
|
2018-03-06 11:24:49 +08:00
|
|
|
];
|
|
|
|
|
2018-04-02 03:32:01 +08:00
|
|
|
if ($ref_model) {
|
|
|
|
$where['ref_model'] = $ref_model;
|
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-03-02 06:20:13 +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) {
|
|
|
|
$where['ref_model'] = $ref_model;
|
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
|
|
|
}
|