perbaikan data report

This commit is contained in:
2026-04-23 21:21:33 +07:00
parent ecb2a369af
commit a898e4432f
13 changed files with 140 additions and 134 deletions

View File

@@ -6,7 +6,7 @@ class BalanceSheetModel {
factory BalanceSheetModel.fromJson(Map<String, dynamic> json) {
return BalanceSheetModel(
totalAsset: json["total_asset"],
totalAsset: num.tryParse(json["total_asset"].toString()),
data: json["asset_datas"] == null
? []
: List<AssetData>.from(json["asset_datas"]!.map((x) => AssetData.fromJson(x))),
@@ -40,8 +40,8 @@ class AssetData {
if (stocks is List && stocks.isNotEmpty) {
final _firstStock = stocks.first as Map<String, dynamic>;
final _purchasePrice = (_firstStock["productPurchasePrice"] as num?) ?? 0;
final _stockQty = (_firstStock["productStock"] as num?) ?? 0;
final _purchasePrice = num.tryParse(_firstStock["productPurchasePrice"].toString()) ?? 0;
final _stockQty = num.tryParse(_firstStock["productStock"].toString()) ?? 0;
_amount = _purchasePrice * _stockQty;
}
@@ -51,8 +51,8 @@ class AssetData {
if (comboProducts is List) {
_amount = comboProducts.fold<num>(0, (sum, item) {
if (item is Map<String, dynamic>) {
final _price = (item["purchase_price"] as num?) ?? 0;
final _qty = (item["quantity"] as num?) ?? 0;
final _price = num.tryParse(item["purchase_price"].toString()) ?? 0;
final _qty = num.tryParse(item["quantity"].toString()) ?? 0;
return sum + (_price * _qty);
}
return sum;
@@ -60,7 +60,7 @@ class AssetData {
}
}
} else if (_source == "bank") {
_amount = (json["balance"] as num?) ?? 0;
_amount = num.tryParse(json["balance"].toString()) ?? 0;
}
return AssetData(

View File

@@ -13,9 +13,9 @@ class BillWiseLossProfitReportModel {
factory BillWiseLossProfitReportModel.fromJson(Map<String, dynamic> json) {
return BillWiseLossProfitReportModel(
totalSaleAmount: json["total_amount"],
totalProfit: json['total_bill_profit'],
totalLoss: json['total_bill_loss'],
totalSaleAmount: num.tryParse(json["total_amount"].toString()),
totalProfit: num.tryParse(json['total_bill_profit'].toString()),
totalLoss: num.tryParse(json['total_bill_loss'].toString()),
transactions: json['data'] == null
? null
: List<TransactionModel>.from(json['data'].map((x) => TransactionModel.fromJson(x))),
@@ -50,8 +50,8 @@ class TransactionModel {
partyName: json['party']?['name'],
invoiceNumber: json['invoiceNumber'],
transactionDate: json["saleDate"] == null ? null : DateTime.parse(json['saleDate']),
totalAmount: json['totalAmount'],
lossProfit: json['lossProfit'],
totalAmount: num.tryParse(json['totalAmount'].toString()),
lossProfit: num.tryParse(json['lossProfit'].toString()),
items: json['details'] == null
? null
: List<TransactionItem>.from(json['details'].map((x) => TransactionItem.fromJson(x))),
@@ -82,10 +82,10 @@ class TransactionItem {
return TransactionItem(
id: json['id'],
name: json['product']?['productName'],
quantity: json['quantities'],
purchasePrice: json['productPurchasePrice'],
salesPrice: json['price'],
lossProfit: json['lossProfit'],
quantity: int.tryParse(json['quantities'].toString()),
purchasePrice: num.tryParse(json['productPurchasePrice'].toString()),
salesPrice: num.tryParse(json['price'].toString()),
lossProfit: num.tryParse(json['lossProfit'].toString()),
);
}
}

View File

@@ -15,10 +15,10 @@ class CashflowModel {
factory CashflowModel.fromJson(Map<String, dynamic> json) {
return CashflowModel(
cashIn: json["cash_in"],
cashOut: json["cash_out"],
runningCash: json["running_cash"],
initialRunningCash: json["initial_running_cash"],
cashIn: num.tryParse(json["cash_in"].toString()),
cashOut: num.tryParse(json["cash_out"].toString()),
runningCash: num.tryParse(json["running_cash"].toString()),
initialRunningCash: num.tryParse(json["initial_running_cash"].toString()),
data: json["data"] == null ? [] : List<CashflowData>.from(json["data"]!.map((x) => CashflowData.fromJson(x))),
);
}
@@ -55,7 +55,7 @@ class CashflowData {
platform: json["platform"],
transactionType: json["transaction_type"],
type: json["type"],
amount: json["amount"],
amount: num.tryParse(json["amount"].toString()),
date: json["date"] == null ? null : DateTime.parse(json["date"]),
invoiceNo: json["invoice_no"],
paymentType: json["payment_type"]?["name"],

View File

@@ -29,13 +29,13 @@ class LossProfitModel {
expenseSummary: json["mergedExpenseData"] == null
? []
: List<ExpenseSummaryModel>.from(json["mergedExpenseData"]!.map((x) => ExpenseSummaryModel.fromJson(x))),
grossSalProfit: json["grossSaleProfit"],
grossIncomeProfit: json['grossIncomeProfit'],
totalExpenses: json['totalExpenses'],
netProfit: json['netProfit'],
cartGrossProfit: json['cardGrossProfit'],
totalCardExpense: json['totalCardExpenses'],
cardNetProfit: json['cardNetProfit'],
grossSalProfit: num.tryParse(json["grossSaleProfit"].toString()),
grossIncomeProfit: num.tryParse(json['grossIncomeProfit'].toString()),
totalExpenses: num.tryParse(json['totalExpenses'].toString()),
netProfit: num.tryParse(json['netProfit'].toString()),
cartGrossProfit: num.tryParse(json['cardGrossProfit'].toString()),
totalCardExpense: num.tryParse(json['totalCardExpenses'].toString()),
cardNetProfit: num.tryParse(json['cardNetProfit'].toString()),
);
}
}
@@ -51,7 +51,7 @@ class IncomeSummaryModel {
return IncomeSummaryModel(
type: json["type"],
date: json["date"],
totalIncome: json["total_incomes"],
totalIncome: num.tryParse(json["total_incomes"].toString()),
);
}
}
@@ -67,7 +67,7 @@ class ExpenseSummaryModel {
return ExpenseSummaryModel(
type: json["type"],
date: json["date"],
totalExpense: json["total_expenses"],
totalExpense: num.tryParse(json["total_expenses"].toString()),
);
}
}

View File

@@ -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() ?? ''),
);
}
}

View File

@@ -17,7 +17,7 @@ class SubscriptionReportModel {
factory SubscriptionReportModel.fromJson(Map<String, dynamic> json) {
final _startDate = json["created_at"] == null ? null : DateTime.parse(json['created_at']);
final int _duration = json['duration'] ?? 0;
final int _duration = int.tryParse(json['duration']?.toString() ?? '') ?? 0;
return SubscriptionReportModel(
id: json['id'],

View File

@@ -18,16 +18,16 @@ class TaxReportModel {
overviews: [
// Sales
OverviewModel(
totalAmount: json['sales_total_amount'] ?? 0,
totalDiscount: json['sales_total_discount'] ?? 0,
totalVat: json['sales_total_vat'] ?? 0,
totalAmount: num.tryParse(json['sales_total_amount'].toString()) ?? 0,
totalDiscount: num.tryParse(json['sales_total_discount'].toString()) ?? 0,
totalVat: num.tryParse(json['sales_total_vat'].toString()) ?? 0,
),
// Purchase
OverviewModel(
totalAmount: json['purchases_total_amount'] ?? 0,
totalDiscount: json['purchases_total_discount'] ?? 0,
totalVat: json['purchases_total_vat'] ?? 0,
totalAmount: num.tryParse(json['purchases_total_amount'].toString()) ?? 0,
totalDiscount: num.tryParse(json['purchases_total_discount'].toString()) ?? 0,
totalVat: num.tryParse(json['purchases_total_vat'].toString()) ?? 0,
),
],
);
@@ -63,10 +63,10 @@ class InvoiceModel {
partyName: json['party']?['name'],
invoiceNumber: json['invoiceNumber'],
transactionDate: _dateKey == null ? null : DateTime.parse(_dateKey),
amount: json['totalAmount'],
discountAmount: json['discountAmount'],
amount: num.tryParse(json['totalAmount'].toString()),
discountAmount: num.tryParse(json['discountAmount'].toString()),
vatName: json['vat']?['name'],
vatAmount: json['vat_amount'],
vatAmount: num.tryParse(json['vat_amount'].toString()),
);
}
}