Ejemplo n.º 1
0
        public ActionResult Save(_PreCommission model)
        {
            PreCommission newmodel = new PreCommission();

            newmodel = CH.GetDataById <PreCommission>(model.ID);
            //newmodel.StartDate = model.StartDate;
            //newmodel.EndDate = model.EndDate;
            newmodel.TargetNameEN       = model.TargetNameEN;
            newmodel.TargetNameCN       = model.TargetNameCN;
            newmodel.ProjectID          = model.ProjectID;
            newmodel.InOut              = model.InOut;
            newmodel.DelegateLessIncome = model.DelegateLessIncome;
            newmodel.DelegateMoreCount  = model.DelegateMoreCount;
            newmodel.DelegateMoreIncome = model.DelegateMoreIncome;
            newmodel.SponsorIncome      = model.SponsorIncome;
            newmodel.Income             = model.Income;
            newmodel.CommissionRate     = model.CommissionRate;
            newmodel.Commission         = model.Commission;
            newmodel.Tax              = model.Tax;
            newmodel.Bonus            = model.Bonus;
            newmodel.ReturnIncome     = model.ReturnIncome;
            newmodel.ReturnReason     = model.ReturnReason;
            newmodel.ActualCommission = model.ActualCommission;

            newmodel.DelegateLessRate       = model.DelegateLessRate;
            newmodel.DelegateLessCommission = model.DelegateLessCommission;
            newmodel.DelegateMoreRate       = model.DelegateMoreRate;
            newmodel.DelegateMoreCommission = model.DelegateMoreCommission;
            newmodel.SponsorRate            = model.SponsorRate;
            newmodel.SponsorCommission      = model.SponsorCommission;
            newmodel.TotalCommission        = model.TotalCommission;

            newmodel.DelegateIncome     = model.DelegateIncome;
            newmodel.DelegateRate       = model.DelegateRate;
            newmodel.DelegateCommission = model.DelegateCommission;

            CH.Edit <PreCommission>(newmodel);
            var list = Finance_Logical._PreCommissionBLL.GetPreCommission(model.StartDate.Year, model.StartDate.Month);
            var data = list.OrderBy(p => p.TargetNameEN).ToList();

            return(View(new GridModel(data)));
        }
Ejemplo n.º 2
0
        public ActionResult Insert(_PreCommission model)
        {
            PreCommission newmodel = new PreCommission();

            newmodel.StartDate          = model.StartDate;
            newmodel.EndDate            = model.StartDate.AddMonths(1).AddDays(-1);
            newmodel.TargetNameEN       = model.TargetNameEN;
            newmodel.TargetNameCN       = model.TargetNameCN;
            newmodel.ProjectID          = model.ProjectID;
            newmodel.InOut              = model.InOut;
            newmodel.DelegateLessIncome = model.DelegateLessIncome;
            newmodel.DelegateMoreCount  = model.DelegateMoreCount;
            newmodel.DelegateMoreIncome = model.DelegateMoreIncome;
            newmodel.SponsorIncome      = model.SponsorIncome;
            newmodel.Income             = model.Income;
            newmodel.CommissionRate     = model.CommissionRate;
            newmodel.Commission         = model.Commission;
            newmodel.Tax              = model.Tax;
            newmodel.Bonus            = model.Bonus;
            newmodel.ReturnIncome     = model.ReturnIncome;
            newmodel.ReturnReason     = model.ReturnReason;
            newmodel.ActualCommission = model.ActualCommission;

            newmodel.DelegateLessRate       = model.DelegateLessRate;
            newmodel.DelegateLessCommission = model.DelegateLessCommission;
            newmodel.DelegateMoreRate       = model.DelegateMoreRate;
            newmodel.DelegateMoreCommission = model.DelegateMoreCommission;
            newmodel.SponsorRate            = model.SponsorRate;
            newmodel.SponsorCommission      = model.SponsorCommission;
            newmodel.TotalCommission        = model.TotalCommission;

            newmodel.DelegateIncome     = model.DelegateIncome;
            newmodel.DelegateRate       = model.DelegateRate;
            newmodel.DelegateCommission = model.DelegateCommission;

            newmodel.CommID = model.TargetNameEN + model.StartDate.Year.ToString() + model.StartDate.Month.ToString().PadLeft(2, '0');
            CH.Create <PreCommission>(newmodel);
            var list = Finance_Logical._PreCommissionBLL.GetPreCommission(model.StartDate.Year, model.StartDate.Month);
            var data = list.OrderBy(p => p.TargetNameEN).ToList();

            return(View(new GridModel(data)));
        }
