Untitled

 avatar
unknown
dart
3 years ago
7.1 kB
1
Indexable
import 'package:iketfaa_delivery/App/Delivery/Models/Main/OrderAddress.dart';
import 'package:iketfaa_delivery/App/Delivery/Models/Main/OrderCanceled.dart';
import 'package:iketfaa_delivery/App/Delivery/Models/Main/StoreBill.dart';

class ActiveOrder {
  String? orderID, offerID;
  int? paymentType, orderType, orderStatus;
  String? customerName, customerID, customerMobileNumber, driverID, reason;
  OrderAddress? customerAddress;
  OrderCanceled? orderCanceled;
  double? firstEstimatePrice, secondEstimatePrice, rate, totalPrice;
  List<StoreOrder>? orders;
  bool? arrived, moneyReceived, userConfirmed;
  DateTime? date;

  ActiveOrder({
    this.customerID,
    this.customerName,
    this.orderStatus,
    this.customerMobileNumber,
    this.customerAddress,
    this.orders,
    this.orderType,
    this.orderID,
    this.offerID,
    this.paymentType,
    this.firstEstimatePrice,
    this.secondEstimatePrice,
    this.rate,
    this.totalPrice,
    this.arrived,
    this.moneyReceived,
    this.orderCanceled,
    this.userConfirmed,
    this.driverID,
    this.reason,
    this.date,
  });

  ActiveOrder.fromJson(Map<String, dynamic> json) {
    orderType = json['orderType'];
    orderID = json['orderID'];
    offerID = json['offerID'];
    customerID = json['customerID'];
    customerName = json['customerName'];
    orderStatus = json['orderStatus'];
    customerMobileNumber = json['customerMobileNumber'];
    customerAddress = json['customerAddress'] != null
        ? OrderAddress.fromMap(json['customerAddress'])
        : null;
    paymentType = json['paymentType'];
    if (json['orders'] != null) {
      orders = <StoreOrder>[];
      json['orders'].forEach((v) {
        orders!.add(new StoreOrder.fromJson(v));
      });
    }
    firstEstimatePrice = json['firstEstimatePrice'];
    secondEstimatePrice = json['secondEstimatePrice'];
    rate = json['rate'] == null ? null : json['rate'].toDouble();
    totalPrice = json['totalPrice'].toDouble();
    arrived = json['arrived'];
    moneyReceived = json['moneyReceived'];
    orderCanceled = json['orderCanceled'] == null
        ? null
        : OrderCanceled.fromJson(json['orderCanceled']);
    userConfirmed = json['userConfirmed'];
    driverID = json['driverID'];
    reason = json['reason'];
    date = json['date'].toString().contains(':')
        ? json['date']
        : json['date'].toDate();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['orderType'] = this.orderType;
    data['orderID'] = this.orderID;
    data['offerID'] = this.offerID;
    data['customerID'] = this.customerID;
    data['customerName'] = this.customerName;
    data['orderStatus'] = this.orderStatus;
    data['customerMobileNumber'] = this.customerMobileNumber;
    data['customerAddress'] = this.customerAddress!.toMap();
    data['paymentType'] = this.paymentType;
    if (this.orders!.isNotEmpty) {
      data['orders'] = this.orders!.map((v) => v.toJson()).toList();
    }
    data['firstEstimatePrice'] = this.firstEstimatePrice;
    data['secondEstimatePrice'] = this.secondEstimatePrice;
    data['rate'] = this.rate;
    data['totalPrice'] = this.totalPrice;
    data['arrived'] = this.arrived;
    data['moneyReceived'] = this.moneyReceived;
    data['orderCanceled'] = this.orderCanceled;
    data['userConfirmed'] = this.userConfirmed;
    data['driverID'] = this.driverID;
    data['reason'] = this.reason;
    data['date'] = this.date;
    return data;
  }
}

class StoreOrder {
  String? storeID;
  String? storeName;
  String? storeCategory;
  String? storeImageRef;
  String? reason;
  double? rating;
  int? storeType;
  StoreLocation? storeLocation;
  List<String>? images;
  StoreBill? storeBill;
  List<OrderItem>? orderItems;
  bool? done;

  StoreOrder(
      {this.storeID,
      this.storeName,
      this.storeCategory,
      this.storeImageRef,
      this.reason,
      this.storeLocation,
      this.images,
      this.storeBill,
      this.orderItems,
      this.storeType,
      this.rating,
      this.done});

  StoreOrder.fromJson(Map<String, dynamic> json) {
    storeID = json['storeID'];
    storeName = json['storeName'];
    storeCategory = json['storeCategory'];
    storeImageRef = json['storeImageRef'];
    storeBill = json['storeBill'] == null
        ? null
        : StoreBill.fromJson(json['storeBill']);
    reason = json['reason'];
    storeLocation = StoreLocation.fromJson(json['storeLocation']);
    images = json['images'] == null ? null : json['images'].cast<String>();
    storeType = json['storeType'];
    rating = json['rating'] == null ? 0.0 : json['rating'].toDouble();
    if (json['orderItems'] != null) {
      orderItems = <OrderItem>[];
      json['orderItems'].forEach((v) {
        orderItems!.add(new OrderItem.fromJson(v));
      });
    }
    done = json['done'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['storeID'] = this.storeID;
    data['storeName'] = this.storeName;
    data['storeCategory'] = this.storeCategory;
    data['storeImageRef'] = this.storeImageRef;
    data['storeLocation'] = this.storeLocation!.toJson();
    data['storeBill'] =
        this.storeBill == null ? null : this.storeBill!.toJson();
    data['reason'] = this.reason;
    data['images'] = this.images;
    data['storeType'] = this.storeType;
    data['rating'] = this.rating;
    if (this.orderItems!.isNotEmpty) {
      data['orderItems'] = this.orderItems!.map((v) => v.toJson()).toList();
    }
    data['done'] = this.done;
    return data;
  }
}

class StoreLocation {
  double? lat;
  double? lng;
  String? street;
  String? city;
  double? distanceFromUser;

  StoreLocation(
      {this.lat, this.lng, this.street, this.city, this.distanceFromUser});

  StoreLocation.fromJson(Map<String, dynamic> json) {
    lat = json['lat'].toDouble();
    lng = json['lng'].toDouble();
    street = json['street'];
    city = json['city'];
    distanceFromUser = json['distanceFromUser'].toDouble();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['lat'] = this.lat;
    data['lng'] = this.lng;
    data['street'] = this.street;
    data['city'] = this.city;
    data['distanceFromUser'] = this.distanceFromUser;
    return data;
  }
}

class OrderImage {
  late String url;

  OrderImage({required this.url});

  OrderImage.fromJson(Map<String, dynamic> json) {
    url = json['url'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['url'] = this.url;
    return data;
  }
}

class OrderItem {
  late String description;
  late int quantity;

  OrderItem({required this.description, required this.quantity});

  OrderItem.fromJson(Map<String, dynamic> json) {
    description = json['description'];
    quantity = json['quantity'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['description'] = this.description;
    data['quantity'] = this.quantity;
    return data;
  }
}
Editor is loading...