コード例 #1
0
        public RespondData AddVoucherBudget(E_VoucherBudgetDTO model)
        {
            model.CreateUser = HttpContext.Current.User.Identity.Name;
            model.CompanyId  = this.GetOrg();
            var result = _service.AddVoucherBudget(model);

            return(Success(result));
        }
コード例 #2
0
        public RespondData SaveCompanyBudgetDistributes(E_VoucherBudgetDTO model)
        {
            model.CompanyId = this.GetOrg();
            var result = _service.SaveCompanyBudgetDistributes(model);

            if (string.IsNullOrWhiteSpace(result))
            {
                return(Success(null));
            }

            return(Fail(result));
        }
コード例 #3
0
        public RespondData ApproveDistribute(E_VoucherBudgetDTO model)
        {
            model.UpdateUser = HttpContext.Current.User.Identity.Name;
            model.UpdateDate = DateTime.Now;
            model.CompanyId  = this.GetOrg();
            var result = _service.ApproveDistribute(model);

            if (!string.IsNullOrWhiteSpace(result))
            {
                return(Fail(result));
            }
            return(Success(null));
        }
コード例 #4
0
        public E_VoucherBudgetDTO GetBudgetDistributesById(EvoucherBudgetDetailPagingFilterModelDTO filter)
        {
            E_VoucherBudgetDTO res = null;
            var budget             = _repo.SelectWhere(x => x.Id == filter.EvoucherBudgetId && x.CompanyId == filter.CompanyId).FirstOrDefault();

            if (budget != null)
            {
                res = new E_VoucherBudgetDTO()
                {
                    Budget       = budget.Budget,
                    BudgetDate   = budget.BudgetDate,
                    CompanyId    = budget.CompanyId,
                    StaffConfirm = budget.StaffConfirm,
                    TotalStaff   = budget.TotalStaff,
                    Status       = budget.Status,
                    StatusName   = budget.StatusName,
                    Id           = budget.Id,
                    TotalValues  = budget.TotalValues,
                    CompanyName  = budget.CompanyName,
                    CreateDate   = budget.CreateDate,
                    CreateUser   = budget.CreateUser
                };
                // tong so voucher da phan bo
                var totalDistriVouchers = _denomiRepo.SelectWhere(x => x.VoucherBudgetId == budget.Id).ToList();
                res.TotalDistributedCount = totalDistriVouchers != null && totalDistriVouchers.Count > 0 ? totalDistriVouchers.Sum(x => x.CountNumber) : 0;

                // cac menh gia
                var denomis = _denomiRepo.SelectWhere(x => x.VoucherBudgetId == filter.EvoucherBudgetId).Select(
                    x => new E_VoucherBudgetDenominationsDTO
                {
                    VoucherBudgetId = x.VoucherBudgetId,
                    CountNumber     = x.CountNumber,
                    Denominations   = x.Denominations,
                    Id              = x.Id,
                    TotalValues     = x.TotalValues,
                    VoucherTypeCode = x.VoucherTypeCode,
                    VoucherTypeName = x.VoucherTypeName
                }).ToList();
                res.BudgetDenominations = denomis;

                // tong so menh gia cac loai
                if (denomis != null && denomis.Count > 0)
                {
                    res.DenomiTotalCount  = denomis.Sum(x => x.CountNumber);
                    res.DenomiTotalValues = denomis.Sum(x => x.TotalValues);
                }
            }
            return(res);
        }
コード例 #5
0
 public string ReturnDistribute(E_VoucherBudgetDTO model)
 {
     return(new EvoucherBudgetRepository(this._unitOfWork).UpdateBudgetStatus(model, BudgetStatus.Distributed, "Đã phân bổ"));
 }
コード例 #6
0
 public string ApproveDistribute(E_VoucherBudgetDTO model)
 {
     return(new EvoucherBudgetRepository(this._unitOfWork).UpdateBudgetStatus(model, BudgetStatus.Approved, "Đã phê duyệt"));
 }
