Work on outbound invoices; inbound invoice list

This commit is contained in:
Rick Falkvinge
2017-09-15 18:49:40 +02:00
parent f37c8c95c7
commit 680b749bfb
16 changed files with 1035 additions and 65 deletions
+9
View File
@@ -312,6 +312,15 @@ namespace Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Client / Customer.
/// </summary>
internal static string Financial_Client {
get {
return ResourceManager.GetString("Financial_Client", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Expenses.
/// </summary>
+3
View File
@@ -909,4 +909,7 @@
<value>Annual Profit/Loss To Date ({0})</value>
<comment>{0} is the currency code</comment>
</data>
<data name="Financial_Client" xml:space="preserve">
<value>Client / Customer</value>
</data>
</root>
+1 -1
View File
@@ -349,7 +349,7 @@ namespace Resources {
}
/// <summary>
/// Looks up a localized string similar to List.
/// Looks up a localized string similar to List....
/// </summary>
internal static string Menu5_Financial_List {
get {
+1 -1
View File
@@ -193,7 +193,7 @@
<value>Gigs Assistant</value>
</data>
<data name="Menu5_Financial_List" xml:space="preserve">
<value>List</value>
<value>List...</value>
</data>
<data name="Menu5_Financial_List_CashRequests" xml:space="preserve">
<value>Cash Requests</value>
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

+28 -1
View File
@@ -245,8 +245,35 @@
<Type>Separator</Type>
<Children />
</MainMenuItem>
<MainMenuItem>
<ResourceKey>Financial_List</ResourceKey>
<UserLevel>3</UserLevel>
<Permissions />
<Type>Disabled</Type>
<Children />
<MainMenuItem>
<ResourceKey>Financial_List_InboundInvoices</ResourceKey>
<UserLevel>3</UserLevel>
<Permissions />
<ImageUrl />
<NavigateUrl>/Pages/v5/Financial/ListInvoicesInbound.aspx</NavigateUrl>
<Type>Link</Type>
<Children />
</MainMenuItem>
<MainMenuItem>
<ResourceKey>Financial_List_OutboundInvoices</ResourceKey>
<UserLevel>3</UserLevel>
<Permissions />
<ImageUrl />
<NavigateUrl>/Pages/v5/Financial/ListInvoicesInbound.aspx</NavigateUrl>
<Type>Link</Type>
<Children />
</MainMenuItem>
</MainMenuItem>
<MainMenuItem>
<ResourceKey>Financial_Payroll</ResourceKey>
<UserLevel>3</UserLevel>
<Permissions />
@@ -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
@@ -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 @@
<h2><asp:Label ID="BoxTitle" runat="server"/></h2>
<asp:HiddenField ID="HiddenTagSetIdentifiers" runat="server"/>
<div class="entryFields">
<div class="stacked-input-control"><asp:TextBox runat="server" ID="TextSupplier" /></div>
<div class="stacked-input-control"><asp:TextBox runat="server" ID="TextClient" /></div>
<Swarmops5:CurrencyAmount runat="server" ID="CurrencyAmount" />
<span class="vatEnabled"><Swarmops5:CurrencyAmount runat="server" ID="CurrencyVat" /></span>
<div class="stacked-input-control"><asp:TextBox runat="server" ID="TextPurpose" /></div>
<div class="stacked-input-control"><asp:TextBox runat="server" ID="TextDueDate" /></div>
<Swarmops5:ComboBudgets ID="ComboBudgets" runat="server" />
<Swarmops5:ComboBudgets ID="ComboBudgets" ListType="InvoiceableOut" runat="server" />
<asp:Repeater ID="RepeaterTagDrop" runat="server"><ItemTemplate><span id="SpanDropTags<%# Eval("TagSetId") %>"><select class="easyui-combotree" url="/Automation/Json-TransactionTagsTree.aspx?TagSetId=<%# Eval("TagSetId") %>" name="DropTags<%# Eval("TagSetId") %>" id="DropTags<%# Eval("TagSetId") %>" animate="true" style="width:300px"></select></span>&nbsp;<br/></ItemTemplate></asp:Repeater>
<div class="stacked-input-control"></div> <!-- placeholder for label-side H2 -->
@@ -162,12 +160,11 @@
<!-- file upload ends -->
<div class="stacked-input-control"></div> <!-- placeholder for label-side H2 -->
<div class="stacked-input-control"><asp:TextBox runat="server" ID="TextAccount" /></div>
<div class="stacked-input-control"><asp:TextBox runat="server" ID="TextReference" /></div>
<asp:Button ID="ButtonCreate" runat="server" CssClass="buttonAccentColor NoInputFocus" OnClientClick="return validateFields();" OnClick="ButtonCreate_Click" Text="Create"/>
</div>
<div class="entryLabels">
<asp:Label runat="server" ID="LabelSupplier" /><br/>
<asp:Label runat="server" ID="LabelClient" /><br/>
<asp:Label runat="server" ID="LabelAmount" /><br/>
<span class="vatEnabled"><asp:Label runat="server" ID="LabelVat" /><br/></span>
<asp:Label runat="server" ID="LabelPurpose" /><br/>
@@ -177,7 +174,6 @@
<h2><asp:Label runat="server" ID="LabelHeaderImageFiles" /></h2>
<asp:Label runat="server" ID="LabelImageFiles" /><br/>
<h2><asp:Label runat="server" ID="LabelHeaderBankDetails" /></h2>
<asp:Label runat="server" ID="LabelAccount" /><br/>
<asp:Label runat="server" ID="LabelReference" /><br/>
</div>
<div style="clear:both"></div>
@@ -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();
}
@@ -49,13 +49,13 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
protected global::System.Web.UI.WebControls.HiddenField HiddenTagSetIdentifiers;
/// <summary>
/// TextSupplier control.
/// TextClient control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox TextSupplier;
protected global::System.Web.UI.WebControls.TextBox TextClient;
/// <summary>
/// CurrencyAmount control.
@@ -120,15 +120,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
/// </remarks>
protected global::Swarmops.Controls.Base.FileUpload FileUpload;
/// <summary>
/// TextAccount control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox TextAccount;
/// <summary>
/// TextReference control.
/// </summary>
@@ -148,13 +139,13 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
protected global::System.Web.UI.WebControls.Button ButtonCreate;
/// <summary>
/// LabelSupplier control.
/// LabelClient control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelSupplier;
protected global::System.Web.UI.WebControls.Label LabelClient;
/// <summary>
/// LabelAmount control.
@@ -237,15 +228,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelHeaderBankDetails;
/// <summary>
/// LabelAccount control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelAccount;
/// <summary>
/// LabelReference control.
/// </summary>
@@ -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" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
<script type="text/javascript" src="/Scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="/Scripts/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="/Scripts/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
<script type="text/javascript">
function preload(arrayOfImages) {
$(arrayOfImages).each(function () {
(new Image()).src = this;
});
}
preload([
'/Images/Abstract/ajaxloader-medium.gif',
'/Images/Abstract/ajaxloader-48x36px.gif',
'/Images/Icons/iconshock-balloon-yes-128x96px-hot.png',
'/Images/Icons/iconshock-balloon-yes-128x96px-disabled.png',
'/Images/Icons/iconshock-balloon-yes-128x96px-hot-disabled.png',
'/Images/Icons/iconshock-balloon-yes-128x96px-gold.png',
'/Images/Icons/iconshock-balloon-yes-128x96px-hot-gold.png',
'/Images/Icons/iconshock-balloon-no-128x96px-hot.png',
'/Images/Icons/iconshock-green-tick-128x96px.png',
'/Images/Icons/iconshock-red-cross-128x96px.png',
'/Images/Icons/iconshock-red-cross-circled-128x96px.png',
'/Images/Icons/iconshock-balloon-undo-128x96px.png',
'/Images/Icons/iconshock-balloon-undo-128x96px-hot.png'
]);
loadUninitializedBudgets(); // no need to wait for doc.ready to load operating params
SwarmopsJS.ajaxCall("/Pages/v5/Financial/AttestCosts.aspx/GetRemainingBudgets", {}, function(data) {
data.forEach(function(accountData, dummy1, dummy2) {
budgetRemainingLookup[accountData.AccountId] = accountData.Remaining;
});
if (budgetRemainingLookup.rowsLoaded == true) {
setAttestability();
}
budgetRemainingLookup.budgetsLoaded = true;
});
// Doc.ready:
$(document).ready(function () {
$('#TableAttestableCosts').datagrid(
{
rowStyler: function (index, rowData) {
if (rowData.previous != null) {
return { class: "rowPrevious row" + rowData.itemId };
}
if (rowData.itemId != null) {
return { class: "row" + rowData.itemId.replace(/\|/g, '') };
}
return '';
},
onLoadSuccess: function () {
budgetRemainingLookup.attestabilityInitialized = false;
$(".LocalViewDox").click(function () {
$("a.FancyBox_Gallery[rel='" + $(this).attr("baseid") + "']").first().click();
});
$("a.FancyBox_Gallery").fancybox({
'overlayShow': true,
'transitionIn': 'fade',
'transitionOut': 'fade',
'type': 'image',
'opacity': true
});
// Check if budgets have been fetched, and if so, initialize attestability
if (budgetRemainingLookup.budgetsLoaded == true) {
setAttestability();
}
budgetRemainingLookup.rowsLoaded = true;
}
}
);
// we're still in document.ready
$('input:radio[name="ModalOptions"]').change(function () {
var pickedButtonName = $(this).val();
$('div.radioOption').slideUp();
$('div#radioOption' + pickedButtonName).slideDown();
});
});
function setAttestability() {
$('.LocalIconApproval').each(function() {
var accountId = $(this).attr('accountid');
var amountRequested = $(this).attr('amount');
var fundsInBudget = -budgetRemainingLookup[accountId];
// console.log("attestability checking accountid " + accountId + ", amount requested is " + amountRequested + ", funds in budget is " + fundsInBudget);
if (fundsInBudget >= amountRequested || budgetUninitializedLookup[accountId] == true) {
// console.log("- removing insufficience marker");
$(this).removeClass("LocalFundsInsufficient");
if ($(this).attr("rel") != "loading") {
$(this).attr("src", "/Images/Icons/iconshock-balloon-yes-128x96px.png");
}
}
else {
if ($(this).attr("rel") != "loading") {
$(this).attr("src", approvalOverdraftIcon);
}
if (!$(this).hasClass("LocalFundsInsufficient")) {
// console.log("- adding insufficience marker");
$(this).addClass("LocalFundsInsufficient");
if ($(this).attr("rel") != "loading") {
$(this).attr("src", approvalOverdraftIcon);
}
}
}
});
budgetRemainingLookup.attestabilityInitialized = true;
}
var recordId = '';
var accountId = 0;
var budgetRemainingLookup = {};
var budgetUninitializedLookup = {};
var uninitializedPopupDisplayed = false;
// The variable below is advisory for the UI - actual access control is done server-side
var canOverdraftBudgets = <asp:Literal ID="LiteralCanOverdraftBudgets" runat="server" />;
var approvalOverdraftIcon = '/Images/Icons/iconshock-balloon-yes-128x96px-disabled.png';
var approvalOverdraftIconHover = approvalOverdraftIconHover;
var buttonRebudgetValue = SwarmopsJS.unescape('<asp:Literal ID="LiteralButtonRebudget" runat="server" Text="RebudgetXYZ" />');
var buttonDenyValue = SwarmopsJS.unescape('<asp:Literal ID="LiteralButtonDeny" runat="server" Text="RebudgetXYZ" />');
var buttonCorrectValue = SwarmopsJS.unescape('<asp:Literal ID="LiteralButtonCorrect" runat="server" Text="AmountXYZ" />');
</script>
<style type="text/css">
.datagrid-row-selected,.datagrid-row-over{
background:transparent;
}
.rowPrevious {
color: #AAA;
}
div.radioOption {
margin-top: -20px;
padding-bottom: 10px;
padding-left: 12px;
margin-right: 10px;
}
body.ltr div.radioOption {
padding-left: initial;
margin-right: initial;
padding-right: 12px;
margin-left: 10px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
<h2><asp:Label runat="server" ID="LabelAttestCostsHeader" Text="XYZ Costs Awaiting Your Attestation" /></h2>
<table id="TableInboundInvoices" class="easyui-datagrid" style="width:680px;height:400px"
data-options="rownumbers:false,singleSelect:false,fit:false,loading:false,selectOnCheck:true,checkOnSelect:true,url:'Json-ListInvoicesInbound.aspx'"
idField="itemId">
<thead>
<tr>
<th data-options="field:'item',width:60"><asp:Label ID="LabelGridHeaderItem" runat="server" Text="XYZ Item"/></th>
<th data-options="field:'dueDate',width:160"><asp:Label ID="LabelDueDate" runat="server" Text="XYZ DueDate" /></th>
<th data-options="field:'sender',width:120,sortable:true"><asp:Label ID="LabelGridHeaderBeneficiary" runat="server" Text="XYZ Beneficiary" /></th>
<th data-options="field:'descript',width:160"><asp:Label ID="LabelGridHeaderDescription" runat="server" Text="XYZ Description" /></th>
<th data-options="field:'budgetName',width:160,sortable:true"><asp:Label ID="LabelGridHeaderBudget" runat="server" Text="XYZ Budget" /></th>
<th data-options="field:'amountRequested',width:80,align:'right',sortable:true,order:'asc'"><asp:Label ID="LabelGridHeaderRequested" runat="server" Text="XYZ Requested" /></th>
<th data-options="field:'dox',width:40,align:'center'"><asp:Label ID="LabelGridHeaderDocs" runat="server" Text="Doxyz" /></th>
<th data-options="field:'progress',width:96,align:'center'"><asp:Label ID="LabelGridHeaderProgress" runat="server" Text="XYZ Progress" /></th>
<th data-options="field:'actions',width:53,align:'center'"><asp:Label ID="Label1" runat="server" Text="Axyztion" /></th>
</tr>
</thead>
</table>
<div style="display:none">
<!-- a href links for FancyBox to trigger on -->
<asp:Repeater runat="server" ID="RepeaterLightboxItems">
<ItemTemplate>
<a href="/Pages/v5/Support/StreamUpload.aspx?DocId=<%# Eval("DocId") %>" title="<%# Eval("Title") %>" class="FancyBox_Gallery" rel="<%# Eval("BaseId") %>">&nbsp;</a>
</ItemTemplate>
</asp:Repeater>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
</asp:Content>
@@ -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<int, bool> _attestationRights;
private List<RepeatedDocument> _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<RepeatedDocument>();
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<int, bool> 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<int, bool> result = new Dictionary<int, bool>();
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<int> result = new List<int>();
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<int, bool> accountLookup = GetAttestationRights();
if (accountLookup.Count == 0)
{
return new BudgetRemainder[0];
}
Organization organization = FinancialAccount.FromIdentity (accountLookup.Keys.First()).Organization;
List<BudgetRemainder> result = new List<BudgetRemainder>();
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; }
}
}
}
@@ -0,0 +1,150 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Swarmops.Frontend.Pages.v5.Financial {
public partial class ListInvoicesInbound {
/// <summary>
/// LiteralCanOverdraftBudgets control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal LiteralCanOverdraftBudgets;
/// <summary>
/// LiteralButtonRebudget control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal LiteralButtonRebudget;
/// <summary>
/// LiteralButtonDeny control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal LiteralButtonDeny;
/// <summary>
/// LiteralButtonCorrect control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal LiteralButtonCorrect;
/// <summary>
/// LabelAttestCostsHeader control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelAttestCostsHeader;
/// <summary>
/// LabelGridHeaderItem control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelGridHeaderItem;
/// <summary>
/// LabelDueDate control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelDueDate;
/// <summary>
/// LabelGridHeaderBeneficiary control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelGridHeaderBeneficiary;
/// <summary>
/// LabelGridHeaderDescription control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelGridHeaderDescription;
/// <summary>
/// LabelGridHeaderBudget control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelGridHeaderBudget;
/// <summary>
/// LabelGridHeaderRequested control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelGridHeaderRequested;
/// <summary>
/// LabelGridHeaderDocs control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelGridHeaderDocs;
/// <summary>
/// LabelGridHeaderProgress control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelGridHeaderProgress;
/// <summary>
/// Label1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label Label1;
/// <summary>
/// RepeaterLightboxItems control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Repeater RepeaterLightboxItems;
}
}
+9
View File
@@ -194,6 +194,13 @@
<Compile Include="Pages\v5\Comms\SendMassMessage.aspx.designer.cs">
<DependentUpon>SendMassMessage.aspx</DependentUpon>
</Compile>
<Compile Include="Pages\v5\Financial\ListInvoicesInbound.aspx.cs">
<DependentUpon>ListInvoicesInbound.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Pages\v5\Financial\ListInvoicesInbound.aspx.designer.cs">
<DependentUpon>ListInvoicesInbound.aspx</DependentUpon>
</Compile>
<Compile Include="Pages\v5\Financial\AttestCosts.aspx.cs">
<DependentUpon>AttestCosts.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
@@ -819,6 +826,7 @@
<Content Include="Images\Icons\iconshock-diskette-upload-32px.png" />
<Content Include="Images\Icons\iconshock-downarrow-16px.png" />
<Content Include="Images\Icons\iconshock-downarrow-40px.png" />
<Content Include="Images\Icons\iconshock-empty-tick-128x96px.png" />
<Content Include="Images\Icons\iconshock-executive-128px.png" />
<Content Include="Images\Icons\iconshock-flag-white-16px.png" />
<Content Include="Images\Icons\iconshock-flag-white-256px.png" />
@@ -1028,6 +1036,7 @@
<Content Include="Pages\v5\Admin\OrgStaffing.aspx" />
<Content Include="Pages\v5\Admin\SystemSettings.aspx" />
<Content Include="Pages\v5\Comms\SendMassMessage.aspx" />
<Content Include="Pages\v5\Financial\ListInvoicesInbound.aspx" />
<Content Include="Pages\v5\Financial\AttestCosts.aspx" />
<Content Include="Pages\v5\Financial\BitcoinHotwalletNotEnabled.aspx" />
<Content Include="Pages\v5\Financial\CreateOutboundInvoice.aspx" />