Exemple #1
0
        /// <summary>
        /// Tinh phep den cuoi nam  2016-05-21
        /// </summary>
        /// <param name="EMP_ID"></param>
        /// <param name="TYP_ID"></param>
        /// <param name="INH_DT"></param>
        /// <param name="con"></param>
        /// <param name="dt"></param>
        // Dau nam tinh duoc ngay phep 1 nam
        public static void CalStaff1(string EMP_ID, string TYP_ID, string INH_DT, SqlConnection con, DateTime dt)
        {
            checkStaff(EMP_ID, con, dt.ToString("yyyy"));
            if (INH_DT + "" == "")        // ko co ngay vao
            {
                UpdateStaff0(EMP_ID, con, dt.ToString("yyyy"));
                return;
            }
            string sql;

            sql = "Select * from FILA11A where TYP_ID=N'" + TYP_ID + "'";
            Func.RecordSet rs = new Func.RecordSet(sql, con);
            if (rs.rows <= 0)          // ko co loai nhan vien
            {
                UpdateStaff0(EMP_ID, con, dt.ToString("yyyy"));
                return;
            }
            int      WAG_MM       = T_String.IsNullTo0(rs.record(0, "WAG_MM"));
            int      ngaytinh     = T_String.IsNullTo0(rs.record(0, "STR_DT"));
            int      phepnam      = T_String.IsNullTo0(rs.record(0, "LEA_DY"));
            int      Loainhanvien = T_String.IsNullTo0(rs.record(0, "LEA_DY"));
            int      heso         = (int)phepnam / 12;
            DateTime dt1          = DateTime.Parse(INH_DT).AddMonths(WAG_MM);

            if (T_String.CompareDate(dt1, dt))           // ko du thoi gian lam viec de tinh phep
            {
                UpdateStaff0(EMP_ID, con, dt.ToString("yyyy"));
                return;
            }
            if (T_String.CompareDate(new DateTime(dt.Year, 1, 1), dt1))
            {
                dt1 = new DateTime(dt.Year, 1, 1);
            }

            int     ngayphep  = 0;     // tinh phep nam
            Decimal ngayphep1 = 0;


            if (dt1.Year == T_String.GetDate(con).Year)
            {
                ngayphep = phepnam - ((int)dt1.Month) + 1;
            }
            else
            {
                ngayphep = phepnam;
            }

            //Kien phep nam Cheng long [PNchenglong]=1
            string PNchenglong = PublicFunction.GetOption("PNchenglong");
            string ALEtop      = PublicFunction.GetOption("ALEtop");

            if (PNchenglong == "1" || ALEtop == "1")
            {
                if (DateTime.Parse(INH_DT).Year == T_String.GetDate(con).Year)
                {
                    ngayphep = T_String.GetDate(con
                                                ).Month - ((int)dt1.Month);
                    if (dt1.Day <= ngaytinh)
                    {
                        ngayphep = T_String.GetDate(con
                                                    ).Month - ((int)dt1.Month);
                    }
                    else
                    {
                        if (dt1.Day > ngaytinh)
                        {
                            ngayphep = T_String.GetDate(con
                                                        ).Month - ((int)dt1.Month) - 1;
                        }
                        // tinh theo ngay neu ngay vao lam nho hon ngay he thong thi thang do khong tinh
                        if (ALEtop == "1")
                        {
                            if (dt1.Day > T_String.GetDate(con).Day)
                            {
                                ngayphep = ngayphep - 1;
                            }
                        }
                    }
                }
                else
                {
                    if (phepnam == 14 && T_String.GetDate(con).Month == 12)
                    {
                        ngayphep = T_String.GetDate(con).Month + 2;
                    }
                    else
                    {
                        ngayphep = T_String.GetDate(con).Month;
                    }
                }
            }

            ///ket thuc cheng long
            string   vacate = T_String.GetDataFromSQL("VAC_BT", "FILB01A", "EMP_ID='" + EMP_ID + "'");
            DateTime vacate_date;

            if (vacate == "True")
            {
                vacate_date = DateTime.Parse(T_String.GetDataFromSQL("VAC_DT", "FILB01AC", "EMP_ID='" + EMP_ID + "'"));
                if (vacate_date.Year == T_String.GetDate(con).Year)
                {
                    if (dt1.Year == vacate_date.Year)
                    {
                        ngayphep = ((int)vacate_date.Month) - ((int)dt1.Month) + 1;
                    }
                    else
                    {
                        ngayphep = ((int)vacate_date.Month);
                    }
                }
            }

            //phep nam esprinta
            string filePath = PublicFunction.Path + "/Esprinta.dll";

            // tinh tham nien
            int      thamnien  = 0;
            Double   thamnien1 = 0;
            DateTime dtk       = DateTime.Parse(INH_DT);

            dt1 = DateTime.Parse(INH_DT);
            int sonam  = T_String.IsNullTo0(rs.record(0, "SEN_YY"));
            int songay = T_String.IsNullTo0(rs.record(0, "SEN_DY"));

            filePath = PublicFunction.Path + "/Esprinta.dll";
            if (System.IO.File.Exists(filePath))
            {
                if (sonam != 0 && songay != 0)
                {
                    while (true)
                    {
                        dt1 = dt1.AddYears(sonam);
                        dtk = dtk.AddYears(sonam - 1);
                        if (T_String.CompareDate(T_String.GetDate(con), dt1))
                        {
                            thamnien1 += songay;
                        }
                        else
                        {
                            //dateTime1=dateTime1.AddDays(+1);
                            //int ngayk1=T_String.DT_GetDays(DateTime.Parse(T_String.GetDate(con).Year + "/01/01"),T_String.GetDate(con));
                            //DateTime dateTime10 = DateTime.Parse(T_String.GetDate(con).Year + "/" + Convert.ToDateTime(INH_DT).Month + "/" + Convert.ToDateTime(INH_DT).Day);//Convert.ToDateTime(INH_DT);
                            DateTime dateTime10 = Convert.ToDateTime(INH_DT);
                            //dateTime10 = dateTime10.AddYears(+5);
                            dateTime10 = dateTime10.AddDays(+1826);
                            //DateTime dateTime1 = Convert.ToDateTime(INH_DT);//Convert.ToDateTime(INH_DT);

                            int ngaytest = 0;
                            //T_String.DT_GetDays1(dateTime1,T_String.GetDate(con));
                            ngaytest = T_String.DT_GetDays(dateTime10, T_String.GetDate(con));
                            if (T_String.CompareDate(T_String.GetDate(con), dtk))
                            {
                                thamnien1 += 0.00273972602739726 * T_String.DT_GetDays(dateTime10, T_String.GetDate(con));
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                if (sonam != 0 && songay != 0)
                {
                    while (true)
                    {
                        dt1 = dt1.AddYears(sonam);
                        if (T_String.CompareDate(DateTime.Parse(dt.Year + "/12/31"), dt1))
                        {
                            thamnien += songay;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            if (System.IO.File.Exists(filePath))
            {
                sql = "update FILC04B set HAV_QT=" + ngayphep1 + " where EMP_ID=N'" + EMP_ID + "' and YYY_YY=N'" + dt.ToString("yyyy") + "' and (nature='' or nature is null)";
                PublicFunction.SQL_Execute(sql, con);

                sql = "update FILC04B set ADD_QT=" + thamnien1 + " where EMP_ID=N'" + EMP_ID + "' and YYY_YY=N'" + dt.ToString("yyyy") + "'";
                PublicFunction.SQL_Execute(sql, con);
            }
            else
            {
                sql = "update FILC04B set HAV_QT=" + ngayphep + " where EMP_ID=N'" + EMP_ID + "' and YYY_YY=N'" + dt.ToString("yyyy") + "' and (nature='' or nature is null)";
                PublicFunction.SQL_Execute(sql, con);

                sql = "update FILC04B set ADD_QT=" + thamnien + " where EMP_ID=N'" + EMP_ID + "' and YYY_YY=N'" + dt.ToString("yyyy") + "'";
                PublicFunction.SQL_Execute(sql, con);
            }
//			sql="update FILC04B set DID_QT=(select SUM(DAY_TT) from FILC04A where  EMP_ID=N'"+EMP_ID+"' "
//				+")where EMP_ID=N'"+EMP_ID+"' and YYY_YY=N'"+dt.ToString("yyyy")+"'";
//			PublicFunction.SQL_Execute(sql,con);
        }