Ejemplo n.º 1
0
        public static int Insert(CuaHangAddNewModel model)
        {
            var dbModel = new CuaHang
            {
                TenCuaHang    = model.TenCuaHang,
                DiaChi        = model.DiaChi,
                Latitude      = model.Latitude,
                Longitude     = model.Longitude,
                NgayTao       = model.NgayTao,
                NguoiTao      = model.NguoiTao,
                QuyTienMat    = model.QuyTienMat,
                VonDauTu      = model.VonDauTu,
                TinhTrang     = model.TinhTrang ? 1 : 0,
                QuanLyCuaHang = model.TKQuanLy
            };

            using (var context = new TIT_Entities())
            {
                context.CuaHangs.Add(dbModel);

                try
                {
                    return(context.SaveChanges());
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    //_logger.Error(ex.ToString());
                    return(-1);
                }
            }
        }
Ejemplo n.º 2
0
 public static int HenGio(string id_HopDong, DateTime ngayHen, string ghiChu)
 {
     using (var context = new TIT_Entities())
     {
         var HD = context.HD_VayDuNoGiamDan.Where(x => x.HD_Id == id_HopDong).FirstOrDefault();
         if (HD != null)
         {
             HD.TrangThaiHenGio = 1;
             HD.NgayHenGio      = ngayHen;
             HD.GhiChuHenGio    = ghiChu;
             try
             {
                 if (context.SaveChanges() > 0)
                 {
                     return(1);
                 }
                 else
                 {
                     return(0);
                 }
             }
             catch (Exception ex)
             {
                 ex.ToString();
                 //_logger.Error(ex.ToString());
             }
         }
     }
     return(0);
 }
Ejemplo n.º 3
0
 public static int CapNhatThongTinGhiChu(string id_HopDong, string ghiChu)
 {
     using (var context = new TIT_Entities())
     {
         var hd_update = context.HD_VayDuNoGiamDan.SingleOrDefault(x => x.HD_Id == id_HopDong);
         hd_update.GhiChu = ghiChu;
         try
         {
             if (context.SaveChanges() > 0)
             {
                 return(1);
             }
             else
             {
                 return(0);
             }
         }
         catch (Exception ex)
         {
             ex.ToString();
             //_logger.Error(ex.ToString());
             return(0);
         }
     }
 }
