updated money
package to 5.0 version
This commit is contained in:
@ -64,7 +64,7 @@ class Currencies extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$currency = config('money.' . $request->get('code'));
|
||||
$currency = config('money.currencies.' . $request->get('code'));
|
||||
|
||||
$request['precision'] = (int) $currency['precision'];
|
||||
$request['symbol'] = $currency['symbol'];
|
||||
|
@ -235,7 +235,7 @@ class Currencies extends Controller
|
||||
if ($code) {
|
||||
$currencies = Currency::all()->pluck('rate', 'code');
|
||||
|
||||
$currency = config('money.' . $code);
|
||||
$currency = config('money.currencies.' . $code);
|
||||
|
||||
$currency['rate'] = isset($currencies[$code]) ? $currencies[$code] : null;
|
||||
$currency['symbol_first'] = ! empty($currency['symbol_first']) ? 1 : 0;
|
||||
|
@ -84,7 +84,7 @@ class Money
|
||||
|
||||
$amount = $item['price'];
|
||||
|
||||
if (strpos($item['price'], config('money.' . $currency_code . '.symbol')) !== false) {
|
||||
if (strpos($item['price'], config('money.currencies.' . $currency_code . '.symbol')) !== false) {
|
||||
$amount = $this->getAmount($item['price'], $currency_code);
|
||||
}
|
||||
|
||||
@ -101,8 +101,8 @@ class Money
|
||||
protected function getAmount($money_format, $currency_code)
|
||||
{
|
||||
try {
|
||||
if (config('money.' . $currency_code . '.decimal_mark') !== '.') {
|
||||
$money_format = Str::replaceFirst('.', config('money.' . $currency_code . '.decimal_mark'), $money_format);
|
||||
if (config('money.currencies.' . $currency_code . '.decimal_mark') !== '.') {
|
||||
$money_format = Str::replaceFirst('.', config('money.currencies.' . $currency_code . '.decimal_mark'), $money_format);
|
||||
}
|
||||
|
||||
$amount = money($money_format, $currency_code)->getAmount();
|
||||
|
@ -69,7 +69,7 @@ class CreateBankingDocumentTransaction extends Job implements ShouldCreate
|
||||
$this->request['company_id'] = $this->model->company_id;
|
||||
$this->request['currency_code'] = $currency_code;
|
||||
$this->request['paid_at'] = isset($this->request['paid_at']) ? $this->request['paid_at'] : Date::now()->toDateTimeString();
|
||||
$this->request['currency_rate'] = config('money.' . $currency_code . '.rate');
|
||||
$this->request['currency_rate'] = config('money.currencies.' . $currency_code . '.rate');
|
||||
$this->request['account_id'] = isset($this->request['account_id']) ? $this->request['account_id'] : setting('default.account');
|
||||
$this->request['document_id'] = isset($this->request['document_id']) ? $this->request['document_id'] : $this->model->id;
|
||||
$this->request['contact_id'] = isset($this->request['contact_id']) ? $this->request['contact_id'] : $this->model->contact_id;
|
||||
@ -83,7 +83,7 @@ class CreateBankingDocumentTransaction extends Job implements ShouldCreate
|
||||
$code = $this->request['currency_code'];
|
||||
$rate = $this->request['currency_rate'];
|
||||
|
||||
$precision = config('money.' . $code . '.precision');
|
||||
$precision = config('money.currencies.' . $code . '.precision');
|
||||
|
||||
$amount = $this->request['amount'] = round($this->request['amount'], $precision);
|
||||
|
||||
|
@ -107,7 +107,7 @@ class CreateTransfer extends Job implements HasOwner, HasSource, ShouldCreate
|
||||
$currency_rate = $this->request->get($type . '_account_rate');
|
||||
|
||||
if (empty($currency_rate)) {
|
||||
$currency_rate = config('money.' . $this->getCurrencyCode($type) . '.rate');
|
||||
$currency_rate = config('money.currencies.' . $this->getCurrencyCode($type) . '.rate');
|
||||
}
|
||||
|
||||
return $currency_rate;
|
||||
|
@ -42,7 +42,7 @@ class MatchBankingDocumentTransaction extends Job
|
||||
$code = $this->transaction->currency_code;
|
||||
$rate = $this->transaction->currency_rate;
|
||||
|
||||
$precision = config('money.' . $code . '.precision');
|
||||
$precision = config('money.currencies.' . $code . '.precision');
|
||||
|
||||
$amount = $this->transaction->amount = round($this->transaction->amount, $precision);
|
||||
|
||||
|
@ -56,7 +56,7 @@ class SplitTransaction extends Job implements ShouldUpdate
|
||||
$total_amount += $item['amount'];
|
||||
}
|
||||
|
||||
$precision = config('money.' . $this->model->currency_code . '.precision');
|
||||
$precision = config('money.currencies.' . $this->model->currency_code . '.precision');
|
||||
|
||||
$compare = bccomp($total_amount, $this->model->amount, $precision);
|
||||
|
||||
|
@ -68,7 +68,7 @@ class UpdateBankingDocumentTransaction extends Job implements ShouldUpdate
|
||||
$this->request['company_id'] = $this->model->company_id;
|
||||
$this->request['currency_code'] = $currency_code;
|
||||
$this->request['paid_at'] = isset($this->request['paid_at']) ? $this->request['paid_at'] : Date::now()->toDateTimeString();
|
||||
$this->request['currency_rate'] = config('money.' . $currency_code . '.rate');
|
||||
$this->request['currency_rate'] = config('money.currencies.' . $currency_code . '.rate');
|
||||
$this->request['account_id'] = isset($this->request['account_id']) ? $this->request['account_id'] : setting('default.account');
|
||||
$this->request['document_id'] = isset($this->request['document_id']) ? $this->request['document_id'] : $this->model->id;
|
||||
$this->request['contact_id'] = isset($this->request['contact_id']) ? $this->request['contact_id'] : $this->model->contact_id;
|
||||
@ -82,7 +82,7 @@ class UpdateBankingDocumentTransaction extends Job implements ShouldUpdate
|
||||
$code = $this->request['currency_code'];
|
||||
$rate = $this->request['currency_rate'];
|
||||
|
||||
$precision = config('money.' . $code . '.precision');
|
||||
$precision = config('money.currencies.' . $code . '.precision');
|
||||
|
||||
$amount = $this->request['amount'] = round($this->request['amount'], $precision);
|
||||
|
||||
@ -92,7 +92,7 @@ class UpdateBankingDocumentTransaction extends Job implements ShouldUpdate
|
||||
$amount = round($converted_amount, $precision);
|
||||
}
|
||||
|
||||
// if you edit transaction before remove transaction amount
|
||||
// if you edit transaction before remove transaction amount
|
||||
$this->model->paid_amount = ($this->model->paid - $this->transaction->amount);
|
||||
event(new PaidAmountCalculated($this->model));
|
||||
|
||||
|
@ -102,7 +102,7 @@ class UpdateTransfer extends Job implements ShouldUpdate
|
||||
$currency_rate = $this->request->get($type . '_account_rate');
|
||||
|
||||
if (empty($currency_rate)) {
|
||||
$currency_rate = config('money.' . $this->getCurrencyCode($type) . '.rate');
|
||||
$currency_rate = config('money.currencies.' . $this->getCurrencyCode($type) . '.rate');
|
||||
}
|
||||
|
||||
return $currency_rate;
|
||||
|
@ -29,7 +29,7 @@ class CreateDocumentItem extends Job implements HasOwner, HasSource, ShouldCreat
|
||||
public function handle(): DocumentItem
|
||||
{
|
||||
$item_id = ! empty($this->request['item_id']) ? $this->request['item_id'] : 0;
|
||||
$precision = config('money.' . $this->document->currency_code . '.precision');
|
||||
$precision = config('money.currencies.' . $this->document->currency_code . '.precision');
|
||||
|
||||
$item_amount = (double) $this->request['price'] * (double) $this->request['quantity'];
|
||||
|
||||
|
@ -28,7 +28,7 @@ class CreateDocumentItemsAndTotals extends Job implements HasOwner, HasSource, S
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$precision = config('money.' . $this->document->currency_code . '.precision');
|
||||
$precision = config('money.currencies.' . $this->document->currency_code . '.precision');
|
||||
|
||||
list($sub_total, $actual_total, $discount_amount_total, $taxes) = $this->createItems();
|
||||
|
||||
|
@ -319,7 +319,7 @@ class Transaction extends Model
|
||||
// Convert amount if not same currency
|
||||
if ($this->account->currency_code != $this->currency_code) {
|
||||
$to_code = $this->account->currency_code;
|
||||
$to_rate = config('money.' . $this->account->currency_code . '.rate');
|
||||
$to_rate = config('money.currencies.' . $this->account->currency_code . '.rate');
|
||||
|
||||
$amount = $this->convertBetween($amount, $this->currency_code, $this->currency_rate, $to_code, $to_rate);
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ class Document extends Model
|
||||
|
||||
$code = $this->currency_code;
|
||||
$rate = $this->currency_rate;
|
||||
$precision = config('money.' . $code . '.precision');
|
||||
$precision = config('money.currencies.' . $code . '.precision');
|
||||
|
||||
if ($this->transactions->count()) {
|
||||
foreach ($this->transactions as $transaction) {
|
||||
@ -361,7 +361,7 @@ class Document extends Model
|
||||
|
||||
$code = $this->currency_code;
|
||||
$rate = $this->currency_rate;
|
||||
$precision = config('money.' . $code . '.precision');
|
||||
$precision = config('money.currencies.' . $code . '.precision');
|
||||
|
||||
if ($this->transactions->count()) {
|
||||
foreach ($this->transactions as $transaction) {
|
||||
@ -391,7 +391,7 @@ class Document extends Model
|
||||
*/
|
||||
public function getAmountDueAttribute()
|
||||
{
|
||||
$precision = config('money.' . $this->currency_code . '.precision');
|
||||
$precision = config('money.currencies.' . $this->currency_code . '.precision');
|
||||
|
||||
return round($this->amount - $this->paid, $precision);
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ class Currency extends Model
|
||||
public function getPrecisionAttribute($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return config('money.' . $this->code . '.precision');
|
||||
return config('money.currencies.' . $this->code . '.precision');
|
||||
}
|
||||
|
||||
return (int) $value;
|
||||
@ -136,7 +136,7 @@ class Currency extends Model
|
||||
public function getSymbolAttribute($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return config('money.' . $this->code . '.symbol');
|
||||
return config('money.currencies.' . $this->code . '.symbol');
|
||||
}
|
||||
|
||||
return $value;
|
||||
@ -150,7 +150,7 @@ class Currency extends Model
|
||||
public function getSymbolFirstAttribute($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return config('money.' . $this->code . '.symbol_first');
|
||||
return config('money.currencies.' . $this->code . '.symbol_first');
|
||||
}
|
||||
|
||||
return $value;
|
||||
@ -164,7 +164,7 @@ class Currency extends Model
|
||||
public function getDecimalMarkAttribute($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return config('money.' . $this->code . '.decimal_mark');
|
||||
return config('money.currencies.' . $this->code . '.decimal_mark');
|
||||
}
|
||||
|
||||
return $value;
|
||||
@ -178,7 +178,7 @@ class Currency extends Model
|
||||
public function getThousandsSeparatorAttribute($value)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return config('money.' . $this->code . '.thousands_separator');
|
||||
return config('money.currencies.' . $this->code . '.thousands_separator');
|
||||
}
|
||||
|
||||
return $value;
|
||||
|
@ -98,11 +98,11 @@ trait Charts
|
||||
public function getChartLabelFormatter($type = 'money', $position = null)
|
||||
{
|
||||
$label = '';
|
||||
$decimal_mark = str_replace("'", "\\'", config('money.' . default_currency() . '.decimal_mark'));
|
||||
$thousands_separator = str_replace("'", "\\'", config('money.' . default_currency() . '.thousands_separator'));
|
||||
$symbol = str_replace("'", "\\'", config('money.' . default_currency() . '.symbol'));
|
||||
$symbol_first = str_replace("'", "\\'", config('money.' . default_currency() . '.symbol_first'));
|
||||
$precision = str_replace("'", "\\'", config('money.' . default_currency() . '.precision'));
|
||||
$decimal_mark = str_replace("'", "\\'", config('money.currencies.' . default_currency() . '.decimal_mark'));
|
||||
$thousands_separator = str_replace("'", "\\'", config('money.currencies.' . default_currency() . '.thousands_separator'));
|
||||
$symbol = str_replace("'", "\\'", config('money.currencies.' . default_currency() . '.symbol'));
|
||||
$symbol_first = str_replace("'", "\\'", config('money.currencies.' . default_currency() . '.symbol_first'));
|
||||
$precision = str_replace("'", "\\'", config('money.currencies.' . default_currency() . '.precision'));
|
||||
$percent_position = $position ?: setting('localisation.percent_position');
|
||||
|
||||
switch ($type) {
|
||||
|
@ -95,11 +95,11 @@ trait Import
|
||||
$data = [
|
||||
'company_id' => company_id(),
|
||||
'code' => $row['currency_code'],
|
||||
'name' => isset($row['currency_name']) ? $row['currency_name'] : config('money.' . $row['currency_code'] . '.name'),
|
||||
'name' => isset($row['currency_name']) ? $row['currency_name'] : config('money.currencies.' . $row['currency_code'] . '.name'),
|
||||
'rate' => isset($row['currency_rate']) ? $row['currency_rate'] : 1,
|
||||
'symbol' => isset($row['currency_symbol']) ? $row['currency_symbol'] : config('money.' . $row['currency_code'] . '.symbol'),
|
||||
'precision' => isset($row['currency_precision']) ? $row['currency_precision'] : config('money.' . $row['currency_code'] . '.precision'),
|
||||
'decimal_mark' => isset($row['currency_decimal_mark']) ? $row['currency_decimal_mark'] : config('money.' . $row['currency_code'] . '.decimal_mark'),
|
||||
'symbol' => isset($row['currency_symbol']) ? $row['currency_symbol'] : config('money.currencies.' . $row['currency_code'] . '.symbol'),
|
||||
'precision' => isset($row['currency_precision']) ? $row['currency_precision'] : config('money.currencies.' . $row['currency_code'] . '.precision'),
|
||||
'decimal_mark' => isset($row['currency_decimal_mark']) ? $row['currency_decimal_mark'] : config('money.currencies.' . $row['currency_code'] . '.decimal_mark'),
|
||||
'created_from' => !empty($row['created_from']) ? $row['created_from'] : $this->getSourcePrefix() . 'import',
|
||||
'created_by' => !empty($row['created_by']) ? $row['created_by'] : user()->id,
|
||||
];
|
||||
|
@ -73,16 +73,16 @@ class Overrider
|
||||
$currencies = Currency::all();
|
||||
|
||||
foreach ($currencies as $currency) {
|
||||
config(['money.' . $currency->code . '.name' => $currency->name]);
|
||||
config(['money.' . $currency->code . '.rate' => $currency->rate]);
|
||||
config(['money.' . $currency->code . '.precision' => $currency->precision]);
|
||||
config(['money.' . $currency->code . '.symbol' => $currency->symbol]);
|
||||
config(['money.' . $currency->code . '.symbol_first' => $currency->symbol_first]);
|
||||
config(['money.' . $currency->code . '.decimal_mark' => $currency->decimal_mark]);
|
||||
config(['money.' . $currency->code . '.thousands_separator' => $currency->thousands_separator]);
|
||||
config(['money.currencies.' . $currency->code . '.name' => $currency->name]);
|
||||
config(['money.currencies.' . $currency->code . '.rate' => $currency->rate]);
|
||||
config(['money.currencies.' . $currency->code . '.precision' => $currency->precision]);
|
||||
config(['money.currencies.' . $currency->code . '.symbol' => $currency->symbol]);
|
||||
config(['money.currencies.' . $currency->code . '.symbol_first' => $currency->symbol_first]);
|
||||
config(['money.currencies.' . $currency->code . '.decimal_mark' => $currency->decimal_mark]);
|
||||
config(['money.currencies.' . $currency->code . '.thousands_separator' => $currency->thousands_separator]);
|
||||
}
|
||||
|
||||
// Set currencies with new settings
|
||||
\Akaunting\Money\Currency::setCurrencies(config('money'));
|
||||
\Akaunting\Money\Currency::setCurrencies(config('money.currencies'));
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class Currency extends Component
|
||||
{
|
||||
$code = ($this->code) ? $this->code : default_currency();
|
||||
|
||||
$this->currency = config('money.' . $code . '.name');
|
||||
$this->currency = config('money.currencies.' . $code . '.name');
|
||||
|
||||
return view('components.index.currency');
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ class CashFlow extends Widget
|
||||
$totals[$i] += $item->getAmountConvertedToDefault();
|
||||
}
|
||||
|
||||
$precision = config('money.' . default_currency() . '.precision');
|
||||
$precision = config('money.currencies.' . default_currency() . '.precision');
|
||||
|
||||
foreach ($totals as $key => $value) {
|
||||
if ($type == 'expense') {
|
||||
@ -206,7 +206,7 @@ class CashFlow extends Widget
|
||||
{
|
||||
$profit = [];
|
||||
|
||||
$precision = config('money.' . default_currency() . '.precision');
|
||||
$precision = config('money.currencies.' . default_currency() . '.precision');
|
||||
|
||||
foreach ($incomes as $key => $income) {
|
||||
$value = $income - abs($expenses[$key]);
|
||||
|
@ -195,7 +195,7 @@ class ProfitLoss extends Widget
|
||||
$totals[$i] += $item->getAmountConvertedToDefault();
|
||||
}
|
||||
|
||||
$precision = config('money.' . default_currency() . '.precision');
|
||||
$precision = config('money.currencies.' . default_currency() . '.precision');
|
||||
|
||||
foreach ($totals as $key => $value) {
|
||||
$totals[$key] = round($value, $precision);
|
||||
|
Reference in New Issue
Block a user