merge
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/vo/message.dart';
|
||||
import 'package:fcs/helpers/api_helper.dart';
|
||||
@@ -32,4 +33,19 @@ class CommonDataProvider {
|
||||
payload: {"owner_id": ownerID, "seen_by_owner": seenByOwner},
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ class RateDataProvider {
|
||||
}
|
||||
|
||||
Future<void> deleteCustomDuty(String id) async {
|
||||
return await requestAPI("/custom_duties", "PUT",
|
||||
return await requestAPI("/custom_duties", "DELETE",
|
||||
payload: {"id": id}, token: await getToken());
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ class RateDataProvider {
|
||||
}
|
||||
|
||||
Future<void> deleteDiscountByWeight(String id) async {
|
||||
return await requestAPI("/discounts_by_weight", "PUT",
|
||||
return await requestAPI("/discounts_by_weight", "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/user_data_provider.dart';
|
||||
import 'package:fcs/domain/entities/discount.dart';
|
||||
import 'package:fcs/domain/entities/payment_method.dart';
|
||||
import 'package:fcs/domain/vo/message.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -37,4 +37,19 @@ class CommonServiceImp implements CommonService {
|
||||
Future<void> seenMessage(String ownerID, bool 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/vo/message.dart';
|
||||
|
||||
@@ -10,4 +11,9 @@ abstract class CommonService {
|
||||
// Messaging
|
||||
Future<void> sendMessage(Message message);
|
||||
Future<void> seenMessage(String ownerID, bool seenByOwner);
|
||||
|
||||
// Payment
|
||||
Future<void> createDiscount(Discount discount);
|
||||
Future<void> updateDiscount(Discount discount);
|
||||
Future<void> deleteDiscount(String id);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
class Discount {
|
||||
String id;
|
||||
String code;
|
||||
String customer;
|
||||
String customerId;
|
||||
String customerName;
|
||||
String status;
|
||||
double amount;
|
||||
int weight;
|
||||
double discountRate;
|
||||
|
||||
<<<<<<< HEAD
|
||||
Discount(
|
||||
{this.id,
|
||||
this.code,
|
||||
@@ -15,4 +15,35 @@ class Discount {
|
||||
this.status,
|
||||
this.weight,
|
||||
this.discountRate});
|
||||
=======
|
||||
Discount({
|
||||
this.id,
|
||||
this.code,
|
||||
this.customerId,
|
||||
this.customerName,
|
||||
this.amount,
|
||||
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'],
|
||||
);
|
||||
}
|
||||
>>>>>>> upstream/master
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/pages/discount/model/discount_model.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:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -97,7 +96,7 @@ class _DiscountListState extends State<DiscountList> {
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
discount.customer,
|
||||
discount.customerName,
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.normal,
|
||||
|
||||
@@ -1,53 +1,65 @@
|
||||
<<<<<<< HEAD
|
||||
import 'dart:ffi';
|
||||
|
||||
=======
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
>>>>>>> upstream/master
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/entities/discount.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
class DiscountModel extends BaseModel {
|
||||
List<Discount> get discounts {
|
||||
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;
|
||||
}
|
||||
final log = Logger('DiscountModel');
|
||||
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
List<Discount> discounts = [];
|
||||
|
||||
>>>>>>> upstream/master
|
||||
void 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
|
||||
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);
|
||||
}
|
||||
|
||||
Future<void> addDiscount(Discount discount) {}
|
||||
|
||||
@@ -59,13 +59,12 @@ class _DiscountByWeightListState extends State<DiscountByWeightList> {
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
CupertinoPageRoute(builder: (context) => DiscountByWeightEditor()));
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => DiscountByWeightEditor()));
|
||||
},
|
||||
icon: Icon(Icons.add, color: Colors.white),
|
||||
backgroundColor: primaryColor,
|
||||
label: LocalText(context, 'discount.new',
|
||||
color: Colors.white)),
|
||||
label: LocalText(context, 'discount.new', color: Colors.white)),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListView.separated(
|
||||
@@ -80,7 +79,7 @@ class _DiscountByWeightListState extends State<DiscountByWeightList> {
|
||||
onTap: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => DiscountByWeightEditor(
|
||||
discount: discountByWeight)));
|
||||
discountByWeight: discountByWeight)));
|
||||
},
|
||||
child: Container(
|
||||
child: _row("${discountByWeight.weight.toString()} lb",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
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/localization/app_translations.dart';
|
||||
@@ -12,8 +11,8 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class DiscountByWeightEditor extends StatefulWidget {
|
||||
final DiscountByWeight discount;
|
||||
DiscountByWeightEditor({this.discount});
|
||||
final DiscountByWeight discountByWeight;
|
||||
DiscountByWeightEditor({this.discountByWeight});
|
||||
|
||||
@override
|
||||
_DiscountByWeightEditorState createState() => _DiscountByWeightEditorState();
|
||||
@@ -24,18 +23,16 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
|
||||
TextEditingController _discountController = new TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
DiscountByWeight _discount = new DiscountByWeight();
|
||||
bool _isNew = false;
|
||||
DiscountByWeight _discountByWeight = new DiscountByWeight();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.discount != null) {
|
||||
_discount = widget.discount;
|
||||
_weightController.text = _discount.weight.toString();
|
||||
_discountController.text = _discount.discount.toString();
|
||||
} else {
|
||||
_isNew = true;
|
||||
if (widget.discountByWeight != null) {
|
||||
_discountByWeight = widget.discountByWeight;
|
||||
_weightController.text = _discountByWeight.weight.toString();
|
||||
_discountController.text = _discountByWeight.discount.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +106,7 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
|
||||
if (_isNew) {
|
||||
await shipmentRateModel.addDiscountByWeight(_discount);
|
||||
} else {
|
||||
_discount.id = widget.discount.id;
|
||||
_discount.id = widget.discountByWeight.id;
|
||||
await shipmentRateModel.updateDiscountByWeight(_discount);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
@@ -134,7 +131,7 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
|
||||
try {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
await shipmentRateModel.deleteDiscountByWeight(widget.discount.id);
|
||||
await shipmentRateModel.deleteDiscountByWeight(widget.discountByWeight.id);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
|
||||
Reference in New Issue
Block a user