Beispiel #1
0
        private void Task_ImportPayments(Objsearch oQuery, Invoice oInvoice, Customer oCustomer, Receivepayment oReceivePayment, Quickbooks oQuickbooks)
        {
            try
             {
            oQuery.OpenQBConnection();
            oInvoice.OpenQBConnection();
            oCustomer.OpenQBConnection();
            oReceivePayment.OpenQBConnection();

            PaymentResult oPaymentResult = oQuickbooks.GetPayments();
            if (oPaymentResult.IsSuccessfull)
            {
               m_iTotal = oPaymentResult.Payments.Count();
               m_iCurrent = 0;
               var errorCount = 0;
               var successCount = 0;

               foreach (SpeedySpots.API.Interfaces.Payment oPayment in oPaymentResult.Payments)
               {
                  decimal fTotal = 0;
                  string sInvoices = string.Empty;
                  oReceivePayment.Reset();

                  foreach (SpeedySpots.API.Interfaces.PaymentLineItem oPaymentLineItem in oPayment.LineItems)
                  {
                     oQuery.Reset();
                     oQuery.QBXMLVersion = "5.0";
                     oQuery.QueryType = ObjsearchQueryTypes.qtInvoiceSearch;
                     oQuery.SearchCriteria = new SearchCriteria();
                     oQuery.SearchCriteria.RefNumber = oPaymentLineItem.InvoiceID;
                     oQuery.IterateResults = true;
                     oQuery.MaxResults = 0;
                     oQuery.Search();

                     if (oQuery.Results.Count > 0)
                     {
                        oInvoice.Get(oQuery.Results[0].ResultId);

                        AppliedTo oAppliedTo = new AppliedTo();
                        oAppliedTo.RefId = oQuery.Results[0].ResultId;
                        oAppliedTo.PaymentAmount = oPaymentLineItem.Amount.ToString("0.00");

                        oReceivePayment.AppliedTo.Add(oAppliedTo);

                        fTotal += oPaymentLineItem.Amount;
                        sInvoices += string.Format("{0}, ", oPaymentLineItem.InvoiceID);
                     }
                  }
                  try
                  {
                     oReceivePayment.AutoApply = ReceivepaymentAutoApplies.aaCustom;
                     oReceivePayment.CustomerName = oInvoice.CustomerName;
                     oReceivePayment.Amount = fTotal.ToString();
                     oReceivePayment.TransactionDate = oPayment.CreatedDateTime.ToString("d");

                     if (oPayment.CreditCardFirstName != string.Empty)
                     {
                        oReceivePayment.RefNumber = string.Format("{0} {1}", oPayment.CreditCardFirstName, oPayment.CreditCardLastName);
                     }

                     if (oPayment.CreditCardType == "Visa")
                     {
                        oReceivePayment.PaymentMethodName = "Visa";
                     }
                     else if (oPayment.CreditCardType == "MasterCard")
                     {
                        oReceivePayment.PaymentMethodName = "Mastercard";
                     }
                     else if (oPayment.CreditCardType == "American Express")
                     {
                        oReceivePayment.PaymentMethodName = "American Express";
                     }
                     else if (oPayment.CreditCardType == "Discover")
                     {
                        oReceivePayment.PaymentMethodName = "Discover";
                     }

                     // Remove last ', '
                     if (sInvoices.Length > 2)
                     {
                        sInvoices = sInvoices.Substring(0, sInvoices.Length - 2);
                     }

                     oReceivePayment.Memo = string.Format("Payment for invoice {0} - AuthID: {1}", sInvoices, oPayment.AuthorizeNetID);

                     oReceivePayment.Add();
                     successCount++;
                  }
                  catch (Exception e)
                  {
                     errorCount++;
                     MessageBox.Show(e.Message + System.Environment.NewLine + System.Environment.NewLine + e.StackTrace);
                  }

                  this.UpdateProgress();

                  if (m_oWorkerProcess.CancellationPending)
                  {
                     break;
                  }
               }

               if (successCount > 0 || errorCount > 0)
               {
                  MessageBox.Show("Finished Payment Import" + Environment.NewLine + "Success: " + successCount + Environment.NewLine + "Error: " + errorCount);
               }
            }
            else
            {
               MessageBox.Show(oPaymentResult.ErrorMessage, "API/Service Error");
            }

            m_oWorkerProcess.ReportProgress(100);
             }
             catch (Exception e)
             {
            MessageBox.Show(e.Message + System.Environment.NewLine + System.Environment.NewLine + e.StackTrace);
             }
             finally
             {
            oQuery.CloseQBConnection();
            oInvoice.CloseQBConnection();
            oCustomer.CloseQBConnection();
            oReceivePayment.CloseQBConnection();
             }
        }
