protected void Page_Load(object sender, EventArgs e)
    {
        _invoice = InboundInvoice.FromIdentity(Int32.Parse(Request.QueryString["InboundInvoiceId"]));

        // TODO: Verify authority (economy assistant or budget owner)

        if (!Page.IsPostBack)
        {
            this.LabelInvoiceFrom.Text         = _invoice.Supplier;
            this.LabelInvoiceReceivedDate.Text = _invoice.CreatedDateTime.ToString("yyyy-MM-dd");
            this.LabelAttested.Text            = _invoice.Attested ? "Yes." : "No.";

            this.DropAccounts.Populate(_invoice.Organization, FinancialAccountType.Cost);

            if (_invoice.BudgetId != 0)
            {
                this.DropAccounts.SelectedFinancialAccount = _invoice.Budget;
            }

            this.DateInvoiceDue.SelectedDate = _invoice.DueDate;
            this.TextAmount.Text             = _invoice.Amount.ToString("N2", new CultureInfo("sv-SE"));
        }

        // The DocumentList control does not hold state - yet - so must be initialized always

        this.DocumentList.Documents = Documents.ForObject(_invoice);
    }
예제 #2
0
        static protected IPayable PayableFromRecordId(string recordId)
        {
            char recordType = recordId[0];
            int  itemId     = Int32.Parse(recordId.Substring(1));

            switch (recordType)
            {
            case 'E':     // Expense claim
                return(ExpenseClaim.FromIdentity(itemId));

            case 'A':     // Cash advance
                return(CashAdvance.FromIdentity(itemId));

            case 'I':     // Inbound invoice
                return(InboundInvoice.FromIdentity(itemId));

            default:
                throw new NotImplementedException("Unknown record type");
            }
        }