Ejemplo n.º 4
0
        public static int CapNhatCuaHangTheoAdmin(CuaHangUpdateModel model)
        {
            using (var context = new TIT_Entities())
            {
                //update
                var item_update = context.CuaHangs.SingleOrDefault(x => x.MaCuaHang == model.MaCuaHang);
                if (item_update != null)
                {
                    item_update.DiaChi        = model.DiaChi;
                    item_update.Latitude      = model.Latitude;
                    item_update.Longitude     = model.Longitude;
                    item_update.QuyTienMat    = model.QuyTienMat;
                    item_update.TenCuaHang    = model.TenCuaHang;
                    item_update.TinhTrang     = model.TinhTrang ? 1 : 0;
                    item_update.VonDauTu      = model.VonDauTu;
                    item_update.QuanLyCuaHang = model.QuanLyCuaHang;

                    try
                    {
                        if (context.SaveChanges() > 0)
                        {
                            return(1);
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                        //_logger.Error(ex.ToString());
                        return(0);
                    }
                }
            }
            return(0);
        }
Ejemplo n.º 5
0
 public static int CapNhatUrl(string idHopDong, string newPath, int STT)
 {
     using (var context = new TIT_Entities())
     {
         var hopdong = context.HD_VayDuNoGiamDan.Where(x => x.HD_Id == idHopDong).FirstOrDefault();
         if (STT == 1)
         {
             hopdong.UrlHinh1 = newPath;
         }
         else if (STT == 2)
         {
             hopdong.UrlHinh2 = newPath;
         }
         else
         {
             hopdong.UrlHinh3 = newPath;
         }
         try
         {
             if (context.SaveChanges() > 0)
             {
                 return(1);
             }
             else
             {
                 return(0);
             }
         }
         catch (Exception ex)
         {
             ex.ToString();
             //_logger.Error(ex.ToString());
             return(0);
         }
     }
 }
Ejemplo n.º 6
0
        public static int DongTienLai(string hD_BatHo_Id, BatHo_ThongTinChiTietDongTienLaiModel update, string Id_NhanVien)
        {
            using (var context = new TIT_Entities())
            {
                //update
                var item_update = context.ThongTinDongLais.SingleOrDefault(x => x.Id == update.ID);
                item_update.DaDong      = update.DaDong;
                item_update.NgayDongLai = DateTime.Now;

                var hd_update = context.HD_BatHo.SingleOrDefault(x => x.HD_BatHo_Id == hD_BatHo_Id);
                hd_update.NgayCuoiCungDongTien = item_update.NgayKetThuc;

                var baocao = context.BaoCaoHangNgays.OrderByDescending(x => x.Ngay).FirstOrDefault(x => x.Id_CuaHang == hd_update.CuaHang_Id);
                if (baocao != null)
                {
                    if (baocao.Ngay == DateTime.Now.Date)
                    {
                        baocao.SoTienVonConLai     += update.TienHo;
                        baocao.TongThu             += update.TienHo;
                        baocao.TongThuHopDongBatHo += update.TienHo;
                    }
                    else
                    {
                        var bcModel = new BaoCaoHangNgay
                        {
                            Id_CuaHang       = hd_update.CuaHang_Id,
                            Ngay             = DateTime.Now.Date,
                            SoTienVonDauNgay = baocao.SoTienVonConLai,
                            SoTienVonConLai  = baocao.SoTienVonConLai,
                        };
                        bcModel.SoTienVonConLai     += update.TienHo;
                        bcModel.TongThu             += update.TienHo;
                        bcModel.TongThuHopDongBatHo += update.TienHo;

                        context.BaoCaoHangNgays.Add(bcModel);
                    }
                }
                else
                {
                    var bcModel = new BaoCaoHangNgay
                    {
                        Id_CuaHang = hd_update.CuaHang_Id,
                        Ngay       = DateTime.Now.Date
                    };
                    bcModel.SoTienVonConLai     += update.TienHo;
                    bcModel.TongThu             += update.TienHo;
                    bcModel.TongThuHopDongBatHo += update.TienHo;
                    context.BaoCaoHangNgays.Add(bcModel);
                }
                decimal QuyTienMat           = 0;
                var     lastestLichSuThaoTac = context.LichSuThaoTacs.Where(x => x.Id_CuaHang == hd_update.CuaHang_Id).OrderByDescending(p => p.Id).FirstOrDefault();
                if (lastestLichSuThaoTac != null)
                {
                    QuyTienMat = lastestLichSuThaoTac.TongCongTon;
                }


                var lichsu = new LichSuThaoTac()
                {
                    Id_CuaHang         = hd_update.CuaHang_Id,
                    Id_HopDong         = hd_update.HD_BatHo_Id,
                    Id_NhanVienThaoTac = Id_NhanVien,
                    NgayThaoTac        = DateTime.Now,
                    NoiDung            = "Đóng họ",
                    SoTien             = item_update.TienLai,
                    ThuTien            = 1,
                    TongCongTon        = QuyTienMat + item_update.TienLai,
                    TenKhachHang       = ""
                };

                context.LichSuThaoTacs.Add(lichsu);


                try
                {
                    if (context.SaveChanges() > 0)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    //_logger.Error(ex.ToString());
                    return(0);
                }
            }
        }
Ejemplo n.º 7
0
        public static int ThanhToanHopDong(string Id_HopDong, int Id_CuaHang, string Id_NhanVien, decimal SoTien)
        {
            using (var context = new TIT_Entities())
            {
                var item_update2 = context.ThongTinDongLais.Where(x => x.HopDong_Id == Id_HopDong).ToList();
                for (int i = 0; i < item_update2.Count; i++)
                {
                    item_update2[i].DaDong = 1;
                }
                //update
                var item_update = context.HD_BatHo.SingleOrDefault(x => x.HD_BatHo_Id == Id_HopDong);
                item_update.TinhTrang            = "Thanh Lý";
                item_update.NgayCuoiCungDongTien = item_update2[item_update2.Count - 1].NgayKetThuc;

                var baocao = context.BaoCaoHangNgays.OrderByDescending(x => x.Ngay).FirstOrDefault(x => x.Id_CuaHang == Id_CuaHang);
                if (baocao != null)
                {
                    if (baocao.Ngay == DateTime.Now.Date)
                    {
                        baocao.SoTienVonConLai     += SoTien;
                        baocao.TongThu             += SoTien;
                        baocao.TongThuHopDongBatHo += SoTien;
                    }
                    else
                    {
                        var bcModel = new BaoCaoHangNgay
                        {
                            Id_CuaHang       = Id_CuaHang,
                            Ngay             = DateTime.Now.Date,
                            SoTienVonDauNgay = baocao.SoTienVonConLai,
                            SoTienVonConLai  = baocao.SoTienVonConLai,
                        };
                        bcModel.SoTienVonConLai     += SoTien;
                        bcModel.TongThu             += SoTien;
                        bcModel.TongThuHopDongBatHo += SoTien;

                        context.BaoCaoHangNgays.Add(bcModel);
                    }
                }
                else
                {
                    var bcModel = new BaoCaoHangNgay
                    {
                        Id_CuaHang = Id_CuaHang,
                        Ngay       = DateTime.Now.Date
                    };
                    bcModel.SoTienVonConLai     += SoTien;
                    bcModel.TongThu             += SoTien;
                    bcModel.TongThuHopDongBatHo += SoTien;
                    context.BaoCaoHangNgays.Add(bcModel);
                }
                decimal QuyTienMat           = 0;
                var     lastestLichSuThaoTac = context.LichSuThaoTacs.Where(x => x.Id_CuaHang == Id_CuaHang).OrderByDescending(p => p.Id).FirstOrDefault();
                if (lastestLichSuThaoTac != null)
                {
                    QuyTienMat = lastestLichSuThaoTac.TongCongTon;
                }

                var model = new LichSuThaoTac()
                {
                    Id_CuaHang         = Id_CuaHang,
                    Id_HopDong         = Id_HopDong,
                    Id_NhanVienThaoTac = Id_NhanVien,
                    NgayThaoTac        = DateTime.Now,
                    NoiDung            = "Thanh lý hợp đồng",
                    SoTien             = SoTien,
                    ThuTien            = 1,
                    TongCongTon        = QuyTienMat + SoTien,
                    TenKhachHang       = ""
                };
                context.LichSuThaoTacs.Add(model);

                try
                {
                    if (context.SaveChanges() > 0)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    //_logger.Error(ex.ToString());
                    return(0);
                }
            }
        }
Ejemplo n.º 8
0
        public static string Insert(HopDongBatHoDataModel model)
        {
            var dbModel = new HD_BatHo
            {
                CuaHang_Id           = model.CuaHang_Id,
                GhiChu               = model.GhiChu,
                BatHo                = model.BatHo,
                BocTrongVong         = model.BocTrongVong,
                KhachHang_CMND       = model.KhachHang.CMND,
                NgayBoc              = model.NgayBoc,
                NgayCuoiCungDongTien = model.NgayBoc,
                NgayTao              = DateTime.Now,
                NhanVien_Id          = model.NhanVien_Id,
                SoNgayDongTien       = model.SoNgayDongTien,
                SoTienKhachDaDong    = 0,
                ThuHoTruoc           = false,
                TienDuaChoKhach      = model.TienDuaChoKhach,
                TinhTrang            = "Đang vay"
            };



            using (var context = new TIT_Entities())
            {
                context.HD_BatHo.Add(dbModel);

                try
                {
                    if (context.SaveChanges() > 0)
                    {
                        var baocao = context.BaoCaoHangNgays.OrderByDescending(x => x.Ngay).FirstOrDefault(x => x.Id_CuaHang == model.CuaHang_Id);
                        if (baocao != null)
                        {
                            if (baocao.Ngay == DateTime.Now.Date)
                            {
                                baocao.SoTienVonConLai     -= model.TienDuaChoKhach;
                                baocao.TongChi             += model.TienDuaChoKhach;
                                baocao.TongChiHopDongBatHo += model.TienDuaChoKhach;
                            }
                            else
                            {
                                var bcModel = new BaoCaoHangNgay
                                {
                                    Id_CuaHang       = model.CuaHang_Id,
                                    Ngay             = DateTime.Now.Date,
                                    SoTienVonDauNgay = baocao.SoTienVonConLai,
                                    SoTienVonConLai  = baocao.SoTienVonConLai,
                                };
                                bcModel.SoTienVonConLai     -= model.TienDuaChoKhach;
                                bcModel.TongChi             += model.TienDuaChoKhach;
                                bcModel.TongChiHopDongBatHo += model.TienDuaChoKhach;

                                context.BaoCaoHangNgays.Add(bcModel);
                            }
                        }
                        else
                        {
                            var bcModel = new BaoCaoHangNgay
                            {
                                Id_CuaHang = model.CuaHang_Id,
                                Ngay       = DateTime.Now.Date
                            };
                            bcModel.SoTienVonConLai     -= model.TienDuaChoKhach;
                            bcModel.TongChi             += model.TienDuaChoKhach;
                            bcModel.TongChiHopDongBatHo += model.TienDuaChoKhach;
                            context.BaoCaoHangNgays.Add(bcModel);
                        }
                        decimal QuyTienMat           = 0;
                        var     lastestLichSuThaoTac = context.LichSuThaoTacs.Where(x => x.Id_CuaHang == model.CuaHang_Id).OrderByDescending(p => p.Id).FirstOrDefault();
                        if (lastestLichSuThaoTac != null)
                        {
                            QuyTienMat = lastestLichSuThaoTac.TongCongTon;
                        }
                        var dbModel2 = new LichSuThaoTac()
                        {
                            Id_CuaHang         = model.CuaHang_Id,
                            Id_HopDong         = dbModel.HD_BatHo_Id,
                            Id_NhanVienThaoTac = model.NhanVien_Id,
                            NgayThaoTac        = DateTime.Now,
                            NoiDung            = "Tạo hợp đồng",
                            SoTien             = model.TienDuaChoKhach,
                            ThuTien            = 0,
                            TenKhachHang       = model.KhachHang.TenKhachHang,
                            TongCongTon        = QuyTienMat - model.TienDuaChoKhach
                        };
                        context.LichSuThaoTacs.Add(dbModel2);

                        List <ThongTinDongLai> listModels = new List <ThongTinDongLai>();
                        int      SoNgay     = model.BocTrongVong / model.SoNgayDongTien;
                        DateTime ngayBatDau = model.NgayBoc;
                        for (int i = 0; i < SoNgay; i++)
                        {
                            ThongTinDongLai item = new ThongTinDongLai()
                            {
                                DaDong      = 0,
                                HopDong_Id  = dbModel.HD_BatHo_Id,
                                NgayBatDau  = ngayBatDau,
                                NgayDongLai = DateTime.Now,
                                NgayKetThuc = ngayBatDau.AddDays(model.SoNgayDongTien - 1),
                                SoNgay      = model.SoNgayDongTien,
                                TienLai     = model.TienMotNgay * model.SoNgayDongTien
                            };
                            context.ThongTinDongLais.Add(item);
                            ngayBatDau = ngayBatDau.AddDays(model.SoNgayDongTien);
                        }
                        if (context.SaveChanges() > 0)
                        {
                            return(dbModel.HD_BatHo_Id);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    //_logger.Error(ex.ToString());
                    return(null);
                }
            }
        }
Ejemplo n.º 9
0
        public static int Insert(ThuChiDataModel model, int PhieuThuHayChi)
        {
            var dbModel = new ThongTinThuChi()
            {
                Id_CuaHang  = model.MaCuaHang,
                Id_NhanVien = model.MaNhanVien,
                KhachHang   = model.KhachHang,
                LoaiPhieu   = model.LoaiPhieu,
                NgayTao     = DateTime.Now,
                PhieuThu    = PhieuThuHayChi,
                GhiChu      = model.GhiChu,
                SoTien      = model.SoTien
            };

            using (var context = new TIT_Entities())
            {
                decimal QuyTienMat           = 0;
                var     lastestLichSuThaoTac = context.LichSuThaoTacs.Where(x => x.Id_CuaHang == model.MaCuaHang).OrderByDescending(p => p.Id).FirstOrDefault();
                if (lastestLichSuThaoTac != null)
                {
                    QuyTienMat = lastestLichSuThaoTac.TongCongTon;
                }

                var dbLichsu = new LichSuThaoTac()
                {
                    Id_CuaHang         = model.MaCuaHang,
                    Id_HopDong         = "",
                    Id_NhanVienThaoTac = model.MaNhanVien,
                    NgayThaoTac        = DateTime.Now,
                    NoiDung            = model.LoaiPhieu + ":" + model.GhiChu,
                    SoTien             = model.SoTien,
                    ThuTien            = PhieuThuHayChi == PHIEU_THU ? 1 : 0,
                    TongCongTon        = QuyTienMat + model.SoTien * (PhieuThuHayChi == PHIEU_THU ? 1 : -1),
                    TenKhachHang       = model.KhachHang
                };
                context.LichSuThaoTacs.Add(dbLichsu);
                var baocao = context.BaoCaoHangNgays.OrderByDescending(x => x.Ngay).FirstOrDefault(x => x.Id_CuaHang == model.MaCuaHang);
                if (baocao != null)
                {
                    if (baocao.Ngay == DateTime.Now.Date)
                    {
                        if (PhieuThuHayChi == PHIEU_THU)
                        {
                            baocao.SoTienVonConLai += model.SoTien;
                            baocao.TongThu         += model.SoTien;
                            baocao.TongThuKhac     += model.SoTien;
                        }
                        else
                        {
                            baocao.SoTienVonConLai -= model.SoTien;
                            baocao.TongChi         += model.SoTien;
                            baocao.TongChiKhac     += model.SoTien;
                        }
                    }
                    else
                    {
                        var bcModel = new BaoCaoHangNgay
                        {
                            Id_CuaHang       = model.MaCuaHang,
                            Ngay             = DateTime.Now.Date,
                            SoTienVonDauNgay = baocao.SoTienVonConLai,
                            SoTienVonConLai  = baocao.SoTienVonConLai
                        };
                        if (PhieuThuHayChi == PHIEU_THU)
                        {
                            bcModel.SoTienVonConLai += model.SoTien;
                            bcModel.TongThu         += model.SoTien;
                            bcModel.TongThuKhac     += model.SoTien;
                        }
                        else
                        {
                            bcModel.SoTienVonConLai -= model.SoTien;
                            bcModel.TongChi         += model.SoTien;
                            bcModel.TongChiKhac     += model.SoTien;
                        }
                        context.BaoCaoHangNgays.Add(bcModel);
                    }
                }
                else
                {
                    var bcModel = new BaoCaoHangNgay
                    {
                        Id_CuaHang = model.MaCuaHang,
                        Ngay       = DateTime.Now.Date
                    };
                    if (PhieuThuHayChi == PHIEU_THU)
                    {
                        bcModel.SoTienVonConLai = model.SoTien;
                        bcModel.TongThu         = model.SoTien;
                        bcModel.TongThuKhac     = model.SoTien;
                    }
                    else
                    {
                        bcModel.SoTienVonConLai = -model.SoTien;
                        bcModel.TongChi         = model.SoTien;
                        bcModel.TongChiKhac     = model.SoTien;
                    }
                    context.BaoCaoHangNgays.Add(bcModel);
                }



                context.ThongTinThuChis.Add(dbModel);
                try
                {
                    if (context.SaveChanges() > 0)
                    {
                        return(dbModel.Id);
                    }
                    else
                    {
                        return(0);
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    //_logger.Error(ex.ToString());
                    return(0);
                }
            }
        }
Ejemplo n.º 10
0
        public static int ThanhToanHopDong(string Id_HopDong, int Id_CuaHang, string Id_NhanVien, decimal SoTien, decimal TienPhat, string NoiDung,
                                           DateTime NgayBatDau, DateTime NgayKetThuc, string TenKhachHang)
        {
            using (var context = new TIT_Entities())
            {
                //update
                var item_update = context.HD_VayDuNoGiamDan.SingleOrDefault(x => x.HD_Id == Id_HopDong);
                item_update.TinhTrang      = "Thanh Lý";
                item_update.TienLaiDaDong += SoTien;
                var item_delete = context.ThongTinDongLais.Where(x => x.DaDong == 0 && x.HopDong_Id == Id_HopDong).ToArray();
                var start       = item_delete.First();
                foreach (var item in item_delete)
                {
                    context.ThongTinDongLais.Remove(item);
                }
                var item_donglai = new ThongTinDongLai()
                {
                    HopDong_Id      = Id_HopDong,
                    GhiChu          = "Thanh lý",
                    DaDong          = 1,
                    NgayBatDau      = start.NgayBatDau,
                    NgayKetThuc     = NgayKetThuc,
                    NgayDongLai     = DateTime.Now,
                    NhanVienThuTien = Id_NhanVien,
                    TienLai         = SoTien,
                    SoTienDaDong    = SoTien,
                    TienKhac        = TienPhat,
                    SoNgay          = 0
                };
                context.ThongTinDongLais.Add(item_donglai);

                decimal QuyTienMat           = 0;
                var     lastestLichSuThaoTac = context.LichSuThaoTacs.Where(x => x.Id_CuaHang == Id_CuaHang).OrderByDescending(p => p.Id).FirstOrDefault();
                if (lastestLichSuThaoTac != null)
                {
                    QuyTienMat = lastestLichSuThaoTac.TongCongTon;
                }

                QuyTienMat += SoTien;
                var model = new LichSuThaoTac()
                {
                    Id_CuaHang         = Id_CuaHang,
                    Id_HopDong         = Id_HopDong,
                    Id_NhanVienThaoTac = Id_NhanVien,
                    NgayThaoTac        = DateTime.Now,
                    NoiDung            = "Thanh lý hợp đồng",
                    SoTien             = SoTien,
                    ThuTien            = 1,
                    TongCongTon        = QuyTienMat,
                    TenKhachHang       = TenKhachHang
                };
                context.LichSuThaoTacs.Add(model);
                if (TienPhat > 0)
                {
                    QuyTienMat += TienPhat;
                    var model2 = new LichSuThaoTac()
                    {
                        Id_CuaHang         = Id_CuaHang,
                        Id_HopDong         = Id_HopDong,
                        Id_NhanVienThaoTac = Id_NhanVien,
                        NgayThaoTac        = DateTime.Now,
                        NoiDung            = NoiDung,
                        SoTien             = TienPhat,
                        ThuTien            = 1,
                        TongCongTon        = QuyTienMat,
                        TenKhachHang       = TenKhachHang
                    };
                    context.LichSuThaoTacs.Add(model2);
                }


                var baocao = context.BaoCaoHangNgays.OrderByDescending(x => x.Ngay).FirstOrDefault(x => x.Id_CuaHang == Id_CuaHang);
                if (baocao != null)
                {
                    if (baocao.Ngay == DateTime.Now.Date)
                    {
                        baocao.SoTienVonConLai          += SoTien + TienPhat;
                        baocao.TongThu                  += SoTien + TienPhat;
                        baocao.TongThuHopDongChoVayDNGD += SoTien + TienPhat;
                    }
                    else
                    {
                        var bcModel = new BaoCaoHangNgay
                        {
                            Id_CuaHang       = Id_CuaHang,
                            Ngay             = DateTime.Now.Date,
                            SoTienVonDauNgay = baocao.SoTienVonConLai,
                            SoTienVonConLai  = baocao.SoTienVonConLai,
                        };
                        bcModel.SoTienVonConLai          += SoTien + TienPhat;
                        bcModel.TongThu                  += SoTien + TienPhat;
                        bcModel.TongThuHopDongChoVayDNGD += SoTien + TienPhat;

                        context.BaoCaoHangNgays.Add(bcModel);
                    }
                }
                else
                {
                    var bcModel = new BaoCaoHangNgay
                    {
                        Id_CuaHang = Id_CuaHang,
                        Ngay       = DateTime.Now.Date
                    };
                    bcModel.SoTienVonConLai          += SoTien + TienPhat;
                    bcModel.TongThu                  += SoTien + TienPhat;
                    bcModel.TongThuHopDongChoVayDNGD += SoTien + TienPhat;
                    context.BaoCaoHangNgays.Add(bcModel);
                }



                try
                {
                    if (context.SaveChanges() > 0)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    //_logger.Error(ex.ToString());
                    return(0);
                }
            }
        }
Ejemplo n.º 11
0
        public static int DongTienLai(string hD_Id, List <ChoVayDNGD_ThongTinChiTietDongTienLaiModel> update, string Id_NhanVien, decimal SoTien, decimal TienPhat, string Ghichu, string GhiChuTong, string TenKhachHang)
        {
            using (var context = new TIT_Entities())
            {
                decimal  TienDongHangThang = update[0].TienLai;
                decimal  SoTienDong        = SoTien;
                int      IDX                 = 0;
                DateTime NgayCuoiCung        = DateTime.MinValue;
                DateTime NgayDongLaiCuoiCung = DateTime.MinValue;
                int      SoKyDongLaiBoSung   = 0;
                bool     IsTienPhat          = true;
                while (SoTienDong > 0 && IDX < update.Count)
                {
                    if (SoTienDong + update[IDX].SoTienDaDong < TienDongHangThang)
                    {
                        int ID          = update[IDX].ID;
                        var item_update = context.ThongTinDongLais.SingleOrDefault(x => x.Id == ID);
                        item_update.SoTienDaDong = SoTienDong + update[IDX].SoTienDaDong;
                        NgayCuoiCung             = item_update.NgayKetThuc;
                        SoTienDong = SoTienDong + update[IDX].SoTienDaDong - TienDongHangThang;
                        if (IsTienPhat)
                        {
                            item_update.TienKhac += TienPhat;
                            item_update.GhiChu    = Ghichu;
                            IsTienPhat            = false;
                        }
                    }
                    else
                    {
                        int ID = update[IDX].ID;
                        SoTienDong = SoTienDong + update[IDX].SoTienDaDong - TienDongHangThang;
                        var item_update = context.ThongTinDongLais.SingleOrDefault(x => x.Id == ID);
                        item_update.SoTienDaDong = TienDongHangThang;
                        NgayDongLaiCuoiCung      = item_update.NgayKetThuc;
                        item_update.DaDong       = 1;
                        SoKyDongLaiBoSung++;
                        if (IsTienPhat)
                        {
                            item_update.TienKhac += TienPhat;
                            item_update.GhiChu    = Ghichu;
                            IsTienPhat            = false;
                        }
                    }
                    IDX++;
                }
                if (IsTienPhat)
                {
                    int ID          = update[IDX].ID;
                    var item_update = context.ThongTinDongLais.SingleOrDefault(x => x.Id == ID);
                    item_update.TienKhac = TienPhat;
                    item_update.GhiChu   = Ghichu;
                    IsTienPhat           = false;
                }



                ////update
                //var item_update = context.ThongTinDongLais.SingleOrDefault(x => x.Id == update.ID);
                //item_update.DaDong = update.DaDong;
                //item_update.TienKhac = update.TienKhac;
                //item_update.NgayDongLai = DateTime.Now;

                var hd_update = context.HD_VayDuNoGiamDan.SingleOrDefault(x => x.HD_Id == hD_Id);
                if (NgayDongLaiCuoiCung != DateTime.MinValue)
                {
                    hd_update.NgayCuoiCungDongTien = NgayDongLaiCuoiCung;
                }
                hd_update.TienLaiDaDong += SoTien;
                hd_update.GhiChu         = GhiChuTong;
                //int desMonth = hd_update.NgayCuoiCungDongTien.Value.Month;
                //int srcMonth = hd_update.NgayVay.Month;
                //int totalMonth = desMonth > srcMonth ? desMonth - srcMonth : desMonth + 13 - srcMonth;
                //if (totalMonth - 1 >= hd_update.ThoiHanVay)
                //    hd_update.TinhTrang = "Thanh Lý";
                if (SoKyDongLaiBoSung == update.Count)
                {
                    hd_update.TinhTrang = "Thanh Lý";
                }


                decimal QuyTienMat           = 0;
                var     lastestLichSuThaoTac = context.LichSuThaoTacs.Where(x => x.Id_CuaHang == hd_update.CuaHang_Id).OrderByDescending(p => p.Id).FirstOrDefault();
                if (lastestLichSuThaoTac != null)
                {
                    QuyTienMat = lastestLichSuThaoTac.TongCongTon;
                }
                QuyTienMat = QuyTienMat + SoTien;
                var lichsu = new LichSuThaoTac()
                {
                    Id_CuaHang         = hd_update.CuaHang_Id,
                    Id_HopDong         = hd_update.HD_Id,
                    Id_NhanVienThaoTac = Id_NhanVien,
                    NgayThaoTac        = DateTime.Now,
                    NoiDung            = "Đóng lãi",
                    SoTien             = SoTien,
                    ThuTien            = 1,
                    TongCongTon        = QuyTienMat,
                    TenKhachHang       = TenKhachHang
                };

                context.LichSuThaoTacs.Add(lichsu);
                if (TienPhat > 0)
                {
                    QuyTienMat = QuyTienMat + TienPhat;
                    var lichsu2 = new LichSuThaoTac()
                    {
                        Id_CuaHang         = hd_update.CuaHang_Id,
                        Id_HopDong         = hd_update.HD_Id,
                        Id_NhanVienThaoTac = Id_NhanVien,
                        NgayThaoTac        = DateTime.Now,
                        NoiDung            = "Tiền khác",
                        SoTien             = TienPhat,
                        ThuTien            = 1,
                        TongCongTon        = QuyTienMat,
                        TenKhachHang       = TenKhachHang
                    };
                    context.LichSuThaoTacs.Add(lichsu2);
                }

                var baocao = context.BaoCaoHangNgays.OrderByDescending(x => x.Ngay).FirstOrDefault(x => x.Id_CuaHang == hd_update.CuaHang_Id);
                if (baocao != null)
                {
                    if (baocao.Ngay == DateTime.Now.Date)
                    {
                        baocao.SoTienVonConLai          += SoTien;
                        baocao.TongThu                  += SoTien;
                        baocao.TongThuHopDongChoVayDNGD += SoTien;
                    }
                    else
                    {
                        var bcModel = new BaoCaoHangNgay
                        {
                            Id_CuaHang       = hd_update.CuaHang_Id,
                            Ngay             = DateTime.Now.Date,
                            SoTienVonDauNgay = baocao.SoTienVonConLai,
                            SoTienVonConLai  = baocao.SoTienVonConLai,
                        };
                        bcModel.SoTienVonConLai          += SoTien;
                        bcModel.TongThu                  += SoTien;
                        bcModel.TongThuHopDongChoVayDNGD += SoTien;

                        context.BaoCaoHangNgays.Add(bcModel);
                    }
                }
                else
                {
                    var bcModel = new BaoCaoHangNgay
                    {
                        Id_CuaHang = hd_update.CuaHang_Id,
                        Ngay       = DateTime.Now.Date
                    };
                    bcModel.SoTienVonConLai          += SoTien;
                    bcModel.TongThu                  += SoTien;
                    bcModel.TongThuHopDongChoVayDNGD += SoTien;
                    context.BaoCaoHangNgays.Add(bcModel);
                }



                try
                {
                    if (context.SaveChanges() > 0)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    //_logger.Error(ex.ToString());
                    return(0);
                }
            }
        }
Ejemplo n.º 12
0
        public static int HuyHopDong(string id_HopDong, string ghiChu, decimal soTienThuLai, string Id_NhanVien, string TenKhachHang)
        {
            using (var context = new TIT_Entities())
            {
                //update
                var item_update = context.HD_VayDuNoGiamDan.SingleOrDefault(x => x.HD_Id == id_HopDong);
                item_update.TinhTrang = "Hủy hợp đồng";

                var item_delete = context.ThongTinDongLais.Where(x => x.HopDong_Id == id_HopDong).ToArray();
                foreach (var item in item_delete)
                {
                    context.ThongTinDongLais.Remove(item);
                }

                decimal QuyTienMat           = 0;
                var     lastestLichSuThaoTac = context.LichSuThaoTacs.Where(x => x.Id_CuaHang == item_update.CuaHang_Id).OrderByDescending(p => p.Id).FirstOrDefault();
                if (lastestLichSuThaoTac != null)
                {
                    QuyTienMat = lastestLichSuThaoTac.TongCongTon;
                }

                QuyTienMat += soTienThuLai;
                var model = new LichSuThaoTac()
                {
                    Id_CuaHang         = item_update.CuaHang_Id,
                    Id_HopDong         = id_HopDong,
                    Id_NhanVienThaoTac = Id_NhanVien,
                    NgayThaoTac        = DateTime.Now,
                    NoiDung            = "Hủy hợp đồng: " + ghiChu,
                    SoTien             = soTienThuLai,
                    ThuTien            = 1,
                    TongCongTon        = QuyTienMat,
                    TenKhachHang       = TenKhachHang
                };
                context.LichSuThaoTacs.Add(model);



                var baocao = context.BaoCaoHangNgays.OrderByDescending(x => x.Ngay).FirstOrDefault(x => x.Id_CuaHang == item_update.CuaHang_Id);
                if (baocao != null)
                {
                    if (baocao.Ngay == DateTime.Now.Date)
                    {
                        baocao.SoTienVonConLai          += soTienThuLai;
                        baocao.TongThu                  += soTienThuLai;
                        baocao.TongThuHopDongChoVayDNGD += soTienThuLai;
                    }
                    else
                    {
                        var bcModel = new BaoCaoHangNgay
                        {
                            Id_CuaHang       = item_update.CuaHang_Id,
                            Ngay             = DateTime.Now.Date,
                            SoTienVonDauNgay = baocao.SoTienVonConLai,
                            SoTienVonConLai  = baocao.SoTienVonConLai,
                        };
                        bcModel.SoTienVonConLai          += soTienThuLai;
                        bcModel.TongThu                  += soTienThuLai;
                        bcModel.TongThuHopDongChoVayDNGD += soTienThuLai;

                        context.BaoCaoHangNgays.Add(bcModel);
                    }
                }
                else
                {
                    var bcModel = new BaoCaoHangNgay
                    {
                        Id_CuaHang = item_update.CuaHang_Id,
                        Ngay       = DateTime.Now.Date
                    };
                    bcModel.SoTienVonConLai          += soTienThuLai;
                    bcModel.TongThu                  += soTienThuLai;
                    bcModel.TongThuHopDongChoVayDNGD += soTienThuLai;
                    context.BaoCaoHangNgays.Add(bcModel);
                }
                try
                {
                    if (context.SaveChanges() > 0)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    //_logger.Error(ex.ToString());
                    return(0);
                }
            }
        }
Ejemplo n.º 13
0
        internal CamDoGridDataModel InsertCamDo(CamDoInsertNewDataModel model)
        {
            var dbModel = new HD_CamDo
            {
                CuaHang_Id = model.Id_CuaHang,
                MaTaiSan   = model.LoaiTaiSan,
                TaiSan     = model.TenTaiSan,
                NgayCuoiCungDongTienLai = model.NgayVay,
                HinhThucLai             = model.HinhThucLai,
                GhiChu             = model.GhiChu,
                KyLai              = model.KyLai,
                Lai                = model.LaiPhi,
                SoTienCam          = model.SoTien,
                NgayCam            = model.NgayVay,
                NgayThanhLyHopDong = null,
                NhanVien_Id        = _userId,
                TinhTrang          = "Đang cầm",
                KhachHang_CMND     = model.CMND,
                KhachHang_HoTen    = model.TenKhachHang,
                NgayTao            = DateTime.Now,
            };

            using (var context = new TIT_Entities())
            {
                context.HD_CamDo.Add(dbModel);

                try
                {
                    if (context.SaveChanges() > 0)
                    {
                        var dbDongLai = new ThongTinDongLai()
                        {
                            HopDong_Id  = dbModel.HD_CamDo_Id,
                            TienLai     = HinhThucLaiHelper.TinhLaiMotNgay(model.HinhThucLai, model.SoTien, model.LaiPhi) * model.KyLai,
                            TienKhac    = 0,
                            DaDong      = 0,
                            NgayBatDau  = model.NgayVay.Date,
                            NgayKetThuc = model.NgayVay.Date.Add(new TimeSpan(model.KyLai - 1, 0, 0, 0)),
                            NgayDongLai = DateTime.Now
                        };

                        CapNhatBaoCao_Chi(context, model.Id_CuaHang, model.SoTien);

                        decimal QuyTienMat           = 0;
                        var     lastestLichSuThaoTac = context.LichSuThaoTacs.Where(x => x.Id_CuaHang == model.Id_CuaHang).OrderByDescending(p => p.Id).FirstOrDefault();
                        if (lastestLichSuThaoTac != null)
                        {
                            QuyTienMat = lastestLichSuThaoTac.TongCongTon;
                        }

                        var dbModel2 = new LichSuThaoTac()
                        {
                            Id_CuaHang         = model.Id_CuaHang,
                            Id_HopDong         = dbModel.HD_CamDo_Id,
                            Id_NhanVienThaoTac = _userId,
                            NgayThaoTac        = DateTime.Now,
                            NoiDung            = "Tạo hợp đồng",
                            SoTien             = model.SoTien,
                            ThuTien            = 0,
                            TongCongTon        = QuyTienMat - model.SoTien,
                            TenKhachHang       = model.TenKhachHang
                        };
                        context.ThongTinDongLais.Add(dbDongLai);
                        context.LichSuThaoTacs.Add(dbModel2);
                        if (context.SaveChanges() > 0)
                        {
                            return(new CamDoGridDataModel()
                            {
                                HopDong_Id = dbModel.HD_CamDo_Id,
                                SoTien = dbModel.SoTienCam,
                                LaiDaDong = "0",
                                LaiPhiDenHomNay = "0",
                                NgayPhaiDongLai = dbModel.NgayCuoiCungDongTienLai.Value.AddDays(1),
                                NgayTaoHopDong = dbModel.NgayCam,
                                NoCu = "0",
                                TaiSan = dbModel.TaiSan,
                                TinhTrang = dbModel.TinhTrang
                            });
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                    //_logger.Error(ex.ToString());
                    return(null);
                }
            }
        }