Files
efrilm 243b7e02aa
Build & Deploy iOS to TestFlight / build-and-deploy (push) Canceled after 0s
feat: update profit shareing
2026-10-04 22:31:01 +07:00

284 lines
7.9 KiB
Dart

import 'package:flutter/material.dart';
import '../../../../common/extension/extension.dart';
import '../../../../common/theme/theme.dart';
import '../../../components/spacer/spacer.dart';
import 'profit_sharing_allocation.dart';
import 'profit_sharing_status.dart';
/// Satu baris rincian SDL, bisa per kategori induk atau per periode.
class ProfitSharingSdlItem {
final String label;
final int sdl;
final int revenue;
final double? feePercent;
const ProfitSharingSdlItem({
required this.label,
required this.sdl,
required this.revenue,
this.feePercent,
});
}
/// Section khusus SDL (bagian owner): total di blok hijau, lalu rinciannya.
/// Urutan [items] ditampilkan apa adanya.
class ProfitSharingSdlSection extends StatelessWidget {
final int sdl;
final int revenue;
/// Persen di blok total: fee owner kalau satu kategori, atau persen
/// efektif terhadap omzet kalau gabungan beberapa kategori.
final double percent;
final String breakdownTitle;
final List<ProfitSharingSdlItem> items;
const ProfitSharingSdlSection({
super.key,
required this.sdl,
required this.revenue,
required this.percent,
required this.breakdownTitle,
this.items = const [],
});
@override
Widget build(BuildContext context) {
final totalSdl = items.fold<int>(0, (sum, e) => sum + e.sdl);
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: AppColor.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: AppColor.textLight.withOpacity(0.08),
spreadRadius: 1,
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
context.lang.sdl_summary,
style: AppStyle.lg.copyWith(
fontWeight: FontWeight.w700,
color: AppColor.textPrimary,
),
),
const SizedBox(height: 2),
Text(
context.lang.sdl_desc,
style: AppStyle.xs.copyWith(color: AppColor.textSecondary),
),
const SpaceHeight(16),
_TotalBlock(sdl: sdl, revenue: revenue, percent: percent),
if (items.isNotEmpty) ...[
const SpaceHeight(20),
Text(
breakdownTitle,
style: AppStyle.md.copyWith(
fontWeight: FontWeight.w700,
color: AppColor.textPrimary,
),
),
const SpaceHeight(12),
for (var i = 0; i < items.length; i++) ...[
if (i > 0) const Divider(height: 24, color: AppColor.borderLight),
_SdlRow(
item: items[i],
share: totalSdl == 0 ? 0 : items[i].sdl / totalSdl,
),
],
],
],
),
);
}
}
class _TotalBlock extends StatelessWidget {
final int sdl;
final int revenue;
final double percent;
const _TotalBlock({
required this.sdl,
required this.revenue,
required this.percent,
});
@override
Widget build(BuildContext context) {
const color = ProfitSharingColor.owner;
return Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [color, darken(color)],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(14),
boxShadow: [
BoxShadow(
color: color.withOpacity(0.3),
blurRadius: 10,
offset: const Offset(0, 4),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: AppColor.textWhite.withOpacity(0.2),
borderRadius: BorderRadius.circular(10),
),
child: const Icon(
Icons.account_balance_wallet_rounded,
color: AppColor.textWhite,
size: 20,
),
),
const SpaceWidth(10),
Expanded(
child: Text(
context.lang.sdl,
style: AppStyle.md.copyWith(
color: AppColor.textWhite,
fontWeight: FontWeight.w700,
),
),
),
ProfitSharingFeeBadge(
feePercent: percent,
onDarkBackground: true,
),
],
),
const SpaceHeight(14),
FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
child: Text(
sdl.currencyFormatRp,
style: AppStyle.h3.copyWith(
color: AppColor.textWhite,
fontWeight: FontWeight.w900,
),
),
),
const SizedBox(height: 4),
Text(
context.lang.from_revenue(revenue.currencyFormatRp),
style: AppStyle.sm.copyWith(
color: AppColor.textWhite.withOpacity(0.85),
),
),
],
),
);
}
}
class _SdlRow extends StatelessWidget {
final ProfitSharingSdlItem item;
/// Porsi baris ini terhadap total SDL di daftar (0..1).
final double share;
const _SdlRow({required this.item, required this.share});
@override
Widget build(BuildContext context) {
final amountColor = darken(ProfitSharingColor.owner);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Row(
children: [
Flexible(
child: Text(
item.label,
style: AppStyle.md.copyWith(
color: AppColor.textPrimary,
fontWeight: FontWeight.w700,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
if (item.feePercent != null) ...[
const SpaceWidth(6),
ProfitSharingFeeBadge(feePercent: item.feePercent!),
],
],
),
),
const SpaceWidth(8),
Text(
item.sdl.currencyFormatRp,
style: AppStyle.md.copyWith(
color: amountColor,
fontWeight: FontWeight.w800,
),
),
],
),
const SpaceHeight(8),
ClipRRect(
borderRadius: BorderRadius.circular(6),
child: LinearProgressIndicator(
value: share.clamp(0.0, 1.0),
minHeight: 6,
backgroundColor: AppColor.border,
valueColor: const AlwaysStoppedAnimation<Color>(
ProfitSharingColor.owner,
),
),
),
const SpaceHeight(6),
Row(
children: [
Expanded(
child: Text(
context.lang.from_revenue(item.revenue.currencyFormatRp),
style: AppStyle.xs.copyWith(color: AppColor.textSecondary),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
Text(
formatPercent(share * 100),
style: AppStyle.xs.copyWith(
color: amountColor,
fontWeight: FontWeight.w700,
),
),
],
),
],
);
}
}