Added ability to balance txs against foreign-currency accounting (imprecise)
This commit is contained in:
@@ -732,6 +732,12 @@
|
||||
<value>Payout #{0:N0}, {5} (expected {1:yyyy-MMM-dd}) for {2}: {3} {4:N2}</value>
|
||||
<comment>0 is the payout Id, 1 is the date (do edit format if called for in culture), 2 is the recipient name, and 3 4 is the currency and amount, 5 is the specification (like "Expense Claim #4711")</comment>
|
||||
</data>
|
||||
<data name="BalanceTransactions_ModalDialog_DescribePayoutForeign" xml:space="preserve">
|
||||
<value>The transaction matches this foreign-currency payout:</value>
|
||||
</data>
|
||||
<data name="BalanceTransactions_ModalDialog_RadioPayoutForeign" xml:space="preserve">
|
||||
<value>Map the transaction to a foreign-currency payout ({0}% amount tolerance)?</value>
|
||||
</data>
|
||||
<data name="BudgetActual_ContentHeader" xml:space="preserve">
|
||||
<value>Budget vs Actual</value>
|
||||
</data>
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
<value>Enter your code from Google Authenticator.</value>
|
||||
</data>
|
||||
<data name="Login_Header" xml:space="preserve">
|
||||
<value>Login with Blockchain Technology (BitId)</value>
|
||||
<value>Login with Bitcoin Signature (BitId)</value>
|
||||
</data>
|
||||
<data name="Login_Help" xml:space="preserve">
|
||||
<value>Help</value>
|
||||
|
||||
@@ -41,6 +41,8 @@
|
||||
$('span#spanModalTransactionDate').text('[...]');
|
||||
<%=this.DropOpenPayouts.ClientID%>_loadData([{ id: 0, text: "<%=Resources.Global.Global_LoadingPlaceholder%>" }]);
|
||||
<%=this.DropOpenPayouts.ClientID%>_val('0');
|
||||
<%=this.DropOpenPayoutsForeign.ClientID%>_loadData([{ id: 0, text: "<%=Resources.Global.Global_LoadingPlaceholder%>" }]);
|
||||
<%=this.DropOpenPayoutsForeign.ClientID%>_val('0');
|
||||
|
||||
SwarmopsJS.ajaxCall(
|
||||
"/Pages/v5/Ledgers/BalanceTransactions.aspx/GetTransactionMatchability",
|
||||
@@ -49,14 +51,22 @@
|
||||
$('#spanTransactionUnbalancedBy').text(data.DifferingAmount);
|
||||
$('span#spanModalTransactionDate').text(data.TransactionDate);
|
||||
|
||||
if (data.OpenPayoutData.length > 0) {
|
||||
<%=this.DropOpenPayouts.ClientID%>_loadData(data.OpenPayoutData);
|
||||
if (data.OpenPayoutData.ExactMatches.length > 0) {
|
||||
<%=this.DropOpenPayouts.ClientID%>_loadData(data.OpenPayoutData.ExactMatches);
|
||||
<%=this.DropOpenPayouts.ClientID%>_text("<%=Resources.Global.Global_SelectOne%>");
|
||||
} else {
|
||||
<%=this.DropOpenPayouts.ClientID%>_loadData({});
|
||||
<%=this.DropOpenPayouts.ClientID%>_text("<%=Resources.Global.Global_NoMatch%>");
|
||||
}
|
||||
|
||||
if (data.OpenPayoutData.TolerantMatches.length > 0) {
|
||||
<%=this.DropOpenPayoutsForeign.ClientID%>_loadData(data.OpenPayoutData.TolerantMatches);
|
||||
<%=this.DropOpenPayoutsForeign.ClientID%>_text("<%=Resources.Global.Global_SelectOne%>");
|
||||
} else {
|
||||
<%=this.DropOpenPayoutsForeign.ClientID%>_loadData({});
|
||||
<%=this.DropOpenPayoutsForeign.ClientID%>_text("<%=Resources.Global.Global_NoMatch%>");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
@@ -92,6 +102,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
function onMatchOpenPayoutForeign() {
|
||||
var payoutId = <%=this.DropOpenPayoutsForeign.ClientID%>_val();
|
||||
|
||||
if (payoutId > 0) {
|
||||
<%= this.DialogTx.ClientID %>_close();
|
||||
SwarmopsJS.ajaxCall(
|
||||
"/Pages/v5/Ledgers/BalanceTransactions.aspx/MatchTransactionOpenPayoutForeign",
|
||||
{ transactionId: transactionId, payoutId: payoutId },
|
||||
function () {
|
||||
$('#gridTransactions').datagrid('reload');
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
@@ -162,6 +187,16 @@
|
||||
<asp:Label runat="server" ID="LabelDescribePayout" Text="Match to payout XYZ" />
|
||||
</div>
|
||||
</div>
|
||||
<p><input type="radio" id="RadioPayoutForeign" name="TxOptions" value="PayoutForeign" /><label for="RadioPayoutForeign"><asp:Label runat="server" ID="LabelRadioPayoutForeign" Text="Match to an open foreign-currency payout? XYZ" /></label></p>
|
||||
<div id="radioOptionPayoutForeign" class="radioOption">
|
||||
<div class="entryFields">
|
||||
<Swarmops5:DropDown ID="DropOpenPayoutsForeign" runat="server" ListType="All" />​<br/>
|
||||
<input type="button" value='<asp:Literal ID="LiteralButtonPayoutForeign" runat="server" Text="MatchXYZ" />' class="buttonAccentColor" onclick="onMatchOpenPayoutForeign(); return false;" id="buttonExecutePayoutForeign"/>
|
||||
</div>
|
||||
<div class="entryLabels">
|
||||
<asp:Label runat="server" ID="LabelDescribePayoutForeign" Text="Match to payout XYZ" />
|
||||
</div>
|
||||
</div>
|
||||
<div id="divHiddenTodoFutureSprint" style="display:none">
|
||||
<p><input type="radio" id="RadioExistingPayment" name="TxOptions" value="ExistingPayment" /><label for="RadioExistingPayment"><asp:Label runat="server" ID="LabelRadioExistingPayment" Text="Match this balance to a recorded payment, uploaded in a payments file? XYZ" /></label></p>
|
||||
<div id="radioOptionExistingPayment" class="radioOption">
|
||||
|
||||
@@ -44,8 +44,12 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
this.LiteralButtonBalance.Text = Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_ButtonBalance;
|
||||
|
||||
this.LabelDescribePayout.Text = Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_DescribePayout;
|
||||
this.LabelDescribePayoutForeign.Text = Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_DescribePayoutForeign;
|
||||
this.LabelRadioPayout.Text = Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_RadioPayout;
|
||||
this.LabelRadioPayoutForeign.Text =
|
||||
String.Format(Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_RadioPayoutForeign, 5);
|
||||
this.LiteralButtonPayout.Text = Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_ButtonPayout;
|
||||
this.LiteralButtonPayoutForeign.Text = Resources.Pages.Ledgers.BalanceTransactions_ModalDialog_ButtonPayout;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +58,14 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
{
|
||||
public string TransactionDate { get; set; }
|
||||
public string DifferingAmount { get; set; }
|
||||
public DropdownOption[] OpenPayoutData { get; set; }
|
||||
public DropdownOptions OpenPayoutData { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class DropdownOptions
|
||||
{
|
||||
public DropdownOption[] ExactMatches { get; set; }
|
||||
public DropdownOption[] TolerantMatches { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -99,33 +110,52 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
return result;
|
||||
}
|
||||
|
||||
private static DropdownOption[] GetOpenPayoutData(FinancialTransaction transaction)
|
||||
private static DropdownOptions GetOpenPayoutData(FinancialTransaction transaction)
|
||||
{
|
||||
DateTime transactionDateTime = transaction.DateTime;
|
||||
Int64 matchAmount = transaction.Rows.AmountCentsTotal;
|
||||
|
||||
List<DropdownOption> result = new List<DropdownOption>();
|
||||
DropdownOptions result = new DropdownOptions();
|
||||
|
||||
List<DropdownOption> listExact = new List<DropdownOption>();
|
||||
List<DropdownOption> listTolerant = new List<DropdownOption>();
|
||||
|
||||
Payouts openPayouts = Payouts.ForOrganization (transaction.Organization);
|
||||
|
||||
foreach (Payout payout in openPayouts)
|
||||
{
|
||||
if (payout.AmountCents == -matchAmount)
|
||||
if (payout.AmountCents > -matchAmount*95/100 &&
|
||||
payout.AmountCents < -matchAmount*105/100)
|
||||
{
|
||||
string description = String.Format (Resources.Pages.Ledgers.BalanceTransactions_PayoutMatch, payout.Identity,
|
||||
string description = String.Format(Resources.Pages.Ledgers.BalanceTransactions_PayoutMatch, payout.Identity,
|
||||
payout.ExpectedTransactionDate, payout.Recipient, payout.Organization.Currency.DisplayCode, payout.AmountCents / 100.0,
|
||||
payout.Specification);
|
||||
|
||||
result.Add(new DropdownOption
|
||||
if (payout.AmountCents == -matchAmount)
|
||||
{
|
||||
id = payout.Identity.ToString(CultureInfo.InvariantCulture),
|
||||
@group = Resources.Pages.Ledgers.BalanceTransactions_ExactMatches,
|
||||
text = description
|
||||
});
|
||||
listExact.Add(new DropdownOption
|
||||
{
|
||||
id = payout.Identity.ToString(CultureInfo.InvariantCulture),
|
||||
@group = Resources.Pages.Ledgers.BalanceTransactions_ExactMatches,
|
||||
text = description
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
listTolerant.Add(new DropdownOption
|
||||
{
|
||||
id = payout.Identity.ToString(CultureInfo.InvariantCulture),
|
||||
@group = Resources.Pages.Ledgers.BalanceTransactions_FivePercentMatches,
|
||||
text = description
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
result.ExactMatches = listExact.ToArray();
|
||||
result.TolerantMatches = listTolerant.ToArray();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
@@ -189,5 +219,61 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
|
||||
payout.BindToTransactionAndClose (transaction, authData.CurrentUser);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
[WebMethod]
|
||||
public static void MatchTransactionOpenPayoutForeign(int transactionId, int payoutId)
|
||||
{
|
||||
// This is like the non-foreign version except this one chalks up the difference to forex gain/loss accounts
|
||||
|
||||
if (transactionId == 0 || payoutId == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture();
|
||||
|
||||
if (
|
||||
!authData.Authority.HasAccess(new Access(authData.CurrentOrganization,
|
||||
AccessAspect.BookkeepingDetails)))
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
FinancialAccount forexSpillAccount =
|
||||
authData.CurrentOrganization.FinancialAccounts.IncomeCurrencyFluctuations;
|
||||
|
||||
if (forexSpillAccount == null)
|
||||
{
|
||||
throw new InvalidOperationException("Need forex gain/loss accounts for this operation"); // TODO: Autocreate?
|
||||
}
|
||||
|
||||
FinancialTransaction transaction = FinancialTransaction.FromIdentity(transactionId);
|
||||
Payout payout = Payout.FromIdentity(payoutId);
|
||||
|
||||
if (transaction.OrganizationId != authData.CurrentOrganization.Identity || payout.OrganizationId != authData.CurrentOrganization.Identity)
|
||||
{
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
if (-transaction.Rows.AmountCentsTotal > payout.AmountCents)
|
||||
{
|
||||
// This is a forex loss, not a gain which is the default
|
||||
forexSpillAccount = authData.CurrentOrganization.FinancialAccounts.CostsCurrencyFluctuations;
|
||||
}
|
||||
|
||||
transaction.AddRow (forexSpillAccount, -(payout.AmountCents + transaction.Rows.AmountCentsTotal), // plus because AmountCentsTotal is negative
|
||||
authData.CurrentUser); // Adds the forex adjustment so we can bind payout to tx and close
|
||||
|
||||
if (transaction.Rows.AmountCentsTotal != -payout.AmountCents)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
payout.BindToTransactionAndClose(transaction, authData.CurrentUser);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user