Beispiel #2
0
        private void Task_ImportInvoices()
        {
            Objsearch oQuery = new Objsearch();

             try
             {
            oQuery.OpenQBConnection();
            m_oInvoice.OpenQBConnection();

            List<SyncInvoice> oInvoices = this.m_oSyncInvoices.GetSelectedInvoices();

            Directory.CreateDirectory(m_sDirectoryRoot);

            string sRootName = string.Format("{0:MM-dd-yyyy hhmmss}", DateTime.Now);
            string fullFileNameAndPath = string.Format(@"Uploads\{0}.7z", sRootName);

            m_iTotal = oInvoices.Count;
            m_iCurrent = 0;

            this._logger.DebugFormat("Invoices found for processing: {0}", oInvoices.Count);

            for (int i = 0; i < oInvoices.Count; i++)
            {
               this.ProcessInvoice(oInvoices[i]);
            }

            if (m_oListInvoices.Count > 0)
            {
               // Serialize invoice information
               string sInvoicesFilename = string.Format(@"{0}\Invoices.dat", m_sDirectoryRoot);

               this._logger.DebugFormat("Writing dat file: {0}", sInvoicesFilename);

               FileStream oFileStream = new FileStream(sInvoicesFilename, FileMode.Create);
               BinaryFormatter oFormatter = new BinaryFormatter();
               oFormatter.Serialize(oFileStream, m_oListInvoices);
               oFileStream.Close();

               this._logger.Debug("Dat file written");

               // Create zipped file
               this._logger.DebugFormat("Zipping folder using: {0}", Path.Combine(Application.StartupPath, "7z.dll"));

               SevenZipCompressor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z.dll"));
               SevenZipCompressor oCompressor = new SevenZipCompressor();
               oCompressor.PreserveDirectoryRoot = true;
               oCompressor.IncludeEmptyDirectories = true;
               oCompressor.CompressDirectory(Path.Combine(Environment.CurrentDirectory, m_sDirectoryRoot), fullFileNameAndPath);

               this._logger.DebugFormat("Folder zipped: {0} {1}", Path.Combine(Environment.CurrentDirectory, m_sDirectoryRoot), fullFileNameAndPath);

               // Upload
               if (!m_oQuickbooks.Upload(fullFileNameAndPath))
               {
                  MessageBox.Show("Upload Error: " + m_oQuickbooks.Error);
               }
               else
               {
                  if (this.DeleteInvoiceFolderAndZipFile)
                  {
                     File.Delete(fullFileNameAndPath);
                  }
               }
            }

            m_oWorkerProcess.ReportProgress(100);
             }
             catch (Exception ex)
             {
            MessageBox.Show(string.Format("Error: {0} \n\n {1}", ex.Message, ex.StackTrace));
             }
             finally
             {
            // Delete root directory, no longer need it
            if (Directory.Exists(m_sDirectoryRoot) && this.DeleteInvoiceFolderAndZipFile)
            {
               Directory.Delete(m_sDirectoryRoot, true);
            }

            m_oListInvoices.Clear();

            oQuery.CloseQBConnection();
            m_oInvoice.CloseQBConnection();
             }
        }
Beispiel #3
0
        private void OnLoad(object sender, EventArgs e)
        {
            // Make sure QB is running
             Objsearch oQuery = new Objsearch();

             try
             {
            oQuery.OpenQBConnection();

            m_bLoading = true;
            m_cboDays.Text = "0";
            m_bLoading = false;

            m_dtStart.Value = DateTime.Today.AddDays(-1);
            m_dtEnd.Value = DateTime.Today;

            OnChangedDays(this, new EventArgs());

            m_chkAllSync.Checked = true;
            m_chkAllEmail.Checked = true;
            OnAllSync(this, new EventArgs());
            OnAllEmail(this, new EventArgs());

            m_grdInvoices.Columns["Amount"].DefaultCellStyle.Format = "c";
             }
             catch (InQBObjsearchException oException)
             {
            if (oException.Code == 606)
            {
               MessageBox.Show("Please start Quickbooks and load your company information before running sync process.", "Quickbooks Error");
            }
            else
            {
               MessageBox.Show(oException.Message);
            }

            DialogResult = System.Windows.Forms.DialogResult.Cancel;
            Close();
             }
             finally
             {
            try
            {
               oQuery.CloseQBConnection();
            }
            catch (Exception)
            {
            }
             }
        }
