private Xero.Api.Core.Model.CreditNote CreateCreditNote(CreditNote CreditNote) { Xero.Api.Core.Model.CreditNote xeroCreditNote = new Xero.Api.Core.Model.CreditNote { Number = CreditNote.No, Date = CreditNote.TransactionDate, Type = Xero.Api.Core.Model.Types.CreditNoteType.AccountsPayable, Status = Xero.Api.Core.Model.Status.InvoiceStatus.Authorised, Reference = CreditNote.ReferenceNumber, CurrencyCode = CreditNote.Currency.Value, SubTotal = (decimal)CreditNote.SubTotalExcl, TotalTax = (decimal)CreditNote.VATTotal, Total = (decimal)CreditNote.TotalIncl, Contact = XeroFunctions.CoreApi().Contacts.Find(CreditNote.Vendor.AccountingPartnerIdentifier) }; CreditNote.AccountingPartnerIdentifier = xeroCreditNote.Id.ToString(); if (xeroCreditNote.Contact == null) { xeroCreditNote.Contact = new Xero.Api.Core.Model.Contact() { Name = CreditNote.Vendor.FullName, IsCustomer = true, FirstName = CreditNote.Vendor.FirstName, LastName = CreditNote.Vendor.LastName, TaxNumber = CreditNote.Vendor.VATNo, EmailAddress = CreditNote.Vendor.Email, ContactNumber = CreditNote.Vendor.CellNo, AccountNumber = CreditNote.Vendor.ExternalAccountsCode }; CreditNote.Vendor.AccountingPartnerIdentifier = xeroCreditNote.Contact.Id.ToString(); } foreach (WorkflowItem workflowItem in CreditNote.Items) { if (xeroCreditNote.LineItems == null) { xeroCreditNote.LineItems = new List <Xero.Api.Core.Model.LineItem>(); } Xero.Api.Core.Model.LineItem lineItem = new Xero.Api.Core.Model.LineItem() { Description = workflowItem.Description, Quantity = (decimal)workflowItem.Quantity, UnitAmount = (decimal)workflowItem.SellingPrice, TaxAmount = (decimal)workflowItem.VATTotal, LineAmount = (decimal)workflowItem.TotalIncl }; xeroCreditNote.LineItems.Add(lineItem); workflowItem.AccountingPartnerIdentifier = lineItem.LineItemId.ToString(); } return(xeroCreditNote); }
private Xero.Api.Core.Model.Invoice CreateInvoice(Invoice Invoice) { Xero.Api.Core.Model.Invoice xeroInvoice = new Xero.Api.Core.Model.Invoice { Number = Invoice.No, Date = Invoice.TransactionDate, Type = Xero.Api.Core.Model.Types.InvoiceType.AccountsReceivable, Status = Xero.Api.Core.Model.Status.InvoiceStatus.Authorised, Reference = Invoice.ReferenceNumber, CurrencyCode = Invoice.Currency.Value, SubTotal = (decimal)Invoice.SubTotalExcl, TotalTax = (decimal)Invoice.VATTotal, Total = (decimal)Invoice.TotalIncl, AmountPaid = (decimal)Invoice.PaymentTotal, AmountDue = (decimal)Invoice.AmountOutstanding, AmountCredited = (decimal)Invoice.CreditTotal, Contact = XeroFunctions.CoreApi().Contacts.Find(Invoice.Vendor.AccountingPartnerIdentifier) }; Invoice.AccountingPartnerIdentifier = xeroInvoice.Id.ToString(); if (xeroInvoice.Contact == null) { xeroInvoice.Contact = new Xero.Api.Core.Model.Contact() { Name = Invoice.Vendor.FullName, IsCustomer = true, FirstName = Invoice.Vendor.FirstName, LastName = Invoice.Vendor.LastName, TaxNumber = Invoice.Vendor.VATNo, EmailAddress = Invoice.Vendor.Email, ContactNumber = Invoice.Vendor.CellNo, AccountNumber = Invoice.Vendor.ExternalAccountsCode }; Invoice.Vendor.AccountingPartnerIdentifier = xeroInvoice.Contact.Id.ToString(); } foreach (WorkflowItem workflowItem in Invoice.Items) { if (xeroInvoice.LineItems == null) { xeroInvoice.LineItems = new List <Xero.Api.Core.Model.LineItem>(); } Xero.Api.Core.Model.LineItem lineItem = new Xero.Api.Core.Model.LineItem() { Description = workflowItem.Description, Quantity = (decimal)workflowItem.Quantity, UnitAmount = (decimal)workflowItem.SellingPrice, TaxAmount = (decimal)workflowItem.VATTotal, LineAmount = (decimal)workflowItem.TotalIncl }; xeroInvoice.LineItems.Add(lineItem); workflowItem.AccountingPartnerIdentifier = lineItem.LineItemId.ToString(); } foreach (WorkFlowPayment workFlowPayment in Invoice.Payments) { if (xeroInvoice.Payments == null) { xeroInvoice.Payments = new List <Xero.Api.Core.Model.Payment>(); } Xero.Api.Core.Model.Payment payment = new Xero.Api.Core.Model.Payment() { Amount = (decimal)workFlowPayment.Amount, Date = workFlowPayment.PaymentDate, Type = Xero.Api.Core.Model.Types.PaymentType.AccountsReceivablePrepayment }; xeroInvoice.Payments.Add(payment); workFlowPayment.AccountingPartnerIdentifier = xeroInvoice.Contact.Id.ToString(); } foreach (CreditNote creditNote in Invoice.ChildItems.Where(g => g.WorkFlowType == Ignyt.BusinessInterface.WorkFlowType.CreditNote)) { if (xeroInvoice.CreditNotes == null) { xeroInvoice.CreditNotes = new List <Xero.Api.Core.Model.CreditNote>(); } Xero.Api.Core.Model.CreditNote xeroCreditNote = XeroFunctions.CoreApi().CreditNotes.Find(creditNote.AccountingPartnerIdentifier); if (xeroCreditNote == null) { xeroInvoice.CreditNotes.Add(CreateCreditNote(creditNote)); } else { xeroInvoice.CreditNotes.Add(xeroCreditNote); } } return(xeroInvoice); }