Added components to article

This commit is contained in:
Dennis Nemec
2026-05-11 17:12:05 +02:00
parent 2470299a10
commit ac6b03227d
37 changed files with 1189 additions and 513 deletions

View File

@ -1,5 +1,7 @@
import 'package:hl_lieferservice/dto/article.dart';
import 'component.dart';
class Article {
Article({
required this.name,
@ -11,13 +13,21 @@ class Article {
required this.scannable,
required this.scannedAmount,
required this.scannedRemovedAmount,
required this.isParent,
this.components = const [],
this.scannedDate,
this.removeNoteId
this.removeNoteId,
this.warehouseNr,
this.warehouseName,
});
final String name;
final String articleNumber;
final int internalId;
final bool isParent;
final List<Component> components;
final String? warehouseNr;
final String? warehouseName;
int amount;
double price;
@ -36,7 +46,35 @@ class Article {
return price * scannedAmount * ((100 + tax) / 100);
}
/// Whether this article is fully scanned.
///
/// For parent articles (Stückliste): delegates to components — all must be
/// individually scanned. For regular articles: the classic amount check.
bool get isFullyScanned {
if (isParent && components.isNotEmpty) {
return components.every((c) => c.isFullyScanned);
}
return scannedAmount + scannedRemovedAmount >= amount;
}
/// Find a component by its article number, or `null` if none matches.
Component? findComponent(String articleNumber) {
for (final c in components) {
if (c.articleNumber == articleNumber) return c;
}
return null;
}
/// Whether this article *or* any of its components carries [articleNumber].
bool hasArticleNumber(String articleNumber) {
if (this.articleNumber == articleNumber) return true;
return components.any((c) => c.articleNumber == articleNumber);
}
bool unscanned() {
if (isParent && components.isNotEmpty) {
return components.every((c) => c.scannedAmount == 0);
}
return scannedAmount == 0;
}
@ -58,6 +96,11 @@ class Article {
price: double.parse(dto.price == "" ? "0.0" : dto.price),
scannable: dto.scannable,
tax: double.parse(dto.taxRate == "" ? "19" : dto.taxRate),
isParent: dto.isParent,
components: dto.components?.map(Component.fromDTO).toList() ?? [],
warehouseNr: dto.warehouseNr?.isEmpty ?? true ? null : dto.warehouseNr,
warehouseName:
dto.warehouseName?.isEmpty ?? true ? null : dto.warehouseName,
);
}
}