102 lines
3.0 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
2017-10-16 21:02:32 +03:00
namespace App\Transformers\Expense;
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
use App\Transformers\Banking\Transaction;
use App\Transformers\Common\Contact;
use App\Transformers\Setting\Currency;
2017-09-14 22:21:00 +03:00
use App\Models\Expense\Bill as Model;
use League\Fractal\TransformerAbstract;
class Bill extends TransformerAbstract
{
/**
* @var array
*/
2019-11-16 10:21:14 +03:00
protected $defaultIncludes = ['contact', 'currency', 'histories', 'items', 'status', 'transactions'];
2017-09-14 22:21:00 +03:00
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $model->id,
'company_id' => $model->company_id,
'bill_number' => $model->bill_number,
'order_number' => $model->order_number,
'bill_status_code' => $model->invoice_status_code,
2019-11-16 10:21:14 +03:00
'billed_at' => $model->billed_at ? $model->billed_at->toIso8601String() : '',
'due_at' => $model->due_at ? $model->due_at->toIso8601String() : '',
2017-09-14 22:21:00 +03:00
'amount' => $model->amount,
'currency_code' => $model->currency_code,
'currency_rate' => $model->currency_rate,
2019-11-16 10:21:14 +03:00
'contact_id' => $model->contact_id,
'contact_name' => $model->contact_name,
'contact_email' => $model->contact_email,
'contact_tax_number' => $model->contact_tax_number,
'contact_phone' => $model->contact_phone,
'contact_address' => $model->contact_address,
2017-09-14 22:21:00 +03:00
'notes' => $model->notes,
'attachment' => $model->attachment,
2019-11-16 10:21:14 +03:00
'created_at' => $model->created_at ? $model->created_at->toIso8601String() : '',
'updated_at' => $model->updated_at ? $model->updated_at->toIso8601String() : '',
2017-09-14 22:21:00 +03:00
];
}
2019-11-16 10:21:14 +03:00
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
*/
public function includeContact(Model $model)
{
return $this->item($model->contact, new Contact());
}
2017-09-14 22:21:00 +03:00
/**
* @param Model $model
2018-02-09 16:23:49 +03:00
* @return \League\Fractal\Resource\Item
2017-09-14 22:21:00 +03:00
*/
public function includeCurrency(Model $model)
2017-09-14 22:21:00 +03:00
{
return $this->item($model->currency, new Currency());
2017-09-14 22:21:00 +03:00
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Collection
2017-09-14 22:21:00 +03:00
*/
public function includeHistories(Model $model)
2017-09-14 22:21:00 +03:00
{
return $this->collection($model->histories, new BillHistories());
2017-09-14 22:21:00 +03:00
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Collection
*/
public function includeItems(Model $model)
{
return $this->collection($model->items, new BillItems());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
2017-09-14 22:21:00 +03:00
*/
public function includeStatus(Model $model)
2017-09-14 22:21:00 +03:00
{
return $this->item($model->status, new BillStatus());
}
/**
* @param Model $model
2019-11-16 10:21:14 +03:00
* @return \League\Fractal\Resource\Collection
*/
2019-11-16 10:21:14 +03:00
public function includeTransactions(Model $model)
{
2019-11-16 10:21:14 +03:00
return $this->collection($model->transactions, new Transaction());
2017-09-14 22:21:00 +03:00
}
}