Changeset View
Changeset View
Standalone View
Standalone View
src/app/Wallet.php
Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | class Wallet extends Model | ||||
* @return string String representation, e.g. "9.99 CHF" | * @return string String representation, e.g. "9.99 CHF" | ||||
*/ | */ | ||||
public function money(int $amount, $locale = 'de_DE') | public function money(int $amount, $locale = 'de_DE') | ||||
{ | { | ||||
$amount = round($amount / 100, 2); | $amount = round($amount / 100, 2); | ||||
// Prefer intl extension's number formatter | // Prefer intl extension's number formatter | ||||
if (class_exists('NumberFormatter')) { | if (class_exists('NumberFormatter')) { | ||||
$nf = new \NumberFormatter($locale, \NumberFormatter::DECIMAL); | $nf = new \NumberFormatter($locale, \NumberFormatter::CURRENCY); | ||||
return $nf->formatCurrency($amount, $this->currency); | $result = $nf->formatCurrency($amount, $this->currency); | ||||
// Replace non-breaking space | |||||
return str_replace("\xC2\xA0", " ", $result); | |||||
} | } | ||||
return sprintf('%.2f %s', $amount, $this->currency); | return sprintf('%.2f %s', $amount, $this->currency); | ||||
} | } | ||||
/** | /** | ||||
* Controllers of this wallet. | * Controllers of this wallet. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | class Wallet extends Model | ||||
public function settings() | public function settings() | ||||
{ | { | ||||
return $this->hasMany('App\WalletSetting'); | return $this->hasMany('App\WalletSetting'); | ||||
} | } | ||||
/** | /** | ||||
* Retrieve the transactions against this wallet. | * Retrieve the transactions against this wallet. | ||||
* | * | ||||
* @return iterable \App\Transaction | * @return \Illuminate\Database\Eloquent\Builder Query builder | ||||
*/ | */ | ||||
public function transactions() | public function transactions() | ||||
{ | { | ||||
return \App\Transaction::where( | return \App\Transaction::where( | ||||
[ | [ | ||||
'object_id' => $this->id, | 'object_id' => $this->id, | ||||
'object_type' => \App\Wallet::class | 'object_type' => \App\Wallet::class | ||||
] | ] | ||||
)->orderBy('created_at')->get(); | ); | ||||
} | } | ||||
} | } |