Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cuenta bancaria #129

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/app/@core/helpers/giros/girosHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
import { RequestManager } from '../../managers/requestManager';

@Injectable({
providedIn: 'root',
})
export class GirosHelper {
constructor(private rqManager: RequestManager) {}

// Terceros

public getCuentasBancarias(parameters?: { id?: any, query?: any, fields?: string[], sortby?: string[], order?: string[], limit?: number, offset?: number }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se observa que { id?: any, query?: any, fields?: string[], sortby?: string[], order?: string[], limit?: number, offset?: number } se repite en varias partes.
Guardar esta estructura como un nuevo modelo de datos, por ejemplo, algo como BeegoQueryParams:

interface BeegoQueryParams {
  id?: string; // evitar el any
  query?: string; // evitar el any
  fields?: string[];
  sortby?: string[];
  order?: string[];
  limit?: number;
  offset?: number;
}
...
export {..., BeegoQueryParams};

De tal manera que el getCuentasBancarias (y dondesea que se use esta misma estructura) se pueda reescribir como

import {BeegoQueryParams} from '...';
...
public getCuentasBancarias(parameters?: BeegoQueryParams){...}

(Si no funciona con interface usar simplemente class)

this.rqManager.setPath('GIROS_CRUD_SERVICE');
return this.rqManager.getv2('cuenta_bancaria', parameters);
}

public createCuentaBancaria(element: any) {
this.rqManager.setPath('GIROS_CRUD_SERVICE');
return this.rqManager.post('cuenta_bancaria/', element);
}

public updateCuentaBancaria(id: number, element: any) {
this.rqManager.setPath('GIROS_CRUD_SERVICE');
return this.rqManager.put('cuenta_bancaria/', element, id);
}

}
43 changes: 43 additions & 0 deletions src/app/@core/helpers/terceros/tercerosHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Injectable } from '@angular/core';
import { RequestManager } from '../../managers/requestManager';

@Injectable({
providedIn: 'root',
})
export class TercerosHelper {
constructor(private rqManager: RequestManager) {}

// Tercero

public getTerceros(parameters?: { id?: any, query?: any, fields?: string[], sortby?: string[], order?: string[], limit?: number, offset?: number }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ver lo comentado en src/app/@core/helpers/giros/girosHelper.ts

this.rqManager.setPath('TERCEROS_CRUD_SERVICE');
return this.rqManager.getv2('tercero', parameters);
}

public createTercero(element: any) {
this.rqManager.setPath('TERCEROS_CRUD_SERVICE');
return this.rqManager.post('tercero/', element);
}

public updateTercero(id: number, element: any) {
this.rqManager.setPath('TERCEROS_CRUD_SERVICE');
return this.rqManager.put('tercero/', element, id);
}

// Tercero_tipo_tercero
public getTerceroTipoTercero(parameters?: { id?: any, query?: any, fields?: string[], sortby?: string[], order?: string[], limit?: number, offset?: number }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ver lo comentado en src/app/@core/helpers/giros/girosHelper.ts

this.rqManager.setPath('TERCEROS_CRUD_SERVICE');
return this.rqManager.getv2('tercero_tipo_tercero', parameters);
}

public createTerceroTipoTercero(element: any) {
this.rqManager.setPath('TERCEROS_CRUD_SERVICE');
return this.rqManager.post('tercero_tipo_tercero/', element);
}

public updateTerceroTipoTercero(id: number, element: any) {
this.rqManager.setPath('TERCEROS_CRUD_SERVICE');
return this.rqManager.put('tercero_tipo_tercero/', element, id);
}

}
17 changes: 17 additions & 0 deletions src/app/@core/helpers/tesoreria/tesoreriaHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Injectable } from '@angular/core';
import { RequestManager } from '../../managers/requestManager';

