예제 #1
0
        public frmChiTietCongNo(Entities.CongNo[] congnochitietncc, Entities.PhieuThu[] ptc,
                                Entities.HoaDonNhap[] hdn1, Entities.TraLaiNCC[] tlncc1, Entities.NhaCungCap ncc1, Entities.PhieuTTNCC[] phieuttncc1, string sddk, string sdck)
        {
            InitializeComponent();
            congnochitiet = new List <Entities.CongNo>();
            foreach (Entities.CongNo item in congnochitietncc)
            {
                if (!string.IsNullOrEmpty(item.MaDoiTuong))
                {
                    this.congnochitiet.Add(item);
                }
            }

            this.hdn1            = hdn1;
            this.tlncc1          = tlncc1;
            this.ncc1            = ncc1;
            this.ptc             = ptc;
            this.phieuttncc1     = phieuttncc1;
            txtducuoiky.Text     = sdck;
            txtdudauky.Text      = sddk;
            lbma.Text            = "Mã nhà cung cấp:";
            lbten.Text           = "Tên nhà cung cấp:";
            grbthongtin.Text     = "Thông tin nhà cung cấp";
            lbhienthidiachi.Text = ncc1.DiaChi;
            lbhienthima.Text     = ncc1.MaNhaCungCap;
            lbhienthiten.Text    = ncc1.TenNhaCungCap;
            Entities.CongNo cnNCC = new Entities.CongNo();

            if (Thu() == 0 && Chi() == 0)
            {
                cnNCC = new Entities.CongNo("Tổng Cộng", "", "0", "0", "");
            }
            else if (Thu() == 0 && Chi() != 0)
            {
                cnNCC = new Entities.CongNo("Tổng Cộng", "", "0", Format(Chi()), "");
            }
            else if (Thu() != 0 && Chi() == 0)
            {
                cnNCC = new Entities.CongNo("Tổng Cộng", "", Format(Thu()), "0", "");
            }
            else if (Thu() != 0 && Chi() != 0)
            {
                cnNCC = new Entities.CongNo("Tổng Cộng", "", Format(Thu()), Format(Chi()), "");
            }
            congnochitiet.Add(cnNCC);
            dtgvhienthi.DataSource = congnochitiet;
            TonNCC();
            fixncc();
            list = GetData(dtgvhienthi);
        }
예제 #2
0
        public frmChiTietCongNo(Entities.CongNo[] congnochitietkh, Entities.HDBanHang[] bb1, Entities.PhieuThu[] ptc,
                                Entities.KhachHangTraLai[] khtl1, Entities.KhachHang kh, Entities.PhieuTTCuaKH[] phieuttcuakh1, string sddk, string sdck)
        {
            InitializeComponent();
            congnochitiet = new List <Entities.CongNo>();
            this.bb1      = bb1;
            foreach (Entities.CongNo item in congnochitietkh)
            {
                if (!string.IsNullOrEmpty(item.MaDoiTuong))
                {
                    this.congnochitiet.Add(item);
                }
            }

            this.khtl1           = khtl1;
            this.kh1             = kh;
            this.ptc             = ptc;
            this.phieuttcuakh1   = phieuttcuakh1;
            lbhienthidiachi.Text = kh1.DiaChi;
            lbhienthima.Text     = kh1.MaKH;
            lbhienthiten.Text    = kh1.Ten;
            txtducuoiky.Text     = sdck;
            txtdudauky.Text      = sddk;
            Entities.CongNo cnkh = new Entities.CongNo();

            if (Thu() == 0 && Chi() == 0)
            {
                cnkh = new Entities.CongNo("Tổng Cộng", "", "0", "0", "");
            }
            else if (Thu() == 0 && Chi() != 0)
            {
                cnkh = new Entities.CongNo("Tổng Cộng", "", "0", Format(Chi()), "");
            }
            else if (Thu() != 0 && Chi() == 0)
            {
                cnkh = new Entities.CongNo("Tổng Cộng", "", Format(Thu()), "0", "");
            }
            else if (Thu() != 0 && Chi() != 0)
            {
                cnkh = new Entities.CongNo("Tổng Cộng", "", Format(Thu()), Format(Chi()), "");
            }

            congnochitiet.Add(cnkh);
            dtgvhienthi.DataSource = congnochitiet;
            Ton();
            fixkh();
            list = GetData(dtgvhienthi);
        }
