feat: add create dividend component (#807)

Fixes: #770
This commit is contained in:
Benura Abeywardena
2020-08-02 11:03:09 +05:30
committed by GitHub
parent d77a78d3c6
commit 26ce041855
8 changed files with 191 additions and 6 deletions
+18 -4
View File
@@ -43,6 +43,7 @@ import { EditTaxComponentComponent } from './manage-tax-components/edit-tax-comp
import { ViewTaxGroupComponent } from './manage-tax-groups/view-tax-group/view-tax-group.component';
import { ShareProductsDividendsComponent } from './share-products/dividends-share-product/dividends.components';
import { CreateRecurringDepositProductComponent } from './recurring-deposit-products/create-recurring-deposit-product/create-recurring-deposit-product.component';
import { CreateDividendComponent } from './share-products/create-dividend/create-dividend.component';
/** Custom Resolvers */
import { LoanProductsResolver } from './loan-products/loan-products.resolver';
@@ -215,10 +216,23 @@ const routes: Routes = [
{
path: 'dividends',
data: { title: extract('Share Products Dividends'), breadcrumb: 'Dividends', routeParamBreadcrumb: false},
component: ShareProductsDividendsComponent,
resolve: {
dividends: DividendsResolver
}
children: [
{
path: '',
component: ShareProductsDividendsComponent,
resolve: {
dividends: DividendsResolver
}
},
{
path: 'create',
component: CreateDividendComponent,
data: { title: extract('Create Dividend'), breadcrumb: 'Create', routeParamBreadcrumb: false },
resolve: {
shareProduct: ShareProductResolver
}
}
]
}
]
}
+3 -1
View File
@@ -87,6 +87,7 @@ import { RecurringDepositProductPreviewStepComponent } from './recurring-deposit
import { RecurringDepositProductSettingsStepComponent } from './recurring-deposit-products/recurring-deposit-product-stepper/recurring-deposit-product-settings-step/recurring-deposit-product-settings-step.component';
import { RecurringDepositProductTermsStepComponent } from './recurring-deposit-products/recurring-deposit-product-stepper/recurring-deposit-product-terms-step/recurring-deposit-product-terms-step.component';
import { EditRecurringDepositProductComponent } from './recurring-deposit-products/edit-recurring-deposit-product/edit-recurring-deposit-product.component';
import { CreateDividendComponent } from './share-products/create-dividend/create-dividend.component';
/**
* Products Module
@@ -177,7 +178,8 @@ import { EditRecurringDepositProductComponent } from './recurring-deposit-produc
RecurringDepositProductPreviewStepComponent,
RecurringDepositProductSettingsStepComponent,
RecurringDepositProductTermsStepComponent,
EditRecurringDepositProductComponent
EditRecurringDepositProductComponent,
CreateDividendComponent
],
entryComponents: [
DepositProductIncentiveFormDialogComponent,
+10
View File
@@ -94,6 +94,16 @@ export class ProductsService {
return this.http.get(`/shareproduct/${shareProductId}/dividend`);
}
/**
* Create Dividend.
* @param shareProductId Share Product Id.
* @param dividendData Dividend Data.
* @returns {Observable<any>}
*/
createDividend(shareProductId: string, dividendData: any): Observable<any> {
return this.http.post(`/shareproduct/${shareProductId}/dividend`, dividendData);
}
/**
* @returns {Observable<any>} Recurring deposit products data
*/
@@ -0,0 +1,52 @@
<div class="container">
<mat-card>
<form [formGroup]="createDividendForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Dividend Period Start Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="startDatePicker" required formControlName="dividendPeriodStartDate">
<mat-datepicker-toggle matSuffix [for]="startDatePicker"></mat-datepicker-toggle>
<mat-datepicker #startDatePicker></mat-datepicker>
<mat-error *ngIf="createDividendForm.controls.dividendPeriodStartDate.hasError('required')">
Starting date <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Dividend Period End Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="endDatePicker" required formControlName="dividendPeriodEndDate">
<mat-datepicker-toggle matSuffix [for]="endDatePicker"></mat-datepicker-toggle>
<mat-datepicker #endDatePicker></mat-datepicker>
<mat-error *ngIf="createDividendForm.controls.dividendPeriodEndDate.hasError('required')">
End date <strong>is required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Dividend Amount</mat-label>
<input matInput required formControlName="dividendAmount">
<mat-error *ngIf="createDividendForm.controls.dividendAmount.hasError('required')">
Amount is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!createDividendForm.valid">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CreateDividendComponent } from './create-dividend.component';
describe('CreateDividendComponent', () => {
let component: CreateDividendComponent;
let fixture: ComponentFixture<CreateDividendComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CreateDividendComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CreateDividendComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,79 @@
/** Angular Imports. */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { DatePipe } from '@angular/common';
/** Custom Services. */
import { ProductsService } from 'app/products/products.service';
/**
* Create Dividend component.
*/
@Component({
selector: 'mifosx-create-dividend',
templateUrl: './create-dividend.component.html',
styleUrls: ['./create-dividend.component.scss']
})
export class CreateDividendComponent implements OnInit {
/** Create Dividend Form. */
createDividendForm: FormGroup;
/** Share Product data. */
shareProductData: any;
/** Minimum Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Date allowed. */
maxDate = new Date();
/**
* Get Share Product data from `Resolver`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router.
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private datePipe: DatePipe,
private productService: ProductsService,
private router: Router) {
this.route.data.subscribe((data: { shareProduct: any }) => {
this.shareProductData = data.shareProduct;
});
}
ngOnInit() {
this.setDividendForm();
}
/**
* Sets Create Dividend from.
*/
setDividendForm() {
this.createDividendForm = this.formBuilder.group({
'dividendPeriodStartDate': ['', Validators.required],
'dividendPeriodEndDate': ['', Validators.required],
'dividendAmount': ['', Validators.required]
});
}
/**
* Submits Create Dividend form.
*/
submit() {
const dateFormat = 'yyyy-MM-dd';
const startDate = this.createDividendForm.value.dividendPeriodStartDate;
const endDate = this.createDividendForm.value.dividendPeriodEndDate;
this.createDividendForm.patchValue({
'dividendPeriodStartDate': this.datePipe.transform(startDate, dateFormat),
'dividendPeriodEndDate': this.datePipe.transform(endDate, dateFormat)
});
const dividendForm = this.createDividendForm.value;
dividendForm.locale = 'en';
dividendForm.dateFormat = dateFormat;
this.productService.createDividend(this.shareProductData.id, dividendForm).subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
}
@@ -1,5 +1,5 @@
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
<button mat-raised-button color="primary">
<button mat-raised-button color="primary" [routerLink]="['create']" *mifosxHasPermission="'mifosxHasPermission'">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp;
Initiate Dividend
</button>