Exemple #1
0
        public static Boolean addorupdateInvoiceFromUNMS(InvoiceReadOnly uinvoice)
        {
            ClientReadOnly uclient = getclientbyid(Convert.ToDouble(uinvoice.ClientId));

            string clientxeroid = "";

            foreach (ClientAttributeReadOnly ca in uclient.Attributes)
            {
                if (ca.name == "xeroIdclient")
                {
                    clientxeroid = ca.value;
                }
                ;
            }
            if (clientxeroid == "")
            {
                clientxeroid = XeroHelper.updateorcreatexerocontact(uclient, "");
            }

            string invoicexeroid = "";

            foreach (InvoiceAttributeReadOnly ca in uinvoice.Attributes)
            {
                if (ca.Name == "xeroIdinvoice")
                {
                    invoicexeroid = ca.Value;
                }
                ;
            }
            if (invoicexeroid == "")
            {
                XeroHelper.updateorcreatexeroinvoice(uinvoice, clientxeroid);
            }
            return(true);
        }
Exemple #2
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());
        }