//get Invoices private void GetInvoicesFromServiceTrade(iDB2Command db2Command) { //Get the List of Inovices from the Service Trade List <FSTINV> InvoiceList = serviceTrade.GetInvoices(); st.insertLog("Total Invoices from Service Trade with sent status : " + InvoiceList.Count(), "Info", "NA", LogId); foreach (FSTINV inv in InvoiceList) { //For each invoice check to see if invoice already exists on the JDE side if (!InvoiceExists(db2Command, inv.SIID)) //If Invoice does not exists { //Get invoice customer's company external id inv.Customer.External = new ExternalId() { JdeId = serviceTrade.GetCompanyExternalId(inv.Customer.CompanyId) }; //Since the assigned technician is coming from the appointment endpoint, we need to make another api call //Get the Technician associated with the Invoice\ //based on Job Number inv.Technician = serviceTrade.GetTechnician(inv.Job.Number); //Get customer location's external id inv.Location.External = new ExternalId() { JdeId = serviceTrade.GetLocationExternalId(inv.Location.LocationId) }; //Get the servicing office for this invoice location inv.ServicingOffice = serviceTrade.GetServicingOffice(inv.Location.LocationId); //Get sales number tag inv.Tags = serviceTrade.GetSalesNumber(inv); //Get public comments inv.CommentsList = serviceTrade.GetInvoiceComments(inv); //Check for FPMAR if (inv.Job != null) { inv.FPMARActive = serviceTrade.GetFPMAR(inv.Job.JobId); } //Insert invoice into FSTINV table InsertInvoiceToJDE(db2Command, inv); //Check if there are comments for this invoice try { if (!string.IsNullOrEmpty(inv.Notes)) { InsertComments(db2Command, inv); } } catch { st.insertLog("The comments/notes are not in the valid format. ", "Exception Error", inv.SIID, LogId); } //Set the invoice to Pending Accouting in ST first. serviceTrade.SetInvoiceToPending(inv.SIID); //9/1/2015 JC: Only set the invoice status to pending accounting until a JDE number is assigned //Set invoice to processed in ServiceTrade //serviceTrade.SetInvoiceToProcessed(inv); } else { st.insertLog(string.Format("Invoice {0} already exists in JDE.", inv.SIID), "Info", inv.SIID.ToString(), LogId); //Set the invoice to Pending Accouting in ST first. serviceTrade.SetInvoiceToPending(inv.SIID); //9/1/2015 JC: Only set the invoice status to pending accounting until a JDE number is assigned //Set invoice to processed in ServiceTrade //inv.Status = "processed"; //serviceTrade.SetInvoiceToProcessed(inv); } } }