public List <cChkInOut_A> GhepCIO_A(List <cChk> DSchkInn, List <cChk> DSchkOut) { List <cChkInOut_A> kq = new List <cChkInOut_A>(); int x1 = 0, x2 = 0; if (DSchkInn.Count == 0 && DSchkOut.Count != 0) { while (x2 < DSchkOut.Count) { kq.Add(new cChkInOut_A() { Vao = null, Raa = DSchkOut[x2], HaveINOUT = -2, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkOut[x2].TimeStr.Date, TimeStrDaiDien = DSchkOut[x2].TimeStr }); } } else if (DSchkInn.Count != 0 && DSchkOut.Count == 0) { while (x1 < DSchkInn.Count) { kq.Add(new cChkInOut_A() { Vao = DSchkInn[x1], Raa = null, HaveINOUT = -1, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkInn[x1].TimeStr.Date, TimeStrDaiDien = DSchkInn[x1].TimeStr }); } } else if (DSchkInn.Count != 0 && DSchkOut.Count != 0) { while (x1 < DSchkInn.Count && x2 < DSchkOut.Count) { cChk chkinn = DSchkInn[x1]; cChk chkout = DSchkOut[x2]; DateTime timeInn = chkinn.TimeStr; DateTime timeOut = chkout.TimeStr; if (timeOut <= timeInn)//ra ko vào { kq.Add(new cChkInOut_A() { Vao = null, Raa = DSchkOut[x2], HaveINOUT = -2, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkOut[x2].TimeStr.Date, TimeStrDaiDien = DSchkOut[x2].TimeStr }); x2++; } else { TimeSpan duration = timeOut - timeInn; if (duration <= ThamSo._30phut || duration > ThamSo._21h45) { kq.Add(new cChkInOut_A() { Vao = DSchkInn[x1], Raa = null, HaveINOUT = -1, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkInn[x1].TimeStr.Date, TimeStrDaiDien = DSchkInn[x1].TimeStr }); kq.Add(new cChkInOut_A() { Vao = null, Raa = DSchkOut[x2], HaveINOUT = -2, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkOut[x2].TimeStr.Date, TimeStrDaiDien = DSchkOut[x2].TimeStr }); } else { kq.Add(new cChkInOut_A() { Vao = DSchkInn[x1], Raa = DSchkOut[x2], HaveINOUT = 1, TongGioThuc = duration, ThuocNgayCong = ThamSo.GetDate(DSchkInn[x1].TimeStr), TimeStrDaiDien = DSchkInn[x1].TimeStr }); } x1++; x2++; } } if (x2 < DSchkOut.Count) { while (x2 < DSchkOut.Count) { kq.Add(new cChkInOut_A() { Vao = null, Raa = DSchkOut[x2], HaveINOUT = -2, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkOut[x2].TimeStr.Date, TimeStrDaiDien = DSchkOut[x2].TimeStr }); } } else if (x1 < DSchkInn.Count) { while (x1 < DSchkInn.Count) { kq.Add(new cChkInOut_A() { Vao = DSchkInn[x1], Raa = null, HaveINOUT = -1, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkInn[x1].TimeStr.Date, TimeStrDaiDien = DSchkInn[x1].TimeStr }); } } } return(kq); }
public List <cNgayCong> TinhCongTheoNgay(List <cChkInOut> pDSVaoRa, DateTime ngayBD, DateTime ngayKT, int UserEnrollNumber) { log.Debug("UserEnrollNumber " + UserEnrollNumber); List <cNgayCong> kq = new List <cNgayCong>(); DateTime ngaydem; if (pDSVaoRa.Count == 0) { ngaydem = ngayBD.Date; while (ngaydem <= ngayKT) // <= vì lấy luôn ngày KT : vắng mặt { cNgayCong ngayKOcheck = new cNgayCong() { NgayCong = ngaydem, HasCheck = false, DSVaoRa = new List <cChkInOut>(), }; kq.Add(ngayKOcheck); ngaydem = ngaydem.AddDays(1.0d); } return(kq); } int vtriBD = 0; ngaydem = ngayBD.Date; while (ngaydem <= ngayKT.Date) { if (vtriBD >= pDSVaoRa.Count) // hết DS nhưng ngaydem <= ngày KT ==> ghi lại những ngày sau là vắng mặt { while (ngaydem <= ngayKT.Date) { cNgayCong ngayKOcheck = new cNgayCong() { NgayCong = ngaydem, HasCheck = false, DSVaoRa = new List <cChkInOut>(), }; kq.Add(ngayKOcheck); ngaydem = ngaydem.AddDays(1d); } continue; } // chưa hết DS, bắt đầu từ ngày của DSVaoRa tại vtbd, đó là ngày có mặt cChkInOut CIO = pDSVaoRa[vtriBD]; XL.TinhCongTheoCa(CIO, CIO.ThuocCa); DateTime ngayCoMat = CIO.ThuocNgayCong; // ghi lại những ngày vắng mặt trước ngày có mặt while (ngaydem < ngayCoMat) // ko có = vì chỉ chạy đến trước ngày của tmpVaoRa thôi { cNgayCong ngayKOcheck = new cNgayCong() { NgayCong = ngaydem, HasCheck = false, DSVaoRa = new List <cChkInOut>(), }; kq.Add(ngayKOcheck); ngaydem = ngaydem.AddDays(1.0d); } //ngaydem = ngày có mặt. stop, tmpVaoRa là vào ra đầu tiên trong ngày #region collapse cNgayCong ngayCOcheck = new cNgayCong() { HasCheck = true, NgayCong = ngayCoMat, TinhPC150 = true, TinhPC200 = false,// mặc định khởi tạo ngày có tính PC 50%, nếu tồn tại ít nhất 1 ca nào ko tính pc 50% thì set cả ngày ko tính pc 50% TongGioLam = CIO.TGLamTinhCong, TongGioLamDem = CIO.TGLamDem, TongGioThuc = CIO.TongGioThuc, TongTre = CIO.VaoTre, TongSom = CIO.RaaSom, TongCong = CIO.Cong, PhuCapDem = ((CIO.TGLamDem.TotalHours > 0f) ? ((float)(CIO.TGLamDem.TotalHours / 8f) * 0.3f) : 0f) // công thức cũ (tính phụ cấp tăng ca theo công) là : + (((tmpVaoRa.Cong > 1f) ? (tmpVaoRa.Cong - 1f) * 0.5f : 0f)) // đổi lại công thức mới (tính phụ cấp theo giờ) là : + (((tmpVaoRa.TGLamTinhCong.TotalHours > 8f) ? (((float)tmpVaoRa.TGLamTinhCong.TotalHours - 8f) / 8f) * 0.5f : 0f)) }; if (CIO.QuaDem == true) { ngayCOcheck.QuaDem = true; // set qua đêm nếu có } if (ngayCOcheck.TinhPC150) { if (CIO.TinhPC150 == false) { ngayCOcheck.TinhPC150 = false; } if (ngayCOcheck.TinhPC150) { ngayCOcheck.PhuCapThem = (((CIO.TGLamTinhCong.TotalHours > 8f) ? ((((float)CIO.TGLamTinhCong.TotalHours - 8f) / 8f) * 0.5f) : 0f)); } else { ngayCOcheck.PhuCapThem = 0f; } } else { ngayCOcheck.PhuCapThem = 0f; } ngayCOcheck.TongPhuCap = ngayCOcheck.PhuCapDem + ngayCOcheck.PhuCapThem; ngayCOcheck.them(CIO); #endregion // sau khi tạo ngày công mới vào ra đó là vào ra đầu tiên thì chuyển sang VAORA next vtriBD++; // nếu hết ds thì ngưng, add tmpNgayCong1 vào danh sách ngày công (do chưa add) if (vtriBD >= pDSVaoRa.Count) { kq.Add(ngayCOcheck); ngaydem = ngayCOcheck.NgayCong.AddDays(1d); while (ngaydem <= ngayKT.Date) { cNgayCong ngayKOcheck = new cNgayCong() { NgayCong = ngaydem, HasCheck = false, DSVaoRa = new List <cChkInOut>(), }; kq.Add(ngayKOcheck); ngaydem = ngaydem.AddDays(1.0d); } continue; } // chưa hết DSVàoRa, xem các vào ra kế tiếp, nếu cùng ngày công thì add thêm vào tmpNgayCong1 while (vtriBD < pDSVaoRa.Count && ThamSo.GetDate(pDSVaoRa[vtriBD].TimeStrDaiDien) == ngayCOcheck.NgayCong) { cChkInOut CIO_1 = pDSVaoRa[vtriBD]; XL.TinhCongTheoCa(CIO_1, CIO_1.ThuocCa); #region collapse ngayCOcheck.TongGioThuc += CIO_1.TongGioThuc; ngayCOcheck.TongGioLam += CIO_1.TGLamTinhCong; ngayCOcheck.TongGioLamDem += CIO_1.TGLamDem; ngayCOcheck.TongTre += CIO_1.VaoTre; ngayCOcheck.TongSom += CIO_1.RaaSom; ngayCOcheck.TongCong += CIO_1.Cong; ngayCOcheck.PhuCapDem = ((ngayCOcheck.TongGioLamDem.TotalHours > 0f) ? ((float)(ngayCOcheck.TongGioLamDem.TotalHours / 8f) * 0.3f) : 0f); #endregion if (CIO_1.QuaDem == true) { ngayCOcheck.QuaDem = true; // set qua đêm nếu có } if (ngayCOcheck.TinhPC150) { if (CIO.TinhPC150 == false) { ngayCOcheck.TinhPC150 = false; } if (ngayCOcheck.TinhPC150) { ngayCOcheck.PhuCapThem = (((ngayCOcheck.TongGioLam.TotalHours > 8f) ? ((((float)ngayCOcheck.TongGioLam.TotalHours - 8f) / 8f) * 0.5f) : 0f)); } else { ngayCOcheck.PhuCapThem = 0f; } } else { ngayCOcheck.PhuCapThem = 0f; } ngayCOcheck.TongPhuCap = ngayCOcheck.PhuCapDem + ngayCOcheck.PhuCapThem; ngayCOcheck.them(CIO_1); vtriBD++; } //thoát khỏi vòng lặp: hoặc hết ds hoặc chuyển sang ngày mới if (vtriBD >= pDSVaoRa.Count) { kq.Add(ngayCOcheck); ngaydem = ngayCOcheck.NgayCong.AddDays(1d); while (ngaydem <= ngayKT.Date) { cNgayCong tmpNgayCong = new cNgayCong() { NgayCong = ngaydem, HasCheck = false, DSVaoRa = new List <cChkInOut>(), }; kq.Add(tmpNgayCong); ngaydem = ngaydem.AddDays(1.0d); } } else { kq.Add(ngayCOcheck); ngaydem = ngaydem.AddDays(1.0d); } } return(kq); }
public void ArrayRowsToDS_CIO_V(DataRow[] arrRows) // cấu trúc là cấu trúc ghép 2 bảng checkinout và xác nhận { if (DS_CIO_V == null) { DS_CIO_V = new List <cChkInOut_V>(); } else { DS_CIO_V.Clear(); } if (arrRows.Length != 0) { for (int i = 0; i < arrRows.Length; i = i + 2) { DataRow rowInn = arrRows[i]; if (i + 1 >= arrRows.Length) { continue; // ko có phần tử kế tiếp để xét } DataRow rowOut = arrRows[i + 1]; int IDinn = (int)rowInn["IDXacNhanCaVaLamThem"]; int IDout = (int)rowOut["IDXacNhanCaVaLamThem"]; if (IDinn != IDout)// bị mất cặp -> giảm 1 để tăng 2 là thằng kế tiếp { i = i - 1; continue; } // đủ điều kiện ghép cặp #region lấy thông tin int shiftID = (int)rowInn["ShiftID"]; string shiftCode = rowInn["ShiftCode"].ToString(); int dayCount = (int)rowInn["DayCount"]; Single workingday = (Single)rowInn["Workingday"]; TimeSpan onnDutyTs, offDutyTs; TimeSpan.TryParse(rowInn["Onduty"].ToString(), out onnDutyTs); TimeSpan.TryParse(rowInn["Offduty"].ToString(), out offDutyTs); TimeSpan afterOTTs = new TimeSpan(0, (int)rowInn["AfterOT"], 0); TimeSpan lateGraceTSS = new TimeSpan(0, (int)rowInn["LateGrace"], 0); TimeSpan earlyGraceTS = new TimeSpan(0, (int)rowInn["EarlyGrace"], 0); lateGraceTSS = onnDutyTs.Add(lateGraceTSS); offDutyTs = offDutyTs.Add(new TimeSpan(dayCount, 0, 0, 0)); earlyGraceTS = offDutyTs.Subtract(earlyGraceTS); afterOTTs = offDutyTs.Add(afterOTTs); int pOTMin = (int)rowInn["OTMin"]; bool tempTinhPC150 = false; if (rowInn["TinhPC150"] == DBNull.Value) { tempTinhPC150 = false; } else { tempTinhPC150 = (bool)rowInn["TinhPC150"]; } int wkt = int.Parse(rowInn["WorkingTime"].ToString()); TimeSpan pWorkingTime = new TimeSpan(0, wkt, 0, 0); string SourceInn = (string)rowInn["Source"]; string SourceOut = (string)rowOut["Source"]; int MachineNoInn = (int)rowInn["MachineNo"]; int MachineNoOut = (int)rowOut["MachineNo"]; DateTime timeInn = (DateTime)rowInn["TimeStr"]; DateTime timeOut = (DateTime)rowOut["TimeStr"]; #endregion cChkInn_V chkInnV = new cChkInn_V() { GioLienQuan = null, ID = IDinn, MachineNo = MachineNoInn, Source = SourceInn, TimeStr = timeInn }; cChkOut_V chkOutV = new cChkOut_V() { GioLienQuan = null, ID = IDout, MachineNo = MachineNoOut, Source = SourceOut, TimeStr = timeOut }; cChkInOut_V chkInOutV = new cChkInOut_V() { Vao = chkInnV, Raa = chkOutV, HaveINOUT = 1, TongGioThuc = chkOutV.TimeStr - chkInnV.TimeStr, TimeStrDaiDien = chkInnV.TimeStr, TinhPC150 = tempTinhPC150, LamThem = new TimeSpan(0, 0, pOTMin, 0), ThuocNgayCong = ThamSo.GetDate(chkInnV.TimeStr), }; // [TBD] xem lại thuộc ngày công cShift tmpThuocCa; if (shiftID > 0) { tmpThuocCa = DSCa.Find(item => item.ShiftID == shiftID); } else if (shiftID > int.MinValue + 100 && shiftID < 0) // ca tách và ca kết hợp [Chú ý] + 100 vì chừa khoảng này cho các loại khác { tmpThuocCa = new cShift() { ShiftID = shiftID, ShiftCode = shiftCode, OnnDutyTS = onnDutyTs, OffDutyTS = offDutyTs, chophepvaotreTS = lateGraceTSS, chopheprasomTS = earlyGraceTS, batdaulamthemTS = afterOTTs, WorkingTimeTS = pWorkingTime, Workingday = workingday, DayCount = dayCount, QuaDem = (dayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 0 } } ; //[TBD] else if (shiftID < int.MinValue + 100) // ca tự do 8 tiếng { tmpThuocCa = new cShift() { ShiftID = shiftID, ShiftCode = shiftCode, OnnDutyTS = onnDutyTs, OffDutyTS = offDutyTs, chophepvaotreTS = lateGraceTSS, chopheprasomTS = earlyGraceTS, batdaulamthemTS = afterOTTs, WorkingTimeTS = pWorkingTime, Workingday = workingday, DayCount = dayCount, QuaDem = (dayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 1 } } ; else { tmpThuocCa = new cShift() { ShiftID = shiftID, ShiftCode = "XacNhan8h", OnnDutyTS = onnDutyTs, OffDutyTS = offDutyTs, chophepvaotreTS = lateGraceTSS, chopheprasomTS = earlyGraceTS, batdaulamthemTS = afterOTTs, WorkingTimeTS = pWorkingTime, Workingday = workingday, DayCount = dayCount, QuaDem = (dayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 1 }; //[TBD] } if (tmpThuocCa == null) { log4net.ILog log = log4net.LogManager.GetLogger("ERROR function Check_GioDaXN "); log.Fatal("ERROR function Check_GioDaXN"); } chkInOutV.ThuocCa = tmpThuocCa; chkInOutV.QuaDem = tmpThuocCa.QuaDem; XL.TinhCongTheoCa(chkInOutV, chkInOutV.ThuocCa);//[TBD] DS_CIO_V.Add(chkInOutV); } } }
internal void Check_GioDaXN(DateTime pTimeStr, string pSource, int tempMachineNo , int pIDXacnhan, int pShiftID, string pShiftCode, TimeSpan pOnduty, TimeSpan pOffduty, TimeSpan pLateGrace, TimeSpan pEarlyGrace, TimeSpan pAfterOT, bool pTinhPC150, int pDayCount, TimeSpan pWorkingTime, Single pWorkingday , DateTime pTimeStrIn, DateTime pTimeStrOut, int pOTMin, string pNote) { if (tempMachineNo % 2 == 1) { cChkIn tChkIn = new cChkIn() { TimeStr = pTimeStr, Source = pSource, MachineNo = tempMachineNo }; ds_Check_ID.Add(tChkIn); } else { cChkOut tChkOut = new cChkOut() { TimeStr = pTimeStr, Source = pSource, MachineNo = tempMachineNo }; ds_Check_ID.Add(tChkOut); if (ds_Check_ID.Count > 1 && ds_Check_ID[ds_Check_ID.Count - 2].GetType() == typeof(cChkIn)) { cChkIn tmpChkIn = (cChkIn)ds_Check_ID[ds_Check_ID.Count - 2]; cChkOut tmpChkOut = (cChkOut)ds_Check_ID[ds_Check_ID.Count - 1]; cChkInOut tmpChkINOUT = new cChkInOut() { Vao = tmpChkIn, Raa = tmpChkOut, HaveINOUT = 1, TongGioThuc = tmpChkOut.TimeStr - tmpChkIn.TimeStr, DaXN = true, IsOT = true, TinhPC150 = pTinhPC150, LamThem = new TimeSpan(0, pOTMin, 0), ThuocNgayCong = ThamSo.GetDate(tmpChkIn.TimeStr), // [TBD] xem lại thuộc ngày công }; cShift tmpThuocCa; if (pShiftID > 0) // ca trong ds ca { tmpThuocCa = DSCa.Find(item => item.ShiftID == pShiftID); } else if (pShiftID > int.MinValue + 100 && pShiftID < 0) // ca tách và ca kết hợp [Chú ý] + 100 vì chừa khoảng này cho các loại khác { tmpThuocCa = new cShift() { ShiftID = pShiftID, ShiftCode = pShiftCode, OnnDutyTS = pOnduty, OffDutyTS = pOffduty, chophepvaotreTS = pLateGrace, chopheprasomTS = pEarlyGrace, batdaulamthemTS = pAfterOT, WorkingTimeTS = pWorkingTime, Workingday = pWorkingday, DayCount = pDayCount, QuaDem = (pDayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 0 } } ; //[TBD] else if (pShiftID < int.MinValue + 100) { tmpThuocCa = new cShift() { ShiftID = pShiftID, ShiftCode = pShiftCode, OnnDutyTS = pOnduty, OffDutyTS = pOffduty, chophepvaotreTS = pLateGrace, chopheprasomTS = pEarlyGrace, batdaulamthemTS = pAfterOT, WorkingTimeTS = pWorkingTime, Workingday = pWorkingday, DayCount = pDayCount, QuaDem = (pDayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 1 } } ; else { tmpThuocCa = new cShift() { ShiftID = pShiftID, ShiftCode = "XacNhan8h", OnnDutyTS = pOnduty, OffDutyTS = pOffduty, chophepvaotreTS = pLateGrace, chopheprasomTS = pEarlyGrace, batdaulamthemTS = pAfterOT, WorkingTimeTS = pWorkingTime, Workingday = pWorkingday, DayCount = pDayCount, QuaDem = (pDayCount == 1), LunchMinute = ThamSo._0gio, LoaiCa = 1 }; //[TBD] } if (tmpThuocCa == null) { log4net.ILog log = log4net.LogManager.GetLogger("ERROR function Check_GioDaXN "); log.Fatal("ERROR function Check_GioDaXN"); } tmpChkINOUT.ThuocCa = tmpThuocCa; tmpChkINOUT.QuaDem = tmpThuocCa.QuaDem; XL.TinhCongTheoCa(tmpChkINOUT, tmpChkINOUT.ThuocCa); DSVaoRa.Add(tmpChkINOUT); } } }
private void XetCa_A(DataTable tableCIO_A, DataTable tableCa) { TimeSpan onnduty, offduty, cutinn, cutout, onninn, onnout, earlyGrace, LateGrace, afterOT; int daycount = 0; Single workingDayy = 0f, workingTime = 0f; bool flag = false; DateTime t_vao, t_raa, ngay, vaocaa, raacaa, bd_hieuvao, kt_hieuvao, bd_hieuraa, kt_hieuraa; for (int i = 0; i < tableCIO_A.Rows.Count; i++) { DataRow rowCIO = tableCIO_A.Rows[i]; int haveinout = (int)rowCIO["HaveINOUT"]; if (haveinout == -1) { } else if (haveinout == -2) { } else // (haveinout > 0) { t_vao = (DateTime)rowCIO["TimeStrVao"]; t_raa = (DateTime)rowCIO["TimeStrRaa"]; ngay = ThamSo.GetDate(t_vao); foreach (DataRow rowCaa in tableCa.Rows) { #region TimeSpan.TryParse(rowCaa["Onduty"].ToString(), out onnduty); TimeSpan.TryParse(rowCaa["Offduty"].ToString(), out offduty); TimeSpan.TryParse(rowCaa["OnTimeIn"].ToString(), out onninn); TimeSpan.TryParse(rowCaa["OnTimeOut"].ToString(), out onnout); TimeSpan.TryParse(rowCaa["CutIn"].ToString(), out cutinn); TimeSpan.TryParse(rowCaa["CutOut"].ToString(), out cutout); TimeSpan.TryParse(rowCaa["EarlyGrace"].ToString(), out earlyGrace); TimeSpan.TryParse(rowCaa["LateGrace"].ToString(), out LateGrace); TimeSpan.TryParse(rowCaa["AfterOT"].ToString(), out afterOT); workingDayy = (Single)rowCaa["Workingday"]; workingTime = (Single)rowCaa["WorkingTime"]; daycount = (int)(rowCaa["DayCount"]); #endregion vaocaa = ngay.Add(onnduty); raacaa = ngay.AddDays(daycount).Add(offduty); bd_hieuvao = vaocaa - onninn; kt_hieuvao = vaocaa.Add(cutinn); bd_hieuraa = raacaa - onnout; kt_hieuraa = raacaa.Add(cutout); if (t_vao >= bd_hieuvao && t_vao <= kt_hieuvao && t_raa >= bd_hieuraa && t_raa <= kt_hieuraa) { flag = true; if (onnduty > ThamSo._20h00 && workingDayy == 2f && daycount == 1) { DataRow[] ca3_ca1 = Tim(tableCa); DataRow rowca3 = ca3_ca1[0]; TimeSpan.TryParse(rowca3["Onduty"].ToString(), out onnduty); TimeSpan.TryParse(rowca3["Offduty"].ToString(), out offduty); TimeSpan.TryParse(rowca3["OnTimeIn"].ToString(), out onninn); TimeSpan.TryParse(rowca3["OnTimeOut"].ToString(), out onnout); TimeSpan.TryParse(rowca3["CutIn"].ToString(), out cutinn); TimeSpan.TryParse(rowca3["CutOut"].ToString(), out cutout); TimeSpan.TryParse(rowca3["EarlyGrace"].ToString(), out earlyGrace); TimeSpan.TryParse(rowca3["LateGrace"].ToString(), out LateGrace); TimeSpan.TryParse(rowca3["AfterOT"].ToString(), out afterOT); workingDayy = (Single)rowca3["Workingday"]; workingTime = (Single)rowca3["WorkingTime"]; daycount = (int)(rowca3["DayCount"]); rowCIO["VaoCa"] = vaocaa; rowCIO["RaaCa"] = raacaa; rowCIO["TreCa"] = vaocaa.Add(LateGrace); rowCIO["SomCa"] = raacaa - earlyGrace; rowCIO["AfterOT"] = raacaa.Add(afterOT); rowCIO["Workingday"] = workingDayy; rowCIO["WorkingTime"] = workingTime; rowCIO["QuaDem"] = daycount; rowCIO["ShiftID"] = (int)rowCaa["ShiftID"]; rowCIO["ShiftCode"] = rowCaa["ShiftCode"].ToString(); // update lại giờ ra thành giờ ra ca 3 rowCIO["TimeStrRaa"] = raacaa; rowCIO["MachineNoRaa"] = 22; DataRow rowcatach = CopyRow(tableCIO_A, rowCIO); tableCIO_A.Rows.InsertAt(rowcatach, i); DataRow rowca1 = ca3_ca1[1]; // sau insert tăng i lên i++; rowCIO = tableCIO_A.Rows[i]; TimeSpan.TryParse(rowca1["Onduty"].ToString(), out onnduty); TimeSpan.TryParse(rowca1["Offduty"].ToString(), out offduty); TimeSpan.TryParse(rowca1["OnTimeIn"].ToString(), out onninn); TimeSpan.TryParse(rowca1["OnTimeOut"].ToString(), out onnout); TimeSpan.TryParse(rowca1["CutIn"].ToString(), out cutinn); TimeSpan.TryParse(rowca1["CutOut"].ToString(), out cutout); TimeSpan.TryParse(rowca1["EarlyGrace"].ToString(), out earlyGrace); TimeSpan.TryParse(rowca1["LateGrace"].ToString(), out LateGrace); TimeSpan.TryParse(rowca1["AfterOT"].ToString(), out afterOT); workingDayy = (Single)rowca1["Workingday"]; workingTime = (Single)rowca1["WorkingTime"]; daycount = (int)(rowca1["DayCount"]); rowCIO["VaoCa"] = vaocaa; rowCIO["RaaCa"] = raacaa; rowCIO["TreCa"] = vaocaa.Add(LateGrace); rowCIO["SomCa"] = raacaa - earlyGrace; rowCIO["AfterOT"] = raacaa.Add(afterOT); rowCIO["Workingday"] = workingDayy; rowCIO["WorkingTime"] = workingTime; rowCIO["QuaDem"] = daycount; rowCIO["ShiftID"] = (int)rowCaa["ShiftID"]; rowCIO["ShiftCode"] = rowCaa["ShiftCode"].ToString(); // update lại giờ ra thành giờ ra ca 1 rowCIO["TimeStrVao"] = vaocaa; rowCIO["MachineNoVao"] = 21; } else { rowCIO["VaoCa"] = vaocaa; rowCIO["RaaCa"] = raacaa; rowCIO["TreCa"] = vaocaa.Add(LateGrace); rowCIO["SomCa"] = raacaa - earlyGrace; rowCIO["AfterOT"] = raacaa.Add(afterOT); rowCIO["Workingday"] = workingDayy; rowCIO["WorkingTime"] = workingTime; rowCIO["QuaDem"] = daycount; rowCIO["ShiftID"] = (int)rowCaa["ShiftID"]; rowCIO["ShiftCode"] = rowCaa["ShiftCode"].ToString(); } } } } } }
public List <cNgayCong> TinhCongTheoNgay(List <cChkInOut> pDSVaoRa, DateTime ngayBD, DateTime ngayKT, bool macdinhtinhpc50) { List <cNgayCong> kq = new List <cNgayCong>(); DateTime ngaydem; if (pDSVaoRa.Count == 0) { ngaydem = ngayBD.Date; while (ngaydem <= ngayKT) // <= vì lấy luôn ngày KT : vắng mặt { cNgayCong ngayKOcheck = new cNgayCong() { NgayCong = ngaydem, HasCheck = false, DSVaoRa = new List <cChkInOut>(), }; kq.Add(ngayKOcheck); ngaydem = ngaydem.AddDays(1d); } return(kq); } int vtriBD = 0; ngaydem = ngayBD.Date; while (ngaydem <= ngayKT.Date) { if (vtriBD >= pDSVaoRa.Count) // hết DS nhưng ngaydem <= ngày KT ==> ghi lại những ngày sau là vắng mặt { while (ngaydem <= ngayKT.Date) { cNgayCong ngayKOcheck = new cNgayCong() { NgayCong = ngaydem, HasCheck = false, DSVaoRa = new List <cChkInOut>(), }; kq.Add(ngayKOcheck); ngaydem = ngaydem.AddDays(1d); } continue; } // chưa hết DS, bắt đầu từ ngày của DSVaoRa tại vtbd, đó là ngày có mặt cChkInOut CIO = pDSVaoRa[vtriBD]; XL.TinhCongTheoCa(CIO, CIO.ThuocCa); DateTime ngayCoMat = CIO.ThuocNgayCong; // ghi lại những ngày vắng mặt trước ngày có mặt while (ngaydem < ngayCoMat) // ko có = vì chỉ chạy đến trước ngày của tmpVaoRa thôi { cNgayCong ngayKOcheck = new cNgayCong() { NgayCong = ngaydem, HasCheck = false, DSVaoRa = new List <cChkInOut>(), }; kq.Add(ngayKOcheck); ngaydem = ngaydem.AddDays(1d); } //ngaydem = ngày có mặt. stop, tmpVaoRa là vào ra đầu tiên trong ngày #region collapse double pcdem = Convert.ToDouble(Properties.Settings.Default.PCDem / 100); double pctc = Convert.ToDouble(Properties.Settings.Default.PCTangCuong / 100); cNgayCong ngayCOcheck = new cNgayCong() { HasCheck = true, NgayCong = ngayCoMat, TinhPC150 = macdinhtinhpc50, // mặc định khởi tạo ngày có tính PC 50%, nếu tồn tại ít nhất 1 ca nào ko tính pc 50% thì set cả ngày ko tính pc 50% TG = new ThoiGian() { LamTinhCong = CIO.TG.LamTinhCong, LamTinhPC30 = CIO.TG.LamTinhPC30 }, TongGioThuc = CIO.TongGioThuc, TongTre = CIO.VaoTre, TongSom = CIO.RaaSom, TongCong = Math.Round(CIO.Cong, 2), PhuCap30 = Math.Round(((CIO.TG.LamTinhPC30.TotalHours > 0d) ? ((CIO.TG.LamTinhPC30.TotalHours / 8d) * pcdem) : 0d), 2) // công thức cũ (tính phụ cấp tăng ca theo công) là : + (((tmpVaoRa.Cong > 1f) ? (tmpVaoRa.Cong - 1f) * 0.5f : 0f)) // đổi lại công thức mới (tính phụ cấp theo giờ) là : + (((tmpVaoRa.TGLamTinhCong.TotalHours > 8f) ? (((float)tmpVaoRa.TGLamTinhCong.TotalHours - 8f) / 8f) * 0.5f : 0f)) }; if (CIO.QuaDem == true) { ngayCOcheck.QuaDem = true; // set qua đêm nếu có } if (CIO.TinhPC150 != macdinhtinhpc50) { ngayCOcheck.TinhPC150 = CIO.TinhPC150; } if (ngayCOcheck.TinhPC150) { ngayCOcheck.PhuCap50 = Math.Round((((CIO.TG.LamTinhCong.TotalHours > 8d) ? (((CIO.TG.LamTinhCong.TotalHours - 8d) / 8d) * pctc) : 0d)), 2); } else { ngayCOcheck.PhuCap50 = 0d; } ngayCOcheck.TongPhuCap = Math.Round((ngayCOcheck.PhuCap30 + ngayCOcheck.PhuCap50), 2); ngayCOcheck.them(CIO); #endregion // sau khi tạo ngày công mới vào ra đó là vào ra đầu tiên thì chuyển sang VAORA next vtriBD++; // nếu hết ds thì ngưng, add tmpNgayCong1 vào danh sách ngày công (do chưa add) if (vtriBD >= pDSVaoRa.Count) { kq.Add(ngayCOcheck); ngaydem = ngayCOcheck.NgayCong.AddDays(1d); while (ngaydem <= ngayKT.Date) { cNgayCong ngayKOcheck = new cNgayCong() { NgayCong = ngaydem, HasCheck = false, DSVaoRa = new List <cChkInOut>(), }; kq.Add(ngayKOcheck); ngaydem = ngaydem.AddDays(1.0d); } continue; } // chưa hết DSVàoRa, xem các vào ra kế tiếp, nếu cùng ngày công thì add thêm vào tmpNgayCong1 while (vtriBD < pDSVaoRa.Count && ThamSo.GetDate(pDSVaoRa[vtriBD].TimeStrDaiDien) == ngayCOcheck.NgayCong) { cChkInOut CIO_1 = pDSVaoRa[vtriBD]; XL.TinhCongTheoCa(CIO_1, CIO_1.ThuocCa); #region collapse ngayCOcheck.TongGioThuc += CIO_1.TongGioThuc; ngayCOcheck.TG.LamTinhCong += CIO_1.TG.LamTinhCong; ngayCOcheck.TG.LamTinhPC30 += CIO_1.TG.LamTinhPC30; ngayCOcheck.TongTre += CIO_1.VaoTre; ngayCOcheck.TongSom += CIO_1.RaaSom; ngayCOcheck.TongCong += Math.Round(CIO_1.Cong, 2); ngayCOcheck.PhuCap30 = Math.Round(((ngayCOcheck.TG.LamTinhPC30.TotalHours > 0d) ? ((ngayCOcheck.TG.LamTinhPC30.TotalHours / 8d) * pcdem) : 0d), 2); #endregion if (CIO_1.QuaDem == true) { ngayCOcheck.QuaDem = true; // set qua đêm nếu có } if (CIO_1.TinhPC150 != macdinhtinhpc50) { ngayCOcheck.TinhPC150 = CIO_1.TinhPC150; } if (ngayCOcheck.TinhPC150) { ngayCOcheck.PhuCap50 = Math.Round((((ngayCOcheck.TG.LamTinhCong.TotalHours > 8d) ? (((ngayCOcheck.TG.LamTinhCong.TotalHours - 8d) / 8d) * pctc) : 0d)), 2); } else { ngayCOcheck.PhuCap50 = 0d; } ngayCOcheck.TongPhuCap = Math.Round((ngayCOcheck.PhuCap30 + ngayCOcheck.PhuCap50), 2); ngayCOcheck.them(CIO_1); vtriBD++; } //thoát khỏi vòng lặp: hoặc hết ds hoặc chuyển sang ngày mới if (vtriBD >= pDSVaoRa.Count) { kq.Add(ngayCOcheck); ngaydem = ngayCOcheck.NgayCong.AddDays(1d); while (ngaydem <= ngayKT.Date) { cNgayCong tmpNgayCong = new cNgayCong() { NgayCong = ngaydem, HasCheck = false, DSVaoRa = new List <cChkInOut>(), }; kq.Add(tmpNgayCong); ngaydem = ngaydem.AddDays(1d); } } else { kq.Add(ngayCOcheck); ngaydem = ngaydem.AddDays(1d); } } return(kq); }
public List <cChkInOut_A> GhepCIO_A(List <cChk> DSchkInn, List <cChk> DSchkOut) { List <cChkInOut_A> kq = new List <cChkInOut_A>(); try { int x1 = 0, x2 = 0; if (DSchkInn.Count == 0 && DSchkOut.Count != 0) { while (x2 < DSchkOut.Count) { kq.Add(new cChkInOut_A() { Vao = null, Raa = DSchkOut[x2], TG = new ThoiGian(), HaveINOUT = -2, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkOut[x2].TimeStr.Date, TimeStrDaiDien = DSchkOut[x2].TimeStr, }); x2++; } } else if (DSchkInn.Count != 0 && DSchkOut.Count == 0) { while (x1 < DSchkInn.Count) { kq.Add(new cChkInOut_A() { Vao = DSchkInn[x1], Raa = null, TG = new ThoiGian(), HaveINOUT = -1, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkInn[x1].TimeStr.Date, TimeStrDaiDien = DSchkInn[x1].TimeStr, }); x1++; } } else if (DSchkInn.Count != 0 && DSchkOut.Count != 0) { while (x1 < DSchkInn.Count && x2 < DSchkOut.Count) { cChk chkinn = DSchkInn[x1]; cChk chkout = DSchkOut[x2]; DateTime timeInn = chkinn.TimeStr; DateTime timeOut = chkout.TimeStr; if (timeOut <= timeInn) //ra ko vào { cChkInOut_A CIO = new cChkInOut_A { Vao = null, Raa = DSchkOut[x2], TG = new ThoiGian(), HaveINOUT = -2, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkOut[x2].TimeStr.Date, TimeStrDaiDien = DSchkOut[x2].TimeStr }; // lưu prev kq.Add(CIO); x2++; } else { TimeSpan duration = timeOut - timeInn; if (duration <= ThamSo._30phut) { kq.Add(new cChkInOut_A() { Vao = DSchkInn[x1], Raa = null, TG = new ThoiGian(), HaveINOUT = -1, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkInn[x1].TimeStr.Date, TimeStrDaiDien = DSchkInn[x1].TimeStr, }); kq.Add(new cChkInOut_A() { Vao = null, Raa = DSchkOut[x2], TG = new ThoiGian(), HaveINOUT = -2, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkOut[x2].TimeStr.Date, TimeStrDaiDien = DSchkOut[x2].TimeStr, }); x1++; x2++; } else if (duration > ThamSo._21h45) { cChkInOut_A CIO = new cChkInOut_A() { Vao = DSchkInn[x1], Raa = null, TG = new ThoiGian(), HaveINOUT = -1, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkInn[x1].TimeStr.Date, TimeStrDaiDien = DSchkInn[x1].TimeStr }; kq.Add(CIO); x1++; } else { kq.Add(new cChkInOut_A() { Vao = DSchkInn[x1], Raa = DSchkOut[x2], TG = new ThoiGian(), HaveINOUT = 1, TongGioThuc = duration, ThuocNgayCong = ThamSo.GetDate(DSchkInn[x1].TimeStr), TimeStrDaiDien = DSchkInn[x1].TimeStr }); x1++; x2++; } } } if (x2 < DSchkOut.Count) { while (x2 < DSchkOut.Count) { cChkInOut_A CIO = new cChkInOut_A() { Vao = null, Raa = DSchkOut[x2], TG = new ThoiGian(), HaveINOUT = -2, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkOut[x2].TimeStr.Date, TimeStrDaiDien = DSchkOut[x2].TimeStr }; kq.Add(CIO); x2++; } } else if (x1 < DSchkInn.Count) { while (x1 < DSchkInn.Count) { cChkInOut_A CIO = new cChkInOut_A() { Vao = DSchkInn[x1], Raa = null, TG = new ThoiGian(), HaveINOUT = -1, TongGioThuc = ThamSo._0gio, ThuocNgayCong = DSchkInn[x1].TimeStr.Date, TimeStrDaiDien = DSchkInn[x1].TimeStr }; kq.Add(CIO); x1++; } } } } catch (Exception ex) { log4net.Config.XmlConfigurator.Configure(); ILog lg = LogManager.GetLogger("GhepCaCIO_A"); lg.Error(null, ex); throw ex; } return(kq); }