예제 #1
0
        public bool Add_Paid_Money(historyPaid hisPaid, int action_status, user user)
        {
            bool check = false;

            try
            {
                hisPaid.CreatedBy = user.id;
                hisPaid.UpdatedBy = user.id;
                _db.historyPaids.Add(hisPaid);
                _db.SaveChanges();
                check = true;
            }
            catch (Exception)
            {
                return(check);
            }
            return(check);
        }
예제 #2
0
        public int Get_After_Date(int IdCustomer) //lấy số ngày chậm lãi
        {
            _db = new QLKHEntities();
            customer Customer = new customer();

            Customer = (from data in _db.customers
                        where data.id == IdCustomer && data.Status == true
                        select data).FirstOrDefault();
            historyPaid Last_Paid = new historyPaid();

            Last_Paid = (from data in _db.historyPaids
                         where data.CustomerId == IdCustomer && data.TypePaid == "1"
                         orderby data.PaidDate descending
                         select data).FirstOrDefault();
            if (Last_Paid != null)
            {
                return((DateTime.Now - Last_Paid.PaidDate).Days + 1 > Customer.cycle ? (DateTime.Now - Last_Paid.PaidDate).Days + 1 - Customer.cycle : 0);
            }
            return((DateTime.Now - Customer.CreatedAt).Days + 1 > Customer.cycle ? (DateTime.Now - Customer.CreatedAt).Days + 1 - Customer.cycle : 0);
        }
예제 #3
0
        public double Get_Tien_Lai(int IdCustomer)
        {
            _db = new QLKHEntities();
            historyPaid history  = new historyPaid();
            customer    customer = new customer();

            try
            {
                history = (from data in _db.historyPaids              // lấy bản ghi trả nợ gần nhất
                           join data_customer in _db.customers
                           on data.CustomerId equals data_customer.id
                           where data.CustomerId == IdCustomer && data.TypePaid == "1" && data_customer.Status == true
                           orderby data.PaidDate descending
                           select data).FirstOrDefault();


                customer = (from data in _db.customers
                            where data.id == IdCustomer
                            select data).FirstOrDefault();

                DateTime start_date = customer.CreatedAt;
                if (history != null)
                {
                    start_date = history.PaidDate;
                }

                List <historyInterestRate> lst_lai_suat = new List <historyInterestRate>();
                lst_lai_suat = (from data in _db.historyInterestRates
                                orderby data.StartDate ascending
                                select data).ToList();

                double tien_lai = 0;
                if (history == null || history.PaidDate.Date.ToString() != DateTime.Now.Date.ToString())
                {
                    int so_tien_vay = customer.Money;

                    int demngay = (Convert.ToDateTime(DateTime.Now) - Convert.ToDateTime(start_date)).Days + 1;

                    for (int i = 0; i < demngay; i++)
                    {
                        DateTime date_start = start_date.AddDays(i);//ngày để tính số tiền gốc đang nợ
                        double   tien_goc   = get_tien_goc_by_day(date_start, IdCustomer);

                        if (date_start >= lst_lai_suat[lst_lai_suat.Count - 1].StartDate)
                        {
                            tien_lai += tien_goc * lst_lai_suat[lst_lai_suat.Count - 1].Percents * 0.01;
                        }
                        else
                        {
                            for (int j = 0; j < (lst_lai_suat.Count - 1); j++)
                            {
                                if (date_start >= lst_lai_suat[j].StartDate && date_start < lst_lai_suat[j + 1].StartDate)
                                {
                                    tien_lai += tien_goc * lst_lai_suat[j].Percents * 0.01;
                                }
                            }
                        }
                    }
                }


                // Util.Show_Message_Notification(Message.msg_notification, dateRange.ToString());
                return(tien_lai);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #4
0
        private void btn_thanh_toan_Click(object sender, EventArgs e)
        {
            bool check = false, checkTienLai = false, checkTienGoc = false;

            try
            {
                if (CheckValidate())
                {
                    bool confirmPaid = Util.Show_Message_YesNo(Message.msg_notification, "Chắc chắn thanh toán ?");
                    if (confirmPaid)
                    {
                        if (_isTienlai)
                        {
                            historyPaid paid = new historyPaid();
                            paid.Money      = Convert.ToInt32(txt_money_lai.Text.ToString().Trim().Replace(",", ""));
                            paid.TypePaid   = "1";
                            paid.CustomerId = idCustomer;
                            paid.CreatedAt  = DateTime.Now;
                            paid.UpdatedAt  = DateTime.Now;
                            paid.UpdatedBy  = _user.id;
                            paid.CreatedBy  = _user.id;
                            paid.Status     = true;
                            paid.PaidDate   = DateTime.Now;
                            checkTienLai    = DAL_LichSuTraTien.Add_Paid_Money(paid, Variable.action_status.is_add, _user);
                        }
                        if (_isTiengoc)
                        {
                            historyPaid paid = new historyPaid();
                            paid.Money      = Convert.ToInt32(txt_money.Text.ToString().Trim().Replace(",", ""));
                            paid.TypePaid   = "0";
                            paid.CustomerId = idCustomer;
                            paid.CreatedAt  = DateTime.Now;
                            paid.UpdatedAt  = DateTime.Now;
                            paid.UpdatedBy  = _user.id;
                            paid.CreatedBy  = _user.id;
                            paid.Status     = true;
                            paid.PaidDate   = DateTime.Now;
                            checkTienGoc    = DAL_LichSuTraTien.Add_Paid_Money(paid, Variable.action_status.is_add, _user);
                        }
                        if (_isTienlai && _isTiengoc)
                        {
                            if (checkTienGoc && checkTienLai)
                            {
                                check = true;
                            }
                        }
                        else if (_isTiengoc)
                        {
                            if (checkTienGoc)
                            {
                                check = true;
                            }
                        }
                        else if (_isTienlai)
                        {
                            if (checkTienLai)
                            {
                                check = true;
                            }
                        }
                        if (check)
                        {
                            Util.Show_Message_Notification(Message.msg_notification, "Thanh toán thành công !!!");
                            ((Form)this.TopLevelControl).Close();
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }