Ejemplo n.º 1
0
        public void TongTienNhanVien()
        {
            try
            {
                List <Entities.BCLaiLoChiTiet> ctLaiLoList = new List <Entities.BCLaiLoChiTiet>();
                nam   = int.Parse(cbbnam.Text);
                thang = int.Parse(cbbthang.Text);
                for (int i = 0; i < hdbanhang.Length; i++)
                {
                    int namht   = hdbanhang[i].NgayBan.Year;
                    int thanght = hdbanhang[i].NgayBan.Month;
                    Entities.BCLaiLoChiTiet laiLoChiTiet = new Entities.BCLaiLoChiTiet();
                    if (nam == namht && thanght == thang)
                    {
                        laiLoChiTiet.DoanhSo = (double.Parse(hdbanhang[i].TongTienThanhToan) - double.Parse(hdbanhang[i].ThueGTGT)).ToString();
                        laiLoChiTiet.Ngay    = hdbanhang[i].NgayBan.ToShortDateString();
                        double giaVon = 0;
                        for (int j = 0; j < chitiethdbanhang.Length; j++)
                        {
                            if (hdbanhang[i].MaHDBanHang.Equals(chitiethdbanhang[j].MaHDBanHang))
                            {
                                if (LayGiaVonHangHoa(chitiethdbanhang[j]) == 0)
                                {
                                    if (LayGiaVonGoiHang(chitiethdbanhang[j], goihang) == 0)
                                    {
                                        giaVon = 0;
                                    }
                                    else
                                    {
                                        giaVon += LayGiaVonGoiHang(chitiethdbanhang[j], goihang);
                                    }
                                }
                                else
                                {
                                    giaVon += LayGiaVonHangHoa(chitiethdbanhang[j]);
                                }
                            }
                        }

                        laiLoChiTiet.GiaVon = giaVon.ToString();
                        laiLoChiTiet.LaiGop = (double.Parse(laiLoChiTiet.DoanhSo) - double.Parse(laiLoChiTiet.GiaVon)).ToString();
                        ctLaiLoList.Add(laiLoChiTiet);
                    }
                }

                List <string> Ltem = new List <string>();
                foreach (Entities.BCLaiLoChiTiet item in ctLaiLoList)
                {
                    if (!Ltem.Contains(DateTime.Parse(item.Ngay).ToShortDateString()))
                    {
                        Ltem.Add(DateTime.Parse(item.Ngay).ToShortDateString());
                    }
                }
                List <Entities.BCLaiLoChiTiet> Fixhienthi = new List <Entities.BCLaiLoChiTiet>();
                int ii = 0;
                foreach (string item1 in Ltem)
                {
                    Entities.BCLaiLoChiTiet bientam = new Entities.BCLaiLoChiTiet();
                    bientam.HanhDong = ii.ToString();
                    ii++;
                    double doanhso = 0; double giavon = 0; double laigop = 0;
                    foreach (Entities.BCLaiLoChiTiet item2 in ctLaiLoList)
                    {
                        if (item2.Ngay.Equals(item1))
                        {
                            bientam.Ngay = item2.Ngay;
                            doanhso     += double.Parse(item2.DoanhSo);
                            giavon      += double.Parse(item2.GiaVon);
                            laigop      += double.Parse(item2.LaiGop);
                        }
                    }
                    bientam.DoanhSo = new Common.Utilities().FormatMoney(doanhso);
                    bientam.GiaVon  = new Common.Utilities().FormatMoney(giavon);
                    bientam.LaiGop  = new Common.Utilities().FormatMoney(laigop);
                    Fixhienthi.Add(bientam);
                }

                /// Lay Datasour cho BC.
                foreach (Entities.BCLaiLoChiTiet item in (Entities.BCLaiLoChiTiet[])Fixhienthi.ToArray())
                {
                    try
                    {
                        DateTime         ngay    = DateTime.Parse(DateTime.Parse(item.Ngay).ToShortDateString());
                        double           doanhSo = double.Parse(item.DoanhSo);
                        double           giaVon  = double.Parse(item.GiaVon);
                        double           laiGop  = double.Parse(item.LaiGop);
                        Entities.BCLaiLo laiLo   = new Entities.BCLaiLo(ngay, doanhSo, giaVon, laiGop);
                        hienthibaocao.Add(laiLo);
                    }
                    catch (Exception)
                    { }
                }

                Entities.BCLaiLoChiTiet tongCong = new Entities.BCLaiLoChiTiet();
                double tongDoanhSo = 0;
                double tongGiaVon  = 0;
                double tongLaiGop  = 0;
                foreach (Entities.BCLaiLoChiTiet item in (Entities.BCLaiLoChiTiet[])Fixhienthi.ToArray())
                {
                    tongDoanhSo += double.Parse(item.DoanhSo);
                    tongGiaVon  += double.Parse(item.GiaVon);
                    tongLaiGop  += double.Parse(item.LaiGop);
                }
                tongCong.DoanhSo = new Common.Utilities().FormatMoney(tongDoanhSo);
                tongCong.GiaVon  = new Common.Utilities().FormatMoney(tongGiaVon);
                tongCong.LaiGop  = new Common.Utilities().FormatMoney(tongLaiGop);
                tongCong.Ngay    = "Tổng Cộng:";
                Fixhienthi.Add(tongCong);

                dtgvhienthi.DataSource = (Entities.BCLaiLoChiTiet[])Fixhienthi.ToArray();
                if (Fixhienthi.ToArray().Length > 0)
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                }
                else
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                }
            }
            catch
            {
            }
            finally
            {
                fix();
            }
        }
