feat: update profit loss ui
Build & Deploy iOS to TestFlight / build-and-deploy (push) Waiting to run
Build & Deploy iOS to TestFlight / build-and-deploy (push) Waiting to run
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:line_icons/line_icons.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
|
||||
import '../../../application/analytic/purchasing_analytic_loader/purchasing_analytic_loader_bloc.dart';
|
||||
@@ -9,13 +8,12 @@ import '../../../application/outlet/outlet_list_loader/outlet_list_loader_bloc.d
|
||||
import '../../../common/extension/extension.dart';
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../injection.dart';
|
||||
import '../../components/appbar/appbar.dart';
|
||||
import '../../components/field/date_range_picker_field.dart';
|
||||
import '../../components/spacer/spacer.dart';
|
||||
import 'widgets/ingredient_card.dart';
|
||||
import 'widgets/outlet_selector_field.dart';
|
||||
import 'widgets/purchase_daily_tile.dart';
|
||||
import 'widgets/stat_card.dart';
|
||||
import 'widgets/purchase_header.dart';
|
||||
import 'widgets/purchase_rincian_card.dart';
|
||||
import 'widgets/vendor_card.dart';
|
||||
|
||||
@RoutePage()
|
||||
@@ -29,12 +27,14 @@ class PurchasePage extends StatefulWidget implements AutoRouteWrapper {
|
||||
Widget wrappedRoute(BuildContext context) => MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (context) => getIt<PurchasingAnalyticLoaderBloc>()
|
||||
..add(const PurchasingAnalyticLoaderEvent.fetched()),
|
||||
create: (context) =>
|
||||
getIt<PurchasingAnalyticLoaderBloc>()
|
||||
..add(const PurchasingAnalyticLoaderEvent.fetched()),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => getIt<OutletListLoaderBloc>()
|
||||
..add(const OutletListLoaderEvent.fetched()),
|
||||
create: (context) =>
|
||||
getIt<OutletListLoaderBloc>()
|
||||
..add(const OutletListLoaderEvent.fetched()),
|
||||
),
|
||||
],
|
||||
child: this,
|
||||
@@ -74,19 +74,20 @@ class _PurchasePageState extends State<PurchasePage>
|
||||
backgroundColor: AppColor.background,
|
||||
body: MultiBlocListener(
|
||||
listeners: [
|
||||
// Re-fetch when date range changes
|
||||
BlocListener<PurchasingAnalyticLoaderBloc,
|
||||
PurchasingAnalyticLoaderState>(
|
||||
BlocListener<
|
||||
PurchasingAnalyticLoaderBloc,
|
||||
PurchasingAnalyticLoaderState
|
||||
>(
|
||||
listenWhen: (prev, curr) =>
|
||||
prev.dateFrom != curr.dateFrom ||
|
||||
prev.dateTo != curr.dateTo,
|
||||
prev.dateFrom != curr.dateFrom || prev.dateTo != curr.dateTo,
|
||||
listener: (context, _) => context
|
||||
.read<PurchasingAnalyticLoaderBloc>()
|
||||
.add(const PurchasingAnalyticLoaderEvent.fetched()),
|
||||
),
|
||||
// Re-fetch when outlet changes
|
||||
BlocListener<PurchasingAnalyticLoaderBloc,
|
||||
PurchasingAnalyticLoaderState>(
|
||||
BlocListener<
|
||||
PurchasingAnalyticLoaderBloc,
|
||||
PurchasingAnalyticLoaderState
|
||||
>(
|
||||
listenWhen: (prev, curr) => prev.outletId != curr.outletId,
|
||||
listener: (context, _) => context
|
||||
.read<PurchasingAnalyticLoaderBloc>()
|
||||
@@ -95,108 +96,61 @@ class _PurchasePageState extends State<PurchasePage>
|
||||
],
|
||||
child: BlocBuilder<OutletListLoaderBloc, OutletListLoaderState>(
|
||||
builder: (context, outletListState) {
|
||||
return BlocBuilder<PurchasingAnalyticLoaderBloc,
|
||||
PurchasingAnalyticLoaderState>(
|
||||
return BlocBuilder<
|
||||
PurchasingAnalyticLoaderBloc,
|
||||
PurchasingAnalyticLoaderState
|
||||
>(
|
||||
builder: (context, state) {
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
// App Bar
|
||||
SliverAppBar(
|
||||
expandedHeight: 120.0,
|
||||
floating: false,
|
||||
pinned: true,
|
||||
elevation: 0,
|
||||
backgroundColor: AppColor.primary,
|
||||
flexibleSpace:
|
||||
CustomAppBar(title: context.lang.purchase),
|
||||
// Header (same style as Sales)
|
||||
SliverToBoxAdapter(
|
||||
child: PurchaseHeader(
|
||||
state: state,
|
||||
onDateRangeChanged: (startDate, endDate) {
|
||||
context.read<PurchasingAnalyticLoaderBloc>().add(
|
||||
PurchasingAnalyticLoaderEvent.rangeDateChanged(
|
||||
startDate,
|
||||
endDate,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// Date Range + Outlet Picker
|
||||
// Outlet Selector
|
||||
SliverToBoxAdapter(
|
||||
child: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 0),
|
||||
child: Column(
|
||||
children: [
|
||||
DateRangePickerField(
|
||||
maxDate: DateTime.now(),
|
||||
startDate: state.dateFrom,
|
||||
endDate: state.dateTo,
|
||||
onChanged: (startDate, endDate) {
|
||||
context
|
||||
.read<PurchasingAnalyticLoaderBloc>()
|
||||
.add(
|
||||
PurchasingAnalyticLoaderEvent
|
||||
.rangeDateChanged(
|
||||
startDate!,
|
||||
endDate!,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SpaceHeight(8),
|
||||
PurchaseOutletSelectorField(
|
||||
selectedOutletId: state.outletId,
|
||||
outlets: outletListState.outlets,
|
||||
isLoading: outletListState.isFetching,
|
||||
onOutletChanged: (outletId) {
|
||||
context
|
||||
.read<PurchasingAnalyticLoaderBloc>()
|
||||
.add(
|
||||
PurchasingAnalyticLoaderEvent
|
||||
.outletChanged(outletId),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
child: PurchaseOutletSelectorField(
|
||||
selectedOutletId: state.outletId,
|
||||
outlets: outletListState.outlets,
|
||||
isLoading: outletListState.isFetching,
|
||||
onOutletChanged: (outletId) {
|
||||
context.read<PurchasingAnalyticLoaderBloc>().add(
|
||||
PurchasingAnalyticLoaderEvent.outletChanged(
|
||||
outletId,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SliverToBoxAdapter(child: SpaceHeight(16)),
|
||||
|
||||
// Summary Section
|
||||
// Rincian Pembelian (same style as Sales)
|
||||
SliverToBoxAdapter(
|
||||
child: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context.lang.summary,
|
||||
style: AppStyle.xxl.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.textPrimary,
|
||||
),
|
||||
),
|
||||
const SpaceHeight(16),
|
||||
state.isFetching
|
||||
? _buildSummaryShimmer()
|
||||
: _buildSummaryCards(state),
|
||||
],
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: PurchaseRincianCard(state: state),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SliverToBoxAdapter(child: SpaceHeight(24)),
|
||||
|
||||
// Total Purchases Highlight Card
|
||||
SliverToBoxAdapter(
|
||||
child: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: state.isFetching
|
||||
? _buildHighlightShimmer()
|
||||
: _buildTotalPurchasesCard(state),
|
||||
),
|
||||
),
|
||||
|
||||
const SliverToBoxAdapter(child: SpaceHeight(24)),
|
||||
|
||||
// Daily Breakdown Header
|
||||
SliverToBoxAdapter(
|
||||
child: FadeTransition(
|
||||
@@ -278,211 +232,13 @@ class _PurchasePageState extends State<PurchasePage>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Summary Cards ────────────────────────────────────────────────────────
|
||||
|
||||
Widget _buildSummaryCards(PurchasingAnalyticLoaderState state) {
|
||||
final s = state.purchasing.summary;
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PurchaseStatCard(
|
||||
title: 'Total Pembelian',
|
||||
value: s.totalPurchases.currencyFormatRp,
|
||||
icon: LineIcons.shoppingCart,
|
||||
iconColor: AppColor.primary,
|
||||
cardAnimation: _fadeAnimation,
|
||||
),
|
||||
),
|
||||
const SpaceWidth(12),
|
||||
Expanded(
|
||||
child: PurchaseStatCard(
|
||||
title: 'Total PO',
|
||||
value: '${s.totalPurchaseOrders} PO',
|
||||
icon: LineIcons.fileAlt,
|
||||
iconColor: AppColor.info,
|
||||
cardAnimation: _fadeAnimation,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SpaceHeight(12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PurchaseStatCard(
|
||||
title: 'Bahan Baku',
|
||||
value: s.rawMaterialPurchases.currencyFormatRp,
|
||||
icon: LineIcons.leaf,
|
||||
iconColor: AppColor.secondary,
|
||||
cardAnimation: _fadeAnimation,
|
||||
),
|
||||
),
|
||||
const SpaceWidth(12),
|
||||
Expanded(
|
||||
child: PurchaseStatCard(
|
||||
title: 'Pengeluaran',
|
||||
value: s.expensePurchases.currencyFormatRp,
|
||||
icon: LineIcons.receipt,
|
||||
iconColor: AppColor.warning,
|
||||
cardAnimation: _fadeAnimation,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SpaceHeight(12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PurchaseStatCard(
|
||||
title: 'Total Qty',
|
||||
value: '${s.totalQuantity} pcs',
|
||||
icon: LineIcons.boxes,
|
||||
iconColor: AppColor.warning,
|
||||
cardAnimation: _fadeAnimation,
|
||||
),
|
||||
),
|
||||
const SpaceWidth(12),
|
||||
Expanded(
|
||||
child: PurchaseStatCard(
|
||||
title: 'Rata-rata PO',
|
||||
value: s.averagePurchaseOrderValue.round().currencyFormatRp,
|
||||
icon: LineIcons.dollarSign,
|
||||
iconColor: AppColor.secondaryDark,
|
||||
cardAnimation: _fadeAnimation,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SpaceHeight(12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PurchaseStatCard(
|
||||
title: 'Item Bahan Baku',
|
||||
value: '${s.totalIngredients} item',
|
||||
icon: LineIcons.leaf,
|
||||
iconColor: AppColor.secondaryDark,
|
||||
cardAnimation: _fadeAnimation,
|
||||
),
|
||||
),
|
||||
const SpaceWidth(12),
|
||||
Expanded(
|
||||
child: PurchaseStatCard(
|
||||
title: 'Vendor',
|
||||
value: '${s.totalVendors} vendor',
|
||||
icon: LineIcons.truck,
|
||||
iconColor: AppColor.primaryDark,
|
||||
cardAnimation: _fadeAnimation,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTotalPurchasesCard(PurchasingAnalyticLoaderState state) {
|
||||
return TweenAnimationBuilder<double>(
|
||||
tween: Tween(begin: 0.0, end: 1.0),
|
||||
duration: const Duration(milliseconds: 900),
|
||||
curve: Curves.bounceOut,
|
||||
builder: (context, value, _) {
|
||||
return Transform.scale(
|
||||
scale: value,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: AppColor.primaryGradient,
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColor.primary.withOpacity(0.35),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 6),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
LineIcons.shoppingBag,
|
||||
color: AppColor.textWhite,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
const SpaceWidth(16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context.lang.total_purchase,
|
||||
style: TextStyle(
|
||||
color: AppColor.textWhite.withOpacity(0.9),
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SpaceHeight(4),
|
||||
Text(
|
||||
state.purchasing.summary.totalPurchases
|
||||
.currencyFormatRp,
|
||||
style: const TextStyle(
|
||||
color: AppColor.textWhite,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
'${state.purchasing.summary.totalPurchaseOrders} PO',
|
||||
style: const TextStyle(
|
||||
color: AppColor.textWhite,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'purchase order',
|
||||
style: TextStyle(
|
||||
color: AppColor.textWhite.withOpacity(0.8),
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Lists ────────────────────────────────────────────────────────────────
|
||||
|
||||
Widget _buildDailyList(PurchasingAnalyticLoaderState state) {
|
||||
if (state.purchasing.data.isEmpty) {
|
||||
return SliverToBoxAdapter(
|
||||
child: _buildEmptyState('Tidak ada data harian'));
|
||||
child: _buildEmptyState('Tidak ada data harian'),
|
||||
);
|
||||
}
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
@@ -499,7 +255,8 @@ class _PurchasePageState extends State<PurchasePage>
|
||||
Widget _buildIngredientList(PurchasingAnalyticLoaderState state) {
|
||||
if (state.purchasing.ingredientData.isEmpty) {
|
||||
return SliverToBoxAdapter(
|
||||
child: _buildEmptyState('Tidak ada data bahan baku'));
|
||||
child: _buildEmptyState('Tidak ada data bahan baku'),
|
||||
);
|
||||
}
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
@@ -516,7 +273,8 @@ class _PurchasePageState extends State<PurchasePage>
|
||||
Widget _buildVendorList(PurchasingAnalyticLoaderState state) {
|
||||
if (state.purchasing.vendorData.isEmpty) {
|
||||
return SliverToBoxAdapter(
|
||||
child: _buildEmptyState('Tidak ada data vendor'));
|
||||
child: _buildEmptyState('Tidak ada data vendor'),
|
||||
);
|
||||
}
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
@@ -552,51 +310,6 @@ class _PurchasePageState extends State<PurchasePage>
|
||||
|
||||
// ─── Shimmer Loaders ──────────────────────────────────────────────────────
|
||||
|
||||
Widget _buildSummaryShimmer() {
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _shimmerCard(height: 100)),
|
||||
const SpaceWidth(12),
|
||||
Expanded(child: _shimmerCard(height: 100)),
|
||||
],
|
||||
),
|
||||
const SpaceHeight(12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _shimmerCard(height: 100)),
|
||||
const SpaceWidth(12),
|
||||
Expanded(child: _shimmerCard(height: 100)),
|
||||
],
|
||||
),
|
||||
const SpaceHeight(12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _shimmerCard(height: 100)),
|
||||
const SpaceWidth(12),
|
||||
Expanded(child: _shimmerCard(height: 100)),
|
||||
],
|
||||
),
|
||||
const SpaceHeight(12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: _shimmerCard(height: 100)),
|
||||
const SpaceWidth(12),
|
||||
Expanded(child: _shimmerCard(height: 100)),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHighlightShimmer() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: _shimmerCard(height: 88),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildListShimmer() {
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
|
||||
import '../../../../application/analytic/purchasing_analytic_loader/purchasing_analytic_loader_bloc.dart';
|
||||
import '../../../../common/extension/extension.dart';
|
||||
import '../../../../common/painter/wave_painter.dart';
|
||||
import '../../../../common/theme/theme.dart';
|
||||
import '../../../components/bottom_sheet/date_range_bottom_sheet.dart';
|
||||
import '../../../components/spacer/spacer.dart';
|
||||
|
||||
class PurchaseHeader extends StatelessWidget {
|
||||
final PurchasingAnalyticLoaderState state;
|
||||
final void Function(DateTime startDate, DateTime endDate)? onDateRangeChanged;
|
||||
|
||||
const PurchaseHeader({
|
||||
super.key,
|
||||
required this.state,
|
||||
this.onDateRangeChanged,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final dateLabel = _formatDateRange(state.dateFrom, state.dateTo, context);
|
||||
final outletLabel = state.purchasing.outletName.isNotEmpty
|
||||
? state.purchasing.outletName
|
||||
: 'Semua Outlet';
|
||||
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: AppColor.primaryGradient,
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
),
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(24),
|
||||
bottomRight: Radius.circular(24),
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
// Decorative circles
|
||||
Positioned(
|
||||
top: -20,
|
||||
right: -30,
|
||||
child: Container(
|
||||
width: 120,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColor.textWhite.withOpacity(0.08),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 30,
|
||||
right: 20,
|
||||
child: Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColor.textWhite.withOpacity(0.05),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 10,
|
||||
left: -20,
|
||||
child: Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColor.textWhite.withOpacity(0.04),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Wave pattern
|
||||
Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: WavePainter(
|
||||
animation: 0.0,
|
||||
color: AppColor.textWhite.withOpacity(0.1),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Content
|
||||
SafeArea(
|
||||
bottom: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Back button + Title row + Calendar button
|
||||
Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => context.router.maybePop(),
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.textWhite.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.chevron_left_rounded,
|
||||
color: AppColor.textWhite,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SpaceWidth(12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context.lang.purchase,
|
||||
style: AppStyle.xl.copyWith(
|
||||
color: AppColor.textWhite,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'$dateLabel · $outletLabel',
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.textWhite.withOpacity(0.75),
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 12,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SpaceWidth(8),
|
||||
// Date filter button
|
||||
GestureDetector(
|
||||
onTap: () => _showDatePicker(context),
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.textWhite.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.calendar_month_rounded,
|
||||
color: AppColor.textWhite,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SpaceHeight(24),
|
||||
|
||||
// Total Pembelian label
|
||||
Text(
|
||||
context.lang.total_purchase,
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.textWhite.withOpacity(0.75),
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
|
||||
const SpaceHeight(4),
|
||||
|
||||
// Big value
|
||||
state.isFetching
|
||||
? _buildHeaderValueShimmer()
|
||||
: Text(
|
||||
state
|
||||
.purchasing
|
||||
.summary
|
||||
.totalPurchases
|
||||
.currencyFormatRp,
|
||||
style: AppStyle.h1.copyWith(
|
||||
color: AppColor.textWhite,
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 32,
|
||||
),
|
||||
),
|
||||
|
||||
const SpaceHeight(16),
|
||||
|
||||
// Chips row
|
||||
state.isFetching
|
||||
? _buildHeaderChipsShimmer()
|
||||
: _buildHeaderChips(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showDatePicker(BuildContext context) {
|
||||
DateRangePickerBottomSheet.show(
|
||||
context: context,
|
||||
primaryColor: AppColor.primary,
|
||||
initialStartDate: state.dateFrom,
|
||||
initialEndDate: state.dateTo,
|
||||
maxDate: DateTime.now(),
|
||||
onChanged: (startDate, endDate) {
|
||||
if (startDate != null && endDate != null) {
|
||||
onDateRangeChanged?.call(startDate, endDate);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeaderValueShimmer() {
|
||||
return Shimmer.fromColors(
|
||||
baseColor: AppColor.textWhite.withOpacity(0.3),
|
||||
highlightColor: AppColor.textWhite.withOpacity(0.6),
|
||||
child: Container(
|
||||
width: 200,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.textWhite.withOpacity(0.3),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeaderChipsShimmer() {
|
||||
return Row(
|
||||
children: List.generate(
|
||||
3,
|
||||
(index) => Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: Shimmer.fromColors(
|
||||
baseColor: AppColor.textWhite.withOpacity(0.15),
|
||||
highlightColor: AppColor.textWhite.withOpacity(0.3),
|
||||
child: Container(
|
||||
width: 90,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.textWhite.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeaderChips(BuildContext context) {
|
||||
final summary = state.purchasing.summary;
|
||||
|
||||
return Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
_buildChip('${summary.totalPurchaseOrders} PO'),
|
||||
_buildChip('${summary.totalQuantity} pcs'),
|
||||
_buildChip('${summary.totalVendors} vendor'),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildChip(String label) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.textWhite.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: AppColor.textWhite.withOpacity(0.25)),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: AppStyle.sm.copyWith(
|
||||
color: AppColor.textWhite,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _formatDateRange(DateTime from, DateTime to, BuildContext context) {
|
||||
const months = [
|
||||
'Jan',
|
||||
'Feb',
|
||||
'Mar',
|
||||
'Apr',
|
||||
'Mei',
|
||||
'Jun',
|
||||
'Jul',
|
||||
'Agu',
|
||||
'Sep',
|
||||
'Okt',
|
||||
'Nov',
|
||||
'Des',
|
||||
];
|
||||
|
||||
if (from.year == to.year && from.month == to.month && from.day == to.day) {
|
||||
return '${context.lang.report} ${from.day} ${months[from.month - 1]} ${from.year}';
|
||||
}
|
||||
return '${context.lang.report} ${from.day} ${months[from.month - 1]} - ${to.day} ${months[to.month - 1]} ${to.year}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
|
||||
import '../../../../application/analytic/purchasing_analytic_loader/purchasing_analytic_loader_bloc.dart';
|
||||
import '../../../../common/extension/extension.dart';
|
||||
import '../../../../common/theme/theme.dart';
|
||||
import '../../../components/spacer/spacer.dart';
|
||||
|
||||
class PurchaseRincianCard extends StatelessWidget {
|
||||
final PurchasingAnalyticLoaderState state;
|
||||
|
||||
const PurchaseRincianCard({super.key, required this.state});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (state.isFetching) return _buildShimmer();
|
||||
|
||||
final summary = state.purchasing.summary;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.04),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
context.lang.daily_breakdown,
|
||||
style: AppStyle.xl.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.textPrimary,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
const SpaceHeight(16),
|
||||
_buildRow('Total Pembelian', summary.totalPurchases.currencyFormatRp),
|
||||
_buildDivider(),
|
||||
_buildRow(
|
||||
'Bahan Baku',
|
||||
summary.rawMaterialPurchases.currencyFormatRp,
|
||||
),
|
||||
_buildDivider(),
|
||||
_buildRow('Pengeluaran', summary.expensePurchases.currencyFormatRp),
|
||||
_buildDivider(),
|
||||
_buildRow('Total PO', '${summary.totalPurchaseOrders} PO'),
|
||||
_buildDivider(),
|
||||
_buildRow('Total Qty', '${summary.totalQuantity} pcs'),
|
||||
_buildDivider(),
|
||||
_buildRow(
|
||||
'Rata-rata PO',
|
||||
summary.averagePurchaseOrderValue.round().currencyFormatRp,
|
||||
),
|
||||
_buildDivider(),
|
||||
_buildRow('Item Bahan Baku', '${summary.totalIngredients} item'),
|
||||
_buildDivider(),
|
||||
_buildRow('Vendor', '${summary.totalVendors} vendor'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRow(String label, String value, {bool isBold = false}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: AppStyle.md.copyWith(
|
||||
color: isBold ? AppColor.textPrimary : AppColor.textSecondary,
|
||||
fontWeight: isBold ? FontWeight.w700 : FontWeight.w500,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: AppStyle.md.copyWith(
|
||||
color: AppColor.textPrimary,
|
||||
fontWeight: isBold ? FontWeight.w700 : FontWeight.w600,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDivider() {
|
||||
return Divider(
|
||||
height: 1,
|
||||
thickness: 1,
|
||||
color: AppColor.border.withOpacity(0.5),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildShimmer() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.surface,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.04),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Shimmer.fromColors(
|
||||
baseColor: Colors.grey[300]!,
|
||||
highlightColor: Colors.grey[100]!,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: 140,
|
||||
height: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
const SpaceHeight(20),
|
||||
...List.generate(
|
||||
8,
|
||||
(index) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Container(
|
||||
width: 100,
|
||||
height: 14,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: 80,
|
||||
height: 14,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user