예제 #3
0
        private static AjaxCallResult HandleAttestationDeattestation(string identifier, AttestationMode mode)
        {
            AuthenticationData authData = GetAuthenticationDataAndCulture();

            IApprovable approvableItem;
            string      attestedTemplate;
            string      deattestedTemplate;

            char   costType = identifier[0];
            int    itemId   = Int32.Parse(identifier.Substring(1));
            Int64  amountCents;
            string beneficiary;
            string result;

            // Find the item we are attesting or deattesting

            switch (costType)
            {
            case 'A':     // Case advance
                CashAdvance advance = CashAdvance.FromIdentity(itemId);
                if (advance.OrganizationId != authData.CurrentOrganization.Identity)
                {
                    throw new InvalidOperationException("Called to attest out-of-org line item");
                }
                if (advance.Budget.OwnerPersonId != authData.CurrentUser.Identity &&
                    advance.Budget.OwnerPersonId != Person.NobodyId)
                {
                    throw new SecurityException("Called without attestation privileges");
                }

                approvableItem     = advance;
                attestedTemplate   = Resources.Pages.Financial.AttestCosts_AdvanceAttested;
                deattestedTemplate = Resources.Pages.Financial.AttestCosts_AdvanceDeattested;
                beneficiary        = advance.Person.Name;
                amountCents        = advance.AmountCents;

                break;

            case 'E':     // Expense claim
                ExpenseClaim expense = ExpenseClaim.FromIdentity(itemId);
                if (expense.OrganizationId != authData.CurrentOrganization.Identity)
                {
                    throw new InvalidOperationException("Called to attest out-of-org line item");
                }
                if (expense.Budget.OwnerPersonId != authData.CurrentUser.Identity &&
                    expense.Budget.OwnerPersonId != Person.NobodyId)
                {
                    throw new SecurityException("Called without attestation privileges");
                }

                approvableItem     = expense;
                attestedTemplate   = Resources.Pages.Financial.AttestCosts_ExpenseAttested;
                deattestedTemplate = Resources.Pages.Financial.AttestCosts_ExpenseDeattested;
                beneficiary        = expense.Claimer.Name;
                amountCents        = expense.AmountCents;

                break;

            case 'I':     // Inbound invoice
                InboundInvoice invoice = InboundInvoice.FromIdentity(itemId);
                if (invoice.OrganizationId != authData.CurrentOrganization.Identity)
                {
                    throw new InvalidOperationException("Called to attest out-of-org line item");
                }
                if (invoice.Budget.OwnerPersonId != authData.CurrentUser.Identity &&
                    invoice.Budget.OwnerPersonId != Person.NobodyId)
                {
                    throw new SecurityException("Called without attestation privileges");
                }

                approvableItem     = invoice;
                attestedTemplate   = Resources.Pages.Financial.AttestCosts_InvoiceAttested;
                deattestedTemplate = Resources.Pages.Financial.AttestCosts_InvoiceDeattested;
                beneficiary        = invoice.Supplier;
                amountCents        = invoice.AmountCents;

                break;

            case 'S':     // Salary payout
                Salary salary = Salary.FromIdentity(itemId);
                if (salary.PayrollItem.OrganizationId != authData.CurrentOrganization.Identity)
                {
                    throw new InvalidOperationException("Called to attest out-of-org line item");
                }
                if (salary.PayrollItem.Budget.OwnerPersonId != authData.CurrentUser.Identity &&
                    salary.PayrollItem.Budget.OwnerPersonId != Person.NobodyId)
                {
                    throw new SecurityException("Called without attestation privileges");
                }

                approvableItem     = salary;
                attestedTemplate   = Resources.Pages.Financial.AttestCosts_SalaryAttested;
                deattestedTemplate = Resources.Pages.Financial.AttestCosts_SalaryDeattested;
                beneficiary        = salary.PayrollItem.PersonCanonical;
                amountCents        = salary.GrossSalaryCents + salary.AdditiveTaxCents;

                break;

            case 'P':     // Parley, aka Conference
                Parley parley = Parley.FromIdentity(itemId);
                if (parley.OrganizationId != authData.CurrentOrganization.Identity)
                {
                    throw new InvalidOperationException("Called to attest out-of-org line item");
                }
                if (parley.Budget.OwnerPersonId != authData.CurrentUser.Identity &&
                    parley.Budget.OwnerPersonId != Person.NobodyId)
                {
                    throw new SecurityException("Called without attestation privileges");
                }

                approvableItem     = parley;
                attestedTemplate   = Resources.Pages.Financial.AttestCosts_ParleyAttested;
                deattestedTemplate = Resources.Pages.Financial.AttestCosts_ParleyDeattested;
                beneficiary        = parley.Person.Name;
                amountCents        = parley.BudgetCents;

                break;

            default:
                throw new InvalidOperationException("Unknown Cost Type in HandleAttestationDeattestation: \"" +
                                                    identifier + "\"");
            }

            // Finally, attest or deattest

            if (mode == AttestationMode.Attestation)
            {
                Int64 budgetRemaining = approvableItem.Budget.GetBudgetCentsRemaining();

                result = string.Empty;

                if (amountCents > -budgetRemaining)
                {
                    if (
                        authData.Authority.HasAccess(new Access(authData.CurrentOrganization,
                                                                AccessAspect.Administration)))
                    {
                        // Admin rights, so allow (forced) overdraft

                        // Unless budget was nonzero and allocated, set protest message

                        if (approvableItem.Budget.Owner != null || approvableItem.Budget.GetBudgetCents() != 0)
                        {
                            result = Resources.Pages.Financial.AttestCosts_Overdrafted + " ";
                        }
                    }
                    else
                    {
                        // Do not allow overdraft

                        return(new AjaxCallResult
                        {
                            DisplayMessage = Resources.Pages.Financial.AttestCosts_OutOfBudget,
                            Success = false
                        });
                    }
                }

                approvableItem.Approve(authData.CurrentUser);
                result += string.Format(attestedTemplate, itemId, beneficiary,
                                        authData.CurrentOrganization.Currency.Code,
                                        amountCents / 100.0);
            }
            else if (mode == AttestationMode.Deattestation)
            {
                approvableItem.RetractApproval(authData.CurrentUser);
                result = string.Format(deattestedTemplate, itemId, beneficiary,
                                       authData.CurrentOrganization.Currency.Code,
                                       amountCents / 100.0);
            }
            else
            {
                throw new InvalidOperationException("Unknown Approval Mode: " + mode);
            }

            FinancialAccount.ClearApprovalAdjustmentsCache(authData.CurrentOrganization);

            return(new AjaxCallResult {
                DisplayMessage = result, Success = true
            });
        }
예제 #4
0
        private static string HandleAttestationDeattestation(string identifier, AttestationMode mode)
        {
            AuthenticationData authData = GetAuthenticationDataAndCulture();

            IAttestable attestableItem     = null;
            string      attestedTemplate   = string.Empty;
            string      deattestedTemplate = string.Empty;

            char   costType = identifier[0];
            int    itemId   = Int32.Parse(identifier.Substring(1));
            Int64  amountCents;
            string beneficiary = string.Empty;
            string result      = string.Empty;

            // Find the item we are attesting or deattesting

            switch (costType)
            {
            case 'A':     // Case advance
                CashAdvance advance = CashAdvance.FromIdentity(itemId);
                if (advance.OrganizationId != authData.CurrentOrganization.Identity)
                {
                    throw new InvalidOperationException("Called to attest out-of-org line item");
                }
                if (advance.Budget.OwnerPersonId != authData.CurrentUser.Identity &&
                    advance.Budget.OwnerPersonId != Person.NobodyId)
                {
                    throw new SecurityAccessDeniedException("Called without attestation privileges");
                }

                attestableItem     = advance;
                attestedTemplate   = Resources.Pages.Financial.AttestCosts_AdvanceAttested;
                deattestedTemplate = Resources.Pages.Financial.AttestCosts_AdvanceDeattested;
                beneficiary        = advance.Person.Name;
                amountCents        = advance.AmountCents;

                break;

            case 'E':     // Expense claim
                ExpenseClaim expense = ExpenseClaim.FromIdentity(itemId);
                if (expense.OrganizationId != authData.CurrentOrganization.Identity)
                {
                    throw new InvalidOperationException("Called to attest out-of-org line item");
                }
                if (expense.Budget.OwnerPersonId != authData.CurrentUser.Identity &&
                    expense.Budget.OwnerPersonId != Person.NobodyId)
                {
                    throw new SecurityAccessDeniedException("Called without attestation privileges");
                }

                attestableItem     = expense;
                attestedTemplate   = Resources.Pages.Financial.AttestCosts_ExpenseAttested;
                deattestedTemplate = Resources.Pages.Financial.AttestCosts_ExpenseDeattested;
                beneficiary        = expense.Claimer.Name;
                amountCents        = expense.AmountCents;

                break;

            case 'I':     // Inbound invoice
                InboundInvoice invoice = InboundInvoice.FromIdentity(itemId);
                if (invoice.OrganizationId != authData.CurrentOrganization.Identity)
                {
                    throw new InvalidOperationException("Called to attest out-of-org line item");
                }
                if (invoice.Budget.OwnerPersonId != authData.CurrentUser.Identity &&
                    invoice.Budget.OwnerPersonId != Person.NobodyId)
                {
                    throw new SecurityAccessDeniedException("Called without attestation privileges");
                }

                attestableItem     = invoice;
                attestedTemplate   = Resources.Pages.Financial.AttestCosts_InvoiceAttested;
                deattestedTemplate = Resources.Pages.Financial.AttestCosts_InvoiceDeattested;
                beneficiary        = invoice.Supplier;
                amountCents        = invoice.AmountCents;

                break;

            case 'S':     // Salary payout
                Salary salary = Salary.FromIdentity(itemId);
                if (salary.PayrollItem.OrganizationId != authData.CurrentOrganization.Identity)
                {
                    throw new InvalidOperationException("Called to attest out-of-org line item");
                }
                if (salary.PayrollItem.Budget.OwnerPersonId != authData.CurrentUser.Identity &&
                    salary.PayrollItem.Budget.OwnerPersonId != Person.NobodyId)
                {
                    throw new SecurityAccessDeniedException("Called without attestation privileges");
                }

                attestableItem     = salary;
                attestedTemplate   = Resources.Pages.Financial.AttestCosts_SalaryAttested;
                deattestedTemplate = Resources.Pages.Financial.AttestCosts_SalaryDeattested;
                beneficiary        = salary.PayrollItem.PersonCanonical;
                amountCents        = salary.GrossSalaryCents;

                break;

            case 'P':     // Parley, aka Conference
                Parley parley = Parley.FromIdentity(itemId);
                if (parley.OrganizationId != authData.CurrentOrganization.Identity)
                {
                    throw new InvalidOperationException("Called to attest out-of-org line item");
                }
                if (parley.Budget.OwnerPersonId != authData.CurrentUser.Identity &&
                    parley.Budget.OwnerPersonId != Person.NobodyId)
                {
                    throw new SecurityAccessDeniedException("Called without attestation privileges");
                }

                attestableItem     = parley;
                attestedTemplate   = Resources.Pages.Financial.AttestCosts_ParleyAttested;
                deattestedTemplate = Resources.Pages.Financial.AttestCosts_ParleyDeattested;
                beneficiary        = parley.Person.Name;
                amountCents        = parley.BudgetCents;

                break;

            default:
                throw new InvalidOperationException("Unknown Cost Type in HandleAttestationDeattestation: \"" +
                                                    identifier + "\"");
            }

            // Finally, attest or deattest

            if (mode == AttestationMode.Attestation)
            {
                attestableItem.Attest(authData.CurrentUser);
                result = string.Format(attestedTemplate, itemId, beneficiary,
                                       authData.CurrentOrganization.Currency.Code,
                                       amountCents / 100.0);
            }
            else if (mode == AttestationMode.Deattestation)
            {
                attestableItem.Deattest(authData.CurrentUser);
                result = string.Format(deattestedTemplate, itemId, beneficiary,
                                       authData.CurrentOrganization.Currency.Code,
                                       amountCents / 100.0);
            }
            else
            {
                throw new InvalidOperationException("Unknown Attestation Mode: " + mode);
            }

            return(result);
        }
예제 #5
0
        public static PaymentTransferInfoResult GetPaymentTransferInfo(string prototypeId)
        {
            AuthenticationData authData = GetAuthenticationDataAndCulture();

            // TODO: Authentication check

            string[] payoutComponents = prototypeId.Split('|');

            if (payoutComponents.Length < 1)
            {
                throw new InvalidOperationException("Prototype ID can't be empty");
            }

            PaymentTransferInfo info = new PaymentTransferInfo();

            // Some payouts are composites of multiple objects, but all these will share the same
            // payout data, so we can safely use just the first object to determine payment
            // target information
            //
            // with one exception -- we need to determine the amount by adding all the objects
            // together, if applicable

            DateTime paymentDueBy = Constants.DateTimeLow;

            switch (Char.ToUpperInvariant(payoutComponents[0][0]))
            {
            case 'C':     // expense claim
                info =
                    PaymentTransferInfo.FromObject(
                        ExpenseClaim.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1))),
                        new Money(GetSumCentsTotal(prototypeId), authData.CurrentOrganization.Currency));
                break;

            case 'A':     // cash advance (payout or payback, same logic either way)
                info =
                    PaymentTransferInfo.FromObject(
                        CashAdvance.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1))),
                        new Money(GetSumCentsTotal(prototypeId), authData.CurrentOrganization.Currency));
                break;

            case 'S':     // salary
                Salary salary = Salary.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1)));
                info         = PaymentTransferInfo.FromObject(salary);
                paymentDueBy = salary.PayoutDate;
                break;

            case 'I':     // inbound invoice
                InboundInvoice invoice = InboundInvoice.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1)));
                info         = PaymentTransferInfo.FromObject(invoice);
                paymentDueBy = invoice.DueDate;
                break;

            default:
                throw new NotImplementedException("Unrecognized payment type");
            }

            PaymentTransferInfoResult result = new PaymentTransferInfoResult
            {
                Success        = true,
                CurrencyAmount = info.CurrencyAmount,
                DisplayMessage = string.Empty,
                Recipient      = info.Recipient,
                Reference      = info.Reference,
                TransferMethod = info.LocalizedPaymentMethodName
            };

            if (paymentDueBy < Constants.DateTimeLowThreshold)
            {
                result.DueBy = Resources.Global.Global_ASAP;
            }
            else
            {
                DateTime nowUtc = DateTime.UtcNow;

                if (paymentDueBy.Year != nowUtc.Year || paymentDueBy < nowUtc.AddMonths(-3))
                {
                    result.DueBy = paymentDueBy.ToString(Resources.Global.Global_DateFormatLongSansWeekday);
                }
                else
                {
                    result.DueBy = paymentDueBy.ToString(Resources.Global.Global_DateFormatLongDateMonth);
                }

                if (paymentDueBy < nowUtc.AddDays(-1))
                {
                    result.DueBy += " - " + Resources.Pages.Financial.PayOutMoney_PaymentLate;
                }
            }

            List <string> listTransferMethodLabels = new List <string>();
            List <string> listTransferMethodData   = new List <string>();

            foreach (string label in info.LocalizedPaymentInformation.Keys)
            {
                listTransferMethodLabels.Add(HttpUtility.HtmlEncode(label));
                listTransferMethodData.Add(HttpUtility.HtmlEncode(info.LocalizedPaymentInformation [label]));
            }

            result.TransferMethodLabels = listTransferMethodLabels.ToArray();
            result.TransferMethodData   = listTransferMethodData.ToArray();
            result.OcrData = info.OcrData;  // can be null and that's ok

            return(result);
        }
