/// <summary>
        /// constructor for the first dept receipt
        /// </summary>
        /// <param name="receipt"></param>
        public PhieuThuTienNo_Form(PHIEUBANHANG receipt)
        {
            InitializeComponent();
            this.bulKhachHang   = new BUL_KhachHang();
            this.bulDeptReceipt = new BUL_PhieuThuTienNo();
            this.bulBangThamSo  = new BUL_BangThamSo();
            this.receipt        = receipt;

            // set defaul value for date time picker : system current date
            this.dateTimePickerNgayLap.DateTime = DateTime.Now.Date;
            this.dateTimePickerNgayLap.ReadOnly = true;
            this.dateTimePickerNgayTra.DateTime = DateTime.Now.Date;
            this.previousDeptRecepit            = null;
            // indicate that, this is the first dept
            this.isTheFirstDept = true;
            // this is the first decpt receipt
            this.textEditMaPhieuBanHang.Text = receipt.SoPhieuBH.ToString();
            this.textEditTenKhachHang.Text   = this.bulKhachHang.GetKhachhangById(receipt.MaKH).TenKH;
            this.textEditMaKhachHang.Text    = receipt.MaKH.ToString();

            // the first dept
            this.textEditSoTienNo.Text = receipt.TongTien.ToString();
            this.labelControlRecommendedInput.Visible = true;
            decimal ACCEPTABLE_FIRST_PREPAID_PERCENTAGE = Convert.ToDecimal(this.bulBangThamSo.getValueByArgument("TienTraToiThieu"));
            decimal minimumAmout = decimal.Multiply(ACCEPTABLE_FIRST_PREPAID_PERCENTAGE, receipt.TongTien);

            this.labelControlRecommendedInput.Text = "(Tối thiểu: " + Math.Round(minimumAmout) + ")";
        }
示例#2
0
        private void lậpPhiếuNợToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // get the focused row
            if (this.gridViewDanhSachPhieuBanHang.DataRowCount == 0)
            {
                return;
            }
            PHIEUBANHANG selectedReceipt = (PHIEUBANHANG)this.gridViewDanhSachPhieuBanHang.GetRow(this.gridViewDanhSachPhieuBanHang.FocusedRowHandle);

            // check if this recept has dept recepit or not ?
            if (this.bulPhieuBanHang.hasDebtReceipts(selectedReceipt.SoPhieuBH) == false)
            {
                // create the first dept receipt
                PhieuThuTienNo_Form firstDeptReceiptForm = new PhieuThuTienNo_Form(selectedReceipt);
                firstDeptReceiptForm.refreshDebtReceiptDataCallback = new PhieuThuTienNo_Form.RefreshDebtReceiptData(this.refreshDebtReceiptData);
                firstDeptReceiptForm.ShowDialog();
            }
            else // otherwise
            {
                // get the last dept recpeit
                PHIEUTHUTIENNO lastDeptReceip = this.bulPhieuBanHang.findTheLastDeiptReceiptFromReceiptId(selectedReceipt.SoPhieuBH);
                // check if user paid for all the depts
                if (decimal.Equals(lastDeptReceip.SoTienConLai, decimal.Zero))
                {
                    MessageBox.Show("Phiếu bán hàng này đã được trả nợ hết !", ErrorMessage.ERROR_MESSARE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                // start to show the form
                PhieuThuTienNo_Form deptReceiptForm = new PhieuThuTienNo_Form(lastDeptReceip);
                deptReceiptForm.refreshDebtReceiptDataCallback = new PhieuThuTienNo_Form.RefreshDebtReceiptData(this.refreshDebtReceiptData);
                deptReceiptForm.ShowDialog();
            }
        }
示例#3
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            string         tiennoID = txtMaPhieu.Text;
            PHIEUTHUTIENNO tienno   = db.PHIEUTHUTIENNOes.Where(p => p.MaPhieu == tiennoID).SingleOrDefault();

            if (tienno != null)
            {
                MessageBox.Show("Mã thu nợ đã tồn tại");
                return;
            }
            if (tienno == null)
            {
                PHIEUTHUTIENNO p = new PHIEUTHUTIENNO()
                {
                    MaPhieu    = tiennoID,
                    MaDaiLy    = cbDaiLy.Text,
                    MaThuTien  = txtMaThuTien.Text,
                    SoTienThu  = int.Parse(txtSoTienThu.Text),
                    TienConLai = int.Parse(txtTienConLai.Text),
                };
                db.PHIEUTHUTIENNOes.Add(p);
                db.SaveChanges();
                LoadDataThuTienNo();
                MessageBox.Show("Thêm phiếu thu tiền nợ thành công");
            }
        }