@Injectable({
providedIn: 'root',
})
export class TesoreriaHelper {
constructor(private rqManager: RequestManager) {}

// tesoreria_mid

public getCuentasBancarias(parameters?: { id?: any, limit?: number, offset?: number }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posiblemente se pueda hacer algo similar a lo comentado en src/app/@core/helpers/giros/girosHelper.ts

this.rqManager.setPath('TESORERIA_MID_SERVICE');
return this.rqManager.getv2('cuenta_bancaria_banco', parameters);
}

}
46 changes: 43 additions & 3 deletions src/app/@core/managers/requestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export class RequestManager {
private path: string;
public httpOptions: any;
constructor(private http: HttpClient, private errManager: HttpErrorManager) {
this.initHttpOptions();
}

/**
* Set http options to initial state
*/
private initHttpOptions() {
this.httpOptions = {
headers: new HttpHeaders({
'Accept': 'application/json',
Expand All @@ -25,7 +32,6 @@ export class RequestManager {
};
}


/**
* Use for set the source path of the service (service's name must be present at src/app/app-config.ts)
* @param service: string
Expand All @@ -34,6 +40,37 @@ export class RequestManager {
this.path = environment[service];
}

/**
*
* @param endpoint service's end-point
* @param id object id
* @param query (a Key, Value object with que query params for the request)
* @param fields array of strings with field names
* @param sortby array of strings with field names
* @param order array of strings with asc, desc for each sortby field names
* @param limit Limit the size of result set. Must be an integer
* @param offset Start position of result set. Must be an integer
* @returns
*/
getv2(endpoint: string, parameters?: { id?: any, query?: any, fields?: string[], sortby?: string[], order?: string[], limit?: number, offset?: number }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ver lo comentado en src/app/@core/helpers/giros/girosHelper.ts respecto a parameters

const params = {};
const id = parameters ? parameters.id : undefined;
if (parameters) {
if (parameters.query) {
let queryParams = '';
for (const [key, value] of Object.entries(parameters.query))
queryParams += `${key}:${value},`;
queryParams = queryParams.substr(0, queryParams.length - 1);
params['query'] = queryParams;
}
if (parameters.fields) params['fields'] = parameters.fields.join(',');
if (parameters.sortby) params['sortby'] = parameters.sortby.join(',');
if (parameters.order) params['order'] = parameters.order;
if (parameters.limit !== null && parameters.limit !== undefined) params['limit'] = parameters.limit;
if (parameters.offset != null && parameters.offset !== undefined) params['offset'] = parameters.offset;
}
return this.get(endpoint + (id ? `/${id}` : ''), params);
}

/**
* Perform a GET http request
Expand All @@ -42,10 +79,10 @@ export class RequestManager {
* @returns Observable<any>
*/
get(endpoint, params?) {
const queryParams = new HttpParams();
let queryParams = new HttpParams();
if (params) {
for (const [key, value] of Object.entries(params)) {
queryParams.append(key, value + '');
queryParams = queryParams.append(key, value + '');
}

}
Expand Down Expand Up @@ -76,6 +113,7 @@ export class RequestManager {
* @returns Observable<any>
*/
post(endpoint, element) {
this.initHttpOptions();
return this.http.post<any>(`${this.path}${endpoint}`, element, this.httpOptions).pipe(
catchError(this.errManager.handleError),
map(
Expand All @@ -98,6 +136,7 @@ export class RequestManager {
* @returns Observable<any>
*/
put(endpoint, element, id) {
this.initHttpOptions();
return this.http.put<any>(`${this.path}${endpoint}${id}`, JSON.stringify(element), this.httpOptions).pipe(
catchError(this.errManager.handleError),
);
Expand All @@ -110,6 +149,7 @@ export class RequestManager {
* @returns Observable<any>
*/
putParams(endpoint, element) {
this.initHttpOptions();
return this.http.put<any>(`${this.path}${endpoint}`, element, this.httpOptions).pipe(
catchError(this.errManager.handleError),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FormManager } from '../../@core/managers/formManager';
import { FORM_NODO_CUENTA_CONTABLE } from './form_nodo_cuenta_contable';
import { TranslateService } from '@ngx-translate/core';
import { PopUpManager } from '../../@core/managers/popUpManager';
import { TesoreriaHelper } from '../../@core/helpers/tesoreria/tesoreriaHelper';

registerLocaleData(locales, 'co');

Expand Down Expand Up @@ -87,13 +88,13 @@ export class ArbolCuentasContablesComponent implements OnInit, OnChanges {
private translate: TranslateService,
private pUpManager: PopUpManager,
// private rubroHelper: RubroHelper,
private tesoreriaHelper: TesoreriaHelper,
) {
}

ngOnInit() {

this.loadTree();

this.formData = FORM_NODO_CUENTA_CONTABLE;
this.nodeData = undefined;
this.construirForm();
Expand All @@ -109,6 +110,7 @@ export class ArbolCuentasContablesComponent implements OnInit, OnChanges {
const tipoMonedaIndex = FormManager.getIndexForm(this.formData, 'MonedaID');
const detalleCuentaIndex = FormManager.getIndexForm(this.formData, 'DetalleCuentaID');
const centroCostosIndex = FormManager.getIndexForm(this.formData, 'CentroDecostosID');
const cuentaBancariaIndex = FormManager.getIndexForm(this.formData, 'CuentaBancariaID');

this.treeHelper.getNaturalezaCuenta().subscribe(res => {
this.formData.campos[naturalezaIndex].opciones = res;
Expand All @@ -126,6 +128,13 @@ export class ArbolCuentasContablesComponent implements OnInit, OnChanges {
this.formData.campos[centroCostosIndex].opciones = res;
});

// Cuentas bancarias
this.tesoreriaHelper.getCuentasBancarias().subscribe(res => {
if (res && res.Data) {
this.formData.campos[cuentaBancariaIndex].opciones = res.Data.map(
c => ({ Id: c.Id, Label: c.NumeroCuenta + ' - ' + c.NombreBanco + ' - ' + c.NombreSucursal }));
}
});

}
ngOnChanges(changes) {
Expand Down Expand Up @@ -281,6 +290,7 @@ export class ArbolCuentasContablesComponent implements OnInit, OnChanges {
nodeData['CodigoCuentaAlterna'] = this.cuentaAlterna !== null ? this.cuentaAlterna.replaceAll('-', '') : null;
nodeData['Codigo'] = nodeData['Codigo'] + '';
nodeData['Activo'] = nodeData['Activa']['Id'];
nodeData['CuentaBancariaID'] = nodeData['CuentaBancariaID']['Id'];
if (this.selectedNodeData) {
nodeData['Padre'] = this.selectedNodeData['Codigo'];
}
Expand Down Expand Up @@ -345,6 +355,7 @@ export class ArbolCuentasContablesComponent implements OnInit, OnChanges {
const tipoMonedaIndex = FormManager.getIndexForm(this.formData, 'MonedaID');
const detalleCuentaIndex = FormManager.getIndexForm(this.formData, 'DetalleCuentaID');
const centroCostosIndex = FormManager.getIndexForm(this.formData, 'CentroDecostosID');
const cuentaBancariaIndex = FormManager.getIndexForm(this.formData, 'CuentaBancariaID');
this.nodeData['DetalleCuentaID'] = this.formData.campos[detalleCuentaIndex].opciones.find(element => element.Id === this.nodeData['DetalleCuentaID']);
this.nodeData['CentroDecostosID'] = this.formData.campos[centroCostosIndex].opciones.find(element => element.Id === this.nodeData['CentroDecostosID']);
this.nodeData['MonedaID'] = this.formData.campos[tipoMonedaIndex].opciones.find(element => element.Id === this.nodeData['MonedaID']);
Expand All @@ -355,6 +366,7 @@ export class ArbolCuentasContablesComponent implements OnInit, OnChanges {
this.nodeData['CuentaAlterna'] =
this.nodeData['CodigoCuentaAlterna'] !== null && this.nodeData['CodigoCuentaAlterna'] !== '' ? { Label: 'Si', Id: true } : { Label: 'No', Id: false };
this.nodeData['Activa'] = this.nodeData['Activo'] === true ? { Label: 'Si', Id: true } : { Label: 'No', Id: false };
this.nodeData['CuentaBancariaID'] = this.formData.campos[cuentaBancariaIndex].opciones.find(element => element.Id === this.nodeData['CuentaBancariaID']);
});
}

Expand Down
12 changes: 12 additions & 0 deletions src/app/pages/arbol-cuentas-contables/form_nodo_cuenta_contable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,17 @@ export let FORM_NODO_CUENTA_CONTABLE = {
unActiveData,
],
},

{
etiqueta: 'select',
claseGrid: 'col-md-12',
nombre: 'CuentaBancariaID',
label_i18n: 'Cuenta bancaria',
placeholder_i18n: 'Cuenta bancaria',
requerido: true,
tipo: 'Cuenta',
key: 'Label',
opciones: [],
},
],
};
1 change: 1 addition & 0 deletions src/environments/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const environment = {
PLAN_CUENTAS_MONGO_SERVICE: 'https://autenticacion.portaloas.udistrital.edu.co/apioas/plan_cuentas_mongo_crud/v1/',
CUENTAS_CONTABLES_SERVICE: 'https://autenticacion.portaloas.udistrital.edu.co/apioas/cuentas_contables_crud/v1/',
CONFIGURACION_SERVICE: 'https://autenticacion.portaloas.udistrital.edu.co/apioas/configuracion_crud_api/v1/',
TESORERIA_MID_SERVICE: 'http://pruebasapi2.intranetoas.udistrital.edu.co:8214/v1/',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revisar lo comentado en src/environments/environment.ts

CONF_MENU_SERVICE: 'https://autenticacion.portaloas.udistrital.edu.co/apioas/configuracion_crud_api/v1/menu_opcion_padre/ArbolMenus/',
TOKEN: {
AUTORIZATION_URL: 'https://autenticacion.portaloas.udistrital.edu.co/oauth2/authorize',
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const environment = {
WSO2_SERVICE: 'https://autenticacion.portaloas.udistrital.edu.co/apioas/',
PLAN_CUENTAS_MONGO_SERVICE: 'https://autenticacion.portaloas.udistrital.edu.co/apioas/plan_cuentas_mongo_crud/v1/',
CUENTAS_CONTABLES_SERVICE: 'https://autenticacion.portaloas.udistrital.edu.co/apioas/cuentas_contables_crud/v1/',
TESORERIA_MID_SERVICE: 'http://pruebasapi2.intranetoas.udistrital.edu.co:8214/v1/',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Esto solo funcionaría bajo VPN, no se encuentra desplegado?
  • Ajustar no solo acá sino en el .test.ts y en el .prod.ts

CONFIGURACION_SERVICE: 'https://autenticacion.portaloas.udistrital.edu.co/apioas/configuracion_crud_api/v1/',
CONF_MENU_SERVICE: 'https://autenticacion.portaloas.udistrital.edu.co/apioas/configuracion_crud_api/v1/menu_opcion_padre/ArbolMenus/',
TOKEN: {
Expand Down