diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index d3d0097d8..97c78a636 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -26,13 +26,14 @@ import { HomeModule } from './home/home.module';
import { LoginModule } from './login/login.module';
import { SettingsModule } from './settings/settings.module';
import { NavigationModule } from './navigation/navigation.module';
-import { ClientsModule} from './clients/clients.module';
+import { ClientsModule } from './clients/clients.module';
import { GroupsModule } from './groups/groups.module';
import { CentersModule } from './centers/centers.module';
import { AccountingModule } from './accounting/accounting.module';
import { SelfServiceModule } from './self-service/self-service.module';
import { SystemModule } from './system/system.module';
import { ProductsModule } from './products/products.module';
+import { LoansModule } from './loans/loans.module';
/** Main Routing Module */
import { AppRoutingModule } from './app-routing.module';
@@ -60,6 +61,7 @@ import { AppRoutingModule } from './app-routing.module';
CentersModule,
AccountingModule,
SelfServiceModule,
+ LoansModule,
SystemModule,
ProductsModule,
AppRoutingModule
diff --git a/src/app/loans/add-loan-charge/add-loan-charge.component.html b/src/app/loans/add-loan-charge/add-loan-charge.component.html
new file mode 100644
index 000000000..365db7f98
--- /dev/null
+++ b/src/app/loans/add-loan-charge/add-loan-charge.component.html
@@ -0,0 +1,62 @@
+
diff --git a/src/app/loans/add-loan-charge/add-loan-charge.component.scss b/src/app/loans/add-loan-charge/add-loan-charge.component.scss
new file mode 100644
index 000000000..c5d1982b3
--- /dev/null
+++ b/src/app/loans/add-loan-charge/add-loan-charge.component.scss
@@ -0,0 +1,3 @@
+.container{
+ width: 37rem;
+}
diff --git a/src/app/loans/add-loan-charge/add-loan-charge.component.spec.ts b/src/app/loans/add-loan-charge/add-loan-charge.component.spec.ts
new file mode 100644
index 000000000..26b206bf2
--- /dev/null
+++ b/src/app/loans/add-loan-charge/add-loan-charge.component.spec.ts
@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { AddLoanChargeComponent } from './add-loan-charge.component';
+
+describe('AddloanchargeComponent', () => {
+ let component: AddLoanChargeComponent;
+ let fixture: ComponentFixture;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ AddLoanChargeComponent ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(AddLoanChargeComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/app/loans/add-loan-charge/add-loan-charge.component.ts b/src/app/loans/add-loan-charge/add-loan-charge.component.ts
new file mode 100644
index 000000000..4e55a5a1a
--- /dev/null
+++ b/src/app/loans/add-loan-charge/add-loan-charge.component.ts
@@ -0,0 +1,108 @@
+/** Angular Imports */
+import { Component, OnInit } from '@angular/core';
+import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
+import { Router, ActivatedRoute } from '@angular/router';
+import { DatePipe } from '@angular/common';
+
+/** Custom Services */
+import { LoansService } from '../loans.service';
+
+/**
+ * Create Add Loan Charge component.
+ */
+@Component({
+ selector: 'mifosx-addloancharge',
+ templateUrl: './add-loan-charge.component.html',
+ styleUrls: ['./add-loan-charge.component.scss']
+})
+export class AddLoanChargeComponent implements OnInit {
+
+ /** Minimum Due Date allowed. */
+ minDate = new Date(2000, 0, 1);
+ /** Maximum Due Date allowed. */
+ maxDate = new Date();
+ /** Add Loan Charge form. */
+ loanChargeForm: FormGroup;
+ /** loan charge options. */
+ loanChargeOptions: {
+ id: number;
+ name: string;
+ amount: number;
+ chargeCalculationType: {
+ value: any;
+ };
+ chargeTimeType: {
+ id: number;
+ value: any;
+ };
+ }[];
+ /** loan Id of the loan account. */
+ loanId: string;
+
+ /**
+ * Retrieves the loan charge template data from `resolve`.
+ * @param {FormBuilder} formBuilder Form Builder.
+ * @param {AccountingService} accountingService Accounting Service.
+ * @param {ActivatedRoute} route Activated Route.
+ * @param {Router} router Router for navigation.
+ */
+ constructor(private formBuilder: FormBuilder,
+ private route: ActivatedRoute,
+ private router: Router,
+ private datePipe: DatePipe,
+ private loansService: LoansService) {
+ this.route.data.subscribe((data: { loanChargeTemplate: any }) => {
+ this.loanChargeOptions = data.loanChargeTemplate.chargeOptions;
+ });
+ this.loanId = this.route.snapshot.params['loanId'];
+ }
+
+ /**
+ * Creates the Loan Charge form.
+ */
+ ngOnInit() {
+ this.createLoanChargeForm();
+ this.loanChargeForm.controls.chargeId.valueChanges.subscribe(chargeId => {
+ const chargeDetails = this.loanChargeOptions.find(option => {
+ return option.id === chargeId;
+ });
+ if (chargeDetails.chargeTimeType.id === 2) {
+ this.loanChargeForm.addControl('dueDate', new FormControl('', Validators.required));
+ } else {
+ this.loanChargeForm.removeControl('dueDate');
+ }
+ this.loanChargeForm.patchValue({
+ 'amount': chargeDetails.amount,
+ 'chargeCalculation': chargeDetails.chargeCalculationType.value,
+ 'chargeTime': chargeDetails.chargeTimeType.value
+ });
+ });
+ }
+
+ /**
+ * Creates the Loan Charge form.
+ */
+ createLoanChargeForm() {
+ this.loanChargeForm = this.formBuilder.group({
+ 'chargeId': ['', Validators.required],
+ 'amount': ['', Validators.required],
+ 'chargeCalculation': [{ value: '', disabled: true }],
+ 'chargeTime': [{ value: '', disabled: true }]
+ });
+ }
+
+ submit() {
+ const prevDueDate: Date = this.loanChargeForm.value.dueDate;
+ // TODO: Update once language and date settings are setup
+ const dateFormat = 'yyyy-MM-dd';
+ this.loanChargeForm.patchValue({
+ dueDate: this.datePipe.transform(prevDueDate, dateFormat)
+ });
+ const loanCharge = this.loanChargeForm.value;
+ loanCharge.locale = 'en';
+ loanCharge.dateFormat = dateFormat;
+ this.loansService.createLoanCharge(this.loanId, 'charges', loanCharge).subscribe(res => {
+ this.router.navigate(['../'], { relativeTo: this.route });
+ });
+ }
+}
diff --git a/src/app/loans/common-resolvers/loan-charge-template.resolver.ts b/src/app/loans/common-resolvers/loan-charge-template.resolver.ts
new file mode 100644
index 000000000..0af6438eb
--- /dev/null
+++ b/src/app/loans/common-resolvers/loan-charge-template.resolver.ts
@@ -0,0 +1,31 @@
+/** Angular Imports */
+import { Injectable } from '@angular/core';
+import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
+
+/** rxjs Imports */
+import { Observable } from 'rxjs';
+
+/** Custom Services */
+import { LoansService } from '../loans.service';
+
+/**
+ * Loan Charge Template data resolver.
+ */
+@Injectable()
+export class LoanChargeTemplateResolver implements Resolve