Skip to content

Commit

Permalink
feat: prices
Browse files Browse the repository at this point in the history
  • Loading branch information
leoriofrio committed Aug 19, 2020
1 parent a6e1f26 commit ca197e2
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/app/admin/menu/menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ <h2 class="brand-text mb-0">Santillana</h2>
</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="/price"><i class="bx bx-grid-alt"></i><span class="menu-title" data-i18n="Kanban">Precios</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>
Expand Down
11 changes: 9 additions & 2 deletions src/app/app.keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = {
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/app/configuration/configuration-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down
Empty file.
20 changes: 20 additions & 0 deletions src/app/configuration/price/price.component.html
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>
25 changes: 25 additions & 0 deletions src/app/configuration/price/price.component.spec.ts
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();
});
});
103 changes: 103 additions & 0 deletions src/app/configuration/price/price.component.ts
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');
}

}
9 changes: 9 additions & 0 deletions src/app/configuration/price/priceColumns.ts
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 },

];
11 changes: 11 additions & 0 deletions src/app/shared/service/price.service.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -24,4 +25,14 @@ export class PriceService {
const url = this.baseUrl+`price/`+promotion;
return this.http.get<any>(url);
}

public createPrice(promotion: string, price: any): Observable<any> {
const url = this.baseUrl+`price/`+ promotion.toString();
return this.http.post<any>(url, price, httpOptions);
}

public updatePrice(promotion: string, price: any): Observable<any> {
const url = this.baseUrl+`price/`+promotion.toString();
return this.http.patch<any>(url, price, httpOptions);
}
}

0 comments on commit ca197e2

Please sign in to comment.