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,94 @@
<?php
namespace App\Transformers\Expense;
use App\Transformers\Expense\BillHistories;
use App\Transformers\Expense\BillItems;
use App\Transformers\Expense\BillPayments;
use App\Transformers\Expense\BillStatus;
use App\Transformers\Expense\Vendor;
use App\Models\Expense\Bill as Model;
use League\Fractal\TransformerAbstract;
class Bill extends TransformerAbstract
{
/**
* @var array
*/
protected $defaultIncludes = ['vendor', 'status', 'items', 'payments', 'histories'];
/**
* @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,
'billed_at' => $model->billed_at->toIso8601String(),
'due_at' => $model->due_at->toIso8601String(),
'amount' => $model->amount,
'currency_code' => $model->currency_code,
'currency_rate' => $model->currency_rate,
'vendor_id' => $model->vendor_id,
'vendor_name' => $model->vendor_name,
'vendor_email' => $model->vendor_email,
'vendor_tax_number' => $model->vendor_tax_number,
'vendor_phone' => $model->vendor_phone,
'vendor_address' => $model->vendor_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 includeVendor(Model $model)
{
return $this->item($model->vendor, new Vendor());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
*/
public function includeStatus(Model $model)
{
return $this->item($model->status, new BillStatus());
}
/**
* @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\Collection
*/
public function includeHistories(Model $model)
{
return $this->collection($model->histories, new BillHistories());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Collection
*/
public function includePayments(Model $model)
{
return $this->collection($model->payments, new BillPayments());
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Transformers\Expense;
use App\Models\Expense\BillHistory as Model;
use League\Fractal\TransformerAbstract;
class BillHistories extends TransformerAbstract
{
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $model->id,
'company_id' => $model->company_id,
'bill_id' => $model->bill_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\Expense;
use App\Models\Expense\BillItem as Model;
use League\Fractal\TransformerAbstract;
class BillItems extends TransformerAbstract
{
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $model->id,
'company_id' => $model->company_id,
'bill_id' => $model->bill_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\Expense;
use App\Transformers\Banking\Account;
use App\Models\Expense\BillPayment as Model;
use League\Fractal\TransformerAbstract;
class BillPayments 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,
'bill_id' => $model->bill_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\Expense;
use App\Models\Expense\BillStatus as Model;
use League\Fractal\TransformerAbstract;
class BillStatus 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\Expense;
use App\Models\Expense\BillTotal as Model;
use League\Fractal\TransformerAbstract;
class BillTotals extends TransformerAbstract
{
/**
* @param Model $model
* @return array
*/
public function transform(Model $model)
{
return [
'id' => $model->id,
'company_id' => $model->company_id,
'bill_id' => $model->bill_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\Expense;
use App\Transformers\Banking\Account;
use App\Transformers\Expense\Vendor;
use App\Transformers\Setting\Category;
use App\Models\Expense\Payment as Model;
use League\Fractal\TransformerAbstract;
class Payment extends TransformerAbstract
{
/**
* @var array
*/
protected $defaultIncludes = ['account', 'vendor', '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,
'vendor_id' => $model->vendor_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 includeVendor(Model $model)
{
if (!$model->vendor) {
return $this->null();
}
return $this->item($model->vendor, new Vendor());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
*/
public function includeCategory(Model $model)
{
return $this->item($model->category, new Category());
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Transformers\Expense;
use App\Models\Expense\Vendor as Model;
use League\Fractal\TransformerAbstract;
class Vendor 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(),
];
}
}