示例#1
0
        //this Method Update XERO Invoice Status given by Guid
        public XeroApi.Model.Invoice UpdtateInvoice(Repository repos, String strGuid, String[] arrOrderItems, int PaymentTerms, Decimal deDeliveryCharges, String PROMO)
        {
            if (repos == null)
            {
                return(null);
            }

            String[] arrLineItem;

            //create Line Itmes
            XeroApi.Model.LineItems LItems = new LineItems();

            //Xero Model LineItem
            XeroApi.Model.LineItem lItem;

            /*Invoice Line Items Creation*/
            #region Invoice LineItems
            for (int i = 0; i < arrOrderItems.Length; i++)
            {
                if (!String.IsNullOrEmpty(arrOrderItems[i]))
                {
                    arrLineItem = arrOrderItems[i].Split(',');
                    if (i == 0)
                    {
                        lItem = new XeroApi.Model.LineItem {
                            Description = arrLineItem[1], ItemCode = arrLineItem[2], UnitAmount = Convert.ToDecimal(arrLineItem[5]), Quantity = Int32.Parse(arrLineItem[4]), TaxType = "OUTPUT"
                        };
                        lItem.AccountCode = "200";
                        LItems.Add(lItem);
                    }
                    if (i != 0)
                    {
                        lItem = new XeroApi.Model.LineItem {
                            Description = arrLineItem[2], ItemCode = arrLineItem[3], UnitAmount = Convert.ToDecimal(arrLineItem[6]), Quantity = Int32.Parse(arrLineItem[5]), TaxType = "OUTPUT"
                        };
                        lItem.AccountCode = "200";
                        LItems.Add(lItem);
                    }
                }
            }
            //Delivery Handling item Adding here
            lItem = new XeroApi.Model.LineItem {
                Description = "Delivery & Handling, D & H", UnitAmount = Convert.ToDecimal(deDeliveryCharges)
            };
            lItem.AccountCode = "200";
            LItems.Add(lItem);
            #endregion
            /*End Invoice Line Items Creation*/


            #region Promotional Item Creation

            if (!String.IsNullOrEmpty(PROMO))
            {
                String[] ProItems = PROMO.Split('|');
                String[] ProItem;
                for (int i = 0; i < ProItems.Length; i++)
                {
                    if (!String.IsNullOrEmpty(ProItems[i]))
                    {
                        ProItem = ProItems[i].Split(',');
                        if (i == 0)
                        {
                            float   ShippingCost;
                            decimal amount = 0;

                            //Add a line for promotional Item
                            lItem = new XeroApi.Model.LineItem {
                                Description = ProItem[0].ToString(), UnitAmount = Convert.ToDecimal(amount), Quantity = Int32.Parse(ProItem[2])
                            };
                            lItem.AccountCode = "200";
                            LItems.Add(lItem);
                        }
                        if (i != 0)
                        {
                            float   ShipCost;
                            decimal amount = 0;

                            //Add a line for promotional Item
                            lItem = new XeroApi.Model.LineItem {
                                Description = ProItem[1].ToString(), UnitAmount = Convert.ToDecimal(amount), Quantity = Int32.Parse(ProItem[3])
                            };
                            lItem.AccountCode = "200";
                            LItems.Add(lItem);
                        }
                    }
                }
            }


            #endregion Promotional Item Creation


            XeroApi.Model.Invoice deltoneInvoice = new XeroApi.Model.Invoice
            {
                Type            = "ACCREC",
                InvoiceID       = new Guid(strGuid),
                LineItems       = LItems,
                LineAmountTypes = XeroApi.Model.LineAmountType.Inclusive,
                Status          = "AUTHORISED"
            };

            var updatedInvoice = repos.UpdateOrCreate(deltoneInvoice);

            if (updatedInvoice.ValidationStatus == XeroApi.Model.ValidationStatus.ERROR)
            {
                foreach (var message in updatedInvoice.ValidationErrors)
                {
                    Console.WriteLine("Validation Error: " + message.Message);
                }
                return(null);
            }
            return((XeroApi.Model.Invoice)updatedInvoice);
        }
