Ejemplo n.º 1
0
        public void ExportToCsv(List<Gen4Transaction> Gen4ExportTransactions)
        {
            DateTime exportDateTime = DateTime.Now;

            StringBuilder sbExportFile = new StringBuilder();
            sbExportFile.AppendLine("TransactionID,ParentTransactionID,CustomerID,Company,CustomerName,CustomerEmail,CustomerPhone,LeadID,LeadType,Source,Description,TransactionType,IsReported,Action,Created");

            foreach (var gen4ExportTransaction in Gen4ExportTransactions)
            {
                sbExportFile.AppendLine(this.FormatForExportToCSV(gen4ExportTransaction.TransactionID.ToString()) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.ParentTransactionID.ToString()) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.CustomerID.ToString()) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.Company) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.CustomerName) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.CustomerEmail) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.CustomerPhone) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.LeadID.ToString()) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.LeadType) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.Source) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.Description) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.TransactionType) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.IsReported.ToString()) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.Action.ToString()) + "," +
                                        this.FormatForExportToCSV(gen4ExportTransaction.Created.ToString()));
            }

            string exportedFilename = this.GetExportFilename(exportDateTime);

            using (System.Transactions.TransactionScope trans = new System.Transactions.TransactionScope())
            {
                using (System.IO.StreamWriter sw = new System.IO.StreamWriter(exportedFilename))
                {
                    sw.WriteLine(sbExportFile);
                }
                
                Gen4LiveEntities gen4Ctx = new Gen4LiveEntities();
                foreach (var gen4ExportTransaction in Gen4ExportTransactions)
                {
                    var gen4Transaction = (from t in gen4Ctx.Gen4PplLedger
                                           where t.TransactionID == gen4ExportTransaction.TransactionID
                                           select t).Single();
                    gen4Transaction.IsReported = true;
                    gen4Transaction.ReportStatus = "Exported to CSV on " + exportDateTime.ToString();
                    gen4Transaction.LastModified = DateTime.Now;
                    gen4Ctx.SaveChanges();
                }

                trans.Complete();
            }            
        }
Ejemplo n.º 2
0
        public void ImportToQuickbooks(Gen4Transaction Gen4ImportTransaction)
        {
            var gen4Customer = (from c in Gen4Customers
                                where c.CustomerID == Gen4ImportTransaction.CustomerID
                                select c).Single();
            var quickBookItem = (from i in QuickbookItems
                                 where i.Name == gen4Customer.QuickbookPaymentPlan
                                 select i).Single();

            IdaQuickbookEntities ctxQuickbooks = new IdaQuickbookEntities();
            if (Gen4ImportTransaction.TransactionType == "Invoice")
            {
                InvoiceLineItem myItem = new InvoiceLineItem();
                myItem.CustomerId = gen4Customer.QuickbookCustomerID;
                myItem.ItemId = quickBookItem.ID;
                myItem.ItemQuantity = 1;
                myItem.Memo = "TrxID: {" + Gen4ImportTransaction.TransactionID + "}, Type: {" + Gen4ImportTransaction.LeadType + "}, Source: {" + Gen4ImportTransaction.Source + "}";
                ctxQuickbooks.InvoiceLineItems.AddObject(myItem);
                ctxQuickbooks.SaveChanges();
            }
            else if (Gen4ImportTransaction.TransactionType == "Credit")
            {
                var quickbooksCustomer = (from q in QuickbooksCustomers
                                          where q.ID == gen4Customer.QuickbookCustomerID
                                          select q).Single();

                CreditMemo creditItem = new CreditMemo();
                creditItem.CustomerName = quickbooksCustomer.Name;
                creditItem.CustomerId = gen4Customer.QuickbookCustomerID;
                creditItem.ItemAggregate = "<CreditMemoLineItems><Row><ItemQuantity>1</ItemQuantity><ItemName>" + quickBookItem.FullName + "</ItemName></Row></CreditMemoLineItems>";
                creditItem.Memo = "TrxID: {" + Gen4ImportTransaction.TransactionID + "}, Type: {" + Gen4ImportTransaction.LeadType + "}, Source: {" + Gen4ImportTransaction.Source + "}, ParentTrxID: {" + Gen4ImportTransaction.ParentTransactionID + "}";
                ctxQuickbooks.CreditMemos.AddObject(creditItem);
                ctxQuickbooks.SaveChanges();
            }

            Gen4LiveEntities gen4Ctx = new Gen4LiveEntities();
            var gen4Transaction = (from t in gen4Ctx.Gen4PplLedger
                                   where t.TransactionID == Gen4ImportTransaction.TransactionID
                                   select t).Single();
            gen4Transaction.IsReported = true;
            gen4Transaction.ReportStatus = "Imported to QB on " + DateTime.Now.ToString();
            gen4Transaction.LastModified = DateTime.Now;
            gen4Ctx.SaveChanges();

        }