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({
int page = 1,
int limit = 50,
int limit = 10,
String? status,
}) async {
try {

View File

@ -72,14 +72,10 @@ class ProfitLossData {
dateTo: map['date_to'],
groupBy: map['group_by'],
summary: ProfitLossSummary.fromMap(map['summary']),
data: map['data'] == null
? []
: List<ProfitLossItem>.from(
map['data'].map((x) => ProfitLossItem.fromMap(x))),
productData: map['product_data'] == null
? []
: List<ProfitLossProduct>.from(
map['product_data'].map((x) => ProfitLossProduct.fromMap(x))),
data: List<ProfitLossItem>.from(
map['data'].map((x) => ProfitLossItem.fromMap(x))),
productData: List<ProfitLossProduct>.from(
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/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 {
@ -104,7 +102,8 @@ class RefundSuccessDialog extends StatelessWidget {
Expanded(
child: ElevatedButton(
onPressed: () {
context.push(DashboardPage());
Navigator.pop(context);
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.primary,

View File

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

View File

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