Skip to content
This repository has been archived by the owner on Apr 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #398 from LukeKirbyDG/bugfix-batchpayments
Browse files Browse the repository at this point in the history
Changes to BatchPayment to avoid timezone Issue
  • Loading branch information
MJMortimer authored Apr 27, 2020
2 parents ac9ceba + 02f226b commit 89ac0c3
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CoreTests/CoreTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
<Compile Include="Integration\BankTransfers\BankTransfersTest.cs" />
<Compile Include="Integration\BankTransfers\Create.cs" />
<Compile Include="Integration\BankTransfers\Find.cs" />
<Compile Include="Integration\BatchPayment\Create.cs" />
<Compile Include="Integration\BatchPayment\BatchPaymentsTest.cs" />
<Compile Include="Integration\ContactGroups\Add_Contact.cs" />
<Compile Include="Integration\ContactGroups\ContactGroupsTest.cs" />
<Compile Include="Integration\ContactGroups\Create.cs" />
Expand Down
66 changes: 66 additions & 0 deletions CoreTests/Integration/BatchPayment/BatchPaymentsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Status;
using Xero.Api.Core.Model.Types;

namespace CoreTests.Integration.BatchPayments
{
public abstract class BatchPaymentsTest : ApiWrapperTest
{
protected BatchPayment Given_a_batch_payment(decimal invoiceAmount, DateTime date, decimal amount, bool isReconciled = false)
{
var batchPayment = CreateBatchPayment(invoiceAmount, date, amount, isReconciled);

return Api.BatchPayments.Create(batchPayment);
}

protected BatchPayment CreateBatchPayment(decimal invoiceAmount, DateTime date, decimal amount, bool isReconciled = false)
{
var invoice = Given_an_invoice(invoiceAmount, Account.Code);
var bankCode = BankAccount.Id;

var payment = new BatchPayment
{
Account = new Account { Id = bankCode },
Date = date,
Payments = new List<BatchPaymentPayment> { new BatchPaymentPayment {
Amount = amount,
Invoice = new Invoice { Id = invoice.Id},
BankAccountNumber = BankAccount.BankAccountNumber,
}}
};

if (isReconciled)
{
payment.IsReconciled = true;
}

return payment;
}

private Invoice Given_an_invoice(decimal amount = 100m, string accountCode = "100")
{
return Api.Create(new Invoice
{
Contact = new Contact { Name = "Richard" },
Number = Random.GetRandomString(10),
Type = InvoiceType.AccountsPayable,
Date = DateTime.UtcNow,
DueDate = DateTime.UtcNow.AddDays(90),
LineAmountTypes = LineAmountType.Inclusive,
Status = InvoiceStatus.Authorised,
LineItems = new List<LineItem>
{
new LineItem
{
AccountCode = accountCode,
Description = "Good value item",
LineAmount = amount
}
}
});
}

}
}
36 changes: 36 additions & 0 deletions CoreTests/Integration/BatchPayment/Create.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;

namespace CoreTests.Integration.BatchPayments
{
[TestFixture]
public class Create : BatchPaymentsTest
{
[TestFixtureSetUp]
public void CreateBatchPaymentsSetUp()
{
SetUp();
}

[Test]
public void create_simple_batch_payment()
{
var date = DateTime.UtcNow;
const decimal expectedTotal = 32.6m;
const decimal invoiceAmount = 100;

var batchPayment = Given_a_batch_payment(invoiceAmount, date, expectedTotal);

Assert.IsNotNull(batchPayment);

Assert.AreEqual(expectedTotal, batchPayment.Total);
Assert.AreEqual(date.Date, batchPayment.Date);


}

}
}
18 changes: 15 additions & 3 deletions Xero.Api/Core/Model/BatchPayment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Xero.Api.Common;
using Xero.Api.Core.Model.Status;
using Xero.Api.Core.Model.Types;
using Xero.Api.Infrastructure.ThirdParty.ServiceStack.Text.Common;

namespace Xero.Api.Core.Model
{
Expand Down Expand Up @@ -37,10 +38,21 @@ public class BatchPayment : HasUpdatedDate, IHasId
[DataMember(Name = "Narrative", EmitDefaultValue = false)]
public string Narrative { get; set; }

[DataMember(Name = "Date", EmitDefaultValue = false)]
public DateTime? Date { get; set; }
public DateTime? Date { get; set; }

[DataMember(Name = "Payments")]
[DataMember(Name = "Date", EmitDefaultValue = false)]
public string DateString {
get
{
return Date.Value.ToString("yyyy-MM-dd");
}
set
{
Date = DateTimeSerializer.ParseDateTimeOffset(value).UtcDateTime;
}
}

[DataMember(Name = "Payments")]
public List<BatchPaymentPayment> Payments { get; set; }

[DataMember(Name = "TotalAmount", EmitDefaultValue = false)]
Expand Down

0 comments on commit 89ac0c3

Please sign in to comment.