public void Init()
        {
            try
            {
                _accountSvc = new AccountSvc();

                _accountSvc.Configuration.Url = ConfigurationSettings.AppSettings.Get("Url");

                //fill these only if they haven't been loaded from Avalara.AvaTax.Adapter.dll.config
                //if (_addressSvc.Configuration.Security.Account == null || _addressSvc.Configuration.Security.Account.Length == 0)
                //{
                _accountSvc.Configuration.Security.Account  = ConfigurationSettings.AppSettings.Get("account");
                _accountSvc.Configuration.Security.UserName = ConfigurationSettings.AppSettings.Get("UserName");
                //}
                //if (_addressSvc.Configuration.Security.Key == null || _addressSvc.Configuration.Security.Key.Length == 0)
                //{
                _accountSvc.Configuration.Security.License  = ConfigurationSettings.AppSettings.Get("key");
                _accountSvc.Configuration.Security.Password = ConfigurationSettings.AppSettings.Get("Password");
                //}

                //_addressSvc.Configuration.Security.Timeout = Convert.ToInt32(ConfigurationSettings.AppSettings.Get("timeout"));
                _accountSvc.Profile.Client = "NUnit AccountSvcTest";
                _accountSvc.Profile.Name   = "";
            }
            catch (Exception ex)
            {
                Assert.Fail("AccountSvc failed creation: " + ex.Message + " : " + ex.StackTrace);
            }
        }
        /// <summary>
        /// 获取所有详细分类(包括税费)
        /// </summary>
        /// <returns></returns>
        /// <summary>
        public string GetAllSonType()
        {
            var typeList = new AccountSvc().GetAllSonType(Session["CurrentCompanyGuid"].ToString());
            var strJson  = ConvertToSelectJson(typeList, "ExpenseType", "ExpenseType");

            return(strJson.ToString());
        }
        public string UpdateUsingThLA()
        {
            bool   result   = false;
            string msg      = string.Empty;
            string jsonData = (Request.Form["jsonData3"]).ToString();
            List <T_GeneralLedgerAccount> List = Newtonsoft.Json.JsonConvert.DeserializeObject <List <T_GeneralLedgerAccount> >(jsonData);

            if (List.Count > 0)
            {
                for (int i = 0; i < List.Count; i++)
                {
                    result = new AccountSvc().UpdateUsingThLA(List[i].TDA_GUID, List[i].ParentAccGuid, List[i].State, Session["CurrentCompanyGuid"].ToString());
                }
            }


            if (result)
            {
                msg = General.Resource.Common.Success;
            }
            else
            {
                msg = General.Resource.Common.Failed;
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
        public string GetAllDetailSubject(string Name)
        {
            var List    = new AccountSvc().GetDetailLAByName(Name, Session["CurrentCompanyGuid"].ToString(), "");
            var strJson = new JavaScriptSerializer().Serialize(List);

            return(strJson.ToString());
        }
        public string GetLAccount(string Name, string State)
        {
            int AccGroup = 0;

            switch (Name)
            {
            case "Assets":
                AccGroup = 1;
                break;

            case "Liabilities":
                AccGroup = 2;
                break;

            case "OwnerEquity":
                AccGroup = 4;
                break;

            case "Cost":
                AccGroup = 5;
                break;

            case "IncomeStatement":
                AccGroup = 6;
                break;

            default:
                break;
            }
            List <T_GeneralLedgerAccount> List = new AccountSvc().GetLedgerAccount(AccGroup, Session["CurrentCompanyGuid"].ToString(), State);
            string json = new JavaScriptSerializer().Serialize(List);

            return(json);
        }
        public string GetLAByName(string Name)
        {
            T_GeneralLedgerAccount GL = new AccountSvc().GetLAByName(Name, Session["CurrentCompanyGuid"].ToString());
            string json = new JavaScriptSerializer().Serialize(GL);

            return(json);
        }
        public string GetLAccountList()
        {
            List <T_GeneralLedgerAccount> List = new AccountSvc().GetLedgerAccount(Session["CurrentCompanyGuid"].ToString());
            string json = new JavaScriptSerializer().Serialize(List);

            return(json);
        }
        private static void AddNexus(AccountSvc svc, int companyId)
        {
            FetchRequest nexusFetch = new FetchRequest();
            nexusFetch.Filters = "CompanyId=" + companyId;

            nexusFetch.Filters = "CompanyId=1,EndDate='12/31/9999'";//Gets master list of possible nexus
            NexusFetchResult databaseNexus = svc.NexusFetch(nexusFetch);

            Nexus[] to_add = {databaseNexus.Nexuses[2], databaseNexus.Nexuses[7], databaseNexus.Nexuses[10] }; //I've just selected some values to add at random, this would be informed by your user input matched against the master list to find the
                                                // correct jurisdiction. You should compare the Nexus.JurisName. You don't have to add US nexus to add states throught the API, it adds the country nexus automatically.

            foreach (Nexus n in to_add)
            {
                Nexus newNexus = new Nexus();
                newNexus = n;
                newNexus.CompanyId = companyId;
                newNexus.NexusId = 0; //Always set to 0 for a new nexus, otherwise use the fetched NexusId value to edit an existing nexus.
                newNexus.EffDate = DateTime.Today.AddYears(-1); //I'm setting the default start/end dates the same way the Admin Console will, user should specify.
                newNexus.EndDate = DateTime.MaxValue;
                newNexus.LocalNexusTypeId = LocalNexusTypeId.Selected; //This may vary based on the jurisdiction and needs of the client.
                NexusSaveResult res = svc.NexusSave(newNexus);
                if (res.ResultCode.Equals(SeverityLevel.Success))
                {
                    Console.WriteLine("Nexus saved for: " + newNexus.JurisName);
                }
                else{
                    Console.WriteLine("Nexus NOT saved for: " + newNexus.JurisName +
                        " //Error: " + res.Messages[0].Summary);
                }
            }
        }
        public string GetALLThSubject(string parentAccGuid)
        {
            var List    = new AccountSvc().GetThByID(parentAccGuid, Session["CurrentCompanyGuid"].ToString());
            var strJson = ConvertToSelectJson(List, "Name", "TDA_GUID");

            return(strJson.ToString());
        }
        public string GetThirdDetailLAccount(string strParentID, string State)
        {
            List <T_GeneralLedgerAccount> List = new AccountSvc().GetThirdLedgerAccount(strParentID, Session["CurrentCompanyGuid"].ToString(), State);
            string json = new JavaScriptSerializer().Serialize(List);

            return(json);
        }
        public string GetDetailLAccountByName1(string Name)
        {
            List <T_GeneralLedgerAccount> List = new AccountSvc().GetDetailLAByName(Name, Session["CurrentCompanyGuid"].ToString(), "1");
            string json = new JavaScriptSerializer().Serialize(List);

            return(json);
        }
        public string GetDetailSubject(string Name)
        {
            var List    = new AccountSvc().GetDetailLAByName(Name, Session["CurrentCompanyGuid"].ToString(), "1");
            var strJson = ConvertToSelectJson(List, "Name", "DA_GUID");

            return(strJson.ToString());
        }
        public string GetParentGuid(string id)
        {
            T_GeneralLedgerAccount GL = new AccountSvc().GetParentGuid(id);
            string json = new JavaScriptSerializer().Serialize(GL);

            return(json);
        }
        public string GetThirdByName(string Name, string strType)
        {
            var List    = new AccountSvc().GetThirdLAByName(Name, Session["CurrentCompanyGuid"].ToString(), strType);
            var strJson = ConvertToSelectJson(List, "Name", "TDA_GUID");

            return(strJson.ToString());
        }
        public void Init()
        {
            try
            {
                _accountSvc = new AccountSvc();

                _accountSvc.Configuration.Url = ConfigurationSettings.AppSettings.Get("Url");           //"http://117.195.94.233/avaservice";

                //fill these only if they haven't been loaded from Avalara.AvaTax.Adapter.dll.config
                //if (_addressSvc.Configuration.Security.Account == null || _addressSvc.Configuration.Security.Account.Length == 0)
                //{
                //_accountSvc.Configuration.Security.Account = ConfigurationSettings.AppSettings.Get("account");
                _accountSvc.Configuration.Security.UserName = "******"; //"*****@*****.**"; //"*****@*****.**";// ConfigurationSettings.AppSettings.Get("UserName");
                //}
                //if (_addressSvc.Configuration.Security.Key == null || _addressSvc.Configuration.Security.Key.Length == 0)
                //{
                //_accountSvc.Configuration.Security.License = ConfigurationSettings.AppSettings.Get("key");
                _accountSvc.Configuration.Security.Password = "******";//"Avalara`1#";// ConfigurationSettings.AppSettings.Get("Password");
                //}

                //_addressSvc.Configuration.Security.Timeout = Convert.ToInt32(ConfigurationSettings.AppSettings.Get("timeout"));
                _accountSvc.Profile.Client = "NUnit AccountSvcTest";
                _accountSvc.Profile.Name   = "";
            }
            catch (Exception ex)
            {
                Assert.Fail("AccountSvc failed creation: " + ex.Message + " : " + ex.StackTrace);
            }
        }
예제 #16
0
        public static List <InMemoryUser> Get()
        {
            var userList = new AccountSvc().GetFullList();
            var users    = SysAccountToUser(userList);

            return(users);
        }
        /// <summary>
        /// 删除总账科目
        /// </summary>
        /// <param name="id">总账科目标识</param>
        /// <returns></returns>
        public string DelLedgerAcc(string id)
        {
            bool   result = new AccountSvc().DelLedgerAcc(id);
            string msg    = result ? General.Resource.Common.Success : General.Resource.Common.Failed;

            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
        public static Company CreateCompany(AccountSvc _accountSvc, int accountId, bool isSST = false)
        {
            var companyContact = new CompanyContact
            {
                CompanyContactCode = "001",
                FirstName          = "testfirstname",
                LastName           = "testlastname",
                Line1        = "700 Pike St",
                City         = "Seattle",
                Region       = "WA",
                PostalCode   = "98101",
                Phone        = "1-877-780-4848",
                Email        = "*****@*****.**",
                CreatedDate  = DateTime.UtcNow,
                ModifiedDate = DateTime.UtcNow
            };

            var company = new Company
            {
                AccountId            = accountId,
                CompanyCode          = Guid.NewGuid().ToString("N").Substring(0, 25),
                CompanyName          = "TEST::" + Guid.NewGuid().ToString("N"),
                CompanyId            = 0,
                IsActive             = true,
                HasProfile           = true,
                IsReportingEntity    = true,
                CreatedDate          = DateTime.UtcNow,
                ModifiedDate         = DateTime.UtcNow,
                RoundingLevelId      = RoundingLevelId.Document,
                DefaultCountry       = "US",
                IsTest               = false,
                TaxDependencyLevelId = TaxDependencyLevelId.Document,
                IsDefault            = false,
                TIN = "123457777"
            };

            if (isSST)
            {
                company.SSTEffDate = DateTime.UtcNow.AddYears(-10);
                company.SSTPID     = "Test";
            }
            company.Contacts.Add(companyContact);

            CompanySaveResult result = _accountSvc.CompanySave(company);

            if (result.ResultCode != SeverityLevel.Success)
            {
                foreach (Message message in result.Messages)
                {
                    Console.WriteLine(message.Summary);
                }

                return(null);
            }

            company.CompanyId = result.CompanyId;
            return(company);
        }
        /// <summary>
        /// 更新使用的总账科目
        /// </summary>
        /// <param name="accCodes">总账科目代码串</param>
        /// <returns></returns>
        public string UpdUsingLedgerAcc(string accCodes)
        {
            bool   result = new AccountSvc().UpdUsingLedgerAcc(accCodes.Trim(','), Session["CurrentCompanyGuid"].ToString());
            string msg    = string.Empty;

            if (result)
            {
                msg = General.Resource.Common.Success;
            }
            else
            {
                msg = General.Resource.Common.Failed;
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
예제 #20
0
        /// <summary>
        /// 删除明细科目
        /// </summary>
        /// <param name="id">明细科目标识</param>
        /// <returns></returns>
        public string DelDetailedAccount(string id)
        {
            bool   result = new AccountSvc().DelDetailedAccount(id);
            string msg    = string.Empty;

            if (result)
            {
                msg = General.Resource.Common.Success;
            }
            else
            {
                msg = General.Resource.Common.Failed;
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
        public string AddSubject(string strParentID, int AccCode, string Name, string Subject)
        {
            bool   result = false;
            string msg    = string.Empty;

            result = new AccountSvc().AddSubject(strParentID, AccCode, Name, Subject, Session["CurrentCompanyGuid"].ToString());
            if (result)
            {
                msg = General.Resource.Common.Success;
            }
            else
            {
                msg = General.Resource.Common.Failed;
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
        ///<summary>
        ///验证科目余额
        ///</summary>
        public string CheckSubAmount(string RPer, string SubName, string Amount)
        {
            string C_GUID = Session["CurrentCompanyGuid"].ToString();
            var    result = AccountSvc.CheckSubjectAmount(RPer, SubName, C_GUID, Amount);
            string msg    = string.Empty;

            if (result == 1)
            {
                msg = "符合";
            }
            else
            {
                msg = "输入金额大于科目余额";
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
        /// <summary>
        /// 更新总账科目信息
        /// </summary>
        /// <param name="acc">总账科目对象</param>
        /// <returns></returns>
        public string UpdLedgerAcc(T_GeneralLedgerAccount acc)
        {
            AccountSvc svc    = new AccountSvc();
            bool       result = false;
            string     msg    = string.Empty;
            List <T_GeneralLedgerAccount> accs = svc.GetLedgerAccounts(Session["CurrentCompanyGuid"].ToString());

            if (accs.Any(i => !i.LA_GUID.Equals(acc.LA_GUID) && i.AccCode.Equals(acc.AccCode)))
            {
                msg = FMS.Resource.Account.Account.AccExisted;
            }
            else
            {
                result = svc.UpdLedgerAcc(acc);
                msg    = result ? General.Resource.Common.Success : General.Resource.Common.Failed;
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
예제 #24
0
        /// <summary>
        /// 获取用户的总账科目
        /// </summary>
        /// <param name="accGrp">科目分组标识</param>
        /// <returns></returns>
        public string GetUserLedgerAccount(string accGrp = null)
        {
            string        strFormatter         = "{{\"text\":\"{0}\",\"value\":\"{1}\",\"Group\":\"{2}\",\"Code\":\"{3}\"}},";
            StringBuilder strJson              = new StringBuilder("[ ");
            List <T_GeneralLedgerAccount> accs =
                new AccountSvc().GetUserLedgerAccounts(Session["CurrentCompany"].ToString());

            if (!string.IsNullOrEmpty(accGrp))
            {
                IEnumerable <int> accGrps = accGrp.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Cast <int>();
                accs = accs.Where(i => accGrps.Contains(i.AccGroup)).ToList();
            }
            foreach (T_GeneralLedgerAccount item in accs)
            {
                strJson.AppendFormat(strFormatter, item.Name, item.LA_GUID, item.AccGroup, item.AccCode);
            }
            strJson.Remove(strJson.Length - 1, 1);
            strJson.Append("]");
            return(strJson.ToString());
        }
        //You might want to create a company-specific user login for the company in question.
        private static void AddUser(AccountSvc svc, int companyId, int accountId)
        {
            User newUser = new User();
            newUser.CompanyId = companyId;
            newUser.AccountId = accountId;

            newUser.Email = "*****@*****.**";//Should be merchant/client user email
            newUser.FirstName = "Anya";
            newUser.LastName = "Stettler";
            newUser.UserName = "******"+DateTime.Now; //Must be unique within the Avalara server - we usually use email address. I've added a timestamp here for testing.
            newUser.PostalCode = "98110"; //Not required, but improves user experience (as postal code is required to perform a password reset)

            newUser.SecurityRoleId = SecurityRoleId.CompanyAdmin; //This will give the user access to the specified company ONLY, and will allow them to change profile settings, etc. for that company.
            newUser.IsActive = true;

            UserSaveResult res = new UserSaveResult();
            try
            {
                res = svc.UserSave(newUser); //Save the user
                if (res.ResultCode.Equals(SeverityLevel.Success))
                {
                    Console.WriteLine("User saved successfully. UserId: " + res.UserId);
                }
                else
                {
                    Console.WriteLine("Error when saving user. Error: " + res.Messages[0].Summary);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error in UserSave: " + ex);
            }

            //By default, a new user is assigned a password (which is emailed to them). They are required to change this password upon first login to the admin console.
            //If you want to eliminate all contact with the Admin Console, you'll need to reset the password programatically.
            //Note: this kicks off an email to the user email address notifying them that someone has changed their account.
            newUser.UserId = res.UserId;
            newUser.PasswordStatusId = PasswordStatusId.UserCanChange; //This removes the "must change" property
            newUser.Password = "******";
            res = svc.UserSave(newUser);
        }
예제 #26
0
        public AccountFixture()
        {
            MainBus = new Dispatcher("Test bus");

            ConnectToLiveES();

            _streamNameBuilder = new PrefixedCamelCaseStreamNameBuilder("upgrade");

            _getListener = name => new Model.Foundation.StreamListener(
                listenerName: name,
                eventStoreConnection: Connection,
                streamNameBuilder: _streamNameBuilder,
                serializer: new JsonMessageSerializer());

            // Build event store repository
            Repo = new StreamStoreRepository(
                streamNameBuilder: _streamNameBuilder,
                eventStoreConnection: Connection,
                eventSerializer: new JsonMessageSerializer());

            var _ = new AccountSvc(MainBus, Repo);
        }
예제 #27
0
        /// <summary>
        /// Stops the monitoring clock.
        /// </summary>
        public void Stop(AccountSvc svc, ref Proxies.AccountSvcProxy.ProxyUserFetchResult result)
        {
            _end = DateTime.Now;

            if (!_running)
            {
                throw new ApplicationException("An attempt was made to stop the performance timekeeper that was not running. Call the Start method prior to calling Stop method.");
            }
            try
            {
                if (Utilities.HasClientMetricMessage(result.Messages))
                {
                    //call Ping Method and send ClientMetric
                    //Sample Entry - ClientMetrics:17849,ClientDuration,1500
                    svc.Ping(Utilities.BuildAuditMetrics("", result.TransactionId, _end.Subtract(_start).Milliseconds));
                }
            }
            catch (Exception ex)
            {
                _avaLog.Error(string.Format("Error sending ClientMetrics: {0}", ex.Message));
            }
            _running = false;
        }
예제 #28
0
        /// <summary>
        /// 更新明细科目
        /// </summary>
        /// <param name="acc">明细科目对象</param>
        /// <returns></returns>
        public string UpdDetailedAccount(T_DetailedAccount acc, string flag, string cname)
        {
            if (flag == "1")
            {
                acc.D_GUID = acc.Name;
                acc.Name   = cname;
            }
            AccountSvc svc                = new AccountSvc();
            bool       result             = false;
            string     msg                = string.Empty;
            List <T_DetailedAccount> accs = svc.GetDetailsAccs(Session["CurrentCompany"].ToString());

            if (accs.Any(i => !i.DA_GUID.Equals(acc.DA_GUID) && i.AccCode.Equals(acc.AccCode)))
            {
                msg = FMS.Resource.Account.Account.AccExisted;
            }
            else
            {
                result = svc.UpdDetailedAccount(acc);
                msg    = result ? General.Resource.Common.Success : General.Resource.Common.Failed;
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
        static void Main(string[] args)
        {
            String url = "https://development.avalara.net";
            String username = "******"; //TODO: You must authenticate with username/password (and not account number/ license key)
            String password = "******"; //TODO: Also, the credentials will need to be CompanyAdmin or AccountAdmin level.

            int accountId = 1100012345; //This should be your account Id - used for company creation, not authentication.

            AccountSvc svc = new AccountSvc(url, username, password);

            int companyId = CreateNewCompany(svc, accountId); //When a new company is created, you assign it a company code, and we assign it a companyId. I'll use that CompanyId to create users and nexus.
            AddNexus(svc, companyId);
            AddUser(svc, companyId, accountId);

            //Here are some other things that aren't in the sample, but let me know if you'd like to see them:
                //- Use merchant credentials for further editing (and allow them to reset an initial password progamatically)
                //- Add/modify Tax Codes, Tax Rules, Exemption Certificates, Users

            Console.WriteLine("Tests Done!");
            Console.ReadLine();
        }
        //Creates a new company in the target account with hardcoded company detail.
        private static int CreateNewCompany(AccountSvc svc, int accountId)
        {
            //check credentials by pulling current account data
            FetchRequest req = new FetchRequest();
            req.Filters = "AccountId=" + accountId;
            CompanyFetchResult fetchres = svc.CompanyFetch(req);
            Console.WriteLine("Companies fetched: "+ fetchres.RecordCount);

            Company company = new Company();
            company.AccountId = accountId;
            company.CompanyCode = "XYZ"+DateTime.Now; //This will need to be unique on the account - it should be whatever unique system value you assign to the merchant.
            company.CompanyName = "Test Company XYZ"; //Does not need to be strictly unique - should be the legal name of the merchant.

            CompanyContact company_contact = new CompanyContact(); //This should be the contact info for your primary contact at the merchant company.
            company_contact.CompanyContactCode = "001";
            company_contact.FirstName = "Anya";
            company_contact.LastName = "Stettler";
            company_contact.Line1 = "100 Ravine Lane";
            company_contact.City = "Bainbridge Island";
            company_contact.Region = "WA";
            company_contact.PostalCode = "98110";
            company_contact.Phone = "1-877-780-4848";
            company_contact.Email = "*****@*****.**";
            CompanyContact[] arr = new CompanyContact[1];
            arr[0] = company_contact;
            company.Contacts = arr;

            company.IsActive = true; // Allow us to skip activiation later.
            company.HasProfile = true; //Tells us that you will be creating a tax profile for this company instead of inheriting an existing one.
            company.IsReportingEntity = true; //Separates reported transctions from other companies.

            CompanySaveResult res = new CompanySaveResult();
            try
            {
                res = svc.CompanySave(company); //Save the company
                if (res.ResultCode.Equals(SeverityLevel.Success))
                {
                    Console.WriteLine("Company saved successfully. CompanyId: " + res.CompanyId);
                }
                else
                {
                    Console.WriteLine("Error when saving company. Error: " + res.Messages[0].Summary);

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error in CompanySave: " + ex);
            }

            return res.CompanyId; //Return the newly-created companyId
        }
 protected override void Given()
 {
     base.Given();
     AcctSvc = new AccountSvc(Bus, Repository);
 }
        public string UpdWageCostsRecord(List <T_WageCost> payList, string addstyle)
        {
            bool   result     = false;
            string msg        = string.Empty;
            string strVouchID = Guid.NewGuid().ToString();

            List <T_DetailedAccount> rec = new AccountSvc().GetLAccountByName("职工薪酬", Session["CurrentCompanyGuid"].ToString());

            foreach (T_WageCost wag in payList)
            {
                var query = rec.Where(p => p.ParentName == wag.Profit_Name);
                wag.C_GUID = Session["CurrentCompanyGuid"].ToString();
                T_IERecord Record = new T_IERecord();
                Record.Creator    = base.userData.LoginFullName;
                Record.C_GUID     = Session["CurrentCompanyGuid"].ToString();
                Record.IE_GUID    = wag.W_GUID;
                Record.RPer       = "e5e38321-4549-4c24-9f3a-3cd70ee1d591";
                Record.AffirmDate = wag.Date;
                Record.Date       = wag.Date;
                Record.SumAmount  = wag.Total;
                Record.InvType    = wag.InvType;
                if (query.Any())
                {
                    Record.IEGroup = query.FirstOrDefault().DA_GUID;
                }
                Record.Remark         = wag.Employee;
                Record.Currency       = wag.Currency;
                Record.Amount         = wag.Total - wag.PersonalTaxes;
                Record.CreateDate     = GetNowDate();
                Record.Profit_Name    = wag.Profit_Name;
                Record.TaxationAmount = 0;
                Record.TaxationType   = "";
                Record.IE_Flag        = "SA";
                //T_GeneralLedgerAccount rec = new AccountSvc().GetLAccount(Record.IEGroup, Session["CurrentCompanyGuid"].ToString(), Record.Profit_Name);
                //Record.IEGroup = rec.Where(p => p.ParentName == wag.Profit_Name).FirstOrDefault().DA_GUID;
                if (addstyle == "1")
                {
                    Record.State = "已付";
                }
                else
                {
                    Record.State = "应付";
                }
                result = new IESvc().UpdWageCost(wag, strVouchID);
                if (result)
                {
                    DateTime EditThreshold = DateTime.Parse(Session["EditThreshold"].ToString());
                    if (Record.Date <= DateTime.Now && Record.Date >= EditThreshold)
                    {
                        new IESvc().UpdExpenseInfo(Record, strVouchID);
                        if (result)
                        {
                            msg = General.Resource.Common.Success;
                        }
                        else
                        {
                            msg = General.Resource.Common.Failed;
                        }
                    }
                    else
                    {
                        result = false;
                        msg    = FMS.Resource.Finance.Finance.DateError;
                    }
                }
                else
                {
                    msg = General.Resource.Common.Failed;
                }
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
        /// <summary>
        /// 批量导入excel数据
        /// </summary>
        /// 20180514修改对应新的职工薪酬模板
        public ActionResult Upexcel(FormCollection from)
        {
            ExceResult res = new ExceResult();

            res.success = true;
            HttpPostedFileBase file       = Request.Files["upload"];
            string             result     = string.Empty;
            string             strVouchID = Guid.NewGuid().ToString();

            if (file == null || file.ContentLength <= 0)
            {
                res.success = false;
                res.msg     = "无有效文件";
            }
            else
            {
                try
                {
                    List <T_DetailedAccount> rec = new AccountSvc().GetLAccountByName("职工薪酬", Session["CurrentCompanyGuid"].ToString());
                    Workbook  workbook           = new Workbook(file.InputStream);
                    Cells     cells   = workbook.Worksheets[0].Cells;
                    DataTable tab     = cells.ExportDataTable(0, 0, cells.Rows.Count, cells.MaxDisplayRange.ColumnCount);
                    int       rowsnum = tab.Rows.Count;
                    if (rowsnum == 0)
                    {
                        res.success = false;
                        result      = "Excel表为空!请重新导入!"; //当Excel表为空时,对用户进行提示
                    }
                    //数据表一共多少行!
                    DataRow[] dr = tab.Select();
                    T_GeneralLedgerAccount gen = new AccountSvc().GetLAByName("银行存款", Session["CurrentCompanyGuid"].ToString());
                    string RpTypeID            = string.Empty;
                    if (gen != null)
                    {
                        RpTypeID = gen.LA_GUID;
                    }
                    //按行进行数据存储操作!
                    for (int i = 3; i < dr.Length; i++)
                    {
                        T_WageCost WageCostRecord = new T_WageCost();
                        WageCostRecord.W_GUID           = Guid.NewGuid().ToString();
                        WageCostRecord.C_GUID           = Session["CurrentCompanyGuid"].ToString();
                        WageCostRecord.State            = "未付";
                        WageCostRecord.PayType          = RpTypeID;
                        WageCostRecord.Date             = Convert.ToDateTime(dr[i][1].ToString());
                        WageCostRecord.Profit_Name      = dr[i][2].ToString();
                        WageCostRecord.Employee         = dr[i][0].ToString();
                        WageCostRecord.Cash             = Convert.ToDecimal(GetValue(dr[i][4].ToString())) + Convert.ToDecimal(GetValue(dr[i][5].ToString())) - Convert.ToDecimal(GetValue(dr[i][6].ToString()));
                        WageCostRecord.Total            = Convert.ToDecimal(GetValue(dr[i][23].ToString()));
                        WageCostRecord.PersonalTaxes    = Convert.ToDecimal(GetValue(dr[i][12].ToString()));
                        WageCostRecord.BonusAllowance   = Convert.ToDecimal(GetValue(dr[i][7].ToString())) + Convert.ToDecimal(GetValue(dr[i][8].ToString())) + Convert.ToDecimal(GetValue(dr[i][9].ToString()));
                        WageCostRecord.EmployeeWelfare  = Convert.ToDecimal(GetValue(dr[i][10].ToString()));
                        WageCostRecord.SocialSecurity   = Convert.ToDecimal(GetValue(dr[i][16].ToString()));
                        WageCostRecord.HousingProvident = Convert.ToDecimal(GetValue(dr[i][19].ToString()));
                        WageCostRecord.NonCurrency      = Convert.ToDecimal(GetValue(dr[i][22].ToString()));
                        WageCostRecord.StaffEducation   = Convert.ToDecimal(GetValue(dr[i][21].ToString()));
                        WageCostRecord.TradeUnion       = Convert.ToDecimal(GetValue(dr[i][20].ToString()));
                        WageCostRecord.DismissWelfare   = Convert.ToDecimal(GetValue(dr[i][11].ToString()));

                        T_IERecord Record = new T_IERecord();
                        Record.Creator    = base.userData.LoginFullName;
                        Record.C_GUID     = Session["CurrentCompanyGuid"].ToString();
                        Record.IE_GUID    = WageCostRecord.W_GUID;
                        Record.RPer       = "e5e38321-4549-4c24-9f3a-3cd70ee1d591";
                        Record.AffirmDate = WageCostRecord.Date;
                        Record.Date       = WageCostRecord.Date;
                        Record.SumAmount  = WageCostRecord.Total;
                        Record.InvType    = WageCostRecord.Profit_Name;
                        if (WageCostRecord.Profit_Name == "营业成本")
                        {
                            WageCostRecord.Profit_Name = "主营业务成本";
                        }
                        var query = rec.Where(p => p.ParentName == WageCostRecord.Profit_Name);
                        if (query.Any())
                        {
                            Record.IEGroup = query.FirstOrDefault().DA_GUID;//工资类别guid
                        }
                        Record.Remark      = WageCostRecord.Employee;
                        Record.Currency    = dr[i][3].ToString();
                        Record.Amount      = WageCostRecord.Total - WageCostRecord.PersonalTaxes;
                        Record.CreateDate  = GetNowDate();
                        Record.Profit_Name = WageCostRecord.Profit_Name;

                        Record.TaxationAmount = 0;
                        Record.TaxationType   = "";
                        Record.IE_Flag        = "SA";
                        Record.State          = "应付";

                        if (WageCostRecord.Date.CompareTo(Convert.ToDateTime(GetNowDate())) > 0)
                        {
                            result = "导入失败,时间错误";
                            break;
                        }
                        if (WageCostRecord.Date == null)
                        {
                            result = "导入失败,excel表第二列第" + dr[i] + "行时间没有填写";
                            break;
                        }
                        if (WageCostRecord.Employee == null)
                        {
                            result = "导入失败,excel表第一列第" + dr[i] + "行姓名没有填写";
                            break;
                        }
                        try
                        {
                            string currency = (new CurrencySvc().GetCurrency(dr[i][3].ToString())).ToString();
                            WageCostRecord.Currency = currency;
                        }
                        catch (Exception)
                        {
                            result = "导入失败,无此货币";
                            break;
                        }

                        if (dr[i][2].ToString() != "营业成本" && dr[i][2].ToString() != "销售费用" && dr[i][2].ToString() != "管理费用")
                        {
                            result = "导入失败,类别错误";
                            break;
                        }


                        bool TorF = new IESvc().UpdWageCost(WageCostRecord, strVouchID);

                        if (TorF)
                        {
                            DateTime EditThreshold = DateTime.Parse(Session["EditThreshold"].ToString());
                            if (Record.Date <= DateTime.Now && Record.Date >= EditThreshold)
                            {
                                bool ExpR = new IESvc().UpdExpenseInfo(Record, strVouchID);
                                if (ExpR)
                                {
                                    result = "导入成功!";
                                }
                                else
                                {
                                    result = General.Resource.Common.Failed;
                                }
                            }
                            else
                            {
                                result = FMS.Resource.Finance.Finance.DateError;
                            }
                        }
                        else
                        {
                            result = "导入失败!";
                        }
                    }
                }
                catch (Exception)
                {
                    result = "导入失败,请检查EXCEL格式是否错误!";
                }
            }
            JsonResult json = new JsonResult();

            json.Data = result;
            return(json);
        }