Customer discount with prefill discount in sales.
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve } from '@angular/router';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
|
||||
import { SettingsService } from './settings.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class PrefillCustomerDiscountResolver implements Resolve<boolean> {
|
||||
constructor(private ser: SettingsService) {}
|
||||
|
||||
resolve(): Observable<boolean> {
|
||||
return this.ser.getPrefillCustomerDiscount();
|
||||
}
|
||||
}
|
||||
29
bookie/src/app/settings/settings-routing.module.ts
Normal file
29
bookie/src/app/settings/settings-routing.module.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
|
||||
import { PrefillCustomerDiscountResolver } from './prefill-customer-discount-resolver.service';
|
||||
import { SettingsComponent } from './settings.component';
|
||||
|
||||
const settingsRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: SettingsComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Settings',
|
||||
},
|
||||
resolve: {
|
||||
prefillCustomerDiscount: PrefillCustomerDiscountResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [CommonModule, RouterModule.forChild(settingsRoutes)],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class SettingsRoutingModule {}
|
||||
32
bookie/src/app/settings/settings.component.css
Normal file
32
bookie/src/app/settings/settings.component.css
Normal file
@ -0,0 +1,32 @@
|
||||
.right {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.selected {
|
||||
background: #fff3cd;
|
||||
}
|
||||
|
||||
.unposted {
|
||||
background: #f8d7da;
|
||||
}
|
||||
|
||||
.center {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.img-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.img-container .overlay {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.img-container:hover > .overlay {
|
||||
display: inline-block;
|
||||
position: absolute;
|
||||
left: 60px;
|
||||
top: 0;
|
||||
}
|
||||
18
bookie/src/app/settings/settings.component.html
Normal file
18
bookie/src/app/settings/settings.component.html
Normal file
@ -0,0 +1,18 @@
|
||||
<mat-tab-group>
|
||||
<mat-tab label="Prefill Customer Discount">
|
||||
<mat-card>
|
||||
<mat-card-content>
|
||||
<mat-slide-toggle
|
||||
(click)="togglePrefill()"
|
||||
fxFlex="100"
|
||||
[checked]="prefillCustomerDiscount"
|
||||
>
|
||||
Prefill the customer discount
|
||||
</mat-slide-toggle>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
<footer class="footer">
|
||||
<p>Backend: v{{ auth.user?.ver }} / Frontend: v{{ version }}</p>
|
||||
</footer>
|
||||
50
bookie/src/app/settings/settings.component.ts
Normal file
50
bookie/src/app/settings/settings.component.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { environment } from '../../environments/environment';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
|
||||
import { SettingsService } from './settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-settings',
|
||||
templateUrl: './settings.component.html',
|
||||
styleUrls: ['./settings.component.css'],
|
||||
})
|
||||
export class SettingsComponent implements OnInit {
|
||||
prefillCustomerDiscount = true;
|
||||
|
||||
version: string;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private dialog: MatDialog,
|
||||
private toaster: ToasterService,
|
||||
public auth: AuthService,
|
||||
private ser: SettingsService,
|
||||
) {
|
||||
this.version = environment.version;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as {
|
||||
prefillCustomerDiscount: boolean;
|
||||
};
|
||||
|
||||
this.prefillCustomerDiscount = data.prefillCustomerDiscount;
|
||||
});
|
||||
}
|
||||
|
||||
togglePrefill() {
|
||||
this.ser.setPrefillCustomerDiscount(!this.prefillCustomerDiscount).subscribe((x) => {
|
||||
this.prefillCustomerDiscount = x;
|
||||
});
|
||||
}
|
||||
}
|
||||
81
bookie/src/app/settings/settings.module.ts
Normal file
81
bookie/src/app/settings/settings.module.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import { A11yModule } from '@angular/cdk/a11y';
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { MomentDateAdapter } from '@angular/material-moment-adapter';
|
||||
import { MatAutocompleteModule } from '@angular/material/autocomplete';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import {
|
||||
DateAdapter,
|
||||
MAT_DATE_FORMATS,
|
||||
MAT_DATE_LOCALE,
|
||||
MatNativeDateModule,
|
||||
} from '@angular/material/core';
|
||||
import { MatDatepickerModule } from '@angular/material/datepicker';
|
||||
import { MatDialogModule } from '@angular/material/dialog';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatPaginatorModule } from '@angular/material/paginator';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatSlideToggle, MatSlideToggleModule } from '@angular/material/slide-toggle';
|
||||
import { MatSortModule } from '@angular/material/sort';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
|
||||
import { SettingsRoutingModule } from './settings-routing.module';
|
||||
import { SettingsComponent } from './settings.component';
|
||||
|
||||
export const MY_FORMATS = {
|
||||
parse: {
|
||||
dateInput: 'DD-MMM-YYYY',
|
||||
},
|
||||
display: {
|
||||
dateInput: 'DD-MMM-YYYY',
|
||||
monthYearLabel: 'MMM YYYY',
|
||||
dateA11yLabel: 'DD-MMM-YYYY',
|
||||
monthYearA11yLabel: 'MMM YYYY',
|
||||
},
|
||||
};
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
A11yModule,
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatAutocompleteModule,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatCheckboxModule,
|
||||
MatDatepickerModule,
|
||||
MatDialogModule,
|
||||
MatSlideToggleModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatNativeDateModule,
|
||||
MatPaginatorModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSelectModule,
|
||||
MatSortModule,
|
||||
MatTableModule,
|
||||
MatTabsModule,
|
||||
ReactiveFormsModule,
|
||||
SharedModule,
|
||||
SettingsRoutingModule,
|
||||
],
|
||||
declarations: [SettingsComponent],
|
||||
providers: [
|
||||
{ provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] },
|
||||
{ provide: MAT_DATE_FORMATS, useValue: MY_FORMATS },
|
||||
],
|
||||
})
|
||||
export class SettingsModule {}
|
||||
31
bookie/src/app/settings/settings.service.ts
Normal file
31
bookie/src/app/settings/settings.service.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
|
||||
const serviceName = 'SettingsService';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class SettingsService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
getPrefillCustomerDiscount(): Observable<boolean> {
|
||||
const url = '/api/settings/prefill-customer-discount';
|
||||
return this.http.get<{ value: boolean }>(url).pipe(
|
||||
map((x) => x.value),
|
||||
catchError(this.log.handleError(serviceName, 'getPrefillCustomerDiscount')),
|
||||
) as Observable<boolean>;
|
||||
}
|
||||
|
||||
setPrefillCustomerDiscount(value: boolean): Observable<boolean> {
|
||||
const url = '/api/settings/prefill-customer-discount';
|
||||
return this.http
|
||||
.post<{ value: boolean }>(url, { value: value })
|
||||
.pipe(
|
||||
map((x) => x.value),
|
||||
catchError(this.log.handleError(serviceName, 'setPrefillCustomerDiscount')),
|
||||
) as Observable<boolean>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user