Merge branch 'master' of tzw/fcs into master

This commit is contained in:
2024-02-21 22:02:53 +06:30
committed by Gogs
10 changed files with 214 additions and 74 deletions

View File

@@ -392,9 +392,9 @@
"FCSshipment.create":"Create new shipment",
"FCSshipment.update":"Update shipment",
"FCSshipment.ship.btn":"Ship this shipment",
"FCSshipment.process.btn":"Processed this shipment",
"FCSshipment.arrive.btn":"Arrived this shipment",
"FCSshipment.invoiced.btn":"Invoiced this shipment",
"FCSshipment.process.btn":"Process this shipment",
"FCSshipment.arrive.btn":"Arrive this shipment",
"FCSshipment.invoiced.btn":"Invoice this shipment",
"FCSshipment.ship.confirm":"Confirm ship?",
"FCSshipment.cancel.btn":"Cancel this shipment",
"FCSshipment.cancel.confirm":"Cancel this shipment?",

View File

@@ -21,14 +21,34 @@ class FcsShipmentDataProvider {
payload: fcsShipment.toMap(), token: await getToken());
}
Future<void> ship(FcsShipment fcsShipment) async {
return await requestAPI("/fcs_shipments/ship", "PUT",
payload: fcsShipment.toMap(), token: await getToken());
}
Future<String> reportFcsShipment(FcsShipment fcsShipment) async {
dynamic data = await requestAPI("/fcs_shipments/report", "POST",
payload: fcsShipment.toMap(), token: await getToken());
return data["url"];
}
Future<void> processFcsShipment(String id) async {
return await requestAPI("/shipments/process", "PUT",
payload: {"id": id}, token: await getToken());
}
Future<void> cancelFcsShipment(String id) async {
return await requestAPI("/shipments/cancel", "PUT",
payload: {"id": id}, token: await getToken());
}
Future<void> shipFcsShipment(String id) async {
return await requestAPI("/shipments/ship", "PUT",
payload: {"id": id}, token: await getToken());
}
Future<void> arriveFcsShipment(String id) async {
return await requestAPI("/shipments/arrive", "PUT",
payload: {"id": id}, token: await getToken());
}
Future<void> invoiceFcsShipment(String id) async {
return await requestAPI("/shipments/invoice", "PUT",
payload: {"id": id}, token: await getToken());
}
}

View File

@@ -28,13 +28,33 @@ class FcsShipmentServiceImp implements FcsShipmentService {
return shipmentDataProvider.deleteFcsShipment(fcsShipment);
}
@override
Future<void> ship(FcsShipment fcsShipment) {
return shipmentDataProvider.ship(fcsShipment);
}
@override
Future<String> report(FcsShipment fcsShipment) {
return shipmentDataProvider.reportFcsShipment(fcsShipment);
}
@override
Future<void> arriveFcsShipment(String id) {
return shipmentDataProvider.arriveFcsShipment(id);
}
@override
Future<void> cancelFcsShipment(String id) {
return shipmentDataProvider.cancelFcsShipment(id);
}
@override
Future<void> invoiceFcsShipment(String id) {
return shipmentDataProvider.invoiceFcsShipment(id);
}
@override
Future<void> processFcsShipment(String id) {
return shipmentDataProvider.processFcsShipment(id);
}
@override
Future<void> shipFcsShipment(String id) {
return shipmentDataProvider.shipFcsShipment(id);
}
}

View File

@@ -4,6 +4,10 @@ abstract class FcsShipmentService {
Future<void> createFcsShipment(FcsShipment fcsShipment);
Future<void> updateFcsShipment(FcsShipment fcsShipment);
Future<void> deleteFcsShipment(FcsShipment fcsShipment);
Future<void> ship(FcsShipment fcsShipment);
Future<String> report(FcsShipment fcsShipment);
Future<void> processFcsShipment(String id);
Future<void> cancelFcsShipment(String id);
Future<void> shipFcsShipment(String id);
Future<void> arriveFcsShipment(String id);
Future<void> invoiceFcsShipment(String id);
}

View File

