moved transformers

This commit is contained in:
denisdulici
2017-10-16 21:02:32 +03:00
parent b1b36d8a64
commit 33f805fba5
44 changed files with 96 additions and 66 deletions

View File

@ -0,0 +1,32 @@
<?php
namespace App\Transformers\Income;
use App\Models\Income\Customer as Model;
use League\Fractal\TransformerAbstract;
class Customer extends TransformerAbstract
{
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $model->id,
'company_id' => $model->company_id,
'user_id' => $model->user_id,
'name' => $model->name,
'email' => $model->email,
'tax_number' => $model->tax_number,
'phone' => $model->phone,
'address' => $model->address,
'website' => $model->website,
'currency_code' => $model->currency_code,
'enabled' => $model->enabled,
'created_at' => $model->created_at->toIso8601String(),
'updated_at' => $model->updated_at->toIso8601String(),
];
}
}

View File

@ -0,0 +1,94 @@
<?php
namespace App\Transformers\Income;
use App\Transformers\Income\Customer;
use App\Transformers\Income\InvoiceHistories;
use App\Transformers\Income\InvoiceItems;
use App\Transformers\Income\InvoicePayments;
use App\Transformers\Income\InvoiceStatus;
use App\Models\Income\Invoice as Model;
use League\Fractal\TransformerAbstract;
class Invoice extends TransformerAbstract
{
/**
* @var array
*/
protected $defaultIncludes = ['customer', 'status', 'items', 'payments', 'histories'];
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $model->id,
'company_id' => $model->company_id,
'invoice_number' => $model->invoice_number,
'order_number' => $model->order_number,
'invoice_status_code' => $model->invoice_status_code,
'invoiced_at' => $model->invoiced_at->toIso8601String(),
'due_at' => $model->due_at->toIso8601String(),
'amount' => $model->amount,
'currency_code' => $model->currency_code,
'currency_rate' => $model->currency_rate,
'customer_id' => $model->customer_id,
'customer_name' => $model->customer_name,
'customer_email' => $model->customer_email,
'customer_tax_number' => $model->customer_tax_number,
'customer_phone' => $model->customer_phone,
'customer_address' => $model->customer_address,
'notes' => $model->notes,
'attachment' => $model->attachment,
'created_at' => $model->created_at->toIso8601String(),
'updated_at' => $model->updated_at->toIso8601String(),
];
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
*/
public function includeCustomer(Model $model)
{
return $this->item($model->customer, new Customer());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
*/
public function includeStatus(Model $model)
{
return $this->item($model->status, new InvoiceStatus());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Collection
*/
public function includeItems(Model $model)
{
return $this->collection($model->items, new InvoiceItems());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Collection
*/
public function includeHistories(Model $model)
{
return $this->collection($model->histories, new InvoiceHistories());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Collection
*/
public function includePayments(Model $model)
{
return $this->collection($model->payments, new InvoicePayments());
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Transformers\Income;
use App\Models\Income\InvoiceHistory as Model;
use League\Fractal\TransformerAbstract;
class InvoiceHistories extends TransformerAbstract
{
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $model->id,
'company_id' => $model->company_id,
'invoice_id' => $model->invoice_id,
'status_code' => $model->status_code,
'notify' => $model->notify,
'description' => $model->description,
'created_at' => $model->created_at->toIso8601String(),
'updated_at' => $model->updated_at->toIso8601String(),
];
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Transformers\Income;
use App\Models\Income\InvoiceItem as Model;
use League\Fractal\TransformerAbstract;
class InvoiceItems extends TransformerAbstract
{
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $model->id,
'company_id' => $model->company_id,
'invoice_id' => $model->invoice_id,
'item_id' => $model->item_id,
'name' => $model->name,
'sku' => $model->sku,
'quantity' => $model->quantity,
'price' => $model->price,
'total' => $model->total,
'tax' => $model->tax,
'tax_id' => $model->tax_id,
'created_at' => $model->created_at->toIso8601String(),
'updated_at' => $model->updated_at->toIso8601String(),
];
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace App\Transformers\Income;
use App\Transformers\Banking\Account;
use App\Models\Income\InvoicePayment as Model;
use League\Fractal\TransformerAbstract;
class InvoicePayments extends TransformerAbstract
{
/**
* @var array
*/
protected $defaultIncludes = ['account'];
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $model->id,
'company_id' => $model->company_id,
'invoice_id' => $model->invoice_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,
'description' => $model->description,
'payment_method' => $model->payment_method,
'reference' => $model->reference,
'attachment' => $model->attachment,
'created_at' => $model->created_at->toIso8601String(),
'updated_at' => $model->updated_at->toIso8601String(),
];
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
*/
public function includeAccount(Model $model)
{
return $this->item($model->account, new Account());
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Transformers\Income;
use App\Models\Income\InvoiceStatus as Model;
use League\Fractal\TransformerAbstract;
class InvoiceStatus extends TransformerAbstract
{
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $model->id,
'company_id' => $model->company_id,
'name' => $model->name,
'code' => $model->code,
'created_at' => $model->created_at->toIso8601String(),
'updated_at' => $model->updated_at->toIso8601String(),
];
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\Transformers\Income;
use App\Models\Income\InvoiceTotal as Model;
use League\Fractal\TransformerAbstract;
class InvoiceTotals extends TransformerAbstract
{
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $model->id,
'company_id' => $model->company_id,
'invoice_id' => $model->invoice_id,
'code' => $model->code,
'name' => $model->name,
'amount' => $model->amount,
'sort_order' => $model->sort_order,
'created_at' => $model->created_at->toIso8601String(),
'updated_at' => $model->updated_at->toIso8601String(),
];
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace App\Transformers\Income;
use App\Transformers\Banking\Account;
use App\Transformers\Income\Customer;
use App\Transformers\Setting\Category;
use App\Models\Income\Revenue as Model;
use League\Fractal\TransformerAbstract;
class Revenue extends TransformerAbstract
{
/**
* @var array
*/
protected $defaultIncludes = ['account', 'customer', 'category'];
/**
* @param Model $model
* @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(),
];
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
*/
public function includeAccount(Model $model)
{
return $this->item($model->account, new Account());
}
/**
* @param Model $model
* @return mixed
*/
public function includeCustomer(Model $model)
{
if (!$model->customer) {
return $this->null();
}
return $this->item($model->customer, new Customer());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
*/
public function includeCategory(Model $model)
{
return $this->item($model->category, new Category());
}
}