akaunting/app/Transformers/Banking/Transaction.php

87 lines
2.4 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
2019-11-16 10:21:14 +03:00
namespace App\Transformers\Banking;
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
use App\Transformers\Common\Contact;
2017-10-16 21:02:32 +03:00
use App\Transformers\Setting\Category;
use App\Transformers\Setting\Currency;
2019-11-16 10:21:14 +03:00
use App\Models\Banking\Transaction as Model;
2017-09-14 22:21:00 +03:00
use League\Fractal\TransformerAbstract;
2019-11-16 10:21:14 +03:00
class Transaction extends TransformerAbstract
2017-09-14 22:21:00 +03:00
{
/**
* @var array
*/
2019-11-16 10:21:14 +03:00
protected $defaultIncludes = ['account', 'category', 'contact', 'currency'];
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,
2019-11-16 10:21:14 +03:00
'type' => $model->type,
2017-09-14 22:21:00 +03:00
'account_id' => $model->account_id,
'paid_at' => $model->paid_at->toIso8601String(),
'amount' => $model->amount,
2021-06-22 17:44:38 +03:00
'amount_format' => money($model->amount, $model->currency_code, true)->format(),
2017-09-14 22:21:00 +03:00
'currency_code' => $model->currency_code,
'currency_rate' => $model->currency_rate,
2019-11-16 10:21:14 +03:00
'document_id' => $model->document_id,
'contact_id' => $model->contact_id,
2017-09-14 22:21:00 +03:00
'description' => $model->description,
'category_id' => $model->category_id,
'payment_method' => $model->payment_method,
'reference' => $model->reference,
'attachment' => $model->attachment,
2021-06-17 10:59:07 +03:00
'created_by' => $model->created_by,
2017-09-14 22:21:00 +03:00
'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
* @return \League\Fractal\Resource\Item
2017-09-14 22:21:00 +03:00
*/
public function includeCategory(Model $model)
2017-09-14 22:21:00 +03:00
{
return $this->item($model->category, new Category());
}
2017-10-09 11:59:58 +03:00
/**
* @param Model $model
2018-02-09 16:23:49 +03:00
* @return \League\Fractal\Resource\Item
*/
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
* @return mixed
2017-09-14 22:21:00 +03:00
*/
2019-11-16 10:21:14 +03:00
public function includeContact(Model $model)
2017-09-14 22:21:00 +03:00
{
2019-11-16 10:21:14 +03:00
if (!$model->contact) {
return $this->null();
}
2019-11-16 10:21:14 +03:00
return $this->item($model->contact, new Contact());
2017-09-14 22:21:00 +03:00
}
}