add discount api
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:fcs/domain/entities/discount.dart';
|
||||||
import 'package:fcs/domain/entities/payment_method.dart';
|
import 'package:fcs/domain/entities/payment_method.dart';
|
||||||
import 'package:fcs/domain/vo/message.dart';
|
import 'package:fcs/domain/vo/message.dart';
|
||||||
import 'package:fcs/helpers/api_helper.dart';
|
import 'package:fcs/helpers/api_helper.dart';
|
||||||
@@ -32,4 +33,19 @@ class CommonDataProvider {
|
|||||||
payload: {"owner_id": ownerID, "seen_by_owner": seenByOwner},
|
payload: {"owner_id": ownerID, "seen_by_owner": seenByOwner},
|
||||||
token: await getToken());
|
token: await getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> createDiscount(Discount discount) async {
|
||||||
|
return await requestAPI("/discounts", "POST",
|
||||||
|
payload: discount.toMap(), token: await getToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> updateDiscount(Discount discount) async {
|
||||||
|
return await requestAPI("/discounts", "PUT",
|
||||||
|
payload: discount.toMap(), token: await getToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> deleteDiscount(String id) async {
|
||||||
|
return await requestAPI("/discounts", "DELETE",
|
||||||
|
payload: {"id": id}, token: await getToken());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:fcs/data/provider/common_data_provider.dart';
|
import 'package:fcs/data/provider/common_data_provider.dart';
|
||||||
import 'package:fcs/data/provider/user_data_provider.dart';
|
import 'package:fcs/domain/entities/discount.dart';
|
||||||
import 'package:fcs/domain/entities/payment_method.dart';
|
import 'package:fcs/domain/entities/payment_method.dart';
|
||||||
import 'package:fcs/domain/vo/message.dart';
|
import 'package:fcs/domain/vo/message.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -37,4 +37,19 @@ class CommonServiceImp implements CommonService {
|
|||||||
Future<void> seenMessage(String ownerID, bool seenByOwner) {
|
Future<void> seenMessage(String ownerID, bool seenByOwner) {
|
||||||
return commonDataProvider.seenMessage(ownerID, seenByOwner);
|
return commonDataProvider.seenMessage(ownerID, seenByOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> createDiscount(Discount discount) {
|
||||||
|
return commonDataProvider.createDiscount(discount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> deleteDiscount(String id) {
|
||||||
|
return commonDataProvider.deleteDiscount(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> updateDiscount(Discount discount) {
|
||||||
|
return commonDataProvider.updateDiscount(discount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:fcs/domain/entities/discount.dart';
|
||||||
import 'package:fcs/domain/entities/payment_method.dart';
|
import 'package:fcs/domain/entities/payment_method.dart';
|
||||||
import 'package:fcs/domain/vo/message.dart';
|
import 'package:fcs/domain/vo/message.dart';
|
||||||
|
|
||||||
@@ -10,4 +11,9 @@ abstract class CommonService {
|
|||||||
// Messaging
|
// Messaging
|
||||||
Future<void> sendMessage(Message message);
|
Future<void> sendMessage(Message message);
|
||||||
Future<void> seenMessage(String ownerID, bool seenByOwner);
|
Future<void> seenMessage(String ownerID, bool seenByOwner);
|
||||||
|
|
||||||
|
// Payment
|
||||||
|
Future<void> createDiscount(Discount discount);
|
||||||
|
Future<void> updateDiscount(Discount discount);
|
||||||
|
Future<void> deleteDiscount(String id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,38 @@
|
|||||||
class Discount {
|
class Discount {
|
||||||
|
String id;
|
||||||
String code;
|
String code;
|
||||||
String customer;
|
String customerId;
|
||||||
|
String customerName;
|
||||||
String status;
|
String status;
|
||||||
double amount;
|
double amount;
|
||||||
int weight;
|
|
||||||
double discountRate;
|
|
||||||
|
|
||||||
Discount(
|
Discount({
|
||||||
{this.code,
|
this.id,
|
||||||
this.customer,
|
this.code,
|
||||||
this.amount,
|
this.customerId,
|
||||||
this.status,
|
this.customerName,
|
||||||
this.weight,
|
this.amount,
|
||||||
this.discountRate});
|
this.status,
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'id': id,
|
||||||
|
'code': code,
|
||||||
|
"customer_id": customerId,
|
||||||
|
"customer_name": customerName,
|
||||||
|
"amount": amount,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory Discount.fromMap(Map<String, dynamic> map, String id) {
|
||||||
|
return Discount(
|
||||||
|
id: id,
|
||||||
|
code: map['code'],
|
||||||
|
customerId: map['customer_id'],
|
||||||
|
customerName: map['customer_name'],
|
||||||
|
amount: map['amount'],
|
||||||
|
status: map['status'],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import 'package:fcs/helpers/theme.dart';
|
|||||||
import 'package:fcs/localization/app_translations.dart';
|
import 'package:fcs/localization/app_translations.dart';
|
||||||
import 'package:fcs/pages/discount/model/discount_model.dart';
|
import 'package:fcs/pages/discount/model/discount_model.dart';
|
||||||
import 'package:fcs/pages/main/util.dart';
|
import 'package:fcs/pages/main/util.dart';
|
||||||
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
|
||||||
import 'package:fcs/pages/widgets/progress.dart';
|
import 'package:fcs/pages/widgets/progress.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -87,7 +86,7 @@ class _DiscountListState extends State<DiscountList> {
|
|||||||
Row(
|
Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(
|
Text(
|
||||||
discount.customer,
|
discount.customerName,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
fontWeight: FontWeight.normal,
|
fontWeight: FontWeight.normal,
|
||||||
|
|||||||
@@ -1,56 +1,56 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
|
import 'package:fcs/data/services/services.dart';
|
||||||
import 'package:fcs/domain/entities/discount.dart';
|
import 'package:fcs/domain/entities/discount.dart';
|
||||||
import 'package:fcs/pages/main/model/base_model.dart';
|
import 'package:fcs/pages/main/model/base_model.dart';
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
|
|
||||||
class DiscountModel extends BaseModel {
|
class DiscountModel extends BaseModel {
|
||||||
List<Discount> get discounts {
|
final log = Logger('DiscountModel');
|
||||||
List<Discount> discountList = [
|
|
||||||
Discount(
|
|
||||||
code: 'XMQY01',
|
|
||||||
customer: 'Ko Nyi',
|
|
||||||
amount: 5000,
|
|
||||||
status: 'Used',
|
|
||||||
),
|
|
||||||
Discount(
|
|
||||||
code: 'XMQY02',
|
|
||||||
customer: 'Ko Aung Myo',
|
|
||||||
amount: 3000,
|
|
||||||
status: 'Avaliable',
|
|
||||||
),
|
|
||||||
Discount(
|
|
||||||
code: 'XMQY03',
|
|
||||||
customer: 'Ko Zaw Thu',
|
|
||||||
amount: 2000,
|
|
||||||
status: 'Used',
|
|
||||||
),
|
|
||||||
Discount(
|
|
||||||
code: 'XMQY04',
|
|
||||||
customer: 'Ko Myo Min',
|
|
||||||
amount: 3000,
|
|
||||||
status: 'Avaliable',
|
|
||||||
),
|
|
||||||
Discount(
|
|
||||||
code: 'XMQY05',
|
|
||||||
customer: 'Ko Nyi',
|
|
||||||
amount: 3000,
|
|
||||||
status: 'Avaliable',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
return discountList;
|
|
||||||
}
|
|
||||||
|
|
||||||
// List<Discount> get discountByCustomer {
|
StreamSubscription<QuerySnapshot> listener;
|
||||||
// return invoices.where((e) => e.status == "Avaliable").toList()
|
|
||||||
// ..sort((e1, e2) {
|
List<Discount> discounts = [];
|
||||||
// return e2.invoiceNumber.compareTo(e1.invoiceNumber);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
void initUser(user) {
|
void initUser(user) {
|
||||||
super.initUser(user);
|
super.initUser(user);
|
||||||
|
_load();
|
||||||
|
}
|
||||||
|
|
||||||
|
_load() {
|
||||||
|
if (listener != null) listener.cancel();
|
||||||
|
try {
|
||||||
|
listener = Firestore.instance
|
||||||
|
.collection("/discounts")
|
||||||
|
.orderBy("code", descending: false)
|
||||||
|
.snapshots()
|
||||||
|
.listen((snaps) {
|
||||||
|
discounts.clear();
|
||||||
|
snaps.documents.forEach((d) {
|
||||||
|
discounts.add(Discount.fromMap(d.data, d.documentID));
|
||||||
|
});
|
||||||
|
notifyListeners();
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
log.warning("error:$e");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
logout() async {
|
logout() async {
|
||||||
// discounts = [];
|
discounts = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> addDiscount(Discount discount) async {
|
||||||
|
return Services.instance.commonService.createDiscount(discount);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> updateDiscount(Discount discount) async {
|
||||||
|
return Services.instance.commonService.updateDiscount(discount);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> deleteDiscount(Discount discount) async {
|
||||||
|
return Services.instance.commonService.deleteDiscount(discount.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import 'package:fcs/domain/entities/discount.dart';
|
import 'package:fcs/domain/entities/discount_by_weight.dart';
|
||||||
import 'package:fcs/helpers/theme.dart';
|
import 'package:fcs/helpers/theme.dart';
|
||||||
import 'package:fcs/localization/app_translations.dart';
|
import 'package:fcs/localization/app_translations.dart';
|
||||||
import 'package:fcs/pages/main/util.dart';
|
import 'package:fcs/pages/main/util.dart';
|
||||||
@@ -9,8 +9,8 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
|
|
||||||
class DiscountByWeightEditor extends StatefulWidget {
|
class DiscountByWeightEditor extends StatefulWidget {
|
||||||
final Discount discount;
|
final DiscountByWeight discountByWeight;
|
||||||
DiscountByWeightEditor({this.discount});
|
DiscountByWeightEditor({this.discountByWeight});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_DiscountByWeightEditorState createState() => _DiscountByWeightEditorState();
|
_DiscountByWeightEditorState createState() => _DiscountByWeightEditorState();
|
||||||
@@ -21,15 +21,15 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
|
|||||||
TextEditingController _rateController = new TextEditingController();
|
TextEditingController _rateController = new TextEditingController();
|
||||||
|
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
Discount _discount = new Discount();
|
DiscountByWeight _discountByWeight = new DiscountByWeight();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
if (widget.discount != null) {
|
if (widget.discountByWeight != null) {
|
||||||
_discount = widget.discount;
|
_discountByWeight = widget.discountByWeight;
|
||||||
_weightController.text = _discount.weight.toString();
|
_weightController.text = _discountByWeight.weight.toString();
|
||||||
_rateController.text = _discount.discountRate.toString();
|
_rateController.text = _discountByWeight.discount.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
widget.discount == null
|
widget.discountByWeight == null
|
||||||
? fcsButton(context, "Create", callack: () {})
|
? fcsButton(context, "Create", callack: () {})
|
||||||
: fcsButton(context, "Save", callack: () {}),
|
: fcsButton(context, "Save", callack: () {}),
|
||||||
SizedBox(height: 10)
|
SizedBox(height: 10)
|
||||||
|
|||||||
Reference in New Issue
Block a user