Skip to content

Commit

Permalink
fix: summary proform
Browse files Browse the repository at this point in the history
  • Loading branch information
leoriofrio committed Jun 7, 2020
1 parent 6ad4c6c commit 94f0941
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 43 deletions.
14 changes: 14 additions & 0 deletions src/app/app.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/components/grid/grid.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<button type="submit" class="btn btn-primary submit-button" (click)="add()">Añadir</button>

<div id="example" class="hot handsontable htColumnHeaders" #container>
<div id="example" class="hot handsontable htColumnHeaders" #container>

</div>

<!--<button class="btn" (click)="addCalc()">Add Calculation</button>-->


5 changes: 4 additions & 1 deletion src/app/shared/components/grid/grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class GridComponent implements OnInit, OnDestroy {
public hot: Handsontable;

private setter = false;
public addProform: boolean = false;

constructor() { }

Expand All @@ -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, {
Expand Down Expand Up @@ -204,6 +205,8 @@ export class GridComponent implements OnInit, OnDestroy {
}

public add() {
this.addProform = false;
this.addProform = true;
this.hot.alter('insert_row', 0);
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ 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: [
CommonModule,
BrowserModule,
FormsModule,
ReactiveFormsModule,
NgxUiLoaderModule,
AgGridModule.withComponents([selectionRenderComponent, SelectProjectRendererComponent]),
HotTableModule.forRoot(),
FormlyModule.forRoot({
Expand Down
57 changes: 33 additions & 24 deletions src/app/ui/proform-add/proform-add.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,45 @@
<!-- invoice view page -->
<div class="col-xl-12 ">
<div class="card">
<div class="card-body">
<!-- header section -->
<div class="">
<form [formGroup]="form">
<formly-form [model]="model" [fields]="formFields" [options]="options" [form]="form"></formly-form>
</form>
</div>
<div class="col-xl-4">
<button type="submit" class="btn btn-primary submit-button" (click)="save()">Guardar</button>
<span></span>
<button type="submit" class="btn btn-primary submit-button" (click)="close()">Cancelar</button>
</div>
<div class="card-body">
<!-- header section -->
<div class="">
<form [formGroup]="form">
<formly-form [model]="model" [fields]="formFields" [options]="options" [form]="form"></formly-form>
</form>
</div>

<div class="col-xl-4">
<button type="submit" class="btn btn-primary submit-button" (click)="save()">Guardar</button>
<span></span>
<button type="submit" class="btn btn-primary submit-button" (click)="close()">Cancelar</button>
</div>
</div>
</div>
</div>
<div class="col-xl-12 ">
<div class="col-xl-12 ">
<div class="content-body">

<!--
<app-project [gridColumns]="gridColumns" [data]="data" [enabledTitleOp] = "enabledTitle"
[allowExcelExportOp] = "allowExcelExport" [defaultColDef] = "defaultColDefVal"
(exportExcel)= "onExportExcel($event)"></app-project>
-->
<app-grid [budgetRecords]="dataset" [columnsGrid]="columnsGrid" [columnsHeader] = "columnsHeader"
(change)="onChange($event)"></app-grid>


</div>
<!---->
<div class="content-body" >
<button type="submit" class="btn btn-primary submit-button" (click)="refreshData()">Actualizar Resumen Proforma</button>
<table class="table">
<thead>
<tr>
<th>Unidades</th>
<th>Subtotal</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ datasetSummary.quantity }}</td>
<td>{{ datasetSummary.subtotal }}</td>
<td>{{ datasetSummary.total }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Expand Down
33 changes: 31 additions & 2 deletions src/app/ui/proform-add/proform-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -93,6 +94,7 @@ export class ProformAddComponent implements OnInit {

}


ngOnInit() {
const self = this;
this.enabledTitle = false;
Expand Down Expand Up @@ -151,6 +153,8 @@ export class ProformAddComponent implements OnInit {

};

this.refreshData();

}


Expand Down Expand Up @@ -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)) ) {
Expand Down Expand Up @@ -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();

}

Expand Down
29 changes: 19 additions & 10 deletions src/app/ui/proform-edit/proform-edit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,27 @@
</div>
<div class="col-xl-12 ">
<div class="content-body" *ngIf="editProform">

<!--
<app-project [gridColumns]="gridColumns" [data]="data" [enabledTitleOp] = "enabledTitle"
[allowExcelExportOp] = "allowExcelExport" [defaultColDef] = "defaultColDefVal"
(exportExcel)= "onExportExcel($event)"></app-project>
-->
<app-grid [budgetRecords]="dataset" [columnsGrid]="columnsGrid" [columnsHeader] = "columnsHeader"
(change)="onChange($event)"></app-grid>


</div>
<div class="content-body" *ngIf="editProform">
<button type="submit" class="btn btn-primary submit-button" (click)="refreshData()">Actualizar Resumen Proforma</button>
<table class="table">
<thead>
<tr>
<th>Unidades</th>
<th>Subtotal</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ datasetSummary.quantity }}</td>
<td>{{ datasetSummary.subtotal }}</td>
<td>{{ datasetSummary.total }}</td>
</tr>
</tbody>
</table>
</div>
</div>
<ngx-ui-loader [loaderId]="loaderProjectForm" ></ngx-ui-loader>
Expand Down
34 changes: 30 additions & 4 deletions src/app/ui/proform-edit/proform-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -362,6 +363,7 @@ export class ProformEditComponent implements OnInit {
self.dataset.push(row);
};
}
this.refreshData();
});


Expand All @@ -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();

}

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 94f0941

Please sign in to comment.