202 lines
7.3 KiB
Dart
202 lines
7.3 KiB
Dart
class CreditNoteItem {
|
|
final int? id;
|
|
final int? creditNoteId;
|
|
final int? invoiceItemId;
|
|
final int? productId;
|
|
final int? inventoryItemId;
|
|
final String? productName;
|
|
final String? sku;
|
|
final String? huid;
|
|
final String? hsnCode;
|
|
final double quantity;
|
|
final double? weight;
|
|
final double unitPrice;
|
|
final double taxRate;
|
|
final double cgst;
|
|
final double sgst;
|
|
final double igst;
|
|
final double discount;
|
|
final double makingCharge;
|
|
final double otherCharges;
|
|
final double total;
|
|
|
|
CreditNoteItem({
|
|
this.id,
|
|
this.creditNoteId,
|
|
this.invoiceItemId,
|
|
this.productId,
|
|
this.inventoryItemId,
|
|
this.productName,
|
|
this.sku,
|
|
this.huid,
|
|
this.hsnCode,
|
|
required this.quantity,
|
|
this.weight,
|
|
required this.unitPrice,
|
|
this.taxRate = 0.0,
|
|
this.cgst = 0.0,
|
|
this.sgst = 0.0,
|
|
this.igst = 0.0,
|
|
this.discount = 0.0,
|
|
this.makingCharge = 0.0,
|
|
this.otherCharges = 0.0,
|
|
required this.total,
|
|
});
|
|
|
|
factory CreditNoteItem.fromJson(Map<String, dynamic> json) {
|
|
return CreditNoteItem(
|
|
id: json['id'],
|
|
creditNoteId: json['creditNoteId'] ?? json['credit_note_id'],
|
|
invoiceItemId: json['invoiceItemId'] ?? json['invoice_item_id'],
|
|
productId: json['productId'] ?? json['product_id'],
|
|
inventoryItemId: json['inventoryItemId'] ?? json['inventory_item_id'],
|
|
productName: json['productName'] ?? json['product_name'],
|
|
sku: json['sku'],
|
|
huid: json['huid'],
|
|
hsnCode: json['hsnCode'] ?? json['hsn_code'],
|
|
quantity: (json['quantity'] as num?)?.toDouble() ?? 1.0,
|
|
weight: (json['weight'] as num?)?.toDouble(),
|
|
unitPrice: (json['unitPrice'] ?? json['unit_price'] as num?)?.toDouble() ?? 0.0,
|
|
taxRate: (json['taxRate'] ?? json['tax_rate'] as num?)?.toDouble() ?? 0.0,
|
|
cgst: (json['cgst'] as num?)?.toDouble() ?? 0.0,
|
|
sgst: (json['sgst'] as num?)?.toDouble() ?? 0.0,
|
|
igst: (json['igst'] as num?)?.toDouble() ?? 0.0,
|
|
discount: (json['discount'] as num?)?.toDouble() ?? 0.0,
|
|
makingCharge: (json['makingCharge'] ?? json['making_charge'] as num?)?.toDouble() ?? 0.0,
|
|
otherCharges: (json['otherCharges'] ?? json['other_charges'] as num?)?.toDouble() ?? 0.0,
|
|
total: (json['total'] as num?)?.toDouble() ?? 0.0,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
final Map<String, dynamic> data = {};
|
|
if (id != null) data['id'] = id;
|
|
if (creditNoteId != null) data['creditNoteId'] = creditNoteId;
|
|
if (invoiceItemId != null) data['invoiceItemId'] = invoiceItemId;
|
|
if (productId != null) data['productId'] = productId;
|
|
if (inventoryItemId != null) data['inventoryItemId'] = inventoryItemId;
|
|
if (productName != null) data['productName'] = productName;
|
|
if (sku != null) data['sku'] = sku;
|
|
if (huid != null) data['huid'] = huid;
|
|
if (hsnCode != null) data['hsnCode'] = hsnCode;
|
|
data['quantity'] = quantity;
|
|
if (weight != null) data['weight'] = weight;
|
|
data['unitPrice'] = unitPrice;
|
|
data['taxRate'] = taxRate;
|
|
data['cgst'] = cgst;
|
|
data['sgst'] = sgst;
|
|
data['igst'] = igst;
|
|
data['discount'] = discount;
|
|
data['makingCharge'] = makingCharge;
|
|
data['otherCharges'] = otherCharges;
|
|
data['total'] = total;
|
|
return data;
|
|
}
|
|
}
|
|
|
|
class CreditNote {
|
|
final int? id;
|
|
final int? userId;
|
|
final int invoiceId;
|
|
final String creditNoteNumber;
|
|
final int? customerId;
|
|
final DateTime returnDate;
|
|
final String reason; // CUSTOMER_RETURN, RTO_UNDELIVERED, DEFECTIVE, EXCHANGE, OTHER
|
|
final bool restockItems;
|
|
final double subtotal;
|
|
final double taxTotal;
|
|
final double cgstTotal;
|
|
final double sgstTotal;
|
|
final double igstTotal;
|
|
final double discountTotal;
|
|
final double totalAmount;
|
|
final String refundStatus; // ADJUSTED_TO_AR, REFUNDED_TO_WALLET, STORE_CREDIT, PENDING
|
|
final int? refundWalletId;
|
|
final String? notes;
|
|
final DateTime? createdAt;
|
|
final DateTime? updatedAt;
|
|
final List<CreditNoteItem> items;
|
|
|
|
CreditNote({
|
|
this.id,
|
|
this.userId,
|
|
required this.invoiceId,
|
|
required this.creditNoteNumber,
|
|
this.customerId,
|
|
required this.returnDate,
|
|
this.reason = 'CUSTOMER_RETURN',
|
|
this.restockItems = true,
|
|
required this.subtotal,
|
|
this.taxTotal = 0.0,
|
|
this.cgstTotal = 0.0,
|
|
this.sgstTotal = 0.0,
|
|
this.igstTotal = 0.0,
|
|
this.discountTotal = 0.0,
|
|
required this.totalAmount,
|
|
this.refundStatus = 'ADJUSTED_TO_AR',
|
|
this.refundWalletId,
|
|
this.notes,
|
|
this.createdAt,
|
|
this.updatedAt,
|
|
this.items = const [],
|
|
});
|
|
|
|
factory CreditNote.fromJson(Map<String, dynamic> json) {
|
|
return CreditNote(
|
|
id: json['id'],
|
|
userId: json['userId'] ?? json['user_id'],
|
|
invoiceId: json['invoiceId'] ?? json['invoice_id'] ?? 0,
|
|
creditNoteNumber: json['creditNoteNumber'] ?? json['credit_note_number'] ?? '',
|
|
customerId: json['customerId'] ?? json['customer_id'],
|
|
returnDate: json['returnDate'] != null
|
|
? DateTime.parse(json['returnDate'])
|
|
: (json['return_date'] != null ? DateTime.parse(json['return_date']) : DateTime.now()),
|
|
reason: json['reason'] ?? 'CUSTOMER_RETURN',
|
|
restockItems: json['restockItems'] ?? json['restock_items'] ?? true,
|
|
subtotal: (json['subtotal'] as num?)?.toDouble() ?? 0.0,
|
|
taxTotal: (json['taxTotal'] ?? json['tax_total'] as num?)?.toDouble() ?? 0.0,
|
|
cgstTotal: (json['cgstTotal'] ?? json['cgst_total'] as num?)?.toDouble() ?? 0.0,
|
|
sgstTotal: (json['sgstTotal'] ?? json['sgst_total'] as num?)?.toDouble() ?? 0.0,
|
|
igstTotal: (json['igstTotal'] ?? json['igst_total'] as num?)?.toDouble() ?? 0.0,
|
|
discountTotal: (json['discountTotal'] ?? json['discount_total'] as num?)?.toDouble() ?? 0.0,
|
|
totalAmount: (json['totalAmount'] ?? json['total_amount'] as num?)?.toDouble() ?? 0.0,
|
|
refundStatus: json['refundStatus'] ?? json['refund_status'] ?? 'ADJUSTED_TO_AR',
|
|
refundWalletId: json['refundWalletId'] ?? json['refund_wallet_id'],
|
|
notes: json['notes'],
|
|
createdAt: json['createdAt'] != null
|
|
? DateTime.parse(json['createdAt'])
|
|
: (json['created_at'] != null ? DateTime.parse(json['created_at']) : null),
|
|
updatedAt: json['updatedAt'] != null
|
|
? DateTime.parse(json['updatedAt'])
|
|
: (json['updated_at'] != null ? DateTime.parse(json['updated_at']) : null),
|
|
items: json['items'] != null
|
|
? (json['items'] as List).map((i) => CreditNoteItem.fromJson(i)).toList()
|
|
: [],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
final Map<String, dynamic> data = {};
|
|
if (id != null) data['id'] = id;
|
|
if (userId != null) data['userId'] = userId;
|
|
data['invoiceId'] = invoiceId;
|
|
data['creditNoteNumber'] = creditNoteNumber;
|
|
if (customerId != null) data['customerId'] = customerId;
|
|
data['returnDate'] = returnDate.toIso8601String().split('T')[0];
|
|
data['reason'] = reason;
|
|
data['restockItems'] = restockItems;
|
|
data['subtotal'] = subtotal;
|
|
data['taxTotal'] = taxTotal;
|
|
data['cgstTotal'] = cgstTotal;
|
|
data['sgstTotal'] = sgstTotal;
|
|
data['igstTotal'] = igstTotal;
|
|
data['discountTotal'] = discountTotal;
|
|
data['totalAmount'] = totalAmount;
|
|
data['refundStatus'] = refundStatus;
|
|
if (refundWalletId != null) data['refundWalletId'] = refundWalletId;
|
|
if (notes != null) data['notes'] = notes;
|
|
data['items'] = items.map((i) => i.toJson()).toList();
|
|
return data;
|
|
}
|
|
}
|