示例#2
0
        //This Function Create a New Invoice in the Xero System Given by Details //Add Invoice Representator  Modified Sumudu Kodikara 1/52015
        public XeroApi.Model.Invoice CreateInvoice(Repository repository, String strContactName, String[] arrOrderItems, int PaymentTerms, Decimal deDeliveryCharges, String PROMO)
        {
            if (repository == null)
            {
                //User Must Authenticate and trow an Error
                return(null);
            }

            String[] arrLineItem;

            //create Line Itmes
            XeroApi.Model.LineItems LItems = new LineItems();

            //Xero Model LineItem
            XeroApi.Model.LineItem lItem;

            /*Invoice Line Items Creation*/
            #region Invoice LineItems
            for (int i = 0; i < arrOrderItems.Length; i++)
            {
                if (!String.IsNullOrEmpty(arrOrderItems[i]))
                {
                    arrLineItem = arrOrderItems[i].Split(',');
                    if (i == 0)
                    {
                        lItem = new XeroApi.Model.LineItem {
                            Description = arrLineItem[1], ItemCode = arrLineItem[2], UnitAmount = Convert.ToDecimal(arrLineItem[5]), Quantity = Int32.Parse(arrLineItem[4]), TaxType = "OUTPUT"
                        };
                        lItem.AccountCode = "200";
                        LItems.Add(lItem);
                    }
                    if (i != 0)
                    {
                        lItem = new XeroApi.Model.LineItem {
                            Description = arrLineItem[2], ItemCode = arrLineItem[3], UnitAmount = Convert.ToDecimal(arrLineItem[6]), Quantity = Int32.Parse(arrLineItem[5]), TaxType = "OUTPUT"
                        };
                        lItem.AccountCode = "200";
                        LItems.Add(lItem);
                    }
                }
            }
            //Delivery Handling item Adding here
            lItem = new XeroApi.Model.LineItem {
                Description = "Delivery & Handling, D & H", UnitAmount = Convert.ToDecimal(deDeliveryCharges)
            };
            lItem.AccountCode = "200";
            LItems.Add(lItem);
            #endregion


            #region Promotional Items Creation

            if (!String.IsNullOrEmpty(PROMO))
            {
                String[] ProItems = PROMO.Split('|');
                String[] ProItem;
                for (int i = 0; i < ProItems.Length; i++)
                {
                    if (!String.IsNullOrEmpty(ProItems[i]))
                    {
                        ProItem = ProItems[i].Split(',');
                        if (i == 0)
                        {
                            float   ShippingCost;
                            decimal amount = 0;

                            //Add a line for promotional Item
                            lItem = new XeroApi.Model.LineItem {
                                Description = ProItem[0].ToString(), UnitAmount = Convert.ToDecimal(amount), Quantity = Int32.Parse(ProItem[2])
                            };
                            lItem.AccountCode = "200";
                            LItems.Add(lItem);
                        }
                        if (i != 0)
                        {
                            float   ShipCost;
                            decimal amount = 0;

                            //Add a line for promotional Item
                            lItem = new XeroApi.Model.LineItem {
                                Description = ProItem[1].ToString(), UnitAmount = Convert.ToDecimal(amount), Quantity = Int32.Parse(ProItem[3])
                            };
                            lItem.AccountCode = "200";
                            LItems.Add(lItem);
                        }
                    }
                }
            }

            #endregion Promotional Items Creation

            /*End Invoice Line Items Creation*/

            XeroApi.Model.Invoice deltoneInvoice = new XeroApi.Model.Invoice
            {
                Type    = "ACCREC",
                Contact = new XeroApi.Model.Contact {
                    Name = strContactName
                },
                Date            = DateTime.Today,
                DueDate         = DateTime.Today.AddDays(PaymentTerms),
                Status          = "DRAFT",
                LineItems       = LItems,
                LineAmountTypes = XeroApi.Model.LineAmountType.Inclusive
            };


            var createdInvoice = repository.Create(deltoneInvoice);

            //Check wether Validation Errors Exsists or Not
            if (createdInvoice.ValidationStatus == XeroApi.Model.ValidationStatus.ERROR)
            {
                foreach (var message in createdInvoice.ValidationErrors)
                {
                    Console.WriteLine("Validation Error: " + message.Message);
                }
                return(null);
            }

            return((XeroApi.Model.Invoice)createdInvoice);
        }