-
Notifications
You must be signed in to change notification settings - Fork 888
Expand file tree
/
Copy pathcreate-provisioning-entry.component.ts
More file actions
100 lines (92 loc) · 3.18 KB
/
create-provisioning-entry.component.ts
File metadata and controls
100 lines (92 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Copyright since 2025 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/** Angular Imports */
import { Component, OnInit, inject } from '@angular/core';
import { UntypedFormGroup, UntypedFormBuilder, Validators, ReactiveFormsModule } from '@angular/forms';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
/** Custom Services */
import { AccountingService } from '../../accounting.service';
import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
import { MatCheckbox } from '@angular/material/checkbox';
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
/**
* Create provisioning entry component.
*/
@Component({
selector: 'mifosx-create-provisioning-entry',
templateUrl: './create-provisioning-entry.component.html',
styleUrls: ['./create-provisioning-entry.component.scss'],
imports: [
...STANDALONE_SHARED_IMPORTS,
MatCheckbox
]
})
export class CreateProvisioningEntryComponent implements OnInit {
private formBuilder = inject(UntypedFormBuilder);
private accountingService = inject(AccountingService);
private settingsService = inject(SettingsService);
private dateUtils = inject(Dates);
private route = inject(ActivatedRoute);
private router = inject(Router);
/** Minimum provisioning date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum provisioning date allowed. */
maxDate = new Date();
/** Provisioning entry form. */
provisioningEntryForm: UntypedFormGroup;
/**
* Creates the provisioning entry form.
*/
ngOnInit() {
this.maxDate = this.settingsService.businessDate;
this.createProvisioningEntryForm();
}
/**
* Creates the provisioning entry form.
*/
createProvisioningEntryForm() {
this.provisioningEntryForm = this.formBuilder.group({
date: [
'',
Validators.required
],
createjournalentries: [false]
});
}
/**
* Submits the provisioning entry form and creates provisioning entry,
* if successful redirects to view created entry.
*/
submit() {
const provisioningEntry = this.provisioningEntryForm.value;
provisioningEntry.locale = this.settingsService.language.code;
provisioningEntry.dateFormat = this.settingsService.dateFormat;
if (provisioningEntry.date instanceof Date) {
provisioningEntry.date = this.dateUtils.formatDate(provisioningEntry.date, this.settingsService.dateFormat);
}
this.accountingService.createProvisioningEntry(provisioningEntry).subscribe({
next: (response: any) => {
this.router.navigate(
[
'../view',
response.resourceId
],
{ relativeTo: this.route }
);
},
error: (error: any) => {
if (error.status === 500) {
// Fineract returns 500 even when the entry is created successfully.
// Navigate to the list since we don't have a resourceId.
this.router.navigate(['../'], { relativeTo: this.route });
}
}
});
}
}