Browse Source

dditional summary

Dr-Swopt 2 months ago
parent
commit
b9b97f89a1

+ 101 - 66
src/app/components/calculate-dialog/calculate-dialog.component.html

@@ -1,82 +1,117 @@
 <h2 mat-dialog-title>Activity Quantitative Report</h2>
 
 <mat-dialog-content>
-  <!-- Resources grouped by type -->
-  <section>
-    <h3>👷 Resources ({{ resourceSummary.length }})</h3>
-    <mat-accordion>
-      <mat-expansion-panel *ngFor="let type of resourceSummary">
-        <mat-expansion-panel-header>
-          <mat-panel-title>
-            {{ type.type | titlecase }} ({{ type.resources.length }})
-          </mat-panel-title>
-        </mat-expansion-panel-header>
+    <!-- Resources grouped by type -->
+    <section>
+        <h3>👷 Resources ({{ resourceSummary.length }})</h3>
+        <mat-accordion>
+            <mat-expansion-panel *ngFor="let type of resourceSummary">
+                <mat-expansion-panel-header>
+                    <mat-panel-title>
+                        {{ type.type | titlecase }} ({{ type.resources.length }})
+                    </mat-panel-title>
+                </mat-expansion-panel-header>
 
-        <!-- List each resource of this type -->
-        <div *ngFor="let res of type.resources" class="resource-row">
-          <span>{{ res.name }}: {{ res.totalQuantity }} {{ res.uom }}</span>
-        </div>
-      </mat-expansion-panel>
-    </mat-accordion>
-  </section>
+                <!-- List each resource of this type -->
+                <div *ngFor="let res of type.resources" class="resource-row">
+                    <span>{{ res.name }}: {{ res.totalQuantity }} {{ res.uom }}</span>
+                </div>
+            </mat-expansion-panel>
+        </mat-accordion>
+    </section>
 
-  <hr />
+    <hr />
+    <section>
+        <h3>📦 Outputs ({{ outputSummary.length }})</h3>
+        <mat-accordion>
+            <mat-expansion-panel *ngFor="let type of outputSummary">
+                <mat-expansion-panel-header>
+                    <mat-panel-title>
+                        {{ type.type | titlecase }} ({{ type.outputs.length }})
+                    </mat-panel-title>
+                </mat-expansion-panel-header>
 
-  <!-- OUTPUT TOTALS -->
-  <section>
-    <h3>📦 Total Outputs</h3>
-    <ul>
-      <li *ngFor="let uom of (totalOutputs | keyvalue)">
-        {{ uom.value }} {{ totalOutputUoms[uom.key] }}
-      </li>
-    </ul>
-  </section>
+                <div *ngFor="let out of type.outputs" class="output-row">
+                    <span>{{ out.name }}: {{ out.totalQuantity }} {{ out.uom }}
+                        <span *ngIf="out.totalWeight">({{ out.totalWeight }} kg)</span>
+                    </span>
+                </div>
+            </mat-expansion-panel>
+        </mat-accordion>
+    </section>
+    <section>
+        <h3>🎯 Targets ({{ targetSummary.length }})</h3>
+        <mat-accordion>
+            <mat-expansion-panel *ngFor="let type of targetSummary">
+                <mat-expansion-panel-header>
+                    <mat-panel-title>
+                        {{ type.type | titlecase }} ({{ type.targets.length }})
+                    </mat-panel-title>
+                </mat-expansion-panel-header>
 
-  <hr />
+                <div *ngFor="let tgt of type.targets" class="target-row">
+                    <span>{{ tgt.name }}: {{ tgt.totalQuantity }} {{ tgt.uom }}</span>
+                </div>
+            </mat-expansion-panel>
+        </mat-accordion>
+    </section>
 
-  <!-- TARGET TOTALS -->
-  <section>
-    <h3>🎯 Total Targets</h3>
-    <ul>
-      <li *ngFor="let uom of (totalTargets | keyvalue)">
-        {{ uom.value }} {{ totalTargetUoms[uom.key] }}
-      </li>
-    </ul>
-  </section>
 
