private double GetRecordAmmount(Document document, AccountingRecord accountingRecord) { var ammountType = !string.IsNullOrEmpty(accountingRecord.Debit) ? accountingRecord.Debit : accountingRecord.Credit; double ammount = 0; switch (ammountType) { case "netto": ammount = Convert.ToDouble(document.Net); break; case "brutto": ammount = Convert.ToDouble(document.Gross); break; case "vat": ammount = Convert.ToDouble(document.Vat); break; } return(ammount); }
private void InsertAccountRecordWithAccountValueToAccountRecordList( ObservableCollection <AccountingRecord> accountingRecordList, Account account, bool isActiv = true) { var accountingRecord = accountingRecordList.FirstOrDefault(x => x.Account == account); if (accountValue.Value != null) { accountValue.Value = (decimal)accountValue.Value < 0 ? -1 * (decimal)accountValue.Value : (decimal)accountValue.Value; } if (accountingRecord != null) { if (accountValue.Value != null) { accountingRecord.Value = (decimal)accountValue.Value; var ledgerCreditRecord = LedgerAccountHelper.LedgerAccountList.FirstOrDefault(x => x.Account.Id == account.Id && x.CreditAccountingRecords != null && x.CreditAccountingRecords.Any(y => y.ID == 0))?.CreditAccountingRecords.First(y => y.ID == 0); var ledgerDebitRecord = LedgerAccountHelper.LedgerAccountList.FirstOrDefault(x => x.Account == account && x.DebitAccountingRecords != null && x.DebitAccountingRecords.Any(y => y.ID == 0))?.DebitAccountingRecords.First(y => y.ID == 0); if (ledgerCreditRecord != null) { ledgerCreditRecord.Value = accountingRecord.Value; } else if (ledgerDebitRecord != null) { ledgerDebitRecord.Value = accountingRecord.Value; } else { if (!isActiv) { LedgerAccountHelper.LedgerAccountList.AddBuchungssatz(new Journal(0) { CreditAccount = account.Id, Text = "Anfangsbilanz", Value = accountingRecord.Value }); } else { LedgerAccountHelper.LedgerAccountList.AddBuchungssatz(new Journal(0) { DebitAccount = account.Id, Text = "Anfangsbilanz", Value = accountingRecord.Value }); } } } } else { if (accountValue.Value != null) { var newRecord = new AccountingRecord { Account = account, Value = (decimal)accountValue.Value, Text = "Anfangsbilanz" }; accountingRecordList.Add(newRecord); if (!isActiv) { LedgerAccountHelper.LedgerAccountList.AddBuchungssatz(new Journal(0) { CreditAccount = account.Id, Text = newRecord.Text, Value = newRecord.Value }); } else { LedgerAccountHelper.LedgerAccountList.AddBuchungssatz(new Journal(0) { DebitAccount = account.Id, Text = newRecord.Text, Value = newRecord.Value }); } } } }
public async Task CreateFlowAsync(long fromId, User fromUser, string accountingPlan, long?toId, User toUser = null, string subConto1 = null, string subConto2 = null, string comment = null, string followInformation = null) { var accPlan = await db.AccountingPlans.FirstOrDefaultAsync(x => x.Name == accountingPlan); if (accPlan == null) { db.AccountingPlans.Add(new AccountingPlan() { Name = accountingPlan }); await db.SaveChangesAsync(); } IQueryable <AccountingRecord> fromQuery = db.AccountingRecords.Where(x => x.Id == fromId && x.AccountingPlanId == accPlan.Id); if (!string.IsNullOrEmpty(subConto1)) { fromQuery = db.AccountingRecords.Where(x => x.SubConto1 == subConto1); } if (!string.IsNullOrEmpty(subConto2)) { fromQuery = db.AccountingRecords.Where(x => x.SubConto2 == subConto2); } var from = await fromQuery.SingleOrDefaultAsync(); if (from == null) { db.AccountingRecords.Add(new AccountingRecord() { AccountingPlanId = accPlan.Id, UserId = fromUser.Id, SubConto1 = subConto1, SubConto2 = subConto2 }); await db.SaveChangesAsync(); } Flow result = new Flow(); var currentUser = await db.Users.FirstOrDefaultAsync(x => x.Id == from.UserId); if (currentUser == null) { throw new ApiError(new ServerException("API ERROR!!!")); } AccountingRecord to = null; if (toId.HasValue) { IQueryable <AccountingRecord> toQuery = db.AccountingRecords.Where(x => x.Id == toId.Value); if (!string.IsNullOrEmpty(subConto1)) { toQuery = db.AccountingRecords.Where(x => x.SubConto1 == subConto1); } if (!string.IsNullOrEmpty(subConto2)) { toQuery = db.AccountingRecords.Where(x => x.SubConto2 == subConto2); } to = await toQuery.SingleOrDefaultAsync(); if (to == null && toUser == null) { throw new ApiError(new ServerException("Incorrect accounting record")); } to = new AccountingRecord() { UserId = toUser.Id, AccountingPlanId = accPlan.Id, SubConto1 = subConto1, SubConto2 = subConto2 }; db.AccountingRecords.Add(to); await db.SaveChangesAsync(); result.ToId = to.Id; } AccountingComment accComment = null; if (!string.IsNullOrEmpty(comment)) { accComment = await db.AccountingComments.FirstOrDefaultAsync(x => x.Comment == comment); if (accComment == null) { db.AccountingComments.Add(new AccountingComment() { Comment = comment }); await db.SaveChangesAsync(); } result.AccountingCommentId = accComment.Id; } if (!string.IsNullOrEmpty(followInformation)) { result.FollowInformation = followInformation; } db.Flows.Add(result); await db.SaveChangesAsync(); }