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

Commit 9952fb8

Browse files
authored
Merge pull request #327 from MJMortimer/cis-settings
Cis settings for contacts and orgs
2 parents 99bc60c + 155a773 commit 9952fb8

11 files changed

+101
-15
lines changed

Xero.Api/Core/Endpoints/ContactsEndpoint.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Xero.Api.Common;
1+
using System;
2+
using System.Linq;
3+
using Xero.Api.Common;
24
using Xero.Api.Core.Endpoints.Base;
35
using Xero.Api.Core.Model;
46
using Xero.Api.Core.Request;
@@ -12,6 +14,7 @@ public interface IContactsEndpoint
1214
IPageableEndpoint<IContactsEndpoint>
1315
{
1416
IContactsEndpoint IncludeArchived(bool include);
17+
ContactCisSetting GetCisSettings(Guid id);
1518
}
1619

1720
public class ContactsEndpoint
@@ -29,12 +32,6 @@ public IContactsEndpoint Page(int page)
2932
return this;
3033
}
3134

32-
public override void ClearQueryString()
33-
{
34-
base.ClearQueryString();
35-
Page(1);
36-
}
37-
3835
public IContactsEndpoint IncludeArchived(bool include)
3936
{
4037
if (include)
@@ -44,5 +41,17 @@ public IContactsEndpoint IncludeArchived(bool include)
4441

4542
return this;
4643
}
44+
45+
public ContactCisSetting GetCisSettings(Guid id)
46+
{
47+
var contactCisSettings = Client.Get<ContactCisSetting, ContactCisSettingsResponse>(string.Format("/api.xro/2.0/contacts/{0}/cissettings", id));
48+
return contactCisSettings.FirstOrDefault();
49+
}
50+
51+
public override void ClearQueryString()
52+
{
53+
base.ClearQueryString();
54+
Page(1);
55+
}
4756
}
4857
}

Xero.Api/Core/Endpoints/OrganisationEndpoint.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Xero.Api.Common;
1+
using System;
2+
using System.Linq;
3+
using Xero.Api.Common;
24
using Xero.Api.Core.Model;
35
using Xero.Api.Core.Response;
46
using Xero.Api.Infrastructure.Http;
@@ -7,6 +9,7 @@ namespace Xero.Api.Core.Endpoints
79
{
810
public interface IOrganisationEndpoint : IXeroReadEndpoint<OrganisationEndpoint, Organisation, OrganisationResponse>
911
{
12+
OrganisationCisSetting GetCisSettings(Guid id);
1013
}
1114

1215
public class OrganisationEndpoint : XeroReadEndpoint<OrganisationEndpoint, Organisation, OrganisationResponse>, IOrganisationEndpoint
@@ -15,5 +18,12 @@ internal OrganisationEndpoint(XeroHttpClient client)
1518
: base(client, "/api.xro/2.0/Organisation")
1619
{
1720
}
21+
22+
public OrganisationCisSetting GetCisSettings(Guid id)
23+
{
24+
var organisationCisSettings = Client.Get<OrganisationCisSetting, OrganisationCisSettingsResponse>(string.Format("/api.xro/2.0/organisations/{0}/cissettings", id));
25+
26+
return organisationCisSettings.FirstOrDefault();
27+
}
1828
}
1929
}

Xero.Api/Core/IXeroCoreApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public interface IXeroCoreApi
3030
IJournalsEndpoint Journals { get; }
3131
ILinkedTransactionsEndpoint LinkedTransactions { get; }
3232
IManualJournalsEndpoint ManualJournals { get; }
33+
IOrganisationEndpoint Organisations { get; }
3334
IOverpaymentsEndpoint Overpayments { get; }
3435
IPaymentsEndpoint Payments { get; }
3536
PdfEndpoint PdfFiles { get; }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Xero.Api.Core.Model
4+
{
5+
public class ContactCisSetting
6+
{
7+
[DataMember(Name = "CISEnabled")]
8+
public bool CisEnabled { get; set; }
9+
10+
[DataMember]
11+
public decimal Rate { get; set; }
12+
}
13+
}

Xero.Api/Core/Model/CreditNote.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,8 @@ public class CreditNote : HasUpdatedDate, IHasId, IHasAttachment
7878

7979
[DataMember(EmitDefaultValue = false)]
8080
public List<Payment> Payments { get; set; }
81+
82+
[DataMember(EmitDefaultValue = false, Name = "CISDeduction")]
83+
public decimal? CisDeduction { get; set; }
8184
}
8285
}

Xero.Api/Core/Model/Invoice.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ public List<LineItem> Items
104104
[DataMember(EmitDefaultValue = false)]
105105
public List<Overpayment> Overpayments { get; set; }
106106

107-
[DataMember(EmitDefaultValue = false)]
108-
public List<Payment> Payments { get; set; }
109-
107+
[DataMember(EmitDefaultValue = false)]
108+
public List<Payment> Payments { get; set; }
109+
110+
[DataMember(EmitDefaultValue = false, Name = "CISDeduction")]
111+
public decimal? CisDeduction { get; set; }
110112
}
111113
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Xero.Api.Core.Model
4+
{
5+
public class OrganisationCisSetting
6+
{
7+
[DataMember(Name = "CISContractorEnabled")]
8+
public bool CisContractorEnabled { get; set; }
9+
10+
[DataMember(Name = "CISSubContractorEnabled")]
11+
public bool CisSubContractorEnabled { get; set; }
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
using Xero.Api.Common;
3+
using Xero.Api.Core.Model;
4+
5+
namespace Xero.Api.Core.Response
6+
{
7+
public class ContactCisSettingsResponse : XeroResponse<ContactCisSetting>
8+
{
9+
public List<ContactCisSetting> ContactCisSettings { get; set; }
10+
11+
public override IList<ContactCisSetting> Values
12+
{
13+
get { return ContactCisSettings; }
14+
}
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
using Xero.Api.Common;
3+
using Xero.Api.Core.Model;
4+
5+
namespace Xero.Api.Core.Response
6+
{
7+
public class OrganisationCisSettingsResponse : XeroResponse<OrganisationCisSetting>
8+
{
9+
public List<OrganisationCisSetting> OrganisationCisSettings { get; set; }
10+
11+
public override IList<OrganisationCisSetting> Values
12+
{
13+
get { return OrganisationCisSettings; }
14+
}
15+
}
16+
}

Xero.Api/Core/XeroCoreApi.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ namespace Xero.Api.Core
1313
{
1414
public class XeroCoreApi : XeroApi, IXeroCoreApi
1515
{
16-
private IOrganisationEndpoint OrganisationEndpoint { get; set; }
17-
1816
public XeroCoreApi(string baseUri, IAuthenticator auth, IConsumer consumer, IUser user,
1917
IJsonObjectMapper readMapper, IXmlObjectMapper writeMapper)
2018
: this(baseUri, auth, consumer, user, readMapper, writeMapper, null)
@@ -59,6 +57,7 @@ public XeroCoreApi(string baseUri, IAuthenticator auth, IConsumer consumer, IUse
5957
public IJournalsEndpoint Journals { get; protected set; }
6058
public ILinkedTransactionsEndpoint LinkedTransactions { get; private set; }
6159
public IManualJournalsEndpoint ManualJournals { get; private set; }
60+
public IOrganisationEndpoint Organisations { get; private set; }
6261
public IOverpaymentsEndpoint Overpayments { get; private set; }
6362
public IPaymentsEndpoint Payments { get; private set; }
6463
public PdfEndpoint PdfFiles { get; private set; }
@@ -75,7 +74,7 @@ public XeroCoreApi(string baseUri, IAuthenticator auth, IConsumer consumer, IUse
7574

7675
private void Connect()
7776
{
78-
OrganisationEndpoint = new OrganisationEndpoint(Client);
77+
Organisations = new OrganisationEndpoint(Client);
7978

8079
Accounts = new AccountsEndpoint(Client);
8180
Allocations = new AllocationsEndpoint(Client);
@@ -117,7 +116,7 @@ public Organisation Organisation
117116
{
118117
get
119118
{
120-
return OrganisationEndpoint.Find().FirstOrDefault();
119+
return Organisations.Find().FirstOrDefault();
121120
}
122121
}
123122

Xero.Api/Xero.Api.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="Core\Endpoints\HistoryAndNotesEndpoint.cs" />
6161
<Compile Include="Core\Endpoints\InboxEndpoint.cs" />
6262
<Compile Include="Core\Endpoints\LinkedTransactionsEndpoint.cs" />
63+
<Compile Include="Core\Model\ContactCisSetting.cs" />
6364
<Compile Include="Core\Model\EnumExtensions.cs" />
6465
<Compile Include="Core\Model\HistoryRecord.cs" />
6566
<Compile Include="Core\Model\OnlineInvoice.cs" />
@@ -68,6 +69,7 @@
6869
<Compile Include="Core\Model\Association.cs" />
6970
<Compile Include="Core\Model\ContactTrackingCategory.cs" />
7071
<Compile Include="Core\Model\LinkedTransaction.cs" />
72+
<Compile Include="Core\Model\OrganisationCisSetting.cs" />
7173
<Compile Include="Core\Model\PurchaseOrder.cs" />
7274
<Compile Include="Core\Model\Status\LinkedTransactionStatus.cs" />
7375
<Compile Include="Core\Model\Status\PurchaseOrderStatus.cs" />
@@ -99,9 +101,11 @@
99101
<Compile Include="Core\Model\Types\OverpaymentType.cs" />
100102
<Compile Include="Common\CoreData.cs" />
101103
<Compile Include="Core\Model\Status\ValidationStatus.cs" />
104+
<Compile Include="Core\Response\ContactCisSettingsResponse.cs" />
102105
<Compile Include="Core\Response\HistoryRecordsResponse.cs" />
103106
<Compile Include="Core\Response\LinkedTransactionsResponse.cs" />
104107
<Compile Include="Core\Response\OnlineInvoicesResponse.cs" />
108+
<Compile Include="Core\Response\OrganisationCisSettingsResponse.cs" />
105109
<Compile Include="Core\Response\OverpaymentsResponse.cs" />
106110
<Compile Include="Core\Response\PrepaymentsResponse.cs" />
107111
<Compile Include="Core\Model\Prepayment.cs" />

0 commit comments

Comments
 (0)