diff --git a/src/app/app.module.ts b/src/app/app.module.ts index a066217..6dd3cd4 100755 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -93,11 +93,14 @@ import { FacturaCompraComponent } from './components/factura-compra/factura-comp import { NuevoRenglonFacturaModalComponent } from './components/nuevo-renglon-factura-modal/nuevo-renglon-factura-modal.component'; import { ConfiguracionComponent } from './components/configuracion/configuracion.component'; import { NgChartsModule } from 'ng2-charts'; +import { FormsModule } from '@angular/forms'; import { DashboardComponent } from './components/dashboard/dashboard.component'; import { ChartStatisticsMonthComponent } from './components/chart-statistics-month/chart-statistics-month.component'; import { ChartStatisticsMonthSupplierComponent } from './components/chart-statistics-month-supplier/chart-statistics-month-supplier.component'; import { ChartStatisticsYearComponent } from './components/chart-statistics-year/chart-statistics-year.component'; import { ChartStatisticsYearSupplierComponent } from './components/chart-statistics-year-supplier/chart-statistics-year-supplier.component'; +import { ChartTableSupplierComponent } from './components/chart-table-supplier/chart-table-supplier.component'; + registerLocaleData(localeEsAR, 'es-AR', localeEsARExtra); @@ -193,7 +196,8 @@ registerLocaleData(localeEsAR, 'es-AR', localeEsARExtra); ChartStatisticsMonthComponent, ChartStatisticsMonthSupplierComponent, ChartStatisticsYearComponent, - ChartStatisticsYearSupplierComponent + ChartStatisticsYearSupplierComponent, + ChartTableSupplierComponent ], imports: [ BrowserModule, @@ -202,7 +206,8 @@ registerLocaleData(localeEsAR, 'es-AR', localeEsARExtra); NgSelectModule, AppRoutingModule, ShareModule, - NgChartsModule + NgChartsModule, + FormsModule ], providers: [ { provide: LOCALE_ID, useValue: 'es-AR' }, diff --git a/src/app/components/chart-statistics-month-supplier/chart-statistics-month-supplier.component.html b/src/app/components/chart-statistics-month-supplier/chart-statistics-month-supplier.component.html index 3395966..1280cea 100644 --- a/src/app/components/chart-statistics-month-supplier/chart-statistics-month-supplier.component.html +++ b/src/app/components/chart-statistics-month-supplier/chart-statistics-month-supplier.component.html @@ -1,33 +1,12 @@ -
- {{ title }} -
- - -
-
- No hay información disponible para este periodo. Seleccione un mes diferente -
-
- - - - - - - - - - - - - - - -
#ProveedorMonto $
{{i + 1}}{{supplier.entidad}}{{supplier.monto | currency:'ARS':'symbol':'1.0-2'}}
-
-
\ No newline at end of file + + + diff --git a/src/app/components/chart-statistics-month-supplier/chart-statistics-month-supplier.component.ts b/src/app/components/chart-statistics-month-supplier/chart-statistics-month-supplier.component.ts index e68d74d..e190294 100644 --- a/src/app/components/chart-statistics-month-supplier/chart-statistics-month-supplier.component.ts +++ b/src/app/components/chart-statistics-month-supplier/chart-statistics-month-supplier.component.ts @@ -2,50 +2,33 @@ import { Component, Input } from '@angular/core'; import { ChartDirectiveDirective } from 'src/app/directives/chart-directive.directive'; import { ChartService } from 'src/app/services/chart.service'; + @Component({ selector: 'app-chart-statistics-month-supplier', - templateUrl: './chart-statistics-month-supplier.component.html', - styleUrls: ['./chart-statistics-month-supplier.component.scss'] + templateUrl: './chart-statistics-month-supplier.component.html' }) + export class ChartStatisticsMonthSupplierComponent extends ChartDirectiveDirective { + @Input() title: string; @Input() dataType: 'compras' | 'ventas'; - @Input() title: string = ''; + constructor(protected chartData: ChartService) { super(chartData); } loadChartData(year: number, month: number): void { - let chartDataPurchaseSale; - - if (this.dataType === 'compras') { - chartDataPurchaseSale = this.chartData.getChartDataPurchaseMonthSupplier(year, month); - } else if (this.dataType === 'ventas') { - chartDataPurchaseSale = this.chartData.getChartDataSalesMonthSupplier(year, month); - } + const chartDataPurchaseSale = this.dataType === 'compras' ? + this.chartData.getChartDataPurchaseMonthSupplier(year, month) : + this.chartData.getChartDataSalesMonthSupplier(year, month); chartDataPurchaseSale.subscribe({ - next: (data) => { - if (data && data.labels && data.datasets && data.datasets.length > 0) { - const labels = data.labels; - const datasetData = data.datasets[0].data; - - if (labels.length === datasetData.length) { - this.suppliers = labels.map((label, index) => ({ - entidad: label, - monto: datasetData[index], - })); - this.updateChart(data, labels); - } else { - console.log('Desajuste en la longitud de los datos'); - this.suppliers = []; - } - } - }, - error: (err) => { - console.log('Error al cargar los datos', err); - this.suppliers = []; - } - }) + next: (data) => this.handleChartData(data), + error: (err) => console.log('Error al cargar datos',err), + }); } + isMonthOptional(): boolean { + return false; + } + } diff --git a/src/app/components/chart-statistics-month/chart-statistics-month.component.ts b/src/app/components/chart-statistics-month/chart-statistics-month.component.ts index 6ec03db..5846464 100644 --- a/src/app/components/chart-statistics-month/chart-statistics-month.component.ts +++ b/src/app/components/chart-statistics-month/chart-statistics-month.component.ts @@ -43,4 +43,9 @@ export class ChartStatisticsMonthComponent extends ChartDirectiveDirective { } } + // onYearChange(year: string): void { + // this.selectedYear = parseInt(year, 10); + // this.loadInitialChartData(); + // } + } diff --git a/src/app/components/chart-statistics-year-supplier/chart-statistics-year-supplier.component.html b/src/app/components/chart-statistics-year-supplier/chart-statistics-year-supplier.component.html index daa6431..ab1ca68 100644 --- a/src/app/components/chart-statistics-year-supplier/chart-statistics-year-supplier.component.html +++ b/src/app/components/chart-statistics-year-supplier/chart-statistics-year-supplier.component.html @@ -1,28 +1,9 @@ -
- {{ title }} - -
- No hay información disponible para este periodo. Seleccione un mes diferente -
-
- - - - - - - - - - - - - - - -
#ProveedorMonto $
{{i + 1}}{{supplier.entidad}}{{supplier.monto | currency:'ARS':'symbol':'1.0-2'}}
-
-
\ No newline at end of file + + + diff --git a/src/app/components/chart-statistics-year-supplier/chart-statistics-year-supplier.component.scss b/src/app/components/chart-statistics-year-supplier/chart-statistics-year-supplier.component.scss deleted file mode 100644 index 6970db3..0000000 --- a/src/app/components/chart-statistics-year-supplier/chart-statistics-year-supplier.component.scss +++ /dev/null @@ -1,23 +0,0 @@ -.container { - padding-left: 4px; - padding-right: 4px; - width: 100%; - max-width: 100%; - box-sizing: border-box; -} - -.custom-table-responsive{ - height: 40vh; - overflow-y: auto; - width: 100%; - max-width: 100%; -} - -span { - font-size: 16px; - font-weight: bold; - display: flex; - justify-content: center; - align-items: center; - padding-bottom: 6px; -} diff --git a/src/app/components/chart-statistics-year-supplier/chart-statistics-year-supplier.component.ts b/src/app/components/chart-statistics-year-supplier/chart-statistics-year-supplier.component.ts index e721600..6a9f1b0 100644 --- a/src/app/components/chart-statistics-year-supplier/chart-statistics-year-supplier.component.ts +++ b/src/app/components/chart-statistics-year-supplier/chart-statistics-year-supplier.component.ts @@ -1,49 +1,30 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { Component, Input } from '@angular/core'; import { ChartDirectiveDirective } from 'src/app/directives/chart-directive.directive'; import { ChartService } from 'src/app/services/chart.service'; @Component({ selector: 'app-chart-statistics-year-supplier', - templateUrl: './chart-statistics-year-supplier.component.html', - styleUrls: ['./chart-statistics-year-supplier.component.scss'] + templateUrl: './chart-statistics-year-supplier.component.html' }) export class ChartStatisticsYearSupplierComponent extends ChartDirectiveDirective { + @Input() title: string; @Input() dataType: 'compras' | 'ventas'; - @Input() title: string = ''; - constructor(protected chartData: ChartService) { super(chartData); - } + } loadChartData(year: number): void { - let chartDataPurchaseSaleSupplier; + const chartDataPurchaseSaleSupplier = this.dataType === 'compras' ? + this.chartData.getChartDataPurchaseAnnualSupplier(year) : + this.chartData.getChartDataSalesAnnualSupplier(year); - if (this.dataType === 'compras') { - chartDataPurchaseSaleSupplier = this.chartData.getChartDataPurchaseAnnualSupplier(year) - } else if (this.dataType === 'ventas') { - chartDataPurchaseSaleSupplier = this.chartData.getChartDataSalesAnnualSupplier(year) - } chartDataPurchaseSaleSupplier.subscribe({ - next: (data) => { - if (data && data.labels && data.datasets && data.datasets.length > 0) { - const labels = data.labels; - const datasetData = data.datasets[0].data; - if (labels.length === datasetData.length) { - this.suppliers = labels.map((label, index) => ({ - entidad: label, - monto: datasetData[index], - })); - this.updateChart(data, labels); - } else { - console.log('Desajuste en la longitud de los datos'); - this.suppliers = []; - } - } - }, - error: (error) => { - console.error('Error al cargar los datos', error); - } + next: (data) => this.handleChartData(data), + error: (err) => console.log('Error al cargar datos', err), }) } + isMonthOptional(): boolean { + return true; + } } diff --git a/src/app/components/chart-table-supplier/chart-table-supplier.component.html b/src/app/components/chart-table-supplier/chart-table-supplier.component.html new file mode 100644 index 0000000..089fba8 --- /dev/null +++ b/src/app/components/chart-table-supplier/chart-table-supplier.component.html @@ -0,0 +1,33 @@ +
+ {{ title }} +
+ + +
+
+ No hay información disponible para este periodo. Seleccione otro periodo +
+
+ + + + + + + + + + + + + + + +
#ProveedorMonto $
{{i + 1}}{{supplier.entidad}}{{supplier.monto | currency:'ARS':'symbol':'1.0-2'}}
+
+
\ No newline at end of file diff --git a/src/app/components/chart-statistics-month-supplier/chart-statistics-month-supplier.component.scss b/src/app/components/chart-table-supplier/chart-table-supplier.component.scss similarity index 100% rename from src/app/components/chart-statistics-month-supplier/chart-statistics-month-supplier.component.scss rename to src/app/components/chart-table-supplier/chart-table-supplier.component.scss diff --git a/src/app/components/chart-table-supplier/chart-table-supplier.component.ts b/src/app/components/chart-table-supplier/chart-table-supplier.component.ts new file mode 100644 index 0000000..cca0cbe --- /dev/null +++ b/src/app/components/chart-table-supplier/chart-table-supplier.component.ts @@ -0,0 +1,42 @@ +import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { ChartInterface } from 'src/app/models/chart-interface'; + + +@Component({ + selector: 'app-chart-table-supplier', + templateUrl: './chart-table-supplier.component.html', + styleUrls: ['./chart-table-supplier.component.scss'] +}) +export class ChartTableSupplierComponent { + @Input() title: string = ''; + @Input() suppliers: ChartInterface[] = []; + @Input() years: number[] = []; + @Input() months: {value: number, name: string}[] = []; + @Input() selectedYear: number | null = null; + @Input() selectedMonth: number | null = null; + @Input() showMonthSelector: boolean = true; + + @Output() yearChange = new EventEmitter(); + @Output() monthChange = new EventEmitter(); + + onYearChange($event: Event): void { + const target = $event.target as HTMLSelectElement; + if (target && target.value) { + const year = parseInt(target.value, 10); + this.yearChange.emit(year); + } else { + console.error("Error: El evento no tiene un valor válido", $event); + } +} + + onMonthChange($event: Event): void { + const target = $event.target as HTMLSelectElement; + if (target && target.value) { + const month = parseInt(target.value, 10); + this.monthChange.emit(month); + } else { + console.error("Error: El evento no tiene un valor válido", $event); + } +} + +} diff --git a/src/app/components/dashboard/dashboard.component.html b/src/app/components/dashboard/dashboard.component.html index d2fc07d..c2ca2da 100644 --- a/src/app/components/dashboard/dashboard.component.html +++ b/src/app/components/dashboard/dashboard.component.html @@ -22,18 +22,22 @@