예제 #3
0
        public frmChiTietCongNo(Entities.CongNo[] congnochitietkh, Entities.HDBanHang[] bb1, Entities.PhieuThu[] ptc,
            Entities.KhachHangTraLai[] khtl1, Entities.KhachHang kh, Entities.PhieuTTCuaKH[] phieuttcuakh1, string sddk, string sdck)
        {
            InitializeComponent();
            congnochitiet = new List<Entities.CongNo>();
            this.bb1 = bb1;
            foreach (Entities.CongNo item in congnochitietkh)
            {
                if (!string.IsNullOrEmpty(item.MaDoiTuong))
                    this.congnochitiet.Add(item);
            }

            this.khtl1 = khtl1;
            this.kh1 = kh;
            this.ptc = ptc;
            this.phieuttcuakh1 = phieuttcuakh1;
            lbhienthidiachi.Text = kh1.DiaChi;
            lbhienthima.Text = kh1.MaKH;
            lbhienthiten.Text = kh1.Ten;
            txtducuoiky.Text = sdck;
            txtdudauky.Text = sddk;
            Entities.CongNo cnkh = new Entities.CongNo();

            if (Thu() == 0 && Chi() == 0)
                cnkh = new Entities.CongNo("Tổng Cộng", "", "0", "0", "");
            else if (Thu() == 0 && Chi() != 0)
                cnkh = new Entities.CongNo("Tổng Cộng", "", "0", Format(Chi()), "");
            else if (Thu() != 0 && Chi() == 0)
                cnkh = new Entities.CongNo("Tổng Cộng", "", Format(Thu()), "0", "");
            else if (Thu() != 0 && Chi() != 0)
                cnkh = new Entities.CongNo("Tổng Cộng", "", Format(Thu()), Format(Chi()), "");

            congnochitiet.Add(cnkh);
            dtgvhienthi.DataSource = congnochitiet;
            Ton();
            fixkh();
            list = GetData(dtgvhienthi);
        }
 private void txttimkiem_TextChanged(object sender, EventArgs e)
 {
     try
     {
         if (rdbtimkiem3.Checked == true)
         {
             return;
         }
         if (txttimkiem.Text.Length == 0)
         {
             dtgvhienthi.DataSource = new Entities.CongNo[0];
             return;
         }
         int soluong = 0;
         if (hienthi != null)
         {
             if (rdbtimkiem1.Checked == true)
             {
                 for (int i = 0; i < hienthi.ToArray().Length; i++)
                 {
                     int kiemtra = hienthi[i].MaDoiTuong.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                     if (kiemtra >= 0)
                     {
                         soluong++;
                     }
                 }
                 if (soluong == 0)
                 {
                     dtgvhienthi.DataSource = new Entities.CongNo[0];
                     return;
                 }
                 Entities.CongNo[] hienthitheoid = new Entities.CongNo[soluong];
                 soluong = 0;
                 for (int i = 0; i < hienthi.ToArray().Length; i++)
                 {
                     int kiemtra = hienthi[i].MaDoiTuong.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                     if (kiemtra >= 0)
                     {
                         hienthitheoid[soluong] = hienthi[i];
                         soluong++;
                     }
                 }
                 dtgvhienthi.DataSource = hienthitheoid;
             }
             if (rdbtimkiem2.Checked == true)
             {
                 for (int i = 0; i < hienthi.ToArray().Length; i++)
                 {
                     int kiemtra = hienthi[i].TenDoiTuong.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                     if (kiemtra >= 0)
                     {
                         soluong++;
                     }
                 }
                 if (soluong == 0)
                 {
                     dtgvhienthi.DataSource = new Entities.CongNo[0];
                     return;
                 }
                 Entities.CongNo[] hienthitheoma = new Entities.CongNo[soluong];
                 soluong = 0;
                 for (int i = 0; i < hienthi.ToArray().Length; i++)
                 {
                     int kiemtra = hienthi[i].TenDoiTuong.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                     if (kiemtra >= 0)
                     {
                         hienthitheoma[soluong] = hienthi[i];
                         soluong++;
                     }
                 }
                 dtgvhienthi.DataSource = hienthitheoma;
             }
             if (dtgvhienthi.RowCount > 0)
             {
                 tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
             }
             else
             {
                 tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
             }
         }
     }
     finally
     {
         fix();
     }
 }
        /// <summary>
        /// hiển thị tổng
        /// </summary>
        public void HienThiTong(DateTime batdau, DateTime ketthuc)
        {
            try
            {
                //SelectData();

                hienthi   = new List <Entities.CongNo>();
                congnoncc = new List <Entities.CongNo>();
                int    soluong    = 0;
                int    soluongncc = 0;
                double phatsinhno = 0;
                double phatsinhco = 0;
                double sdck       = 0;
                double sddk       = 0;

                // Nhà Cung Cấp
                for (int i = 0; i < ncc.Length; i++)
                {
                    phatsinhco = 0;
                    phatsinhno = 0;
                    sdck       = sddk = 0;
                    string maSoDuCongNo = "";
                    for (int j = 0; j < hienthi1.Length; j++)
                    {
                        if (hienthi1[j].MaDoiTuong == ncc[i].MaNhaCungCap && hienthi1[j].NgayKetChuyen.Month == batdau.Month && hienthi1[j].NgayKetChuyen.Year == batdau.Year)
                        {
                            maSoDuCongNo = hienthi1[j].MaSoDuCongNo;
                            sddk         = Double.Parse(hienthi1[j].SoDuDauKy);
                            break;
                        }
                    }
                    // hóa đơn nhập
                    for (int j = 0; j < hdn.Length; j++)
                    {
                        if (ncc[i].MaNhaCungCap == hdn[j].MaNhaCungCap && hdn[j].NgayNhap.Date >= batdau.Date && hdn[j].NgayNhap.Date <= ketthuc.Date)
                        {
                            phatsinhco += Convert.ToDouble(hdn[j].TongTien);
                            phatsinhno += Convert.ToDouble(hdn[j].ThanhToanNgay);
                        }
                    }


                    // Phieu thu
                    for (int j = 0; j < phieuThuChi.Length; j++)
                    {
                        try
                        {
                            if (phieuThuChi[j].DoiTuong.Equals(ncc[i].MaNhaCungCap) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Thu".ToUpper()) && phieuThuChi[j].Deleted == false && phieuThuChi[j].NgayLap.Date >= batdau.Date && phieuThuChi[j].NgayLap.Date <= ketthuc.Date)
                            {
                                phatsinhco += double.Parse(phieuThuChi[j].TongTienThanhToan);
                            }
                        }
                        catch (Exception)
                        { }
                    }

                    // Phieu chi
                    for (int j = 0; j < phieuThuChi.Length; j++)
                    {
                        try
                        {
                            if (phieuThuChi[j].DoiTuong.Equals(ncc[i].MaNhaCungCap) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Chi".ToUpper()) && phieuThuChi[j].Deleted == false && phieuThuChi[j].NgayLap.Date >= batdau.Date && phieuThuChi[j].NgayLap.Date <= ketthuc.Date)
                            {
                                phatsinhno += double.Parse(phieuThuChi[j].TongTienThanhToan);
                            }
                        }
                        catch (Exception)
                        { }
                    }

                    // trả lại nhà cung cấp
                    for (int j = 0; j < tl.Length; j++)
                    {
                        if (tl[j].MaNCC == ncc[i].MaNhaCungCap && tl[j].Ngaytra.Date >= batdau.Date && tl[j].Ngaytra.Date <= ketthuc.Date)
                        {
                            phatsinhno += Convert.ToDouble(tl[j].TienBoiThuong);
                            phatsinhco += double.Parse(tl[j].ThanhToanNgay);
                        }
                    }
                    // phiếu thanh toán của nhà cung cấp
                    for (int j = 0; j < phieuttncc.Length; j++)
                    {
                        if (phieuttncc[j].MaNCC == ncc[i].MaNhaCungCap && phieuttncc[j].NgayLap.Date >= batdau.Date && phieuttncc[j].NgayLap.Date <= ketthuc.Date)
                        {
                            double tienthanhtoan = 0;
                            for (int k = 0; k < chitietphieuttncc.Length; k++)
                            {
                                if (phieuttncc[j].MaPhieuTTNCC == chitietphieuttncc[k].MaPhieuTTNCC)
                                {
                                    phatsinhno    += Convert.ToDouble(chitietphieuttncc[k].ThanhToan.ToString());
                                    tienthanhtoan += Convert.ToDouble(chitietphieuttncc[k].ThanhToan.ToString());
                                }
                            }
                        }
                    }
                    sdck = sddk + phatsinhco - phatsinhno;
                    Entities.CongNo cn = new Entities.CongNo(ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi, Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck));
                    congnoncc.Add(cn);
                }
                sddk       = 0;
                sdck       = 0;
                phatsinhno = 0;
                phatsinhco = 0;
                // tính toán của mảng nhà cung cấp
                Entities.CongNo cnNCC = new Entities.CongNo();
                int             count = congnoncc.ToArray().Length;
                if (count == 1)
                {
                    for (int i = 0; i < count; i++)
                    {
                        sddk       = double.Parse(congnoncc[i].DuDauKy);
                        phatsinhno = double.Parse(congnoncc[i].PhatSinhNo);
                        phatsinhco = double.Parse(congnoncc[i].PhatSinhCo);
                        sdck       = sddk + phatsinhco - phatsinhno;
                        cnNCC      = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                    }
                    congnoncc.Add(cnNCC);
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        sddk       += double.Parse(congnoncc[i].DuDauKy);
                        phatsinhco += Convert.ToDouble(congnoncc[i].PhatSinhCo);
                        phatsinhno += Convert.ToDouble(congnoncc[i].PhatSinhNo);
                        sdck        = sddk + phatsinhco - phatsinhno;
                        cnNCC       = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                    }
                    congnoncc.Add(cnNCC);
                }

                foreach (Entities.CongNo item in congnoncc)
                {
                    if (!string.IsNullOrEmpty(item.MaDoiTuong))
                    {
                        hienthi.Add(item);
                    }
                }


                dtgvhienthi.DataSource = congnoncc;
                if (hienthi.ToArray().Length > 1)
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                }
                else
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                }
                dtgvhienthi.Rows[dtgvhienthi.RowCount - 1].DefaultCellStyle.Font = new Font(dtgvhienthi.DefaultCellStyle.Font, FontStyle.Bold);
            }
            catch
            {
            }
            finally
            {
                fix();
            }
        }
        private void txttimkiem_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (rdbtimkiem3.Checked == true)
                {
                    return;
                }
                if (txttimkiem.Text.Length == 0)
                {
                    dtgvhienthi.DataSource = new Entities.CongNo[0];
                    return;
                }
                int soluong = 0;
                if (hienthi != null)
                {
                    if (rdbtimkiem1.Checked == true)
                    {
                        for (int i = 0; i < hienthi.ToArray().Length; i++)
                        {
                            int kiemtra = hienthi[i].MaDoiTuong.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                            if (kiemtra >= 0)
                            {
                                soluong++;
                            }
                        }
                        if (soluong == 0)
                        {
                            dtgvhienthi.DataSource = new Entities.CongNo[0];
                            return;
                        }
                        Entities.CongNo[] hienthitheoid = new Entities.CongNo[soluong];
                        soluong = 0;
                        for (int i = 0; i < hienthi.ToArray().Length; i++)
                        {
                            int kiemtra = hienthi[i].MaDoiTuong.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                            if (kiemtra >= 0)
                            {
                                hienthitheoid[soluong] = hienthi[i];
                                soluong++;
                            }
                        }
                        dtgvhienthi.DataSource = hienthitheoid;
                    }
                    if (rdbtimkiem2.Checked == true)
                    {
                        for (int i = 0; i < hienthi.ToArray().Length; i++)
                        {
                            int kiemtra = hienthi[i].TenDoiTuong.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                            if (kiemtra >= 0)
                            {
                                soluong++;
                            }
                        }
                        if (soluong == 0)
                        {
                            dtgvhienthi.DataSource = new Entities.CongNo[0];
                            return;
                        }
                        Entities.CongNo[] hienthitheoma = new Entities.CongNo[soluong];
                        soluong = 0;
                        for (int i = 0; i < hienthi.ToArray().Length; i++)
                        {
                            int kiemtra = hienthi[i].TenDoiTuong.ToString().ToUpper().IndexOf(txttimkiem.Text.ToUpper());
                            if (kiemtra >= 0)
                            {
                                hienthitheoma[soluong] = hienthi[i];
                                soluong++;
                            }
                        }
                        dtgvhienthi.DataSource = hienthitheoma;

                    }
                    if (dtgvhienthi.RowCount > 0)
                    {
                        tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                    }
                    else
                    {
                        tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                    }
                }
            }
            finally
            {
                fix();
            }
        }
        /// <summary>
        /// hiển thị tổng
        /// </summary>
        public void HienThiTong(DateTime batdau, DateTime ketthuc)
        {
            double phatsinhno = 0;
            double phatsinhco = 0;
            double sdck = 0;
            double sddk = 0;
            try
            {

                SelectData();

                congnokh = new List<Entities.CongNo>();
                hienthi = new List<Entities.CongNo>();

                int soluong = 0;
                int soluongkh = 0;
                sdck = sddk = 0;
                // Khách Hàng
                for (int i = 0; i < kh.Length; i++)
                {
                    phatsinhco = 0;
                    phatsinhno = 0;
                    sdck = sddk = 0;
                    for (int j = 0; j < soducongno.Length; j++)
                    {
                        if (soducongno[j].MaDoiTuong == kh[i].MaKH && soducongno[j].NgayKetChuyen.Month == batdau.Month && soducongno[j].NgayKetChuyen.Year == batdau.Year)
                        {
                            sddk = Double.Parse(soducongno[j].SoDuDauKy);
                            break;
                        }
                    }
                    // bán buôn
                    for (int j = 0; j < bb.Length; j++)
                    {
                        if (bb[j].MaKhachHang == kh[i].MaKH && bb[j].NgayBan.Date >= batdau.Date && bb[j].NgayBan.Date <= ketthuc.Date)
                        {
                            phatsinhno += Convert.ToDouble(bb[j].TongTienThanhToan);
                            phatsinhco += Convert.ToDouble(bb[j].ThanhToanKhiLapPhieu);
                        }
                    }

                    // Phieu thu
                    for (int j = 0; j < phieuThuChi.Length; j++)
                    {
                        try
                        {
                            if (phieuThuChi[j].DoiTuong.Equals(kh[i].MaKH) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Thu".ToUpper()) && phieuThuChi[j].Deleted == false && phieuThuChi[j].NgayLap.Date >= batdau.Date && phieuThuChi[j].NgayLap.Date <= ketthuc.Date)
                            {
                                phatsinhco += double.Parse(phieuThuChi[j].TongTienThanhToan);
                            }
                        }
                        catch (Exception)
                        { }
                    }

                    // Phieu chi
                    for (int j = 0; j < phieuThuChi.Length; j++)
                    {
                        try
                        {

                            if (phieuThuChi[j].DoiTuong.Equals(kh[i].MaKH) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Chi".ToUpper()) && phieuThuChi[j].Deleted == false && phieuThuChi[j].NgayLap.Date >= batdau.Date && phieuThuChi[j].NgayLap.Date <= ketthuc.Date)
                            {
                                phatsinhno += double.Parse(phieuThuChi[j].TongTienThanhToan);

                            }
                        }
                        catch (Exception)
                        { }
                    }

                    // khách hàng trả lại
                    for (int j = 0; j < khtl.Length; j++)
                    {
                        if (khtl[j].MaKhachHang == kh[i].MaKH && khtl[j].NgayNhap.Date >= batdau.Date && khtl[j].NgayNhap.Date <= ketthuc.Date)
                        {
                            phatsinhco += Convert.ToDouble(khtl[j].TienBoiThuong);
                            phatsinhno += double.Parse(khtl[j].ThanhToanNgay);
                        }
                    }
                    // phiếu thanh toán của khách hàng
                    for (int j = 0; j < phieuttcuakh.Length; j++)
                    {
                        if (phieuttcuakh[j].MaKhachHang == kh[i].MaKH && phieuttcuakh[j].NgayLap.Date >= batdau.Date && phieuttcuakh[j].NgayLap.Date <= ketthuc.Date)
                        {
                            double tienthanhtoan = 0;
                            for (int k = 0; k < chitietphieuttcuakh.Length; k++)
                            {
                                if (phieuttcuakh[j].MaPhieuTTCuaKH == chitietphieuttcuakh[k].MaPhieuTTCuaKH)
                                {
                                    phatsinhco += Convert.ToDouble(chitietphieuttcuakh[k].ThanhToan.ToString());
                                    tienthanhtoan += Convert.ToDouble(chitietphieuttcuakh[k].ThanhToan.ToString());
                                }
                            }
                        }
                    }
                    sdck = sddk + phatsinhno - phatsinhco;
                    Entities.CongNo cn = new Entities.CongNo(kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck));
                    congnokh.Add(cn);
                }

                sddk = sdck = phatsinhno = phatsinhco = 0;
                // tính toán của mảng khách hàng
                Entities.CongNo cnKH = new Entities.CongNo();
                int count = congnokh.ToArray().Length;
                if (count == 1)
                {
                    for (int i = 0; i < count; i++)
                    {
                        sdck = sddk + phatsinhno - phatsinhco;
                        cnKH = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                    }

                    congnokh.Add(cnKH);
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        sddk += Convert.ToDouble(congnokh[i].DuDauKy);
                        phatsinhco += Convert.ToDouble(congnokh[i].PhatSinhCo);
                        phatsinhno += Convert.ToDouble(congnokh[i].PhatSinhNo);
                        sdck = sddk + phatsinhno - phatsinhco;
                        cnKH = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                    }

                    congnokh.Add(cnKH);
                }

                foreach (Entities.CongNo item in congnokh)
                {
                    if (!string.IsNullOrEmpty(item.MaDoiTuong))
                        hienthi.Add(item);
                }

                dtgvhienthi.DataSource = congnokh;
                if (hienthi.ToArray().Length > 1)
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                }
                else
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                }
                dtgvhienthi.Rows[dtgvhienthi.RowCount - 1].DefaultCellStyle.Font = new Font(dtgvhienthi.DefaultCellStyle.Font, FontStyle.Bold);
            }
            catch
            {
            }
            finally
            {
                fix();
            }
        }
        /// <summary>
        /// hiển thị tổng
        /// </summary>

        public void HienThiTong(DateTime batdau, DateTime ketthuc)
        {
            double phatsinhno = 0;
            double phatsinhco = 0;
            double sdck       = 0;
            double sddk       = 0;

            try
            {
                SelectData();


                congnokh = new List <Entities.CongNo>();
                hienthi  = new List <Entities.CongNo>();

                int soluong   = 0;
                int soluongkh = 0;
                sdck = sddk = 0;
                // Khách Hàng
                for (int i = 0; i < kh.Length; i++)
                {
                    phatsinhco = 0;
                    phatsinhno = 0;
                    sdck       = sddk = 0;
                    for (int j = 0; j < soducongno.Length; j++)
                    {
                        if (soducongno[j].MaDoiTuong == kh[i].MaKH && soducongno[j].NgayKetChuyen.Month == batdau.Month && soducongno[j].NgayKetChuyen.Year == batdau.Year)
                        {
                            sddk = Double.Parse(soducongno[j].SoDuDauKy);
                            break;
                        }
                    }
                    // bán buôn
                    for (int j = 0; j < bb.Length; j++)
                    {
                        if (bb[j].MaKhachHang == kh[i].MaKH && bb[j].NgayBan.Date >= batdau.Date && bb[j].NgayBan.Date <= ketthuc.Date)
                        {
                            phatsinhno += Convert.ToDouble(bb[j].TongTienThanhToan);
                            phatsinhco += Convert.ToDouble(bb[j].ThanhToanKhiLapPhieu);
                        }
                    }

                    // Phieu thu
                    for (int j = 0; j < phieuThuChi.Length; j++)
                    {
                        try
                        {
                            if (phieuThuChi[j].DoiTuong.Equals(kh[i].MaKH) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Thu".ToUpper()) && phieuThuChi[j].Deleted == false && phieuThuChi[j].NgayLap.Date >= batdau.Date && phieuThuChi[j].NgayLap.Date <= ketthuc.Date)
                            {
                                phatsinhco += double.Parse(phieuThuChi[j].TongTienThanhToan);
                            }
                        }
                        catch (Exception)
                        { }
                    }

                    // Phieu chi
                    for (int j = 0; j < phieuThuChi.Length; j++)
                    {
                        try
                        {
                            if (phieuThuChi[j].DoiTuong.Equals(kh[i].MaKH) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Chi".ToUpper()) && phieuThuChi[j].Deleted == false && phieuThuChi[j].NgayLap.Date >= batdau.Date && phieuThuChi[j].NgayLap.Date <= ketthuc.Date)
                            {
                                phatsinhno += double.Parse(phieuThuChi[j].TongTienThanhToan);
                            }
                        }
                        catch (Exception)
                        { }
                    }

                    // khách hàng trả lại
                    for (int j = 0; j < khtl.Length; j++)
                    {
                        if (khtl[j].MaKhachHang == kh[i].MaKH && khtl[j].NgayNhap.Date >= batdau.Date && khtl[j].NgayNhap.Date <= ketthuc.Date)
                        {
                            phatsinhco += Convert.ToDouble(khtl[j].TienBoiThuong);
                            phatsinhno += double.Parse(khtl[j].ThanhToanNgay);
                        }
                    }
                    // phiếu thanh toán của khách hàng
                    for (int j = 0; j < phieuttcuakh.Length; j++)
                    {
                        if (phieuttcuakh[j].MaKhachHang == kh[i].MaKH && phieuttcuakh[j].NgayLap.Date >= batdau.Date && phieuttcuakh[j].NgayLap.Date <= ketthuc.Date)
                        {
                            double tienthanhtoan = 0;
                            for (int k = 0; k < chitietphieuttcuakh.Length; k++)
                            {
                                if (phieuttcuakh[j].MaPhieuTTCuaKH == chitietphieuttcuakh[k].MaPhieuTTCuaKH)
                                {
                                    phatsinhco    += Convert.ToDouble(chitietphieuttcuakh[k].ThanhToan.ToString());
                                    tienthanhtoan += Convert.ToDouble(chitietphieuttcuakh[k].ThanhToan.ToString());
                                }
                            }
                        }
                    }
                    sdck = sddk + phatsinhno - phatsinhco;
                    Entities.CongNo cn = new Entities.CongNo(kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck));
                    congnokh.Add(cn);
                }

                sddk = sdck = phatsinhno = phatsinhco = 0;
                // tính toán của mảng khách hàng
                Entities.CongNo cnKH  = new Entities.CongNo();
                int             count = congnokh.ToArray().Length;
                if (count == 1)
                {
                    for (int i = 0; i < count; i++)
                    {
                        sdck = sddk + phatsinhno - phatsinhco;
                        cnKH = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                    }

                    congnokh.Add(cnKH);
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        sddk       += Convert.ToDouble(congnokh[i].DuDauKy);
                        phatsinhco += Convert.ToDouble(congnokh[i].PhatSinhCo);
                        phatsinhno += Convert.ToDouble(congnokh[i].PhatSinhNo);
                        sdck        = sddk + phatsinhno - phatsinhco;
                        cnKH        = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                    }

                    congnokh.Add(cnKH);
                }

                foreach (Entities.CongNo item in congnokh)
                {
                    if (!string.IsNullOrEmpty(item.MaDoiTuong))
                    {
                        hienthi.Add(item);
                    }
                }

                dtgvhienthi.DataSource = congnokh;
                if (hienthi.ToArray().Length > 1)
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                }
                else
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                }
                dtgvhienthi.Rows[dtgvhienthi.RowCount - 1].DefaultCellStyle.Font = new Font(dtgvhienthi.DefaultCellStyle.Font, FontStyle.Bold);
            }
            catch
            {
            }
            finally
            {
                fix();
            }
        }
        /// <summary>
        /// hiển thị tổng
        /// </summary>
        public void HienThiTong(DateTime batdau, DateTime ketthuc)
        {
            try
            {
                //SelectData();

                hienthi = new List<Entities.CongNo>();
                congnoncc = new List<Entities.CongNo>();
                int soluong = 0;
                int soluongncc = 0;
                double phatsinhno = 0;
                double phatsinhco = 0;
                double sdck = 0;
                double sddk = 0;

                // Nhà Cung Cấp
                for (int i = 0; i < ncc.Length; i++)
                {
                    phatsinhco = 0;
                    phatsinhno = 0;
                    sdck = sddk = 0;
                    string maSoDuCongNo = "";
                    for (int j = 0; j < hienthi1.Length; j++)
                    {
                        if (hienthi1[j].MaDoiTuong == ncc[i].MaNhaCungCap && hienthi1[j].NgayKetChuyen.Month == batdau.Month && hienthi1[j].NgayKetChuyen.Year == batdau.Year)
                        {
                            maSoDuCongNo = hienthi1[j].MaSoDuCongNo;
                            sddk = Double.Parse(hienthi1[j].SoDuDauKy);
                            break;
                        }
                    }
                    // hóa đơn nhập
                    for (int j = 0; j < hdn.Length; j++)
                    {
                        if (ncc[i].MaNhaCungCap == hdn[j].MaNhaCungCap && hdn[j].NgayNhap.Date >= batdau.Date && hdn[j].NgayNhap.Date <= ketthuc.Date)
                        {
                            phatsinhco += Convert.ToDouble(hdn[j].TongTien);
                            phatsinhno += Convert.ToDouble(hdn[j].ThanhToanNgay);
                        }
                    }

                    // Phieu thu
                    for (int j = 0; j < phieuThuChi.Length; j++)
                    {
                        try
                        {
                            if (phieuThuChi[j].DoiTuong.Equals(ncc[i].MaNhaCungCap) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Thu".ToUpper()) && phieuThuChi[j].Deleted == false && phieuThuChi[j].NgayLap.Date >= batdau.Date && phieuThuChi[j].NgayLap.Date <= ketthuc.Date)
                            {
                                phatsinhco += double.Parse(phieuThuChi[j].TongTienThanhToan);
                            }
                        }
                        catch (Exception)
                        { }
                    }

                    // Phieu chi
                    for (int j = 0; j < phieuThuChi.Length; j++)
                    {
                        try
                        {
                            if (phieuThuChi[j].DoiTuong.Equals(ncc[i].MaNhaCungCap) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Chi".ToUpper()) && phieuThuChi[j].Deleted == false && phieuThuChi[j].NgayLap.Date >= batdau.Date && phieuThuChi[j].NgayLap.Date <= ketthuc.Date)
                            {
                                phatsinhno += double.Parse(phieuThuChi[j].TongTienThanhToan);
                            }
                        }
                        catch (Exception)
                        { }
                    }

                    // trả lại nhà cung cấp
                    for (int j = 0; j < tl.Length; j++)
                    {
                        if (tl[j].MaNCC == ncc[i].MaNhaCungCap && tl[j].Ngaytra.Date >= batdau.Date && tl[j].Ngaytra.Date <= ketthuc.Date)
                        {
                            phatsinhno += Convert.ToDouble(tl[j].TienBoiThuong);
                            phatsinhco += double.Parse(tl[j].ThanhToanNgay);
                        }
                    }
                    // phiếu thanh toán của nhà cung cấp
                    for (int j = 0; j < phieuttncc.Length; j++)
                    {
                        if (phieuttncc[j].MaNCC == ncc[i].MaNhaCungCap && phieuttncc[j].NgayLap.Date >= batdau.Date && phieuttncc[j].NgayLap.Date <= ketthuc.Date)
                        {
                            double tienthanhtoan = 0;
                            for (int k = 0; k < chitietphieuttncc.Length; k++)
                            {
                                if (phieuttncc[j].MaPhieuTTNCC == chitietphieuttncc[k].MaPhieuTTNCC)
                                {
                                    phatsinhno += Convert.ToDouble(chitietphieuttncc[k].ThanhToan.ToString());
                                    tienthanhtoan += Convert.ToDouble(chitietphieuttncc[k].ThanhToan.ToString());
                                }
                            }
                        }
                    }
                    sdck = sddk + phatsinhco - phatsinhno;
                    Entities.CongNo cn = new Entities.CongNo(ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi, Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck));
                    congnoncc.Add(cn);
                }
                sddk = 0;
                sdck = 0;
                phatsinhno = 0;
                phatsinhco = 0;
                // tính toán của mảng nhà cung cấp
                Entities.CongNo cnNCC = new Entities.CongNo();
                int count = congnoncc.ToArray().Length;
                if (count == 1)
                {
                    for (int i = 0; i < count; i++)
                    {
                        sddk = double.Parse(congnoncc[i].DuDauKy);
                        phatsinhno = double.Parse(congnoncc[i].PhatSinhNo);
                        phatsinhco = double.Parse(congnoncc[i].PhatSinhCo);
                        sdck = sddk + phatsinhco - phatsinhno;
                        cnNCC = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                    }
                    congnoncc.Add(cnNCC);
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        sddk += double.Parse(congnoncc[i].DuDauKy);
                        phatsinhco += Convert.ToDouble(congnoncc[i].PhatSinhCo);
                        phatsinhno += Convert.ToDouble(congnoncc[i].PhatSinhNo);
                        sdck = sddk + phatsinhco - phatsinhno;
                        cnNCC = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                    }
                    congnoncc.Add(cnNCC);
                }

                foreach (Entities.CongNo item in congnoncc)
                {
                    if (!string.IsNullOrEmpty(item.MaDoiTuong))
                    {
                        hienthi.Add(item);
                    }
                }

                dtgvhienthi.DataSource = congnoncc;
                if (hienthi.ToArray().Length > 1)
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                }
                else
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                }
                dtgvhienthi.Rows[dtgvhienthi.RowCount - 1].DefaultCellStyle.Font = new Font(dtgvhienthi.DefaultCellStyle.Font, FontStyle.Bold);
            }
            catch
            {
            }
            finally
            {
                fix();
            }
        }
