Ejemplo n.º 1
0
        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));
                 */
            }
        }
Ejemplo n.º 2
0
        public static void CreateGeneralJournal(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];                //Operation
                string str2 = wkLine[1];                //Company ID
                string str3 = wkLine[2];                //Company Name
                string str4 = wkLine[3];                //Street
                string str5 = wkLine[4];                //Street2
                string str6 = wkLine[5];                //Street3

                //Import to AX
                DataServiceCollection <GeneralLedgerCustInvoiceJournalHeader> generalJournalCollection     = new DataServiceCollection <GeneralLedgerCustInvoiceJournalHeader>(context);
                DataServiceCollection <GeneralLedgerCustInvoiceJournalLine>   generalJournalLineCollection = new DataServiceCollection <GeneralLedgerCustInvoiceJournalLine>(context);

                //create General Journal
                GeneralLedgerCustInvoiceJournalHeader generalJournal = new GeneralLedgerCustInvoiceJournalHeader();
                generalJournalCollection.Add(generalJournal);
                generalJournal.JournalName        = "test jn2";
                generalJournal.JournalBatchNumber = "11223";
                generalJournal.Description        = "test1";
                generalJournal.DataAreaId         = "USMF";

                GeneralLedgerCustInvoiceJournalLine generalJournalLine  = new GeneralLedgerCustInvoiceJournalLine();
                GeneralLedgerCustInvoiceJournalLine generalJournalLine2 = new GeneralLedgerCustInvoiceJournalLine();

                generalJournalLineCollection.Add(generalJournalLine);
                generalJournalLineCollection.Add(generalJournalLine2);

                generalJournalLine.InvoiceDate = new System.DateTime();
                generalJournalLine.AccountType = LedgerJournalACType.Cust;
                generalJournalLine.CustomerAccountDisplayValue = "test0001";
                generalJournalLine.JournalBatchNumber          = "11223";
                generalJournalLine.Company                   = "usmf";
                generalJournalLine.DebitAmount               = 100;
                generalJournalLine.OffsetAccountType         = LedgerJournalACType.Ledger;
                generalJournalLine.OffsetAccountDisplayValue = "----";
                generalJournalLine.MethodOfPayment           = "CHECK";
                generalJournalLine.OffsetCompany             = "usmf";
                generalJournalLine.InvoiceId                 = "test2";
                generalJournalLine.Currency                  = "USD";
                generalJournalLine.DataAreaId                = "USMF";
                generalJournalLine.ApprovedBy                = "test";
                generalJournalLine.Approved                  = NoYes.Yes;

                Console.WriteLine(string.Format("LedgerJournalACType.Vend {0} - !", (int)(LedgerJournalACType.Vend)));
                generalJournalLine2.InvoiceDate = new System.DateTime();
                generalJournalLine2.AccountType = LedgerJournalACType.Vend;
                generalJournalLine2.CustomerAccountDisplayValue = "----";
                generalJournalLine2.JournalBatchNumber          = "11223";
                generalJournalLine2.Company                   = "usmf";
                generalJournalLine2.CreditAmount              = 100;
                generalJournalLine2.OffsetAccountType         = LedgerJournalACType.Ledger;
                generalJournalLine2.OffsetAccountDisplayValue = "----";
                generalJournalLine2.OffsetCompany             = "usmf";
                //generalJournalLine2.InvoiceId = "afeafe";
                generalJournalLine2.Currency   = "USD";
                generalJournalLine2.DataAreaId = "USMF";

                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 !", wkLine[1]));
            }
        }
Ejemplo n.º 3
0
        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));
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            System.Threading.Mutex mtx = null;

            //connect to D365
            var context = ImportCommon.Connect();

            //read config
            string strFilePath    = ImportCommon.GetAppSetting(BusinessConst.CSV_FILE_PATH);
            string strSuccessPath = ImportCommon.GetAppSetting(BusinessConst.SUC_FILE_PATH);
            string strErrorPath   = ImportCommon.GetAppSetting(BusinessConst.ERR_FILE_PATH);
            string strLogPath     = ImportCommon.GetAppSetting(BusinessConst.LOG_FILE_PATH);

            //log file
            StringBuilder logMsg      = new System.Text.StringBuilder();
            string        strLogName  = ImportCommon.GetLogFileName(BusinessConst.REDAC_NAME_INVOICE);
            string        strfileName = "";
            int           iFileCnt    = 0;

            Console.WriteLine("logName : {0}", strLogName);
            Console.WriteLine("FilePath :  {0}", strFilePath);

            //mail set
            Console.WriteLine("mail setting :::");
            EmailConf emailConf = new EmailConf();

            try
            {
                string mutextName = "SanImportAccountCsv";

                mtx = new System.Threading.Mutex(false, mutextName);

                mtx.WaitOne();

                //open file
                ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, BusinessConst.LOG_ST);
                IEnumerable <System.IO.FileInfo> targetCsvfiles = ImportCommon.GetCsvFile(strFilePath);

                Console.WriteLine("start loop  ");

                //import data
                foreach (System.IO.FileInfo targetCsvfile in targetCsvfiles)
                {
                    iFileCnt++;
                    strfileName = targetCsvfile.Name;
                    ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, "File name:" + targetCsvfile.Name);
                    Console.WriteLine("strfileName : {0}", strfileName);

                    //write import data
                    List <string> accRecords = ImportCommon.WriteCsvFile(targetCsvfile);

                    var wkLine = ImportCommon.TrimDoubleQuotationMarks(accRecords[1].Replace("\",\"", "\t")).Split('\t');
                    Console.WriteLine("create customer : ");

                    string comId = wkLine[25];
                    if (wkLine[27].Equals("Tenant"))
                    {
                        comId = comId.Replace(",", "");
                    }

                    if (SanODataQuerys.CheckByCustomId(context, comId))
                    {
                        SanODataChangesets.CreateCustomAdv(wkLine, context);
                    }
                    else
                    {
                        Console.WriteLine("customer aleady exist: ");
                        SanODataChangesets.AddCustomAddress(wkLine, context);
                    }

                    Console.WriteLine("create journal : ");
                    SanODataChangesets.CreateGeneralJournalAdv(accRecords, context, logMsg);
                    Console.WriteLine("create done !!");

                    //move file
                    ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, "Done:" + strfileName);
                    ImportCommon.MoveCsvFile(strFilePath + "/" + strfileName, strSuccessPath + "/" + strfileName);
                }


                ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, "File count:" + iFileCnt);
                ImportCommon.Writelog(logMsg, BusinessConst.LOG_INFO, BusinessConst.LOG_EN);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("err somthing  : {0}", e.InnerException);
                //move file
                ImportCommon.Writelog(logMsg, BusinessConst.LOG_ERROR, "Detail1:" + e.Message);
                ImportCommon.Writelog(logMsg, BusinessConst.LOG_ERROR, "Detail2:" + e.InnerException);
                ImportCommon.MoveCsvFile(strFilePath + "/" + strfileName, strErrorPath + "/" + strfileName);

                SendEmail email = new SendEmail(emailConf);
                email.SendException(e, strLogName);

                if (mtx != null)
                {
                    mtx.ReleaseMutex();
                    mtx = null;
                }
            }
            finally
            {
                Console.WriteLine("check log : {0} ", logMsg.ToString());
                if (iFileCnt > 0)
                {
                    ImportCommon.CreatelogFile(strLogPath + "/" + strLogName, logMsg.ToString());
                }
                Console.WriteLine("end  ");

                if (mtx != null)
                {
                    mtx.ReleaseMutex();
                }
            }
        }