Example #1
0
 // DELETE api/<controller>
 public void Delete(Guid ID)
 {
     var service = new Cat_KPIBonusServices();
     var result = service.Remove<Cat_KPIBonusItemEntity>(ID);
 }
Example #2
0
        public DataTable GetReportRevenueForShop(DateTime dateFrom, DateTime dateTo, string orderNumber, string UserLogin, bool isCreateTemplate)
        {
            using (var context = new VnrHrmDataContext())
            {
                string status = string.Empty;
                DataTable table = GetSchemaReportVenueForShop(UserLogin);
                if (isCreateTemplate)
                {
                    return table.ConfigTable();
                }

                var orgServices = new Cat_OrgStructureServices();
                var lstObjOrg = new List<object>();
                lstObjOrg.Add(orderNumber);
                var lstOrgID = orgServices.GetData<Cat_OrgStructureEntity>(lstObjOrg, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, UserLogin, ref status).Select(s => s.ID).ToList();



                var shopServices = new Cat_ShopServices();
                var lstObjShop = new List<object>();
                lstObjShop.Add(null);
                lstObjShop.Add(null);
                lstObjShop.Add(null);
                lstObjShop.Add(1);
                lstObjShop.Add(int.MaxValue - 1);
                var lstShop = shopServices.GetData<Cat_ShopEntity>(lstObjShop, ConstantSql.hrm_cat_sp_get_Shop, UserLogin, ref status).ToList();
                var lstShopID = new List<Guid>();
                if (lstOrgID != null)
                {
                    lstShop = lstShop.Where(s => lstOrgID.Contains(s.OrgStructureID.Value)).ToList();
                }
                var kpiBonusService = new Cat_KPIBonusServices();
                var lstObjKPIBonus = new List<object>();
                lstObjKPIBonus.Add(null);
                lstObjKPIBonus.Add(null);
                lstObjKPIBonus.Add(1);
                lstObjKPIBonus.Add(int.MaxValue - 1);
                var lstKPIBonus = kpiBonusService.GetData<Cat_KPIBonusEntity>(lstObjKPIBonus, ConstantSql.hrm_cat_sp_get_KPIBonus, UserLogin, ref status).ToList();

                var kpiBonusItemServices = new Cat_KPIBonusItemServices();
                var lstObjKPIBonusItem = new List<object>();
                lstObjKPIBonusItem.Add(null);
                lstObjKPIBonusItem.Add(null);
                lstObjKPIBonusItem.Add(1);
                lstObjKPIBonusItem.Add(int.MaxValue - 1);
                var lstKPIBonusItem = kpiBonusItemServices.GetData<Cat_KPIBonusItemEntity>(lstObjKPIBonusItem, ConstantSql.hrm_cat_sp_get_KPIBonusItem, UserLogin, ref status).ToList();

                var revenueForRecordServices = new Sal_RevenueRecordService();
                var lstObjRevenueRecord = new List<object>();
                lstObjRevenueRecord.Add(null);
                lstObjRevenueRecord.Add(null);
                lstObjRevenueRecord.Add(1);
                lstObjRevenueRecord.Add(int.MaxValue - 1);
                var lstRevenueRecord = revenueForRecordServices.GetData<Sal_RevenueRecordEntity>(lstObjRevenueRecord, ConstantSql.hrm_sal_sp_get_RevenueRecord, UserLogin, ref status).Where(s => s.Month.Value.Month == dateFrom.Month && s.Month.Value.Year == dateFrom.Year && s.Month.Value.Month == dateFrom.Month && s.Month.Value.Year == dateFrom.Year).ToList();

                var revenueForShopServices = new Sal_RevenueForShopServices();
                var lstObjRevenueForShop = new List<object>();
                lstObjRevenueForShop.Add(null);
                lstObjRevenueForShop.Add(null);
                lstObjRevenueForShop.Add(null);
                lstObjRevenueForShop.Add(null);
                lstObjRevenueForShop.Add(1);
                lstObjRevenueForShop.Add(int.MaxValue - 1);
                var lstRevenueForShop = revenueForRecordServices.GetData<Sal_RevenueForShopEntity>(lstObjRevenueForShop, ConstantSql.hrm_sal_sp_get_RevenueForShop, UserLogin, ref status).ToList();

                List<object> listModel = new List<object>();
                listModel.AddRange(new object[18]);
                listModel[16] = 1;
                listModel[17] = int.MaxValue - 1;
                List<Hre_ProfileEntity> listProfile = GetData<Hre_ProfileEntity>(listModel, ConstantSql.hrm_hr_sp_get_Profile, UserLogin, ref status).ToList();


                List<ElementFormula> listElementFormula = new List<ElementFormula>();

                foreach (var item in lstShop)
                {
                    #region Lấy các phần tử là Enum
                    Sal_RevenueForShopEntity RevenueForShopItem = new Sal_RevenueForShopEntity();
                    RevenueForShopItem = lstRevenueForShop.Where(m => m.ShopID == item.ID && m.KPIBonusID == lstKPIBonus.Where(t => t.IsTotalRevenue == true).FirstOrDefault().ID && m.DateFrom <= dateTo && m.DateTo >= dateFrom).FirstOrDefault();

                    if (RevenueForShopItem != null)
                    {
                        listElementFormula.Add(new ElementFormula(PayrollElement.SAL_COM_TAGET_SHOP.ToString(), RevenueForShopItem.Target, 0));
                        listElementFormula.Add(new ElementFormula(PayrollElement.SAL_COM_ACTUAL_SHOP.ToString(), RevenueForShopItem.Actual, 0));
                        listElementFormula.Add(new ElementFormula(PayrollElement.SAL_COM_PRECENT_REVENUE.ToString(), RevenueForShopItem.Actual / RevenueForShopItem.Target, 0));
                    }
                    else
                    {
                        listElementFormula.Add(new ElementFormula(PayrollElement.SAL_COM_TAGET_SHOP.ToString(), 0, 0));
                        listElementFormula.Add(new ElementFormula(PayrollElement.SAL_COM_ACTUAL_SHOP.ToString(), 0, 0));
                        listElementFormula.Add(new ElementFormula(PayrollElement.SAL_COM_PRECENT_REVENUE.ToString(), 0, 0));
                    }

                    listElementFormula.Add(new ElementFormula(PayrollElement.SAL_COM_COUNT_SHOPMEMBER.ToString(), listProfile.Where(m => m.ShopID == item.ID).Count(), 0));


                    listElementFormula.Add(new ElementFormula(PayrollElement.SAL_COM_COUNT_SL.ToString(), lstShop.Where(m => m.ID == item.ID).FirstOrDefault().NoShiftLeader, 0));


                    listElementFormula.Add(new ElementFormula(PayrollElement.SAL_COM_RANK.ToString(), lstShop.Where(m => m.ID == item.ID).FirstOrDefault().Rank, 0));

                    #endregion




                    DataRow dr = table.NewRow();
                    var lstRevenueForShopByID = lstRevenueForShop.Where(s => s.ShopID == item.ID && lstKPIBonus.Where(m => m.IsTotalRevenue == true).FirstOrDefault().ID == s.KPIBonusID).FirstOrDefault();

                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.ShopCode] = item != null ? item.Code : string.Empty;
                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.ShopName] = item != null ? item.ShopName : string.Empty;
                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.Rank] = item != null ? item.Rank : string.Empty;
                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.Target] = lstRevenueForShopByID != null ? lstRevenueForShopByID.Target : 0;
                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.Actual] = lstRevenueForShopByID != null ? lstRevenueForShopByID.Actual : 0;

                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.CompletionRate] = lstRevenueForShopByID != null ? lstRevenueForShopByID.Actual.Value / lstRevenueForShopByID.Target.Value : 0;

                    double totalPrice = 0;
                    foreach (var kpi in lstKPIBonus)
                    {
                        var CommissionName = Sal_ReportRevenueForShopsEntity.FieldNames.Commission + kpi.KPIBonusName;
                        var lstKpiBonusByID = lstKPIBonusItem.Where(s => s.ShopID == item.ID && kpi.ID == s.KPIBonusID).FirstOrDefault();
                        var lstRevenueRecordByID = lstRevenueRecord.Where(s => s.ShopID.Value == item.ID && s.KPIBonusID == kpi.ID).FirstOrDefault();
                        if (table.Columns.Contains(kpi.KPIBonusName))
                        {
                            dr[kpi.KPIBonusName] = lstKpiBonusByID != null ? lstKpiBonusByID.Value : 0;
                        }
                        if (table.Columns.Contains(CommissionName))
                        {
                            dr[CommissionName] = lstRevenueRecordByID != null ? lstRevenueRecordByID.Amount * 1 : 0;
                            totalPrice += lstRevenueRecordByID != null ? (double)lstRevenueRecordByID.Amount : 0;
                        }
                    }
                    var lstRevenueRecordByItem = lstRevenueRecord.Where(s => s.KPIBonusID == null && s.Type == EnumDropDown.SalesType.E_ITEM_MAJOR.ToString() && s.ShopID == item.ID).FirstOrDefault();
                    var lstRevenueRecordByLineItem = lstRevenueRecord.Where(s => s.KPIBonusID == null && s.Type == EnumDropDown.SalesType.E_LINEITEM_MAJOR.ToString() && s.ShopID == item.ID).FirstOrDefault();
                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.TopLine5Forcus] = item != null ? item.MainLineProduct : 0;
                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.CommissionTopLine5Forcus] = lstRevenueRecordByItem != null ?
                        lstRevenueRecordByItem.Amount : 0;
                    totalPrice += lstRevenueRecordByItem != null ? (double)lstRevenueRecordByItem.Amount : 0;

                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.ProductForcus] = item != null ? item.PromoteProduct : 0;
                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.CommissionProductForcus] = lstRevenueRecordByLineItem != null ? lstRevenueRecordByLineItem.Amount : 0;
                    totalPrice += lstRevenueRecordByLineItem != null ? (double)lstRevenueRecordByLineItem.Amount : 0;

                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.Commission] = totalPrice;
                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.Incentive] = totalPrice;
                    double FriceSL = (double)GetObjectValue(new List<Cat_ElementEntity>(), listElementFormula, item.Formular1).Value;
                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.Shiftleader] = FriceSL;
                    dr[Sal_ReportRevenueForShopsEntity.FieldNames.Total] = totalPrice + FriceSL;

                    table.Rows.Add(dr);

                }
                return table.ConfigTable(true);
            }
        }
