Quellcode durchsuchen

cambio para bloquear registro si existe previo registro; se pinta la data del previo registro y se pasa a read-only

EmilianoOrtiz vor 3 Tagen
Ursprung
Commit
d07b25ad94

+ 13 - 0
src/app/components/corrective-maintenance/operations-management/cost-analysis-modal/cost-analysis-modal.component.css

@@ -71,4 +71,17 @@
 h3 {
   margin: 20px 0 10px 0;
   color: #333;
+}
+
+.previous-analysis-info {
+  background-color: #e3f2fd;
+  padding: 10px;
+  border-radius: 4px;
+  margin-bottom: 15px;
+  border-left: 4px solid #2196f3;
+}
+
+.previous-analysis-info p {
+  margin: 5px 0;
+  font-size: 14px;
 }

+ 34 - 12
src/app/components/corrective-maintenance/operations-management/cost-analysis-modal/cost-analysis-modal.component.html

@@ -1,4 +1,13 @@
-<h1 mat-dialog-title class="prevent-select">Análisis de costos</h1>
+<h1 mat-dialog-title class="prevent-select">
+  {{ hasPreviousAnalysis ? 'Análisis de costos - Registro previo' : 'Análisis de costos' }}
+</h1>
+
+@if (hasPreviousAnalysis && previousAnalysis) {
+  <div class="previous-analysis-info">
+    <p><strong>Fecha:</strong> {{ previousAnalysis.FECHA }}</p>
+    <p><strong>Usuario:</strong> {{ previousAnalysis.USUARIO }}</p>
+  </div>
+}
 
 <div mat-dialog-content class="cost-analysis-content">
   @if (costData) {
@@ -11,11 +20,11 @@
             <span class="user-name">{{ user.NOMBRE }}</span>
             <mat-form-field appearance="outline" class="cost-input">
               <mat-label>Costo</mat-label>
-              <input matInput type="number" [(ngModel)]="userCosts[user.ID].amount" (ngModelChange)="onUserCostChange()">
+              <input matInput type="number" [(ngModel)]="userCosts[user.ID].amount" (ngModelChange)="onUserCostChange()" [readonly]="isReadOnly">
             </mat-form-field>
             <mat-form-field appearance="outline" class="currency-select">
               <mat-label>Moneda</mat-label>
-              <mat-select [(ngModel)]="userCosts[user.ID].currency" (selectionChange)="onUserCostChange()">
+              <mat-select [(ngModel)]="userCosts[user.ID].currency" (selectionChange)="onUserCostChange()" [disabled]="isReadOnly">
                 @for (currency of currencies; track currency) {
                   <mat-option [value]="currency">{{ currency }}</mat-option>
                 }
@@ -27,10 +36,10 @@
     }
 
     <!-- Herramientas -->
