|
|
@@ -44,6 +44,7 @@ export class CreateFfbProductionDialogComponent implements OnInit {
|
|
|
form: FormGroup;
|
|
|
saving = false;
|
|
|
generatingRemark = false;
|
|
|
+ generatingIssues = false;
|
|
|
|
|
|
weightUomOptions = ['Kg', 'Ton'];
|
|
|
quantityUomOptions = ['Bunch', 'Bag'];
|
|
|
@@ -71,7 +72,8 @@ export class CreateFfbProductionDialogComponent implements OnInit {
|
|
|
quantityUom: ['Bunch', Validators.required],
|
|
|
weight: [0, Validators.required],
|
|
|
weightUom: ['Kg', Validators.required],
|
|
|
- remarks: [{ value: '', disabled: true }]
|
|
|
+ remarks: [{ value: '', disabled: true }],
|
|
|
+ issues: ['']
|
|
|
});
|
|
|
|
|
|
// Monitor form changes to enable/disable remarks
|
|
|
@@ -100,7 +102,8 @@ export class CreateFfbProductionDialogComponent implements OnInit {
|
|
|
quantityUom: harvest.quantityUom,
|
|
|
weight: harvest.weight,
|
|
|
weightUom: harvest.weightUom,
|
|
|
- remarks: harvest.remarks
|
|
|
+ remarks: harvest.remarks,
|
|
|
+ issues: harvest.issues
|
|
|
});
|
|
|
|
|
|
// For dependent dropdowns, we need to load them sequentially
|
|
|
@@ -230,6 +233,41 @@ export class CreateFfbProductionDialogComponent implements OnInit {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ generateIssues() {
|
|
|
+ if (this.generatingIssues) return;
|
|
|
+
|
|
|
+ this.generatingIssues = true;
|
|
|
+ const payload = this.form.value;
|
|
|
+
|
|
|
+ const context = {
|
|
|
+ siteId: payload.site?._id || payload.site?.id,
|
|
|
+ phaseId: payload.phase?._id || payload.phase?.id,
|
|
|
+ blockId: payload.block?._id || payload.block?.id,
|
|
|
+ site: payload.site?.name,
|
|
|
+ phase: payload.phase?.name,
|
|
|
+ block: payload.block?.name,
|
|
|
+ date: payload.productionDate,
|
|
|
+ quantity: payload.quantity,
|
|
|
+ quantityUom: payload.quantityUom,
|
|
|
+ weight: payload.weight,
|
|
|
+ weightUom: payload.weightUom
|
|
|
+ };
|
|
|
+
|
|
|
+ this.http.post<{ issues: string }>(`${webConfig.exposedUrl}/api/ffb-production/generate-issues`, context).subscribe({
|
|
|
+ next: (res) => {
|
|
|
+ this.form.patchValue({ issues: res.issues });
|
|
|
+ this.snackBar.open('Issues generated!', 'Close', { duration: 2000 });
|
|
|
+ this.generatingIssues = false;
|
|
|
+ },
|
|
|
+ error: (err) => {
|
|
|
+ console.error(err);
|
|
|
+ this.snackBar.open('Failed to generate issues.', 'Close', { duration: 3000 });
|
|
|
+ this.generatingIssues = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
randomize() {
|
|
|
// Randomize needs to pick valid existing sites now
|
|
|
if (this.sites.length === 0) {
|
|
|
@@ -302,7 +340,8 @@ export class CreateFfbProductionDialogComponent implements OnInit {
|
|
|
productionDate: new Date(formVal.productionDate).toISOString(),
|
|
|
site: { id: formVal.site._id || formVal.site.id, name: formVal.site.name },
|
|
|
phase: { id: formVal.phase._id || formVal.phase.id, name: formVal.phase.name },
|
|
|
- block: { id: formVal.block._id || formVal.block.id, name: formVal.block.name }
|
|
|
+ block: { id: formVal.block._id || formVal.block.id, name: formVal.block.name },
|
|
|
+ issues: formVal.issues
|
|
|
};
|
|
|
|
|
|
// If editing, we need the ID?
|