applied new features of money package

This commit is contained in:
Denis Duliçi
2023-07-11 12:03:14 +03:00
parent 20e5b57562
commit bfb37c62c6
51 changed files with 110 additions and 105 deletions

View File

@@ -283,8 +283,8 @@ abstract class Index extends Component
$items[] = [
'title' => ($key == 'overdue') ? trans('general.overdue') : trans('documents.statuses.' . $key),
//'href' => route($route, ['search' => 'status:' . $key]),
'amount' => money($total, default_currency(), true)->formatForHumans(),
'tooltip' => money($total, default_currency(), true)->format(),
'amount' => money($total)->formatForHumans(),
'tooltip' => money($total)->format(),
];
}

View File

@@ -392,8 +392,8 @@ abstract class Index extends Component
foreach ($totals as $key => $total) {
$title = ($key == 'overdue') ? trans('general.overdue') : trans('documents.statuses.' . $key);
$href = route($route, ['search' => 'status:' . $key]);
$amount = money($total, default_currency(), true)->formatForHumans();
$tooltip = money($total, default_currency(), true)->format();
$amount = money($total)->formatForHumans();
$tooltip = money($total)->format();
$items[] = [
'title' => $title,

View File

@@ -42,9 +42,9 @@ class Accounts extends Controller
->orWhereHas('income_transaction', fn ($query) => $query->where('account_id', $account->id))
->collect(['expense_transaction.paid_at' => 'desc']);
$incoming_amount = money($account->income_balance, $account->currency_code, true);
$outgoing_amount = money($account->expense_balance, $account->currency_code, true);
$current_amount = money($account->balance, $account->currency_code, true);
$incoming_amount = money($account->income_balance, $account->currency_code);
$outgoing_amount = money($account->expense_balance, $account->currency_code);
$current_amount = money($account->balance, $account->currency_code);
$summary_amounts = [
'incoming_exact' => $incoming_amount->format(),

View File

@@ -24,8 +24,8 @@ class Reconciliations extends Controller
{
$reconciliations = Reconciliation::with('account')->collect();
$reconciled_amount = money($reconciliations->where('reconciled', 1)->sum('closing_balance'), default_currency(), true);
$in_progress_amount = money($reconciliations->where('reconciled', 0)->sum('closing_balance'), default_currency(), true);
$reconciled_amount = money($reconciliations->where('reconciled', 1)->sum('closing_balance'));
$in_progress_amount = money($reconciliations->where('reconciled', 0)->sum('closing_balance'));
$summary_amounts = [
'amount_exact' => $reconciled_amount->format(),
@@ -246,9 +246,9 @@ class Reconciliations extends Controller
$difference = $closing_balance - $cleared_amount;
$json->closing_balance = money($closing_balance, $currency_code, true)->format();
$json->cleared_amount = money($cleared_amount, $currency_code, true)->format();
$json->difference = money($difference, $currency_code, true)->format();
$json->closing_balance = money($closing_balance, $currency_code)->format();
$json->cleared_amount = money($cleared_amount, $currency_code)->format();
$json->difference = money($difference, $currency_code)->format();
$json->difference_raw = (int) $difference;
return response()->json($json);

View File

@@ -56,9 +56,9 @@ class Transactions extends Controller
$totals['profit'] = $totals['income'] - $totals['expense'];
$incoming_amount = money($totals['income'], default_currency(), true);
$expense_amount = money($totals['expense'], default_currency(), true);
$profit_amount = money($totals['profit'], default_currency(), true);
$incoming_amount = money($totals['income']);
$expense_amount = money($totals['expense']);
$profit_amount = money($totals['profit']);
$summary_amounts = [
'incoming_exact' => $incoming_amount->format(),

View File

@@ -51,9 +51,9 @@ class DocumentTransactions extends Controller
$document->{$document_total->code} = $document_total->amount;
}
$total = money($document->total, $currency->code, true)->format();
$total = money($document->total, $currency->code)->format();
$document->grand_total = money($total, $currency->code)->getAmount();
$document->grand_total = money($total, $currency->code, false)->getAmount();
if (! empty($paid)) {
$document->grand_total = round($document->total - $paid, $currency->precision);
@@ -140,7 +140,7 @@ class DocumentTransactions extends Controller
$number = $transaction->number;
$document->grand_total = money($transaction->amount, $currency->code)->getAmount();
$document->grand_total = money($transaction->amount, $currency->code, false)->getAmount();
$document->paid_at = $transaction->paid_at;

View File

@@ -105,7 +105,7 @@ class Money
$money_format = Str::replaceFirst('.', config('money.currencies.' . $currency_code . '.decimal_mark'), $money_format);
}
$amount = money($money_format, $currency_code)->getAmount();
$amount = money($money_format, $currency_code, false)->getAmount();
} catch (InvalidArgumentException | OutOfBoundsException | UnexpectedValueException $e) {
report($e);

View File

@@ -22,9 +22,9 @@ class Account extends JsonResource
'number' => $this->number,
'currency_code' => $this->currency_code,
'opening_balance' => $this->opening_balance,
'opening_balance_formatted' => money($this->opening_balance, $this->currency_code, true)->format(),
'opening_balance_formatted' => money($this->opening_balance, $this->currency_code)->format(),
'current_balance' => $this->balance,
'current_balance_formatted' => money($this->balance, $this->currency_code, true)->format(),
'current_balance_formatted' => money($this->balance, $this->currency_code)->format(),
'bank_name' => $this->bank_name,
'bank_phone' => $this->bank_phone,
'bank_address' => $this->bank_address,

View File

@@ -22,7 +22,7 @@ class Reconciliation extends JsonResource
'started_at' => $this->started_at->toIso8601String(),
'ended_at' => $this->ended_at->toIso8601String(),
'closing_balance' => $this->closing_balance,
'closing_balance_formatted' => money($this->closing_balance, default_currency(), true)->format(),
'closing_balance_formatted' => money($this->closing_balance)->format(),
'reconciled' => $this->reconciled,
'created_from' => $this->created_from,
'created_by' => $this->created_by,

View File

@@ -25,7 +25,7 @@ class Transaction extends JsonResource
'account_id' => $this->account_id,
'paid_at' => $this->paid_at->toIso8601String(),
'amount' => $this->amount,
'amount_formatted' => money($this->amount, $this->currency_code, true)->format(),
'amount_formatted' => money($this->amount, $this->currency_code)->format(),
'currency_code' => $this->currency_code,
'currency_rate' => $this->currency_rate,
'document_id' => $this->document_id,

View File

@@ -25,7 +25,7 @@ class Transfer extends JsonResource
'to_account' => $income_transaction->account->name,
'to_account_id' => $income_transaction->account->id,
'amount' => $expense_transaction->amount,
'amount_formatted' => money($expense_transaction->amount, $expense_transaction->currency_code, true)->format(),
'amount_formatted' => money($expense_transaction->amount, $expense_transaction->currency_code)->format(),
'currency_code' => $expense_transaction->currency_code,
'paid_at' => $expense_transaction->paid_at ? $expense_transaction->paid_at->toIso8601String() : '',
'created_from' => $this->created_from,

View File

@@ -23,9 +23,9 @@ class Item extends JsonResource
'name' => $this->name,
'description' => $this->description,
'sale_price' => $this->sale_price,
'sale_price_formatted' => money((double) $this->sale_price, default_currency(), true)->format(),
'sale_price_formatted' => money((double) $this->sale_price)->format(),
'purchase_price' => $this->purchase_price,
'purchase_price_formatted' => money((double) $this->purchase_price, default_currency(), true)->format(),
'purchase_price_formatted' => money((double) $this->purchase_price)->format(),
'category_id' => $this->category_id,
'picture' => $this->picture,
'enabled' => $this->enabled,

View File

@@ -32,7 +32,7 @@ class Document extends JsonResource
'issued_at' => $this->issued_at ? $this->issued_at->toIso8601String() : '',
'due_at' => $this->due_at ? $this->due_at->toIso8601String() : '',
'amount' => $this->amount,
'amount_formatted' => money($this->amount, $this->currency_code, true)->format(),
'amount_formatted' => money($this->amount, $this->currency_code)->format(),
'category_id' => $this->category_id,
'currency_code' => $this->currency_code,
'currency_rate' => $this->currency_rate,

View File

@@ -24,9 +24,9 @@ class DocumentItem extends JsonResource
'name' => $this->name,
'description' => $this->description,
'price' => $this->price,
'price_formatted' => money($this->price, $this->document->currency_code, true)->format(),
'price_formatted' => money($this->price, $this->document->currency_code)->format(),
'total' => $this->total,
'total_formatted' => money($this->total, $this->document->currency_code, true)->format(),
'total_formatted' => money($this->total, $this->document->currency_code)->format(),
'created_from' => $this->created_from,
'created_by' => $this->created_by,
'created_at' => $this->created_at ? $this->created_at->toIso8601String() : '',

View File

@@ -24,7 +24,7 @@ class DocumentItemTax extends JsonResource
'tax_id' => $this->tax_id,
'name' => $this->name,
'amount' => $this->amount,
'amount_formatted' => money($this->amount, $this->document->currency_code, true)->format(),
'amount_formatted' => money($this->amount, $this->document->currency_code)->format(),
'created_from' => $this->created_from,
'created_by' => $this->created_by,
'created_at' => $this->created_at ? $this->created_at->toIso8601String() : '',

View File

@@ -22,7 +22,7 @@ class DocumentTotal extends JsonResource
'code' => $this->code,
'name' => $this->name,
'amount' => $this->amount,
'amount_formatted' => money($this->amount, $this->document->currency_code, true)->format(),
'amount_formatted' => money($this->amount, $this->document->currency_code)->format(),
'sort_order' => $this->sort_order,
'created_from' => $this->created_from,
'created_by' => $this->created_by,

View File

@@ -112,7 +112,7 @@ class CreateBankingDocumentTransaction extends Job implements ShouldCreate
$error_amount = round($converted_amount, $precision);
}
$message = trans('messages.error.over_payment', ['amount' => money($error_amount, $code, true)]);
$message = trans('messages.error.over_payment', ['amount' => money($error_amount, $code)]);
throw new \Exception($message);
} else {
@@ -124,7 +124,7 @@ class CreateBankingDocumentTransaction extends Job implements ShouldCreate
protected function createHistory(): void
{
$history_desc = money((double) $this->transaction->amount, (string) $this->transaction->currency_code, true)->format() . ' ' . trans_choice('general.payments', 1);
$history_desc = money((double) $this->transaction->amount, (string) $this->transaction->currency_code)->format() . ' ' . trans_choice('general.payments', 1);
$this->dispatch(new CreateDocumentHistory($this->model, 0, $history_desc));
}

View File

@@ -71,7 +71,7 @@ class MatchBankingDocumentTransaction extends Job
$error_amount = round($converted_amount, $precision);
}
$message = trans('messages.error.over_match', ['type' => ucfirst($this->model->type), 'amount' => money($error_amount, $code, true)]);
$message = trans('messages.error.over_match', ['type' => ucfirst($this->model->type), 'amount' => money($error_amount, $code)]);
throw new \Exception($message);
} else {
@@ -83,7 +83,7 @@ class MatchBankingDocumentTransaction extends Job
protected function createHistory(): void
{
$history_desc = money((double) $this->transaction->amount, (string) $this->transaction->currency_code, true)->format() . ' ' . trans_choice('general.payments', 1);
$history_desc = money((double) $this->transaction->amount, (string) $this->transaction->currency_code)->format() . ' ' . trans_choice('general.payments', 1);
$this->dispatch(new CreateDocumentHistory($this->model, 0, $history_desc));
}

View File

@@ -65,7 +65,7 @@ class SplitTransaction extends Job implements ShouldUpdate
$message = trans('messages.error.same_amount', [
'transaction' => ucfirst(trans_choice('general.' . Str::plural($this->model->type), 1)),
'amount' => money($error_amount, $this->model->currency_code, true)
'amount' => money($error_amount, $this->model->currency_code)
]);
throw new \Exception($message);

View File

@@ -112,7 +112,7 @@ class UpdateBankingDocumentTransaction extends Job implements ShouldUpdate
$error_amount = round($converted_amount, $precision);
}
$message = trans('messages.error.over_payment', ['amount' => money($error_amount, $code, true)]);
$message = trans('messages.error.over_payment', ['amount' => money($error_amount, $code)]);
throw new \Exception($message);
} else {
@@ -124,7 +124,7 @@ class UpdateBankingDocumentTransaction extends Job implements ShouldUpdate
protected function createHistory(): void
{
$history_desc = money((double) $this->transaction->amount, (string) $this->transaction->currency_code, true)->format() . ' ' . trans_choice('general.payments', 1);
$history_desc = money((double) $this->transaction->amount, (string) $this->transaction->currency_code)->format() . ' ' . trans_choice('general.payments', 1);
$this->dispatch(new CreateDocumentHistory($this->model, 0, $history_desc));
}

View File

@@ -118,7 +118,7 @@ class Transaction extends Notification
];
return [
money($this->transaction->amount, $this->transaction->currency_code, true),
money($this->transaction->amount, $this->transaction->currency_code),
company_date($this->transaction->paid_at),
URL::signedRoute('signed.payments.show', $route_params),
route('transactions.show', $route_params),

View File

@@ -129,13 +129,13 @@ class PaymentReceived extends Notification
return [
$this->invoice->document_number,
money($this->invoice->amount, $this->invoice->currency_code, true),
money($this->invoice->amount, $this->invoice->currency_code),
company_date($this->invoice->due_at),
trans('documents.statuses.' . $this->invoice->status),
URL::signedRoute('signed.invoices.show', $route_params),
route('invoices.show', $route_params),
route('portal.invoices.show', $route_params),
money($this->transaction->amount, $this->transaction->currency_code, true),
money($this->transaction->amount, $this->transaction->currency_code),
company_date($this->transaction->paid_at),
$this->transaction->payment_method,
$this->invoice->contact_name,

View File

@@ -97,8 +97,8 @@ class Bill extends Notification
return [
$this->bill->document_number,
money($this->bill->amount, $this->bill->currency_code, true),
money($this->bill->amount_due, $this->bill->currency_code, true),
money($this->bill->amount, $this->bill->currency_code),
money($this->bill->amount_due, $this->bill->currency_code),
company_date($this->bill->issued_at),
company_date($this->bill->due_at),
route('bills.show', $route_params),

View File

@@ -142,8 +142,8 @@ class Invoice extends Notification
return [
$this->invoice->document_number,
money($this->invoice->amount, $this->invoice->currency_code, true),
money($this->invoice->amount_due, $this->invoice->currency_code, true),
money($this->invoice->amount, $this->invoice->currency_code),
money($this->invoice->amount_due, $this->invoice->currency_code),
company_date($this->invoice->issued_at),
company_date($this->invoice->due_at),
URL::signedRoute('signed.invoices.show', $route_params),

View File

@@ -60,7 +60,7 @@ class Transaction extends Observer
protected function getDescription($transaction)
{
$amount = money((double) $transaction->amount, (string) $transaction->currency_code, true)->format();
$amount = money((double) $transaction->amount, (string) $transaction->currency_code)->format();
return trans('messages.success.deleted', ['type' => $amount . ' ' . trans_choice('general.payments', 1)]);
}

View File

@@ -28,7 +28,7 @@ trait Charts
public function addMoneyToDonutChart($color, $amount, $description = '')
{
$label = money($amount, default_currency(), true)->formatForHumans();
$label = money($amount)->formatForHumans();
if (!empty($description)) {
$label .= ' - ' . $description;

View File

@@ -62,6 +62,9 @@ class Overrider
// Set locale for Money package
Money::setLocale(app()->getLocale());
// Money
config(['money.defaults.currency' => setting('default.currency')]);
// Set app url dynamically if empty
if (! config('app.url')) {
config(['app.url' => url('/')]);

View File

@@ -72,9 +72,9 @@ class Content extends Component
$totals['paid'] += $item->getAmountConvertedToDefault();
});
$open_amount = money($totals['open'], default_currency(), true);
$overdue_amount = money($totals['overdue'], default_currency(), true);
$paid_amount = money($totals['paid'], default_currency(), true);
$open_amount = money($totals['open']);
$overdue_amount = money($totals['overdue']);
$paid_amount = money($totals['paid']);
$summary_amounts = [
'open_exact' => $open_amount->format(),

View File

@@ -15,7 +15,7 @@ class GetPaid extends Component
*/
public function render()
{
$this->description = trans('general.amount_due') . ': ' . '<span class="font-medium">' . money($this->document->amount_due, $this->document->currency_code, true) . '</span>';
$this->description = trans('general.amount_due') . ': ' . '<span class="font-medium">' . money($this->document->amount_due, $this->document->currency_code) . '</span>';
return view('components.documents.show.get-paid');
}

View File

@@ -15,7 +15,7 @@ class MakePayment extends Component
*/
public function render()
{
$this->description = trans('general.amount_due') . ': ' . '<span class="font-medium">' . money($this->document->amount_due, $this->document->currency_code, true) . '</span>';
$this->description = trans('general.amount_due') . ': ' . '<span class="font-medium">' . money($this->document->amount_due, $this->document->currency_code) . '</span>';
return view('components.documents.show.make-payment');
}

View File

@@ -16,7 +16,7 @@ class AccountBalance extends Widget
public function show()
{
$accounts = Account::with('income_transactions', 'expense_transactions')->enabled()->take(5)->get()->map(function($account) {
$account->balance_formatted = money($account->balance, $account->currency_code, true);
$account->balance_formatted = money($account->balance, $account->currency_code);
return $account;
})->all();

View File

@@ -53,9 +53,9 @@ class CashFlow extends Widget
->setDataset(trans('general.outgoing'), 'column', $expense)
->setDataset(trans_choice('general.profits', 1), 'line', $profit);
$incoming_amount = money(array_sum($income), default_currency(), true);
$outgoing_amount = money(abs(array_sum($expense)), default_currency(), true);
$profit_amount = money(array_sum($profit), default_currency(), true);
$incoming_amount = money(array_sum($income));
$outgoing_amount = money(abs(array_sum($expense)));
$profit_amount = money(array_sum($profit));
$totals = [
'incoming_exact' => $incoming_amount->format(),

View File

@@ -52,7 +52,7 @@ class Payables extends Widget
});
foreach ($periods as $period_name => $period_amount) {
$periods[$period_name] = money($period_amount, default_currency(), true);
$periods[$period_name] = money($period_amount);
}
$has_progress = !empty($open) || !empty($overdue);
@@ -61,9 +61,9 @@ class Payables extends Widget
$grand = $open + $overdue;
$totals = [
'grand' => money($grand, default_currency(), true),
'open' => money($open, default_currency(), true),
'overdue' => money($overdue, default_currency(), true),
'grand' => money($grand),
'open' => money($open),
'overdue' => money($overdue),
];
$grand_total_text = trans('widgets.total_unpaid_bills');

View File

@@ -52,7 +52,7 @@ class Receivables extends Widget
});
foreach ($periods as $period_name => $period_amount) {
$periods[$period_name] = money($period_amount, default_currency(), true);
$periods[$period_name] = money($period_amount);
}
$has_progress = !empty($open) || !empty($overdue);
@@ -61,9 +61,9 @@ class Receivables extends Widget
$grand = $open + $overdue;
$totals = [
'grand' => money($grand, default_currency(), true),
'open' => money($open, default_currency(), true),
'overdue' => money($overdue, default_currency(), true),
'grand' => money($grand),
'open' => money($open),
'overdue' => money($overdue),
];
$grand_total_text = trans('widgets.total_unpaid_invoices');