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.create":"Create new shipment",
"FCSshipment.update":"Update shipment", "FCSshipment.update":"Update shipment",
"FCSshipment.ship.btn":"Ship this shipment", "FCSshipment.ship.btn":"Ship this shipment",
"FCSshipment.process.btn":"Processed this shipment", "FCSshipment.process.btn":"Process this shipment",
"FCSshipment.arrive.btn":"Arrived this shipment", "FCSshipment.arrive.btn":"Arrive this shipment",
"FCSshipment.invoiced.btn":"Invoiced this shipment", "FCSshipment.invoiced.btn":"Invoice this shipment",
"FCSshipment.ship.confirm":"Confirm ship?", "FCSshipment.ship.confirm":"Confirm ship?",
"FCSshipment.cancel.btn":"Cancel this shipment", "FCSshipment.cancel.btn":"Cancel this shipment",
"FCSshipment.cancel.confirm":"Cancel this shipment?", "FCSshipment.cancel.confirm":"Cancel this shipment?",

View File

@@ -21,14 +21,34 @@ class FcsShipmentDataProvider {
payload: fcsShipment.toMap(), token: await getToken()); 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 { Future<String> reportFcsShipment(FcsShipment fcsShipment) async {
dynamic data = await requestAPI("/fcs_shipments/report", "POST", dynamic data = await requestAPI("/fcs_shipments/report", "POST",
payload: fcsShipment.toMap(), token: await getToken()); payload: fcsShipment.toMap(), token: await getToken());
return data["url"]; 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); return shipmentDataProvider.deleteFcsShipment(fcsShipment);
} }
@override
Future<void> ship(FcsShipment fcsShipment) {
return shipmentDataProvider.ship(fcsShipment);
}
@override @override
Future<String> report(FcsShipment fcsShipment) { Future<String> report(FcsShipment fcsShipment) {
return shipmentDataProvider.reportFcsShipment(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> createFcsShipment(FcsShipment fcsShipment);
Future<void> updateFcsShipment(FcsShipment fcsShipment); Future<void> updateFcsShipment(FcsShipment fcsShipment);
Future<void> deleteFcsShipment(FcsShipment fcsShipment); Future<void> deleteFcsShipment(FcsShipment fcsShipment);
Future<void> ship(FcsShipment fcsShipment);
Future<String> report(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; return null;
}, },
), ),
const SizedBox(height: 20),
DropdownButtonFormField( DropdownButtonFormField(
value: value:
_currentShipmentType == "" ? null : _currentShipmentType, _currentShipmentType == "" ? null : _currentShipmentType,
decoration: InputDecoration( decoration: InputDecoration(
contentPadding: EdgeInsets.zero,
enabledBorder: UnderlineInputBorder( enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor)), borderSide: BorderSide(color: primaryColor)),
focusedBorder: UnderlineInputBorder( focusedBorder: UnderlineInputBorder(
@@ -175,6 +177,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
}) })
}, },
), ),
const SizedBox(height: 5),
InputText( InputText(
labelTextKey: 'FCSshipment.consignee', labelTextKey: 'FCSshipment.consignee',
iconData: Icons.work, iconData: Icons.work,

View File

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

View File

@@ -147,8 +147,20 @@ class FcsShipmentModel extends BaseModel {
return Services.instance.fcsShipmentService.updateFcsShipment(fcsShipment); return Services.instance.fcsShipmentService.updateFcsShipment(fcsShipment);
} }
Future<void> ship(FcsShipment fcsShipment) { Future<void> process(String id) {
return Services.instance.fcsShipmentService.ship(fcsShipment); 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) { Future<String> report(FcsShipment fcsShipment) {

View File

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

View File

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