示例#4
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            string         tiennoID = txtMaPhieu.Text;
            PHIEUTHUTIENNO tienno   = db.PHIEUTHUTIENNOes.Where(p => p.MaPhieu == tiennoID).SingleOrDefault();

            if (tienno != null)
            {
                db.PHIEUTHUTIENNOes.Remove(tienno);
                db.SaveChanges();
                LoadDataThuTienNo();
                MessageBox.Show("Xoá phiếu thu tiền thành công");
            }
        }
示例#5
0
        private void btnSua_Click(object sender, EventArgs e)
        {
            string         tiennoID = txtMaPhieu.Text;
            PHIEUTHUTIENNO tienno   = db.PHIEUTHUTIENNOes.Where(p => p.MaPhieu == tiennoID).SingleOrDefault();

            if (tienno == null)
            {
                MessageBox.Show("Mã thu tiền nợ tồn tại");
                return;
            }
            if (tienno != null)
            {
                tienno.MaPhieu    = tiennoID;
                tienno.MaDaiLy    = cbDaiLy.Text;
                tienno.MaThuTien  = txtMaThuTien.Text;
                tienno.SoTienThu  = int.Parse(txtSoTienThu.Text);
                tienno.TienConLai = int.Parse(txtTienConLai.Text);
                db.SaveChanges();
                LoadDataThuTienNo();
                MessageBox.Show("Cập nhật phiếu thu tiền thành công");
            }
        }
        public PhieuThuTienNo_Form(PHIEUTHUTIENNO previousDeptReceipt)
        {
            InitializeComponent();
            this.bulKhachHang        = new BUL_KhachHang();
            this.bulDeptReceipt      = new BUL_PhieuThuTienNo();
            this.previousDeptRecepit = previousDeptReceipt;
            // indicate that, this is NOT the first dept
            this.isTheFirstDept = false;
            // this is the first decpt receipt
            this.textEditMaPhieuBanHang.Text = this.previousDeptRecepit.SoPhieuBH.ToString();

            this.receipt = new BUL_PhieuBanHang().findReceiptById(this.previousDeptRecepit.SoPhieuBH);
            this.textEditTenKhachHang.Text = this.bulKhachHang.GetKhachhangById(this.receipt.MaKH).TenKH;
            this.textEditMaKhachHang.Text  = this.receipt.MaKH.ToString();

            // the first dept
            this.textEditSoTienNo.Text = this.previousDeptRecepit.SoTienConLai.ToString();

            // set defaul value for date time picker : system current date
            this.dateTimePickerNgayLap.DateTime       = DateTime.Now.Date;
            this.dateTimePickerNgayLap.ReadOnly       = true;
            this.dateTimePickerNgayTra.DateTime       = DateTime.Now.Date;
            this.labelControlRecommendedInput.Visible = false;
        }
        /// <summary>
        /// Save the dept receipt into database.
        /// Here including checks to make sure all values are valid before being saved
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void simpleButtonLuu_Click(object sender, EventArgs e)
        {
            // make sure that all input is valid
            if (string.IsNullOrEmpty(this.textEditSoTienTra.Text) ||
                string.IsNullOrEmpty(this.textEditConLai.Text) ||
                this.dateTimePickerNgayLap.DateTime == null ||
                this.dateTimePickerNgayTra.DateTime == null)
            {
                MessageBox.Show(ErrorMessage.CLIENT_INVALID_INPUT_MESSAGE, ErrorMessage.ERROR_MESSARE_TITLE, MessageBoxButtons.OK
                                , MessageBoxIcon.Error);
                return;
            }


            /// If any values are valid  ////

            decimal frequenterPrepay = decimal.Parse(this.textEditSoTienTra.Text.Trim());
            decimal deptAmount       = decimal.Parse(this.textEditSoTienNo.Text.Trim());

            if (this.isTheFirstDept) // is the first dept recepit
            {
                // get minimun percentage for the first repayment
                decimal ACCEPTABLE_FIRST_PREPAID_PERCENTAGE = Convert.ToDecimal(this.bulBangThamSo.getValueByArgument("TienTraToiThieu"));
                if (decimal.Compare(frequenterPrepay, decimal.Multiply(deptAmount, ACCEPTABLE_FIRST_PREPAID_PERCENTAGE)) < 0)
                {
                    MessageBox.Show("Số tiền trả trước không được nhỏ hơn" + ACCEPTABLE_FIRST_PREPAID_PERCENTAGE + "% tổng tiền phiếu bán.", ErrorMessage.ERROR_MESSARE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else // start to save into database
                {
                    PHIEUTHUTIENNO newDeptReceipt = new PHIEUTHUTIENNO
                    {
                        SoPhieuBH    = this.receipt.SoPhieuBH,
                        NgayLap      = this.dateTimePickerNgayLap.DateTime.Date,
                        NgayTra      = this.dateTimePickerNgayTra.DateTime.Date,
                        MaNV         = UserAccess.Instance.GetUserId,
                        SoTienNo     = deptAmount,
                        SoTienTra    = frequenterPrepay,
                        SoTienConLai = decimal.Subtract(deptAmount, frequenterPrepay)
                    };

                    // start to save into database
                    this.bulDeptReceipt.add(newDeptReceipt);
                    this.refreshDebtReceiptDataCallback(); // delegate to main form to refresh data
                    // PhieuThuTienNo recentSavedDeptReceipt = this.bulDeptReceipt
                    if (decimal.Compare(newDeptReceipt.SoTienConLai, decimal.Zero) == 0)
                    {
                        if (MessageBox.Show("Đã lưu phiếu thu nợ . Phiếu nợ đã được trả đủ !", NotificationMessage.MESSAGE_TITLE,
                                            MessageBoxButtons.OK, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.OK)
                        {
                            this.Close();
                        }
                    }
                    else if (MessageBox.Show("Đã lưu phiếu thu nợ .Ngày hẹn trả : " + this.dateTimePickerNgayTra.DateTime.ToShortDateString(), NotificationMessage.MESSAGE_TITLE,
                                             MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        this.Close();
                    }
                }
            }
            else // NOT the first dept recepit
            {
                PHIEUTHUTIENNO newDeptReceipt = new PHIEUTHUTIENNO
                {
                    SoPhieuBH    = this.previousDeptRecepit.SoPhieuBH,
                    NgayLap      = this.dateTimePickerNgayLap.DateTime.Date,
                    NgayTra      = this.dateTimePickerNgayTra.DateTime.Date,
                    MaNV         = UserAccess.Instance.GetUserId,
                    SoTienNo     = deptAmount,
                    SoTienTra    = frequenterPrepay,
                    SoTienConLai = decimal.Subtract(deptAmount, frequenterPrepay)
                };
                // start to save into database
                this.bulDeptReceipt.add(newDeptReceipt);
                this.refreshDebtReceiptDataCallback(); // delegate to main form to refresh data
                if (decimal.Compare(newDeptReceipt.SoTienConLai, decimal.Zero) == 0)
                {
                    if (MessageBox.Show("Đã lưu phiếu thu nợ . Phiếu nợ đã được trả đủ !", NotificationMessage.MESSAGE_TITLE,
                                        MessageBoxButtons.OK, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.OK)
                    {
                        this.Close();
                    }
                }
                else if (MessageBox.Show("Đã lưu phiếu thu nợ .Ngày hẹn trả : " + this.dateTimePickerNgayTra.DateTime.ToShortDateString(), NotificationMessage.MESSAGE_TITLE,
                                         MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    this.Close();
                }
            }
        }