Esempio n. 1
0
 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);
 }
Esempio n. 2
0
        public static bool updateorcreatexeropayment(PaymentReadOnly Upayment, string clientxeroid)
        {
            XeroCoreApi xeroapp = getxeroapp();

            Xero.Api.Core.Model.Payment Xpayment = new Xero.Api.Core.Model.Payment();
            Xpayment.Amount    = Convert.ToDecimal(Upayment.Amount);
            Xpayment.Date      = Convert.ToDateTime(Upayment.CreatedDate);
            Xpayment.Status    = Xero.Api.Core.Model.Status.PaymentStatus.Authorised;
            Xpayment.Type      = Xero.Api.Core.Model.Types.PaymentType.AccountsReceivable;
            Xpayment.Account   = xeroapp.Accounts.Where("Name==\"Stripe Payment Account\"").Find().First();
            Xpayment.Reference = "from Unms";
            foreach (PaymentCoverReadOnly pc in Upayment.PaymentCovers)
            {
                string invnumber = UNMSHelper.getinvoicenumberbyid(Convert.ToDouble(pc.InvoiceId));
                Xpayment.Invoice = xeroapp.Invoices.Where("InvoiceNumber=\"" + invnumber + "\"").Find().FirstOrDefault();
            }
            Xero.Api.Core.Model.Payment Xpaymentreturned = xeroapp.Update(Xpayment);
            return(true);
        }
Esempio n. 3
0
        public static string updateorcreatexeroinvoice(InvoiceReadOnly Uinvoice, string clientxeroid)
        {
            XeroCoreApi xeroapp = getxeroapp();

            Xero.Api.Core.Model.Invoice Xinvoice = new Xero.Api.Core.Model.Invoice();
            Xinvoice.Number = Uinvoice.Number;
            Xero.Api.Core.Model.Contact Xcontact = xeroapp.Contacts.Find(new Guid(clientxeroid));
            Xinvoice.Contact         = Xcontact;
            Xinvoice.Date            = Convert.ToDateTime(Uinvoice.CreatedDate);
            Xinvoice.Type            = Xero.Api.Core.Model.Types.InvoiceType.AccountsReceivable;
            Xinvoice.LineAmountTypes = Xero.Api.Core.Model.Types.LineAmountType.Inclusive;
            Xinvoice.Status          = Xero.Api.Core.Model.Status.InvoiceStatus.Authorised;
            Xinvoice.DueDate         = Convert.ToDateTime(Uinvoice.DueDate);
            List <LineItem> Xiilist = new List <LineItem>();

            foreach (InvoiceItemReadOnly uii in Uinvoice.Items)
            {
                Xero.Api.Core.Model.LineItem xii = new Xero.Api.Core.Model.LineItem();
                xii.Quantity    = Convert.ToDecimal(uii.Quantity);
                xii.Description = uii.Label;
                xii.UnitAmount  = Convert.ToDecimal(uii.Price);
                xii.LineAmount  = Convert.ToDecimal(uii.Total);
                xii.AccountCode = "200";
                Xiilist.Add(xii);
            }
            Xinvoice.LineItems = Xiilist;
            Xero.Api.Core.Model.Invoice Xinvoicereturned = xeroapp.Update(Xinvoice);

            UnmsInvoice      UXinvoice        = new UnmsInvoice();
            InvoiceAttribute newUcrmAttribute = new InvoiceAttribute()
            {
                CustomAttributeId = UNMSHelper.getcustomattributeid("xeroIdinvoice"),
                Value             = Xinvoicereturned.Id.ToString()
            };
            List <InvoiceAttribute> newlistattributes = new List <InvoiceAttribute>();

            newlistattributes.Add(newUcrmAttribute);
            UXinvoice.attributes = newlistattributes;

            HTTPHelper.httpPatch("invoices" + "/" + Uinvoice.Id, UXinvoice);
            return(Xinvoice.Id.ToString());
        }
Esempio n. 4
0
        public static bool importxerocontact()
        {
            XeroCoreApi xeroapp = getxeroapp();
            int         z       = 0;

            while ((z <= 50))
            {
                List <Contact> contacts = xeroapp.Contacts.Page(z).Where("IsCustomer=true").Find().ToList();
                if (contacts.Count == 0)
                {
                    break;
                }
                foreach (Contact contact in contacts)

                {
                    UNMSHelper.addorupdateClientFromXero(contact);
                }
                z = z + 1;
            }
            return(true);
        }
Esempio n. 5
0
        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);
        }