Exemplo n.º 1
0
        public static UndoPayoutResult UndoPayout(int databaseId)
        {
            AuthenticationData authData = GetAuthenticationDataAndCulture();

            if (
                !authData.Authority.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.Financials)))
            {
                throw new SecurityException("Insufficient privileges for operation");
            }

            UndoPayoutResult result = new UndoPayoutResult();
            Payout           payout = Payout.FromIdentity(databaseId);

            if (!payout.Open)
            {
                // this payout has already been settled, or picked up for settling

                result.Success        = false;
                result.DisplayMessage = String.Format(Resources.Pages.Financial.PayOutMoney_PayoutCannotUndo,
                                                      databaseId);

                return(result);
            }

            payout.UndoPayout();

            result.DisplayMessage = String.Format(Resources.Pages.Financial.PayOutMoney_PayoutUndone, databaseId);
            result.Success        = true;
            return(result);
        }
Exemplo n.º 2
0
    protected void ButtonExecute_Click(object sender, EventArgs e)
    {
        if (!_authority.HasPermission(Permission.CanDoEconomyTransactions, thisPayout.OrganizationId, -1, Authorization.Flag.ExactOrganization))
        {
            throw new UnauthorizedAccessException("Access Denied");
        }

        if (this.RadioManualMap.Checked)
        {
            int transactionId = Int32.Parse(this.DropTransactions.SelectedValue);
            FinancialTransaction transaction = FinancialTransaction.FromIdentity(transactionId);

            thisPayout.BindToTransactionAndClose(transaction, _currentUser);
        }
        else if (this.RadioManualMerge.Checked)
        {
            int    otherPayoutId = Int32.Parse(this.DropPayouts.SelectedValue);
            Payout otherPayout   = Payout.FromIdentity(otherPayoutId);

            otherPayout.MigrateDependenciesTo(thisPayout);
            otherPayout.Open     = false;
            thisPayout.Reference = GetDependencyString(thisPayout);
        }
        else if (this.RadioUndoPayout.Checked)
        {
            thisPayout.UndoPayout();
        }

        ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
    }
Exemplo n.º 3
0
        public static void MatchTransactionOpenPayout(int transactionId, int payoutId)
        {
            if (transactionId == 0 || payoutId == 0)
            {
                return;
            }

            AuthenticationData authData = GetAuthenticationDataAndCulture();

            if (
                !authData.Authority.HasAccess(new Access(authData.CurrentOrganization,
                                                         AccessAspect.BookkeepingDetails)))
            {
                throw new UnauthorizedAccessException();
            }

            FinancialTransaction transaction = FinancialTransaction.FromIdentity(transactionId);
            Payout payout = Payout.FromIdentity(payoutId);

            if (transaction.OrganizationId != authData.CurrentOrganization.Identity || payout.OrganizationId != authData.CurrentOrganization.Identity)
            {
                throw new UnauthorizedAccessException();
            }

            if (transaction.Rows.AmountCentsTotal != -payout.AmountCents)
            {
                throw new InvalidOperationException();
            }

            payout.BindToTransactionAndClose(transaction, authData.CurrentUser);
        }
Exemplo n.º 4
0
        public static UndoPayoutResult UndoPayout(int databaseId)
        {
            AuthenticationData authData = GetAuthenticationDataAndCulture();
            UndoPayoutResult   result   = new UndoPayoutResult();

            Payout payout = Payout.FromIdentity(databaseId);

            if (!payout.Open)
            {
                // this payout has already been settled, or picked up for settling

                result.Success        = false;
                result.DisplayMessage = String.Format(Resources.Pages.Financial.PayOutMoney_PayoutCannotUndo,
                                                      databaseId);

                return(result);
            }

            payout.UndoPayout();

            result.DisplayMessage =
                HttpUtility.UrlEncode(String.Format(Resources.Pages.Financial.PayOutMoney_PayoutUndone, databaseId))
                .Replace("+", "%20");
            result.Success = true;
            return(result);
        }
