Format date fields without patch form

This commit is contained in:
Jose Alberto Hernandez
2022-06-10 10:34:19 +02:00
committed by Arnold Gálovics
parent 9d43181cea
commit 6ea3d97538
191 changed files with 1408 additions and 1173 deletions
@@ -2,7 +2,7 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { DatePipe } from '@angular/common';
import { Dates } from 'app/core/utils/dates';
/** Custom Services. */
import { OrganizationService } from 'app/organization/organization.service';
@@ -31,14 +31,14 @@ export class AllocateCashComponent implements OnInit {
* Get cashier data from `Resolver`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {ActivatedRoute} route ActivateRoute.
* @param {DatePipe} datePipe Date Pipe.
* @param {Dates} dateUtils Date Utils.
* @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 dateUtils: Dates,
private organizationService: OrganizationService,
private settingsService: SettingsService,
private router: Router) {
@@ -59,7 +59,7 @@ export class AllocateCashComponent implements OnInit {
'office': [{value: this.cashierData.officeName, disabled: true}],
'tellerName': [{value: this.cashierData.tellerName, disabled: true}],
'cashier': [{value: this.cashierData.cashierName, disabled: true}],
'assignmentPeriod': [{value: this.datePipe.transform(this.cashierData.startDate, 'dd MMMM yyyy') + ' - ' + this.datePipe.transform(this.cashierData.endDate, 'dd MMMM yyyy'), disabled: true}],
'assignmentPeriod': [{value: this.dateUtils.formatDate(this.cashierData.startDate, 'dd MMMM yyyy') + ' - ' + this.dateUtils.formatDate(this.cashierData.endDate, 'dd MMMM yyyy'), disabled: true}],
'txnDate': [new Date(), Validators.required],
'currencyCode': ['', Validators.required],
'txnAmount': ['', Validators.required],
@@ -71,15 +71,19 @@ export class AllocateCashComponent implements OnInit {
* Submits Allocate Cash form.
*/
submit() {
const allocateCashFormData = this.allocateCashForm.value;
const locale = this.settingsService.language.code;
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 = this.settingsService.language.code;
this.organizationService.allocateCash(this.cashierData.tellerId, this.cashierData.cashierId, allocateCashForm).subscribe((response: any) => {
if (allocateCashFormData.closureDate instanceof Date) {
allocateCashFormData.txnDate = this.dateUtils.formatDate(txnDate, dateFormat);
}
const data = {
...allocateCashFormData,
dateFormat,
locale
};
this.organizationService.allocateCash(this.cashierData.tellerId, this.cashierData.cashierId, data).subscribe((response: any) => {
this.router.navigate(['../'], {relativeTo: this.route});
});
}
@@ -55,7 +55,7 @@
</mat-error>
</mat-form-field>
<div fxFlex="48%" style="padding-top: 10px;">
<div fxFlex="48%" class="space">
<mat-checkbox labelPosition="before" formControlName="isFullDay">
Full Day?
</mat-checkbox>
@@ -0,0 +1,3 @@
.space {
padding-top: 10px;
}
@@ -2,7 +2,7 @@
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { DatePipe } from '@angular/common';
import { Dates } from 'app/core/utils/dates';
/** Custom Services. */
import { OrganizationService } from 'app/organization/organization.service';
@@ -32,14 +32,14 @@ export class CreateCashierComponent implements OnInit {
* @param {FormBuilder} formBuilder Form Builder.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router.
* @param {DatePipe} datePipe Date Pipe.
* @param {Dates} dateUtils Date Utils.
* @param {OrganizationService} organizationService Organization Service.
* @param {SettingsService} settingsService Settings Service.
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe,
private dateUtils: Dates,
private organizationService: OrganizationService,
private settingsService: SettingsService ) {
this.route.data.subscribe((data: { cashierTemplate: any }) => {
@@ -68,17 +68,23 @@ export class CreateCashierComponent implements OnInit {
* Submits Create cashier form.
*/
submit() {
const createCashierFormData = this.createCashierForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const startDate = this.createCashierForm.value.startDate;
const endDate = this.createCashierForm.value.endDate;
this.createCashierForm.patchValue({
'startDate': this.datePipe.transform(startDate, dateFormat),
'endDate': this.datePipe.transform(endDate, dateFormat)
});
const createCashierForm = this.createCashierForm.value;
createCashierForm.locale = this.settingsService.language.code;
createCashierForm.dateFormat = dateFormat;
this.organizationService.createCashier(this.cashierTemplate.tellerId, createCashierForm).subscribe((response: any) => {
const prevStartDate: Date = this.createCashierForm.value.startDate;
const prevEndDate: Date = this.createCashierForm.value.endDate;
if (createCashierFormData.startDate instanceof Date) {
createCashierFormData.startDate = this.dateUtils.formatDate(prevStartDate, dateFormat);
}
if (createCashierFormData.endDate instanceof Date) {
createCashierFormData.endDate = this.dateUtils.formatDate(prevEndDate, dateFormat);
}
const data = {
...createCashierFormData,
dateFormat,
locale
};
this.organizationService.createCashier(this.cashierTemplate.tellerId, data).subscribe((response: any) => {
this.router.navigate(['../'], {relativeTo: this.route});
});
}
@@ -61,7 +61,7 @@
</mat-error>
</mat-form-field>
<div fxFlex="48%" style="padding-top: 10px;">
<div fxFlex="48%" class="space">
<mat-checkbox labelPosition="before" formControlName="isFullDay">
Full Day?
</mat-checkbox>
@@ -0,0 +1,3 @@
.space {
padding-top: 10px;
}
@@ -2,7 +2,7 @@
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { DatePipe } from '@angular/common';
import { Dates } from 'app/core/utils/dates';
/** Custom Services. */
import { OrganizationService } from 'app/organization/organization.service';
@@ -34,14 +34,14 @@ export class EditCashierComponent implements OnInit {
* @param {FormBuilder} formBuilder Form Builder.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router.
* @param {DatePipe} datePipe Date Pipe.
* @param {Dates} dateUtils Date Utils.
* @param {OrganizationService} organizationService Organization Service.
* @param {SettingsService} settingsService Settings Service.
*/
constructor(private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe,
private dateUtils: Dates,
private organizationService: OrganizationService,
private settingsService: SettingsService ) {
this.route.data.subscribe((data: { cashier: any, cashierTemplate: any }) => {
@@ -72,18 +72,24 @@ export class EditCashierComponent implements OnInit {
* Submits edit cashier form.
*/
submit() {
const editCashierFormData = this.editCashierForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
const startDate = this.editCashierForm.value.startDate;
const endDate = this.editCashierForm.value.endDate;
this.editCashierForm.patchValue({
'startDate': this.datePipe.transform(startDate, dateFormat),
'endDate': this.datePipe.transform(endDate, dateFormat)
});
const editCashierForm = this.editCashierForm.value;
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) => {
const prevStartDate: Date = this.editCashierForm.value.startDate;
const prevEndDate: Date = this.editCashierForm.value.endDate;
if (editCashierFormData.startDate instanceof Date) {
editCashierFormData.startDate = this.dateUtils.formatDate(prevStartDate, dateFormat);
}
if (editCashierFormData.endDate instanceof Date) {
editCashierFormData.endDate = this.dateUtils.formatDate(prevEndDate, dateFormat);
}
const data = {
...editCashierFormData,
staffId: this.cashierData.data.staffId,
dateFormat,
locale
};
this.organizationService.updateCashier(this.cashierData.data.tellerId, this.cashierData.data.id, data).subscribe((response: any) => {
this.router.navigate(['../'], {relativeTo: this.route});
});
}
@@ -2,7 +2,7 @@
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { DatePipe } from '@angular/common';
import { Dates } from 'app/core/utils/dates';
/** Customer Services. */
import { OrganizationService } from 'app/organization/organization.service';
@@ -28,14 +28,14 @@ export class SettleCashComponent implements OnInit {
* Get cashier data from `Resolver`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {ActivatedRoute} route ActivateRoute.
* @param {DatePipe} datePipe Date Pipe.
* @param {Dates} dateUtils Date Utils.
* @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 dateUtils: Dates,
private organizationService: OrganizationService,
private settingsService: SettingsService,
private router: Router) {
@@ -56,7 +56,7 @@ export class SettleCashComponent implements OnInit {
'office': [{value: this.cashierData.officeName, disabled: true}],
'tellerName': [{value: this.cashierData.tellerName, disabled: true}],
'cashier': [{value: this.cashierData.cashierName, disabled: true}],
'assignmentPeriod': [{value: this.datePipe.transform(this.cashierData.startDate, 'dd MMMM yyyy') + ' - ' + this.datePipe.transform(this.cashierData.endDate, 'dd MMMM yyyy'), disabled: true}],
'assignmentPeriod': [{value: this.dateUtils.formatDate(this.cashierData.startDate, 'dd MMMM yyyy') + ' - ' + this.dateUtils.formatDate(this.cashierData.endDate, 'dd MMMM yyyy'), disabled: true}],
'txnDate': [new Date(), Validators.required],
'currencyCode': ['', Validators.required],
'txnAmount': ['', Validators.required],
@@ -68,15 +68,19 @@ export class SettleCashComponent implements OnInit {
* Submits Settle Cash form.
*/
submit() {
const settleCashFormData = this.settleCashForm.value;
const locale = this.settingsService.language.code;
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 = this.settingsService.language.code;
this.organizationService.settleCash(this.cashierData.tellerId, this.cashierData.cashierId, settleCashForm).subscribe((response: any) => {
const prevTxnDate: Date = this.settleCashForm.value.txnDate;
if (settleCashFormData.txnDate instanceof Date) {
settleCashFormData.txnDate = this.dateUtils.formatDate(prevTxnDate, dateFormat);
}
const data = {
...settleCashFormData,
dateFormat,
locale
};
this.organizationService.settleCash(this.cashierData.tellerId, this.cashierData.cashierId, data).subscribe((response: any) => {
this.router.navigate(['../'], {relativeTo: this.route});
});
}
@@ -2,11 +2,11 @@
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import { DatePipe } from '@angular/common';
/** Custom Services */
import { OrganizationService } from '../../organization.service';
import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
/**
* Create teller component.
@@ -36,14 +36,14 @@ export class CreateTellerComponent implements OnInit {
* @param {SettingsService} settingsService Settings Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {DatePipe} datePipe Date Pipe to format date.
* @param {Dates} dateUtils Date Utils to format date.
*/
constructor(private formBuilder: FormBuilder,
private organizationService: OrganizationService,
private settingsService: SettingsService,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe) {
private dateUtils: Dates) {
this.route.data.subscribe((data: { offices: any }) => {
this.officeData = data.offices;
});
@@ -77,18 +77,23 @@ export class CreateTellerComponent implements OnInit {
* if successful redirects to tellers.
*/
submit() {
const tellerFormData = this.tellerForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
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 = 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 = this.settingsService.language.code;
teller.dateFormat = dateFormat;
this.organizationService.createTeller(teller).subscribe((response: any) => {
if (tellerFormData.startDate instanceof Date) {
tellerFormData.startDate = this.dateUtils.formatDate(prevStartDate, dateFormat);
}
if (tellerFormData.endDate instanceof Date) {
tellerFormData.endDate = this.dateUtils.formatDate(prevEndDate, dateFormat);
}
const data = {
...tellerFormData,
dateFormat,
locale
};
this.organizationService.createTeller(data).subscribe((response: any) => {
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
});
}
@@ -2,11 +2,11 @@
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import { DatePipe } from '@angular/common';
/** Custom Services */
import { OrganizationService } from '../../organization.service';
import { SettingsService } from 'app/settings/settings.service';
import { Dates } from 'app/core/utils/dates';
/**
* Create teller component.
@@ -39,14 +39,14 @@ export class EditTellerComponent implements OnInit {
* @param {SettingsService} settingsService Settings Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {DatePipe} datePipe Date Pipe to format date.
* @param {Dates} dateUtils Date Utils to format date.
*/
constructor(private formBuilder: FormBuilder,
private organizationService: OrganizationService,
private settingsService: SettingsService,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe) {
private dateUtils: Dates) {
this.route.data.subscribe((data: { teller: any, offices: any }) => {
this.tellerData = data.teller;
this.officeData = data.offices;
@@ -89,19 +89,24 @@ export class EditTellerComponent implements OnInit {
* if successful redirects to tellers.
*/
submit() {
const tellerFormData = this.tellerForm.value;
const locale = this.settingsService.language.code;
const dateFormat = this.settingsService.dateFormat;
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 = 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 = this.settingsService.language.code;
teller.officeId = this.tellerData.officeId;
teller.dateFormat = dateFormat;
this.organizationService.updateTeller(this.tellerData.id, teller).subscribe((response: any) => {
if (tellerFormData.startDate instanceof Date) {
tellerFormData.startDate = this.dateUtils.formatDate(prevStartDate, dateFormat);
}
if (tellerFormData.endDate instanceof Date) {
tellerFormData.endDate = this.dateUtils.formatDate(prevEndDate, dateFormat);
}
const data = {
...tellerFormData,
officeId: this.tellerData.officeId,
dateFormat,
locale
};
this.organizationService.updateTeller(this.tellerData.id, data).subscribe((response: any) => {
this.router.navigate(['../../', response.resourceId], { relativeTo: this.route });
});
}