diff --git a/matsen-tool/src/app/app-routing.module.ts b/matsen-tool/src/app/app-routing.module.ts index 3281c28..081653b 100644 --- a/matsen-tool/src/app/app-routing.module.ts +++ b/matsen-tool/src/app/app-routing.module.ts @@ -12,6 +12,7 @@ import {DocumentsComponent} from "@app/documents/documents.component"; import {ContactsComponent} from "@app/contacts/contacts.component"; import {ContactsDetailComponent} from "@app/contacts/contacts-detail/contacts-detail.component"; import {TasksComponent} from "@app/tasks/tasks.component"; +import {SalesComponent} from "@app/sales/sales.component"; const accountModule = () => import('./account/account.module').then(x => x.AccountModule); const usersModule = () => import('./users/users.module').then(x => x.UsersModule); @@ -81,6 +82,14 @@ const routes: Routes = [ {path: '', component: DocumentsComponent, data: {dataType: 'document'}}, ] }, + { + path: 'sales', + component: TwoColumnComponent, + canActivate: [AuthGuard], + children: [ + {path: '', component: SalesComponent, data: {dataType: 'sales'}}, + ] + }, // otherwise redirect to home {path: '**', redirectTo: ''} diff --git a/matsen-tool/src/app/app.module.ts b/matsen-tool/src/app/app.module.ts index e5a7ec5..998d79c 100644 --- a/matsen-tool/src/app/app.module.ts +++ b/matsen-tool/src/app/app.module.ts @@ -43,6 +43,8 @@ import {MatFormFieldModule} from "@angular/material/form-field"; import {MatInputModule} from "@angular/material/input"; import { NewTaskNoteComponent } from './tasks/new-task-note/new-task-note.component'; import { DocumentsDetailComponent } from './documents/documents-detail/documents-detail.component'; +import { SalesComponent } from './sales/sales.component'; +import { SalesDetailComponent } from './sales/sales-detail/sales-detail.component'; export function apiConfigFactory(): Configuration { const params: ConfigurationParameters = { @@ -106,7 +108,9 @@ export function HttpLoaderFactory(http: HttpClient) { NewProductComponent, NewCommentComponent, NewTaskNoteComponent, - DocumentsDetailComponent + DocumentsDetailComponent, + SalesComponent, + SalesDetailComponent ], providers: [ {provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true}, diff --git a/matsen-tool/src/app/layout/two-column/two-column.component.html b/matsen-tool/src/app/layout/two-column/two-column.component.html index 21c180f..9bb4234 100644 --- a/matsen-tool/src/app/layout/two-column/two-column.component.html +++ b/matsen-tool/src/app/layout/two-column/two-column.component.html @@ -43,6 +43,13 @@ +
diff --git a/matsen-tool/src/app/partners/partners.component.html b/matsen-tool/src/app/partners/partners.component.html index 8458063..61152ba 100644 --- a/matsen-tool/src/app/partners/partners.component.html +++ b/matsen-tool/src/app/partners/partners.component.html @@ -1,6 +1,6 @@
-

{{ partnerName }}

+

{{ headline }}