예제 #10
0
        /// <summary>
        /// hiển thị tổng
        /// </summary>
        public void HienThiTong()
        {
            try
            {
                if (cbbdoituong.SelectedIndex == 0)
                {
                    SelectDataKH();
                }
                else
                {
                    SelectDataNCC();
                }
                SelectBanBuonLe();

                hienthi = new List<Entities.CongNo>();

                congnokh = new List<Entities.CongNo>();

                congnoncc = new List<Entities.CongNo>();
                int soluong = 0;
                int soluongkh = 0;
                int soluongncc = 0;
                sdck = sddk = 0;
                if (cbbdoituong.SelectedIndex == 0)
                {
                    string maSoDuCongNo = "";
                    SelectSoDuCongNo();
                    // Khách Hàng
                    for (int i = 0; i < kh.Length; i++)
                    {
                        phatsinhco = 0;
                        phatsinhno = 0;
                        sddk = 0;
                        for (int j = 0; j < hienthi1.Length; j++)
                        {
                            if (hienthi1[j].MaDoiTuong == kh[i].MaKH)
                            {
                                maSoDuCongNo = hienthi1[j].MaSoDuCongNo;
                                sddk = Double.Parse(hienthi1[j].SoDuDauKy);
                                break;
                            }
                        }
                        // bán buôn
                        for (int j = 0; j < bb.Length; j++)
                        {
                            if (bb[j].MaKhachHang == kh[i].MaKH)
                            {
                                double a = Convert.ToDouble(bb[j].TongTienThanhToan);
                                double b = Convert.ToDouble(bb[j].ThanhToanKhiLapPhieu);
                                if (b > a)
                                {
                                    b = a;
                                }
                                phatsinhno += a;
                                phatsinhco += b;
                                string ngaylap = new Common.Utilities().XuLy(2, bb[j].NgayBan.ToShortDateString());
                                Entities.CongNo cn = new Entities.CongNo(ngaylap, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi,
                                   Format(a), Format(b), bb[j].GhiChu, "PhieuThu");
                                hienthi.Add(cn);
                            }
                        }

                        // Phieu thu
                        for (int j = 0; j < phieuThuChi.Length; j++)
                        {
                            try
                            {
                                string month1 = phieuThuChi[j].NgayLap.Month.ToString();
                                string year1 = phieuThuChi[j].NgayLap.Year.ToString();

                                if (phieuThuChi[j].DoiTuong.Equals(kh[i].MaKH) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Thu".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year)
                                {
                                    phatsinhco += double.Parse(phieuThuChi[j].TongTienThanhToan);
                                    string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString());
                                    Entities.CongNo cn = new Entities.CongNo(ngaylap, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi,
                                       "0", Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), phieuThuChi[j].GhiChu, "Thu");
                                    hienthi.Add(cn);
                                }
                            }
                            catch { }
                        }

                        // Phieu chi
                        for (int j = 0; j < phieuThuChi.Length; j++)
                        {
                            try
                            {
                                string month1 = phieuThuChi[j].NgayLap.Month.ToString();
                                string year1 = phieuThuChi[j].NgayLap.Year.ToString();

                                if (phieuThuChi[j].DoiTuong.Equals(kh[i].MaKH) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Chi".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year)
                                {
                                    phatsinhno += double.Parse(phieuThuChi[j].TongTienThanhToan);
                                    string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString());
                                    Entities.CongNo cn = new Entities.CongNo(ngaylap, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi,
                                       Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), "0", phieuThuChi[j].GhiChu, "Chi");
                                    hienthi.Add(cn);
                                }
                            }
                            catch { }
                        }

                        // khách hàng trả lại
                        for (int j = 0; j < khtl.Length; j++)
                        {
                            if (khtl[j].MaKhachHang == kh[i].MaKH)
                            {
                                double a = Convert.ToDouble(khtl[j].TienBoiThuong);
                                double b = Convert.ToDouble(khtl[j].ThanhToanNgay);
                                if (b > a)
                                {
                                    b = a;
                                }
                                phatsinhco += a;
                                phatsinhno += b;
                                string ngaylap = new Common.Utilities().XuLy(2, khtl[j].NgayNhap.ToShortDateString());
                                Entities.CongNo cn = new Entities.CongNo(ngaylap, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, Format(b),
                                    Format(a), khtl[j].GhiChu, "PhieuThu");
                                hienthi.Add(cn);
                            }
                        }
                        // phiếu thanh toán của khách hàng
                        for (int j = 0; j < phieuttcuakh.Length; j++)
                        {
                            if (phieuttcuakh[j].MaKhachHang == kh[i].MaKH)
                            {
                                double tienthanhtoan = 0;
                                for (int k = 0; k < chitietphieuttcuakh.Length; k++)
                                {
                                    if (phieuttcuakh[j].MaPhieuTTCuaKH == chitietphieuttcuakh[k].MaPhieuTTCuaKH)
                                    {
                                        phatsinhco += Convert.ToDouble(chitietphieuttcuakh[k].ThanhToan.ToString());
                                        tienthanhtoan += Convert.ToDouble(chitietphieuttcuakh[k].ThanhToan.ToString());
                                    }
                                }
                                string ngaylap = new Common.Utilities().XuLy(2, phieuttcuakh[j].NgayLap.ToShortDateString());
                                Entities.CongNo cn = new Entities.CongNo(ngaylap, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, "0",
                                    Format(tienthanhtoan), phieuttcuakh[j].GhiChu, "PhieuTTCuaKH");
                                hienthi.Add(cn);
                            }
                        }
                        sdck = sddk + phatsinhno - phatsinhco;
                        Entities.SoDuCongNo sdcnKH = new Entities.SoDuCongNo("UpdateTrangThai", maSoDuCongNo, kh[i].MaKH, kh[i].Ten, kh[i].DiaChi, (sddk + phatsinhno - phatsinhco).ToString(), Convert.ToDateTime(cbbthang.Text + "/01/" + cbbnam.Text), false);
                        Entities.CongNo cnkh = new Entities.CongNo(kh[i].MaKH, kh[i].Ten, kh[i].DiaChi,
                            Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck));
                        mangchitiet.Add(sdcnKH);
                        congnokh.Add(cnkh);
                    }
                    sddk = phatsinhno = phatsinhco = 0;
                    // tính toán của mảng khách hàng
                    Entities.CongNo cnkh1 = new Entities.CongNo();
                    int count = congnokh.ToArray().Length;
                    if (count == 1)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            sdck = sddk + phatsinhno - phatsinhco;
                            cnkh1 = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);

                        }
                        congnokh.Add(cnkh1);
                    }
                    else
                    {
                        for (int i = 0; i < count; i++)
                        {
                            phatsinhco += Convert.ToDouble(congnokh[i].PhatSinhCo);
                            phatsinhno += Convert.ToDouble(congnokh[i].PhatSinhNo);
                            sddk += double.Parse(congnokh[i].DuDauKy);
                            sdck = sddk + phatsinhno - phatsinhco;
                            cnkh1 = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                        }
                        congnokh.Add(cnkh1);
                    }

                    Entities.TongHopCongNo thcn;
                    congNoList = new List<Entities.TongHopCongNo>();
                    foreach (Entities.CongNo item in congnokh)
                    {
                        double psn = 0;
                        double psc = 0;
                        double ddk = 0;
                        double dck = 0;
                        if (!string.IsNullOrEmpty(item.PhatSinhNo))
                            psn = double.Parse(item.PhatSinhNo);
                        if (!string.IsNullOrEmpty(item.PhatSinhCo))
                            psc = double.Parse(item.PhatSinhCo);
                        if (!string.IsNullOrEmpty(item.DuDauKy))
                            ddk = double.Parse(item.DuDauKy);
                        if (!string.IsNullOrEmpty(item.DuCuoiKy))
                            dck = double.Parse(item.DuCuoiKy);
                        thcn = new Entities.TongHopCongNo();
                        thcn.MaDoiTuong = item.MaDoiTuong;
                        thcn.TenDoiTuong = item.TenDoiTuong;
                        thcn.DiaChi = item.DiaChi;
                        thcn.PhatSinhNo = psn;
                        thcn.PhatSinhCo = psc;
                        thcn.DuDauKy = ddk;
                        thcn.DuCuoiKy = dck;
                        if (!string.IsNullOrEmpty(item.MaDoiTuong))
                            congNoList.Add(thcn);
                    }
                }
                else
                {
                    SelectSoDuCongNo();
                    // Nhà Cung Cấp
                    for (int i = 0; i < ncc.Length; i++)
                    {
                        phatsinhco = 0;
                        phatsinhno = 0;
                        sddk = 0;
                        string maSoDuCongNo = "";
                        for (int j = 0; j < hienthi1.Length; j++)
                        {
                            if (hienthi1[j].MaDoiTuong == ncc[i].MaNhaCungCap)
                            {
                                maSoDuCongNo = hienthi1[j].MaSoDuCongNo;
                                sddk = Double.Parse(hienthi1[j].SoDuDauKy);
                                break;
                            }
                        }
                        // hóa đơn nhập
                        for (int j = 0; j < hdn.Length; j++)
                        {
                            if (ncc[i].MaNhaCungCap == hdn[j].MaNhaCungCap)
                            {
                                double a = Convert.ToDouble(hdn[j].TongTien);
                                double b = Convert.ToDouble(hdn[j].ThanhToanNgay);
                                if (b > a)
                                {
                                    b = a;
                                }
                                phatsinhco += a;
                                phatsinhno += b;
                                string ngaylap = new Common.Utilities().XuLy(2, hdn[j].NgayNhap.ToShortDateString());
                                Entities.CongNo cn = new Entities.CongNo(ngaylap, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi,
                                    Format(b), Format(a), hdn[j].GhiChu, "HoaDonNhap");
                                hienthi.Add(cn);
                            }
                        }

                        // Phieu thu
                        for (int j = 0; j < phieuThuChi.Length; j++)
                        {
                            try
                            {
                                string month1 = phieuThuChi[j].NgayLap.Month.ToString();
                                string year1 = phieuThuChi[j].NgayLap.Year.ToString();

                                if (phieuThuChi[j].DoiTuong.Equals(ncc[i].MaNhaCungCap) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Thu".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year)
                                {
                                    phatsinhco += double.Parse(phieuThuChi[j].TongTienThanhToan);
                                    string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString());
                                    Entities.CongNo cn = new Entities.CongNo(ngaylap, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi,
                                       "0", Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), phieuThuChi[j].GhiChu, "Thu");
                                    hienthi.Add(cn);
                                }
                            }
                            catch { }
                        }

                        // Phieu chi
                        for (int j = 0; j < phieuThuChi.Length; j++)
                        {
                            try
                            {
                                string month1 = phieuThuChi[j].NgayLap.Month.ToString();
                                string year1 = phieuThuChi[j].NgayLap.Year.ToString();

                                if (phieuThuChi[j].DoiTuong.Equals(ncc[i].MaNhaCungCap) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Chi".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year)
                                {
                                    phatsinhno += double.Parse(phieuThuChi[j].TongTienThanhToan);
                                    string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString());
                                    Entities.CongNo cn = new Entities.CongNo(ngaylap, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi,
                                       Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), "0", phieuThuChi[j].GhiChu, "Chi");
                                    hienthi.Add(cn);
                                }
                            }
                            catch { }
                        }

                        // trả lại nhà cung cấp
                        for (int j = 0; j < tl.Length; j++)
                        {
                            if (tl[j].MaNCC == ncc[i].MaNhaCungCap)
                            {
                                double tongTienThanhToan = Convert.ToDouble(tl[j].TienBoiThuong);
                                double thanhToanNgay = Convert.ToDouble(tl[j].ThanhToanNgay);
                                if (thanhToanNgay > tongTienThanhToan)
                                    thanhToanNgay = tongTienThanhToan;

                                phatsinhno += tongTienThanhToan;
                                phatsinhco += thanhToanNgay;
                                string ngaylap = new Common.Utilities().XuLy(2, tl[j].Ngaytra.ToShortDateString());
                                Entities.CongNo cn = new Entities.CongNo(ngaylap, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi,
                                    Format(double.Parse(tl[j].ThanhToanNgay)), Format(double.Parse(tl[j].TienBoiThuong)), tl[j].GhiChu, "KHTL");
                                hienthi.Add(cn);
                            }
                        }
                        // phiếu thanh toán của nhà cung cấp
                        for (int j = 0; j < phieuttncc.Length; j++)
                        {
                            if (phieuttncc[j].MaNCC == ncc[i].MaNhaCungCap)
                            {
                                double tienthanhtoan = 0;
                                for (int k = 0; k < chitietphieuttncc.Length; k++)
                                {
                                    if (phieuttncc[j].MaPhieuTTNCC == chitietphieuttncc[k].MaPhieuTTNCC)
                                    {
                                        phatsinhno += Convert.ToDouble(chitietphieuttncc[k].ThanhToan.ToString());
                                        tienthanhtoan += Convert.ToDouble(chitietphieuttncc[k].ThanhToan.ToString());
                                    }
                                }
                                string ngaylap = new Common.Utilities().XuLy(2, phieuttncc[j].NgayLap.ToShortDateString());
                                Entities.CongNo cn = new Entities.CongNo(ngaylap, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi,
                                    "0", Format(tienthanhtoan), phieuttncc[j].GhiChu, "PhieuThu");
                                hienthi.Add(cn);
                            }
                        }
                        sdck = sddk + phatsinhco - phatsinhno;
                        Entities.SoDuCongNo sdcnNCC = new Entities.SoDuCongNo("UpdateTrangThai", maSoDuCongNo, ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi, sdck.ToString(), Convert.ToDateTime(cbbthang.Text + "/01/" + cbbnam.Text), true);
                        Entities.CongNo cnncc = new Entities.CongNo(ncc[i].MaNhaCungCap, ncc[i].TenNhaCungCap, ncc[i].DiaChi,
                            Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck));
                        mangchitiet.Add(sdcnNCC);
                        congnoncc.Add(cnncc);
                        soluongncc++;
                    }
                    sddk = phatsinhno = phatsinhco = 0;
                    // tính toán của mảng nhà cung cấp
                    int count = congnoncc.ToArray().Length;
                    Entities.CongNo cnNCC = new Entities.CongNo();
                    if (count == 1)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            sdck = sddk + phatsinhco - phatsinhno;
                            cnNCC = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                        }

                        congnoncc.Add(cnNCC);
                    }
                    else
                    {
                        for (int i = 0; i < count; i++)
                        {
                            phatsinhco += Convert.ToDouble(congnoncc[i].PhatSinhCo);
                            phatsinhno += Convert.ToDouble(congnoncc[i].PhatSinhNo);
                            sddk += double.Parse(congnoncc[i].DuDauKy);
                            sdck = sddk + phatsinhco - phatsinhno;
                            cnNCC = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                        }
                        congnoncc.Add(cnNCC);
                    }
                }
                if (cbbdoituong.SelectedIndex == 0)
                {
                    soluong = 0;
                    int sl = 0;
                    Entities.CongNo[] sdcn = new Entities.CongNo[congnokh.ToArray().Length];
                    for (int i = 0; i < congnokh.ToArray().Length - 1; i++)
                    {
                        double dauky = Convert.ToDouble(congnokh[i].DuDauKy);
                        double cuoiky = Convert.ToDouble(congnokh[i].DuCuoiKy);
                        double psco = Convert.ToDouble(congnokh[i].PhatSinhCo);
                        double psno = Convert.ToDouble(congnokh[i].PhatSinhNo);
                        if (dauky == 0 && cuoiky == 0 && psco == 0 && psno == 0)
                        {
                            soluong++;
                        }
                        else
                        {
                            sdcn[sl] = congnokh[i];
                            sl++;
                        }
                    }
                    Entities.CongNo[] sdcn1 = new Entities.CongNo[sl + 1];
                    for (int i = 0; i < sdcn1.Length; i++)
                    {
                        if (i < sdcn1.Length - 1)
                            sdcn1[i] = sdcn[i];
                        else
                            sdcn1[i] = congnokh[congnokh.ToArray().Length - 1];

                    }
                    dtgvcongno.DataSource = sdcn1;
                    fixKH();
                }
                else
                {
                    soluong = 0;
                    int sl = 0;
                    Entities.CongNo[] sdcn = new Entities.CongNo[congnoncc.ToArray().Length];
                    for (int i = 0; i < congnoncc.ToArray().Length - 1; i++)
                    {
                        double dauky = Convert.ToDouble(congnoncc[i].DuDauKy);
                        double cuoiky = Convert.ToDouble(congnoncc[i].DuCuoiKy);
                        double psco = Convert.ToDouble(congnoncc[i].PhatSinhCo);
                        double psno = Convert.ToDouble(congnoncc[i].PhatSinhNo);
                        if (dauky == 0 && cuoiky == 0 && psco == 0 && psno == 0)
                        {
                            soluong++;
                        }
                        else
                        {
                            sdcn[sl] = congnoncc[i];
                            sl++;
                        }
                    }
                    Entities.CongNo[] sdcn1 = new Entities.CongNo[sl + 1];
                    for (int i = 0; i < sdcn1.Length; i++)
                    {
                        Entities.TongHopCongNo cn = new Entities.TongHopCongNo();
                        if (i < sdcn1.Length - 1)
                        {
                            sdcn1[i] = sdcn[i];
                        }
                        else
                        {
                            sdcn1[i] = congnoncc[congnoncc.ToArray().Length - 1];
                        }

                    }

                    Entities.TongHopCongNo cn1;
                    congNoList = new List<Entities.TongHopCongNo>();
                    foreach (Entities.CongNo item in sdcn1)
                    {
                        cn1 = new Entities.TongHopCongNo();
                        cn1.MaDoiTuong = item.MaDoiTuong;
                        cn1.TenDoiTuong = item.TenDoiTuong;
                        cn1.DiaChi = item.DiaChi;
                        cn1.PhatSinhNo = double.Parse(item.PhatSinhNo);
                        cn1.PhatSinhCo = double.Parse(item.PhatSinhCo);
                        cn1.DuDauKy = double.Parse(item.DuDauKy);
                        cn1.DuCuoiKy = double.Parse(item.DuCuoiKy);
                        if (!string.IsNullOrEmpty(item.MaDoiTuong))
                            congNoList.Add(cn1);
                    }
                    dtgvcongno.DataSource = sdcn1;
                    fixNCC();
                }

                dtgvcongno.Rows[dtgvcongno.RowCount - 1].DefaultCellStyle.Font = new Font(dtgvcongno.DefaultCellStyle.Font, FontStyle.Bold);
            }
            catch
            {
            }
            finally
            {

            }
        }
