Пример #1
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();

        }
Пример #2
0
        public List<Gen4Transaction> GetIdaLeads(DateTime StartDate, DateTime EndDate, bool? IsReported, out ActionResult actionResult)
        {
            actionResult = new ActionResult();

            Gen4Transactions = new List<Gen4Transaction>();

            Gen4LiveEntities gen4Ctx = new Gen4LiveEntities();
            if (IsReported.HasValue)
            {
                Gen4PplLedgerTransactions = (from l in gen4Ctx.Gen4PplLedger
                                             where l.Created >= StartDate && l.Created <= EndDate
                                             && l.IsReported == IsReported
                                             select l).ToList();
            }
            else
            {
                Gen4PplLedgerTransactions = (from l in gen4Ctx.Gen4PplLedger
                                             where l.Created >= StartDate && l.Created <= EndDate
                                             select l).ToList();
            }
            var CustomerLocationWebsiteIDs = (from w in gen4Ctx.Websites
                                              join l in gen4Ctx.CustomerLocations on w.LocationID equals l.LocationID
                                              join c in gen4Ctx.IdaCustomers on l.CustomerID equals c.CustomerID
                                              select new
                                              {
                                                  CustomerID = c.CustomerID,
                                                  LocationID = l.LocationID,
                                                  WebsiteID = w.WebsiteID
                                              }).Distinct().ToList();

            StringBuilder sbErrorMessages = new StringBuilder();
            foreach (var ledgerTransaction in Gen4PplLedgerTransactions)
            {
                var customer = (from c in Gen4Customers
                                where c.CustomerID == ledgerTransaction.CustomerID
                                select c).SingleOrDefault();

                if (customer == null)
                {
                    if (ExcludedCustomers.ContainsKey(ledgerTransaction.CustomerID))
                    {
                        actionResult.IsErrorPresent = true;
                        sbErrorMessages.AppendLine("TrxID: " + ledgerTransaction.TransactionID + " belongs to an excluded Customer. Customer: " + ledgerTransaction.CustomerID + " - " + ExcludedCustomers[ledgerTransaction.CustomerID]);
                        sbErrorMessages.AppendLine("  If you would like to process this Transaction remove CustomerID from Excluded Customers XML file.\r\n");
                        continue;
                    }
                }

                Gen4Transaction newLead = new Gen4Transaction();
                newLead.TransactionID = ledgerTransaction.TransactionID;
                newLead.ParentTransactionID = ledgerTransaction.ParentTransactionID;
                newLead.CustomerID = ledgerTransaction.CustomerID;
                newLead.Company = customer.CompanyName;
                newLead.CustomerName = customer.FirstName + " " + customer.LastName;
                newLead.CustomerEmail = customer.Email;
                newLead.CustomerPhone = customer.Phone;
                newLead.LeadID = ledgerTransaction.LeadID;
                newLead.LeadType = ledgerTransaction.LeadType;
                newLead.MarketID = ledgerTransaction.MarketID;
                newLead.Source = ledgerTransaction.Source;
                newLead.Description = ledgerTransaction.Description;
                newLead.TransactionType = ledgerTransaction.TransactionType;
                newLead.IsReported = ledgerTransaction.IsReported;
                newLead.Created = ledgerTransaction.Created;
                newLead.ReportStatus = ledgerTransaction.ReportStatus;

                if (ledgerTransaction.IsReported)
                {
                    newLead.Action = QuickbooksAction.None;
                    //override any errors for already reported transactions
                    newLead.IsErrorPresent = false;
                    newLead.ErrorMessage = null;
                }
                else
                {
                    newLead.Action = customer.Action;
                    newLead.IsErrorPresent = customer.IsErrorPresent;
                    newLead.ErrorMessage = customer.ErrorMessage;
                }

                Gen4Transactions.Add(newLead);
            }

            if (actionResult.IsErrorPresent)
            {
                actionResult.ErrorMessage = sbErrorMessages.ToString();
            }

            return Gen4Transactions;
        }