Ejemplo n.º 1
0
    public void TransferAssetTaxFree(AssetAccount client, BankAccount cba, BankAccount sba, int price, Asset asset)
    {
        MoneyTransferHistory history = new MoneyTransferHistory
        {
            sender   = sba,
            reciver  = cba,
            title    = "ATRANSFER MTRANSFER FROM " + sba.owner.ID + " TO " + cba.owner.ID,
            money    = price,
            ID       = MoneyTransferRegister.Instance.GenerateTransactionID(),
            tax      = 0,
            taxPayed = true
        };

        sba.bankStatements.Add(history);
        cba.bankStatements.Add(history);
        AssetTransferHistory transferHistory = new AssetTransferHistory()
        {
            sender  = this,
            reciver = client,
            money   = price,
            ID      = AssetTransferRegister.Instance.GenerateTransactionID(),
            asset   = asset
        };

        transferHistory.tax      = 0;
        transferHistory.taxPayed = true;
        transferHistory.title    = "ATRANSFER FROM " + owner.ID + " TO " + client.owner.ID;
        MoneyTransferRegister.Instance.transfers.Add(history);
        transferHistories.Add(transferHistory);
        client.transferHistories.Add(transferHistory);
        AssetTransferRegister.Instance.transfers.Add(transferHistory);
        asset.owner = client.owner;
        sba.money  += price;
        cba.money  -= price;
    }
Ejemplo n.º 2
0
    public void TransferAssetWithTax(AssetAccount client, BankAccount cba, BankAccount sba, int price, Asset asset)
    {
        AssetTransferTaxLaw law = new AssetTransferTaxLaw();
        int tax = law.CalculateTaxes(asset);

        if (price + tax >= cba.money && cba.accountBlocked == false && haveAccess)
        {
            if (asset.owner == this.owner)
            {
                MoneyTransferHistory history = new MoneyTransferHistory
                {
                    sender   = sba,
                    reciver  = cba,
                    title    = "ATRANSFER MTRANSFER FROM " + sba.owner.ID + " TO " + cba.owner.ID,
                    money    = price,
                    ID       = MoneyTransferRegister.Instance.GenerateTransactionID(),
                    tax      = 0,
                    taxPayed = true
                };
                sba.bankStatements.Add(history);
                cba.bankStatements.Add(history);
                MoneyTransferHistory thistory = new MoneyTransferHistory
                {
                    sender  = sba,
                    reciver = GovermentAccounts.Instance.govAccount,
                    money   = price,
                    ID      = MoneyTransferRegister.Instance.GenerateTransactionID()
                };
                AssetTransferHistory transferHistory = new AssetTransferHistory()
                {
                    sender  = this,
                    reciver = client,
                    money   = price,
                    ID      = AssetTransferRegister.Instance.GenerateTransactionID(),
                    asset   = asset
                };
                transferHistory.tax      = tax;
                transferHistory.taxPayed = true;
                transferHistory.title    = "ATRANSFER FROM " + owner.ID + " TO " + client.owner.ID;
                thistory.title           = "ATT MTRANSFER" + thistory.ID + " FROM ATRANSFER " + transferHistory.ID + "FROM PERSON " + owner.ID;
                MoneyTransferRegister.Instance.transfers.Add(history);
                MoneyTransferRegister.Instance.transfers.Add(thistory);
                law.isVioleted = false;
                transferHistories.Add(transferHistory);
                client.transferHistories.Add(transferHistory);
                AssetTransferRegister.Instance.transfers.Add(transferHistory);
                asset.owner = client.owner;
                sba.money  += price;
                cba.money  -= price;
            }
        }
        else
        {
            return;
        }
    }
Ejemplo n.º 3
0
        public A2ARetrievableAccount SavePluginVaultAccount(string name, AssetAccount sppAccount)
        {
            var plugin = _configDb.GetPluginByName(name);

            if (plugin == null)
            {
                throw LogAndException($"Plugin {name} not found.");
            }
            if (sppAccount == null)
            {
                throw LogAndException("Invalid account.");
            }

            var account = _safeguardLogic.GetAccount(sppAccount.Id);

            if (account == null)
            {
                throw LogAndException($"Account {sppAccount.Id} not found.");
            }

            // Make sure that the vault account isn't being used by another plugin before we delete it.
            if (plugin.VaultAccountId != null && (VaultAccountUsage(plugin.VaultAccountId.Value) <= 1))
            {
                _safeguardLogic.DeleteA2ARetrievableAccount(plugin.VaultAccountId.Value, A2ARegistrationType.Vault);
            }

            var accounts = _safeguardLogic.AddA2ARetrievableAccounts(new List <SppAccount>()
            {
                new SppAccount()
                {
                    Id = account.Id, Name = account.Name
                }
            }, A2ARegistrationType.Vault);

            var a2aAccount = accounts.FirstOrDefault(x => x.AccountId == account.Id);

            if (a2aAccount != null)
            {
                plugin.VaultAccountId = a2aAccount.AccountId;
                _configDb.SavePluginConfiguration(plugin);
            }
            else
            {
                throw LogAndException($"Failed to add the account to the A2A vault registration.  {account.Id} - {account.Name}.");
            }

            return(a2aAccount);
        }