예제 #11
0
        public void ChiTietTheoKhachHang(string maKhachHang)
        {
            try
            {
                congnokh1 = new List<Entities.CongNo>();
                int soluong = 0;
                int sotang = 0;
                phatsinhco = 0;
                phatsinhno = 0;
                sdck = sddk = 0;

                bb1 = new List<Entities.HDBanHang>();
                ptcKH = new List<Entities.PhieuThu>();
                khtl1 = new List<Entities.KhachHangTraLai>();
                phieuttcuakh1 = new List<Entities.PhieuTTCuaKH>();
                congnochitietkh = new List<Entities.CongNo>();
                // lấy thông tin của khách hàng
                string tenkh = "";
                string diachi = "";
                for (int j = 0; j < kh.Length; j++)
                {
                    if (kh[j].MaKH == maKhachHang)
                    {
                        kh1 = kh[j];
                        tenkh = kh[j].Ten;
                        diachi = kh[j].DiaChi;
                        break;
                    }
                }
                for (int j = 0; j < hienthi1.Length; j++)
                {
                    if (hienthi1[j].MaDoiTuong == maKhachHang)
                    {
                        sddk = Double.Parse(hienthi1[j].SoDuDauKy);
                        break;
                    }
                }
                // bán buôn
                soluong = 0;
                sotang = 0;
                for (int j = 0; j < bb.Length; j++)
                {
                    if (bb[j].MaKhachHang == maKhachHang)
                    {
                        Entities.CongNo cn = null;
                        string ngay = new Common.Utilities().XuLy(2, bb[j].NgayBan.ToShortDateString());
                        double tongTienThanhToan = double.Parse(bb[j].TongTienThanhToan);
                        double thanhToanNgay = double.Parse(bb[j].ThanhToanKhiLapPhieu);
                        if (thanhToanNgay > tongTienThanhToan)
                            cn = new Entities.CongNo(ngay, maKhachHang, tenkh, diachi, "0",
                          tongTienThanhToan.ToString(), tongTienThanhToan.ToString(), "0", bb[j].GhiChu, "BanBuon", "0", bb[j].MaHDBanHang);
                        else
                            cn = new Entities.CongNo(ngay, maKhachHang, tenkh, diachi, "0",
                          tongTienThanhToan.ToString(), thanhToanNgay.ToString(), "0", bb[j].GhiChu, "BanBuon", "0", bb[j].MaHDBanHang);
                        congnochitietkh.Add(cn);
                        bb1.Add(bb[j]);
                    }
                }

                // Phieu thu
                for (int j = 0; j < phieuThuChi.Length; j++)
                {
                    try
                    {
                        string month1 = phieuThuChi[j].NgayLap.Month.ToString();
                        string year1 = phieuThuChi[j].NgayLap.Year.ToString();

                        if (phieuThuChi[j].DoiTuong.Equals(maKhachHang) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Thu".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year)
                        {
                            string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString());
                            Entities.CongNo cn = new Entities.CongNo(ngaylap, maKhachHang, tenkh, diachi, "0",
                               "0", Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), "0", phieuThuChi[j].GhiChu, "Thu", "0", phieuThuChi[j].MaPhieuThu);
                            congnochitietkh.Add(cn);
                            ptcKH.Add(phieuThuChi[j]);
                        }
                    }
                    catch (Exception)
                    { }
                }

                // Phieu chi
                for (int j = 0; j < phieuThuChi.Length; j++)
                {
                    try
                    {
                        string month1 = phieuThuChi[j].NgayLap.Month.ToString();
                        string year1 = phieuThuChi[j].NgayLap.Year.ToString();

                        if (phieuThuChi[j].DoiTuong.Equals(maKhachHang) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Chi".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year)
                        {
                            string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString());
                            Entities.CongNo cn = new Entities.CongNo(ngaylap, maKhachHang, tenkh, diachi, "0",
                               Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), "0", "0", phieuThuChi[j].GhiChu, "Chi", "0", phieuThuChi[j].MaPhieuThu);
                            congnochitietkh.Add(cn);
                            ptcKH.Add(phieuThuChi[j]);
                        }
                    }
                    catch (Exception)
                    { }
                }

                // khách hàng trả lại
                sotang = 0;
                for (int j = 0; j < khtl.Length; j++)
                {
                    if (khtl[j].MaKhachHang == maKhachHang)
                    {
                        Entities.CongNo cn = null;
                        string ngay = new Common.Utilities().XuLy(2, khtl[j].NgayNhap.ToShortDateString());
                        double tongTienThanhToan = double.Parse(khtl[j].TienBoiThuong);
                        double thanhToanNgay = double.Parse(khtl[j].ThanhToanNgay);
                        if (thanhToanNgay > tongTienThanhToan)
                            cn = new Entities.CongNo(ngay, maKhachHang, tenkh, diachi, "0",
                           tongTienThanhToan.ToString(), tongTienThanhToan.ToString(), "0", khtl[j].GhiChu, "KHTL", "0", khtl[j].MaKhachHangTraLai);
                        else
                            cn = new Entities.CongNo(ngay, maKhachHang, tenkh, diachi, "0",
                            thanhToanNgay.ToString(), tongTienThanhToan.ToString(), "0", khtl[j].GhiChu, "KHTL", "0", khtl[j].MaKhachHangTraLai);
                        congnochitietkh.Add(cn);
                        khtl1.Add(khtl[j]);
                    }
                }
                // phiếu thanh toán của khách hàng
                sotang = 0;
                for (int j = 0; j < phieuttcuakh.Length; j++)
                {
                    if (phieuttcuakh[j].MaKhachHang == maKhachHang)
                    {
                        double tienthanhtoan = 0;
                        for (int k = 0; k < chitietphieuttcuakh.Length; k++)
                        {
                            if (phieuttcuakh[j].MaPhieuTTCuaKH == chitietphieuttcuakh[k].MaPhieuTTCuaKH)
                            {
                                tienthanhtoan += Convert.ToDouble(chitietphieuttcuakh[k].ThanhToan.ToString());
                            }
                        }
                        string ngay = new Common.Utilities().XuLy(2, phieuttcuakh[j].NgayLap.ToShortDateString());
                        Entities.CongNo cn = new Entities.CongNo(ngay, maKhachHang, tenkh, diachi, "0", "0",
                            Format(tienthanhtoan), "0", phieuttcuakh[j].GhiChu, "PhieuTTCuaKH", "0", phieuttcuakh[j].MaPhieuTTCuaKH);
                        congnochitietkh.Add(cn);
                        phieuttcuakh1.Add(phieuttcuakh[j]);
                    }
                }
                phatsinhno = phatsinhco = 0;
                // tính toán của mảng khách hàng
                Entities.CongNo cnTong = new Entities.CongNo();
                for (int j = 0; j < congnochitietkh.ToArray().Length; j++)
                {
                    phatsinhco += Convert.ToDouble(congnochitietkh[j].PhatSinhCo);
                    phatsinhno += Convert.ToDouble(congnochitietkh[j].PhatSinhNo);
                    sdck = sddk + phatsinhno - phatsinhco;
                    cnTong = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                }

                congnochitietkh.Add(cnTong);

            }
            catch
            {
            }
        }
