-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6e1f26
commit ca197e2
Showing
10 changed files
with
185 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
<content > | ||
|
||
<!-- BEGIN: Content--> | ||
<div class="app-content content"> | ||
<div class="content-overlay"></div> | ||
<div class="content-wrapper"> | ||
<div class="content-header row">Precios | ||
</div> | ||
<div class="content-body"> | ||
<app-project [gridColumns]="gridColumns" [data]="data" [enabledTitleOp] = "enabledTitle" | ||
[allowExcelExportOp] = "allowExcelExport" | ||
(exportExcel)= "onExportExcel($event)" | ||
(emitJsonData)="onJsonData($event)"></app-project> | ||
</div> | ||
</div> | ||
</div> | ||
<!-- END: Content--> | ||
|
||
</content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { PriceComponent } from './price.component'; | ||
|
||
describe('PriceComponent', () => { | ||
let component: PriceComponent; | ||
let fixture: ComponentFixture<PriceComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ PriceComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(PriceComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
'use strict'; | ||
|
||
import { Component, OnInit, ViewChild } from '@angular/core'; | ||
import { ClientColumns, PriceColumns, TransformColumns, TypeRegion } from '../../app.keys'; | ||
import { COLUMNS_PRICE } from './priceColumns'; | ||
import { ProjectComponent } from '../../shared/components/project/project.component'; | ||
import { ExcelExportService } from '../../shared/service/export-excel.service'; | ||
import * as _ from 'lodash'; | ||
import { forkJoin } from 'rxjs'; | ||
import { PriceService } from 'src/app/shared/service/price.service'; | ||
import { Router } from '@angular/router'; | ||
|
||
@Component({ | ||
selector: 'app-price', | ||
templateUrl: './price.component.html', | ||
styleUrls: ['./price.component.css'] | ||
}) | ||
export class PriceComponent implements OnInit { | ||
@ViewChild(ProjectComponent, {static: true}) child: ProjectComponent; | ||
|
||
public data: any; | ||
public gridColumns = COLUMNS_PRICE; | ||
public enabledTitle: boolean; | ||
public allowExcelExport: boolean; | ||
|
||
constructor( | ||
private excelExportService: ExcelExportService, | ||
private priceService: PriceService, | ||
private router: Router, | ||
) { } | ||
|
||
ngOnInit(): void { | ||
const self = this; | ||
this.enabledTitle = true; | ||
this.allowExcelExport = true; | ||
|
||
this.getDataPrice().subscribe(data => { | ||
self.data = data; | ||
}); | ||
} | ||
|
||
/** | ||
* Export Excel | ||
* @param {name, gridColumns, data} | ||
* | ||
*/ | ||
public onExportExcel(excelData): any { | ||
if (!_.isNil(excelData.data) && !_.isEmpty(excelData.data)) { | ||
this.excelExportService.generateExcelFromJson( | ||
excelData.name, | ||
excelData.gridColumns, | ||
excelData.data | ||
); | ||
} | ||
} | ||
|
||
public onJsonData(jsonData){ | ||
let jsonEditPrice: any[] = []; | ||
let jsonAddPrice: any[] = []; | ||
//console.log('data de Prices es', jsonData); | ||
let jsonFinal = this.namesToProps(jsonData); | ||
//console.log('jsonFinal', jsonFinal); | ||
for ( const row of jsonFinal ){ | ||
if( !_.isNil(row['id']) ){ | ||
jsonEditPrice.push(row); | ||
} else { | ||
jsonAddPrice.push(row); | ||
} | ||
} | ||
|
||
for ( const row of jsonAddPrice ) | ||
delete row['id']; | ||
|
||
const self = this; | ||
forkJoin( | ||
this.priceService.createPrice('20201',JSON.stringify(jsonAddPrice)), | ||
this.priceService.updatePrice('20201',JSON.stringify(jsonEditPrice)) | ||
).subscribe( ([addPrice, editPrice ]) => { | ||
alert('Se ha guardado correctamente los precios'); | ||
this.router.navigateByUrl('/Price', { skipLocationChange: true }).then(() => { | ||
this.router.navigate(['/Price']); | ||
}); | ||
setTimeout(() => {}, 1000); | ||
}); | ||
} | ||
|
||
public namesToProps(json){ | ||
return json.map(key => { | ||
let res = {}; | ||
res[`${PriceColumns.ID.prop}`] = key[PriceColumns.ID.name]; | ||
res[`${PriceColumns.TYPE_PROMOTION.prop}`] = key[PriceColumns.TYPE_PROMOTION.name]; | ||
res[`${PriceColumns.CODE.prop}`] = key[PriceColumns.CODE.name]; | ||
res[`${PriceColumns.PRICE.prop}`] = key[PriceColumns.PRICE.name]; | ||
|
||
return res; | ||
}); | ||
} | ||
|
||
public getDataPrice() { | ||
return this.priceService.getPriceByPromotion('20201'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { PriceColumns } from '../../app.keys'; | ||
|
||
export const COLUMNS_PRICE = [ | ||
{field: PriceColumns.ID.prop, headerName: PriceColumns.ID.name }, | ||
{field: PriceColumns.TYPE_PROMOTION.prop , headerName: PriceColumns.TYPE_PROMOTION.name }, | ||
{field: PriceColumns.CODE.prop , headerName: PriceColumns.CODE.name }, | ||
{field: PriceColumns.PRICE.prop , headerName: PriceColumns.PRICE.name }, | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters