diff --git a/src/app/admin/menu/menu.component.html b/src/app/admin/menu/menu.component.html
index 2ad6cb5..30e8de8 100644
--- a/src/app/admin/menu/menu.component.html
+++ b/src/app/admin/menu/menu.component.html
@@ -78,6 +78,8 @@
Santillana
+
+
diff --git a/src/app/app.keys.ts b/src/app/app.keys.ts
index 0625395..9d395ad 100644
--- a/src/app/app.keys.ts
+++ b/src/app/app.keys.ts
@@ -12,8 +12,8 @@ export enum AppStatusForm {
}
export namespace ApiKeys {
- export const API_URL = "http://104.210.146.134:3000/";
- //export const API_URL = "http://localhost:3000/";
+ //export const API_URL = "http://104.210.146.134:3000/";
+ export const API_URL = "http://localhost:3000/";
}
export namespace TitleNames {
@@ -155,6 +155,13 @@ export namespace UserColumns {
export const STATUS = {prop: 'status', name: 'Estado'};
}
+export namespace PriceColumns {
+ export const ID = {prop: 'id', name: 'Id'};
+ export const TYPE_PROMOTION = {prop: 'typePromotion', name: 'Promoción'};
+ export const CODE = {prop: 'cod', name: 'Código del Producto'};
+ export const PRICE = {prop: 'price', name: 'Precio Unitario'};
+}
+
export namespace WorkflowServiceConstants {
export const WORKFLOW_STATES = {
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index f0c7a5f..95b9bf0 100755
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -17,12 +17,14 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { UploadDirective } from './directives/upload.directive';
import { FormlyFieldNgbDatePicker } from './shared/components/form/ngb-date-picker.type.component';
import { NgxUiLoaderModule } from 'ngx-ui-loader';
+import { PriceComponent } from './configuration/price/price.component';
@NgModule({
declarations: [
AppComponent,
- UploadDirective
+ UploadDirective,
+ PriceComponent
],
imports: [
BrowserModule,
diff --git a/src/app/configuration/configuration-routing.module.ts b/src/app/configuration/configuration-routing.module.ts
index 657843a..99c1984 100644
--- a/src/app/configuration/configuration-routing.module.ts
+++ b/src/app/configuration/configuration-routing.module.ts
@@ -6,13 +6,15 @@ import { ClientComponent } from './client/client.component';
import { UserComponent } from './user/user.component';
import { CollegesComponent } from './colleges/colleges.component';
import { CampaignComponent } from './campaign/campaign.component';
+import { PriceComponent } from './price/price.component';
const configurationRoutes: Routes = [
{ path: 'product', component: ProductComponent },
{ path: 'client', component: ClientComponent },
{ path: 'user', component: UserComponent},
{ path: 'college', component: CollegesComponent},
- { path: 'campaign', component: CampaignComponent}
+ { path: 'campaign', component: CampaignComponent},
+ { path: 'price', component: PriceComponent}
];
@NgModule({
imports: [RouterModule.forChild(configurationRoutes)],
diff --git a/src/app/configuration/price/price.component.css b/src/app/configuration/price/price.component.css
new file mode 100644
index 0000000..e69de29
diff --git a/src/app/configuration/price/price.component.html b/src/app/configuration/price/price.component.html
new file mode 100644
index 0000000..b46e639
--- /dev/null
+++ b/src/app/configuration/price/price.component.html
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/app/configuration/price/price.component.spec.ts b/src/app/configuration/price/price.component.spec.ts
new file mode 100644
index 0000000..8959430
--- /dev/null
+++ b/src/app/configuration/price/price.component.spec.ts
@@ -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;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ PriceComponent ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(PriceComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/app/configuration/price/price.component.ts b/src/app/configuration/price/price.component.ts
new file mode 100644
index 0000000..932cb17
--- /dev/null
+++ b/src/app/configuration/price/price.component.ts
@@ -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');
+ }
+
+}
diff --git a/src/app/configuration/price/priceColumns.ts b/src/app/configuration/price/priceColumns.ts
new file mode 100644
index 0000000..8e91aa5
--- /dev/null
+++ b/src/app/configuration/price/priceColumns.ts
@@ -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 },
+
+ ];
\ No newline at end of file
diff --git a/src/app/shared/service/price.service.ts b/src/app/shared/service/price.service.ts
index 3cbd1f1..062aabe 100644
--- a/src/app/shared/service/price.service.ts
+++ b/src/app/shared/service/price.service.ts
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';
import { HttpHeaders, HttpClient } from '@angular/common/http';
import { ApiKeys } from 'src/app/app.keys';
+import { Observable } from 'rxjs';
const httpOptions = {
headers: new HttpHeaders({
@@ -24,4 +25,14 @@ export class PriceService {
const url = this.baseUrl+`price/`+promotion;
return this.http.get(url);
}
+
+ public createPrice(promotion: string, price: any): Observable {
+ const url = this.baseUrl+`price/`+ promotion.toString();
+ return this.http.post(url, price, httpOptions);
+ }
+
+ public updatePrice(promotion: string, price: any): Observable {
+ const url = this.baseUrl+`price/`+promotion.toString();
+ return this.http.patch(url, price, httpOptions);
+ }
}