예제 #12
0
        public void SelectSoDuCongNo()
        {
            try
            {
                bool loaiDoiTuong = false;
                if (cbbdoituong.SelectedIndex == 0)
                    loaiDoiTuong = false;
                else
                    loaiDoiTuong = true;
                cl = new Server_Client.Client();
                // gán TCPclient
                this.client1 = cl.Connect(Luu.IP, Luu.Ports);
                // khởi tạo biến truyền vào với hàm khởi tạo
                Entities.SoDuCongNo[] pt = new Entities.SoDuCongNo[1];
                pt[0] = new Entities.SoDuCongNo("Select");
                // khởi tạo mảng đối tượng để hứng giá trị
                clientstrem = cl.SerializeHepper(this.client1, "CongNo", pt);
                Entities.CongNo[] hienthi = new Entities.CongNo[1];
                // đổ mảng đối tượng vào datagripview
                hienthi1 = (Entities.SoDuCongNo[])cl.DeserializeHepper1(clientstrem, hienthi);
                if (hienthi1 == null)
                {
                    hienthi1 = new Entities.SoDuCongNo[0];
                    return;
                }
                year = cbbnam.Text;
                month = cbbthang.Text;
                int sotang = 0;
                Entities.SoDuCongNo[] sq = new Entities.SoDuCongNo[hienthi1.Length];
                for (int i = 0; i < sq.Length; i++)
                {
                    string namkt = hienthi1[i].NgayKetChuyen.Year.ToString();
                    string thangkt = hienthi1[i].NgayKetChuyen.Month.ToString();

                    if (namkt == year && thangkt == month && hienthi1[i].LoaiDoiTuong == loaiDoiTuong)
                    {
                        sq[sotang] = hienthi1[i];
                        sotang++;
                    }

                }
                if (sotang != 0)
                {
                    hienthi1 = new Entities.SoDuCongNo[sotang];
                    for (int i = 0; i < sotang; i++)
                    {
                        hienthi1[i] = new Entities.SoDuCongNo("", sq[i].MaSoDuCongNo, sq[i].MaDoiTuong, sq[i].TenDoiTuong, sq[i].DiaChi, sq[i].SoDuDauKy);
                    }
                }
                else
                    hienthi1 = new Entities.SoDuCongNo[0];
            }
            catch
            {
            }
            finally
            {

            }
        }
