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

fix: bug fix on loan #85

Merged
merged 2 commits into from
May 17, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Contact\ManageLoans\Web\ViewHelpers;

use App\Helpers\DateHelper;
use App\Helpers\MonetaryNumberHelper;
use App\Models\Contact;
use App\Models\Loan;
use App\Models\User;
Expand Down Expand Up @@ -56,7 +57,8 @@ public static function dtoLoan(Loan $loan, Contact $contact, User $user): array
'type' => $loan->type,
'name' => $loan->name,
'description' => $loan->description,
'amount_lent' => $loan->amount_lent / 100,
'amount_lent' => MonetaryNumberHelper::format($user, $loan->amount_lent),
'amount_lent_int' => $loan->amount_lent / 100,
'currency_id' => $loan->currency_id,
'currency_name' => $loan->currency ? $loan->currency->code : null,
'loaned_at' => $loan->loaned_at->format('Y-m-d'),
Expand Down
5 changes: 3 additions & 2 deletions resources/js/Shared/Modules/Loans.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
:input-class="'w-full'"
:required="false"
:min="0"
:max="10000000"
:autocomplete="false"
@esc-key-pressed="createLoanModalShown = false" />

Expand Down Expand Up @@ -329,7 +330,7 @@
:input-class="'w-full'"
:required="false"
:min="0"
:max="1000000"
:max="10000000"
:autocomplete="false"
@esc-key-pressed="createLoanModalShown = false" />

Expand Down Expand Up @@ -502,7 +503,7 @@ export default {
this.form.name = loan.name;
this.form.description = loan.description;
this.form.loaned_at = loan.loaned_at;
this.form.amount_lent = loan.amount_lent;
this.form.amount_lent = loan.amount_lent_int;
this.form.currency_id = loan.currency_id;
this.form.loaners = loan.loaners;
this.form.loanees = loan.loanees;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@ public function it_gets_the_data_transfer_object(): void
Carbon::setTestNow(Carbon::create(2018, 1, 1));
$contact = Contact::factory()->create();
$otherContact = Contact::factory()->create();
$user = User::factory()->create();
$user = User::factory()->create([
'number_format' => User::NUMBER_FORMAT_TYPE_NO_SPACE_DOT_DECIMAL,
]);
$loan = Loan::factory()->create([
'currency_id' => Currency::factory()->create(),
'loaned_at' => '2019-02-02',
'amount_lent' => 100032,
]);
$contact->loansAsLoaner()->syncWithoutDetaching([$loan->id => ['loanee_id' => $otherContact->id]]);

$array = ModuleLoanViewHelper::dtoLoan($loan, $contact, $user);

$this->assertEquals(
14,
15,
count($array)
);

Expand All @@ -88,9 +91,13 @@ public function it_gets_the_data_transfer_object(): void
$array['description']
);
$this->assertEquals(
$loan->amount_lent / 100,
'1000.32',
$array['amount_lent']
);
$this->assertEquals(
'1000.32',
$array['amount_lent_int']
);
$this->assertEquals(
$loan->currency_id,
$array['currency_id']
Expand Down