-  <hr />
+    <!-- OUTPUT TOTALS -->
+    <section>
+        <h3>📦 Total Outputs</h3>
+        <ul>
+            <li *ngFor="let uom of (totalOutputs | keyvalue)">
+                {{ uom.value }} {{ totalOutputUoms[uom.key] }}
+            </li>
+        </ul>
+    </section>
 
-  <!-- DURATION -->
-  <section>
-    <h3>⏱️ Total Duration</h3>
-    <p>{{ totalDuration }} {{ durationUom }}</p>
-  </section>
+    <hr />
 
-  <!-- MONTHLY AVERAGES -->
-  <section *ngIf="averageOutputsPerMonth && (averageOutputsPerMonth | keyvalue).length">
-    <h3>📦 Average Outputs per Month</h3>
-    <ul>
-      <li *ngFor="let uom of (averageOutputsPerMonth | keyvalue)">
-        {{ uom.value | number:'1.0-2' }} {{ totalOutputUoms[uom.key] }}
-      </li>
-    </ul>
-  </section>
+    <!-- TARGET TOTALS -->
+    <section>
+        <h3>🎯 Total Targets</h3>
+        <ul>
+            <li *ngFor="let uom of (totalTargets | keyvalue)">
+                {{ uom.value }} {{ totalTargetUoms[uom.key] }}
+            </li>
+        </ul>
+    </section>
 
-  <section *ngIf="averageTargetsPerMonth && (averageTargetsPerMonth | keyvalue).length">
-    <h3>🎯 Average Targets per Month</h3>
-    <ul>
-      <li *ngFor="let uom of (averageTargetsPerMonth | keyvalue)">
-        {{ uom.value | number:'1.0-2' }} {{ totalTargetUoms[uom.key] }}
-      </li>
-    </ul>
-  </section>
+    <hr />
 
-  <section *ngIf="averageDurationPerMonth && averageDurationPerMonth > 0">
-    <h3>⏱️ Average Duration per Month</h3>
-    <p>{{ averageDurationPerMonth | number:'1.0-2' }} {{ durationUom }}</p>
-  </section>
+    <!-- DURATION -->
+    <section>
+        <h3>⏱️ Total Duration</h3>
+        <p>{{ totalDuration }} {{ durationUom }}</p>
+    </section>
+
+    <!-- MONTHLY AVERAGES -->
+    <section *ngIf="averageOutputsPerMonth && (averageOutputsPerMonth | keyvalue).length">
+        <h3>📦 Average Outputs per Month</h3>
+        <ul>
+            <li *ngFor="let uom of (averageOutputsPerMonth | keyvalue)">
+                {{ uom.value | number:'1.0-2' }} {{ totalOutputUoms[uom.key] }}
+            </li>
+        </ul>
+    </section>
+
+    <section *ngIf="averageTargetsPerMonth && (averageTargetsPerMonth | keyvalue).length">
+        <h3>🎯 Average Targets per Month</h3>
+        <ul>
+            <li *ngFor="let uom of (averageTargetsPerMonth | keyvalue)">
+                {{ uom.value | number:'1.0-2' }} {{ totalTargetUoms[uom.key] }}
+            </li>
+        </ul>
+    </section>
+
+    <section *ngIf="averageDurationPerMonth && averageDurationPerMonth > 0">
+        <h3>⏱️ Average Duration per Month</h3>
+        <p>{{ averageDurationPerMonth | number:'1.0-2' }} {{ durationUom }}</p>
+    </section>
 </mat-dialog-content>
 
 <mat-dialog-actions align="end">
-  <button mat-button (click)="closeDialog()">Close</button>
-</mat-dialog-actions>
+    <button mat-button (click)="closeDialog()">Close</button>
+</mat-dialog-actions>

+ 65 - 1
src/app/components/calculate-dialog/calculate-dialog.component.ts