예제 #13
0
        public void ChiTietNhaCungCap(string maNhaCungCap)
        {
            try
            {
                congnoncc2 = new List<Entities.CongNo>();
                int soluong = 0;
                int sotang = 0;
                phatsinhco = 0;
                phatsinhno = 0;
                sdck = sddk = 0;
                phatsinhco = 0;
                phatsinhno = 0;

                hdn2 = new List<Entities.HoaDonNhap>();
                tlncc2 = new List<Entities.TraLaiNCC>();
                phieuttncc2 = new List<Entities.PhieuTTNCC>();
                congnochitietncc2 = new List<Entities.CongNo>();
                ptcNCC = new List<Entities.PhieuThu>();

                // lấy thông tin của Nhà cung cấp
                string tenncc = "";
                string diachi = "";
                for (int j = 0; j < ncc.Length; j++)
                {
                    if (ncc[j].MaNhaCungCap == maNhaCungCap)
                    {
                        ncc2 = ncc[j];
                        tenncc = ncc[j].TenNhaCungCap;
                        diachi = ncc[j].DiaChi;
                        break;
                    }
                }
                for (int j = 0; j < hienthi1.Length; j++)
                {
                    if (hienthi1[j].MaDoiTuong == maNhaCungCap)
                    {
                        sddk = Double.Parse(hienthi1[j].SoDuDauKy);
                        break;
                    }
                }
                // Hóa đơn nhập
                for (int j = 0; j < hdn.Length; j++)
                {
                    if (hdn[j].MaNhaCungCap == maNhaCungCap)
                    {
                        double a = Convert.ToDouble(hdn[j].TongTien);
                        double b = Convert.ToDouble(hdn[j].ThanhToanNgay);
                        if (b > a)
                        {
                            b = a;
                        }
                        string ngay = new Common.Utilities().XuLy(2, hdn[j].NgayNhap.ToShortDateString());
                        Entities.CongNo cn = new Entities.CongNo(ngay, maNhaCungCap, tenncc, diachi, "0",
                           Format(b), Format(a), "0", hdn[j].GhiChu, "HoaDonNhap", "0", hdn[j].MaHoaDonNhap);
                        congnochitietncc2.Add(cn);
                        hdn2.Add(hdn[j]);
                    }
                }

                // Phieu thu
                for (int j = 0; j < phieuThuChi.Length; j++)
                {
                    try
                    {
                        string month1 = phieuThuChi[j].NgayLap.Month.ToString();
                        string year1 = phieuThuChi[j].NgayLap.Year.ToString();

                        if (phieuThuChi[j].DoiTuong.Equals(maNhaCungCap) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Thu".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year)
                        {
                            string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString());
                            Entities.CongNo cn = new Entities.CongNo(ngaylap, maNhaCungCap, tenncc, diachi, "0",
                               "0", Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), "0", phieuThuChi[j].GhiChu, "Thu", "0", phieuThuChi[j].MaPhieuThu);
                            congnochitietncc2.Add(cn);
                            ptcNCC.Add(phieuThuChi[j]);
                        }
                    }
                    catch (Exception)
                    { }
                }

                // Phieu chi
                for (int j = 0; j < phieuThuChi.Length; j++)
                {
                    try
                    {
                        string month1 = phieuThuChi[j].NgayLap.Month.ToString();
                        string year1 = phieuThuChi[j].NgayLap.Year.ToString();

                        if (phieuThuChi[j].DoiTuong.Equals(maNhaCungCap) && phieuThuChi[j].LoaiPhieu.ToUpper().Equals("Chi".ToUpper()) && phieuThuChi[j].Deleted == false && month1 == month && year1 == year)
                        {
                            string ngaylap = new Common.Utilities().XuLy(2, phieuThuChi[j].NgayLap.ToShortDateString());
                            Entities.CongNo cn = new Entities.CongNo(ngaylap, maNhaCungCap, tenncc, diachi, "0",
                               Format(double.Parse(phieuThuChi[j].TongTienThanhToan)), "0", "0", phieuThuChi[j].GhiChu, "Chi", "0", phieuThuChi[j].MaPhieuThu);
                            congnochitietncc2.Add(cn);
                            ptcNCC.Add(phieuThuChi[j]);
                        }
                    }
                    catch (Exception)
                    { }
                }

                // trả lại nhà cung cấp
                sotang = 0;
                for (int j = 0; j < tl.Length; j++)
                {
                    if (tl[j].MaNCC == maNhaCungCap)
                    {
                        Entities.CongNo cn = null;
                        string ngay = new Common.Utilities().XuLy(2, tl[j].Ngaytra.ToShortDateString());
                        double tongTienThanhToan = double.Parse(tl[j].TienBoiThuong);
                        double thanhToanNgay = double.Parse(tl[j].ThanhToanNgay);
                        if (thanhToanNgay > tongTienThanhToan)
                            cn = new Entities.CongNo(ngay, maNhaCungCap, tenncc, diachi, "0",
                            tongTienThanhToan.ToString(), tongTienThanhToan.ToString(), "0", tl[j].GhiChu, "TLNCC", "0", tl[j].MaHDTraLaiNCC);
                        else
                            cn = new Entities.CongNo(ngay, maNhaCungCap, tenncc, diachi, "0",
                               tongTienThanhToan.ToString(), thanhToanNgay.ToString(), "0", tl[j].GhiChu, "TLNCC", "0", tl[j].MaHDTraLaiNCC);
                        congnochitietncc2.Add(cn);
                        tlncc2.Add(tl[j]);
                    }
                }
                // phiếu thanh toán nhà cung cấp
                for (int j = 0; j < phieuttncc.Length; j++)
                {
                    if (phieuttncc[j].MaNCC == maNhaCungCap)
                    {
                        double tienthanhtoan = 0;
                        for (int k = 0; k < chitietphieuttncc.Length; k++)
                        {
                            if (phieuttncc[j].MaPhieuTTNCC == chitietphieuttncc[k].MaPhieuTTNCC)
                            {
                                tienthanhtoan += Convert.ToDouble(chitietphieuttncc[k].ThanhToan.ToString());
                            }
                        }
                        string ngay = new Common.Utilities().XuLy(2, phieuttncc[j].NgayLap.ToShortDateString());
                        Entities.CongNo cn = new Entities.CongNo(ngay, maNhaCungCap, tenncc, diachi, "0",
                             Format(tienthanhtoan), "0", "0", phieuttncc[j].GhiChu, "PhieuTTNCC", "0", phieuttncc[j].MaPhieuTTNCC);
                        congnochitietncc2.Add(cn);
                        phieuttncc2.Add(phieuttncc[j]);
                    }
                }
                phatsinhno = phatsinhco = 0;
                // tính toán của mảng nhà cung cấp
                Entities.CongNo tongCnNCC = new Entities.CongNo();
                for (int j = 0; j < congnochitietncc2.ToArray().Length; j++)
                {
                    phatsinhco += Convert.ToDouble(congnochitietncc2[j].PhatSinhCo);
                    phatsinhno += Convert.ToDouble(congnochitietncc2[j].PhatSinhNo);
                    sdck = sddk + phatsinhco - phatsinhno;
                    tongCnNCC = new Entities.CongNo("Tổng cộng", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), string.Empty);
                }
                congnochitietncc2.Add(tongCnNCC);
            }
            catch
            {
            }
        }
