perbaikan data report
This commit is contained in:
@@ -23,8 +23,8 @@ class ProductHistoryListModel {
|
||||
|
||||
factory ProductHistoryListModel.fromJson(Map<String, dynamic> json) {
|
||||
return ProductHistoryListModel(
|
||||
totalPurchaseQuantity: json['total_purchase_qty'],
|
||||
totalSaleQuantity: json['total_sale_qty'],
|
||||
totalPurchaseQuantity: int.tryParse(json['total_purchase_qty']?.toString() ?? ''),
|
||||
totalSaleQuantity: int.tryParse(json['total_sale_qty']?.toString() ?? ''),
|
||||
items: json['data'] == null
|
||||
? null
|
||||
: List<ProductHistoryItemModel>.from(json['data']!.map((x) => ProductHistoryItemModel.fromJson(x))),
|
||||
@@ -54,34 +54,40 @@ class ProductHistoryItemModel {
|
||||
factory ProductHistoryItemModel.fromJson(Map<String, dynamic> json) {
|
||||
final int _totalPurchaseQuantity = json["purchase_details"] == null
|
||||
? 0
|
||||
: (json["purchase_details"] as List<dynamic>).fold<int>(0, (p, ev) => p + (ev["quantities"] as int? ?? 0));
|
||||
: (json["purchase_details"] as List<dynamic>)
|
||||
.fold<int>(0, (p, ev) => p + (int.tryParse(ev["quantities"]?.toString() ?? '') ?? 0));
|
||||
|
||||
final int _totalSaleQuantity = json["sale_details"] == null
|
||||
? 0
|
||||
: (json["sale_details"] as List<dynamic>).fold<int>(0, (p, ev) => p + (ev["quantities"] as int? ?? 0));
|
||||
: (json["sale_details"] as List<dynamic>)
|
||||
.fold<int>(0, (p, ev) => p + (int.tryParse(ev["quantities"]?.toString() ?? '') ?? 0));
|
||||
|
||||
final _remainingQuantity = switch (json["product_type"]?.trim().toLowerCase()) {
|
||||
"combo" => json["combo_products"] == null
|
||||
? 0
|
||||
: (json["combo_products"] as List<dynamic>).fold<int>(0, (p, ev) {
|
||||
return p + (ev["stock"]?["productStock"] as int? ?? 0);
|
||||
return p + (int.tryParse(ev["stock"]?["productStock"]?.toString() ?? '') ?? 0);
|
||||
}),
|
||||
_ => json["stocks"] == null ? null : (json["stocks"] as List<dynamic>).firstOrNull?["productStock"] as int? ?? 0,
|
||||
_ => json["stocks"] == null
|
||||
? null
|
||||
: int.tryParse((json["stocks"] as List<dynamic>).firstOrNull?["productStock"]?.toString() ?? '') ?? 0,
|
||||
};
|
||||
|
||||
final _salePrice = switch (json["product_type"]?.trim().toLowerCase()) {
|
||||
"combo" => json["productSalePrice"] ?? 0,
|
||||
_ =>
|
||||
json["stocks"] == null ? null : (json["stocks"] as List<dynamic>).firstOrNull?["productSalePrice"] as num? ?? 0,
|
||||
"combo" => num.tryParse(json["productSalePrice"]?.toString() ?? '') ?? 0,
|
||||
_ => json["stocks"] == null
|
||||
? null
|
||||
: num.tryParse((json["stocks"] as List<dynamic>).firstOrNull?["productSalePrice"]?.toString() ?? '') ?? 0,
|
||||
};
|
||||
|
||||
final _purchasePrice = switch (json["product_type"]?.trim().toLowerCase()) {
|
||||
"combo" => json["combo_products"] == null
|
||||
? 0
|
||||
: (json["combo_products"] as List<dynamic>).fold<num>(0, (p, ev) => p + (ev["purchase_price"] as num? ?? 0)),
|
||||
: (json["combo_products"] as List<dynamic>)
|
||||
.fold<num>(0, (p, ev) => p + (num.tryParse(ev["purchase_price"]?.toString() ?? '') ?? 0)),
|
||||
_ => json["stocks"] == null
|
||||
? null
|
||||
: (json["stocks"] as List<dynamic>).firstOrNull?["productPurchasePrice"] as num? ?? 0,
|
||||
: num.tryParse((json["stocks"] as List<dynamic>).firstOrNull?["productPurchasePrice"]?.toString() ?? '') ?? 0,
|
||||
};
|
||||
|
||||
return ProductHistoryItemModel(
|
||||
@@ -116,9 +122,9 @@ class ProductHistoryDetailsModel {
|
||||
final _detailsKey = _json["sale_details"] ?? _json["purchase_details"];
|
||||
|
||||
return ProductHistoryDetailsModel(
|
||||
totalQuantities: j['total_quantities'],
|
||||
totalSalePrice: j['total_sale_price'],
|
||||
totalPurchasePrice: j['total_purchase_price'],
|
||||
totalQuantities: int.tryParse(j['total_quantities']?.toString() ?? ''),
|
||||
totalSalePrice: num.tryParse(j['total_sale_price']?.toString() ?? ''),
|
||||
totalPurchasePrice: num.tryParse(j['total_purchase_price']?.toString() ?? ''),
|
||||
productName: _json?["productName"],
|
||||
items: _detailsKey == null
|
||||
? null
|
||||
@@ -155,9 +161,9 @@ class ProductHistoryDetailsItem {
|
||||
invoiceNo: _invoiceKey,
|
||||
type: 'Purchase',
|
||||
transactionDate: _transactionDate != null ? DateTime.parse(_transactionDate) : null,
|
||||
quantities: json['quantities'],
|
||||
salePrice: json['price'],
|
||||
purchasePrice: json['productPurchasePrice'],
|
||||
quantities: int.tryParse(json['quantities']?.toString() ?? ''),
|
||||
salePrice: num.tryParse(json['price']?.toString() ?? ''),
|
||||
purchasePrice: num.tryParse(json['productPurchasePrice']?.toString() ?? ''),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user