Apply clinic lab workflow feedback
This commit is contained in:
@@ -27,14 +27,47 @@ class PricingService {
|
||||
int billableUnitsForType(ProstheticType type, int memberCount) {
|
||||
final safeCount = memberCount <= 0 ? 1 : memberCount;
|
||||
return switch (type) {
|
||||
ProstheticType.tamProtez || ProstheticType.parsiyel => 1,
|
||||
ProstheticType.hareketli ||
|
||||
ProstheticType.tamProtez ||
|
||||
ProstheticType.parsiyel =>
|
||||
1,
|
||||
_ => safeCount,
|
||||
};
|
||||
}
|
||||
|
||||
int billableUnitsForTeeth(ProstheticType type, Iterable<int> teeth) {
|
||||
final selected = teeth.toSet();
|
||||
if (selected.isEmpty) return billableUnitsForType(type, 0);
|
||||
if (type.family == ProstheticFamily.hareketli) return 1;
|
||||
|
||||
final upper = {
|
||||
for (int i = 11; i <= 18; i++) i,
|
||||
for (int i = 21; i <= 28; i++) i,
|
||||
};
|
||||
final lower = {
|
||||
for (int i = 31; i <= 38; i++) i,
|
||||
for (int i = 41; i <= 48; i++) i,
|
||||
};
|
||||
|
||||
var units = 0;
|
||||
final remaining = Set<int>.from(selected);
|
||||
if (upper.every(selected.contains)) {
|
||||
units += 1;
|
||||
remaining.removeAll(upper);
|
||||
}
|
||||
if (lower.every(selected.contains)) {
|
||||
units += 1;
|
||||
remaining.removeAll(lower);
|
||||
}
|
||||
return units + remaining.length;
|
||||
}
|
||||
|
||||
String unitLabelForType(ProstheticType type) {
|
||||
return switch (type) {
|
||||
ProstheticType.tamProtez || ProstheticType.parsiyel => 'vaka',
|
||||
ProstheticType.hareketli ||
|
||||
ProstheticType.tamProtez ||
|
||||
ProstheticType.parsiyel =>
|
||||
'vaka',
|
||||
_ => 'diş',
|
||||
};
|
||||
}
|
||||
@@ -45,14 +78,18 @@ class PricingService {
|
||||
required int memberCount,
|
||||
required String clinicTenantId,
|
||||
required List<ClinicDiscount> discounts,
|
||||
Iterable<int>? teeth,
|
||||
}) {
|
||||
final billableUnits = billableUnitsForType(prostheticType, memberCount);
|
||||
final billableUnits = teeth == null
|
||||
? billableUnitsForType(prostheticType, memberCount)
|
||||
: billableUnitsForTeeth(prostheticType, teeth);
|
||||
final unitPrice = product.unitPrice ?? 0;
|
||||
final baseAmount = unitPrice * billableUnits;
|
||||
|
||||
final applicable = discounts.where((discount) {
|
||||
if (!discount.isActive) return false;
|
||||
if (!(discount.appliesToAll || discount.clinicTenantId == clinicTenantId)) {
|
||||
if (!(discount.appliesToAll ||
|
||||
discount.clinicTenantId == clinicTenantId)) {
|
||||
return false;
|
||||
}
|
||||
if (!(discount.appliesToAllTypes ||
|
||||
@@ -77,9 +114,8 @@ class PricingService {
|
||||
billableUnits: billableUnits,
|
||||
unitPrice: unitPrice,
|
||||
baseAmount: baseAmount,
|
||||
discountAmount: (baseAmount - finalAmount)
|
||||
.clamp(0, double.infinity)
|
||||
.toDouble(),
|
||||
discountAmount:
|
||||
(baseAmount - finalAmount).clamp(0, double.infinity).toDouble(),
|
||||
finalAmount: finalAmount,
|
||||
appliedDiscounts: applicable,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user