From bbb34ab50a62fdaee1b1630c52a82701a0cde0d2 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Wed, 4 Oct 2017 01:25:03 +0300 Subject: [PATCH] fixed #36 --- app/Models/Banking/Account.php | 11 ++++++++++ app/Models/Expense/Bill.php | 22 +++++++++++++++++++ app/Models/Expense/Payment.php | 22 +++++++++++++++++++ app/Models/Income/Invoice.php | 22 +++++++++++++++++++ app/Models/Income/Revenue.php | 22 +++++++++++++++++++ app/Models/Item/Item.php | 22 +++++++++++++++++++ app/Models/Setting/Currency.php | 11 ++++++++++ ...017_09_01_000000_create_accounts_table.php | 2 +- 8 files changed, 133 insertions(+), 1 deletion(-) diff --git a/app/Models/Banking/Account.php b/app/Models/Banking/Account.php index b4f24f609..fbc1fedd2 100644 --- a/app/Models/Banking/Account.php +++ b/app/Models/Banking/Account.php @@ -70,6 +70,17 @@ class Account extends Model return $this->hasMany('App\Models\Expense\Payment'); } + /** + * Convert opening balance to float. + * + * @param string $value + * @return void + */ + public function setOpeningBalanceAttribute($value) + { + $this->attributes['opening_balance'] = (float) $value; + } + public function canDelete() { $error = false; diff --git a/app/Models/Expense/Bill.php b/app/Models/Expense/Bill.php index 15ce9bb09..f131812cf 100644 --- a/app/Models/Expense/Bill.php +++ b/app/Models/Expense/Bill.php @@ -84,6 +84,28 @@ class Bill extends Model return $this->hasMany('App\Models\Expense\BillHistory'); } + /** + * Convert amount to float. + * + * @param string $value + * @return void + */ + public function setAmountAttribute($value) + { + $this->attributes['amount'] = (float) $value; + } + + /** + * Convert currency rate to float. + * + * @param string $value + * @return void + */ + public function setCurrencyRateAttribute($value) + { + $this->attributes['currency_rate'] = (float) $value; + } + public function scopeDue($query, $date) { return $query->where('due_at', '=', $date); diff --git a/app/Models/Expense/Payment.php b/app/Models/Expense/Payment.php index e6ad5ef27..1fca04f28 100644 --- a/app/Models/Expense/Payment.php +++ b/app/Models/Expense/Payment.php @@ -64,6 +64,28 @@ class Payment extends Model return $this->hasMany('App\Models\Banking\Transfer'); } + /** + * Convert amount to float. + * + * @param string $value + * @return void + */ + public function setAmountAttribute($value) + { + $this->attributes['amount'] = (float) $value; + } + + /** + * Convert currency rate to float. + * + * @param string $value + * @return void + */ + public function setCurrencyRateAttribute($value) + { + $this->attributes['currency_rate'] = (float) $value; + } + public static function scopeLatest($query) { return $query->orderBy('paid_at', 'desc'); diff --git a/app/Models/Income/Invoice.php b/app/Models/Income/Invoice.php index cbf4c4996..35443d604 100644 --- a/app/Models/Income/Invoice.php +++ b/app/Models/Income/Invoice.php @@ -89,6 +89,28 @@ class Invoice extends Model return $this->hasMany('App\Models\Income\InvoiceHistory'); } + /** + * Convert amount to float. + * + * @param string $value + * @return void + */ + public function setAmountAttribute($value) + { + $this->attributes['amount'] = (float) $value; + } + + /** + * Convert currency rate to float. + * + * @param string $value + * @return void + */ + public function setCurrencyRateAttribute($value) + { + $this->attributes['currency_rate'] = (float) $value; + } + public function scopeDue($query, $date) { return $query->where('due_at', '=', $date); diff --git a/app/Models/Income/Revenue.php b/app/Models/Income/Revenue.php index 74ec9fd97..2e3cd8c7d 100644 --- a/app/Models/Income/Revenue.php +++ b/app/Models/Income/Revenue.php @@ -70,6 +70,28 @@ class Revenue extends Model return $this->hasMany('App\Models\Banking\Transfer'); } + /** + * Convert amount to float. + * + * @param string $value + * @return void + */ + public function setAmountAttribute($value) + { + $this->attributes['amount'] = (float) $value; + } + + /** + * Convert currency rate to float. + * + * @param string $value + * @return void + */ + public function setCurrencyRateAttribute($value) + { + $this->attributes['currency_rate'] = (float) $value; + } + public function scopeLatest($query) { return $query->orderBy('paid_at', 'desc'); diff --git a/app/Models/Item/Item.php b/app/Models/Item/Item.php index 88a6a7c8d..631a4e07d 100644 --- a/app/Models/Item/Item.php +++ b/app/Models/Item/Item.php @@ -59,6 +59,28 @@ class Item extends Model return $this->hasMany('App\Models\Income\Invoice'); } + /** + * Convert sale price to float. + * + * @param string $value + * @return void + */ + public function setSalePriceAttribute($value) + { + $this->attributes['sale_price'] = (float) $value; + } + + /** + * Convert purchase price to float. + * + * @param string $value + * @return void + */ + public function setPurchasePriceAttribute($value) + { + $this->attributes['purchase_price'] = (float) $value; + } + public function getConvertedAmount($format = false) { return $this->convert($this->amount, $this->currency_code, $this->currency_rate, $format); diff --git a/app/Models/Setting/Currency.php b/app/Models/Setting/Currency.php index 42cfc1716..2e0eff22e 100644 --- a/app/Models/Setting/Currency.php +++ b/app/Models/Setting/Currency.php @@ -53,6 +53,17 @@ class Currency extends Model return $this->hasMany('App\Models\Expense\Payment', 'currency_code', 'code'); } + /** + * Convert rate to float. + * + * @param string $value + * @return void + */ + public function setRateAttribute($value) + { + $this->attributes['rate'] = (float) $value; + } + public function canDisable() { $error = false; diff --git a/database/migrations/2017_09_01_000000_create_accounts_table.php b/database/migrations/2017_09_01_000000_create_accounts_table.php index d6cb5addc..c3a2321a2 100644 --- a/database/migrations/2017_09_01_000000_create_accounts_table.php +++ b/database/migrations/2017_09_01_000000_create_accounts_table.php @@ -18,7 +18,7 @@ class CreateAccountsTable extends Migration $table->string('name'); $table->string('number'); $table->string('currency_code'); - $table->decimal('opening_balance')->default('0'); + $table->float('opening_balance', 15, 4)->default('0.0000'); $table->string('bank_name')->nullable(); $table->string('bank_phone')->nullable(); $table->text('bank_address')->nullable();