Skip to content

Commit

Permalink
Merge pull request #12 from jogaec22/Dev-JE
Browse files Browse the repository at this point in the history
Dev je: Transformacion de nombres de cabeceras para json data
  • Loading branch information
leoriofrio authored Aug 15, 2020
2 parents a418016 + a9ee865 commit 98ce4f9
Show file tree
Hide file tree
Showing 21 changed files with 419 additions and 119 deletions.
8 changes: 4 additions & 4 deletions src/app/admin/menu/menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ <h2 class="brand-text mb-0">Santillana</h2>
</li>
</ul>
</li>
<li class=" nav-item"><a routerLink="/campaign"><i class="bx bx-grid-alt"></i><span class="menu-title" data-i18n="Kanban">Campañas</span></a>
</li>
<!--<li class=" nav-item"><a routerLink="/campaign"><i class="bx bx-grid-alt"></i><span class="menu-title" data-i18n="Kanban">Campañas</span></a>
</li>-->
<li class=" nav-item"><a routerLink="/product"><i class="bx bx-grid-alt"></i><span class="menu-title" data-i18n="Kanban">Productos</span></a>
</li>
<li class=" nav-item"><a routerLink="/client"><i class="bx bx-grid-alt"></i><span class="menu-title" data-i18n="Kanban">Clientes</span></a>
</li>
<li class=" nav-item"><a routerLink="/college"><i class="bx bx-grid-alt"></i><span class="menu-title" data-i18n="Kanban">Colegios</span></a>
</li>
<li class=" nav-item"><a routerLink="/"><i class="bx bx-check-circle"></i><span class="menu-title" data-i18n="Todo">Precios</span></a>
</li>
<!--<li class=" nav-item"><a routerLink="/"><i class="bx bx-check-circle"></i><span class="menu-title" data-i18n="Todo">Precios</span></a>
</li>-->
</ul>
</div>
</div>
Expand Down
12 changes: 9 additions & 3 deletions src/app/app.keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export namespace ExcelKeys {
export const EXCEL_TITLE_SIZE = 16;
export const EXCEL_TITLE_UNDERLINE = 'none';
export const EXCEL_HEADER_FGCOLOR = '';
export const EXCEL_HEADER_BGCOLOR = '';
export const EXCEL_HEADER_BGCOLOR = '#FFFFFF';
export const EXCEL_DETAIL_CELL = 'cell';
export const EXCEL_DETAIL_METADATA = 'metadata';
export const EXCEL_DETAIL_FIELD = 'field';
Expand All @@ -47,8 +47,8 @@ export namespace ExcelKeys {


export namespace Proform {
export const ID = {prop: 'id', name: 'Id Proforma Interna'};
export const NUMBER_PROFORM = {prop: 'number_proform', name: 'Número Proforma'};
export const ID = {prop: 'id', name: 'Id'};
export const NUMBER_PROFORM = {prop: 'number_proform', name: 'Número'};
export const USER_ID = {prop: 'user_id', name: 'Vendedor'};
export const COLLEGE_ID = {prop: 'college_id', name: 'Colegios'};
export const CLIENT_ID = {prop: 'client_id', name: 'Clientes'};
Expand Down Expand Up @@ -77,6 +77,7 @@ export namespace ProformDetail {
export const SALE_SCHOLARSHIPS = {prop: 'sale_scholarships', name: 'Becas PLANTEL'};
export const SALE_STAFF = {prop: 'sale_staff', name: 'Equipos PLANTEL'};
export const SALE_TRAINING = {prop: 'sale_training', name: 'Capacitación PLANTEL'};
export const CAPEX = {prop: 'capex', name: 'Beneficio'};
export const TOTAL = {prop: 'total', name: 'Total'};
}

Expand Down Expand Up @@ -211,4 +212,9 @@ export const FilesType = {

export const ValidatesPattern = {
alphanumeric: "[a-zA-Z0-9\\s]+"
}

export declare interface TransformColumns {

namesToProps(json): any;
}
20 changes: 19 additions & 1 deletion src/app/app.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,26 @@ export type GridRecord = {
sale_scholarships: 0,
sale_staff: 0,
sale_training: 0,
capex: 0,
proform_id: 0,
product_id: 0
};

export interface PROFORM_SUMMARY {
quantity: 0,
subtotal:0,
sale_direct: 0,
sale_external_library: 0,
sale_event: 0,
sale_teacher: 0,
sale_infrastructure: 0,
sale_scholarships: 0,
sale_staff: 0,
sale_training: 0,
capex:0,
total:0,
};

export const MODEL_DETAIL = {
"id": 0,
"degree": "string",
Expand All @@ -78,7 +94,8 @@ export type GridRecord = {
"sale_infrastructure": 0,
"sale_scholarships": 0,
"sale_staff": 0,
"sale_training": 0
"sale_training": 0,
"capex": 0
};


Expand All @@ -95,6 +112,7 @@ export type GridRecord = {
"sale_scholarships": 0,
"sale_staff": 0,
"sale_training": 0,
"capex": 0,
"proform_id": 0,
"product_id": 0
};
Expand Down
21 changes: 19 additions & 2 deletions src/app/configuration/client/client.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import { Component, OnInit, ViewChild } from '@angular/core';
import { ClientColumns } from '../../app.keys';
import { ClientColumns, TransformColumns } from '../../app.keys';
import { COLUMNS_CLIENT } from './clientColumns';
import { ProjectComponent } from '../../shared/components/project/project.component';
import { ExcelExportService } from '../../shared/service/export-excel.service';
Expand All @@ -14,7 +14,7 @@ const dataVal = require('./client.json');
templateUrl: './client.component.html',
styleUrls: ['./client.component.scss']
})
export class ClientComponent implements OnInit {
export class ClientComponent implements OnInit, TransformColumns {
@ViewChild(ProjectComponent, { static: true }) child: ProjectComponent;

public data = dataVal;
Expand Down Expand Up @@ -48,6 +48,23 @@ export class ClientComponent implements OnInit {

public onJsonData(jsonData) {
console.log('data de Cliente es', jsonData);
let jsonFinal = this.namesToProps(jsonData);
console.log('jsonFinal', jsonFinal);
}

public namesToProps(json){
return json.map(key => {
let res = {};
res[`${ClientColumns.ID.prop}`] = key[ClientColumns.ID.name];
res[`${ClientColumns.COD_CLIENT.prop}`] = key[ClientColumns.COD_CLIENT.name];
res[`${ClientColumns.PROVINCE.prop}`] = key[ClientColumns.PROVINCE.name];
res[`${ClientColumns.CITY.prop}`] = key[ClientColumns.CITY.name];
res[`${ClientColumns.NAME.prop}`] = key[ClientColumns.NAME.name];
res[`${ClientColumns.NICKNAME.prop}`] = key[ClientColumns.NICKNAME.name];
res[`${ClientColumns.TYPE.prop}`] = key[ClientColumns.TYPE.name];
res[`${ClientColumns.STATUS.prop}`] = key[ClientColumns.STATUS.name];
return res;
});
}

}
32 changes: 30 additions & 2 deletions src/app/configuration/colleges/colleges.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import { Component, OnInit, ViewChild } from '@angular/core';
import { ClientColumns } from '../../app.keys';
import { ClientColumns, CollegesColumns } from '../../app.keys';
import { COLUMNS_COLLEGES } from './collegesColumns';
import { ProjectComponent } from '../../shared/components/project/project.component';
import { ExcelExportService } from '../../shared/service/export-excel.service';
Expand All @@ -14,7 +14,7 @@ const dataVal = require('./colleges.json');
templateUrl: './colleges.component.html',
styleUrls: ['./colleges.component.css']
})
export class CollegesComponent implements OnInit {
export class CollegesComponent implements OnInit, TransformColumns {
@ViewChild(ProjectComponent, {static: true}) child: ProjectComponent;

public data = dataVal;
Expand Down Expand Up @@ -46,6 +46,34 @@ export class CollegesComponent implements OnInit {

public onJsonData(jsonData){
console.log('data de Colleges es', jsonData);
let jsonFinal = this.namesToProps(jsonData);
console.log('jsonFinal', jsonFinal);
}

public namesToProps(json){
return json.map(key => {
let res = {};
res[`${CollegesColumns.ID.prop}`] = key[CollegesColumns.ID.name];
res[`${CollegesColumns.COD_SANTILLANA.prop}`] = key[CollegesColumns.COD_SANTILLANA.name];
res[`${CollegesColumns.COD_INSTITUTO.prop}`] = key[CollegesColumns.COD_INSTITUTO.name];
res[`${CollegesColumns.STATUS.prop}`] = key[CollegesColumns.STATUS.name];
res[`${CollegesColumns.DELEGATE_TEXT.prop}`] = key[CollegesColumns.DELEGATE_TEXT.name];
res[`${CollegesColumns.DELEGATE_ENGLISH.prop}`] = key[CollegesColumns.DELEGATE_ENGLISH.name];
res[`${CollegesColumns.DELEGATE_SHARED.prop}`] = key[CollegesColumns.DELEGATE_SHARED.name];
res[`${CollegesColumns.PROVINCE.prop}`] = key[CollegesColumns.PROVINCE.name];
res[`${CollegesColumns.CANTON.prop}`] = key[CollegesColumns.CANTON.name];
res[`${CollegesColumns.PARISH.prop}`] = key[CollegesColumns.PARISH.name];

res[`${CollegesColumns.NAME.prop}`] = key[CollegesColumns.NAME.name];
res[`${CollegesColumns.ADDRESS.prop}`] = key[CollegesColumns.ADDRESS.name];
res[`${CollegesColumns.NIVEL.prop}`] = key[CollegesColumns.NIVEL.name];
res[`${CollegesColumns.TYPE.prop}`] = key[CollegesColumns.TYPE.name];
res[`${CollegesColumns.SCHOOL_SYSTEM.prop}`] = key[CollegesColumns.SCHOOL_SYSTEM.name];
res[`${CollegesColumns.MODALITY.prop}`] = key[CollegesColumns.MODALITY.name];
res[`${CollegesColumns.SCHOOL_DAY.prop}`] = key[CollegesColumns.SCHOOL_DAY.name];
res[`${CollegesColumns.REGION_ID.prop}`] = key[CollegesColumns.REGION_ID.name];
return res;
});
}

}
51 changes: 41 additions & 10 deletions src/app/configuration/product/product.component.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
'use strict';

import { Component, OnInit, ViewChild } from '@angular/core';
import { ProductColumns } from '../../app.keys';
import { ProductColumns, TypeRegion, TransformColumns } from '../../app.keys';
import { ProjectComponent } from '../../shared/components/project/project.component';
import { COLUMNS_PRODUCT, COLUMNS_PINNED_TOP_DATA } from './productColumns';
import { ExcelExportService } from '../../shared/service/export-excel.service';
import * as _ from 'lodash';
import { ProductService } from 'src/app/shared/service/product.service';


const dataVal = require('./product.json');
//const dataVal = require('./product.json');

@Component({
selector: 'app-product',
templateUrl: './product.component.html',
styleUrls: ['./product.component.css']
styleUrls: ['./product.component.scss']
})
export class ProductComponent implements OnInit {
export class ProductComponent implements OnInit, TransformColumns {
@ViewChild(ProjectComponent, {static: true}) child: ProjectComponent;


public data = dataVal;
public data: any; //dataVal;
public gridColumns = COLUMNS_PRODUCT;
public enabledTitle: boolean;
public allowExcelExport: boolean;
public val: string;
public pinnedTopRowDataVal: any;
public pinnedBottomRowDataVal: any;
public defaultColDefVal: any;


constructor(private excelExportService: ExcelExportService) {

constructor(
private excelExportService: ExcelExportService,
private productService: ProductService,
) {
const self = this;
this.getDataProduct().subscribe(data => {
self.data = data;
});
}

ngOnInit() {
Expand Down Expand Up @@ -71,8 +78,32 @@ export class ProductComponent implements OnInit {
}
}

public onJsonData(jsonData){
console.log('data de Producto es', jsonData);
public onJsonData(jsonData){
console.log('data de Producto es', JSON.stringify(jsonData));
let jsonFinal = this.namesToProps(jsonData);
console.log('jsonFinal', jsonFinal);
return this.productService.createProduct('1', JSON.stringify(jsonFinal));
}

public getDataProduct() {
return this.productService.getProductByRegion(TypeRegion.SIERRA);
}

public namesToProps(json){
return json.map(key => {
let res = {};
res[`${ProductColumns.ID.prop}`] = key[ProductColumns.ID.name];
res[`${ProductColumns.COD.prop}`] = key[ProductColumns.COD.name];
res[`${ProductColumns.SUBLINE.prop}`] = key[ProductColumns.SUBLINE.name];
res[`${ProductColumns.DESCRIPTION.prop}`] = key[ProductColumns.DESCRIPTION.name];
res[`${ProductColumns.SERIE.prop}`] = key[ProductColumns.SERIE.name];
res[`${ProductColumns.NIVEL.prop}`] = key[ProductColumns.NIVEL.name];
res[`${ProductColumns.DEGREE.prop}`] = key[ProductColumns.DEGREE.name];
res[`${ProductColumns.BUSINESS_LINE.prop}`] = key[ProductColumns.BUSINESS_LINE.name];
res[`${ProductColumns.ISBN.prop}`] = key[ProductColumns.ISBN.name];
res[`${ProductColumns.REGION.prop}`] = key[ProductColumns.REGION.name];
return res;
});
}

}
4 changes: 2 additions & 2 deletions src/app/shared/components/grid/grid.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<button type="submit" class="btn btn-primary submit-button" (click)="add()">Añadir</button>

<div id="example" class="hot handsontable htColumnHeaders" #container>
<div id="example" class="hot handsontable htColumnHeaders" #container>

</div>

<!--<button class="btn" (click)="addCalc()">Add Calculation</button>-->


15 changes: 11 additions & 4 deletions src/app/shared/components/grid/grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class GridComponent implements OnInit, OnDestroy {
public hot: Handsontable;

private setter = false;
public addProform: boolean = false;

constructor() { }

Expand All @@ -39,7 +40,7 @@ export class GridComponent implements OnInit, OnDestroy {
let varField: any;
let varRow: any;

const containerVal = this.container.nativeElement;
//const containerVal = this.container.nativeElement;
var container = document.getElementById('example');

this.hot = new Handsontable(container, {
Expand Down Expand Up @@ -94,7 +95,8 @@ export class GridComponent implements OnInit, OnDestroy {
case 'sale_infrastructure':
case 'sale_scholarships':
case 'sale_staff':
case 'sale_training':{
case 'sale_training':
case 'capex':{

varRow = 0;

Expand All @@ -109,6 +111,7 @@ export class GridComponent implements OnInit, OnDestroy {
varRow = (row[1] === 'sale_scholarships' && varRow === 0 ) ? varRow = 12 : varRow = varRow;
varRow = (row[1] === 'sale_staff' && varRow === 0 ) ? varRow = 13 : varRow = varRow;
varRow = (row[1] === 'sale_training' && varRow === 0 ) ? varRow = 14 : varRow = varRow;
varRow = (row[1] === 'capex' && varRow === 0 ) ? varRow = 15 : varRow = varRow;

this.setDataAtCell(row[0], varRow, Number(varField) );

Expand All @@ -123,6 +126,7 @@ export class GridComponent implements OnInit, OnDestroy {
let sale_scholarships;
let sale_staff;
let sale_training;
let capex;

sale_direct = _.isNil(this.getDataAtCell(row[0],7)) ? sale_direct = 0 : sale_direct = Number(this.getDataAtCell(row[0],7));
sale_external_library = _.isNil(this.getDataAtCell(row[0],8)) ? sale_external_library = 0 : sale_external_library = Number(this.getDataAtCell(row[0],8));
Expand All @@ -132,12 +136,13 @@ export class GridComponent implements OnInit, OnDestroy {
sale_scholarships = _.isNil(this.getDataAtCell(row[0],12)) ? sale_scholarships = 0 : sale_scholarships = Number(this.getDataAtCell(row[0],12));
sale_staff = _.isNil(this.getDataAtCell(row[0],13)) ? sale_staff = 0 : sale_staff = Number(this.getDataAtCell(row[0],13));
sale_training = _.isNil(this.getDataAtCell(row[0],14)) ? sale_training = 0 : sale_training = Number(this.getDataAtCell(row[0],14));
capex = _.isNil(this.getDataAtCell(row[0],15)) ? capex = 0 : capex = Number(this.getDataAtCell(row[0],15));

let total_descount = sale_direct + sale_external_library + sale_event + sale_teacher + sale_infrastructure + sale_scholarships + sale_staff + sale_training;
let total_descount = sale_direct + sale_external_library + sale_event + sale_teacher + sale_infrastructure + sale_scholarships + sale_staff + sale_training + capex;
let total = Number(this.getDataAtCell(row[0],6)) - ( Number(this.getDataAtCell(row[0],6)) * total_descount / 100 );


this.setDataAtCell(row[0], 15, total );
this.setDataAtCell(row[0], 16, total );
break;
}
}
Expand Down Expand Up @@ -204,6 +209,8 @@ export class GridComponent implements OnInit, OnDestroy {
}

public add() {
this.addProform = false;
this.addProform = true;
this.hot.alter('insert_row', 0);
}

Expand Down
1 change: 1 addition & 0 deletions src/app/shared/service/import-excel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ export class ExcelImportService {
}
});
}

}
6 changes: 6 additions & 0 deletions src/app/shared/service/product.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ export class ProductService {
const url = this.baseUrl+`product/`+region.toString();
return this.http.get<any>(url);
}

public createProduct(id: string, product: any): Observable<any> {
debugger;
const url = this.baseUrl+`product/Sierra`;
return this.http.post<any>(url, product, httpOptions);
}
}
5 changes: 5 additions & 0 deletions src/app/shared/service/proform.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export class ProformService {
return this.http.post<any>(url, proformDetail, httpOptions);
}

public updateProformDetail(id: string, proformDetail: any): Observable<any> {
const url = this.baseUrl+`proform/`+id.toString()+`/proformDetail/edit`;
return this.http.patch<any>(url, proformDetail, httpOptions);
}



}
Loading

0 comments on commit 98ce4f9

Please sign in to comment.