diff --git a/Logic/Financial/VatReport.cs b/Logic/Financial/VatReport.cs index 0d441a8f..4c57a19a 100644 --- a/Logic/Financial/VatReport.cs +++ b/Logic/Financial/VatReport.cs @@ -107,6 +107,11 @@ namespace Swarmops.Logic.Financial } vatReportTransaction.Dependency = newReport; + newReport.OpenTransaction = vatReportTransaction; + } + else + { + newReport.Open = false; // nothing to close, no tx created } return newReport; @@ -243,7 +248,10 @@ namespace Swarmops.Logic.Financial public new int OpenTransactionId { - get { return base.OpenTransactionId; } + get + { + return base.OpenTransactionId; + } set { SwarmDb.GetDatabaseForWriting().SetVatReportOpenTransaction(this.Identity, value); @@ -253,7 +261,11 @@ namespace Swarmops.Logic.Financial public FinancialTransaction OpenTransaction { - get { return FinancialTransaction.FromIdentity(OpenTransactionId); } + get + { + if (base.OpenTransactionId == 0) return null; + return FinancialTransaction.FromIdentity(OpenTransactionId); + } set { this.OpenTransactionId = value.Identity; } } @@ -269,8 +281,33 @@ namespace Swarmops.Logic.Financial public FinancialTransaction CloseTransaction { - get { return FinancialTransaction.FromIdentity(CloseTransactionId); } - set { this.CloseTransactionId = value.Identity; } + get + { + if (base.CloseTransactionId == 0) return null; + return FinancialTransaction.FromIdentity(CloseTransactionId); + } + set + { + if (value != null) + { + this.CloseTransactionId = value.Identity; + this.Open = false; + } + else + { + throw new ArgumentNullException(); // is this a valid case? + } + } + } + + public new bool Open + { + get { return base.Open; } + set + { + SwarmDb.GetDatabaseForWriting().SetVatReportOpen(this.Identity, value); + base.Open = value; + } } } diff --git a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx index 3cc7fbba..b7c7fbcf 100644 --- a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx +++ b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx @@ -70,9 +70,11 @@ if (data.OpenOutboundInvoiceData != null) { if (data.OpenOutboundInvoiceData.ExactMatches.length > 0) { + $('#divOutboundInvoice').show(); <%=this.DropOpenOutboundInvoices.ClientID%>_loadData(data.OpenOutboundInvoiceData.ExactMatches); <%=this.DropOpenOutboundInvoices.ClientID%>_text("<%=Resources.Global.Global_SelectOne%>"); } else { + $('#divOutboundInvoice').hide(); <%=this.DropOpenOutboundInvoices.ClientID%>_loadData({}); <%=this.DropOpenOutboundInvoices.ClientID%>_text("<%=Resources.Global.Global_NoMatch%>"); } @@ -179,7 +181,7 @@ } - function onMatchVatReport() { + function onMatchOpenVatReport() { var vatReportId = <%=this.DropOpenVatReports.ClientID%>_val(); if (vatReportId > 0) { @@ -232,7 +234,7 @@ idField="id"> - + @@ -248,7 +250,6 @@

-

@@ -284,17 +285,20 @@
-

-
-
- ​
- -
- +

​
diff --git a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.cs b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.cs index 00642598..47ad6a7e 100644 --- a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.cs +++ b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.cs @@ -458,7 +458,53 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers [WebMethod] public static void MatchTransactionOpenVatReport(int transactionId, int vatReportId) { - + if (transactionId == 0 || vatReportId == 0) + { + return; + } + + AuthenticationData authData = GetAuthenticationDataAndCulture(); + + if ( + !authData.Authority.HasAccess(new Access(authData.CurrentOrganization, + AccessAspect.BookkeepingDetails))) + { + throw new UnauthorizedAccessException(); + } + + FinancialTransaction transaction = FinancialTransaction.FromIdentity(transactionId); + VatReport vatReport = VatReport.FromIdentity(vatReportId); + + if (authData.CurrentOrganization.Identity != transaction.OrganizationId + || authData.CurrentOrganization.Identity != vatReport.OrganizationId) + { + throw new InvalidOperationException("Organization mismatch"); + } + + Int64 diffCents = vatReport.VatInboundCents - vatReport.VatOutboundCents; + + if (transaction.Rows.AmountCentsTotal != diffCents) + { + throw new InvalidOperationException("Amount mismatch"); + } + + // Go ahead and close + + vatReport.CloseTransaction = transaction; // throws if already closed + vatReport.Open = false; + + if (diffCents > 0) + { + // Positive amount - asset account + transaction.AddRow(authData.CurrentOrganization.FinancialAccounts.AssetsVatInboundReported, -diffCents, + null); + } + else + { + // Negative amount - liability account + transaction.AddRow(authData.CurrentOrganization.FinancialAccounts.DebtsVatOutboundReported, -diffCents, + null); + } } diff --git a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.designer.cs b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.designer.cs index bbafa3c6..b1d107fc 100644 --- a/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.designer.cs +++ b/Site/Pages/v5/Ledgers/BalanceTransactions.aspx.designer.cs @@ -102,15 +102,6 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers { /// protected global::System.Web.UI.WebControls.Literal LabelDoYouWishTo; - /// - /// LabelRadioBalance control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Label LabelRadioBalance; - /// /// LabelRadioVatReport control. /// @@ -219,6 +210,15 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers { /// protected global::System.Web.UI.WebControls.Label LabelDescribeOutboundInvoice; + /// + /// LabelRadioBalance control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label LabelRadioBalance; + /// /// DropBudgetBalance control. ///