update database
This commit is contained in:
45
lib/features/quotes/data/models/quote_item_model.dart
Normal file
45
lib/features/quotes/data/models/quote_item_model.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:worker/core/constants/storage_constants.dart';
|
||||
|
||||
part 'quote_item_model.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.quoteItemModel)
|
||||
class QuoteItemModel extends HiveObject {
|
||||
QuoteItemModel({required this.quoteItemId, required this.quoteId, required this.productId, required this.quantity, required this.originalPrice, required this.negotiatedPrice, required this.discountPercent, required this.subtotal, this.notes});
|
||||
|
||||
@HiveField(0) final String quoteItemId;
|
||||
@HiveField(1) final String quoteId;
|
||||
@HiveField(2) final String productId;
|
||||
@HiveField(3) final double quantity;
|
||||
@HiveField(4) final double originalPrice;
|
||||
@HiveField(5) final double negotiatedPrice;
|
||||
@HiveField(6) final double discountPercent;
|
||||
@HiveField(7) final double subtotal;
|
||||
@HiveField(8) final String? notes;
|
||||
|
||||
factory QuoteItemModel.fromJson(Map<String, dynamic> json) => QuoteItemModel(
|
||||
quoteItemId: json['quote_item_id'] as String,
|
||||
quoteId: json['quote_id'] as String,
|
||||
productId: json['product_id'] as String,
|
||||
quantity: (json['quantity'] as num).toDouble(),
|
||||
originalPrice: (json['original_price'] as num).toDouble(),
|
||||
negotiatedPrice: (json['negotiated_price'] as num).toDouble(),
|
||||
discountPercent: (json['discount_percent'] as num).toDouble(),
|
||||
subtotal: (json['subtotal'] as num).toDouble(),
|
||||
notes: json['notes'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'quote_item_id': quoteItemId,
|
||||
'quote_id': quoteId,
|
||||
'product_id': productId,
|
||||
'quantity': quantity,
|
||||
'original_price': originalPrice,
|
||||
'negotiated_price': negotiatedPrice,
|
||||
'discount_percent': discountPercent,
|
||||
'subtotal': subtotal,
|
||||
'notes': notes,
|
||||
};
|
||||
|
||||
double get totalDiscount => originalPrice * quantity - subtotal;
|
||||
}
|
||||
65
lib/features/quotes/data/models/quote_item_model.g.dart
Normal file
65
lib/features/quotes/data/models/quote_item_model.g.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'quote_item_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class QuoteItemModelAdapter extends TypeAdapter<QuoteItemModel> {
|
||||
@override
|
||||
final typeId = 17;
|
||||
|
||||
@override
|
||||
QuoteItemModel read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return QuoteItemModel(
|
||||
quoteItemId: fields[0] as String,
|
||||
quoteId: fields[1] as String,
|
||||
productId: fields[2] as String,
|
||||
quantity: (fields[3] as num).toDouble(),
|
||||
originalPrice: (fields[4] as num).toDouble(),
|
||||
negotiatedPrice: (fields[5] as num).toDouble(),
|
||||
discountPercent: (fields[6] as num).toDouble(),
|
||||
subtotal: (fields[7] as num).toDouble(),
|
||||
notes: fields[8] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, QuoteItemModel obj) {
|
||||
writer
|
||||
..writeByte(9)
|
||||
..writeByte(0)
|
||||
..write(obj.quoteItemId)
|
||||
..writeByte(1)
|
||||
..write(obj.quoteId)
|
||||
..writeByte(2)
|
||||
..write(obj.productId)
|
||||
..writeByte(3)
|
||||
..write(obj.quantity)
|
||||
..writeByte(4)
|
||||
..write(obj.originalPrice)
|
||||
..writeByte(5)
|
||||
..write(obj.negotiatedPrice)
|
||||
..writeByte(6)
|
||||
..write(obj.discountPercent)
|
||||
..writeByte(7)
|
||||
..write(obj.subtotal)
|
||||
..writeByte(8)
|
||||
..write(obj.notes);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is QuoteItemModelAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
69
lib/features/quotes/data/models/quote_model.dart
Normal file
69
lib/features/quotes/data/models/quote_model.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'dart:convert';
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:worker/core/constants/storage_constants.dart';
|
||||
import 'package:worker/core/database/models/enums.dart';
|
||||
|
||||
part 'quote_model.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.quoteModel)
|
||||
class QuoteModel extends HiveObject {
|
||||
QuoteModel({required this.quoteId, required this.quoteNumber, required this.userId, required this.status, required this.totalAmount, required this.discountAmount, required this.finalAmount, this.projectName, this.deliveryAddress, this.paymentTerms, this.notes, this.validUntil, this.convertedOrderId, this.erpnextQuotation, required this.createdAt, this.updatedAt});
|
||||
|
||||
@HiveField(0) final String quoteId;
|
||||
@HiveField(1) final String quoteNumber;
|
||||
@HiveField(2) final String userId;
|
||||
@HiveField(3) final QuoteStatus status;
|
||||
@HiveField(4) final double totalAmount;
|
||||
@HiveField(5) final double discountAmount;
|
||||
@HiveField(6) final double finalAmount;
|
||||
@HiveField(7) final String? projectName;
|
||||
@HiveField(8) final String? deliveryAddress;
|
||||
@HiveField(9) final String? paymentTerms;
|
||||
@HiveField(10) final String? notes;
|
||||
@HiveField(11) final DateTime? validUntil;
|
||||
@HiveField(12) final String? convertedOrderId;
|
||||
@HiveField(13) final String? erpnextQuotation;
|
||||
@HiveField(14) final DateTime createdAt;
|
||||
@HiveField(15) final DateTime? updatedAt;
|
||||
|
||||
factory QuoteModel.fromJson(Map<String, dynamic> json) => QuoteModel(
|
||||
quoteId: json['quote_id'] as String,
|
||||
quoteNumber: json['quote_number'] as String,
|
||||
userId: json['user_id'] as String,
|
||||
status: QuoteStatus.values.firstWhere((e) => e.name == json['status']),
|
||||
totalAmount: (json['total_amount'] as num).toDouble(),
|
||||
discountAmount: (json['discount_amount'] as num).toDouble(),
|
||||
finalAmount: (json['final_amount'] as num).toDouble(),
|
||||
projectName: json['project_name'] as String?,
|
||||
deliveryAddress: json['delivery_address'] != null ? jsonEncode(json['delivery_address']) : null,
|
||||
paymentTerms: json['payment_terms'] as String?,
|
||||
notes: json['notes'] as String?,
|
||||
validUntil: json['valid_until'] != null ? DateTime.parse(json['valid_until']?.toString() ?? '') : null,
|
||||
convertedOrderId: json['converted_order_id'] as String?,
|
||||
erpnextQuotation: json['erpnext_quotation'] as String?,
|
||||
createdAt: DateTime.parse(json['created_at']?.toString() ?? ''),
|
||||
updatedAt: json['updated_at'] != null ? DateTime.parse(json['updated_at']?.toString() ?? '') : null,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'quote_id': quoteId,
|
||||
'quote_number': quoteNumber,
|
||||
'user_id': userId,
|
||||
'status': status.name,
|
||||
'total_amount': totalAmount,
|
||||
'discount_amount': discountAmount,
|
||||
'final_amount': finalAmount,
|
||||
'project_name': projectName,
|
||||
'delivery_address': deliveryAddress != null ? jsonDecode(deliveryAddress!) : null,
|
||||
'payment_terms': paymentTerms,
|
||||
'notes': notes,
|
||||
'valid_until': validUntil?.toIso8601String(),
|
||||
'converted_order_id': convertedOrderId,
|
||||
'erpnext_quotation': erpnextQuotation,
|
||||
'created_at': createdAt.toIso8601String(),
|
||||
'updated_at': updatedAt?.toIso8601String(),
|
||||
};
|
||||
|
||||
bool get isExpired => validUntil != null && DateTime.now().isAfter(validUntil!);
|
||||
bool get isConverted => convertedOrderId != null;
|
||||
}
|
||||
86
lib/features/quotes/data/models/quote_model.g.dart
Normal file
86
lib/features/quotes/data/models/quote_model.g.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'quote_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class QuoteModelAdapter extends TypeAdapter<QuoteModel> {
|
||||
@override
|
||||
final typeId = 16;
|
||||
|
||||
@override
|
||||
QuoteModel read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return QuoteModel(
|
||||
quoteId: fields[0] as String,
|
||||
quoteNumber: fields[1] as String,
|
||||
userId: fields[2] as String,
|
||||
status: fields[3] as QuoteStatus,
|
||||
totalAmount: (fields[4] as num).toDouble(),
|
||||
discountAmount: (fields[5] as num).toDouble(),
|
||||
finalAmount: (fields[6] as num).toDouble(),
|
||||
projectName: fields[7] as String?,
|
||||
deliveryAddress: fields[8] as String?,
|
||||
paymentTerms: fields[9] as String?,
|
||||
notes: fields[10] as String?,
|
||||
validUntil: fields[11] as DateTime?,
|
||||
convertedOrderId: fields[12] as String?,
|
||||
erpnextQuotation: fields[13] as String?,
|
||||
createdAt: fields[14] as DateTime,
|
||||
updatedAt: fields[15] as DateTime?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, QuoteModel obj) {
|
||||
writer
|
||||
..writeByte(16)
|
||||
..writeByte(0)
|
||||
..write(obj.quoteId)
|
||||
..writeByte(1)
|
||||
..write(obj.quoteNumber)
|
||||
..writeByte(2)
|
||||
..write(obj.userId)
|
||||
..writeByte(3)
|
||||
..write(obj.status)
|
||||
..writeByte(4)
|
||||
..write(obj.totalAmount)
|
||||
..writeByte(5)
|
||||
..write(obj.discountAmount)
|
||||
..writeByte(6)
|
||||
..write(obj.finalAmount)
|
||||
..writeByte(7)
|
||||
..write(obj.projectName)
|
||||
..writeByte(8)
|
||||
..write(obj.deliveryAddress)
|
||||
..writeByte(9)
|
||||
..write(obj.paymentTerms)
|
||||
..writeByte(10)
|
||||
..write(obj.notes)
|
||||
..writeByte(11)
|
||||
..write(obj.validUntil)
|
||||
..writeByte(12)
|
||||
..write(obj.convertedOrderId)
|
||||
..writeByte(13)
|
||||
..write(obj.erpnextQuotation)
|
||||
..writeByte(14)
|
||||
..write(obj.createdAt)
|
||||
..writeByte(15)
|
||||
..write(obj.updatedAt);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is QuoteModelAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
Reference in New Issue
Block a user