Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. import { Component, OnInit, Output, EventEmitter, Input, ViewChild } from '@angular/core';
  2. import { toBool, moeda, tiraHoraDaData, moedaParaDecimal, moedaBancoParaMoedaPt } from 'app/helper';
  3. import { FormGroup, Validators, FormControl } from '@angular/forms';
  4. import { PagamentoContratoLocacaoTemporada } from '../../../../domain/entities/pagamentoContratoLocacaoTemporada';
  5. import { ContratoLocacaoTemporadaService } from 'app/services/root/contratoLocacaoTemporada.service';
  6. import { PagamentoContratoLocacaoTemporadaService } from 'app/services/root/pagamentoContratoLocacaoTemporada.service';
  7. import { NgbModalRef, NgbModal } from '@ng-bootstrap/ng-bootstrap';
  8. import { ToastrService } from 'ngx-toastr';
  9. import { Router, ActivatedRoute } from '@angular/router';
  10.  
  11. @Component({
  12. selector: 'app-pagamento-contrato-locacao-temporada',
  13. templateUrl: './pagamento-contrato-locacao-temporada.component.html',
  14. })
  15. export class PagamentoContratoLocacaoTemporadaComponent implements OnInit {
  16.  
  17. @Output() PagamentoContratoLocacaoTemporadaModal = new EventEmitter()
  18. @Output() outPagamentos = new EventEmitter
  19.  
  20. form: FormGroup = this.buildForm()
  21.  
  22.  
  23.  
  24. contratoLocacaoTemporadaId: number
  25. pagamentoContratoLocacaoTemporadaId: number
  26. listaPagamentos = []
  27. tipos = [
  28. "PROPRIETARIO", "FAXINA", "CORRETOR", "IMOBILIARIA", "GERENCIA", "AGENCIADOR"
  29. ]
  30.  
  31. object: PagamentoContratoLocacaoTemporada
  32.  
  33. @ViewChild('content') modal;
  34. modalRef: NgbModalRef;
  35.  
  36. constructor(
  37. private pagamentoContratoLocacaoTemporadaS: PagamentoContratoLocacaoTemporadaService,
  38. private active: ActivatedRoute,
  39. private modalService: NgbModal,
  40. private toastS: ToastrService, ) { }
  41.  
  42. ngOnInit() {
  43.  
  44. }
  45.  
  46. open(pagamentoContratoLocacaoTemporadaId, pagamentos) {
  47. this.object = new PagamentoContratoLocacaoTemporada()
  48. this.pagamentoContratoLocacaoTemporadaId = pagamentoContratoLocacaoTemporadaId
  49. this.listaPagamentos = pagamentos
  50. if (this.pagamentoContratoLocacaoTemporadaId == null) {
  51. this.form.get('tipoPagamentoContratoLocacaoTemporadaId').enable()
  52. this.listaPagamentos = pagamentos
  53. this.modalRef = this.modalService.open(this.modal, { size: 'lg' });
  54. } else {
  55. this.form.get('tipoPagamentoContratoLocacaoTemporadaId').disable()
  56. pagamentos.map((pagamento) => {
  57. if (pagamento.id == pagamentoContratoLocacaoTemporadaId) {
  58. this.pagamentoContratoLocacaoTemporadaId = pagamentoContratoLocacaoTemporadaId
  59. this.object = pagamento
  60. this.object.dataLancamento = tiraHoraDaData(this.object.dataLancamento)
  61. this.object.dataPagamento = tiraHoraDaData(this.object.dataPagamento)
  62. this.formataValores()
  63. this.modalRef = this.modalService.open(this.modal, { size: 'lg' });
  64. }
  65. })
  66. };
  67.  
  68. }
  69.  
  70. close() {
  71. this.pagamentoContratoLocacaoTemporadaId = null
  72. this.object = null
  73. this.modalRef.close()
  74. }
  75.  
  76. change(event) {
  77. this.object.tipoPagamentoContratoLocacaoTemporadaId = event.target.selectedIndex
  78. }
  79.  
  80. moeda(valor) {
  81. return moeda(valor).toString() == '' ? 0 : moeda(valor);
  82. }
  83.  
  84. // validaValores(): boolean {
  85. // this.object.valor = this.object.valorDisplay == "" ||
  86. // this.object.valorDisplay == null ? 0 :
  87. // parseFloat(this.object.valorDisplay.replace(".", "").replace(",", "."))
  88.  
  89. // return true
  90. // }
  91.  
  92. formataValores() {
  93. this.object.valorDisplay = moedaBancoParaMoedaPt(this.object.valor)
  94. console.log(this.object)
  95. }
  96.  
  97. salvar() {
  98. this.object.valor = parseFloat(moedaParaDecimal(this.object.valorDisplay))
  99. if (this.pagamentoContratoLocacaoTemporadaId == null) { //teste para alteração ou inserção
  100. this.listaPagamentos.push(this.object)
  101. this.outPagamentos.emit(this.listaPagamentos)
  102. } else {
  103. this.outPagamentos.emit(this.listaPagamentos)
  104. }
  105. this.close()
  106. }
  107.  
  108. excluir() {
  109. if (this.pagamentoContratoLocacaoTemporadaId != null) {
  110. var index = this.listaPagamentos.indexOf(this.object)
  111. this.listaPagamentos.splice(index, 1)
  112. this.outPagamentos.emit(this.listaPagamentos)
  113. console.log(this.object)
  114. console.log(this.listaPagamentos)
  115. }
  116. this.close()
  117. }
  118.  
  119. buildForm() {
  120. return new FormGroup({
  121. id: new FormControl(''),
  122. contratoLocacaoTemporada: new FormControl(''),
  123. contratoLocacaoTemporadaId: new FormControl(''),
  124. dataLancamento: new FormControl(''),
  125. dataPagamento: new FormControl(''),
  126. tipoPagamentoContratoLocacaoTemporada: new FormControl(''),
  127. tipoPagamentoContratoLocacaoTemporadaId: new FormControl(''),
  128. valor: new FormControl(''),
  129. complemento: new FormControl(''),
  130. })
  131. }
  132.  
  133. // verificaCamposObrigatorios() {
  134.  
  135. // if (this.object.tipoPagamentoContratoLocacaoTemporadaId == 0) {
  136. // this.toastS.error("O campo 'Nome' é obrigatório.")
  137. // return false;
  138. // }
  139.  
  140. // if (this.object.email == null || this.object.email == "") {
  141. // this.toastS.error("O campo 'e-Mail' é obrigatório.")
  142. // return false;
  143. // }
  144.  
  145. // if (this.object.fones.length == 0) {
  146. // this.toastS.error("É necessário cadastrar pelo menos um telefone.")
  147. // return false;
  148. // }
  149.  
  150. // if (this.object.dataInicio == null || this.object.dataInicio.toString() == '') {
  151. // this.toastS.error("O campo 'Data de Início' é obrigatório.")
  152. // return false;
  153. // }
  154.  
  155. // if (this.object.dataFim == null || this.object.dataFim.toString() == '') {
  156. // this.toastS.error("O campo 'Data de Saída' é obrigatório.")
  157. // return false;
  158. // }
  159.  
  160. // if (this.object.moeda == null) {
  161. // this.toastS.error("O campo 'Moeda' é obrigatório.")
  162. // return false;
  163. // }
  164.  
  165. // if (this.object.corretorId == null) {
  166. // this.toastS.error("O campo 'Corretor' é obrigatório.")
  167. // return false;
  168. // }
  169.  
  170. // if (this.object.imovelId == null) {
  171. // this.toastS.error("O campo 'Imóvel' é obrigatório.")
  172. // return false;
  173. // }
  174.  
  175. // return true;
  176. // }
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement