Purchase orders

This commit is contained in:
Hillel Coren 2022-07-07 08:47:22 +03:00
parent 50d045ed79
commit 8824370249
8 changed files with 85 additions and 60 deletions

View File

@ -134,7 +134,6 @@ abstract class ExpenseEntity extends Object
? client.settings.currencyId // TODO handle group currency
: (state?.company?.currencyId ?? kDefaultCurrencyId),
documents: BuiltList<DocumentEntity>(),
purchaseOrderId: '',
taxName1: '',
taxName2: '',
taxName3: '',
@ -307,9 +306,6 @@ abstract class ExpenseEntity extends Object
@BuiltValueField(wireName: 'recurring_id')
String get recurringId;
@BuiltValueField(wireName: 'purchase_order_id')
String get purchaseOrderId;
@BuiltValueField(wireName: 'frequency_id')
String get frequencyId;
@ -830,7 +826,6 @@ abstract class ExpenseEntity extends Object
// ignore: unused_element
static void _initializeBuilder(ExpenseEntityBuilder builder) => builder
..entityType = EntityType.expense
..purchaseOrderId = ''
..frequencyId = ''
..lastSentDate = ''
..nextSendDate = ''

View File

@ -213,9 +213,6 @@ class _$ExpenseEntitySerializer implements StructuredSerializer<ExpenseEntity> {
'number',
serializers.serialize(object.number,
specifiedType: const FullType(String)),
'purchase_order_id',
serializers.serialize(object.purchaseOrderId,
specifiedType: const FullType(String)),
'frequency_id',
serializers.serialize(object.frequencyId,
specifiedType: const FullType(String)),
@ -515,10 +512,6 @@ class _$ExpenseEntitySerializer implements StructuredSerializer<ExpenseEntity> {
result.recurringId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String;
break;
case 'purchase_order_id':
result.purchaseOrderId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String;
break;
case 'frequency_id':
result.frequencyId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String;
@ -948,8 +941,6 @@ class _$ExpenseEntity extends ExpenseEntity {
@override
final String recurringId;
@override
final String purchaseOrderId;
@override
final String frequencyId;
@override
final String lastSentDate;
@ -1022,7 +1013,6 @@ class _$ExpenseEntity extends ExpenseEntity {
this.documents,
this.number,
this.recurringId,
this.purchaseOrderId,
this.frequencyId,
this.lastSentDate,
this.nextSendDate,
@ -1096,8 +1086,6 @@ class _$ExpenseEntity extends ExpenseEntity {
BuiltValueNullFieldError.checkNotNull(
documents, 'ExpenseEntity', 'documents');
BuiltValueNullFieldError.checkNotNull(number, 'ExpenseEntity', 'number');
BuiltValueNullFieldError.checkNotNull(
purchaseOrderId, 'ExpenseEntity', 'purchaseOrderId');
BuiltValueNullFieldError.checkNotNull(
frequencyId, 'ExpenseEntity', 'frequencyId');
BuiltValueNullFieldError.checkNotNull(
@ -1164,7 +1152,6 @@ class _$ExpenseEntity extends ExpenseEntity {
documents == other.documents &&
number == other.number &&
recurringId == other.recurringId &&
purchaseOrderId == other.purchaseOrderId &&
frequencyId == other.frequencyId &&
lastSentDate == other.lastSentDate &&
nextSendDate == other.nextSendDate &&
@ -1202,12 +1189,12 @@ class _$ExpenseEntity extends ExpenseEntity {
$jc(
$jc(
$jc(
$jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, privateNotes.hashCode), publicNotes.hashCode), shouldBeInvoiced.hashCode), invoiceDocuments.hashCode), transactionId.hashCode), transactionReference.hashCode), bankId.hashCode), currencyId.hashCode), categoryId.hashCode), amount.hashCode), date.hashCode), paymentDate.hashCode), exchangeRate.hashCode), invoiceCurrencyId.hashCode), paymentTypeId.hashCode), taxName1.hashCode), taxName2.hashCode), taxRate1.hashCode), taxRate2.hashCode), taxName3.hashCode), taxRate3.hashCode), clientId.hashCode), invoiceId.hashCode), vendorId.hashCode), projectId.hashCode), statusId.hashCode), customValue1.hashCode), customValue2.hashCode), customValue3.hashCode), customValue4.hashCode), taxAmount1.hashCode), taxAmount2.hashCode), taxAmount3.hashCode), usesInclusiveTaxes.hashCode),
calculateTaxByAmount.hashCode),
documents.hashCode),
number.hashCode),
recurringId.hashCode),
purchaseOrderId.hashCode),
$jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, privateNotes.hashCode), publicNotes.hashCode), shouldBeInvoiced.hashCode), invoiceDocuments.hashCode), transactionId.hashCode), transactionReference.hashCode), bankId.hashCode), currencyId.hashCode), categoryId.hashCode), amount.hashCode), date.hashCode), paymentDate.hashCode), exchangeRate.hashCode), invoiceCurrencyId.hashCode), paymentTypeId.hashCode), taxName1.hashCode), taxName2.hashCode), taxRate1.hashCode), taxRate2.hashCode), taxName3.hashCode), taxRate3.hashCode), clientId.hashCode), invoiceId.hashCode), vendorId.hashCode), projectId.hashCode), statusId.hashCode), customValue1.hashCode), customValue2.hashCode), customValue3.hashCode), customValue4.hashCode), taxAmount1.hashCode), taxAmount2.hashCode), taxAmount3.hashCode),
usesInclusiveTaxes.hashCode),
calculateTaxByAmount.hashCode),
documents.hashCode),
number.hashCode),
recurringId.hashCode),
frequencyId.hashCode),
lastSentDate.hashCode),
nextSendDate.hashCode),
@ -1265,7 +1252,6 @@ class _$ExpenseEntity extends ExpenseEntity {
..add('documents', documents)
..add('number', number)
..add('recurringId', recurringId)
..add('purchaseOrderId', purchaseOrderId)
..add('frequencyId', frequencyId)
..add('lastSentDate', lastSentDate)
..add('nextSendDate', nextSendDate)
@ -1451,11 +1437,6 @@ class ExpenseEntityBuilder
String get recurringId => _$this._recurringId;
set recurringId(String recurringId) => _$this._recurringId = recurringId;
String _purchaseOrderId;
String get purchaseOrderId => _$this._purchaseOrderId;
set purchaseOrderId(String purchaseOrderId) =>
_$this._purchaseOrderId = purchaseOrderId;
String _frequencyId;
String get frequencyId => _$this._frequencyId;
set frequencyId(String frequencyId) => _$this._frequencyId = frequencyId;
@ -1566,7 +1547,6 @@ class ExpenseEntityBuilder
_documents = $v.documents.toBuilder();
_number = $v.number;
_recurringId = $v.recurringId;
_purchaseOrderId = $v.purchaseOrderId;
_frequencyId = $v.frequencyId;
_lastSentDate = $v.lastSentDate;
_nextSendDate = $v.nextSendDate;
@ -1649,7 +1629,6 @@ class ExpenseEntityBuilder
documents: documents.build(),
number: BuiltValueNullFieldError.checkNotNull(number, 'ExpenseEntity', 'number'),
recurringId: recurringId,
purchaseOrderId: BuiltValueNullFieldError.checkNotNull(purchaseOrderId, 'ExpenseEntity', 'purchaseOrderId'),
frequencyId: BuiltValueNullFieldError.checkNotNull(frequencyId, 'ExpenseEntity', 'frequencyId'),
lastSentDate: BuiltValueNullFieldError.checkNotNull(lastSentDate, 'ExpenseEntity', 'lastSentDate'),
nextSendDate: BuiltValueNullFieldError.checkNotNull(nextSendDate, 'ExpenseEntity', 'nextSendDate'),

View File

@ -163,6 +163,7 @@ abstract class InvoiceEntity extends Object
taxAmount: 0,
poNumber: '',
projectId: '',
expenseId: '',
vendorId: vendor?.id ?? '',
date: convertDateTimeToSqlDate(),
dueDate: '',
@ -294,6 +295,7 @@ abstract class InvoiceEntity extends Object
..remainingCycles = -1
..invoiceId = ''
..projectId = ''
..expenseId = ''
..subscriptionId = ''
..number = ''
..date = convertDateTimeToSqlDate()
@ -403,6 +405,9 @@ abstract class InvoiceEntity extends Object
@BuiltValueField(wireName: 'project_id')
String get projectId;
@BuiltValueField(wireName: 'expense_id')
String get expenseId;
@override
@BuiltValueField(wireName: 'vendor_id')
String get vendorId;
@ -1008,8 +1013,12 @@ abstract class InvoiceEntity extends Object
}
if (isPurchaseOrder) {
if (userCompany.canCreate(EntityType.expense)) {
actions.add(EntityAction.convertToExpense);
if (expenseId.isEmpty) {
if (userCompany.canCreate(EntityType.expense)) {
actions.add(EntityAction.convertToExpense);
}
} else {
actions.add(EntityAction.viewExpense);
}
if (statusId == kPurchaseOrderStatusAccepted) {
actions.add(EntityAction.addToInventory);
@ -1417,6 +1426,7 @@ abstract class InvoiceEntity extends Object
..activities.replace(BuiltList<ActivityEntity>())
..paidToDate = 0
..projectId = ''
..expenseId = ''
..vendorId = ''
..autoBillEnabled = false
..subscriptionId = '';

View File

@ -141,6 +141,9 @@ class _$InvoiceEntitySerializer implements StructuredSerializer<InvoiceEntity> {
'project_id',
serializers.serialize(object.projectId,
specifiedType: const FullType(String)),
'expense_id',
serializers.serialize(object.expenseId,
specifiedType: const FullType(String)),
'vendor_id',
serializers.serialize(object.vendorId,
specifiedType: const FullType(String)),
@ -449,6 +452,10 @@ class _$InvoiceEntitySerializer implements StructuredSerializer<InvoiceEntity> {
result.projectId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String;
break;
case 'expense_id':
result.expenseId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String;
break;
case 'vendor_id':
result.vendorId = serializers.deserialize(value,
specifiedType: const FullType(String)) as String;
@ -1410,6 +1417,8 @@ class _$InvoiceEntity extends InvoiceEntity {
@override
final String projectId;
@override
final String expenseId;
@override
final String vendorId;
@override
final String subscriptionId;
@ -1551,6 +1560,7 @@ class _$InvoiceEntity extends InvoiceEntity {
this.paidToDate,
this.clientId,
this.projectId,
this.expenseId,
this.vendorId,
this.subscriptionId,
this.statusId,
@ -1626,6 +1636,8 @@ class _$InvoiceEntity extends InvoiceEntity {
clientId, 'InvoiceEntity', 'clientId');
BuiltValueNullFieldError.checkNotNull(
projectId, 'InvoiceEntity', 'projectId');
BuiltValueNullFieldError.checkNotNull(
expenseId, 'InvoiceEntity', 'expenseId');
BuiltValueNullFieldError.checkNotNull(
vendorId, 'InvoiceEntity', 'vendorId');
BuiltValueNullFieldError.checkNotNull(
@ -1733,6 +1745,7 @@ class _$InvoiceEntity extends InvoiceEntity {
paidToDate == other.paidToDate &&
clientId == other.clientId &&
projectId == other.projectId &&
expenseId == other.expenseId &&
vendorId == other.vendorId &&
subscriptionId == other.subscriptionId &&
statusId == other.statusId &&
@ -1820,7 +1833,7 @@ class _$InvoiceEntity extends InvoiceEntity {
$jc(
$jc(
$jc(
$jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, amount.hashCode), balance.hashCode), paidToDate.hashCode), clientId.hashCode), projectId.hashCode), vendorId.hashCode), subscriptionId.hashCode), statusId.hashCode), number.hashCode), discount.hashCode), poNumber.hashCode), date.hashCode), dueDate.hashCode), publicNotes.hashCode), privateNotes.hashCode), terms.hashCode), footer.hashCode), designId.hashCode), usesInclusiveTaxes.hashCode), taxName1.hashCode), taxRate1.hashCode), taxName2.hashCode), taxRate2.hashCode), taxName3.hashCode), taxRate3.hashCode), isAmountDiscount.hashCode), partial.hashCode), taxAmount.hashCode), partialDueDate.hashCode), autoBill.hashCode), customValue1.hashCode), customValue2.hashCode), customValue3.hashCode), customValue4.hashCode), customSurcharge1.hashCode), customSurcharge2.hashCode), customSurcharge3.hashCode), customSurcharge4.hashCode), customTaxes1.hashCode), customTaxes2.hashCode), customTaxes3.hashCode), customTaxes4.hashCode), exchangeRate.hashCode), reminder1Sent.hashCode), reminder2Sent.hashCode), reminder3Sent.hashCode), reminderLastSent.hashCode), frequencyId.hashCode), lastSentDate.hashCode), nextSendDate.hashCode),
$jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, amount.hashCode), balance.hashCode), paidToDate.hashCode), clientId.hashCode), projectId.hashCode), expenseId.hashCode), vendorId.hashCode), subscriptionId.hashCode), statusId.hashCode), number.hashCode), discount.hashCode), poNumber.hashCode), date.hashCode), dueDate.hashCode), publicNotes.hashCode), privateNotes.hashCode), terms.hashCode), footer.hashCode), designId.hashCode), usesInclusiveTaxes.hashCode), taxName1.hashCode), taxRate1.hashCode), taxName2.hashCode), taxRate2.hashCode), taxName3.hashCode), taxRate3.hashCode), isAmountDiscount.hashCode), partial.hashCode), taxAmount.hashCode), partialDueDate.hashCode), autoBill.hashCode), customValue1.hashCode), customValue2.hashCode), customValue3.hashCode), customValue4.hashCode), customSurcharge1.hashCode), customSurcharge2.hashCode), customSurcharge3.hashCode), customSurcharge4.hashCode), customTaxes1.hashCode), customTaxes2.hashCode), customTaxes3.hashCode), customTaxes4.hashCode), exchangeRate.hashCode), reminder1Sent.hashCode), reminder2Sent.hashCode), reminder3Sent.hashCode), reminderLastSent.hashCode), frequencyId.hashCode), lastSentDate.hashCode), nextSendDate.hashCode),
remainingCycles.hashCode),
dueDateDays.hashCode),
invoiceId.hashCode),
@ -1850,6 +1863,7 @@ class _$InvoiceEntity extends InvoiceEntity {
..add('paidToDate', paidToDate)
..add('clientId', clientId)
..add('projectId', projectId)
..add('expenseId', expenseId)
..add('vendorId', vendorId)
..add('subscriptionId', subscriptionId)
..add('statusId', statusId)
@ -1944,6 +1958,10 @@ class InvoiceEntityBuilder
String get projectId => _$this._projectId;
set projectId(String projectId) => _$this._projectId = projectId;
String _expenseId;
String get expenseId => _$this._expenseId;
set expenseId(String expenseId) => _$this._expenseId = expenseId;
String _vendorId;
String get vendorId => _$this._vendorId;
set vendorId(String vendorId) => _$this._vendorId = vendorId;
@ -2246,6 +2264,7 @@ class InvoiceEntityBuilder
_paidToDate = $v.paidToDate;
_clientId = $v.clientId;
_projectId = $v.projectId;
_expenseId = $v.expenseId;
_vendorId = $v.vendorId;
_subscriptionId = $v.subscriptionId;
_statusId = $v.statusId;
@ -2344,14 +2363,15 @@ class InvoiceEntityBuilder
clientId, 'InvoiceEntity', 'clientId'),
projectId: BuiltValueNullFieldError.checkNotNull(
projectId, 'InvoiceEntity', 'projectId'),
expenseId: BuiltValueNullFieldError.checkNotNull(
expenseId, 'InvoiceEntity', 'expenseId'),
vendorId: BuiltValueNullFieldError.checkNotNull(
vendorId, 'InvoiceEntity', 'vendorId'),
subscriptionId: BuiltValueNullFieldError.checkNotNull(
subscriptionId, 'InvoiceEntity', 'subscriptionId'),
statusId: BuiltValueNullFieldError.checkNotNull(
statusId, 'InvoiceEntity', 'statusId'),
number:
BuiltValueNullFieldError.checkNotNull(number, 'InvoiceEntity', 'number'),
statusId:
BuiltValueNullFieldError.checkNotNull(statusId, 'InvoiceEntity', 'statusId'),
number: BuiltValueNullFieldError.checkNotNull(number, 'InvoiceEntity', 'number'),
discount: BuiltValueNullFieldError.checkNotNull(discount, 'InvoiceEntity', 'discount'),
poNumber: BuiltValueNullFieldError.checkNotNull(poNumber, 'InvoiceEntity', 'poNumber'),
date: BuiltValueNullFieldError.checkNotNull(date, 'InvoiceEntity', 'date'),

