protected async Task HandleValidSubmit() { if (string.IsNullOrEmpty(revenue.id)) { var vatAccount = await appDBContext.GLAccounts.Where(a => a.outputVatAccount).FirstOrDefaultAsync(); var company = await appDBContext.Companies.Where(a => a.companyId.Equals("ASRC")).FirstOrDefaultAsync(); var r = new Revenue(); r.id = Guid.NewGuid(); r.transactionDate = revenue.transactionDate; r.dueDate = revenue.dueDate; r.description = revenue.description; r.account = revenue.revenueAccounts.Where(a => a.accountId.Equals(Guid.Parse(revenue.glAccountId))).FirstOrDefault(); r.cashAccount = await appDBContext.GLAccounts.Where(a => a.accountId.Equals(Guid.Parse(revenue.cashAccountId))).FirstOrDefaultAsync(); r.propertyDirectory = revenue.propertyDirectories.Where(a => a.id.ToString().Equals(revenue.propertyDirectoryId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); r.amount = revenue.amount; r.createDate = DateTime.Now; r.createdBy = "testadmin"; r.receiptNo = revenue.receiptNo; r.reference = revenue.reference; r.remarks = string.Format("{0}_{1}_{2} {3}", r.account.accountDesc, r.propertyDirectory.property.description, r.propertyDirectory.tenant.lastName, r.propertyDirectory.tenant.lastName); r.company = company; r.cashOrCheck = revenue.cashOrCheck; if (r.cashOrCheck.Equals("1")) { r.checkDetails = new CheckDetails() { amount = revenue.checkAmount, bankName = revenue.bankName, branch = revenue.branch, checkDate = revenue.checkDate.HasValue ? revenue.checkDate.Value : DateTime.MinValue, checkDetailId = Guid.NewGuid() }; } appDBContext.Revenues.Add(r); var jeHdr = new JournalEntryHdr() { createDate = DateTime.Now, createdBy = "testadmin", id = Guid.NewGuid(), source = "revenue", sourceId = r.id.ToString() }; jeHdr.description = r.remarks; jeHdr.company = company; var amount = r.cashOrCheck.Equals("1") ? r.checkDetails.amount : r.amount; var vat = Math.Round(amount * 0.12m, 2); r.taxAmount = vat; var jeList = new List <JournalEntryDtl>() { new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = "testadmin", lineNumber = 0, amount = amount - vat, type = "D", account = r.account }, new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = "testadmin", lineNumber = 1, amount = vat, type = "D", account = vatAccount }, new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = "testadmin", lineNumber = 2, amount = amount, type = "C", account = r.cashAccount }, }; jeHdr.JournalDetails = jeList.AsEnumerable(); r.journalEntry = jeHdr; appDBContext.JournalEntriesHdr.Add(jeHdr); await appDBContext.SaveChangesAsync(); NavigateToList(); } }
protected async Task HandleValidSubmit() { try { if (string.IsNullOrEmpty(revenue.id)) { var vatAccount = await appDBContext.GLAccounts.Where(a => a.outputVatAccount).FirstOrDefaultAsync(); var r = new Revenue(); r.id = Guid.NewGuid(); r.transactionDate = revenue.transactionDate; r.dueDate = revenue.dueDate; r.description = revenue.description; r.amount = revenue.amount; r.createDate = DateTime.Now; r.createdBy = UserName; r.receiptNo = revenue.receiptNo; r.reference = revenue.reference; r.companyId = CompanyId; r.cashOrCheck = revenue.cashOrCheck; if (r.cashOrCheck.Equals("1")) { r.checkDetails = new CheckDetails() { amount = revenue.checkAmount, bankName = revenue.bankName, branch = revenue.branch, checkDate = revenue.checkDate.HasValue ? revenue.checkDate.Value : DateTime.MinValue, checkDetailId = Guid.NewGuid() }; } appDBContext.Revenues.Add(r); var jeHdr = new JournalEntryHdr() { createDate = DateTime.Now, createdBy = UserName, id = Guid.NewGuid(), source = "revenue", sourceId = r.id.ToString(), companyId = CompanyId, postingDate = r.transactionDate }; jeHdr.description = r.remarks; jeHdr.postingDate = r.transactionDate; var amount = r.cashOrCheck.Equals("1") ? r.checkDetails.amount : r.amount; var beforeVat = 0m; var vat = 0m; if (amount != 0) { beforeVat = Math.Round(amount / 1.12m, 2); vat = amount - beforeVat; } r.beforeTax = beforeVat; r.taxAmount = vat; var jeList = new List <JournalEntryDtl>() { new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = UserName, lineNumber = 0, amount = amount - vat, type = "C", //account = r.account }, new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = UserName, lineNumber = 1, amount = vat, type = "C", account = vatAccount }, new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = UserName, lineNumber = 2, amount = amount, type = "D", //account = r.cashAccount }, }; jeHdr.JournalDetails = jeList.AsEnumerable(); r.journalEntry = jeHdr; appDBContext.JournalEntriesHdr.Add(jeHdr); await appDBContext.SaveChangesAsync(); StateHasChanged(); NavigateToList(); } } catch (Exception ex) { ErrorMessage = ex.ToString(); } finally { DataSaved = true; } }
protected async Task HandleValidSubmit() { try { IsSaving = true; if (string.IsNullOrEmpty(revenue.id)) { var pd = await appDBContext.PropertyDirectory .Where(b => b.propertyId.Equals(revenue.propertyId) && b.tenandId.Equals(revenue.tenantId) && revenue.dueDate.Value >= b.dateFrom && revenue.dueDate.Value <= b.dateTo && b.companyId.Equals(CompanyId)).FirstOrDefaultAsync(); if (pd == null) { await JSRuntime.InvokeVoidAsync("alert", "Tenant is not currently renting the selected property."); return; } var validationMessage = new StringBuilder(); if (revenue.revenueLineItems.Where(a => string.IsNullOrEmpty(a.debitAccountId)).Any()) { validationMessage.AppendLine("Debit account is required. Please select a debit account."); } if (revenue.revenueLineItems.Where(a => string.IsNullOrEmpty(a.creditAccountId)).Any()) { validationMessage.AppendLine("Credit account is required. Please select a Credit account."); } if (!revenue.dueDate.HasValue) { validationMessage.AppendLine("Due date is required."); } else if (BillingType == "MB" && revenue.dueDate.Value.ToString("yyyyMM") != DateTime.Today.ToString("yyyyMM")) { validationMessage.AppendLine("Due date must be within the current month and year."); } if (!string.IsNullOrEmpty(validationMessage.ToString())) { await JSRuntime.InvokeVoidAsync("alert", validationMessage.ToString()); return; } //var vatAccount = await appDBContext.GLAccounts.Where(a => a.outputVatAccount).FirstOrDefaultAsync(); var r = new Revenue(); r.id = Guid.NewGuid(); r.documentId = revenue.documentId; r.transactionDate = revenue.transactionDate; r.dueDate = revenue.dueDate; r.description = revenue.description; r.propertyDirectory = pd; //revenue.propertyDirectories.Where(a => a.id.ToString().Equals(revenue.propertyDirectoryId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); r.amount = revenue.revenueLineItems.Sum(a => a.amountApplied); r.beforeTax = revenue.revenueLineItems.Where(a => !IsTaxLineItem(a.billLineType) ).Sum(a => a.amountApplied); r.taxAmount = revenue.revenueLineItems.Where(a => IsTaxLineItem(a.billLineType)).Sum(a => a.amountApplied); r.createDate = DateTime.Now; r.createdBy = UserName; r.receiptNo = revenue.receiptNo; r.reference = revenue.reference; r.remarks = string.Empty; //string.Format("{0}_{1}_{2} {3}", r.account.accountDesc, r.propertyDirectory.property.description, r.propertyDirectory.tenant.lastName, r.propertyDirectory.tenant.firstName); r.companyId = CompanyId; r.cashOrCheck = revenue.cashOrCheck; r.billId = Guid.Parse(revenue.billingId); r.billingType = BillingType; if (r.cashOrCheck.Equals("1")) { r.checkDetails = new CheckDetails() { amount = revenue.checkAmount, bankName = revenue.bankName, branch = revenue.branch, checkDate = revenue.checkDate.HasValue ? revenue.checkDate.Value : DateTime.MinValue, checkNo = revenue.checkNo, depositDate = revenue.checkDepositDate, checkDetailId = Guid.NewGuid() }; } 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)}"; } var jeHdr = new JournalEntryHdr() { documentId = documentId, createDate = DateTime.Now, createdBy = UserName, id = Guid.NewGuid(), source = "revenue", sourceId = r.id.ToString(), companyId = CompanyId, postingDate = r.transactionDate, transactionDate = r.transactionDate }; jeHdr.description = r.remarks; jeHdr.postingDate = r.transactionDate; var jeList = new List <JournalEntryDtl>(); var lineNo = 0; r.revenueLineItems = new List <RevenueLineItem>(); foreach (var line in this.revenue.revenueLineItems) { var jeLine = new JournalEntryDtl(); jeLine.id = Guid.NewGuid().ToString(); jeLine.description = line.description; jeLine.createDate = DateTime.Now; jeLine.createdBy = UserName; jeLine.lineNumber = lineNo; jeLine.amount = line.amountApplied; jeLine.type = "D"; jeLine.accountId = Guid.Parse(line.debitAccountId); jeList.Add(jeLine); jeLine = new JournalEntryDtl(); jeLine.id = Guid.NewGuid().ToString(); jeLine.description = line.description; jeLine.createDate = DateTime.Now; jeLine.createdBy = UserName; jeLine.lineNumber = lineNo; jeLine.amount = line.amountApplied; jeLine.type = "C"; jeLine.accountId = Guid.Parse(line.creditAccountId); jeList.Add(jeLine); r.revenueLineItems.Add(new RevenueLineItem() { id = line.Id, billingLineItemId = line.billingLineItemId, amount = line.amountApplied, cashOrCheck = line.cashOrCheck, //checkDetails = line.cashOrCheck.Equals("1") ? new CheckDetails() { bankName = line.bankName, checkDate = line.checkDate.Value, branch = line.branch, amount = line.amount } : null, bankName = line.bankName, branch = line.branch, checkDate = line.checkDate, debitAccountId = Guid.Parse(line.debitAccountId), creditAccountId = Guid.Parse(line.creditAccountId), description = line.description });; } r.journalEntry = jeHdr; appDBContext.Revenues.Add(r); jeHdr.JournalDetails = jeList.AsEnumerable(); appDBContext.JournalEntriesHdr.Add(jeHdr); await appDBContext.SaveChangesAsync(); DynamicParameters par = new DynamicParameters(); par.Add("billingId", Guid.Parse(revenue.billingId)); await dapperManager.ExecuteAsync("spUpdateBalance", par); StateHasChanged(); NavigateToList(); } } catch (Exception ex) { ErrorMessage = ex.ToString(); } finally { DataSaved = true; IsSaving = false; } }
protected async Task HandleValidSubmit() { ErrorMessage = string.Empty; if (!journalEntry.journalEntryDtls.Any()) { ErrorMessage = "There is no entry."; StateHasChanged(); return; } if (TotalBalance != 0) { ErrorMessage = "Total Balance must be 0."; StateHasChanged(); return; } var id = Guid.NewGuid(); var jeHdr = new JournalEntryHdr() { createDate = DateTime.Now, createdBy = UserName, id = id, source = "JE", sourceId = id.ToString(), companyId = CompanyId }; jeHdr.documentId = journalEntry.documentId; jeHdr.description = journalEntry.description; jeHdr.postingDate = journalEntry.postingDate; jeHdr.transactionDate = journalEntry.transactionDate; jeHdr.reference = journalEntry.reference; jeHdr.remarks = journalEntry.remarks; jeHdr.companyId = CompanyId; jeHdr.createdBy = UserName; jeHdr.createDate = DateTime.Now; var jeList = new List <JournalEntryDtl>(); int lineNo = 1; foreach (var dtl in journalEntry.journalEntryDtls) { jeList.Add(new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = jeHdr.createdBy, lineNumber = lineNo, amount = dtl.amount, type = dtl.type, accountId = Guid.Parse(dtl.accountId), reference = dtl.reference, description = dtl.description, remarks = dtl.remarks }); lineNo++; } jeHdr.JournalDetails = jeList.AsEnumerable(); appDBContext.JournalEntriesHdr.Add(jeHdr); await appDBContext.SaveChangesAsync(); StateHasChanged(); NavigateToList(); }
protected async Task HandleValidSubmit() { if (string.IsNullOrEmpty(expense.id)) { var vatAccount = await appDBContext.GLAccounts.Where(a => a.outputVatAccount).FirstOrDefaultAsync(); var r = new Expense(); r.id = Guid.NewGuid(); r.transactionDate = expense.transactionDate; r.dueDate = expense.dueDate; r.description = expense.description; r.account = expense.expenseAccounts.Where(a => a.accountId.Equals(Guid.Parse(expense.glAccountId))).FirstOrDefault(); r.cashAccount = await appDBContext.GLAccounts.Where(a => a.accountId.Equals(Guid.Parse(expense.cashAccountId))).FirstOrDefaultAsync(); r.documentId = expense.documentId; r.amount = expense.amount; r.createDate = DateTime.Now; r.createdBy = UserName; r.receiptNo = expense.receiptNo; r.reference = expense.reference; r.remarks = $"{r.account.accountCode} {r.account.accountDesc}"; r.companyId = CompanyId; r.cashOrCheck = expense.cashOrCheck; r.vendorId = expense.vendorId; r.vendorOther = expense.vendorOther; if (r.cashOrCheck.Equals("1")) { r.checkDetails = new CheckDetails() { amount = expense.checkAmount, bankName = expense.bankName, branch = expense.branch, checkDate = expense.checkDate.HasValue ? expense.checkDate.Value : DateTime.MinValue, checkDetailId = Guid.NewGuid(), checkNo = expense.checkNo, releaseDate = expense.checkReleaseDate }; } 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)}"; } var jeHdr = new JournalEntryHdr() { documentId = documentId, createDate = DateTime.Now, createdBy = UserName, id = Guid.NewGuid(), source = "expense", sourceId = r.id.ToString(), companyId = CompanyId, postingDate = r.transactionDate, transactionDate = r.transactionDate }; jeHdr.description = r.remarks; var amount = r.cashOrCheck.Equals("1") ? r.checkDetails.amount : r.amount; r.beforeTax = amount; var jeList = new List <JournalEntryDtl>() { new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = UserName, lineNumber = 0, amount = InputVatAccountId.HasValue? CalculateBeforeVat(amount):amount, type = "D", account = r.account } }; if (InputVatAccountId.HasValue) { var beforeVat = CalculateBeforeVat(amount); var taxAmount = CalculateVat(amount); r.beforeTax = beforeVat; r.taxAmount = taxAmount; jeList.Add(new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = UserName, lineNumber = 1, amount = taxAmount, type = "D", accountId = InputVatAccountId.Value }); } jeList.Add(new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = UserName, lineNumber = 2, amount = amount, type = "C", account = r.cashAccount }); jeHdr.JournalDetails = jeList.AsEnumerable(); r.journalEntry = jeHdr; appDBContext.Expenses.Add(r); appDBContext.JournalEntriesHdr.Add(jeHdr); await appDBContext.SaveChangesAsync(); StateHasChanged(); NavigateToList(); } }
protected async Task HandleValidSubmit() { if (string.IsNullOrEmpty(expense.id)) { var vatAccount = await appDBContext.GLAccounts.Where(a => a.outputVatAccount).FirstOrDefaultAsync(); var company = await appDBContext.Companies.Where(a => a.companyId.Equals("ASRC")).FirstOrDefaultAsync(); var r = new Expense(); r.id = Guid.NewGuid(); r.transactionDate = expense.transactionDate; r.dueDate = expense.dueDate; r.description = expense.description; r.account = expense.expenseAccounts.Where(a => a.accountId.Equals(Guid.Parse(expense.glAccountId))).FirstOrDefault(); r.cashAccount = await appDBContext.GLAccounts.Where(a => a.accountId.Equals(Guid.Parse(expense.cashAccountId))).FirstOrDefaultAsync(); r.amount = expense.amount; r.createDate = DateTime.Now; r.createdBy = "testadmin"; r.receiptNo = expense.receiptNo; r.reference = expense.reference; r.remarks = $"{r.account.accountCode} {r.account.accountDesc}"; r.company = company; r.cashOrCheck = expense.cashOrCheck; if (r.cashOrCheck.Equals("1")) { r.checkDetails = new CheckDetails() { amount = expense.checkAmount, bankName = expense.bankName, branch = expense.branch, checkDate = expense.checkDate.HasValue ? expense.checkDate.Value : DateTime.MinValue, checkDetailId = Guid.NewGuid() }; } appDBContext.Expenses.Add(r); var jeHdr = new JournalEntryHdr() { createDate = DateTime.Now, createdBy = "testadmin", id = Guid.NewGuid(), source = "expense", sourceId = r.id.ToString() }; jeHdr.description = r.remarks; jeHdr.company = company; var amount = r.cashOrCheck.Equals("1") ? r.checkDetails.amount : r.amount; var vat = Math.Round(amount * 0.12m, 2); r.taxAmount = vat; var jeList = new List <JournalEntryDtl>() { new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = "testadmin", lineNumber = 0, amount = amount - vat, type = "C", account = r.account }, new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = "testadmin", lineNumber = 1, amount = vat, type = "C", account = vatAccount }, new JournalEntryDtl() { id = Guid.NewGuid().ToString(), createDate = DateTime.Now, createdBy = "testadmin", lineNumber = 2, amount = amount, type = "D", account = r.cashAccount }, }; jeHdr.JournalDetails = jeList.AsEnumerable(); r.journalEntry = jeHdr; appDBContext.JournalEntriesHdr.Add(jeHdr); await appDBContext.SaveChangesAsync(); NavigateToList(); } }