Compare commits

..

No commits in common. "f87309af3f495483780618f7c7e84bd41f95ca2e" and "c09822b47057f9737e5446325d43a7acaaf1420c" have entirely different histories.

6 changed files with 41 additions and 103 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -58,24 +58,6 @@ 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), const SizedBox(height: 12),

View File

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