Exemplo n.º 5
0
        public static AjaxCallResult UndoPayout(int databaseId)
        {
            AuthenticationData authData = GetAuthenticationDataAndCulture();

            if (
                !authData.Authority.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.Financials)))
            {
                throw new UnauthorizedAccessException("Insufficient privileges for operation");
            }

            Payout payout = Payout.FromIdentity(databaseId);

            if (!payout.Open)
            {
                // this payout has already been settled, or picked up for settling. This is a concurrency error, detected before actually trying to change it.

                return(new AjaxCallResult
                {
                    Success = false,
                    DisplayMessage = String.Format(Resources.Pages.Financial.PayOutMoney_PayoutCannotUndo,
                                                   databaseId)
                });
            }

            payout.UndoPayout();   // TODO: catch ConcurrencyException

            return(new AjaxCallResult
            {
                DisplayMessage = String.Format(Resources.Pages.Financial.PayOutMoney_PayoutUndone, databaseId),
                Success = true
            });
        }
Exemplo n.º 6
0
        public static void MatchTransactionOpenPayout(int transactionId, int payoutId)
        {
            if (transactionId == 0 || payoutId == 0)
            {
                return;
            }

            AuthenticationData authData = GetAuthenticationDataAndCulture();

            if (
                !authData.Authority.HasAccess(new Access(authData.CurrentOrganization,
                                                         AccessAspect.BookkeepingDetails)))
            {
                throw new UnauthorizedAccessException();
            }

            FinancialTransaction transaction = FinancialTransaction.FromIdentity(transactionId);
            Payout payout = Payout.FromIdentity(payoutId);

            if (transaction.OrganizationId != authData.CurrentOrganization.Identity || payout.OrganizationId != authData.CurrentOrganization.Identity)
            {
                throw new UnauthorizedAccessException();
            }

            Int64 transactionCents = transaction.Rows.AmountCentsTotal;
            Int64 payoutCents      = payout.AmountCents;

            FinancialAccount forexSpillAccount =
                authData.CurrentOrganization.FinancialAccounts.IncomeCurrencyFluctuations;

            if (forexSpillAccount == null && payoutCents != -transactionCents)                           // the tx-negative is because it's a payout
            {
                throw new InvalidOperationException("Need forex gain/loss accounts for this operation"); // TODO: Autocreate?
            }

            if ((-transactionCents) > payoutCents)  // the tx-negative is because it's a payout
            {
                // This is a forex loss, not a gain which is the default
                forexSpillAccount = authData.CurrentOrganization.FinancialAccounts.CostsCurrencyFluctuations;
            }

            if (-transactionCents != payoutCents)
            {
                // Forex adjust
                transaction.AddRow(forexSpillAccount, -(payoutCents + transactionCents),
                                                          // plus because transactionCents is negative
                                   authData.CurrentUser); // Adds the forex adjustment so we can bind payout to tx and close
            }

            // The amounts should match now

            if (transaction.Rows.AmountCentsTotal != -payout.AmountCents)
            {
                throw new InvalidOperationException();
            }


            payout.BindToTransactionAndClose(transaction, authData.CurrentUser);
        }
Exemplo n.º 7
0
        public static void MatchTransactionOpenPayoutForeign(int transactionId, int payoutId)
        {
            // This is like the non-foreign version except this one chalks up the difference to forex gain/loss accounts

            if (transactionId == 0 || payoutId == 0)
            {
                return;
            }

            AuthenticationData authData = GetAuthenticationDataAndCulture();

            if (
                !authData.Authority.HasAccess(new Access(authData.CurrentOrganization,
                                                         AccessAspect.BookkeepingDetails)))
            {
                throw new UnauthorizedAccessException();
            }

            FinancialAccount forexSpillAccount =
                authData.CurrentOrganization.FinancialAccounts.IncomeCurrencyFluctuations;

            if (forexSpillAccount == null)
            {
                throw new InvalidOperationException("Need forex gain/loss accounts for this operation");  // TODO: Autocreate?
            }

            FinancialTransaction transaction = FinancialTransaction.FromIdentity(transactionId);
            Payout payout = Payout.FromIdentity(payoutId);

            if (transaction.OrganizationId != authData.CurrentOrganization.Identity || payout.OrganizationId != authData.CurrentOrganization.Identity)
            {
                throw new UnauthorizedAccessException();
            }

            if (-transaction.Rows.AmountCentsTotal > payout.AmountCents)
            {
                // This is a forex loss, not a gain which is the default
                forexSpillAccount = authData.CurrentOrganization.FinancialAccounts.CostsCurrencyFluctuations;
            }

            transaction.AddRow(forexSpillAccount, -(payout.AmountCents + transaction.Rows.AmountCentsTotal), // plus because AmountCentsTotal is negative
                               authData.CurrentUser);                                                        // Adds the forex adjustment so we can bind payout to tx and close

            if (transaction.Rows.AmountCentsTotal != -payout.AmountCents)
            {
                throw new InvalidOperationException();
            }

            payout.BindToTransactionAndClose(transaction, authData.CurrentUser);
        }
