protected void ButtonInvoice_Click(object sender, EventArgs e)
    {
        if (_authority.HasPermission(Permission.CanPayOutMoney, Organization.PPSEid, -1, Authorization.Flag.ExactOrganization))
        {
            foreach (string indexString in this.GridDebts.SelectedIndexes)
            {
                // Creating the invoice closes the expense claims.

                int      index           = Int32.Parse(indexString);
                string   protoIdentity   = (string)this.GridDebts.MasterTableView.DataKeyValues[index]["ProtoIdentity"];
                string[] identityStrings = protoIdentity.Split(',');

                ExpenseClaim template = ExpenseClaim.FromIdentity(Int32.Parse(identityStrings[0]));

                CultureInfo oldCulture = CultureInfo.CurrentUICulture;
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(Organization.PPSE.DefaultCountry.Culture);

                OutboundInvoice invoice = OutboundInvoice.Create(Organization.PPSE, _currentUser,
                                                                 DateTime.Today.AddDays(30),
                                                                 Organization.PPSE.FinancialAccounts.DebtsExpenseClaims,
                                                                 template.Claimer.Name,
                                                                 template.Claimer.Email,
                                                                 template.Claimer.Street + "\r\n" +
                                                                 template.Claimer.PostalCodeAndCity,
                                                                 Organization.PPSE.DefaultCountry.Currency,
                                                                 true, GetLocalResourceObject("InvoiceLiterals.ReclaimedCashAdvance").ToString());

                Thread.CurrentThread.CurrentUICulture = oldCulture;

                foreach (string idString in identityStrings)
                {
                    int          claimId = Int32.Parse(idString);
                    ExpenseClaim claim   = ExpenseClaim.FromIdentity(claimId);

                    invoice.AddItem("Exp #" + claim.Identity.ToString() + ": " + claim.Description, -claim.AmountCents);
                    claim.Repaid = true;
                    claim.Open   = false;
                }

                // Create transaction

                FinancialTransaction transaction = FinancialTransaction.Create(Organization.PPSEid, DateTime.Now,
                                                                               "Outbound Invoice #" + invoice.Identity +
                                                                               ": " + template.ClaimerCanonical);
                transaction.AddRow(Organization.PPSE.FinancialAccounts.DebtsExpenseClaims, -invoice.AmountCents, _currentUser);
                transaction.AddRow(Organization.PPSE.FinancialAccounts.AssetsOutboundInvoices, invoice.AmountCents, _currentUser);

                transaction.Dependency = invoice;

                // Create event

                Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.OutboundInvoiceCreated,
                                                            _currentUser.Identity, 1, 1, 0, invoice.Identity,
                                                            protoIdentity);
            }

            PopulateGrid();
            this.GridDebts.Rebind();
        }
    }
    private void CheckExceedage()
    {
        this.IconWarningExceedage.Visible  = false;
        this.LabelWarningExceedage.Visible = false;

        if (this.RadioPreattested.Checked && this.DropPreattested.SelectedIndex != 0)
        {
            // Compare the preattested amount with the claimed amount. If claimed > attested, show warning that re-attestation is needed.

            try
            {
                decimal claimedAmount  = Decimal.Parse(this.TextAmount.Text, NumberStyles.Float, new CultureInfo("sv-SE"));
                decimal attestedAmount =
                    ExpenseClaim.FromIdentity(Int32.Parse(this.DropPreattested.SelectedValue)).Amount;

                bool warningVisible = (claimedAmount > attestedAmount);
                this.LabelWarningExceedage.Visible = warningVisible;
                this.IconWarningExceedage.Visible  = warningVisible;
            }
            catch (Exception)
            {
                // Ignore exceptions, which will come from a non-selection of preattested claim or an invalid number
            }
        }
    }
