-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreturn_summary_screen.dart
More file actions
195 lines (182 loc) · 6.07 KB
/
return_summary_screen.dart
File metadata and controls
195 lines (182 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import 'package:flutter/material.dart';
import 'returned_item_model.dart';
// Enum to distinguish between return types
enum ReturnType { sales, purchase }
class ReturnSummaryScreen extends StatefulWidget {
final ReturnType returnType;
final double originalValue;
final double returnedGoodsValue;
final List<ReturnedItem> returnedItems;
const ReturnSummaryScreen({
super.key,
required this.returnType,
required this.originalValue,
required this.returnedGoodsValue,
required this.returnedItems,
});
@override
State<ReturnSummaryScreen> createState() => _ReturnSummaryScreenState();
}
class _ReturnSummaryScreenState extends State<ReturnSummaryScreen> {
late final TextEditingController _amountController;
@override
void initState() {
super.initState();
_amountController = TextEditingController(
text: widget.returnedGoodsValue.toStringAsFixed(2),
);
}
@override
void dispose() {
_amountController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final isSalesReturn = widget.returnType == ReturnType.sales;
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: Text(
isSalesReturn ? 'Sales Return Summary' : 'Purchase Return Summary',
),
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildSummaryCard(theme, isSalesReturn),
const SizedBox(height: 24),
_buildInventorySection(theme, isSalesReturn),
const SizedBox(height: 40),
ElevatedButton(
onPressed: () {
// Handle confirmation logic
final amount = double.tryParse(_amountController.text) ?? 0.0;
// You can use this value for your business logic
print('Confirmed Return. Amount: $amount');
Navigator.of(context).pop();
},
style: ElevatedButton.styleFrom(
minimumSize: const Size(double.infinity, 50),
),
child: const Text('Confirm Return'),
),
],
),
),
);
}
Widget _buildSummaryCard(ThemeData theme, bool isSalesReturn) {
return Card(
elevation: 2,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
_buildSummaryRow(
label: isSalesReturn
? 'Original Sales Value:'
: 'Original Purchase Cost:',
value: '₹${widget.originalValue.toStringAsFixed(2)}',
),
const SizedBox(height: 12),
_buildSummaryRow(
label: 'Value of Returned Goods:',
value: '₹${widget.returnedGoodsValue.toStringAsFixed(2)}',
),
const SizedBox(height: 12),
_buildAmountInputRow(
label: isSalesReturn
? 'Amount Refunded (if any):'
: 'Amount Expected from Distributor (if any):',
theme: theme,
),
],
),
),
);
}
Widget _buildInventorySection(ThemeData theme, bool isSalesReturn) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
isSalesReturn
? Icons.replay_circle_filled_outlined
: Icons.upload_outlined,
color: isSalesReturn ? Colors.green : Colors.red,
),
const SizedBox(width: 8),
Text(
isSalesReturn
? 'Inventory Adjusted (items added back to stock):'
: 'Inventory Adjusted (items removed from stock):',
style: theme.textTheme.titleMedium
?.copyWith(fontWeight: FontWeight.bold),
),
],
),
const SizedBox(height: 12),
Card(
elevation: 2,
child: ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: widget.returnedItems.length,
itemBuilder: (context, index) {
final item = widget.returnedItems[index];
return ListTile(
title: Text(item.name),
trailing: Text('Qty: ${item.quantity}',
style: const TextStyle(fontWeight: FontWeight.bold)),
);
},
separatorBuilder: (context, index) => const Divider(height: 1),
),
),
],
);
}
Widget _buildSummaryRow({required String label, required String value}) => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(label, style: Theme.of(context).textTheme.bodyLarge),
Text(value,
style: Theme.of(context)
.textTheme
.bodyLarge
?.copyWith(fontWeight: FontWeight.bold)),
],
);
Widget _buildAmountInputRow(
{required String label, required ThemeData theme}) =>
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(flex: 3, child: Text(label, style: theme.textTheme.bodyLarge)),
const SizedBox(width: 16),
Expanded(
flex: 2,
child: TextFormField(
controller: _amountController,
keyboardType:
const TextInputType.numberWithOptions(decimal: true),
textAlign: TextAlign.right,
style: theme.textTheme.bodyLarge
?.copyWith(fontWeight: FontWeight.bold),
decoration: const InputDecoration(
prefixText: '₹',
isDense: true,
contentPadding:
EdgeInsets.symmetric(vertical: 8, horizontal: 4),
),
),
),
],
);
}