refactor (df/locale): organization module (#1268)

See: #1213
This commit is contained in:
Benura Abeywardena
2020-11-12 19:36:37 +05:30
committed by GitHub
parent dbd34aaf42
commit 5f90bc00bd
26 changed files with 139 additions and 62 deletions
@@ -6,6 +6,7 @@ import { DatePipe } from '@angular/common';
/** Custom Services. */
import { OrganizationService } from 'app/organization/organization.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Allocate Cash component.
@@ -32,12 +33,14 @@ export class AllocateCashComponent implements OnInit {
* @param {ActivatedRoute} route ActivateRoute.
* @param {DatePipe} datePipe Date Pipe.
* @param {OrganizationService} organizationService Organization Service.
* @param {SettingsService} settingsService Settings Service.
* @param {Router} router Router.
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private datePipe: DatePipe,
private organizationService: OrganizationService,
private settingsService: SettingsService,
private router: Router) {
this.route.data.subscribe((data: { cashierTemplate: any}) => {
this.cashierData = data.cashierTemplate;
@@ -68,14 +71,14 @@ export class AllocateCashComponent implements OnInit {
* Submits Allocate Cash form.
*/
submit() {
const dateFormat = 'dd MMMM yyyy';
const dateFormat = this.settingsService.dateFormat;
const txnDate = this.allocateCashForm.value.txnDate;
this.allocateCashForm.patchValue({
txnDate: this.datePipe.transform(txnDate, dateFormat)
});
const allocateCashForm = this.allocateCashForm.value;
allocateCashForm.dateFormat = dateFormat;
allocateCashForm.locale = 'en';
allocateCashForm.locale = this.settingsService.language.code;
this.organizationService.allocateCash(this.cashierData.tellerId, this.cashierData.cashierId, allocateCashForm).subscribe((response: any) => {
this.router.navigate(['../'], {relativeTo: this.route});
});
@@ -6,6 +6,7 @@ import { DatePipe } from '@angular/common';
/** Custom Services. */
import { OrganizationService } from 'app/organization/organization.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Create Cashier component.
@@ -33,12 +34,14 @@ export class CreateCashierComponent implements OnInit {
* @param {Router} router Router.
* @param {DatePipe} datePipe Date Pipe.
* @param {OrganizationService} organizationService Organization Service.
* @param {SettingsService} settingsService Settings Service.
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe,
private organizationService: OrganizationService ) {
private organizationService: OrganizationService,
private settingsService: SettingsService ) {
this.route.data.subscribe((data: { cashierTemplate: any }) => {
this.cashierTemplate = data.cashierTemplate;
});
@@ -65,7 +68,7 @@ export class CreateCashierComponent implements OnInit {
* Submits Create cashier form.
*/
submit() {
const dateFormat = 'dd MMMM yyyy';
const dateFormat = this.settingsService.dateFormat;
const startDate = this.createCashierForm.value.startDate;
const endDate = this.createCashierForm.value.endDate;
this.createCashierForm.patchValue({
@@ -73,7 +76,7 @@ export class CreateCashierComponent implements OnInit {
'endDate': this.datePipe.transform(endDate, dateFormat)
});
const createCashierForm = this.createCashierForm.value;
createCashierForm.locale = 'en';
createCashierForm.locale = this.settingsService.language.code;
createCashierForm.dateFormat = dateFormat;
this.organizationService.createCashier(this.cashierTemplate.tellerId, createCashierForm).subscribe((response: any) => {
this.router.navigate(['../'], {relativeTo: this.route});
@@ -6,6 +6,7 @@ import { DatePipe } from '@angular/common';
/** Custom Services. */
import { OrganizationService } from 'app/organization/organization.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Edit Cashier component.
@@ -35,12 +36,14 @@ export class EditCashierComponent implements OnInit {
* @param {Router} router Router.
* @param {DatePipe} datePipe Date Pipe.
* @param {OrganizationService} organizationService Organization Service.
* @param {SettingsService} settingsService Settings Service.
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe,
private organizationService: OrganizationService ) {
private organizationService: OrganizationService,
private settingsService: SettingsService ) {
this.route.data.subscribe((data: { cashier: any, cashierTemplate: any }) => {
this.cashierData.data = data.cashier;
this.cashierData.template = data.cashierTemplate;
@@ -69,7 +72,7 @@ export class EditCashierComponent implements OnInit {
* Submits edit cashier form.
*/
submit() {
const dateFormat = 'yyyy-MM-dd';
const dateFormat = this.settingsService.dateFormat;
const startDate = this.editCashierForm.value.startDate;
const endDate = this.editCashierForm.value.endDate;
this.editCashierForm.patchValue({
@@ -77,7 +80,7 @@ export class EditCashierComponent implements OnInit {
'endDate': this.datePipe.transform(endDate, dateFormat)
});
const editCashierForm = this.editCashierForm.value;
editCashierForm.locale = 'en';
editCashierForm.locale = this.settingsService.language.code;
editCashierForm.dateFormat = dateFormat;
editCashierForm.staffId = this.cashierData.data.staffId;
this.organizationService.updateCashier(this.cashierData.data.tellerId, this.cashierData.data.id, editCashierForm).subscribe((response: any) => {
@@ -1,8 +1,12 @@
/** 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';
/** Customer Services. */
import { OrganizationService } from 'app/organization/organization.service';
import { SettingsService } from 'app/settings/settings.service';
@Component({
selector: 'mifosx-settle-cash',
@@ -26,12 +30,14 @@ export class SettleCashComponent implements OnInit {
* @param {ActivatedRoute} route ActivateRoute.
* @param {DatePipe} datePipe Date Pipe.
* @param {OrganizationService} organizationService Organization Service.
* @param {SettingsService} settingsService Settings Service.
* @param {Router} router Router.
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private datePipe: DatePipe,
private organizationService: OrganizationService,
private settingsService: SettingsService,
private router: Router) {
this.route.data.subscribe((data: { cashierTemplate: any}) => {
this.cashierData = data.cashierTemplate;
@@ -62,14 +68,14 @@ export class SettleCashComponent implements OnInit {
* Submits Settle Cash form.
*/
submit() {
const dateFormat = 'dd MMMM yyyy';
const dateFormat = this.settingsService.dateFormat;
const txnDate = this.settleCashForm.value.txnDate;
this.settleCashForm.patchValue({
txnDate: this.datePipe.transform(txnDate, dateFormat)
});
const settleCashForm = this.settleCashForm.value;
settleCashForm.dateFormat = dateFormat;
settleCashForm.locale = 'en';
settleCashForm.locale = this.settingsService.language.code;
this.organizationService.settleCash(this.cashierData.tellerId, this.cashierData.cashierId, settleCashForm).subscribe((response: any) => {
this.router.navigate(['../'], {relativeTo: this.route});
});
@@ -6,6 +6,7 @@ import { DatePipe } from '@angular/common';
/** Custom Services */
import { OrganizationService } from '../../organization.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Create teller component.
@@ -32,12 +33,14 @@ export class CreateTellerComponent implements OnInit {
* Retrieves the offices data from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {OrganizationService} organizationService Organization Service.
* @param {SettingsService} settingsService Settings Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {DatePipe} datePipe Date Pipe to format date.
*/
constructor(private formBuilder: FormBuilder,
private organizationService: OrganizationService,
private settingsService: SettingsService,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe) {
@@ -77,13 +80,13 @@ export class CreateTellerComponent implements OnInit {
const prevStartDate: Date = this.tellerForm.value.startDate;
const prevEndDate: Date = this.tellerForm.value.endDate;
// TODO: Update once language and date settings are setup
const dateFormat = 'yyyy-MM-dd';
const dateFormat = this.settingsService.dateFormat;
this.tellerForm.patchValue({
startDate: this.datePipe.transform(prevStartDate, dateFormat),
endDate: this.datePipe.transform(prevEndDate, dateFormat)
});
const teller = this.tellerForm.value;
teller.locale = 'en';
teller.locale = this.settingsService.language.code;
teller.dateFormat = dateFormat;
this.organizationService.createTeller(teller).subscribe((response: any) => {
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
@@ -6,6 +6,7 @@ import { DatePipe } from '@angular/common';
/** Custom Services */
import { OrganizationService } from '../../organization.service';
import { SettingsService } from 'app/settings/settings.service';
/**
* Create teller component.
@@ -35,12 +36,14 @@ export class EditTellerComponent implements OnInit {
* Retrieves the offices data from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {OrganizationService} organizationService Organization Service.
* @param {SettingsService} settingsService Settings Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {DatePipe} datePipe Date Pipe to format date.
*/
constructor(private formBuilder: FormBuilder,
private organizationService: OrganizationService,
private settingsService: SettingsService,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe) {
@@ -89,13 +92,13 @@ export class EditTellerComponent implements OnInit {
const prevStartDate: Date = this.tellerForm.value.startDate;
const prevEndDate: Date = this.tellerForm.value.endDate;
// TODO: Update once language and date settings are setup
const dateFormat = 'yyyy-MM-dd';
const dateFormat = this.settingsService.dateFormat;
this.tellerForm.patchValue({
startDate: this.datePipe.transform(prevStartDate, dateFormat),
endDate: this.datePipe.transform(prevEndDate, dateFormat)
});
const teller = this.tellerForm.value;
teller.locale = 'en';
teller.locale = this.settingsService.language.code;
teller.officeId = this.tellerData.officeId;
teller.dateFormat = dateFormat;
this.organizationService.updateTeller(this.tellerData.id, teller).subscribe((response: any) => {