Receipt validation appears to be functional
This commit is contained in:
@@ -87,6 +87,29 @@ namespace Swarmops.Database
|
||||
}
|
||||
|
||||
|
||||
public BasicFinancialTransactionTagType[] GetFinancialTransactionTagTypesByIdentity (int[] identities)
|
||||
{
|
||||
List<BasicFinancialTransactionTagType> result = new List<BasicFinancialTransactionTagType>();
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SELECT" + financialTransactionTagTypeFieldSequence + " WHERE FinancialTransactionTagTypeId IN (" + JoinIds(identities) + ")", connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(ReadFinancialTransactionTagTypeFromDataReader(reader));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Swarmops.Database
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand("SELECT FinancialTransactionTagTypeId WHERE FinancialTransactionId=" + financialTransactionId.ToString(CultureInfo.InvariantCulture), connection);
|
||||
GetDbCommand("SELECT FinancialTransactionTagTypeId FROM FinancialTransactionTags WHERE FinancialTransactionId=" + financialTransactionId.ToString(CultureInfo.InvariantCulture), connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
|
||||
@@ -149,5 +149,23 @@ namespace Swarmops.Logic.App_GlobalResources {
|
||||
return ResourceManager.GetString("Payout_Urgent_One", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Validate claims {0}.
|
||||
/// </summary>
|
||||
internal static string Validate_Receipts_Many {
|
||||
get {
|
||||
return ResourceManager.GetString("Validate_Receipts_Many", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Validate claim #{0}.
|
||||
/// </summary>
|
||||
internal static string Validate_Receipts_One {
|
||||
get {
|
||||
return ResourceManager.GetString("Validate_Receipts_One", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,4 +148,10 @@
|
||||
<data name="Payout_Urgent_One" xml:space="preserve">
|
||||
<value>Settle one urgent payout</value>
|
||||
</data>
|
||||
<data name="Validate_Receipts_Many" xml:space="preserve">
|
||||
<value>Validate claims {0}</value>
|
||||
</data>
|
||||
<data name="Validate_Receipts_One" xml:space="preserve">
|
||||
<value>Validate claim #{0}</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -405,6 +405,8 @@ namespace Swarmops.Logic.Financial
|
||||
FinancialDependencyType.ExpenseClaim, this.Identity,
|
||||
DateTime.Now, validator.Identity, (double) this.Amount);
|
||||
base.Validated = true;
|
||||
|
||||
OutboundComm.CreateNotificationOfFinancialValidation(this.Budget, this.Claimer, (double)this.AmountCents / 100.0, this.Description, NotificationResource.ExpenseClaim_Validated);
|
||||
}
|
||||
|
||||
public void Devalidate (Person devalidator)
|
||||
@@ -414,6 +416,8 @@ namespace Swarmops.Logic.Financial
|
||||
FinancialDependencyType.ExpenseClaim, this.Identity,
|
||||
DateTime.Now, devalidator.Identity, (double) this.Amount);
|
||||
base.Validated = false;
|
||||
|
||||
OutboundComm.CreateNotificationOfFinancialValidation(this.Budget, this.Claimer, (double)this.AmountCents / 100.0, this.Description, NotificationResource.ExpenseClaim_Devalidated);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -58,7 +58,20 @@ namespace Swarmops.Logic.Financial
|
||||
|
||||
|
||||
|
||||
public static ExpenseClaims FromClaimingPersonAndOrganization (Person person, Organization organization)
|
||||
public ExpenseClaims WhereUnvalidated
|
||||
{
|
||||
get
|
||||
{
|
||||
ExpenseClaims result = new ExpenseClaims();
|
||||
result.AddRange(this.Where(expenseClaim => !expenseClaim.Validated));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static ExpenseClaims FromClaimingPersonAndOrganization(Person person, Organization organization)
|
||||
{
|
||||
return
|
||||
FromArray(SwarmDb.GetDatabaseForReading().GetExpenseClaimsByClaimerAndOrganization(person.Identity,
|
||||
|
||||
@@ -281,6 +281,29 @@ namespace Swarmops.Logic.Financial
|
||||
// TODO: Log that the tag was added (and by whom?)
|
||||
}
|
||||
|
||||
public FinancialTransactionTagType GetTag (FinancialTransactionTagSet tagSet)
|
||||
{
|
||||
// We're lazy: we're getting ALL tags and picking out the correct one. It's a minimum of overhead given that
|
||||
// there should be at most five records in the most advanced scenarios, and this is cheaper than doing it
|
||||
// database-side.
|
||||
|
||||
// Possible todo: cache tags (it's likely there are several calls in a row).
|
||||
|
||||
FinancialTransactionTagTypes tagTypes = FinancialTransactionTagTypes.ForTransaction(this);
|
||||
|
||||
foreach (FinancialTransactionTagType tagType in tagTypes)
|
||||
{
|
||||
if (tagType.FinancialTransactionTagSetId == tagSet.Identity)
|
||||
{
|
||||
return tagType;
|
||||
}
|
||||
}
|
||||
|
||||
// None found, so return null
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public bool RecalculateTransaction (Dictionary<int, Int64> nominalTransaction, Person loggingPerson)
|
||||
{
|
||||
|
||||
@@ -14,5 +14,22 @@ namespace Swarmops.Logic.Financial
|
||||
{
|
||||
return FromArray(SwarmDb.GetDatabaseForReading().GetFinancialTransactionTagTypes(set));
|
||||
}
|
||||
|
||||
public static FinancialTransactionTagTypes FromIdentities (int[] identities)
|
||||
{
|
||||
return FromArray(SwarmDb.GetDatabaseForReading().GetFinancialTransactionTagTypesByIdentity(identities));
|
||||
}
|
||||
|
||||
public static FinancialTransactionTagTypes ForTransaction (FinancialTransaction transaction)
|
||||
{
|
||||
int[] tagTypeIdentities = SwarmDb.GetDatabaseForReading().GetFinancialTransactionTagTypes(transaction.Identity);
|
||||
|
||||
if (tagTypeIdentities.Length == 0)
|
||||
{
|
||||
return new FinancialTransactionTagTypes(); // none, so return empty set
|
||||
}
|
||||
|
||||
return FromIdentities(tagTypeIdentities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,6 +301,12 @@ namespace Swarmops.Logic.Financial
|
||||
SwarmDb.GetDatabaseForWriting().CreatePayoutDependency(payoutId, FinancialDependencyType.ExpenseClaim,
|
||||
claimId);
|
||||
}
|
||||
|
||||
foreach (int advancePaybackId in advancePaybackIdentityList)
|
||||
{
|
||||
SwarmDb.GetDatabaseForWriting().CreatePayoutDependency(payoutId, FinancialDependencyType.CashAdvancePayback,
|
||||
advancePaybackId);
|
||||
}
|
||||
}
|
||||
else if (components[0][0] == 'I')
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace Swarmops.Logic.Swarm
|
||||
|
||||
result.AddExpenseClaimAttestations(person, organization);
|
||||
result.AddCashAdvanceAttestations(person, organization);
|
||||
result.AddReceiptValidations(person, organization);
|
||||
result.AddPayouts(person, organization);
|
||||
|
||||
// TODO: Add any hooks
|
||||
@@ -28,6 +29,38 @@ namespace Swarmops.Logic.Swarm
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void AddReceiptValidations(Person person, Organization organization)
|
||||
{
|
||||
if (!person.HasAccess(new Access(organization, AccessAspect.Financials, AccessType.Write)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ExpenseClaims claims = ExpenseClaims.ForOrganization(organization);
|
||||
claims = claims.WhereUnvalidated;
|
||||
|
||||
DashboardTodo todo = new DashboardTodo();
|
||||
|
||||
if (claims.Count > 1)
|
||||
{
|
||||
todo.Description = String.Format(App_GlobalResources.Logic_Swarm_DashboardTodos.Validate_Receipts_Many, Formatting.GenerateRangeString(claims.Identities));
|
||||
}
|
||||
else
|
||||
{
|
||||
todo.Description = String.Format(App_GlobalResources.Logic_Swarm_DashboardTodos.Validate_Receipts_One, claims[0].Identity);
|
||||
}
|
||||
|
||||
todo.Icon = "/Images/PageIcons/iconshock-invoice-greentick-16px.png";
|
||||
todo.Url = "/Pages/v5/Financial/ValidateReceipts.aspx";
|
||||
|
||||
this.Add(todo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// TODO: Refactor the attest-X functions into one function with minimal differences
|
||||
|
||||
|
||||
|
||||
@@ -348,4 +348,16 @@
|
||||
<data name="Financial_ExpenseClaimsSpecificationLessAdvances" xml:space="preserve">
|
||||
<value>Expenses {0} (minus advances)</value>
|
||||
</data>
|
||||
<data name="Financial_ExpenseClaimSpecificationWithClaimer" xml:space="preserve">
|
||||
<value>Expense Claim #{0} by {1}</value>
|
||||
</data>
|
||||
<data name="Financial_InboundInvoiceSpecificationWithSender" xml:space="preserve">
|
||||
<value>Inbound Invoice #{0} from {1}</value>
|
||||
</data>
|
||||
<data name="Financial_ReceiptSpecification" xml:space="preserve">
|
||||
<value>Receipt Image {0} of {1}</value>
|
||||
</data>
|
||||
<data name="Global_ImageSpecification" xml:space="preserve">
|
||||
<value>Image {0} of {1}</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -207,6 +207,9 @@
|
||||
<data name="Menu5_Financial_SendInvoice" xml:space="preserve">
|
||||
<value>Send Invoice</value>
|
||||
</data>
|
||||
<data name="Menu5_Financial_ValidateReceipts" xml:space="preserve">
|
||||
<value>Validate Receipts</value>
|
||||
</data>
|
||||
<data name="Menu5_Financial_ViewBudgetActuals" xml:space="preserve">
|
||||
<value>View Budget and Actuals</value>
|
||||
</data>
|
||||
|
||||
@@ -354,4 +354,19 @@
|
||||
<data name="RequestCashAdvance_ValidationError_Purpose" xml:space="preserve">
|
||||
<value>Please state the purpose of the cash advance.</value>
|
||||
</data>
|
||||
<data name="ValidateReceipts_Header_ReceiptsAwaitingValidation" xml:space="preserve">
|
||||
<value>Receipts awaiting your validation</value>
|
||||
</data>
|
||||
<data name="ValidateReceipts_Info" xml:space="preserve">
|
||||
<value>This is where you inspect and confirm the validity of receipts that accompany expense claims. Check that the amount is correct and that the receipt appears to be for what it is claimed to be for.</value>
|
||||
</data>
|
||||
<data name="ValidateReceipts_PageTitle" xml:space="preserve">
|
||||
<value>Validate Receipts</value>
|
||||
</data>
|
||||
<data name="ValidateReceipts_ReceiptsDevalidated" xml:space="preserve">
|
||||
<value>The receipts for Expense Claim #{0} for {1} {2:N2} have been DE-validated. The expense claim will not proceed to payout unless re-validated.</value>
|
||||
</data>
|
||||
<data name="ValidateReceipts_ReceiptsValidated" xml:space="preserve">
|
||||
<value>The receipts for Expense Claim #{0} for {1} {2:N2} have been validated.</value>
|
||||
</data>
|
||||
</root>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 731 B |
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
@@ -162,6 +162,7 @@
|
||||
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="2" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Manage Budget" Permission="All" UserLevel="2" GlobalResourceKey="Menu5_Financial_ManageBudget" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Attest Costs" NavigateUrl="~/Pages/v5/Financial/AttestCosts.aspx" ImageUrl="~/Images/PageIcons/iconshock-stamped-paper-16px.png" Permission="All" UserLevel="2" GlobalResourceKey="Menu5_Financial_AttestCosts" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Validate Receipts" NavigateUrl="~/Pages/v5/Financial/ValidateReceipts.aspx" ImageUrl="~/Images/PageIcons/iconshock-invoice-greentick-16px.png" Permission="Economy:Write" UserLevel="2" GlobalResourceKey="Menu5_Financial_ValidateReceipts" />
|
||||
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="2" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Send Invoice" Permission="Economy:Write" UserLevel="2" GlobalResourceKey="Menu5_Financial_SendInvoice" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Received Invoice" Permission="Economy:Write" UserLevel="2" GlobalResourceKey="Menu5_Financial_ReceivedInvoice" />
|
||||
|
||||
@@ -254,7 +254,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
{
|
||||
if (_attestationRights.ContainsKey(expenseClaim.BudgetId) || expenseClaim.Budget.OwnerPersonId == Person.NobodyId)
|
||||
{
|
||||
AddDocuments(expenseClaim.Documents, "E" + expenseClaim.Identity.ToString(CultureInfo.InvariantCulture), String.Format("Expense Claim #{0} by {1} - ", expenseClaim.Identity, expenseClaim.ClaimerCanonical) + "Receipt Image {0} of {1}");
|
||||
AddDocuments(expenseClaim.Documents, "E" + expenseClaim.Identity.ToString(CultureInfo.InvariantCulture), String.Format(Resources.Global.Financial_ExpenseClaimSpecificationWithClaimer + " - ", expenseClaim.Identity, expenseClaim.ClaimerCanonical) + Resources.Global.Financial_ReceiptSpecification);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -271,7 +271,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
|
||||
if (_attestationRights.ContainsKey(invoice.BudgetId) || invoice.Budget.OwnerPersonId == Person.NobodyId)
|
||||
{
|
||||
AddDocuments(invoice.Documents, "I" + invoice.Identity.ToString(CultureInfo.InvariantCulture), String.Format("Invoice #{0} from {1} - ", invoice.Identity, invoice.Supplier) + "Image {0} of {1}");
|
||||
AddDocuments(invoice.Documents, "I" + invoice.Identity.ToString(CultureInfo.InvariantCulture), String.Format(Resources.Global.Financial_InboundInvoiceSpecificationWithSender + " - ", invoice.Identity, invoice.Supplier) + Resources.Global.Global_ImageSpecification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,15 +58,16 @@ namespace Swarmops.Frontend.Pages.Financial
|
||||
"\"reference\":\"{5}\"," +
|
||||
"\"amount\":\"{6:N2}\"," +
|
||||
"\"action\":\"" +
|
||||
"<img id=\\\"IconApproval{0}\\\" class=\\\"LocalIconApproval\\\" baseid=\\\"{0}\\\" height=\\\"16\\\" width=\\\"16\\\" />" +
|
||||
"<img id=\\\"IconApproved{0}\\\" class=\\\"LocalIconApproved\\\" baseid=\\\"{0}\\\" height=\\\"16\\\" width=\\\"16\\\" />\"",
|
||||
"<img id=\\\"IconApproval{7}\\\" class=\\\"LocalIconApproval\\\" baseid=\\\"{0}\\\" height=\\\"16\\\" width=\\\"16\\\" />" +
|
||||
"<img id=\\\"IconApproved{7}\\\" class=\\\"LocalIconApproved\\\" baseid=\\\"{0}\\\" height=\\\"16\\\" width=\\\"16\\\" />\"",
|
||||
payout.ProtoIdentity,
|
||||
(payout.ExpectedTransactionDate <= today? Resources.Global.Global_ASAP: payout.ExpectedTransactionDate.ToShortDateString()),
|
||||
TryLocalize(payout.Recipient),
|
||||
payout.Bank,
|
||||
payout.Account,
|
||||
TryLocalize(payout.Reference),
|
||||
payout.AmountCents/100.0);
|
||||
payout.AmountCents/100.0,
|
||||
payout.ProtoIdentity.Replace("|", ""));
|
||||
result.Append("},");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-ValidatableReceipts.aspx.cs" Inherits="Pages_v5_Finance_Json_ValidatableReceipts" %>
|
||||
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Swarmops.Basic.Interfaces;
|
||||
using Swarmops.Logic.Financial;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Support;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
public partial class Pages_v5_Finance_Json_ValidatableReceipts : DataV5Base
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!CurrentUser.HasAccess(new Access(CurrentOrganization, AccessAspect.Financials, AccessType.Read)))
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
ExpenseClaims claims = ExpenseClaims.ForOrganization(CurrentOrganization);
|
||||
claims = claims.WhereUnvalidated;
|
||||
|
||||
// Format as JSON and return
|
||||
|
||||
Response.ContentType = "application/json";
|
||||
string json = FormatAsJson(claims);
|
||||
Response.Output.WriteLine(json);
|
||||
Response.End();
|
||||
}
|
||||
|
||||
private string FormatAsJson(ExpenseClaims claims)
|
||||
{
|
||||
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=\\\"E{5}\\\" class=\\\"LocalViewDox\\\" style=\\\"cursor:pointer\\\" />";
|
||||
|
||||
result.Append("{\"rows\":[");
|
||||
FinancialTransactionTagSets tagSets = FinancialTransactionTagSets.ForOrganization(CurrentOrganization);
|
||||
|
||||
foreach (ExpenseClaim claim in claims)
|
||||
{
|
||||
StringBuilder extraTags = new StringBuilder();
|
||||
|
||||
FinancialTransaction transaction = claim.FinancialTransaction;
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
foreach (FinancialTransactionTagSet tagSet in tagSets)
|
||||
{
|
||||
FinancialTransactionTagType tagType = transaction.GetTag(tagSet);
|
||||
|
||||
extraTags.AppendFormat("\"tagSet{0}\":\"{1}\",",
|
||||
tagSet.Identity, tagType != null ? tagType.Name : string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
result.Append("{");
|
||||
result.AppendFormat(
|
||||
"\"description\":\"{2}\",\"budgetName\":\"{3}\",{6}\"amountRequested\":\"{4:N2}\",\"itemId\":\"E{5}\"," +
|
||||
"\"dox\":\"" + (claim.Documents.Count > 0? hasDoxString: " ") + "\"," +
|
||||
"\"actions\":\"<span style=\\\"position:relative;top:3px\\\">" +
|
||||
"<img id=\\\"IconApprovalE{5}\\\" class=\\\"LocalIconApproval\\\" baseid=\\\"E{5}\\\" height=\\\"16\\\" width=\\\"16\\\" />" +
|
||||
"<img id=\\\"IconApprovedE{5}\\\" class=\\\"LocalIconApproved\\\" baseid=\\\"E{5}\\\" height=\\\"16\\\" width=\\\"16\\\" /> " +
|
||||
"<img id=\\\"IconDenialE{5}\\\" class=\\\"LocalIconDenial\\\" baseid=\\\"E{5}\\\" height=\\\"16\\\" width=\\\"16\\\" />" +
|
||||
"<img id=\\\"IconDeniedE{5}\\\" class=\\\"LocalIconDenied\\\" baseid=\\\"E{5}\\\" height=\\\"16\\\" width=\\\"16\\\" /></span>\"",
|
||||
"olditem", claim.ClaimerCanonical, claim.Description, claim.Budget.Name,
|
||||
claim.AmountCents/100.0, claim.Identity, extraTags.ToString());
|
||||
result.Append("},");
|
||||
}
|
||||
|
||||
result.Remove(result.Length - 1, 1); // remove last comma
|
||||
|
||||
result.Append("]}");
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -58,7 +58,7 @@
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("rel", "loading");
|
||||
$(this).attr("src", "/Images/Abstract/ajaxloader-medium.gif");
|
||||
$("#IconDenial" + $(this).attr("baseid")).fadeTo(1000, 0.01).css("cursor", "default");
|
||||
$("#IconDenial" + $(this).attr("baseid").replace(/\|/g,'')).fadeTo(1000, 0.01).css("cursor", "default");
|
||||
var thisIcon = this;
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
@@ -95,7 +95,7 @@
|
||||
$(thisIcon).css("display", "none");
|
||||
$(thisIcon).attr("src", "/Images/Icons/iconshock-greentick-16px.png");
|
||||
$(thisIcon).attr("rel", "");
|
||||
$("#IconApproval" + $(thisIcon).attr("baseid")).fadeIn(100);
|
||||
$("#IconApproval" + $(thisIcon).attr("baseid").replace(/\|/g, '')).fadeIn(100);
|
||||
$("#" + $(thisIcon).attr("rel"), "");
|
||||
alertify.log(unescape(msg.d.DisplayMessage));
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="ValidateReceipts.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.ValidateReceipts" %>
|
||||
<%@ Register src="~/Controls/v5/UI/ExternalScripts.ascx" tagname="ExternalScripts" tagprefix="Swarmops5" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
|
||||
<Swarmops5:ExternalScripts ID="ExternalScripts1" Package="easyui" Control="datagrid" 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/Icons/iconshock-balloon-yes-16px-hot.png',
|
||||
'/Images/Icons/iconshock-balloon-no-16px-hot.png',
|
||||
'/Images/Icons/iconshock-greentick-16px.png',
|
||||
'/Images/Icons/iconshock-redcross-16px.png',
|
||||
'/Images/Icons/undo-16px.png'
|
||||
]);
|
||||
|
||||
$(document).ready(function () {
|
||||
$('#TableAttestableCosts').datagrid(
|
||||
{
|
||||
onLoadSuccess: function () {
|
||||
$(".LocalIconApproval").attr("src", "/Images/Icons/iconshock-balloon-yes-16px.png");
|
||||
$(".LocalIconApproved").attr("src", "/Images/Icons/iconshock-greentick-16px.png");
|
||||
$(".LocalIconApproved, .LocalIconDenied").css("display", "none");
|
||||
$(".LocalIconDenial").attr("src", "/Images/Icons/iconshock-balloon-no-16px.png");
|
||||
$(".LocalIconApproval, .LocalIconApproved, .LocalIconDenial").css("cursor", "pointer");
|
||||
|
||||
$(".LocalIconApproval").mouseover(function () {
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("src", "/Images/Icons/iconshock-balloon-yes-16px-hot.png");
|
||||
}
|
||||
});
|
||||
|
||||
$(".LocalIconApproval").mouseout(function () {
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("src", "/Images/Icons/iconshock-balloon-yes-16px.png");
|
||||
}
|
||||
});
|
||||
|
||||
$(".LocalIconApproved").mouseover(function () {
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("src", "/Images/Icons/undo-16px.png");
|
||||
}
|
||||
});
|
||||
|
||||
$(".LocalIconApproved").mouseout(function () {
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("src", "/Images/Icons/iconshock-greentick-16px.png");
|
||||
}
|
||||
});
|
||||
|
||||
$(".LocalIconApproval").click(function () {
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("rel", "loading");
|
||||
$(this).attr("src", "/Images/Abstract/ajaxloader-medium.gif");
|
||||
$("#IconDenial" + $(this).attr("baseid")).fadeTo(1000, 0.01).css("cursor", "default");
|
||||
var thisIcon = this;
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "ValidateReceipts.aspx/Validate",
|
||||
data: "{'identifier': '" + escape($(this).attr("baseid")) + "'}",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
success: function (msg) {
|
||||
$(thisIcon).css("display", "none");
|
||||
$(thisIcon).attr("src", "/Images/Icons/iconshock-balloon-yes-16px.png");
|
||||
$(thisIcon).attr("rel", "active");
|
||||
$("#IconApproved" + $(thisIcon).attr("baseid")).fadeIn(100);
|
||||
alertify.success(unescape(msg.d));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$(".LocalIconApproved").click(function () {
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("rel", "loading");
|
||||
$(this).attr("src", "/Images/Abstract/ajaxloader-medium.gif");
|
||||
var thisIcon = this;
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "ValidateReceipts.aspx/Devalidate",
|
||||
data: "{'identifier': '" + escape($(this).attr("baseid")) + "'}",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
dataType: "json",
|
||||
success: function (msg) {
|
||||
$(thisIcon).css("display", "none");
|
||||
$(thisIcon).attr("src", "/Images/Icons/iconshock-greentick-16px.png");
|
||||
$(thisIcon).attr("rel", "");
|
||||
$("#IconApproval" + $(thisIcon).attr("baseid")).fadeIn(100);
|
||||
$("#" + $(thisIcon).attr("rel"), "");
|
||||
alertify.log(unescape(msg.d).replace('+', ' '));
|
||||
$("#IconDenial" + $(thisIcon).attr("baseid")).fadeTo(100, 1).css("cursor", "pointer");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
$(".LocalIconDenial").mouseover(function () {
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("src", "/Images/Icons/iconshock-balloon-no-16px-hot.png");
|
||||
}
|
||||
});
|
||||
|
||||
$(".LocalIconDenial").mouseout(function () {
|
||||
if ($(this).attr("rel") != "loading") {
|
||||
$(this).attr("src", "/Images/Icons/iconshock-balloon-no-16px.png");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$(".LocalIconDenial").click(function () {
|
||||
alert('Denying validation is not yet implemented, but you can just leave the unwanted cost here until it is.');
|
||||
});
|
||||
|
||||
$(".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
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
.datagrid-row-selected,.datagrid-row-over{
|
||||
background:transparent;
|
||||
}
|
||||
</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="TableAttestableCosts" class="easyui-datagrid" style="width:680px;height:400px"
|
||||
data-options="rownumbers:false,singleSelect:false,fit:false,loading:false,selectOnCheck:true,checkOnSelect:true,url:'Json-ValidatableReceipts.aspx'"
|
||||
idField="itemId">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-options="field:'description',width:140"><asp:Label ID="LabelGridHeaderDescription" runat="server" Text="XYZ Description" /></th>
|
||||
<th data-options="field:'budgetName',width:180,sortable:true"><asp:Label ID="LabelGridHeaderBudget" runat="server" Text="XYZ Budget" /></th>
|
||||
<asp:Literal runat="server" ID="LiteralExtraTags" />
|
||||
<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:'actions',width:53,align:'center'"><asp:Label ID="LabelGridHeaderAction" 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") %>"> </a>
|
||||
</ItemTemplate>
|
||||
</asp:Repeater>
|
||||
|
||||
</div>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
|
||||
</asp:Content>
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.ServiceModel.Security;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Services;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
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 ValidateReceipts : PageV5Base
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!this.CurrentOrganization.IsEconomyEnabled)
|
||||
{
|
||||
Response.Redirect("/Pages/v5/Financial/EconomyNotEnabled.aspx", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.CurrentUser.HasAccess (new Access(CurrentOrganization, AccessAspect.Financials, AccessType.Write)))
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
this.PageIcon = "iconshock-invoice-greentick";
|
||||
|
||||
if (!Page.IsPostBack)
|
||||
{
|
||||
Localize();
|
||||
}
|
||||
|
||||
_documentList = new List<RepeatedDocument>();
|
||||
|
||||
PopulateExpenses();
|
||||
|
||||
this.RepeaterLightboxItems.DataSource = _documentList;
|
||||
this.RepeaterLightboxItems.DataBind();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private Dictionary<int, bool> _attestationRights;
|
||||
private List<RepeatedDocument> _documentList;
|
||||
|
||||
|
||||
|
||||
private Dictionary<int, bool> 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, bool> result = new Dictionary<int, bool>();
|
||||
FinancialAccounts accounts = FinancialAccounts.ForOrganization(this.CurrentOrganization);
|
||||
|
||||
foreach (FinancialAccount account in accounts)
|
||||
{
|
||||
if (account.OwnerPersonId == this.CurrentUser.Identity)
|
||||
{
|
||||
result[account.Identity] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Localize()
|
||||
{
|
||||
this.PageTitle = Resources.Pages.Financial.ValidateReceipts_PageTitle;
|
||||
this.InfoBoxLiteral = Resources.Pages.Financial.ValidateReceipts_Info;
|
||||
this.LabelAttestCostsHeader.Text = Resources.Pages.Financial.ValidateReceipts_Header_ReceiptsAwaitingValidation;
|
||||
this.LabelGridHeaderAction.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Action; // Reuse some strings from Attest Costs
|
||||
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.LabelGridHeaderRequested.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Requested;
|
||||
|
||||
FinancialTransactionTagSets tagSets = FinancialTransactionTagSets.ForOrganization(CurrentOrganization);
|
||||
if (tagSets.Count > 0)
|
||||
{
|
||||
int tagWidth = 360/(tagSets.Count + 1);
|
||||
|
||||
//this.LiteralBudgetNameWidth.Text = tagWidth.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
StringBuilder tagSetHtml = new StringBuilder();
|
||||
|
||||
foreach (FinancialTransactionTagSet tagSet in tagSets)
|
||||
{
|
||||
tagSetHtml.AppendFormat(
|
||||
"<th data-options=\"field:'tagSet{0}',width:{1},sortable:true,order:'asc'\">{2}</th>\r\n",
|
||||
tagSet.Identity, tagWidth, FinancialTransactionTagSetType.GetLocalizedName(tagSet.FinancialTransactionTagSetTypeId));
|
||||
}
|
||||
|
||||
this.LiteralExtraTags.Text = tagSetHtml.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private enum AttestationMode
|
||||
{
|
||||
Unknown = 0,
|
||||
Attestation,
|
||||
Deattestation
|
||||
};
|
||||
|
||||
[WebMethod]
|
||||
public static string Validate (string identifier)
|
||||
{
|
||||
identifier = HttpUtility.UrlDecode(identifier);
|
||||
|
||||
string result = HandleValidationDevalidation(identifier, AttestationMode.Attestation);
|
||||
|
||||
return HttpUtility.UrlEncode(result).Replace("+", "%20");
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
public static string Devalidate(string identifier)
|
||||
{
|
||||
identifier = HttpUtility.UrlDecode(identifier);
|
||||
|
||||
string result = HandleValidationDevalidation(identifier, AttestationMode.Deattestation);
|
||||
|
||||
return HttpUtility.UrlEncode(result).Replace("+", "%20");
|
||||
}
|
||||
|
||||
|
||||
private static string HandleValidationDevalidation (string identifier, AttestationMode mode)
|
||||
{
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture();
|
||||
|
||||
IValidatable validatableItem = null;
|
||||
string validatedTemplate = string.Empty;
|
||||
string devalidatedTemplate = 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.CurrentUser.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.Financials, AccessType.Write)))
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
validatableItem = expense;
|
||||
validatedTemplate = Resources.Pages.Financial.ValidateReceipts_ReceiptsValidated;
|
||||
devalidatedTemplate = 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 == AttestationMode.Attestation)
|
||||
{
|
||||
validatableItem.Validate(authData.CurrentUser);
|
||||
result = string.Format(validatedTemplate, itemId, authData.CurrentOrganization.Currency.Code,
|
||||
amountCents/100.0);
|
||||
}
|
||||
else if (mode == AttestationMode.Deattestation)
|
||||
{
|
||||
validatableItem.Devalidate(authData.CurrentUser);
|
||||
result = string.Format(devalidatedTemplate, itemId, authData.CurrentOrganization.Currency.Code,
|
||||
amountCents / 100.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Unknown Attestation Mode: " + mode.ToString());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void PopulateExpenses()
|
||||
{
|
||||
ExpenseClaims expenses = ExpenseClaims.ForOrganization(this.CurrentOrganization).WhereUnattested;
|
||||
|
||||
foreach (var expenseClaim in expenses)
|
||||
{
|
||||
AddDocuments(expenseClaim.Documents, "E" + expenseClaim.Identity.ToString(CultureInfo.InvariantCulture), String.Format(Resources.Global.Financial_ExpenseClaimSpecification + " - ", expenseClaim.Identity) + Resources.Global.Financial_ReceiptSpecification);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)};
|
||||
|
||||
_documentList.Add(newDoc);
|
||||
}
|
||||
}
|
||||
|
||||
public class RepeatedDocument
|
||||
{
|
||||
public int DocId { get; set; }
|
||||
public string BaseId { get; set; }
|
||||
public string Title { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user