예제 #14
0
        public frmChiTietCongNo(Entities.CongNo[] congnochitietncc, Entities.PhieuThu[] ptc,
            Entities.HoaDonNhap[] hdn1, Entities.TraLaiNCC[] tlncc1, Entities.NhaCungCap ncc1, Entities.PhieuTTNCC[] phieuttncc1, string sddk, string sdck)
        {
            InitializeComponent();
            congnochitiet = new List<Entities.CongNo>();
            foreach (Entities.CongNo item in congnochitietncc)
            {
                if (!string.IsNullOrEmpty(item.MaDoiTuong))
                    this.congnochitiet.Add(item);
            }

            this.hdn1 = hdn1;
            this.tlncc1 = tlncc1;
            this.ncc1 = ncc1;
            this.ptc = ptc;
            this.phieuttncc1 = phieuttncc1;
            txtducuoiky.Text = sdck;
            txtdudauky.Text = sddk;
            lbma.Text = "Mã nhà cung cấp:";
            lbten.Text = "Tên nhà cung cấp:";
            grbthongtin.Text = "Thông tin nhà cung cấp";
            lbhienthidiachi.Text = ncc1.DiaChi;
            lbhienthima.Text = ncc1.MaNhaCungCap;
            lbhienthiten.Text = ncc1.TenNhaCungCap;
            Entities.CongNo cnNCC = new Entities.CongNo();

            if (Thu() == 0 && Chi() == 0)
                cnNCC = new Entities.CongNo("Tổng Cộng", "", "0", "0", "");
            else if (Thu() == 0 && Chi() != 0)
                cnNCC = new Entities.CongNo("Tổng Cộng", "", "0", Format(Chi()), "");
            else if (Thu() != 0 && Chi() == 0)
                cnNCC = new Entities.CongNo("Tổng Cộng", "", Format(Thu()), "0", "");
            else if (Thu() != 0 && Chi() != 0)
                cnNCC = new Entities.CongNo("Tổng Cộng", "", Format(Thu()), Format(Chi()), "");
            congnochitiet.Add(cnNCC);
            dtgvhienthi.DataSource = congnochitiet;
            TonNCC();
            fixncc();
            list = GetData(dtgvhienthi);
        }