public ActionResult GenerateDocs(int contractorId, int cycle) { var templateFile = new FileInfo($"{WebRootPath}\\Content\\TimeCardTemplates.xlsx"); try { string name = LookupRepo.GetLookups("Contractor").Where(x => x.Id == contractorId).FirstOrDefault()?.Descr; var fileList = new List <string>(); GenerateTimeCards(contractorId, name, templateFile, cycle, fileList); GenerateTimeBooks(contractorId, name, templateFile, cycle, fileList); GenerateInvoices(contractorId, name, templateFile, cycle, fileList); GenerateSummary(contractorId, name, templateFile, cycle, fileList); if (!fileList.Any()) { return(Json(new { success = false, message = "Nothing to generate." })); } string zipFile = $"C:\\TEMP\\{name}.zip"; TempData["Download"] = JsonConvert.SerializeObject(new Infrastructure.ZipDownload { FileName = zipFile, FileList = fileList }); return(Json(new { success = true })); } catch (Exception ex) { return(Json(new { success = false, message = ex.Message })); } }
private void prepWork(ViewModels.WorkViewModel vm) { var cycles = GetPayCycles(); int cycle = int.Parse(cycles.First().Value); vm.Jobs = _WorkRepo.GetJobs("- Select -").Select(x => new SelectListItem { Text = x.Descr, Value = x.Id.ToString() }); vm.WorkTypes = _LookupRepo.GetLookups("WorkType", "- Select -").Select(x => new SelectListItem { Text = x.Descr, Value = x.Id.ToString() }); vm.PayCycles = cycles; if (vm.SelectedCycle == 0) { vm.SelectedCycle = cycle; } vm.WorkEntries = _WorkRepo.GetWork(vm.Contractor.Id, vm.SelectedCycle, true); if (vm.EditWork == null) { vm.EditWork = new Domain.Work { ContractorId = vm.Contractor.Id, WorkDay = DateRef.GetWorkDay(DateTime.Today) }; } vm.EditDays = GetEditDays(vm.SelectedCycle); }
private IEnumerable <SelectListItem> GetLookup(string group) { return(LookupRepo.GetLookups(group, "- Select -").Where(x => x.Id == 0 || x.Active == true) .Select(x => new SelectListItem { Text = x.Descr, Value = x.Id.ToString() })); }
private void prepWork(Models.WorkViewModel vm, bool clearEdit = false) { var cycles = GetPayCycles(); int cycle = int.Parse(cycles.First().Value); vm.WorkTypes = LookupRepo.GetLookups("WorkType", "- Select -").Select(x => new SelectListItem { Text = x.Descr, Value = x.Id.ToString() }); vm.PayCycles = cycles; vm.IsCycleOpen = false; vm.CanCloseCycle = true; if (vm.SelectedCycle == 0) { vm.SelectedCycle = cycle; } if (vm.SelectedCycle == cycle) { vm.IsCycleOpen = true; vm.CanCloseCycle = false; } vm.Jobs = _JobRepo.GetJobsForWork(vm.SelectedContractorId, vm.SelectedCycle).Select(x => new SelectListItem { Text = x.Descr, Value = x.Id.ToString() }); vm.WorkEntries = _WorkRepo.GetWork(vm.SelectedContractorId, vm.SelectedCycle, true); if (vm.SortByJob) { vm.WorkEntries = vm.WorkEntries.OrderBy(x => x.Job).ThenBy(x => x.WorkDay); } if (vm.EditWork == null) { vm.EditWork = new TimeCard.Domain.Work { ContractorId = vm.SelectedContractorId, WorkDay = DateRef.GetWorkDay(DateTime.Today) }; } if (clearEdit) { vm.EditWork = new TimeCard.Domain.Work { ContractorId = vm.SelectedContractorId, WorkDay = vm.EditWork.WorkDay, JobId = vm.EditWork.JobId, WorkType = vm.EditWork.WorkType }; } vm.EditDays = GetEditDays(vm.SelectedCycle); vm.DailyTotals = new decimal[2][]; for (int i = 0; i < 2; i++) { vm.DailyTotals[i] = new decimal[8]; for (int j = 0; j < 7; j++) { vm.DailyTotals[i][j] = vm.WorkEntries.Where(x => x.WeekDay == j + i * 7).Sum(x => x.Hours); vm.DailyTotals[i][7] += vm.DailyTotals[i][j]; } } if (!vm.IsCycleOpen) { vm.IsCycleOpen = _WorkRepo.GetWorkOpen(vm.SelectedContractorId).Any(x => x == vm.SelectedCycle); } }
void prepIndex(LookupViewModel vm) { vm.LookupGroups = LookupRepo.GetGroups().Select(x => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem { Value = x.GroupId.ToString(), Text = x.Descr }); if (vm.SelectedGroupId != 0) { vm.Lookups = LookupRepo.GetLookups(vm.SelectedGroupId); } }