From 6ad4c6cc0d00e82500a009f4bb943a68232f3f9d Mon Sep 17 00:00:00 2001 From: leoriofrio Date: Fri, 5 Jun 2020 20:00:29 -0500 Subject: [PATCH 1/7] fix: current date --- src/app/app.keys.ts | 4 ++-- src/app/ui/proform-add/proform-add.component.ts | 10 ++++++++-- src/app/ui/proform-edit/proform-edit.component.ts | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/app/app.keys.ts b/src/app/app.keys.ts index e4ff58d..915b22d 100644 --- a/src/app/app.keys.ts +++ b/src/app/app.keys.ts @@ -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'}; diff --git a/src/app/ui/proform-add/proform-add.component.ts b/src/app/ui/proform-add/proform-add.component.ts index 25c0d9d..7d5e497 100644 --- a/src/app/ui/proform-add/proform-add.component.ts +++ b/src/app/ui/proform-add/proform-add.component.ts @@ -143,7 +143,13 @@ export class ProformAddComponent implements OnInit { resizable: true }; + let date_now = new Date(); + self.model = { + "date_proform": date_now.getFullYear() + '-' + _.padStart(date_now.getMonth().toString(), 2, '0') + '-' + _.padStart(date_now.getDate().toString(), 2, '0'), + "date_delivery": date_now.getFullYear() + '-' + _.padStart(date_now.getMonth().toString(), 2, '0') + '-' + _.padStart(date_now.getDate().toString(), 2, '0'), + + }; } @@ -228,7 +234,7 @@ export class ProformAddComponent implements OnInit { { type: 'input', key: Proform.DATE_PROFORM.prop, - className: 'col-sm-2', + className: 'col-m-1', defaultValue: this.currentDate, templateOptions: { type: 'date', @@ -242,7 +248,7 @@ export class ProformAddComponent implements OnInit { { type: 'input', key: Proform.DATE_DELIVERY.prop, - className: 'col-sm-2', + className: 'col-m-1', defaultValue: new Date(), templateOptions: { type: 'date', diff --git a/src/app/ui/proform-edit/proform-edit.component.ts b/src/app/ui/proform-edit/proform-edit.component.ts index 8b82202..9044637 100644 --- a/src/app/ui/proform-edit/proform-edit.component.ts +++ b/src/app/ui/proform-edit/proform-edit.component.ts @@ -340,8 +340,8 @@ export class ProformEditComponent implements OnInit { "user_id":data['user']['userName'], "college_id": data['college']['codSantillana'] + ' - ' + data['college']['name'], "client_id":data['client_id'], - "date_proform": new Date(data['date_proform']).getFullYear() + '-0' + new Date(data['date_proform']).getMonth() + '-' + new Date(data['date_proform']).getDate(), - "date_delivery": new Date(data['date_delivery']).getFullYear() + '-0' + new Date(data['date_delivery']).getMonth() + '-' + new Date(data['date_delivery']).getDate(), + "date_proform": new Date(data['date_proform']).getFullYear() + '-' + _.padStart(new Date(data['date_proform']).getMonth().toString(), 2, '0') + '-' + _.padStart(new Date(data['date_proform']).getDate().toString(), 2, '0'), + "date_delivery": new Date(data['date_delivery']).getFullYear() + '-' + _.padStart(new Date(data['date_delivery']).getMonth().toString(), 2, '0') + '-' + _.padStart(new Date(data['date_delivery']).getDate().toString(), 2, '0'), "type_client_sale": data['type_client_sale'], "agreement": data['agreement'] }; From 94f09413c11317c01e41cb11171fd313945b792f Mon Sep 17 00:00:00 2001 From: leoriofrio Date: Sun, 7 Jun 2020 17:53:49 -0500 Subject: [PATCH 2/7] fix: summary proform --- src/app/app.type.ts | 14 +++++ .../components/grid/grid.component.html | 4 +- .../shared/components/grid/grid.component.ts | 5 +- src/app/shared/shared.module.ts | 2 + .../ui/proform-add/proform-add.component.html | 57 +++++++++++-------- .../ui/proform-add/proform-add.component.ts | 33 ++++++++++- .../proform-edit/proform-edit.component.html | 29 ++++++---- .../ui/proform-edit/proform-edit.component.ts | 34 +++++++++-- 8 files changed, 135 insertions(+), 43 deletions(-) diff --git a/src/app/app.type.ts b/src/app/app.type.ts index fd141ad..bf430f5 100644 --- a/src/app/app.type.ts +++ b/src/app/app.type.ts @@ -62,6 +62,20 @@ export type GridRecord = { 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, + total:0, + }; + export const MODEL_DETAIL = { "id": 0, "degree": "string", diff --git a/src/app/shared/components/grid/grid.component.html b/src/app/shared/components/grid/grid.component.html index 7541446..4f2b744 100644 --- a/src/app/shared/components/grid/grid.component.html +++ b/src/app/shared/components/grid/grid.component.html @@ -1,8 +1,8 @@ - -
+
+ diff --git a/src/app/shared/components/grid/grid.component.ts b/src/app/shared/components/grid/grid.component.ts index 254836e..75c7344 100644 --- a/src/app/shared/components/grid/grid.component.ts +++ b/src/app/shared/components/grid/grid.component.ts @@ -27,6 +27,7 @@ export class GridComponent implements OnInit, OnDestroy { public hot: Handsontable; private setter = false; + public addProform: boolean = false; constructor() { } @@ -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, { @@ -204,6 +205,8 @@ export class GridComponent implements OnInit, OnDestroy { } public add() { + this.addProform = false; + this.addProform = true; this.hot.alter('insert_row', 0); } diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index f444a2e..2fee3a3 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -14,6 +14,7 @@ import { FormlyFieldNgbDatePicker } from './components/form/ngb-date-picker.type import { FormlyFieldNgbTimePicker } from './components/form/ngb-time-picker.type.component'; import { BrowserModule } from '@angular/platform-browser'; import { SelectProjectRendererComponent } from './components/project/select-project-renderer.component'; +import { NgxUiLoaderModule } from 'ngx-ui-loader'; @NgModule({ imports: [ @@ -21,6 +22,7 @@ import { SelectProjectRendererComponent } from './components/project/select-proj BrowserModule, FormsModule, ReactiveFormsModule, + NgxUiLoaderModule, AgGridModule.withComponents([selectionRenderComponent, SelectProjectRendererComponent]), HotTableModule.forRoot(), FormlyModule.forRoot({ diff --git a/src/app/ui/proform-add/proform-add.component.html b/src/app/ui/proform-add/proform-add.component.html index 160a1ef..83c92a7 100644 --- a/src/app/ui/proform-add/proform-add.component.html +++ b/src/app/ui/proform-add/proform-add.component.html @@ -11,36 +11,45 @@
-
- -
-
- -
-
-
- - - -
+
+ +
+
+ +
- +
+ + + +
+
-
+
- - - - +
+ +
+ + + + + + + + + + + + + + + + +
UnidadesSubtotalTotal
{{ datasetSummary.quantity }}{{ datasetSummary.subtotal }}{{ datasetSummary.total }}
diff --git a/src/app/ui/proform-add/proform-add.component.ts b/src/app/ui/proform-add/proform-add.component.ts index 7d5e497..b9fc48f 100644 --- a/src/app/ui/proform-add/proform-add.component.ts +++ b/src/app/ui/proform-add/proform-add.component.ts @@ -9,7 +9,7 @@ import { ExcelExportService } from 'src/app/shared/service/export-excel.service' import * as _ from 'lodash'; import { of as observableOf } from 'rxjs'; import { ActivatedRoute } from '@angular/router'; -import { GridRecord, IProform, IProformDetail, MODEL_DETAIL, DataType, MODEL_DETAIL_SAVE } from 'src/app/app.type'; +import { GridRecord, PROFORM_SUMMARY, MODEL_DETAIL_SAVE } from 'src/app/app.type'; import Handsontable from 'handsontable'; import { ProformService } from '../../shared/service/proform.service'; import { Router } from '@angular/router'; @@ -40,6 +40,7 @@ export class ProformAddComponent implements OnInit { public data: any; public dataOfBank: any[] = []; public dataset: any[] = []; + public datasetSummary: PROFORM_SUMMARY ; public gridColumns = COLUMNS_DETAIL_PROFORM; public columnsGrid: any; // = COLUMNS_DETAIL; public columnsHeader = COLUMNS_HEADER; @@ -93,6 +94,7 @@ export class ProformAddComponent implements OnInit { } + ngOnInit() { const self = this; this.enabledTitle = false; @@ -151,6 +153,8 @@ export class ProformAddComponent implements OnInit { }; + this.refreshData(); + } @@ -460,7 +464,7 @@ export class ProformAddComponent implements OnInit { this.model['client_id'] = null; } - console.log(JSON.stringify(this.dataProduct)); + for (const row of grid) { if ( !_.isNil(row['codigo'])) { if( _.isNil(this.matchProduct(row['codigo'], this.dataProduct)) ) { @@ -492,7 +496,32 @@ export class ProformAddComponent implements OnInit { return true; } + public refreshData(){ + const self = this; + self.datasetSummary = { + 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, + total:0, + }; + + _.forEach(this.dataset, function(value, key) { + self.datasetSummary.quantity = Number(self.datasetSummary.quantity) + value['quantity']; + self.datasetSummary.subtotal = Number(self.datasetSummary.subtotal) + value['subtotal']; + self.datasetSummary.total = Number(self.datasetSummary.total) + value['total']; + self.datasetSummary.sale_direct = (Number(self.datasetSummary.subtotal) * value['sale_direct'] / 100) as any; + }); + } + public onChange(data: GridRecord[]): void { + this.refreshData(); } diff --git a/src/app/ui/proform-edit/proform-edit.component.html b/src/app/ui/proform-edit/proform-edit.component.html index 8268a23..5643ae3 100644 --- a/src/app/ui/proform-edit/proform-edit.component.html +++ b/src/app/ui/proform-edit/proform-edit.component.html @@ -32,18 +32,27 @@
- - - - +
+
+ + + + + + + + + + + + + + + + +
UnidadesSubtotalTotal
{{ datasetSummary.quantity }}{{ datasetSummary.subtotal }}{{ datasetSummary.total }}
diff --git a/src/app/ui/proform-edit/proform-edit.component.ts b/src/app/ui/proform-edit/proform-edit.component.ts index 9044637..cb85ca3 100644 --- a/src/app/ui/proform-edit/proform-edit.component.ts +++ b/src/app/ui/proform-edit/proform-edit.component.ts @@ -9,7 +9,7 @@ import { ExcelExportService } from 'src/app/shared/service/export-excel.service' import * as _ from 'lodash'; import { of as observableOf, of } from 'rxjs'; import { ActivatedRoute } from '@angular/router'; -import { GridRecord, IProform, MODEL_DETAIL } from 'src/app/app.type'; +import { GridRecord, IProform, MODEL_DETAIL, PROFORM_SUMMARY } from 'src/app/app.type'; import Handsontable from 'handsontable'; import { ProformService } from '../../shared/service/proform.service'; import { Router } from '@angular/router'; @@ -47,6 +47,7 @@ export class ProformEditComponent implements OnInit { public data: any[]; public dataOfBank: any[] = []; public dataset: any[] = []; + public datasetSummary: PROFORM_SUMMARY ; public dataTransform: any[]; public dataTransformTempo: any[]; public gridColumns = COLUMNS_DETAIL_PROFORM; @@ -362,6 +363,7 @@ export class ProformEditComponent implements OnInit { self.dataset.push(row); }; } + this.refreshData(); }); @@ -372,11 +374,11 @@ export class ProformEditComponent implements OnInit { this.form.enable(); setTimeout(() => { this.loaderService.stopLoader('loader-list-proform'); - }, 2000); + }, 2500); - this.cd.detectChanges(); + this.cd.detectChanges(); } @@ -427,8 +429,32 @@ export class ProformEditComponent implements OnInit { } - public onChange(data: GridRecord[]): void { + public refreshData(){ + const self = this; + self.datasetSummary = { + 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, + total:0, + }; + _.forEach(this.dataset, function(value, key) { + self.datasetSummary.quantity = Number(self.datasetSummary.quantity) + value['quantity']; + self.datasetSummary.subtotal = Number(self.datasetSummary.subtotal) + value['subtotal']; + self.datasetSummary.total = Number(self.datasetSummary.total) + value['total']; + self.datasetSummary.sale_direct = (Number(self.datasetSummary.subtotal) * value['sale_direct'] / 100) as any; + }); + } + + public onChange(data: GridRecord[]): void { + this.refreshData(); } public close() { From 422f2eed8f541948a16a202a7cbe91020dccf783 Mon Sep 17 00:00:00 2001 From: leoriofrio Date: Sun, 7 Jun 2020 19:32:16 -0500 Subject: [PATCH 3/7] feat: excel exportation --- src/app/app.keys.ts | 2 +- .../ui/proform-add/proform-add.component.ts | 16 +++++-- .../proform-edit/proform-edit.component.html | 1 + .../ui/proform-edit/proform-edit.component.ts | 45 +++++++++++-------- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/app/app.keys.ts b/src/app/app.keys.ts index 915b22d..6c16cd7 100644 --- a/src/app/app.keys.ts +++ b/src/app/app.keys.ts @@ -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'; diff --git a/src/app/ui/proform-add/proform-add.component.ts b/src/app/ui/proform-add/proform-add.component.ts index b9fc48f..a8c76df 100644 --- a/src/app/ui/proform-add/proform-add.component.ts +++ b/src/app/ui/proform-add/proform-add.component.ts @@ -15,7 +15,7 @@ import { ProformService } from '../../shared/service/proform.service'; import { Router } from '@angular/router'; import { ProductService } from 'src/app/shared/service/product.service'; import { UtilsService } from 'src/app/shared/service/utils.service'; -import { map, switchMap } from 'rxjs/operators'; +import { map, switchMap, tap, startWith } from 'rxjs/operators'; @@ -228,7 +228,17 @@ export class ProformAddComponent implements OnInit { field.templateOptions.options = _.sortBy(data, "userName"); this.userData = data; }); - + const numberProform = this.form.get(Proform.NUMBER_PROFORM.prop); + form + .get(Proform.NUMBER_PROFORM.prop) + .valueChanges.pipe( + tap(value => { + if (value) { + field.formControl.setValue(' '); + } + }) + ) + .subscribe(); } }, expressionProperties: { @@ -526,7 +536,7 @@ export class ProformAddComponent implements OnInit { } public close() { - + this.router.navigate(['/']); } public getDataProduct() { diff --git a/src/app/ui/proform-edit/proform-edit.component.html b/src/app/ui/proform-edit/proform-edit.component.html index 5643ae3..56b48ff 100644 --- a/src/app/ui/proform-edit/proform-edit.component.html +++ b/src/app/ui/proform-edit/proform-edit.component.html @@ -26,6 +26,7 @@ +
diff --git a/src/app/ui/proform-edit/proform-edit.component.ts b/src/app/ui/proform-edit/proform-edit.component.ts index cb85ca3..41798c2 100644 --- a/src/app/ui/proform-edit/proform-edit.component.ts +++ b/src/app/ui/proform-edit/proform-edit.component.ts @@ -75,7 +75,7 @@ export class ProformEditComponent implements OnInit { private router: Router, private cd : ChangeDetectorRef, private utilsService: UtilsService, - private loaderService: NgxUiLoaderService, + private loaderService: NgxUiLoaderService, ) { const self = this; @@ -282,32 +282,32 @@ export class ProformEditComponent implements OnInit { this.proformId = this.route.snapshot.paramMap.get("id"); this.columnsGrid = [ - { data: ProformDetail.ID.prop, readOnly: true }, - { type: 'text', data: ProformDetail.DEGREE.prop, }, + { data: ProformDetail.ID.prop, readOnly: true, headerName: ProformDetail.ID.name, field: ProformDetail.ID.prop }, + { type: 'text', data: ProformDetail.DEGREE.prop, headerName: ProformDetail.DEGREE.name, field: ProformDetail.DEGREE.prop }, { type: 'autocomplete', data: 'codigo', renderer: 'currency', source: this.productCod, strict: true, - filter: false}, + filter: false, headerName: 'Código', field: 'codigo'}, { type: 'autocomplete', data: ProformDetail.PRODUCT_ID.prop, renderer: 'currency', source: this.productDescription, strict: true, - filter: false}, - { type: 'numeric', data: ProformDetail.QUANTITY.prop, renderer: 'currency' }, - { type: 'numeric', data: ProformDetail.PRICE.prop, renderer: 'currency' }, - { type: 'numeric', data: ProformDetail.SUB_TOTAL.prop, renderer: 'currency' , readOnly: true }, - { type: 'numeric', data: ProformDetail.SALE_DIRECT.prop, renderer: 'currency' }, - { type: 'numeric', data: ProformDetail.SALE_EXTERNAL_LIBRARY.prop, renderer: 'currency' }, - { type: 'numeric', data: ProformDetail.SALE_EVENT.prop, renderer: 'currency' }, - { type: 'numeric', data: ProformDetail.SALE_TEACHER.prop, renderer: 'currency' }, - { type: 'numeric', data: ProformDetail.SALE_INFRASTRUCTURE.prop, renderer: 'currency' }, - { type: 'numeric', data: ProformDetail.SALE_SCHOLARSHIPS.prop, renderer: 'currency' }, - { type: 'numeric', data: ProformDetail.SALE_STAFF.prop, renderer: 'currency' }, - { type: 'numeric', data: ProformDetail.SALE_TRAINING.prop, renderer: 'currency' }, - { type: 'numeric', data: ProformDetail.TOTAL.prop, renderer: 'currency' , readOnly: true }, + filter: false, headerName: ProformDetail.PRODUCT_ID.name, field: ProformDetail.PRODUCT_ID.prop, }, + { type: 'numeric', data: ProformDetail.QUANTITY.prop, renderer: 'currency', headerName: ProformDetail.QUANTITY.name, field: ProformDetail.QUANTITY.prop }, + { type: 'numeric', data: ProformDetail.PRICE.prop, renderer: 'currency', headerName: ProformDetail.PRICE.name, field: ProformDetail.PRICE.prop }, + { type: 'numeric', data: ProformDetail.SUB_TOTAL.prop, renderer: 'currency' , readOnly: true , headerName: ProformDetail.SUB_TOTAL.name, field: ProformDetail.SUB_TOTAL.prop }, + { type: 'numeric', data: ProformDetail.SALE_DIRECT.prop, renderer: 'currency', headerName: ProformDetail.SALE_DIRECT.name, field: ProformDetail.SALE_DIRECT.prop }, + { type: 'numeric', data: ProformDetail.SALE_EXTERNAL_LIBRARY.prop, renderer: 'currency', headerName: ProformDetail.SALE_EXTERNAL_LIBRARY.name, field: ProformDetail.SALE_EXTERNAL_LIBRARY.prop }, + { type: 'numeric', data: ProformDetail.SALE_EVENT.prop, renderer: 'currency', headerName: ProformDetail.SALE_EVENT.name, field: ProformDetail.SALE_EVENT.prop }, + { type: 'numeric', data: ProformDetail.SALE_TEACHER.prop, renderer: 'currency', headerName: ProformDetail.SALE_TEACHER.name, field: ProformDetail.SALE_TEACHER.prop }, + { type: 'numeric', data: ProformDetail.SALE_INFRASTRUCTURE.prop, renderer: 'currency', headerName: ProformDetail.SALE_INFRASTRUCTURE.name, field: ProformDetail.SALE_INFRASTRUCTURE.prop }, + { type: 'numeric', data: ProformDetail.SALE_SCHOLARSHIPS.prop, renderer: 'currency', headerName: ProformDetail.SALE_SCHOLARSHIPS.name, field: ProformDetail.SALE_SCHOLARSHIPS.prop }, + { type: 'numeric', data: ProformDetail.SALE_STAFF.prop, renderer: 'currency', headerName: ProformDetail.SALE_STAFF.name, field: ProformDetail.SALE_STAFF.prop }, + { type: 'numeric', data: ProformDetail.SALE_TRAINING.prop, renderer: 'currency', headerName: ProformDetail.SALE_TRAINING.name, field: ProformDetail.SALE_TRAINING.prop }, + { type: 'numeric', data: ProformDetail.TOTAL.prop, renderer: 'currency' , readOnly: true, headerName: ProformDetail.TOTAL.name, field: ProformDetail.TOTAL.prop }, ] if (!this.enableEdit){ @@ -458,7 +458,16 @@ export class ProformEditComponent implements OnInit { } public close() { - + this.router.navigate(['/']); + } + + public exportExcel() { + debugger; + this.excelExportService.generateExcelFromJson( + "Proforma", + this.columnsGrid, + this.dataset + ); } public matchProduct(description: string, product: any[]): number | undefined { From 5b16ea70c6fe5e6e08dc2a82f2fa01ae633d217d Mon Sep 17 00:00:00 2001 From: leoriofrio Date: Sun, 7 Jun 2020 23:10:19 -0500 Subject: [PATCH 4/7] fix: services and capex --- src/app/admin/menu/menu.component.html | 8 +- src/app/app.keys.ts | 1 + src/app/app.type.ts | 6 +- .../shared/components/grid/grid.component.ts | 10 +- src/app/shared/service/proform.service.ts | 5 + .../proform-add/model/proformColumns.model.ts | 4 +- .../ui/proform-add/proform-add.component.ts | 19 +++- .../model/proformColumns.model.ts | 3 +- .../ui/proform-edit/proform-edit.component.ts | 95 +++++++++++++++---- .../ui/proform-list/proform-list.component.ts | 6 ++ src/app/ui/proform-list/proformColumns.ts | 3 +- 11 files changed, 123 insertions(+), 37 deletions(-) diff --git a/src/app/admin/menu/menu.component.html b/src/app/admin/menu/menu.component.html index 9c51e43..2ad6cb5 100644 --- a/src/app/admin/menu/menu.component.html +++ b/src/app/admin/menu/menu.component.html @@ -76,16 +76,16 @@

Santillana

- + - + diff --git a/src/app/app.keys.ts b/src/app/app.keys.ts index 6c16cd7..88b75c3 100644 --- a/src/app/app.keys.ts +++ b/src/app/app.keys.ts @@ -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'}; } diff --git a/src/app/app.type.ts b/src/app/app.type.ts index bf430f5..f9970f8 100644 --- a/src/app/app.type.ts +++ b/src/app/app.type.ts @@ -58,6 +58,7 @@ export type GridRecord = { sale_scholarships: 0, sale_staff: 0, sale_training: 0, + capex: 0, proform_id: 0, product_id: 0 }; @@ -73,6 +74,7 @@ export type GridRecord = { sale_scholarships: 0, sale_staff: 0, sale_training: 0, + capex:0, total:0, }; @@ -92,7 +94,8 @@ export type GridRecord = { "sale_infrastructure": 0, "sale_scholarships": 0, "sale_staff": 0, - "sale_training": 0 + "sale_training": 0, + "capex": 0 }; @@ -109,6 +112,7 @@ export type GridRecord = { "sale_scholarships": 0, "sale_staff": 0, "sale_training": 0, + "capex": 0, "proform_id": 0, "product_id": 0 }; diff --git a/src/app/shared/components/grid/grid.component.ts b/src/app/shared/components/grid/grid.component.ts index 75c7344..4d71f45 100644 --- a/src/app/shared/components/grid/grid.component.ts +++ b/src/app/shared/components/grid/grid.component.ts @@ -95,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; @@ -110,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) ); @@ -124,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)); @@ -133,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; } } diff --git a/src/app/shared/service/proform.service.ts b/src/app/shared/service/proform.service.ts index 8e04e6b..a012f63 100644 --- a/src/app/shared/service/proform.service.ts +++ b/src/app/shared/service/proform.service.ts @@ -44,6 +44,11 @@ export class ProformService { return this.http.post(url, proformDetail, httpOptions); } + public updateProformDetail(id: string, proformDetail: any): Observable { + const url = this.baseUrl+`proform/`+id.toString()+`/proformDetail/edit`; + return this.http.patch(url, proformDetail, httpOptions); + } + } diff --git a/src/app/ui/proform-add/model/proformColumns.model.ts b/src/app/ui/proform-add/model/proformColumns.model.ts index 46ed6c2..2582292 100644 --- a/src/app/ui/proform-add/model/proformColumns.model.ts +++ b/src/app/ui/proform-add/model/proformColumns.model.ts @@ -21,6 +21,7 @@ export const COLUMNS_DETAIL_PROFORM = [ {field: ProformDetail.SALE_SCHOLARSHIPS.prop, headerName: ProformDetail.SALE_SCHOLARSHIPS.name, resizable: true, width: 100}, {field: ProformDetail.SALE_STAFF.prop, headerName: ProformDetail.SALE_STAFF.name, resizable: true, width: 100}, {field: ProformDetail.SALE_TRAINING.prop, headerName: ProformDetail.SALE_TRAINING.name, resizable: true, width: 100}, + {field: ProformDetail.CAPEX.prop, headerName: ProformDetail.CAPEX.name, resizable: true, width: 100}, {field: ProformDetail.TOTAL.prop, headerName: ProformDetail.TOTAL.name, resizable: true, width: 100} ]; @@ -50,6 +51,7 @@ export const COLUMNS_DETAIL = [ { type: 'numeric', data: ProformDetail.SALE_SCHOLARSHIPS.prop, renderer: 'currency' }, { type: 'numeric', data: ProformDetail.SALE_STAFF.prop, renderer: 'currency' }, { type: 'numeric', data: ProformDetail.SALE_TRAINING.prop, renderer: 'currency' }, + { type: 'numeric', data: ProformDetail.CAPEX.prop, renderer: 'currency' }, { type: 'numeric', data: ProformDetail.TOTAL.prop, renderer: 'currency' , readOnly: true }, ] @@ -58,7 +60,7 @@ export const COLUMNS_HEADER = [ ProformDetail.PRICE.name, ProformDetail.SUB_TOTAL.name, ProformDetail.SALE_DIRECT.name, ProformDetail.SALE_EXTERNAL_LIBRARY.name, ProformDetail.SALE_EVENT.name, ProformDetail.SALE_TEACHER.name, ProformDetail.SALE_INFRASTRUCTURE.name, ProformDetail.SALE_SCHOLARSHIPS.name, - ProformDetail.SALE_STAFF.name, ProformDetail.SALE_TRAINING.name, ProformDetail.TOTAL.name + ProformDetail.SALE_STAFF.name, ProformDetail.SALE_TRAINING.name, ProformDetail.CAPEX.name, ProformDetail.TOTAL.name ]; diff --git a/src/app/ui/proform-add/proform-add.component.ts b/src/app/ui/proform-add/proform-add.component.ts index a8c76df..449484c 100644 --- a/src/app/ui/proform-add/proform-add.component.ts +++ b/src/app/ui/proform-add/proform-add.component.ts @@ -126,6 +126,7 @@ export class ProformAddComponent implements OnInit { { type: 'numeric', data: ProformDetail.SALE_SCHOLARSHIPS.prop, renderer: 'currency' }, { type: 'numeric', data: ProformDetail.SALE_STAFF.prop, renderer: 'currency' }, { type: 'numeric', data: ProformDetail.SALE_TRAINING.prop, renderer: 'currency' }, + { type: 'numeric', data: ProformDetail.CAPEX.prop, renderer: 'currency' }, { type: 'numeric', data: ProformDetail.TOTAL.prop, renderer: 'currency' , readOnly: true }, ] @@ -216,7 +217,7 @@ export class ProformAddComponent implements OnInit { label: Proform.USER_ID.name, required: true, valueProp: 'id', - labelProp: 'userName', + labelProp: 'name', //options: vendedores, }, lifecycle: { @@ -225,16 +226,23 @@ export class ProformAddComponent implements OnInit { .getUsers() .pipe() .subscribe(data => { - field.templateOptions.options = _.sortBy(data, "userName"); + //field.templateOptions.options = _.sortBy(data, "userName"); + let dataUser: any[] = []; + _.forEach(data, function(value, key) { + dataUser.push({'id': value['id'], 'name': value['userName'] + ' - ' + value['codUser'], 'codUser': Number(value['codUser'])}); + }); + field.templateOptions.options = _.sortBy(dataUser, "name"); this.userData = data; }); const numberProform = this.form.get(Proform.NUMBER_PROFORM.prop); form - .get(Proform.NUMBER_PROFORM.prop) + .get(Proform.USER_ID.prop) .valueChanges.pipe( tap(value => { if (value) { - field.formControl.setValue(' '); + //field.formControl.setValue(' '); + console.log(this.userData); + numberProform.setValue('2020-1-' + this.userData['codUser'].value); } }) ) @@ -303,7 +311,7 @@ export class ProformAddComponent implements OnInit { _.forEach(data, function(value, key) { dataCollege.push({'id': value['id'], 'name': value['codSantillana'] + ' - ' + value['name'], 'codSantillana': Number(value['codSantillana'])}); }); - field.templateOptions.options = _.sortBy(dataCollege, "codSantillana"); + field.templateOptions.options = _.sortBy(dataCollege, "codSantillana"); }); } }, @@ -519,6 +527,7 @@ export class ProformAddComponent implements OnInit { sale_scholarships: 0, sale_staff: 0, sale_training: 0, + capex: 0, total:0, }; diff --git a/src/app/ui/proform-edit/model/proformColumns.model.ts b/src/app/ui/proform-edit/model/proformColumns.model.ts index 813515f..38d93ad 100644 --- a/src/app/ui/proform-edit/model/proformColumns.model.ts +++ b/src/app/ui/proform-edit/model/proformColumns.model.ts @@ -21,6 +21,7 @@ export const COLUMNS_DETAIL_PROFORM = [ {field: ProformDetail.SALE_SCHOLARSHIPS.prop, headerName: ProformDetail.SALE_SCHOLARSHIPS.name, resizable: true, width: 100}, {field: ProformDetail.SALE_STAFF.prop, headerName: ProformDetail.SALE_STAFF.name, resizable: true, width: 100}, {field: ProformDetail.SALE_TRAINING.prop, headerName: ProformDetail.SALE_TRAINING.name, resizable: true, width: 100}, + {field: ProformDetail.CAPEX.prop, headerName: ProformDetail.CAPEX.name, resizable: true, width: 100}, {field: ProformDetail.TOTAL.prop, headerName: ProformDetail.TOTAL.name, resizable: true, width: 100} ]; @@ -58,7 +59,7 @@ export const COLUMNS_HEADER = [ ProformDetail.PRICE.name, ProformDetail.SUB_TOTAL.name, ProformDetail.SALE_DIRECT.name, ProformDetail.SALE_EXTERNAL_LIBRARY.name, ProformDetail.SALE_EVENT.name, ProformDetail.SALE_TEACHER.name, ProformDetail.SALE_INFRASTRUCTURE.name, ProformDetail.SALE_SCHOLARSHIPS.name, - ProformDetail.SALE_STAFF.name, ProformDetail.SALE_TRAINING.name, ProformDetail.TOTAL.name + ProformDetail.SALE_STAFF.name, ProformDetail.SALE_TRAINING.name, ProformDetail.CAPEX.name, ProformDetail.TOTAL.name ]; diff --git a/src/app/ui/proform-edit/proform-edit.component.ts b/src/app/ui/proform-edit/proform-edit.component.ts index 41798c2..840a286 100644 --- a/src/app/ui/proform-edit/proform-edit.component.ts +++ b/src/app/ui/proform-edit/proform-edit.component.ts @@ -9,7 +9,7 @@ import { ExcelExportService } from 'src/app/shared/service/export-excel.service' import * as _ from 'lodash'; import { of as observableOf, of } from 'rxjs'; import { ActivatedRoute } from '@angular/router'; -import { GridRecord, IProform, MODEL_DETAIL, PROFORM_SUMMARY } from 'src/app/app.type'; +import { GridRecord, IProform, MODEL_DETAIL, PROFORM_SUMMARY, MODEL_DETAIL_SAVE } from 'src/app/app.type'; import Handsontable from 'handsontable'; import { ProformService } from '../../shared/service/proform.service'; import { Router } from '@angular/router'; @@ -307,6 +307,7 @@ export class ProformEditComponent implements OnInit { { type: 'numeric', data: ProformDetail.SALE_SCHOLARSHIPS.prop, renderer: 'currency', headerName: ProformDetail.SALE_SCHOLARSHIPS.name, field: ProformDetail.SALE_SCHOLARSHIPS.prop }, { type: 'numeric', data: ProformDetail.SALE_STAFF.prop, renderer: 'currency', headerName: ProformDetail.SALE_STAFF.name, field: ProformDetail.SALE_STAFF.prop }, { type: 'numeric', data: ProformDetail.SALE_TRAINING.prop, renderer: 'currency', headerName: ProformDetail.SALE_TRAINING.name, field: ProformDetail.SALE_TRAINING.prop }, + { type: 'numeric', data: ProformDetail.CAPEX.prop, renderer: 'currency', headerName: ProformDetail.CAPEX.name, field: ProformDetail.CAPEX.prop }, { type: 'numeric', data: ProformDetail.TOTAL.prop, renderer: 'currency' , readOnly: true, headerName: ProformDetail.TOTAL.name, field: ProformDetail.TOTAL.prop }, ] @@ -354,7 +355,7 @@ export class ProformEditComponent implements OnInit { let row = _.pick(this.dataTransform[value], _.keys(MODEL_DETAIL) ); let rowId = row['product_id']; - let descount = Number(row['sale_direct']) + Number(row['sale_external_library']) + Number(row['sale_event']) + Number(row['sale_teacher']) + Number(row['sale_infrastructure']) + Number(row['sale_scholarships']) + Number(row['sale_staff']) + Number(row['sale_training']); + let descount = Number(row['sale_direct']) + Number(row['sale_external_library']) + Number(row['sale_event']) + Number(row['sale_teacher']) + Number(row['sale_infrastructure']) + Number(row['sale_scholarships']) + Number(row['sale_staff']) + Number(row['sale_training'])+ Number(row['capex']); row['codigo'] = self.matchProductCodById(rowId, data); row['product_id'] = self.matchProductDescriptionById(rowId, data); row['subtotal'] = Number(row['quantity']) * Number(row['price']) @@ -401,34 +402,84 @@ export class ProformEditComponent implements OnInit { } } - public save() { - alert('Se ha guardado la Proforma'); - this.router.navigate(['/']); - /* + public save() { if (this.form.valid) { + this.model['id'] = Number(this.model['id']); this.model['date_delivery'] = new Date(this.model['date_delivery']).toISOString(); this.model['date_proform'] = new Date(this.model['date_proform']).toISOString(); this.model['user_id'] = Number(this.model['user_id']); this.model['college_id'] = Number(this.model['college_id']); this.model['client_id'] = Number(this.model['client_id']); this.model['state_number'] = 0; - this.model['status'] = AppStatusForm.active; + this.model['status'] = AppStatusForm.active; + + } - //Detail - this.proformService.createProform(this.model).subscribe(response => { - this.dataProformId = Number(response.id); - for (const row of this.dataset) { - row['product_id'] = this.matchProduct(row['product_id'], this.dataProduct); - } - this.proformService.createProformDetail(this.dataProformId.toString(), JSON.stringify(this.dataset)).subscribe(); - alert('Se ha guardado la Proforma correctamente '); - this.router.navigate(['/']); - }); + if (!this.validateFields()) { + return; + } + + for (const row of this.dataset) { + row['product_id'] = this.matchProduct(row['codigo'], this.dataProduct); + } + + let grid = _.cloneDeep(this.dataset); + let objTemp =[]; + + for( let obj of grid ) { + objTemp.push(_.pick(obj, _.keys(MODEL_DETAIL_SAVE) )); } - */ + + this.proformService.updateProformDetail(this.model['id'].toString(), _.replace(JSON.stringify(objTemp), '\r\n', 0)).subscribe(); + alert('Se ha guardado la Proforma ' + this.model['id'].toString() + ' correctamente '); + this.router.navigate(['/']); } + public validateFields (): any { + + let grid = _.cloneDeep(this.dataset); + + if ( _.size(grid) <= 0 ) { + alert('Antes de guardar debe ingresar el detalle de los productos'); + return false; + } + + if ( _.isNil(this.model['client_id']) || _.isNaN(this.model['client_id']) ) { + this.model['client_id'] = null; + } + + for (const row of grid) { + if ( !_.isNil(row['codigo'])) { + if( _.isNil(this.matchProduct(row['codigo'], this.dataProduct)) ) { + alert('No existe el producto ' + row['product_id']); + return false; + } + } else { + alert('No existe el código del producto ' + row['cod']); + return false; + } + + if ( Number(row['quantity']) <= 0 ) { + alert('No puede tener valor 0 el producto ' + row['product_id']); + return false; + } + + if ( Number(row['price']) <= 0 ) { + alert('No puede tener valor 0 el producto ' + row['product_id']); + return false; + } + + if ( Number(row['total']) <= 0 ) { + alert('No puede tener el valor total menor a 0 en el producto ' + row['product_id']); + return false; + } + + } + + return true; + } + public refreshData(){ const self = this; self.datasetSummary = { @@ -442,6 +493,7 @@ export class ProformEditComponent implements OnInit { sale_scholarships: 0, sale_staff: 0, sale_training: 0, + capex: 0, total:0, }; @@ -462,7 +514,6 @@ export class ProformEditComponent implements OnInit { } public exportExcel() { - debugger; this.excelExportService.generateExcelFromJson( "Proforma", this.columnsGrid, @@ -470,8 +521,9 @@ export class ProformEditComponent implements OnInit { ); } - public matchProduct(description: string, product: any[]): number | undefined { - let productObj = _.find(product, (x) => x.description === description); + public matchProduct(codigo: string, product: any[]): number | undefined { + + let productObj = _.find(product, (x) => x.cod === codigo); if (_.isNil(productObj)) { return null; } @@ -479,6 +531,7 @@ export class ProformEditComponent implements OnInit { } + public matchProductCodById(id: any, product: any[]): number | undefined { let productObj = _.find(product, (x) => x.id === Number(id)); if (_.isNil(productObj)) { diff --git a/src/app/ui/proform-list/proform-list.component.ts b/src/app/ui/proform-list/proform-list.component.ts index c58e68c..44051b8 100644 --- a/src/app/ui/proform-list/proform-list.component.ts +++ b/src/app/ui/proform-list/proform-list.component.ts @@ -40,6 +40,12 @@ export class ProformListComponent implements OnInit { public getProform(): void { this.proformService.getProform().subscribe( proform => { + _.forEach(proform, function(value, key) { + value['number_proform'] = value['number_proform'] + ' - ' + value['state_number']; + value['user_id'] = value['user']['codUser'] + ' - ' + value['user']['userName']; + value['college_id'] = value['college']['codSantillana'] + ' - ' + value['college']['name']; + value['client_id'] = value['client']['codClient'] + ' - ' + value['client']['name']; + }); this.data = proform; }); } diff --git a/src/app/ui/proform-list/proformColumns.ts b/src/app/ui/proform-list/proformColumns.ts index c417be9..5cfe0b3 100644 --- a/src/app/ui/proform-list/proformColumns.ts +++ b/src/app/ui/proform-list/proformColumns.ts @@ -8,10 +8,11 @@ export const COLUMNS_PROFORM = [ colId: 'params', width: 85 }, - {field: Proform.ID.prop, headerName: Proform.ID.name, resizable: true, width: 160 }, + {field: Proform.ID.prop, headerName: Proform.ID.name, resizable: true, width: 90 }, {field: Proform.NUMBER_PROFORM.prop , headerName: Proform.NUMBER_PROFORM.name, resizable: true, width: 150 }, {field: Proform.DATE_PROFORM.prop , headerName: Proform.DATE_PROFORM.name, resizable: true, width: 120 }, {field: Proform.DATE_DELIVERY.prop , headerName: Proform.DATE_DELIVERY.name, resizable: true, width: 120 }, + {field: Proform.USER_ID.prop , headerName: Proform.USER_ID.name, resizable: true, width: 150 }, {field: Proform.CLIENT_ID.prop , headerName: Proform.CLIENT_ID.name, resizable: true, width: 150 }, {field: Proform.COLLEGE_ID.prop , headerName: Proform.COLLEGE_ID.name, resizable: true, width: 200 }, {field: Proform.TYPE_CLIENT_SALE.prop , headerName: Proform.TYPE_CLIENT_SALE.name, resizable: true, width: 250 }, From 2b0b4e11485ac0775524e0b5600d4da4c4f597a0 Mon Sep 17 00:00:00 2001 From: leoriofrio Date: Sun, 7 Jun 2020 23:26:50 -0500 Subject: [PATCH 5/7] fix: save message --- src/app/ui/proform-add/proform-add.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/ui/proform-add/proform-add.component.ts b/src/app/ui/proform-add/proform-add.component.ts index 449484c..5c25f5c 100644 --- a/src/app/ui/proform-add/proform-add.component.ts +++ b/src/app/ui/proform-add/proform-add.component.ts @@ -459,7 +459,7 @@ export class ProformAddComponent implements OnInit { } this.proformService.createProformDetail(this.dataProformId.toString(), _.replace(JSON.stringify(objTemp), '\r\n', 0)).subscribe(); - alert('Se ha guardado la Proforma correctamente '); + alert('Se ha guardado la Proforma ' + this.dataProformId.toString() + ' correctamente '); this.router.navigate(['/']); }); From 3c8d41bb24c172e9829961cb88ef0cd604bdd705 Mon Sep 17 00:00:00 2001 From: leoriofrio Date: Mon, 8 Jun 2020 09:49:49 -0500 Subject: [PATCH 6/7] fix: process --- ...t.component.css => product.component.scss} | 0 .../product/product.component.ts | 30 +++++++++++++------ src/app/shared/service/product.service.ts | 6 ++++ .../ui/proform-add/proform-add.component.html | 8 +++-- .../proform-edit/proform-edit.component.html | 8 +++-- 5 files changed, 39 insertions(+), 13 deletions(-) rename src/app/configuration/product/{product.component.css => product.component.scss} (100%) diff --git a/src/app/configuration/product/product.component.css b/src/app/configuration/product/product.component.scss similarity index 100% rename from src/app/configuration/product/product.component.css rename to src/app/configuration/product/product.component.scss diff --git a/src/app/configuration/product/product.component.ts b/src/app/configuration/product/product.component.ts index e58f1b2..ad7ff9d 100644 --- a/src/app/configuration/product/product.component.ts +++ b/src/app/configuration/product/product.component.ts @@ -1,25 +1,25 @@ 'use strict'; import { Component, OnInit, ViewChild } from '@angular/core'; -import { ProductColumns } from '../../app.keys'; +import { ProductColumns, TypeRegion } 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 { @ViewChild(ProjectComponent, {static: true}) child: ProjectComponent; - public data = dataVal; + public data: any; //dataVal; public gridColumns = COLUMNS_PRODUCT; public enabledTitle: boolean; public allowExcelExport: boolean; @@ -27,9 +27,16 @@ export class ProductComponent implements OnInit { 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() { @@ -71,8 +78,13 @@ 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)); + return this.productService.createProduct('1', JSON.stringify(jsonData)); + } + + public getDataProduct() { + return this.productService.getProductByRegion(TypeRegion.SIERRA); } } diff --git a/src/app/shared/service/product.service.ts b/src/app/shared/service/product.service.ts index bbb55dd..9988fd1 100644 --- a/src/app/shared/service/product.service.ts +++ b/src/app/shared/service/product.service.ts @@ -25,4 +25,10 @@ export class ProductService { const url = this.baseUrl+`product/`+region.toString(); return this.http.get(url); } + + public createProduct(id: string, product: any): Observable { + debugger; + const url = this.baseUrl+`product/Sierra`; + return this.http.post(url, product, httpOptions); + } } diff --git a/src/app/ui/proform-add/proform-add.component.html b/src/app/ui/proform-add/proform-add.component.html index 83c92a7..fdde2f4 100644 --- a/src/app/ui/proform-add/proform-add.component.html +++ b/src/app/ui/proform-add/proform-add.component.html @@ -39,14 +39,18 @@ Unidades Subtotal + % Descuento + Descuento Total {{ datasetSummary.quantity }} - {{ datasetSummary.subtotal }} - {{ datasetSummary.total }} + {{ datasetSummary.subtotal.toFixed(2) }} + {{ ( ( 1 -datasetSummary.total / datasetSummary.subtotal) * 100 ).toFixed(2) }} % + {{ (datasetSummary.subtotal - datasetSummary.total).toFixed(2) }} + {{ datasetSummary.total.toFixed(2) }} diff --git a/src/app/ui/proform-edit/proform-edit.component.html b/src/app/ui/proform-edit/proform-edit.component.html index 56b48ff..c26bbed 100644 --- a/src/app/ui/proform-edit/proform-edit.component.html +++ b/src/app/ui/proform-edit/proform-edit.component.html @@ -43,14 +43,18 @@ Unidades Subtotal + % Descuento + Descuento Total {{ datasetSummary.quantity }} - {{ datasetSummary.subtotal }} - {{ datasetSummary.total }} + {{ datasetSummary.subtotal.toFixed(2) }} + {{ ( ( 1 -datasetSummary.total / datasetSummary.subtotal) * 100 ).toFixed(2) }} % + {{ (datasetSummary.subtotal - datasetSummary.total).toFixed(2) }} + {{ datasetSummary.total.toFixed(2) }} From a9ee865da7c1ccbb2ba5d833f1bde0310553b7b0 Mon Sep 17 00:00:00 2001 From: jogaec22 Date: Wed, 17 Jun 2020 20:20:10 -0500 Subject: [PATCH 7/7] transformacion de nombres de cabeceras para json data --- src/app/app.keys.ts | 5 +++ .../configuration/client/client.component.ts | 21 ++++++++++-- .../colleges/colleges.component.ts | 32 +++++++++++++++++-- .../product/product.component.ts | 27 +++++++++++++--- .../shared/service/import-excel.service.ts | 1 + 5 files changed, 78 insertions(+), 8 deletions(-) diff --git a/src/app/app.keys.ts b/src/app/app.keys.ts index 88b75c3..0625395 100644 --- a/src/app/app.keys.ts +++ b/src/app/app.keys.ts @@ -212,4 +212,9 @@ export const FilesType = { export const ValidatesPattern = { alphanumeric: "[a-zA-Z0-9\\s]+" +} + +export declare interface TransformColumns { + + namesToProps(json): any; } \ No newline at end of file diff --git a/src/app/configuration/client/client.component.ts b/src/app/configuration/client/client.component.ts index 39db843..97187b1 100644 --- a/src/app/configuration/client/client.component.ts +++ b/src/app/configuration/client/client.component.ts @@ -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'; @@ -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; @@ -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; + }); } } diff --git a/src/app/configuration/colleges/colleges.component.ts b/src/app/configuration/colleges/colleges.component.ts index 1d5edcd..f0f659e 100644 --- a/src/app/configuration/colleges/colleges.component.ts +++ b/src/app/configuration/colleges/colleges.component.ts @@ -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'; @@ -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; @@ -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; + }); } } diff --git a/src/app/configuration/product/product.component.ts b/src/app/configuration/product/product.component.ts index ad7ff9d..ea2a3f8 100644 --- a/src/app/configuration/product/product.component.ts +++ b/src/app/configuration/product/product.component.ts @@ -1,7 +1,7 @@ 'use strict'; import { Component, OnInit, ViewChild } from '@angular/core'; -import { ProductColumns, TypeRegion } 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'; @@ -15,7 +15,7 @@ import { ProductService } from 'src/app/shared/service/product.service'; templateUrl: './product.component.html', styleUrls: ['./product.component.scss'] }) -export class ProductComponent implements OnInit { +export class ProductComponent implements OnInit, TransformColumns { @ViewChild(ProjectComponent, {static: true}) child: ProjectComponent; @@ -79,12 +79,31 @@ export class ProductComponent implements OnInit { } public onJsonData(jsonData){ - console.log('data de Producto es', JSON.stringify(jsonData)); - return this.productService.createProduct('1', JSON.stringify(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; + }); + } + } diff --git a/src/app/shared/service/import-excel.service.ts b/src/app/shared/service/import-excel.service.ts index 8a7e87d..6e23115 100644 --- a/src/app/shared/service/import-excel.service.ts +++ b/src/app/shared/service/import-excel.service.ts @@ -39,4 +39,5 @@ export class ExcelImportService { } }); } + }