diff --git a/src/app/accounting/accounting-routing.module.ts b/src/app/accounting/accounting-routing.module.ts index 8109221d8..5d02709ab 100644 --- a/src/app/accounting/accounting-routing.module.ts +++ b/src/app/accounting/accounting-routing.module.ts @@ -5,6 +5,7 @@ import { Route, extract } from '../core'; import { AccountingComponent } from './accounting.component'; import { FrequentPostingsComponent } from './frequent-postings/frequent-postings.component'; import { ViewTransactionComponent } from './view-transaction/view-transaction.component'; +import { CreateJournalEntryComponent } from './create-journal-entry/create-journal-entry.component'; const routes: Routes = [ Route.withShell([ @@ -31,6 +32,11 @@ const routes: Routes = [ data: { title: extract('View Transaction'), routeParamBreadcrumb: 'id' } } ] + }, + { + path: 'journal-entries/create', + component: CreateJournalEntryComponent, + data: { title: extract('Create Journal Entry'), breadcrumb: 'Create Journal Entry' } } ] } diff --git a/src/app/accounting/accounting.component.html b/src/app/accounting/accounting.component.html index a4826d62f..55db81f90 100644 --- a/src/app/accounting/accounting.component.html +++ b/src/app/accounting/accounting.component.html @@ -12,11 +12,9 @@

These are predefined postings

- + add - - Add Journal Entries - +

Create Journal Entries

Manual journal entry transactions recorded in a journal

