update shipment type

This commit is contained in:
tzw
2024-03-01 17:27:56 +06:30
parent 1acb2057d4
commit 41a1be745e
14 changed files with 112 additions and 52 deletions

View File

@@ -7,17 +7,12 @@ class FcsShipmentDataProvider {
final log = Logger('FcsShipmentDataProvider');
Future<void> createFcsShipment(FcsShipment fcsShipment) async {
return await requestAPI("/fcs_shipments", "POST",
return await requestAPI("/shipments", "POST",
payload: fcsShipment.toMap(), token: await getToken());
}
Future<void> updateFcsShipment(FcsShipment fcsShipment) async {
return await requestAPI("/fcs_shipments", "PUT",
payload: fcsShipment.toMap(), token: await getToken());
}
Future<void> deleteFcsShipment(FcsShipment fcsShipment) async {
return await requestAPI("/fcs_shipments", "DELETE",
return await requestAPI("/shipments", "PUT",
payload: fcsShipment.toMap(), token: await getToken());
}

View File

@@ -23,11 +23,6 @@ class FcsShipmentServiceImp implements FcsShipmentService {
return shipmentDataProvider.updateFcsShipment(fcsShipment);
}
@override
Future<void> deleteFcsShipment(FcsShipment fcsShipment) {
return shipmentDataProvider.deleteFcsShipment(fcsShipment);
}
@override
Future<String> report(FcsShipment fcsShipment) {
return shipmentDataProvider.reportFcsShipment(fcsShipment);

View File

@@ -3,7 +3,6 @@ import 'package:fcs/domain/entities/fcs_shipment.dart';
abstract class FcsShipmentService {
Future<void> createFcsShipment(FcsShipment fcsShipment);
Future<void> updateFcsShipment(FcsShipment fcsShipment);
Future<void> deleteFcsShipment(FcsShipment fcsShipment);
Future<String> report(FcsShipment fcsShipment);
Future<void> processFcsShipment(String id);
Future<void> cancelFcsShipment(String id);

View File

@@ -7,6 +7,7 @@ const invitations_collection = "invitations";
const privilege_collection = "privileges";
const markets_collection = "markets";
const carton_sizes_collection = "carton_sizes";
const shipment_type_collection = "shipment_types";
const packages_collection = "packages";
const messages_collection = "messages";

View File

@@ -6,6 +6,7 @@ class FcsShipment {
String? id;
String? shipmentNumber;
DateTime? cutoffDate;
String? shipmentTypeId;
String? shipType;
DateTime? arrivalDate;
DateTime? departureDate;
@@ -19,6 +20,7 @@ class FcsShipment {
this.id,
this.shipmentNumber,
this.cutoffDate,
this.shipmentTypeId,
this.shipType,
this.status,
this.arrivalDate,
@@ -34,17 +36,14 @@ class FcsShipment {
map['cutoff_date'] == null ? null : (map['cutoff_date'] as Timestamp);
var _arrivalDate =
map['arrival_date'] == null ? null : (map['arrival_date'] as Timestamp);
var _departureDate = map['departure_date'] == null
? null
: (map['departure_date'] as Timestamp);
return FcsShipment(
id: docID,
cutoffDate: _cutoffDate != null ? _cutoffDate.toDate() : null,
arrivalDate: _arrivalDate != null ? _arrivalDate.toDate() : null,
departureDate: _departureDate != null ? _departureDate.toDate() : null,
shipmentNumber: map['shipment_number'],
shipType: map['shipment_type'],
shipmentTypeId: map['shipment_type_id'] ?? "",
status: map['status'],
consignee: map['consignee'],
port: map['port'],
@@ -62,8 +61,8 @@ class FcsShipment {
'consignee': consignee,
'port': port,
'destination': destination,
'status': status,
'report_name': reportName,
// 'status': status,
// 'report_name': reportName,
};
}
@@ -75,7 +74,7 @@ class FcsShipment {
return fcsShipment.shipmentNumber != this.shipmentNumber ||
fcsShipment.cutoffDate != this.cutoffDate ||
fcsShipment.arrivalDate != this.arrivalDate ||
fcsShipment.shipType != this.shipType ||
fcsShipment.shipmentTypeId != this.shipmentTypeId ||
fcsShipment.consignee != this.consignee ||
fcsShipment.port != this.port ||
fcsShipment.destination != this.destination;

View File

@@ -0,0 +1,10 @@
class ShipmentType {
String id;
String desc;
ShipmentType({required this.id, required this.desc});
factory ShipmentType.fromMap(Map<String, dynamic> map, String id) {
return ShipmentType(id: id, desc: map['desc'] ?? "");
}
}

View File

@@ -5,7 +5,7 @@ import 'package:intl/intl.dart';
import '../constants.dart';
DateFormat dayFormat = DateFormat("MMM dd yyyy");
DateFormat timeFormat = DateFormat("HH:mm");
DateFormat timeFormat = DateFormat("hh:mm a");
final DateFormat dateFormat = DateFormat("d MMM yyyy");
class User {

View File

@@ -40,6 +40,8 @@ Future<dynamic> requestAPI(String path, method,
headers: headers,
);
log.info("baseUrl:${options.baseUrl}, path:$path");
log.info("payload:$payload");
try {
Dio dio = new Dio(options);
Response response = await dio.request(

View File

@@ -130,7 +130,7 @@ class _CustomerListState extends State<CustomerList> {
),
customer.status == user_invited_status
? Padding(
padding: const EdgeInsets.only(right: 10.0),
padding: const EdgeInsets.only(right: 10),
child: SizedBox(
height: 30,
child: TextButton(
@@ -182,14 +182,14 @@ class _CustomerListState extends State<CustomerList> {
decoration:
BoxDecoration(shape: BoxShape.circle, color: secondaryColor),
child: Text(customer.getFcsUnseenCount,
style: TextStyle(color: Colors.white)),
style: TextStyle(color: Colors.white, fontSize: 12)),
)
: Container();
}
Widget _status(String status) {
return user_requested_status == status || user_disabled_status == status
? Text(status, style: TextStyle(color: primaryColor, fontSize: 14))
? Text(status, style: TextStyle(color: primaryColor, fontSize: 12))
: Container();
}

View File

@@ -60,11 +60,13 @@ class DiscountListRow extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(discount.status ?? ''),
Text(discount.status ?? '',
style: TextStyle(
color: primaryColor,
fontSize: 15,
fontWeight: FontWeight.bold)),
Padding(
padding: const EdgeInsets.only(
top: 5,
),
padding: const EdgeInsets.only(top: 5),
child: Row(
children: <Widget>[
new Text(

View File

@@ -3,7 +3,6 @@ import 'package:fcs/helpers/theme.dart';
import 'package:fcs/localization/app_translations.dart';
import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart';
import 'package:fcs/pages/main/model/language_model.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/widgets/input_date.dart';
import 'package:fcs/pages/widgets/input_text.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
@@ -15,6 +14,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import '../../domain/entities/shipment_type.dart';
import '../main/util.dart';
class FcsShipmentEditor extends StatefulWidget {
@@ -39,13 +39,14 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
FcsShipment _shipment = new FcsShipment();
bool _isLoading = false;
String? _currentShipmentType;
ShipmentType? _currentShipmentType;
bool _isNew = false;
@override
void initState() {
super.initState();
_isNew = widget.shipment == null;
var model = Provider.of<FcsShipmentModel>(context, listen: false);
if (widget.shipment != null) {
_shipment = widget.shipment!;
_shipmentNumberController.text = _shipment.shipmentNumber ?? "";
@@ -59,13 +60,13 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
_departureDateControler.text =
dateFormatter.format(_shipment.departureDate!);
_statusController.text = _shipment.status ?? "";
_currentShipmentType = _shipment.shipType;
_consigneeController.text = _shipment.consignee ?? "";
_portController.text = _shipment.port ?? "";
_destinationController.text = _shipment.destination ?? "";
// _currentShipmentType = model.shipmentTypes.where((e) => e.id == _shipment.shipmentTypeId).first;
} else {
var mainModel = Provider.of<MainModel>(context, listen: false);
_currentShipmentType = mainModel.setting!.shipmentTypes[0];
_currentShipmentType = model.shipmentTypes[0];
}
}
@@ -77,7 +78,8 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
@override
Widget build(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
var mainModel = Provider.of<MainModel>(context);
List<ShipmentType> shipmentTypes =
context.watch<FcsShipmentModel>().shipmentTypes;
final createBtn = Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
@@ -171,10 +173,11 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
labelText: AppTranslations.of(context)!
.text('FCSshipment.shipment_type'),
icon: Icon(Ionicons.ios_airplane, color: primaryColor)),
items: mainModel.setting!.shipmentTypes
.map((e) => DropdownMenuItem(child: Text(e), value: e))
items: shipmentTypes
.map((e) =>
DropdownMenuItem(child: Text(e.desc), value: e))
.toList(),
onChanged: (String? selected) => {
onChanged: (selected) => {
setState(() {
_currentShipmentType = selected;
})
@@ -206,7 +209,7 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
FcsShipment fcsShipment = FcsShipment();
fcsShipment.id = _shipment.id;
fcsShipment.shipmentNumber = _shipmentNumberController.text;
fcsShipment.shipType = _currentShipmentType!;
fcsShipment.shipmentTypeId = _currentShipmentType?.id;
fcsShipment.consignee = _consigneeController.text;
fcsShipment.port = _portController.text;
fcsShipment.destination = _destinationController.text;
@@ -262,14 +265,14 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
isDataChanged() {
if (_isNew) {
var mainModel = Provider.of<MainModel>(context, listen: false);
var shipmentModel = Provider.of<FcsShipmentModel>(context, listen: false);
return _shipmentNumberController.text != "" ||
_cutoffDateController.text != "" ||
_arrivalDateController.text != "" ||
_consigneeController.text != "" ||
_portController.text != "" ||
_destinationController.text != "" ||
_currentShipmentType != mainModel.setting!.shipmentTypes[0];
_currentShipmentType != shipmentModel.shipmentTypes[0];
} else {
FcsShipment fcsShipment = _getPayload();
return widget.shipment!.isChangedForEdit(fcsShipment);

View File

@@ -159,7 +159,9 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
color: dangerColor,
textKey: "FCSshipment.cancel.btn",
callBack: () {
showConfirmDialog(context, "FCSshipment.cancel.confirm", () {});
showConfirmDialog(context, "FCSshipment.cancel.confirm", () {
_cancelFcsShipment();
});
},
),
);
@@ -174,10 +176,12 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
labelColor: primaryColor,
arrowColor: primaryColor,
actions: [
IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: _edit,
),
_fcsShipment?.status == fcs_shipment_pending_status
? IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: _edit,
)
: const SizedBox(),
//menuPopWidget(context)
],
),
@@ -377,6 +381,24 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
}
}
_cancelFcsShipment() async {
setState(() {
_isLoading = true;
});
try {
FcsShipmentModel fcsShipmentModel =
Provider.of<FcsShipmentModel>(context, listen: false);
await fcsShipmentModel.cancel(_fcsShipment!.id!);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
_showPDF(int id) async {
setState(() {
_isLoading = true;

View File

@@ -7,6 +7,7 @@ import 'package:fcs/domain/entities/fcs_shipment.dart';
import 'package:fcs/pages/main/model/base_model.dart';
import 'package:logging/logging.dart';
import '../../../domain/entities/shipment_type.dart';
import '../../../pagination/paginator_listener.dart';
class FcsShipmentModel extends BaseModel {
@@ -15,6 +16,9 @@ class FcsShipmentModel extends BaseModel {
bool isLoading = false;
int selectedIndex = 0;
List<ShipmentType> shipmentTypes = [];
StreamSubscription<QuerySnapshot>? _shipmentTypeListener;
onChanged(int index) {
selectedIndex = index;
loadFcsShipments(selectedIndex);
@@ -132,11 +136,35 @@ class FcsShipmentModel extends BaseModel {
void initUser(user) {
super.initUser(user);
_loadShipmentTypes();
}
@override
logout() async {
fcsShipments?.close();
_shipmentTypeListener?.cancel();
shipmentTypes.clear();
}
Future<void> _loadShipmentTypes() async {
try {
_shipmentTypeListener = FirebaseFirestore.instance
.collection(
"/$config_collection/$setting_doc_id/$shipment_type_collection")
.snapshots()
.listen((QuerySnapshot snapshot) {
shipmentTypes.clear();
shipmentTypes = snapshot.docs.map((documentSnapshot) {
var privilege = ShipmentType.fromMap(
documentSnapshot.data() as Map<String, dynamic>,
documentSnapshot.id);
return privilege;
}).toList();
notifyListeners();
});
} catch (e) {
log.warning("Error!! $e");
}
}
Future<void> create(FcsShipment fcsShipment) {
@@ -163,6 +191,10 @@ class FcsShipmentModel extends BaseModel {
return Services.instance.fcsShipmentService.invoiceFcsShipment(id);
}
Future<void> cancel(String id) {
return Services.instance.fcsShipmentService.cancelFcsShipment(id);
}
Future<String> report(FcsShipment fcsShipment) {
return Services.instance.fcsShipmentService.report(fcsShipment);
}

View File

@@ -82,13 +82,13 @@ class StaffModel extends BaseModel {
{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());
await request("/employee/pin", "PUT",
payload: {
"id": userID,
"enable_pin_login": enablePin,
"pin": pin
},
token: await getToken());
}
Future<User?> findUser(String phoneNumber) {