Beispiel #4
0
        private void Task_ImportCustomers(Objsearch oQuery, Quickbooks oQuickbooks)
        {
            try
             {
            oQuery.OpenQBConnection();

            oQuery.QBXMLVersion = "5.0";
            oQuery.QueryType = ObjsearchQueryTypes.qtCustomerSearch;

            CustomerResult oCustomerResult = oQuickbooks.GetCustomers();

            List<int> oSMSIDImported = new List<int>();

            if (oCustomerResult.IsSuccessfull)
            {
               m_iTotal = oCustomerResult.Customers.Count();
               m_iCurrent = 0;

               int customerCount = 0;
               int importedCount = 0;
               int duplicateNameCount = 0;
               int errorCount = 0;

               customerCount = oCustomerResult.Customers.Count;

               foreach (var oCustomer in oCustomerResult.Customers)
               {
                  oQuery.SearchCriteria = new SearchCriteria();
                  oQuery.SearchCriteria.NameStartsWith = oCustomer.Name;
                  oQuery.Search();

                  CompanyUniqueness companyUnique = this.IsUniqueCustomerName(oCustomer.Name, oQuery.Results);

                  if (companyUnique == CompanyUniqueness.Unique)
                  {
                     // Add new customer into Quickbooks
                     Customer oQuickbooksCustomer = new Customer();
                     oQuickbooksCustomer.OpenQBConnection();

                     oQuickbooksCustomer.CustomerName = oCustomer.Name;
                     oQuickbooksCustomer.CompanyName = oCustomer.Name;
                     oQuickbooksCustomer.AltContactName = oCustomer.BillingName;
                     oQuickbooksCustomer.AltPhone = oCustomer.BillingPhone;
                     oQuickbooksCustomer.ContactName = oCustomer.Contact;
                     oQuickbooksCustomer.Phone = oCustomer.Phone;
                     oQuickbooksCustomer.Fax = oCustomer.Fax;

                     if (oCustomer.ShippingCountry == "United States")
                     {
                        oQuickbooksCustomer.ShippingAddress = string.Format("<Addr1>{0}</Addr1><Addr2>{1}</Addr2><Addr3>{2}</Addr3><City>{3}</City><State>{4}</State><PostalCode>{5}</PostalCode><Country>{6}</Country>", oCustomer.Name, oCustomer.ShippingAddressLine1, oCustomer.ShippingAddressLine2, oCustomer.ShippingCity, oCustomer.ShippingState, oCustomer.ShippingZip, oCustomer.ShippingCountry);
                     }
                     else
                     {
                        // Not the United States, ignore the state value completely
                        oQuickbooksCustomer.ShippingAddress = string.Format("<Addr1>{0}</Addr1><Addr2>{1}</Addr2><Addr3>{2}</Addr3><City>{3}</City><PostalCode>{4}</PostalCode><Country>{5}</Country>", oCustomer.Name, oCustomer.ShippingAddressLine1, oCustomer.ShippingAddressLine2, oCustomer.ShippingCity, oCustomer.ShippingZip, oCustomer.ShippingCountry);
                     }

                     if (oCustomer.BillingCountry == "United States")
                     {
                        oQuickbooksCustomer.BillingAddress = string.Format("<Addr1>{0}</Addr1><Addr2>{1}</Addr2><Addr3>{2}</Addr3><City>{3}</City><State>{4}</State><PostalCode>{5}</PostalCode><Country>{6}</Country>", oCustomer.Name, oCustomer.BillingAddressLine1, oCustomer.BillingAddressLine2, oCustomer.BillingCity, oCustomer.BillingState, oCustomer.BillingZip, oCustomer.BillingCountry);
                     }
                     else
                     {
                        // Not the United States, ignore the state value completely
                        oQuickbooksCustomer.BillingAddress = string.Format("<Addr1>{0}</Addr1><Addr2>{1}</Addr2><Addr3>{2}</Addr3><City>{3}</City><PostalCode>{4}</PostalCode><Country>{5}</Country>", oCustomer.Name, oCustomer.BillingAddressLine1, oCustomer.BillingAddressLine2, oCustomer.BillingCity, oCustomer.BillingZip, oCustomer.BillingCountry);
                     }

                     oQuickbooksCustomer.Email = oCustomer.InvoiceEmails.Replace(",", ";");
                     oQuickbooksCustomer.TermsName = "NET 30 DAYS";

                     oQuickbooksCustomer.Config(string.Format("FirstName={0}", oCustomer.Name));
                     oQuickbooksCustomer.Config("LastName=");

                     try
                     {
                        oQuickbooksCustomer.Add();

                        oQuickbooksCustomer.SetCustomField("SMSID", oCustomer.SMSID.ToString());
                        oSMSIDImported.Add(oCustomer.SMSID);
                        importedCount += 1;
                     }
                     catch (Exception oException)
                     {
                        errorCount += 1;
                        MessageBox.Show(oException.Message + System.Environment.NewLine + System.Environment.NewLine + oException.StackTrace);
                     }
                     finally
                     {
                        oQuickbooksCustomer.CloseQBConnection();
                     }
                  }
                  else if (companyUnique == CompanyUniqueness.DuplicateMarkImported)
                  {
                     oSMSIDImported.Add(oCustomer.SMSID);
                     duplicateNameCount += 1;
                  }
                  else
                  {
                     duplicateNameCount += 1;
                  }

                  this.UpdateProgress();

                  if (m_oWorkerProcess.CancellationPending)
                  {
                     break;
                  }
               }

               if (customerCount > 0)
               {
                  MessageBox.Show("Customer import results:" + System.Environment.NewLine + "  Attempted: " + customerCount.ToString() + System.Environment.NewLine + "  Imported: " + importedCount.ToString() + System.Environment.NewLine + "  Duplicates: " + duplicateNameCount.ToString() + System.Environment.NewLine + "  Errors: " + errorCount.ToString(), "Import Results");
               }
            }
            else
            {
               MessageBox.Show(oCustomerResult.ErrorMessage, "API/Service Error");
            }

            oQuickbooks.UpdateWebServiceOfImportedCustomer(oSMSIDImported);

            m_oWorkerProcess.ReportProgress(100);
             }
             catch (Exception e)
             {
            MessageBox.Show(e.Message + System.Environment.NewLine + System.Environment.NewLine + e.StackTrace);
             }
             finally
             {
            oQuery.CloseQBConnection();
             }
        }