예제 #6
0
    protected void ButtonAttest_Click(object sender, EventArgs e)
    {
        List <string> identityStrings = new List <string>();

        foreach (string indexString in this.GridAttestables.SelectedIndexes)
        {
            int    index = Int32.Parse(indexString);
            string itemIdentityString = (string)this.GridAttestables.MasterTableView.DataKeyValues[index]["Identity"];
            int    itemIdentity       = Int32.Parse(itemIdentityString.Substring(1));


            // Mark items as attested

            switch (itemIdentityString[0])
            {
            case 'E':
                ExpenseClaim claim = ExpenseClaim.FromIdentity(itemIdentity);

                if (attestationRights.ContainsKey(claim.BudgetId))
                {
                    claim.Attest(_currentUser);
                    Activizr.Logic.Support.PWEvents.CreateEvent(
                        EventSource.PirateWeb, EventType.ExpenseAttested, _currentUser.Identity,
                        claim.OrganizationId, 0, claim.ClaimingPersonId, claim.Identity, string.Empty);
                }
                break;

            case 'I':
                InboundInvoice invoice = InboundInvoice.FromIdentity(itemIdentity);

                if (attestationRights.ContainsKey(invoice.BudgetId))
                {
                    invoice.Attest(_currentUser);
                    Activizr.Logic.Support.PWEvents.CreateEvent(
                        EventSource.PirateWeb, EventType.InboundInvoiceAttested, _currentUser.Identity,
                        invoice.OrganizationId, 0, 0, invoice.Identity, string.Empty);
                }
                break;

            case 'S':
                Salary salary = Salary.FromIdentity(itemIdentity);

                // Mark as attested

                bool mayAttest = false;

                if (attestationRights.ContainsKey(salary.PayrollItem.BudgetId) && salary.PayrollItem.PersonId != _currentUser.Identity)
                {
                    mayAttest = true;
                }

                if (salary.PayrollItem.ReportsToPersonId == _currentUser.Identity)
                {
                    mayAttest = true;
                }

                if (mayAttest)
                {
                    salary.Attest(_currentUser);
                    Activizr.Logic.Support.PWEvents.CreateEvent(
                        EventSource.PirateWeb, EventType.SalaryAttested, _currentUser.Identity,
                        salary.PayrollItem.OrganizationId, 0, 0, salary.Identity, string.Empty);
                }
                break;

            case 'P':
                Parley parley = Parley.FromIdentity(itemIdentity);

                if (attestationRights.ContainsKey(parley.BudgetId))
                {
                    parley.Attest(_currentUser);
                }
                break;
            }
        }

        this.GridAttestables.Rebind();
    }