88 lines
1.9 KiB
Dart
88 lines
1.9 KiB
Dart
import 'package:hl_lieferservice/dto/payment.dart';
|
|
|
|
import 'car.dart';
|
|
import 'delivery.dart';
|
|
|
|
class Payment {
|
|
const Payment({
|
|
required this.description,
|
|
required this.shortcode,
|
|
required this.id,
|
|
});
|
|
|
|
final String id;
|
|
final String description;
|
|
final String shortcode;
|
|
|
|
factory Payment.fromDTO(PaymentMethodDTO dto) {
|
|
return Payment(
|
|
description: dto.description,
|
|
shortcode: dto.shortCode,
|
|
id: dto.id,
|
|
);
|
|
}
|
|
}
|
|
|
|
class Tour {
|
|
Tour({
|
|
required this.date,
|
|
required this.deliveries,
|
|
required this.driver,
|
|
required this.discountArticleNumber,
|
|
required this.paymentMethods,
|
|
});
|
|
|
|
final DateTime date;
|
|
final String discountArticleNumber;
|
|
Driver driver;
|
|
final List<Delivery> deliveries;
|
|
List<Payment> paymentMethods;
|
|
|
|
int getFinishedDeliveries(int carId) {
|
|
return deliveries
|
|
.where((delivery) => delivery.carId == carId)
|
|
.where((delivery) => delivery.state == DeliveryState.finished)
|
|
.toList()
|
|
.length;
|
|
}
|
|
|
|
Tour copyWith({
|
|
DateTime? date,
|
|
String? discountArticleNumber,
|
|
Driver? driver,
|
|
List<Delivery>? deliveries,
|
|
List<Payment>? paymentMethods,
|
|
}) {
|
|
return Tour(
|
|
date: date ?? this.date,
|
|
discountArticleNumber: discountArticleNumber ?? this.discountArticleNumber,
|
|
driver: driver ?? this.driver,
|
|
deliveries: deliveries ?? this.deliveries,
|
|
paymentMethods: paymentMethods ?? this.paymentMethods,
|
|
);
|
|
}
|
|
}
|
|
|
|
class Driver {
|
|
Driver({
|
|
required this.teamNumber,
|
|
required this.name,
|
|
required this.salutation,
|
|
required this.cars,
|
|
});
|
|
|
|
final int teamNumber;
|
|
final String name;
|
|
final String salutation;
|
|
List<Car> cars;
|
|
|
|
/// If the driver is representing a company, then the company name is returned.
|
|
String getSalutatedLastName() {
|
|
if (salutation != "Firma") {
|
|
return "$salutation, ${name.split(" ").first}";
|
|
}
|
|
|
|
return "$salutation, $name";
|
|
}
|
|
}
|