예제 #1
0
        private void GetFileName2()        // Lay danh sach file chuyen du lieu
        {
            try
            {
                string    dir    = T_String.GetDataFromSQL("DIR_DR", "GP_SYS_READER", "SEQ_NO='1'", con21);
                string    FIL_NM = T_String.GetDataFromSQL("FIL_NM", "GP_SYS_READER", "SEQ_NO='1'", con21);
                DateTime  dt     = GetDateOfFileTXT(FIL_NM, "1");
                string [] f1     = Directory.GetFiles(dir);

                for (int i = 0; i < f1.Length; i++)
                {
                    if (PublicFunction.S_Right(f1[i], 4).ToUpper() == ".TXT")
                    {
                        DateTime dt1 = GetDateOfFileTXT(f1[i], "1");
                        if (T_String.CompareDate(dt1, dt))
                        {
                            int j = 0;
                            for (j = 0; j < lb3.Items.Count; j++)
                            {
                                if (T_String.CompareDate(GetDateOfFileTXT(lb3.Items[j] + "", "1"), dt1))
                                {
                                    break;
                                }
                            }
                            lb3.Items.Insert(j, f1[i]);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
예제 #2
0
        private bool GetFileName(ListBox _lbxFile, string _sDir, string _sFile, SqlConnection _con)
        {
            try
            {
                int i, j;

                DateTime S_dDt = AQ800(GetName(_sFile));

                if (S_dDt == new DateTime(1, 1, 1))
                {
                    return(false);
                }

                string [] lsFile = Directory.GetFiles(_sDir, "*.txt");
                Array.Sort(lsFile);

                j = 0;
                for (i = 0; i < lsFile.Length; i++)
                {
                    string sFileName = string.Empty;
                    sFileName = lsFile[i].Substring(lsFile[i].LastIndexOf("\\") + 1);
                    DateTime dDt = AQ800(sFileName);

                    if (T_String.CompareDate(dDt, S_dDt) && dDt != new DateTime(1, 1, 1))
                    {
                        _lbxFile.Items.Insert(j, sFileName);
                        j++;
                    }
                }
            }
            catch
            {
                //MessageBox.Show (ex.Message);
                return(false);
            }

            return(true);
        }
예제 #3
0
        // 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      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

            ngayphep = phepnam;
//			if(dt1.Day<=ngaytinh)
//			{
//				ngayphep+= heso;
//				dem++;
//			}
//			dt1=dt1.AddMonths(1);
//			while (dt1.Month<dt.Month)
//			{
//				ngayphep+= heso;
//				dt1=dt1.AddMonths(1);
//				dem++;
//			}
//			if(dt.Day>=ngaytinh && dt1.Month==dt.Month)
//			{
//				if(dem+1==12)
//				{
//					ngayphep=phepnam;
//				}
//				else
//				{
//					ngayphep+= heso;
//				}
//
//			}
            // tinh tham nien
            int thamnien = 0;

            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"));

            if (sonam != 0 && songay != 0)
            {
                while (true)
                {
                    dt1 = dt1.AddYears(sonam);
                    if (T_String.CompareDate(dt, dt1))
                    {
                        thamnien += songay;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            sql = "update FILC04C set HAV_QT=" + ngayphep + ",ADD_QT=" + thamnien + " where EMP_ID=N'" + EMP_ID + "' and YYY_YY=N'" + dt.ToString("yyyy") + "'";
            PublicFunction.SQL_Execute(sql, con);
//			sql="update FILC04C 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);
        }
예제 #4
0
        private void Cal()
        {
            //dt=T_String.GetDate();
            lb.Text        = "";
            lb2.Text       = "";
            cmd_OK.Enabled = false;
            SqlConnection con = new SqlConnection(PublicFunction.C_con.ConnectionString);

            con.Open();
            //Tinh phep nam tu thang den thang
            DateTime fromdate = (DateTime)dtpfrom.Value;
            DateTime todate   = (DateTime)dtpto.Value;

            while (T_String.IsNullTo0(fromdate.ToString("yyyyMM")) <= T_String.IsNullTo0(todate.ToString("yyyyMM")))         // tung Ngay
            {
                string str = "delete FILC04C from FILC04C LEFT OUTER JOIN FILB01A ON FILB01A.EMP_ID=FILC04C.EMP_ID";
                str += " LEFT OUTER JOIN FILB01AC ON FILB01A.EMP_ID=FILB01AC.EMP_ID";
                str += " where ((VAC_BT=0 or VAC_BT is null) or (VAC_BT=1 and VAC_DT>='" + fromdate.ToString("yyyy/MM") + "/01'))";
                str += " and YYY_YY=N'" + fromdate.ToString("yyyyMM") + "' and " + control1.GetWhere("", false);
                PublicFunction.SQL_Execute(str, con);
                //Kiem tra thu tinh dua vao ngay vao lam hay ngay hop dong

                string sql = "Select FILB01A.EMP_ID,EMP_NM,FILB01A.TYP_ID,INH_DT,LAB_NO,LAB_ST,LAB_ED,LAB_TM,";
                sql += "LEA_DY,NEW_OD,STR_DT,WAG_MM,SEN_YY,SEN_DY,LEA_PY,LEA_DM,CHK_LB";
                sql += " from FILB01A left outer join FILB01AF on FILB01A.EMP_ID=FILB01AF.EMP_ID";
                sql += " left outer join FILA11A on FILA11A.TYP_ID=FILB01A.TYP_ID";
                sql += " LEFT OUTER JOIN FILB01AC ON FILB01A.EMP_ID=FILB01AC.EMP_ID";
                sql += " where " + control1.GetWhere("", false);
                sql += " and ((VAC_BT=0 or VAC_BT is null) or (VAC_BT=1 and VAC_DT>='" + fromdate.ToString("yyyy/MM") + "/01'))";
                sql += " and INH_DT<'" + fromdate.AddMonths(1).ToString("yyyy/MM") + "/01'";
                Func.RecordSet rs = new Func.RecordSet(sql, con);
                for (int i = 0; i < rs.rows; i++)
                {
                    if (stop)
                    {
                        return;
                    }
                    //Phep nam cho ung truoc hay ko
                    if (PublicFunction.tinhphepnam == 0)
                    {
                        String EMP_ID = rs.record(i, "EMP_ID");
                        String INH_DT = rs.record(i, "INH_DT");
                        string TYP_ID = rs.record(i, "TYP_ID");
                        string LAB_ST = rs.record(i, "LAB_ST");
                        //xet co ngay vao lam va loai nhan vien hay ko
                        //Chuyen nhan vien vao FILC04C
                        checkStaff(EMP_ID, con, fromdate.ToString("yyyyMM"));
                        if (INH_DT + "" == "")                    // ko co ngay vao
                        {
                            UpdateStaff0(EMP_ID, con, fromdate.ToString("yyyyMM"));
                            return;
                        }
                        //string sql;
                        sql = "Select * from FILA11A where TYP_ID=N'" + TYP_ID + "'";
                        Func.RecordSet rrs = new Func.RecordSet(sql, con);
                        if (rrs.rows <= 0)                      // ko co loai nhan vien
                        {
                            UpdateStaff0(EMP_ID, con, fromdate.ToString("yyyyMM"));
                            return;
                        }
                        string checkHD = rs.record(0, "CHK_LB");
                        if (checkHD == "True")
                        {
                            //Thang bat dau tinh phep nam
                            int WAG_MM = T_String.IsNullTo0(rs.record(0, "WAG_MM"));
                            /////////
                            ///Ngay tinh de doi chieu voi ngay tinh cua chuong trinh
                            int ngaytinh      = T_String.IsNullTo0(rs.record(0, "STR_DT"));
                            int phepnam1nam   = T_String.IsNullTo0(rs.record(0, "LEA_DY"));
                            int phepnamnuanam = T_String.IsNullTo0(rs.record(0, "LEA_PY"));
                            int phepnam1thang = T_String.IsNullTo0(rs.record(0, "LEA_DM"));
                            //Thang bat dau tinh cong them vao ngay vao lam
                            DateTime Batdautinh = DateTime.Parse(LAB_ST).AddMonths(WAG_MM);
                            DateTime dt1 = DateTime.Parse(LAB_ST);
                            int      phepduochuongtuden = 0, phepduochuongtrongthang = 0, phepnghitrongthang = 0, phepnghituden = 0, phepconlaitrongthang = 0, phepconlaituden = 0;
                            label5.Text = fromdate.ToString("yyyy/MM");
                            sql         = "Select (Select isnull(SUM(DAY_TT),0) from FILC04A where LEA_ID=N'001' and EMP_ID=N'" + EMP_ID + "' and STR_DT>='"
                                          + fromdate.ToString("yyyy") + "/01/01' and STR_DT<'" + fromdate.AddMonths(1).ToString("yyyy/MM") + "/01') AS Tuden,";
                            sql += "(Select isnull(SUM(DAY_TT),0) from FILC04A where LEA_ID=N'001' and EMP_ID=N'" + EMP_ID + "' and STR_DT>='"
                                   + fromdate.ToString("yyyy/MM") + "/01' and STR_DT<'" + fromdate.AddMonths(1).ToString("yyyy/MM") + "/01') AS Trongthang";
                            sql += " from FILC04C where EMP_ID=N'" + EMP_ID + "' and YYY_YY=N'" + fromdate.ToString("yyyyMM") + "'";
                            //sql="Select FILC04C set DID_QT="+sqltuden+",DID_MM="+sqltrongthang+" where EMP_ID=N'"+EMP_ID+"' and YYY_YY=N'"+fromdate.ToString("yyyyMM")+"'";
                            Func.RecordSet rrss = new Func.RecordSet(sql, con);
                            if (Batdautinh.Year > fromdate.Year)
                            {
                                UpdateStaff0(EMP_ID, con, fromdate.ToString("yyyyMM"));
                                return;
                            }
                            else
                            {
                                if (fromdate.Year == Batdautinh.Year)
                                {
                                    if (fromdate.Month - Batdautinh.Month + 1 >= 12)
                                    {
                                        phepduochuongtuden = phepnam1nam;
                                    }
                                    else
                                    {
                                        if (fromdate.Month - Batdautinh.Month + 1 >= 6)
                                        {
                                            phepduochuongtuden = phepnamnuanam + (fromdate.Month - Batdautinh.Month + 1 - 6) * phepnam1thang;
                                        }
                                        else
                                        {
                                            if (fromdate.Month - Batdautinh.Month + 1 >= 0 && (fromdate.Month - Batdautinh.Month + 1 < 6))
                                            {
                                                phepduochuongtuden = phepnam1thang * (fromdate.Month - Batdautinh.Month + 1);
                                            }
                                        }
                                    }
                                    phepduochuongtrongthang = phepnam1thang;
                                    phepnghitrongthang      = T_String.IsNullTo0(rrss.record(0, "Trongthang"));
                                    phepconlaitrongthang    = phepduochuongtrongthang - phepnghitrongthang;
                                    phepnghituden           = T_String.IsNullTo0(rrss.record(0, "Tuden"));
                                    phepconlaituden         = phepduochuongtuden - phepnghituden;
                                }
                                else
                                {
                                    DateTime ngaytinhmoi = fromdate.AddMonths(-fromdate.Month + 1);
                                    if (fromdate.Month - ngaytinhmoi.Month + 1 >= 12)
                                    {
                                        phepduochuongtuden = phepnam1nam;
                                    }
                                    else
                                    {
                                        if (fromdate.Month - ngaytinhmoi.Month + 1 >= 6)
                                        {
                                            phepduochuongtuden = phepnamnuanam + (fromdate.Month - ngaytinhmoi.Month + 1 - 6) * phepnam1thang;
                                        }
                                        else
                                        {
                                            if (fromdate.Month - ngaytinhmoi.Month + 1 >= 0 && (fromdate.Month - ngaytinhmoi.Month + 1 < 6))
                                            {
                                                phepduochuongtuden = phepnam1thang * (fromdate.Month - ngaytinhmoi.Month + 1);
                                            }
                                        }
                                    }
                                    phepduochuongtrongthang = phepnam1thang;
                                    phepnghitrongthang      = T_String.IsNullTo0(rrss.record(0, "Trongthang"));
                                    phepconlaitrongthang    = phepduochuongtrongthang - phepnghitrongthang;
                                    phepnghituden           = T_String.IsNullTo0(rrss.record(0, "Tuden"));
                                    phepconlaituden         = phepduochuongtuden - phepnghituden;
                                }
                            }
                            // tinh tham nien
                            int      thamnien   = 0;
                            DateTime Ngayvaolam = DateTime.Parse(INH_DT);
                            int      sonam      = T_String.IsNullTo0(rs.record(0, "SEN_YY"));
                            int      songay     = T_String.IsNullTo0(rs.record(0, "SEN_DY"));
                            if (sonam != 0 && songay != 0)
                            {
                                while (true)
                                {
                                    Ngayvaolam = Ngayvaolam.AddYears(sonam);
                                    if (T_String.CompareDate(fromdate, Ngayvaolam))
                                    {
                                        thamnien += songay;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            sql  = "update FILC04C set HAV_QT=" + phepconlaituden + ",HAV_MM=" + phepconlaitrongthang + ",ADD_QT=" + thamnien + ",";
                            sql += "DID_QT=" + phepnghituden + ",DID_MM=" + phepnghitrongthang + ",CAN_QT=" + phepduochuongtuden + ",APP_MM=" + phepduochuongtrongthang + " ";
                            sql += " where EMP_ID=N'" + EMP_ID + "' and YYY_YY=N'" + fromdate.ToString("yyyyMM") + "'";
                            PublicFunction.SQL_Execute(sql, con);
                        }
                        else
                        {
                            //Thang bat dau tinh phep nam
                            int WAG_MM = T_String.IsNullTo0(rs.record(0, "WAG_MM"));
                            /////////
                            ///Ngay tinh de doi chieu voi ngay tinh cua chuong trinh
                            int ngaytinh      = T_String.IsNullTo0(rs.record(0, "STR_DT"));
                            int phepnam1nam   = T_String.IsNullTo0(rs.record(0, "LEA_DY"));
                            int phepnamnuanam = T_String.IsNullTo0(rs.record(0, "LEA_PY"));
                            int phepnam1thang = T_String.IsNullTo0(rs.record(0, "LEA_DM"));
                            //Thang bat dau tinh cong them vao ngay vao lam
                            DateTime Batdautinh = DateTime.Parse(INH_DT).AddMonths(WAG_MM);
                            DateTime dt1 = DateTime.Parse(INH_DT);
                            int      phepduochuongtuden = 0, phepduochuongtrongthang = 0, phepnghitrongthang = 0, phepnghituden = 0, phepconlaitrongthang = 0, phepconlaituden = 0;
                            label5.Text = fromdate.ToString("yyyy/MM");
                            sql         = "Select (Select isnull(SUM(DAY_TT),0) from FILC04A where LEA_ID=N'001' and EMP_ID=N'" + EMP_ID + "' and STR_DT>='"
                                          + fromdate.ToString("yyyy") + "/01/01' and STR_DT<'" + fromdate.AddMonths(1).ToString("yyyy/MM") + "/01') AS Tuden,";
                            sql += "(Select isnull(SUM(DAY_TT),0) from FILC04A where LEA_ID=N'001' and EMP_ID=N'" + EMP_ID + "' and STR_DT>='"
                                   + fromdate.ToString("yyyy/MM") + "/01' and STR_DT<'" + fromdate.AddMonths(1).ToString("yyyy/MM") + "/01') AS Trongthang";
                            sql += " from FILC04C where EMP_ID=N'" + EMP_ID + "' and YYY_YY=N'" + fromdate.ToString("yyyyMM") + "'";
                            //sql="Select FILC04C set DID_QT="+sqltuden+",DID_MM="+sqltrongthang+" where EMP_ID=N'"+EMP_ID+"' and YYY_YY=N'"+fromdate.ToString("yyyyMM")+"'";
                            Func.RecordSet rrss = new Func.RecordSet(sql, con);
                            if (Batdautinh.Year > fromdate.Year)
                            {
                                UpdateStaff0(EMP_ID, con, fromdate.ToString("yyyyMM"));
                                return;
                            }
                            else
                            {
                                if (fromdate.Year == Batdautinh.Year)
                                {
                                    if (fromdate.Month - Batdautinh.Month + 1 >= 12)
                                    {
                                        phepduochuongtuden = phepnam1nam;
                                    }
                                    else
                                    {
                                        if (fromdate.Month - Batdautinh.Month + 1 >= 6)
                                        {
                                            phepduochuongtuden = phepnamnuanam + (fromdate.Month - Batdautinh.Month + 1 - 6) * phepnam1thang;
                                        }
                                        else
                                        {
                                            if (fromdate.Month - Batdautinh.Month + 1 >= 0 && (fromdate.Month - Batdautinh.Month + 1 < 6))
                                            {
                                                phepduochuongtuden = phepnam1thang * (fromdate.Month - Batdautinh.Month + 1);
                                            }
                                        }
                                    }
                                    phepduochuongtrongthang = phepnam1thang;
                                    phepnghitrongthang      = T_String.IsNullTo0(rrss.record(0, "Trongthang"));
                                    phepconlaitrongthang    = phepduochuongtrongthang - phepnghitrongthang;
                                    phepnghituden           = T_String.IsNullTo0(rrss.record(0, "Tuden"));
                                    phepconlaituden         = phepduochuongtuden - phepnghituden;
                                }
                                else
                                {
                                    DateTime ngaytinhmoi = fromdate.AddMonths(-fromdate.Month + 1);
                                    if (fromdate.Month - ngaytinhmoi.Month + 1 >= 12)
                                    {
                                        phepduochuongtuden = phepnam1nam;
                                    }
                                    else
                                    {
                                        if (fromdate.Month - ngaytinhmoi.Month + 1 >= 6)
                                        {
                                            phepduochuongtuden = phepnamnuanam + (fromdate.Month - ngaytinhmoi.Month + 1 - 6) * phepnam1thang;
                                        }
                                        else
                                        {
                                            if (fromdate.Month - ngaytinhmoi.Month + 1 >= 0 && (fromdate.Month - ngaytinhmoi.Month + 1 < 6))
                                            {
                                                phepduochuongtuden = phepnam1thang * (fromdate.Month - ngaytinhmoi.Month + 1);
                                            }
                                        }
                                    }
                                    phepduochuongtrongthang = phepnam1thang;
                                    phepnghitrongthang      = T_String.IsNullTo0(rrss.record(0, "Trongthang"));
                                    phepconlaitrongthang    = phepduochuongtrongthang - phepnghitrongthang;
                                    phepnghituden           = T_String.IsNullTo0(rrss.record(0, "Tuden"));
                                    phepconlaituden         = phepduochuongtuden - phepnghituden;
                                }
                            }
                            // tinh tham nien
                            int      thamnien   = 0;
                            DateTime Ngayvaolam = DateTime.Parse(INH_DT);
                            int      sonam      = T_String.IsNullTo0(rs.record(0, "SEN_YY"));
                            int      songay     = T_String.IsNullTo0(rs.record(0, "SEN_DY"));
                            if (sonam != 0 && songay != 0)
                            {
                                while (true)
                                {
                                    Ngayvaolam = Ngayvaolam.AddYears(sonam);
                                    if (T_String.CompareDate(fromdate, Ngayvaolam))
                                    {
                                        thamnien += songay;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                            sql  = "update FILC04C set HAV_QT=" + phepconlaituden + ",HAV_MM=" + phepconlaitrongthang + ",ADD_QT=" + thamnien + ",";
                            sql += "DID_QT=" + phepnghituden + ",DID_MM=" + phepnghitrongthang + ",CAN_QT=" + phepduochuongtuden + ",APP_MM=" + phepduochuongtrongthang + " ";
                            sql += " where EMP_ID=N'" + EMP_ID + "' and YYY_YY=N'" + fromdate.ToString("yyyyMM") + "'";
                            PublicFunction.SQL_Execute(sql, con);
                        }
                    }
                    else
                    {
                        if (PublicFunction.tinhphepnam == 1)
                        {
                            CalStaff1(rs.record(i, "EMP_ID") + "", rs.record(i, "TYP_ID") + "", rs.record(i, "INH_DT") + "", con, dt);
                        }
                        CalStaffDaNghi(rs.record(i, "EMP_ID") + "", con, fromdate);
                    }
                    lb.Text   = (i + 1) + "/" + rs.rows + " __ " + ((int)(i + 1) * 100 / rs.rows) + "%";
                    lb2.Text  = rs.record(i, "EMP_ID") + " __ " + rs.record(i, "EMP_NM");
                    pro.Value = (int)(i + 1) * 100 / rs.rows;
                }
                lb2.Text       = PublicFunction.L_Get_Msg("Staff", 1);
                cmd_OK.Enabled = true;

                fromdate = fromdate.AddMonths(1);
            }
        }
예제 #5
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);
        }
예제 #6
0
/*		public static void CalStaff(string EMP_ID,string TYP_ID,string INH_DT,SqlConnection con,string YYY,DateTime dt)
 *              {
 *                      checkStaff(EMP_ID,con,YYY);
 *                      if(INH_DT+""=="") // ko co ngay vao
 *                      {
 *                              UpdateStaff0(EMP_ID,con,YYY);
 *                              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,YYY);
 *                              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 heso=(int)phepnam/12;
 *                      DateTime dt1=DateTime.Parse(INH_DT).AddMonths(WAG_MM);
 *                      //if(T_String.CompareDate(dt1,T_String.GetDate(con))) // ko du thoi gian lam viec de tinh phep
 *                      if(T_String.CompareDate(dt1,dt))
 *                      {
 *                              UpdateStaff0(EMP_ID,con,YYY);
 *                              return;
 *                      }
 *                      if(T_String.CompareDate(new DateTime(dt.Year,1,1),dt1))
 *                              dt1=new DateTime(dt.Year,1,1);
 *                      int ngayphep=0,dem=0;// tinh phep nam
 *                      if(dt1.Day<=ngaytinh)
 *                      {
 *                              ngayphep+= heso;
 *                              dem++;
 *                      }
 *                      dt1=dt1.AddMonths(1);
 *                      while (dt1.Month<dt.Month && dt1.Year==dt.Year)
 *                      {
 *                              ngayphep+= heso;
 *                              dt1=dt1.AddMonths(1);
 *                              dem++;
 *                      }
 *                      if(dt.Day>=ngaytinh && dt1.Month==dt.Month)
 *                      {
 *                              if(dem+1==12)
 *                              {
 *                                      ngayphep=phepnam;
 *                              }
 *                              else
 *                              {
 *                                      ngayphep+= heso;
 *                              }
 *                      }
 *                      // tinh tham nien
 *                      int thamnien=0;
 *                      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"));
 *                      if(sonam!=0 && songay!=0)
 *                      {
 *                              while(true)
 *                              {
 *                                      dt1=dt1.AddYears(sonam);
 *                                      if(T_String.CompareDate(dt,dt1))
 *                                              thamnien+=songay;
 *                                      else
 *                                              break;
 *                              }
 *                      }
 *
 *                      sql="update FILC04B set HAV_QT="+ngayphep+",ADD_QT="+thamnien+" where EMP_ID=N'"+EMP_ID+"' and YYY_YY=N'"+dt.ToString("yyyy")+"'";
 *                      PublicFunction.SQL_Execute(sql,con);
 *              }
 */
        #endregion
        public static void CalStaff(string EMP_ID, string TYP_ID, string INH_DT, SqlConnection con, string YYY, DateTime dt)
        {
            checkStaff(EMP_ID, con, YYY);

            if (INH_DT + "" == "")        // ko co ngay vao
            {
                UpdateStaff0(EMP_ID, con, YYY);
                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, YYY);
                return;
            }
            int WAG_MM   = T_String.IsNullTo0(rs.record(0, "WAG_MM"));
            int ngaytinh = T_String.IsNullTo0(rs.record(0, "STR_DT"));

//			//////////////kien
            string PNcalday = PublicFunction.GetOption("PNcalday");

            ////kien cho phep sua trung ma bo phan
            if (PNcalday == "1")
            {
                int test = DateTime.Parse(INH_DT).Day;
                // string ngaytemp=Convert.ToString((test));
                ngaytinh = test;
            }
            int      phepnam = T_String.IsNullTo0(rs.record(0, "LEA_DY"));
            int      heso    = (int)phepnam / 12;
            DateTime dt1     = DateTime.Parse(INH_DT).AddMonths(WAG_MM);

            if (dt.Year < T_String.GetDate(con).Year)
            {
                if (T_String.CompareDate(dt1, dt))               // ko du thoi gian lam viec de tinh phep
                {
                    UpdateStaff0(EMP_ID, con, YYY);
                    return;
                }
            }
            else
            {
                if (T_String.CompareDate(dt1, T_String.GetDate(con)))               // ko du thoi gian lam viec de tinh phep
                {
                    UpdateStaff0(EMP_ID, con, YYY);
                    return;
                }
            }
            /// khuend them vao de nhan biet nguoi cu tinh tu thang 1
            ///
            if (T_String.CompareDate(new DateTime(dt.Year, 1, 1), dt1))
            {
                dt1 = new DateTime(dt.Year, 1, 1);
            }
            int     ngayphep = 0, dem = 0;   // tinh phep nam
            Decimal ngayphep1 = 0;

            //////////////////////////////////////Kien tinh so ngay toi thoi diem hien tai hoa toi nghi viec/////////////////////////////////////////
            while (dt1.Month <= dt.Month && dt1.Year == dt.Year)
            {
                ngayphep += heso;
                dt1       = dt1.AddMonths(1);
                dem++;
            }
            if ((dt.Day >= ngaytinh || DateTime.Parse(INH_DT).Year < dt.Year || ngayphep > 0) && dt1.Month == dt.Month)
            {
                if (dem + 1 == 12)
                {
                    ngayphep = phepnam;
                }
                else
                {
                    ngayphep += heso;
                }
            }
            //////////////kien phep nam tinh ngay
            ////string PNcalday=PublicFunction.GetOption("PNcalday");
            ////kien cho phep sua trung ma bo phan
            if (PNcalday == "1")
            {
                int test = DateTime.Parse(INH_DT).Day;
                ngaytinh = test;
            }
            //////////////////////kien ket thuc phep nam tinh ngay
            //moi thang duoc 1 ngay phep nam ,neu cong nhan 14 du 1 nam se duoc cong 2 ngay, nguoc lai thi moi thang duoc 1 ngay
            string ALEtop      = PublicFunction.GetOption("ALEtop");
            string ALAngelbell = PublicFunction.GetOption("ALAngelbell");

            if (ALEtop == "1" || ALAngelbell == "1")
            {
                if (phepnam == 14 && T_String.GetDate(con).Month == 12)
                {
                    DateTime dateTime = Convert.ToDateTime(T_String.GetDate(con));
                    DateTime temp     = Convert.ToDateTime(INH_DT);
                    temp = temp.AddYears(+1);
                    if (temp <= dateTime)
                    {
                        ngayphep = ngayphep + 2;
                    }
                    else
                    {
                    }
                }
                else
                {
                    //ngayphep=T_String.GetDate(con).Month;
                }

                if (ALEtop == "1")
                {
                    if (dt1.Day > T_String.GetDate(con).Day)
                    {
                        ngayphep = ngayphep - 1;
                    }
                }

                if (ALAngelbell == "1")
                {
                    if (DateTime.Parse(INH_DT).Year == T_String.GetDate(con).Year)
                    {
                        ngayphep = 0;
                    }
                    if (DateTime.Parse(INH_DT).Year + 1 == T_String.GetDate(con).Year)
                    {
                        ngayphep = ngayphep + phepnam - DateTime.Parse(INH_DT).Month;
                    }
                    if (DateTime.Parse(INH_DT).Year + 1 == T_String.GetDate(con).Year&& DateTime.Parse(INH_DT).Month > T_String.GetDate(con).Month)
                    {
                        ngayphep = 0;
                    }
                }
            }

            if (PublicFunction.CUS_ID == "22")
            {
                dt1 = DateTime.Parse(INH_DT);
                if ((dt1.Day > 15) && (dt1.Year == dt.Year))
                {
                    if (ngayphep != 0)
                    {
                        ngayphep -= 1;
                    }
                }
            }

            // tinh tham nien
            int thamnien = 0;

            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"));

            if (sonam != 0 && songay != 0)
            {
                while (true)
                {
                    dt1 = dt1.AddYears(sonam);
                    if (T_String.CompareDate(dt, dt1))
                    {
                        thamnien += songay;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //luan sua de tinh ngay vao 15
            DateTime dtResult = dt;

            if (dt.Day < 15 && ngayphep > 0)
            {
                ngayphep = ngayphep - 1;
            }

            ngayphep1 = ngayphep;

            if (phepnam == 14)
            {
                //Math.Round(Convert.ToDecimal(temp), 4)
                ngayphep1 = ngayphep1 * Math.Round(Convert.ToDecimal(14 / 12.0), 2);           //ngayphep1*Math.Round(Convert.ToDecimal(14/12.0), 2);
                if (ngayphep1 > 14)
                {
                    ngayphep1 = 14;
                }
            }
            //nhieu loai nhan vien
            if (T_String.IsNullTo0(T_String.GetDataFromSQL("Count(*)", "FILB02AA", "year(SEQ_DT)='" + dt.ToString("yyyy") + "' and EMP_ID='" + EMP_ID + "'")) > 0)
            {
                ngayphep1 = 0;
                dt1       = DateTime.Parse(INH_DT);
                if (dt1.Year < T_String.GetDate(con).Year)
                {
                    //dt1=T_String.DT_GetDays(DateTime.Parse(T_String.GetDate(con).Year + "/01/01"),T_String.GetDate(con));
                    dt1 = Convert.ToDateTime((T_String.GetDate(con).Year + "/01/01"));
                    //ngayk2=T_String.DT_GetDays(Convert.ToDateTime(INH_DT),T_String.GetDate(con));
                }

                string         sqlkk = "Select * from FILB02AA where EMP_ID='" + EMP_ID + "' order by SEQ_DT";
                Func.RecordSet rsk   = new Func.RecordSet(sqlkk, con);
                for (int k = 0; k < rsk.rows; k++)
                {
                    dt = Convert.ToDateTime(rsk.record(k, "SEQ_DT"));
                    while (dt1.Month < dt.Month && dt1.Year == dt.Year)
                    {
                        dt1 = dt1.AddMonths(1);
                        string TYP_IDt = rsk.record(k, "TYP_ID");
                        string ngay    = T_String.GetDataFromSQL("LEA_DY", "FILA11A", "TYP_ID='" + TYP_IDt + "'");
                        if (ngay == "14")
                        {
                            ngayphep1 += Math.Round(Convert.ToDecimal(14 / 12.0), 2);                          //Convert.ToDecimal(14/12.0); //Math.Round(Convert.ToDecimal(14/12.0), 2);
                        }
                        else
                        {
                            ngayphep1 += 1;
                        }
                    }
                    DateTime dtt     = Convert.ToDateTime(rsk.record(rsk.rows - 1, "SEQ_DT"));
                    DateTime monthtt = T_String.GetDate(con);

                    string vacate = T_String.GetDataFromSQL("VAC_BT", "FILB01A", "EMP_ID='" + EMP_ID + "'");
                    //DateTime vacate_date;
                    if (vacate == "True")
                    {
                        monthtt = DateTime.Parse(T_String.GetDataFromSQL("VAC_DT", "FILB01AC", "EMP_ID='" + EMP_ID + "'"));
                    }
                    while (dtt.Month <= monthtt.Month && dtt.Year == T_String.GetDate(con).Year&& k == rsk.rows - 1)
                    {
                        dtt = dtt.AddMonths(1);
                        string TYP_IDtt = rsk.record(k, "TYP_I1");
                        string ngayt    = T_String.GetDataFromSQL("LEA_DY", "FILA11A", "TYP_ID='" + TYP_IDtt + "'");
                        if (ngayt == "14")
                        {
                            ngayphep1 += Math.Round(Convert.ToDecimal(14 / 12.0), 2);
                        }
                        else
                        {
                            ngayphep1 += 1;
                        }
                    }
                }
            }
            Decimal ngayphep2 = 0;

            if (PublicFunction.CUS_ID == "22")         //Rehong
            {
                ngayphep2 = Math.Round(Convert.ToDecimal(ngayphep1), 2);
                if (ngayphep1 - Decimal.Floor(ngayphep1) > (Decimal)0.5000)
                {
                    ngayphep2 = Decimal.Floor(ngayphep1) + 1;
                }
            }

//			///////doi voi nv chua lam du 1 thang da nghi/////////////
            string nghiviec = T_String.GetDataFromSQL("VAC_BT", "FILB01A", "EMP_ID='" + EMP_ID + "'");

            if (nghiviec == "True")
            {
                DateTime ngayvao  = DateTime.Parse(INH_DT);
                DateTime ngaynghi = DateTime.Parse(T_String.GetDataFromSQL("VAC_DT", "FILB01AC", "EMP_ID='" + EMP_ID + "'"));
                TimeSpan m        = ngaynghi.Subtract(ngayvao);
                int      thang    = m.Days;
                if (thang / 30 <= 1)
                {
                    ngayphep1 = 0;
                    ngayphep2 = 0;
                }
            }
            ////////////////////////////
            sql = "update FILC04B set HAV_QT=" + ngayphep1 + ",ADD_QT=" + thamnien + ",TLCN=" + ngayphep2 + " where EMP_ID=N'" + EMP_ID + "' and YYY_YY=N'" + dt.ToString("yyyy") + "'";
            PublicFunction.SQL_Execute(sql, con);
        }
        public static void CalStaff(string EMP_ID, string TYP_ID, string INH_DT, SqlConnection con, string YYY, DateTime dt, Boolean nghiviec)
        {
            checkStaff(EMP_ID, con, YYY);
            if (INH_DT + "" == "")        // ko co ngay vao
            {
                UpdateStaff0(EMP_ID, con, YYY);
                return;
            }
            //LAY OPTION XEM CO TINH TRUOC PHEP NAM DEN CUOI NAM KO??
            if (T_String.IsNullTo0(PublicFunction.GetOption("ALLASTYEAR")) == 1)
            {
                if (!nghiviec)
                {
                    if (PublicFunction.CUS_ID == "22")                 //omexey,vao lam >=1 nam moi duoc muon truoc
                    {
                        if (double.Parse(DateTime.Parse(INH_DT).AddYears(1).ToString("yyyyMMdd")) <= double.Parse(dt.ToString("yyyyMMdd")))
                        {
                            dt = new DateTime(dt.Year, 12, 31);
                        }
                    }
                    else
                    {
                        dt = new DateTime(dt.Year, 12, 31);
                    }
                }
            }

            string sql;
            double ngayphep = 0;

            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, YYY);
                return;
            }
            //KIEM TRA LICH SU CHUYEN LOAI NHAN VIEN
            if (PublicFunction.GetOption("TYP_BT") == "1")         //quang viet
            {
                int ngaytinh = T_String.IsNullTo0(T_String.GetDataFromSQL("STR_DT", "FILA11A", "TYP_ID='" + TYP_ID + "'"));
                sql = "SELECT * FROM FILB09A WHERE EMP_ID='" + EMP_ID + "' AND YEAR(SWI_DT)=" + YYY + " ORDER BY SWI_DT";
                Func.RecordSet rs1 = new Func.RecordSet(sql, con);
                if (rs1.rows > 0)
                {
                    string   TYP_NEW = "", TYP_OLD = "", dt_INH = "";
                    DateTime dt_DT = DateTime.Parse(rs1.record(0, "SWI_DT") + "");
                    if (dt_DT < dt)
                    {
                        for (int i = 0; i < rs1.rows; i++)
                        {
                            TYP_NEW = rs1.record(i, "TYP_I1") + "";
                            TYP_OLD = rs1.record(i, "TYP_I2") + "";
                            if (i == 0)
                            {
                                dt_INH = INH_DT;
                            }
                            else
                            {
                                dt_INH = DateTime.Parse(rs1.record(i - 1, "SWI_DT") + "").ToString();
                            }

                            dt_DT = DateTime.Parse(rs1.record(i, "SWI_DT") + "");
                            if (dt_DT.Month > 1 && dt_DT.Day > 1)
                            {
                                dt_DT = dt_DT.AddDays(-1);
                            }
                            if (dt_DT > dt)
                            {
                                dt_DT = dt;
                                if (dt_DT.Day < ngaytinh)                              //neu ngay chuyen nho hon ngay tinh thi thang do ko tinh
                                {
                                    if (dt_DT.Month == 1)
                                    {
                                        ngayphep += 0;
                                    }
                                    else
                                    {
                                        ngayphep += CalStaff_Sub(EMP_ID, TYP_OLD, dt_INH, con, YYY, dt_DT.AddMonths(-1), nghiviec);
                                    }
                                }
                                else
                                {
                                    ngayphep += CalStaff_Sub(EMP_ID, TYP_OLD, dt_INH, con, YYY, dt_DT, nghiviec);
                                }
                                i = rs1.rows;                               //ket thuc for
                            }
                            else
                            {
                                if (dt_DT.Day < ngaytinh)
                                {
                                    if (dt_DT.Month == 1)
                                    {
                                        ngayphep += 0;
                                    }
                                    else
                                    {
                                        ngayphep += CalStaff_Sub(EMP_ID, TYP_OLD, dt_INH, con, YYY, dt_DT.AddMonths(-1), nghiviec);
                                    }
                                }
                                //ngayphep+=CalStaff_Sub(EMP_ID,TYP_OLD,dt_INH,con,YYY,dt_DT,nghiviec);
                                else
                                {
                                    ngayphep += CalStaff_Sub(EMP_ID, TYP_OLD, dt_INH, con, YYY, dt_DT, nghiviec);
                                }
                                if (i == rs1.rows - 1)                             //dong cuoi cung
                                {
                                    //dt_DT=dt_DT.AddDays(1);
                                    if (dt_DT > dt)
                                    {
                                        i = rs1.rows;                                      //ket thuc for
                                    }
                                    else
                                    {
                                        if (DateTime.Parse(dt_INH) < dt_DT)
                                        {
                                            dt_INH = dt_DT.ToString();
                                        }
                                        if (i + 1 < rs1.rows)
                                        {
                                            dt_DT = DateTime.Parse(rs1.record(i + 1, "SWI_DT") + "");
                                            if (dt_DT > dt)
                                            {
                                                dt_DT = dt;
                                                i     = rs1.rows;
                                            }
                                        }
                                        else
                                        {
                                            dt_DT = dt;
                                        }
                                        ngayphep += CalStaff_Sub(EMP_ID, TYP_NEW, dt_INH, con, YYY, dt_DT, nghiviec);
                                    }
                                }
                            }
                        }                        // end for
                    }
                    else
                    {
                        ngayphep = CalStaff_Sub(EMP_ID, TYP_ID, INH_DT, con, YYY, dt, nghiviec);
                    }
                }
                else
                {
                    ngayphep = CalStaff_Sub(EMP_ID, TYP_ID, INH_DT, con, YYY, dt, nghiviec);
                }
            }
            else
            {
                ngayphep = CalStaff_Sub(EMP_ID, TYP_ID, INH_DT, con, YYY, dt, nghiviec);
            }
            //truong hop nghi viec
            if (nghiviec)
            {
                if (PublicFunction.CUS_ID == "52")             //domex quang nam
                {
                    DateTime dtoff = DateTime.Parse(T_String.GetDataFromSQL("VAC_DT", "FILB01AC", "EMP_ID='" + EMP_ID + "'"));
                    if (dtoff.Day < 16)
                    {
                        ngayphep = ngayphep - (float)T_String.IsNullTo0(rs.record(0, "LEA_DY")) / 12;
                    }
                    if (dtoff.Day >= 16 && dtoff.Day <= 24)
                    {
                        ngayphep = ngayphep - ((float)T_String.IsNullTo0(rs.record(0, "LEA_DY")) / 12) * 0.5;
                    }
                    if (dtoff.Day > 24)
                    {
                        ngayphep = ngayphep;
                    }
                }
            }
            //end nghi viec
            // tinh tham nien
            int      thamnien = 0;
            DateTime 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"));

            if (sonam != 0 && songay != 0)
            {
                while (true)
                {
                    dt1 = dt1.AddYears(sonam);
                    if (T_String.CompareDate(dt, dt1))
                    {
                        thamnien += songay;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            //NEU OPTION WAGMM_BT=1-> TINH LUON NHUNG THANG KHOI TINH KHI DU DK TINH PHEP NAM
            if (PublicFunction.GetOption("WAGMM_BT") == "1" && DateTime.Parse(INH_DT).Year == dt.Year)
            {
                ngayphep = ngayphep + T_String.IsNullTo0(rs.record(0, "WAG_MM")) * (float)T_String.IsNullTo0(rs.record(0, "LEA_DY")) / 12;;
            }                                                   //END
            if (PublicFunction.CUS_ID == "51")                  //cong ty Quang viet TG
            {
                ngayphep = Math.Floor(Math.Round(ngayphep, 1)); //Math.Round(ngayphep,2);
            }
            else if (PublicFunction.CUS_ID == "50")             //QV Cu Chi
            {
                ngayphep = Math.Round(ngayphep, 1);
                if (ngayphep - Math.Floor(ngayphep) < 0.5)
                {
                    ngayphep = Math.Floor(ngayphep);
                }
                else
                {
                    ngayphep = Math.Floor(ngayphep) + 1;
                }
            }
            else
            {
                if (PublicFunction.CUS_ID == "62")             //DOMEX
                {
                    ngayphep = Math.Round(ngayphep, 1);
                    if (ngayphep - Math.Floor(ngayphep) <= 0.4)
                    {
                        ngayphep = Math.Floor(ngayphep);
                    }
                    else
                    {
                        ngayphep = Math.Floor(ngayphep) + 1;
                    }
                }
                else
                {
                    if (ngayphep - Math.Floor(ngayphep) > 0.49 && (ngayphep - Math.Floor(ngayphep) < 0.99))
                    {
                        //ngayphep=Math.Floor(ngayphep)+0.5;
                        ngayphep = ngayphep;
                    }
                    else if (ngayphep - Math.Floor(ngayphep) >= 0.99)
                    {
                        //ngayphep=Math.Floor(ngayphep)+1;
                        ngayphep = ngayphep;
                    }
                    else
                    {
                        ngayphep = ngayphep;
                    }
                }
            }
//			//if (PublicFunction.CUS_ID=="300")//cong ty KenYa
//			if (ngayphep-Math.Floor(ngayphep)>0.49 && (ngayphep-Math.Floor(ngayphep)<0.99))
//				ngayphep=Math.Floor(ngayphep)+0.5;
//			else if (ngayphep-Math.Floor(ngayphep)>=0.99)
//				ngayphep=Math.Floor(ngayphep)+1;
//			else
//				ngayphep=Math.Floor(ngayphep);
//======== THU SUA PHEP NAM TINH THEO LICH SU THAY DOI LOAI NHAN VIEN END=========
            sql = "update FILC04B set HAV_QT=" + ngayphep + ",ADD_QT=" + thamnien + " where EMP_ID=N'" + EMP_ID + "' and YYY_YY=N'" + dt.ToString("yyyy") + "'";
            PublicFunction.SQL_Execute(sql, con);
        }
        public static double CalStaff_Sub(string EMP_ID, string TYP_ID, string INH_DT, SqlConnection con, string YYY, DateTime dt, Boolean nghiviec)
        {
            if (DateTime.Parse(INH_DT) >= dt)
            {
                return(0);
            }
            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, YYY);
                return(0);
            }
            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"));
            //if (TYP_ID== )
            float    heso = (float)phepnam / 12;
            DateTime dt1  = new DateTime();

            //kiem tra ngay vao lam
            if (DateTime.Parse(T_String.GetDataFromSQL("INH_DT", "FILB01A", "EMP_ID='" + EMP_ID + "'")) == DateTime.Parse(INH_DT))
            {
                dt1 = DateTime.Parse(INH_DT).AddMonths(WAG_MM);
            }
            //dt1=DateTime.Parse(INH_DT);
            else
            {
                dt1 = DateTime.Parse(INH_DT);
            }
            if (nghiviec)
            {
                if (dt.Year < T_String.GetDate(con).Year)
                {
                    if (T_String.CompareDate(dt1, dt))                   // ko du thoi gian lam viec de tinh phep

                    {
                        UpdateStaff0(EMP_ID, con, YYY);
                        return(0);
                    }
                }
                else
                {
                    if (T_String.CompareDate(dt1, dt))                   // ko du thoi gian lam viec de tinh phep

                    {
                        UpdateStaff0(EMP_ID, con, YYY);
                        return(0);
                    }
                }
            }
            else
            {
                if (dt.Year < T_String.GetDate(con).Year)
                {
                    if (T_String.CompareDate(dt1, dt))                   // ko du thoi gian lam viec de tinh phep

                    {
                        UpdateStaff0(EMP_ID, con, YYY);
                        return(0);
                    }
                }
                else
                {
                    if (T_String.CompareDate(dt1, T_String.GetDate(con)))                   // ko du thoi gian lam viec de tinh phep

                    {
                        UpdateStaff0(EMP_ID, con, YYY);
                        return(0);
                    }
                }
            }
            if (T_String.CompareDate(new DateTime(dt.Year, 1, 1), dt1))
            {
                dt1 = new DateTime(dt.Year, 1, 1);
                //ngaytinh=32;
            }
            double ngayphep = 0, dem = 0;       // tinh phep nam

            if (dt1.Day <= ngaytinh)
            {
                ngayphep += heso;
                dem++;
            }
            dt1 = dt1.AddMonths(1);
            while (dt1.Month <= dt.Month && dt1.Year == dt.Year)        //// luc truoc tinh <= nhung khuend sua lai <
            {
                ngayphep += heso;

                dt1 = dt1.AddMonths(1);
                dem++;
            }
            if ((dt.Day >= ngaytinh || DateTime.Parse(INH_DT).Year < dt.Year || ngayphep > 0) && dt1.Month == dt.Month)
            {
                if (dem + 1 == 12)
                {
                    ngayphep = phepnam;
                }
                else
                {
                    ngayphep += heso;
                }
            }
            string PNcalday = PublicFunction.GetOption("PNcalday");

            if (PNcalday == "1")
            {
                // DateTime dateTime = Convert.ToDateTime(vs4.Rows[i]["LAB_ED"]);
                // // dateTime=dateTime.AddDays(-1);
                // vs4.Rows[i]["LAB_ED"]=dateTime;
                int test = DateTime.Parse(INH_DT).Day;
                // string ngaytemp=Convert.ToString((test));
                ngaytinh = test;

                if (ngayphep > 0 && test > 15 && DateTime.Parse(INH_DT).Year == dt.Year)           /// luc truoc la the nay test>dt.Day
                {
                    ngayphep = ngayphep - heso;
                }
            }

            return(ngayphep);
        }