Example #3
0
 // DELETE api/<controller>
 public void Delete(Guid ID)
 {
     var service = new Cat_KPIBonusServices();
     var result  = service.Remove <Cat_KPIBonusItemEntity>(ID);
 }
Example #4
0
        public DataTable GetSchemaReportVenueForShop(string UserLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                string status = string.Empty;
                DataTable tb = new DataTable("Sal_ReportRevenueForShopsModel");
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.ShopCode, typeof(string));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.ShopName, typeof(string));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.Rank, typeof(string));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.Target, typeof(double));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.Actual, typeof(double));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.CompletionRate, typeof(double));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.Total, typeof(double));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.Shiftleader, typeof(double));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.Commission, typeof(double));

                var kpiBonusService = new Cat_KPIBonusServices();
                var lstObj = new List<object>();
                lstObj.Add(null);
                lstObj.Add(null);
                lstObj.Add(1);
                lstObj.Add(int.MaxValue - 1);
                var lstKPIBonus = kpiBonusService.GetData<Cat_KPIBonusEntity>(lstObj, ConstantSql.hrm_cat_sp_get_KPIBonus, UserLogin, ref status).ToList();
                if (lstKPIBonus != null)
                {
                    foreach (var item in lstKPIBonus)
                    {
                        var CommissionName = Sal_ReportRevenueForShopsEntity.FieldNames.Commission + item.KPIBonusName;
                        if (!tb.Columns.Contains(item.KPIBonusName) || !tb.Columns.Contains(CommissionName))
                        {
                            tb.Columns.Add(item.KPIBonusName, typeof(double));
                            tb.Columns.Add(CommissionName, typeof(double));
                        }
                    }
                }
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.TopLine5Forcus, typeof(double));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.CommissionTopLine5Forcus, typeof(double));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.ProductForcus, typeof(double));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.CommissionProductForcus, typeof(double));
                tb.Columns.Add(Sal_ReportRevenueForShopsEntity.FieldNames.Incentive, typeof(double));

                return tb;
            }
        }