Exemplo n.º 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get account

        int thisPayoutId = Int32.Parse(Request.QueryString["PayoutId"]);

        thisPayout = Payout.FromIdentity(thisPayoutId);
        int year = DateTime.Today.Year;

        if (!_authority.HasPermission(Permission.CanDoEconomyTransactions, thisPayout.OrganizationId, -1, Authorization.Flag.ExactOrganization))
        {
            throw new UnauthorizedAccessException("Access Denied");
        }

        if (!Page.IsPostBack)
        {
            // Populate all data

            this.LabelHeader.Text = String.Format("Editing Payout #{0} ({1:N2})", thisPayout.Identity, thisPayout.Amount);
            PopulateDropTransactions();
            PopulateDropPayouts();
        }
    }
Exemplo n.º 9
0
    private void UpdateExecute()
    {
        bool   valid   = false;
        string message = string.Empty;

        Dictionary <decimal, List <int> > transactionDeltas = new Dictionary <decimal, List <int> >();
        FinancialTransactions             transactions      = FinancialTransactions.GetUnbalanced(thisPayout.Organization);

        this.ButtonExecute.Enabled = false;

        foreach (FinancialTransaction transaction in transactions)
        {
            decimal diff = transaction.Rows.AmountTotal;

            if (!transactionDeltas.ContainsKey(-diff))
            {
                transactionDeltas[-diff] = new List <int>();
            }

            transactionDeltas[-diff].Add(transaction.Identity);
        }

        if (this.RadioManualMap.Checked)
        {
            int transactionId = Int32.Parse(this.DropTransactions.SelectedValue);

            if (transactionId > 0)
            {
                FinancialTransaction transaction = FinancialTransaction.FromIdentity(transactionId);

                this.LabelActionDescription.Text =
                    String.Format(
                        "Payout #{0}, supposed date {1:yyyy-MM-dd}, will be mapped to Transaction #{2} on date {3:yyyy-MM-dd}. Transaction #{2} will be balanced and documented and tied to {4}. Payout #{0} will be closed.",
                        thisPayout.Identity, thisPayout.ExpectedTransactionDate, transaction.Identity, transaction.DateTime, GetDependencyString(thisPayout));
                valid = true;
                this.ButtonExecute.Text    = "Execute MAP";
                this.ButtonExecute.Enabled = true;
            }
        }

        if (this.RadioManualMerge.Checked)
        {
            int payoutId = Int32.Parse(this.DropPayouts.SelectedValue);

            if (payoutId > 0)
            {
                Payout  payout    = Payout.FromIdentity(payoutId);
                decimal newAmount = (decimal)(payout.Amount + thisPayout.Amount);
                this.LabelActionDescription.Text =
                    String.Format(
                        "Payout #{0} will be zeroed and closed. Payout #{1} will take over the dependencies of Payout #{0}. It will cover {2} and have an amount of {3:N2}.",
                        payout.Identity, thisPayout.Identity, GetDependencyString(thisPayout, payout), newAmount);

                if (transactionDeltas.ContainsKey(newAmount))
                {
                    this.LabelActionDescription.Text += " This matches Transaction " +
                                                        Formatting.GenerateRangeString(transactionDeltas[newAmount]) +
                                                        ".";
                }
                valid = true;
                this.ButtonExecute.Text    = "Execute MERGE";
                this.ButtonExecute.Enabled = true;
            }
        }

        if (this.RadioUndoPayout.Checked)
        {
            this.LabelActionDescription.Text =
                String.Format("Payout #{0} will be zeroed and closed. {1} will be re-opened and ready for payout.",
                              thisPayout.Identity, GetDependencyString(thisPayout));
            valid = true;
            this.ButtonExecute.Text    = "Execute UNDO";
            this.ButtonExecute.Enabled = true;
        }

        if (!valid)
        {
            this.ButtonExecute.Enabled       = false;
            this.ButtonExecute.Text          = "Execute Nothing";
            this.LabelActionDescription.Text = "Nothing.";
        }
    }