Offers And Discounts Apis
parent
9a93e2ea1a
commit
0b67fb7570
@ -0,0 +1,265 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class OffersAndDiscountsDetailedResponseModel {
|
||||
int id;
|
||||
String ref;
|
||||
String name;
|
||||
String nameAr;
|
||||
Category category;
|
||||
List<Branch> branches;
|
||||
double listPrice;
|
||||
String currency;
|
||||
String imageUrl;
|
||||
DateTime validFrom;
|
||||
DateTime validTo;
|
||||
String description;
|
||||
String descriptionAr;
|
||||
int vatExclusivePrice;
|
||||
double vatInclusivePrice;
|
||||
bool requirePatientRegistration;
|
||||
Images images;
|
||||
List<OfferLine> offerLines;
|
||||
|
||||
OffersAndDiscountsDetailedResponseModel({
|
||||
required this.id,
|
||||
required this.ref,
|
||||
required this.name,
|
||||
required this.nameAr,
|
||||
required this.category,
|
||||
required this.branches,
|
||||
required this.listPrice,
|
||||
required this.currency,
|
||||
required this.imageUrl,
|
||||
required this.validFrom,
|
||||
required this.validTo,
|
||||
required this.description,
|
||||
required this.descriptionAr,
|
||||
required this.vatExclusivePrice,
|
||||
required this.vatInclusivePrice,
|
||||
required this.requirePatientRegistration,
|
||||
required this.images,
|
||||
required this.offerLines,
|
||||
});
|
||||
|
||||
factory OffersAndDiscountsDetailedResponseModel.fromRawJson(String str) => OffersAndDiscountsDetailedResponseModel.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory OffersAndDiscountsDetailedResponseModel.fromJson(Map<String, dynamic> json) => OffersAndDiscountsDetailedResponseModel(
|
||||
id: json["id"],
|
||||
ref: json["ref"],
|
||||
name: json["name"],
|
||||
nameAr: json["name_ar"],
|
||||
category: Category.fromJson(json["category"]),
|
||||
branches: List<Branch>.from(json["branches"].map((x) => Branch.fromJson(x))),
|
||||
listPrice: json["list_price"]?.toDouble(),
|
||||
currency: json["currency"],
|
||||
imageUrl: json["image_url"],
|
||||
validFrom: DateTime.parse(json["valid_from"]),
|
||||
validTo: DateTime.parse(json["valid_to"]),
|
||||
description: json["description"],
|
||||
descriptionAr: json["description_ar"],
|
||||
vatExclusivePrice: json["vat_exclusive_price"],
|
||||
vatInclusivePrice: json["vat_inclusive_price"]?.toDouble(),
|
||||
requirePatientRegistration: json["require_patient_registration"],
|
||||
images: Images.fromJson(json["images"]),
|
||||
offerLines: List<OfferLine>.from(json["offer_lines"].map((x) => OfferLine.fromJson(x))),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"id": id,
|
||||
"ref": ref,
|
||||
"name": name,
|
||||
"name_ar": nameAr,
|
||||
"category": category.toJson(),
|
||||
"branches": List<dynamic>.from(branches.map((x) => x.toJson())),
|
||||
"list_price": listPrice,
|
||||
"currency": currency,
|
||||
"image_url": imageUrl,
|
||||
"valid_from": "${validFrom.year.toString().padLeft(4, '0')}-${validFrom.month.toString().padLeft(2, '0')}-${validFrom.day.toString().padLeft(2, '0')}",
|
||||
"valid_to": "${validTo.year.toString().padLeft(4, '0')}-${validTo.month.toString().padLeft(2, '0')}-${validTo.day.toString().padLeft(2, '0')}",
|
||||
"description": description,
|
||||
"description_ar": descriptionAr,
|
||||
"vat_exclusive_price": vatExclusivePrice,
|
||||
"vat_inclusive_price": vatInclusivePrice,
|
||||
"require_patient_registration": requirePatientRegistration,
|
||||
"images": images.toJson(),
|
||||
"offer_lines": List<dynamic>.from(offerLines.map((x) => x.toJson())),
|
||||
};
|
||||
}
|
||||
|
||||
class Branch {
|
||||
int id;
|
||||
String code;
|
||||
String name;
|
||||
String nameAr;
|
||||
|
||||
Branch({
|
||||
required this.id,
|
||||
required this.code,
|
||||
required this.name,
|
||||
required this.nameAr,
|
||||
});
|
||||
|
||||
factory Branch.fromRawJson(String str) => Branch.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory Branch.fromJson(Map<String, dynamic> json) => Branch(
|
||||
id: json["id"],
|
||||
code: json["code"],
|
||||
name: json["name"],
|
||||
nameAr: json["name_ar"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"id": id,
|
||||
"code": code,
|
||||
"name": name,
|
||||
"name_ar": nameAr,
|
||||
};
|
||||
}
|
||||
|
||||
class Category {
|
||||
int id;
|
||||
bool code;
|
||||
String name;
|
||||
String nameAr;
|
||||
|
||||
Category({
|
||||
required this.id,
|
||||
required this.code,
|
||||
required this.name,
|
||||
required this.nameAr,
|
||||
});
|
||||
|
||||
factory Category.fromRawJson(String str) => Category.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory Category.fromJson(Map<String, dynamic> json) => Category(
|
||||
id: json["id"],
|
||||
code: json["code"],
|
||||
name: json["name"],
|
||||
nameAr: json["name_ar"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"id": id,
|
||||
"code": code,
|
||||
"name": name,
|
||||
"name_ar": nameAr,
|
||||
};
|
||||
}
|
||||
|
||||
class Images {
|
||||
List<Banner> main;
|
||||
List<Banner> banners;
|
||||
List<Banner> details;
|
||||
|
||||
Images({
|
||||
required this.main,
|
||||
required this.banners,
|
||||
required this.details,
|
||||
});
|
||||
|
||||
factory Images.fromRawJson(String str) => Images.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory Images.fromJson(Map<String, dynamic> json) => Images(
|
||||
main: List<Banner>.from(json["main"].map((x) => Banner.fromJson(x))),
|
||||
banners: List<Banner>.from(json["banners"].map((x) => Banner.fromJson(x))),
|
||||
details: List<Banner>.from(json["details"].map((x) => Banner.fromJson(x))),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"main": List<dynamic>.from(main.map((x) => x.toJson())),
|
||||
"banners": List<dynamic>.from(banners.map((x) => x.toJson())),
|
||||
"details": List<dynamic>.from(details.map((x) => x.toJson())),
|
||||
};
|
||||
}
|
||||
|
||||
class Banner {
|
||||
int id;
|
||||
String url;
|
||||
int sequence;
|
||||
|
||||
Banner({
|
||||
required this.id,
|
||||
required this.url,
|
||||
required this.sequence,
|
||||
});
|
||||
|
||||
factory Banner.fromRawJson(String str) => Banner.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory Banner.fromJson(Map<String, dynamic> json) => Banner(
|
||||
id: json["id"],
|
||||
url: json["url"],
|
||||
sequence: json["sequence"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"id": id,
|
||||
"url": url,
|
||||
"sequence": sequence,
|
||||
};
|
||||
}
|
||||
|
||||
class OfferLine {
|
||||
int sequence;
|
||||
String lineType;
|
||||
String procedureCode;
|
||||
String name;
|
||||
String nameAr;
|
||||
int basePrice;
|
||||
int discountedPrice;
|
||||
String discountType;
|
||||
int discountValue;
|
||||
int quantity;
|
||||
|
||||
OfferLine({
|
||||
required this.sequence,
|
||||
required this.lineType,
|
||||
required this.procedureCode,
|
||||
required this.name,
|
||||
required this.nameAr,
|
||||
required this.basePrice,
|
||||
required this.discountedPrice,
|
||||
required this.discountType,
|
||||
required this.discountValue,
|
||||
required this.quantity,
|
||||
});
|
||||
|
||||
factory OfferLine.fromRawJson(String str) => OfferLine.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory OfferLine.fromJson(Map<String, dynamic> json) => OfferLine(
|
||||
sequence: json["sequence"],
|
||||
lineType: json["line_type"],
|
||||
procedureCode: json["procedure_code"],
|
||||
name: json["name"],
|
||||
nameAr: json["name_ar"],
|
||||
basePrice: json["base_price"],
|
||||
discountedPrice: json["discounted_price"],
|
||||
discountType: json["discount_type"],
|
||||
discountValue: json["discount_value"],
|
||||
quantity: json["quantity"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"sequence": sequence,
|
||||
"line_type": lineType,
|
||||
"procedure_code": procedureCode,
|
||||
"name": name,
|
||||
"name_ar": nameAr,
|
||||
"base_price": basePrice,
|
||||
"discounted_price": discountedPrice,
|
||||
"discount_type": discountType,
|
||||
"discount_value": discountValue,
|
||||
"quantity": quantity,
|
||||
};
|
||||
}
|
||||
@ -1,52 +1,201 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class OffersAndDiscountsResponseModel {
|
||||
int? id;
|
||||
String? title;
|
||||
String? description;
|
||||
String? imageUrl;
|
||||
String? facilityType; // HMC, HMG, or Both
|
||||
String? startDate;
|
||||
String? endDate;
|
||||
String? discount;
|
||||
bool? isActive;
|
||||
List<OfferData> data;
|
||||
Meta meta;
|
||||
|
||||
OffersAndDiscountsResponseModel({
|
||||
this.id,
|
||||
this.title,
|
||||
this.description,
|
||||
this.imageUrl,
|
||||
this.facilityType,
|
||||
this.startDate,
|
||||
this.endDate,
|
||||
this.discount,
|
||||
this.isActive,
|
||||
required this.data,
|
||||
required this.meta,
|
||||
});
|
||||
|
||||
factory OffersAndDiscountsResponseModel.fromJson(Map<String, dynamic> json) {
|
||||
return OffersAndDiscountsResponseModel(
|
||||
id: json['ID'] as int?,
|
||||
title: json['Title'] as String?,
|
||||
description: json['Description'] as String?,
|
||||
imageUrl: json['ImageURL'] as String?,
|
||||
facilityType: json['FacilityType'] as String?,
|
||||
startDate: json['StartDate'] as String?,
|
||||
endDate: json['EndDate'] as String?,
|
||||
discount: json['Discount'] as String?,
|
||||
isActive: json['IsActive'] as bool?,
|
||||
);
|
||||
}
|
||||
factory OffersAndDiscountsResponseModel.fromRawJson(String str) => OffersAndDiscountsResponseModel.fromJson(json.decode(str));
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'ID': id,
|
||||
'Title': title,
|
||||
'Description': description,
|
||||
'ImageURL': imageUrl,
|
||||
'FacilityType': facilityType,
|
||||
'StartDate': startDate,
|
||||
'EndDate': endDate,
|
||||
'Discount': discount,
|
||||
'IsActive': isActive,
|
||||
};
|
||||
}
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory OffersAndDiscountsResponseModel.fromJson(Map<String, dynamic> json) => OffersAndDiscountsResponseModel(
|
||||
data: List<OfferData>.from(json["data"].map((x) => OfferData.fromJson(x))),
|
||||
meta: Meta.fromJson(json["meta"]),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"data": List<dynamic>.from(data.map((x) => x.toJson())),
|
||||
"meta": meta.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
class OfferData {
|
||||
int id;
|
||||
String ref;
|
||||
String name;
|
||||
String nameAr;
|
||||
Category category;
|
||||
List<Branch> branches;
|
||||
double listPrice;
|
||||
Currency currency;
|
||||
String imageUrl;
|
||||
DateTime validFrom;
|
||||
DateTime validTo;
|
||||
|
||||
OfferData({
|
||||
required this.id,
|
||||
required this.ref,
|
||||
required this.name,
|
||||
required this.nameAr,
|
||||
required this.category,
|
||||
required this.branches,
|
||||
required this.listPrice,
|
||||
required this.currency,
|
||||
required this.imageUrl,
|
||||
required this.validFrom,
|
||||
required this.validTo,
|
||||
});
|
||||
|
||||
factory OfferData.fromRawJson(String str) => OfferData.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory OfferData.fromJson(Map<String, dynamic> json) => OfferData(
|
||||
id: json["id"],
|
||||
ref: json["ref"],
|
||||
name: json["name"],
|
||||
nameAr: json["name_ar"],
|
||||
category: Category.fromJson(json["category"]),
|
||||
branches: List<Branch>.from(json["branches"].map((x) => Branch.fromJson(x))),
|
||||
listPrice: json["list_price"]?.toDouble(),
|
||||
currency: currencyValues.map[json["currency"]]!,
|
||||
imageUrl: json["image_url"],
|
||||
validFrom: DateTime.parse(json["valid_from"]),
|
||||
validTo: DateTime.parse(json["valid_to"]),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"id": id,
|
||||
"ref": ref,
|
||||
"name": name,
|
||||
"name_ar": nameAr,
|
||||
"category": category.toJson(),
|
||||
"branches": List<dynamic>.from(branches.map((x) => x.toJson())),
|
||||
"list_price": listPrice,
|
||||
"currency": currencyValues.reverse[currency],
|
||||
"image_url": imageUrl,
|
||||
"valid_from": "${validFrom.year.toString().padLeft(4, '0')}-${validFrom.month.toString().padLeft(2, '0')}-${validFrom.day.toString().padLeft(2, '0')}",
|
||||
"valid_to": "${validTo.year.toString().padLeft(4, '0')}-${validTo.month.toString().padLeft(2, '0')}-${validTo.day.toString().padLeft(2, '0')}",
|
||||
};
|
||||
}
|
||||
|
||||
class Branch {
|
||||
int id;
|
||||
String code;
|
||||
String name;
|
||||
String nameAr;
|
||||
|
||||
Branch({
|
||||
required this.id,
|
||||
required this.code,
|
||||
required this.name,
|
||||
required this.nameAr,
|
||||
});
|
||||
|
||||
factory Branch.fromRawJson(String str) => Branch.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory Branch.fromJson(Map<String, dynamic> json) => Branch(
|
||||
id: json["id"],
|
||||
code: json["code"],
|
||||
name: json["name"],
|
||||
nameAr: json["name_ar"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"id": id,
|
||||
"code": code,
|
||||
"name": name,
|
||||
"name_ar": nameAr,
|
||||
};
|
||||
}
|
||||
|
||||
class Category {
|
||||
int id;
|
||||
bool code;
|
||||
String name;
|
||||
String nameAr;
|
||||
|
||||
Category({
|
||||
required this.id,
|
||||
required this.code,
|
||||
required this.name,
|
||||
required this.nameAr,
|
||||
});
|
||||
|
||||
factory Category.fromRawJson(String str) => Category.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory Category.fromJson(Map<String, dynamic> json) => Category(
|
||||
id: json["id"],
|
||||
code: json["code"],
|
||||
name: json["name"],
|
||||
nameAr: json["name_ar"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"id": id,
|
||||
"code": code,
|
||||
"name": name,
|
||||
"name_ar": nameAr,
|
||||
};
|
||||
}
|
||||
|
||||
enum Currency {
|
||||
SAR
|
||||
}
|
||||
|
||||
final currencyValues = EnumValues({
|
||||
"SAR": Currency.SAR
|
||||
});
|
||||
|
||||
class Meta {
|
||||
int total;
|
||||
int page;
|
||||
int perPage;
|
||||
int pages;
|
||||
|
||||
Meta({
|
||||
required this.total,
|
||||
required this.page,
|
||||
required this.perPage,
|
||||
required this.pages,
|
||||
});
|
||||
|
||||
factory Meta.fromRawJson(String str) => Meta.fromJson(json.decode(str));
|
||||
|
||||
String toRawJson() => json.encode(toJson());
|
||||
|
||||
factory Meta.fromJson(Map<String, dynamic> json) => Meta(
|
||||
total: json["total"],
|
||||
page: json["page"],
|
||||
perPage: json["per_page"],
|
||||
pages: json["pages"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"total": total,
|
||||
"page": page,
|
||||
"per_page": perPage,
|
||||
"pages": pages,
|
||||
};
|
||||
}
|
||||
|
||||
class EnumValues<T> {
|
||||
Map<String, T> map;
|
||||
late Map<T, String> reverseMap;
|
||||
|
||||
EnumValues(this.map);
|
||||
|
||||
Map<T, String> get reverse {
|
||||
reverseMap = map.map((k, v) => MapEntry(v, k));
|
||||
return reverseMap;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue