Exemplo n.º 1
0
        /// <summary>
        /// xử lý hiển thị
        /// </summary>
        public void HienThiTongThe()
        {
            try
            {
                phatsinhno = phatsinhco = sdck = sddk = 0;
                try
                {
                    hienthi = new Entities.SoQuy[pt.Length + pc.Length + bl.Length + bb.Length + hdn.Length + kh.Length + tl.Length + pttkh.Length + pttncc.Length + 1];
                }
                catch { }
                if (kt == false)
                {
                    for (int i = 0; i < sodu.Length; i++)
                    {
                        string monthsodu = sodu[i].NgayKetChuyen.Month.ToString();
                        string yearsodu  = sodu[i].NgayKetChuyen.Year.ToString();
                        if (month == monthsodu && year == yearsodu)
                        {
                            sddk = Convert.ToDouble(sodu[i].SoDuDauKy);
                            break;
                        }
                    }
                }
                int soluong = 0;

                // Phiếu Thu
                for (int i = 0; i < pt.Length; i++)
                {
                    string month1 = pt[i].NgayLap.Month.ToString();
                    string year1  = pt[i].NgayLap.Year.ToString();
                    if (month == month1 && year == year1)
                    {
                        phatsinhno = Convert.ToDouble(pt[i].TongTienThanhToan);
                        string ngaylap = new Common.Utilities().XuLy(2, pt[i].NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy(ngaylap, pt[i].MaPhieuThu, "1111", "Tiền mặt việt nam",
                                                              Format(phatsinhno), Format(phatsinhco), pt[i].GhiChu, "PhieuThu");
                        soluong++;
                    }
                }
                phatsinhno = phatsinhco = 0;
                // Phiếu Chi
                for (int i = 0; i < pc.Length; i++)
                {
                    string month1 = pc[i].NgayLap.Month.ToString();
                    string year1  = pc[i].NgayLap.Year.ToString();
                    if (month == month1 && year == year1)
                    {
                        phatsinhco = Convert.ToDouble(pc[i].TongTienThanhToan);
                        string ngaylap = new Common.Utilities().XuLy(2, pc[i].NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy(ngaylap, pc[i].MaPhieuThu, "1111", "Tiền mặt việt nam",
                                                              Format(phatsinhno), Format(phatsinhco), pc[i].GhiChu, "PhieuChi");
                        soluong++;
                    }
                }
                phatsinhno = phatsinhco = 0;
                // Bán Lẻ
                for (int i = 0; i < bl.Length; i++)
                {
                    string month1 = bl[i].NgayBan.Month.ToString();
                    string year1  = bl[i].NgayBan.Year.ToString();
                    if (month == month1 && year == year1)
                    {
                        List <double> bientam = TienIch.TinhDoanhThu(Convert.ToDouble(bl[i].TongTienThanhToan), Convert.ToDouble(bl[i].GiaTriThe), Convert.ToDouble(bl[i].GiaTriTheGiaTri));
                        phatsinhno = bientam[3];  //bl[i].ThanhToanNgay
                        string ngaylap = new Common.Utilities().XuLy(2, bl[i].NgayBan.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy(ngaylap, bl[i].MaHDBanHang, "1111", "Tiền mặt việt nam",
                                                              Format(phatsinhno), Format(phatsinhco), bl[i].GhiChu, "BanLe");
                        soluong++;
                    }
                }
                phatsinhno = phatsinhco = 0;
                // Bán Buôn
                for (int i = 0; i < bb.Length; i++)
                {
                    string month1 = bb[i].NgayBan.Month.ToString();
                    string year1  = bb[i].NgayBan.Year.ToString();
                    if (month == month1 && year == year1)
                    {
                        double a = Convert.ToDouble(bb[i].TongTienThanhToan);
                        double b = Convert.ToDouble(bb[i].ThanhToanKhiLapPhieu);
                        if (b > a)
                        {
                            b = a;
                        }
                        phatsinhno = b;
                        string ngaylap = new Common.Utilities().XuLy(2, bb[i].NgayBan.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy(ngaylap, bb[i].MaHDBanHang, "1111", "Tiền mặt việt nam",
                                                              Format(phatsinhno), Format(phatsinhco), bb[i].GhiChu, "BanBuon");
                        soluong++;
                    }
                }
                phatsinhno = phatsinhco = 0;
                // Hóa Đơn Nhập
                for (int i = 0; i < hdn.Length; i++)
                {
                    string month1 = hdn[i].NgayNhap.Month.ToString();
                    string year1  = hdn[i].NgayNhap.Year.ToString();
                    if (month == month1 && year == year1)
                    {
                        double a = Convert.ToDouble(hdn[i].TongTien);
                        double b = Convert.ToDouble(hdn[i].ThanhToanNgay);
                        if (b > a)
                        {
                            b = a;
                        }
                        phatsinhco = b;
                        string ngaylap = new Common.Utilities().XuLy(2, hdn[i].NgayNhap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy(ngaylap, hdn[i].MaHoaDonNhap, "1111", "Tiền mặt việt nam",
                                                              Format(phatsinhno), Format(phatsinhco), hdn[i].GhiChu, "HoaDonNhap");
                        soluong++;
                    }
                }
                phatsinhno = phatsinhco = 0;
                // Khách Hàng Trả Lại
                for (int i = 0; i < kh.Length; i++)
                {
                    string month1 = kh[i].NgayNhap.Month.ToString();
                    string year1  = kh[i].NgayNhap.Year.ToString();
                    double a      = Convert.ToDouble(kh[i].TienBoiThuong);
                    double b      = double.Parse(kh[i].ThanhToanNgay);
                    if (b > a)
                    {
                        b = a;
                    }
                    double a1 = b;
                    if (month == month1 && year == year1)
                    {
                        phatsinhco = a1;
                        string ngaylap = new Common.Utilities().XuLy(2, kh[i].NgayNhap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy(ngaylap, kh[i].MaKhachHangTraLai, "1111", "Tiền mặt việt nam",
                                                              Format(phatsinhno), Format(phatsinhco), kh[i].GhiChu, "KHTL");
                        soluong++;
                    }
                }
                phatsinhno = phatsinhco = 0;
                // Trả Lại Nhà Cung Cấp
                for (int i = 0; i < tl.Length; i++)
                {
                    string month1 = tl[i].Ngaytra.Month.ToString();
                    string year1  = tl[i].Ngaytra.Year.ToString();
                    double a      = Convert.ToDouble(tl[i].TienBoiThuong);
                    double b      = Convert.ToDouble(tl[i].ThanhToanNgay);
                    if (b > a)
                    {
                        b = a;
                    }
                    double a1 = b;
                    if (month == month1 && year == year1)
                    {
                        phatsinhno = a1;
                        string ngaylap = new Common.Utilities().XuLy(2, tl[i].Ngaytra.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy(ngaylap, tl[i].MaHDTraLaiNCC, "1111", "Tiền mặt việt nam",
                                                              Format(phatsinhno), Format(phatsinhco), tl[i].GhiChu, "TLNCC");
                        soluong++;
                    }
                }
                phatsinhno = phatsinhco = 0;
                // Phiếu thanh toán nhà cung cấp
                for (int i = 0; i < pttncc.Length; i++)
                {
                    string month1 = pttncc[i].NgayLap.Month.ToString();
                    string year1  = pttncc[i].NgayLap.Year.ToString();
                    //double a1 = double.Parse(pttncc[i].NoHienThoi);
                    double a1 = TongThanhToanCuaPhieuThanhToan("NCC", pttncc[i].MaPhieuTTNCC);
                    if (month == month1 && year == year1)
                    {
                        phatsinhco = a1;
                        string ngaylap = new Common.Utilities().XuLy(2, pttncc[i].NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy(ngaylap, pttncc[i].MaPhieuTTNCC, "1111", "Tiền mặt việt nam",
                                                              Format(phatsinhno), Format(phatsinhco), pttncc[i].GhiChu, "PTTNCC");
                        soluong++;
                    }
                }
                phatsinhno = phatsinhco = 0;
                // Phiếu thanh toán khách hàng
                for (int i = 0; i < pttkh.Length; i++)
                {
                    string month1 = pttkh[i].NgayLap.Month.ToString();
                    string year1  = pttkh[i].NgayLap.Year.ToString();
                    //double a1 = double.Parse(pttkh[i].NoHienThoi);
                    double a1 = TongThanhToanCuaPhieuThanhToan("KH", pttkh[i].MaPhieuTTCuaKH);
                    if (month == month1 && year == year1)
                    {
                        phatsinhno = a1;
                        string ngaylap = new Common.Utilities().XuLy(2, pttkh[i].NgayLap.ToShortDateString());
                        hienthi[soluong] = new Entities.SoQuy(ngaylap, pttkh[i].MaPhieuTTCuaKH, "1111", "Tiền mặt việt nam",
                                                              Format(phatsinhno), Format(phatsinhco), pttkh[i].GhiChu, "PTTKH");
                        soluong++;
                    }
                }

                phatsinhno = phatsinhco = 0;
                List <Entities.SoQuy> l = new List <Entities.SoQuy>();
                foreach (Entities.SoQuy item in hienthi)
                {
                    if (item != null)
                    {
                        l.Add(item);
                    }
                }
                hienthi = l.ToArray();
                //Tính toán
                if (hienthi.Length == 0)
                {//Chỉ có số dư đầu kỳ
                    if (sddk == 0 && sdck == 0)
                    {
                        soquy = new Entities.SoQuy[0];
                    }
                    else
                    {
                        soquy    = new Entities.SoQuy[1];
                        soquy[0] = new Entities.SoQuy("0", "0", "Tổng Cộng", Format(sddk), Format(sdck));
                    }
                }
                else
                {
                    soquy = new Entities.SoQuy[2];
                    for (int i = 0; i < hienthi.Length; i++)
                    {
                        phatsinhco += Convert.ToDouble(hienthi[i].PhatSinhCo);
                        phatsinhno += Convert.ToDouble(hienthi[i].PhatSinhNo);
                        sdck        = sddk + phatsinhno - phatsinhco;
                        soquy[0]    = new Entities.SoQuy("1111", "Tiền mặt việt nam", Format(sddk), Format(phatsinhno), Format(phatsinhco), Format(sdck), "TongHop");
                    }
                    if (phatsinhno == 0 && phatsinhco == 0)
                    {
                        sdck     = sddk + phatsinhno - phatsinhco;
                        soquy[1] = new Entities.SoQuy("0", "0", "Tổng Cộng", Format(sddk), Format(sdck));
                    }
                    else if (phatsinhno == 0 && phatsinhco != 0)
                    {
                        soquy[1] = new Entities.SoQuy("0", Format(phatsinhco), "Tổng Cộng", Format(sddk), Format(sdck));
                    }
                    else if (phatsinhno != 0 && phatsinhco == 0)
                    {
                        soquy[1] = new Entities.SoQuy(Format(phatsinhno), "0", "Tổng Cộng", Format(sddk), Format(sdck));
                    }
                    else if (phatsinhno != 0 && phatsinhco != 0)
                    {
                        soquy[1] = new Entities.SoQuy(Format(phatsinhno), Format(phatsinhco), "Tổng Cộng", Format(sddk), Format(sdck));
                    }
                    a = soquy[1].DuCuoiKy;
                }
                dtgvsoquy.DataSource = soquy;
            }
            catch
            {
                dtgvsoquy.DataSource = new Entities.SoQuy[0];
            }
            finally
            {
                fix();
            }
        }
 public void TongTienNhanVien(DateTime batdau, DateTime ketthuc)
 {
     try
     {
         int sotang = 0;
         for (int i = 0; i < nv.Length; i++)
         {
             for (int j = 0; j < bcnv.Length; j++)
             {
                 DateTime hientai = bcnv[j].NgayBan;
                 if (hientai.Date >= batdau.Date && hientai.Date <= ketthuc.Date && bcnv[j].MaNhanVien == nv[i].MaNhanVien)
                 {
                     sotang++;
                 }
             }
         }
         Entities.BCDTTheoNhanVien[] bcdt = new Entities.BCDTTheoNhanVien[sotang];
         sotang = 0;
         double tongtien;
         for (int i = 0; i < nv.Length; i++)
         {
             tongtien = 0;
             for (int j = 0; j < bcnv.Length; j++)
             {
                 DateTime hientai = bcnv[j].NgayBan;
                 if (hientai.Date >= batdau.Date && hientai.Date <= ketthuc.Date && bcnv[j].MaNhanVien == nv[i].MaNhanVien)
                 {
                     List <double> bientam = TienIch.TinhDoanhThu(bcnv[j].TongTienThanhToan, bcnv[j].GiaTriThe, bcnv[j].GiaTriTheGiaTri);
                     tongtien += bientam[3];   //bcnv[j].ThanhToanNgay
                 }
             }
             if (tongtien != 0)
             {
                 bcdt[sotang] = new Entities.BCDTTheoNhanVien("", nv[i].MaNhanVien, nv[i].TenNhanVien, new Common.Utilities().FormatMoney(tongtien));
                 sotang++;
             }
         }
         hienthi = new Entities.BCDTTheoNhanVien[sotang];
         for (int i = 0; i < hienthi.Length; i++)
         {
             hienthi[i] = bcdt[i];
         }
         //////////////////////////////////////////////Mrk FIX
         List <Entities.BCDTTheoNhanVien> tem0 = new List <Entities.BCDTTheoNhanVien>();
         double tong0 = 0;
         for (int i = 0; i < bcdt.Length; i++)
         {
             if (bcdt[i] == null)
             {
                 break;
             }
             tong0 += double.Parse(bcdt[i].TongTien.Replace(",", ""));
             tem0.Add(bcdt[i]);
         }
         Entities.BCDTTheoNhanVien tem1 = new Entities.BCDTTheoNhanVien();
         tem1.TongTien    = new Common.Utilities().FormatMoney(tong0);
         tem1.TenNhanVien = "Tổng Cộng: ";
         tem0.Add(tem1);
         //foreach (Entities.BCDTTheoNhanVien item in tem0)
         //{
         //    hienthi[i] = item;
         //}
         //////////////////////////////////////////////////////
         //dtgvhienthi.DataSource = hienthi;
         if (tem0.Count == 1 && tem0[0].TenNhanVien.Equals("Tổng Cộng: "))
         {
             //tem0.Remove(tem0[0]);
             tem0 = new List <Entities.BCDTTheoNhanVien>();
         }
         else if (tem0.Count > 1)
         {
             foreach (Entities.BCDTTheoNhanVien item in tem0)
             {
                 if (item.TenNhanVien.Equals("Tổng Cộng: "))
                 {
                     item.GiaTriThe = 0;
                 }
             }
         }
         dtgvhienthi.DataSource = tem0.ToArray();
         if (bcdt.Length > 0)
         {
             tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
         }
         else
         {
             tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
         }
         fix();
     }
     catch
     {
     }
 }