Work on balancing positive mismatches in bank account

This commit is contained in:
Rick Falkvinge
2017-10-03 14:21:49 +02:00
parent 3027e84aac
commit 33da06b893
3 changed files with 154 additions and 31 deletions
+68 -30
View File
@@ -55,20 +55,44 @@
$('#spanTransactionUnbalancedBy').text(data.DifferingAmount);
$('span#spanModalTransactionDate').text(data.TransactionDate);
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 == null) // amount is positive
{
$('#divPositiveDifference').show();
$('#divNegativeDifference').hide();
if (data.OpenInvoiceData != null) {
if (data.OpenInvoiceData.ExactMatches.length > 0) {
<%=this.DropOpenOutboundInvoices.ClientID%>_loadData(data.OpenInvoiceData.ExactMatches);
<%=this.DropOpenOutboundInvoices.ClientID%>_text("<%=Resources.Global.Global_SelectOne%>");
} else {
<%=this.DropOpenOutboundInvoices.ClientID%>_loadData({});
<%=this.DropOpenOutboundInvoices.ClientID%>_text("<%=Resources.Global.Global_NoMatch%>");
}
}
} else { // amount is negative
$('#divPositiveDifference').hide();
$('#divNegativeDifference').show();
if (data.OpenPayoutData != null) {
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%>");
}
}
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%>");
}
});
@@ -174,7 +198,7 @@
<DialogCode>
<h2><asp:Literal runat="server" ID="LiteralModalHeader" Text="Matching/Balancing transaction #foobar XYZ" /></h2>
<p><asp:Literal ID="LabelDoYouWishTo" runat="server" Text="The balance is off by SEK +6,141.14. is Do you wish to... XYZ" /></p>
<p><input type="radio" id="RadioBalance" name="TxOptions" value="Balance" /><label for="RadioBalance"><asp:Label runat="server" ID="LabelRadioBalance" Text="Balance the transaction manually? XYZ" /></label></p>
<p><input type="radio" id="RadioBalance" name="TxOptions" value="Balance" /><label for="RadioBalance">&nbsp;<asp:Label runat="server" ID="LabelRadioBalance" Text="Balance the transaction manually? XYZ" /></label></p>
<div id="radioOptionBalance" class="radioOption">
<div class="entryFields">
<Swarmops5:ComboBudgets ID="DropBudgetBalance" runat="server" ListType="All" />&#8203;<br/>
@@ -185,27 +209,41 @@
</div>
<div style="clear:both"></div>
</div>
<p><input type="radio" id="RadioPayout" name="TxOptions" value="Payout" /><label for="RadioPayout"><asp:Label runat="server" ID="LabelRadioPayout" Text="Match this balance to an open payout? XYZ" /></label></p>
<div id="radioOptionPayout" class="radioOption">
<div class="entryFields">
<Swarmops5:DropDown ID="DropOpenPayouts" runat="server" ListType="All" />&#8203;<br/>
<input type="button" value='#Payout#' class="buttonAccentColor" onclick="onMatchOpenPayout(); return false;" id="buttonExecutePayout"/>
<div id="divNegativeDifference">
<p><input type="radio" id="RadioPayout" name="TxOptions" value="Payout" /><label for="RadioPayout">&nbsp;<asp:Label runat="server" ID="LabelRadioPayout" Text="Match this balance to an open payout? XYZ" /></label></p>
<div id="radioOptionPayout" class="radioOption">
<div class="entryFields">
<Swarmops5:DropDown ID="DropOpenPayouts" runat="server" ListType="All" />&#8203;<br/>
<input type="button" value='#Payout#' class="buttonAccentColor" onclick="onMatchOpenPayout(); return false;" id="buttonExecutePayout"/>
</div>
<div class="entryLabels">
<asp:Label runat="server" ID="LabelDescribePayout" Text="Match to payout XYZ" />
</div>
</div>
<div class="entryLabels">
<asp:Label runat="server" ID="LabelDescribePayout" Text="Match to payout XYZ" />
<p><input type="radio" id="RadioPayoutForeign" name="TxOptions" value="PayoutForeign" /><label for="RadioPayoutForeign">&nbsp;<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" />&#8203;<br/>
<input type="button" value='#PayoutForeign#' 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>
<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" />&#8203;<br/>
<input type="button" value='#PayoutForeign#' class="buttonAccentColor" onclick="onMatchOpenPayoutForeign(); return false;" id="buttonExecutePayoutForeign"/>
</div>
<div class="entryLabels">
<asp:Label runat="server" ID="LabelDescribePayoutForeign" Text="Match to payout XYZ" />
<div id="divPositiveDifference">
<p><input type="radio" id="RadioPaymentDirect" name="TxOptions" value="PaymentDirect" /><label for="RadioPaymentDirect">&nbsp;<asp:Label runat="server" ID="LabelRadioPaymentDirect" Text="Match to an open outbound invoice? XYZ" /></label></p>
<div id="radioOptionPaymentDirect" class="radioOption">
<div class="entryFields">
<Swarmops5:DropDown ID="DropOpenOutboundInvoices" runat="server" ListType="All" />&#8203;<br/>
<input type="button" value='#PaymentInvoice#' class="buttonAccentColor" onclick="onMatchOpenOutboundInvoice(); return false;" id="buttonExecutePayoutForeign"/>
</div>
<div class="entryLabels">
<asp:Label runat="server" ID="Label2" Text="Match to payout XYZ" />
</div>
</div>
</div>
<div id="radioOptionPayment" class="radioOption"></div>
<div id="radioOptionPayment2" class="radioOption"></div>
<div id="radioOptionPaymentForeign" class="radioOption"></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>
@@ -60,6 +60,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
public string TransactionDate { get; set; }
public string DifferingAmount { get; set; }
public DropdownOptions OpenPayoutData { get; set; }
public DropdownOptions OpenOutboundInvoiceData { get; set; }
public DropdownOptions OpenVatReports { get; set; }
}
[Serializable]
@@ -106,7 +108,17 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
// this is a UNICODE MINUS (U+2212), not the hyphen on the keyboard
authData.CurrentOrganization.Currency.DisplayCode, transaction.Rows.AmountCentsTotal/100.0);
result.OpenPayoutData = GetOpenPayoutData (transaction);
if (transaction.Rows.AmountCentsTotal > 0)
{
result.OpenOutboundInvoiceData = GetOpenOutboundInvoiceData(transaction);
result.OpenVatReports = null; // TODO
}
else
{
// Negative difference
result.OpenPayoutData = GetOpenPayoutData(transaction);
}
return result;
}
@@ -159,6 +171,52 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
return result;
}
private static DropdownOptions GetOpenOutboundInvoiceData(FinancialTransaction transaction)
{
DateTime txDateTime = transaction.DateTime;
Int64 matchAmount = transaction.Rows.AmountCentsTotal;
DropdownOptions result = new DropdownOptions();
List<DropdownOption> listExact = new List<DropdownOption>();
List<DropdownOption> listTolerant = new List<DropdownOption>();
OutboundInvoices invoices = OutboundInvoices.ForOrganization(transaction.Organization);
foreach (OutboundInvoice invoice in invoices)
{
if (invoice.AmountCents > -matchAmount * 95 / 100 &&
invoice.AmountCents < -matchAmount * 105 / 100)
{
string description = String.Format(Resources.Pages.Ledgers.BalanceTransactions_PayoutMatch, invoice.Identity,
invoice.DueDate, invoice.CustomerName, invoice.Organization.Currency.DisplayCode, invoice.AmountCents / 100.0,
invoice.DisplayNativeAmount);
if (invoice.AmountCents == matchAmount)
{
listExact.Add(new DropdownOption
{
id = invoice.Identity.ToString(CultureInfo.InvariantCulture),
@group = Resources.Pages.Ledgers.BalanceTransactions_ExactMatches,
text = description
});
}
else
{
listTolerant.Add(new DropdownOption
{
id = invoice.Identity.ToString(CultureInfo.InvariantCulture),
@group = Resources.Pages.Ledgers.BalanceTransactions_FivePercentMatches,
text = description
});
}
}
}
return result;
}
[WebMethod]
public static void BalanceTransactionManually(int transactionId, int accountId)
{
@@ -210,6 +210,33 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers {
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelDescribePayoutForeign;
/// <summary>
/// LabelRadioPaymentDirect 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 LabelRadioPaymentDirect;
/// <summary>
/// DropOpenOutboundInvoices control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Frontend.Controls.Base.DropDown DropOpenOutboundInvoices;
/// <summary>
/// Label2 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 Label2;
/// <summary>
/// LabelRadioExistingPayment control.
/// </summary>