2017-09-14 22:21:00 +03:00
|
|
|
<?php
|
|
|
|
|
2020-12-24 01:28:38 +03:00
|
|
|
namespace App\Transformers\Document;
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2021-01-02 12:21:16 +03:00
|
|
|
use App\Models\Document\Document as Model;
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Transformers\Banking\Transaction;
|
|
|
|
use App\Transformers\Common\Contact;
|
2018-02-09 16:18:56 +03:00
|
|
|
use App\Transformers\Setting\Currency;
|
2017-09-14 22:21:00 +03:00
|
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
|
2020-12-24 01:28:38 +03:00
|
|
|
class Document extends TransformerAbstract
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2021-01-02 12:21:16 +03:00
|
|
|
protected $defaultIncludes = ['contact', 'currency', 'histories', 'items', 'item_taxes', 'totals', '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,
|
2020-12-24 01:28:38 +03:00
|
|
|
'type' => $model->type,
|
|
|
|
'document_number' => $model->document_number,
|
2017-09-14 22:21:00 +03:00
|
|
|
'order_number' => $model->order_number,
|
2020-01-11 16:57:32 +03:00
|
|
|
'status' => $model->status,
|
2020-12-24 01:28:38 +03:00
|
|
|
'issued_at' => $model->issued_at ? $model->issued_at->toIso8601String() : '',
|
2019-11-16 10:21:14 +03:00
|
|
|
'due_at' => $model->due_at ? $model->due_at->toIso8601String() : '',
|
2017-09-14 22:21:00 +03:00
|
|
|
'amount' => $model->amount,
|
2021-06-22 18:17:48 +03:00
|
|
|
'amount_formatted' => 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
|
|
|
'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,
|
2021-06-17 10:59:07 +03:00
|
|
|
'created_by' => $model->created_by,
|
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
|
|
|
/**
|
2018-02-09 16:18:56 +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
|
|
|
*/
|
2018-02-09 16:18:56 +03:00
|
|
|
public function includeCurrency(Model $model)
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
2018-02-09 16:18:56 +03:00
|
|
|
return $this->item($model->currency, new Currency());
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Model $model
|
2018-02-09 16:18:56 +03:00
|
|
|
* @return \League\Fractal\Resource\Collection
|
2017-09-14 22:21:00 +03:00
|
|
|
*/
|
2018-02-09 16:18:56 +03:00
|
|
|
public function includeHistories(Model $model)
|
2017-09-14 22:21:00 +03:00
|
|
|
{
|
2021-01-02 12:21:16 +03:00
|
|
|
return $this->collection($model->histories, new DocumentHistory());
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Model $model
|
|
|
|
* @return \League\Fractal\Resource\Collection
|
|
|
|
*/
|
|
|
|
public function includeItems(Model $model)
|
|
|
|
{
|
2021-01-02 12:21:16 +03:00
|
|
|
return $this->collection($model->items, new DocumentItem());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Model $model
|
|
|
|
* @return \League\Fractal\Resource\Collection
|
|
|
|
*/
|
|
|
|
public function includeItemTaxes(Model $model)
|
|
|
|
{
|
|
|
|
return $this->collection($model->item_taxes, new DocumentItemTax());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Model $model
|
|
|
|
* @return \League\Fractal\Resource\Collection
|
|
|
|
*/
|
|
|
|
public function includeTotals(Model $model)
|
|
|
|
{
|
|
|
|
return $this->collection($model->totals, new DocumentTotal());
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:18:56 +03:00
|
|
|
/**
|
|
|
|
* @param Model $model
|
2019-11-16 10:21:14 +03:00
|
|
|
* @return \League\Fractal\Resource\Collection
|
2018-02-09 16:18:56 +03:00
|
|
|
*/
|
2019-11-16 10:21:14 +03:00
|
|
|
public function includeTransactions(Model $model)
|
2018-02-09 16:18:56 +03:00
|
|
|
{
|
2019-11-16 10:21:14 +03:00
|
|
|
return $this->collection($model->transactions, new Transaction());
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
|
|
|
}
|