-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(IN): implementa periodos censables en internacion
- Loading branch information
Showing
6 changed files
with
218 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/app/apps/rup/mapa-camas/sidebar/periodos-censables/periodos-censables.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { Plex } from '@andes/plex'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { PrestacionesService } from 'src/app/modules/rup/services/prestaciones.service'; | ||
import { MapaCamasService } from '../../services/mapa-camas.service'; | ||
|
||
interface Periodo { | ||
desde: moment.Moment; | ||
hasta: moment.Moment; | ||
} | ||
|
||
@Component({ | ||
selector: 'app-periodos-censables', | ||
templateUrl: './periodos-censables.html', | ||
styleUrls: ['./periodos-censables.scss'] | ||
}) | ||
|
||
export class PeriodosCensablesComponent implements OnInit { | ||
prestacion; | ||
agregar = false; | ||
nuevoPeriodo: Periodo; | ||
periodos: Periodo[] = []; | ||
error = false; | ||
camaEsCensable = false; | ||
|
||
constructor( | ||
private mapaCamasService: MapaCamasService, | ||
private servicioPrestacion: PrestacionesService, | ||
private plex: Plex, | ||
) { } | ||
|
||
ngOnInit() { | ||
this.mapaCamasService.prestacion$.subscribe((prestacion) => { | ||
this.prestacion = prestacion; | ||
|
||
const primerRegistro = prestacion?.ejecucion?.registros[0]; | ||
|
||
if (!!primerRegistro?.esCensable) { | ||
this.periodos = this.prestacion?.periodosCensables; | ||
|
||
if (!this.periodos.length) { | ||
const fechaInicio = primerRegistro.createdAt; | ||
|
||
this.periodos.push({ desde: moment(fechaInicio), hasta: moment() }); | ||
} | ||
} | ||
}); | ||
|
||
this.initNuevoPeriodo(); | ||
} | ||
|
||
private initNuevoPeriodo() { | ||
this.nuevoPeriodo = { | ||
desde: moment(), | ||
hasta: null | ||
}; | ||
} | ||
|
||
private periodoValido(desde, hasta) { | ||
return hasta ? !this.periodos.find((periodo) => moment(periodo.desde)?.isSame(desde, 'day') && moment(periodo.hasta)?.isSame(hasta, 'day')) | ||
: false; | ||
} | ||
|
||
private guardarPrestacion() { | ||
const registros = this.prestacion.ejecucion.registros; | ||
|
||
if (!!this.periodos?.length) { | ||
registros[0].esCensable = true; | ||
} else { | ||
delete registros[0].esCensable; | ||
} | ||
|
||
const params: any = { | ||
op: 'periodosCensables', | ||
periodosCensables: this.periodos, | ||
registros, | ||
}; | ||
|
||
return this.servicioPrestacion.patch(this.prestacion.id, params); | ||
} | ||
|
||
public toggleAgregar() { | ||
this.agregar = !this.agregar; | ||
} | ||
|
||
public eliminarPeriodo(index) { | ||
this.periodos?.splice(index, 1); | ||
|
||
this.guardarPrestacion().subscribe({ | ||
error: () => { | ||
this.plex.toast('danger', 'Ha ocurrido un error al eliminar el periodo'); | ||
} | ||
}); | ||
} | ||
|
||
public agregarPeriodo() { | ||
const { desde, hasta } = this.nuevoPeriodo; | ||
|
||
if (this.periodoValido(desde, hasta)) { | ||
this.error = false; | ||
this.periodos.push({ ...this.nuevoPeriodo, hasta }); | ||
|
||
this.initNuevoPeriodo(); | ||
} else { | ||
this.error = true; | ||
} | ||
} | ||
|
||
public guardar() { | ||
this.guardarPrestacion().subscribe({ | ||
complete: () => { | ||
this.plex.info('success', 'Periodos guardados exitosamente'); | ||
this.toggleAgregar(); | ||
}, | ||
error: () => { | ||
this.plex.toast('danger', 'Ha ocurrido un error al guardar el periodo'); | ||
} | ||
}); | ||
} | ||
|
||
public cancelar() { | ||
this.agregar = false; | ||
this.initNuevoPeriodo(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/app/apps/rup/mapa-camas/sidebar/periodos-censables/periodos-censables.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<ng-container> | ||
<plex-title size="sm" justify titulo="PERIODOS CENSABLES"> | ||
|
||
<plex-button *ngIf="!agregar" title="Agregar" label="Editar" type="success" size="sm" class="mr-1" | ||
(click)="toggleAgregar()"> | ||
</plex-button> | ||
|
||
<plex-button *ngIf="agregar" label="Guardar" type="success" size="sm" class="mr-1" (click)="guardar()">Guardar | ||
</plex-button> | ||
|
||
<plex-button *ngIf="agregar" icon="close" type="danger" size="sm" class="mr-1" (click)="cancelar()"> | ||
</plex-button> | ||
|
||
|
||
</plex-title> | ||
<div *ngIf="agregar"> | ||
<div class="nuevo-periodo"> | ||
<div class="fechas-periodo"> | ||
<plex-datetime type="date" label="Inicio de censo" [(ngModel)]="nuevoPeriodo.desde" name="fechaDesde" | ||
grow="full"> | ||
</plex-datetime> | ||
<plex-datetime type="date" label="Fin de censo" [(ngModel)]="nuevoPeriodo.hasta" name="fechaHasta" | ||
grow="full" [min]="nuevoPeriodo.desde"> | ||
</plex-datetime> | ||
<plex-button icon="check" type="success" size="md" class="mr-1" (click)="agregarPeriodo()" | ||
[disabled]="!nuevoPeriodo.hasta"></plex-button> | ||
</div> | ||
<div class="periodo-controls mt-2"> | ||
<span *ngIf="error" class="periodo-error text-danger">El periodo seleccionado ya existe</span> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
<div *ngIf="periodos?.length" class="lista-periodos"> | ||
<div *ngFor="let periodo of periodos; let i = index" class="periodo"> | ||
<plex-label titulo="Desde" subtitulo="{{periodo.desde | fecha}}"> | ||
</plex-label> | ||
<plex-label titulo="Hasta" subtitulo="{{periodo.hasta | fecha}}"> | ||
</plex-label> | ||
<div> | ||
<plex-button *ngIf="agregar" type="danger" size="sm" icon="delete" (click)="eliminarPeriodo(i)" | ||
ariaLabel="Eliminar periodo"> | ||
</plex-button> | ||
</div> | ||
</div> | ||
</div> | ||
<div justify="center" *ngIf="!agregar && !periodos?.length"> | ||
<plex-label class="mt-2" direction="column" size="md" icon="" titulo="No hay periodos censables cargados" | ||
icon="calendario-rango-bold"> | ||
</plex-label> | ||
</div> | ||
</ng-container> |
32 changes: 32 additions & 0 deletions
32
src/app/apps/rup/mapa-camas/sidebar/periodos-censables/periodos-censables.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.nuevo-periodo { | ||
display: flex; | ||
flex-direction: column; | ||
margin-top: 10px; | ||
} | ||
|
||
.periodo-controls { | ||
display: flex; | ||
justify-content: flex-end; | ||
|
||
.periodo-error { | ||
display: flex; | ||
flex-grow: 1; | ||
} | ||
} | ||
|
||
.fechas-periodo { | ||
display: flex; | ||
column-gap: 5px; | ||
align-items: flex-end; | ||
} | ||
|
||
.lista-periodos { | ||
margin-top: 10px; | ||
|
||
.periodo { | ||
display: flex; | ||
padding: 5px; | ||
align-items: center; | ||
justify-content: space-between; | ||
} | ||
} |