updated money package to 5.0 version

This commit is contained in:
Denis Duliçi 2023-07-10 12:53:43 +03:00
parent 7a589e5bbd
commit 20e5b57562
26 changed files with 1887 additions and 1877 deletions

View File

@ -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'];

View File

@ -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;

View File

@ -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();

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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'];

View File

@ -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();

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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) {

View File

@ -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,
];

View File

@ -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'));
}
}

View File

@ -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');
}

View File

@ -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]);

View File

@ -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);

View File

@ -33,7 +33,7 @@
"akaunting/laravel-language": "^1.0",
"akaunting/laravel-menu": "^3.0",
"akaunting/laravel-module": "^3.0",
"akaunting/laravel-money": "^4.0",
"akaunting/laravel-money": "^5.0",
"akaunting/laravel-mutable-observer": "^2.0",
"akaunting/laravel-setting": "^1.2",
"akaunting/laravel-sortable": "^2.0",

38
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "e5aa0bb32c6ddfd816280b738eb71113",
"content-hash": "c3f66e10a7d0f5845e1d1a4f99dfced6",
"packages": [
{
"name": "akaunting/laravel-apexcharts",
@ -409,16 +409,16 @@
},
{
"name": "akaunting/laravel-money",
"version": "4.0.1",
"version": "5.0.0",
"source": {
"type": "git",
"url": "https://github.com/akaunting/laravel-money.git",
"reference": "df99d0f5d415490ef7e79362c3b694e8cc8af903"
"reference": "104d41aabc144150054d225fec6b2a0ae8b76d1d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/akaunting/laravel-money/zipball/df99d0f5d415490ef7e79362c3b694e8cc8af903",
"reference": "df99d0f5d415490ef7e79362c3b694e8cc8af903",
"url": "https://api.github.com/repos/akaunting/laravel-money/zipball/104d41aabc144150054d225fec6b2a0ae8b76d1d",
"reference": "104d41aabc144150054d225fec6b2a0ae8b76d1d",
"shasum": ""
},
"require": {
@ -472,9 +472,9 @@
],
"support": {
"issues": "https://github.com/akaunting/laravel-money/issues",
"source": "https://github.com/akaunting/laravel-money/tree/4.0.1"
"source": "https://github.com/akaunting/laravel-money/tree/5.0.0"
},
"time": "2023-03-16T14:39:27+00:00"
"time": "2023-07-10T09:34:33+00:00"
},
{
"name": "akaunting/laravel-mutable-observer",
@ -1245,16 +1245,16 @@
},
{
"name": "barryvdh/reflection-docblock",
"version": "v2.1.0",
"version": "v2.1.1",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/ReflectionDocBlock.git",
"reference": "bf44b757feb8ba1734659029357646466ded673e"
"reference": "e6811e927f0ecc37cc4deaa6627033150343e597"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/ReflectionDocBlock/zipball/bf44b757feb8ba1734659029357646466ded673e",
"reference": "bf44b757feb8ba1734659029357646466ded673e",
"url": "https://api.github.com/repos/barryvdh/ReflectionDocBlock/zipball/e6811e927f0ecc37cc4deaa6627033150343e597",
"reference": "e6811e927f0ecc37cc4deaa6627033150343e597",
"shasum": ""
},
"require": {
@ -1291,9 +1291,9 @@
}
],
"support": {
"source": "https://github.com/barryvdh/ReflectionDocBlock/tree/v2.1.0"
"source": "https://github.com/barryvdh/ReflectionDocBlock/tree/v2.1.1"
},
"time": "2022-10-31T15:35:43+00:00"
"time": "2023-06-14T05:06:27+00:00"
},
{
"name": "bkwld/cloner",
@ -14256,16 +14256,16 @@
},
{
"name": "phpunit/phpunit",
"version": "10.2.3",
"version": "10.2.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "35c8cac1734ede2ae354a6644f7088356ff5b08e"
"reference": "68484779b5a2ed711fbdeba6ca01910d87acdff2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35c8cac1734ede2ae354a6644f7088356ff5b08e",
"reference": "35c8cac1734ede2ae354a6644f7088356ff5b08e",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/68484779b5a2ed711fbdeba6ca01910d87acdff2",
"reference": "68484779b5a2ed711fbdeba6ca01910d87acdff2",
"shasum": ""
},
"require": {
@ -14337,7 +14337,7 @@
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.3"
"source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.4"
},
"funding": [
{
@ -14353,7 +14353,7 @@
"type": "tidelift"
}
],
"time": "2023-06-30T06:17:38+00:00"
"time": "2023-07-10T04:06:08+00:00"
},
{
"name": "sebastian/cli-parser",

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,7 @@ class Currency extends Factory
*/
public function definition()
{
$currencies = config('money');
$currencies = config('money.currencies');
Model::pluck('code')->each(function ($db_code) use (&$currencies) {
unset($currencies[$db_code]);

View File

@ -36,11 +36,11 @@ class Currencies extends Seeder
'code' => 'USD',
'rate' => '1.00',
'enabled' => '1',
'precision' => config('money.USD.precision'),
'symbol' => config('money.USD.symbol'),
'symbol_first' => config('money.USD.symbol_first'),
'decimal_mark' => config('money.USD.decimal_mark'),
'thousands_separator' => config('money.USD.thousands_separator'),
'precision' => config('money.currencies.USD.precision'),
'symbol' => config('money.currencies.USD.symbol'),
'symbol_first' => config('money.currencies.USD.symbol_first'),
'decimal_mark' => config('money.currencies.USD.decimal_mark'),
'thousands_separator' => config('money.currencies.USD.thousands_separator'),
],
];

View File

@ -75,13 +75,13 @@ class PaymentTestCase extends FeatureTestCase
} elseif ($this->invoice_currency != null) {
$this->dispatch(new CreateCurrency([
'company_id' => company_id(),
'name' => config('money.' . $this->invoice_currency . '.name'),
'name' => config('money.currencies.' . $this->invoice_currency . '.name'),
'code' => $this->invoice_currency,
'rate' => config(['money.' . $this->invoice_currency . '.rate' => 1]),
'enabled' => 1,
'symbol_first' => config('money.' . $this->invoice_currency . '.symbol_first'),
'decimal_mark' => config('money.' . $this->invoice_currency . '.decimal_mark'),
'thousands_separator' => config('money.' . $this->invoice_currency . '.thousands_separator'),
'symbol_first' => config('money.currencies.' . $this->invoice_currency . '.symbol_first'),
'decimal_mark' => config('money.currencies.' . $this->invoice_currency . '.decimal_mark'),
'thousands_separator' => config('money.currencies.' . $this->invoice_currency . '.thousands_separator'),
'default_currency' => true,
]));
}