Ejemplo n.º 4
0
        public ActionResult <AssetAccount> PutPluginVaultAccount([FromServices] IPluginsLogic pluginsLogic, [FromRoute] string name, [FromBody] AssetAccount assetAccount)
        {
            var account = pluginsLogic.SavePluginVaultAccount(name, assetAccount);

            return(Ok(account));
        }
        public Task period_closing_started(LocalDate openedOn, EquityAccount retainedEarnings,
                                           AssetAccount cashAccount, IncomeAccount incomeAccount, ExpenseAccount expenseAccount,
                                           GeneralLedgerEntryIdentifier[] generalLedgerEntryIdentifiers,
                                           GeneralLedgerEntryIdentifier closingGeneralLedgerEntryIdentifier, Money income, Money expense)
        {
            var period = AccountingPeriod.Open(openedOn);

            var closingOn = openedOn.AtMidnight();

            var accountingPeriodClosing = new AccountingPeriodClosing {
                Period    = period.ToString(),
                ClosingOn = Time.Format.LocalDateTime(closingOn),
                RetainedEarningsAccountNumber = retainedEarnings.AccountNumber.ToInt32(),
                ClosingGeneralLedgerEntryId   = closingGeneralLedgerEntryIdentifier.ToGuid(),
                GeneralLedgerEntryIds         =
                    Array.ConvertAll(generalLedgerEntryIdentifiers, identifier => identifier.ToGuid())
            };
            var net = income - expense;
            var generalLedgerEntryFacts = generalLedgerEntryIdentifiers.SelectMany(
                (identifier, index) => Array.ConvertAll(new object[] {
                new GeneralLedgerEntryCreated {
                    Number               = $"sale-{index}",
                    Period               = period.ToString(),
                    CreatedOn            = Time.Format.LocalDate(openedOn),
                    GeneralLedgerEntryId = identifier.ToGuid()
                },
                new CreditApplied {
                    Amount               = income.ToDecimal(),
                    AccountNumber        = incomeAccount.AccountNumber.ToInt32(),
                    GeneralLedgerEntryId = identifier.ToGuid()
                },
                new DebitApplied {
                    Amount               = expense.ToDecimal(),
                    AccountNumber        = expenseAccount.AccountNumber.ToInt32(),
                    GeneralLedgerEntryId = identifier.ToGuid()
                },
                net > Money.Zero
                                                        ? new DebitApplied {
                    Amount               = net.ToDecimal(),
                    AccountNumber        = cashAccount.AccountNumber.ToInt32(),
                    GeneralLedgerEntryId = identifier.ToGuid()
                }
                                                        : new CreditApplied {
                    Amount               = -net.ToDecimal(),
                    AccountNumber        = cashAccount.AccountNumber.ToInt32(),
                    GeneralLedgerEntryId = identifier.ToGuid()
                },
                new GeneralLedgerEntryPosted {
                    Period = period.ToString(),
                    GeneralLedgerEntryId = identifier.ToGuid()
                },
            }, e => new Fact(GeneralLedgerEntry.FormatStreamIdentifier(identifier), e)))
                                          .ToArray();

            return(new Scenario()
                   .Given(ChartOfAccounts.Identifier,
                          new AccountDefined {
                AccountName = cashAccount.AccountName.ToString(),
                AccountNumber = cashAccount.AccountNumber.ToInt32()
            },
                          new AccountDefined {
                AccountName = incomeAccount.AccountName.ToString(),
                AccountNumber = incomeAccount.AccountNumber.ToInt32()
            },
                          new AccountDefined {
                AccountName = expenseAccount.AccountName.ToString(),
                AccountNumber = expenseAccount.AccountNumber.ToInt32()
            },
                          new AccountDefined {
                AccountName = retainedEarnings.AccountName.ToString(),
                AccountNumber = retainedEarnings.AccountNumber.ToInt32()
            })
                   .Given(GeneralLedger.Identifier,
                          new GeneralLedgerOpened {
                OpenedOn = Time.Format.LocalDate(openedOn)
            },
                          accountingPeriodClosing)
                   .Given(generalLedgerEntryFacts)
                   .When(accountingPeriodClosing)
                   .Then(GeneralLedger.Identifier,
                         new GeneralLedgerEntryCreated {
                CreatedOn = Time.Format.LocalDateTime(closingOn),
                GeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid(),
                Number = $"jec-{period}",
                Period = period.ToString()
            },
                         new DebitApplied {
                Amount = income.ToDecimal() * generalLedgerEntryIdentifiers.Length,
                AccountNumber = incomeAccount.AccountNumber.ToInt32(),
                GeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid()
            },
                         new CreditApplied {
                Amount = expense.ToDecimal() * generalLedgerEntryIdentifiers.Length,
                AccountNumber = expenseAccount.AccountNumber.ToInt32(),
                GeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid()
            },
                         net < Money.Zero
                                                ? new DebitApplied {
                Amount = -net.ToDecimal() * generalLedgerEntryIdentifiers.Length,
                AccountNumber = retainedEarnings.AccountNumber.ToInt32(),
                GeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid()
            }
                                                : new CreditApplied {
                Amount = net.ToDecimal() * generalLedgerEntryIdentifiers.Length,
                AccountNumber = retainedEarnings.AccountNumber.ToInt32(),
                GeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid()
            },
                         new GeneralLedgerEntryPosted {
                Period = period.ToString(),
                GeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid()
            },
                         new AccountingPeriodClosed {
                Period = period.ToString(),
                GeneralLedgerEntryIds = Array.ConvertAll(generalLedgerEntryIdentifiers,
                                                         identifier => identifier.ToGuid()),
                ClosingGeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid(),
                Balance = new[] {
                    new BalanceLineItem {
                        AccountNumber = cashAccount.AccountNumber.ToInt32(),
                        Amount = net.ToDecimal() * generalLedgerEntryIdentifiers.Length
                    },
                    new BalanceLineItem {
                        AccountNumber = retainedEarnings.AccountNumber.ToInt32(),
                        Amount = net.ToDecimal() * generalLedgerEntryIdentifiers.Length
                    },
                    new BalanceLineItem {
                        AccountNumber = incomeAccount.AccountNumber.ToInt32(),
                        Amount = Money.Zero.ToDecimal()
                    },
                    new BalanceLineItem {
                        AccountNumber = expenseAccount.AccountNumber.ToInt32(),
                        Amount = Money.Zero.ToDecimal()
                    }
                }
            })
                   .Assert(_handler, _facts));
        }