Ejemplo n.º 2
0
        public void TongTienNhanVien()
        {
            try
            {
                List<Entities.BCLaiLoChiTiet> ctLaiLoList = new List<Entities.BCLaiLoChiTiet>();
                nam = int.Parse(cbbnam.Text);
                thang = int.Parse(cbbthang.Text);
                for (int i = 0; i < hdbanhang.Length; i++)
                {
                    int namht = hdbanhang[i].NgayBan.Year;
                    int thanght = hdbanhang[i].NgayBan.Month;
                    Entities.BCLaiLoChiTiet laiLoChiTiet = new Entities.BCLaiLoChiTiet();
                    if (nam == namht && thanght == thang)
                    {
                        laiLoChiTiet.DoanhSo = (double.Parse(hdbanhang[i].TongTienThanhToan) - double.Parse(hdbanhang[i].ThueGTGT)).ToString();
                        laiLoChiTiet.Ngay = hdbanhang[i].NgayBan.ToShortDateString();
                        double giaVon = 0;
                        for (int j = 0; j < chitiethdbanhang.Length; j++)
                        {
                            if (hdbanhang[i].MaHDBanHang.Equals(chitiethdbanhang[j].MaHDBanHang))
                            {
                                if (LayGiaVonHangHoa(chitiethdbanhang[j]) == 0)
                                {
                                    if (LayGiaVonGoiHang(chitiethdbanhang[j], goihang) == 0)
                                    {
                                        giaVon = 0;
                                    }
                                    else
                                    {
                                        giaVon += LayGiaVonGoiHang(chitiethdbanhang[j], goihang);
                                    }

                                }
                                else
                                {
                                    giaVon += LayGiaVonHangHoa(chitiethdbanhang[j]);
                                }
                            }
                        }

                        laiLoChiTiet.GiaVon = giaVon.ToString();
                        laiLoChiTiet.LaiGop = (double.Parse(laiLoChiTiet.DoanhSo) - double.Parse(laiLoChiTiet.GiaVon)).ToString();
                        ctLaiLoList.Add(laiLoChiTiet);
                    }

                }

                List<string> Ltem = new List<string>();
                foreach (Entities.BCLaiLoChiTiet item in ctLaiLoList)
                {
                    if (!Ltem.Contains(DateTime.Parse(item.Ngay).ToShortDateString()))
                    {
                        Ltem.Add(DateTime.Parse(item.Ngay).ToShortDateString());
                    }
                }
                List<Entities.BCLaiLoChiTiet> Fixhienthi = new List<Entities.BCLaiLoChiTiet>();
                int ii = 0;
                foreach (string item1 in Ltem)
                {
                    Entities.BCLaiLoChiTiet bientam = new Entities.BCLaiLoChiTiet();
                    bientam.HanhDong = ii.ToString();
                    ii++;
                    double doanhso = 0; double giavon = 0; double laigop = 0;
                    foreach (Entities.BCLaiLoChiTiet item2 in ctLaiLoList)
                    {
                        if (item2.Ngay.Equals(item1))
                        {
                            bientam.Ngay = item2.Ngay;
                            doanhso += double.Parse(item2.DoanhSo);
                            giavon += double.Parse(item2.GiaVon);
                            laigop += double.Parse(item2.LaiGop);
                        }
                    }
                    bientam.DoanhSo = new Common.Utilities().FormatMoney(doanhso);
                    bientam.GiaVon = new Common.Utilities().FormatMoney(giavon);
                    bientam.LaiGop = new Common.Utilities().FormatMoney(laigop);
                    Fixhienthi.Add(bientam);
                }

                /// Lay Datasour cho BC.
                foreach (Entities.BCLaiLoChiTiet item in (Entities.BCLaiLoChiTiet[])Fixhienthi.ToArray())
                {
                    try
                    {
                        DateTime ngay = DateTime.Parse(DateTime.Parse(item.Ngay).ToShortDateString());
                        double doanhSo = double.Parse(item.DoanhSo);
                        double giaVon = double.Parse(item.GiaVon);
                        double laiGop = double.Parse(item.LaiGop);
                        Entities.BCLaiLo laiLo = new Entities.BCLaiLo(ngay, doanhSo, giaVon, laiGop);
                        hienthibaocao.Add(laiLo);
                    }
                    catch (Exception)
                    { }
                }

                Entities.BCLaiLoChiTiet tongCong = new Entities.BCLaiLoChiTiet();
                double tongDoanhSo = 0;
                double tongGiaVon = 0;
                double tongLaiGop = 0;
                foreach (Entities.BCLaiLoChiTiet item in (Entities.BCLaiLoChiTiet[])Fixhienthi.ToArray())
                {
                    tongDoanhSo += double.Parse(item.DoanhSo);
                    tongGiaVon += double.Parse(item.GiaVon);
                    tongLaiGop += double.Parse(item.LaiGop);
                }
                tongCong.DoanhSo = new Common.Utilities().FormatMoney(tongDoanhSo);
                tongCong.GiaVon = new Common.Utilities().FormatMoney(tongGiaVon);
                tongCong.LaiGop = new Common.Utilities().FormatMoney(tongLaiGop);
                tongCong.Ngay = "Tổng Cộng:";
                Fixhienthi.Add(tongCong);

                dtgvhienthi.DataSource = (Entities.BCLaiLoChiTiet[])Fixhienthi.ToArray();
                if (Fixhienthi.ToArray().Length > 0)
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = true;
                }
                else
                {
                    tsslexcel.Enabled = tsslPdf.Enabled = tsslWord.Enabled = tsslchitiet.Enabled = false;
                }
            }
            catch
            {
            }
            finally
            {
                fix();
            }
        }