refractor: accounting module (#300)
* Refractor components. * Add resolvers. * Add relative router links. * Replace mat-icons by font-awesome icons. * Add comments. Fixes: #298
This commit is contained in:
@@ -9,19 +9,27 @@
|
||||
<div fxLayout="row wrap" fxLayoutGap="2%" fxLayout.lt-md="column">
|
||||
|
||||
<mat-form-field fxFlex="48%">
|
||||
<input matInput placeholder="Accounting Rule Name" required formControlName="name">
|
||||
<mat-label>Accounting Rule Name</mat-label>
|
||||
<input matInput required formControlName="name">
|
||||
<mat-error *ngIf="accountingRuleForm.controls.name.hasError('required')">
|
||||
Accounting Rule Name is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field fxFlex="48%">
|
||||
<mat-select placeholder="Office" required formControlName="officeId">
|
||||
<mat-label>Office</mat-label>
|
||||
<mat-select required formControlName="officeId">
|
||||
<mat-option *ngFor="let office of officeData" [value]="office.id">
|
||||
{{ office.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="accountingRuleForm.controls.officeId.hasError('required')">
|
||||
Office is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<div fxFlex="48%" fxLayout="row" fxLayout.lt-md="column" class="rule-wrapper">
|
||||
<label fxFlex="50%">Affected GL Entry (Debit) Rule Type *</label>
|
||||
<mat-label fxFlex="50%">Affected GL Entry (Debit) Rule Type *</mat-label>
|
||||
<mat-radio-group fxFlex="50%" fxLayout="row" fxLayoutGap="5%" formControlName="debitRuleType">
|
||||
<mat-radio-button value="fixedAccount">Fixed Account</mat-radio-button>
|
||||
<mat-radio-button value="listOfAccounts">List of Accounts</mat-radio-button>
|
||||
@@ -29,7 +37,8 @@
|
||||
</div>
|
||||
|
||||
<mat-form-field fxFlex="48%" *ngIf="accountingRuleForm.controls.debitRuleType.value === 'fixedAccount'">
|
||||
<mat-select placeholder="Account to Debit" required formControlName="accountToDebit">
|
||||
<mat-label>Account to Debit</mat-label>
|
||||
<mat-select formControlName="accountToDebit">
|
||||
<mat-option *ngFor="let glAccount of glAccountData" [value]="glAccount.id">
|
||||
{{ glAccount.name }}
|
||||
</mat-option>
|
||||
@@ -38,22 +47,23 @@
|
||||
|
||||
<div fxFlex="48%" fxLayout="row" fxLayoutGap="2%" fxLayout.lt-md="column" *ngIf="accountingRuleForm.controls.debitRuleType.value === 'listOfAccounts'">
|
||||
<mat-form-field fxFlex="50%">
|
||||
<mat-select placeholder="Debit Tags" required formControlName="debitTags" multiple>
|
||||
<mat-label>Debit Tags</mat-label>
|
||||
<mat-select formControlName="debitTags" multiple>
|
||||
<mat-option *ngFor="let debitTag of debitTagData" [value]="debitTag.id">
|
||||
{{ debitTag.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<div fxFlex="50%" class="entries-wrapper">
|
||||
<mat-checkbox labelPosition="before" required formControlName="allowMultipleDebitEntries" class="entries">
|
||||
<div fxFlex="50%" ngClass.gt-md="entries-wrapper">
|
||||
<mat-checkbox labelPosition="before" formControlName="allowMultipleDebitEntries" class="entries">
|
||||
Multiple Debit Entries Allowed
|
||||
</mat-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div fxFlex="48%" fxLayout="row" fxLayout.lt-md="column" class="rule-wrapper">
|
||||
<label fxFlex="50%">Affected GL Entry (Credit) Rule Type *</label>
|
||||
<mat-label fxFlex="50%">Affected GL Entry (Credit) Rule Type *</mat-label>
|
||||
<mat-radio-group fxFlex="50%" fxLayout="row" fxLayoutGap="5%" formControlName="creditRuleType">
|
||||
<mat-radio-button value="fixedAccount">Fixed Account</mat-radio-button>
|
||||
<mat-radio-button value="listOfAccounts">List of Accounts</mat-radio-button>
|
||||
@@ -61,7 +71,8 @@
|
||||
</div>
|
||||
|
||||
<mat-form-field fxFlex="48%" *ngIf="accountingRuleForm.controls.creditRuleType.value === 'fixedAccount'">
|
||||
<mat-select placeholder="Account to Credit" required formControlName="accountToCredit">
|
||||
<mat-label>Account to Credit</mat-label>
|
||||
<mat-select formControlName="accountToCredit">
|
||||
<mat-option *ngFor="let glAccount of glAccountData" [value]="glAccount.id">
|
||||
{{ glAccount.name }}
|
||||
</mat-option>
|
||||
@@ -70,22 +81,24 @@
|
||||
|
||||
<div fxFlex="48%" fxLayout="row" fxLayoutGap="2%" fxLayout.lt-md="column" *ngIf="accountingRuleForm.controls.creditRuleType.value === 'listOfAccounts'">
|
||||
<mat-form-field fxFlex="50%">
|
||||
<mat-select placeholder="Credit Tags" required formControlName="creditTags" multiple>
|
||||
<mat-label>Credit Tags</mat-label>
|
||||
<mat-select formControlName="creditTags" multiple>
|
||||
<mat-option *ngFor="let creditTag of creditTagData" [value]="creditTag.id">
|
||||
{{ creditTag.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<div fxFlex="50%" class="entries-wrapper">
|
||||
<mat-checkbox labelPosition="before" required formControlName="allowMultipleCreditEntries" class="entries">
|
||||
<div fxFlex="50%" ngClass.gt-md="entries-wrapper">
|
||||
<mat-checkbox labelPosition="before" formControlName="allowMultipleCreditEntries" class="entries">
|
||||
Multiple Credit Entries Allowed
|
||||
</mat-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<mat-form-field fxFlex="98%">
|
||||
<textarea matInput placeholder="Description" formControlName="description"></textarea>
|
||||
<mat-label>Description</mat-label>
|
||||
<textarea matInput formControlName="description"></textarea>
|
||||
</mat-form-field>
|
||||
|
||||
</div>
|
||||
@@ -93,8 +106,8 @@
|
||||
</mat-card-content>
|
||||
|
||||
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
|
||||
<button type="button" mat-raised-button [routerLink]="['/accounting/accounting-rules']">Cancel</button>
|
||||
<button mat-raised-button color="primary">Submit</button>
|
||||
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
|
||||
<button mat-raised-button color="primary" [disabled]="!accountingRuleForm.valid">Submit</button>
|
||||
</mat-card-actions>
|
||||
|
||||
</form>
|
||||
|
||||
@@ -2,11 +2,6 @@
|
||||
margin: 17.5px 0 0 0;
|
||||
}
|
||||
|
||||
.additional-selection {
|
||||
opacity: 0.75;
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
.entries-wrapper {
|
||||
position: relative;
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, Validators, ValidatorFn, ValidationErrors } from '@angular/forms';
|
||||
import { Router } from '@angular/router';
|
||||
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
|
||||
/** Custom Services */
|
||||
import { AccountingService } from '../../accounting.service';
|
||||
|
||||
const oneOfTheFieldsIsRequiredValidator: ValidatorFn = (accountingRuleForm: FormGroup): ValidationErrors | null => {
|
||||
const accountToDebit = accountingRuleForm.controls.accountToDebit.value;
|
||||
const debitTags = accountingRuleForm.controls.debitTags.value;
|
||||
const accountToCredit = accountingRuleForm.controls.accountToCredit.value;
|
||||
const creditTags = accountingRuleForm.controls.creditTags.value;
|
||||
return ((accountToDebit || debitTags) && (accountToCredit || creditTags)) ? null : { 'error': true };
|
||||
};
|
||||
/** Custom Validators */
|
||||
import { oneOfTheFieldsIsRequiredValidator } from '../one-of-the-fields-is-required.validator';
|
||||
|
||||
/**
|
||||
* Create accounting rule component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-create-rule',
|
||||
templateUrl: './create-rule.component.html',
|
||||
@@ -19,23 +19,48 @@ const oneOfTheFieldsIsRequiredValidator: ValidatorFn = (accountingRuleForm: Form
|
||||
})
|
||||
export class CreateRuleComponent implements OnInit {
|
||||
|
||||
/** Accounting rule form. */
|
||||
accountingRuleForm: FormGroup;
|
||||
/** Office data. */
|
||||
officeData: any;
|
||||
/** GL Account data. */
|
||||
glAccountData: any;
|
||||
/** Debit tag data. */
|
||||
debitTagData: any;
|
||||
/** Credit tag data. */
|
||||
creditTagData: any;
|
||||
|
||||
/**
|
||||
* Retrieves the offices, gl accounts, debit tags and credit tags 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 accountingService: AccountingService,
|
||||
private router: Router) { }
|
||||
private route: ActivatedRoute,
|
||||
private router: Router) {
|
||||
this.route.data.subscribe((data: { accountingRulesTemplate: any }) => {
|
||||
this.officeData = data.accountingRulesTemplate.allowedOffices;
|
||||
this.glAccountData = data.accountingRulesTemplate.allowedAccounts;
|
||||
this.debitTagData = data.accountingRulesTemplate.allowedDebitTagOptions;
|
||||
this.creditTagData = data.accountingRulesTemplate.allowedCreditTagOptions;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and sets accounting rules form.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.createAccountingRulesForm();
|
||||
this.getAccountingRulesTemplate();
|
||||
this.createAccountingRuleForm();
|
||||
this.setAccountingRulesForm();
|
||||
}
|
||||
|
||||
createAccountingRulesForm() {
|
||||
/**
|
||||
* Creates accounting rule form.
|
||||
*/
|
||||
createAccountingRuleForm() {
|
||||
this.accountingRuleForm = this.formBuilder.group({
|
||||
'name': ['', Validators.required],
|
||||
'officeId': ['', Validators.required],
|
||||
@@ -51,40 +76,52 @@ export class CreateRuleComponent implements OnInit {
|
||||
}, { validator: oneOfTheFieldsIsRequiredValidator });
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets accounting rule form for selected accounting rule type.
|
||||
*/
|
||||
setAccountingRulesForm() {
|
||||
this.accountingRuleForm.get('debitRuleType').valueChanges.subscribe(debitRuleType => {
|
||||
this.accountingRuleForm.get('debitRuleType').valueChanges.subscribe((debitRuleType: string) => {
|
||||
if (debitRuleType === 'fixedAccount') {
|
||||
this.accountingRuleForm.get('debitTags').reset();
|
||||
this.accountingRuleForm.get('allowMultipleDebitEntries').reset();
|
||||
} else {
|
||||
this.accountingRuleForm.get('accountToDebit').reset();
|
||||
this.accountingRuleForm.get('allowMultipleDebitEntries').setValue(false);
|
||||
}
|
||||
});
|
||||
this.accountingRuleForm.get('creditRuleType').valueChanges.subscribe(creditRuleType => {
|
||||
this.accountingRuleForm.get('creditRuleType').valueChanges.subscribe((creditRuleType: string) => {
|
||||
if (creditRuleType === 'fixedAccount') {
|
||||
this.accountingRuleForm.get('creditTags').reset();
|
||||
this.accountingRuleForm.get('allowMultipleCreditEntries').reset();
|
||||
} else {
|
||||
this.accountingRuleForm.get('accountToCredit').reset();
|
||||
this.accountingRuleForm.get('allowMultipleCreditEntries').setValue(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getAccountingRulesTemplate() {
|
||||
this.accountingService.getAccountingRulesTemplate().subscribe((accountingRulesData: any) => {
|
||||
this.officeData = accountingRulesData.allowedOffices;
|
||||
this.glAccountData = accountingRulesData.allowedAccounts;
|
||||
this.debitTagData = accountingRulesData.allowedDebitTagOptions;
|
||||
this.creditTagData = accountingRulesData.allowedCreditTagOptions;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the accounting rule form and creates accounting rule,
|
||||
* if successful redirects to view created rule.
|
||||
*/
|
||||
submit() {
|
||||
const accountingRule = this.accountingRuleForm.value;
|
||||
if (accountingRule.debitRuleType === 'fixedAccount') {
|
||||
delete accountingRule.debitTags;
|
||||
delete accountingRule.allowMultipleDebitEntries;
|
||||
} else {
|
||||
delete accountingRule.accountToDebit;
|
||||
}
|
||||
if (accountingRule.creditRuleType === 'fixedAccount') {
|
||||
delete accountingRule.creditTags;
|
||||
delete accountingRule.allowMultipleCreditEntries;
|
||||
} else {
|
||||
delete accountingRule.accountToCredit;
|
||||
}
|
||||
delete accountingRule.debitRuleType;
|
||||
delete accountingRule.creditRuleType;
|
||||
this.accountingService.createAccountingRule(accountingRule).subscribe((response: any) => {
|
||||
this.router.navigate(['/accounting/accounting-rules/view', response.resourceId]);
|
||||
this.router.navigate(['../view', response.resourceId], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user