Exemplo n.º 1
0
 //Get invoice by ID
 public string GetInvoice(string invoiceId)
 {
     Invoice existedInvoice = new Invoice();
     // Guid newGuid = new Guid();
     existedInvoice = _api.Invoices.Find(new Guid(invoiceId));
     return existedInvoice.Id.ToString();
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
        //===================== Invoice Operation ================
        //Create Invoice for existed Contact
        public string InvoiceCreate(Invoice invoice,string contactId)
        {
            invoice.Contact = GetContactById(contactId);
            // Could get distince item codes from LineItems if the invoice has multi line items.
            foreach(LineItem item in invoice.LineItems)
            {
                string itemCode = item.ItemCode;

                if(!IsItemCodeExist(itemCode))
                {
                    ItemCreate(itemCode);
                }
            }
            return GenerateInvoiceId(invoice);
        }
        public InvoiceViewModel Convert(Invoice invoiceToConvert)
        {
            ContactToContactViewModelConverter contactConverter = new ContactToContactViewModelConverter();

            InvoiceViewModel invoiceViewModel = new InvoiceViewModel();
            invoiceViewModel.AccountCode = invoiceToConvert.Items.FirstOrDefault().AccountCode;
            invoiceViewModel.Description = invoiceToConvert.Items.FirstOrDefault().Description;
            invoiceViewModel.ItemCode = invoiceToConvert.Items.FirstOrDefault().ItemCode;
            invoiceViewModel.Quantity = invoiceToConvert.Items.FirstOrDefault().Quantity.GetValueOrDefault();
            if (invoiceToConvert.Items.FirstOrDefault().TaxType == "OUTPUT2")
            {
                invoiceViewModel.TaxType = "15% GST on Income";
            }
            else if (invoiceToConvert.Items.FirstOrDefault().TaxType == "NONE")
            {
                invoiceViewModel.TaxType = "No GST";
            }
            else if (invoiceToConvert.Items.FirstOrDefault().TaxType == "INPUT2")
            {
                invoiceViewModel.TaxType = "15% GST on Expenses";
            }
            else
            {
                invoiceViewModel.TaxType = "";
            }

            if (invoiceToConvert.Items.FirstOrDefault().Tracking.Count > 0)
            {
                invoiceViewModel.TrackingName = invoiceToConvert.Items.FirstOrDefault().Tracking.FirstOrDefault().Name;
                invoiceViewModel.TrackingOption = invoiceToConvert.Items.FirstOrDefault().Tracking.FirstOrDefault().Option;
            }

            invoiceViewModel.UnitAmount = invoiceToConvert.Items.FirstOrDefault().UnitAmount.GetValueOrDefault();
            invoiceViewModel.DiscountRate = invoiceToConvert.Items.FirstOrDefault().DiscountRate.GetValueOrDefault();
            invoiceViewModel.BrandingThemeId = invoiceToConvert.BrandingThemeId.ToString();
            invoiceViewModel.Contact = contactConverter.Convert(invoiceToConvert.Contact);
            invoiceViewModel.CurrencyCode = invoiceToConvert.CurrencyCode;
            invoiceViewModel.Date = invoiceToConvert.Date.GetValueOrDefault();
            invoiceViewModel.DueDate = invoiceToConvert.DueDate.GetValueOrDefault();
            invoiceViewModel.Number = invoiceToConvert.Number;
            invoiceViewModel.Reference = invoiceToConvert.Reference;

            return invoiceViewModel;
        }
        public void Given_approved_invoice_with_tracking_option(InvoiceType type = InvoiceType.AccountsPayable, InvoiceStatus status = InvoiceStatus.Draft)
        {
            Guid category = category1_.Id;
            string name = category1_.Name;
            string option = category1_.Options.FirstOrDefault().Name;

            var inv = Api.Create(new Invoice
            {
                Contact = new Contact { Name = "Wayne Enterprises" },
                Type = type,
                Date = DateTime.UtcNow,
                DueDate = DateTime.UtcNow.AddDays(90),
                LineAmountTypes = LineAmountType.Inclusive,
                Status = status,
                Items = new List<LineItem>
                {
                    new LineItem
                    {
                        AccountCode = "200",
                        Description = "Good value item",
                        LineAmount = 100m,
                        Tracking = new ItemTracking
                            {
                                new ItemTrackingCategory
                                {
                                    Id = category,
                                    Name = name,
                                    Option = option
                                }
                            }
                    }
                }

            });

            inv.Status = InvoiceStatus.Authorised;
            invoice_ = Api.Update(inv);
        }
Exemplo n.º 6
0
 public Invoice Update(Invoice item)
 {
     return Invoices.Update(item);
 }
Exemplo n.º 7
0
 public Invoice Create(Invoice item)
 {
     return Invoices.Create(item);
 }
Exemplo n.º 8
0
 public Task<Invoice> UpdateAsync(Invoice item)
 {
     return Invoices.UpdateAsync(item);
 }
Exemplo n.º 9
0
 public Task<Invoice> CreateAsync(Invoice item)
 {
     return Invoices.CreateAsync(item);
 }
Exemplo n.º 10
0
        // Generate Invoice Id
        private string GenerateInvoiceId(Invoice i)
        {
            Invoice result = new Invoice();

            try
            {
                result = _api.Create(i);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return result.Id.ToString();
        }
 /// <summary>
 /// Create a new invoice in the organization.
 /// </summary>
 /// <param name="newInvoice">First name.</param>
 /// <returns>A new employee with an unique ID.</returns>
 public Invoice SubmitAnInvoice(Invoice newInvoice)
 {
     return _api.Create(newInvoice);
 }
Exemplo n.º 12
0
        private void btnInvoice_Click(object sender, EventArgs e)
        {
            var invoiceTime = Stopwatch.StartNew();
            Invoice invoice = new Invoice();
            invoice.LineItems = new List<LineItem>();

            LineItem item = new LineItem();
            item.Quantity = Convert.ToDecimal(txtQuantity.Text);
            item.UnitAmount = Convert.ToDecimal(txtUnitAmount.Text);

            item.Description = txtInvoiceDescription.Text;
            item.AccountCode = "200";
            item.ItemCode =  txtItemCode.Text.Trim();
            invoice.LineItems.Add(item);
            txtPaidAmount.Text = (item.Quantity * item.UnitAmount).ToString();

            invoice.Date = DateTime.Now;
            invoice.DueDate = DateTime.Now.AddDays(3);
            invoice.Type = InvoiceType.AccountsReceivable;
            invoice.Status = InvoiceStatus.Authorised;
            invoice.LineAmountTypes = LineAmountType.Inclusive;

            XeroAPI xeroapi = new XeroAPI(api);
            string contactId = txtContactId.Text;

            lblInvoiceID.Text = xeroapi.InvoiceCreate(invoice, contactId);
            invoiceTime.Stop();
            lblInvoiceTime.Text = "Execute time: " + invoiceTime.Elapsed.TotalSeconds.ToString() + "s";
        }
        public Invoice convert(InvoiceViewModel invoiceViewModel)
        {
            ContactViewModelToContactConverter contactConverter = new ContactViewModelToContactConverter();
            Invoice invoice = new Invoice();
            if (!(string.IsNullOrEmpty(invoiceViewModel.BrandingThemeId)))
            {
                try
                {
                    invoice.BrandingThemeId = Guid.Parse(invoiceViewModel.BrandingThemeId);
                }
                catch (ArgumentNullException)
                {
                    throw new BrandingThemeIsNullException("Branding theme can not be empty");
                }
                catch (FormatException)
                {
                    throw new BrandingThemeIdIsNotVallid("Branding theme id is not a vallid branding theme id");
                }
            }
            invoice.Contact = contactConverter.Convert(invoiceViewModel.Contact);

            if(!(string.IsNullOrEmpty(invoiceViewModel.CurrencyCode)))
            {
                invoice.CurrencyCode = invoiceViewModel.CurrencyCode;
            }
            invoice.Date = invoiceViewModel.Date;
            invoice.DueDate = invoiceViewModel.DueDate;

            List<LineItem> lineItemList = new List<LineItem>();
            ItemTrackingCategory itemTrackingCategory = new ItemTrackingCategory();
            itemTrackingCategory.Name = invoiceViewModel.TrackingName;
            itemTrackingCategory.Option = invoiceViewModel.TrackingOption;

            ItemTracking itemTraking = new ItemTracking()
            {
               itemTrackingCategory
            };

            string taxType = null;

            if (invoiceViewModel.TaxType == "15% GST on Income")
            {
                taxType = "OUTPUT2";
            }

            if (invoiceViewModel.TaxType == "No GST")
            {
                taxType = "NONE";
            }

            if (invoiceViewModel.TaxType == "15% GST on Expenses")
            {
                taxType = "INPUT2";
            }

            LineItem lineItem = new LineItem();

            lineItem.Description = invoiceViewModel.Description;
            if (invoiceViewModel.DiscountRate > 0)
            {
                lineItem.DiscountRate = invoiceViewModel.DiscountRate;
            }
            //lineItem.ItemCode = invoiceViewModel.ItemCode;
            lineItem.ItemCode = "GB3-White";
            lineItem.Quantity = invoiceViewModel.Quantity;
            lineItem.TaxType = taxType;
            lineItem.Tracking = itemTraking;
            lineItem.UnitAmount = invoiceViewModel.UnitAmount;
            lineItem.AccountCode = invoiceViewModel.AccountCode;

            lineItemList.Add(lineItem);
            invoice.Items = lineItemList;
            invoice.Number = invoiceViewModel.Number;
            invoice.Reference = invoiceViewModel.Reference;
            invoice.Status = InvoiceStatus.Draft;
            if (invoiceViewModel.typeOfInvoice == "ACCPAY")
            {
                invoice.Type = InvoiceType.AccountsPayable;
            }

            if (invoiceViewModel.typeOfInvoice == "ACCREC")
            {
                invoice.Type = InvoiceType.AccountsReceivable;
            }

            if (invoiceViewModel.typeOfInvoice == "ACCREC")
            {
                invoice.Type = InvoiceType.AccountsReceivable;
                CreditNote cr = new CreditNote();

            }

            return invoice;
        }
Exemplo n.º 14
0
        protected void Given_a_zero_total_ACCREC_invoice_using_the_item_with_code(string code)
        {
            var invoice = new Invoice
            {
                Contact = new Contact { Name = "ABC Bank" },
                Type = InvoiceType.AccountsReceivable,
                Date = DateTime.UtcNow,
                DueDate = DateTime.UtcNow.AddDays(90),
                LineAmountTypes = LineAmountType.Inclusive,
                Status = InvoiceStatus.Authorised,
                LineItems = new List<LineItem>
                {
                    new LineItem
                    {
                        ItemCode = code,
                        AccountCode = RevenueAccountCode,
                        Quantity = 2
                    },
                    new LineItem
                    {
                        Description = "Inventory Adjustment",
                        AccountCode = DirectCostsAccountCode, //Using this account for the example. You would probably want to have your own inventory adjustments account
                        Quantity = 2,
                        UnitAmount = CreatedItem.PurchaseDetails.UnitPrice * -1
                    }
                }

            };

            CreatedAccrecInvoice = Api.Invoices.Create(invoice);
        }
Exemplo n.º 15
0
        protected void Given_an_ACCREC_invoice_using_the_item_with_code(string code)
        {
            var invoice = new Invoice
            {
                Contact = new Contact { Name = "ABC Bank" },
                Type = InvoiceType.AccountsReceivable,
                Date = DateTime.UtcNow,
                DueDate = DateTime.UtcNow.AddDays(90),
                LineAmountTypes = LineAmountType.Inclusive,
                Status = InvoiceStatus.Authorised,
                LineItems = new List<LineItem>
                {
                    new LineItem
                    {
                        ItemCode = code,
                        AccountCode = RevenueAccountCode,
                        Quantity = 2
                    }
                }
            };

            CreatedAccrecInvoice = Api.Invoices.Create(invoice);
        }
Exemplo n.º 16
0
        protected async Task Given_an_ACCPAY_invoice_using_the_item_with_code(string code)
        {
            var invoice = new Invoice
            {
                Contact = new Contact { Name = "ABC Bank" },
                Type = InvoiceType.AccountsPayable,
                Date = DateTime.UtcNow,
                DueDate = DateTime.UtcNow.AddDays(90),
                LineAmountTypes = LineAmountType.Inclusive,
                Status = InvoiceStatus.Authorised,
                LineItems = new List<LineItem>
                {
                    new LineItem
                    {
                        ItemCode = code,
                        AccountCode = InventoryAccountCode,
                        Quantity = 2
                    }
                }

            };

            CreatedAccpayInvoice = await Api.Invoices.CreateAsync(invoice);
        }