private static void WalkCustomerRet(XmlNode CustomerRet) { if (CustomerRet == null) { return; } RotoTrackDb db = new RotoTrackDb(); //Get value of Sublevel. If it is not set to 0 or 1, then return (we only care about parents with sublevel of 0, and their direct descendents, sublevel of 1) string Sublevel = CustomerRet.SelectSingleNode("./Sublevel").InnerText; if (Sublevel != "0" && Sublevel != "1") { return; } // Archive all parent and child customers in a JobArchive table. We use this for time and mileage and for debugging. string JobSublevel = Sublevel; string JobFullName = CustomerRet.SelectSingleNode("./FullName").InnerText; string JobName = CustomerRet.SelectSingleNode("./Name").InnerText; string JobListID = CustomerRet.SelectSingleNode("./ListID").InnerText; string JobEditSequence = CustomerRet.SelectSingleNode("./EditSequence").InnerText; string JobIsActive = CustomerRet.SelectSingleNode("./IsActive").InnerText; JobArchive ja = null; if (db.JobArchives.Any(j => j.QBListId == JobListID)) { ja = db.JobArchives.First(j => j.QBListId == JobListID); } else { ja = new JobArchive(); db.JobArchives.Add(ja); } ja.QBListId = JobListID; ja.QBEditSequence = JobEditSequence; ja.IsActive = (JobIsActive == "true") ? true : false; ja.Name = JobName; ja.FullName = JobFullName; ja.Sublevel = JobSublevel; db.SaveChanges(); // Note that those that have a parent are actually jobs bool IsJob = false; string parentListID = ""; XmlNode ParentRef = CustomerRet.SelectSingleNode("./ParentRef"); if (ParentRef != null) { IsJob = true; parentListID = ParentRef.SelectSingleNode("./ListID").InnerText; } // If this is a Customer record (not a job record), add/update Customer information, first. Customer c = null; if (!IsJob) { string ListID = CustomerRet.SelectSingleNode("./ListID").InnerText; if (db.Customers.Any(f => f.QBListId == ListID)) { c = db.Customers.First(f => f.QBListId == ListID); } else { c = new Customer(); db.Customers.Add(c); } c.QBListId = ListID; //Get value of Name string Name = CustomerRet.SelectSingleNode("./Name").InnerText; c.Name = Name; //Get value of IsActive string IsActive = "false"; if (CustomerRet.SelectSingleNode("./IsActive") != null) { IsActive = CustomerRet.SelectSingleNode("./IsActive").InnerText; } c.IsActive = (IsActive == "true") ? true : false; } // Else, update IsActive for the associated WorkOrder and then get the parent customer record so we can update info for the parent else { // Get associated work order and update the IsActive flag in case someone marked it inactive in QuickBooks. // Also, update some additional info that the user may set in QuickBooks that we need to sync back over. string ListID = CustomerRet.SelectSingleNode("./ListID").InnerText; if (db.WorkOrders.Any(f => f.QBListId == ListID)) { WorkOrder wo = db.WorkOrders.First(f => f.QBListId == ListID); string IsActive = "false"; if (CustomerRet.SelectSingleNode("./IsActive") != null) { IsActive = CustomerRet.SelectSingleNode("./IsActive").InnerText; if (IsActive == "false") { wo.Status = WorkOrderStatus.Inactive; } } // Leave wo.Status alone if not marked Inactive. //<DataExtName>Invoice Delivery Status</DataExtName><DataExtType>STR255TYPE</DataExtType><DataExtValue>Warranty</DataExtValue></DataExtRet><DataExtRet><OwnerID>0</OwnerID><DataExtName>Invoice Delivery Status Date</DataExtName><DataExtType>STR255TYPE</DataExtType><DataExtValue>09/12/2014</DataExtValue></DataExtRet> bool gotInvoiceDeliveryStatus = false; bool gotInvoiceDeliveryStatusDate = false; XmlNodeList DataExtRetList = CustomerRet.SelectNodes("./DataExtRet"); if (DataExtRetList != null) { for (int i = 0; i < DataExtRetList.Count; i++) { XmlNode DataExtRet = DataExtRetList.Item(i); //Get value of DataExtName string DataExtName = DataExtRet.SelectSingleNode("./DataExtName").InnerText; //Get value of DataExtType string DataExtType = DataExtRet.SelectSingleNode("./DataExtType").InnerText; //Get value of DataExtValue string DataExtValue = DataExtRet.SelectSingleNode("./DataExtValue").InnerText; if (DataExtName == "Invoice Delivery Status") { //wo.InvoiceDeliveryStatus switch (DataExtValue) { case "Closed at Zero $": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.ClosedAtZeroDollars; break; case "Warranty": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.Warranty; break; case "Invoice Hold-Coding/Signature": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.InvoiceHoldCodingSignature; break; case "Invoice Mailed": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.InvoiceMailed; break; case "Invoice Emailed": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.InvoiceEmailed; break; case "Invoice Thru ADP": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.InvoiceThruADP; break; case "Invoice Hand Delivered": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.InvoiceHandDelivered; break; case "Filed": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.Filed; break; default: Logging.RototrackErrorLog("QBMigrationTool: " + RototrackConfig.GetBuildType() + ": " + "Unknown Invoice Delivery Status:" + DataExtValue); break; } gotInvoiceDeliveryStatus = true; } else if (DataExtName == "Invoice Delivery Status Date") { if (DataExtValue.Length > 0) { DateTime invoiceDeliveryStatusDate; if (DateTime.TryParse(DataExtValue, out invoiceDeliveryStatusDate)) { wo.InvoiceDeliveryStatusDate = invoiceDeliveryStatusDate; } gotInvoiceDeliveryStatusDate = true; } } else if (DataExtName == "Reason for Lost Quote") { switch (DataExtValue) { case "Price Level": wo.ReasonForLostQuote = ReasonForLostQuote.PriceLevel; break; case "Delivery of Service": wo.ReasonForLostQuote = ReasonForLostQuote.DeliveryOfService; break; case "Slow Quote Response": wo.ReasonForLostQuote = ReasonForLostQuote.SlowQuoteResponse; break; case "Relationship w Competitor": wo.ReasonForLostQuote = ReasonForLostQuote.RelationshipWithCompetitor; break; case "Billing/ Invoicing": wo.ReasonForLostQuote = ReasonForLostQuote.BillingInvoicing; break; case "Warranty": wo.ReasonForLostQuote = ReasonForLostQuote.Warranty; break; case "Lack of Knowledge": wo.ReasonForLostQuote = ReasonForLostQuote.LackOfKnowledge; break; case "Lack of Product Choice": wo.ReasonForLostQuote = ReasonForLostQuote.LackOfProductChoice; break; case "In-House (Customer)": wo.ReasonForLostQuote = ReasonForLostQuote.InHouseCustomer; break; case "None": wo.ReasonForLostQuote = ReasonForLostQuote.None; break; case "Budgetary Estimate": wo.ReasonForLostQuote = ReasonForLostQuote.BudgetaryEstimate; break; default: Logging.RototrackErrorLog("QBMigrationTool: " + RototrackConfig.GetBuildType() + ": " + "Unknown Reason for Lost Quote"); break; } } else if (DataExtName == "Collection Status") { switch (DataExtValue) { case "Dispute - Labor Rate": wo.CollectionStatus = CollectionStatus.DisputeLaborRate; break; case "Dispute - Parts Rate": wo.CollectionStatus = CollectionStatus.DisputePartsRate; break; case "Missing - Codes": wo.CollectionStatus = CollectionStatus.MissingCodes; break; case "Missing - PO/ AFE #": wo.CollectionStatus = CollectionStatus.MissingPOAFE; break; case "Missing - Signature": wo.CollectionStatus = CollectionStatus.MissingSignature; break; case "Request - Approver Name": wo.CollectionStatus = CollectionStatus.RequestApproverName; break; case "Request - DSR Copies": wo.CollectionStatus = CollectionStatus.RequestDSRCopies; break; case "Request - Parts Receipts": wo.CollectionStatus = CollectionStatus.RequestPartsReceipts; break; case "Request - Resubmit": wo.CollectionStatus = CollectionStatus.RequestResubmit; break; case "Request - Revision per Quote": wo.CollectionStatus = CollectionStatus.RequestRevisionPerQuote; break; case "In Process": wo.CollectionStatus = CollectionStatus.InProcess; break; case "In Process - Customer Queue": wo.CollectionStatus = CollectionStatus.InProcessCustomerQueue; break; case "In Process-Cust Approve Paym": wo.CollectionStatus = CollectionStatus.InProcessCustomerApprovePayment; break; case "Paid": wo.CollectionStatus = CollectionStatus.Paid; break; case "Write-off": wo.CollectionStatus = CollectionStatus.WriteOff; break; default: Logging.RototrackErrorLog("QBMigrationTool: " + RototrackConfig.GetBuildType() + ": " + "Unknown Collection Status"); break; } } } } if (gotInvoiceDeliveryStatus && gotInvoiceDeliveryStatusDate) { // Don't update if we set it to Inactive above or if it was already set to Inactive if (wo.Status != WorkOrderStatus.Inactive) { wo.Status = WorkOrderStatus.Invoiced; } } db.SaveChanges(); } // Get parent customer c = db.Customers.First(f => f.QBListId == parentListID); } string EditSequence = CustomerRet.SelectSingleNode("./EditSequence").InnerText; c.QBEditSequence = EditSequence; if (CustomerRet.SelectSingleNode("./CompanyName") != null) { string CompanyName = CustomerRet.SelectSingleNode("./CompanyName").InnerText; c.CompanyName = CompanyName; } XmlNode BillAddress = CustomerRet.SelectSingleNode("./BillAddress"); if (BillAddress != null) { //Get value of Addr1 if (CustomerRet.SelectSingleNode("./BillAddress/Addr1") != null) { string Addr1 = CustomerRet.SelectSingleNode("./BillAddress/Addr1").InnerText; c.Address.Address1 = Addr1; } //Get value of Addr2 if (CustomerRet.SelectSingleNode("./BillAddress/Addr2") != null) { string Addr2 = CustomerRet.SelectSingleNode("./BillAddress/Addr2").InnerText; c.Address.Address2 = Addr2; } //Get value of Addr3 if (CustomerRet.SelectSingleNode("./BillAddress/Addr3") != null) { string Addr3 = CustomerRet.SelectSingleNode("./BillAddress/Addr3").InnerText; c.Address.Address3 = Addr3; } //Get value of Addr4 if (CustomerRet.SelectSingleNode("./BillAddress/Addr4") != null) { string Addr4 = CustomerRet.SelectSingleNode("./BillAddress/Addr4").InnerText; c.Address.Address4 = Addr4; } //Get value of Addr5 if (CustomerRet.SelectSingleNode("./BillAddress/Addr5") != null) { string Addr5 = CustomerRet.SelectSingleNode("./BillAddress/Addr5").InnerText; c.Address.Address5 = Addr5; } //Get value of City if (CustomerRet.SelectSingleNode("./BillAddress/City") != null) { string City = CustomerRet.SelectSingleNode("./BillAddress/City").InnerText; c.Address.City = City; } //Get value of State if (CustomerRet.SelectSingleNode("./BillAddress/State") != null) { string State = CustomerRet.SelectSingleNode("./BillAddress/State").InnerText; c.Address.State = State; } //Get value of PostalCode if (CustomerRet.SelectSingleNode("./BillAddress/PostalCode") != null) { string PostalCode = CustomerRet.SelectSingleNode("./BillAddress/PostalCode").InnerText; c.Address.Zip = PostalCode; } } //Done with field values for BillAddress aggregate // Add any new contacts (that were added to QB, or existed initially) AddNewContactsFromQB(c, CustomerRet); // Save changes to the database if (c != null) { db.SaveChanges(); } }
private static void WalkCustomerRet(XmlNode CustomerRet) { if (CustomerRet == null) return; RotoTrackDb db = new RotoTrackDb(); //Get value of Sublevel. If it is not set to 0 or 1, then return (we only care about parents with sublevel of 0, and their direct descendents, sublevel of 1) string Sublevel = CustomerRet.SelectSingleNode("./Sublevel").InnerText; if (Sublevel != "0" && Sublevel != "1") { return; } // Archive all parent and child customers in a JobArchive table. We use this for time and mileage and for debugging. string JobSublevel = Sublevel; string JobFullName = CustomerRet.SelectSingleNode("./FullName").InnerText; string JobName = CustomerRet.SelectSingleNode("./Name").InnerText; string JobListID = CustomerRet.SelectSingleNode("./ListID").InnerText; string JobEditSequence = CustomerRet.SelectSingleNode("./EditSequence").InnerText; string JobIsActive = CustomerRet.SelectSingleNode("./IsActive").InnerText; JobArchive ja = null; if (db.JobArchives.Any(j => j.QBListId == JobListID)) { ja = db.JobArchives.First(j => j.QBListId == JobListID); } else { ja = new JobArchive(); db.JobArchives.Add(ja); } ja.QBListId = JobListID; ja.QBEditSequence = JobEditSequence; ja.IsActive = (JobIsActive == "true") ? true : false; ja.Name = JobName; ja.FullName = JobFullName; ja.Sublevel = JobSublevel; db.SaveChanges(); // Note that those that have a parent are actually jobs bool IsJob = false; string parentListID = ""; XmlNode ParentRef = CustomerRet.SelectSingleNode("./ParentRef"); if (ParentRef != null) { IsJob = true; parentListID = ParentRef.SelectSingleNode("./ListID").InnerText; } // If this is a Customer record (not a job record), add/update Customer information, first. Customer c = null; if (!IsJob) { string ListID = CustomerRet.SelectSingleNode("./ListID").InnerText; if (db.Customers.Any(f => f.QBListId == ListID)) { c = db.Customers.First(f => f.QBListId == ListID); } else { c = new Customer(); db.Customers.Add(c); } c.QBListId = ListID; //Get value of Name string Name = CustomerRet.SelectSingleNode("./Name").InnerText; c.Name = Name; //Get value of IsActive string IsActive = "false"; if (CustomerRet.SelectSingleNode("./IsActive") != null) { IsActive = CustomerRet.SelectSingleNode("./IsActive").InnerText; } c.IsActive = (IsActive == "true") ? true : false; } // Else, update IsActive for the associated WorkOrder and then get the parent customer record so we can update info for the parent else { // Get associated work order and update the IsActive flag in case someone marked it inactive in QuickBooks. // Also, update some additional info that the user may set in QuickBooks that we need to sync back over. string ListID = CustomerRet.SelectSingleNode("./ListID").InnerText; if (db.WorkOrders.Any(f => f.QBListId == ListID)) { WorkOrder wo = db.WorkOrders.First(f => f.QBListId == ListID); string IsActive = "false"; if (CustomerRet.SelectSingleNode("./IsActive") != null) { IsActive = CustomerRet.SelectSingleNode("./IsActive").InnerText; if (IsActive == "false") { wo.Status = WorkOrderStatus.Inactive; } } // Leave wo.Status alone if not marked Inactive. //<DataExtName>Invoice Delivery Status</DataExtName><DataExtType>STR255TYPE</DataExtType><DataExtValue>Warranty</DataExtValue></DataExtRet><DataExtRet><OwnerID>0</OwnerID><DataExtName>Invoice Delivery Status Date</DataExtName><DataExtType>STR255TYPE</DataExtType><DataExtValue>09/12/2014</DataExtValue></DataExtRet> bool gotInvoiceDeliveryStatus = false; bool gotInvoiceDeliveryStatusDate = false; XmlNodeList DataExtRetList = CustomerRet.SelectNodes("./DataExtRet"); if (DataExtRetList != null) { for (int i = 0; i < DataExtRetList.Count; i++) { XmlNode DataExtRet = DataExtRetList.Item(i); //Get value of DataExtName string DataExtName = DataExtRet.SelectSingleNode("./DataExtName").InnerText; //Get value of DataExtType string DataExtType = DataExtRet.SelectSingleNode("./DataExtType").InnerText; //Get value of DataExtValue string DataExtValue = DataExtRet.SelectSingleNode("./DataExtValue").InnerText; if (DataExtName == "Invoice Delivery Status") { //wo.InvoiceDeliveryStatus switch (DataExtValue) { case "Closed at Zero $": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.ClosedAtZeroDollars; break; case "Warranty": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.Warranty; break; case "Invoice Hold-Coding/Signature": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.InvoiceHoldCodingSignature; break; case "Invoice Mailed": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.InvoiceMailed; break; case "Invoice Emailed": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.InvoiceEmailed; break; case "Invoice Thru ADP": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.InvoiceThruADP; break; case "Invoice Hand Delivered": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.InvoiceHandDelivered; break; case "Filed": wo.InvoiceDeliveryStatus = InvoiceDeliveryStatus.Filed; break; default: Logging.RototrackErrorLog("QBMigrationTool: " + RototrackConfig.GetBuildType() + ": " + "Unknown Invoice Delivery Status:" + DataExtValue); break; } gotInvoiceDeliveryStatus = true; } else if (DataExtName == "Invoice Delivery Status Date") { if (DataExtValue.Length > 0) { DateTime invoiceDeliveryStatusDate; if (DateTime.TryParse(DataExtValue, out invoiceDeliveryStatusDate)) { wo.InvoiceDeliveryStatusDate = invoiceDeliveryStatusDate; } gotInvoiceDeliveryStatusDate = true; } } else if (DataExtName == "Reason for Lost Quote") { switch (DataExtValue) { case "Price Level": wo.ReasonForLostQuote = ReasonForLostQuote.PriceLevel; break; case "Delivery of Service": wo.ReasonForLostQuote = ReasonForLostQuote.DeliveryOfService; break; case "Slow Quote Response": wo.ReasonForLostQuote = ReasonForLostQuote.SlowQuoteResponse; break; case "Relationship w Competitor": wo.ReasonForLostQuote = ReasonForLostQuote.RelationshipWithCompetitor; break; case "Billing/ Invoicing": wo.ReasonForLostQuote = ReasonForLostQuote.BillingInvoicing; break; case "Warranty": wo.ReasonForLostQuote = ReasonForLostQuote.Warranty; break; case "Lack of Knowledge": wo.ReasonForLostQuote = ReasonForLostQuote.LackOfKnowledge; break; case "Lack of Product Choice": wo.ReasonForLostQuote = ReasonForLostQuote.LackOfProductChoice; break; case "In-House (Customer)": wo.ReasonForLostQuote = ReasonForLostQuote.InHouseCustomer; break; case "None": wo.ReasonForLostQuote = ReasonForLostQuote.None; break; case "Budgetary Estimate": wo.ReasonForLostQuote = ReasonForLostQuote.BudgetaryEstimate; break; default: Logging.RototrackErrorLog("QBMigrationTool: " + RototrackConfig.GetBuildType() + ": " + "Unknown Reason for Lost Quote"); break; } } else if (DataExtName == "Collection Status") { switch (DataExtValue) { case "Dispute - Labor Rate": wo.CollectionStatus = CollectionStatus.DisputeLaborRate; break; case "Dispute - Parts Rate": wo.CollectionStatus = CollectionStatus.DisputePartsRate; break; case "Missing - Codes": wo.CollectionStatus = CollectionStatus.MissingCodes; break; case "Missing - PO/ AFE #": wo.CollectionStatus = CollectionStatus.MissingPOAFE; break; case "Missing - Signature": wo.CollectionStatus = CollectionStatus.MissingSignature; break; case "Request - Approver Name": wo.CollectionStatus = CollectionStatus.RequestApproverName; break; case "Request - DSR Copies": wo.CollectionStatus = CollectionStatus.RequestDSRCopies; break; case "Request - Parts Receipts": wo.CollectionStatus = CollectionStatus.RequestPartsReceipts; break; case "Request - Resubmit": wo.CollectionStatus = CollectionStatus.RequestResubmit; break; case "Request - Revision per Quote": wo.CollectionStatus = CollectionStatus.RequestRevisionPerQuote; break; case "In Process": wo.CollectionStatus = CollectionStatus.InProcess; break; case "In Process - Customer Queue": wo.CollectionStatus = CollectionStatus.InProcessCustomerQueue; break; case "In Process-Cust Approve Paym": wo.CollectionStatus = CollectionStatus.InProcessCustomerApprovePayment; break; case "Paid": wo.CollectionStatus = CollectionStatus.Paid; break; case "Write-off": wo.CollectionStatus = CollectionStatus.WriteOff; break; default: Logging.RototrackErrorLog("QBMigrationTool: " + RototrackConfig.GetBuildType() + ": " + "Unknown Collection Status"); break; } } } } if (gotInvoiceDeliveryStatus && gotInvoiceDeliveryStatusDate) { // Don't update if we set it to Inactive above or if it was already set to Inactive if (wo.Status != WorkOrderStatus.Inactive) { wo.Status = WorkOrderStatus.Invoiced; } } db.SaveChanges(); } // Get parent customer c = db.Customers.First(f => f.QBListId == parentListID); } string EditSequence = CustomerRet.SelectSingleNode("./EditSequence").InnerText; c.QBEditSequence = EditSequence; if (CustomerRet.SelectSingleNode("./CompanyName") != null) { string CompanyName = CustomerRet.SelectSingleNode("./CompanyName").InnerText; c.CompanyName = CompanyName; } XmlNode BillAddress = CustomerRet.SelectSingleNode("./BillAddress"); if (BillAddress != null) { //Get value of Addr1 if (CustomerRet.SelectSingleNode("./BillAddress/Addr1") != null) { string Addr1 = CustomerRet.SelectSingleNode("./BillAddress/Addr1").InnerText; c.Address.Address1 = Addr1; } //Get value of Addr2 if (CustomerRet.SelectSingleNode("./BillAddress/Addr2") != null) { string Addr2 = CustomerRet.SelectSingleNode("./BillAddress/Addr2").InnerText; c.Address.Address2 = Addr2; } //Get value of Addr3 if (CustomerRet.SelectSingleNode("./BillAddress/Addr3") != null) { string Addr3 = CustomerRet.SelectSingleNode("./BillAddress/Addr3").InnerText; c.Address.Address3 = Addr3; } //Get value of Addr4 if (CustomerRet.SelectSingleNode("./BillAddress/Addr4") != null) { string Addr4 = CustomerRet.SelectSingleNode("./BillAddress/Addr4").InnerText; c.Address.Address4 = Addr4; } //Get value of Addr5 if (CustomerRet.SelectSingleNode("./BillAddress/Addr5") != null) { string Addr5 = CustomerRet.SelectSingleNode("./BillAddress/Addr5").InnerText; c.Address.Address5 = Addr5; } //Get value of City if (CustomerRet.SelectSingleNode("./BillAddress/City") != null) { string City = CustomerRet.SelectSingleNode("./BillAddress/City").InnerText; c.Address.City = City; } //Get value of State if (CustomerRet.SelectSingleNode("./BillAddress/State") != null) { string State = CustomerRet.SelectSingleNode("./BillAddress/State").InnerText; c.Address.State = State; } //Get value of PostalCode if (CustomerRet.SelectSingleNode("./BillAddress/PostalCode") != null) { string PostalCode = CustomerRet.SelectSingleNode("./BillAddress/PostalCode").InnerText; c.Address.Zip = PostalCode; } } //Done with field values for BillAddress aggregate // Add any new contacts (that were added to QB, or existed initially) AddNewContactsFromQB(c, CustomerRet); // Save changes to the database if (c != null) { db.SaveChanges(); } }