Exemplo n.º 1
0
        private void CreateInvoice(string inFilename, XeroInvoice invoice)
        {
            var xeroInvoice    = XeroInvoiceController.Instance.CreateInvoice(invoice);
            var createdInvoice = _repository.Create(xeroInvoice);

            if (createdInvoice.ValidationStatus == Xero.Api.Core.Model.Status.ValidationStatus.Error)
            {
                MoveFileToFailedFolder(inFilename);

                foreach (var message in createdInvoice.Warnings)
                {
                    ServiceLogger.Log(string.Format(@"Xero Server Validation Error: {0}  [Invoice Reference: {1}]", message.Message, xeroInvoice.Reference));
                }
            }
            else
            {
                if (invoice.Payments != null && invoice.Payments.Item != null && invoice.Payments.Item.Count > 0)
                {
                    var invoicePayments = XeroInvoiceController.Instance.GetInvoicePayments(invoice.Payments, createdInvoice);
                    _repository.Create(invoicePayments);
                }
                MoveFileToSuccesfulFolder(inFilename);
                ServiceLogger.Log(string.Format(@"Invoice: {0}  has been sent with reference number: {1}", xeroInvoice.Number, xeroInvoice.Reference));
            }
        }
Exemplo n.º 2
0
 public Invoice CreateInvoice(XeroInvoice invoice)
 {
     try
     {
         var invoiceToCreate = new Invoice();
         invoiceToCreate.Contact         = GetInvoiceContact(invoice.Contact);
         invoiceToCreate.Type            = GetInvoiceType(invoice.Type);
         invoiceToCreate.Number          = invoice.Number;
         invoiceToCreate.Reference       = invoice.Reference;
         invoiceToCreate.LineAmountTypes = GetInvoiceLineAmountType(invoice.LineAmountType);
         invoiceToCreate.Date            = GetDate(invoice.Date);
         invoiceToCreate.DueDate         = GetDate(invoice.DueDate);
         invoiceToCreate.LineItems       = GetLineItems(invoice.Items);
         invoiceToCreate.Status          = GetStatus(invoice.Status);
         return(invoiceToCreate);
     }
     catch (Exception exception)
     {
         throw new XeroIntegrationException(exception.Message);
     }
 }