param and home updates

This commit is contained in:
Cyril Joseph 2025-08-04 21:39:43 -03:00
parent a808c677bd
commit ca9397894e
9 changed files with 227 additions and 161 deletions

View File

@ -14,7 +14,7 @@
</mat-menu>
<button mat-button [matMenuTriggerFor]="configurations">Configurations</button>
<mat-menu #configurations="matMenu">
<button mat-menu-item (click)="navigateTo('table-record')">Configurations</button>
<button mat-menu-item (click)="navigateTo('table-record')">Table Records</button>
<button mat-menu-item (click)="navigateTo('country-messages')">Country Messages</button>
</mat-menu>

View File

@ -0,0 +1,6 @@
import { ParamProperties } from "./parameters";
export interface CountryMessage extends ParamProperties {
countryMessage: string | null;
isInactive: boolean;
}

View File

@ -5,18 +5,18 @@ export interface ParamProperties {
paramType: string;
paramDesc: string;
paramValue: string;
addlParamValue1: string | null;
addlParamValue2: string | null;
addlParamValue3: string | null;
addlParamValue4: string | null;
addlParamValue5: string | null;
addlParamValue1?: string | null;
addlParamValue2?: string | null;
addlParamValue3?: string | null;
addlParamValue4?: string | null;
addlParamValue5?: string | null;
sortSeq?: number;
inactiveCodeFlag: 'Y' | 'N' | null;
inactiveDate: string | null;
createdBy: string;
dateCreated: string;
lastUpdatedBy: string | null;
lastUpdatedDate: string | null;
errorMesg: string | null;
inactiveCodeFlag?: 'Y' | 'N' | null;
inactiveDate?: string | null;
createdBy?: string;
dateCreated?: string;
lastUpdatedBy?: string | null;
lastUpdatedDate?: string | null;
errorMesg?: string | null;
userId?: string;
}

View File

@ -38,15 +38,31 @@ export class HomeService {
expiryDate: item.EXPDATE || null,
orderType: item.ORDERTYPE,
carnetStatus: item.CARNETSTATUS,
HEADERID: item.HEADERID
headerid: item.HEADERID
}));
}
deleteCarnet(headerid: number): Observable<any> {
return this.http.patch(`${this.apiUrl}/${this.apiDb}/ReactivateClientContacts/${this.userService.getUserSpid()}/${headerid}/${this.userService.getUser()}`, null);
const data = {
P_USERID: this.userService.getUser(),
P_HEADERID: headerid
}
return this.http.delete(`${this.apiUrl}/${this.apiDb}/DeleteCarnet`, { body: data });
}
resetCarnet(headerid: number): Observable<any> {
return this.http.patch(`${this.apiUrl}/${this.apiDb}/ReactivateClientContacts/${this.userService.getUserSpid()}/${headerid}/${this.userService.getUser()}`, null);
const data = {
P_USERID: this.userService.getUser(),
P_HEADERID: headerid
}
return this.http.patch(`${this.apiUrl}/${this.apiDb}/ResetCarnet`, data);
}
printCarnet(headerid: number): Observable<any> {
const data = {
P_USERID: this.userService.getUser(),
P_HEADERID: headerid
}
return this.http.patch(`${this.apiUrl}/${this.apiDb}/UpdatePrintCarnet`, data);
}
}

View File

@ -99,19 +99,19 @@
matTooltip="View">
<mat-icon>article</mat-icon>
</button>
<button mat-icon-button color="primary" (click)="resetClient(item)"
<button mat-icon-button color="primary" (click)="resetClient(item.headerid)"
*ngIf="getCarnetStatusLabel(item.carnetStatus) === 'Submitted'"
[hidden]="getCarnetStatusLabel(item.carnetStatus) !== 'Submitted'"
matTooltip="Reset to Client">
<mat-icon>assignment_return</mat-icon>
</button>
<button mat-icon-button color="primary" (click)="deleteCarnet(item.HEADERID)"
<button mat-icon-button color="primary" (click)="deleteCarnet(item.headerid)"
*ngIf="getCarnetStatusLabel(item.carnetStatus) === 'Submitted'"
[hidden]="getCarnetStatusLabel(item.carnetStatus) !== 'Submitted'"
matTooltip="Delete">
<mat-icon>delete</mat-icon>
</button>
<button mat-icon-button color="primary" (click)="printCarnet(item)"
<button mat-icon-button color="primary" (click)="printCarnet(item.headerid)"
*ngIf="getCarnetStatusLabel(item.carnetStatus) === 'Submitted'"
[hidden]="getCarnetStatusLabel(item.carnetStatus) !== 'Submitted'"
matTooltip="Print">

View File