Beispiel #5
0
        private void OnChangedDays(object sender, EventArgs e)
        {
            if (!m_bLoading)
             {
            if (m_dtStart.Value > m_dtEnd.Value)
            {
               MessageBox.Show("The start date must come before the end date.", "Invoice Date Error");
               return;
            }

            ToggleControls(false);

            m_oRows = new List<InvoiceRow>();
            Objsearch oQuery = new Objsearch();

            try
            {
               oQuery.OpenQBConnection();
               m_oInvoice.OpenQBConnection();

               oQuery.QBXMLVersion = "5.0";
               oQuery.QueryType = ObjsearchQueryTypes.qtInvoiceSearch;
               oQuery.IterateResults = true;
               oQuery.MaxResults = 50;
               oQuery.SearchCriteria = new SearchCriteria();
               oQuery.SearchCriteria.TransactionDateStart = m_dtStart.Value.ToString("d");
               oQuery.SearchCriteria.TransactionDateEnd = m_dtEnd.Value.ToString("d");
               oQuery.Search();

               for (int i = 0; i < oQuery.Results.Count; i++)
               {
                  InsertRow(oQuery.Results[i].ResultId);
               }

               while (oQuery.RemainingResults > 0)
               {
                  oQuery.GetNextResults();

                  for (int i = 0; i < oQuery.Results.Count; i++)
                  {
                     InsertRow(oQuery.Results[i].ResultId);
                  }
               }

               m_oRows.Sort(0, m_oRows.Count, null);

               StringBuilder oData = new StringBuilder();
               foreach (InvoiceRow oRow in m_oRows)
               {
                  oData.Append(string.Format("{0}-{1}-{2}|", oRow.InvoiceNumber, oRow.JobID, oRow.SMSID));
               }

               string sData = oData.ToString();

               if (sData.Length > 2)
               {
                  sData = sData.Substring(0, sData.Length - 1);
               }

               MarkInvalidInvoices(sData);
            }
            finally
            {
               oQuery.CloseQBConnection();
               m_oInvoice.CloseQBConnection();

               ToggleControls(true);
            }
             }
        }