Ejemplo n.º 6
0
        public void ConfigureDevOpsAddOn(string addonName)
        {
            var sg = _safeguardLogic.Connect();

            try
            {
                var addon = _configDb.GetAddonByName(addonName);
                if (addon == null)
                {
                    throw LogAndException($"Add-on {addonName} not found.");
                }

                if (!addon.VaultCredentials.Any())
                {
                    throw LogAndException($"Waiting for the Add-on {addonName} to post the vault credentials.  Try again later...");
                }

                if ((_configDb.AssetPartitionId ?? 0) == 0 || (_configDb.AssetId ?? 0) == 0)
                {
                    var assetPartition = _safeguardLogic.CreateAssetPartition(sg);
                    _safeguardLogic.CreateAsset(sg, assetPartition);
                    _safeguardLogic.CreateAssetAccountGroup(sg, addon);
                }

                var assetId = _configDb.AssetId;
                if ((assetId ?? 0) == 0)
                {
                    throw LogAndException($"Failed to configure the Add-on {addonName}. No associated asset found in Safeguard.");
                }

                if (addon.VaultCredentials.Any() && !SafeguardHasVaultCredentials(addon))
                {
                    var tasks = new List <Task>();
                    foreach (var vaultCredential in addon.VaultCredentials)
                    {
                        var newAccount = new AssetAccount()
                        {
                            Name    = vaultCredential.Key,
                            AssetId = assetId.Value
                        };
                        var p = addon.VaultCredentials[newAccount.Name];

                        tasks.Add(Task.Run(() =>
                        {
                            newAccount = _safeguardLogic.AddAssetAccount(sg, newAccount);
                            _safeguardLogic.SetAssetAccountPassword(sg, newAccount, p);
                        }));
                    }

                    if (tasks.Any())
                    {
                        Task.WaitAll(tasks.ToArray());
                    }
                }

                var asset = _safeguardLogic.GetAsset(sg);
                if (asset != null)
                {
                    addon.VaultAssetId   = asset.Id;
                    addon.VaultAssetName = asset.Name;

                    if (addon.VaultAccountName != null)
                    {
                        var account = _safeguardLogic.GetAssetAccounts(sg, asset.Id)
                                      .FirstOrDefault(x => x.Name.StartsWith(addon.VaultAccountName, StringComparison.OrdinalIgnoreCase));
                        addon.VaultAccountId   = account?.Id ?? 0;
                        addon.VaultAccountName = account?.Name ?? addon.VaultAccountName;
                    }

                    _configDb.SaveAddon(addon);
                }

                var plugin = _configDb.GetPluginByName(addon.Manifest.PluginName);
                if (plugin != null && plugin.VaultAccountId != addon.VaultAccountId)
                {
                    plugin.VaultAccountId = addon.VaultAccountId;
                    _pluginsLogic.SavePluginVaultAccount(sg, plugin.Name, new AssetAccount()
                    {
                        Id = addon.VaultAccountId.Value
                    });
                }
            }
            finally
            {
                sg.Dispose();
            }
        }