From 94f09413c11317c01e41cb11171fd313945b792f Mon Sep 17 00:00:00 2001 From: leoriofrio Date: Sun, 7 Jun 2020 17:53:49 -0500 Subject: [PATCH] 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() {