コード例 #1
0
        public ActionResult adddo(string sysflag, int?page, string orderdata, string orderdata1)
        {
            page               = ((!page.HasValue || page < 1) ? 1 : page);
            ViewBag.page       = page;
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;

            string qbseason = "", qslyear = "", qslmonth = "", qvtype = "", qvendcomid = "", qsdate = "", qedate = "";

            if (!string.IsNullOrWhiteSpace(Request["qbseason"]))
            {
                qbseason         = Request["qbseason"].Trim();
                ViewBag.qbseason = qbseason;
            }
            if (!string.IsNullOrWhiteSpace(Request["qslyear"]))
            {
                qslyear         = Request["qslyear"].Trim();
                ViewBag.qslyear = qslyear;
            }
            if (!string.IsNullOrWhiteSpace(Request["qslmonth"]))
            {
                qslmonth         = Request["qslmonth"].Trim();
                ViewBag.qslmonth = qslmonth;
            }
            if (!string.IsNullOrWhiteSpace(Request["qvtype"]))
            {
                qvtype         = Request["qvtype"].Trim();
                ViewBag.qvtype = qvtype;
            }

            if (!string.IsNullOrWhiteSpace(Request["qvendcomid"]))
            {
                qvendcomid         = Request["qvendcomid"].Trim();
                ViewBag.qvendcomid = qvendcomid;
            }


            if (!string.IsNullOrWhiteSpace(Request["qsdate"]))
            {
                qsdate         = Request["qsdate"].Trim();
                ViewBag.qsdate = qsdate;
            }


            if (!string.IsNullOrWhiteSpace(Request["qedate"]))
            {
                qedate         = Request["qedate"].Trim();
                ViewBag.qedate = qedate;
            }


            NDcommon dbobj = new NDcommon();

            SqlConnection erpconn  = dbobj.get_conn("AitagBill_DBContext");
            SqlConnection erpconn1 = dbobj.get_conn("AitagBill_DBContext");

            using (AitagBill_DBContext con = new AitagBill_DBContext())
            {
                string tmpssql = "";
                int    strym   = 0;
                int    etrym   = 0;
                //找審過過單
                tmpssql = "select (payvendcomid) as vendno, isnull(sum(psummoney),0) as psummoney FROM vend_contractinvclose INNER JOIN vend_contractinvclose_det ON vend_contractinvclose.vcinvid =vend_contractinvclose_det.vcinvid where vstatus<>'D' ";

                switch (qbseason)
                {
                case "01":    //月獎
                    tmpssql += " and slyear =" + qslyear + " and slmonth = " + qslmonth + "  group by payvendcomid ";
                    break;

                case "02":    //季獎 3 / 6 / 9/ 12
                    strym = 365 * int.Parse(qslyear) + 30 * int.Parse(qslmonth);
                    //etrym = qslyear.ToString() + qslmonth.ToString().PadLeft(2, '0');
                    if (qslmonth.ToString().PadLeft(2, '0') == "03")
                    {
                        strym = 365 * int.Parse(qslyear) + 30 * 1;
                        etrym = 365 * int.Parse(qslyear) + 30 * 3;
                    }
                    else if (qslmonth.ToString().PadLeft(2, '0') == "06")
                    {
                        strym = 365 * int.Parse(qslyear) + 30 * 4;
                        etrym = 365 * int.Parse(qslyear) + 30 * 6;
                    }
                    else if (qslmonth.ToString().PadLeft(2, '0') == "09")
                    {
                        strym = 365 * int.Parse(qslyear) + 30 * 7;
                        etrym = 365 * int.Parse(qslyear) + 30 * 9;
                    }
                    else if (qslmonth.ToString().PadLeft(2, '0') == "12")
                    {
                        strym = 365 * int.Parse(qslyear) + 30 * 10;
                        etrym = 365 * int.Parse(qslyear) + 30 * 12;
                    }
                    tmpssql += " and (slyear * 365 + slmonth * 30) >= " + strym.ToString() + " and (slyear * 365 + slmonth * 30)  <= " + etrym.ToString() + " group by payvendcomid ";
                    break;

                case "03":    //半年獎 06 / 12
                    strym = 365 * int.Parse(qslyear) + 30 * int.Parse(qslmonth);
                    //etrym = qslyear.ToString() + qslmonth.ToString().PadLeft(2, '0');
                    if (qslmonth.ToString().PadLeft(2, '0') == "06")
                    {
                        strym = 365 * int.Parse(qslyear) + 30 * 1;
                        etrym = 365 * int.Parse(qslyear) + 30 * 6;
                    }
                    else if (qslmonth.ToString().PadLeft(2, '0') == "12")
                    {
                        strym = 365 * int.Parse(qslyear) + 30 * 7;
                        etrym = 365 * int.Parse(qslyear) + 30 * 12;
                    }

                    tmpssql += " and (slyear * 365 + slmonth * 30) >= " + strym.ToString() + " and (slyear * 365 + slmonth * 30)  <= " + etrym.ToString() + " group by payvendcomid ";
                    break;

                case "04":    //年獎
                    tmpssql += " and year(vadate) =" + qslyear + " group by payvendcomid ";
                    break;
                }

                SqlDataReader dr    = dbobj.dbselect(erpconn, tmpssql);
                string        iftax = "";
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        decimal tmprate        = 0;
                        decimal tmppsummoney   = decimal.Parse(dr["psummoney"].ToString());
                        decimal pallbonusmoney = tmppsummoney;
                        // 找 廠商/客戶的 計算方式 , vendno 在客戶計算是客戶的欄位
                        //tmpssql = "select * from allcompany_rate where bseason='" + qbseason + "' and allcomid='" + dr["vendno"].ToString() + "' and (bsmoney <=" + tmppsummoney + " and  bemoney >=" + tmppsummoney + " )";
                        //單筆金額
                        tmpssql = "select * from allcompany_rate where bseason='" + qbseason + "' and allcomid='" + dr["vendno"].ToString() + "' and btype = '0'";
                        SqlDataReader dr1 = dbobj.dbselect(erpconn1, tmpssql);
                        if (dr1.Read())
                        {
                            pallbonusmoney = decimal.Parse(dr1["brate"].ToString());
                        }

                        dr1.Close();
                        dr1.Dispose();

                        //單筆比例
                        tmpssql = "select * from allcompany_rate where bseason='" + qbseason + "' and allcomid='" + dr["vendno"].ToString() + "' and btype = '1'";
                        dr1     = dbobj.dbselect(erpconn1, tmpssql);
                        if (dr1.Read())
                        {
                            iftax   = dr1["brate"].ToString();
                            tmprate = decimal.Parse(dr1["brate"].ToString());
                            if (iftax == "0")
                            {
                                pallbonusmoney = pallbonusmoney * tmprate / 100;
                            }
                            else
                            {
                                pallbonusmoney = (pallbonusmoney * tmprate * decimal.Parse("1.05")) / 100;
                            }
                        }

                        dr1.Close();
                        dr1.Dispose();

                        //落點金額比例
                        tmpssql = "select * from allcompany_rate where bseason='" + qbseason + "' and allcomid='" + dr["vendno"].ToString() + "' and btype = '2' and (bsmoney <=" + tmppsummoney + " and  bemoney >=" + tmppsummoney + ")";
                        dr1     = dbobj.dbselect(erpconn1, tmpssql);
                        if (dr1.Read())
                        {
                            iftax   = dr1["brate"].ToString();
                            tmprate = decimal.Parse(dr1["brate"].ToString());
                            if (iftax == "0")
                            {
                                pallbonusmoney = pallbonusmoney * tmprate / 100;
                            }
                            else
                            {
                                pallbonusmoney = (pallbonusmoney * tmprate * decimal.Parse("1.05")) / 100;
                            }
                        }

                        dr1.Close();
                        dr1.Dispose();

                        //累積金額比例
                        tmpssql = "select * from allcompany_rate where bseason='" + qbseason + "' and allcomid='" + dr["vendno"].ToString() + "' and btype = '3' and (bsmoney <=" + tmppsummoney + " and  bemoney >=" + tmppsummoney + ")";
                        dr1     = dbobj.dbselect(erpconn1, tmpssql);
                        if (dr1.Read())
                        {
                            iftax   = dr1["brate"].ToString();
                            tmprate = decimal.Parse(dr1["brate"].ToString());
                            if (iftax == "0")
                            {
                                pallbonusmoney = pallbonusmoney * tmprate / 100;
                            }
                            else
                            {
                                pallbonusmoney = (pallbonusmoney * tmprate * decimal.Parse("1.05")) / 100;
                            }
                        }

                        dr1.Close();
                        dr1.Dispose();

                        vend_monthmoney addobj = new vend_monthmoney();
                        addobj.bseason = qbseason; //01:月獎 02:季獎 03:半年獎 04:年獎  05:現折
                        addobj.slyear  = int.Parse(qslyear);
                        if (qbseason == "04")
                        {
                            addobj.slmonth = 12;
                        }
                        else
                        {
                            addobj.slmonth = int.Parse(qslmonth);
                        }

                        addobj.vendcomid      = dr["vendno"].ToString();
                        addobj.vtype          = "2";//1:收入 2:支出
                        addobj.pallbonusmoney = pallbonusmoney;
                        addobj.pallmoney      = tmppsummoney;

                        addobj.bmodid   = Session["empid"].ToString();
                        addobj.bmoddate = DateTime.Now;
                        addobj.comid    = Session["comid"].ToString();
                        con.vend_monthmoney.Add(addobj);
                    }
                }


                con.SaveChanges();
                con.Dispose();
            }

            erpconn.Close();
            erpconn.Dispose();

            erpconn1.Close();
            erpconn1.Dispose();
            string tmpform = "";

            tmpform  = "<body onload=qfr1.submit();>";
            tmpform += "<form name='qfr1' action='/vend_monthmoney/list' method='post'>";
            tmpform += "<input type=hidden name='sysflag' id='sysflag' value='" + sysflag + "'>";
            tmpform += "<input type=hidden name='page' id='page' value='" + page + "'>";
            tmpform += "<input type=hidden name='orderdata' id='orderdata' value='" + orderdata + "'>";
            tmpform += "<input type=hidden name='orderdata1' id='orderdata1' value='" + orderdata1 + "'>";
            tmpform += "<input type=hidden id='qbseason' name='qbseason' value='" + qbseason + "'>";
            tmpform += "<input type=hidden id='qslyear' name='qslyear' value='" + qslyear + "'>";
            tmpform += "<input type=hidden id='qslmonth' name='qslmonth' value='" + qslmonth + "'>";
            tmpform += "<input type=hidden id='qvendcomid' name='qvendcomid' value='" + qvendcomid + "'>";

            tmpform += "</form>";
            tmpform += "</body>";


            return(new ContentResult()
            {
                Content = @"" + tmpform
            });
        }