Exemple #3
0
        static private Int64 GetSumCentsTotal(string prototypeId)
        {
            string[] payoutComponents = prototypeId.Split('|');

            Int64 amountCentsTotal = 0;

            foreach (string payoutComponent in payoutComponents)
            {
                switch (payoutComponent[0])
                {
                case 'C':
                    amountCentsTotal += ExpenseClaim.FromIdentity(Int32.Parse(payoutComponent.Substring(1))).AmountCents;
                    break;

                case 'A':      // Advance pay-OUT
                    amountCentsTotal += CashAdvance.FromIdentity(Int32.Parse(payoutComponent.Substring(1))).AmountCents;
                    break;

                case 'a':      // Advance pay-BACK
                    amountCentsTotal -= CashAdvance.FromIdentity(Int32.Parse(payoutComponent.Substring(1))).AmountCents;
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            return(amountCentsTotal);
        }
    protected void ButtonValidate_Click(object sender, EventArgs e)
    {
        List <string> identityStrings = new List <string>();

        foreach (string indexString in this.GridExpenseClaims.SelectedIndexes)
        {
            int          index   = Int32.Parse(indexString);
            int          claimId = (int)this.GridExpenseClaims.MasterTableView.DataKeyValues[index]["Identity"];
            ExpenseClaim claim   = ExpenseClaim.FromIdentity(claimId);

            // Mark as validated

            if (_authority.HasPermission(Permission.CanDoEconomyTransactions, Organization.PPSEid, -1, Authorization.Flag.ExactOrganization))
            {
                claim.Validate(_currentUser);
                Activizr.Logic.Support.PWEvents.CreateEvent(
                    EventSource.PirateWeb, EventType.ExpenseValidated, _currentUser.Identity,
                    claim.OrganizationId, 0, claim.ClaimingPersonId, claimId, string.Empty);
            }
        }

        // TODO: Create event, so that expenser is informed. Use 'identityStrings'.

        this.GridExpenseClaims.Rebind();
    }
    protected void GridExpenses_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
        case "Approve":
            int          currentUserId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
            int          index         = Convert.ToInt32(e.CommandArgument);
            int          expenseId     = Convert.ToInt32(this.GridExpenses.DataKeys[index].Value);
            ExpenseClaim expenseClaim  = ExpenseClaim.FromIdentity(expenseId);

            expenseClaim.CreateEvent(ExpenseEventType.Approved, currentUserId);
            Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.ExpenseChanged, currentUserId, expenseClaim.OrganizationId, expenseClaim.GeographyId, expenseClaim.ClaimingPersonId, expenseClaim.Identity, ExpenseEventType.Approved.ToString());
            Repopulate();
            break;
        }
    }
        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");
            }
        }
Exemple #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        _expenseClaim = ExpenseClaim.FromIdentity(Int32.Parse(Request.QueryString["ExpenseClaimId"]));

        // TODO: Verify authority (economy assistant or claimer)

        if (!Page.IsPostBack)
        {
            this.LabelClaimer.Text    = _expenseClaim.ClaimerCanonical;
            this.LabelClaimDate.Text  = _expenseClaim.CreatedDateTime.ToString("yyyy-MM-dd HH:mm");
            this.TextDescription.Text = _expenseClaim.Description;
            this.LabelAttested.Text   = _expenseClaim.Attested? "Yes." : "No.";
            this.LabelValidated.Text  = _expenseClaim.Validated? "Yes." : "No.";

            if (_expenseClaim.AmountCents < 0)
            {
                // If the expense amount is negative, include income accounts (donations, etc)

                this.DropAccounts.Populate(_expenseClaim.Organization, FinancialAccountType.Result);
            }
            else
            {
                this.DropAccounts.Populate(_expenseClaim.Organization, FinancialAccountType.Cost);
            }

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

            this.DateExpense.SelectedDate = _expenseClaim.ExpenseDate;
            this.TextAmount.Text          = _expenseClaim.Amount.ToString("N2", new CultureInfo("sv-SE"));
            this.TextDescription.Style[HtmlTextWriterStyle.Width] = "250px";
        }

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

        this.DocumentList.Documents = Documents.ForObject(_expenseClaim);
    }
    private void ProcessPreattestChange()
    {
        bool selectedPreattested = this.RadioPreattested.Checked;

        if (this.DropPreattested.SelectedIndex == 0)
        {
            selectedPreattested = false;
        }
        else
        {
            ExpenseClaim claim = ExpenseClaim.FromIdentity(Int32.Parse(this.DropPreattested.SelectedValue));

            this.LabelPreattestedBudget.Text = claim.Budget.Name;
            this.LabelDescription.Text       = claim.Description;
            this.TextDescription.Text        = claim.Description;
        }

        this.DropBudgets.Visible            = !selectedPreattested;
        this.LabelBudgetOwner.Visible       = selectedPreattested;
        this.TextDescription.Visible        = !selectedPreattested;
        this.LabelDescription.Visible       = selectedPreattested;
        this.LabelPreattestedBudget.Visible = selectedPreattested;
    }
