Skip to content

Commit

Permalink
Update customer flow
Browse files Browse the repository at this point in the history
  • Loading branch information
deep-mm committed Nov 8, 2022
1 parent bdcbf57 commit 157518a
Show file tree
Hide file tree
Showing 8 changed files with 421 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,47 @@ <h3><strong>Cart</strong></h3>
<tr class="header" style="background-color: #ffffff;">
<th scope="col">Service ID</th>
<th scope="col">Service Name</th>
<th scope="col">Service Time (hrs)</th>
<th scope="col">Service Price ($)</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let service of cartService" class="table-row-item">
<td>{{service.id}}</td>
<td>{{service.service_NAME}}</td>
<td>{{getServiceTime(service)}}</td>
<td>{{getServicePrice(service)}}</td>
</tr>
<tr>
<td><strong>Total</strong></td>
<td></td>
<td><strong>{{getTotalTime()}}</strong></td>
<td><strong>{{getTotalPrice()}}</strong></td>
</tr>
</tbody>
</table>
<div>
<mat-label>Preferred Date</mat-label><br>
<mat-form-field appearance="outline">
<input matInput #PreferredDate="ngModel" [(ngModel)]="preferredDate" name="PreferredDate" required min="{{date | date:'yyyy-MM-dd'}}"
type="date" [class.is-invalid]="PreferredDate.invalid && (PreferredDate.touched || PreferredDate.dirty)">
<mat-error *ngIf="PreferredDate.invalid && (PreferredDate.touched || PreferredDate.dirty)">
Enter a valid date
</mat-error>
</mat-form-field>
</div>
<div>
<mat-label>Preferred Start Time</mat-label><br>
<mat-form-field appearance="outline">
<select matNativeControl [(ngModel)]="preferredTime" name="time">
<option value="" selected></option>
<option *ngFor="let t of time" [value]="t">
{{t + ":00"}}
</option>
</select>
</mat-form-field>
</div>
<br>
<button mat-raised-button (click)="checkout()" *ngIf="cartService.length>0">Checkout</button>

<br><br>
Expand All @@ -26,24 +58,27 @@ <h3><strong>Repair Services</strong></h3>
<tr class="header" style="background-color: #ffffff;">
<th scope="col">Service ID</th>
<th scope="col">Service Name</th>
<th scope="col">Service Time (hrs)</th>
<th scope="col">Service Price ($)</th>
<th scope="col">Add to cart</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let service of onlyRepairServices" class="table-row-item">
<td>{{service.id}}</td>
<td>{{service.service_NAME}}</td>
<td>{{getServiceTime(service)}}</td>
<td>{{getServicePrice(service)}}</td>
<td>
<button mat-raised-button (click)="addToCart(service)" *ngIf="!isServiceInCart(service)">Add to cart</button>
<button mat-raised-button (click)="addToCart(service)" *ngIf="!isServiceInCart(service)" [disabled]="getServiceTime(service) > remainingTime">Add to cart</button>
</td>
</tr>
</tbody>
</table>

<div style="margin-bottom: 50px;">
<h3><strong>Maintenance Service</strong></h3>
<h4>Your next scheduled maintenance is: Schedule {{this.nextScheduledService}} <button mat-raised-button (click)="addMaintenanceServicesToCart()" *ngIf="!maintenanceServiceAdded" style="margin-left: 10px;">Add to cart</button></h4>
<h4>Your next scheduled maintenance is: <strong>Schedule {{this.nextScheduledService}}</strong> <button mat-raised-button (click)="addMaintenanceServicesToCart()" *ngIf="!maintenanceServiceAdded" style="margin-left: 10px;">Add to cart</button></h4>
</div>
<br><br>
</div>

145 changes: 138 additions & 7 deletions service-center-app/src/app/add-schedule/add-schedule.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { DatePipe } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Router } from '@angular/router';
import { Customer } from '../models/Customer';
import { CustomerCar } from '../models/CustomerCar';
import { Invoice } from '../models/Invoice';
import { MaintenanceService } from '../models/MaintenanceService';
import { RepairService } from '../models/RepairService';
import { Service } from '../models/Service';
import { ServiceCenterProvidesService } from '../models/ServiceCenterProvidesService';
import { ServiceEvent } from '../models/ServiceEvent';
import { ServicesCar } from '../models/ServicesCar';
import { ServiceCenterProvidesServiceService } from '../services/service-center-provides-service/service-center-provides-service.service';
import { ServiceService } from '../services/service/service.service';

