public static void Create(int InvoiceId)
        {
            ProductInvoiceRepository        productInvoiceRepository        = new Domain.Sale.Repositories.ProductInvoiceRepository(new Domain.Sale.ErpSaleDbContext());
            CommisionRepository             CommisionRepository             = new Domain.Sale.Repositories.CommisionRepository(new Domain.Sale.ErpSaleDbContext());
            CommisionStaffRepository        commisionStaffRepository        = new Domain.Sale.Repositories.CommisionStaffRepository(new Domain.Sale.ErpSaleDbContext());
            UsingServiceLogDetailRepository usingServiceLogDetailRepository = new Domain.Sale.Repositories.UsingServiceLogDetailRepository(new Domain.Sale.ErpSaleDbContext());
            var product_invoice       = productInvoiceRepository.GetAllvwInvoiceDetailsByInvoiceId(InvoiceId).ToList();
            var usingServiceLogDetail = usingServiceLogDetailRepository.GetAllvwUsingServiceLogDetail().Where(x => x.ProductInvoiceId == InvoiceId).ToList();

            foreach (var item in product_invoice)
            {
                if (item.ProductType == "service")
                {
                    //lấy nhân viên làm dịch vụ của hóa đơn ra
                    var user = usingServiceLogDetail.Where(x => x.ServiceInvoiceDetailId == item.Id).OrderBy(x => x.CreatedDate).FirstOrDefault();
                    //kiểm tra xem nhân viên đó có được nhận hoa hồng hay k
                    var setting_commision = CommisionRepository.GetAllCommision().Where(x => x.StaffId == user.StaffId && x.ProductId == item.ProductId).ToList();
                    if (setting_commision.Count() > 0)
                    {
                        var CommisionStaff = new CommisionStaff();
                        CommisionStaff.IsDeleted      = false;
                        CommisionStaff.CreatedUserId  = WebSecurity.CurrentUserId;
                        CommisionStaff.ModifiedUserId = WebSecurity.CurrentUserId;
                        CommisionStaff.StaffId        = user.StaffId.Value;
                        //nếu hoa hồng của nhân viên là % thì dựa vào hóa đơn tính ra số tiền chiết khấu
                        //ngược lại thì dựa vào số tiền chiết khấu tính ra %.
                        if (setting_commision.FirstOrDefault().IsMoney == false)
                        {
                            CommisionStaff.PercentOfCommision = Convert.ToInt32(setting_commision.FirstOrDefault().CommissionValue);
                            CommisionStaff.AmountOfCommision  = (item.Price * item.Quantity) * setting_commision.FirstOrDefault().CommissionValue / 100;
                        }
                        else
                        {
                            CommisionStaff.AmountOfCommision  = setting_commision.FirstOrDefault().CommissionValue;
                            CommisionStaff.PercentOfCommision = Convert.ToInt32(setting_commision.FirstOrDefault().CommissionValue / (item.Price * item.Quantity) * 100);
                        }
                        CommisionStaff.CreatedDate     = DateTime.Now;
                        CommisionStaff.ModifiedDate    = DateTime.Now;
                        CommisionStaff.InvoiceType     = "ProductInvoice";
                        CommisionStaff.InvoiceId       = item.ProductInvoiceId.Value;
                        CommisionStaff.InvoiceDetailId = item.Id;
                        CommisionStaff.BranchId        = item.BranchId;
                        commisionStaffRepository.InsertCommisionStaff(CommisionStaff);
                    }
                }
            }
        }
        public static void CreateCommission(int InvoiceId)
        {
            ProductInvoiceRepository   productInvoiceRepository = new Domain.Sale.Repositories.ProductInvoiceRepository(new Domain.Sale.ErpSaleDbContext());
            CommisionRepository        CommisionRepository      = new Domain.Sale.Repositories.CommisionRepository(new Domain.Sale.ErpSaleDbContext());
            CommisionStaffRepository   commisionStaffRepository = new Domain.Sale.Repositories.CommisionStaffRepository(new Domain.Sale.ErpSaleDbContext());
            ProductOrServiceRepository productRepository        = new Domain.Sale.Repositories.ProductOrServiceRepository(new Domain.Sale.ErpSaleDbContext());
            var product_invoice = productInvoiceRepository.GetAllvwInvoiceDetailsByInvoiceId(InvoiceId).Where(x => x.StaffId != null).ToList();

            foreach (var item in product_invoice)
            {
                var product = productRepository.GetAllvwProductAndService().Where(x => x.Id == item.ProductId).ToList();
                if (product.Count() > 0)
                {
                    var setting_product = product.FirstOrDefault();
                    if (setting_product.DiscountStaff != null && setting_product.DiscountStaff > 0)
                    {
                        var CommisionStaff = new CommisionStaff();
                        CommisionStaff.IsDeleted      = false;
                        CommisionStaff.CreatedUserId  = WebSecurity.CurrentUserId;
                        CommisionStaff.ModifiedUserId = WebSecurity.CurrentUserId;
                        CommisionStaff.StaffId        = item.StaffId.Value;
                        //nếu hoa hồng của nhân viên là % thì dựa vào hóa đơn tính ra số tiền chiết khấu
                        //ngược lại thì dựa vào số tiền chiết khấu tính ra %.
                        if (setting_product.IsMoneyDiscount == null || setting_product.IsMoneyDiscount == false)
                        {
                            CommisionStaff.PercentOfCommision = Convert.ToInt32(setting_product.DiscountStaff);
                            CommisionStaff.AmountOfCommision  = (item.Price * item.Quantity) * setting_product.DiscountStaff / 100;
                        }
                        else
                        {
                            CommisionStaff.AmountOfCommision  = setting_product.DiscountStaff;
                            CommisionStaff.PercentOfCommision = Convert.ToInt32(setting_product.DiscountStaff / (item.Price * item.Quantity) * 100);
                        }
                        CommisionStaff.CreatedDate     = DateTime.Now;
                        CommisionStaff.ModifiedDate    = DateTime.Now;
                        CommisionStaff.InvoiceType     = "ProductInvoice";
                        CommisionStaff.InvoiceId       = item.ProductInvoiceId.Value;
                        CommisionStaff.InvoiceDetailId = item.Id;
                        CommisionStaff.BranchId        = item.BranchId;
                        commisionStaffRepository.InsertCommisionStaff(CommisionStaff);
                    }
                }
            }
        }