|
|
@@ -14,15 +14,15 @@ import { ReactiveFormsModule, FormControl } from '@angular/forms';
|
|
|
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
|
|
|
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
|
|
import { combineLatest, startWith } from 'rxjs';
|
|
|
-import { FFBHarvest } from './ffb-harvest.interface';
|
|
|
+import { FFBProduction } from './ffb-production.interface';
|
|
|
import { webConfig } from '../config';
|
|
|
-import { CreateFfbHarvestDialogComponent } from '../components/ffb-harvest-dialog/create-ffb-harvest-dialog.component';
|
|
|
-import { FfbHarvestCalculateDialogComponent } from '../components/ffb-calculation/ffb-harvest-calculate-dialog.component';
|
|
|
+import { CreateFfbProductionDialogComponent } from '../components/ffb-production-dialog/create-ffb-production-dialog.component';
|
|
|
+import { FfbHarvestCalculateDialogComponent } from '../components/ffb-calculation/ffb-production-calculate-dialog.component';
|
|
|
|
|
|
@Component({
|
|
|
- selector: 'app-ffb-harvest',
|
|
|
- templateUrl: './ffb-harvest.component.html',
|
|
|
- styleUrls: ['./ffb-harvest.component.css'],
|
|
|
+ selector: 'app-ffb-production',
|
|
|
+ templateUrl: './ffb-production.component.html',
|
|
|
+ styleUrls: ['./ffb-production.component.css'],
|
|
|
standalone: true,
|
|
|
imports: [
|
|
|
CommonModule,
|
|
|
@@ -41,7 +41,7 @@ import { FfbHarvestCalculateDialogComponent } from '../components/ffb-calculatio
|
|
|
MatDialogModule
|
|
|
],
|
|
|
})
|
|
|
-export class FfbHarvestComponent implements OnInit {
|
|
|
+export class FfbProductionComponent implements OnInit {
|
|
|
private http = inject(HttpClient);
|
|
|
private snack = inject(MatSnackBar);
|
|
|
private dialog = inject(MatDialog);
|
|
|
@@ -58,17 +58,15 @@ export class FfbHarvestComponent implements OnInit {
|
|
|
startDateControl = new FormControl<Date | null>(null);
|
|
|
endDateControl = new FormControl<Date | null>(null);
|
|
|
|
|
|
- harvests: FFBHarvest[] = [];
|
|
|
- filteredHarvests: FFBHarvest[] = [];
|
|
|
+ production: FFBProduction[] = [];
|
|
|
+ filteredProductions: FFBProduction[] = [];
|
|
|
|
|
|
uniqueSites: string[] = [];
|
|
|
uniquePhases: string[] = [];
|
|
|
uniqueBlocks: string[] = [];
|
|
|
- uniqueHarvesters: string[] = [];
|
|
|
|
|
|
displayedColumns: string[] = [
|
|
|
- 'harvestDate',
|
|
|
- 'harvester',
|
|
|
+ 'productionDate',
|
|
|
'site',
|
|
|
'phase',
|
|
|
'block',
|
|
|
@@ -80,7 +78,7 @@ export class FfbHarvestComponent implements OnInit {
|
|
|
loading = false;
|
|
|
|
|
|
ngOnInit() {
|
|
|
- this.loadHarvests();
|
|
|
+ this.loadFFBproduction();
|
|
|
|
|
|
combineLatest([
|
|
|
this.searchControl.valueChanges.pipe(startWith(this.searchControl.value)),
|
|
|
@@ -93,19 +91,16 @@ export class FfbHarvestComponent implements OnInit {
|
|
|
]).subscribe(() => this.applyFilters());
|
|
|
}
|
|
|
|
|
|
- loadHarvests() {
|
|
|
+ loadFFBproduction() {
|
|
|
this.loading = true;
|
|
|
- this.http.get<FFBHarvest[]>(`${webConfig.exposedUrl}/api/ffb-harvest`).subscribe({
|
|
|
+ this.http.get<FFBProduction[]>(`${webConfig.exposedUrl}/api/ffb-production`).subscribe({
|
|
|
next: (data) => {
|
|
|
- this.harvests = data.map(h => ({ ...h, harvestDate: new Date(h.harvestDate) }));
|
|
|
- this.filteredHarvests = [...this.harvests];
|
|
|
-
|
|
|
+ this.production = data.map(h => ({ ...h, productionDate: new Date(h.productionDate) }));
|
|
|
+ this.filteredProductions = [...this.production];
|
|
|
// populate unique arrays for filters and autocompletes
|
|
|
- this.uniqueSites = [...new Set(this.harvests.map(h => h.site))];
|
|
|
- this.uniquePhases = [...new Set(this.harvests.map(h => h.phase))];
|
|
|
- this.uniqueBlocks = [...new Set(this.harvests.map(h => h.block))];
|
|
|
- this.uniqueHarvesters = [...new Set(this.harvests.map(h => h.harvester))];
|
|
|
-
|
|
|
+ this.uniqueSites = [...new Set(this.production.map(h => h.site))];
|
|
|
+ this.uniquePhases = [...new Set(this.production.map(h => h.phase))];
|
|
|
+ this.uniqueBlocks = [...new Set(this.production.map(h => h.block))];
|
|
|
this.loading = false;
|
|
|
},
|
|
|
error: (err) => {
|
|
|
@@ -125,13 +120,12 @@ export class FfbHarvestComponent implements OnInit {
|
|
|
const weightUom = this.weightUomControl.value;
|
|
|
const quantityUom = this.quantityUomControl.value;
|
|
|
|
|
|
- this.filteredHarvests = this.harvests.filter(h => {
|
|
|
+ this.filteredProductions = this.production.filter(h => {
|
|
|
const matchesKeyword =
|
|
|
!keyword ||
|
|
|
h.site.toLowerCase().includes(keyword) ||
|
|
|
h.phase.toLowerCase().includes(keyword) ||
|
|
|
h.block.toLowerCase().includes(keyword) ||
|
|
|
- h.harvester.toLowerCase().includes(keyword) ||
|
|
|
h.weight.toString().includes(keyword) ||
|
|
|
h.quantity.toString().includes(keyword);
|
|
|
|
|
|
@@ -140,7 +134,7 @@ export class FfbHarvestComponent implements OnInit {
|
|
|
const matchesWeightUom = !weightUom || h.weightUom === weightUom;
|
|
|
const matchesQuantityUom = !quantityUom || h.quantityUom === quantityUom;
|
|
|
|
|
|
- const hDate = new Date(h.harvestDate);
|
|
|
+ const hDate = new Date(h.productionDate);
|
|
|
const matchesDate =
|
|
|
(!startDate || hDate >= startDate) && (!endDate || hDate <= endDate);
|
|
|
|
|
|
@@ -157,20 +151,20 @@ export class FfbHarvestComponent implements OnInit {
|
|
|
this.endDateControl.setValue(null);
|
|
|
this.weightUomControl.setValue('');
|
|
|
this.quantityUomControl.setValue('');
|
|
|
- this.filteredHarvests = [...this.harvests];
|
|
|
+ this.filteredProductions = [...this.production];
|
|
|
}
|
|
|
|
|
|
refresh() {
|
|
|
- this.loadHarvests();
|
|
|
+ this.loadFFBproduction();
|
|
|
}
|
|
|
|
|
|
- deleteHarvest(id?: string) {
|
|
|
+ deleteProduction(id?: string) {
|
|
|
if (!id || !confirm('Are you sure you want to delete this record?')) return;
|
|
|
|
|
|
- this.http.delete(`${webConfig.exposedUrl}/api/ffb-harvest/${id}`).subscribe({
|
|
|
+ this.http.delete(`${webConfig.exposedUrl}/api/ffb-production/${id}`).subscribe({
|
|
|
next: () => {
|
|
|
this.snack.open('Deleted', 'Close', { duration: 2000 });
|
|
|
- this.loadHarvests();
|
|
|
+ this.loadFFBproduction();
|
|
|
},
|
|
|
error: (err) => {
|
|
|
console.error(err);
|
|
|
@@ -186,46 +180,41 @@ export class FfbHarvestComponent implements OnInit {
|
|
|
|
|
|
// ================== DIALOG HANDLERS ==================
|
|
|
|
|
|
- createHarvest() {
|
|
|
- const dialogRef = this.dialog.open(CreateFfbHarvestDialogComponent, {
|
|
|
+ createProduction() {
|
|
|
+ const dialogRef = this.dialog.open(CreateFfbProductionDialogComponent, {
|
|
|
width: '800px',
|
|
|
data: {
|
|
|
allSites: this.uniqueSites,
|
|
|
allPhases: this.uniquePhases,
|
|
|
allBlocks: this.uniqueBlocks,
|
|
|
- allHarvesters: this.uniqueHarvesters
|
|
|
}
|
|
|
});
|
|
|
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
|
- if (result === 'refresh') this.loadHarvests();
|
|
|
+ if (result === 'refresh') this.loadFFBproduction();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- editHarvest(harvest: FFBHarvest) {
|
|
|
- const dialogRef = this.dialog.open(CreateFfbHarvestDialogComponent, {
|
|
|
+ editProduction(harvest: FFBProduction) {
|
|
|
+ const dialogRef = this.dialog.open(CreateFfbProductionDialogComponent, {
|
|
|
width: '800px',
|
|
|
data: {
|
|
|
harvest,
|
|
|
allSites: this.uniqueSites,
|
|
|
allPhases: this.uniquePhases,
|
|
|
allBlocks: this.uniqueBlocks,
|
|
|
- allHarvesters: this.uniqueHarvesters
|
|
|
}
|
|
|
});
|
|
|
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
|
- if (result === 'refresh') this.loadHarvests();
|
|
|
+ if (result === 'refresh') this.loadFFBproduction();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
openCalculateDialog() {
|
|
|
this.dialog.open(FfbHarvestCalculateDialogComponent, {
|
|
|
data: {
|
|
|
- allSites: this.uniqueSites,
|
|
|
- allPhases: this.uniquePhases,
|
|
|
- allBlocks: this.uniqueBlocks,
|
|
|
- allHarvesters: this.uniqueHarvesters
|
|
|
+ productions: this.filteredProductions, // ✅ send the filtered list (or this.production)
|
|
|
},
|
|
|
width: '400px'
|
|
|
});
|