|
|
|
|
@ -1,5 +1,3 @@
|
|
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:test_sa/extensions/context_extension.dart';
|
|
|
|
|
@ -10,6 +8,7 @@ import 'package:test_sa/extensions/text_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
|
import 'package:test_sa/models/lookup.dart';
|
|
|
|
|
import 'package:test_sa/modules/asset_delivery_module/models/cost_center_model.dart';
|
|
|
|
|
import 'package:test_sa/modules/asset_delivery_module/models/cost_center_serial_no_form_model.dart';
|
|
|
|
|
import 'package:test_sa/modules/asset_delivery_module/provider/asset_delivery_provider.dart';
|
|
|
|
|
import 'package:test_sa/modules/asset_delivery_module/provider/cost_center_provider.dart';
|
|
|
|
|
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
|
|
|
|
|
@ -47,8 +46,9 @@ class CostCenterFormView extends StatefulWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _CostCenterFormViewState extends State<CostCenterFormView> {
|
|
|
|
|
List<CostCenterModel> _list = [];
|
|
|
|
|
CostCenterSerialNoFormModel formModel = CostCenterSerialNoFormModel(costCenters: [], serialNos: []);
|
|
|
|
|
late AssetDeliveryProvider assetDeliveryProvider;
|
|
|
|
|
CostCenterType _selectedType = CostCenterType.costCenter;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
@ -60,15 +60,20 @@ class _CostCenterFormViewState extends State<CostCenterFormView> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getInitialData() async {
|
|
|
|
|
_list = await assetDeliveryProvider.getAssetDeliveryCostCenterListForLines(
|
|
|
|
|
formModel = await assetDeliveryProvider.getAssetDeliveryCostCenterListForLines(
|
|
|
|
|
lineId: widget.lineId,
|
|
|
|
|
tableItemId: widget.tableItemId,
|
|
|
|
|
);
|
|
|
|
|
if (_list.isEmpty) {
|
|
|
|
|
_list.add(CostCenterModel(
|
|
|
|
|
if (formModel.costCenters!.isEmpty) {
|
|
|
|
|
formModel.costCenters!.add(CostCenterModel(
|
|
|
|
|
id: 0,
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
// if (formModel.serialNos!.isEmpty) {
|
|
|
|
|
// formModel.serialNos!.add(SerialNoModel(
|
|
|
|
|
// id: 0,
|
|
|
|
|
// ));
|
|
|
|
|
// }
|
|
|
|
|
if (widget.isHmg == true) {
|
|
|
|
|
CostCenterProvider costCenterProvider = Provider.of<CostCenterProvider>(context, listen: false);
|
|
|
|
|
if (costCenterProvider.items.isEmpty) {
|
|
|
|
|
@ -78,21 +83,21 @@ class _CostCenterFormViewState extends State<CostCenterFormView> {
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _addNewEntry() {
|
|
|
|
|
void addItem<T>(List<T> list, T Function() creator) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_list.add(CostCenterModel(costCenter: Lookup()));
|
|
|
|
|
list.add(creator());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _removeEntry(int index) {
|
|
|
|
|
void removeItem<T>(List<T> list, int index) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_list.removeAt(index);
|
|
|
|
|
list.removeAt(index);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _updateModel(int index, void Function(CostCenterModel model) updateList) {
|
|
|
|
|
void updateItem<T>(List<T> list, int index, void Function(T item) updater) {
|
|
|
|
|
setState(() {
|
|
|
|
|
updateList(_list[index]);
|
|
|
|
|
updater(list[index]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -111,34 +116,9 @@ class _CostCenterFormViewState extends State<CostCenterFormView> {
|
|
|
|
|
? const CircularProgressIndicator(color: AppColor.primary10).center
|
|
|
|
|
: Column(
|
|
|
|
|
children: [
|
|
|
|
|
itemDetails(context: context, itemNo: widget.itemNo, itemDescription: widget.itemDescription),
|
|
|
|
|
ListView.builder(
|
|
|
|
|
itemCount: _list.length + 1,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16, top: 8),
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
if (index == _list.length) {
|
|
|
|
|
return AppFilledButton(
|
|
|
|
|
label: "Add Cost Center".addTranslation,
|
|
|
|
|
maxWidth: true,
|
|
|
|
|
textColor: AppColor.textColor(context),
|
|
|
|
|
buttonColor: context.isDark ? AppColor.neutral60 : AppColor.white10,
|
|
|
|
|
icon: Icon(Icons.add_circle, color: AppColor.blueStatus(context)),
|
|
|
|
|
showIcon: true,
|
|
|
|
|
onPressed: _addNewEntry,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return CostCenterItemCard(
|
|
|
|
|
model: _list[index],
|
|
|
|
|
index: index,
|
|
|
|
|
isReadOnly: false,
|
|
|
|
|
isHmg: widget.isHmg,
|
|
|
|
|
requestId: widget.requestId,
|
|
|
|
|
onUpdate: (updateList) => _updateModel(index, updateList),
|
|
|
|
|
onRemove: () => _removeEntry(index),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
).expanded,
|
|
|
|
|
itemDetails(),
|
|
|
|
|
selectionButton(),
|
|
|
|
|
_selectedType == CostCenterType.costCenter ? _buildCostCenterList() : _buildSerialNumberList(),
|
|
|
|
|
FooterActionButton.footerContainer(
|
|
|
|
|
context: context,
|
|
|
|
|
child: AppFilledButton(
|
|
|
|
|
@ -147,7 +127,9 @@ class _CostCenterFormViewState extends State<CostCenterFormView> {
|
|
|
|
|
maxWidth: true,
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading());
|
|
|
|
|
await assetDeliveryProvider.saveCostCenterToLineDeliveryInspection(tableItemId: widget.tableItemId, lineId: widget.lineId, list: _list).then((status) async {
|
|
|
|
|
await assetDeliveryProvider
|
|
|
|
|
.saveCostCenterToLineDeliveryInspection(tableItemId: widget.tableItemId, lineId: widget.lineId, list: formModel.costCenters, serialNoList: formModel.serialNos)
|
|
|
|
|
.then((status) async {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
if (status) {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
@ -163,40 +145,169 @@ class _CostCenterFormViewState extends State<CostCenterFormView> {
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget itemDetails({required BuildContext context, String? itemNo, String? itemDescription}) {
|
|
|
|
|
return Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
'Item No'.addTranslation,
|
|
|
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
|
|
|
),
|
|
|
|
|
8.height,
|
|
|
|
|
Text(
|
|
|
|
|
itemNo ?? '-',
|
|
|
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
|
|
|
),
|
|
|
|
|
8.height,
|
|
|
|
|
Text(
|
|
|
|
|
'Item Description'.addTranslation,
|
|
|
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
|
|
|
Widget _buildCostCenterList() {
|
|
|
|
|
return ListView.builder(
|
|
|
|
|
itemCount: formModel.costCenters!.length + 1,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16, top: 8),
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
if (index == formModel.costCenters!.length) {
|
|
|
|
|
return AppFilledButton(
|
|
|
|
|
label: "Add Cost Center".addTranslation,
|
|
|
|
|
maxWidth: true,
|
|
|
|
|
textColor: AppColor.textColor(context),
|
|
|
|
|
buttonColor: context.isDark ? AppColor.neutral60 : AppColor.white10,
|
|
|
|
|
icon: Icon(Icons.add_circle, color: AppColor.blueStatus(context)),
|
|
|
|
|
showIcon: true,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
addItem(formModel.costCenters!, () => CostCenterModel(costCenter: Lookup()));
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CostCenterItemCard(
|
|
|
|
|
model: formModel.costCenters![index],
|
|
|
|
|
index: index,
|
|
|
|
|
isReadOnly: false,
|
|
|
|
|
isHmg: widget.isHmg,
|
|
|
|
|
requestId: widget.requestId,
|
|
|
|
|
onUpdate: (update) {
|
|
|
|
|
updateItem<CostCenterModel>(formModel.costCenters!, index, update);
|
|
|
|
|
},
|
|
|
|
|
onRemove: () {
|
|
|
|
|
removeItem<CostCenterModel>(formModel.costCenters!, index);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
).expanded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildSerialNumberList() {
|
|
|
|
|
return ListView.builder(
|
|
|
|
|
itemCount: formModel.serialNos!.length + 1,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16, top: 8),
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
if (index == formModel.serialNos!.length) {
|
|
|
|
|
return AppFilledButton(
|
|
|
|
|
label: "Add Serial Number".addTranslation,
|
|
|
|
|
maxWidth: true,
|
|
|
|
|
textColor: AppColor.textColor(context),
|
|
|
|
|
buttonColor: context.isDark ? AppColor.neutral60 : AppColor.white10,
|
|
|
|
|
icon: Icon(Icons.add_circle, color: AppColor.blueStatus(context)),
|
|
|
|
|
showIcon: true,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
addItem(formModel.serialNos!, () => SerialNoModel());
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SerialNumberItemCard(
|
|
|
|
|
model: formModel.serialNos![index],
|
|
|
|
|
onUpdate: (update) {
|
|
|
|
|
updateItem<SerialNoModel>(formModel.serialNos!, index, update);
|
|
|
|
|
},
|
|
|
|
|
onRemove: () {
|
|
|
|
|
removeItem<SerialNoModel>(formModel.serialNos!, index);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
).expanded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget selectionButton() {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: _radioItem(
|
|
|
|
|
value: CostCenterType.costCenter,
|
|
|
|
|
groupValue: _selectedType,
|
|
|
|
|
title: 'Cost Center',
|
|
|
|
|
onTap: () {
|
|
|
|
|
setState(() {
|
|
|
|
|
_selectedType = CostCenterType.costCenter;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: _radioItem(
|
|
|
|
|
value: CostCenterType.serialNumber,
|
|
|
|
|
groupValue: _selectedType,
|
|
|
|
|
title: 'Serial Number',
|
|
|
|
|
onTap: () {
|
|
|
|
|
setState(() {
|
|
|
|
|
_selectedType = CostCenterType.serialNumber;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
8.height,
|
|
|
|
|
Text(
|
|
|
|
|
itemDescription ?? '-',
|
|
|
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _radioItem({
|
|
|
|
|
required CostCenterType value,
|
|
|
|
|
required CostCenterType groupValue,
|
|
|
|
|
required String title,
|
|
|
|
|
required VoidCallback onTap,
|
|
|
|
|
}) {
|
|
|
|
|
return GestureDetector(
|
|
|
|
|
behavior: HitTestBehavior.opaque,
|
|
|
|
|
onTap: onTap,
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Radio<CostCenterType>(
|
|
|
|
|
value: value,
|
|
|
|
|
groupValue: groupValue,
|
|
|
|
|
onChanged: (_) => onTap(),
|
|
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
|
visualDensity: VisualDensity.compact,
|
|
|
|
|
),
|
|
|
|
|
4.width,
|
|
|
|
|
title.addTranslation.bodyText(context),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
).toShadowContainer(
|
|
|
|
|
context,
|
|
|
|
|
borderRadius: 20,
|
|
|
|
|
padding: 12,
|
|
|
|
|
showShadow: false,
|
|
|
|
|
margin: const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 8),
|
|
|
|
|
);
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget itemDetails() {
|
|
|
|
|
return Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
'Item No'.addTranslation,
|
|
|
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
|
|
|
),
|
|
|
|
|
8.height,
|
|
|
|
|
Text(
|
|
|
|
|
widget.itemNo ?? '-',
|
|
|
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
|
|
|
),
|
|
|
|
|
8.height,
|
|
|
|
|
Text(
|
|
|
|
|
'Item Description'.addTranslation,
|
|
|
|
|
style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.black10),
|
|
|
|
|
),
|
|
|
|
|
8.height,
|
|
|
|
|
Text(
|
|
|
|
|
widget.itemDescription ?? '-',
|
|
|
|
|
style: AppTextStyles.bodyText2.copyWith(color: context.isDark ? AppColor.neutral30 : AppColor.neutral120),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
).toShadowContainer(
|
|
|
|
|
context,
|
|
|
|
|
borderRadius: 20,
|
|
|
|
|
padding: 12,
|
|
|
|
|
showShadow: false,
|
|
|
|
|
margin: const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 8),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class CostCenterItemCard extends StatelessWidget {
|
|
|
|
|
@ -294,3 +405,53 @@ class CostCenterItemCard extends StatelessWidget {
|
|
|
|
|
).toShadowContainer(context, paddingObject: const EdgeInsets.symmetric(horizontal: 12, vertical: 12)).paddingOnly(bottom: 12);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SerialNumberItemCard extends StatelessWidget {
|
|
|
|
|
final SerialNoModel model;
|
|
|
|
|
final VoidCallback onRemove;
|
|
|
|
|
final void Function(void Function(SerialNoModel model)) onUpdate;
|
|
|
|
|
|
|
|
|
|
const SerialNumberItemCard({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.model,
|
|
|
|
|
required this.onRemove,
|
|
|
|
|
required this.onUpdate,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
'Serial Number'.addTranslation.bodyText(context),
|
|
|
|
|
Container(
|
|
|
|
|
height: 28,
|
|
|
|
|
width: 28,
|
|
|
|
|
padding: const EdgeInsets.all(6),
|
|
|
|
|
child: "trash".toSvgAsset(height: 20, width: 20),
|
|
|
|
|
).onPress(onRemove),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
8.height,
|
|
|
|
|
AppTextFormField(
|
|
|
|
|
labelText: 'Serial Number'.addTranslation,
|
|
|
|
|
backgroundColor: AppColor.fieldBgColor(context),
|
|
|
|
|
initialValue: model.serialNo ?? '',
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
showShadow: false,
|
|
|
|
|
onChange: (value) {
|
|
|
|
|
model.serialNo = value;
|
|
|
|
|
},
|
|
|
|
|
style: Theme.of(context).textTheme.titleMedium,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
.toShadowContainer(
|
|
|
|
|
context,
|
|
|
|
|
paddingObject: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
|
|
|
|
)
|
|
|
|
|
.paddingOnly(bottom: 12);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|