@ -165,8 +165,8 @@ export class HomeComponent {
}
processCarnet(item: any): void {
if (item && item.HEADERID) {
this.navigateTo(['edit-carnet', item.HEADERID], {
if (item && item.headerid) {
this.navigateTo(['edit-carnet', item.headerid], {
queryParams: { applicationname: item.applicationName }
});
} else {
@ -175,8 +175,8 @@ export class HomeComponent {
}
viewCarnet(item: any): void {
if (item && item.HEADERID) {
this.navigateTo(['view-carnet', item.HEADERID], {
if (item && item.headerid) {
this.navigateTo(['view-carnet', item.headerid], {
queryParams: { applicationname: item.applicationName }
});
} else {
@ -184,8 +184,18 @@ export class HomeComponent {
}
}
printCarnet(item: any): void {
if (item && item.HEADERID) {
printCarnet(headerId: number): void {
if (headerId) {
this.homeService.printCarnet(headerId).subscribe({
next: () => {
this.notificationService.showSuccess('Carnet printed successfully');
},
error: (error) => {
let errorMessage = this.errorHandler.handleApiError(error, 'Failed to print carnet');
this.notificationService.showError(errorMessage);
console.error('Error printing carnet:', error);
}
});
} else {
this.notificationService.showError('Invalid carnet data');
}

View File

@ -7,7 +7,7 @@
<div class="form-row">
<mat-form-field appearance="outline">
<mat-label>Country</mat-label>
<mat-select [(value)]="currentCountryId" (selectionChange)="onCountrySelectionChanged($event)">
<mat-select (selectionChange)="onCountrySelectionChanged($event)">
<mat-option *ngFor="let country of countries" [value]="country.paramId">
{{ country.paramDesc }}
</mat-option>
@ -17,76 +17,33 @@
<div class="form-row">
<mat-form-field appearance="outline">
<mat-label>Param Type</mat-label>
<input matInput formControlName="paramType" readonly required>
<mat-error *ngIf="countryForm.get('paramType')?.errors?.['required']">
Param Type is required
</mat-error>
<mat-error *ngIf="countryForm.get('paramType')?.errors?.['maxlength']">
Maximum 10 characters allowed
</mat-error>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Description</mat-label>
<input matInput formControlName="paramDesc" required>
<mat-error *ngIf="countryForm.get('paramDesc')?.errors?.['required']">
Param Description is required
</mat-error>
<mat-error *ngIf="countryForm.get('paramDesc')?.errors?.['maxlength']">
Maximum 100 characters allowed
</mat-error>
</mat-form-field>
</div>
<div class="form-row">
<mat-form-field appearance="outline">
<mat-label>Additional Value 1</mat-label>
<input matInput formControlName="addlParamValue1">
<mat-error *ngIf="countryForm.get('addlParamValue1')?.errors?.['maxlength']">
Maximum 20 characters allowed
<mat-label>Message</mat-label>
<textarea matInput formControlName="countryMessage" placeholder="Enter a message" rows="10"
required></textarea>
<mat-error *ngIf="countryForm.get('countryMessage')?.errors?.['required']">
Message is required
</mat-error>
</mat-form-field>
</div>
<div class="form-row">
<mat-form-field appearance="outline">
<mat-label>Additional Value 2</mat-label>
<input matInput formControlName="addlParamValue2">
<mat-error *ngIf="countryForm.get('addlParamValue2')?.errors?.['maxlength']">
Maximum 20 characters allowed
</mat-error>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Additional Value 3</mat-label>
<input matInput formControlName="addlParamValue3">
<mat-error *ngIf="countryForm.get('addlParamValue3')?.errors?.['maxlength']">
Maximum 20 characters allowed
</mat-error>
</mat-form-field>
<div class="readonly-section top-divider">
<div class="readonly-fields">
<div class="field-column">
<div class="readonly-field">
<label>Action Type</label>
<div class="readonly-value">
{{paramReadOnlyFields.actionType || 'N/A'}}
</div>
</div>
</div>
<div class="field-column">
<div class="readonly-field">
<label>Action </label>
<div class="readonly-value">
{{paramReadOnlyFields.action || 'N/A'}}
</div>
</div>
</div>
</div>
<div class="form-row">
<mat-form-field appearance="outline">
<mat-label>Additional Value 4</mat-label>
<input matInput formControlName="addlParamValue4">
<mat-error *ngIf="countryForm.get('addlParamValue4')?.errors?.['maxlength']">
Maximum 20 characters allowed
</mat-error>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Additional Value 5</mat-label>
<input matInput formControlName="addlParamValue5">
<mat-error *ngIf="countryForm.get('addlParamValue5')?.errors?.['maxlength']">
Maximum 20 characters allowed
</mat-error>
</mat-form-field>
</div>
<div class="form-actions">
@ -94,8 +51,12 @@
[disabled]="countryForm.invalid || changeInProgress">
Save
</button>
<button mat-button type="button" (click)="inActivateParamRecord(1)">Inactivate Record</button>
<button mat-button type="button" (click)="reActivateParamRecord(1)">Reactivate Record</button>
<button mat-raised-button color="primary" type="button" *ngIf="!currentCountry?.isInactive"
(click)="inActivateParamRecord()">Inactivate
Record</button>
<button mat-raised-button color="primary" type="button" *ngIf="currentCountry?.isInactive"
(click)="reActivateParamRecord()">Reactivate
Record</button>
</div>
</form>
</div>

View File

@ -12,10 +12,7 @@
}
.form-container {
background-color: white;
padding: 24px;
border-radius: 8px;
margin-top: 16px;
margin-top: 0.5rem;
.form-header {
margin-bottom: 24px;

View File

@ -1,13 +1,16 @@
import { CommonModule } from '@angular/common';
import { Component, inject } from '@angular/core';
import { ReactiveFormsModule, FormGroup, Validators, FormBuilder } from '@angular/forms';
import { finalize } from 'rxjs';
import { finalize, forkJoin } from 'rxjs';
import { ParamProperties } from '../../core/models/param/parameters';
import { ApiErrorHandlerService } from '../../core/services/common/api-error-handler.service';
import { NotificationService } from '../../core/services/common/notification.service';
import { ParamService } from '../../core/services/param/param.service';
import { AngularMaterialModule } from '../../shared/module/angular-material.module';
import { MatSelectChange } from '@angular/material/select';
import { CountryMessage } from '../../core/models/param/country-message';
import { MatDialog } from '@angular/material/dialog';
import { ConfirmDialogComponent } from '../../shared/components/confirm-dialog/confirm-dialog.component';
@Component({
selector: 'app-manage-country',
@ -16,35 +19,33 @@ import { MatSelectChange } from '@angular/material/select';
styleUrl: './manage-country.component.scss'
})
export class ManageCountryComponent {
isLoading: boolean = false;
changeInProgress: boolean = false;
countries: ParamProperties[] = [];
currentCountryId: number | null = null;
currentCountry: ParamProperties | undefined | null = null;
currentParamid: number | null = null;
countries: CountryMessage[] = [];
countriesWithMessages: ParamProperties[] = [];
currentCountryId: number = 0;
currentCountry: CountryMessage | undefined | null = null;
private paramService = inject(ParamService);
private errorHandler = inject(ApiErrorHandlerService);
private notificationService = inject(NotificationService);
private fb = inject(FormBuilder);
private dialog = inject(MatDialog);
countryForm: FormGroup;
paramReadOnlyFields: any = {
actionType: null,
action: null
};
constructor() {
this.countryForm = this.initializeForm();
}
initializeForm(): FormGroup {
return this.fb.group({
paramType: ['', [Validators.required, Validators.maxLength(10)]],
paramValue: ['', [Validators.required, Validators.maxLength(20)]],
paramDesc: ['', [Validators.required, Validators.maxLength(100)]],
addlParamValue1: ['', [Validators.maxLength(20)]],
addlParamValue2: ['', [Validators.maxLength(20)]],
addlParamValue3: ['', [Validators.maxLength(20)]],
addlParamValue4: ['', [Validators.maxLength(20)]],
addlParamValue5: ['', [Validators.maxLength(20)]],
countryMessage: ['', [Validators.required]]
});
}
@ -53,29 +54,31 @@ export class ManageCountryComponent {
}
onCountrySelectionChanged(event: MatSelectChange) {
console.log(event);
this.currentCountry = this.countries.find(c => c.paramId === +event.value);
this.currentCountryId = this.currentCountry?.paramId ?? 0;
this.currentCountryId = this.countriesWithMessages.
find(c => c.paramValue === this.currentCountry?.paramValue)?.paramId ?? 0;
this.patchCountryData();
}
getCountries(): void {
this.isLoading = true;
this.paramService.getParameters('014').pipe(finalize(() => {
forkJoin({
countries: this.paramService.getParameters('002'),
countriesWithMessages: this.paramService.getParameters('014')
}).pipe(finalize(() => {
this.isLoading = false;
})).subscribe({
next: (paramData: ParamProperties[]) => {
this.countries = paramData;
this.currentCountry = this.countries.find(c => c.paramValue === 'US');
this.currentCountryId = this.currentCountry?.paramId ?? 0;
this.patchCountryData();
next: (results) => {
this.countries = this.joinCountriesWithMessages(results.countries, results.countriesWithMessages);
this.countriesWithMessages = results.countriesWithMessages;
},
error: (error: any) => {
let errorMessage = this.errorHandler.handleApiError(error, 'Failed to get countries');
error: (error) => {
console.error('Error loading countries messages data', error);
let errorMessage = this.errorHandler.handleApiError(error, 'Failed to load countries messages data');
this.notificationService.showError(errorMessage);
console.error('Error loading countries :', error);
}
});
}
@ -86,15 +89,11 @@ export class ManageCountryComponent {
}
this.countryForm.patchValue({
paramType: this.currentCountry.paramType,
paramValue: this.currentCountry.paramValue,
paramDesc: this.currentCountry.paramDesc,
addlParamValue1: this.currentCountry.addlParamValue1,
addlParamValue2: this.currentCountry.addlParamValue2,
addlParamValue3: this.currentCountry.addlParamValue3,
addlParamValue4: this.currentCountry.addlParamValue4,
addlParamValue5: this.currentCountry.addlParamValue5
countryMessage: this.currentCountry.countryMessage
});
this.paramReadOnlyFields.actionType = this.currentCountry.addlParamValue1;
this.paramReadOnlyFields.action = this.currentCountry.addlParamValue2;
}
saveRecord(): void {
@ -103,11 +102,17 @@ export class ManageCountryComponent {
return;
}
const paramData: ParamProperties = this.countryForm.value;
paramData.paramId = this.currentParamid ?? 0;
paramData.sortSeq = 1;
const paramData: ParamProperties = {
paramDesc: this.countryForm.value.countryMessage,
paramType: '014',
paramValue: this.currentCountry?.paramValue ?? '',
sortSeq: 1,
paramId: this.currentCountryId ?? 0
};
const saveObservable = this.paramService.updateParamRecord(paramData as ParamProperties);
const saveObservable = this.currentCountryId > 0
? this.paramService.updateParamRecord(paramData)
: this.paramService.createParamRecord(paramData);
this.changeInProgress = true;
saveObservable.pipe(finalize(() => {
@ -115,6 +120,7 @@ export class ManageCountryComponent {
})).subscribe({
next: () => {
this.notificationService.showSuccess(`Country message updated successfully`);
this.getCountries();
},
error: (error) => {
let errorMessage = this.errorHandler.handleApiError(error, `Failed to update country message`);
@ -124,8 +130,25 @@ export class ManageCountryComponent {
});
}
inActivateParamRecord(paramId: number): void {
this.paramService.inActivateParamRecord(paramId).subscribe(
inActivateParamRecord(): void {
if (this.currentCountryId === 0) {
this.notificationService.showError('Not a valid country to inactivate');
return;
}
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '350px',
data: {
title: 'Inactivate Country Message',
message: 'Are you sure you want to inactivate this message?',
confirmText: 'Yes',
cancelText: 'Cancel'
}
});
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.paramService.inActivateParamRecord(this.currentCountryId).subscribe(
{
next: (data: any) => {
this.notificationService.showSuccess(`Country message inactivated successfully`);
@ -138,9 +161,27 @@ export class ManageCountryComponent {
}
);
}
});
}
reActivateParamRecord(paramId: number): void {
this.paramService.reActivateParamRecord(paramId).subscribe(
reActivateParamRecord(): void {
if (this.currentCountryId === 0) {
this.notificationService.showError('Not a valid country to reactivate');
return;
}
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '350px',
data: {
title: 'Reactivate Country Message',
message: 'Are you sure you want to reactivate this message?',
confirmText: 'Yes',
cancelText: 'Cancel'
}
});
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.paramService.reActivateParamRecord(this.currentCountryId).subscribe(
{
next: (data: any) => {
this.notificationService.showSuccess(`Country message reactivated successfully`);
@ -153,4 +194,39 @@ export class ManageCountryComponent {
}
);
}
});
}
joinCountriesWithMessages(countries: ParamProperties[], countryMessages: ParamProperties[]): CountryMessage[] {
// Group messages by paramvalue
const messagesByCountry = countryMessages.reduce((acc, message) => {
if (!acc[message.paramValue]) {
acc[message.paramValue] = {
messages: [],
// paramId: message.paramId, // Store one paramid from messages
isInactive: message.inactiveCodeFlag === 'N'
};
}
acc[message.paramValue].messages.push(message.paramDesc);
return acc;
}, {} as Record<string, {
messages: string[]; //paramId?: number;
isInactive: boolean
}>);
// Join countries with their messages
return countries.map(country => {
const countryMessages = messagesByCountry[country.paramValue] || {
messages: [], //paramId: null,
isInactive: false
};
return {
...country,
countryMessage: countryMessages.messages.join(' '),
isInactive: countryMessages.isInactive,
paramType: '014',
};
});
}
}