コード例 #7
0
        public string SaveCompanyBudgetDistributes(E_VoucherBudgetDTO model)
        {
            using (var ts = this._unitOfWork.BeginTransaction())
            {
                try
                {
                    var budget = this._repo.SelectWhere(x => x.Id == model.Id && x.CompanyId == model.CompanyId).FirstOrDefault();
                    if (budget != null)
                    {
                        // da hoan thanh phan bo
                        if (budget.Status >= (int?)BudgetStatus.DistributedCompleted)
                        {
                            return("Ngân sách của công ty ngày này đã hoàn thành phân bổ");
                        }

                        // update trang thai thanh da phan bo
                        var properties = new List <Expression <Func <E_VoucherBudget, object> > >
                        {
                            (x => x.Status),
                            (x => x.StatusName),
                        };
                        budget.Status     = (int?)BudgetStatus.Distributed;
                        budget.StatusName = "Đã phân bổ";
                        this._repo.UpdateByProperties(budget, properties);
                        _unitOfWork.SaveChanges();

                        #region Them dong menh gia cua cac nhan vien
                        foreach (var empData in model.BudgetDetails)
                        {
                            var budDetail = _detailRepo.SelectWhere(x => x.Id == empData.Id && x.OrgCompanyId == model.CompanyId).FirstOrDefault();
                            if (budDetail != null)
                            {
                                if (empData.DistributeLines != null && empData.DistributeLines.Count > 0)
                                {
                                    // update trang thai thanh da phan bo va so luong
                                    var detailProps = new List <Expression <Func <E_VoucherBudgetDetail, object> > >
                                    {
                                        (x => x.Status),
                                        (x => x.StatusName),
                                    };
                                    budDetail.Status     = (int?)BudgetStatus.Distributed;
                                    budDetail.StatusName = "Đã phân bổ";
                                    this._detailRepo.UpdateByProperties(budDetail, detailProps);
                                    _unitOfWork.SaveChanges();

                                    if (empData.DistributeLines.Sum(x => x.TotalValues) > empData.Budget)
                                    {
                                        return("Dữ liệu không khớp: [" + empData.CodeUser + "] Tổng tiền voucher lớn hơn ngân sách");
                                    }

                                    foreach (var demino in empData.DistributeLines)
                                    {
                                        // tim dong co cung menh gia cua nhan vien nay
                                        var demi = _detailLineRepo.SelectWhere(x => x.VoucherTypeCode == demino.VoucherTypeCode && x.VoucherBudgetDetailId == empData.Id).FirstOrDefault();
                                        if (demi != null) // update
                                        {
                                            demi.CountNumberPage = demino.CountNumberPage;
                                            demi.Denominations   = demino.Denominations;
                                            demi.TotalValues     = demino.TotalValues;

                                            var detailLineProps = new List <Expression <Func <E_VoucherBudgetDetailLine, object> > >
                                            {
                                                (x => x.CountNumberPage),
                                                (x => x.Denominations),
                                                (x => x.TotalValues),
                                            };
                                            this._detailLineRepo.UpdateByProperties(demi, detailLineProps);
                                            _unitOfWork.SaveChanges();
                                        }
                                        else // add
                                        {
                                            var demi1 = new E_VoucherBudgetDetailLine()
                                            {
                                                CountNumberPage       = demino.CountNumberPage,
                                                Denominations         = demino.Denominations,
                                                TotalValues           = demino.TotalValues,
                                                VoucherBudgetDetailId = (int?)empData.Id,
                                                VoucherTypeCode       = demino.VoucherTypeCode,
                                                VoucherTypeName       = demino.VoucherTypeName
                                            };

                                            _detailLineRepo.Add(demi1);
                                            _unitOfWork.SaveChanges();
                                        }
                                    }
                                }
                            }
                        }
                        #endregion


                        #region Them dong menh gia cua ngay
                        foreach (var budDeno in model.BudgetDenominations)
                        {
                            // tim dong co cung menh gia cua nhan vien nay
                            var tBudDenomi = _denomiRepo.SelectWhere(x => x.VoucherTypeCode == budDeno.VoucherTypeCode && x.VoucherBudgetId == model.Id).FirstOrDefault();
                            if (tBudDenomi != null) // update
                            {
                                tBudDenomi.CountNumber   = budDeno.CountNumber;
                                tBudDenomi.Denominations = budDeno.Denominations;
                                tBudDenomi.TotalValues   = budDeno.TotalValues;

                                var budDenoProps = new List <Expression <Func <E_VoucherBudgetDenominations, object> > >
                                {
                                    (x => x.CountNumber),
                                    (x => x.Denominations),
                                    (x => x.TotalValues),
                                };
                                this._denomiRepo.UpdateByProperties(tBudDenomi, budDenoProps);
                                _unitOfWork.SaveChanges();
                            }
                            else // add
                            {
                                var demi1 = new E_VoucherBudgetDenominations()
                                {
                                    CountNumber     = budDeno.CountNumber,
                                    Denominations   = budDeno.Denominations,
                                    TotalValues     = budDeno.TotalValues,
                                    VoucherBudgetId = model.Id,
                                    VoucherTypeCode = budDeno.VoucherTypeCode,
                                    VoucherTypeName = budDeno.VoucherTypeName,
                                };

                                _denomiRepo.Add(demi1);
                                _unitOfWork.SaveChanges();
                            }
                        }
                        #endregion

                        ts.Commit();
                    }
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }
            return("");
        }
コード例 #8
0
 public string ReturnDistribute(E_VoucherBudgetDTO model)
 {
     return(this._repo.ReturnDistribute(model));
 }
コード例 #9
0
        public string UpdateBudgetStatus(E_VoucherBudgetDTO model, BudgetStatus status, string statusName)
        {
            using (var ts = this._unitOfWork.BeginTransaction())
            {
                try
                {
                    var budget = this._repo.SelectWhere(x => x.Id == model.Id && x.CompanyId == model.CompanyId).FirstOrDefault();
                    if (budget != null)
                    {
                        #region kiem tra cac trang thai
                        if (status == BudgetStatus.CreatedCompleted)// hoan thanh nhap ngan sach
                        {
                            if (budget.Status != (int?)BudgetStatus.Created)
                            {
                                return("Lỗi: Không thể hoàn thành nhập ngân sách có trạng thái không phải 'Đã nhập'.");
                            }
                        }
                        else if (status == BudgetStatus.DistributedCompleted) // hoan thanh phan bo
                        {
                            if (budget.Status != (int?)BudgetStatus.Distributed)
                            {
                                return("Lỗi: Không thể hoàn thành phân bổ ngân sách có trạng thái không phải 'Đã phân bổ'.");
                            }
                        }
                        else if (status == BudgetStatus.Approved) // duyet phan bo
                        {
                            if (budget.Status != (int?)BudgetStatus.DistributedCompleted)
                            {
                                return("Lỗi: Không thể duyệt phân bổ ngân sách có trạng thái không phải 'Hoàn thành phân bổ'.");
                            }
                        }
                        else if (status == BudgetStatus.Distributed) //  tra lai
                        {
                            if (budget.Status != (int?)BudgetStatus.DistributedCompleted)
                            {
                                return("Lỗi: Không thể trả lại phân bổ ngân sách có trạng thái không phải 'Đã hoàn thành phân bổ'.");
                            }
                        }
                        #endregion

                        // update trang thai budget
                        var properties = new List <Expression <Func <E_VoucherBudget, object> > >
                        {
                            (x => x.Status),
                            (x => x.StatusName),
                            (x => x.UpdateUser),
                            (x => x.UpdateDate),
                        };
                        budget.Status     = (int?)status;
                        budget.StatusName = statusName;
                        budget.UpdateUser = model.UpdateUser;
                        budget.UpdateDate = DateTime.Now;

                        this._repo.UpdateByProperties(budget, properties);
                        _unitOfWork.SaveChanges();


                        var budgetDetails = _detailRepo.SelectWhere(x => x.VoucherBudgetId == budget.Id).ToList();
                        if (budgetDetails != null && budgetDetails.Count > 0)
                        {
                            foreach (var item in budgetDetails)
                            { // update trang thai budget
                                var properties1 = new List <Expression <Func <E_VoucherBudgetDetail, object> > >
                                {
                                    (x => x.Status),
                                    (x => x.StatusName),
                                    (x => x.UpdateUser),
                                    (x => x.UpdateDate),
                                };
                                item.Status     = (int?)status;
                                item.StatusName = statusName;
                                item.UpdateUser = model.UpdateUser;
                                item.UpdateDate = DateTime.Now;

                                this._detailRepo.UpdateByProperties(item, properties1);
                                _unitOfWork.SaveChanges();
                            }
                        }
                        ts.Commit();
                    }
                }
                catch (Exception ex)
                {
                    FileLog.WriteLog(ex.ToString());
                    return(ex.Message);
                }
            }
            return("");
        }
コード例 #10
0
        public ImportDataResult AddVoucherBudget(E_VoucherBudgetDTO model)
        {
            using (var ts = this._unitOfWork.BeginTransaction())
            {
                try
                {
                    var totalBudget = model.BudgetDetails.Sum(x => x.Budget);
                    var totalEmp    = model.BudgetDetails.Count();
                    // kiem tra cong ty co ton tai va hop le
                    var comp = this._orgRepo.SelectWhere(x => x.Id == model.CompanyId && x.IsActive != null && x.IsActive.Value).FirstOrDefault();
                    if (comp == null)
                    {
                        return(new ImportDataResult()
                        {
                            IsSuccess = false,
                            Message = "Công ty không tồn tại hoặc không hợp lệ",
                            Budget = totalBudget,
                            BudgetDate = model.BudgetDate,
                            TotalValue = totalBudget,
                            StaffConfirm = totalEmp,
                            TotalStaff = totalEmp,
                            CompanyName = comp.Name
                        });
                    }

                    // lay danh sach nhan vien loi
                    var errors = GetErrors(model.BudgetDetails);
                    if (errors != null && errors.Count > 0)
                    {
                        return(new ImportDataResult()
                        {
                            ErrorLines = errors,
                            IsSuccess = false,
                            Budget = totalBudget,
                            BudgetDate = model.BudgetDate,
                            TotalValue = totalBudget,
                            StaffConfirm = totalEmp,
                            TotalStaff = totalEmp,
                            CompanyName = comp.Name
                        });
                    }

                    // xoa du lieu cu theo cong ty + ngay
                    // lai chi lay theo ngay bo thoi gian
                    model.BudgetDate = model.BudgetDate.Value.Date;
                    var budget = this._repo.SelectWhere(x => x.CompanyId == model.CompanyId && x.BudgetDate == model.BudgetDate).FirstOrDefault();
                    if (budget != null)
                    {
                        // da hoan thanh nhap
                        if (budget.Status != (int?)BudgetStatus.Created)
                        {
                            return(new ImportDataResult()
                            {
                                IsSuccess = false,
                                Message = "Ngân sách của công ty ngày này đã hoàn thành nhập",
                                Budget = totalBudget,
                                BudgetDate = model.BudgetDate,
                                TotalValue = totalBudget,
                                StaffConfirm = totalEmp,
                                TotalStaff = totalEmp,
                                CompanyName = comp.Name
                            });
                        }

                        _repo.Delete(budget);
                        var budgetDetails = _detailRepo.SelectWhere(x => x.VoucherBudgetId == budget.Id).ToList();
                        if (budgetDetails != null && budgetDetails.Count > 0)
                        {
                            foreach (var item in budgetDetails)
                            {
                                _detailRepo.Delete(item);
                            }
                        }
                        _unitOfWork.SaveChanges();
                    }

                    // tao budget
                    var entity = new E_VoucherBudget()
                    {
                        Budget       = totalBudget,
                        TotalValues  = totalBudget,
                        BudgetDate   = model.BudgetDate,
                        BudgetYear   = model.BudgetDate.Value.Year,
                        BudgetMonth  = model.BudgetDate.Value.Month,
                        CompanyId    = model.CompanyId,
                        CompanyName  = comp.Name,
                        CreateDate   = DateTime.Now,
                        StaffConfirm = totalEmp,
                        TotalStaff   = totalEmp,
                        Status       = (int?)BudgetStatus.Created,
                        StatusName   = "Đã nhập"
                    };
                    var result = _repo.Add(entity);
                    _unitOfWork.SaveChanges();

                    // tao budget details
                    if (result != null)
                    {
                        foreach (var item in model.BudgetDetails)
                        {
                            var bDetail = new E_VoucherBudgetDetail()
                            {
                                VoucherBudgetId = result.Id,
                                Budget          = item.Budget,
                                CodeUser        = item.CodeUser,
                                CreatedUser     = model.CreateUser,
                                CreatedDate     = DateTime.Now,
                                NameUser        = item.NameUser,
                                OrgCompanyId    = model.CompanyId,
                                OrgCompanyName  = comp.Name,
                                JobTitle        = item.JobTitle,
                                Status          = (int?)BudgetStatus.Created,
                                StatusName      = "Đã nhập",
                                OrderNo         = item.OrderNo
                            };
                            _detailRepo.Add(bDetail);
                            _unitOfWork.SaveChanges();
                        }
                    }

                    ts.Commit();

                    return(new ImportDataResult()
                    {
                        IsSuccess = true,
                        Budget = totalBudget,
                        BudgetDate = model.BudgetDate,
                        TotalValue = totalBudget,
                        StaffConfirm = totalEmp,
                        TotalStaff = totalEmp,
                        CompanyName = comp.Name
                    });
                }
                catch (Exception ex)
                {
                    return(new ImportDataResult()
                    {
                        IsSuccess = false,
                        Message = ex.ToString()
                    });
                }
            }
        }
コード例 #11
0
 public string FinishBudget(E_VoucherBudgetDTO model)
 {
     return(UpdateBudgetStatus(model, BudgetStatus.CreatedCompleted, "Đã hoàn thành nhập"));
 }
コード例 #12
0
 public string SaveCompanyBudgetDistributes(E_VoucherBudgetDTO model)
 {
     return(_repo.SaveCompanyBudgetDistributes(model));
 }
コード例 #13
0
 public string CompleteDistribute(E_VoucherBudgetDTO model)
 {
     return(this._repo.CompleteDistribute(model));
 }
コード例 #14
0
 public ImportDataResult AddVoucherBudget(E_VoucherBudgetDTO model)
 {
     return(this._repo.AddVoucherBudget(model));
 }
コード例 #15
0
 public string CompleteDistribute(E_VoucherBudgetDTO model)
 {
     return(new EvoucherBudgetRepository(this._unitOfWork).UpdateBudgetStatus(model, BudgetStatus.DistributedCompleted, "Hoàn thành phân bổ"));
 }
コード例 #16
0
 public string FinishBudget(E_VoucherBudgetDTO model)
 {
     return(this._repo.FinishBudget(model));
 }
コード例 #17
0
 public string ApproveDistribute(E_VoucherBudgetDTO model)
 {
     return(this._repo.ApproveDistribute(model));
 }