public async Task <ActionResult <AccountingSetupDto> > GetAccountingSetup(string company) { var accountingSetUp = await _accountingSetUpQueries.GetAccountingSetup(company); if (accountingSetUp != null) { return(Ok(accountingSetUp)); } return(Ok(accountingSetUp)); }
internal async Task <int> GetDocumentReferenceYear(DateTime documentDate, string company) { bool isPostOpClosedPrivilege = false; int documentDateYear = 0; isPostOpClosedPrivilege = true; // await CheckPrivileges(); AccountingSetupDto accountingSetup = await _accountingQueries.GetAccountingSetup(company); if (IsLastMonthOpenForAccounting(accountingSetup.LastMonthClosed, documentDate, accountingSetup.NumberOfOpenPeriod)) { if (IsOperationLastMonthClosed(accountingSetup.LastMonthClosedForOperation, documentDate)) { documentDateYear = documentDate.Year; } else { if (isPostOpClosedPrivilege) { documentDateYear = documentDate.Year; } else { int nextOpenMonthForOperations = accountingSetup.LastMonthClosedForOperation.Month + 1; if (nextOpenMonthForOperations > 12) { documentDateYear = accountingSetup.LastMonthClosedForOperation.Year + 1; } else { documentDateYear = accountingSetup.LastMonthClosedForOperation.Year; } } } } else { int nextOpenMonthForOperations = accountingSetup.LastMonthClosedForOperation.Month + 1; if (nextOpenMonthForOperations > 12) { documentDateYear = accountingSetup.LastMonthClosedForOperation.Year + 1; } else { documentDateYear = accountingSetup.LastMonthClosedForOperation.Year; } } return(documentDateYear); }
public async Task <ManualJournalResponse> Handle(CreateManualJournalDocumentCommand request, CancellationToken cancellationToken) { _unitOfWork.BeginTransaction(); AccountingSetupDto accountingSetup = null; Company company = null; try { string documentLabel = string.Empty; string year = string.Empty; int documentReferenceYear = 0; string documentReferenceYearValue = string.Empty; ManualJournalDocument manualJournalDocument = request.ManualJournal; company = await _masterDataService.GetCompanyByIdAsync(request.Company); CommonRules commonRules = new CommonRules(_accountingQueries, _authorizationService, _identityService); if (manualJournalDocument.AccountingPeriod.Year < manualJournalDocument.DocumentDate.Year || (manualJournalDocument.AccountingPeriod.Year <= manualJournalDocument.DocumentDate.Year && manualJournalDocument.AccountingPeriod.Month < manualJournalDocument.DocumentDate.Month)) { throw new AtlasBusinessException("A/c period should not be before doc. Date"); } accountingSetup = await _accountingQueries.GetAccountingSetup(request.Company); if (accountingSetup != null) { if (await CheckIfDocumentDateAccountingPeriodValid(manualJournalDocument, accountingSetup)) { if (company.IsProvinceEnable) { foreach (var item in manualJournalDocument.ManualJournalLines) { item.ProvinceId = company.DefaultProvinceId; item.BranchId = company.DefaultBranchId; } } else { foreach (var item in manualJournalDocument.ManualJournalLines) { item.ProvinceId = item.BranchId = null; } } if (manualJournalDocument.TransactionDocumentTypeId == (int)MasterDocumentType.TA || manualJournalDocument.TransactionDocumentTypeId == (int)MasterDocumentType.JL) { documentLabel = Enum.GetName(typeof(MasterDocumentType), manualJournalDocument.TransactionDocumentTypeId); year = manualJournalDocument.DocumentDate.Year.ToString(CultureInfo.InvariantCulture).Substring(2, 2); documentReferenceYear = await commonRules.GetDocumentReferenceYear(manualJournalDocument.DocumentDate, request.Company); documentReferenceYearValue = documentReferenceYear.ToString(System.Globalization.CultureInfo.InvariantCulture).Substring(2, 2); } if (manualJournalDocument.TransactionDocumentTypeId == (int)MasterDocumentType.JL) { manualJournalDocument.JLTypeId = (int)JLType.ManualRegularJournal; } else if (manualJournalDocument.TransactionDocumentTypeId == (int)MasterDocumentType.TA) { if (manualJournalDocument.TATypeId != null) { manualJournalDocument.TATypeId = (int)TAType.ManualMarkToMarket; } else { manualJournalDocument.TATypeId = (int)TAType.ManualTemporaryAdjustment; } } int referencenumber = await _manualJournalQueries.GetManualDocumentReferenceValues(request.Company, (int)manualJournalDocument.TransactionDocumentTypeId, documentReferenceYear); manualJournalDocument.YearNumber = referencenumber; manualJournalDocument.Year = documentReferenceYear; manualJournalDocument.DocumentReference = string.Concat(documentLabel, documentReferenceYearValue, string.Format(CultureInfo.InvariantCulture, "{0:D5}", referencenumber)); var objResponse = await _manualJournalRepository.CreateManualJournal(manualJournalDocument, request.Company); var authorizationResult = await _authorizationService.AuthorizeAsync(_identityService.GetUser(), Policies.PostOpClosedPolicy); var content = new JObject(); content.Add(new JProperty("docId", objResponse.TransactionDocumentId)); content.Add(new JProperty("postOpClosedPolicy", authorizationResult.Succeeded)); Atlas.Application.Core.Entities.ProcessMessage message = new Atlas.Application.Core.Entities.ProcessMessage { ProcessTypeId = (long)Atlas.Application.Core.Entities.ProcessType.AtlasAccountingDocumentProcessor, CompanyId = request.Company, Content = content.ToString(), }; await _processMessageService.SendMessage(message); _unitOfWork.Commit(); return(objResponse); } else { throw new AtlasSecurityException($"Please check the document date and accounting period"); } } else { throw new AtlasSecurityException($"No Accounting Setup found"); } } catch { _unitOfWork.Rollback(); throw; } }
public async Task <MonthEndTAResponse> Handle(MonthEndTemporaryAdjustmentListCommand request, CancellationToken cancellationToken) { _unitOfWork.BeginTransaction(); try { List <MonthEndTemporaryAdjustmentReport> monthEndTemporaryAdjustmentData = new List <MonthEndTemporaryAdjustmentReport>(); if (request.ReportType == 3) { monthEndTemporaryAdjustmentData = await GetFxDealMonthEndTemporaryAdjustment(request.Company, request.DataVersionId); } else { monthEndTemporaryAdjustmentData = await GetMonthEndTemporaryAdjustment(request.Company, (int)MonthEndType.Postings, request.ReportType, request.DataVersionId, request.AccountingPeriod, request.DocumentDate); } var accountingSetUp = await _accountingSetUpQueries.GetAccountingSetup(request.Company); if (accountingSetUp != null) { request.AccountingPeriod = CalculateAccountPeriod(accountingSetUp, request.DocumentDate); } else { throw new Exception("Unable to create document header and lines"); } var response = await _monthEndTemporaryAdjustmentRepository.SaveMonthEndReport(monthEndTemporaryAdjustmentData, request.Company, request.DataVersionId, request.ReportType, request.DocumentDate, request.AccountingPeriod); List <Atlas.Application.Core.Entities.ProcessMessage> postingProcessMessage = new List <Atlas.Application.Core.Entities.ProcessMessage>(); var authorizationResult = await _authorizationService.AuthorizeAsync(_identityService.GetUser(), Policies.PostOpClosedPolicy); foreach (var documentId in response.TransactionDocumentId) { var content = new JObject(); content.Add(new JProperty("docId", documentId)); content.Add(new JProperty("postOpClosedPolicy", authorizationResult.Succeeded)); Atlas.Application.Core.Entities.ProcessMessage message = new Atlas.Application.Core.Entities.ProcessMessage { ProcessTypeId = (int)Atlas.Application.Core.Entities.ProcessType.AtlasAccountingDocumentProcessor, CompanyId = request.Company, Content = content.ToString(), }; postingProcessMessage.Add(message); } await _processMessageService.SendBulkMessage(postingProcessMessage); _unitOfWork.Commit(); _logger.LogInformation("autoreversal have been created:", response); return(response); } catch { _unitOfWork.Rollback(); throw; } }