private static Collection <JournalDetail> GetJournalDetailCollection(string json) { Collection <JournalDetail> details = new Collection <JournalDetail>(); var jss = new JavaScriptSerializer(); dynamic result = jss.Deserialize <dynamic>(json); foreach (var item in result) { JournalDetail detail = new JournalDetail(); detail.StatementReference = item[0]; detail.AccountNumber = item[1]; detail.Account = item[2]; detail.CashRepositoryCode = item[3]; detail.CurrencyCode = item[4]; detail.Debit = Conversion.TryCastDecimal(item[5]); detail.Credit = Conversion.TryCastDecimal(item[6]); detail.ExchangeRate = Conversion.TryCastDecimal(item[7]); detail.LocalCurrencyDebit = Conversion.TryCastDecimal(item[8]); detail.LocalCurrencyCredit = Conversion.TryCastDecimal(item[9]); details.Add(detail); } return(details); }
public ActionResult AddExpenseJournalSave(string voucherNo, int CostHeadId, DateTime voucherDate, string notes, List <JournalDetail> journalDetails, decimal TotalAmount, string ChkNo) { JournalMaster jmaster = new JournalMaster(); JournalDetail jd = new JournalDetail(); jmaster.InvoiceNo = voucherNo; jmaster.LadgerDate = voucherDate; jmaster.Narration = notes; jmaster.TotalAmount = TotalAmount; journalPostingService.Save(jmaster); jd.LedgerId = CostHeadId; jd.Credit = TotalAmount; jd.Credit = 0; jd.ChequeNo = ChkNo; jd.ChequeDate = voucherDate; journalPostingService.Save(jd); foreach (var item in journalDetails) { JournalDetail jdetails = new JournalDetail(); jdetails.LedgerId = item.LedgerId; jdetails.Credit = 0; jdetails.Debit = item.Credit; jdetails.ChequeNo = ""; jdetails.ChequeDate = voucherDate; journalPostingService.Save(jdetails); } //credit foreach (var item in journalDetails) { LedgerPosting lposting = new LedgerPosting(); lposting.Credit = item.Debit ?? 0 + item.Credit ?? 0;; lposting.VoucherNo = voucherNo; lposting.LedgerId = item.LedgerId; lposting.Debit = 0; lposting.PostingDate = voucherDate; lposting.ChequeDate = DateTime.Now; lposting.ChequeNo = ""; lposting.VoucherTypeId = 4; lposting.Extra1 = "Voucher:" + voucherNo + " " + notes; postingService.Save(lposting); } //debit LedgerPosting posting = new LedgerPosting(); posting.ChequeDate = DateTime.Now; posting.VoucherNo = voucherNo; posting.ChequeNo = ""; posting.VoucherTypeId = 4; posting.LedgerId = CostHeadId; posting.PostingDate = voucherDate; posting.Credit = 0; posting.Debit = TotalAmount; posting.Extra1 = "Voucher:" + voucherNo + " " + notes; postingService.Save(posting); return(Json("", JsonRequestBehavior.AllowGet)); }
public void DeleteJournalDetail(JournalDetail journalDetail) { if ((journalDetail.EntityState == EntityState.Detached)) { this.ObjectContext.JournalDetail.Attach(journalDetail); } this.ObjectContext.JournalDetail.DeleteObject(journalDetail); }
public ProxyResponse <InsertJournalResult> InsertJournal(JournalDetail journalDetail) { _requestPrefix = ResourceNames.Journal; OperationMethod = HttpMethod.Post; var uri = base.GetRequestUri(null); return(base.GetResponse <JournalDetail, InsertJournalResult>(uri, journalDetail)); }
public ProxyResponse <UpdateJournalResult> UpdateJournal(int journalId, JournalDetail journalDetail) { OperationMethod = HttpMethod.Put; _requestPrefix = ResourceNames.Journal; var uri = base.GetRequestUri(journalId.ToString()); return(base.GetResponse <JournalDetail, UpdateJournalResult>(uri, journalDetail)); }
private void CreateJournals() { var proxy = new JournalProxy(); var journal1 = new JournalDetail { TransactionDate = DateTime.Now, Summary = string.Format("test Summary_{0}", _testIdentifier), Currency = "AUD", Items = new List <JournalItem> { new JournalItem { AccountId = _assetAccountId, Type = "debit", Amount = 10.00M }, new JournalItem { AccountId = _liabilityAccountId, Type = "credit", Amount = 10.00M } } }; var journal2 = new JournalDetail { TransactionDate = DateTime.Now, Summary = string.Format("test Summary_{0}", _testIdentifier), Currency = "AUD", Items = new List <JournalItem> { new JournalItem { AccountId = _assetAccountId, Type = "debit", Amount = 10.00M }, new JournalItem { AccountId = _liabilityAccountId, Type = "credit", Amount = 10.00M } } }; //Create journals. _DeletedJournalTranId = proxy.InsertJournal(journal1).DataObject.InsertedEntityId; _NotDeletedJournalTranId = proxy.InsertJournal(journal2).DataObject.InsertedEntityId; //Delete only first journal. proxy.DeleteJournal(_DeletedJournalTranId); }
public ActionResult JournalSave(string voucherNo, DateTime voucherDate, string notes, List <JournalRequest> ledgerPosting) { string invoiceNumber = DateTime.Now.Year + new GlobalClass().GetMaxId("Id", "LedgerPosting"); voucherNo = "JV" + invoiceNumber; JournalMaster jmaster = new JournalMaster(); jmaster.InvoiceNo = voucherNo; jmaster.VoucherNo = voucherNo; jmaster.LadgerDate = voucherDate; jmaster.Narration = notes; jmaster.TotalAmount = ledgerPosting.Where(a => a.DrOrCr == "Dr").Sum(a => a.Amount); journalPostingService.Save(jmaster); foreach (var item in ledgerPosting) { JournalDetail jdetails = new JournalDetail(); jdetails.LedgerId = item.LedgerId; jdetails.ChequeNo = item.ChequeNo; //ledger posting LedgerPosting ledgersave = new LedgerPosting(); ledgersave.VoucherTypeId = (int)BAL.VoucherTypeEnum.JournalVoucher; ledgersave.VoucherNo = voucherNo; ledgersave.InvoiceNo = voucherNo; ledgersave.Extra1 = notes; ledgersave.LedgerId = item.LedgerId; int a = ledgersave.LedgerId ?? 0; if (item.DrOrCr == "Dr") { ledgersave.Debit = item.Amount; ledgersave.Credit = 0; jdetails.Debit = item.Amount; } else { ledgersave.Credit = item.Amount; ledgersave.Debit = 0; jdetails.Credit = item.Amount; } ledgersave.InvoiceNo = voucherNo; ledgersave.ChequeNo = item.ChequeNo; ledgersave.PostingDate = Convert.ToDateTime(voucherDate); if (!string.IsNullOrEmpty(item.ChequeDate)) { ledgersave.ChequeDate = Convert.ToDateTime(item.ChequeDate); jdetails.ChequeDate = Convert.ToDateTime(item.ChequeDate); } postingService.Save(ledgersave); journalPostingService.Save(jdetails); } return(Json("", JsonRequestBehavior.AllowGet)); }
public void InsertJournalDetail(JournalDetail journalDetail) { if ((journalDetail.EntityState != EntityState.Detached)) { this.ObjectContext.ObjectStateManager.ChangeObjectState(journalDetail, EntityState.Added); } else { this.ObjectContext.JournalDetail.AddObject(journalDetail); } }
public static List <JournalDetail> GetJournalDetail(int JournalID, string type) { List <JournalDetail> jdList = new List <JournalDetail>(); try { string strErr = ""; CRSDAL dal = new CRSDAL(); dal.AddParameter("p_JournalId", JournalID, ParameterDirection.Input); DataSet dstOutPut = dal.ExecuteSelect("spTallyGet_JournalDetail_Kabra", CommandType.StoredProcedure, 0, ref strErr, "p_ErrMessage", false, "", false); if (dstOutPut != null && dstOutPut.Tables != null && dstOutPut.Tables.Count > 0) { for (int j = 0; j < dstOutPut.Tables.Count; j++) { if (dstOutPut.Tables[j] != null && dstOutPut.Tables[j].Rows != null && dstOutPut.Tables[j].Rows.Count > 0) { for (int i = 0; i < dstOutPut.Tables[j].Rows.Count; i++) { JournalDetail jd = new JournalDetail(); jd.Amount = Convert.ToDecimal(dstOutPut.Tables[j].Rows[i]["amount"].ToString()); jd.Description = dstOutPut.Tables[j].Rows[i]["description"].ToString(); jd.LedgerName = dstOutPut.Tables[j].Rows[i]["ledgername"].ToString(); jd.ClassName = dstOutPut.Tables[j].Rows[i]["classname"].ToString(); jd.IsDebit = Convert.ToInt16(dstOutPut.Tables[j].Rows[i]["isdebit"].ToString()); jd.LedgerId = Convert.ToInt32(dstOutPut.Tables[j].Rows[i]["accsysledgerid"].ToString()); jd.ClassId = Convert.ToInt32(dstOutPut.Tables[j].Rows[i]["accsysclassid"].ToString()); jd.JournalId = Convert.ToInt32(dstOutPut.Tables[j].Rows[i]["voucherjournalid"].ToString()); jdList.Add(jd); } } } } } catch (Exception ex) { Logger.WriteLog("AccountingAPI", "GetJournalDetail", ex.Message); } return(jdList); }
public JournalDetail Save(JournalDetail JDetails) { var max = journalDetails.LastRow().OrderByDescending(a => a.Id).FirstOrDefault(); if (max == null) { JDetails.Id = 1; } else { JDetails.Id = max.Id + 1; } int value = int.Parse(journalMaster.LastRow().OrderByDescending(p => p.Id).Select(r => r.Id).First().ToString()); JDetails.JournalMasterId = value; var result = journalDetails.Save(JDetails); return(result); }
private void CreateTestJournals() { var tran1 = new JournalDetail { TransactionDate = DateTime.UtcNow, Items = new List <JournalItem> { new JournalItem { Type = "Debit", AccountId = _assetAccountId, TaxCode = "G1", Amount = 10.00M }, new JournalItem { Type = "Credit", AccountId = _expenseAccountId, TaxCode = "G1", Amount = 10.00M } }, Summary = "test journal 1", Currency = "AUD", Reference = "123", JournalContactId = _contactId1, Tags = new List <string> { "test tag 1, test tag 2" } }; var tran2 = new JournalDetail { TransactionDate = DateTime.UtcNow.AddDays(-5), Items = new List <JournalItem> { new JournalItem { Type = "Debit", AccountId = _assetAccountId, TaxCode = "G1,G2", Amount = 20.00M }, new JournalItem { Type = "Credit", AccountId = _expenseAccountId, TaxCode = "G1", Amount = 20.00M } }, Summary = "test journal 2", Currency = "AUD", Reference = "456", JournalContactId = _contactId2, Tags = new List <string> { "test tag 1, test tag 2" } }; var tran3 = new JournalDetail { TransactionDate = DateTime.UtcNow.AddDays(-10), Items = new List <JournalItem> { new JournalItem { Type = "Debit", AccountId = _assetAccountId, TaxCode = "G1,G2", Amount = 20.00M }, new JournalItem { Type = "Credit", AccountId = _expenseAccountId, TaxCode = "G1", Amount = 20.00M } }, Summary = "test journal 3", Currency = "AUD", Reference = "456", JournalContactId = _contactId2, Tags = new List <string> { "test tag 1, test tag 2" } }; _testJournalTranId1 = new JournalProxy().InsertJournal(tran1).DataObject.InsertedEntityId; _testJournalTranId2 = new JournalProxy().InsertJournal(tran2).DataObject.InsertedEntityId; _testJournalTranId3 = new JournalProxy().InsertJournal(tran2).DataObject.InsertedEntityId; }
public async Task <VoucherDetailEntityModel> AddVoucherDetail(AddVoucherDetailCommand request) { try { request.TimezoneOffset = request.TimezoneOffset > 0 ? request.TimezoneOffset * -1 : Math.Abs(request.TimezoneOffset.Value); DateTime filterVoucherDate = request.VoucherDate.AddMinutes(request.TimezoneOffset.Value); Task <List <CurrencyDetails> > currencyListTask = _dbContext.CurrencyDetails.Where(x => x.IsDeleted == false).ToListAsync(); if (request.IsExchangeGainLossVoucher) { request.VoucherDate = DateTime.UtcNow; } Task <List <ExchangeRateDetail> > exchangeRatePresentTask = _dbContext.ExchangeRateDetail.Where(x => x.Date.Date == request.VoucherDate.Date && x.IsDeleted == false).ToListAsync(); List <CurrencyDetails> currencyList = await currencyListTask; List <int> currencyIds = currencyList.Select(x => x.CurrencyId).ToList(); string currencyCode = currencyList.FirstOrDefault(x => x.CurrencyId == request.CurrencyId).CurrencyCode; List <ExchangeRateDetail> exchangeRatePresent = await exchangeRatePresentTask; if (!CheckExchangeRateIsPresent(currencyIds, exchangeRatePresent)) { throw new Exception(StaticResource.ExchagneRateNotDefined); } var officeDetail = await _dbContext.OfficeDetail.FirstOrDefaultAsync(o => o.OfficeId == request.OfficeId); //use OfficeCode if (officeDetail == null) { throw new Exception(StaticResource.officeCodeNotFound); } Task <FinancialYearDetail> financialYearTask = _dbContext.FinancialYearDetail.FirstOrDefaultAsync(o => o.IsDefault); Task <CurrencyDetails> currencyDetailTask = _dbContext.CurrencyDetails.FirstOrDefaultAsync(o => o.CurrencyId == request.CurrencyId); // NOTE: Dont remove this as we will need journal details in response Task <JournalDetail> journaldetailTask = _dbContext.JournalDetail.FirstOrDefaultAsync(o => o.JournalCode == request.JournalCode); int voucherCount = await _dbContext.VoucherDetail.Where(x => x.VoucherDate.Month == request.VoucherDate.Month && x.VoucherDate.Year == filterVoucherDate.Year && x.OfficeId == request.OfficeId && x.CurrencyId == request.CurrencyId).CountAsync(); FinancialYearDetail financialYear = await financialYearTask; if (financialYear == null) { throw new Exception(StaticResource.defaultFinancialYearIsNotSet); } CurrencyDetails currencyDetail = await currencyDetailTask; if (currencyDetail == null) { throw new Exception(StaticResource.CurrencyNotFound); } JournalDetail journaldetail = await journaldetailTask; VoucherDetail obj = _mapper.Map <VoucherDetail>(request); obj.JournalCode = journaldetail != null ? journaldetail.JournalCode : request.JournalCode; obj.FinancialYearId = financialYear.FinancialYearId; obj.CreatedById = request.CreatedById; obj.VoucherDate = request.VoucherDate; obj.CreatedDate = DateTime.UtcNow; obj.IsDeleted = false; // Pattern: Office Code - Currency Code - Month Number - voucher count on selected month - Year string referenceNo = AccountingUtility.GenerateVoucherReferenceCode(request.VoucherDate, voucherCount, currencyDetail.CurrencyCode, officeDetail.OfficeCode); int sameVoucherReferenceNoCount = 0; if (!string.IsNullOrEmpty(referenceNo)) { do { sameVoucherReferenceNoCount = await _dbContext.VoucherDetail.Where(x => x.ReferenceNo == referenceNo).CountAsync(); if (sameVoucherReferenceNoCount == 0) { obj.ReferenceNo = referenceNo; } else { //DO NOT REMOVE: This is used to get the latest voucher and then we will get the count of vouhcer sequence from it // VoucherDetail voucherDetail = _dbContext.VoucherDetail.OrderByDescending(x => x.VoucherDate).FirstOrDefault(x => x.VoucherDate.Month == filterVoucherDate.Month && x.OfficeId == request.OfficeId && x.VoucherDate.Year == filterVoucherDate.Year); var refNo = referenceNo.Split('-'); int count = Convert.ToInt32(refNo[3]); referenceNo = AccountingUtility.GenerateVoucherReferenceCode(request.VoucherDate, count, currencyCode, officeDetail.OfficeCode); } }while (sameVoucherReferenceNoCount != 0); } await _dbContext.VoucherDetail.AddAsync(obj); await _dbContext.SaveChangesAsync(); VoucherDetailEntityModel voucherModel = _mapper.Map <VoucherDetail, VoucherDetailEntityModel>(obj); return(voucherModel); } catch (Exception ex) { throw new Exception(ex.Message); } }
public int SaveJournalData(JournalForm JForm) { int autoId = 0; Journal obj = new Journal(); obj.J_No = JForm.JournalData.JournalNo; obj.J_Date = JForm.JournalData.JournalDate; try { using (SASEntitiesEDM entities = new SASEntitiesEDM()) { if (entities.Journals.AsNoTracking().FirstOrDefault(x => x.ID == JForm.JournalData.ID) == null) { //obj.CreatedBy = invoiceData.SIModel.CreatedBy; obj.J_CreatedDate = DateTime.Now; entities.Journals.Add(obj); entities.SaveChanges(); autoId = obj.ID; } else { // obj.ModifiedBy = invoiceData.SIModel.ModifiedBy; obj.J_ModifiedDate = DateTime.Now; entities.Entry(obj).State = EntityState.Modified; autoId = entities.SaveChanges(); } JForm.JournalData.ID = autoId; if (autoId > 0) { JournalDetail obj1; if (JForm.JournalaDataDetails != null) { foreach (JournalFormEntity JEntity in JForm.JournalaDataDetails) { //save entity value obj1 = new JournalDetail(); obj1.Acc_ID = JEntity.ID; obj1.JO_ID_ = autoId; obj1.JO_No = JForm.JournalData.JournalNo; obj1.JO_Date = JForm.JournalData.JournalDate; obj1.JO_Debit_ = JEntity.Debit; obj1.JO_Credit_ = JEntity.Credit; if (entities.JournalDetails.AsNoTracking().FirstOrDefault(x => x.ID == JEntity.ID) == null) { entities.JournalDetails.Add(obj1); entities.SaveChanges(); } else { entities.Entry(obj1).State = EntityState.Modified; entities.SaveChanges(); } } } } else { } } return(autoId); } catch (Exception ex) { return(0); throw ex; } //return 1; }
/// <summary> /// Update a General Ledger Journal after editing. /// </summary> public AjaxReturn DocumentSave(JournalDocument json) { Database.BeginTransaction(); Extended_Document document = json.header; JObject oldDoc = getCompleteDocument(document.idDocument); checkDocType(document.DocumentTypeId, DocType.GeneralJournal); allocateDocumentIdentifier(document); decimal total = 0, vat = 0; int lineNum = 1; Database.Update(document); Settings.RegisterNumber(this, (int?)DocType.GeneralJournal, Utils.ExtractNumber(document.DocumentIdentifier)); // Find any existing VAT record Journal vatJournal = Database.QueryOne <Journal>("SELECT * FROM Journal WHERE DocumentId = " + document.idDocument + " AND AccountId = " + (int)Acct.VATControl + " ORDER BY JournalNum DESC"); JournalDetail vatDetail = null; if (vatJournal.idJournal != null) { Database.Delete("Journal", (int)vatJournal.idJournal, false); } foreach (JournalDetail detail in json.detail) { if (detail.AccountId == 0) { Utils.Check(detail.Amount == 0, "All lines must be allocated to an account"); continue; } total += detail.Amount; if (detail.AccountId == (int)Acct.VATControl) { // Vat has to all be posted on the last line vatDetail = detail; vat += detail.Amount; continue; } // Get existing journal (if any) Journal journal = Database.Get(new Journal() { DocumentId = (int)document.idDocument, JournalNum = lineNum }); detail.Id = journal.Id; detail.DocumentId = (int)document.idDocument; detail.JournalNum = lineNum; if (detail.NameAddressId == null || detail.NameAddressId == 0) { detail.NameAddressId = string.IsNullOrWhiteSpace(detail.Name) ? 1 : Database.ForeignKey("NameAddress", "Type", "O", "Name", detail.Name); } // Change outstanding by the change in the amount detail.Outstanding = journal.Outstanding + detail.Amount - journal.Amount; Database.Update(detail); if (lineNum > 1) { // Create a dummy line record Line line = new Line() { idLine = detail.idJournal, Qty = 0, LineAmount = -detail.Amount, VatCodeId = null, VatRate = 0, VatAmount = 0 }; Database.Update(line); } lineNum++; } Utils.Check(total == 0, "Journal does not balance by {0}", total); // Delete any lines and journals that were in the old version, but not in the new Database.Execute("DELETE FROM Line WHERE idLine IN (SELECT idJournal FROM Journal WHERE DocumentId = " + document.idDocument + " AND JournalNum >= " + lineNum + ")"); Database.Execute("DELETE FROM Journal WHERE DocumentId = " + document.idDocument + " AND JournalNum >= " + lineNum); if (vat != 0 || vatJournal.idJournal != null) { // There is, or was, a posting to vat decimal changeInVatAmount = vat - vatJournal.Amount; vatJournal.DocumentId = (int)document.idDocument; vatJournal.AccountId = (int)Acct.VATControl; if (vatDetail != null) { if ((vatDetail.NameAddressId == null || vatDetail.NameAddressId == 0) && !string.IsNullOrWhiteSpace(vatDetail.Name)) { vatJournal.NameAddressId = Database.ForeignKey("NameAddress", "Type", "O", "Name", vatDetail.Name); } else { vatJournal.NameAddressId = vatDetail.NameAddressId; } } if (vatJournal.NameAddressId == null || vatJournal.NameAddressId == 0) { vatJournal.NameAddressId = 1; } vatJournal.Memo = "Total VAT"; vatJournal.JournalNum = lineNum++; vatJournal.Amount = vat; vatJournal.Outstanding += changeInVatAmount; Database.Update(vatJournal); } // Audit the change JObject newDoc = getCompleteDocument(document.idDocument); Database.AuditUpdate("Document", document.idDocument, oldDoc, newDoc); Settings.RegisterNumber(this, document.DocumentTypeId, Utils.ExtractNumber(document.DocumentIdentifier)); Database.Commit(); return(new AjaxReturn() { message = "Journal saved", id = document.idDocument }); }
public bool PostIncomeTax(string taxOfficeAccountNumber, string taxExpensesAccountNumber, int costCenterId, string referenceNumber, string statementReference) { bool isAdmin = AppUsers.GetCurrent().View.IsAdmin.ToBool(); if (!isAdmin) { throw new MixERPException(Warnings.AccessIsDenied); } if (string.IsNullOrWhiteSpace(taxOfficeAccountNumber) || string.IsNullOrWhiteSpace(taxExpensesAccountNumber)) { throw new MixERPException(Warnings.InvalidAccount); } string catalog = AppUsers.GetCurrentUserDB(); int officeId = AppUsers.GetCurrent().View.OfficeId.ToInt(); int userId = AppUsers.GetCurrent().View.UserId.ToInt(); long loginId = AppUsers.GetCurrent().View.LoginId.ToLong(); string currencyCode = AppUsers.GetCurrent().View.CurrencyCode; decimal tax = this.GetEoyProfitSummary().Tax; if (tax <= 0) { return(true); } DateTime valueDate = DatePersister.GetFrequencyDates(catalog, officeId).Today; DateTime eoyDate = DatePersister.GetFrequencyDates(catalog, officeId).FiscalYearEndDate; if (valueDate != eoyDate) { throw new MixERPException(Warnings.AccessIsDenied); } DateTime bookDate = valueDate; Collection <JournalDetail> details = new Collection <JournalDetail>(); JournalDetail liability = new JournalDetail { Account = string.Empty, AccountNumber = taxOfficeAccountNumber, Credit = tax, Debit = 0, CashRepositoryCode = string.Empty, CurrencyCode = currencyCode, ExchangeRate = 1, LocalCurrencyCredit = tax, LocalCurrencyDebit = 0, StatementReference = statementReference }; JournalDetail expenses = new JournalDetail { Account = string.Empty, AccountNumber = taxExpensesAccountNumber, Credit = 0, Debit = tax, CashRepositoryCode = string.Empty, CurrencyCode = currencyCode, ExchangeRate = 1, LocalCurrencyCredit = 0, LocalCurrencyDebit = tax, StatementReference = statementReference }; details.Add(liability); details.Add(expenses); Transaction.Add(catalog, valueDate, bookDate, officeId, userId, loginId, costCenterId, referenceNumber, details, new Collection <Attachment>()); return(true); }
public void UpdateJournalDetail(JournalDetail currentJournalDetail) { this.ObjectContext.JournalDetail.AttachAsModified(currentJournalDetail, this.ChangeSet.GetOriginal(currentJournalDetail)); }