@Component({
Expand All @@ -27,15 +33,23 @@ export class AddScheduleComponent implements OnInit {
nextScheduledService: String = '';
nextScheduledServiceId: number = 0;
maintenanceServiceAdded: boolean = false;
serviceCars: ServicesCar[] = [];
scps: ServiceCenterProvidesService[] = [];
preferredDate: Date = new Date();
date: Date = new Date();
time = [8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19]
preferredTime: number = 0;
remainingTime: number = 11;
mechanicId: number = 0;

constructor(public router: Router, public _apiService: ServiceService, private _snackBar: MatSnackBar) { }
constructor(public router: Router, public _apiService: ServiceService, private _snackBar: MatSnackBar, public scpsApi: ServiceCenterProvidesServiceService) { }

ngOnInit(): void {
this.loading = true;
this.customer = ServiceService.selectedCustomer;
this.customerCar = ServiceService.selectedCustomerCar;
this.nextScheduledService = this.customerCar.last_SCHEDULED_MAINTENANCE==1?'B':(this.customerCar.last_SCHEDULED_MAINTENANCE==2?'C':'A');
this.nextScheduledServiceId = this.customerCar.last_SCHEDULED_MAINTENANCE==1?2:(this.customerCar.last_SCHEDULED_MAINTENANCE==2?3:1);
this.nextScheduledService = this.customerCar.last_SCHEDULED_MAINTENANCE == 1 ? 'B' : (this.customerCar.last_SCHEDULED_MAINTENANCE == 2 ? 'C' : 'A');
this.nextScheduledServiceId = this.customerCar.last_SCHEDULED_MAINTENANCE == 1 ? 2 : (this.customerCar.last_SCHEDULED_MAINTENANCE == 2 ? 3 : 1);
this._apiService.getServices().subscribe(
(res: any) => {
this.services = res;
Expand All @@ -47,7 +61,25 @@ export class AddScheduleComponent implements OnInit {
(res: any) => {
this.repairServices = res;
this.onlyRepairServices = this.services.filter(service => this.checkIfServiceIsRepair(service));
this.loading = false;
this.scpsApi.getServiceCenterProvidesServices(this.customer.service_CENTER_ID).subscribe(
(res: any) => {
this.scps = res;
this._apiService.getServiceCars(this.customerCar.car_ID).subscribe(
(res: any) => {
this.serviceCars = res;
this.loading = false;
},
(err: any) => {
this.loading = false;
console.log(err);
}
);
},
(err: any) => {
this.loading = false;
console.log(err);
}
);
},
error => {
this.loading = false;
Expand Down Expand Up @@ -91,6 +123,8 @@ export class AddScheduleComponent implements OnInit {
this._snackBar.open('Service added to cart', 'Close', {
duration: 2000,
});
this.remainingTime = this.remainingTime - this.getServiceTime(service);
this.time = this.time.slice(0, this.remainingTime + 1);
}

removeFromCart(service: Service) {
Expand All @@ -115,10 +149,107 @@ export class AddScheduleComponent implements OnInit {
this._snackBar.open('Maintenance services added to cart', 'Close', {
duration: 2000,
});
this.remainingTime = 11 - this.getTotalTime();
this.time = this.time.slice(0, this.remainingTime + 1);
}

checkout() {
ServiceService.selectedServices = this.cartService;
this.router.navigate(['/checkout']);
getServiceTime(service: Service): number {
for (const element of this.serviceCars) {
if (element.id == service.id) {
return element.time_ESTIMATED;
}
}
return 0;
}

getServicePrice(service: Service) {
for (const element of this.scps) {
if (element.id == service.id) {
return element.price;
}
}
return 0;
}

getTotalTime() {
let total = 0;
for (const element of this.cartService) {
total += this.getServiceTime(element);
}
return total;
}

getTotalPrice() {
let total = 0;
for (const element of this.cartService) {
total += this.getServicePrice(element);
}
return total;
}

checkout() {
this.loading = true;
let datePipe = new DatePipe('en-US');
let dateString = datePipe.transform(this.preferredDate, 'dd-MMM-yyyy')!.toString();
let currentStartTime = this.preferredTime;
this._apiService.getAvailableMechanic(this.customer.service_CENTER_ID, dateString).subscribe(
(res: any) => {
this.mechanicId = res;
let invoiceId = Math.floor(Math.random() * 90000) + 10000;
let invoice = new Invoice({
invoice_ID: invoiceId,
invoice_STATUS: 0,
total_COST: this.getTotalPrice()
});
this._apiService.addInvoice(invoice).subscribe(
(res: any) => {
if (res) {
let serviceEvents: ServiceEvent[] = [];
this.cartService.forEach(element => {
let start_TIME = currentStartTime > 12 ? currentStartTime - 12 : currentStartTime;
let end_TIME = +currentStartTime + this.getServiceTime(element);
end_TIME = end_TIME > 12 ? end_TIME - 12 : end_TIME;
currentStartTime = end_TIME;
let serviceEvent = new ServiceEvent({
service_ID: Math.floor(Math.random() * 90000) + 10000,
id: element.id,
mechanic_ID: this.mechanicId,
service_CENTER_ID: this.customer.service_CENTER_ID,
vin: this.customerCar.vin,
invoice_ID: invoiceId,
start_TIME: datePipe.transform(this.preferredDate, 'dd-MMM-yyyy')!.toString() + " " + start_TIME + ":00:00",
end_TIME: datePipe.transform(this.preferredDate, 'dd-MMM-yyyy')!.toString() + " " + end_TIME + ":00:00"
});
serviceEvents.push(serviceEvent);
});
this._apiService.addServiceEvents(serviceEvents).subscribe(
(res: any) => {
if (res) {
this.loading = false;
this._snackBar.open('Service booked', 'Close', {
duration: 2000,
});
this.router.navigate(['customerHomePage']);
}
},
(err: any) => {
this.loading = false;
console.log(err);
}
);
}
},
(err: any) => {
this.loading = false;
console.log(err);
}
);

},
(err: any) => {
this.loading = false;
console.log(err);
}
)
};
}
35 changes: 35 additions & 0 deletions service-center-app/src/app/add-service/add-service.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,41 @@ <h2>New Service</h2>
</mat-form-field>
</div>

<div style="margin-top: 10px;">
<mat-label>Time Taken for Honda</mat-label><br>
<mat-form-field appearance="outline">
<input matInput #TimeTakenHonda="ngModel" [(ngModel)]="timeTaken[0]" name="TimeTakenHonda" required type="number" min="0"
maxlength="50" [class.is-invalid]="TimeTakenHonda.invalid && (TimeTakenHonda.touched || TimeTakenHonda.dirty)">
<mat-error *ngIf="TimeTakenHonda.invalid && (TimeTakenHonda.touched || TimeTakenHonda.dirty)">
Enter a valid time
</mat-error>
</mat-form-field>
</div>

<!--Nissan-->
<div style="margin-top: 10px;">
<mat-label>Time Taken for Nissan</mat-label><br>
<mat-form-field appearance="outline">
<input matInput #TimeTakenNissan="ngModel" [(ngModel)]="timeTaken[1]" name="TimeTakenNissan" required type="number" min="0"
maxlength="50" [class.is-invalid]="TimeTakenNissan.invalid && (TimeTakenNissan.touched || TimeTakenNissan.dirty)">
<mat-error *ngIf="TimeTakenNissan.invalid && (TimeTakenNissan.touched || TimeTakenNissan.dirty)">
Enter a valid time
</mat-error>
</mat-form-field>
</div>

<!--Toyota-->
<div style="margin-top: 10px;">
<mat-label>Time Taken for Toyota</mat-label><br>
<mat-form-field appearance="outline">
<input matInput #TimeTakenToyota="ngModel" [(ngModel)]="timeTaken[2]" name="TimeTakenToyota" required type="number" min="0"
maxlength="50" [class.is-invalid]="TimeTakenToyota.invalid && (TimeTakenToyota.touched || TimeTakenToyota.dirty)">
<mat-error *ngIf="TimeTakenToyota.invalid && (TimeTakenToyota.touched || TimeTakenToyota.dirty)">
Enter a valid time
</mat-error>
</mat-form-field>
</div>

<br>
<button mat-raised-button (click)="submitForm()" [disabled]="leaveForm.form.invalid"
style="margin-top: 50px;">Submit</button>
Expand Down
21 changes: 21 additions & 0 deletions service-center-app/src/app/add-service/add-service.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { RepairService } from '../models/RepairService';
import { ScheduleBundle } from '../models/ScheduleBundle';
import { Service } from '../models/Service';
import { ServiceCategory } from '../models/ServiceCategory';
import { ServicesCar } from '../models/ServicesCar';
import { ScheduleBundleService } from '../services/schedule-bundle/schedule-bundle.service';
import { ServiceCategoryService } from '../services/service-category/service-category.service';
import { ServiceService } from '../services/service/service.service';
Expand Down Expand Up @@ -37,6 +38,7 @@ export class AddServiceComponent implements OnInit {
scheduleBundles: ScheduleBundle[] = [];
repairServiceCheck: boolean = false;
maintenanceServiceCheck: boolean = false;
timeTaken = [0,0,0]

constructor(public router: Router, public _apiService: ServiceService, private _snackBar: MatSnackBar, private categoryServce: ServiceCategoryService, private scheduleBundleService: ScheduleBundleService) { }

Expand Down Expand Up @@ -100,6 +102,25 @@ export class AddServiceComponent implements OnInit {
console.error('Error occurred while adding maintenance service to the database. Error: ' + error);
});
}

for (let i=0; i<3; i++){
let serviceCar = new ServicesCar({
id: this.service.id,
car_ID: i+1,
time_ESTIMATED: this.timeTaken[i]
});
this._apiService.addServiceCar(serviceCar).subscribe((result: boolean) => {
if (result) {
this._snackBar.open('Service added successfully', 'Close', {
duration: 2000,
});
this.router.navigate(['adminHomePage']);
this.loading = false;
}
this.loading = false;
}
);
}
}
else{
this.loading = false;
Expand Down
Loading

0 comments on commit 157518a

Please sign in to comment.