Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
  2. import { Catalogo } from 'src/app/models/catalogo';
  3. import { ClaseService } from 'src/app/services/clase.service';
  4. import { Clase } from 'src/app/models/clase';
  5. import { Transaccion } from 'src/app/models/transaccion';
  6. import { Cuenta } from 'src/app/models/cuenta';
  7. import { CuentaService } from 'src/app/services/cuenta.service';
  8.  
  9. export interface CuentaTable {
  10. cuenta: string;
  11. debe: number;
  12. haber: number;
  13. }
  14.  
  15. @Component({
  16. selector: 'app-crear-partida',
  17. templateUrl: './crear-partida.component.html',
  18. styleUrls: ['./crear-partida.component.css'],
  19. providers: [ClaseService, CuentaService]
  20. })
  21.  
  22.  
  23. export class CrearPartidaComponent implements OnInit {
  24. //Titulos
  25. public title: string;
  26. public subtitle: string;
  27. //Declarar modelos
  28. public register_transaccion: Transaccion;
  29. public clase: Clase;
  30. public cuenta: Cuenta;
  31. //Tabla
  32. public CUENTAS_DATA: CuentaTable[];
  33. //Filas a indexar
  34. public newRow;
  35. //Variables para debe y haber
  36. public debe: number;
  37. public haber: number;
  38.  
  39. constructor(
  40. private _claseService: ClaseService,
  41. private _cuentaService: CuentaService,
  42. ) {
  43. this.title = 'Nueva Partida'
  44. this.subtitle = 'Partida'
  45. this.register_transaccion = new Transaccion('', '', '', null, null, null);
  46. this.CUENTAS_DATA = [];
  47. this.newRow = new Array();
  48. }
  49.  
  50. ngOnInit() {
  51. console.log(this.CUENTAS_DATA)
  52. }
  53.  
  54. getDebeHaber() {
  55. if(this.register_transaccion.saldo == 0) {
  56. if(this.register_transaccion.transaccion == 0) {
  57. this.debe = this.register_transaccion.monto;
  58. this.haber = 0;
  59. } else {
  60. this.debe = 0;
  61. this.haber = this.register_transaccion.monto;
  62. }
  63. } else {
  64. if(this.register_transaccion.transaccion == 1) {
  65. this.debe = this.register_transaccion.monto;
  66. this.haber = 0;
  67. } else {
  68. this.debe = 0;
  69. this.haber = this.register_transaccion.monto;
  70. }
  71. }
  72. }
  73.  
  74. addToTable() {
  75. let codigo = this.register_transaccion.codigo
  76. this.getClase(codigo.substring(0,1));
  77. switch(this.register_transaccion.codigo.length) {
  78. case 3:
  79. this.getCuenta(codigo);
  80. break;
  81. case 5:
  82. break;
  83. case 7:
  84. break;
  85. }
  86. this.getDebeHaber();
  87. this.newRow = {
  88. codigo: codigo,
  89. cuenta: this.register_transaccion.cuenta,
  90. debe: this.debe,
  91. haber: this.haber
  92. };
  93. this.CUENTAS_DATA.push(this.newRow);
  94. console.log(this.CUENTAS_DATA)
  95. console.log(this.register_transaccion.saldo)
  96. }
  97.  
  98. getClase(id: string) {
  99. this._claseService.getClase(id).subscribe(
  100. response => {
  101. if(!response.clase) {
  102. //this._router.navigate(['/']);
  103. } else {
  104. this.clase = response.clase
  105. this.register_transaccion.saldo = this.clase.saldo;
  106. }
  107. },
  108. error => {
  109. var errorMessage = <any>error
  110.  
  111. if(errorMessage != null) {
  112. var body = JSON.parse(error._body);
  113. console.log(error);
  114. }
  115. }
  116. )
  117. }
  118. getCuenta(id: string){
  119. this._cuentaService.getCuenta(id).subscribe(
  120. response => {
  121. if(!response.cuenta) {
  122. //this._router.navigate(['/']);
  123. } else {
  124. this.cuenta = response.cuenta;
  125. this.register_transaccion._id = this.cuenta._id;
  126. this.register_transaccion.codigo = this.cuenta.codigo;
  127. this.register_transaccion.cuenta = this.cuenta.cuenta;
  128. }
  129. },
  130. error => {
  131. var errorMessage = <any>error
  132.  
  133. if(errorMessage != null) {
  134. var body = JSON.parse(error._body);
  135. console.log(error);
  136. }
  137. }
  138. )
  139. }
  140. }
  141.  
  142. <h1>{{title}}</h1>
  143. <mat-card>
  144. <form autocomplete="off" class="input-form" #inputForm="ngForm" (ngSubmit)="addToTable()">
  145. <mat-form-field>
  146. <input type="text" matInput placeholder="Código de Cuenta" #codigo="ngModel" name="codigo" [(ngModel)]="register_transaccion.codigo">
  147. </mat-form-field>
  148. <mat-form-field>
  149. <input type="number" matInput placeholder="Monto $" min="0" step="0.01" #monto="ngModel" name="monto" [(ngModel)]="register_transaccion.monto" value="0">
  150. </mat-form-field>
  151. <mat-form-field>
  152. <input type="number" matInput placeholder="Transacción" #transaccion="ngModel" name="transaccion" [(ngModel)]="register_transaccion.transaccion" min="0" max="1" value="0">
  153. <mat-hint><i>0: Ingreso / 1: Egreso</i></mat-hint>
  154. </mat-form-field>
  155. <button mat-raised-button class="submit-button" type="submit" color="primary">Agregar</button>
  156. </form>
  157. </mat-card>
  158.  
  159. getCuenta(id: string){
  160. this._cuentaService.getCuenta(id).subscribe(
  161. response => {
  162. if(!response.cuenta) {
  163. //this._router.navigate(['/']);
  164. } else {
  165. this.cuenta = response.cuenta;
  166. this.register_transaccion._id = this.cuenta._id;
  167. this.setValues(this.cuenta.codigo, this.cuenta.cuenta);
  168. }
  169. },
  170. error => {
  171. var errorMessage = <any>error
  172.  
  173. if(errorMessage != null) {
  174. var body = JSON.parse(error._body);
  175. console.log(error);
  176. }
  177. }
  178. )
  179. }
  180.  
  181. //Set valores de cuentas
  182. setValues(codigo: string, cuenta: string) {
  183. this.register_transaccion.codigo = codigo;
  184. this.register_transaccion.cuenta = cuenta;
  185. this.getDebeHaber();
  186. this.newRow = {
  187. codigo: codigo,
  188. cuenta: this.register_transaccion.cuenta,
  189. debe: this.debe,
  190. haber: this.haber
  191. };
  192. this.CUENTAS_DATA.push(this.newRow);
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement