Work on Direct Purchases
This commit is contained in:
@@ -256,13 +256,6 @@ namespace Swarmops.Logic.Financial
|
||||
}
|
||||
}
|
||||
|
||||
[Obsolete ("Do not use double-precision methods. They leak cents. Use AddRow (FinancialAccount, Int64, Person).",
|
||||
true)]
|
||||
public void AddRow (FinancialAccount account, double amount, Person person)
|
||||
{
|
||||
AddRow (account, (Int64) (amount*100), person);
|
||||
}
|
||||
|
||||
public FinancialTransactionRow AddRow (FinancialAccount account, Int64 amountCents, Person person)
|
||||
{
|
||||
return AddRow (account.Identity, amountCents, person != null ? person.Identity : 0);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Swarmops.Basic.Types;
|
||||
using Swarmops.Basic.Types.Structure;
|
||||
using Swarmops.Common.Interfaces;
|
||||
@@ -79,5 +80,16 @@ namespace Swarmops.Logic.Support
|
||||
doc.SetForeignObject (foreignObject);
|
||||
}
|
||||
}
|
||||
|
||||
public Documents WhereNotAssociated
|
||||
{
|
||||
get
|
||||
{
|
||||
Documents result = new Documents();
|
||||
result.AddRange(this.Where(doc => doc.ForeignId == 0));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -501,6 +501,33 @@ namespace Resources.Pages {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to The transaction description cannot be empty..
|
||||
/// </summary>
|
||||
internal static string BalanceTransactions_Error_NeedDescription {
|
||||
get {
|
||||
return ResourceManager.GetString("BalanceTransactions_Error_NeedDescription", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to The transaction needs a proof of purchase..
|
||||
/// </summary>
|
||||
internal static string BalanceTransactions_Error_NeedDocumentation {
|
||||
get {
|
||||
return ResourceManager.GetString("BalanceTransactions_Error_NeedDocumentation", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to The VAT amount doesn't seem to be correctly entered..
|
||||
/// </summary>
|
||||
internal static string BalanceTransactions_Error_VatAmountParseError {
|
||||
get {
|
||||
return ResourceManager.GetString("BalanceTransactions_Error_VatAmountParseError", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Exact Matches For This Amount.
|
||||
/// </summary>
|
||||
|
||||
@@ -920,6 +920,15 @@
|
||||
<value>Totals for this report</value>
|
||||
<comment>Displayed as description of footer</comment>
|
||||
</data>
|
||||
<data name="BalanceTransactions_Error_NeedDescription" xml:space="preserve">
|
||||
<value>The transaction description cannot be empty.</value>
|
||||
</data>
|
||||
<data name="BalanceTransactions_Error_NeedDocumentation" xml:space="preserve">
|
||||
<value>The transaction needs a proof of purchase.</value>
|
||||
</data>
|
||||
<data name="BalanceTransactions_Error_VatAmountParseError" xml:space="preserve">
|
||||
<value>The VAT amount doesn't seem to be correctly entered.</value>
|
||||
</data>
|
||||
<data name="BalanceTransactions_ModalDialog_ButtonPurchase" xml:space="preserve">
|
||||
<value>Mark as Direct Purchase</value>
|
||||
</data>
|
||||
|
||||
@@ -218,7 +218,8 @@
|
||||
transactionId: transactionId,
|
||||
budgetId: budgetId,
|
||||
vatAmountString: vatAmount,
|
||||
newDescription: txDescription
|
||||
newDescription: txDescription,
|
||||
guid: uploadGuid
|
||||
},
|
||||
function(result) {
|
||||
if (result.Success) {
|
||||
@@ -246,6 +247,8 @@
|
||||
var buttonVatReportValue = SwarmopsJS.unescape('<%=this.Localized_ButtonVatReport%>');
|
||||
var buttonPurchaseValue = SwarmopsJS.unescape('<%=this.Localized_ButtonPurchase%>');
|
||||
|
||||
var uploadGuid = '<%=this.UploadPurchase.GuidString%>';
|
||||
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Web;
|
||||
using System.Web.Services;
|
||||
using System.Web.UI;
|
||||
@@ -9,6 +10,7 @@ using System.Web.UI.WebControls;
|
||||
using Newtonsoft.Json;
|
||||
using Swarmops.Logic.Financial;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
{
|
||||
@@ -523,7 +525,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
|
||||
[WebMethod]
|
||||
public static AjaxCallResult MarkDirectPurchase(int transactionId, int budgetId, string vatAmountString,
|
||||
string newDescription)
|
||||
string newDescription, string guid)
|
||||
{
|
||||
if (transactionId == 0 | budgetId == 0)
|
||||
{
|
||||
@@ -539,14 +541,70 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
FinancialAccount budget = FinancialAccount.FromIdentity(budgetId);
|
||||
|
||||
if (authData.CurrentOrganization.Identity != budget.Organization.Identity)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
newDescription = newDescription.Trim();
|
||||
if (newDescription.Length < 1)
|
||||
{
|
||||
return new AjaxCallResult
|
||||
{
|
||||
Success = false,
|
||||
DisplayMessage = Resources.Pages.Ledgers.BalanceTransactions_Error_NeedDescription
|
||||
};
|
||||
}
|
||||
|
||||
Documents docs = Documents.RecentFromDescription(guid).WhereNotAssociated;
|
||||
if (docs.Count < 1)
|
||||
{
|
||||
return new AjaxCallResult
|
||||
{
|
||||
Success = false,
|
||||
DisplayMessage = Resources.Pages.Ledgers.BalanceTransactions_Error_NeedDocumentation
|
||||
};
|
||||
}
|
||||
|
||||
Int64 vatCents = 0;
|
||||
bool vatEnabled = authData.CurrentOrganization.VatEnabled;
|
||||
|
||||
if (vatEnabled)
|
||||
{
|
||||
double vatDouble;
|
||||
try
|
||||
{
|
||||
vatCents = Swarmops.Logic.Support.Formatting.ParseDoubleStringAsCents(vatAmountString);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
return new AjaxCallResult
|
||||
{
|
||||
Success = false,
|
||||
DisplayMessage = Resources.Pages.Ledgers.BalanceTransactions_Error_VatAmountParseError
|
||||
};
|
||||
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// We're FINALLY ready to update the transaction
|
||||
|
||||
FinancialTransaction tx = FinancialTransaction.FromIdentity(transactionId);
|
||||
tx.Description = newDescription;
|
||||
docs.SetForeignObjectForAll(tx);
|
||||
|
||||
Int64 centsDiff = tx.Rows.AmountCentsTotal;
|
||||
|
||||
if (vatEnabled)
|
||||
{
|
||||
tx.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsVatInboundUnreported, vatCents, authData.CurrentUser);
|
||||
tx.AddRow(budget, (-centsDiff) - vatCents, authData.CurrentUser);
|
||||
}
|
||||
else
|
||||
{
|
||||
tx.AddRow(budget, -centsDiff, authData.CurrentUser);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user