View File

@ -105,6 +105,7 @@ class EntityAction extends EnumClass {
static const EntityAction resendInvite = _$resendInvite;
static const EntityAction disconnect = _$disconnect;
static const EntityAction viewInvoice = _$viewInvoice;
static const EntityAction viewExpense = _$viewExpense;
static const EntityAction changeStatus = _$changeStatus;
static const EntityAction addToInvoice = _$addToInvoice;
static const EntityAction cancel = _$cancel;

View File

@ -72,6 +72,7 @@ const EntityAction _$invoiceProject = const EntityAction._('invoiceProject');
const EntityAction _$resendInvite = const EntityAction._('resendInvite');
const EntityAction _$disconnect = const EntityAction._('disconnect');
const EntityAction _$viewInvoice = const EntityAction._('viewInvoice');
const EntityAction _$viewExpense = const EntityAction._('viewExpense');
const EntityAction _$changeStatus = const EntityAction._('changeStatus');
const EntityAction _$addToInvoice = const EntityAction._('addToInvoice');
const EntityAction _$cancel = const EntityAction._('cancel');
@ -199,6 +200,8 @@ EntityAction _$valueOf(String name) {
return _$disconnect;
case 'viewInvoice':
return _$viewInvoice;
case 'viewExpense':
return _$viewExpense;
case 'changeStatus':
return _$changeStatus;
case 'addToInvoice':
@ -278,6 +281,7 @@ final BuiltSet<EntityAction> _$values =
_$resendInvite,
_$disconnect,
_$viewInvoice,
_$viewExpense,
_$changeStatus,
_$addToInvoice,
_$cancel,

View File

@ -377,6 +377,26 @@ class MarkPurchaseOrderSentFailure implements StopSaving {
final Object error;
}
class ConvertPurchaseOrdersToExpensesRequest implements StartSaving {
ConvertPurchaseOrdersToExpensesRequest(this.completer, this.purchaseOrderIds);
final Completer completer;
final List<String> purchaseOrderIds;
}
class ConvertPurchaseOrdersToExpensesSuccess
implements StopSaving, PersistData {
ConvertPurchaseOrdersToExpensesSuccess(this.purchaseOrders);
final List<InvoiceEntity> purchaseOrders;
}
class ConvertPurchaseOrdersToExpensesFailure implements StopSaving {
ConvertPurchaseOrdersToExpensesFailure(this.error);
final Object error;
}
class AddPurchaseOrdersToInventoryRequest implements StartSaving {
AddPurchaseOrdersToInventoryRequest(this.completer, this.purchaseOrderIds);
@ -589,27 +609,13 @@ void handlePurchaseOrderAction(BuildContext context,
purchaseOrderIds));
break;
case EntityAction.convertToExpense:
final vendor = state.vendorState.get(purchaseOrder.vendorId);
final client = state.clientState.get(purchaseOrder.clientId);
final project = state.projectState.get(purchaseOrder.projectId);
editEntity(
entity: ExpenseEntity(
state: state,
vendor: vendor,
client: client,
project: project,
).rebuild((b) => b
..purchaseOrderId = purchaseOrder.id
..amount = purchaseOrder.usesInclusiveTaxes
? purchaseOrder.amount
: purchaseOrder.netAmount
..taxRate1 = purchaseOrder.taxRate1
..taxName1 = purchaseOrder.taxName1
..taxRate2 = purchaseOrder.taxRate2
..taxName2 = purchaseOrder.taxName2
..taxRate3 = purchaseOrder.taxRate3
..taxName3 = purchaseOrder.taxName3
..usesInclusiveTaxes = purchaseOrder.usesInclusiveTaxes));
store.dispatch(ConvertPurchaseOrdersToExpensesRequest(
snackBarCompleter<Null>(
context,
purchaseOrders.length == 1
? localization.convertedToExpense
: localization.convertedToExpenses),
purchaseOrderIds));
break;
case EntityAction.markSent:
store.dispatch(MarkPurchaseOrdersSentRequest(

View File

@ -16,6 +16,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
static final Map<String, Map<String, String>> _localizedValues = {
'en': {
// STARTER: lang key - do not remove comment
'converted_to_expense': 'Successfully converted to expense',
'converted_to_expenses': 'Successfully converted to expenses',
'convert_to_expense': 'Convert to Expense',
'add_to_inventory': 'Add to Inventory',
'added_purchase_order_to_inventory':
@ -70933,6 +70935,14 @@ mixin LocalizationsProvider on LocaleCodeAware {
_localizedValues[localeCode]['convert_to_expense'] ??
_localizedValues['en']['convert_to_expense'];
String get convertedToExpense =>
_localizedValues[localeCode]['converted_to_expense'] ??
_localizedValues['en']['converted_to_expense'];
String get convertedToExpenses =>
_localizedValues[localeCode]['converted_to_expenses'] ??
_localizedValues['en']['converted_to_expenses'];
// STARTER: lang field - do not remove comment
String lookup(String key) {