diff --git a/Logic/Financial/OutboundInvoice.cs b/Logic/Financial/OutboundInvoice.cs
index ee39b092..c3daaaf2 100644
--- a/Logic/Financial/OutboundInvoice.cs
+++ b/Logic/Financial/OutboundInvoice.cs
@@ -228,9 +228,7 @@ namespace Swarmops.Logic.Financial
return result;
}
- public static OutboundInvoice Create (Organization organization, Person createdByPerson, DateTime dueDate,
- FinancialAccount budget, string customerName, string invoiceAddressMail, string invoiceAddressPaper,
- Currency currency, bool domestic, string theirReference)
+ public static OutboundInvoice Create (Organization organization, DateTime dueDate, FinancialAccount budget, string customerName, string invoiceAddressMail, string invoiceAddressPaper, Currency currency, bool domestic, string theirReference, Person createdByPerson)
{
OutboundInvoice invoice =
FromIdentity (SwarmDb.GetDatabaseForWriting()
@@ -272,11 +270,11 @@ namespace Swarmops.Logic.Financial
public OutboundInvoice Credit (Person creditingPerson)
{
- OutboundInvoice credit = Create (Organization, creditingPerson, DateTime.Now,
+ OutboundInvoice credit = Create (Organization, DateTime.Now,
Budget, CustomerName,
InvoiceAddressMail,
InvoiceAddressPaper, Currency,
- Domestic, TheirReference);
+ Domestic, TheirReference, creditingPerson);
if (Domestic) // TODO: LANGUAGE
{
credit.AddItem ("Kredit för faktura " + Reference, -AmountCents);
diff --git a/Logic/Swarm/ParleyAttendee.cs b/Logic/Swarm/ParleyAttendee.cs
index babcfea9..de0aac51 100644
--- a/Logic/Swarm/ParleyAttendee.cs
+++ b/Logic/Swarm/ParleyAttendee.cs
@@ -79,11 +79,11 @@ namespace Swarmops.Logic.Swarm
invoiceDue = maxInvoiceDue;
}
- OutboundInvoice invoice = OutboundInvoice.Create (Parley.Organization, Parley.Person, invoiceDue,
+ OutboundInvoice invoice = OutboundInvoice.Create (Parley.Organization, invoiceDue,
Parley.Budget, Person.Name, Person.Mail,
string.Empty,
Parley.Organization.DefaultCountry.Currency, true,
- string.Empty);
+ string.Empty, Parley.Person);
invoice.AddItem ("Deltagarkostnad " + Parley.Name, Parley.AttendanceFeeCents); // TODO: Localize
diff --git a/Site/App_GlobalResources/Global.designer.cs b/Site/App_GlobalResources/Global.designer.cs
index 253c4e09..8b17e99d 100644
--- a/Site/App_GlobalResources/Global.designer.cs
+++ b/Site/App_GlobalResources/Global.designer.cs
@@ -312,6 +312,15 @@ namespace Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Client / Customer.
+ ///
+ internal static string Financial_Client {
+ get {
+ return ResourceManager.GetString("Financial_Client", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Expenses.
///
diff --git a/Site/App_GlobalResources/Global.resx b/Site/App_GlobalResources/Global.resx
index 512aa333..1f4e80fa 100644
--- a/Site/App_GlobalResources/Global.resx
+++ b/Site/App_GlobalResources/Global.resx
@@ -909,4 +909,7 @@
Annual Profit/Loss To Date ({0})
{0} is the currency code
+
+ Client / Customer
+
\ No newline at end of file
diff --git a/Site/App_GlobalResources/Menu5.designer.cs b/Site/App_GlobalResources/Menu5.designer.cs
index 27a9dae9..cd5a1e94 100644
--- a/Site/App_GlobalResources/Menu5.designer.cs
+++ b/Site/App_GlobalResources/Menu5.designer.cs
@@ -349,7 +349,7 @@ namespace Resources {
}
///
- /// Looks up a localized string similar to List.
+ /// Looks up a localized string similar to List....
///
internal static string Menu5_Financial_List {
get {
diff --git a/Site/App_GlobalResources/Menu5.resx b/Site/App_GlobalResources/Menu5.resx
index b5bacf21..3aeb93d4 100644
--- a/Site/App_GlobalResources/Menu5.resx
+++ b/Site/App_GlobalResources/Menu5.resx
@@ -193,7 +193,7 @@
Gigs Assistant
- List
+ List...
Cash Requests
diff --git a/Site/Images/Icons/iconshock-empty-tick-128x96px.png b/Site/Images/Icons/iconshock-empty-tick-128x96px.png
new file mode 100644
index 00000000..ff6911e7
Binary files /dev/null and b/Site/Images/Icons/iconshock-empty-tick-128x96px.png differ
diff --git a/Site/MainMenu-v5.xml b/Site/MainMenu-v5.xml
index d5b4720f..7c92713b 100644
--- a/Site/MainMenu-v5.xml
+++ b/Site/MainMenu-v5.xml
@@ -245,8 +245,35 @@
Separator
-
+
+
+ Financial_List
+ 3
+
+ Disabled
+
+ Financial_List_InboundInvoices
+ 3
+
+
+ /Pages/v5/Financial/ListInvoicesInbound.aspx
+ Link
+
+
+
+ Financial_List_OutboundInvoices
+ 3
+
+
+ /Pages/v5/Financial/ListInvoicesInbound.aspx
+ Link
+
+
+
+
+
+
Financial_Payroll
3
diff --git a/Site/Pages/v5/Admin/Hacks/TemporaryHack.aspx.cs b/Site/Pages/v5/Admin/Hacks/TemporaryHack.aspx.cs
index 8043f192..d949b476 100644
--- a/Site/Pages/v5/Admin/Hacks/TemporaryHack.aspx.cs
+++ b/Site/Pages/v5/Admin/Hacks/TemporaryHack.aspx.cs
@@ -22,9 +22,9 @@ public partial class Pages_v5_Admin_Hacks_TemporaryHack : Page
{
// outbound intl invoice. Add an untracked intl invoice 10 days prior, map it to this
- OutboundInvoice newInvoice = OutboundInvoice.Create (euroPirates, Person.FromIdentity (1),
+ OutboundInvoice newInvoice = OutboundInvoice.Create (euroPirates,
transaction.DateTime, euroPirates.FinancialAccounts.IncomeSales, "Untracked",
- "untracked@example.com", string.Empty, euroPirates.Currency, false, string.Empty);
+ "untracked@example.com", string.Empty, euroPirates.Currency, false, string.Empty, Person.FromIdentity (1));
newInvoice.AddItem ("Untracked item", transaction.Rows.BalanceCentsDelta);
// Doesn't close
diff --git a/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx b/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx
index 024c24cc..4aa756f9 100644
--- a/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx
+++ b/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx
@@ -39,8 +39,6 @@
function validateFields() {
var isValid = true;
- isValid = validateTextField('#<%=this.TextAccount.ClientID %>', SwarmopsJS.unescape('<%= this.Localized_ValidationError_Account %>')) && isValid;
-
if ($('#<%=this.ComboBudgets.ClientID %>_DropBudgets').combotree('tree').tree('getSelected') == null) {
isValid = false;
$('#<%=this.ComboBudgets.ClientID %>_SpanBudgets').addClass("entryError");
@@ -145,12 +143,12 @@
-
+
-
+
">
@@ -162,12 +160,11 @@
-
-
+
@@ -177,7 +174,6 @@
-
diff --git a/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.cs b/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.cs
index ff1d6dce..1a56fd3c 100644
--- a/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.cs
+++ b/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.cs
@@ -101,7 +101,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
this.CurrencyAmount.Cents = 0;
this.CurrencyVat.Cents = 0;
- this.TextSupplier.Focus();
+ this.TextClient.Focus();
this.TextDueDate.Text = DateTime.Today.AddDays (30).ToShortDateString(); // Use current culture
Localize();
@@ -111,7 +111,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
private void Localize()
{
- this.LabelSupplier.Text = Global.Financial_Supplier;
+ this.LabelClient.Text = Global.Financial_Client;
this.LabelDueDate.Text = Global.Financial_DueDate;
this.LabelAmount.Text = string.Format (Resources.Pages.Financial.CreateInboundInvoice_Amount,
CurrentOrganization.Currency.Code);
@@ -123,7 +123,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial
this.LabelHeaderImageFiles.Text = Resources.Pages.Financial.CreateInboundInvoice_HeaderInvoiceImage;
this.LabelImageFiles.Text = Resources.Pages.Financial.CreateInboundInvoice_UploadInvoiceImage;
this.LabelReference.Text = Resources.Pages.Financial.CreateInboundInvoice_Reference;
- this.LabelAccount.Text = Resources.Pages.Financial.CreateInboundInvoice_SupplierAccount;
this.ButtonCreate.Text = Resources.Pages.Financial.CreateInboundInvoice_ButtonCreate;
}
@@ -148,7 +147,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
if (budget.Organization.Identity != CurrentOrganization.Identity)
{
- throw new InvalidOperationException ("Budget-organization mismatch; won't file expense claim");
+ throw new InvalidOperationException ("Budget-organization mismatch; won't file invoice");
}
@@ -161,25 +160,11 @@ namespace Swarmops.Frontend.Pages.v5.Financial
throw new InvalidOperationException ("No documents uploaded");
}
- InboundInvoice invoice = InboundInvoice.Create (CurrentOrganization, dueDate, amountCents, amountVatCents, budget,
- this.TextSupplier.Text, this.TextPurpose.Text, this.TextAccount.Text, string.Empty,
- this.TextReference.Text, CurrentUser);
+ OutboundInvoice invoice = OutboundInvoice.Create (CurrentOrganization, dueDate, budget, this.TextClient.Text, string.Empty, string.Empty, CurrentOrganization.Currency, false, this.TextReference.Text, CurrentUser);
- foreach (int tagSetId in this._tagSetIds)
- {
- string selectedTagString =
- Request.Form["DropTags" + tagSetId.ToString (CultureInfo.InvariantCulture)];
+ invoice.AddItem(this.TextPurpose.Text, amountCents);
- if (!String.IsNullOrEmpty (selectedTagString))
- {
- int selectedTagType = Int32.Parse (selectedTagString);
- if (selectedTagType != 0)
- {
- invoice.FinancialTransaction.CreateTag (
- FinancialTransactionTagType.FromIdentity (selectedTagType), CurrentUser);
- }
- }
- }
+ // TODO: VAT
documents.SetForeignObjectForAll (invoice);
@@ -190,8 +175,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
// Reset all fields for next invoice
this.FileUpload.Reset();
- this.TextSupplier.Text = String.Empty;
- this.TextAccount.Text = String.Empty;
+ this.TextClient.Text = String.Empty;
this.TextPurpose.Text = String.Empty;
this.TextReference.Text = String.Empty;
this.CurrencyAmount.Cents = 0;
@@ -200,7 +184,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
// the easyUI combo fields should reset automatically on form submission unless we explicitly reconstruct
- this.TextSupplier.Focus();
+ this.TextClient.Focus();
}
diff --git a/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.designer.cs b/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.designer.cs
index 897d1842..791334d9 100644
--- a/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.designer.cs
+++ b/Site/Pages/v5/Financial/CreateOutboundInvoice.aspx.designer.cs
@@ -49,13 +49,13 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
protected global::System.Web.UI.WebControls.HiddenField HiddenTagSetIdentifiers;
///
- /// TextSupplier control.
+ /// TextClient control.
///
///
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
///
- protected global::System.Web.UI.WebControls.TextBox TextSupplier;
+ protected global::System.Web.UI.WebControls.TextBox TextClient;
///
/// CurrencyAmount control.
@@ -120,15 +120,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
///
protected global::Swarmops.Controls.Base.FileUpload FileUpload;
- ///
- /// TextAccount control.
- ///
- ///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
- ///
- protected global::System.Web.UI.WebControls.TextBox TextAccount;
-
///
/// TextReference control.
///
@@ -148,13 +139,13 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
protected global::System.Web.UI.WebControls.Button ButtonCreate;
///
- /// LabelSupplier control.
+ /// LabelClient control.
///
///
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
///
- protected global::System.Web.UI.WebControls.Label LabelSupplier;
+ protected global::System.Web.UI.WebControls.Label LabelClient;
///
/// LabelAmount control.
@@ -237,15 +228,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
///
protected global::System.Web.UI.WebControls.Label LabelHeaderBankDetails;
- ///
- /// LabelAccount control.
- ///
- ///
- /// Auto-generated field.
- /// To modify move field declaration from designer file to code-behind file.
- ///
- protected global::System.Web.UI.WebControls.Label LabelAccount;
-
///
/// LabelReference control.
///
diff --git a/Site/Pages/v5/Financial/ListInvoicesInbound.aspx b/Site/Pages/v5/Financial/ListInvoicesInbound.aspx
new file mode 100644
index 00000000..ee49ab2e
--- /dev/null
+++ b/Site/Pages/v5/Financial/ListInvoicesInbound.aspx
@@ -0,0 +1,212 @@
+<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" Inherits="Swarmops.Frontend.Pages.v5.Financial.ListInvoicesInbound" Codebehind="ListInvoicesInbound.aspx.cs" %>
+<%@ Register src="~/Controls/v5/Base/ModalDialog.ascx" tagname="ModalDialog" tagprefix="Swarmops5" %>
+<%@ Register src="~/Controls/v5/Financial/ComboBudgets.ascx" tagname="ComboBudgets" tagprefix="Swarmops5" %>
+<%@ Register src="~/Controls/v5/Financial/CurrencyTextBox.ascx" tagname="CurrencyTextBox" tagprefix="Swarmops5" %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
+
+
+
+
+
+
+
+
+
diff --git a/Site/Pages/v5/Financial/ListInvoicesInbound.aspx.cs b/Site/Pages/v5/Financial/ListInvoicesInbound.aspx.cs
new file mode 100644
index 00000000..f9e02c0f
--- /dev/null
+++ b/Site/Pages/v5/Financial/ListInvoicesInbound.aspx.cs
@@ -0,0 +1,600 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Security;
+using System.Threading;
+using System.Web;
+using System.Web.Services;
+using System.Web.UI;
+using Resources;
+using Swarmops.Common.Enums;
+using Swarmops.Logic.Financial;
+using Swarmops.Logic.Security;
+using Swarmops.Logic.Structure;
+using Swarmops.Logic.Support;
+using Swarmops.Logic.Swarm;
+
+namespace Swarmops.Frontend.Pages.v5.Financial
+{
+ public partial class ListInvoicesInbound : PageV5Base
+ {
+ private Dictionary _attestationRights;
+ private List _documentList;
+
+ protected void Page_Load (object sender, EventArgs e)
+ {
+ if (!CurrentOrganization.IsEconomyEnabled)
+ {
+ Response.Redirect ("/Pages/v5/Financial/EconomyNotEnabled.aspx", true);
+ return;
+ }
+
+ PageIcon = "iconshock-stamped-paper";
+
+ PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Participant, AccessType.Read); // No specific access aspect for owning a budget (yet?)
+
+ if (!Page.IsPostBack)
+ {
+ Localize();
+ }
+
+ // this.TextDenyReason.Style [HtmlTextWriterStyle.FontSize] = "60% !important";
+
+ this._attestationRights = GetAttestationRights();
+ this._documentList = new List();
+ this.LiteralCanOverdraftBudgets.Text =
+ CurrentAuthority.HasAccess (new Access (CurrentOrganization, AccessAspect.Administration)).ToString(CultureInfo.InvariantCulture).ToLowerInvariant();
+
+ PopulateInboundInvoices();
+ PopulateExpenses();
+ // PopulateSalaries();
+
+ RegisterControl(EasyUIControl.DataGrid);
+
+ this.RepeaterLightboxItems.DataSource = this._documentList;
+ this.RepeaterLightboxItems.DataBind();
+ }
+
+
+ static private Dictionary GetAttestationRights()
+ {
+ AuthenticationData authData = GetAuthenticationDataAndCulture();
+
+ // Right now, this function is quite primitive. At some point in the future, it needs to take into
+ // account that a budget may have several attesters. Right now, it just loops over all accounts and
+ // checks the owner.
+
+ Dictionary result = new Dictionary();
+ FinancialAccounts accounts = FinancialAccounts.ForOrganization(authData.CurrentOrganization);
+
+ foreach (FinancialAccount account in accounts)
+ {
+ if (account.OwnerPersonId == authData.CurrentUser.Identity ||
+ (account.OwnerPersonId == 0 && authData.Authority.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.Administration))))
+ {
+ if (account.AccountType == FinancialAccountType.Cost)
+ {
+ result[account.Identity] = true;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ [WebMethod]
+ public static int[] GetUninitializedBudgets()
+ {
+ AuthenticationData authData = GetAuthenticationDataAndCulture();
+
+ // This function finds the exceptional accounts that aren't initialized, to let a sysadmin approve expenses to them.
+
+ List result = new List();
+ FinancialAccounts accounts = FinancialAccounts.ForOrganization(authData.CurrentOrganization);
+
+ foreach (FinancialAccount account in accounts)
+ {
+ if (account.AccountType == FinancialAccountType.Cost)
+ {
+ if (account.OwnerPersonId == 0 &&
+ authData.Authority.HasAccess (new Access (authData.CurrentOrganization,
+ AccessAspect.Administration)))
+ {
+ result.Add (account.Identity);
+ }
+ }
+ }
+
+ return result.ToArray();
+ }
+
+ private void Localize()
+ {
+ PageTitle = Resources.Pages.Financial.AttestCosts_PageTitle;
+ InfoBoxLiteral = Resources.Pages.Financial.AttestCosts_Info;
+ this.LabelAttestCostsHeader.Text = Resources.Pages.Financial.AttestCosts_Header_CostsAwaitingAttestation;
+ //this.LabelGridHeaderAction.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Action;
+ this.LabelGridHeaderBeneficiary.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Beneficiary;
+ this.LabelGridHeaderBudget.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Budget;
+ this.LabelGridHeaderDescription.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Description;
+ this.LabelGridHeaderDocs.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Docs;
+ this.LabelGridHeaderItem.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Item;
+ this.LabelGridHeaderRequested.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Requested;
+
+ /* this.LiteralErrorInsufficientBudget.Text = JavascriptEscape (Resources.Pages.Financial.AttestCosts_OutOfBudget);
+ this.LiteralWarnUnintializedBudget.Text =
+ JavascriptEscape (Resources.Pages.Financial.AttestCosts_Warn_UninitializedBudget);*/
+/*
+ this.LabelDescribeDeny.Text = Resources.Pages.Financial.AttestCosts_Modal_DescribeOptionDeny;
+ this.LabelDescribeCorrect.Text = String.Format (Resources.Pages.Financial.AttestCosts_Modal_DescribeOptionAmount, CurrentOrganization.Currency.DisplayCode);
+ this.LabelDescribeRebudget.Text = Resources.Pages.Financial.AttestCosts_Modal_DescribeOptionRebudget;
+
+ this.LabelRadioCorrect.Text = Resources.Pages.Financial.AttestCosts_Modal_RadioOptionAmount;
+ this.LabelRadioDeny.Text = Resources.Pages.Financial.AttestCosts_Modal_RadioOptionDeny;
+ this.LabelRadioRebudget.Text = Resources.Pages.Financial.AttestCosts_Modal_RadioOptionRebudget;*/
+
+ this.LiteralButtonCorrect.Text = JavascriptEscape(Resources.Pages.Financial.AttestCosts_Modal_ButtonAmount);
+ this.LiteralButtonDeny.Text = JavascriptEscape(Resources.Pages.Financial.AttestCosts_Modal_ButtonDeny);
+ this.LiteralButtonRebudget.Text = JavascriptEscape(Resources.Pages.Financial.AttestCosts_Modal_ButtonRebudget);
+
+ /* this.LabelModalDenyHeader.Text = Resources.Pages.Financial.AttestCosts_Modal_Header;
+ this.LabelWhatProblem.Text = Resources.Pages.Financial.AttestCosts_Modal_WhatIsProblem;
+
+ this.LiteralPleaseSelectBudget.Text = JavascriptEscape (Resources.Pages.Financial.AttestCosts_Error_PleaseSelectBudget);
+ this.LiteralCannotRebudgetSalary.Text =
+ JavascriptEscape (Resources.Pages.Financial.AttestCosts_Error_CantRebudgetSalary);
+
+ this.LiteralConfirmOverdraftNo.Text = JavascriptEscape(Resources.Pages.Financial.AttestCosts_OverdraftConfirmNo);
+ this.LiteralConfirmOverdraftYes.Text = JavascriptEscape(Resources.Pages.Financial.AttestCosts_OverdraftConfirmYes);
+ this.LiteralConfirmOverdraft.Text = JavascriptEscape(Resources.Pages.Financial.AttestCosts_OverdraftConfirm);*/
+ }
+
+ 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");
+ }
+ }
+
+
+ [WebMethod]
+ public static AjaxCallResult DenyItem (string recordId, string reason)
+ {
+ AuthenticationData authData = GetAuthenticationDataAndCulture();
+ IPayable payable = PayableFromRecordId (recordId);
+ FinancialAccount budget = payable.Budget;
+
+ if (budget.OrganizationId != authData.CurrentOrganization.Identity ||
+ (budget.OwnerPersonId != authData.CurrentUser.Identity &&
+ budget.OwnerPersonId != Person.NobodyId))
+ {
+ throw new UnauthorizedAccessException();
+ }
+
+ if (String.IsNullOrEmpty (reason.Trim()))
+ {
+ reason = Resources.Global.Global_NoReasonGiven;
+ }
+
+ payable.DenyAttestation (authData.CurrentUser, reason);
+
+ return new AjaxCallResult { Success = true };
+ }
+
+
+ [WebMethod]
+ public static void RebudgetItem (string recordId, int newAccountId)
+ {
+ AuthenticationData authData = GetAuthenticationDataAndCulture();
+
+ IPayable payable = PayableFromRecordId (recordId);
+ FinancialAccount newAccount = FinancialAccount.FromIdentity(newAccountId);
+
+ if (payable.Budget.OrganizationId != authData.CurrentOrganization.Identity ||
+ payable.Budget.OwnerPersonId != authData.CurrentUser.Identity ||
+ newAccount.OrganizationId != authData.CurrentOrganization.Identity)
+ {
+ throw new UnauthorizedAccessException();
+ }
+
+ payable.SetBudget (newAccount, authData.CurrentUser);
+ }
+
+ [WebMethod]
+ public static AjaxCallResult AttestCorrectedItem(string recordId, string amountString)
+ {
+ AuthenticationData authData = GetAuthenticationDataAndCulture();
+ double amount = 0.0;
+
+ try
+ {
+ amount = Double.Parse (amountString, NumberStyles.Currency, Thread.CurrentThread.CurrentCulture);
+ }
+ catch (Exception)
+ {
+ return new AjaxCallResult
+ {
+ Success = false,
+ DisplayMessage = String.Format(Resources.Global.Error_CurrencyParsing, 1000.00)
+ };
+ }
+
+ Int64 amountCents = (Int64) (amount*100);
+
+ if (amountCents < 0)
+ {
+ return new AjaxCallResult
+ {
+ Success = false,
+ DisplayMessage = Resources.Pages.Financial.AttestCosts_CannotAttestNegative
+ };
+ }
+
+ if (amountCents == 0)
+ {
+ return new AjaxCallResult
+ {
+ Success = false,
+ DisplayMessage = Resources.Pages.Financial.AttestCosts_CannotAttestZero
+ };
+ }
+
+ IPayable payable = PayableFromRecordId (recordId);
+ FinancialAccount budget = payable.Budget;
+
+ if (budget.OrganizationId != authData.CurrentOrganization.Identity ||
+ budget.OwnerPersonId != authData.CurrentUser.Identity)
+ {
+ throw new UnauthorizedAccessException();
+ }
+
+ Int64 centsRemaining = budget.GetBudgetCentsRemaining();
+
+ if (centsRemaining/100.0 < amount)
+ {
+ // TODO: Handle the special case where the IPayable is not on current year, so against another (last) year's budget
+
+ string notEnoughFunds;
+
+ if (centsRemaining > 0)
+ {
+ notEnoughFunds = String.Format (Resources.Pages.Financial.AttestCosts_OutOfBudgetPrecise,
+ authData.CurrentOrganization.Currency.DisplayCode, centsRemaining/100.0, DateTime.UtcNow.Year);
+ }
+ else
+ {
+ notEnoughFunds = String.Format (Resources.Pages.Financial.AttestCosts_BudgetIsEmpty,
+ DateTime.UtcNow.Year);
+ }
+
+ return new AjaxCallResult
+ {
+ Success = false,
+ DisplayMessage = notEnoughFunds
+ };
+ }
+
+ payable.SetAmountCents (amountCents, authData.CurrentUser);
+ payable.Attest (authData.CurrentUser);
+
+ return new AjaxCallResult
+ {
+ Success = true
+ };
+ }
+
+
+
+ [WebMethod]
+ public static BudgetRemainder[] GetRemainingBudgets()
+ {
+ Dictionary accountLookup = GetAttestationRights();
+
+ if (accountLookup.Count == 0)
+ {
+ return new BudgetRemainder[0];
+ }
+
+ Organization organization = FinancialAccount.FromIdentity (accountLookup.Keys.First()).Organization;
+
+ List result = new List();
+ int currentYear = DateTime.UtcNow.Year;
+
+ foreach (int accountId in accountLookup.Keys)
+ {
+ FinancialAccount account = FinancialAccount.FromIdentity (accountId);
+ Int64 remaining = account.GetBudgetCentsRemaining (currentYear);
+
+ result.Add (new BudgetRemainder { AccountId = accountId, Remaining = remaining/100.0 });
+ }
+
+ return result.ToArray();
+ }
+
+
+ public class BudgetRemainder
+ {
+ public int AccountId { get; set; }
+ public double Remaining { get; set; }
+ }
+
+
+
+ [WebMethod]
+ public static AjaxCallResult Attest (string identifier)
+ {
+ identifier = HttpUtility.UrlDecode (identifier);
+
+ return HandleAttestationDeattestation (identifier, AttestationMode.Attestation);
+ }
+
+ [WebMethod]
+ public static AjaxCallResult Deattest (string identifier)
+ {
+ identifier = HttpUtility.UrlDecode (identifier);
+
+ return HandleAttestationDeattestation (identifier, AttestationMode.Deattestation);
+ }
+
+
+ private static AjaxCallResult HandleAttestationDeattestation (string identifier, AttestationMode mode)
+ {
+ AuthenticationData authData = GetAuthenticationDataAndCulture();
+
+ IAttestable attestableItem;
+ 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");
+ }
+
+ 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 SecurityException ("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 SecurityException ("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 SecurityException ("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 + 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");
+ }
+
+ 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)
+ {
+ Int64 budgetRemaining = attestableItem.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 (attestableItem.Budget.Owner != null || attestableItem.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
+ };
+ }
+ }
+
+ 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);
+ }
+
+ FinancialAccount.ClearAttestationAdjustmentsCache (authData.CurrentOrganization);
+
+ return new AjaxCallResult {DisplayMessage = result, Success = true};
+ }
+
+
+ private void PopulateExpenses()
+ {
+ ExpenseClaims expenses = ExpenseClaims.ForOrganization (CurrentOrganization).WhereUnattested;
+
+ foreach (ExpenseClaim expenseClaim in expenses)
+ {
+ if (this._attestationRights.ContainsKey (expenseClaim.BudgetId) ||
+ expenseClaim.Budget.OwnerPersonId == Person.NobodyId)
+ {
+ AddDocuments (expenseClaim.Documents,
+ "E" + expenseClaim.Identity.ToString (CultureInfo.InvariantCulture),
+ String.Format (Global.Financial_ExpenseClaimSpecificationWithClaimer + " - ",
+ expenseClaim.Identity, expenseClaim.ClaimerCanonical) +
+ Global.Financial_ReceiptSpecification);
+ }
+ }
+ }
+
+
+ private void PopulateInboundInvoices()
+ {
+ InboundInvoices invoices = InboundInvoices.ForOrganization (CurrentOrganization).WhereUnattested;
+
+ foreach (InboundInvoice invoice in invoices)
+ {
+ Documents dox = invoice.Documents;
+ bool hasDox = (dox.Count > 0 ? true : false);
+
+ if (this._attestationRights.ContainsKey (invoice.BudgetId) ||
+ invoice.Budget.OwnerPersonId == Person.NobodyId)
+ {
+ AddDocuments (invoice.Documents, "I" + invoice.Identity.ToString (CultureInfo.InvariantCulture),
+ String.Format (Global.Financial_InboundInvoiceSpecificationWithSender + " - ",
+ invoice.Identity, invoice.Supplier) + Global.Global_ImageSpecification);
+ }
+ }
+ }
+
+
+ private void AddDocuments (Documents docs, string baseId, string titleBase)
+ {
+ int countTotal = docs.Count;
+ int count = 0;
+
+ foreach (Document document in docs)
+ {
+ RepeatedDocument newDoc = new RepeatedDocument
+ {
+ DocId = document.Identity,
+ BaseId = baseId,
+ Title = String.Format (titleBase, ++count, countTotal)
+ };
+
+ this._documentList.Add (newDoc);
+ }
+ }
+
+ private enum AttestationMode
+ {
+ Unknown = 0,
+ Attestation,
+ Deattestation
+ };
+
+ public class RepeatedDocument
+ {
+ public int DocId { get; set; }
+ public string BaseId { get; set; }
+ public string Title { get; set; }
+ }
+
+
+ }
+}
\ No newline at end of file
diff --git a/Site/Pages/v5/Financial/ListInvoicesInbound.aspx.designer.cs b/Site/Pages/v5/Financial/ListInvoicesInbound.aspx.designer.cs
new file mode 100644
index 00000000..4dd838b1
--- /dev/null
+++ b/Site/Pages/v5/Financial/ListInvoicesInbound.aspx.designer.cs
@@ -0,0 +1,150 @@
+//------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace Swarmops.Frontend.Pages.v5.Financial {
+
+
+ public partial class ListInvoicesInbound {
+
+ ///
+ /// LiteralCanOverdraftBudgets control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Literal LiteralCanOverdraftBudgets;
+
+ ///
+ /// LiteralButtonRebudget control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Literal LiteralButtonRebudget;
+
+ ///
+ /// LiteralButtonDeny control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Literal LiteralButtonDeny;
+
+ ///
+ /// LiteralButtonCorrect control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Literal LiteralButtonCorrect;
+
+ ///
+ /// LabelAttestCostsHeader control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label LabelAttestCostsHeader;
+
+ ///
+ /// LabelGridHeaderItem control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label LabelGridHeaderItem;
+
+ ///
+ /// LabelDueDate control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label LabelDueDate;
+
+ ///
+ /// LabelGridHeaderBeneficiary control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label LabelGridHeaderBeneficiary;
+
+ ///
+ /// LabelGridHeaderDescription control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label LabelGridHeaderDescription;
+
+ ///
+ /// LabelGridHeaderBudget control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label LabelGridHeaderBudget;
+
+ ///
+ /// LabelGridHeaderRequested control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label LabelGridHeaderRequested;
+
+ ///
+ /// LabelGridHeaderDocs control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label LabelGridHeaderDocs;
+
+ ///
+ /// LabelGridHeaderProgress control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label LabelGridHeaderProgress;
+
+ ///
+ /// Label1 control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Label Label1;
+
+ ///
+ /// RepeaterLightboxItems control.
+ ///
+ ///
+ /// Auto-generated field.
+ /// To modify move field declaration from designer file to code-behind file.
+ ///
+ protected global::System.Web.UI.WebControls.Repeater RepeaterLightboxItems;
+ }
+}
diff --git a/Site/Site.csproj b/Site/Site.csproj
index c4493e6c..81b21afe 100644
--- a/Site/Site.csproj
+++ b/Site/Site.csproj
@@ -194,6 +194,13 @@
SendMassMessage.aspx
+
+ ListInvoicesInbound.aspx
+ ASPXCodeBehind
+
+
+ ListInvoicesInbound.aspx
+
AttestCosts.aspx
ASPXCodeBehind
@@ -819,6 +826,7 @@
+
@@ -1028,6 +1036,7 @@
+