products filtering fix

merge-requests/282/head
hussam al-habibeh 5 years ago
parent b39e88d9c8
commit a534b1415e

@ -12,8 +12,8 @@ const EXA_CART_API_BASE_URL = 'https://mdlaboratories.com/exacartapi';
const PACKAGES_CATEGORIES = '/api/categories';
const PACKAGES_PRODUCTS = '/api/products';
//const BASE_URL = 'https://uat.hmgwebservices.com/';
const BASE_URL = 'https://hmgwebservices.com/';
const BASE_URL = 'https://uat.hmgwebservices.com/';
//const BASE_URL = 'https://.hmgwebservices.com/';
//const BASE_PHARMACY_URL = 'http://swd-pharapp-01:7200/api/';
const BASE_PHARMACY_URL = 'https://uat.hmgwebservices.com/epharmacy/api/';
@ -560,6 +560,8 @@ const GET_SEARCH_PRODUCTS =
const SCAN_QR_CODE = 'productbysku/';
const FILTERED_PRODUCTS = 'products?categoryids=';
class AppGlobal {
static var context;

@ -27,8 +27,8 @@ class PharmacyCategoriseService extends BaseService {
List<PharmacyProduct> get parentProductsList => _parentProductsList;
//service four
List<SubCategoriesModel> _subCategoriseList = List();
List<SubCategoriesModel> get subCategoriseList => _subCategoriseList;
List<CategoriseParentModel> _subCategoriseList = List();
List<CategoriseParentModel> get subCategoriseList => _subCategoriseList;
//service five
List<PharmacyProduct> _subProductsList = List();
@ -40,8 +40,8 @@ class PharmacyCategoriseService extends BaseService {
//service 7
List<BrandsModel> _brandsList = List();
List<BrandsModel> get brandsList => _brandsList;
List<CategoriseParentModel> _brandsList = List();
List<CategoriseParentModel> get brandsList => _brandsList;
// service 8
@ -116,10 +116,10 @@ class PharmacyCategoriseService extends BaseService {
hasError = false;
_brandsList.clear();
await baseAppClient.getPharmacy(
GET_BRANDS_LIST,
GET_BRANDS_LIST + "$id" + "&fields=id,name,image,namen",
onSuccess: (dynamic response, int statusCode) {
response['manufacturer'].forEach((item) {
_brandsList.add(BrandsModel.fromJson(item));
_brandsList.add(CategoriseParentModel.fromJson(item));
});
},
onFailure: (String error, int statusCode) {
@ -178,7 +178,7 @@ class PharmacyCategoriseService extends BaseService {
endPoint,
onSuccess: (dynamic response, int statusCode) {
response['categories'].forEach((item) {
_subCategoriseList.add(SubCategoriesModel.fromJson(item));
_subCategoriseList.add(CategoriseParentModel.fromJson(item));
});
},
onFailure: (String error, int statusCode) {
@ -291,4 +291,29 @@ class PharmacyCategoriseService extends BaseService {
throw error;
}
}
Future getFilteredProducts(
{String categoryId, String brandId, String min, String max}) async {
hasError = false;
String endPoint;
_parentProductsList.clear();
endPoint = FILTERED_PRODUCTS +
"$categoryId" +
"&manufacturerids=$brandId" +
"&price_min=$min" +
"&price_max=$max&page=1&limit=50";
await baseAppClient.getPharmacy(
endPoint,
onSuccess: (dynamic response, int statusCode) {
response['products'].forEach((item) {
_parentProductsList.add(PharmacyProduct.fromJson(item));
});
},
onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
},
);
}
}

@ -29,7 +29,7 @@ class PharmacyCategoriseViewModel extends BaseViewModel {
List<PharmacyProduct> get parentProducts =>
_pharmacyCategoriseService.parentProductsList;
List<SubCategoriesModel> get subCategorise =>
List<CategoriseParentModel> get subCategorise =>
_pharmacyCategoriseService.subCategoriseList;
List<PharmacyProduct> get subProducts =>
@ -37,7 +37,8 @@ class PharmacyCategoriseViewModel extends BaseViewModel {
List<PharmacyProduct> get finalProducts =>
_pharmacyCategoriseService.finalProducts;
List<BrandsModel> get brandsList => _pharmacyCategoriseService.brandsList;
List<CategoriseParentModel> get brandsList =>
_pharmacyCategoriseService.brandsList;
List<PharmacyProduct> get searchList => _pharmacyCategoriseService.searchList;
@ -156,6 +157,20 @@ class PharmacyCategoriseViewModel extends BaseViewModel {
setState(ViewState.Idle);
}
Future getFilteredProducts(
{String categoryId, String brandId, String min, String max}) async {
hasError = false;
// _insuranceCardService.clearInsuranceCard();
setState(ViewState.Busy);
await _pharmacyCategoriseService.getFilteredProducts(
categoryId: categoryId, brandId: brandId, max: max, min: min);
if (_pharmacyCategoriseService.hasError) {
error = _pharmacyCategoriseService.error;
setState(ViewState.ErrorLocal);
} else
setState(ViewState.Idle);
}
Future getManufacturerProducts(String id) async {
setState(ViewState.Busy);
await _pharmacyCategoriseService.getManufacturerProducts(id);

@ -11,6 +11,7 @@ import 'package:diplomaticquarterapp/widgets/others/app_scaffold_pharmacy_widget
import 'package:diplomaticquarterapp/widgets/others/entity_checkbox_list.dart';
import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
@ -44,9 +45,14 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
color: Colors.blue,
size: 29.0,
);
List<CategoriseParentModel> entityList = List();
List<CategoriseParentModel> entityListBrands = List();
@override
Widget build(BuildContext context) {
TextEditingController minField = TextEditingController();
TextEditingController maxField = TextEditingController();
ProjectViewModel projectViewModel = Provider.of(context);
return BaseView<PharmacyCategoriseViewModel>(
onModelReady: (model) => model.getCategoriseParent(i: id),
@ -401,45 +407,35 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
ExpansionTile(
title: Texts('Brands'),
children: [
Container(
height: 350,
child: ListView
.builder(
scrollDirection:
Axis
.vertical,
shrinkWrap:
true,
itemCount: model
.brandsList
.length,
itemBuilder:
(BuildContext
context,
int index) {
return CheckboxListTile(
tristate:
true,
title: Texts(model
.brandsList[index]
.name),
controlAffinity:
ListTileControlAffinity.leading,
value:
checkedBrands,
onChanged:
(bool
value) {
setState(
() {
checkedBrands =
value;
});
},
autofocus:
true,
);
}),
ProcedureListWidget(
model: model,
masterList: model
.brandsList,
removeHistory:
(item) {
setState(() {
entityListBrands
.remove(
item);
});
},
addHistory:
(history) {
setState(() {
entityListBrands
.add(
history);
});
},
addSelectedHistories:
() {
//TODO build your fun herr
// widget.addSelectedHistories();
},
isEntityListSelected:
(master) =>
isEntityListSelectedBrands(
master),
)
],
),
@ -479,6 +475,8 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
border:
OutlineInputBorder(),
),
controller:
minField,
),
),
],
@ -504,6 +502,8 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
border:
OutlineInputBorder(),
),
controller:
maxField,
),
),
],
@ -546,6 +546,50 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
Container(
width: 200,
child: Button(
onTap: () {
String
categoriesId =
"";
for (CategoriseParentModel category
in entityList) {
if (categoriesId ==
"") {
categoriesId =
category
.id;
} else {
categoriesId =
"$categoriesId,${category.id}";
}
}
String
brandIds =
"";
for (CategoriseParentModel brand
in entityListBrands) {
if (brandIds ==
"") {
brandIds =
brand
.id;
} else {
brandIds =
"$brandIds,${brand.id}";
}
}
model.getFilteredProducts(
min: minField
.text
.toString(),
max: maxField
.text
.toString(),
categoryId:
categoriesId,
brandId:
brandIds);
},
label: 'Apply',
backgroundColor:
Colors
@ -1088,4 +1132,13 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
}
return false;
}
bool isEntityListSelectedBrands(CategoriseParentModel masterKey) {
Iterable<CategoriseParentModel> history =
entityListBrands.where((element) => masterKey.id == element.id);
if (history.length > 0) {
return true;
}
return false;
}
}

@ -104,7 +104,17 @@ class _PharmacyCategorisePageState extends State<PharmacyCategorisePage> {
child: Padding(
padding: EdgeInsets.all(4.0),
child: InkWell(
onTap: () {},
onTap: () {
Navigator.push(
context,
FadePage(
page: FinalProductsPage(
id: "",
productType: 4,
),
),
);
},
child: Container(
height: 50.0,
width: 55.0,
@ -181,7 +191,15 @@ class _PharmacyCategorisePageState extends State<PharmacyCategorisePage> {
padding: EdgeInsets.all(4.0),
child: InkWell(
onTap: () {
// _scanQrAndGetPatient(context, model);
Navigator.push(
context,
FadePage(
page: FinalProductsPage(
id: "",
productType: 3,
),
),
);
},
child: Container(
height: 50.0,

@ -1,9 +1,11 @@
import 'package:diplomaticquarterapp/core/model/pharmacy/categorise_parent_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacy_categorise_view_model.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/product_detail.dart';
import 'package:diplomaticquarterapp/widgets/buttons/button.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/StarRating.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_pharmacy_widget.dart';
import 'package:diplomaticquarterapp/widgets/others/entity_checkbox_list.dart';
import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
@ -40,9 +42,12 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
color: Colors.blue,
size: 29.0,
);
List<CategoriseParentModel> entityList = List();
List<CategoriseParentModel> entityListBrands = List();
@override
Widget build(BuildContext context) {
TextEditingController minField = TextEditingController();
TextEditingController maxField = TextEditingController();
return BaseView<PharmacyCategoriseViewModel>(
onModelReady: (model) => model.getSubCategorise(i: id),
builder: (BuildContext context, PharmacyCategoriseViewModel model,
@ -281,6 +286,7 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
return SingleChildScrollView(
controller: scrollController,
child: Container(
color: Colors.white,
height: MediaQuery.of(context)
.size
.height *
@ -332,45 +338,34 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
title:
Texts('Categorise'),
children: [
Container(
height: 350,
child: ListView
.builder(
controller:
scrollController,
scrollDirection:
Axis
.vertical,
shrinkWrap:
true,
itemCount: model
.categoriseParent
.length,
itemBuilder:
(BuildContext
context,
int index) {
return CheckboxListTile(
tristate:
true,
title: Texts(model
.categoriseParent[index]
.name),
controlAffinity:
ListTileControlAffinity.leading,
value:
checkedCategorise,
onChanged:
(bool
value) {
setState(
() {
checkedCategorise =
value;
});
},
);
}),
ProcedureListWidget(
model: model,
masterList: model
.subCategorise,
removeHistory:
(item) {
setState(() {
entityList
.remove(
item);
});
},
addHistory:
(history) {
setState(() {
entityList.add(
history);
});
},
addSelectedHistories:
() {
//TODO build your fun herr
// widget.addSelectedHistories();
},
isEntityListSelected:
(master) =>
isEntityListSelected(
master),
)
],
),
@ -381,45 +376,35 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
ExpansionTile(
title: Texts('Brands'),
children: [
Container(
height: 350,
child: ListView
.builder(
scrollDirection:
Axis
.vertical,
shrinkWrap:
true,
itemCount: model
.brandsList
.length,
itemBuilder:
(BuildContext
context,
int index) {
return CheckboxListTile(
tristate:
true,
title: Texts(model
.brandsList[index]
.name),
controlAffinity:
ListTileControlAffinity.leading,
value:
checkedBrands,
onChanged:
(bool
value) {
setState(
() {
checkedBrands =
value;
});
},
autofocus:
true,
);
}),
ProcedureListWidget(
model: model,
masterList: model
.brandsList,
removeHistory:
(item) {
setState(() {
entityListBrands
.remove(
item);
});
},
addHistory:
(history) {
setState(() {
entityListBrands
.add(
history);
});
},
addSelectedHistories:
() {
//TODO build your fun herr
// widget.addSelectedHistories();
},
isEntityListSelected:
(master) =>
isEntityListSelectedBrands(
master),
)
],
),
@ -459,6 +444,8 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
border:
OutlineInputBorder(),
),
controller:
minField,
),
),
],
@ -484,6 +471,8 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
border:
OutlineInputBorder(),
),
controller:
maxField,
),
),
],
@ -526,6 +515,50 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
Container(
width: 200,
child: Button(
onTap: () {
String
categoriesId =
"";
for (CategoriseParentModel category
in entityList) {
if (categoriesId ==
"") {
categoriesId =
category
.id;
} else {
categoriesId =
"$categoriesId,${category.id}";
}
}
String
brandIds =
"";
for (CategoriseParentModel brand
in entityListBrands) {
if (brandIds ==
"") {
brandIds =
brand
.id;
} else {
brandIds =
"$brandIds,${brand.id}";
}
}
model.getFilteredProducts(
min: minField
.text
.toString(),
max: maxField
.text
.toString(),
categoryId:
categoriesId,
brandId:
brandIds);
},
label: 'Apply',
backgroundColor:
Colors
@ -994,4 +1027,22 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
),
));
}
bool isEntityListSelected(CategoriseParentModel masterKey) {
Iterable<CategoriseParentModel> history =
entityList.where((element) => masterKey.id == element.id);
if (history.length > 0) {
return true;
}
return false;
}
bool isEntityListSelectedBrands(CategoriseParentModel masterKey) {
Iterable<CategoriseParentModel> history =
entityListBrands.where((element) => masterKey.id == element.id);
if (history.length > 0) {
return true;
}
return false;
}
}

Loading…
Cancel
Save