update staff list, add pin editor and privilege editor
This commit is contained in:
@@ -151,6 +151,14 @@
|
|||||||
"staff.add":"Add",
|
"staff.add":"Add",
|
||||||
"staff.update":"Update",
|
"staff.update":"Update",
|
||||||
"staff.phone.search":"Enter phone number",
|
"staff.phone.search":"Enter phone number",
|
||||||
|
"staff.pin_login":"PIN Login",
|
||||||
|
"staff.edit_pin":"Edit PIN",
|
||||||
|
"staff.edit_privileges":"Edit Privileges",
|
||||||
|
"staff.privilege.title":"Privileges",
|
||||||
|
"staff.pin.title":"PIN",
|
||||||
|
"staff.new_pin":"New PIN",
|
||||||
|
"staff.confirm_pin":"Confirm PIN",
|
||||||
|
"staff.enable_pin":"Enable PIN Login",
|
||||||
"Staff End ================================================================":"",
|
"Staff End ================================================================":"",
|
||||||
|
|
||||||
"Profile Start ================================================================":"",
|
"Profile Start ================================================================":"",
|
||||||
|
|||||||
@@ -133,6 +133,7 @@
|
|||||||
"customer.disable.btn":"ပိတ်ပါ",
|
"customer.disable.btn":"ပိတ်ပါ",
|
||||||
"customer.enable.btn":"ဖွင့်ပါ",
|
"customer.enable.btn":"ဖွင့်ပါ",
|
||||||
"customer.chat.btn":"Chat",
|
"customer.chat.btn":"Chat",
|
||||||
|
|
||||||
"Customer End ================================================================":"",
|
"Customer End ================================================================":"",
|
||||||
|
|
||||||
"Invitation Start ================================================================":"",
|
"Invitation Start ================================================================":"",
|
||||||
@@ -151,6 +152,14 @@
|
|||||||
"staff.add":"အသစ်ထည့်မည်",
|
"staff.add":"အသစ်ထည့်မည်",
|
||||||
"staff.update":"ပြုပြင်မည်",
|
"staff.update":"ပြုပြင်မည်",
|
||||||
"staff.phone.search":"ဖုန်းနံပါတ် ရိုက်ထည့်ပါ",
|
"staff.phone.search":"ဖုန်းနံပါတ် ရိုက်ထည့်ပါ",
|
||||||
|
"staff.pin_login":"PIN Login",
|
||||||
|
"staff.edit_pin":"Edit PIN",
|
||||||
|
"staff.edit_privileges":"Edit Privileges",
|
||||||
|
"staff.privilege.title":"Privileges",
|
||||||
|
"staff.pin.title":"PIN",
|
||||||
|
"staff.new_pin":"New PIN",
|
||||||
|
"staff.confirm_pin":"Confirm PIN",
|
||||||
|
"staff.enable_pin":"Enable PIN Login",
|
||||||
"Staff End ================================================================":"",
|
"Staff End ================================================================":"",
|
||||||
|
|
||||||
"Profile Start ================================================================":"",
|
"Profile Start ================================================================":"",
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ const pkg_files_path = "/packages";
|
|||||||
const shipment_labels_files_path = "/shipment_labels";
|
const shipment_labels_files_path = "/shipment_labels";
|
||||||
const receipt_labels_files_path = "/receipts";
|
const receipt_labels_files_path = "/receipts";
|
||||||
const pickups_files_path = "/pickups";
|
const pickups_files_path = "/pickups";
|
||||||
|
const carton_files_path = "/cartons";
|
||||||
|
|
||||||
// Link page
|
// Link page
|
||||||
const page_payment_methods = "payment_methods";
|
const page_payment_methods = "payment_methods";
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ class Carton {
|
|||||||
int weight;
|
int weight;
|
||||||
String? packageType;
|
String? packageType;
|
||||||
String? pickUpID;
|
String? pickUpID;
|
||||||
List<String> photos = [];
|
|
||||||
List<String> photoUrls;
|
List<String> photoUrls;
|
||||||
String? remark;
|
String? remark;
|
||||||
DateTime? arrivedDate;
|
DateTime? arrivedDate;
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ class User {
|
|||||||
int userUnseenCount;
|
int userUnseenCount;
|
||||||
int fcsUnseenCount;
|
int fcsUnseenCount;
|
||||||
String? preferCurrency;
|
String? preferCurrency;
|
||||||
|
bool enablePinLogin;
|
||||||
|
String? pinDigit;
|
||||||
|
String? confirmPinDigit;
|
||||||
|
|
||||||
String get initial =>
|
String get initial =>
|
||||||
name != null && name != "" ? name!.substring(0, 1) : "?";
|
name != null && name != "" ? name!.substring(0, 1) : "?";
|
||||||
@@ -68,7 +71,10 @@ class User {
|
|||||||
this.lastMessageTime,
|
this.lastMessageTime,
|
||||||
this.userUnseenCount = 0,
|
this.userUnseenCount = 0,
|
||||||
this.fcsUnseenCount = 0,
|
this.fcsUnseenCount = 0,
|
||||||
this.preferCurrency});
|
this.preferCurrency,
|
||||||
|
this.enablePinLogin = false,
|
||||||
|
this.pinDigit,
|
||||||
|
this.confirmPinDigit});
|
||||||
|
|
||||||
factory User.fromJson(Map<String, dynamic> json) {
|
factory User.fromJson(Map<String, dynamic> json) {
|
||||||
return User(
|
return User(
|
||||||
|
|||||||
@@ -4,29 +4,29 @@ import 'package:fcs/pages/widgets/local_app_bar.dart';
|
|||||||
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
||||||
import 'package:fcs/pages/widgets/progress.dart';
|
import 'package:fcs/pages/widgets/progress.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import '../main/util.dart';
|
||||||
import '../widgets/local_button.dart';
|
import '../widgets/local_button.dart';
|
||||||
import '../widgets/multi_img_file.dart';
|
import '../widgets/multi_img_file.dart';
|
||||||
|
import 'model/carton_model.dart';
|
||||||
typedef void FindCallBack();
|
|
||||||
|
|
||||||
class CartonImageUploadEditor extends StatefulWidget {
|
class CartonImageUploadEditor extends StatefulWidget {
|
||||||
final Carton? box;
|
final Carton carton;
|
||||||
const CartonImageUploadEditor({this.box});
|
const CartonImageUploadEditor({required this.carton});
|
||||||
@override
|
@override
|
||||||
_CartonImageUploaState createState() => _CartonImageUploaState();
|
_CartonImageUploaState createState() => _CartonImageUploaState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CartonImageUploaState extends State<CartonImageUploadEditor> {
|
class _CartonImageUploaState extends State<CartonImageUploadEditor> {
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
Carton? _box;
|
|
||||||
MultiImgController multiImgController = MultiImgController();
|
MultiImgController _multiImgController = MultiImgController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_box = widget.box;
|
_multiImgController.setImageUrls = widget.carton.photoUrls;
|
||||||
multiImgController.setImageUrls = _box?.photoUrls;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -35,8 +35,9 @@ class _CartonImageUploaState extends State<CartonImageUploadEditor> {
|
|||||||
padding: const EdgeInsets.symmetric(horizontal: 30),
|
padding: const EdgeInsets.symmetric(horizontal: 30),
|
||||||
child: LocalButton(
|
child: LocalButton(
|
||||||
textKey: "btn.save",
|
textKey: "btn.save",
|
||||||
callBack: () {},
|
callBack: () {
|
||||||
),
|
_uploadImage();
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
return LocalProgress(
|
return LocalProgress(
|
||||||
@@ -53,19 +54,37 @@ class _CartonImageUploaState extends State<CartonImageUploadEditor> {
|
|||||||
child: ListView(
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
Center(
|
Center(
|
||||||
child: Text("${_box?.cartonNumber}",
|
child: Text("${widget.carton.cartonNumber}",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: primaryColor,
|
color: primaryColor,
|
||||||
fontSize: 25,
|
fontSize: 25,
|
||||||
))),
|
))),
|
||||||
MultiImageFile(
|
MultiImageFile(
|
||||||
enabled: true,
|
enabled: true,
|
||||||
controller: multiImgController,
|
controller: _multiImgController,
|
||||||
title: "Receipt File",
|
title: "Receipt File",
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
saveBtn,
|
saveBtn,
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_uploadImage() async {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await context.read<CartonModel>().uploadCartonImages(widget.carton,
|
||||||
|
_multiImgController.getAddedFile, _multiImgController.getDeletedUrl);
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
} catch (e) {
|
||||||
|
showMsgDialog(context, "Error", e.toString());
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class CartonInfo extends StatefulWidget {
|
|||||||
class _CartonInfoState extends State<CartonInfo> {
|
class _CartonInfoState extends State<CartonInfo> {
|
||||||
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
||||||
final NumberFormat numberFormatter = NumberFormat("#,###");
|
final NumberFormat numberFormatter = NumberFormat("#,###");
|
||||||
MultiImgController multiImgController = MultiImgController();
|
MultiImgController _multiImgController = MultiImgController();
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
late Carton _carton;
|
late Carton _carton;
|
||||||
List<CargoType> _cargoTypes = [];
|
List<CargoType> _cargoTypes = [];
|
||||||
@@ -58,7 +58,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
_carton.cartonType = carton_from_packages;
|
_carton.cartonType = carton_from_packages;
|
||||||
_carton.billTo = billToConsignee;
|
_carton.billTo = billToConsignee;
|
||||||
_carton.cartonSizeType = customCarton;
|
_carton.cartonSizeType = customCarton;
|
||||||
multiImgController.setImageUrls = _carton.photos;
|
_multiImgController.setImageUrls = _carton.photoUrls;
|
||||||
_cargoTypes = _carton.cargoTypes.where((e) => !e.isCutomDuty).toList();
|
_cargoTypes = _carton.cargoTypes.where((e) => !e.isCutomDuty).toList();
|
||||||
_surchareItems = _carton.cargoTypes.where((e) => e.isCutomDuty).toList();
|
_surchareItems = _carton.cargoTypes.where((e) => e.isCutomDuty).toList();
|
||||||
if (_carton.cartonType == carton_from_packages) {
|
if (_carton.cartonType == carton_from_packages) {
|
||||||
@@ -245,7 +245,6 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
style: TextStyle(color: Colors.black54, fontSize: 15)))
|
style: TextStyle(color: Colors.black54, fontSize: 15)))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
//),
|
|
||||||
Container(
|
Container(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(right: 60),
|
padding: const EdgeInsets.only(right: 60),
|
||||||
@@ -273,7 +272,6 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
);
|
);
|
||||||
}).toList()),
|
}).toList()),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -283,7 +281,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
|
|
||||||
final img = MultiImageFile(
|
final img = MultiImageFile(
|
||||||
enabled: false,
|
enabled: false,
|
||||||
controller: multiImgController,
|
controller: _multiImgController,
|
||||||
title: "Receipt File",
|
title: "Receipt File",
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -293,19 +291,29 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: Color(0xff272262),
|
backgroundColor: Color(0xff272262),
|
||||||
elevation: 3,
|
elevation: 3,
|
||||||
shape:
|
shape: RoundedRectangleBorder(
|
||||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
|
borderRadius: BorderRadius.circular(5.0)),
|
||||||
minimumSize: Size(10, 35),
|
minimumSize: Size(10, 35),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
Navigator.push(
|
bool? updated = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) => CartonImageUploadEditor(box: _carton)),
|
builder: (context) =>
|
||||||
|
CartonImageUploadEditor(carton: _carton)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (updated ?? false) {
|
||||||
|
Carton? c = await context
|
||||||
|
.read<CartonModel>()
|
||||||
|
.getCarton(widget.carton.id ?? "");
|
||||||
|
if (c == null) return;
|
||||||
|
_carton = c;
|
||||||
|
_init();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: const Text('Upload Images'),
|
child: LocalText(context, "box.imageupload.title",
|
||||||
),
|
color: Colors.white, fontSize: 14)),
|
||||||
);
|
);
|
||||||
|
|
||||||
final deleteBtn = Padding(
|
final deleteBtn = Padding(
|
||||||
@@ -390,7 +398,9 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
_surchareItems.isEmpty ? const SizedBox() : surchargeItemBox,
|
_surchareItems.isEmpty ? const SizedBox() : surchargeItemBox,
|
||||||
uploadImageBtn,
|
uploadImageBtn,
|
||||||
img,
|
img,
|
||||||
deleteBtn
|
const SizedBox(height: 15),
|
||||||
|
deleteBtn,
|
||||||
|
const SizedBox(height: 20)
|
||||||
]))));
|
]))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,11 +95,18 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
|
|||||||
_heightController.text =
|
_heightController.text =
|
||||||
widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0);
|
widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0);
|
||||||
|
|
||||||
|
_loadShipment();
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_loadShipment() async {
|
||||||
var fcsShipments =
|
var fcsShipments =
|
||||||
await context.read<FcsShipmentModel>().getActiveFcsShipments();
|
await context.read<FcsShipmentModel>().getActiveFcsShipments();
|
||||||
_shipments = fcsShipments;
|
_shipments = fcsShipments;
|
||||||
_shipment = widget.shipment;
|
_shipment = widget.shipment;
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
@@ -107,7 +114,7 @@ class _CartonSizeWidgetState extends State<CartonSizeWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void didUpdateWidget(covariant CartonSizeWidget oldWidget) {
|
void didUpdateWidget(covariant CartonSizeWidget oldWidget) {
|
||||||
_init();
|
_loadShipment();
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,11 +76,18 @@ class _TypeWidgetState extends State<TypeWidget> {
|
|||||||
_heightController.text =
|
_heightController.text =
|
||||||
widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0);
|
widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0);
|
||||||
|
|
||||||
|
_loadShipment();
|
||||||
|
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_loadShipment() async {
|
||||||
var fcsShipments =
|
var fcsShipments =
|
||||||
await context.read<FcsShipmentModel>().getActiveFcsShipments();
|
await context.read<FcsShipmentModel>().getActiveFcsShipments();
|
||||||
_shipments = fcsShipments;
|
_shipments = fcsShipments;
|
||||||
_shipment = widget.shipment;
|
_shipment = widget.shipment;
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
@@ -88,7 +95,7 @@ class _TypeWidgetState extends State<TypeWidget> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void didUpdateWidget(covariant TypeWidget oldWidget) {
|
void didUpdateWidget(covariant TypeWidget oldWidget) {
|
||||||
_init();
|
_loadShipment();
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
import 'package:fcs/data/services/services.dart';
|
import 'package:fcs/data/services/services.dart';
|
||||||
@@ -10,6 +11,8 @@ import 'package:fcs/pagination/paginator_listener.dart';
|
|||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
import '../../../domain/entities/user.dart';
|
import '../../../domain/entities/user.dart';
|
||||||
|
import '../../../helpers/firebase_helper.dart';
|
||||||
|
import 'package:path/path.dart' as Path;
|
||||||
|
|
||||||
class CartonModel extends BaseModel {
|
class CartonModel extends BaseModel {
|
||||||
final log = Logger('CartonModel');
|
final log = Logger('CartonModel');
|
||||||
@@ -241,4 +244,40 @@ class CartonModel extends BaseModel {
|
|||||||
}
|
}
|
||||||
return cartons;
|
return cartons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> uploadCartonImages(
|
||||||
|
Carton carton, List<File?> files, List<String?> deletedUrls) async {
|
||||||
|
if (deletedUrls.isNotEmpty) {
|
||||||
|
for (String? url in deletedUrls) {
|
||||||
|
carton.photoUrls.remove(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> uploadedURL = [];
|
||||||
|
if (files.isNotEmpty) {
|
||||||
|
var count =
|
||||||
|
(carton.photoUrls.length) + files.length - (deletedUrls.length);
|
||||||
|
|
||||||
|
if (count > uploadPhotoLimit)
|
||||||
|
throw Exception("Exceed number of file upload");
|
||||||
|
|
||||||
|
carton.photoUrls = carton.photoUrls;
|
||||||
|
String path = Path.join(carton_files_path);
|
||||||
|
uploadedURL = await uploadFiles(path, files);
|
||||||
|
uploadedURL.forEach((url) {
|
||||||
|
carton.photoUrls.add(url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// await Services.instance.packageService.updateReceiving(package);
|
||||||
|
} catch (e) {
|
||||||
|
// delete newly uploaded photos if fails
|
||||||
|
try {
|
||||||
|
deleteStorageFromUrls(uploadedURL);
|
||||||
|
carton.photoUrls.removeWhere((i) => uploadedURL.contains(i));
|
||||||
|
} catch (e) {}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return deleteStorageFromUrls(deletedUrls);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import 'package:fcs/domain/entities/discount.dart';
|
import 'package:fcs/domain/entities/discount.dart';
|
||||||
import 'package:fcs/helpers/theme.dart';
|
import 'package:fcs/helpers/theme.dart';
|
||||||
import 'package:fcs/localization/app_translations.dart';
|
|
||||||
import 'package:fcs/pages/discount/model/discount_model.dart';
|
import 'package:fcs/pages/discount/model/discount_model.dart';
|
||||||
import 'package:fcs/pages/main/util.dart';
|
import 'package:fcs/pages/main/util.dart';
|
||||||
import 'package:fcs/pages/user_search/user_search.dart';
|
import 'package:fcs/pages/user_search/user_search.dart';
|
||||||
import 'package:fcs/pages/widgets/display_text.dart';
|
import 'package:fcs/pages/widgets/display_text.dart';
|
||||||
import 'package:fcs/pages/widgets/input_text.dart';
|
import 'package:fcs/pages/widgets/input_text.dart';
|
||||||
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
||||||
import 'package:fcs/pages/widgets/progress.dart';
|
import 'package:fcs/pages/widgets/progress.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
@@ -88,29 +87,17 @@ class _DiscountEditorState extends State<DiscountEditor> {
|
|||||||
inAsyncCall: _isLoading,
|
inAsyncCall: _isLoading,
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
appBar: AppBar(
|
appBar: LocalAppBar(
|
||||||
centerTitle: true,
|
labelKey: "discount.form",
|
||||||
title: Text(
|
backgroundColor: Colors.white,
|
||||||
AppTranslations.of(context)!.text("discount.form"),
|
arrowColor: primaryColor,
|
||||||
),
|
labelColor: primaryColor,
|
||||||
leading: new IconButton(
|
|
||||||
icon: new Icon(CupertinoIcons.back),
|
|
||||||
onPressed: () {
|
|
||||||
if (isDataChanged()) {
|
|
||||||
showConfirmDialog(context, "back.button_confirm", () {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
backgroundColor: primaryColor,
|
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
_isNew
|
||||||
icon: Icon(Icons.delete),
|
? const SizedBox()
|
||||||
onPressed: _delete,
|
: IconButton(
|
||||||
)
|
icon: Icon(Icons.delete, color: primaryColor),
|
||||||
|
onPressed: _delete)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:fcs/helpers/theme.dart';
|
import 'package:fcs/helpers/theme.dart';
|
||||||
import 'package:fcs/localization/app_translations.dart';
|
|
||||||
import 'package:fcs/pages/discount/discount_list_row.dart';
|
import 'package:fcs/pages/discount/discount_list_row.dart';
|
||||||
import 'package:fcs/pages/discount/model/discount_model.dart';
|
import 'package:fcs/pages/discount/model/discount_model.dart';
|
||||||
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
||||||
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
|
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
|
||||||
import 'package:fcs/domain/vo/local_popupmenu.dart';
|
import 'package:fcs/domain/vo/local_popupmenu.dart';
|
||||||
import 'package:fcs/pages/widgets/local_text.dart';
|
import 'package:fcs/pages/widgets/local_text.dart';
|
||||||
@@ -58,26 +58,13 @@ class _DiscountListState extends State<DiscountList> {
|
|||||||
return LocalProgress(
|
return LocalProgress(
|
||||||
inAsyncCall: _isLoading,
|
inAsyncCall: _isLoading,
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: LocalAppBar(labelKey: "discount.title", actions: [popupMenu]),
|
||||||
centerTitle: true,
|
|
||||||
title: Text(
|
|
||||||
AppTranslations.of(context)!.text("discount.title"),
|
|
||||||
),
|
|
||||||
leading: new IconButton(
|
|
||||||
icon: new Icon(CupertinoIcons.back),
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
),
|
|
||||||
backgroundColor: primaryColor,
|
|
||||||
actions: <Widget>[popupMenu],
|
|
||||||
),
|
|
||||||
body: Column(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.separated(
|
child: ListView.separated(
|
||||||
separatorBuilder: (context, index) => Divider(
|
separatorBuilder: (context, index) =>
|
||||||
color: Colors.black,
|
Divider(color: Colors.black, height: 1),
|
||||||
height: 1,
|
|
||||||
),
|
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
itemCount: discountModel.discounts.length,
|
itemCount: discountModel.discounts.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
|
|||||||
body: Card(
|
body: Card(
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(10.0),
|
padding: const EdgeInsets.only(left: 12.0, right: 12),
|
||||||
child: ListView(children: <Widget>[
|
child: ListView(children: <Widget>[
|
||||||
statusBox,
|
statusBox,
|
||||||
Row(mainAxisAlignment: MainAxisAlignment.end, children: [
|
Row(mainAxisAlignment: MainAxisAlignment.end, children: [
|
||||||
|
|||||||
@@ -396,7 +396,6 @@ bool hasUnicode(String text) {
|
|||||||
return unicodeSymbols.length > 0;
|
return unicodeSymbols.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String removeTrailingZeros(double number) {
|
String removeTrailingZeros(double number) {
|
||||||
String result = number.toString();
|
String result = number.toString();
|
||||||
result = result.indexOf('.') > 0
|
result = result.indexOf('.') > 0
|
||||||
|
|||||||
@@ -106,4 +106,29 @@ class StaffModel extends BaseModel {
|
|||||||
}
|
}
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<User?> getUser(String userID) async {
|
||||||
|
if (userID == "") return null;
|
||||||
|
|
||||||
|
String path = "/$user_collection";
|
||||||
|
try {
|
||||||
|
var snap = await FirebaseFirestore.instance
|
||||||
|
.collection(path)
|
||||||
|
.doc(userID)
|
||||||
|
.get(const GetOptions(source: Source.server));
|
||||||
|
|
||||||
|
if (snap.data() == null) return null;
|
||||||
|
Map<String, dynamic>? data = snap.data() as Map<String, dynamic>;
|
||||||
|
|
||||||
|
if (data['delete_time'] == 0) {
|
||||||
|
User user = User.fromMap(data, snap.id);
|
||||||
|
return user;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.warning("Error!! $e");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class _StaffEditorState extends State<StaffEditor> {
|
|||||||
}),
|
}),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(right: 8.0),
|
padding: const EdgeInsets.only(right: 8.0),
|
||||||
child: Icon(p.iconData, size: 50, color: Colors.black38),
|
child: Icon(p.iconData, size: 30, color: Colors.black38),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -80,10 +80,10 @@ class _StaffEditorState extends State<StaffEditor> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Text(
|
new Text(
|
||||||
p.name ?? "",
|
p.name ?? "",
|
||||||
style: TextStyle(fontSize: 15.0, color: primaryColor),
|
style: TextStyle(fontSize: 15.0, color: Colors.black),
|
||||||
),
|
),
|
||||||
Text(p.desc ?? "",
|
Text(p.desc ?? "",
|
||||||
style: TextStyle(fontSize: 13, color: Colors.grey[600]))
|
style: TextStyle(fontSize: 13, color: labelColor))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -155,15 +155,22 @@ class _StaffEditorState extends State<StaffEditor> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
final updateButton = fcsButton(
|
final updateButton = Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 30),
|
||||||
|
child: fcsButton(
|
||||||
context,
|
context,
|
||||||
getLocalString(context, 'staff.update'),
|
getLocalString(context, 'staff.update'),
|
||||||
callack: _save,
|
callack: _save,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
final addButton = fcsButton(
|
|
||||||
|
final addButton = Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 30),
|
||||||
|
child: fcsButton(
|
||||||
context,
|
context,
|
||||||
getLocalString(context, 'staff.add'),
|
getLocalString(context, 'staff.add'),
|
||||||
callack: _add,
|
callack: _add,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
return LocalProgress(
|
return LocalProgress(
|
||||||
@@ -196,9 +203,7 @@ class _StaffEditorState extends State<StaffEditor> {
|
|||||||
Container(
|
Container(
|
||||||
child: isNew ? addButton : updateButton,
|
child: isNew ? addButton : updateButton,
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(height: 20)
|
||||||
height: 10,
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
203
lib/pages/staff/staff_info.dart
Normal file
203
lib/pages/staff/staff_info.dart
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
import 'package:fcs/domain/entities/user.dart';
|
||||||
|
import 'package:fcs/domain/vo/privilege.dart';
|
||||||
|
import 'package:fcs/helpers/theme.dart';
|
||||||
|
import 'package:fcs/pages/main/util.dart';
|
||||||
|
import 'package:fcs/pages/staff/model/staff_model.dart';
|
||||||
|
import 'package:fcs/pages/widgets/display_text.dart';
|
||||||
|
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
|
||||||
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
||||||
|
import 'package:fcs/pages/widgets/local_text.dart';
|
||||||
|
import 'package:fcs/pages/widgets/progress.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import 'staff_pin_editor.dart';
|
||||||
|
import 'staff_privilege_editor.dart';
|
||||||
|
|
||||||
|
class StaffInfo extends StatefulWidget {
|
||||||
|
final User staff;
|
||||||
|
const StaffInfo({required this.staff});
|
||||||
|
@override
|
||||||
|
_StaffInfoState createState() => _StaffInfoState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StaffInfoState extends State<StaffInfo> {
|
||||||
|
bool _isLoading = false;
|
||||||
|
late User _staff;
|
||||||
|
List<Privilege> _privileges = [];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_staff = widget.staff;
|
||||||
|
_init();
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
_init() {
|
||||||
|
List<Privilege> list =
|
||||||
|
Provider.of<StaffModel>(context, listen: false).privileges;
|
||||||
|
list.forEach((p) => _staff.privileges.contains(p.id)
|
||||||
|
? p.isChecked = true
|
||||||
|
: p.isChecked = false);
|
||||||
|
_privileges = list.where((e) => e.isChecked ?? false).toList();
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> showprivilegeList(BuildContext context) {
|
||||||
|
return _privileges.map((p) {
|
||||||
|
return new ListTile(
|
||||||
|
title: new Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 8.0),
|
||||||
|
child: Icon(p.iconData, size: 30, color: Colors.black38),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
new Text(
|
||||||
|
p.name ?? "",
|
||||||
|
style: TextStyle(fontSize: 15.0, color: Colors.black),
|
||||||
|
),
|
||||||
|
Text(p.desc ?? "",
|
||||||
|
style: TextStyle(fontSize: 13, color: labelColor))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
));
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final fcsIdBox = DisplayText(
|
||||||
|
text: _staff.fcsID,
|
||||||
|
labelTextKey: "customer.fcs.id",
|
||||||
|
icon: FcsIDIcon(),
|
||||||
|
);
|
||||||
|
|
||||||
|
final namebox = DisplayText(
|
||||||
|
text: _staff.name,
|
||||||
|
labelTextKey: "customer.name",
|
||||||
|
iconData: Icons.person,
|
||||||
|
);
|
||||||
|
|
||||||
|
final phoneNumberBox = Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Expanded(
|
||||||
|
child: DisplayText(
|
||||||
|
text: _staff.phoneNumber,
|
||||||
|
labelTextKey: "customer.phone",
|
||||||
|
iconData: Icons.phone,
|
||||||
|
)),
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.open_in_new, color: primaryColor),
|
||||||
|
onPressed: () => call(context, _staff.phoneNumber!)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
final pinBox = Row(
|
||||||
|
children: <Widget>[
|
||||||
|
Expanded(
|
||||||
|
child: DisplayText(
|
||||||
|
text: _staff.enablePinLogin ? "Enabled" : "Disabled",
|
||||||
|
labelTextKey: "staff.pin_login",
|
||||||
|
iconData: MaterialCommunityIcons.lock)),
|
||||||
|
SizedBox(
|
||||||
|
width: 65,
|
||||||
|
height: 35,
|
||||||
|
child: OutlinedButton(
|
||||||
|
style: OutlinedButton.styleFrom(
|
||||||
|
padding: EdgeInsets.all(5),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5.0)),
|
||||||
|
side: BorderSide(color: primaryColor),
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
bool? updated = await Navigator.of(context).push(
|
||||||
|
CupertinoPageRoute(
|
||||||
|
builder: (context) => StaffPinEditor(staff: _staff)));
|
||||||
|
|
||||||
|
if (updated ?? false) {
|
||||||
|
User? _u =
|
||||||
|
await context.read<StaffModel>().getUser(widget.staff.id!);
|
||||||
|
if (_u == null) return;
|
||||||
|
_staff = _u;
|
||||||
|
_init();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: LocalText(context, 'staff.edit_pin',
|
||||||
|
color: primaryColor, fontSize: 13),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
final privilegeTitleBox = Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: LocalText(context, 'staff.privilege.title',
|
||||||
|
color: Colors.black54, fontSize: 15)),
|
||||||
|
SizedBox(
|
||||||
|
width: 100,
|
||||||
|
height: 35,
|
||||||
|
child: OutlinedButton(
|
||||||
|
style: OutlinedButton.styleFrom(
|
||||||
|
padding: EdgeInsets.all(5),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5.0)),
|
||||||
|
side: BorderSide(color: primaryColor),
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
bool? updated = await Navigator.of(context).push(
|
||||||
|
CupertinoPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
StaffPrivilegeEditor(staff: _staff)));
|
||||||
|
|
||||||
|
if (updated ?? false) {
|
||||||
|
User? _u =
|
||||||
|
await context.read<StaffModel>().getUser(widget.staff.id!);
|
||||||
|
if (_u == null) return;
|
||||||
|
_staff = _u;
|
||||||
|
_init();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: LocalText(context, 'staff.edit_privileges',
|
||||||
|
color: primaryColor, fontSize: 13),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
return LocalProgress(
|
||||||
|
inAsyncCall: _isLoading,
|
||||||
|
child: Scaffold(
|
||||||
|
appBar: LocalAppBar(
|
||||||
|
labelKey: "staff.form.title",
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
labelColor: primaryColor,
|
||||||
|
arrowColor: primaryColor),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 12.0, right: 12),
|
||||||
|
child: ListView(
|
||||||
|
children: <Widget>[
|
||||||
|
fcsIdBox,
|
||||||
|
phoneNumberBox,
|
||||||
|
namebox,
|
||||||
|
pinBox,
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
privilegeTitleBox,
|
||||||
|
Column(children: showprivilegeList(context)),
|
||||||
|
SizedBox(height: 30)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import 'package:provider/provider.dart';
|
|||||||
|
|
||||||
import '../../pagination/paginator_listview.dart';
|
import '../../pagination/paginator_listview.dart';
|
||||||
import 'staff_editor.dart';
|
import 'staff_editor.dart';
|
||||||
|
import 'staff_info.dart';
|
||||||
|
|
||||||
class StaffList extends StatefulWidget {
|
class StaffList extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@@ -57,23 +58,19 @@ class _StaffListState extends State<StaffList> {
|
|||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
CupertinoPageRoute(builder: (context) => StaffEditor(staff: user)));
|
CupertinoPageRoute(builder: (context) => StaffInfo(staff: user)));
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Expanded(
|
Expanded(
|
||||||
child: new Padding(
|
child: new Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10.0),
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
child: new Row(
|
child: new Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Padding(
|
new Padding(
|
||||||
padding: new EdgeInsets.symmetric(
|
padding: new EdgeInsets.symmetric(horizontal: 15),
|
||||||
horizontal: 32.0 - dotSize / 2),
|
child: Icon(MaterialCommunityIcons.account_hard_hat,
|
||||||
child: Icon(
|
color: primaryColor, size: 30),
|
||||||
MaterialCommunityIcons.account_hard_hat,
|
|
||||||
color: primaryColor,
|
|
||||||
size: 40,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
new Expanded(
|
new Expanded(
|
||||||
child: new Column(
|
child: new Column(
|
||||||
@@ -84,7 +81,15 @@ class _StaffListState extends State<StaffList> {
|
|||||||
style: new TextStyle(fontSize: 15.0),
|
style: new TextStyle(fontSize: 15.0),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 8.0),
|
padding: const EdgeInsets.only(top: 2),
|
||||||
|
child: new Text(
|
||||||
|
user.fcsID ?? "",
|
||||||
|
style: new TextStyle(
|
||||||
|
fontSize: 15.0, color: Colors.grey),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 2),
|
||||||
child: new Text(
|
child: new Text(
|
||||||
user.phoneNumber ?? "",
|
user.phoneNumber ?? "",
|
||||||
style: new TextStyle(
|
style: new TextStyle(
|
||||||
|
|||||||
192
lib/pages/staff/staff_pin_editor.dart
Normal file
192
lib/pages/staff/staff_pin_editor.dart
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
import 'package:fcs/domain/entities/user.dart';
|
||||||
|
import 'package:fcs/helpers/theme.dart';
|
||||||
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
||||||
|
import 'package:fcs/pages/widgets/progress.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pin_input_text_field/pin_input_text_field.dart';
|
||||||
|
|
||||||
|
import '../main/util.dart';
|
||||||
|
import '../widgets/local_text.dart';
|
||||||
|
|
||||||
|
class StaffPinEditor extends StatefulWidget {
|
||||||
|
final User staff;
|
||||||
|
const StaffPinEditor({required this.staff});
|
||||||
|
@override
|
||||||
|
_StaffPinEditorState createState() => _StaffPinEditorState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StaffPinEditorState extends State<StaffPinEditor> {
|
||||||
|
bool _isLoading = false;
|
||||||
|
late User _staff;
|
||||||
|
bool _enablePinLogin = false;
|
||||||
|
String _newPin = "";
|
||||||
|
String _confirmPin = "";
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_staff = widget.staff;
|
||||||
|
_enablePinLogin = _staff.enablePinLogin;
|
||||||
|
_newPin = _staff.pinDigit ?? "";
|
||||||
|
_confirmPin = _staff.confirmPinDigit ?? "";
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final enablePinBox = Row(
|
||||||
|
children: [
|
||||||
|
Checkbox(
|
||||||
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
visualDensity: const VisualDensity(
|
||||||
|
horizontal: VisualDensity.minimumDensity,
|
||||||
|
vertical: VisualDensity.minimumDensity),
|
||||||
|
activeColor: primaryColor,
|
||||||
|
side: BorderSide(color: Colors.black38, width: 2),
|
||||||
|
value: _enablePinLogin,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
_enablePinLogin = value ?? false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(width: 15),
|
||||||
|
LocalText(context, 'staff.enable_pin',
|
||||||
|
fontSize: 15, color: Colors.black)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
final newPinBox = Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
LocalText(context, 'staff.new_pin',
|
||||||
|
color: Colors.black54, fontSize: 15),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
PinInputTextField(
|
||||||
|
cursor: Cursor(
|
||||||
|
color: primaryColor, enabled: true, width: 2, height: 30),
|
||||||
|
pinLength: 6,
|
||||||
|
decoration: BoxLooseDecoration(
|
||||||
|
strokeColorBuilder:
|
||||||
|
PinListenColorBuilder(primaryColor, Colors.grey.shade400)),
|
||||||
|
textInputAction: TextInputAction.done,
|
||||||
|
autoFocus: true,
|
||||||
|
onChanged: _newPinChange),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
final confirmPinBox = Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
LocalText(context, 'staff.confirm_pin',
|
||||||
|
color: Colors.black54, fontSize: 15),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
PinInputTextField(
|
||||||
|
pinLength: 6,
|
||||||
|
cursor: Cursor(
|
||||||
|
color: primaryColor, enabled: true, width: 2, height: 30),
|
||||||
|
decoration: BoxLooseDecoration(
|
||||||
|
strokeColorBuilder:
|
||||||
|
PinListenColorBuilder(primaryColor, Colors.grey.shade400)),
|
||||||
|
textInputAction: TextInputAction.done,
|
||||||
|
autoFocus: false,
|
||||||
|
onChanged: _confirmPinChange),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
final saveButton = Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 30),
|
||||||
|
child: fcsButton(
|
||||||
|
context,
|
||||||
|
getLocalString(context, 'btn.save'),
|
||||||
|
callack: _save,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return LocalProgress(
|
||||||
|
inAsyncCall: _isLoading,
|
||||||
|
child: Scaffold(
|
||||||
|
appBar: LocalAppBar(
|
||||||
|
labelKey: "staff.pin.title",
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
labelColor: primaryColor,
|
||||||
|
arrowColor: primaryColor),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 15.0, right: 15),
|
||||||
|
child: ListView(
|
||||||
|
children: <Widget>[
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
Text(_staff.name ?? "",
|
||||||
|
style: TextStyle(color: Colors.black, fontSize: 18)),
|
||||||
|
Text(_staff.fcsID ?? "",
|
||||||
|
style: TextStyle(color: Colors.black, fontSize: 15)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
enablePinBox,
|
||||||
|
const SizedBox(height: 30),
|
||||||
|
newPinBox,
|
||||||
|
SizedBox(height: 30),
|
||||||
|
confirmPinBox,
|
||||||
|
SizedBox(height: 30),
|
||||||
|
saveButton,
|
||||||
|
SizedBox(height: 30)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
_newPinChange(pin) {
|
||||||
|
setState(() {
|
||||||
|
this._newPin = pin;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_confirmPinChange(pin) {
|
||||||
|
setState(() {
|
||||||
|
this._confirmPin = pin;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_save() async {
|
||||||
|
if (_newPin == "") {
|
||||||
|
showMsgDialog(context, "Error", "Invalid new PIN");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_newPin.length < 6) {
|
||||||
|
showMsgDialog(context, "Error", "New PIN must be 6 digits");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_confirmPin == "") {
|
||||||
|
showMsgDialog(context, "Error", "Invalid confirm PIN");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_confirmPin.length < 6) {
|
||||||
|
showMsgDialog(context, "Error", "Confirm PIN must be 6 digits");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_confirmPin != _newPin) {
|
||||||
|
showMsgDialog(context, "Error", "Those pins didn’t match. Try again.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
} catch (e) {
|
||||||
|
showMsgDialog(context, "Error", e.toString());
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
149
lib/pages/staff/staff_privilege_editor.dart
Normal file
149
lib/pages/staff/staff_privilege_editor.dart
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
import 'package:fcs/domain/entities/user.dart';
|
||||||
|
import 'package:fcs/domain/vo/privilege.dart';
|
||||||
|
import 'package:fcs/helpers/theme.dart';
|
||||||
|
import 'package:fcs/pages/staff/model/staff_model.dart';
|
||||||
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
||||||
|
import 'package:fcs/pages/widgets/progress.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import '../main/util.dart';
|
||||||
|
import '../widgets/local_text.dart';
|
||||||
|
|
||||||
|
class StaffPrivilegeEditor extends StatefulWidget {
|
||||||
|
final User staff;
|
||||||
|
const StaffPrivilegeEditor({required this.staff});
|
||||||
|
@override
|
||||||
|
_StaffPrivilegeEditorState createState() => _StaffPrivilegeEditorState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StaffPrivilegeEditorState extends State<StaffPrivilegeEditor> {
|
||||||
|
bool _isLoading = false;
|
||||||
|
late User _staff;
|
||||||
|
List<Privilege> _privileges = [];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_staff = widget.staff;
|
||||||
|
_privileges = Provider.of<StaffModel>(context, listen: false).privileges;
|
||||||
|
_privileges.forEach((p) => _staff.privileges.contains(p.id)
|
||||||
|
? p.isChecked = true
|
||||||
|
: p.isChecked = false);
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> showprivilegeList(BuildContext context) {
|
||||||
|
return _privileges.map((p) {
|
||||||
|
return new ListTile(
|
||||||
|
title: InkWell(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
p.isChecked = p.isChecked == null ? true : !p.isChecked!;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: new Row(
|
||||||
|
children: <Widget>[
|
||||||
|
new Checkbox(
|
||||||
|
value: p.isChecked == null ? false : p.isChecked,
|
||||||
|
activeColor: primaryColor,
|
||||||
|
side: BorderSide(color: Colors.black38, width: 2),
|
||||||
|
onChanged: (bool? value) {
|
||||||
|
if (value != null)
|
||||||
|
setState(() {
|
||||||
|
p.isChecked = value;
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 8.0),
|
||||||
|
child: Icon(p.iconData, size: 30, color: Colors.black38),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
new Text(
|
||||||
|
p.name ?? "",
|
||||||
|
style: TextStyle(fontSize: 15.0, color: Colors.black),
|
||||||
|
),
|
||||||
|
Text(p.desc ?? "",
|
||||||
|
style: TextStyle(fontSize: 13, color: labelColor))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final saveButton = Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 30),
|
||||||
|
child: fcsButton(
|
||||||
|
context,
|
||||||
|
getLocalString(context, 'btn.save'),
|
||||||
|
callack: _save,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return LocalProgress(
|
||||||
|
inAsyncCall: _isLoading,
|
||||||
|
child: Scaffold(
|
||||||
|
appBar: LocalAppBar(
|
||||||
|
labelKey: "staff.privilege.title",
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
labelColor: primaryColor,
|
||||||
|
arrowColor: primaryColor),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 12.0, right: 12),
|
||||||
|
child: ListView(
|
||||||
|
children: <Widget>[
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
Text(_staff.name ?? "",
|
||||||
|
style: TextStyle(color: Colors.black, fontSize: 18)),
|
||||||
|
Text(_staff.fcsID ?? "",
|
||||||
|
style: TextStyle(color: Colors.black, fontSize: 15)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
LocalText(context, 'staff.privilege.title',
|
||||||
|
color: Colors.black54, fontSize: 15),
|
||||||
|
Column(
|
||||||
|
children: showprivilegeList(context),
|
||||||
|
),
|
||||||
|
saveButton,
|
||||||
|
SizedBox(height: 20)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> privilegesIDs() {
|
||||||
|
return this
|
||||||
|
._privileges
|
||||||
|
.where((p) => p.isChecked!)
|
||||||
|
.map((p) => p.id)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
_save() async {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
StaffModel staffModel = Provider.of<StaffModel>(context, listen: false);
|
||||||
|
try {
|
||||||
|
await staffModel.updatePrivileges(widget.staff.id!, privilegesIDs());
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
} catch (e) {
|
||||||
|
showMsgDialog(context, "Error", e.toString());
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user