Ejemplo n.º 1
0
        void Accept()
        {
            try
            {
                if (txtFeePay.Text == "")
                {
                    NoteBox.Show("Số tiền thanh toán không được để trống");
                    txtFeePay.Focus();
                    return;
                }

                if (dpPay_Date.Text == "")
                {
                    NoteBox.Show("Ngày thanh toán không được để trống", "", NoteBoxLevel.Error);
                    dpPay_Date.Focus();
                    return;
                }
                if (CheckValidate.CheckValidDate(dpPay_Date.Text) == false)
                {
                    NoteBox.Show("Ngày thanh toán không đúng định dạng", "", NoteBoxLevel.Error);
                    dpPay_Date.Focus();
                    return;
                }

                Fees_Revenue_Info _Fees_Revenue_Info = new Fees_Revenue_Info();
                _Fees_Revenue_Info.Fee_Id       = c_Fees_MustPay.Fee_Id;
                _Fees_Revenue_Info.Pay_Date     = Common.ConvertData.ConvertString2Date(dpPay_Date.Text);
                _Fees_Revenue_Info.Fee          = Convert.ToDecimal(txtFeePay.Text);
                _Fees_Revenue_Info.Debit_Amount = c_Fees_MustPay.Fee_Expected - _Fees_Revenue_Info.Fee;
                _Fees_Revenue_Info.Pay_Status   = (decimal)Enum_Fee_Status.Payed;

                MessageBoxResult result = NoteBox.Show("Bạn có muốn thanh toán phí môi giới cho hợp đồng này hay không?", "Thông báo", NoteBoxLevel.Question);
                if (MessageBoxResult.Yes != result)
                {
                    return;
                }

                if (_Fees_Revenue_Controller.Fees_Revenue_Update(_Fees_Revenue_Info) == false)
                {
                    NoteBox.Show("Lỗi thanh toán", "", NoteBoxLevel.Error);
                    return;
                }

                Contract_Info _Contract_Info = c_Contract_Info;

                if (c_index == c_lst_Fee_All.Count - 1)
                {
                    _Contract_Info.Fee_Status = (decimal)Enum_Fee_Status.Payed;
                }
                else
                {
                    _Contract_Info.Fee_Status = (decimal)Enum_Fee_Status.No_Pay;
                }

                if (_Contract_Controller.Contract_Update(c_Contract_Info.Contract_Id, _Contract_Info) == false)
                {
                    NoteBox.Show("Lỗi cập nhật hợp đồng cho thuê nhà", "", NoteBoxLevel.Error);
                    return;
                }

                NoteBox.Show("Thanh toán phí thành công");
                c_ok = true;
                this.Close();
            }
            catch (Exception ex)
            {
                ErrorLog.log.Error(ex.ToString());
            }
        }
        void Accept()
        {
            try
            {
                if (Renter_CheckValidate() == false)
                {
                    return;
                }

                MessageBoxResult result = NoteBox.Show("Bạn có muốn cập nhật hợp đồng này hay không?", "Thông báo", NoteBoxLevel.Question);
                if (MessageBoxResult.Yes != result)
                {
                    return;
                }

                //Customer_Info _Customer_Info = Get_Customer_Info();

                //if (_Customer_Info == null)
                //{
                //    NoteBox.Show("Lỗi khởi tạo khách người thuê nhà", "", NoteBoxLevel.Error);
                //    return;
                //}

                //if (c_Customer_Controller.Customer_Update(c_Contract_Info.Object_Id, _Customer_Info) == false)
                //{
                //    NoteBox.Show("Lỗi cập nhật mới khách thuê nhà", "", NoteBoxLevel.Error);
                //    return;
                //}

                Contract_Info _Contract_Info = Get_Contract_Info();
                if (_Contract_Info == null)
                {
                    NoteBox.Show("Lỗi khởi tạo đối tượng hợp đồng thuê nhà", "", NoteBoxLevel.Error);
                    return;
                }

                if (_Contract_Controller.Contract_Update(c_Contract_Info.Contract_Id, _Contract_Info, c_Contract_Info) == false)
                {
                    NoteBox.Show("Lỗi cập nhật mới hợp đồng thuê nhà", "", NoteBoxLevel.Error);
                    return;
                }

                // nếu không phải là gia hạn hợp đồng thì mới xóa đi tạo lại
                if (c_lst_Fee_Extend.Count == 0)
                {
                    // nếu mà kỳ hạn hợp đồng thay đổi thì xóa đi tạo lại dữ liệu thu chi
                    _Fees_Revenue_Controller.Fees_Revenue_DeleteByContract(c_Contract_Info.Contract_Id);

                    #region Thanh toán bình thường
                    foreach (Fees_Revenue_Info _Fees_Revenue_Info in c_lst_Fee)
                    {
                        _Fees_Revenue_Info.Contract_Id = c_Contract_Info.Contract_Id;
                        _Fees_Revenue_Info.Object_Id   = c_Contract_Info.Object_Id;
                        _Fees_Revenue_Info.Object_Type = (decimal)Enum_Contract_Type.Tenant;
                        _Fees_Revenue_Info.Currency    = Convert.ToDecimal(cboCurrency.SelectedValue);

                        if (_Fees_Revenue_Info.Fee_Expected != Convert.ToDecimal(txtFee.Text))
                        {
                            _Fees_Revenue_Info.Fee_Expected = Convert.ToDecimal(txtFee.Text);
                        }

                        _Fees_Revenue_Info.Debit_Amount = _Fees_Revenue_Info.Fee_Expected - _Fees_Revenue_Info.Fee;

                        if (_Contract_Info.Currency == (decimal)Enum_Contract_Currency.USD)
                        {
                            _Fees_Revenue_Info.Fee_Vnd = Convert.ToDecimal(txtFee_Vnd.Text);
                        }
                        else
                        {
                            _Fees_Revenue_Info.Fee_Vnd = 0;
                        }

                        if (_Fees_Revenue_Info.Fee != 0)
                        {
                            _Fees_Revenue_Info.Pay_Status = (decimal)Enum_Fee_Status.Payed;
                        }

                        if (_Fees_Revenue_Controller.Fees_Revenue_Insert(_Fees_Revenue_Info) == false)
                        {
                            NoteBox.Show("Lỗi thanh toán", "", NoteBoxLevel.Error);
                            return;
                        }
                    }
                    #endregion
                }
                else
                {
                    #region Phí gia hạn hợp đồng

                    Extend_Contract_Info _Extend_Contract_Info = new Extend_Contract_Info();
                    _Extend_Contract_Info.Contract_Id = c_Contract_Info.Contract_Id;

                    _Extend_Contract_Info.Contract_FromDate = ConvertData.ConvertString2Date(dpFromDate_Extend.Text);
                    _Extend_Contract_Info.Contract_ToDate   = ConvertData.ConvertString2Date(dpToDate_Extend.Text);

                    _Extend_Contract_Info.Fee       = Convert.ToDecimal(txtFee_Extend.Text);
                    _Extend_Contract_Info.FeeOnePay = _Extend_Contract_Info.Fee;
                    _Extend_Contract_Info.Term      = 1;
                    _Extend_Contract_Info.Price     = 0;

                    bool _is_payed = true;
                    foreach (Fees_Revenue_Info _Fees_Revenue_Info in c_lst_Fee_Extend)
                    {
                        _Fees_Revenue_Info.Contract_Id = c_Contract_Info.Contract_Id;
                        _Fees_Revenue_Info.Object_Id   = c_Contract_Info.Object_Id;
                        _Fees_Revenue_Info.Object_Type = (decimal)Enum_Contract_Type.Tenant;
                        _Fees_Revenue_Info.Currency    = Convert.ToDecimal(cboCurrency.SelectedValue);

                        if (c_Contract_Info.Status == (decimal)Enum_Contract_Status.Het_Han)
                        {
                            _Fees_Revenue_Info.Is_Extend = c_max_number_extend + 1;
                        }
                        else
                        {
                            _Fees_Revenue_Info.Is_Extend = c_max_number_extend;
                        }

                        _Fees_Revenue_Info.Debit_Amount = _Fees_Revenue_Info.Fee_Expected - _Fees_Revenue_Info.Fee;

                        if (_Fees_Revenue_Info.Fee != 0)
                        {
                            _Fees_Revenue_Info.Pay_Status = (decimal)Enum_Fee_Status.Payed;
                        }
                        else
                        {
                            _is_payed = false;
                        }

                        if (_Contract_Info.Currency == (decimal)Enum_Contract_Currency.USD)
                        {
                            _Fees_Revenue_Info.Fee_Vnd = Convert.ToDecimal(txtFee_Vnd_Extend.Text);
                        }
                        else
                        {
                            _Fees_Revenue_Info.Fee_Vnd = 0;
                        }

                        if (_Fees_Revenue_Controller.Fees_Revenue_Insert(_Fees_Revenue_Info) == false)
                        {
                            NoteBox.Show("Lỗi thanh toán", "", NoteBoxLevel.Error);
                            return;
                        }
                    }

                    // lần đầu chuyển trạng thái hợp đồng
                    if (c_Extend_Contract_Info == null)
                    {
                        _Extend_Contract_Info.Extend_Date = DateTime.Now;
                        _Extend_Contract_Controller.Extend_Contract_Insert(_Extend_Contract_Info);
                    }
                    else
                    {
                        if (_is_payed == false)
                        {
                            _Extend_Contract_Info.Fee_Status = (decimal)Enum_Fee_Status.No_Pay;
                        }
                        else
                        {
                            _Extend_Contract_Info.Fee_Status = (decimal)Enum_Fee_Status.Payed;
                        }

                        // update lại thông tin về hợp đồng
                        _Extend_Contract_Info.Extend_Date = c_Extend_Contract_Info.Extend_Date;
                        _Extend_Contract_Controller.Extend_Contract_Update(_Extend_Contract_Info);
                    }

                    #endregion
                }

                c_id_insert = c_Contract_Info.Contract_Id;

                NoteBox.Show("Cập nhật dữ liệu thành công", "");
                this.Close();
            }
            catch (Exception ex)
            {
                ErrorLog.log.Error(ex.ToString());
            }
        }