327 lines
12 KiB
Dart
327 lines
12 KiB
Dart
// import 'package:flutter/material.dart';
|
|
// import 'package:get/get.dart';
|
|
// import 'package:marco/controller/inventory/material_requisition_controller.dart';
|
|
// import 'package:marco/helpers/theme/app_theme.dart';
|
|
// import 'package:marco/helpers/widgets/my_card.dart';
|
|
// import 'package:marco/helpers/widgets/my_button.dart';
|
|
|
|
// class MaterialRequisitionFormScreen extends StatelessWidget {
|
|
// MaterialRequisitionFormScreen({super.key});
|
|
|
|
// final controller = Get.put(MaterialRequisitionController());
|
|
|
|
// @override
|
|
// Widget build(BuildContext context) {
|
|
// return Scaffold(
|
|
// appBar: AppBar(
|
|
// title: const Text('Material Requisition Form'),
|
|
// backgroundColor: Theme.of(context).colorScheme.primary,
|
|
// ),
|
|
// body: Obx(() {
|
|
// if (controller.isLoading.value) {
|
|
// return const Center(child: CircularProgressIndicator());
|
|
// }
|
|
|
|
// return SingleChildScrollView(
|
|
// padding: const EdgeInsets.all(16),
|
|
// child: Column(
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
// children: [
|
|
// // 🧱 Project Selection
|
|
// MyCard(
|
|
// child: DropdownButtonFormField<int>(
|
|
// decoration: const InputDecoration(labelText: 'Select Project'),
|
|
// value: controller.selectedProjectId.value,
|
|
// items: controller.projects
|
|
// .map(
|
|
// (proj) => DropdownMenuItem<int>(
|
|
// value: proj.id, // assuming id is int
|
|
// child: Text(proj.name ?? ''),
|
|
// ),
|
|
// )
|
|
// .toList(),
|
|
// onChanged: (val) {
|
|
// controller.selectedProjectId.value = val;
|
|
// if (val != null) {
|
|
// controller.fetchMaterialsByProject(val);
|
|
// }
|
|
// },
|
|
// ),
|
|
// ),
|
|
// const SizedBox(height: 16),
|
|
|
|
// // 🧱 Materials List
|
|
// MyCard(
|
|
// child: Column(
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
// children: [
|
|
// const Text(
|
|
// 'Selected Materials',
|
|
// style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
|
|
// ),
|
|
// const SizedBox(height: 8),
|
|
// Obx(() {
|
|
// final items = controller.selectedMR.value.items ?? [];
|
|
// if (items.isEmpty) {
|
|
// return const Text(
|
|
// 'No materials added yet.',
|
|
// style: TextStyle(color: Colors.grey),
|
|
// );
|
|
// }
|
|
|
|
// return ListView.builder(
|
|
// shrinkWrap: true,
|
|
// physics: const NeverScrollableScrollPhysics(),
|
|
// itemCount: items.length,
|
|
// itemBuilder: (context, index) {
|
|
// final item = items[index];
|
|
// return ListTile(
|
|
// title: Text(item.materialName ?? ''),
|
|
// subtitle: Text(
|
|
// 'Code: ${item.materialCode} | UOM: ${item.uom}',
|
|
// ),
|
|
// trailing: Text('Qty: ${item.qtyRequired ?? 0}'),
|
|
// );
|
|
// },
|
|
// );
|
|
// }),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
// const SizedBox(height: 24),
|
|
|
|
// // 🧱 Action Buttons
|
|
// Row(
|
|
// children: [
|
|
// // Cancel
|
|
// Expanded(
|
|
// child: MyButton.outlined(
|
|
// borderColor: Colors.grey,
|
|
// onPressed: () => Get.back(),
|
|
// child: const Text(
|
|
// 'Cancel',
|
|
// style: TextStyle(color: Colors.black54),
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// const SizedBox(width: 12),
|
|
|
|
// // Save as Draft
|
|
// Expanded(
|
|
// child: MyButton.medium(
|
|
// onPressed: () {
|
|
// final mr = controller.selectedMR.value;
|
|
// controller.saveDraft(mr);
|
|
// },
|
|
// backgroundColor: Theme.of(context).colorScheme.primary,
|
|
// child: const Text(
|
|
// 'Save as Draft',
|
|
// style: TextStyle(
|
|
// color: Colors.white,
|
|
// fontWeight: FontWeight.w600,
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// const SizedBox(height: 12),
|
|
|
|
// // 🧱 Submit (Full Width)
|
|
// MyButton.block(
|
|
// onPressed: () {
|
|
// final mr = controller.selectedMR.value;
|
|
// // ✅ use correct field name instead of `id`
|
|
// final mrId = mr.mrId ?? mr.id ?? mr.requisitionId;
|
|
|
|
// if (mrId != null) {
|
|
// controller.submitMR(mrId);
|
|
// } else {
|
|
// Get.snackbar('Error', 'Please save as draft first');
|
|
// }
|
|
// },
|
|
// backgroundColor: Colors.green,
|
|
// child: const Text(
|
|
// 'Submit Requisition',
|
|
// style: TextStyle(
|
|
// color: Colors.white,
|
|
// fontWeight: FontWeight.w600,
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// );
|
|
// }),
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:marco/controller/inventory/material_requisition_controller.dart';
|
|
|
|
class MaterialRequisitionFormScreen extends StatelessWidget {
|
|
final Map<String, dynamic>? mrData;
|
|
|
|
const MaterialRequisitionFormScreen({Key? key, this.mrData}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final controller = Get.put(MaterialRequisitionController());
|
|
final isNew = mrData == null;
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(isNew ? "Create Material Requisition" : "Requisition Details"),
|
|
backgroundColor: const Color(0xFF2C3E50), // Marco PMS blue-grey
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: isNew
|
|
? _buildNewForm(context, controller)
|
|
: _buildDetailView(context),
|
|
),
|
|
);
|
|
}
|
|
|
|
// 🧱 UI for new MR form (mock only)
|
|
Widget _buildNewForm(BuildContext context, MaterialRequisitionController controller) {
|
|
final TextEditingController projectNameCtrl = TextEditingController();
|
|
final TextEditingController requestedByCtrl = TextEditingController();
|
|
final TextEditingController materialCtrl = TextEditingController();
|
|
final TextEditingController qtyCtrl = TextEditingController();
|
|
|
|
return SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
const Text("Project Name", style: TextStyle(fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 6),
|
|
TextField(
|
|
controller: projectNameCtrl,
|
|
decoration: _inputDecoration("Enter project name"),
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text("Requested By", style: TextStyle(fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 6),
|
|
TextField(
|
|
controller: requestedByCtrl,
|
|
decoration: _inputDecoration("Enter requester name"),
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text("Material", style: TextStyle(fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 6),
|
|
TextField(
|
|
controller: materialCtrl,
|
|
decoration: _inputDecoration("Enter material name"),
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text("Quantity", style: TextStyle(fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 6),
|
|
TextField(
|
|
controller: qtyCtrl,
|
|
keyboardType: TextInputType.number,
|
|
decoration: _inputDecoration("Enter quantity"),
|
|
),
|
|
const SizedBox(height: 24),
|
|
Center(
|
|
child: ElevatedButton.icon(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: const Color(0xFF34495E),
|
|
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
icon: const Icon(Icons.save),
|
|
label: const Text("Save Draft"),
|
|
onPressed: () {
|
|
Get.snackbar("Saved", "Mock Material Requisition saved successfully!",
|
|
snackPosition: SnackPosition.BOTTOM,
|
|
backgroundColor: Colors.green.shade600,
|
|
colorText: Colors.white);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// 🧱 UI for viewing existing MR
|
|
Widget _buildDetailView(BuildContext context) {
|
|
final data = mrData ?? {};
|
|
|
|
return SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text("Project: ${data['projectName']}", style: const TextStyle(fontSize: 16)),
|
|
const SizedBox(height: 8),
|
|
Text("Requested By: ${data['requestedBy']}"),
|
|
Text("Date: ${data['date']}"),
|
|
Text("Status: ${data['status']}"),
|
|
const Divider(height: 32),
|
|
const Text("Materials:", style: TextStyle(fontWeight: FontWeight.bold)),
|
|
const SizedBox(height: 8),
|
|
...List.generate(
|
|
(data['materials'] as List).length,
|
|
(index) {
|
|
final item = (data['materials'] as List)[index];
|
|
return Text("- ${item['name']} (${item['qty']} ${item['unit']})");
|
|
},
|
|
),
|
|
const SizedBox(height: 24),
|
|
Center(
|
|
child: ElevatedButton.icon(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: const Color(0xFF34495E),
|
|
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
icon: const Icon(Icons.send),
|
|
label: const Text("Submit"),
|
|
onPressed: () {
|
|
Get.snackbar("Submitted", "Mock submission successful!",
|
|
snackPosition: SnackPosition.BOTTOM,
|
|
backgroundColor: Colors.blueGrey.shade700,
|
|
colorText: Colors.white);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
// 🧩 Common input field decoration
|
|
InputDecoration _inputDecoration(String hint) {
|
|
return InputDecoration(
|
|
hintText: hint,
|
|
filled: true,
|
|
fillColor: Colors.grey.shade100,
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
borderSide: const BorderSide(color: Color(0xFFBDC3C7)),
|
|
),
|
|
enabledBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
borderSide: const BorderSide(color: Color(0xFFBDC3C7)),
|
|
),
|
|
focusedBorder: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
borderSide: const BorderSide(color: Color(0xFF34495E), width: 1.5),
|
|
),
|
|
);
|
|
}
|
|
}
|