2017-09-14 22:21:00 +03:00
|
|
|
<?php
|
|
|
|
|
2017-10-16 21:02:32 +03:00
|
|
|
namespace App\Transformers\Income;
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2017-10-16 21:02:32 +03:00
|
|
|
use App\Transformers\Banking\Account;
|
|
|
|
use App\Transformers\Income\Customer;
|
|
|
|
use App\Transformers\Setting\Category;
|
2018-02-09 16:18:56 +03:00
|
|
|
use App\Transformers\Setting\Currency;
|
2017-09-14 22:21:00 +03:00
|
|
|
use App\Models\Income\Revenue as Model;
|
|
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
|
|
|
|
class Revenue extends TransformerAbstract
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2018-02-09 16:18:56 +03:00
|
|
|
protected $defaultIncludes = ['account', 'category', 'currency', 'customer'];
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
/**
|
2017-10-09 11:59:58 +03:00
|
|
|
* @param Model $model
|
2017-09-14 22:21:00 +03:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(Model $model)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $model->id,
|
|
|
|
'company_id' => $model->company_id,
|
|
|
|
'account_id' => $model->account_id,
|
|
|
|
'paid_at' => $model->paid_at->toIso8601String(),
|
|
|
|
'amount' => $model->amount,
|
|
|
|
'currency_code' => $model->currency_code,
|
|
|
|
'currency_rate' => $model->currency_rate,
|
|
|
|
'customer_id' => $model->customer_id,
|
|
|
|
'description' => $model->description,
|
|
|
|
'category_id' => $model->category_id,
|
|
|
|
'payment_method' => $model->payment_method,
|
|
|
|
'reference' => $model->reference,
|
|
|
|
'attachment' => $model->attachment,
|
|
|
|
'created_at' => $model->created_at->toIso8601String(),
|
|
|
|
'updated_at' => $model->updated_at->toIso8601String(),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-09 11:59:58 +03:00
|
|
|
* @param Model $model
|
2017-09-14 22:21:00 +03:00
|
|
|
* @return \League\Fractal\Resource\Item
|
|
|
|
*/
|
|
|
|
public function includeAccount(Model $model)
|
|
|
|
{
|
|
|
|
return $this->item($model->account, new Account());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-09 11:59:58 +03:00
|
|
|
* @param Model $model
|
2018-02-09 16:18:56 +03:00
|
|
|
* @return \League\Fractal\Resource\Item
|
2017-09-14 22:21:00 +03:00
|
|
|
*/
|
2018-02-09 16:18:56 +03:00
|
|
|
public function includeCategory(Model $model)
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
2018-02-09 16:18:56 +03:00
|
|
|
return $this->item($model->category, new Category());
|
|
|
|
}
|
2017-10-09 11:59:58 +03:00
|
|
|
|
2018-02-09 16:18:56 +03:00
|
|
|
/**
|
|
|
|
* @param Model $model
|
2018-02-09 16:23:49 +03:00
|
|
|
* @return \League\Fractal\Resource\Item
|
2018-02-09 16:18:56 +03:00
|
|
|
*/
|
|
|
|
public function includeCurrency(Model $model)
|
|
|
|
{
|
|
|
|
return $this->item($model->currency, new Currency());
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-09 11:59:58 +03:00
|
|
|
* @param Model $model
|
2018-02-09 16:18:56 +03:00
|
|
|
* @return mixed
|
2017-09-14 22:21:00 +03:00
|
|
|
*/
|
2018-02-09 16:18:56 +03:00
|
|
|
public function includeCustomer(Model $model)
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
2018-02-09 16:18:56 +03:00
|
|
|
if (!$model->customer) {
|
|
|
|
return $this->null();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->item($model->customer, new Customer());
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
}
|