diff --git a/src/app/accounting/accounting.module.ts b/src/app/accounting/accounting.module.ts index 9aef9efb6..c33f805db 100644 --- a/src/app/accounting/accounting.module.ts +++ b/src/app/accounting/accounting.module.ts @@ -9,6 +9,7 @@ import { FrequentPostingsComponent } from './frequent-postings/frequent-postings import { ViewTransactionComponent } from './view-transaction/view-transaction.component'; import { RevertTransactionComponent } from './revert-transaction/revert-transaction.component'; import { ViewJournalEntryComponent } from './view-journal-entry/view-journal-entry.component'; +import { CreateJournalEntryComponent } from './create-journal-entry/create-journal-entry.component'; @NgModule({ imports: [ @@ -22,7 +23,8 @@ import { ViewJournalEntryComponent } from './view-journal-entry/view-journal-ent FrequentPostingsComponent, ViewTransactionComponent, RevertTransactionComponent, - ViewJournalEntryComponent + ViewJournalEntryComponent, + CreateJournalEntryComponent ], entryComponents: [ RevertTransactionComponent, diff --git a/src/app/accounting/accounting.service.ts b/src/app/accounting/accounting.service.ts index 470b7cb14..adf6f75a9 100644 --- a/src/app/accounting/accounting.service.ts +++ b/src/app/accounting/accounting.service.ts @@ -46,4 +46,12 @@ export class AccountingService { return this.http.post(`/journalentries/${transactionId}`, data, { params: httpParams }); } + getGlAccounts() { + let httpParams = new HttpParams(); + httpParams = httpParams.set('manualEntriesAllowed', 'true'); + httpParams = httpParams.set('usage', '1'); + httpParams = httpParams.set('disabled', 'false'); + return this.http.get(`/glaccounts`, { params: httpParams }); + } + } diff --git a/src/app/accounting/create-journal-entry/create-journal-entry.component.html b/src/app/accounting/create-journal-entry/create-journal-entry.component.html new file mode 100644 index 000000000..08487858f --- /dev/null +++ b/src/app/accounting/create-journal-entry/create-journal-entry.component.html @@ -0,0 +1,131 @@ + + +
+ + + +
+ + + + + {{ office.name }} + + + + + + + + {{ currency.displayLabel }} + + + + +
+ +
+ + + + + {{ affectedGLEntryDebit.name + ' (' + affectedGLEntryDebit.glCode + ')' }} + + + + + + + + + + + + + +
+ +
+ +
+ +
+ + + + + {{ affectedGLEntryCredit.name + ' (' + affectedGLEntryCredit.glCode + ')' }} + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + {{ paymentType.name }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + +
+ +
+ diff --git a/src/app/accounting/create-journal-entry/create-journal-entry.component.scss b/src/app/accounting/create-journal-entry/create-journal-entry.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/accounting/create-journal-entry/create-journal-entry.component.spec.ts b/src/app/accounting/create-journal-entry/create-journal-entry.component.spec.ts new file mode 100644 index 000000000..662f9a496 --- /dev/null +++ b/src/app/accounting/create-journal-entry/create-journal-entry.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreateJournalEntryComponent } from './create-journal-entry.component'; + +describe('CreateJournalEntryComponent', () => { + let component: CreateJournalEntryComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CreateJournalEntryComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CreateJournalEntryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/accounting/create-journal-entry/create-journal-entry.component.ts b/src/app/accounting/create-journal-entry/create-journal-entry.component.ts new file mode 100644 index 000000000..c17a565c0 --- /dev/null +++ b/src/app/accounting/create-journal-entry/create-journal-entry.component.ts @@ -0,0 +1,108 @@ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators, FormArray } from '@angular/forms'; +import { Router } from '@angular/router'; + +import { AccountingService } from '../accounting.service'; + +@Component({ + selector: 'mifosx-create-journal-entry', + templateUrl: './create-journal-entry.component.html', + styleUrls: ['./create-journal-entry.component.scss'] +}) +export class CreateJournalEntryComponent implements OnInit { + + // TODO: Validations + + minDate = new Date(2000, 0, 1); + maxDate = new Date(); + journalEntryForm: FormGroup; + officeData: any; + currencyData: any; + paymentTypeData: any; + glAccountData: any; + + constructor(private formBuilder: FormBuilder, + private accountingService: AccountingService, + private router: Router) { } + + ngOnInit() { + this.createJournalEntryForm(); + this.getOffices(); + this.getCurrencies(); + this.getPaymentTypes(); + this.getGlAccounts(); + } + + createJournalEntryForm() { + this.journalEntryForm = this.formBuilder.group({ + 'officeId': ['', Validators.required], + 'currencyCode': ['', Validators.required], + 'debits': this.formBuilder.array([this.createAffectedGLEntryForm()]), + 'credits': this.formBuilder.array([this.createAffectedGLEntryForm()]), + 'referenceNumber': [''], + 'transactionDate': ['', Validators.required], + 'paymentTypeId': [''], + 'accountNumber': [''], + 'checkNumber': [''], + 'routingCode': [''], + 'receiptNumber': [''], + 'bankNumber': [''], + 'comments': [''] + }); + } + + createAffectedGLEntryForm(): FormGroup { + return this.formBuilder.group({ + 'glAccountId': ['', Validators.required], + 'amount': ['', Validators.required] + }); + } + + getFormArrayData(type: string): FormArray { + return this.journalEntryForm.get(type); + } + + addAffectedGLEntry(affectedGLEntryFormArray: FormArray) { + affectedGLEntryFormArray.push(this.createAffectedGLEntryForm()); + } + + removeAffectedGLEntry(affectedGLEntryFormArray: FormArray, index: number) { + affectedGLEntryFormArray.removeAt(index); + } + + getOffices() { + this.accountingService.getOffices().subscribe(officeData => { + this.officeData = officeData; + }); + } + + getCurrencies() { + this.accountingService.getCurrencies().subscribe(currencyData => { + this.currencyData = currencyData.selectedCurrencyOptions; + }); + } + + getPaymentTypes() { + this.accountingService.getPaymentTypes().subscribe(paymentTypeData => { + this.paymentTypeData = paymentTypeData; + }); + } + + getGlAccounts() { + this.accountingService.getGlAccounts().subscribe(glAccountData => { + this.glAccountData = glAccountData; + }); + } + + submit() { + const journalEntry = this.journalEntryForm.value; + // TODO: Update once language and date settings are setup + journalEntry.locale = 'en'; + journalEntry.dateFormat = 'dd MMMM yyyy'; + journalEntry.transactionDate = '20 July 2018'; + this.accountingService.createJournalEntry(journalEntry).subscribe(response => { + this.router.navigate(['/accounting/transactions/view', response.transactionId]); + }); + } + +} diff --git a/src/app/accounting/frequent-postings/frequent-postings.component.html b/src/app/accounting/frequent-postings/frequent-postings.component.html index d6fd8880b..a6f1ed4fb 100644 --- a/src/app/accounting/frequent-postings/frequent-postings.component.html +++ b/src/app/accounting/frequent-postings/frequent-postings.component.html @@ -131,8 +131,8 @@ + -