Ejemplo n.º 1
0
        private static void AddAdjustmentChild(Transaction parent, Transactions availableTransactions, decimal amount
                                               , TransactionReason transactionReason, string adjustmentTag)
        {
            ImportInfo matcherImportInfo;

            if (availableTransactions.HasImportInfo(ImportInfoId))
            {
                matcherImportInfo = availableTransactions.GetImportInfo(ImportInfoId);
            }
            else
            {
                matcherImportInfo = new ImportInfo(ImportInfoId, ImportInfoId, null, null, ImportInfoId, null);   //TODO: how can we accomodate manufatured import?
            }
            AccountInfo accountInfo = availableTransactions.GetAccountInfo(parent.AccountId);

            if (amount != 0)
            {
                var tx = new Transaction(matcherImportInfo.Id, accountInfo,
                                         new Transaction.ImportedValues()
                {
                    Amount               = amount,
                    EntityName           = "{0} - {1}".FormatEx(adjustmentTag, parent.EntityName),
                    EntityNameNormalized = "{0} - {1}".FormatEx(adjustmentTag, parent.EntityName),
                    InstituteReference   = "{0}.{1}".FormatEx(adjustmentTag, parent.InstituteReference),
                    RequiresParent       = true,
                    SubAccountName       = parent.SubAccountName,
                    TransactionDate      = parent.TransactionDate,
                    TransactionReason    = transactionReason,
                    LineNumber           = null
                });
                availableTransactions.AddNew(tx, accountInfo, matcherImportInfo, false);

                availableTransactions.RelateParentChild(parent.Id, tx.Id);
            }
        }