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

@ -27,6 +27,11 @@ class BillPayment extends Model
return $this->belongsTo('App\Models\Banking\Account'); return $this->belongsTo('App\Models\Banking\Account');
} }
public function currency()
{
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
}
public function bill() public function bill()
{ {
return $this->belongsTo('App\Models\Expense\Bill'); return $this->belongsTo('App\Models\Expense\Bill');

View File

@ -27,6 +27,11 @@ class InvoicePayment extends Model
return $this->belongsTo('App\Models\Banking\Account'); return $this->belongsTo('App\Models\Banking\Account');
} }
public function currency()
{
return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code');
}
public function invoice() public function invoice()
{ {
return $this->belongsTo('App\Models\Income\Invoice'); return $this->belongsTo('App\Models\Income\Invoice');

View File

@ -38,6 +38,11 @@ class Currency extends Model
return $this->hasMany('App\Models\Income\Invoice', 'currency_code', 'code'); return $this->hasMany('App\Models\Income\Invoice', 'currency_code', 'code');
} }
public function invoice_payments()
{
return $this->hasMany('App\Models\Income\InvoicePayment', 'currency_code', 'code');
}
public function revenues() public function revenues()
{ {
return $this->hasMany('App\Models\Income\Revenue', 'currency_code', 'code'); return $this->hasMany('App\Models\Income\Revenue', 'currency_code', 'code');
@ -48,6 +53,11 @@ class Currency extends Model
return $this->hasMany('App\Models\Expense\Bill', 'currency_code', 'code'); return $this->hasMany('App\Models\Expense\Bill', 'currency_code', 'code');
} }
public function bill_payments()
{
return $this->hasMany('App\Models\Expense\BillPayment', 'currency_code', 'code');
}
public function payments() public function payments()
{ {
return $this->hasMany('App\Models\Expense\Payment', 'currency_code', 'code'); return $this->hasMany('App\Models\Expense\Payment', 'currency_code', 'code');

View File

@ -7,6 +7,7 @@ use App\Transformers\Expense\BillItems;
use App\Transformers\Expense\BillPayments; use App\Transformers\Expense\BillPayments;
use App\Transformers\Expense\BillStatus; use App\Transformers\Expense\BillStatus;
use App\Transformers\Expense\Vendor; use App\Transformers\Expense\Vendor;
use App\Transformers\Setting\Currency;
use App\Models\Expense\Bill as Model; use App\Models\Expense\Bill as Model;
use League\Fractal\TransformerAbstract; use League\Fractal\TransformerAbstract;
@ -15,7 +16,7 @@ class Bill extends TransformerAbstract
/** /**
* @var array * @var array
*/ */
protected $defaultIncludes = ['vendor', 'status', 'items', 'payments', 'histories']; protected $defaultIncludes = ['currency', 'histories', 'items', 'payments', 'status', 'vendor'];
/** /**
* @param Model $model * @param Model $model
@ -49,29 +50,11 @@ class Bill extends TransformerAbstract
/** /**
* @param Model $model * @param Model $model
* @return \League\Fractal\Resource\Item * @return mixed
*/ */
public function includeVendor(Model $model) public function includeCurrency(Model $model)
{ {
return $this->item($model->vendor, new Vendor()); return $this->item($model->currency, new Currency());
}
/**
* @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());
} }
/** /**
@ -83,6 +66,15 @@ class Bill extends TransformerAbstract
return $this->collection($model->histories, new BillHistories()); 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 * @param Model $model
* @return \League\Fractal\Resource\Collection * @return \League\Fractal\Resource\Collection
@ -91,4 +83,22 @@ class Bill extends TransformerAbstract
{ {
return $this->collection($model->payments, new BillPayments()); 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; namespace App\Transformers\Expense;
use App\Transformers\Banking\Account; use App\Transformers\Banking\Account;
use App\Transformers\Setting\Currency;
use App\Models\Expense\BillPayment as Model; use App\Models\Expense\BillPayment as Model;
use League\Fractal\TransformerAbstract; use League\Fractal\TransformerAbstract;
@ -11,7 +12,7 @@ class BillPayments extends TransformerAbstract
/** /**
* @var array * @var array
*/ */
protected $defaultIncludes = ['account']; protected $defaultIncludes = ['account', 'currency'];
/** /**
* @param Model $model * @param Model $model
@ -45,4 +46,13 @@ class BillPayments extends TransformerAbstract
{ {
return $this->item($model->account, new Account()); 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\Banking\Account;
use App\Transformers\Expense\Vendor; use App\Transformers\Expense\Vendor;
use App\Transformers\Setting\Category; use App\Transformers\Setting\Category;
use App\Transformers\Setting\Currency;
use App\Models\Expense\Payment as Model; use App\Models\Expense\Payment as Model;
use League\Fractal\TransformerAbstract; use League\Fractal\TransformerAbstract;
@ -13,7 +14,7 @@ class Payment extends TransformerAbstract
/** /**
* @var array * @var array
*/ */
protected $defaultIncludes = ['account', 'vendor', 'category']; protected $defaultIncludes = ['account', 'category', 'currency', 'vendor'];
/** /**
* @param Model $model * @param Model $model
@ -49,6 +50,24 @@ class Payment extends TransformerAbstract
return $this->item($model->account, new Account()); 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 * @param Model $model
* @return mixed * @return mixed
@ -61,13 +80,4 @@ class Payment extends TransformerAbstract
return $this->item($model->vendor, new Vendor()); 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\InvoiceItems;
use App\Transformers\Income\InvoicePayments; use App\Transformers\Income\InvoicePayments;
use App\Transformers\Income\InvoiceStatus; use App\Transformers\Income\InvoiceStatus;
use App\Transformers\Setting\Currency;
use App\Models\Income\Invoice as Model; use App\Models\Income\Invoice as Model;
use League\Fractal\TransformerAbstract; use League\Fractal\TransformerAbstract;
@ -15,7 +16,7 @@ class Invoice extends TransformerAbstract
/** /**
* @var array * @var array
*/ */
protected $defaultIncludes = ['customer', 'status', 'items', 'payments', 'histories']; protected $defaultIncludes = ['currency', 'customer', 'histories', 'items', 'payments', 'status'];
/** /**
* @param Model $model * @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 * @param Model $model
* @return \League\Fractal\Resource\Item * @return \League\Fractal\Resource\Item
@ -56,24 +66,6 @@ class Invoice extends TransformerAbstract
return $this->item($model->customer, new Customer()); 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 * @param Model $model
* @return \League\Fractal\Resource\Collection * @return \League\Fractal\Resource\Collection
@ -83,6 +75,15 @@ class Invoice extends TransformerAbstract
return $this->collection($model->histories, new InvoiceHistories()); 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 * @param Model $model
* @return \League\Fractal\Resource\Collection * @return \League\Fractal\Resource\Collection
@ -91,4 +92,13 @@ class Invoice extends TransformerAbstract
{ {
return $this->collection($model->payments, new InvoicePayments()); 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; namespace App\Transformers\Income;
use App\Transformers\Banking\Account; use App\Transformers\Banking\Account;
use App\Transformers\Setting\Currency;
use App\Models\Income\InvoicePayment as Model; use App\Models\Income\InvoicePayment as Model;
use League\Fractal\TransformerAbstract; use League\Fractal\TransformerAbstract;
@ -11,7 +12,7 @@ class InvoicePayments extends TransformerAbstract
/** /**
* @var array * @var array
*/ */
protected $defaultIncludes = ['account']; protected $defaultIncludes = ['account', 'currency'];
/** /**
* @param Model $model * @param Model $model
@ -45,4 +46,13 @@ class InvoicePayments extends TransformerAbstract
{ {
return $this->item($model->account, new Account()); 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\Banking\Account;
use App\Transformers\Income\Customer; use App\Transformers\Income\Customer;
use App\Transformers\Setting\Category; use App\Transformers\Setting\Category;
use App\Transformers\Setting\Currency;
use App\Models\Income\Revenue as Model; use App\Models\Income\Revenue as Model;
use League\Fractal\TransformerAbstract; use League\Fractal\TransformerAbstract;
@ -13,7 +14,7 @@ class Revenue extends TransformerAbstract
/** /**
* @var array * @var array
*/ */
protected $defaultIncludes = ['account', 'customer', 'category']; protected $defaultIncludes = ['account', 'category', 'currency', 'customer'];
/** /**
* @param Model $model * @param Model $model
@ -49,6 +50,24 @@ class Revenue extends TransformerAbstract
return $this->item($model->account, new Account()); 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 * @param Model $model
* @return mixed * @return mixed
@ -61,13 +80,4 @@ class Revenue extends TransformerAbstract
return $this->item($model->customer, new Customer()); 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());
}
} }