Fix for creating manual entries

This commit is contained in:
Jose Alberto Hernandez
2022-05-25 20:22:10 -05:00
parent 01abdde8ab
commit d48c223cba
9 changed files with 54 additions and 90 deletions
@@ -42,9 +42,11 @@ export class GlAccountAndChartOfAccountsTemplateResolver implements Resolve<Obje
case 'LIABILITY': accountOptions = glAccountData.liabilityHeaderAccountOptions; case 'LIABILITY': accountOptions = glAccountData.liabilityHeaderAccountOptions;
break; break;
} }
glAccountData.parent = accountOptions.find((accountOption: any) => { if (glAccountData.parentId) {
return accountOption.id === glAccountData.parentId; glAccountData.parent = accountOptions.find((accountOption: any) => {
}); return accountOption.id === glAccountData.parentId;
});
}
return glAccountData; return glAccountData;
}) })
); );
@@ -6,6 +6,7 @@ import { Router, ActivatedRoute } from '@angular/router';
/** Custom Services */ /** Custom Services */
import { AccountingService } from '../../accounting.service'; import { AccountingService } from '../../accounting.service';
import { SettingsService } from 'app/settings/settings.service'; import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
/** /**
* Create closure component. * Create closure component.
*/ */
@@ -36,6 +37,7 @@ export class CreateClosureComponent implements OnInit {
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private accountingService: AccountingService, private accountingService: AccountingService,
private settingsService: SettingsService, private settingsService: SettingsService,
private dateUtils: Dates,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { private router: Router) {
this.route.data.subscribe((data: { offices: any }) => { this.route.data.subscribe((data: { offices: any }) => {
@@ -70,17 +72,8 @@ export class CreateClosureComponent implements OnInit {
// TODO: Update once language and date settings are setup // TODO: Update once language and date settings are setup
accountingClosure.locale = this.settingsService.language.code; accountingClosure.locale = this.settingsService.language.code;
accountingClosure.dateFormat = this.settingsService.dateFormat; accountingClosure.dateFormat = this.settingsService.dateFormat;
if (accountingClosure.closingDate instanceof Date) { if (accountingClosure.closingDate) {
let day = accountingClosure.closingDate.getDate(); accountingClosure.closingDate = this.dateUtils.getDate(accountingClosure.closingDate);
let month = accountingClosure.closingDate.getMonth() + 1;
const year = accountingClosure.closingDate.getFullYear();
if (day < 10) {
day = `0${day}`;
}
if (month < 10) {
month = `0${month}`;
}
accountingClosure.closingDate = `${year}-${month}-${day}`;
} }
this.accountingService.createAccountingClosure(accountingClosure).subscribe((response: any) => { this.accountingService.createAccountingClosure(accountingClosure).subscribe((response: any) => {
this.router.navigate(['../view', response.resourceId], { relativeTo: this.route }); this.router.navigate(['../view', response.resourceId], { relativeTo: this.route });
@@ -6,6 +6,7 @@ import { Router, ActivatedRoute } from '@angular/router';
/** Custom Services */ /** Custom Services */
import { AccountingService } from '../accounting.service'; import { AccountingService } from '../accounting.service';
import { SettingsService } from 'app/settings/settings.service'; import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
/** /**
* Create Journal Entry component. * Create Journal Entry component.
*/ */
@@ -42,6 +43,7 @@ export class CreateJournalEntryComponent implements OnInit {
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private accountingService: AccountingService, private accountingService: AccountingService,
private settingsService: SettingsService, private settingsService: SettingsService,
private dateUtils: Dates,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { private router: Router) {
this.route.data.subscribe((data: { this.route.data.subscribe((data: {
@@ -138,17 +140,8 @@ export class CreateJournalEntryComponent implements OnInit {
// TODO: Update once language and date settings are setup // TODO: Update once language and date settings are setup
journalEntry.locale = this.settingsService.language.code; journalEntry.locale = this.settingsService.language.code;
journalEntry.dateFormat = this.settingsService.dateFormat; journalEntry.dateFormat = this.settingsService.dateFormat;
if (journalEntry.transactionDate instanceof Date) { if (journalEntry.transactionDate) {
let day = journalEntry.transactionDate.getDate(); journalEntry.transactionDate = this.dateUtils.getDate(journalEntry.transactionDate);
let month = journalEntry.transactionDate.getMonth() + 1;
const year = journalEntry.transactionDate.getFullYear();
if (day < 10) {
day = `0${day}`;
}
if (month < 10) {
month = `0${month}`;
}
journalEntry.transactionDate = `${year}-${month}-${day}`;
} }
this.accountingService.createJournalEntry(journalEntry).subscribe(response => { this.accountingService.createJournalEntry(journalEntry).subscribe(response => {
this.router.navigate(['../transactions/view', response.transactionId], { relativeTo: this.route }); this.router.navigate(['../transactions/view', response.transactionId], { relativeTo: this.route });
@@ -6,6 +6,7 @@ import { Router, ActivatedRoute } from '@angular/router';
/** Custom Services */ /** Custom Services */
import { AccountingService } from '../accounting.service'; import { AccountingService } from '../accounting.service';
import { SettingsService } from 'app/settings/settings.service'; import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
/** /**
* Frequent Postings component. * Frequent Postings component.
*/ */
@@ -50,6 +51,7 @@ export class FrequentPostingsComponent implements OnInit {
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private accountingService: AccountingService, private accountingService: AccountingService,
private settingsService: SettingsService, private settingsService: SettingsService,
private dateUtils: Dates,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { private router: Router) {
this.route.data.subscribe((data: { this.route.data.subscribe((data: {
@@ -170,16 +172,7 @@ export class FrequentPostingsComponent implements OnInit {
journalEntry.locale = this.settingsService.language.code; journalEntry.locale = this.settingsService.language.code;
journalEntry.dateFormat = this.settingsService.dateFormat; journalEntry.dateFormat = this.settingsService.dateFormat;
if (journalEntry.transactionDate instanceof Date) { if (journalEntry.transactionDate instanceof Date) {
let day = journalEntry.transactionDate.getDate(); journalEntry.transactionDate = this.dateUtils.getDate(journalEntry.transactionDate);
let month = journalEntry.transactionDate.getMonth() + 1;
const year = journalEntry.transactionDate.getFullYear();
if (day < 10) {
day = `0${day}`;
}
if (month < 10) {
month = `0${month}`;
}
journalEntry.transactionDate = `${year}-${month}-${day}`;
} }
this.accountingService.createJournalEntry(journalEntry).subscribe(response => { this.accountingService.createJournalEntry(journalEntry).subscribe(response => {
this.router.navigate(['../transactions/view', response.transactionId], { relativeTo: this.route }); this.router.navigate(['../transactions/view', response.transactionId], { relativeTo: this.route });
@@ -8,6 +8,7 @@ import { AccountingService } from '../accounting.service';
import { SettingsService } from 'app/settings/settings.service'; import { SettingsService } from 'app/settings/settings.service';
/** Custom Validators */ /** Custom Validators */
import { onlyOneOfTheFieldsIsRequiredValidator } from './only-one-of-the-fields-is-required.validator'; import { onlyOneOfTheFieldsIsRequiredValidator } from './only-one-of-the-fields-is-required.validator';
import { Dates } from 'app/core/utils/dates';
/** /**
* Migrate opening balances component. * Migrate opening balances component.
@@ -47,6 +48,7 @@ export class MigrateOpeningBalancesComponent implements OnInit {
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private accountingService: AccountingService, private accountingService: AccountingService,
private settingsService: SettingsService, private settingsService: SettingsService,
private dateUtils: Dates,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { private router: Router) {
this.route.data.subscribe((data: { this.route.data.subscribe((data: {
@@ -139,16 +141,7 @@ export class MigrateOpeningBalancesComponent implements OnInit {
openingBalances.locale = this.settingsService.language.code; openingBalances.locale = this.settingsService.language.code;
openingBalances.dateFormat = this.settingsService.dateFormat; openingBalances.dateFormat = this.settingsService.dateFormat;
if (openingBalances.transactionDate instanceof Date) { if (openingBalances.transactionDate instanceof Date) {
let day = openingBalances.transactionDate.getDate(); openingBalances.transactionDate = this.dateUtils.getDate(openingBalances.transactionDate);
let month = openingBalances.transactionDate.getMonth() + 1;
const year = openingBalances.transactionDate.getFullYear();
if (day < 10) {
day = `0${day}`;
}
if (month < 10) {
month = `0${month}`;
}
openingBalances.transactionDate = `${year}-${month}-${day}`;
} }
openingBalances.debits = []; openingBalances.debits = [];
openingBalances.credits = []; openingBalances.credits = [];
@@ -6,6 +6,7 @@ import { Router, ActivatedRoute } from '@angular/router';
/** Custom Services */ /** Custom Services */
import { AccountingService } from '../accounting.service'; import { AccountingService } from '../accounting.service';
import { SettingsService } from 'app/settings/settings.service'; import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
/** /**
* Periodic accruals component. * Periodic accruals component.
*/ */
@@ -33,6 +34,7 @@ export class PeriodicAccrualsComponent implements OnInit {
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private accountingService: AccountingService, private accountingService: AccountingService,
private settingsService: SettingsService, private settingsService: SettingsService,
private dateUtils: Dates,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { } private router: Router) { }
@@ -62,16 +64,7 @@ export class PeriodicAccrualsComponent implements OnInit {
periodicAccruals.locale = this.settingsService.language.code; periodicAccruals.locale = this.settingsService.language.code;
periodicAccruals.dateFormat = this.settingsService.dateFormat; periodicAccruals.dateFormat = this.settingsService.dateFormat;
if (periodicAccruals.tillDate instanceof Date) { if (periodicAccruals.tillDate instanceof Date) {
let day = periodicAccruals.tillDate.getDate(); periodicAccruals.tillDate = this.dateUtils.getDate(periodicAccruals.tillDate);
let month = periodicAccruals.tillDate.getMonth() + 1;
const year = periodicAccruals.tillDate.getFullYear();
if (day < 10) {
day = `0${day}`;
}
if (month < 10) {
month = `0${month}`;
}
periodicAccruals.tillDate = `${year}-${month}-${day}`;
} }
this.accountingService.executePeriodicAccruals(periodicAccruals).subscribe(() => { this.accountingService.executePeriodicAccruals(periodicAccruals).subscribe(() => {
this.router.navigate(['../'], { relativeTo: this.route }); this.router.navigate(['../'], { relativeTo: this.route });
@@ -6,6 +6,7 @@ import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */ /** Custom Services */
import { AccountingService } from '../../accounting.service'; import { AccountingService } from '../../accounting.service';
import { SettingsService } from 'app/settings/settings.service'; import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
/** /**
* Create provisioning entry component. * Create provisioning entry component.
*/ */
@@ -33,6 +34,7 @@ export class CreateProvisioningEntryComponent implements OnInit {
constructor(private formBuilder: FormBuilder, constructor(private formBuilder: FormBuilder,
private accountingService: AccountingService, private accountingService: AccountingService,
private settingsService: SettingsService, private settingsService: SettingsService,
private dateUtils: Dates,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { } private router: Router) { }
@@ -63,16 +65,7 @@ export class CreateProvisioningEntryComponent implements OnInit {
provisioningEntry.locale = this.settingsService.language.code; provisioningEntry.locale = this.settingsService.language.code;
provisioningEntry.dateFormat = this.settingsService.dateFormat; provisioningEntry.dateFormat = this.settingsService.dateFormat;
if (provisioningEntry.date instanceof Date) { if (provisioningEntry.date instanceof Date) {
let day = provisioningEntry.date.getDate(); provisioningEntry.date = this.dateUtils.getDate(provisioningEntry.date);
let month = provisioningEntry.date.getMonth() + 1;
const year = provisioningEntry.date.getFullYear();
if (day < 10) {
day = `0${day}`;
}
if (month < 10) {
month = `0${month}`;
}
provisioningEntry.date = `${year}-${month}-${day}`;
} }
this.accountingService.createProvisioningEntry(provisioningEntry) this.accountingService.createProvisioningEntry(provisioningEntry)
.subscribe((response: any) => { .subscribe((response: any) => {
@@ -14,6 +14,7 @@ import { AccountingService } from '../accounting.service';
import { SettingsService } from 'app/settings/settings.service'; import { SettingsService } from 'app/settings/settings.service';
/** Custom Data Source */ /** Custom Data Source */
import { JournalEntriesDataSource } from './journal-entry.datasource'; import { JournalEntriesDataSource } from './journal-entry.datasource';
import { Dates } from 'app/core/utils/dates';
/** /**
* Search journal entry component. * Search journal entry component.
@@ -88,11 +89,11 @@ export class SearchJournalEntryComponent implements OnInit, AfterViewInit {
}, },
{ {
type: 'fromDate', type: 'fromDate',
value: this.getDate(new Date(new Date().setMonth(new Date().getMonth() - 1))) value: this.dateUtils.getDate(new Date(new Date().setMonth(new Date().getMonth() - 1)))
}, },
{ {
type: 'toDate', type: 'toDate',
value: this.getDate(new Date()) value: this.dateUtils.getDate(new Date())
}, },
{ {
type: 'dateFormat', type: 'dateFormat',
@@ -117,6 +118,7 @@ export class SearchJournalEntryComponent implements OnInit, AfterViewInit {
*/ */
constructor(private accountingService: AccountingService, constructor(private accountingService: AccountingService,
private settingsService: SettingsService, private settingsService: SettingsService,
private dateUtils: Dates,
private route: ActivatedRoute) { private route: ActivatedRoute) {
this.route.data.subscribe((data: { this.route.data.subscribe((data: {
offices: any, offices: any,
@@ -179,7 +181,7 @@ export class SearchJournalEntryComponent implements OnInit, AfterViewInit {
debounceTime(500), debounceTime(500),
distinctUntilChanged(), distinctUntilChanged(),
tap((filterValue) => { tap((filterValue) => {
this.applyFilter(this.getDate(filterValue), 'fromDate'); this.applyFilter(this.dateUtils.getDate(filterValue), 'fromDate');
}) })
) )
.subscribe(); .subscribe();
@@ -189,7 +191,7 @@ export class SearchJournalEntryComponent implements OnInit, AfterViewInit {
debounceTime(500), debounceTime(500),
distinctUntilChanged(), distinctUntilChanged(),
tap((filterValue) => { tap((filterValue) => {
this.applyFilter(this.getDate(filterValue), 'toDate'); this.applyFilter(this.dateUtils.getDate(filterValue), 'toDate');
}) })
) )
.subscribe(); .subscribe();
@@ -292,25 +294,4 @@ export class SearchJournalEntryComponent implements OnInit, AfterViewInit {
this.dataSource = new JournalEntriesDataSource(this.accountingService); this.dataSource = new JournalEntriesDataSource(this.accountingService);
this.dataSource.getJournalEntries(this.filterJournalEntriesBy, this.sort.active, this.sort.direction, this.paginator.pageIndex, this.paginator.pageSize); this.dataSource.getJournalEntries(this.filterJournalEntriesBy, this.sort.active, this.sort.direction, this.paginator.pageIndex, this.paginator.pageSize);
} }
/**
* Gets the date from the passed timestamp.
*
* TODO: Update once language and date settings are setup.
*
* @param {any} timestamp Timestam from which date is to be extracted.
*/
private getDate(timestamp: any) {
let day = timestamp.getDate();
let month = timestamp.getMonth() + 1;
const year = timestamp.getFullYear();
if (day < 10) {
day = `0${day}`;
}
if (month < 10) {
month = `0${month}`;
}
return `${year}-${month}-${day}`;
}
} }
+23
View File
@@ -0,0 +1,23 @@
import { DatePipe } from '@angular/common';
import { Injectable } from '@angular/core';
import { SettingsService } from 'app/settings/settings.service';
@Injectable({
providedIn: 'root'
})
export class Dates {
constructor(private settingsService: SettingsService,
private datePipe: DatePipe) {}
public getDate(timestamp: any) {
const dateFormat = this.settingsService.dateFormat;
return this.datePipe.transform(timestamp, dateFormat);
}
public formatDate(timestamp: any, dateFormat: string) {
return this.datePipe.transform(timestamp, dateFormat);
}
}