Invoice inbound list work
This commit is contained in:
@@ -268,6 +268,7 @@ namespace Swarmops.Logic.Financial
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void UpdateTransaction (Person updatingPerson)
|
||||
{
|
||||
Dictionary<int, Int64> nominalTransaction = new Dictionary<int, Int64>();
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Globalization;
|
||||
using Swarmops.Basic.Types;
|
||||
using Swarmops.Basic.Types.Financial;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Common.Interfaces;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Communications;
|
||||
using Swarmops.Logic.Communications.Payload;
|
||||
@@ -43,6 +44,18 @@ namespace Swarmops.Logic.Financial
|
||||
// return payout;
|
||||
}
|
||||
|
||||
public static Payout FromDependency(IHasIdentity dependency)
|
||||
{
|
||||
int payoutId = SwarmDb.GetDatabaseForReading().GetPayoutIdFromDependency(dependency);
|
||||
if (payoutId == 0)
|
||||
{
|
||||
throw new ArgumentException("Supplied item does not have an associated payout");
|
||||
}
|
||||
|
||||
return Payout.FromIdentity(payoutId);
|
||||
}
|
||||
|
||||
|
||||
public static Payout Empty
|
||||
{
|
||||
get { return new Payout (new BasicPayout (0, 0, string.Empty, string.Empty, string.Empty, 0, DateTime.UtcNow, true, DateTime.UtcNow, 0)); }
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 170 B |
@@ -0,0 +1 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" Inherits="Pages_v5_Finance_Json_InvoicesInbound" Codebehind="Json-ListInvoicesInbound.aspx.cs" %>
|
||||
@@ -0,0 +1,167 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Common.Interfaces;
|
||||
using Swarmops.Frontend;
|
||||
using Swarmops.Logic.Financial;
|
||||
using Swarmops.Logic.Support;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
public partial class Pages_v5_Finance_Json_ListInvoicesInbound : DataV5Base
|
||||
{
|
||||
private Dictionary<int, Int64> _attestationRights;
|
||||
private InboundInvoices _invoices;
|
||||
|
||||
protected void Page_Load (object sender, EventArgs e)
|
||||
{
|
||||
// Get invoices and attestation rights
|
||||
|
||||
this._attestationRights = GetAttestationRights();
|
||||
this._invoices = InboundInvoices.ForOrganization(this.CurrentOrganization);
|
||||
|
||||
// Format as JSON and return
|
||||
|
||||
Response.ContentType = "application/json";
|
||||
string json = FormatAsJson();
|
||||
Response.Output.WriteLine (json);
|
||||
Response.End();
|
||||
}
|
||||
|
||||
private string FormatAsJson()
|
||||
{
|
||||
// Fields: item, dueDate, sender, budget, amount, progress, docs, action
|
||||
|
||||
StringBuilder result = new StringBuilder (16384);
|
||||
|
||||
string hasDoxString =
|
||||
"<img src=\\\"/Images/Icons/iconshock-glass-16px.png\\\" onmouseover=\\\"this.src='/Images/Icons/iconshock-glass-16px-hot.png';\\\" onmouseout=\\\"this.src='/Images/Icons/iconshock-glass-16px.png';\\\" baseid=\\\"{5}\\\" class=\\\"LocalViewDox\\\" style=\\\"cursor:pointer\\\" />";
|
||||
|
||||
result.Append ("{\"rows\":[");
|
||||
|
||||
foreach (InboundInvoice invoice in _invoices)
|
||||
{
|
||||
result.Append("{");
|
||||
result.AppendFormat(
|
||||
"\"item\":\"{0}\",\"dueDate\":\"{1}\",\"sender\":\"{2}\",\"budget\":\"{3}\",\"amount\":\"{4}\",\"progress\":\"{5}\"," +
|
||||
"\"dox\":\"" + (invoice.Documents.Count > 0 ? hasDoxString : " ") + "\"," +
|
||||
"\"actions\":\"<span style='position:relative;left:-2px'>" +
|
||||
//"<img id=\\\"IconApproval{5}\\\" class=\\\"LocalIconApproval LocalNew LocalFundsInsufficient\\\" accountid=\\\"{6}\\\" amount=\\\"{4}\\\" baseid=\\\"{5}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
|
||||
//"<img id=\\\"IconApproved{5}\\\" class=\\\"LocalIconApproved LocalNew\\\" baseid=\\\"{5}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
|
||||
//"<img id=\\\"IconDenial{5}\\\" class=\\\"LocalIconDenial LocalNew\\\" baseid=\\\"{5}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
|
||||
//"<img id=\\\"IconDenied{5}\\\" class=\\\"LocalIconDenied LocalNew\\\" baseid=\\\"{5}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
|
||||
//"<img id=\\\"IconUndo{5}\\\" class=\\\"LocalIconUndo LocalNew\\\" baseid=\\\"{5}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
|
||||
"</span>\"",
|
||||
"#" + invoice.Identity.ToString("N0"),
|
||||
JsonSanitize(invoice.DueDate.ToString("MMM-dd")),
|
||||
JsonSanitize(invoice.Supplier),
|
||||
JsonSanitize(invoice.Budget.Name),
|
||||
JsonSanitize((invoice.AmountCents/100.0).ToString("N2")),
|
||||
GetProgressTicks(invoice));
|
||||
result.Append("},");
|
||||
}
|
||||
|
||||
if (_invoices.Count > 1)
|
||||
{
|
||||
result.Remove(result.Length - 1, 1); // remove last comma
|
||||
}
|
||||
|
||||
result.Append ("]}");
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
private string _emptyTick = "<img src='/Images/Icons/iconshock-empty-tick-128x96px.png' height='16' width='24'>";
|
||||
private string _greenTick = "<img src='/Images/Icons/iconshock-green-tick-128x96px.png' height='16' width='24'>";
|
||||
private string _redCross = "<img src='/Images/Icons/iconshock-red-cross-128x96px.png' height='16' width='24'>";
|
||||
private string _filler = "<img src='/Images/Icons/transparency-16px.png' height='16' width='24'>";
|
||||
|
||||
|
||||
private string GetProgressTicks(InboundInvoice invoice)
|
||||
{
|
||||
StringBuilder ticks = new StringBuilder(512);
|
||||
|
||||
// The first tick is whether the invoice was even received yet, in anticipation of Purchase Orders
|
||||
// For now, it is always filled
|
||||
|
||||
ticks.Append(_greenTick);
|
||||
|
||||
// The second tick is whether the invoice has been attested
|
||||
|
||||
if (invoice.Attested)
|
||||
{
|
||||
ticks.Append(_greenTick);
|
||||
|
||||
// Is it also paid?
|
||||
|
||||
if (invoice.PaidOut)
|
||||
{
|
||||
ticks.Append(_greenTick);
|
||||
|
||||
// Is the payout closed, that is, registered closed with the bank?
|
||||
|
||||
if (Payout.FromDependency(invoice).Open)
|
||||
{
|
||||
ticks.Append(_emptyTick);
|
||||
}
|
||||
else
|
||||
{
|
||||
ticks.Append(_greenTick);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// attested but not paid yet
|
||||
|
||||
ticks.Append(_emptyTick + _emptyTick);
|
||||
}
|
||||
}
|
||||
else // not attested
|
||||
{
|
||||
// Is the invoice closed? If so, it was denied entirely
|
||||
|
||||
if (invoice.Open)
|
||||
{
|
||||
ticks.Append(_emptyTick + _emptyTick + _emptyTick);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Closed, and therefore it was denied attestation
|
||||
ticks.Append(_redCross + _filler + _filler);
|
||||
}
|
||||
}
|
||||
|
||||
return ticks.ToString();
|
||||
}
|
||||
|
||||
|
||||
private Dictionary<int, Int64> GetAttestationRights()
|
||||
{
|
||||
// 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, Int64> result = new Dictionary<int, Int64>();
|
||||
FinancialAccounts accounts = FinancialAccounts.ForOrganization (CurrentOrganization);
|
||||
|
||||
foreach (FinancialAccount account in accounts)
|
||||
{
|
||||
if (account.OwnerPersonId == CurrentUser.Identity)
|
||||
{
|
||||
if (account.AccountType == FinancialAccountType.Cost)
|
||||
{
|
||||
result[account.Identity] = account.GetBudgetCentsRemaining();
|
||||
}
|
||||
else
|
||||
{
|
||||
result[account.Identity] = 1; // any value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <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>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
public partial class Pages_v5_Finance_Json_InvoicesInbound {
|
||||
}
|
||||
@@ -187,7 +187,7 @@
|
||||
<th data-options="field:'dueDate',width:80"><asp:Label ID="LabelGridHeaderDueDate" runat="server" Text="XYZ DueDate" /></th>
|
||||
<th data-options="field:'sender',width:160,sortable:true"><asp:Label ID="LabelGridHeaderBeneficiary" runat="server" Text="XYZ Beneficiary" /></th>
|
||||
<th data-options="field:'budget',width:80,sortable:true"><asp:Label ID="LabelGridHeaderBudget" runat="server" Text="XYZ Budget" /></th>
|
||||
<th data-options="field:'amountRequested',width:100,align:'right',sortable:true,order:'asc'"><asp:Label ID="LabelGridHeaderRequested" runat="server" Text="XYZ Requested" /></th>
|
||||
<th data-options="field:'amount',width:100,align:'right',sortable:true,order:'asc'"><asp:Label ID="LabelGridHeaderRequested" runat="server" Text="XYZ Requested" /></th>
|
||||
<th data-options="field:'progress',width:96,align:'center'"><asp:Label ID="LabelGridHeaderProgress" runat="server" Text="XYZ Progress" /></th>
|
||||
<th data-options="field:'dox',width:40,align:'center'"><asp:Label ID="LabelGridHeaderDocs" runat="server" Text="Doxyz" /></th>
|
||||
<th data-options="field:'actions',width:53,align:'center'"><asp:Label ID="LabelGridHeaderActions" runat="server" Text="XYZAction" /></th>
|
||||
|
||||
@@ -194,6 +194,13 @@
|
||||
<Compile Include="Pages\v5\Comms\SendMassMessage.aspx.designer.cs">
|
||||
<DependentUpon>SendMassMessage.aspx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Pages\v5\Financial\Json-ListInvoicesInbound.aspx.cs">
|
||||
<DependentUpon>Json-ListInvoicesInbound.aspx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Pages\v5\Financial\Json-ListInvoicesInbound.aspx.designer.cs">
|
||||
<DependentUpon>Json-ListInvoicesInbound.aspx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Pages\v5\Financial\ListInvoicesInbound.aspx.cs">
|
||||
<DependentUpon>ListInvoicesInbound.aspx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
@@ -895,6 +902,7 @@
|
||||
<Content Include="Images\Icons\iconshock-wrench-128x96px-centered.png" />
|
||||
<Content Include="Images\Icons\iconshock-wrench-16px-hot.png" />
|
||||
<Content Include="Images\Icons\iconshock-wrench-16px.png" />
|
||||
<Content Include="Images\Icons\transparency-16px.png" />
|
||||
<Content Include="Images\Icons\undo-16px.png" />
|
||||
<Content Include="Images\Ledgers\uploadbankfiles-bankgirose-full.png" />
|
||||
<Content Include="Images\Ledgers\uploadbankfiles-bankgirose-small.png" />
|
||||
@@ -1041,6 +1049,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\Json-ListInvoicesInbound.aspx" />
|
||||
<Content Include="Pages\v5\Financial\ListInvoicesInbound.aspx" />
|
||||
<Content Include="Pages\v5\Financial\AttestCosts.aspx" />
|
||||
<Content Include="Pages\v5\Financial\BitcoinHotwalletNotEnabled.aspx" />
|
||||
|
||||
Reference in New Issue
Block a user