Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

fix: fix convertamount format #1191

Merged
merged 4 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
.env
.env.cypress.local
.phpunit.result.cache
.php_cs.cache
.php-cs-fixer.cache
Homestead.json
Homestead.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Carbon\Carbon;
use ErrorException;
use Illuminate\Support\Str;
use App\Helpers\MoneyHelper;
use App\Services\BaseService;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Http;
Expand Down Expand Up @@ -118,7 +119,7 @@ private function getConversionRate(): void

private function convert(): void
{
$this->convertedAmount = $this->amount / $this->rate;
$this->convertedAmount = MoneyHelper::parseInput((string) ($this->amount / $this->rate), $this->companyCurrency);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public function up(): void
$table->unsignedBigInteger('expense_category_id')->nullable();
$table->string('status')->default('created');
$table->string('title');
$table->integer('amount');
$table->unsignedBigInteger('amount');
$table->string('currency');
$table->double('converted_amount')->nullable();
$table->unsignedBigInteger('converted_amount')->nullable();
$table->string('converted_to_currency')->nullable();
$table->datetime('converted_at')->nullable();
$table->double('exchange_rate')->nullable();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use App\Helpers\MoneyHelper;
use App\Models\Company\Expense;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class FixExpenseConvertedAmount extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Expense::whereNotNull('converted_amount')
->chunk(100, function ($expenses) {
foreach ($expenses as $expense) {
$expense->converted_amount = MoneyHelper::parseInput((string) $expense->converted_amount, $expense->converted_to_currency);
$expense->save();
}
});

/** @var \Illuminate\Database\Connection $connection */
$connection = DB::connection();
if ($connection->getDriverName() !== 'sqlite') {
Schema::table('expenses', function (Blueprint $table) {
$table->unsignedBigInteger('amount')->change();
$table->unsignedBigInteger('converted_amount')->change();
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function it_converts_an_amount_from_eur_to_cad_and_store_rate_in_cache():
$this->assertEquals(
[
'exchange_rate' => 0.847968,
'converted_amount' => 11792.897845201705,
'converted_amount' => 1179290,
'converted_to_currency' => 'USD',
'converted_at' => '2018-01-01 00:00:00',
],
Expand Down