private Object GetData_SoTaiSanCoDinh(List <Guid> ListLoaiTaiSan, List <Guid> ListCoSo, int Year, Boolean ChuaCoViTri) { ResetDbContext(); IQueryable <CTTaiSan> IQueryable = MyNewDbContext.CTTAISANS.AsQueryable <CTTaiSan>(); //get luon so luong = 0, vi tinh tang giam //IQueryable = IQueryable.Where(x => x.soluong > 0); IQueryable = IQueryable.Where(item => Object.Equals(item.ngay, null) == false); IQueryable = IQueryable.Where(item => ((DateTime)item.ngay).Year <= Year); //LTB if (ListLoaiTaiSan != null && ListLoaiTaiSan.Count > 0) { IQueryable = IQueryable.Where(x => x.taisan.loaitaisan == null || ListLoaiTaiSan.Contains(x.taisan.loaitaisan.id)); } //COSO if (ListCoSo != null && ListCoSo.Count > 0) { List <Guid> ListPhong = Phong.getQuery().Where(x => ListCoSo.Contains(x.vitri.coso.id)).Select(c => c.id).ToList(); IQueryable = IQueryable.Where(x => ListCoSo.Contains(x.vitri.coso.id) || ListPhong.Contains(x.phong.id)); } if (ChuaCoViTri) { IQueryable = IQueryable.Where(x => Object.Equals(x.vitri, null) == true); } //var DataFiltered_Groups = IQueryable.OrderByDescending(item => item.date_create).DistinctBy(item => new { item.taisan_id, item.tinhtrang_id }).GroupBy(item => item.taisan_id).ToList(); var DataFiltered_Groups = IQueryable.OrderByDescending(item => item.date_create).GroupBy(item => item.taisan_id).ToList(); List <TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter> Data = new List <TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter>(); foreach (var _Group in DataFiltered_Groups) { int intCount = _Group.Count(); if (intCount == 1) { TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter item = new TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter(); //CTTS nay la tang tai san, neu la giam thi ... -_- item.ngay = _Group.ElementAt(0).ngay; item.sohieu_ct = _Group.ElementAt(0).chungtu != null?_Group.ElementAt(0).chungtu.sohieu : ""; item.ten = _Group.ElementAt(0).taisan.ten; item.nuocsx = _Group.ElementAt(0).taisan.nuocsx; //Do chi co 1 CTTS ma no giam (dac thu la chuyen tinh trang soluong dau = soluong chuyen se khong phat //CTTS moi) nen du lieu tang = giam if (_Group.ElementAt(0).tinhtrang.giam_taisan) { item.sohieu_ct_giam = _Group.ElementAt(0).chungtu != null?_Group.ElementAt(0).chungtu.sohieu : ""; item.ngay_ct_giam = _Group.ElementAt(0).chungtu != null?_Group.ElementAt(0).chungtu.ngay : null; item.ghichu = _Group.ElementAt(0).mota; } //Giam nen lay giam vo tang luon, gia tri ban dau item.dongia_tang = _Group.ElementAt(0).taisan.dongia; item.sohieu_ct_tang = _Group.ElementAt(0).chungtu != null?_Group.ElementAt(0).chungtu.sohieu : ""; item.ngay_ct_tang = _Group.ElementAt(0).chungtu != null?_Group.ElementAt(0).chungtu.ngay : null; item.dongia_tang = !_Group.ElementAt(0).tinhtrang.giam_taisan ? _Group.ElementAt(0).taisan.dongia : 0; item.sohieu_ct_tang = !_Group.ElementAt(0).tinhtrang.giam_taisan ? (_Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.sohieu : "") : ""; item.ngay_ct_tang = !_Group.ElementAt(0).tinhtrang.giam_taisan ? (_Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.ngay : null) : null; item.sohieu_ct_giam = _Group.ElementAt(0).tinhtrang.giam_taisan ? (_Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.sohieu : "") : ""; item.ngay_ct_giam = _Group.ElementAt(0).tinhtrang.giam_taisan ? (_Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.ngay : null) : null; item.ghichu = _Group.ElementAt(0).tinhtrang.giam_taisan ? _Group.ElementAt(0).mota : null; item.phantramhaomon_32 = Object.Equals(_Group.ElementAt(0).taisan, null) ? 0 : Object.Equals(_Group.ElementAt(0).taisan.loaitaisan, null) ? 0 : _Group.ElementAt(0).taisan.loaitaisan.phantramhaomon_32 * 100; item.sotientrongmotnam = Object.Equals(_Group.ElementAt(0).taisan, null) ? 0 : Object.Equals(_Group.ElementAt(0).taisan.loaitaisan, null) ? 0 : Object.Equals(_Group.ElementAt(0).taisan.loaitaisan.phantramhaomon_32, null) ? 0 : (long)(_Group.ElementAt(0).taisan.dongia *_Group.ElementAt(0).taisan.loaitaisan.phantramhaomon_32); item.haomon_1nam = _Group.ElementAt(0).sonamsudungconlai_final(Year) <= 0 ? 0 : _Group.ElementAt(0).haomon_1nam; item.giatriconlai_final = _Group.ElementAt(0).giatriconlai_final(Year); item.haomonluyke = _Group.ElementAt(0).haomonluyke(Year); item.haomonnamtruocchuyensang = _Group.ElementAt(0).haomonnamtruocchuyensang(Year); Data.Add(item); } else if (intCount > 1) { //Tai san nay co so luong > 1 nen se co n dong cho tai san nay foreach (var CTTS in _Group) { if (CTTS.tinhtrang.giam_taisan) { //Giam for (int i = 1; i <= CTTS.soluong; i++) { TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter item = new TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter(); item.ngay = CTTS.ngay; item.sohieu_ct = CTTS.chungtu != null ? CTTS.chungtu.sohieu : ""; item.ten = CTTS.taisan.ten; item.nuocsx = CTTS.taisan.nuocsx; item.dongia_tang = CTTS.taisan.dongia; item.sohieu_ct_tang = CTTS.chungtu != null ? CTTS.chungtu.sohieu : ""; item.ngay_ct_tang = CTTS.chungtu != null ? CTTS.chungtu.ngay : null; item.sohieu_ct_giam = CTTS.chungtu != null ? CTTS.chungtu.sohieu : ""; item.ngay_ct_giam = CTTS.chungtu != null ? CTTS.chungtu.ngay : null; item.ghichu = CTTS.mota; item.phantramhaomon_32 = Object.Equals(CTTS.taisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan, null) ? 0 : CTTS.taisan.loaitaisan.phantramhaomon_32 * 100; item.sotientrongmotnam = Object.Equals(CTTS.taisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan.phantramhaomon_32, null) ? 0 : (long)(CTTS.taisan.dongia * CTTS.taisan.loaitaisan.phantramhaomon_32); item.haomon_1nam = CTTS.sonamsudungconlai_final(Year) <= 0 ? 0 : CTTS.haomon_1nam; item.giatriconlai_final = CTTS.giatriconlai_final(Year); item.haomonluyke = CTTS.haomonluyke(Year); item.haomonnamtruocchuyensang = CTTS.haomonnamtruocchuyensang(Year); Data.Add(item); } } else { //Tang for (int i = 1; i <= CTTS.soluong; i++) { TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter item = new TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter(); item.ngay = CTTS.ngay; item.sohieu_ct = _Group.ElementAt(1).chungtu != null?_Group.ElementAt(1).chungtu.sohieu : ""; item.ten = CTTS.taisan.ten; item.nuocsx = CTTS.taisan.nuocsx; item.dongia_tang = !_Group.ElementAt(1).tinhtrang.giam_taisan ? _Group.ElementAt(1).taisan.dongia : 0; item.sohieu_ct_tang = !_Group.ElementAt(1).tinhtrang.giam_taisan ? (_Group.ElementAt(1).chungtu != null ? _Group.ElementAt(1).chungtu.sohieu : "") : ""; item.ngay_ct_tang = !_Group.ElementAt(1).tinhtrang.giam_taisan ? (_Group.ElementAt(1).chungtu != null ? _Group.ElementAt(1).chungtu.ngay : null) : null; item.phantramhaomon_32 = Object.Equals(CTTS.taisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan, null) ? 0 : CTTS.taisan.loaitaisan.phantramhaomon_32 * 100; item.sotientrongmotnam = Object.Equals(CTTS.taisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan.phantramhaomon_32, null) ? 0 : (long)(CTTS.taisan.dongia * CTTS.taisan.loaitaisan.phantramhaomon_32); item.haomon_1nam = CTTS.sonamsudungconlai_final(Year) <= 0 ? 0 : CTTS.haomon_1nam; item.giatriconlai_final = CTTS.giatriconlai_final(Year); item.haomonluyke = CTTS.haomonluyke(Year); item.haomonnamtruocchuyensang = CTTS.haomonnamtruocchuyensang(Year); Data.Add(item); } } } } } return(Data.OrderBy(item => item.ngay).ToList());; }
private Object GetData_SoTaiSanCoDinh(List<Guid> ListLoaiTaiSan, List<Guid> ListCoSo, int Year, Boolean ChuaCoViTri) { ResetDbContext(); IQueryable<CTTaiSan> IQueryable = MyNewDbContext.CTTAISANS.AsQueryable<CTTaiSan>(); //get luon so luong = 0, vi tinh tang giam //IQueryable = IQueryable.Where(x => x.soluong > 0); IQueryable = IQueryable.Where(item => Object.Equals(item.ngay, null) == false); IQueryable = IQueryable.Where(item => ((DateTime)item.ngay).Year <= Year); //LTB if (ListLoaiTaiSan != null && ListLoaiTaiSan.Count > 0) { IQueryable = IQueryable.Where(x => x.taisan.loaitaisan == null || ListLoaiTaiSan.Contains(x.taisan.loaitaisan.id)); } //COSO if (ListCoSo != null && ListCoSo.Count > 0) { List<Guid> ListPhong = Phong.getQuery().Where(x => ListCoSo.Contains(x.vitri.coso.id)).Select(c => c.id).ToList(); IQueryable = IQueryable.Where(x => ListCoSo.Contains(x.vitri.coso.id) || ListPhong.Contains(x.phong.id)); } if (ChuaCoViTri) IQueryable = IQueryable.Where(x => Object.Equals(x.vitri, null) == true); //var DataFiltered_Groups = IQueryable.OrderByDescending(item => item.date_create).DistinctBy(item => new { item.taisan_id, item.tinhtrang_id }).GroupBy(item => item.taisan_id).ToList(); var DataFiltered_Groups = IQueryable.OrderByDescending(item => item.date_create).GroupBy(item => item.taisan_id).ToList(); List<TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter> Data = new List<TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter>(); foreach (var _Group in DataFiltered_Groups) { int intCount = _Group.Count(); if (intCount == 1) { TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter item = new TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter(); //CTTS nay la tang tai san, neu la giam thi ... -_- item.ngay = _Group.ElementAt(0).ngay; item.sohieu_ct = _Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.sohieu : ""; item.ten = _Group.ElementAt(0).taisan.ten; item.nuocsx = _Group.ElementAt(0).taisan.nuocsx; //Do chi co 1 CTTS ma no giam (dac thu la chuyen tinh trang soluong dau = soluong chuyen se khong phat //CTTS moi) nen du lieu tang = giam if (_Group.ElementAt(0).tinhtrang.giam_taisan) { item.sohieu_ct_giam = _Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.sohieu : ""; item.ngay_ct_giam = _Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.ngay : null; item.ghichu = _Group.ElementAt(0).mota; } //Giam nen lay giam vo tang luon, gia tri ban dau item.dongia_tang = _Group.ElementAt(0).taisan.dongia; item.sohieu_ct_tang = _Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.sohieu : ""; item.ngay_ct_tang = _Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.ngay : null; item.dongia_tang = !_Group.ElementAt(0).tinhtrang.giam_taisan ? _Group.ElementAt(0).taisan.dongia : 0; item.sohieu_ct_tang = !_Group.ElementAt(0).tinhtrang.giam_taisan ? (_Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.sohieu : "") : ""; item.ngay_ct_tang = !_Group.ElementAt(0).tinhtrang.giam_taisan ? (_Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.ngay : null) : null; item.sohieu_ct_giam = _Group.ElementAt(0).tinhtrang.giam_taisan ? (_Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.sohieu : "") : ""; item.ngay_ct_giam = _Group.ElementAt(0).tinhtrang.giam_taisan ? (_Group.ElementAt(0).chungtu != null ? _Group.ElementAt(0).chungtu.ngay : null) : null; item.ghichu = _Group.ElementAt(0).tinhtrang.giam_taisan ? _Group.ElementAt(0).mota : null; item.phantramhaomon_32 = Object.Equals(_Group.ElementAt(0).taisan, null) ? 0 : Object.Equals(_Group.ElementAt(0).taisan.loaitaisan, null) ? 0 : _Group.ElementAt(0).taisan.loaitaisan.phantramhaomon_32 * 100; item.sotientrongmotnam = Object.Equals(_Group.ElementAt(0).taisan, null) ? 0 : Object.Equals(_Group.ElementAt(0).taisan.loaitaisan, null) ? 0 : Object.Equals(_Group.ElementAt(0).taisan.loaitaisan.phantramhaomon_32, null) ? 0 : (long)(_Group.ElementAt(0).taisan.dongia * _Group.ElementAt(0).taisan.loaitaisan.phantramhaomon_32); item.haomon_1nam = _Group.ElementAt(0).sonamsudungconlai_final(Year) <= 0 ? 0 : _Group.ElementAt(0).haomon_1nam; item.giatriconlai_final = _Group.ElementAt(0).giatriconlai_final(Year); item.haomonluyke = _Group.ElementAt(0).haomonluyke(Year); item.haomonnamtruocchuyensang = _Group.ElementAt(0).haomonnamtruocchuyensang(Year); Data.Add(item); } else if (intCount > 1) { //Tai san nay co so luong > 1 nen se co n dong cho tai san nay foreach (var CTTS in _Group) { if (CTTS.tinhtrang.giam_taisan) { //Giam for (int i = 1; i <= CTTS.soluong; i++) { TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter item = new TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter(); item.ngay = CTTS.ngay; item.sohieu_ct = CTTS.chungtu != null ? CTTS.chungtu.sohieu : ""; item.ten = CTTS.taisan.ten; item.nuocsx = CTTS.taisan.nuocsx; item.dongia_tang = CTTS.taisan.dongia; item.sohieu_ct_tang = CTTS.chungtu != null ? CTTS.chungtu.sohieu : ""; item.ngay_ct_tang = CTTS.chungtu != null ? CTTS.chungtu.ngay : null; item.sohieu_ct_giam = CTTS.chungtu != null ? CTTS.chungtu.sohieu : ""; item.ngay_ct_giam = CTTS.chungtu != null ? CTTS.chungtu.ngay : null; item.ghichu = CTTS.mota; item.phantramhaomon_32 = Object.Equals(CTTS.taisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan, null) ? 0 : CTTS.taisan.loaitaisan.phantramhaomon_32 * 100; item.sotientrongmotnam = Object.Equals(CTTS.taisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan.phantramhaomon_32, null) ? 0 : (long)(CTTS.taisan.dongia * CTTS.taisan.loaitaisan.phantramhaomon_32); item.haomon_1nam = CTTS.sonamsudungconlai_final(Year) <= 0 ? 0 : CTTS.haomon_1nam; item.giatriconlai_final = CTTS.giatriconlai_final(Year); item.haomonluyke = CTTS.haomonluyke(Year); item.haomonnamtruocchuyensang = CTTS.haomonnamtruocchuyensang(Year); Data.Add(item); } } else { //Tang for (int i = 1; i <= CTTS.soluong; i++) { TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter item = new TSCD.DataFilter.ReportFilter.SoTaiSanCoDinh_DataFilter(); item.ngay = CTTS.ngay; item.sohieu_ct = _Group.ElementAt(1).chungtu != null ? _Group.ElementAt(1).chungtu.sohieu : ""; item.ten = CTTS.taisan.ten; item.nuocsx = CTTS.taisan.nuocsx; item.dongia_tang = !_Group.ElementAt(1).tinhtrang.giam_taisan ? _Group.ElementAt(1).taisan.dongia : 0; item.sohieu_ct_tang = !_Group.ElementAt(1).tinhtrang.giam_taisan ? (_Group.ElementAt(1).chungtu != null ? _Group.ElementAt(1).chungtu.sohieu : "") : ""; item.ngay_ct_tang = !_Group.ElementAt(1).tinhtrang.giam_taisan ? (_Group.ElementAt(1).chungtu != null ? _Group.ElementAt(1).chungtu.ngay : null) : null; item.phantramhaomon_32 = Object.Equals(CTTS.taisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan, null) ? 0 : CTTS.taisan.loaitaisan.phantramhaomon_32 * 100; item.sotientrongmotnam = Object.Equals(CTTS.taisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan, null) ? 0 : Object.Equals(CTTS.taisan.loaitaisan.phantramhaomon_32, null) ? 0 : (long)(CTTS.taisan.dongia * CTTS.taisan.loaitaisan.phantramhaomon_32); item.haomon_1nam = CTTS.sonamsudungconlai_final(Year) <= 0 ? 0 : CTTS.haomon_1nam; item.giatriconlai_final = CTTS.giatriconlai_final(Year); item.haomonluyke = CTTS.haomonluyke(Year); item.haomonnamtruocchuyensang = CTTS.haomonnamtruocchuyensang(Year); Data.Add(item); } } } } } return Data.OrderBy(item => item.ngay).ToList(); ; }