report sales
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../../../application/analytic/dashboard_analytic_loader/dashboard_analytic_loader_bloc.dart';
|
||||
import '../../../../../application/analytic/sales_analytic_loader/sales_analytic_loader_bloc.dart';
|
||||
import '../../../../../application/report/report_bloc.dart';
|
||||
import '../../../../../common/data/report_menu.dart';
|
||||
import '../../../../../common/theme/theme.dart';
|
||||
@@ -13,6 +14,7 @@ import '../../../../components/picker/date_range_picker.dart';
|
||||
import '../../../../components/spaces/space.dart';
|
||||
import '../../../../router/app_router.gr.dart';
|
||||
import 'sections/report_dashboard_section.dart';
|
||||
import 'sections/report_sales_section.dart';
|
||||
import 'widgets/report_menu_card.dart';
|
||||
|
||||
@RoutePage()
|
||||
@@ -119,7 +121,20 @@ class ReportPage extends StatelessWidget implements AutoRouteWrapper {
|
||||
},
|
||||
),
|
||||
1 => Text(state.title),
|
||||
2 => Text(state.title),
|
||||
2 =>
|
||||
BlocBuilder<
|
||||
SalesAnalyticLoaderBloc,
|
||||
SalesAnalyticLoaderState
|
||||
>(
|
||||
builder: (context, sales) {
|
||||
return ReportSalesSection(
|
||||
menu: reportMenus[state.selectedMenu],
|
||||
state: sales,
|
||||
startDate: state.startDate,
|
||||
endDate: state.endDate,
|
||||
);
|
||||
},
|
||||
),
|
||||
3 => Text(state.title),
|
||||
4 => Text(state.title),
|
||||
5 => Text(state.title),
|
||||
@@ -151,6 +166,12 @@ class ReportPage extends StatelessWidget implements AutoRouteWrapper {
|
||||
);
|
||||
case 1:
|
||||
case 2:
|
||||
return context.read<SalesAnalyticLoaderBloc>().add(
|
||||
SalesAnalyticLoaderEvent.fetched(
|
||||
startDate: state.startDate,
|
||||
endDate: state.endDate,
|
||||
),
|
||||
);
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
@@ -174,6 +195,15 @@ class ReportPage extends StatelessWidget implements AutoRouteWrapper {
|
||||
),
|
||||
),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => getIt<SalesAnalyticLoaderBloc>()
|
||||
..add(
|
||||
SalesAnalyticLoaderEvent.fetched(
|
||||
startDate: DateTime.now().subtract(const Duration(days: 30)),
|
||||
endDate: DateTime.now(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
child: this,
|
||||
);
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../../application/analytic/sales_analytic_loader/sales_analytic_loader_bloc.dart';
|
||||
import '../../../../../../common/data/report_menu.dart';
|
||||
import '../../../../../../common/extension/extension.dart';
|
||||
import '../../../../../../common/theme/theme.dart';
|
||||
import '../../../../../components/loader/loader_with_text.dart';
|
||||
import '../../../../../components/spaces/space.dart';
|
||||
import '../../../../../components/widgets/report/report_header.dart';
|
||||
import '../../../../../components/widgets/report/report_summary_card.dart';
|
||||
|
||||
class ReportSalesSection extends StatelessWidget {
|
||||
final ReportMenu menu;
|
||||
final SalesAnalyticLoaderState state;
|
||||
final DateTime startDate;
|
||||
final DateTime endDate;
|
||||
const ReportSalesSection({
|
||||
super.key,
|
||||
required this.menu,
|
||||
required this.state,
|
||||
required this.startDate,
|
||||
required this.endDate,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (state.isFetching) {
|
||||
return const Center(child: LoaderWithText());
|
||||
}
|
||||
|
||||
return ListView(
|
||||
padding: EdgeInsets.all(16),
|
||||
children: [
|
||||
ReportHeader(menu: menu, endDate: endDate, startDate: startDate),
|
||||
_buildSummary(),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.white,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Kinerja Harian',
|
||||
style: AppStyle.lg.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColor.textPrimary,
|
||||
),
|
||||
),
|
||||
SpaceHeight(12),
|
||||
ListView.builder(
|
||||
itemCount: state.salesAnalytic.sortedDailyData.length,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemBuilder: (context, index) {
|
||||
final dayData = state.salesAnalytic.sortedDailyData[index];
|
||||
return _buildDailyPerformanceItem(
|
||||
date: dayData.date.toSimpleMonthDate(),
|
||||
sales: dayData.sales.currencyFormatRpV2,
|
||||
orders: dayData.orders,
|
||||
items: dayData.items,
|
||||
isHighest: dayData == state.salesAnalytic.highestRevenueDay,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SpaceHeight(16),
|
||||
_buildSummaryFooter(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSummaryFooter() {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.success,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Kinerja puncak pada ${state.salesAnalytic.highestRevenueDay.date.toSimpleMonthDate()} dengan pendapatan ${state.salesAnalytic.highestRevenueDay.sales.currencyFormatRpV2} (pesanan ${state.salesAnalytic.highestRevenueDay.orders})',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: const Color(0xFF374151),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDailyPerformanceItem({
|
||||
required String date,
|
||||
required String sales,
|
||||
required int orders,
|
||||
required int items,
|
||||
required bool isHighest,
|
||||
}) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: isHighest ? const Color(0xFF10B981) : const Color(0xFFE5E7EB),
|
||||
width: isHighest ? 2 : 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 60,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
date,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: const Color(0xFF111827),
|
||||
),
|
||||
),
|
||||
if (isHighest)
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 4),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF10B981),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
'TOP',
|
||||
style: TextStyle(
|
||||
fontSize: 8,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
sales,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: const Color(0xFF111827),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Pendapatan',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: const Color(0xFF6B7280),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'$orders pesanan',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: const Color(0xFF374151),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'$items item',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: const Color(0xFF6B7280),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Padding _buildSummary() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ReportSummaryCard(
|
||||
color: AppColor.success,
|
||||
icon: Icons.trending_up,
|
||||
title: "Jumlah Penjualan",
|
||||
value:
|
||||
state.salesAnalytic.summary.totalSales.currencyFormatRpV2,
|
||||
),
|
||||
),
|
||||
SpaceWidth(12),
|
||||
Expanded(
|
||||
child: ReportSummaryCard(
|
||||
color: AppColor.info,
|
||||
icon: Icons.shopping_cart_outlined,
|
||||
title: "Jumlah Pesanan",
|
||||
value: state.salesAnalytic.summary.totalOrders.toString(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SpaceHeight(12),
|
||||
ReportSummaryCard(
|
||||
color: AppColor.primary,
|
||||
icon: Icons.attach_money_outlined,
|
||||
title: "Nilai Pesanan Rata-rata",
|
||||
value: state.salesAnalytic.summary.averageOrderValue.toString(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user