public static Boolean addPaymentFromXero(Xero.Api.Core.Model.Invoice xinvoice) { if ((xinvoice.Type == Xero.Api.Core.Model.Types.InvoiceType.AccountsReceivable) && (xinvoice.Reference != "from Unms")) { // check if invoice matches contact int ucrmclientid = UNMSHelper.getclientbyxeroid(xinvoice.Contact.Id.ToString()); if (ucrmclientid != 0) { // only move payments currently if (xinvoice.Payments != null) { foreach (Xero.Api.Core.Model.Payment Xpay in xinvoice.Payments) { if (Xpay.Reference != "from Unms") { Models.UnmsPaymentAdd Upay = new Models.UnmsPaymentAdd(); Upay.amount = Convert.ToDouble(Xpay.Amount); Upay.clientId = ucrmclientid; Upay.createdDate = string.Format("{0:s}", Xpay.Date) + "+0000"; Upay.note = "from Xero"; Upay.userId = 1924; var uc = HTTPHelper.httpPost("payments", Upay); } } } } } return(true); }
public static Boolean addorupdateClientFromXero(Contact xcontact) { // is the xero id already present int ucrmclientid = UNMSHelper.getclientbyxeroid(xcontact.Id.ToString()); webapi.Models.ClientContactWritable newunmscontact; List <webapi.Models.ClientContactWritable> newlistcontacts = new List <webapi.Models.ClientContactWritable>(); if ((xcontact.EmailAddress != "") || (xcontact.Phones.Any(_ => _.PhoneNumber != ""))) { newunmscontact = new webapi.Models.ClientContactWritable() { Phone = xcontact.Phones.First().PhoneAreaCode + xcontact.Phones.First().PhoneNumber, Email = xcontact.EmailAddress, IsBilling = true, IsContact = true }; newlistcontacts.Add(newunmscontact); } if (xcontact.Phones.Any(_ => _.PhoneNumber != "")) { newunmscontact = new ClientContactWritable() { Phone = xcontact.Phones[3].PhoneAreaCode + xcontact.Phones[3].PhoneNumber }; newlistcontacts.Add(newunmscontact); } var newUcrmAttribute = new ClientAttribute() { CustomAttributeId = 1, Value = xcontact.Id.ToString() }; List <ClientAttribute> newlistattributes = new List <ClientAttribute>(); newlistattributes.Add(newUcrmAttribute); string templastname; string tempfirstname; bool tempLead = false; if (xcontact.IsCustomer == false) { tempLead = true; } if ((xcontact.FirstName == null) && (xcontact.LastName == null)) { tempfirstname = null; templastname = xcontact.Name; } else { tempfirstname = xcontact.FirstName; templastname = xcontact.LastName; } var newunmsclient = new ClientWritable() { OrganizationId = 1, IsLead = tempLead, FirstName = tempfirstname, LastName = templastname, UserIdent = "", Street1 = xcontact.Addresses[1].AddressLine1, Street2 = xcontact.Addresses[1].AddressLine2, City = xcontact.Addresses[1].City, ZipCode = xcontact.Addresses[1].PostalCode, Attributes = newlistattributes, Contacts = newlistcontacts, InvoiceAddressSameAsContact = true, Username = xcontact.EmailAddress, InvoiceMaturityDays = null, RegistrationDate = "2019-09-01T00:00:00+0100" }; if (ucrmclientid == 0) { var uc = HTTPHelper.httpPost("clients", newunmsclient); } else { var uc = HTTPHelper.httpPatch("clients/" + ucrmclientid, newunmsclient); } return(true); }