Skip to content

Commit

Permalink
fix: bug fix on loan (monicahq/chandler#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored and asbiin committed Mar 31, 2023
1 parent f99e74c commit df5822a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
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

0 comments on commit df5822a

Please sign in to comment.