public ActionResult Index(string p, int?t = null, int?b = null) { IncentiveSalesBusiness business = new IncentiveSalesBusiness(); business.SetUserAuth(ViewBag.UserAuth); if (RoleCode.NSM.Equals(ViewBag.UserAuth.RoleCode)) { ViewBag.ListBranch = business.GetListBranch(); } IncentiveSalesReportViewModel model = business.GetReport(p, t, b); return(View(model)); }
public AlertMessage ExportReport(string p, int?t, int?plant) { AlertMessage alert = new AlertMessage(); if (!IsAccessible(ModuleCode.IncentiveSales)) { alert.Text = StaticMessage.ERR_ACCESS_DENIED; return(alert); } IncentiveSalesReportViewModel model = GetReport(p, t, plant); if (model == null) { alert.Text = StaticMessage.ERR_DATA_NOT_FOUND; return(alert); } IWorkbook workbook = new XSSFWorkbook(); Dictionary <string, ICellStyle> dcCellStyle = GetDcCellStyle(workbook); CreateSheetRawSLM(ref workbook, dcCellStyle, model.ListRawSLM); CreateSheetReportSummary(ref workbook, dcCellStyle, model.ListSummarySLM, "Incentive SLM"); CreateSheetRawFSS(ref workbook, dcCellStyle, model.ListRawFSS); CreateSheetReportSummary(ref workbook, dcCellStyle, model.ListSummaryFSS, "Incentive FSS"); if (model.IsQuarter) { CreateSheetRawASM(ref workbook, dcCellStyle, model.ListRawASM); CreateSheetReportSummary(ref workbook, dcCellStyle, model.ListSummaryASM, "Incentive ASM"); } using (var ms = new MemoryStream()) { workbook.Write(ms); alert.Data = ms.ToArray(); } alert.Status = 1; return(alert); }
public IncentiveSalesReportViewModel GetReport(string p, int?type, int?plant) { IncentiveSalesReportViewModel result = new IncentiveSalesReportViewModel() { //FormattedMonthYear = DateTime.UtcNow.ToUtcID().ToString("MM-yyyy"), FormattedMonthYear = "", Plant = plant }; if (!string.IsNullOrEmpty(p)) { result.FormattedMonthYear = p; } try { string[] arr = result.FormattedMonthYear.Split('-'); result.Month = Convert.ToInt16(arr[0]); result.Year = Convert.ToInt16(arr[1]); } catch (Exception) { return(result); } if (result.Year == 0 || result.Month == 0) { return(result); } if (result.Month % 3 == 0) { result.IsQuarter = true; } if ((type != null && type.Value == 1) || RoleCode.RM.Equals(_userAuth.RoleCode)) { result.Type = 1; } else { result.Type = 0; } if (RoleCode.NSM.Equals(_userAuth.RoleCode) && result.Plant == null) { //return result; } //string sp = GetProcedureName(); string sp = "sp_apl_getReportSalesIncentiveAll_v2"; if (result.Type == 1) { sp = "sp_apl_getReportSalesIncentiveMDD_v2"; } if (string.IsNullOrEmpty(sp)) { return(result); } string connString = GetConnectionString(); List <SqlParameter> listSqlParam = new List <SqlParameter>() { new SqlParameter("@inBulan", result.Month), new SqlParameter("@inTahun", result.Year), }; if (RoleCode.RM.Equals(_userAuth.RoleCode)) { string strListNSM = GetStrListNSM(result.Year, result.Month, "BUM", "@nik", _userAuth.NIK.ToString()); if (string.IsNullOrEmpty(strListNSM)) { return(result); } listSqlParam.Add(new SqlParameter("@listNIK", strListNSM)); } else if (RoleCode.NSM.Equals(_userAuth.RoleCode)) { string strListNSM = _userAuth.NIK.ToString(); //if (result.Plant == null) // strListNSM = GetStrListNSM(result.Year, result.Month); //else // strListNSM = GetStrListNSM(result.Year, result.Month, "Plant", "@plant", result.Plant.Value.ToString()); //strListNSM = if (string.IsNullOrEmpty(strListNSM)) { return(result); } listSqlParam.Add(new SqlParameter("@listNIK", strListNSM)); } else if (RoleCode.KaCab.Equals(_userAuth.RoleCode)) { listSqlParam.Add(new SqlParameter("@listNIK", _userAuth.NIK)); } if (RoleCode.AdminExclusive.Equals(_userAuth.RoleCode)) { sp = "sp_apl_getReportSalesIncentiveRayonType"; listSqlParam.Add(new SqlParameter("@nik", _userAuth.NIK)); } DataTableCollection dtCollection = SqlHelper.ExecuteProcedureWithReturnMultipleTable(connString, sp, listSqlParam); if (dtCollection != null) { result.ListRawSLM = GetReportListRawSLM(dtCollection[0]); result.ListSummarySLM = GetReportListSummary(dtCollection[1]); result.ListRawFSS = GetReportListRawFSS(dtCollection[2]); result.ListSummaryFSS = GetReportListSummary(dtCollection[3]); if (result.IsQuarter) { result.ListRawASM = GetReportListRawASM(dtCollection[4]); result.ListSummaryASM = GetReportListSummary(dtCollection[5]); } } return(result); }