public StateProcessApproval Approval(string id) { StateProcessApproval result; var unitCode = GetCurrentUnitCode(); var periods = CurrentSetting.GetKhoaSo(unitCode); if (periods != null) { var tableName = ProcedureCollection.GetTableName(periods.Year, periods.Period); if (ProcedureCollection.DecreaseVoucher(tableName, periods.Year, periods.Period, id)) { result = StateProcessApproval.Success; } else { result = StateProcessApproval.Failed; } } else { result = StateProcessApproval.NoPeriod; } return(result); }
public IHttpActionResult GetTableNameByDate(ParameterInventory param) { if (param.FromDate != null || param.ToDate != null) { var result = new TransferObj(); DateTime day = new DateTime(param.FromDate.Year, param.FromDate.Month, param.FromDate.Day, 0, 0, 0); var data = _service.Repository.DbSet.FirstOrDefault(x => x.FromDate == day); if (data != null) { string tableName = ProcedureCollection.GetTableName(data.Year, data.Period); result.Data = tableName; result.Status = true; result.Message = "Ok"; return(Ok(result)); } else { result.Message = "Chưa khởi tạo kỳ kế toán"; return(NotFound()); } } else { return(NotFound()); } }
public string GetKyKeToan(DateTime ngayChungTu) { DateTime beginDay = new DateTime(ngayChungTu.Year, ngayChungTu.Month, ngayChungTu.Day, 0, 0, 0); DateTime endDay = new DateTime(ngayChungTu.Year, ngayChungTu.Month, ngayChungTu.Day, 23, 59, 59); var kyKeToan = Repository.DbSet.FirstOrDefault(x => x.FromDate >= beginDay && x.FromDate <= endDay); if (kyKeToan != null) { return(ProcedureCollection.GetTableName(kyKeToan.Year, kyKeToan.Period)); } else { var now = DateTime.Now; beginDay = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0); endDay = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59); kyKeToan = Repository.DbSet.FirstOrDefault(x => x.FromDate >= beginDay && x.FromDate <= endDay); return(ProcedureCollection.GetTableName(kyKeToan.Year, kyKeToan.Period)); } }
public List <InventoryDetailItem> CreateReportXNTNewTongHop(ParameterInventory pi) { List <InventoryDetailItem> data = new List <InventoryDetailItem>(); DateTime beginDay, endDay; string ky = string.Empty; beginDay = new DateTime(pi.FromDate.Year, pi.FromDate.Month, pi.FromDate.Day, 0, 0, 0); endDay = new DateTime(pi.ToDate.Year, pi.ToDate.Month, pi.ToDate.Day, 23, 59, 59); var period = UnitOfWork.Repository <MdPeriod>().DbSet.FirstOrDefault(x => x.FromDate >= beginDay && x.FromDate <= endDay); if (period != null) { ky = ProcedureCollection.GetTableName(period.Year, period.Period); } switch (pi.GroupBy) { case TypeGroupInventory.TYPE: data = ProcedureCollection.ReportXNTNew_TongHop(pi.FromDate, pi.ToDate, pi.UnitCode, pi.WareHouseCodes, pi.MerchandiseTypeCodes, pi.MerchandiseGroupCodes, pi.MerchandiseCodes, InventoryGroupBy.MALOAIVATTU.ToString(), pi.NhaCungCapCodes); break; case TypeGroupInventory.GROUP: data = ProcedureCollection.ReportXNTNew_TongHop(pi.FromDate, pi.ToDate, pi.UnitCode, pi.WareHouseCodes, pi.MerchandiseTypeCodes, pi.MerchandiseGroupCodes, pi.MerchandiseCodes, InventoryGroupBy.MANHOMVATTU.ToString(), pi.NhaCungCapCodes); break; case TypeGroupInventory.NHACUNGCAP: data = ProcedureCollection.ReportXNTNew_TongHop(pi.FromDate, pi.ToDate, pi.UnitCode, pi.WareHouseCodes, pi.MerchandiseTypeCodes, pi.MerchandiseGroupCodes, pi.MerchandiseCodes, InventoryGroupBy.MANHACUNGCAP.ToString(), pi.NhaCungCapCodes); break; case TypeGroupInventory.WAREHOUSE: data = ProcedureCollection.ReportXNTNew_TongHop(pi.FromDate, pi.ToDate, pi.UnitCode, pi.WareHouseCodes, pi.MerchandiseTypeCodes, pi.MerchandiseGroupCodes, pi.MerchandiseCodes, InventoryGroupBy.MAKHO.ToString(), pi.NhaCungCapCodes); break; default: data = ProcedureCollection.ReportXNTNew_TongHop(pi.FromDate, pi.ToDate, pi.UnitCode, pi.WareHouseCodes, pi.MerchandiseTypeCodes, pi.MerchandiseGroupCodes, pi.MerchandiseCodes, InventoryGroupBy.MAVATTU.ToString(), pi.NhaCungCapCodes); break; } return(data); }
public IHttpActionResult GetSoLuongTonByDate(ParameterInventory param) { if (param.FromDate != null || param.ToDate != null) { var result = new TransferObj(); DateTime day = new DateTime(param.FromDate.Year, param.FromDate.Month, param.FromDate.Day, 0, 0, 0); var data = _service.Repository.DbSet.FirstOrDefault(x => x.FromDate == day); if (data != null) { MdPeriodVm.ResponseData dataResult = new MdPeriodVm.ResponseData(); string tableName = ProcedureCollection.GetTableName(data.Year, data.Period); var getTonKhoXuat = string.Format("SELECT TONCUOIKYSL FROM {0} where MAVATTU = '{1}' and MAKHO = '{2}'", tableName, param.MerchandiseCodes.ToUpper(), param.WareHouseCodes); var getTonKhoNhap = string.Format("SELECT TONCUOIKYSL FROM {0} where MAVATTU = '{1}' and MAKHO = '{2}'", tableName, param.MerchandiseCodes.ToUpper(), param.WareHouseRecieveCode); using (var ctx = new ERPContext()) { decimal soLuongTonKhoXuat = ctx.Database.SqlQuery <decimal> (getTonKhoXuat).SingleOrDefault(); decimal soLuongTonKhoNhap = ctx.Database.SqlQuery <decimal>(getTonKhoNhap).SingleOrDefault(); dataResult.SoLuongTonKhoNhap = soLuongTonKhoNhap; dataResult.SoLuongTonKhoXuat = soLuongTonKhoXuat; result.Data = dataResult; } result.Status = true; result.Message = "Ok"; return(Ok(result)); } else { result.Message = "Chưa khởi tạo kỳ kế toán"; return(NotFound()); } } else { return(NotFound()); } }
public async Task <IHttpActionResult> GetDetails(string id) { var _ParentUnitCode = _service.GetParentUnitCode(); var result = new TransferObj <NvXuatKhacVm.Dto>(); var temp = new NvXuatKhacVm.Dto(); var phieu = _service.FindById(id); if (phieu != null) { temp = Mapper.Map <NvVatTuChungTu, NvXuatKhacVm.Dto>(phieu); var chiTietPhieu = _service.UnitOfWork.Repository <NvVatTuChungTuChiTiet>().DbSet.Where(x => x.MaChungTuPk == phieu.MaChungTuPk).ToList(); temp.DataDetails = Mapper.Map <List <NvVatTuChungTuChiTiet>, List <NvXuatKhacVm.DtoDetail> >(chiTietPhieu); temp.DataDetails.ForEach( x => { x.CalcResult(); x.GiaVon = x.GiaVon; } ); if (phieu.TrangThai != 10) { decimal sum = 0; List <NvXuatKhacVm.DtoDetail> listDetails = new List <NvXuatKhacVm.DtoDetail>(); var unitCode = _service.GetCurrentUnitCode(); var ky = CurrentSetting.GetKhoaSo(unitCode); var tableName = ProcedureCollection.GetTableName(ky.Year, ky.Period); var MaKho = temp.MaKhoXuat; decimal giaVon = 0; //string kyKeToan = _servicePeriod.GetKyKeToan((DateTime)phieu.NgayCT); foreach (var value in temp.DataDetails) { var sp = _service.UnitOfWork.Repository <MdMerchandisePrice>().DbSet.Where(x => x.MaVatTu.Equals(value.MaHang) && x.MaDonVi.StartsWith(_ParentUnitCode)).FirstOrDefault(); var item = _service.UnitOfWork.Repository <MdMerchandise>().DbSet.Where(x => x.MaVatTu.Equals(value.MaHang) && x.UnitCode.StartsWith(_ParentUnitCode)).FirstOrDefault(); if (sp != null) { value.TyLeVATVao = sp.TyLeVatVao; } if (item != null) { value.TenHang = item.TenHang; } List <MdMerchandiseVm.DataXNT> data = ProcedureCollection.GetDataInventoryByCondition(unitCode, MaKho, value.MaHang, tableName, _ParentUnitCode); if (data.Count > 0) { decimal.TryParse(value.GiaVon.ToString(), out giaVon); value.DonGia = giaVon; value.TyLeVATRa = data[0].TyLeVATRa; value.TyLeVATVao = data[0].TyLeVATVao; value.ThanhTien = value.DonGia * value.SoLuong; sum += (decimal)value.ThanhTien; } listDetails.Add(value); } temp.DataDetails = listDetails; var tyLe = _service.UnitOfWork.Repository <MdTax>().DbSet.Where(x => x.MaLoaiThue == temp.VAT).Select(x => x.TaxRate).FirstOrDefault(); if (tyLe != null) { temp.TienVat = sum * (tyLe / 100); } else { temp.TienVat = 0; } temp.ThanhTienTruocVat = sum; temp.ThanhTienSauVat = temp.ThanhTienTruocVat + temp.TienVat; } result.Data = temp; result.Status = true; return(Ok(result)); } return(NotFound()); }
public NvXuatKhacVm.ReportModel CreateReport(string id) { var _ParentUnitCode = GetParentUnitCode(); var result = new NvXuatKhacVm.ReportModel(); decimal sum = 0; var exsit = FindById(id); if (exsit != null) { result = Mapper.Map <NvVatTuChungTu, NvXuatKhacVm.ReportModel>(exsit); var nhanvien = UnitOfWork.Repository <AU_NGUOIDUNG>().DbSet.Where(x => x.Username == exsit.ICreateBy).FirstOrDefault(); if (nhanvien != null) { result.NameNhanVienCreate = nhanvien.TenNhanVien != null ? nhanvien.TenNhanVien : ""; } var detailData = UnitOfWork.Repository <NvVatTuChungTuChiTiet>().DbSet.Where(x => x.MaChungTuPk == exsit.MaChungTuPk).ToList(); result.DataReportDetails = Mapper.Map <List <NvVatTuChungTuChiTiet>, List <NvXuatKhacVm.ReportDetailModel> >(detailData); var sup = UnitOfWork.Repository <MdSupplier>().DbSet.FirstOrDefault(x => x.MaNCC == result.MaKhachHang); var cus = UnitOfWork.Repository <MdCustomer>().DbSet.FirstOrDefault(x => x.MaKH == result.MaKhachHang); if (sup != null) { result.TenKhachHang = sup.TenNCC; result.DiaChiKhachHang = sup.DiaChi; } else if (cus != null) { result.TenKhachHang = cus.TenKH; result.DiaChiKhachHang = cus.DiaChi; } var typeR = UnitOfWork.Repository <MdTypeReason>().DbSet.FirstOrDefault(x => x.MaLyDo == result.MaLyDo); if (typeR != null) { result.TenLyDo = typeR.TenLyDo; } if (exsit.TrangThai != 10) { List <NvXuatKhacVm.DtoDetail> listDetails = new List <NvXuatKhacVm.DtoDetail>(); var ky = CurrentSetting.GetKhoaSo(exsit.UnitCode); var tableName = ProcedureCollection.GetTableName(ky.Year, ky.Period); var MaKho = exsit.MaKhoXuat; //string kyKeToan = _servicePeriod.GetKyKeToan((DateTime)phieu.NgayCT); foreach (var value in result.DataReportDetails) { List <MdMerchandiseVm.DataXNT> data = ProcedureCollection.GetDataInventoryByCondition(exsit.UnitCode, MaKho, value.MaHang, tableName, _ParentUnitCode); value.GiaVon = value.GiaVon; value.DonGia = value.GiaVon; value.ThanhTien = value.DonGia * value.SoLuong; sum += (decimal)value.ThanhTien; } var tyLe = UnitOfWork.Repository <MdTax>().DbSet.Where(x => x.MaLoaiThue == exsit.VAT).Select(x => x.TaxRate).FirstOrDefault(); if (tyLe != null) { result.TienVat = sum * (tyLe / 100); } else { result.TienVat = 0; } result.ThanhTienTruocVat = sum; result.ThanhTienSauVat = result.ThanhTienTruocVat + result.TienVat; } var warehouses = UnitOfWork.Repository <MdWareHouse>().DbSet; var exportWareHouse = warehouses.FirstOrDefault(x => x.MaKho == result.MaKhoXuat); result.TenKhoXuat = exportWareHouse != null ? exportWareHouse.TenKho : ""; } var unitCode = GetCurrentUnitCode(); var createDate = DateTime.Now; result.CreateDay = createDate.Day; result.CreateMonth = createDate.Month; result.CreateYear = createDate.Year; result.TenDonVi = CurrentSetting.GetUnitName(unitCode); result.DiaChiDonVi = CurrentSetting.GetUnitAddress(unitCode); //GetNhanVien if (HttpContext.Current != null && HttpContext.Current.User is ClaimsPrincipal) { var currentUser = (HttpContext.Current.User as ClaimsPrincipal); var name = currentUser.Identity.Name; var nhanVien = UnitOfWork.Repository <AU_NGUOIDUNG>().DbSet.Where(x => x.Username == name).FirstOrDefault(); if (nhanVien != null) { result.Username = nhanVien.TenNhanVien; } else { result.Username = "******"; } } return(result); }
public async Task <IHttpActionResult> PostReportInventoryTongHop(ParameterInventory para) { var result = new TransferObj <InventoryReport>(); try { var data = new List <InventoryExpImpLevel2>(); var reporter = new InventoryReport(); reporter.UnitCode = _servicePeriod.GetCurrentUnitCode(); reporter.Year = para.ToDate.Year; var period = _service.UnitOfWork.Repository <MdPeriod>().DbSet.Where(x => x.ToDate == para.ToDate).FirstOrDefault(); if (period != null) { reporter.Period = period.Period; } var unitCode = _servicePeriod.GetCurrentUnitCode(); reporter.CreateDateNow(); reporter.FromDay = para.FromDate.Day; reporter.FromMonth = para.FromDate.Month; reporter.FromYear = para.FromDate.Year; reporter.ToDay = para.ToDate.Day; reporter.ToMonth = para.ToDate.Month; reporter.ToYear = para.ToDate.Year; reporter.TenDonVi = CurrentSetting.GetUnitName(unitCode); reporter.DiaChiDonVi = CurrentSetting.GetUnitAddress(unitCode); //GetNhanVien if (HttpContext.Current != null && HttpContext.Current.User is ClaimsPrincipal) { var currentUser = (HttpContext.Current.User as ClaimsPrincipal); var name = currentUser.Identity.Name; var nhanVien = _service.UnitOfWork.Repository <AU_NGUOIDUNG>().DbSet.Where(x => x.Username == name).FirstOrDefault(); if (nhanVien != null) { reporter.Username = nhanVien.TenNhanVien; } else { reporter.Username = "******"; } } var tableName = ProcedureCollection.GetTableName(period.Year, period.Period); data = _service.ReportTonTongHop(para); switch (para.GroupBy) { case TypeGroupInventory.MADONVI: reporter.DetailData = data.ToList(); reporter.MapUnitUserName(_service.UnitOfWork); reporter.GroupType = "Mã đơn vị"; break; case TypeGroupInventory.WAREHOUSE: reporter.DetailData = data.ToList(); reporter.MapUnitUserName(_service.UnitOfWork); reporter.GroupType = "Kho hàng"; break; case TypeGroupInventory.TYPE: reporter.DetailData = data.ToList(); reporter.MapUnitUserName(_service.UnitOfWork); reporter.GroupType = "Loại hàng hóa"; break; case TypeGroupInventory.GROUP: reporter.DetailData = data.ToList(); reporter.MapUnitUserName(_service.UnitOfWork); reporter.GroupType = "Nhóm hàng hóa"; break; case TypeGroupInventory.NHACUNGCAP: reporter.DetailData = data.ToList(); reporter.MapUnitUserName(_service.UnitOfWork); reporter.GroupType = "Nhà cung cấp"; break; default: reporter.DetailData = data.ToList(); reporter.MapUnitUserName(_service.UnitOfWork); reporter.GroupType = "Hàng hóa"; break; } result.Data = reporter; result.Status = true; result.Message = "Xuất báo cáo thành công"; return(Ok(result)); } catch (Exception e) { return(InternalServerError()); } }