Compare commits

...

3 Commits

Author SHA1 Message Date
efrilm
f87309af3f feat: update 2025-08-14 00:16:42 +07:00
efrilm
96d0b91984 feat: succes payment 2025-08-14 00:12:49 +07:00
efrilm
e20dc53fb8 feat: profit loss widget 2025-08-13 23:27:52 +07:00
6 changed files with 103 additions and 41 deletions

View File

@ -55,7 +55,7 @@ class TableRemoteDataSource {
Future<Either<String, TableResponseModel>> getTable({
int page = 1,
int limit = 10,
int limit = 50,
String? status,
}) async {
try {

View File

@ -72,9 +72,13 @@ class ProfitLossData {
dateTo: map['date_to'],
groupBy: map['group_by'],
summary: ProfitLossSummary.fromMap(map['summary']),
data: List<ProfitLossItem>.from(
data: map['data'] == null
? []
: List<ProfitLossItem>.from(
map['data'].map((x) => ProfitLossItem.fromMap(x))),
productData: List<ProfitLossProduct>.from(
productData: map['product_data'] == null
? []
: List<ProfitLossProduct>.from(
map['product_data'].map((x) => ProfitLossProduct.fromMap(x))),
);
}

View File

@ -1,6 +1,8 @@
import 'package:enaklo_pos/core/components/spaces.dart';
import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
import 'package:enaklo_pos/core/extensions/int_ext.dart';
import 'package:enaklo_pos/presentation/home/pages/dashboard_page.dart';
import 'package:flutter/material.dart';
class RefundSuccessDialog extends StatelessWidget {
@ -102,8 +104,7 @@ class RefundSuccessDialog extends StatelessWidget {
Expanded(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
Navigator.pop(context);
context.push(DashboardPage());
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.primary,

View File

@ -172,12 +172,17 @@ class ProfitLossWidget extends StatelessWidget {
break;
}
if (previous == 0) return '+0.0%';
// Handle division by zero and invalid values
if (previous == 0 || previous.isNaN || previous.isInfinite) return '+0.0%';
if (current.isNaN || current.isInfinite) return '+0.0%';
final trendPercentage = ((current - previous) / previous) * 100;
final sign = trendPercentage >= 0 ? '+' : '';
return '$sign${trendPercentage.toStringAsFixed(1)}%';
// Check if trendPercentage is valid
if (trendPercentage.isNaN || trendPercentage.isInfinite) return '+0.0%';
final sign = trendPercentage >= 0 ? '+' : '';
return '$sign${trendPercentage.round()}%';
}
Widget _buildSummaryCards() {
@ -201,8 +206,7 @@ class ProfitLossWidget extends StatelessWidget {
{
'title': 'Laba Kotor',
'value': _formatCurrency(data.summary.grossProfit),
'subtitle':
'${data.summary.grossProfitMargin.toStringAsFixed(1)}% margin',
'subtitle': '${_safeRound(data.summary.grossProfitMargin)}% margin',
'icon': Icons.trending_up,
'color': AppColorProfitLoss.primary,
'trend': _calculateTrend('grossProfit'),
@ -210,8 +214,7 @@ class ProfitLossWidget extends StatelessWidget {
{
'title': 'Laba Bersih',
'value': _formatCurrency(data.summary.netProfit),
'subtitle':
'${data.summary.netProfitMargin.toStringAsFixed(1)}% margin',
'subtitle': '${_safeRound(data.summary.netProfitMargin)}% margin',
'icon': Icons.account_balance,
'color': AppColorProfitLoss.info,
'trend': _calculateTrend('netProfit'),
@ -360,13 +363,17 @@ class ProfitLossWidget extends StatelessWidget {
showTitles: true,
reservedSize: 50,
getTitlesWidget: (value, meta) {
final kValue = (value / 1000);
if (kValue.isFinite) {
return Text(
'${(value / 1000).toInt()}K',
'${kValue.toInt()}K',
style: TextStyle(
color: Colors.grey[600],
fontSize: 10,
),
);
}
return const SizedBox();
},
),
),
@ -402,8 +409,9 @@ class ProfitLossWidget extends StatelessWidget {
// Garis Pendapatan
LineChartBarData(
spots: data.data.asMap().entries.map((entry) {
final revenue = entry.value.revenue.toDouble();
return FlSpot(
entry.key.toDouble(), entry.value.revenue.toDouble());
entry.key.toDouble(), revenue.isFinite ? revenue : 0);
}).toList(),
isCurved: true,
color: AppColorProfitLoss.info,
@ -412,8 +420,9 @@ class ProfitLossWidget extends StatelessWidget {
// Garis Biaya
LineChartBarData(
spots: data.data.asMap().entries.map((entry) {
final cost = entry.value.cost.toDouble();
return FlSpot(
entry.key.toDouble(), entry.value.cost.toDouble());
entry.key.toDouble(), cost.isFinite ? cost : 0);
}).toList(),
isCurved: true,
color: AppColorProfitLoss.danger,
@ -422,8 +431,9 @@ class ProfitLossWidget extends StatelessWidget {
// Garis Laba Bersih
LineChartBarData(
spots: data.data.asMap().entries.map((entry) {
final netProfit = entry.value.netProfit.toDouble();
return FlSpot(entry.key.toDouble(),
entry.value.netProfit.toDouble());
netProfit.isFinite ? netProfit : 0);
}).toList(),
isCurved: true,
color: AppColorProfitLoss.success,
@ -506,9 +516,10 @@ class ProfitLossWidget extends StatelessWidget {
}
Widget _buildProductItem(ProfitLossProduct product) {
final profitColor = product.grossProfitMargin >= 35
final profitMargin = _safeDouble(product.grossProfitMargin);
final profitColor = profitMargin >= 35
? AppColorProfitLoss.success
: product.grossProfitMargin >= 25
: profitMargin >= 25
? AppColorProfitLoss.warning
: AppColorProfitLoss.danger;
@ -572,7 +583,7 @@ class ProfitLossWidget extends StatelessWidget {
borderRadius: BorderRadius.circular(6),
),
child: Text(
'${product.grossProfitMargin.toStringAsFixed(1)}%',
'${_safeRound(profitMargin)}%',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
@ -710,13 +721,17 @@ class ProfitLossWidget extends StatelessWidget {
startDegreeOffset: -90,
sections: breakdownData.asMap().entries.map((entry) {
final item = entry.value;
final grossProfit = data.summary.grossProfit;
final value = item['value'] as int;
// Handle division by zero
final percentage =
(item['value'] as int) / data.summary.grossProfit * 100;
grossProfit > 0 ? (value / grossProfit * 100) : 0.0;
return PieChartSectionData(
color: item['color'] as Color,
value: (item['value'] as int).toDouble(),
title: '${percentage.toStringAsFixed(1)}%',
value: value.toDouble(),
title: '${_safeRound(percentage)}%',
radius: 40,
titleStyle: const TextStyle(
fontSize: 10,
@ -799,7 +814,7 @@ class ProfitLossWidget extends StatelessWidget {
),
const SizedBox(height: 8),
Text(
'${(data.summary.profitabilityRatio * 100).toStringAsFixed(1)}%',
'${_safeRound(data.summary.profitabilityRatio)}%',
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
@ -848,9 +863,7 @@ class ProfitLossWidget extends StatelessWidget {
Expanded(
child: _buildMetricCard(
'Nilai Rata-rata Pesanan',
_formatCurrency(
(data.summary.totalRevenue / data.summary.totalOrders)
.round()),
_formatCurrency(_safeCalculateAverageOrder()),
'Per transaksi',
Icons.shopping_cart_outlined,
AppColorProfitLoss.info,
@ -870,7 +883,7 @@ class ProfitLossWidget extends StatelessWidget {
Expanded(
child: _buildMetricCard(
'Rasio Biaya',
'${((data.summary.totalCost / data.summary.totalRevenue) * 100).toStringAsFixed(1)}%',
'${_safeCalculateCostRatio()}%',
'Dari total pendapatan',
Icons.pie_chart,
AppColorProfitLoss.danger,
@ -1026,7 +1039,7 @@ class ProfitLossWidget extends StatelessWidget {
borderRadius: BorderRadius.circular(4),
),
child: Text(
'${item.netProfitMargin.toStringAsFixed(1)}%',
'${_safeRound(item.netProfitMargin)}%',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 10,
@ -1093,6 +1106,31 @@ class ProfitLossWidget extends StatelessWidget {
);
}
// Helper methods for safe calculations
int _safeRound(double value) {
if (value.isNaN || value.isInfinite) return 0;
return value.round();
}
double _safeDouble(double value) {
if (value.isNaN || value.isInfinite) return 0.0;
return value;
}
int _safeCalculateAverageOrder() {
if (data.summary.totalOrders == 0) return 0;
final average = data.summary.totalRevenue / data.summary.totalOrders;
if (average.isNaN || average.isInfinite) return 0;
return average.round();
}
int _safeCalculateCostRatio() {
if (data.summary.totalRevenue == 0) return 0;
final ratio = (data.summary.totalCost / data.summary.totalRevenue) * 100;
if (ratio.isNaN || ratio.isInfinite) return 0;
return ratio.round();
}
IconData _getProductIcon(String category) {
switch (category.toLowerCase()) {
case 'coffee':
@ -1110,8 +1148,9 @@ class ProfitLossWidget extends StatelessWidget {
}
Color _getMarginColor(double margin) {
if (margin >= 25) return AppColorProfitLoss.success;
if (margin >= 15) return AppColorProfitLoss.warning;
final safeMargin = _safeDouble(margin);
if (safeMargin >= 25) return AppColorProfitLoss.success;
if (safeMargin >= 15) return AppColorProfitLoss.warning;
return AppColorProfitLoss.danger;
}
@ -1126,7 +1165,7 @@ class ProfitLossWidget extends StatelessWidget {
String _formatCurrencyShort(int amount) {
if (amount >= 1000000) {
return 'Rp ${(amount / 1000000).toStringAsFixed(1)}M';
return 'Rp ${(amount / 1000000).round()}M';
} else if (amount >= 1000) {
return 'Rp ${(amount / 1000).toStringAsFixed(0)}K';
}

View File

@ -58,6 +58,24 @@ class SalesCard extends StatelessWidget {
),
),
),
if (order.isVoid == true)
Container(
padding:
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.15),
borderRadius: BorderRadius.circular(16),
),
child: Text(
'Void',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.w600,
fontSize: 10,
letterSpacing: 0.5,
),
),
),
],
),
const SizedBox(height: 12),

View File

@ -887,7 +887,7 @@ class _SuccessPaymentPageState extends State<SuccessPaymentPage> {
],
),
Text(
(order.totalAmount ?? 0).toString().currencyFormatRpV2,
widget.nominalBayar.currencyFormatRpV2,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
@ -965,7 +965,7 @@ class _SuccessPaymentPageState extends State<SuccessPaymentPage> {
],
),
child: Text(
(order.totalAmount ?? 0).toString().currencyFormatRpV2,
widget.nominalBayar.currencyFormatRpV2,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,