Null safety
This commit is contained in:
parent
eecabc6e6a
commit
ac3e430c35
|
|
@ -318,9 +318,8 @@ abstract class InvoiceEntity extends Object
|
|||
..documents.clear()
|
||||
..lineItems.replace(lineItems
|
||||
.where((lineItem) =>
|
||||
lineItem!.typeId != InvoiceItemEntity.TYPE_UNPAID_FEE)
|
||||
.map((lineItem) => lineItem!
|
||||
.rebuild((b) => b..typeId = InvoiceItemEntity.TYPE_STANDARD))
|
||||
lineItem.typeId != InvoiceItemEntity.TYPE_UNPAID_FEE)
|
||||
.map((lineItem) => lineItem.rebuild((b) => b..typeId = InvoiceItemEntity.TYPE_STANDARD))
|
||||
.toList())
|
||||
..invitations.replace(
|
||||
invitations
|
||||
|
|
@ -561,7 +560,7 @@ abstract class InvoiceEntity extends Object
|
|||
|
||||
@override
|
||||
@BuiltValueField(wireName: 'line_items')
|
||||
BuiltList<InvoiceItemEntity?> get lineItems;
|
||||
BuiltList<InvoiceItemEntity> get lineItems;
|
||||
|
||||
BuiltList<InvitationEntity> get invitations;
|
||||
|
||||
|
|
@ -645,11 +644,11 @@ abstract class InvoiceEntity extends Object
|
|||
kMillisecondsToRefreshActivities;
|
||||
}
|
||||
|
||||
bool get hasTasks => lineItems.any((item) => item!.isTask);
|
||||
bool get hasTasks => lineItems.any((item) => item.isTask);
|
||||
|
||||
bool get hasProducts => lineItems.any((item) => !item!.isTask);
|
||||
bool get hasProducts => lineItems.any((item) => !item.isTask);
|
||||
|
||||
bool get hasExpenses => lineItems.any((item) => item!.isExpense);
|
||||
bool get hasExpenses => lineItems.any((item) => item.isExpense);
|
||||
|
||||
@override
|
||||
bool get isEditable {
|
||||
|
|
@ -915,7 +914,7 @@ abstract class InvoiceEntity extends Object
|
|||
@override
|
||||
bool matchesFilter(String? filter) {
|
||||
for (var i = 0; i < lineItems.length; i++) {
|
||||
final lineItem = lineItems[i]!;
|
||||
final lineItem = lineItems[i];
|
||||
final isMatch = matchesStrings(
|
||||
haystacks: [
|
||||
lineItem.productKey,
|
||||
|
|
@ -1409,7 +1408,7 @@ abstract class InvoiceEntity extends Object
|
|||
}
|
||||
|
||||
for (final item in lineItems) {
|
||||
final itemTaxable = getItemTaxable(item!, amount, precision);
|
||||
final itemTaxable = getItemTaxable(item, amount, precision);
|
||||
|
||||
if (item.taxName1.isNotEmpty) {
|
||||
final itemTaxAmount = calculateAmount(itemTaxable, item.taxRate1);
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ class _$InvoiceEntitySerializer implements StructuredSerializer<InvoiceEntity> {
|
|||
'line_items',
|
||||
serializers.serialize(object.lineItems,
|
||||
specifiedType: const FullType(
|
||||
BuiltList, const [const FullType.nullable(InvoiceItemEntity)])),
|
||||
BuiltList, const [const FullType(InvoiceItemEntity)])),
|
||||
'invitations',
|
||||
serializers.serialize(object.invitations,
|
||||
specifiedType: const FullType(
|
||||
|
|
@ -689,9 +689,9 @@ class _$InvoiceEntitySerializer implements StructuredSerializer<InvoiceEntity> {
|
|||
break;
|
||||
case 'line_items':
|
||||
result.lineItems.replace(serializers.deserialize(value,
|
||||
specifiedType: const FullType(BuiltList, const [
|
||||
const FullType.nullable(InvoiceItemEntity)
|
||||
]))! as BuiltList<Object?>);
|
||||
specifiedType: const FullType(
|
||||
BuiltList, const [const FullType(InvoiceItemEntity)]))!
|
||||
as BuiltList<Object?>);
|
||||
break;
|
||||
case 'invitations':
|
||||
result.invitations.replace(serializers.deserialize(value,
|
||||
|
|
@ -1571,7 +1571,7 @@ class _$InvoiceEntity extends InvoiceEntity {
|
|||
@override
|
||||
final BuiltList<InvoiceScheduleEntity>? recurringDates;
|
||||
@override
|
||||
final BuiltList<InvoiceItemEntity?> lineItems;
|
||||
final BuiltList<InvoiceItemEntity> lineItems;
|
||||
@override
|
||||
final BuiltList<InvitationEntity> invitations;
|
||||
@override
|
||||
|
|
@ -2313,10 +2313,10 @@ class InvoiceEntityBuilder
|
|||
set recurringDates(ListBuilder<InvoiceScheduleEntity>? recurringDates) =>
|
||||
_$this._recurringDates = recurringDates;
|
||||
|
||||
ListBuilder<InvoiceItemEntity?>? _lineItems;
|
||||
ListBuilder<InvoiceItemEntity?> get lineItems =>
|
||||
_$this._lineItems ??= new ListBuilder<InvoiceItemEntity?>();
|
||||
set lineItems(ListBuilder<InvoiceItemEntity?>? lineItems) =>
|
||||
ListBuilder<InvoiceItemEntity>? _lineItems;
|
||||
ListBuilder<InvoiceItemEntity> get lineItems =>
|
||||
_$this._lineItems ??= new ListBuilder<InvoiceItemEntity>();
|
||||
set lineItems(ListBuilder<InvoiceItemEntity>? lineItems) =>
|
||||
_$this._lineItems = lineItems;
|
||||
|
||||
ListBuilder<InvitationEntity>? _invitations;
|
||||
|
|
|
|||
|
|
@ -511,9 +511,8 @@ Serializers _$serializers = (new Serializers().toBuilder()
|
|||
BuiltList, const [const FullType(InvoiceScheduleEntity)]),
|
||||
() => new ListBuilder<InvoiceScheduleEntity>())
|
||||
..addBuilderFactory(
|
||||
const FullType(
|
||||
BuiltList, const [const FullType.nullable(InvoiceItemEntity)]),
|
||||
() => new ListBuilder<InvoiceItemEntity?>())
|
||||
const FullType(BuiltList, const [const FullType(InvoiceItemEntity)]),
|
||||
() => new ListBuilder<InvoiceItemEntity>())
|
||||
..addBuilderFactory(
|
||||
const FullType(BuiltList, const [const FullType(InvitationEntity)]),
|
||||
() => new ListBuilder<InvitationEntity>())
|
||||
|
|
|
|||
|
|
@ -189,10 +189,13 @@ class AddCreditItems implements PersistUI {
|
|||
}
|
||||
|
||||
class UpdateCreditItem implements PersistUI {
|
||||
UpdateCreditItem({this.index, this.creditItem});
|
||||
UpdateCreditItem({
|
||||
required this.index,
|
||||
required this.creditItem,
|
||||
});
|
||||
|
||||
final int? index;
|
||||
final InvoiceItemEntity? creditItem;
|
||||
final int index;
|
||||
final InvoiceItemEntity creditItem;
|
||||
}
|
||||
|
||||
class DeleteCreditItem implements PersistUI {
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@ Middleware<AppState> _saveCredit(CreditRepository repository) {
|
|||
// remove any empty line items
|
||||
final updatedCredit = action.credit.rebuild((b) => b
|
||||
..lineItems
|
||||
.replace(action.credit.lineItems.where((item) => !item!.isEmpty)));
|
||||
.replace(action.credit.lineItems.where((item) => !item.isEmpty)));
|
||||
|
||||
repository
|
||||
.saveData(store.state.credentials, updatedCredit, action.action)
|
||||
|
|
|
|||
|
|
@ -178,10 +178,10 @@ InvoiceEntity? _removeCreditItem(
|
|||
|
||||
InvoiceEntity? _updateCreditItem(
|
||||
InvoiceEntity? credit, UpdateCreditItem action) {
|
||||
if (credit!.lineItems.length <= action.index!) {
|
||||
if (credit!.lineItems.length <= action.index) {
|
||||
return credit;
|
||||
}
|
||||
return credit.rebuild((b) => b..lineItems[action.index!] = action.creditItem);
|
||||
return credit.rebuild((b) => b..lineItems[action.index] = action.creditItem);
|
||||
}
|
||||
|
||||
final creditListReducer = combineReducers<ListUIState>([
|
||||
|
|
|
|||
|
|
@ -193,10 +193,13 @@ class AddInvoiceItems implements PersistUI {
|
|||
}
|
||||
|
||||
class UpdateInvoiceItem implements PersistUI {
|
||||
UpdateInvoiceItem({this.index, this.invoiceItem});
|
||||
UpdateInvoiceItem({
|
||||
required this.index,
|
||||
required this.invoiceItem,
|
||||
});
|
||||
|
||||
final int? index;
|
||||
final InvoiceItemEntity? invoiceItem;
|
||||
final int index;
|
||||
final InvoiceItemEntity invoiceItem;
|
||||
}
|
||||
|
||||
class DeleteInvoiceItem implements PersistUI {
|
||||
|
|
@ -700,7 +703,8 @@ void handleInvoiceAction(BuildContext? context, List<BaseEntity?> invoices,
|
|||
title: Text(
|
||||
invoiceIds.length == 1
|
||||
? localization.emailInvoice
|
||||
: localization.emailCountInvoices.replaceFirst(':count', '${invoiceIds.length}'),
|
||||
: localization.emailCountInvoices
|
||||
.replaceFirst(':count', '${invoiceIds.length}'),
|
||||
),
|
||||
children: templates.keys
|
||||
.map((template) => SimpleDialogOption(
|
||||
|
|
|
|||
|
|
@ -381,7 +381,7 @@ Middleware<AppState> _saveInvoice(InvoiceRepository repository) {
|
|||
// remove any empty line items
|
||||
final updatedInvoice = action.invoice.rebuild((b) => b
|
||||
..lineItems
|
||||
.replace(action.invoice.lineItems.where((item) => !item!.isEmpty)));
|
||||
.replace(action.invoice.lineItems.where((item) => !item.isEmpty)));
|
||||
|
||||
repository
|
||||
.saveData(
|
||||
|
|
|
|||
|
|
@ -182,11 +182,11 @@ InvoiceEntity? _removeInvoiceItem(
|
|||
|
||||
InvoiceEntity? _updateInvoiceItem(
|
||||
InvoiceEntity? invoice, UpdateInvoiceItem action) {
|
||||
if (invoice!.lineItems.length <= action.index!) {
|
||||
if (invoice!.lineItems.length <= action.index) {
|
||||
return invoice;
|
||||
}
|
||||
return invoice
|
||||
.rebuild((b) => b..lineItems[action.index!] = action.invoiceItem);
|
||||
.rebuild((b) => b..lineItems[action.index] = action.invoiceItem);
|
||||
}
|
||||
|
||||
final invoiceListReducer = combineReducers<ListUIState>([
|
||||
|
|
|
|||
|
|
@ -488,10 +488,13 @@ class AddPurchaseOrderItems implements PersistUI {
|
|||
}
|
||||
|
||||
class UpdatePurchaseOrderItem implements PersistUI {
|
||||
UpdatePurchaseOrderItem({this.index, this.purchaseOrderItem});
|
||||
UpdatePurchaseOrderItem({
|
||||
required this.index,
|
||||
required this.purchaseOrderItem,
|
||||
});
|
||||
|
||||
final int? index;
|
||||
final InvoiceItemEntity? purchaseOrderItem;
|
||||
final int index;
|
||||
final InvoiceItemEntity purchaseOrderItem;
|
||||
}
|
||||
|
||||
class DeletePurchaseOrderItem implements PersistUI {
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ Middleware<AppState> _savePurchaseOrder(PurchaseOrderRepository repository) {
|
|||
// remove any empty line items
|
||||
final updatedPurchaseOrder = action.purchaseOrder.rebuild((b) => b
|
||||
..lineItems.replace(
|
||||
action.purchaseOrder.lineItems.where((item) => !item!.isEmpty)));
|
||||
action.purchaseOrder.lineItems.where((item) => !item.isEmpty)));
|
||||
|
||||
repository
|
||||
.saveData(
|
||||
|
|
|
|||
|
|
@ -206,11 +206,11 @@ InvoiceEntity? _removePurchaseOrderItem(
|
|||
|
||||
InvoiceEntity? _updatePurchaseOrderItem(
|
||||
InvoiceEntity? purchaseOrder, UpdatePurchaseOrderItem action) {
|
||||
if (purchaseOrder!.lineItems.length <= action.index!) {
|
||||
if (purchaseOrder!.lineItems.length <= action.index) {
|
||||
return purchaseOrder;
|
||||
}
|
||||
return purchaseOrder
|
||||
.rebuild((b) => b..lineItems[action.index!] = action.purchaseOrderItem);
|
||||
.rebuild((b) => b..lineItems[action.index] = action.purchaseOrderItem);
|
||||
}
|
||||
|
||||
final purchaseOrderListReducer = combineReducers<ListUIState>([
|
||||
|
|
|
|||
|
|
@ -190,10 +190,13 @@ class AddQuoteItems implements PersistUI {
|
|||
}
|
||||
|
||||
class UpdateQuoteItem implements PersistUI {
|
||||
UpdateQuoteItem({this.index, this.quoteItem});
|
||||
UpdateQuoteItem({
|
||||
required this.index,
|
||||
required this.quoteItem,
|
||||
});
|
||||
|
||||
final int? index;
|
||||
final InvoiceItemEntity? quoteItem;
|
||||
final int index;
|
||||
final InvoiceItemEntity quoteItem;
|
||||
}
|
||||
|
||||
class DeleteQuoteItem implements PersistUI {
|
||||
|
|
@ -553,7 +556,8 @@ Future handleQuoteAction(BuildContext context, List<BaseEntity?> quotes,
|
|||
break;
|
||||
case EntityAction.approve:
|
||||
final message = quoteIds.length > 1
|
||||
? localization!.approvedQuotes.replaceFirst(':value', ':count')
|
||||
? localization!.approvedQuotes
|
||||
.replaceFirst(':value', ':count')
|
||||
.replaceFirst(':count', quoteIds.length.toString())
|
||||
: localization!.approveQuote;
|
||||
store.dispatch(
|
||||
|
|
|
|||
|
|
@ -329,7 +329,7 @@ Middleware<AppState> _saveQuote(QuoteRepository repository) {
|
|||
// remove any empty line items
|
||||
final updatedQuote = action.quote.rebuild((b) => b
|
||||
..lineItems
|
||||
.replace(action.quote.lineItems.where((item) => !item!.isEmpty)));
|
||||
.replace(action.quote.lineItems.where((item) => !item.isEmpty)));
|
||||
|
||||
repository
|
||||
.saveData(store.state.credentials, updatedQuote, action.action)
|
||||
|
|
|
|||
|
|
@ -177,10 +177,10 @@ InvoiceEntity? _removeQuoteItem(InvoiceEntity? quote, DeleteQuoteItem action) {
|
|||
}
|
||||
|
||||
InvoiceEntity? _updateQuoteItem(InvoiceEntity? quote, UpdateQuoteItem action) {
|
||||
if (quote!.lineItems.length <= action.index!) {
|
||||
if (quote!.lineItems.length <= action.index) {
|
||||
return quote;
|
||||
}
|
||||
return quote.rebuild((b) => b..lineItems[action.index!] = action.quoteItem);
|
||||
return quote.rebuild((b) => b..lineItems[action.index] = action.quoteItem);
|
||||
}
|
||||
|
||||
final quoteListReducer = combineReducers<ListUIState>([
|
||||
|
|
|
|||
|
|
@ -223,10 +223,13 @@ class AddRecurringInvoiceItems implements PersistUI {
|
|||
}
|
||||
|
||||
class UpdateRecurringInvoiceItem implements PersistUI {
|
||||
UpdateRecurringInvoiceItem({this.index, this.item});
|
||||
UpdateRecurringInvoiceItem({
|
||||
required this.index,
|
||||
required this.item,
|
||||
});
|
||||
|
||||
final int? index;
|
||||
final InvoiceItemEntity? item;
|
||||
final int index;
|
||||
final InvoiceItemEntity item;
|
||||
}
|
||||
|
||||
class DeleteRecurringInvoiceItem implements PersistUI {
|
||||
|
|
|
|||
|
|
@ -335,7 +335,7 @@ Middleware<AppState> _saveRecurringInvoice(
|
|||
// remove any empty line items
|
||||
final updatedInvoice = action.recurringInvoice!.rebuild((b) => b
|
||||
..lineItems.replace(
|
||||
action.recurringInvoice!.lineItems.where((item) => !item!.isEmpty)));
|
||||
action.recurringInvoice!.lineItems.where((item) => !item.isEmpty)));
|
||||
|
||||
repository
|
||||
.saveData(store.state.credentials, updatedInvoice,
|
||||
|
|
|
|||
|
|
@ -217,11 +217,11 @@ InvoiceEntity? _removeRecurringInvoiceItem(
|
|||
|
||||
InvoiceEntity? _updateRecurringInvoiceItem(
|
||||
InvoiceEntity? recurringInvoice, UpdateRecurringInvoiceItem action) {
|
||||
if (recurringInvoice!.lineItems.length <= action.index!) {
|
||||
if (recurringInvoice!.lineItems.length <= action.index) {
|
||||
return recurringInvoice;
|
||||
}
|
||||
return recurringInvoice
|
||||
.rebuild((b) => b..lineItems[action.index!] = action.item);
|
||||
.rebuild((b) => b..lineItems[action.index] = action.item);
|
||||
}
|
||||
|
||||
final recurringInvoiceListReducer = combineReducers<ListUIState>([
|
||||
|
|
|
|||
|
|
@ -158,8 +158,8 @@ class _CreditEditState extends State<CreditEdit>
|
|||
invoice: invoice,
|
||||
showTasksAndExpenses: false,
|
||||
excluded: invoice.lineItems
|
||||
.where((item) => item!.isTask || item.isExpense)
|
||||
.map((item) => item!.isTask
|
||||
.where((item) => item.isTask || item.isExpense)
|
||||
.map((item) => item.isTask
|
||||
? viewModel.state!.taskState.map[item.taskId]
|
||||
: viewModel.state!.expenseState.map[item.expenseId])
|
||||
.toList(),
|
||||
|
|
|
|||
|
|
@ -173,8 +173,8 @@ class _InvoiceEditState extends State<InvoiceEdit>
|
|||
invoice: invoice,
|
||||
showTasksAndExpenses: true,
|
||||
excluded: invoice.lineItems
|
||||
.where((item) => item!.isTask || item.isExpense)
|
||||
.map((item) => item!.isTask
|
||||
.where((item) => item.isTask || item.isExpense)
|
||||
.map((item) => item.isTask
|
||||
? viewModel.state!.taskState.map[item.taskId]
|
||||
: viewModel.state!.expenseState.map[item.expenseId])
|
||||
.toList(),
|
||||
|
|
|
|||
|
|
@ -243,11 +243,11 @@ class InvoiceEditDesktopState extends State<InvoiceEditDesktop>
|
|||
|
||||
final countProducts = invoice.lineItems
|
||||
.where((item) =>
|
||||
!item!.isEmpty && item.typeId != InvoiceItemEntity.TYPE_TASK)
|
||||
!item.isEmpty && item.typeId != InvoiceItemEntity.TYPE_TASK)
|
||||
.length;
|
||||
final countTasks = invoice.lineItems
|
||||
.where((item) =>
|
||||
!item!.isEmpty && item.typeId == InvoiceItemEntity.TYPE_TASK)
|
||||
!item.isEmpty && item.typeId == InvoiceItemEntity.TYPE_TASK)
|
||||
.length;
|
||||
|
||||
final showTasksTable = (invoice.hasTasks || company.showTasksTable) &&
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class _InvoiceEditItemsState extends State<InvoiceEditItems> {
|
|||
viewModel: viewModel,
|
||||
entityViewModel: widget.entityViewModel,
|
||||
key: ValueKey('__${lineItemIndex}__'),
|
||||
invoiceItem: invoice.lineItems[lineItemIndex!]!,
|
||||
invoiceItem: invoice.lineItems[lineItemIndex!],
|
||||
index: lineItemIndex,
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -82,18 +82,18 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
final company = state.company;
|
||||
|
||||
final includedLineItems = lineItems.where((lineItem) {
|
||||
return (lineItem!.typeId == InvoiceItemEntity.TYPE_TASK &&
|
||||
return (lineItem.typeId == InvoiceItemEntity.TYPE_TASK &&
|
||||
widget.isTasks) ||
|
||||
(lineItem.typeId != InvoiceItemEntity.TYPE_TASK && !widget.isTasks) ||
|
||||
lineItem.isEmpty;
|
||||
}).toList();
|
||||
|
||||
final hasTax1 = company.enableFirstItemTaxRate ||
|
||||
includedLineItems.any((item) => item!.taxName1.isNotEmpty);
|
||||
includedLineItems.any((item) => item.taxName1.isNotEmpty);
|
||||
final hasTax2 = company.enableSecondItemTaxRate ||
|
||||
includedLineItems.any((item) => item!.taxName2.isNotEmpty);
|
||||
includedLineItems.any((item) => item.taxName2.isNotEmpty);
|
||||
final hasTax3 = company.enableThirdItemTaxRate ||
|
||||
includedLineItems.any((item) => item!.taxName3.isNotEmpty);
|
||||
includedLineItems.any((item) => item.taxName3.isNotEmpty);
|
||||
final hasAnyTax = hasTax1 || hasTax2 || hasTax3;
|
||||
|
||||
final customField1 =
|
||||
|
|
@ -292,7 +292,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
state.staticState.currencyMap[client.currencyId]?.precision ?? 2;
|
||||
final lineItems = invoice.lineItems.toList();
|
||||
final includedLineItems = lineItems.where((lineItem) {
|
||||
return (lineItem!.typeId == InvoiceItemEntity.TYPE_TASK &&
|
||||
return (lineItem.typeId == InvoiceItemEntity.TYPE_TASK &&
|
||||
widget.isTasks) ||
|
||||
(lineItem.typeId != InvoiceItemEntity.TYPE_TASK && !widget.isTasks) ||
|
||||
lineItem.isEmpty;
|
||||
|
|
@ -429,7 +429,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
buildDefaultDragHandles: false,
|
||||
itemCount: lineItems.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = lineItems[index]!;
|
||||
final item = lineItems[index];
|
||||
|
||||
if ((item.typeId == InvoiceItemEntity.TYPE_TASK &&
|
||||
!widget.isTasks) ||
|
||||
|
|
@ -577,7 +577,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
);
|
||||
}
|
||||
|
||||
if (lineItems.where((item) => item!.isEmpty).isEmpty) {
|
||||
if (lineItems.where((item) => item.isEmpty).isEmpty) {
|
||||
lineItems.add(InvoiceItemEntity(
|
||||
quantity: company.defaultQuantity || !company.enableProductQuantity
|
||||
? 1
|
||||
|
|
@ -594,7 +594,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
color: tableFontColor.isNotEmpty
|
||||
? convertHexStringToColor(tableFontColor)
|
||||
: null,
|
||||
onPressed: includedLineItems.where((item) => !item!.isEmpty).length < 2
|
||||
onPressed: includedLineItems.where((item) => !item.isEmpty).length < 2
|
||||
? null
|
||||
: () {
|
||||
setState(() => _isReordering = !_isReordering);
|
||||
|
|
@ -623,14 +623,14 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
: BoxDecoration(),
|
||||
),
|
||||
for (var index = 0; index < lineItems.length; index++)
|
||||
if ((lineItems[index]!.typeId == InvoiceItemEntity.TYPE_TASK &&
|
||||
if ((lineItems[index].typeId == InvoiceItemEntity.TYPE_TASK &&
|
||||
widget.isTasks) ||
|
||||
(lineItems[index]!.typeId != InvoiceItemEntity.TYPE_TASK &&
|
||||
(lineItems[index].typeId != InvoiceItemEntity.TYPE_TASK &&
|
||||
!widget.isTasks) ||
|
||||
lineItems[index]!.isEmpty)
|
||||
lineItems[index].isEmpty)
|
||||
TableRow(
|
||||
key: ValueKey(
|
||||
'__line_item_${index}_${lineItems[index]!.createdAt}__'),
|
||||
'__line_item_${index}_${lineItems[index].createdAt}__'),
|
||||
children: [
|
||||
..._columns.map((column) {
|
||||
if (column == COLUMN_ITEM) {
|
||||
|
|
@ -647,7 +647,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
key: ValueKey('__line_item_${index}_name__'),
|
||||
textEditingController: _textEditingController,
|
||||
initialValue: TextEditingValue(
|
||||
text: lineItems[index]!.productKey),
|
||||
text: lineItems[index].productKey),
|
||||
optionsBuilder:
|
||||
(TextEditingValue textEditingValue) {
|
||||
final options = productIds
|
||||
|
|
@ -672,8 +672,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
|
||||
if (options.length == 1 &&
|
||||
options[0].productKey.toLowerCase() ==
|
||||
lineItems[index]!
|
||||
.productKey
|
||||
lineItems[index].productKey
|
||||
.toLowerCase()) {
|
||||
return <ProductEntity>[];
|
||||
}
|
||||
|
|
@ -706,7 +705,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
}
|
||||
|
||||
final updatedItem = company.fillProducts
|
||||
? item!.rebuild((b) => b
|
||||
? item.rebuild((b) => b
|
||||
..productKey = product.productKey
|
||||
..notes = item.isTask
|
||||
? item.notes
|
||||
|
|
@ -756,7 +755,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
product.taxName3.isNotEmpty
|
||||
? product.taxRate3
|
||||
: item.taxRate3)
|
||||
: item!.rebuild((b) =>
|
||||
: item.rebuild((b) =>
|
||||
b..productKey = product.productKey);
|
||||
|
||||
_onChanged(updatedItem, index, debounce: false);
|
||||
|
|
@ -777,7 +776,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
},
|
||||
onChanged: (value) {
|
||||
_onChanged(
|
||||
lineItems[index]!.rebuild(
|
||||
lineItems[index].rebuild(
|
||||
(b) => b..productKey = value),
|
||||
index);
|
||||
},
|
||||
|
|
@ -865,10 +864,9 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
key: ValueKey(
|
||||
'__line_item_${index}_description__'),
|
||||
autofocus: _autocompleteFocusIndex == index,
|
||||
initialValue: lineItems[index]!.notes,
|
||||
initialValue: lineItems[index].notes,
|
||||
onChanged: (value) => _onChanged(
|
||||
lineItems[index]!
|
||||
.rebuild((b) => b..notes = value),
|
||||
lineItems[index].rebuild((b) => b..notes = value),
|
||||
index),
|
||||
),
|
||||
),
|
||||
|
|
@ -882,11 +880,10 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
const EdgeInsets.only(right: kTableColumnGap),
|
||||
child: CustomField(
|
||||
field: customField1,
|
||||
value: lineItems[index]!.customValue1,
|
||||
value: lineItems[index].customValue1,
|
||||
hideFieldLabel: true,
|
||||
onChanged: (value) => _onChanged(
|
||||
lineItems[index]!
|
||||
.rebuild((b) => b..customValue1 = value),
|
||||
lineItems[index].rebuild((b) => b..customValue1 = value),
|
||||
index),
|
||||
onSavePressed:
|
||||
widget.entityViewModel.onSavePressed,
|
||||
|
|
@ -902,11 +899,10 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
const EdgeInsets.only(right: kTableColumnGap),
|
||||
child: CustomField(
|
||||
field: customField2,
|
||||
value: lineItems[index]!.customValue2,
|
||||
value: lineItems[index].customValue2,
|
||||
hideFieldLabel: true,
|
||||
onChanged: (value) => _onChanged(
|
||||
lineItems[index]!
|
||||
.rebuild((b) => b..customValue2 = value),
|
||||
lineItems[index].rebuild((b) => b..customValue2 = value),
|
||||
index),
|
||||
onSavePressed:
|
||||
widget.entityViewModel.onSavePressed,
|
||||
|
|
@ -922,11 +918,10 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
const EdgeInsets.only(right: kTableColumnGap),
|
||||
child: CustomField(
|
||||
field: customField3,
|
||||
value: lineItems[index]!.customValue3,
|
||||
value: lineItems[index].customValue3,
|
||||
hideFieldLabel: true,
|
||||
onChanged: (value) => _onChanged(
|
||||
lineItems[index]!
|
||||
.rebuild((b) => b..customValue3 = value),
|
||||
lineItems[index].rebuild((b) => b..customValue3 = value),
|
||||
index),
|
||||
onSavePressed:
|
||||
widget.entityViewModel.onSavePressed,
|
||||
|
|
@ -942,11 +937,10 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
const EdgeInsets.only(right: kTableColumnGap),
|
||||
child: CustomField(
|
||||
field: customField4,
|
||||
value: lineItems[index]!.customValue4,
|
||||
value: lineItems[index].customValue4,
|
||||
hideFieldLabel: true,
|
||||
onChanged: (value) => _onChanged(
|
||||
lineItems[index]!
|
||||
.rebuild((b) => b..customValue4 = value),
|
||||
lineItems[index].rebuild((b) => b..customValue4 = value),
|
||||
index),
|
||||
onSavePressed:
|
||||
widget.entityViewModel.onSavePressed,
|
||||
|
|
@ -954,7 +948,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
),
|
||||
);
|
||||
} else if (column == COLUMN_TAX_CATEGORY &&
|
||||
!lineItems[index]!.hasOverrideTax) {
|
||||
!lineItems[index].hasOverrideTax) {
|
||||
return Focus(
|
||||
onFocusChange: (hasFocus) => _onFocusChange(),
|
||||
skipTraversal: true,
|
||||
|
|
@ -963,9 +957,9 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
const EdgeInsets.only(right: kTableColumnGap),
|
||||
child: AppDropdownButton<String>(
|
||||
labelText: '',
|
||||
value: lineItems[index]!.taxCategoryId,
|
||||
value: lineItems[index].taxCategoryId,
|
||||
onChanged: (dynamic value) => _onChanged(
|
||||
lineItems[index]!.rebuild(
|
||||
lineItems[index].rebuild(
|
||||
(b) => b..taxCategoryId = value),
|
||||
index),
|
||||
items: kTaxCategories.keys
|
||||
|
|
@ -980,7 +974,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
);
|
||||
} else if (column == COLUMN_TAX1 ||
|
||||
(column == COLUMN_TAX_CATEGORY &&
|
||||
lineItems[index]!.hasOverrideTax)) {
|
||||
lineItems[index].hasOverrideTax)) {
|
||||
Widget child = Focus(
|
||||
onFocusChange: (hasFocus) => _onFocusChange(),
|
||||
skipTraversal: true,
|
||||
|
|
@ -989,27 +983,27 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
const EdgeInsets.only(right: kTableColumnGap),
|
||||
child: TaxRateDropdown(
|
||||
onSelected: (taxRate) => _onChanged(
|
||||
lineItems[index]!.rebuild((b) => b
|
||||
lineItems[index].rebuild((b) => b
|
||||
..taxName1 = taxRate.name
|
||||
..taxRate1 = taxRate.rate),
|
||||
index,
|
||||
debounce: false,
|
||||
),
|
||||
labelText: null,
|
||||
initialTaxName: lineItems[index]!.taxName1,
|
||||
initialTaxRate: lineItems[index]!.taxRate1,
|
||||
initialTaxName: lineItems[index].taxName1,
|
||||
initialTaxRate: lineItems[index].taxRate1,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (lineItems[index]!.hasOverrideTax) {
|
||||
if (lineItems[index].hasOverrideTax) {
|
||||
child = Row(
|
||||
children: [
|
||||
Expanded(child: child),
|
||||
IconButton(
|
||||
visualDensity: VisualDensity.compact,
|
||||
onPressed: () => _onChanged(
|
||||
lineItems[index]!.rebuild((b) => b
|
||||
lineItems[index].rebuild((b) => b
|
||||
..taxName1 = ''
|
||||
..taxRate1 = 0
|
||||
..taxCategoryId = kTaxCategoryPhysical),
|
||||
|
|
@ -1029,15 +1023,15 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
const EdgeInsets.only(right: kTableColumnGap),
|
||||
child: TaxRateDropdown(
|
||||
onSelected: (taxRate) => _onChanged(
|
||||
lineItems[index]!.rebuild((b) => b
|
||||
lineItems[index].rebuild((b) => b
|
||||
..taxName2 = taxRate.name
|
||||
..taxRate2 = taxRate.rate),
|
||||
index,
|
||||
debounce: false,
|
||||
),
|
||||
labelText: null,
|
||||
initialTaxName: lineItems[index]!.taxName2,
|
||||
initialTaxRate: lineItems[index]!.taxRate2,
|
||||
initialTaxName: lineItems[index].taxName2,
|
||||
initialTaxRate: lineItems[index].taxRate2,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
@ -1050,15 +1044,15 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
const EdgeInsets.only(right: kTableColumnGap),
|
||||
child: TaxRateDropdown(
|
||||
onSelected: (taxRate) => _onChanged(
|
||||
lineItems[index]!.rebuild((b) => b
|
||||
lineItems[index].rebuild((b) => b
|
||||
..taxName3 = taxRate.name
|
||||
..taxRate3 = taxRate.rate),
|
||||
index,
|
||||
debounce: false,
|
||||
),
|
||||
labelText: null,
|
||||
initialTaxName: lineItems[index]!.taxName3,
|
||||
initialTaxRate: lineItems[index]!.taxRate3,
|
||||
initialTaxName: lineItems[index].taxName3,
|
||||
initialTaxRate: lineItems[index].taxRate3,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
@ -1073,7 +1067,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
key: ValueKey('__line_item_${index}_cost__'),
|
||||
textAlign: TextAlign.right,
|
||||
initialValue: formatNumber(
|
||||
lineItems[index]!.cost,
|
||||
lineItems[index].cost,
|
||||
context,
|
||||
formatNumberType: FormatNumberType.inputMoney,
|
||||
clientId: invoice.isPurchaseOrder
|
||||
|
|
@ -1084,7 +1078,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
: null,
|
||||
),
|
||||
onChanged: (value) => _onChanged(
|
||||
lineItems[index]!.rebuild(
|
||||
lineItems[index].rebuild(
|
||||
(b) => b..cost = parseDouble(value)),
|
||||
index,
|
||||
debounce: false,
|
||||
|
|
@ -1107,7 +1101,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
key: ValueKey('__line_item_${index}_quantity__'),
|
||||
textAlign: TextAlign.right,
|
||||
initialValue: formatNumber(
|
||||
lineItems[index]!.quantity,
|
||||
lineItems[index].quantity,
|
||||
context,
|
||||
formatNumberType: FormatNumberType.inputAmount,
|
||||
clientId: invoice.isPurchaseOrder
|
||||
|
|
@ -1118,7 +1112,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
: null,
|
||||
),
|
||||
onChanged: (value) => _onChanged(
|
||||
lineItems[index]!.rebuild(
|
||||
lineItems[index].rebuild(
|
||||
(b) => b..quantity = parseDouble(value)),
|
||||
index,
|
||||
debounce: false,
|
||||
|
|
@ -1141,7 +1135,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
key: ValueKey('__line_item_${index}_discount__'),
|
||||
textAlign: TextAlign.right,
|
||||
initialValue: formatNumber(
|
||||
lineItems[index]!.discount,
|
||||
lineItems[index].discount,
|
||||
context,
|
||||
formatNumberType: FormatNumberType.inputAmount,
|
||||
clientId: invoice.isPurchaseOrder
|
||||
|
|
@ -1152,7 +1146,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
: null,
|
||||
),
|
||||
onChanged: (value) => _onChanged(
|
||||
lineItems[index]!.rebuild(
|
||||
lineItems[index].rebuild(
|
||||
(b) => b..discount = parseDouble(value)),
|
||||
index),
|
||||
keyboardType: TextInputType.numberWithOptions(
|
||||
|
|
@ -1170,11 +1164,11 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
padding: const EdgeInsets.only(right: kTableColumnGap),
|
||||
child: TextFormField(
|
||||
key: ValueKey(
|
||||
'__total_${index}_${lineItems[index]!.total(invoice, precision)}_${invoice.clientId}__'),
|
||||
'__total_${index}_${lineItems[index].total(invoice, precision)}_${invoice.clientId}__'),
|
||||
readOnly: true,
|
||||
enabled: false,
|
||||
initialValue: formatNumber(
|
||||
lineItems[index]!.total(invoice, precision),
|
||||
lineItems[index].total(invoice, precision),
|
||||
context,
|
||||
clientId:
|
||||
invoice.isPurchaseOrder ? null : invoice.clientId,
|
||||
|
|
@ -1186,13 +1180,13 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
),
|
||||
PopupMenuButton<String>(
|
||||
icon: Icon(Icons.more_vert),
|
||||
enabled: !lineItems[index]!.isEmpty,
|
||||
enabled: !lineItems[index].isEmpty,
|
||||
itemBuilder: (BuildContext context) {
|
||||
final sectionIndex =
|
||||
includedLineItems.indexOf(lineItems[index]);
|
||||
final options = {
|
||||
if (widget.isTasks &&
|
||||
(lineItems[index]!.taskId ?? '').isNotEmpty)
|
||||
(lineItems[index].taskId ?? '').isNotEmpty)
|
||||
localization.viewTask: MdiIcons.chevronDoubleRight,
|
||||
if (sectionIndex > 0)
|
||||
localization.moveTop: MdiIcons.chevronDoubleUp,
|
||||
|
|
@ -1218,7 +1212,7 @@ class _InvoiceEditItemsDesktopState extends State<InvoiceEditItemsDesktop> {
|
|||
onSelected: (String action) {
|
||||
if (action == localization.viewTask) {
|
||||
viewEntityById(
|
||||
entityId: lineItems[index]!.taskId,
|
||||
entityId: lineItems[index].taskId,
|
||||
entityType: EntityType.task);
|
||||
} else if (action == localization.moveTop) {
|
||||
viewModel.onMovedInvoiceItem!(index, 0);
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ class InvoiceEditVM extends AbstractInvoiceEditVM {
|
|||
final state = store.state;
|
||||
final clientId = invoice.clientId;
|
||||
for (int i = 0; i < invoice.lineItems.length; i++) {
|
||||
final lineItem = invoice.lineItems[i]!;
|
||||
final lineItem = invoice.lineItems[i];
|
||||
final task = state.taskState.get(lineItem.taskId ?? '');
|
||||
if (task.clientId.isNotEmpty && task.clientId != clientId) {
|
||||
showDialog<ErrorDialog>(
|
||||
|
|
|
|||
|
|
@ -161,8 +161,8 @@ class _PurchaseOrderEditState extends State<PurchaseOrderEdit>
|
|||
invoice: invoice,
|
||||
showTasksAndExpenses: false,
|
||||
excluded: invoice.lineItems
|
||||
.where((item) => item!.isTask || item.isExpense)
|
||||
.map((item) => item!.isTask
|
||||
.where((item) => item.isTask || item.isExpense)
|
||||
.map((item) => item.isTask
|
||||
? viewModel.state!.taskState.map[item.taskId]
|
||||
: viewModel.state!.expenseState.map[item.expenseId])
|
||||
.toList(),
|
||||
|
|
|
|||
|
|
@ -158,8 +158,8 @@ class _QuoteEditState extends State<QuoteEdit>
|
|||
invoice: invoice,
|
||||
showTasksAndExpenses: false,
|
||||
excluded: invoice.lineItems
|
||||
.where((item) => item!.isTask || item.isExpense)
|
||||
.map((item) => item!.isTask
|
||||
.where((item) => item.isTask || item.isExpense)
|
||||
.map((item) => item.isTask
|
||||
? viewModel.state!.taskState.map[item.taskId]
|
||||
: viewModel.state!.expenseState.map[item.expenseId])
|
||||
.toList(),
|
||||
|
|
|
|||
|
|
@ -161,8 +161,8 @@ class _RecurringInvoiceEditState extends State<RecurringInvoiceEdit>
|
|||
invoice: invoice,
|
||||
showTasksAndExpenses: false,
|
||||
excluded: invoice.lineItems
|
||||
.where((item) => item!.isTask || item.isExpense)
|
||||
.map((item) => item!.isTask
|
||||
.where((item) => item.isTask || item.isExpense)
|
||||
.map((item) => item.isTask
|
||||
? viewModel.state!.taskState.map[item.taskId]
|
||||
: viewModel.state!.expenseState.map[item.expenseId])
|
||||
.toList(),
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ ReportResult lineItemReport(
|
|||
|
||||
for (var column in columns) {
|
||||
dynamic value = '';
|
||||
final productId = productKeyMap[lineItem!.productKey];
|
||||
final productId = productKeyMap[lineItem.productKey];
|
||||
|
||||
switch (column) {
|
||||
case CreditItemReportFields.price:
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ ReportResult lineItemReport(
|
|||
|
||||
for (var column in columns) {
|
||||
dynamic value = '';
|
||||
final productId = productKeyMap[lineItem!.productKey];
|
||||
final productId = productKeyMap[lineItem.productKey];
|
||||
|
||||
switch (column) {
|
||||
case InvoiceItemReportFields.price:
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ ReportResult lineItemReport(
|
|||
|
||||
for (var column in columns) {
|
||||
dynamic value = '';
|
||||
final productId = productKeyMap[lineItem!.productKey];
|
||||
final productId = productKeyMap[lineItem.productKey];
|
||||
|
||||
switch (column) {
|
||||
case PurchaseOrderItemReportFields.price:
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ ReportResult lineItemReport(
|
|||
|
||||
for (var column in columns) {
|
||||
dynamic value = '';
|
||||
final productId = productKeyMap[lineItem!.productKey];
|
||||
final productId = productKeyMap[lineItem.productKey];
|
||||
|
||||
switch (column) {
|
||||
case QuoteItemReportFields.price:
|
||||
|
|
|
|||
Loading…
Reference in New Issue