diff --git a/matsen-tool/src/app/partners/partners.component.ts b/matsen-tool/src/app/partners/partners.component.ts index 8d9862f..6b6ce6c 100644 --- a/matsen-tool/src/app/partners/partners.component.ts +++ b/matsen-tool/src/app/partners/partners.component.ts @@ -33,7 +33,7 @@ export class PartnersComponent implements OnInit, AfterViewInit { protected websiteOrderAsc: OrderFilter; protected dataType!: string; - protected partnerName: string; + protected headline: string; protected partnerNameOne: string; protected displayedColumns: string[]; @@ -71,7 +71,7 @@ export class PartnersComponent implements OnInit, AfterViewInit { this.partnersPageSize = 10; this.partnersPageIndex = 0; - this.partnerName = ""; + this.headline = ""; this.partnerNameOne = ""; } @@ -79,7 +79,7 @@ export class PartnersComponent implements OnInit, AfterViewInit { this.dataType = this.route.snapshot.data['dataType']; // this.translateService.use(this.translateService.getDefaultLang()); this.translateService.get('basic.' + this.dataType).subscribe((translation: string) => { - this.partnerName = translation; + this.headline = translation; }); this.translateService.get('basic.' + this.dataType + 'One').subscribe((translation: string) => { this.partnerNameOne = translation; diff --git a/matsen-tool/src/app/sales/sales-detail/sales-detail.component.html b/matsen-tool/src/app/sales/sales-detail/sales-detail.component.html new file mode 100644 index 0000000..30220e8 --- /dev/null +++ b/matsen-tool/src/app/sales/sales-detail/sales-detail.component.html @@ -0,0 +1 @@ +

sales-detail works!

diff --git a/matsen-tool/src/app/sales/sales-detail/sales-detail.component.scss b/matsen-tool/src/app/sales/sales-detail/sales-detail.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/matsen-tool/src/app/sales/sales-detail/sales-detail.component.spec.ts b/matsen-tool/src/app/sales/sales-detail/sales-detail.component.spec.ts new file mode 100644 index 0000000..94ce4c2 --- /dev/null +++ b/matsen-tool/src/app/sales/sales-detail/sales-detail.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SalesDetailComponent } from './sales-detail.component'; + +describe('SalesDetailComponent', () => { + let component: SalesDetailComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [SalesDetailComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(SalesDetailComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/matsen-tool/src/app/sales/sales-detail/sales-detail.component.ts b/matsen-tool/src/app/sales/sales-detail/sales-detail.component.ts new file mode 100644 index 0000000..3e91f64 --- /dev/null +++ b/matsen-tool/src/app/sales/sales-detail/sales-detail.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-sales-detail', + templateUrl: './sales-detail.component.html', + styleUrl: './sales-detail.component.scss' +}) +export class SalesDetailComponent { + +} diff --git a/matsen-tool/src/app/sales/sales.component.html b/matsen-tool/src/app/sales/sales.component.html new file mode 100644 index 0000000..9540d44 --- /dev/null +++ b/matsen-tool/src/app/sales/sales.component.html @@ -0,0 +1,96 @@ +
+
{{ saleSummary.ownerName }} - {{ saleSummary.turnover }} - {{ saleSummary.profit }}
+
+ + +
+
+

{{ 'basic.sales' | translate }}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {{ 'overview.number' | translate }} + {{ (pageSize * pageIndex) + dataSource.filteredData.indexOf(element) + 1 }} + + {{ 'overview.sale-user' | translate }} + + + {{ element.ownerName }} + + + {{ 'overview.sale-partner' | translate }} + + {{ element.partnerName }} + + {{ 'overview.productname' | translate }} + + {{ element.productName }} + + {{ 'overview.turnover' | translate }} + + {{ element.turnover }} + + {{ 'overview.profit' | translate }} + + {{ element.profit }} + + {{ 'overview.createdAt' | translate }} + + {{ element.createdAt }} +
+ + +
\ No newline at end of file diff --git a/matsen-tool/src/app/sales/sales.component.scss b/matsen-tool/src/app/sales/sales.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/matsen-tool/src/app/sales/sales.component.spec.ts b/matsen-tool/src/app/sales/sales.component.spec.ts new file mode 100644 index 0000000..9eb2cff --- /dev/null +++ b/matsen-tool/src/app/sales/sales.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SalesComponent } from './sales.component'; + +describe('SalesComponent', () => { + let component: SalesComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [SalesComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(SalesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/matsen-tool/src/app/sales/sales.component.ts b/matsen-tool/src/app/sales/sales.component.ts new file mode 100644 index 0000000..b1550c5 --- /dev/null +++ b/matsen-tool/src/app/sales/sales.component.ts @@ -0,0 +1,154 @@ +import {ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core'; +import { + PartnerJsonld, ProductJsonld, + SaleJsonld, + SaleService, + SaleSummaryJsonld, + SaleSummaryService +} from "@app/core/api/v1"; +import {Subscription} from "rxjs"; +import {MatPaginator, MatPaginatorIntl, PageEvent} from "@angular/material/paginator"; +import {MatSort, Sort} from "@angular/material/sort"; +import {TranslateService} from "@ngx-translate/core"; +import {NewPartnerComponent} from "@app/partners/new-partner/new-partner.component"; +import {ModalStatus} from "@app/_helpers/modal.states"; +import {NgbModal, NgbModalOptions} from "@ng-bootstrap/ng-bootstrap"; +import {MatTableDataSource} from "@angular/material/table"; +import {OrderFilter} from "@app/_models/orderFilter"; +import {ApiConverter} from "@app/_helpers/api.converter"; +import {Router} from "@angular/router"; + +@Component({ + selector: 'app-sales', + templateUrl: './sales.component.html', + styleUrl: './sales.component.scss' +}) +export class SalesComponent implements OnInit { + @ViewChild(MatSort) sort; + @ViewChild(MatPaginator) paginator: MatPaginator; + + + protected displayedColumns: string[]; + protected salesSub: Subscription; + protected sales: Array; + protected salesSummarySub: Subscription; + protected saleSummaries: Array; + + protected dataSource; + protected length: number; + protected pageEvent: PageEvent; + protected pageSize: number; + protected pageIndex: number; + + protected modalOptions: NgbModalOptions = { + centered: true + }; + + constructor( + private saleService: SaleService, + private saleSummaryService: SaleSummaryService, + private translateService: TranslateService, + private modalService: NgbModal, + private router: Router, + + ) { + this.sort = new MatSort(); + this.displayedColumns = ['pos', 'user', 'partner', 'product', 'turnover', 'profit', 'date']; + this.salesSub = new Subscription(); + this.sales = []; + this.salesSummarySub = new Subscription(); + this.saleSummaries = []; + + this.dataSource = new MatTableDataSource(this.sales); + this.paginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype); + this.length = 0; + this.pageEvent = new PageEvent(); + this.pageSize = 10; + this.pageIndex = 0; + } + + ngOnInit() { + this.getSalesData(); + this.getSalesSummaryData(); + } + + getSalesData() { + this.salesSub = this.saleService.salesGetCollection( + this.pageIndex + 1, + this.pageSize, + ).subscribe( + data => { + this.sales = data["hydra:member"]; + this.dataSource = new MatTableDataSource(this.sales); + this.length = Number(data["hydra:totalItems"]); + this.paginator.length = this.length; + console.log(this.sales); + } + ) + } + + getSalesSummaryData() { + this.salesSummarySub = this.saleSummaryService.saleSummariesGetCollection( + 1, + 50 + ).subscribe( + data => { + this.saleSummaries = data["hydra:member"]; + console.log(this.saleSummaries); + } + ) + } + + onSortChange(sortState: Sort) { + // Reset page index to first page + this.pageIndex = 0; + + let order: OrderFilter; + if (sortState.direction === "") { + order = OrderFilter.Undefined; + } else { + order = sortState.direction; + } + + // this.nameOrderAsc = OrderFilter.Undefined; + // this.cityOrderAsc = OrderFilter.Undefined; + // this.websiteOrderAsc = OrderFilter.Undefined; + // switch (sortState.active) { + // case "name": + // this.nameOrderAsc = order; + // break; + // case "address": + // this.cityOrderAsc = order; + // break; + // case "website": + // this.websiteOrderAsc = order; + // break; + // } + this.getSalesData(); + } + + handlePageEvent(e: PageEvent) { + this.pageEvent = e; + this.length = e.length; + this.pageIndex = e.pageIndex.valueOf(); + this.pageSize = e.pageSize.valueOf(); + this.getSalesData(); + } + + navigateToSaleDetails(element: any) { + const product: ProductJsonld = element as ProductJsonld; + this.router.navigate(['/products', ApiConverter.extractId(product.id)]); + } + + openModalNewSale() { + const modalRefContact = this.modalService.open(NewPartnerComponent, this.modalOptions); + let sale: SaleJsonld = {} as SaleJsonld; + modalRefContact.componentInstance.partner = sale; + modalRefContact.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { + if (modalStatus === ModalStatus.Submitted) { + modalRefContact.dismiss(); + this.getSalesData(); + } + }); + } +} diff --git a/matsen-tool/src/assets/i18n/de.json b/matsen-tool/src/assets/i18n/de.json index 17049d2..60464b7 100644 --- a/matsen-tool/src/assets/i18n/de.json +++ b/matsen-tool/src/assets/i18n/de.json @@ -18,6 +18,7 @@ "serviceOne": "Lieferant", "products": "Produkte", "documents": "Dokumente", + "sales": "Verkäufe", "tasks": "Aufgaben", "contacts": "Kontakte", "posts": "Notizen", @@ -30,6 +31,7 @@ "new-post": "Neue Notiz", "new-comment": "Neuer Kommentar", "new-task-note": "Neue Anmerkung", + "new-sale": "Neuer Verkauf", "edit-before": "", "edit-after": "bearbeiten", "edit-product": "Produkt bearbeiten", @@ -58,7 +60,7 @@ "address": "Adresse", "website": "Website", "image": "Bild", - "productname": "Produktname", + "productname": "Produkt", "storage": "Lagerbestand", "number-long": "Nummer", "document": "Dokument", @@ -68,7 +70,12 @@ "createdBy": "Erstellt von", "download": "Download", "partner": "Partner", - "product": "Produkt" + "product": "Produkt", + "sale-user": "Verkäufer", + "sale-partner": "Kunde", + "turnover": "Umsatz", + "profit": "Gewinn", + "createdAt": "erstellt am" }, "form": {