public string GetQuickbooksInvoice(string quickbooksProject, DateTime fromDate, DateTime toDate, string username, bool useProjectName, int nextInvoice) { // Get the data var fileHeader = _db.GetInvoiceHeader(fromDate, toDate, quickbooksProject); var invoiceHeaders = _db.GetInvoiceEntries(fromDate, toDate, quickbooksProject, useProjectName); // Build the file var sb = new StringBuilder(); sb.AppendLine("!TRNS TRNSID TRNSTYPE DATE ACCNT NAME CLASS AMOUNT DOCNUM MEMO CLEAR TOPRINT NAMEISTAXABLE ADDR1 ADDR3 TERMS SHIPVIA SHIPDATE"); sb.AppendLine("!SPL SPLID TRNSTYPE DATE ACCNT NAME CLASS AMOUNT DOCNUM MEMO CLEAR QNTY PRICE INVITEM TAXABLE OTHER3 YEARTODATE WAGEBASE"); sb.AppendLine("!ENDTRNS "); sb.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}\t{16}\t{17}\r\n", "TRNS", "", "INVOICE", toDate.ToString("MM/dd/yyyy"), "Accounts Receivable", quickbooksProject, "", Math.Round(fileHeader.Total.HasValue ? fileHeader.Total.Value : 0, 2), nextInvoice, "", "N", "N", "N", "", "", fileHeader.BillingTermsDescription, "", toDate.ToString("MM/dd/yyyy")); // Add the invoice headers foreach (var entry in invoiceHeaders) { sb.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}\t{16}\t{17}\r\n", "SPL", "", "INVOICE", entry.DateWorked, "Sales - Support and Maintenance", "", "", entry.Amount * -1, "", entry.Description, "N", entry.Hours * -1, Math.Round(entry.Rate, 2), "Programming - Standard", "N", "Darren Boss", "0", "0"); } sb.AppendLine("ENDTRNS "); return(sb.ToString()); }