products filtering fix

merge-update-with-lab-changes
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_CATEGORIES = '/api/categories';
const PACKAGES_PRODUCTS = '/api/products'; const PACKAGES_PRODUCTS = '/api/products';
//const BASE_URL = 'https://uat.hmgwebservices.com/'; const BASE_URL = 'https://uat.hmgwebservices.com/';
const BASE_URL = 'https://hmgwebservices.com/'; //const BASE_URL = 'https://.hmgwebservices.com/';
//const BASE_PHARMACY_URL = 'http://swd-pharapp-01:7200/api/'; //const BASE_PHARMACY_URL = 'http://swd-pharapp-01:7200/api/';
const BASE_PHARMACY_URL = 'https://uat.hmgwebservices.com/epharmacy/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 SCAN_QR_CODE = 'productbysku/';
const FILTERED_PRODUCTS = 'products?categoryids=';
class AppGlobal { class AppGlobal {
static var context; static var context;

@ -27,8 +27,8 @@ class PharmacyCategoriseService extends BaseService {
List<PharmacyProduct> get parentProductsList => _parentProductsList; List<PharmacyProduct> get parentProductsList => _parentProductsList;
//service four //service four
List<SubCategoriesModel> _subCategoriseList = List(); List<CategoriseParentModel> _subCategoriseList = List();
List<SubCategoriesModel> get subCategoriseList => _subCategoriseList; List<CategoriseParentModel> get subCategoriseList => _subCategoriseList;
//service five //service five
List<PharmacyProduct> _subProductsList = List(); List<PharmacyProduct> _subProductsList = List();
@ -40,8 +40,8 @@ class PharmacyCategoriseService extends BaseService {
//service 7 //service 7
List<BrandsModel> _brandsList = List(); List<CategoriseParentModel> _brandsList = List();
List<BrandsModel> get brandsList => _brandsList; List<CategoriseParentModel> get brandsList => _brandsList;
// service 8 // service 8
@ -116,10 +116,10 @@ class PharmacyCategoriseService extends BaseService {
hasError = false; hasError = false;
_brandsList.clear(); _brandsList.clear();
await baseAppClient.getPharmacy( await baseAppClient.getPharmacy(
GET_BRANDS_LIST, GET_BRANDS_LIST + "$id" + "&fields=id,name,image,namen",
onSuccess: (dynamic response, int statusCode) { onSuccess: (dynamic response, int statusCode) {
response['manufacturer'].forEach((item) { response['manufacturer'].forEach((item) {
_brandsList.add(BrandsModel.fromJson(item)); _brandsList.add(CategoriseParentModel.fromJson(item));
}); });
}, },
onFailure: (String error, int statusCode) { onFailure: (String error, int statusCode) {
@ -178,7 +178,7 @@ class PharmacyCategoriseService extends BaseService {
endPoint, endPoint,
onSuccess: (dynamic response, int statusCode) { onSuccess: (dynamic response, int statusCode) {
response['categories'].forEach((item) { response['categories'].forEach((item) {
_subCategoriseList.add(SubCategoriesModel.fromJson(item)); _subCategoriseList.add(CategoriseParentModel.fromJson(item));
}); });
}, },
onFailure: (String error, int statusCode) { onFailure: (String error, int statusCode) {
@ -291,4 +291,29 @@ class PharmacyCategoriseService extends BaseService {
throw error; 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 => List<PharmacyProduct> get parentProducts =>
_pharmacyCategoriseService.parentProductsList; _pharmacyCategoriseService.parentProductsList;
List<SubCategoriesModel> get subCategorise => List<CategoriseParentModel> get subCategorise =>
_pharmacyCategoriseService.subCategoriseList; _pharmacyCategoriseService.subCategoriseList;
List<PharmacyProduct> get subProducts => List<PharmacyProduct> get subProducts =>
@ -37,7 +37,8 @@ class PharmacyCategoriseViewModel extends BaseViewModel {
List<PharmacyProduct> get finalProducts => List<PharmacyProduct> get finalProducts =>
_pharmacyCategoriseService.finalProducts; _pharmacyCategoriseService.finalProducts;
List<BrandsModel> get brandsList => _pharmacyCategoriseService.brandsList; List<CategoriseParentModel> get brandsList =>
_pharmacyCategoriseService.brandsList;
List<PharmacyProduct> get searchList => _pharmacyCategoriseService.searchList; List<PharmacyProduct> get searchList => _pharmacyCategoriseService.searchList;
@ -156,6 +157,20 @@ class PharmacyCategoriseViewModel extends BaseViewModel {
setState(ViewState.Idle); 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 { Future getManufacturerProducts(String id) async {
setState(ViewState.Busy); setState(ViewState.Busy);
await _pharmacyCategoriseService.getManufacturerProducts(id); 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/entity_checkbox_list.dart';
import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart'; import 'package:diplomaticquarterapp/widgets/others/network_base_view.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -44,9 +45,14 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
color: Colors.blue, color: Colors.blue,
size: 29.0, size: 29.0,
); );
List<CategoriseParentModel> entityList = List(); List<CategoriseParentModel> entityList = List();
List<CategoriseParentModel> entityListBrands = List();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
TextEditingController minField = TextEditingController();
TextEditingController maxField = TextEditingController();
ProjectViewModel projectViewModel = Provider.of(context); ProjectViewModel projectViewModel = Provider.of(context);
return BaseView<PharmacyCategoriseViewModel>( return BaseView<PharmacyCategoriseViewModel>(
onModelReady: (model) => model.getCategoriseParent(i: id), onModelReady: (model) => model.getCategoriseParent(i: id),
@ -401,45 +407,35 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
ExpansionTile( ExpansionTile(
title: Texts('Brands'), title: Texts('Brands'),
children: [ children: [
Container( ProcedureListWidget(
height: 350, model: model,
child: ListView masterList: model
.builder( .brandsList,
scrollDirection: removeHistory:
Axis (item) {
.vertical, setState(() {
shrinkWrap: entityListBrands
true, .remove(
itemCount: model item);
.brandsList });
.length, },
itemBuilder: addHistory:
(BuildContext (history) {
context, setState(() {
int index) { entityListBrands
return CheckboxListTile( .add(
tristate: history);
true, });
title: Texts(model },
.brandsList[index] addSelectedHistories:
.name), () {
controlAffinity: //TODO build your fun herr
ListTileControlAffinity.leading, // widget.addSelectedHistories();
value: },
checkedBrands, isEntityListSelected:
onChanged: (master) =>
(bool isEntityListSelectedBrands(
value) { master),
setState(
() {
checkedBrands =
value;
});
},
autofocus:
true,
);
}),
) )
], ],
), ),
@ -479,6 +475,8 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
border: border:
OutlineInputBorder(), OutlineInputBorder(),
), ),
controller:
minField,
), ),
), ),
], ],
@ -504,6 +502,8 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
border: border:
OutlineInputBorder(), OutlineInputBorder(),
), ),
controller:
maxField,
), ),
), ),
], ],
@ -546,6 +546,50 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
Container( Container(
width: 200, width: 200,
child: Button( 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', label: 'Apply',
backgroundColor: backgroundColor:
Colors Colors
@ -1088,4 +1132,13 @@ class _ParentCategorisePageState extends State<ParentCategorisePage> {
} }
return false; 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( child: Padding(
padding: EdgeInsets.all(4.0), padding: EdgeInsets.all(4.0),
child: InkWell( child: InkWell(
onTap: () {}, onTap: () {
Navigator.push(
context,
FadePage(
page: FinalProductsPage(
id: "",
productType: 4,
),
),
);
},
child: Container( child: Container(
height: 50.0, height: 50.0,
width: 55.0, width: 55.0,
@ -181,7 +191,15 @@ class _PharmacyCategorisePageState extends State<PharmacyCategorisePage> {
padding: EdgeInsets.all(4.0), padding: EdgeInsets.all(4.0),
child: InkWell( child: InkWell(
onTap: () { onTap: () {
// _scanQrAndGetPatient(context, model); Navigator.push(
context,
FadePage(
page: FinalProductsPage(
id: "",
productType: 3,
),
),
);
}, },
child: Container( child: Container(
height: 50.0, 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/core/viewModels/pharmacy_categorise_view_model.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/product_detail.dart'; import 'package:diplomaticquarterapp/pages/pharmacies/product_detail.dart';
import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; import 'package:diplomaticquarterapp/widgets/buttons/button.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/StarRating.dart'; import 'package:diplomaticquarterapp/widgets/others/StarRating.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_pharmacy_widget.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/others/network_base_view.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -40,9 +42,12 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
color: Colors.blue, color: Colors.blue,
size: 29.0, size: 29.0,
); );
List<CategoriseParentModel> entityList = List();
List<CategoriseParentModel> entityListBrands = List();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
TextEditingController minField = TextEditingController();
TextEditingController maxField = TextEditingController();
return BaseView<PharmacyCategoriseViewModel>( return BaseView<PharmacyCategoriseViewModel>(
onModelReady: (model) => model.getSubCategorise(i: id), onModelReady: (model) => model.getSubCategorise(i: id),
builder: (BuildContext context, PharmacyCategoriseViewModel model, builder: (BuildContext context, PharmacyCategoriseViewModel model,
@ -281,6 +286,7 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
return SingleChildScrollView( return SingleChildScrollView(
controller: scrollController, controller: scrollController,
child: Container( child: Container(
color: Colors.white,
height: MediaQuery.of(context) height: MediaQuery.of(context)
.size .size
.height * .height *
@ -332,45 +338,34 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
title: title:
Texts('Categorise'), Texts('Categorise'),
children: [ children: [
Container( ProcedureListWidget(
height: 350, model: model,
child: ListView masterList: model
.builder( .subCategorise,
controller: removeHistory:
scrollController, (item) {
scrollDirection: setState(() {
Axis entityList
.vertical, .remove(
shrinkWrap: item);
true, });
itemCount: model },
.categoriseParent addHistory:
.length, (history) {
itemBuilder: setState(() {
(BuildContext entityList.add(
context, history);
int index) { });
return CheckboxListTile( },
tristate: addSelectedHistories:
true, () {
title: Texts(model //TODO build your fun herr
.categoriseParent[index] // widget.addSelectedHistories();
.name), },
controlAffinity: isEntityListSelected:
ListTileControlAffinity.leading, (master) =>
value: isEntityListSelected(
checkedCategorise, master),
onChanged:
(bool
value) {
setState(
() {
checkedCategorise =
value;
});
},
);
}),
) )
], ],
), ),
@ -381,45 +376,35 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
ExpansionTile( ExpansionTile(
title: Texts('Brands'), title: Texts('Brands'),
children: [ children: [
Container( ProcedureListWidget(
height: 350, model: model,
child: ListView masterList: model
.builder( .brandsList,
scrollDirection: removeHistory:
Axis (item) {
.vertical, setState(() {
shrinkWrap: entityListBrands
true, .remove(
itemCount: model item);
.brandsList });
.length, },
itemBuilder: addHistory:
(BuildContext (history) {
context, setState(() {
int index) { entityListBrands
return CheckboxListTile( .add(
tristate: history);
true, });
title: Texts(model },
.brandsList[index] addSelectedHistories:
.name), () {
controlAffinity: //TODO build your fun herr
ListTileControlAffinity.leading, // widget.addSelectedHistories();
value: },
checkedBrands, isEntityListSelected:
onChanged: (master) =>
(bool isEntityListSelectedBrands(
value) { master),
setState(
() {
checkedBrands =
value;
});
},
autofocus:
true,
);
}),
) )
], ],
), ),
@ -459,6 +444,8 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
border: border:
OutlineInputBorder(), OutlineInputBorder(),
), ),
controller:
minField,
), ),
), ),
], ],
@ -484,6 +471,8 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
border: border:
OutlineInputBorder(), OutlineInputBorder(),
), ),
controller:
maxField,
), ),
), ),
], ],
@ -526,6 +515,50 @@ class _SubCategorisePageState extends State<SubCategorisePage> {
Container( Container(
width: 200, width: 200,
child: Button( 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', label: 'Apply',
backgroundColor: backgroundColor:
Colors 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