- +
- +
- +
- +
@@ -57,18 +61,22 @@

- +
- +
- +
- +
diff --git a/src/app/components/dashboard/dashboard.component.ts b/src/app/components/dashboard/dashboard.component.ts index 76f99c8..986bcf4 100644 --- a/src/app/components/dashboard/dashboard.component.ts +++ b/src/app/components/dashboard/dashboard.component.ts @@ -17,12 +17,12 @@ export class DashboardComponent implements OnInit { allowedRolesToView = [Rol.ADMINISTRADOR, Rol.ENCARGADO]; constructor(private authService: AuthService, - private router: Router, - private cdr: ChangeDetectorRef, - private chartService: ChartService, - accordionConfig: NgbAccordionConfig) { - - accordionConfig.type = 'dark'; + private router: Router, + private cdr: ChangeDetectorRef, + private chartService: ChartService, + accordionConfig: NgbAccordionConfig) { + + accordionConfig.type = 'dark'; } ngOnInit(): void { diff --git a/src/app/directives/chart-directive.directive.ts b/src/app/directives/chart-directive.directive.ts index 30f8e71..3f263f7 100644 --- a/src/app/directives/chart-directive.directive.ts +++ b/src/app/directives/chart-directive.directive.ts @@ -49,30 +49,59 @@ export abstract class ChartDirectiveDirective implements OnInit { constructor(protected chartData: ChartService) { } ngOnInit(): void { - this.years = this.generateYearData(); this.months = this.generateMonthsData(); - if (this.selectedYear && this.selectedMonth) { - this.loadChartData(this.selectedYear, this.selectedMonth!); + + this.selectedMonth = this.selectedMonth || (new Date().getMonth() + 1); + + if (this.selectedYear && (this.selectedMonth || this.isMonthOptional())) { + this.loadChartData(this.selectedYear, this.selectedMonth); } } - abstract loadChartData(year: number, month: number): void; + abstract loadChartData(year: number, month?: number | null): void; - onYearChange($event: Event): void { - const year = parseInt(($event.target as HTMLSelectElement).value, 10); - this.selectedYear = year; - this.selectedMonth = new Date().getMonth() + 1; - if (this.selectedYear && this.selectedMonth) { - this.loadChartData(this.selectedYear, this.selectedMonth!); + isMonthOptional(): boolean { + return true; + } + + onYearChange(year: number | Event): void { + if (typeof year === 'number') { + this.selectedYear = year; + this.selectedMonth = this.selectedMonth || new Date().getMonth() + 1; + if (this.selectedYear && this.selectedMonth) { + this.loadChartData(this.selectedYear, this.selectedMonth!); + } + } else if (year instanceof Event) { + const target = (year.target as HTMLSelectElement); + if (target && target.value) { + const parsedYear = parseInt(target.value, 10); + this.selectedYear = parsedYear; + this.selectedMonth = this.selectedMonth || new Date().getMonth() + 1; + if (this.selectedYear && this.selectedMonth) { + this.loadChartData(this.selectedYear, this.selectedMonth!); + } + } else { + console.error("Error: El evento no tiene un valor válido", year); + } + } else { + console.error("Error: Tipo inesperado de parámetro en onYearChange", year); } } - OnMonthChange($event: Event): void { - const month = parseInt(($event.target as HTMLSelectElement).value, 10); - this.selectedMonth = month; + onMonthChange(month: number | Event): void { + if (typeof month === 'number') { + this.selectedMonth = month; + } else if (month instanceof Event) { + const target = (month.target as HTMLSelectElement); + if (target && target.value) { + this.selectedMonth = parseInt(target.value, 10); + } + } + this.selectedMonth = this.selectedMonth || new Date().getMonth() + 1; + if (this.selectedYear && this.selectedMonth) { - this.loadChartData(this.selectedYear, this.selectedMonth!); + this.loadChartData(this.selectedYear, this.selectedMonth); } } @@ -84,6 +113,7 @@ export abstract class ChartDirectiveDirective implements OnInit { generateMonthsData(): { value: number, name: string }[] { const monthsNames = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']; + return monthsNames.map((name, index) => ({ value: index + 1, name })) @@ -106,4 +136,22 @@ export abstract class ChartDirectiveDirective implements OnInit { }; } + protected handleChartData(data: any): void { + if (data && data.labels && data.datasets && data.datasets.length > 0) { + const labels = data.labels; + const datasetData = data.datasets[0].data; + + if (labels.length === datasetData.length) { + this.suppliers = labels.map((label, index) => ({ + entidad: label, + monto: datasetData[index], + })); + this.updateChart(data, labels); + } else { + console.log('Desajuste en la longitud de los datos'); + this.suppliers = []; + } + } + } + } diff --git a/src/app/services/chart.service.ts b/src/app/services/chart.service.ts index 415a0bb..1e385e6 100644 --- a/src/app/services/chart.service.ts +++ b/src/app/services/chart.service.ts @@ -115,6 +115,7 @@ export class ChartService { getChartDataSalesAnnualSupplier(year: number): Observable<{labels: string[], datasets:{data: number[], label: string }[] }> { const idSucursal = this.sucursalesService.getIdSucursal(); const url = `${this.urlSalesStatistics}/rubros/monto-neto-anual/sucursales/${idSucursal}?anio=${year}`; + return this.http.get(url).pipe( map(data => { const labels = data.map(item => item.entidad); const dataset = data.map(item => item.monto);