Ejemplo n.º 3
0
        private void PreCommByProSales(DateTime ActualPaymentDate, string sale, int projectid)
        {
            var year      = ActualPaymentDate.Year;
            var month     = ActualPaymentDate.Month;
            var startdate = new DateTime(year, month, 1);
            var enddate   = startdate.AddMonths(1).AddDays(-1);
            var deals     = from d in CH.DB.Deals.Where(o => o.ProjectID == projectid && o.Abandoned == false && o.Income > 0 &&
                                                        o.ActualPaymentDate.Value.Month == ActualPaymentDate.Month && o.ActualPaymentDate.Value.Year == year && o.Sales == sale)
                            select d;
            var username    = sale;
            var emps        = CH.DB.EmployeeRoles.Where(w => w.AccountName == username);
            var displayname = emps.Select(s => s.AccountNameCN).FirstOrDefault();
            var roleid      = emps.Select(s => s.RoleID).FirstOrDefault();
            var projects    = from p in deals
                              group p by new { p.Project.ProjectCode } into grp
                select new { projectcode = grp.Key.ProjectCode };
            var proname = "";

            foreach (var name in projects)
            {
                proname = proname + name.projectcode + ",";
            }
            proname = proname.TrimEnd(',');
            string inout = "海外";

            if (roleid != null)
            {
                var name = CH.GetDataById <Role>(roleid).Name;
                if (name.Contains("国内"))
                {
                    inout = "国内";
                }
            }
            decimal standard     = 3000;
            var     sponsorrate  = 5;
            var     delegaterate = 5;
            var     lps          = new PreCommission()
            {
                ProjectID          = projectid,
                Income             = deals.Sum(s => (decimal?)s.Income),
                TargetNameEN       = sale,
                TargetNameCN       = displayname,
                InOut              = inout,
                SponsorIncome      = deals.Where(w => w.Poll == 0).Sum(s => (decimal?)s.Income),
                DelegateIncome     = deals.Where(w => w.Poll > 0).Sum(s => (decimal?)s.Income),
                SponsorRate        = sponsorrate,
                SponsorCommission  = deals.Where(w => w.Poll == 0).Sum(s => (decimal?)s.Income) * sponsorrate / 100,
                DelegateRate       = delegaterate,
                DelegateCommission = deals.Where(w => w.Poll > 0).Sum(s => (decimal?)s.Income) * delegaterate / 100,
            };

            if (lps.SponsorIncome == null)
            {
                lps.SponsorIncome = 0;
            }
            else
            {
                lps.SponsorIncome = (decimal)Math.Round((decimal)lps.SponsorIncome);
            }
            if (lps.DelegateIncome == null)
            {
                lps.DelegateIncome = 0;
            }
            else
            {
                lps.DelegateIncome = (decimal)Math.Round((decimal)lps.DelegateIncome);
            }
            if (lps.SponsorCommission == null)
            {
                lps.SponsorCommission = 0;
            }
            else
            {
                lps.SponsorCommission = (decimal)Math.Round((decimal)lps.SponsorCommission);
            }
            if (lps.DelegateCommission == null)
            {
                lps.DelegateCommission = 0;
            }
            else
            {
                lps.DelegateCommission = (decimal)Math.Round((decimal)lps.DelegateCommission);
            }
            lps.Income     = lps.DelegateIncome + lps.SponsorIncome;
            lps.Commission = lps.SponsorCommission + lps.DelegateCommission;
            if (lps.Commission > 3500)
            {
                lps.Tax = (decimal)Math.Round((((double)lps.Commission - 3500) * 0.07));
            }
            else
            {
                lps.Tax = 0;
            }
            lps.TotalCommission = lps.ActualCommission = lps.Commission - lps.Tax;
            var procode = CH.GetDataById <Project>(projectid).ProjectCode;
            var CommID  = sale + year.ToString() + ActualPaymentDate.Month.ToString().PadLeft(2, '0');

            lps.CommID    = CommID;
            lps.StartDate = startdate;
            lps.EndDate   = enddate;
            var precommission = CH.DB.PreCommissions.Where(x => x.CommID == CommID && x.ProjectID == projectid).FirstOrDefault();

            if (precommission != null)
            {
                CH.Delete <PreCommission>(precommission.ID);
            }
            lps.Creator     = "system";
            lps.CreatedDate = DateTime.Now;
            //CH.Create<PreCommission>(lps);
            CH.DB.Set <PreCommission>().Add(lps);
            CH.DB.SaveChanges();
            //DB.Set<PreCommission>().Add(lps);
            //DB.SaveChanges();
        }