@@ -14,6 +14,25 @@ interface ResourceSummary {
         uom: string;
     }[];
 }
+interface OutputSummary {
+    type: string; // e.g., "FFB harvested"
+    outputs: {
+        name: string;
+        totalQuantity: number;
+        uom: string;
+        totalWeight?: number; // optional, sum of weight in kg
+    }[];
+}
+
+interface TargetSummary {
+    type: string; // e.g., "location"
+    targets: {
+        name: string;
+        totalQuantity: number;
+        uom: string;
+    }[];
+}
+
 
 @Component({
     selector: 'app-calculate-dialog',
@@ -29,7 +48,8 @@ interface ResourceSummary {
 })
 export class CalculateDialogComponent implements OnInit {
     filteredActivities: Activity[] = [];
-
+    outputSummary: OutputSummary[] = [];
+    targetSummary: TargetSummary[] = [];
     resourceSummary: ResourceSummary[] = [];
     totalOutputs: Record<string, number> = {};
     totalOutputUoms: Record<string, string> = {};
@@ -57,6 +77,8 @@ export class CalculateDialogComponent implements OnInit {
     }
 
     calculateTotals(): void {
+        const outputTypeMap: Record<string, Record<string, { totalQuantity: number; uom: string; totalWeight: number }>> = {};
+        const targetTypeMap: Record<string, Record<string, { totalQuantity: number; uom: string }>> = {};
         const resourceTypeMap: Record<string, Record<string, { totalQuantity: number; uom: string }>> = {};
         const outputTotals: Record<string, number> = {};
         const outputUoms: Record<string, string> = {};
@@ -76,6 +98,29 @@ export class CalculateDialogComponent implements OnInit {
             allStartDates.push(start);
             allEndDates.push(end);
 
+            // --- Outputs ---
+            for (const output of activity.outputs) {
+                if (!outputTypeMap[output.type]) outputTypeMap[output.type] = {};
+                if (!outputTypeMap[output.type][output.name]) {
+                    outputTypeMap[output.type][output.name] = {
+                        totalQuantity: 0,
+                        uom: output.value.uom,
+                        totalWeight: 0
+                    };
+                }
+                outputTypeMap[output.type][output.name].totalQuantity += output.value.quantity;
+                outputTypeMap[output.type][output.name].totalWeight += output.weightValue?.weight || 0;
+            }
+
+            // --- Targets ---
+            for (const target of activity.targets) {
+                if (!targetTypeMap[target.type]) targetTypeMap[target.type] = {};
+                if (!targetTypeMap[target.type][target.name]) {
+                    targetTypeMap[target.type][target.name] = { totalQuantity: 0, uom: target.value.uom };
+                }
+                targetTypeMap[target.type][target.name].totalQuantity += target.value.quantity;
+            }
+
             // Group resources by type and sum quantity
             for (const res of activity.resources) {
                 if (!resourceTypeMap[res.type]) resourceTypeMap[res.type] = {};
@@ -133,6 +178,25 @@ export class CalculateDialogComponent implements OnInit {
                 uom: resourceTypeMap[type][name].uom
             }))
         }));
+        // Transform into arrays for template
+        this.outputSummary = Object.keys(outputTypeMap).map(type => ({
+            type,
+            outputs: Object.keys(outputTypeMap[type]).map(name => ({
+                name,
+                totalQuantity: outputTypeMap[type][name].totalQuantity,
+                uom: outputTypeMap[type][name].uom,
+                totalWeight: outputTypeMap[type][name].totalWeight
+            }))
+        }));
+
+        this.targetSummary = Object.keys(targetTypeMap).map(type => ({
+            type,
+            targets: Object.keys(targetTypeMap[type]).map(name => ({
+                name,
+                totalQuantity: targetTypeMap[type][name].totalQuantity,
+                uom: targetTypeMap[type][name].uom
+            }))
+        }));
 
         this.totalOutputs = outputTotals;
         this.totalOutputUoms = outputUoms;