193 lines
5.5 KiB
Dart
Raw Normal View History

2025-08-15 23:53:05 +07:00
import 'package:flutter/material.dart';
import 'package:line_icons/line_icons.dart';
2025-08-17 22:36:46 +07:00
import '../../../../common/extension/extension.dart';
2025-08-15 23:53:05 +07:00
import '../../../../common/theme/theme.dart';
2025-08-17 22:36:46 +07:00
import '../../../../domain/analytic/analytic.dart';
2025-08-15 23:53:05 +07:00
class FinanceProfitLoss extends StatelessWidget {
2025-08-17 22:36:46 +07:00
final ProfitLossSummary data;
const FinanceProfitLoss({super.key, required this.data});
2025-08-15 23:53:05 +07:00
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: AppColor.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: AppColor.textLight.withOpacity(0.1),
spreadRadius: 1,
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: AppColor.info.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child: const Icon(
LineIcons.calculator,
color: AppColor.info,
size: 20,
),
),
const SizedBox(width: 12),
Text(
2025-08-20 13:52:49 +07:00
context.lang.profit_loss_detail,
2025-08-15 23:53:05 +07:00
style: AppStyle.lg.copyWith(fontWeight: FontWeight.bold),
),
],
),
const SizedBox(height: 20),
2025-08-17 22:36:46 +07:00
// Total Revenue (Penjualan Kotor)
2025-08-15 23:53:05 +07:00
_buildPLItem(
2025-08-20 13:52:49 +07:00
context.lang.gross_sales,
2025-08-17 22:36:46 +07:00
data.totalRevenue.currencyFormatRp,
2025-08-15 23:53:05 +07:00
AppColor.success,
true,
),
2025-08-17 22:36:46 +07:00
// Discount (Diskon & Retur)
_buildPLItem(
2025-08-20 13:52:49 +07:00
'${context.lang.discount} & ${context.lang.return_text}',
2025-08-17 22:36:46 +07:00
'- ${data.totalDiscount.currencyFormatRp}',
AppColor.error,
false,
),
2025-08-15 23:53:05 +07:00
const Divider(height: 24),
2025-08-17 22:36:46 +07:00
// Net Sales (Penjualan Bersih = Total Revenue - Discount)
2025-08-15 23:53:05 +07:00
_buildPLItem(
2025-08-20 13:52:49 +07:00
context.lang.net_sales,
2025-08-17 22:36:46 +07:00
(data.totalRevenue - data.totalDiscount).currencyFormatRp,
2025-08-15 23:53:05 +07:00
AppColor.textPrimary,
true,
isHeader: true,
),
2025-08-17 22:36:46 +07:00
2025-08-15 23:53:05 +07:00
const SizedBox(height: 12),
2025-08-17 22:36:46 +07:00
// Cost of Goods Sold (HPP)
2025-08-15 23:53:05 +07:00
_buildPLItem(
2025-08-20 13:52:49 +07:00
'${context.lang.cogs} (${context.lang.cost_of_goods_sold})',
2025-08-17 22:36:46 +07:00
'- ${data.totalCost.currencyFormatRp}',
2025-08-15 23:53:05 +07:00
AppColor.error,
false,
),
2025-08-17 22:36:46 +07:00
2025-08-15 23:53:05 +07:00
const Divider(height: 24),
2025-08-17 22:36:46 +07:00
// Gross Profit (Laba Kotor)
2025-08-15 23:53:05 +07:00
_buildPLItem(
2025-08-20 13:52:49 +07:00
context.lang.gross_profit,
2025-08-17 22:36:46 +07:00
data.grossProfit.currencyFormatRp,
2025-08-15 23:53:05 +07:00
AppColor.success,
true,
isHeader: true,
2025-08-17 22:36:46 +07:00
showPercentage: true,
percentage: '${data.grossProfitMargin.toStringAsFixed(1)}%',
2025-08-15 23:53:05 +07:00
),
2025-08-17 22:36:46 +07:00
2025-08-15 23:53:05 +07:00
const SizedBox(height: 12),
2025-08-17 22:36:46 +07:00
// Operational Cost (Biaya Operasional) - calculated as difference
2025-08-15 23:53:05 +07:00
_buildPLItem(
2025-08-20 13:52:49 +07:00
context.lang.operating_costs,
2025-08-17 22:36:46 +07:00
'- ${_calculateOperationalCost().currencyFormatRp}',
2025-08-15 23:53:05 +07:00
AppColor.error,
false,
),
2025-08-17 22:36:46 +07:00
2025-08-15 23:53:05 +07:00
const Divider(height: 24),
2025-08-17 22:36:46 +07:00
// Net Profit (Laba Bersih)
2025-08-15 23:53:05 +07:00
_buildPLItem(
2025-08-20 13:52:49 +07:00
context.lang.net_profit,
2025-08-17 22:36:46 +07:00
data.netProfit.currencyFormatRp,
2025-08-15 23:53:05 +07:00
AppColor.primary,
true,
isHeader: true,
showPercentage: true,
2025-08-17 22:36:46 +07:00
percentage: '${data.netProfitMargin.round()}%',
2025-08-15 23:53:05 +07:00
),
],
),
);
}
Widget _buildPLItem(
String title,
String amount,
Color color,
bool isPositive, {
bool isHeader = false,
bool showPercentage = false,
String? percentage,
}) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Text(
title,
style: isHeader
? AppStyle.md.copyWith(
fontWeight: FontWeight.bold,
color: color,
)
: AppStyle.md.copyWith(color: AppColor.textSecondary),
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
amount,
style: isHeader
? AppStyle.lg.copyWith(
fontWeight: FontWeight.bold,
color: color,
)
: AppStyle.md.copyWith(
color: color,
fontWeight: FontWeight.w600,
),
),
if (showPercentage && percentage != null)
Text(
percentage,
style: AppStyle.xs.copyWith(
color: AppColor.textSecondary,
fontStyle: FontStyle.italic,
),
),
],
),
],
),
);
}
2025-08-17 22:36:46 +07:00
// Calculate operational cost as the difference between gross profit and net profit
int _calculateOperationalCost() {
return data.grossProfit - data.netProfit - data.totalTax;
}
2025-08-15 23:53:05 +07:00
}