-    @if (costData.HERRAMIENTAS && costData.HERRAMIENTAS.length > 0) {
+    @if ((hasPreviousAnalysis ? previousAnalysis?.HERRAMIENTAS : costData?.HERRAMIENTAS)?.length > 0) {
       <h3>Herramientas</h3>
       <div class="items-table">
-        @for (tool of costData.HERRAMIENTAS; track tool.ID) {
+        @for (tool of (hasPreviousAnalysis ? previousAnalysis.HERRAMIENTAS : costData.HERRAMIENTAS); track tool.ID) {
           <div class="item-row">
             <span class="item-name">{{ tool.NOMBRE }}</span>
             <span class="item-cost">{{ tool.PRECIO_UNITARIO }} {{ tool.MONEDA_SIMBOLO }}</span>
@@ -40,7 +49,7 @@
         }
       </div>
       <div class="subtotal-section">
-        @for (subtotal of costData.SUBTOTAL_HERRAMIENTAS; track subtotal.SIMBOLO) {
+        @for (subtotal of (hasPreviousAnalysis ? previousAnalysis.SUBTOTAL_HERRAMIENTAS : costData.SUBTOTAL_HERRAMIENTAS); track subtotal.SIMBOLO) {
           <div class="subtotal-row">
             <strong>Subtotal Herramientas: {{ subtotal.SUBTOTAL }} {{ subtotal.SIMBOLO }}</strong>
           </div>
@@ -49,10 +58,10 @@
     }
 
     <!-- Refacciones -->
-    @if (costData.REFACCIONES && costData.REFACCIONES.length > 0) {
+    @if ((hasPreviousAnalysis ? previousAnalysis?.REFACCIONES : costData?.REFACCIONES)?.length > 0) {
       <h3>Refacciones</h3>
       <div class="items-table">
-        @for (part of costData.REFACCIONES; track part.ID) {
+        @for (part of (hasPreviousAnalysis ? previousAnalysis.REFACCIONES : costData.REFACCIONES); track part.ID) {
           <div class="item-row">
             <span class="item-name">{{ part.NOMBRE }}</span>
             <span class="item-cost">{{ part.PRECIO_UNITARIO }} {{ part.MONEDA_SIMBOLO }}</span>
@@ -62,7 +71,7 @@
         }
       </div>
       <div class="subtotal-section">
-        @for (subtotal of costData.SUBTOTAL_REFACCIONES; track subtotal.SIMBOLO) {
+        @for (subtotal of (hasPreviousAnalysis ? previousAnalysis.SUBTOTAL_REFACCIONES : costData.SUBTOTAL_REFACCIONES); track subtotal.SIMBOLO) {
           <div class="subtotal-row">
             <strong>Subtotal Refacciones: {{ subtotal.SUBTOTAL }} {{ subtotal.SIMBOLO }}</strong>
           </div>
@@ -70,6 +79,17 @@
       </div>
     }
 
+    <!-- Subtotal Usuarios (solo si hay análisis previo) -->
+    @if (hasPreviousAnalysis && previousAnalysis?.SUBTOTAL_USUARIOS?.length > 0) {
+      <div class="subtotal-section">
+        @for (subtotal of previousAnalysis.SUBTOTAL_USUARIOS; track subtotal.SIMBOLO) {
+          <div class="subtotal-row">
+            <strong>Subtotal Usuarios: {{ subtotal.SUBTOTAL }} {{ subtotal.SIMBOLO }}</strong>
+          </div>
+        }
+      </div>
+    }
+
     <!-- Totales -->
     <div class="totals-section">
       <h3>Total</h3>
@@ -83,11 +103,13 @@
 
   <mat-form-field appearance="outline" class="full-width comments-field">
     <mat-label>Comentarios</mat-label>
-    <textarea matInput [(ngModel)]="comments" rows="3" placeholder="Ingrese sus comentarios..."></textarea>
+    <textarea matInput [(ngModel)]="comments" rows="3" placeholder="Ingrese sus comentarios..." [readonly]="isReadOnly"></textarea>
   </mat-form-field>
 </div>
 
 <div mat-dialog-actions align="end">
-  <button mat-button (click)="onCancel()">Cancelar</button>
-  <button mat-button color="primary" (click)="onSave()">Guardar</button>
+  <button mat-button (click)="onCancel()">{{ isReadOnly ? 'Cerrar' : 'Cancelar' }}</button>
+  @if (!isReadOnly) {
+    <button mat-button color="primary" (click)="onSave()">Guardar</button>
+  }
 </div>

+ 32 - 2
src/app/components/corrective-maintenance/operations-management/cost-analysis-modal/cost-analysis-modal.component.ts

@@ -13,14 +13,27 @@ export class CostAnalysisModalComponent {
   currencies = ['MXN', 'USD'];
   userCosts: { [key: string]: { amount: number, currency: string } } = {};
   totals: { [key: string]: number } = {};
+  hasPreviousAnalysis: boolean = false;
+  previousAnalysis: any = null;
+  isReadOnly: boolean = false;
 
   constructor(
     public dialogRef: MatDialogRef<CostAnalysisModalComponent>,
     @Inject(MAT_DIALOG_DATA) public data: { idOrder: string, costData?: any }
   ) {
     this.costData = data.costData;
-    this.initializeUserCosts();
-    this.calculateTotals();
+    this.hasPreviousAnalysis = data.costData?.TIENE_ANALISIS_PREVIO || false;
+    this.previousAnalysis = data.costData?.ANALISIS_PREVIO || null;
+    this.isReadOnly = this.hasPreviousAnalysis;
+    
+    if (this.hasPreviousAnalysis && this.previousAnalysis) {
+      this.comments = this.previousAnalysis.COMENTARIOS || '';
+      this.initializePreviousUserCosts();
+      this.calculatePreviousTotals();
+    } else {
+      this.initializeUserCosts();
+      this.calculateTotals();
+    }
   }
 
   initializeUserCosts(): void {
@@ -31,6 +44,23 @@ export class CostAnalysisModalComponent {
     }
   }
 
+  initializePreviousUserCosts(): void {
+    if (this.previousAnalysis?.USUARIOS) {
+      this.previousAnalysis.USUARIOS.forEach((user: any) => {
+        this.userCosts[user.ID] = { amount: user.COSTO || 0, currency: user.MONEDA || 'MXN' };
+      });
+    }
+  }
+
+  calculatePreviousTotals(): void {
+    this.totals = {};
+    if (this.previousAnalysis?.TOTAL) {
+      this.previousAnalysis.TOTAL.forEach((item: any) => {
+        this.totals[item.SIMBOLO] = item.TOTAL;
+      });
+    }
+  }
+
   calculateTotals(): void {
     this.totals = {};