public static void CreateGeneralJournalAdv(List <string> accRecords, Resources context, StringBuilder logMsg) { for (int i = 1; i < accRecords.Count; i++) { ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, "Line" + i + ":" + ImportCommon.TrimDoubleQuotationMarks(accRecords[i].Replace("\",\"", "\t"))); var wkLine = ImportCommon.TrimDoubleQuotationMarks(accRecords[i].Replace("\",\"", "\t")).Split('\t'); string str1 = wkLine[0]; //Order No string str2 = wkLine[1]; //Advanced Payment ID string str3 = wkLine[2]; //Submit Date string str4 = wkLine[3]; //Payment Date string str5 = wkLine[4]; //Payment Time string str6 = wkLine[5]; //Total Amount string str7 = wkLine[6]; //Redac Division string str8 = wkLine[7]; //Parent Redac Division string str9 = wkLine[8]; //Tenant Name string str10 = wkLine[9]; //Company Name string str11 = wkLine[10]; //Street string str12 = wkLine[11]; //Street2 string str13 = wkLine[12]; //Street3 string str14 = wkLine[13]; //City string str15 = wkLine[14]; //US State string str16 = wkLine[15]; //ZIP/Postal code string str17 = wkLine[16]; //Country string str18 = wkLine[17]; //Main Phone string str19 = wkLine[18]; //Fax string str20 = wkLine[19]; //Email string str21 = wkLine[20]; //Purpose string str22 = wkLine[21]; //Amount string str23 = wkLine[22]; //Advance/Expense string str24 = wkLine[23]; //Payable to string str25 = wkLine[24]; //Payment Method string str26 = wkLine[25]; //Company ID string str27 = wkLine[26]; //Type string str28 = wkLine[27]; //CustomerGroup string strvendNum = ""; string strInvoice = str2 + "-" + i; Console.WriteLine("create vendor : "); strvendNum = SanODataQuerys.CheckByVendorId(context, str2, str24); if (strvendNum.Length == 0) { strvendNum = CreateVendor(wkLine, context, i); } else { Console.WriteLine("vendor aleady exist: "); } //Import to AX DataServiceCollection <LedgerJournalHeader> generalJournalCollection = new DataServiceCollection <LedgerJournalHeader>(context); //create General Journal header LedgerJournalHeader generalJournal = new LedgerJournalHeader(); generalJournalCollection.Add(generalJournal); generalJournal.JournalName = ConfigurationManager.AppSettings["JournalName"]; //Description [Advanced Payment ID]+[Line#] / [Submit Date] / [Amount] / [Purpose] string strDescription = strInvoice + "/" + str3.Replace("/", "-") + "/" + decimal.Parse(str22).ToString("0.00") + "/" + str21; generalJournal.Description = strDescription; generalJournal.DataAreaId = ConfigurationManager.AppSettings["RedacCompany"]; DataServiceResponse res1 = null; res1 = context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset); string strJournalbatch = ""; foreach (ChangeOperationResponse change in res1) { // Get the descriptor for the entity. EntityDescriptor descriptor = change.Descriptor as EntityDescriptor; if (descriptor != null) { LedgerJournalHeader LedgerJournalres = descriptor.Entity as LedgerJournalHeader; if (LedgerJournalres != null) { strJournalbatch = LedgerJournalres.JournalBatchNumber; Console.WriteLine("New JournalBatchNumber {0}.", strJournalbatch); } } } //create General Journal line DataServiceCollection <LedgerJournalLine> generalJournalLineCollection = new DataServiceCollection <LedgerJournalLine>(context); LedgerJournalLine generalJournalLine = new LedgerJournalLine(); LedgerJournalLine generalJournalLine2 = new LedgerJournalLine(); generalJournalLineCollection.Add(generalJournalLine); generalJournalLineCollection.Add(generalJournalLine2); generalJournalLine.TransDate = Convert.ToDateTime(str3); generalJournalLine.AccountType = LedgerJournalACType.Cust; generalJournalLine.AccountDisplayValue = ImportCommon.Get20CustomerNum(str26).Replace(",", "").Replace("-", "\\-"); generalJournalLine.Text = str21; generalJournalLine.JournalBatchNumber = strJournalbatch; generalJournalLine.Company = ConfigurationManager.AppSettings["RedacCompany"]; generalJournalLine.DebitAmount = Convert.ToDecimal(str22); generalJournalLine.OffsetAccountType = LedgerJournalACType.Ledger; generalJournalLine.OffsetAccountDisplayValue = "----"; generalJournalLine.OffsetCompany = ConfigurationManager.AppSettings["RedacCompany"]; generalJournalLine.Invoice = strInvoice; generalJournalLine.CurrencyCode = ConfigurationManager.AppSettings["Currency"]; generalJournalLine.DataAreaId = ConfigurationManager.AppSettings["RedacCompany"]; generalJournalLine.PostingProfile = ConfigurationManager.AppSettings["AdvancedPostingCustomer"]; Console.WriteLine(string.Format("LedgerJournalACType.Vend {0} - !", (int)(LedgerJournalACType.Vend))); generalJournalLine2.AccountType = LedgerJournalACType.Vend; generalJournalLine2.AccountDisplayValue = strvendNum.Replace("-", "\\-"); generalJournalLine2.JournalBatchNumber = strJournalbatch; generalJournalLine2.Company = ConfigurationManager.AppSettings["RedacCompany"]; generalJournalLine2.CreditAmount = Convert.ToDecimal(str22); generalJournalLine2.OffsetAccountType = LedgerJournalACType.Ledger; generalJournalLine2.OffsetAccountDisplayValue = "----"; generalJournalLine2.PaymentMethod = ConfigurationManager.AppSettings[str25]; generalJournalLine2.DueDate = Convert.ToDateTime(str4); generalJournalLine2.OffsetCompany = ConfigurationManager.AppSettings["RedacCompany"]; generalJournalLine2.Invoice = strInvoice; generalJournalLine2.CurrencyCode = ConfigurationManager.AppSettings["Currency"]; generalJournalLine2.DataAreaId = ConfigurationManager.AppSettings["RedacCompany"]; generalJournalLine2.PostingProfile = ConfigurationManager.AppSettings["AdvancedPostingVendor"]; context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset); // Batch with Single Changeset ensure the saved changed runs in all-or-nothing mode. Console.WriteLine(string.Format("Invoice {0} - Saved !", strJournalbatch)); //SimpleCRUDExamples.GjUpd(context, strJournalbatch); //create General Journal line /* * DataServiceCollection<GeneralLedgerCustInvoiceJournalLine> generalInvoiceCollection = new DataServiceCollection<GeneralLedgerCustInvoiceJournalLine>(context); * GeneralLedgerCustInvoiceJournalLine generalInvoiceLine = new GeneralLedgerCustInvoiceJournalLine(); * generalInvoiceCollection.Add(generalInvoiceLine); * * Console.WriteLine(string.Format("approve Line start - !")); * generalInvoiceLine.JournalBatchNumber = strJournalbatch; * generalInvoiceLine.ApprovedBy = "000728"; * generalInvoiceLine.Approved = NoYes.Yes; * * context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset); // Batch with Single Changeset ensure the saved changed runs in all-or-nothing mode. * Console.WriteLine(string.Format("VendInvoice {0} - Saved !", strJournalbatch)); */ } }
public static void CreateGeneralJournalInv(List <string> accRecords, Resources context, StringBuilder logMsg) { for (int i = 1; i < accRecords.Count; i++) { ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, "Line" + i + ":" + ImportCommon.TrimDoubleQuotationMarks(accRecords[i].Replace("\",\"", "\t"))); var wkLine = ImportCommon.TrimDoubleQuotationMarks(accRecords[i].Replace("\",\"", "\t")).Split('\t'); string str1 = wkLine[0]; //Order No string str2 = wkLine[1]; //Invoice No string str3 = wkLine[2]; //Invoice Date string str4 = wkLine[3]; //Total Amount string str5 = wkLine[4]; //Attention Salutation string str6 = wkLine[5]; //Attention string str7 = wkLine[6]; //Redac Attention string str8 = wkLine[7]; //Redac Division string str9 = wkLine[8]; //Invoice To string str10 = wkLine[9]; //Invoice To Onwer/Other Name string str11 = wkLine[10]; //Street string str12 = wkLine[11]; //Street2 string str13 = wkLine[12]; //Street3 string str14 = wkLine[13]; //City string str15 = wkLine[14]; //US State string str16 = wkLine[15]; //ZIP/Postal code string str17 = wkLine[16]; //Country string str18 = wkLine[17]; //Amount string str19 = wkLine[18]; //Description string str20 = wkLine[19]; //Paid to string str21 = wkLine[20]; //Remarks string str22 = wkLine[21]; //Div code string str23 = wkLine[22]; //Business string str24 = wkLine[23]; //State string str25 = wkLine[24]; //Local string str26 = wkLine[25]; //PL string str27 = wkLine[26]; //Main Phone string str28 = wkLine[27]; //Fax string str29 = wkLine[28]; //Email string str30 = wkLine[29]; //Company ID string str31 = wkLine[30]; //Type string str32 = wkLine[31]; //CustomerGroup //set OffsetAccountDisplayValue string strOffsetAccount = ""; string strInvoice = str2 + "-" + i; if (str19.Equals("Relocation Service Fee") || str19.Equals("Owner's Pay")) { //strOffsetAccount = "40140-IR-Los Angeles-CA-Irvine"; strOffsetAccount = ConfigurationManager.AppSettings["InvoiceLedger"] + "-" + str22 + "-" + str26 + "-" + str24 + "-" + str25; } else { strOffsetAccount = ConfigurationManager.AppSettings["InvoiceLedgerOther"] + "-" + str22 + "-" + str26 + "-" + str24 + "-" + str25; //account-Div code-PL-State-Local //strOffsetAccount = "40140-IR-Los Angeles-CA-Irvine"; } //create General Journal Header DataServiceCollection <LedgerJournalHeader> generalJournalCollection = new DataServiceCollection <LedgerJournalHeader>(context); LedgerJournalHeader generalJournal = new LedgerJournalHeader(); generalJournalCollection.Add(generalJournal); generalJournal.JournalName = ConfigurationManager.AppSettings["JournalName"]; //Description [Invoice ID]+[Line#] / [Submit Date] / [Amount] / [Purpose] string strDescription = strInvoice + "/" + str3.Replace("/", "-") + "/" + decimal.Parse(str18).ToString("0.00") + "/" + str19; generalJournal.Description = strDescription; generalJournal.DataAreaId = ConfigurationManager.AppSettings["RedacCompany"]; DataServiceResponse res1 = null; res1 = context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset); string strJournalbatch = ""; foreach (ChangeOperationResponse change in res1) { // Get the descriptor for the entity. EntityDescriptor descriptor = change.Descriptor as EntityDescriptor; if (descriptor != null) { LedgerJournalHeader LedgerJournalres = descriptor.Entity as LedgerJournalHeader; if (LedgerJournalres != null) { strJournalbatch = LedgerJournalres.JournalBatchNumber; Console.WriteLine("New JournalBatchNumber {0}.", strJournalbatch); } } } //create General Journal Line DataServiceCollection <LedgerJournalLine> generalJournalLineCollection = new DataServiceCollection <LedgerJournalLine>(context); LedgerJournalLine generalJournalLine = new LedgerJournalLine(); generalJournalLineCollection.Add(generalJournalLine); generalJournalLine.TransDate = Convert.ToDateTime(str3); generalJournalLine.AccountType = LedgerJournalACType.Cust; if (str32.Equals("Tenant")) { generalJournalLine.AccountDisplayValue = ImportCommon.Get20CustomerNum(str30).Replace(",", "").Replace("-", "\\-"); } else { generalJournalLine.AccountDisplayValue = ImportCommon.Get20CustomerNum(str30).Replace("-", "\\-"); } generalJournalLine.Text = str19; generalJournalLine.JournalBatchNumber = strJournalbatch; generalJournalLine.Company = ConfigurationManager.AppSettings["RedacCompany"]; generalJournalLine.DebitAmount = Convert.ToDecimal(str18); generalJournalLine.OffsetAccountType = LedgerJournalACType.Ledger; generalJournalLine.OffsetAccountDisplayValue = strOffsetAccount; generalJournalLine.OffsetCompany = ConfigurationManager.AppSettings["RedacCompany"]; generalJournalLine.Invoice = strInvoice; generalJournalLine.CurrencyCode = ConfigurationManager.AppSettings["Currency"]; generalJournalLine.DataAreaId = ConfigurationManager.AppSettings["RedacCompany"]; generalJournalLine.PostingProfile = ConfigurationManager.AppSettings["InvoicePostingcustomer"]; context.SaveChanges(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithSingleChangeset); // Batch with Single Changeset ensure the saved changed runs in all-or-nothing mode. Console.WriteLine(string.Format("Invoice {0} - Saved !", str3)); } }