private void ProcessXmlFile(string inFilename)
        {
            try
            {
                var invoice = XeroHelper.DeSerializeFromFilePath <XeroInvoice>(inFilename);
                if (invoice.Type == "ACCPAYCREDIT" || invoice.Type == "ACCRECCREDIT")
                {
                    CreateCreditNode(inFilename, invoice);
                }
                else
                {
                    CreateInvoice(inFilename, invoice);
                }
            }
            catch (XeroIntegrationException xiExc)
            {
                MoveFileToFailedFolder(inFilename); // Failed. XML Invoice with an invalid structure or NOT Found is moved to the Failed folder for further human action

                ServiceLogger.Log(string.Format(@"Xero Server Validation Error: {0}  [Invoice filename: {1}]", xiExc.Message, inFilename));
            }
            catch (Exception exc)
            {
                ServiceLogger.Log(string.Format(@"Xero Server Error: {0}  [Invoice filename: {1}]", exc.Message, inFilename));

                MoveFileToRetryFolder(inFilename);
            }
        }
        public void LoadConfiguration()
        {
            var configFilePath = ServiceInfo.GetFileURI(AccountingIntegration.Properties.Settings.Default.AccountingIntegrationConfigFilename);

            if (File.Exists(configFilePath))
            {
                _accountingConfiguration = XeroHelper.DeSerializeFromFilePath <AccountingAuthConfiguration>(configFilePath);
            }
            else
            {
                _accountingConfiguration = new AccountingAuthConfiguration
                {
                    AccountingSystemList = new List <AccountingSystem>()
                    {
                        new AccountingSystem()
                        {
                            Type            = "Xero",
                            CredentialsList = new CredentialsList()
                            {
                                Credentials = new List <Credentials>()
                            }
                        },
                        new AccountingSystem()
                        {
                            Type            = "MYOB",
                            CredentialsList = new CredentialsList()
                            {
                                Credentials = new List <Credentials>()
                            }
                        }
                    }
                };
            }
        }
Beispiel #3
0
 private void LogintoCompanyFile()
 {
     try
     {
         IApiConfiguration config = ConfigurationCloud;
         var configFilePath       = ServiceInfo.GetFileURI(AccountingIntegration.Properties.Settings.Default.CompanyFileDetails);
         var credentials          = XeroHelper.DeSerializeFromFilePath <CompanyFileCredentialsCF>(configFilePath);
         Credentials = new CompanyFileCredentials(credentials.CredentialsDetails.UserName, credentials.CredentialsDetails.Password);
         GetCompanyFileDetails(Credentials);
     }
     catch (Exception ex)
     {
         ServiceLogger.LogException("Exception in LogintoCompanyFile", ex);
     }
 }
Beispiel #4
0
        public XeroAuthConfiguration LoadConfiguration()
        {
            XeroAuthConfiguration xeroConfiguration;
            var configFilePath = ServiceInfo.GetFileURI(XeroIntegration.Properties.Settings.Default.XeroIntegrationConfigFilename);

            if (File.Exists(configFilePath))
            {
                xeroConfiguration = XeroHelper.DeSerializeFromFilePath <XeroAuthConfiguration>(configFilePath);
            }
            else
            {
                xeroConfiguration = new XeroAuthConfiguration
                {
                    OAuth = new OAuth()
                    {
                        CredentialsList = new CredentialsList()
                        {
                            Credentials = new List <Credentials>()
                        }
                    }
                };
            }
            return(xeroConfiguration);
        }
Beispiel #5
0
 public void PostInvoice(CompanyFile CompanyFile, string inFilename)
 {
     try
     {
         CompanyFile1 = CompanyFile;
         InitFileandFolders(inFilename);
         CurrentAccount = null;
         var invoice             = XeroHelper.DeSerializeFromFilePath <MYOBInvoice>(inFilename);
         var receiveMoney        = new ReceiveMoneyTxn();
         var receiveMoneyService = new ReceiveMoneyTxnService(ConfigurationCloud, null,
                                                              MyOAuthKeyService);
         decimal amountToBeRecievedIncash = 0.00M;
         receiveMoney.Contact = new CardLink {
             UID = (Guid)GetCustomer(invoice.Contact.Name).UID
         };
         receiveMoney.IsTaxInclusive = true;
         receiveMoney.PaymentMethod  = "Cash";
         receiveMoney.Date           = DateTime.Now;
         receiveMoney.DepositTo      = DepositTo.Account;
         receiveMoney.Memo           = "Job " + invoice.Jobcode + " Time " + invoice.Date;
         for (int i = 0; i < Accounts.Count(); i++)
         {
             if (Accounts[i].DisplayID == invoice.CashGLCode)
             {
                 receiveMoney.Account = new AccountLink {
                     UID = (Guid)Accounts[i].UID
                 };
                 break;
             }
         }
         var lines = new List <ReceiveMoneyTxnLine>();
         foreach (var item in invoice.Items.Item)
         {
             if (item.Description != "Cash")
             {
                 var line = new ReceiveMoneyTxnLine();
                 for (int i = 0; i < Accounts.Count(); i++)
                 {
                     if (item.GLCode == Accounts[i].DisplayID)
                     {
                         line.Account = new AccountLink {
                             UID = (Guid)Accounts[i].UID
                         };
                         CurrentAccount = Accounts[i];
                         break;
                     }
                 }
                 decimal d = 0.0M;
                 Decimal.TryParse(item.UnitAmount, out d);
                 line.Amount = d;
                 amountToBeRecievedIncash += d;   // comprises total amount in hand
                 for (int i = 0; i < Jobs.Count(); i++)
                 {
                     if (invoice.Jobcode == Jobs[i].Number)
                     {
                         line.Job = new JobLink {
                             UID = (Guid)Jobs[i].UID
                         };
                         break;
                     }
                 }
                 line.Memo = item.Description;
                 if (item.TaxStatus == "NonZeroTax")
                 {
                     line.TaxCode = new TaxCodeLink {
                         UID = (Guid)CurrentAccount.TaxCode.UID
                     }
                 }
                 ;
                 else
                 {
                     for (int i = 0; i < TaxCodes.Count(); i++)
                     {
                         if (TaxCodes[i].Rate == 0.0)
                         {
                             line.TaxCode = new TaxCodeLink {
                                 UID = (Guid)TaxCodes[i].UID
                             };
                             break;
                         }
                     }
                 }
                 lines.Add(line);
             }
         }
         receiveMoney.Lines          = lines;
         receiveMoney.AmountReceived = amountToBeRecievedIncash > 0.00M ? amountToBeRecievedIncash : (amountToBeRecievedIncash * -1);
         receiveMoneyService.Insert(CompanyFile, receiveMoney, Credentials, OnSaveComplete, OnError);
     }
     catch (Exception ex)
     {
         ServiceLogger.Log("Exception in PostInvoice " + ex.Message);
         MoveFileToFailedFolder();
     }
 }