Exemple #9
0
        private static string HandleValidationDevalidation(string identifier, ApprovalMode mode)
        {
            AuthenticationData authData = GetAuthenticationDataAndCulture();

            IValidatable validatableItem   = null;
            string       validatedTemplate = string.Empty;
            string       retractedTemplate = string.Empty;

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

            // A lot of this code was copied from attest/deattest, even though validation only concerns expense receipts

            switch (costType)
            {
            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 (
                    !authData.Authority.HasAccess(new Access(authData.CurrentOrganization,
                                                             AccessAspect.Financials, AccessType.Write)))
                {
                    throw new UnauthorizedAccessException();
                }

                validatableItem   = expense;
                validatedTemplate = Resources.Pages.Financial.ValidateReceipts_ReceiptsValidated;
                retractedTemplate = Resources.Pages.Financial.ValidateReceipts_ReceiptsDevalidated;
                amountCents       = expense.AmountCents;

                break;

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

            // Finally, attest or deattest

            if (mode == ApprovalMode.Approval)
            {
                validatableItem.Validate(authData.CurrentUser);
                result = string.Format(validatedTemplate, itemId, authData.CurrentOrganization.Currency.Code,
                                       amountCents / 100.0);
            }
            else if (mode == ApprovalMode.Retraction)
            {
                validatableItem.RetractValidation(authData.CurrentUser);
                result = string.Format(retractedTemplate, itemId, authData.CurrentOrganization.Currency.Code,
                                       amountCents / 100.0);
            }
            else
            {
                throw new InvalidOperationException("Unknown Approval Mode: " + mode);
            }

            return(result);
        }
        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
            });
        }
Exemple #11
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);
        }
    protected void ButtonSubmitClaim_Click(object sender, EventArgs e)
    {
        // First, if there's an upload that the user hasn't processed, process it first.

        if (this.Upload.UploadedFiles.Count > 0)
        {
            ProcessUpload();
        }

        // If args were invalid, abort

        if (!Page.IsValid)
        {
            return;
        }

        // Set bank details

        _currentUser.BankName     = this.TextBank.Text.Trim();
        _currentUser.BankClearing = Formatting.CleanNumber(this.TextBankClearing.Text.Trim());
        _currentUser.BankAccount  = Formatting.CleanNumber(this.TextAccount.Text.Trim());

        // Read the form data

        int temporaryId = Int32.Parse(this.TemporaryDocumentIdentity.Text);

        int          organizationId = Int32.Parse(this.DropOrganizations.SelectedValue);
        Organization organization   = Organization.FromIdentity(organizationId);

        Int64            amountCents = (Int64)(Double.Parse(this.TextAmount.Text, new CultureInfo("sv-SE")) * 100);
        FinancialAccount account     = this.DropBudgets.SelectedFinancialAccount;
        DateTime         created     = DateTime.Now;
        DateTime         expenseDate = (DateTime)this.DatePicker.SelectedDate;
        string           description = this.TextDescription.Text;
        int claimId = 0;

        if (this.RadioNewClaim.Checked)
        {
            // Create the expense claim record

            ExpenseClaim newClaim = ExpenseClaim.Create(_currentUser,
                                                        organization, account, expenseDate,
                                                        description, amountCents);
            claimId = newClaim.Identity;

            // Move documents to the new expense claim

            Documents.ForObject(new TemporaryIdentity(temporaryId)).SetForeignObjectForAll(newClaim);
        }
        else
        {
            // This was a pre-approved claim: modify the existing claim and transaction

            ExpenseClaim         claim       = ExpenseClaim.FromIdentity(Int32.Parse(this.DropPreattested.SelectedValue));
            FinancialTransaction transaction = claim.FinancialTransaction;
            claimId = claim.Identity;

            claim.Claimed = true;

            // If claimed amount exceeds attested amount, unattest

            if (amountCents > claim.AmountCents)
            {
                claim.Deattest(_currentUser);
            }

            // Change amount and date

            claim.SetAmountCents(amountCents, _currentUser);
            claim.ExpenseDate = expenseDate;

            // Move documents to the expense claim

            Documents.ForObject(new TemporaryIdentity(temporaryId)).SetForeignObjectForAll(claim);
        }

        // Create the event for PirateBot-Mono to send off mails

        Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.ExpenseCreated,
                                                    _currentUser.Identity, organizationId, Geography.RootIdentity, _currentUser.Identity,
                                                    claimId, string.Empty);

        Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", @"alert ('Your expense claim has been submitted.');", true);

        // Clear the text fields

        this.TextDescription.Text           = string.Empty;
        this.TextAmount.Text                = "0,00"; // TODO: LOCALIZE BY CULTURE
        this.TemporaryDocumentIdentity.Text = "0";

        PopulateGrid();
        PopulatePreattested();
    }
Exemple #13
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);
        }
Exemple #14
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();
    }