feat(accounting-rules): create rule component
Add create rule component.
This commit is contained in:
@@ -26,6 +26,7 @@ import { CreateClosureComponent } from './closing-entries/create-closure/create-
|
||||
import { ViewClosureComponent } from './closing-entries/view-closure/view-closure.component';
|
||||
import { EditClosureComponent } from './closing-entries/edit-closure/edit-closure.component';
|
||||
import { AccountingRulesComponent } from './accounting-rules/accounting-rules.component';
|
||||
import { CreateRuleComponent } from './accounting-rules/create-rule/create-rule.component';
|
||||
|
||||
const routes: Routes = [
|
||||
Route.withShell([
|
||||
@@ -165,8 +166,18 @@ const routes: Routes = [
|
||||
},
|
||||
{
|
||||
path: 'accounting-rules',
|
||||
component: AccountingRulesComponent,
|
||||
data: { title: extract('Accounting Rules'), breadcrumb: 'Rules' },
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
component: AccountingRulesComponent
|
||||
},
|
||||
{
|
||||
path: 'create',
|
||||
component: CreateRuleComponent,
|
||||
data: { title: extract('Create Accounting Rule'), breadcrumb: 'Create' }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<form [formGroup]="accountingRuleForm" (ngSubmit)="submit()">
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<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-form-field>
|
||||
|
||||
<mat-form-field fxFlex="48%">
|
||||
<mat-select placeholder="Office" required formControlName="officeId">
|
||||
<mat-option *ngFor="let office of officeData" [value]="office.id">
|
||||
{{ office.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</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-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>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
|
||||
<mat-form-field fxFlex="48%" *ngIf="accountingRuleForm.controls.debitRuleType.value === 'fixedAccount'">
|
||||
<mat-select placeholder="Account to Debit" required formControlName="accountToDebit">
|
||||
<mat-option *ngFor="let glAccount of glAccountData" [value]="glAccount.id">
|
||||
{{ glAccount.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<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-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">
|
||||
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-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>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
|
||||
<mat-form-field fxFlex="48%" *ngIf="accountingRuleForm.controls.creditRuleType.value === 'fixedAccount'">
|
||||
<mat-select placeholder="Account to Credit" required formControlName="accountToCredit">
|
||||
<mat-option *ngFor="let glAccount of glAccountData" [value]="glAccount.id">
|
||||
{{ glAccount.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<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-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">
|
||||
Multiple Credit Entries Allowed
|
||||
</mat-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<mat-form-field fxFlex="98%">
|
||||
<textarea matInput placeholder="Description" formControlName="description"></textarea>
|
||||
</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]="['/accounting/accounting-rules']">Cancel</button>
|
||||
<button mat-raised-button color="primary">Submit</button>
|
||||
</mat-card-actions>
|
||||
|
||||
</form>
|
||||
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,19 @@
|
||||
.rule-wrapper {
|
||||
margin: 17.5px 0 0 0;
|
||||
}
|
||||
|
||||
.additional-selection {
|
||||
opacity: 0.75;
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
.entries-wrapper {
|
||||
position: relative;
|
||||
|
||||
.entries {
|
||||
padding: 0 0 17.5px 0;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CreateRuleComponent } from './create-rule.component';
|
||||
|
||||
describe('CreateRuleComponent', () => {
|
||||
let component: CreateRuleComponent;
|
||||
let fixture: ComponentFixture<CreateRuleComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ CreateRuleComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CreateRuleComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, Validators, ValidatorFn, ValidationErrors } from '@angular/forms';
|
||||
|
||||
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 };
|
||||
};
|
||||
|
||||
@Component({
|
||||
selector: 'mifosx-create-rule',
|
||||
templateUrl: './create-rule.component.html',
|
||||
styleUrls: ['./create-rule.component.scss']
|
||||
})
|
||||
export class CreateRuleComponent implements OnInit {
|
||||
|
||||
accountingRuleForm: FormGroup;
|
||||
officeData: any;
|
||||
glAccountData: any;
|
||||
debitTagData: any;
|
||||
creditTagData: any;
|
||||
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private accountingService: AccountingService) { }
|
||||
|
||||
ngOnInit() {
|
||||
this.createAccountingRulesForm();
|
||||
this.getAccountingRulesTemplate();
|
||||
this.setAccountingRulesForm();
|
||||
}
|
||||
|
||||
createAccountingRulesForm() {
|
||||
this.accountingRuleForm = this.formBuilder.group({
|
||||
'name': ['', Validators.required],
|
||||
'officeId': ['', Validators.required],
|
||||
'debitRuleType': ['fixedAccount'],
|
||||
'accountToDebit': [''],
|
||||
'debitTags': [''],
|
||||
'allowMultipleDebitEntries': [''],
|
||||
'creditRuleType': ['fixedAccount'],
|
||||
'accountToCredit': [''],
|
||||
'creditTags': [''],
|
||||
'allowMultipleCreditEntries': [''],
|
||||
'description': ['']
|
||||
}, { validator: oneOfTheFieldsIsRequiredValidator });
|
||||
}
|
||||
|
||||
setAccountingRulesForm() {
|
||||
this.accountingRuleForm.get('debitRuleType').valueChanges.subscribe(debitRuleType => {
|
||||
if (debitRuleType === 'fixedAccount') {
|
||||
this.accountingRuleForm.get('debitTags').reset();
|
||||
this.accountingRuleForm.get('allowMultipleDebitEntries').reset();
|
||||
} else {
|
||||
this.accountingRuleForm.get('allowMultipleDebitEntries').setValue(false);
|
||||
}
|
||||
});
|
||||
this.accountingRuleForm.get('creditRuleType').valueChanges.subscribe(creditRuleType => {
|
||||
if (creditRuleType === 'fixedAccount') {
|
||||
this.accountingRuleForm.get('creditTags').reset();
|
||||
this.accountingRuleForm.get('allowMultipleCreditEntries').reset();
|
||||
} else {
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
submit() {
|
||||
const accountingRule = this.accountingRuleForm.value;
|
||||
delete accountingRule.debitRuleType;
|
||||
delete accountingRule.creditRuleType;
|
||||
this.accountingService.createAccountingRule(accountingRule).subscribe((response: any) => {
|
||||
console.log(response);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import { CreateClosureComponent } from './closing-entries/create-closure/create-
|
||||
import { ViewClosureComponent } from './closing-entries/view-closure/view-closure.component';
|
||||
import { EditClosureComponent } from './closing-entries/edit-closure/edit-closure.component';
|
||||
import { AccountingRulesComponent } from './accounting-rules/accounting-rules.component';
|
||||
import { CreateRuleComponent } from './accounting-rules/create-rule/create-rule.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -54,7 +55,8 @@ import { AccountingRulesComponent } from './accounting-rules/accounting-rules.co
|
||||
CreateClosureComponent,
|
||||
ViewClosureComponent,
|
||||
EditClosureComponent,
|
||||
AccountingRulesComponent
|
||||
AccountingRulesComponent,
|
||||
CreateRuleComponent
|
||||
],
|
||||
entryComponents: [
|
||||
RevertTransactionComponent,
|
||||
|
||||
@@ -145,4 +145,12 @@ export class AccountingService {
|
||||
return this.http.put(`/glclosures/${accountingClosureId}`, accountingClosure);
|
||||
}
|
||||
|
||||
getAccountingRulesTemplate() {
|
||||
return this.http.get('/accountingrules/template');
|
||||
}
|
||||
|
||||
createAccountingRule(accountingRule: any) {
|
||||
return this.http.post('/accountingrules', accountingRule);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user