public async Task <IHttpActionResult> PostUpdateGiaVon(MdPeriod instance) { try { var exsist = _service.Find(instance); if (exsist == null) { return(NotFound()); } var processName = CodeProcess.CAPNHATGIAVON.ToString(); var unitCode = _service.GetCurrentUnitCode(); var process = _service.UnitOfWork.Repository <MdMonitorProcess>().DbSet.FirstOrDefault(x => x.ProcessCode == processName && x.UnitCode == unitCode && x.State == ProcessState.IsRunning); if (process != null) { process.State = ProcessState.IsRunning; return(BadRequest("Đang cập nhật giá vốn")); } if (!_service.UpDateGiaVon(instance)) { return(BadRequest("Chưa thể cập nhật được giá vốn")); } return(Ok()); } catch (Exception) { return(InternalServerError()); } }
public IHttpActionResult PostComplete(NvKiemKeVm.Dto instance) { string unitCode = _service.GetCurrentUnitCode(); MdPeriod curentDate = CurrentSetting.GetKhoaSo(unitCode); int period = curentDate.Period; int year = curentDate.Year; string tablleName = curentDate.GetTableName(); instance.NgayDuyetPhieu = curentDate.ToDate; try { string msg = _serviceKK.Approval(instance, tablleName, year.ToString(), period); if (msg.Length > 0) { return(BadRequest(msg)); } _serviceKK.UpdateApproval(instance); _serviceKK.UnitOfWork.Save(); return(Ok(msg)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IHttpActionResult> GetLastPeriod() { var result = new MdPeriod(); var unitCode = _servicePeriod.GetCurrentUnitCode(); result = CurrentSetting.GetKhoaSo(unitCode); //if(result!=null) //{ } return(Ok(result)); }
public async Task <IHttpActionResult> PostAppoval(MdPeriod instance) { var result = new TransferObj <MdPeriod>(); var exist = _service.Find(instance); if (exist != null) { if (instance.TrangThai == (int)ApprovalState.IsComplete) { return(BadRequest("Kỳ này đã được duyệt!")); } var unitCode = _service.GetCurrentUnitCode(); var exsitPeriodNotClose = _service.Repository.DbSet.Any(x => x.Year == exist.Year && x.Period < exist.Period && x.TrangThai != (int)ApprovalState.IsComplete && x.UnitCode == unitCode); if (exsitPeriodNotClose) { return(BadRequest("Chưa khóa kỳ trước")); } var talbeName = instance.GetTableName(); var preTalbeName = _service.GetPreTableName(instance); ProcessState stateOfPeriod = _service.CheckProcess(instance); switch (stateOfPeriod) { case ProcessState.IsPending: try { _close.ProcedureCloseInventory(preTalbeName, talbeName, instance.UnitCode, instance.Year, instance.Period); exist.TrangThai = (int)ApprovalState.IsComplete; exist.ObjectState = ObjectState.Modified; result.Status = true; result.Message = "Khóa sổ thành công"; _service.UnitOfWork.Save(); } catch (Exception e) { return(InternalServerError(e)); } break; case ProcessState.IsComplete: break; case ProcessState.IsRunning: return(BadRequest("Đang trong quá trình khóa")); case ProcessState.IsError: break; default: break; } } return(Ok(result)); }
public List <IQueryFilter> GetFilters() { var result = new List <IQueryFilter>(); var refObj = new MdPeriod(); if (this.Period > 0) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.Period), Value = this.Period, Method = FilterMethod.EqualTo }); } if (!string.IsNullOrEmpty(this.Name)) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.Name), Value = this.Name, Method = FilterMethod.Like }); } if (this.Year > 0) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.Year), Value = this.Year, Method = FilterMethod.EqualTo }); } if (this.FromDate.HasValue) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.FromDate), Value = this.FromDate.Value, Method = FilterMethod.GreaterThanOrEqualTo }); } if (this.ToDate.HasValue) { result.Add(new QueryFilterLinQ { Property = ClassHelper.GetProperty(() => refObj.ToDate), Value = this.ToDate.Value.AddDays(1), Method = FilterMethod.LessThan }); } return(result); }
public MdPeriod GetPeriodDate() { var unitCode = _servicePeriod.GetCurrentUnitCode(); var period = new MdPeriod(); period = CurrentSetting.GetKhoaSo(unitCode); if (period != null) { return(period); } else { return(null); } }
public static MdPeriod GetKhoaSo(string unitCode) { using (var ctx = new ERPContext()) { var periodCloseds = ctx.MdPeriods.OrderByDescending(x => new { x.Year, x.Period }).FirstOrDefault(x => x.TrangThai == 10 && x.UnitCode == unitCode); if (periodCloseds != null) { MdPeriod lastPeriod = periodCloseds; return(lastPeriod); } else { return(null); } } }
public async Task <IHttpActionResult> PostCapNhatSoXuat(MdPeriod instance) { var result = new TransferObj <MdPeriod>(); var exist = _service.Find(instance); if (exist != null) { instance.TrangThai = (int)ApprovalState.IsNotApproval; var talbeName = instance.GetTableName(); var preTalbeName = _service.GetPreTableName(instance); ProcessState stateOfPeriod = _service.CheckProcess(instance); switch (stateOfPeriod) { case ProcessState.IsPending: try { _close.ProcedureCloseInventory(preTalbeName, talbeName, instance.UnitCode, instance.Year, instance.Period); exist.TrangThai = (int)ApprovalState.IsComplete; exist.ObjectState = BTS.API.ENTITY.ObjectState.Modified; result.Status = true; result.Message = "Cập nhật thành công"; _service.UnitOfWork.Save(); } catch (Exception e) { return(InternalServerError(e)); } break; case ProcessState.IsComplete: break; case ProcessState.IsRunning: return(BadRequest("Đang trong quá trình khóa")); case ProcessState.IsError: break; default: break; } } return(Ok(result)); }
public IHttpActionResult OpenApproval(MdPeriod instance) { var _unitCode = _service.GetCurrentUnitCode(); var result = new TransferObj(); DateTime temp; if (DateTime.TryParse(instance.ToDate.ToString(), out temp)) { try { var listOpen = _service.Repository.DbSet.Where(x => x.FromDate == instance.FromDate && x.ToDate == instance.ToDate && x.TrangThai == 10 && x.UnitCode == _unitCode).ToList(); if (listOpen.Count > 0) { foreach (var data in listOpen) { data.TrangThai = (int)ProcessState.IsUnClosingOut; _service.Update(data); } _service.UnitOfWork.SaveAsync(); result.Status = true; result.Message = "Mở khóa sổ thành công"; result.Data = listOpen; } else { result.Status = false; result.Message = "Kỳ này đang mở"; } } catch (Exception ex) { result.Status = false; result.Message = "Lỗi: " + ex; } } else { result.Status = false; result.Message = "Không có dữ liệu truyền lên ! Kiểm tra lại"; } return(Ok(result)); }
public async Task <IHttpActionResult> Delete(string id) { MdPeriod instance = await _service.Repository.FindAsync(id); if (instance == null) { return(NotFound()); } try { _service.Delete(instance.Id); await _service.UnitOfWork.SaveAsync(); return(Ok(instance)); } catch (Exception) { return(InternalServerError()); } }
public async Task <IHttpActionResult> GetExternalCode(ParameterKiemKe para) { string unitCode = _service.GetCurrentUnitCode(); MdPeriod curentDate = CurrentSetting.GetKhoaSo(unitCode); if (para.WareHouseCodes == null) { para.WareHouseCodes = unitCode + "-K2"; } string tableName = curentDate.GetTableName(); List <NvKiemKeVm.ExternalCodeInInventory> result = new List <NvKiemKeVm.ExternalCodeInInventory>(); result = ProcedureCollection.GetExternalCodeInventory(unitCode, tableName, para); if (result != null) { return(Ok(result)); } else { return(NotFound()); } }
public async Task <IHttpActionResult> Post(MdPeriod instance) { var result = new TransferObj <MdPeriod>(); try { instance.ICreateBy = _service.GetClaimsPrincipal().Identity.Name; instance.ICreateDate = DateTime.Now; var item = _service.Insert(instance); _service.UnitOfWork.Save(); result.Status = true; result.Message = "Thêm mới thành công"; result.Data = item; } catch (Exception e) { result.Status = false; result.Message = e.Message; return(Ok(result)); } return(CreatedAtRoute("DefaultApi", new { controller = this, id = instance.Id }, result)); }
public async Task <IHttpActionResult> GetNextPeriod(MdPeriod instance) { var result = new TransferObj <MdPeriod>(); var unitCode = _service.GetCurrentUnitCode(); DateTime nDay = instance.FromDate.AddDays(+1); DateTime nextDay = new DateTime(nDay.Year, nDay.Month, nDay.Day, 0, 0, 0); var kyKeToan = _service.Repository.DbSet.FirstOrDefault(x => x.ToDate == nextDay && x.FromDate == nextDay && x.UnitCode == unitCode); if (kyKeToan != null) { result.Status = true; result.Message = "Oke"; result.Data = kyKeToan; } else { result.Status = true; result.Message = "NotFound"; result.Data = kyKeToan; } return(Ok(result)); }
public async Task <IHttpActionResult> Put(string id, MdPeriod instance) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != instance.Id) { return(BadRequest()); } var result = new TransferObj <MdPeriod>(); if (id != instance.Id) { result.Status = false; result.Message = "Id không hợp lệ"; return(Ok(result)); } try { instance.IUpdateBy = _service.GetClaimsPrincipal().Identity.Name; instance.IUpdateDate = DateTime.Now; var item = _service.Update(instance); _service.UnitOfWork.Save(); result.Status = true; result.Data = item; result.Message = "Cập nhật thành công"; return(Ok(result)); } catch (Exception e) { result.Status = false; result.Message = e.Message; return(Ok(result)); } }
public async Task <IHttpActionResult> PostComplete(NvKiemKeVm.Dto instance) { string unitCode = _service.GetCurrentUnitCode(); MdPeriod curentDate = CurrentSetting.GetKhoaSo(unitCode); int period = curentDate.Period; int year = curentDate.Year; string tablleName = curentDate.GetTableName(); NvKiemKe phieuKiemKe = _serviceKK.FindById(instance.Id); instance.NgayDuyetPhieu = curentDate.ToDate; //thực hiện tạo phiếu kiểm kê nhập, kiểm kê xuất try { _serviceKK.Approval(instance, tablleName, year.ToString(), period); _serviceKK.UpdateApproval(instance); _serviceKK.UnitOfWork.Save(); return(Ok(true)); } catch (Exception) { return(InternalServerError()); } }
public async Task <IHttpActionResult> PostCurrentPeriod(MdPeriod instance) { var result = new TransferObj <MdPeriod>(); try { var item = _service.InitializePeriod(instance); _service.UnitOfWork.Save(); var exist = _service.Find(instance); if (exist != null) { if (instance.TrangThai == (int)ApprovalState.IsComplete) { return(BadRequest("Kỳ này đã được duyệt!")); } var unitCode = _service.GetCurrentUnitCode(); var tableNameKyTruoc = item.GetTableName(); var talbeName = instance.GetTableName(); var preTalbeName = _service.GetPreTableName(instance); ProcessState stateOfPeriod = _service.CheckProcess(instance); var checkExist = string.Format("SELECT TABLE_NAME FROM DBA_TABLES where TABLE_NAME = '{0}'", tableNameKyTruoc); using (var ctx = new ERPContext()) { var existKyTruoc = ctx.Database.SqlQuery <InventoryExpImp>(checkExist).ToList(); if (existKyTruoc.Count == 0) { //tạo mới bảng XNT kỳ trước _close.CreateTableXNT_KhoaSo(null, tableNameKyTruoc, instance.UnitCode, instance.Year, instance.Period); } else { stateOfPeriod = ProcessState.IsPending; } switch (stateOfPeriod) { case ProcessState.IsPending: try { _close.ProcedureCloseInventory(preTalbeName, talbeName, instance.UnitCode, instance.Year, instance.Period); exist.TrangThai = (int)ApprovalState.IsComplete; exist.ObjectState = BTS.API.ENTITY.ObjectState.Modified; result.Status = true; result.Message = "Khóa sổ thành công"; _service.UnitOfWork.Save(); } catch (Exception e) { return(InternalServerError(e)); } break; case ProcessState.IsComplete: break; case ProcessState.IsRunning: return(BadRequest("Đang trong quá trình khóa")); case ProcessState.IsError: break; default: break; } } } result.Status = true; result.Data = item; return(Ok(result)); } catch (Exception e) { result.Status = false; result.Message = e.Message; return(Ok(result)); } }
public async Task <IHttpActionResult> PostMultiplePeriod(MdPeriod instance) { var result = new TransferObj <List <MdPeriod> >(); result.Data = new List <MdPeriod>(); var exist = _service.Find(instance); if (exist != null) { if (instance.TrangThai == (int)ApprovalState.IsComplete) { return(BadRequest("Kỳ này đã được duyệt!")); } //tìm kỳ cuối cùng khóa var unitCode = _service.GetCurrentUnitCode(); var periodUnlock = _service.Repository.DbSet.OrderBy(x => x.Period).FirstOrDefault( x => x.Year == exist.Year && x.UnitCode == unitCode && x.Period < exist.Period && (x.TrangThai == (int)ApprovalState.IsNotApproval || x.TrangThai == (int)ApprovalState.IsUnClosingOut)); if (periodUnlock != null) { var beforePeriodNotClose = _service.Repository.DbSet.Any(x => x.Year == periodUnlock.Year && x.Period < periodUnlock.Period && x.TrangThai != (int)ApprovalState.IsComplete && x.UnitCode == unitCode); if (beforePeriodNotClose) { return(BadRequest("Kỳ trước ngày này đang mở!")); } else { var listPeriod = _service.Repository.DbSet.Where( x => x.FromDate >= periodUnlock.FromDate && x.FromDate <= exist.FromDate && x.UnitCode == unitCode).OrderBy(x => x.Period).ToList(); if (listPeriod.Count > 0) { for (int a = 0; a < listPeriod.Count; a++) { var talbeName = listPeriod[a].GetTableName(); var preTalbeName = _service.GetPreTableName(listPeriod[a]); ProcessState stateOfPeriod = _service.CheckProcess(listPeriod[a]); switch (stateOfPeriod) { case ProcessState.IsPending: try { _close.ProcedureCloseInventory(preTalbeName, talbeName, listPeriod[a].UnitCode, listPeriod[a].Year, listPeriod[a].Period); listPeriod[a].TrangThai = (int)ApprovalState.IsComplete; listPeriod[a].ObjectState = BTS.API.ENTITY.ObjectState.Modified; _service.UnitOfWork.Save(); result.Data.Add(listPeriod[a]); result.Status = true; result.Message = "Khóa sổ thành công"; } catch (Exception e) { return(InternalServerError(e)); } break; case ProcessState.IsComplete: break; case ProcessState.IsRunning: return(BadRequest("Đang trong quá trình khóa")); case ProcessState.IsError: break; default: break; } } } } } } return(Ok(result)); }