@@ -150,10 +150,12 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
return null;
},
),
const SizedBox(height: 20),
DropdownButtonFormField(
value:
_currentShipmentType == "" ? null : _currentShipmentType,
decoration: InputDecoration(
contentPadding: EdgeInsets.zero,
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor)),
focusedBorder: UnderlineInputBorder(
@@ -175,6 +177,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
})
},
),
const SizedBox(height: 5),
InputText(
labelTextKey: 'FCSshipment.consignee',
iconData: Icons.work,

View File

@@ -135,21 +135,21 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
padding: const EdgeInsets.symmetric(horizontal: 30),
child: LocalButton(
textKey: "FCSshipment.process.btn",
callBack: _ship,
callBack: () {},
),
);
final arriveBtn = Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: LocalButton(
textKey: "FCSshipment.arrive.btn",
callBack: _ship,
callBack: () {},
),
);
final invoiceBtn = Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: LocalButton(
textKey: "FCSshipment.invoice.btn",
callBack: _ship,
callBack: () {},
),
);
@@ -226,9 +226,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
_fcsShipment?.status == fcs_shipment_arrived_status
? invoiceBtn
: Container(),
SizedBox(
height: 20,
)
SizedBox(height: 20)
]),
),
),
@@ -296,7 +294,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
try {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
await fcsShipmentModel.ship(_fcsShipment!);
await fcsShipmentModel.ship(_fcsShipment!.id!);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -147,8 +147,20 @@ class FcsShipmentModel extends BaseModel {
return Services.instance.fcsShipmentService.updateFcsShipment(fcsShipment);
}
Future<void> ship(FcsShipment fcsShipment) {
return Services.instance.fcsShipmentService.ship(fcsShipment);
Future<void> process(String id) {
return Services.instance.fcsShipmentService.processFcsShipment(id);
}
Future<void> ship(String id) {
return Services.instance.fcsShipmentService.shipFcsShipment(id);
}
Future<void> arrive(String id) {
return Services.instance.fcsShipmentService.arriveFcsShipment(id);
}
Future<void> invoice(String id) {
return Services.instance.fcsShipmentService.invoiceFcsShipment(id);
}
Future<String> report(FcsShipment fcsShipment) {

View File

@@ -17,23 +17,20 @@ class PinLoginPage extends StatefulWidget {
class _PinLoginPageState extends State<PinLoginPage> {
bool _isLoading = false;
String pin = "";
String prefixText = "FCS-";
//late User _user;
final _formKey = GlobalKey<FormState>();
TextEditingController _fcsIdCtl = new TextEditingController();
@override
void initState() {
//_user=widget.user;
//pin = _user.pinDigit ?? "";
super.initState();
if (mounted) {
setState(() {});
}
}
Widget build(BuildContext context) {
final fcsIdBox = TextFormField(
controller: _fcsIdCtl,
onChanged: (value) {
_fcsIdCtl.value = TextEditingValue(
text: value.toUpperCase(),
selection: _fcsIdCtl.selection,
);
},
autofocus: true,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
@@ -47,10 +44,16 @@ class _PinLoginPageState extends State<PinLoginPage> {
cursorColor: primaryColor,
keyboardType: TextInputType.text,
decoration: new InputDecoration(
prefix: Text(
prefixText,
style: TextStyle(color: Colors.black),
),
contentPadding: EdgeInsets.all(0),
labelStyle: newLabelStyle(color: Colors.black54, fontSize: 17),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
border: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor, width: 1.0)),
disabledBorder: UnderlineInputBorder(
@@ -120,10 +123,6 @@ class _PinLoginPageState extends State<PinLoginPage> {
return LocalProgress(
inAsyncCall: _isLoading,
child: new Scaffold(
// appBar: LocalAppBar(
// backgroundColor: primaryColor,
// ),
body: Form(
key: _formKey,
child: ListView(
@@ -167,18 +166,11 @@ class _PinLoginPageState extends State<PinLoginPage> {
}
_login() async {
if (pin == "" && _formKey.currentState!.validate()) {
showMsgDialog(context, "Error", "Invalid PIN");
return;
}
if (pin.length < 6 && _formKey.currentState!.validate()) {
showMsgDialog(context, "Error", "PIN must be 6 digits");
return;
}
if (!_formKey.currentState!.validate()) {
return;
}
String fcsId = "$prefixText${_fcsIdCtl.text}";
print(fcsId);
setState(() {
_isLoading = true;

View File

@@ -78,6 +78,19 @@ class StaffModel extends BaseModel {
token: await getToken());
}
Future<void> updatePin(
{required String userID,
required bool enablePin,
required int pin}) async {
// await request("/employee/pin", "PUT",
// payload: {
// "id": userID,
// "enable_pin_login": enablePin,
// "new_pin": pin
// },
// token: await getToken());
}
Future<User?> findUser(String phoneNumber) {
return Services.instance.userService.findUser(phoneNumber);
}

View File

@@ -4,9 +4,11 @@ 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 'package:provider/provider.dart';
import '../main/util.dart';
import '../widgets/local_text.dart';
import 'model/staff_model.dart';
class StaffPinEditor extends StatefulWidget {
final User staff;
@@ -22,38 +24,69 @@ class _StaffPinEditorState extends State<StaffPinEditor> {
bool _enablePinLogin = false;
String _newPin = "";
String _confirmPin = "";
FocusNode _newPinFocus = FocusNode();
FocusNode _confirmPinFocus = FocusNode();
TextEditingController _newPinCtl = TextEditingController();
TextEditingController _confirmPinCtl = TextEditingController();
@override
void initState() {
_init();
super.initState();
}
_init() {
_staff = widget.staff;
_enablePinLogin = _staff.enablePinLogin;
_newPin = _staff.pinDigit ?? "";
_confirmPin = _staff.confirmPinDigit ?? "";
super.initState();
_newPinCtl.text = _newPin;
_confirmPinCtl.text = _confirmPin;
_checkFocusNode();
if (mounted) {
setState(() {});
}
}
@override
void dispose() {
_newPinFocus.dispose();
_confirmPinFocus.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final enablePinBox = Row(
children: [
Checkbox(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
visualDensity: const VisualDensity(
final enablePinBox = InkWell(
onTap: () {
setState(() {
_enablePinLogin = !_enablePinLogin;
});
_checkFocusNode();
},
child: 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)
],
),
activeColor: primaryColor,
side: BorderSide(color: Colors.black38, width: 2),
value: _enablePinLogin,
onChanged: (value) {
setState(() {
_enablePinLogin = value ?? false;
});
_checkFocusNode();
},
),
const SizedBox(width: 15),
LocalText(context, 'staff.enable_pin',
fontSize: 15, color: Colors.black)
],
),
);
final newPinBox = Column(
@@ -63,14 +96,17 @@ class _StaffPinEditorState extends State<StaffPinEditor> {
color: Colors.black54, fontSize: 15),
const SizedBox(height: 8),
PinInputTextField(
controller: _newPinCtl,
enabled: _enablePinLogin,
cursor: Cursor(
color: primaryColor, enabled: true, width: 2, height: 23),
pinLength: 6,
decoration: BoxLooseDecoration(
strokeColorBuilder:
PinListenColorBuilder(primaryColor, Colors.grey.shade400)),
strokeColorBuilder: PinListenColorBuilder(
_enablePinLogin ? primaryColor : Colors.grey.shade400,
Colors.grey.shade400)),
textInputAction: TextInputAction.done,
autoFocus: true,
focusNode: _newPinFocus,
onChanged: _newPinChange),
],
);
@@ -82,14 +118,17 @@ class _StaffPinEditorState extends State<StaffPinEditor> {
color: Colors.black54, fontSize: 15),
const SizedBox(height: 8),
PinInputTextField(
controller: _confirmPinCtl,
enabled: _enablePinLogin,
pinLength: 6,
cursor: Cursor(
color: primaryColor, enabled: true, width: 2, height: 23),
decoration: BoxLooseDecoration(
strokeColorBuilder:
PinListenColorBuilder(primaryColor, Colors.grey.shade400)),
strokeColorBuilder: PinListenColorBuilder(
_enablePinLogin ? primaryColor : Colors.grey.shade400,
Colors.grey.shade400)),
textInputAction: TextInputAction.done,
autoFocus: false,
focusNode: _confirmPinFocus,
onChanged: _confirmPinChange),
],
);
@@ -125,9 +164,9 @@ class _StaffPinEditorState extends State<StaffPinEditor> {
style: TextStyle(color: Colors.black, fontSize: 15)),
],
),
const SizedBox(height: 20),
const SizedBox(height: 10),
enablePinBox,
const SizedBox(height: 30),
const SizedBox(height: 20),
FormField(
builder: (FormFieldState<bool> state) {
return Column(
@@ -211,9 +250,44 @@ class _StaffPinEditorState extends State<StaffPinEditor> {
));
}
_checkFocusNode() {
if (_enablePinLogin) {
_onChangeFocusNode();
} else {
_cancelFoucsNode();
}
if (mounted) {
setState(() {});
}
}
_onChangeFocusNode() {
if (this._newPin.length == 6) {
_newPinFocus.unfocus();
Future.delayed(const Duration(milliseconds: 300), () {
_confirmPinFocus.requestFocus();
});
} else {
_confirmPinFocus.unfocus();
Future.delayed(const Duration(milliseconds: 300), () {
_newPinFocus.requestFocus();
});
}
}
_cancelFoucsNode() {
_newPinFocus.unfocus();
Future.delayed(const Duration(milliseconds: 300), () {
_confirmPinFocus.unfocus();
});
}
_newPinChange(pin) {
setState(() {
this._newPin = pin;
if (this._newPin.length == 6) {
_confirmPinFocus.requestFocus();
}
});
}
@@ -231,6 +305,10 @@ class _StaffPinEditorState extends State<StaffPinEditor> {
});
try {
await context.read<StaffModel>().updatePin(
userID: _staff.id!,
enablePin: _enablePinLogin,
pin: int.parse(_confirmPin));
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());