示例#1
0
        public NvKiemKe InsertPhieu(NvKiemKeVm.Dto instance)
        {
            var unitCode = GetCurrentUnitCode();
            var item     = AutoMapper.Mapper.Map <NvKiemKeVm.Dto, NvKiemKe>(instance);

            item.Id        = Guid.NewGuid().ToString();
            item.MaDonVi   = unitCode;
            item.TrangThai = 20;
            var result     = Insert(item);
            var detailData = AutoMapper.Mapper.Map <List <NvKiemKeVm.DtoDetails>, List <NvKiemKeChiTiet> >(instance.DataDetails);

            detailData.ForEach(x =>
            {
                x.Id               = Guid.NewGuid().ToString();
                x.MaPhieuKiemKe    = item.MaPhieuKiemKe;
                x.SoLuongChenhLech = x.SoLuongTonMay - x.SoLuongKiemKe;
                x.TienTonMay       = x.SoLuongTonMay * x.GiaVon;
                x.TienKiemKe       = x.SoLuongKiemKe * x.GiaVon;
                x.TienChenhLech    = x.TienTonMay - x.TienKiemKe;
                x.MaDonVi          = unitCode;
                x.KhoKiemKe        = instance.KhoKiemKe;
            });
            UnitOfWork.Repository <NvKiemKeChiTiet>().InsertRange(detailData);
            return(result);
        }
示例#2
0
        public NvKiemKe UpdatePhieu(NvKiemKeVm.Dto instance)
        {
            var unitCode  = GetCurrentUnitCode();
            var exsitItem = FindById(instance.Id);

            if (exsitItem.TrangThai == (int)ApprovalState.IsComplete)
            {
                return(null);
            }
            var masterData = Mapper.Map <NvKiemKeVm.Dto, NvKiemKe>(instance);

            masterData.TrangThai = 30;
            var detailData = Mapper.Map <List <NvKiemKeVm.DtoDetails>, List <NvKiemKeChiTiet> >(instance.DataDetails);

            {
                var detailCollection = UnitOfWork.Repository <NvKiemKeChiTiet>().DbSet.Where(x => x.MaPhieuKiemKe == exsitItem.MaPhieuKiemKe);
                detailCollection.ToList().ForEach(x => x.ObjectState = ObjectState.Deleted);
            }
            detailData.ForEach(x =>
            {
                x.Id               = Guid.NewGuid().ToString();
                x.MaPhieuKiemKe    = masterData.MaPhieuKiemKe;
                x.SoLuongChenhLech = x.SoLuongTonMay - x.SoLuongKiemKe;
                x.TienTonMay       = x.SoLuongTonMay * x.GiaVon;
                x.TienKiemKe       = x.SoLuongKiemKe * x.GiaVon;
                x.TienChenhLech    = x.TienTonMay - x.TienKiemKe;
                x.MaDonVi          = unitCode;
                x.KhoKiemKe        = masterData.KhoKiemKe;
            });
            UnitOfWork.Repository <NvKiemKeChiTiet>().InsertRange(detailData);
            var result = Update(masterData);

            return(result);
        }
示例#3
0
        public NvKiemKe UpdateApproval(NvKiemKeVm.Dto instance)
        {
            var exsitItem = FindById(instance.Id);

            if (exsitItem.TrangThai == (int)ApprovalState.IsComplete)
            {
                return(null);
            }
            var masterData = Mapper.Map <NvKiemKeVm.Dto, NvKiemKe>(instance);

            masterData.TrangThai = 10;
            var result = Update(masterData);

            return(result);
        }
示例#4
0
        public string Approval(NvKiemKeVm.Dto instance, string table, string year, int period)
        {
            if (string.IsNullOrEmpty(table))
            {
                return("Kỳ kế toán " + table + "không tồn tại");
            }
            if (string.IsNullOrEmpty(instance.Id))
            {
                return("Không tìm thấy Id phiếu kiểm kê");
            }
            if (string.IsNullOrEmpty(year))
            {
                return("Tham số Năm trống");
            }
            if (period <= 0)
            {
                return("Tham số Kỳ kế toán không đúng");
            }

            var infoPhieu = UnitOfWork.Repository <NvKiemKe>().DbSet.Any(x => x.Id == instance.Id && x.TrangThai != 10);

            if (!infoPhieu)
            {
                return("Không tồn tại phiếu kiểm kê hoặc Phiếu này đã được duyệt");
            }

            var pTableName = new OracleParameter("pTableName", OracleDbType.Varchar2, 50, table, ParameterDirection.Input);
            var pYear      = new OracleParameter("pYear", OracleDbType.Decimal, year, ParameterDirection.Input);
            var pPeriod    = new OracleParameter("period", OracleDbType.Decimal, period, ParameterDirection.Input);
            var pId        = new OracleParameter("pId", OracleDbType.Varchar2, 50, instance.Id, ParameterDirection.Input);

            using (var ctx = new ERPContext())
            {
                try
                {
                    var str = "BEGIN TBNETERP.XNT.XNT_DUYETPHIEU_KIEMKE(:pTableName, :year, :period, :pId); END;";
                    ctx.Database.ExecuteSqlCommand(str, pTableName, pYear, pPeriod, pId);
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }
            return("");
        }
示例#5
0
        public bool Approval(NvKiemKeVm.Dto instance, string table, string year, int period)
        {
            var pTableName = new OracleParameter("pTableName", OracleDbType.NVarchar2, table, ParameterDirection.Input);
            var pYear      = new OracleParameter("pYear", OracleDbType.Decimal, year, ParameterDirection.Input);
            var pPeriod    = new OracleParameter("period", OracleDbType.Decimal, period, ParameterDirection.Input);

            using (var ctx = new ERPContext())
            {
                try
                {
                    var nhapKiemKe = UnitOfWork.Repository <NvKiemKeChiTiet>()
                                     .DbSet.Where(x => x.MaPhieuKiemKe == instance.MaPhieuKiemKe).ToList();
                    foreach (var record in nhapKiemKe)
                    {
                        string id = record.Id;
                        //SoLuongChenhLech < 0 -- NHập kiểm kê
                        if (record.SoLuongChenhLech < 0)
                        {
                            var pId = new OracleParameter("pId", OracleDbType.NVarchar2, id, ParameterDirection.Input);
                            var str = "BEGIN TBNETERP.XNT.XNT_TANGPHIEU_KIEMKE(:pTableName, :year, :period, :pId); END;";
                            ctx.Database.ExecuteSqlCommand(str, pTableName, pYear, pPeriod, pId);
                        }
                        else
                        {
                            var pId = new OracleParameter("pId", OracleDbType.NVarchar2, id, ParameterDirection.Input);
                            var str = "BEGIN TBNETERP.XNT.XNT_GIAMPHIEU_KIEMKE(:pTableName, :year, :period, :pId); END;";
                            ctx.Database.ExecuteSqlCommand(str, pTableName, pYear, pPeriod, pId);
                        }
                    }
                }
                catch
                {
                    return(false);
                }
                return(true);
            }
        }