add structure
This commit is contained in:
279
lib/vo/revenue.dart
Normal file
279
lib/vo/revenue.dart
Normal file
@@ -0,0 +1,279 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class Revenue {
|
||||
Map<dynamic, dynamic> mapData = {};
|
||||
Map<dynamic, dynamic> mapPOCount = {};
|
||||
Map<dynamic, dynamic> mapDOCount = {};
|
||||
Map<dynamic, dynamic> mapDelivery = {};
|
||||
Map<dynamic, dynamic> mapDoDelivery = {};
|
||||
|
||||
List<double> getData1(int index) {
|
||||
var endRange = 0;
|
||||
if (index == 0) {
|
||||
// 7 days
|
||||
endRange = 6 > mapData.length ? mapData.length : 6;
|
||||
} else if (index == 1) {
|
||||
// one months
|
||||
endRange = 30 > mapData.length ? mapData.length : 30;
|
||||
} else {
|
||||
// three months
|
||||
endRange = 90 > mapData.length ? mapData.length : 90;
|
||||
}
|
||||
List<int> result = new List();
|
||||
if (mapData != null) {
|
||||
mapData.forEach((k, value) {
|
||||
result.add(value.toInt());
|
||||
});
|
||||
}
|
||||
return result.getRange(0, endRange).map((v) => v.toDouble()).toList();
|
||||
}
|
||||
|
||||
List<Data> getData() {
|
||||
List<Data> result = new List();
|
||||
if (mapData != null) {
|
||||
DateTime today = new DateTime.now();
|
||||
DateTime thirtyDaysAgo = today.subtract(new Duration(days: 30));
|
||||
String _formatter = new DateFormat("yyyyMMdd").format(thirtyDaysAgo);
|
||||
int _lastThirtyDays = int.tryParse(_formatter);
|
||||
|
||||
mapData.forEach((k, value) {
|
||||
int mapDay = int.tryParse(k);
|
||||
if (mapDay < _lastThirtyDays) return;
|
||||
|
||||
var parsedDate = DateTime.parse(k);
|
||||
var data = Data(date: parsedDate, amount: value);
|
||||
result.add(data);
|
||||
});
|
||||
result.sort((a, b) {
|
||||
return a.date.compareTo(b.date);
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Data> getPOCounts() {
|
||||
List<Data> result = new List();
|
||||
if (mapPOCount != null) {
|
||||
mapPOCount.forEach((k, value) {
|
||||
var parsedDate = DateTime.parse(k);
|
||||
var data = Data(date: parsedDate, count: value);
|
||||
result.add(data);
|
||||
});
|
||||
result.sort((a, b) {
|
||||
return a.date.compareTo(b.date);
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Data> getDOCounts() {
|
||||
List<Data> result = new List();
|
||||
if (mapDOCount != null) {
|
||||
mapDOCount.forEach((k, value) {
|
||||
var parsedDate = DateTime.parse(k);
|
||||
var data = Data(date: parsedDate, count: value);
|
||||
result.add(data);
|
||||
});
|
||||
result.sort((a, b) {
|
||||
return a.date.compareTo(b.date);
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Data> getDelivery() {
|
||||
List<Data> result = new List();
|
||||
if (mapDelivery != null) {
|
||||
mapDelivery.forEach((k, value) {
|
||||
var parsedDate = DateTime.parse(k);
|
||||
var data = Data(date: parsedDate, amount: value);
|
||||
result.add(data);
|
||||
});
|
||||
result.sort((a, b) {
|
||||
return a.date.compareTo(b.date);
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Data> getDeliverySummary() {
|
||||
List<Data> _list = new List();
|
||||
List<Data> result = new List();
|
||||
|
||||
if (mapDelivery != null) {
|
||||
mapDelivery.forEach((k, value) {
|
||||
var parsedDate = DateTime.parse(k);
|
||||
var data = Data(date: parsedDate, amount: value);
|
||||
_list.add(data);
|
||||
});
|
||||
_list.sort((a, b) {
|
||||
return a.date.compareTo(b.date);
|
||||
});
|
||||
|
||||
int _count = 1;
|
||||
int _index = 0;
|
||||
int _totalDay = 0;
|
||||
int _totalAmount = 0;
|
||||
int lastIndex = _list.length - 1;
|
||||
_list.asMap().forEach((index, value) {
|
||||
_totalAmount += value.amount;
|
||||
if (_count == 10 || index == lastIndex) {
|
||||
_totalDay = (_index + 1) * 10;
|
||||
if (index == lastIndex && lastIndex > 0) {
|
||||
_totalDay = lastIndex + 1;
|
||||
_totalAmount +=
|
||||
result.length > 0 ? result[result.length - 1].totalAmount : 0;
|
||||
}
|
||||
if (lastIndex == 0) {
|
||||
_totalDay = 1;
|
||||
}
|
||||
if (_index != 0 && index != lastIndex) {
|
||||
_totalAmount += result[_index - 1].totalAmount;
|
||||
}
|
||||
result.insert(
|
||||
_index, Data(totalDay: _totalDay, totalAmount: _totalAmount));
|
||||
_totalAmount = 0;
|
||||
_count = 0;
|
||||
_index++;
|
||||
}
|
||||
_count++;
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Data> getDeliveryDo() {
|
||||
List<Data> result = new List();
|
||||
if (mapDoDelivery != null) {
|
||||
mapDoDelivery.forEach((k, value) {
|
||||
var parsedDate = DateTime.parse(k);
|
||||
var data = Data(date: parsedDate, count: value);
|
||||
result.add(data);
|
||||
});
|
||||
result.sort((a, b) {
|
||||
return a.date.compareTo(b.date);
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
List<Data> getDeliveryDoSummary() {
|
||||
List<Data> _list = new List();
|
||||
List<Data> result = new List();
|
||||
|
||||
if (mapDoDelivery != null) {
|
||||
mapDoDelivery.forEach((k, value) {
|
||||
var parsedDate = DateTime.parse(k);
|
||||
var data = Data(date: parsedDate, count: value);
|
||||
_list.add(data);
|
||||
});
|
||||
_list.sort((a, b) {
|
||||
return a.date.compareTo(b.date);
|
||||
});
|
||||
|
||||
int _count = 1;
|
||||
int _index = 0;
|
||||
int _totalDay = 0;
|
||||
int _totalCount = 0;
|
||||
int lastIndex = _list.length - 1;
|
||||
_list.asMap().forEach((index, value) {
|
||||
_totalCount += value.count;
|
||||
if (_count == 10 || index == lastIndex) {
|
||||
_totalDay = (_index + 1) * 10;
|
||||
if (index == lastIndex && lastIndex > 0) {
|
||||
_totalDay = lastIndex + 1;
|
||||
_totalCount +=
|
||||
result.length > 0 ? result[result.length - 1].totalCount : 0;
|
||||
}
|
||||
if (lastIndex == 0) {
|
||||
_totalDay = 1;
|
||||
}
|
||||
if (_index != 0 && index != lastIndex) {
|
||||
_totalCount += result[_index - 1].totalCount;
|
||||
}
|
||||
result.insert(
|
||||
_index, Data(totalDay: _totalDay, totalCount: _totalCount));
|
||||
_totalCount = 0;
|
||||
_count = 0;
|
||||
_index++;
|
||||
}
|
||||
_count++;
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int getTotal(int index) {
|
||||
var endRange = 0;
|
||||
if (index == 0) {
|
||||
// 7 days
|
||||
endRange = 6 > mapData.length ? mapData.length : 6;
|
||||
} else if (index == 1) {
|
||||
// one months
|
||||
endRange = 30 > mapData.length ? mapData.length : 30;
|
||||
} else {
|
||||
// three months
|
||||
endRange = 90 > mapData.length ? mapData.length : 90;
|
||||
}
|
||||
|
||||
List<int> result = new List();
|
||||
if (mapData != null) {
|
||||
DateTime today = new DateTime.now();
|
||||
DateTime thirtyDaysAgo = today.subtract(new Duration(days: 30));
|
||||
String _formatter = new DateFormat("yyyyMMdd").format(thirtyDaysAgo);
|
||||
int _lastThirtyDays = int.tryParse(_formatter);
|
||||
|
||||
mapData.forEach((k, value) {
|
||||
int mapDay = int.tryParse(k);
|
||||
if (mapDay < _lastThirtyDays) return;
|
||||
result.add(value.toInt());
|
||||
});
|
||||
}
|
||||
|
||||
return result.fold(0, (prev, element) => prev + element);
|
||||
}
|
||||
|
||||
Revenue(
|
||||
{this.mapData,
|
||||
this.mapPOCount,
|
||||
this.mapDOCount,
|
||||
this.mapDelivery,
|
||||
this.mapDoDelivery});
|
||||
|
||||
factory Revenue.fromMap(Map<String, dynamic> map, String docID) {
|
||||
return Revenue(
|
||||
mapData: map['data'],
|
||||
mapPOCount: map['po_count'],
|
||||
mapDOCount: map['do_count'],
|
||||
mapDelivery: map['delivery'],
|
||||
mapDoDelivery: map['do_delivery']);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class Data {
|
||||
DateTime date;
|
||||
int totalDay;
|
||||
int totalCount;
|
||||
int totalAmount;
|
||||
int amount;
|
||||
int count;
|
||||
Data(
|
||||
{this.date,
|
||||
this.amount,
|
||||
this.count,
|
||||
this.totalDay,
|
||||
this.totalCount,
|
||||
this.totalAmount});
|
||||
}
|
||||
Reference in New Issue
Block a user