public JournalEntryViewModel CreateJournalEntryViewModel(Entry entry, JournalOptions op) { var model = new JournalEntryViewModel(); model.EntryNo = entry.Number; model.EntryOrigin = entry.EntryOrigin; switch (entry.EntryOrigin) { case EntryOrigin.None: model.EntryOriginNo = entry.Number; break; case EntryOrigin.Pay: model.EntryOriginNo = entry.PayEntry.Number; break; case EntryOrigin.Bill: model.EntryOriginNo = entry.BillEntry.Bill.Number; break; } model.Date = entry.Date; model.CreationDate = entry.CreatedDateTime; model.Items = entry.Items.Select(this.CreateJournalEntryItemViewModel).ToList(); if (op.ShowTotalEntries) { model.DebitSum = model.Items.Sum(e => e.Debit); model.CreditSum = model.Items.Sum(e => e.Credit); } return(model); }
public async Task <IActionResult> Modify(JournalEntryViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var entry = await _context.JournalEntries .Include(je => je.TopicTagEntries) .ThenInclude(tte => tte.TopicTag) .FirstOrDefaultAsync(pe => pe.ID == model.ID); if (entry == default(JournalEntry)) { return(RedirectToAction("NoResource", "Error")); } entry.Title = model.Title; entry.Content = model.Content; entry.LastModified = DateTime.Now; entry.Slug = !string.IsNullOrWhiteSpace(model.Slug) ? model.Slug : entry.Title.GenerateSlug(); if (!string.IsNullOrWhiteSpace(model.ProjectSlug)) { var projEntry = await _context.ProjectEntries.FirstOrDefaultAsync(pe => pe.Slug == model.ProjectSlug); if (projEntry != default(ProjectEntry)) { entry.ProjectEntryID = projEntry.ID; } } foreach (var tag in model.TopicTagEntries.Where(tte => entry.TopicTagEntries.All(tt => tt.TopicTag.Title != tte))) { entry.TopicTagEntries.Add(_context.TopicTags.Any(tt => tt.Title == tag) ? new TopicTagEntry { JournalEntry = entry, TopicTag = _context.TopicTags.Single(tt => tt.Title == tag) } : new TopicTagEntry { JournalEntry = entry, TopicTag = new TopicTag { Title = tag } }); } foreach (var tag in entry.TopicTagEntries.Where(tte => model.TopicTagEntries.All(mtte => mtte != tte.TopicTag.Title))) { _context.TopicTagEntries.Remove(tag); } _context.JournalEntries.Update(entry); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { slug = entry.Slug })); }
private LedgerEntry ToLedgerEntry(JournalEntryViewModel entry) { return(new LedgerEntry { Account = _accountRepository.GetAccountWithCode(entry.Account), EntryValue = entry.Credit > 0 ? -entry.Credit : entry.Debit, EntryDate = DateTime.Now, Remarks = entry.Remarks }); }
public async Task Server_Can_Get_Specific(int entryIndex) { var entryToGet = _journalEntries[entryIndex]; var endPoint = ServerUri + "clients/1/journalEntries/" + entryToGet.Id; var entryViewModel = JournalEntryViewModel.ConvertToViewModel(entryToGet); var expectedBody = JsonConvert.SerializeObject(entryViewModel, new JsonApiSerializerSettings()); var response = await _client.GetAsync(endPoint); var responseBody = response.Content.ReadAsStringAsync().Result; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.AreEqual(expectedBody, responseBody); }
public Response GetResponse(HttpListenerRequest request, string[] parameters) { int entryId; if (!int.TryParse(parameters[3], out entryId)) { return(BasicResponseBuilder.GetBadRequest()); } var clientId = int.Parse(parameters[1]); try { switch (request.HttpMethod) { case "GET": var journalEntry = _journalEntryService.GetEntryById(clientId, entryId); var journalEntryVm = JournalEntryViewModel.ConvertToViewModel(journalEntry); var jsonBody = JsonConvert.SerializeObject(journalEntryVm, new JsonApiSerializerSettings()); return(new Response(200, jsonBody)); case "PUT": var body = new StreamReader(request.InputStream).ReadToEnd(); var updatedJournalVm = JsonConvert.DeserializeObject <JournalEntryViewModel>(body); var updatedJournal = JournalEntry.ConvertToJournalEntry(updatedJournalVm); _journalEntryService.UpdateEntry(clientId, entryId, updatedJournal); return(new Response(200, "Updated")); case "DELETE": _journalEntryService.DeleteEntry(clientId, entryId); return(new Response(200, "Deleted")); } } catch (JournalEntryNotFoundException e) { Console.WriteLine(e.Message); return(BasicResponseBuilder.GetNotFound()); } catch (MissingJournalEntryAttributesException e) { Console.WriteLine(e.Message); return(BasicResponseBuilder.GetBadRequest()); } return(BasicResponseBuilder.GetBadRequest()); }
public async Task <IActionResult> Create(JournalEntryViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var entry = new JournalEntry { Title = model.Title, Content = model.Content, DateCreated = DateTime.Now, Slug = !string.IsNullOrWhiteSpace(model.Slug) ? model.Slug : model.Title.GenerateSlug(), TopicTagEntries = new List <TopicTagEntry>() }; if (!string.IsNullOrWhiteSpace(model.ProjectSlug)) { var projEntry = await _context.ProjectEntries.FirstOrDefaultAsync(pe => pe.Slug == model.ProjectSlug); if (projEntry != default(ProjectEntry)) { entry.ProjectEntryID = projEntry.ID; } } foreach (var tag in model.TopicTagEntries) { entry.TopicTagEntries.Add(_context.TopicTags.Any(tt => tt.Title == tag) ? new TopicTagEntry { JournalEntry = entry, TopicTag = _context.TopicTags.Single(tt => tt.Title == tag) } : new TopicTagEntry { JournalEntry = entry, TopicTag = new TopicTag { Title = tag } }); } await _context.JournalEntries.AddAsync(entry); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { slug = entry.Slug })); }
protected override async Task OnInitializedAsync() { try { IsViewOnly = false; UserName = await _sessionStorageService.GetItemAsync <string>("UserName"); CompanyId = await _sessionStorageService.GetItemAsync <string>("CompanyId"); if (string.IsNullOrEmpty(JEId)) { DynamicParameters dynamicParameters = new DynamicParameters(); var IdKey = $"JE{DateTime.Today.ToString("yyyyMM")}"; dynamicParameters.Add("IdKey", IdKey); dynamicParameters.Add("Format", "000000"); dynamicParameters.Add("CompanyId", CompanyId); var documentIdTable = await dapperManager.GetAllAsync <DocumentIdTable>("spGetNextId", dynamicParameters); var documentId = string.Empty; if (documentIdTable.Any()) { documentId = $"{IdKey}{documentIdTable.First().NextId.ToString(documentIdTable.First().Format)}"; } journalEntry = new JournalEntryViewModel(); journalEntry.documentId = documentId; journalEntry.transactionDate = DateTime.Today; journalEntry.postingDate = DateTime.Today; journalEntry.journalEntryDtls = new List <JournalEntryDtlViewModel>(); } else { IsViewOnly = true; var je = await appDBContext .JournalEntriesHdr .Include(a => a.JournalDetails) .ThenInclude(a => a.account) .Where(a => a.id.Equals(Guid.Parse(JEId))).FirstOrDefaultAsync(); journalEntry = new JournalEntryViewModel(); journalEntry.id = je.id; journalEntry.documentId = je.documentId; journalEntry.transactionDate = je.transactionDate; journalEntry.postingDate = je.postingDate; journalEntry.journalEntryDtls = je.JournalDetails.Select(a => new JournalEntryDtlViewModel() { id = a.id, accountId = a.accountId.ToString(), accountCode = a.account.accountCode, accountName = a.account.accountDesc, description = a.description, amount = a.amount, type = a.type }).ToList(); TotalDR = journalEntry.journalEntryDtls.Where(a => a.type.Equals("D", StringComparison.OrdinalIgnoreCase)).Sum(a => a.amount); TotalCR = journalEntry.journalEntryDtls.Where(a => a.type.Equals("C", StringComparison.OrdinalIgnoreCase)).Sum(a => a.amount); TotalBalance = TotalDR - TotalCR; } } catch (Exception ex) { ErrorMessage = ex.Message; } finally { IsDataLoaded = true; } IsDataLoaded = true; }