added currency transformer to incomes/expenses api

This commit is contained in:
denisdulici
2018-02-09 16:18:56 +03:00
parent dc9b33a68f
commit e97731eed9
9 changed files with 144 additions and 64 deletions

View File

@ -7,6 +7,7 @@ use App\Transformers\Expense\BillItems;
use App\Transformers\Expense\BillPayments;
use App\Transformers\Expense\BillStatus;
use App\Transformers\Expense\Vendor;
use App\Transformers\Setting\Currency;
use App\Models\Expense\Bill as Model;
use League\Fractal\TransformerAbstract;
@ -15,7 +16,7 @@ class Bill extends TransformerAbstract
/**
* @var array
*/
protected $defaultIncludes = ['vendor', 'status', 'items', 'payments', 'histories'];
protected $defaultIncludes = ['currency', 'histories', 'items', 'payments', 'status', 'vendor'];
/**
* @param Model $model
@ -48,30 +49,12 @@ class Bill extends TransformerAbstract
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
* @param Model $model
* @return mixed
*/
public function includeVendor(Model $model)
public function includeCurrency(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());
return $this->item($model->currency, new Currency());
}
/**
@ -83,6 +66,15 @@ class Bill extends TransformerAbstract
return $this->collection($model->histories, new BillHistories());
}
/**
* @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
@ -91,4 +83,22 @@ class Bill extends TransformerAbstract
{
return $this->collection($model->payments, new BillPayments());
}
/**
* @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\Item
*/
public function includeVendor(Model $model)
{
return $this->item($model->vendor, new Vendor());
}
}

View File

@ -3,6 +3,7 @@
namespace App\Transformers\Expense;
use App\Transformers\Banking\Account;
use App\Transformers\Setting\Currency;
use App\Models\Expense\BillPayment as Model;
use League\Fractal\TransformerAbstract;
@ -11,7 +12,7 @@ class BillPayments extends TransformerAbstract
/**
* @var array
*/
protected $defaultIncludes = ['account'];
protected $defaultIncludes = ['account', 'currency'];
/**
* @param Model $model
@ -45,4 +46,13 @@ class BillPayments extends TransformerAbstract
{
return $this->item($model->account, new Account());
}
/**
* @param Model $model
* @return mixed
*/
public function includeCurrency(Model $model)
{
return $this->item($model->currency, new Currency());
}
}

View File

@ -5,6 +5,7 @@ namespace App\Transformers\Expense;
use App\Transformers\Banking\Account;
use App\Transformers\Expense\Vendor;
use App\Transformers\Setting\Category;
use App\Transformers\Setting\Currency;
use App\Models\Expense\Payment as Model;
use League\Fractal\TransformerAbstract;
@ -13,7 +14,7 @@ class Payment extends TransformerAbstract
/**
* @var array
*/
protected $defaultIncludes = ['account', 'vendor', 'category'];
protected $defaultIncludes = ['account', 'category', 'currency', 'vendor'];
/**
* @param Model $model
@ -49,6 +50,24 @@ class Payment extends TransformerAbstract
return $this->item($model->account, new Account());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
*/
public function includeCategory(Model $model)
{
return $this->item($model->category, new Category());
}
/**
* @param Model $model
* @return mixed
*/
public function includeCurrency(Model $model)
{
return $this->item($model->currency, new Currency());
}
/**
* @param Model $model
* @return mixed
@ -61,13 +80,4 @@ class Payment extends TransformerAbstract
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

@ -7,6 +7,7 @@ use App\Transformers\Income\InvoiceHistories;
use App\Transformers\Income\InvoiceItems;
use App\Transformers\Income\InvoicePayments;
use App\Transformers\Income\InvoiceStatus;
use App\Transformers\Setting\Currency;
use App\Models\Income\Invoice as Model;
use League\Fractal\TransformerAbstract;
@ -15,7 +16,7 @@ class Invoice extends TransformerAbstract
/**
* @var array
*/
protected $defaultIncludes = ['customer', 'status', 'items', 'payments', 'histories'];
protected $defaultIncludes = ['currency', 'customer', 'histories', 'items', 'payments', 'status'];
/**
* @param Model $model
@ -47,6 +48,15 @@ class Invoice extends TransformerAbstract
];
}
/**
* @param Model $model
* @return mixed
*/
public function includeCurrency(Model $model)
{
return $this->item($model->currency, new Currency());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
@ -56,24 +66,6 @@ class Invoice extends TransformerAbstract
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
@ -83,6 +75,15 @@ class Invoice extends TransformerAbstract
return $this->collection($model->histories, new InvoiceHistories());
}
/**
* @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
@ -91,4 +92,13 @@ class Invoice extends TransformerAbstract
{
return $this->collection($model->payments, new InvoicePayments());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
*/
public function includeStatus(Model $model)
{
return $this->item($model->status, new InvoiceStatus());
}
}

View File

@ -3,6 +3,7 @@
namespace App\Transformers\Income;
use App\Transformers\Banking\Account;
use App\Transformers\Setting\Currency;
use App\Models\Income\InvoicePayment as Model;
use League\Fractal\TransformerAbstract;
@ -11,7 +12,7 @@ class InvoicePayments extends TransformerAbstract
/**
* @var array
*/
protected $defaultIncludes = ['account'];
protected $defaultIncludes = ['account', 'currency'];
/**
* @param Model $model
@ -45,4 +46,13 @@ class InvoicePayments extends TransformerAbstract
{
return $this->item($model->account, new Account());
}
/**
* @param Model $model
* @return mixed
*/
public function includeCurrency(Model $model)
{
return $this->item($model->currency, new Currency());
}
}

View File

@ -5,6 +5,7 @@ namespace App\Transformers\Income;
use App\Transformers\Banking\Account;
use App\Transformers\Income\Customer;
use App\Transformers\Setting\Category;
use App\Transformers\Setting\Currency;
use App\Models\Income\Revenue as Model;
use League\Fractal\TransformerAbstract;
@ -13,7 +14,7 @@ class Revenue extends TransformerAbstract
/**
* @var array
*/
protected $defaultIncludes = ['account', 'customer', 'category'];
protected $defaultIncludes = ['account', 'category', 'currency', 'customer'];
/**
* @param Model $model
@ -49,6 +50,24 @@ class Revenue extends TransformerAbstract
return $this->item($model->account, new Account());
}
/**
* @param Model $model
* @return \League\Fractal\Resource\Item
*/
public function includeCategory(Model $model)
{
return $this->item($model->category, new Category());
}
/**
* @param Model $model
* @return mixed
*/
public function includeCurrency(Model $model)
{
return $this->item($model->currency, new Currency());
}
/**
* @param Model $model
* @return mixed
@ -61,13 +80,4 @@ class Revenue extends TransformerAbstract
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());
}
}