Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <CTongHopCongNo> _datasource = new List <CTongHopCongNo>();
            var    include_THUNO = checkBoxTHUNO.Checked;
            string note          = "";
            var    kho           = long.Parse(comboBoxKHO.SelectedValue.ToString());
            var    _from         = dateTimePicker1.Value.Date;
            var    _to           = dateTimePicker2.Value.Date;

            BindingSource bs = new BindingSource();

            /* Tính tổng tiền, trả trước group theo MAKH */
            var _xh = (from xh in DataInstance.Instance().DBContext().XUAT_HANG
                       join kh in DataInstance.Instance().DBContext().KHACH_HANG on xh.MAKH equals kh.ID
                       where xh.MAKHO == kho
                       where xh.NGAY_XUAT >= _from && xh.NGAY_XUAT <= _to
                       group xh by new { xh.MAKH, kh.NAME } into g
                       select new CTongHopCongNo()
            {
                STT = g.Key.MAKH,
                MAKH = g.Key.MAKH,
                KHACHHANG = g.Key.NAME,
                TRATRUOC = g.Sum(u => u.TRA_TRUOC),
                THANHTIEN = g.Sum(u => u.THANH_TIEN),
                DATRA = 0,
                CONNO = g.Sum(u => u.THANH_TIEN - u.TRA_TRUOC)
            }
                       );

            int STT = 1;

            if (include_THUNO == false)
            {
                note = "KHÔNG TÍNH TIỀN LÃI";
                /* Có sử dụng dữ liệu thu nợ */
                /* Tính tổng lãi cho từng KH */
                foreach (CTongHopCongNo row in _xh)
                {
                    //double lai = 0;
                    double datra = 0;
                    /* Tính lãi cho tất cả những lần xuất hàng cho KH */
                    foreach (XUAT_HANG _row in (from _xh_ in DataInstance.Instance().DBContext().XUAT_HANG
                                                where _xh_.MAKHO == kho
                                                where _xh_.MAKH == row.MAKH
                                                select _xh_))
                    {
                        /* Không sử dụng dữ liệu từ thu nợ */
                        //lai += MXuatHang.GetLaiPhatSinh((int)_row.ID, _to);
                        datra += MChiTietThuNo.TraGocHH((int)_row.ID);
                    }
                    _datasource.Add(new CTongHopCongNo()
                    {
                        STT       = STT++,
                        KHACHHANG = row.KHACHHANG,
                        TRATRUOC  = row.TRATRUOC,
                        THANHTIEN = row.THANHTIEN,
                        DATRA     = (long)datra,
                        CONNO     = row.THANHTIEN - (long)datra - row.TRATRUOC
                    });
                }
            }
            else
            {
                note = "BAO GỒM TIỀN LÃI";
                /* Không sử dụng dữ liệu thu nợ*/
                /* Tính tổng lãi cho từng KH */
                foreach (CTongHopCongNo row in _xh)
                {
                    double lai   = 0;
                    double datra = 0;
                    foreach (XUAT_HANG _row in (from _xh_ in DataInstance.Instance().DBContext().XUAT_HANG
                                                where _xh_.MAKHO == kho
                                                where _xh_.MAKH == row.MAKH
                                                select _xh_))
                    {
                        lai   += MXuatHang.GetLai((int)_row.ID, _to);
                        datra += MChiTietThuNo.DaTraHH((int)_row.ID);
                    }
                    _datasource.Add(new CTongHopCongNo()
                    {
                        STT       = STT++,
                        KHACHHANG = row.KHACHHANG,
                        TRATRUOC  = row.TRATRUOC,
                        THANHTIEN = row.THANHTIEN + (long)lai,
                        DATRA     = (long)datra,
                        CONNO     = row.THANHTIEN - (long)datra - row.TRATRUOC + (long)lai
                    });
                }
            }
            bs.DataSource = _datasource;
            CrystalReportTONGHOPCONGNO rpt = new CrystalReportTONGHOPCONGNO();

            rpt.SetDataSource(bs);
            rpt.SetParameterValue("KHO", comboBoxKHO.Text);
            rpt.SetParameterValue("FROM", _from);
            rpt.SetParameterValue("TO", _to);
            rpt.SetParameterValue("COMP", ConstClass.COMPANY_NAME);
            rpt.SetParameterValue("NOTE", note);
            crystalReportViewer1.ReportSource = rpt;
            crystalReportViewer1.Zoom(150);
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <CCongNoKhachHang> _datasource = new List <CCongNoKhachHang>();
            string        note = "";
            BindingSource bs   = new BindingSource();
            long          MAKH = long.Parse(comboBox1.SelectedValue.ToString());
            DateTime      FROM = dateTimePickerFROM.Value.Date;
            DateTime      TO   = dateTimePickerTO.Value.Date;

            /* Lấy tất cả dữ liệu xuất hàng cho khách hàng này */
            /* Từ ngày đến ngày */
            IQueryable <CCongNoKhachHang> xuat_hang = (from _xh in DataInstance.Instance().DBContext().XUAT_HANG
                                                       join _kho in DataInstance.Instance().DBContext().KHOes on _xh.MAKHO equals _kho.ID
                                                       //join _hh in DataInstance.Instance().DBContext().HANG_HOA on _xh.MAHH equals _hh.ID
                                                       where _xh.MAKH == MAKH
                                                       where _xh.NGAY_XUAT >= FROM && _xh.NGAY_XUAT <= TO
                                                       orderby _xh.NGAY_XUAT ascending
                                                       select new CCongNoKhachHang
            {
                ID = (int)_xh.ID,
                NGAY = _xh.NGAY_XUAT.Value,
                KHO = _kho.NAME,
                HANGHOAID = _xh.MAHH,
                //HANGHOA = _hh.NAME,
                SOLUONG = _xh.SO_LUONG,
                DONGIABAN = _xh.DON_GIA_BAN,
                THANHTIEN = _xh.THANH_TIEN,
                TRATRUOC = _xh.TRA_TRUOC,
                LAISUAT = _xh.LAI_SUAT,
                LAI = 0,
                TRAGOC = 0,
                TRALAI = 0,
                CONNO = 0
            });

            note = "CHI TIẾT LÃI KHÁCH HÀNG";
            DateTime now = dateTimePickerTO.Value.Date;

            /* Không sử dụng dữ liệu từ thu nợ */
            foreach (CCongNoKhachHang row in xuat_hang)
            {
                //double lai = Utility.Lai(row.NGAY, now, row.LAISUAT, row.THANHTIEN - row.TRATRUOC);
                double lai     = MXuatHang.GetLai(row.ID, now);
                string HangHoa = MHangHoa.GetNameByID(row.HANGHOAID);
                _datasource.Add(new CCongNoKhachHang()
                {
                    NGAY      = row.NGAY,
                    KHO       = row.KHO,
                    HANGHOA   = HangHoa,
                    SOLUONG   = row.SOLUONG,
                    DONGIABAN = row.DONGIABAN,
                    THANHTIEN = row.THANHTIEN,
                    TRATRUOC  = row.TRATRUOC,
                    LAISUAT   = row.LAISUAT * 100,
                    /* Cần tính lãi */
                    LAI    = lai,
                    TRAGOC = 0,
                    TRALAI = 0,
                    CONNO  = row.THANHTIEN + (long)lai - row.TRATRUOC
                });
            }
            //}
            bs.DataSource = _datasource;
            CrystalReportCHITIETLAIKHACHHANG rpt = new CrystalReportCHITIETLAIKHACHHANG();

            rpt.SetDataSource(bs);
            rpt.SetParameterValue("KH", comboBox1.Text);
            rpt.SetParameterValue("FROM", dateTimePickerFROM.Value);
            rpt.SetParameterValue("TO", dateTimePickerTO.Value);
            rpt.SetParameterValue("COMP", ConstClass.COMPANY_NAME);
            rpt.SetParameterValue("NOTE", note);
            crystalReportViewer1.ReportSource = rpt;
            crystalReportViewer1.Zoom(150);
        }