Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit, Output, EventEmitter, Input, ViewChild } from '@angular/core';
- import { toBool, moeda, tiraHoraDaData, moedaParaDecimal, moedaBancoParaMoedaPt } from 'app/helper';
- import { FormGroup, Validators, FormControl } from '@angular/forms';
- import { PagamentoContratoLocacaoTemporada } from '../../../../domain/entities/pagamentoContratoLocacaoTemporada';
- import { ContratoLocacaoTemporadaService } from 'app/services/root/contratoLocacaoTemporada.service';
- import { PagamentoContratoLocacaoTemporadaService } from 'app/services/root/pagamentoContratoLocacaoTemporada.service';
- import { NgbModalRef, NgbModal } from '@ng-bootstrap/ng-bootstrap';
- import { ToastrService } from 'ngx-toastr';
- import { Router, ActivatedRoute } from '@angular/router';
- @Component({
- selector: 'app-pagamento-contrato-locacao-temporada',
- templateUrl: './pagamento-contrato-locacao-temporada.component.html',
- })
- export class PagamentoContratoLocacaoTemporadaComponent implements OnInit {
- @Output() PagamentoContratoLocacaoTemporadaModal = new EventEmitter()
- @Output() outPagamentos = new EventEmitter
- form: FormGroup = this.buildForm()
- contratoLocacaoTemporadaId: number
- pagamentoContratoLocacaoTemporadaId: number
- listaPagamentos = []
- tipos = [
- "PROPRIETARIO", "FAXINA", "CORRETOR", "IMOBILIARIA", "GERENCIA", "AGENCIADOR"
- ]
- object: PagamentoContratoLocacaoTemporada
- @ViewChild('content') modal;
- modalRef: NgbModalRef;
- constructor(
- private pagamentoContratoLocacaoTemporadaS: PagamentoContratoLocacaoTemporadaService,
- private active: ActivatedRoute,
- private modalService: NgbModal,
- private toastS: ToastrService, ) { }
- ngOnInit() {
- }
- open(pagamentoContratoLocacaoTemporadaId, pagamentos) {
- this.object = new PagamentoContratoLocacaoTemporada()
- this.pagamentoContratoLocacaoTemporadaId = pagamentoContratoLocacaoTemporadaId
- this.listaPagamentos = pagamentos
- if (this.pagamentoContratoLocacaoTemporadaId == null) {
- this.form.get('tipoPagamentoContratoLocacaoTemporadaId').enable()
- this.listaPagamentos = pagamentos
- this.modalRef = this.modalService.open(this.modal, { size: 'lg' });
- } else {
- this.form.get('tipoPagamentoContratoLocacaoTemporadaId').disable()
- pagamentos.map((pagamento) => {
- if (pagamento.id == pagamentoContratoLocacaoTemporadaId) {
- this.pagamentoContratoLocacaoTemporadaId = pagamentoContratoLocacaoTemporadaId
- this.object = pagamento
- this.object.dataLancamento = tiraHoraDaData(this.object.dataLancamento)
- this.object.dataPagamento = tiraHoraDaData(this.object.dataPagamento)
- this.formataValores()
- this.modalRef = this.modalService.open(this.modal, { size: 'lg' });
- }
- })
- };
- }
- close() {
- this.pagamentoContratoLocacaoTemporadaId = null
- this.object = null
- this.modalRef.close()
- }
- change(event) {
- this.object.tipoPagamentoContratoLocacaoTemporadaId = event.target.selectedIndex
- }
- moeda(valor) {
- return moeda(valor).toString() == '' ? 0 : moeda(valor);
- }
- // validaValores(): boolean {
- // this.object.valor = this.object.valorDisplay == "" ||
- // this.object.valorDisplay == null ? 0 :
- // parseFloat(this.object.valorDisplay.replace(".", "").replace(",", "."))
- // return true
- // }
- formataValores() {
- this.object.valorDisplay = moedaBancoParaMoedaPt(this.object.valor)
- console.log(this.object)
- }
- salvar() {
- this.object.valor = parseFloat(moedaParaDecimal(this.object.valorDisplay))
- if (this.pagamentoContratoLocacaoTemporadaId == null) { //teste para alteração ou inserção
- this.listaPagamentos.push(this.object)
- this.outPagamentos.emit(this.listaPagamentos)
- } else {
- this.outPagamentos.emit(this.listaPagamentos)
- }
- this.close()
- }
- excluir() {
- if (this.pagamentoContratoLocacaoTemporadaId != null) {
- var index = this.listaPagamentos.indexOf(this.object)
- this.listaPagamentos.splice(index, 1)
- this.outPagamentos.emit(this.listaPagamentos)
- console.log(this.object)
- console.log(this.listaPagamentos)
- }
- this.close()
- }
- buildForm() {
- return new FormGroup({
- id: new FormControl(''),
- contratoLocacaoTemporada: new FormControl(''),
- contratoLocacaoTemporadaId: new FormControl(''),
- dataLancamento: new FormControl(''),
- dataPagamento: new FormControl(''),
- tipoPagamentoContratoLocacaoTemporada: new FormControl(''),
- tipoPagamentoContratoLocacaoTemporadaId: new FormControl(''),
- valor: new FormControl(''),
- complemento: new FormControl(''),
- })
- }
- // verificaCamposObrigatorios() {
- // if (this.object.tipoPagamentoContratoLocacaoTemporadaId == 0) {
- // this.toastS.error("O campo 'Nome' é obrigatório.")
- // return false;
- // }
- // if (this.object.email == null || this.object.email == "") {
- // this.toastS.error("O campo 'e-Mail' é obrigatório.")
- // return false;
- // }
- // if (this.object.fones.length == 0) {
- // this.toastS.error("É necessário cadastrar pelo menos um telefone.")
- // return false;
- // }
- // if (this.object.dataInicio == null || this.object.dataInicio.toString() == '') {
- // this.toastS.error("O campo 'Data de Início' é obrigatório.")
- // return false;
- // }
- // if (this.object.dataFim == null || this.object.dataFim.toString() == '') {
- // this.toastS.error("O campo 'Data de Saída' é obrigatório.")
- // return false;
- // }
- // if (this.object.moeda == null) {
- // this.toastS.error("O campo 'Moeda' é obrigatório.")
- // return false;
- // }
- // if (this.object.corretorId == null) {
- // this.toastS.error("O campo 'Corretor' é obrigatório.")
- // return false;
- // }
- // if (this.object.imovelId == null) {
- // this.toastS.error("O campo 'Imóvel' é obrigatório.")
- // return false;
- // }
- // return true;
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement