41 lines
1.0 KiB
Dart
41 lines
1.0 KiB
Dart
|
|
|
||
|
|
import '../models/sake_item.dart';
|
||
|
|
import 'pricing_helper.dart';
|
||
|
|
|
||
|
|
class PricingCalculator {
|
||
|
|
// Round up to nearest 50 yen
|
||
|
|
static int roundUpTo50(double price) {
|
||
|
|
if (price <= 0) return 0;
|
||
|
|
return ((price / 50).ceil() * 50).toInt();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Calculate Selling Price
|
||
|
|
static int calculatePrice(SakeItem item, {double? globalMarkup}) {
|
||
|
|
// 1. Manual Override takes precedence
|
||
|
|
if (item.userData.price != null) {
|
||
|
|
return item.userData.price!;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 2. If no cost, cannot calculate
|
||
|
|
if (item.userData.costPrice == null) {
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 3. Determine Markup
|
||
|
|
// If globalMarkup is provided (e.g. from Settings preview), use it?
|
||
|
|
// Or normally use item.markup.
|
||
|
|
final double markup = globalMarkup ?? item.userData.markup;
|
||
|
|
|
||
|
|
// 4. Calculate
|
||
|
|
final double rawPrice = item.userData.costPrice! * markup;
|
||
|
|
|
||
|
|
// 5. Rounding
|
||
|
|
return roundUpTo50(rawPrice);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 価格フォーマット (PricingHelperに委譲)
|
||
|
|
static String formatPrice(int price) {
|
||
|
|
return PricingHelper.formatPrice(price);
|
||
|
|
}
|
||
|
|
}
|