From bfe5ebeb6156be128b17e3620f4d2e7dcd0ea303 Mon Sep 17 00:00:00 2001 From: Mazarin Date: Tue, 17 May 2022 11:10:46 -0400 Subject: [PATCH] fix: bug fix on loan (monicahq/chandler#85) --- .../Web/ViewHelpers/ModuleLoanViewHelper.php | 4 +++- resources/js/Shared/Modules/Loans.vue | 5 +++-- .../Web/ViewHelpers/ModuleLoanViewHelperTest.php | 13 ++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/domains/Contact/ManageLoans/Web/ViewHelpers/ModuleLoanViewHelper.php b/domains/Contact/ManageLoans/Web/ViewHelpers/ModuleLoanViewHelper.php index b99ea93c352..7050e6565f7 100644 --- a/domains/Contact/ManageLoans/Web/ViewHelpers/ModuleLoanViewHelper.php +++ b/domains/Contact/ManageLoans/Web/ViewHelpers/ModuleLoanViewHelper.php @@ -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; @@ -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'), diff --git a/resources/js/Shared/Modules/Loans.vue b/resources/js/Shared/Modules/Loans.vue index dea0a7efbe8..a621a5dc6cd 100644 --- a/resources/js/Shared/Modules/Loans.vue +++ b/resources/js/Shared/Modules/Loans.vue @@ -112,6 +112,7 @@ :input-class="'w-full'" :required="false" :min="0" + :max="10000000" :autocomplete="false" @esc-key-pressed="createLoanModalShown = false" /> @@ -329,7 +330,7 @@ :input-class="'w-full'" :required="false" :min="0" - :max="1000000" + :max="10000000" :autocomplete="false" @esc-key-pressed="createLoanModalShown = false" /> @@ -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; diff --git a/tests/Unit/Domains/Contact/ManageLoans/Web/ViewHelpers/ModuleLoanViewHelperTest.php b/tests/Unit/Domains/Contact/ManageLoans/Web/ViewHelpers/ModuleLoanViewHelperTest.php index b883341f490..0708fcf3fa5 100644 --- a/tests/Unit/Domains/Contact/ManageLoans/Web/ViewHelpers/ModuleLoanViewHelperTest.php +++ b/tests/Unit/Domains/Contact/ManageLoans/Web/ViewHelpers/ModuleLoanViewHelperTest.php @@ -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) ); @@ -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']