示例#1
0
        private async Task <AccountingDocument> GetInformationForMonthEndTA(
            bool postOpClosedPrivilege,
            long docId,
            int docTypeId,
            AccountingSetupDto accountingSetup,
            Company company,
            DateTime companyDate,
            MonthEndTADocumentDto monthEndTADocument)
        {
            AccountingDocument accountingDocument = null;

            DateTime documentDate = new DateTime(monthEndTADocument.ValueDate.Value.Year, monthEndTADocument.ValueDate.Value.Month, 1).AddDays(-1);

            var fxRates = CommonRules.GetFxRateInformation(documentDate, monthEndTADocument.CurrencyCode, company);

            if (monthEndTADocument != null && fxRates.AreAllFilled())
            {
                accountingDocument = await CommonRules.CreateAccountingDocument(_masterDataService, _identityService.GetUserAtlasId(), postOpClosedPrivilege, docId, docTypeId, CommonRules.BaseCurrency, fxRates.FxRateInvoiceCurrency, accountingSetup, null, null, null, null, null, monthEndTADocument);

                if (accountingDocument != null)
                {
                    accountingDocument.AccountingDocumentLines = await CreateAccountingDocumentLines(docTypeId, company, accountingSetup, fxRates, null, null, null, null, null, null, monthEndTADocument);

                    accountingDocument.StatusId = await CommonRules.GetAccountingDocumentStatus(accountingSetup, _accountingQueries, accountingDocument, company.CompanyId, companyDate, null, null);
                }
            }

            return(accountingDocument);
        }
        private async Task <AccountingDocument> CreateAccountingDocumentForFxDeal(bool postOpClosedPolicy, long docId, int docTypeId, AccountingSetupDto accountingSetup, Company company, string companyId, DateTime companyDate)
        {
            AccountingDocument      accountingDocument   = new AccountingDocument();
            FxSettlementDocumentDto fxSettlementDocument = null;
            FxRateInformation       fxRates = null;

            fxSettlementDocument = await _accountingQueries.GetFxSettlementbyTransactionDocumentId(docId, company.CompanyId);

            if (fxSettlementDocument.FxSettlementDocumentTypeId == FxSettlementDocumentType.FxDeal)
            {
                fxRates = CommonRules.GetFxRateInformation(fxSettlementDocument.DocumentDate, fxSettlementDocument.CurrencyCode, company);
            }
            else
            {
                fxRates = CommonRules.GetFxRateInformation(fxSettlementDocument.DocumentDate, fxSettlementDocument.SettlementCurrencyCode, company);
            }

            if (fxSettlementDocument != null && fxRates.AreAllFilled())
            {
                accountingDocument = await CommonRules.CreateAccountingDocument(_masterDataService, _identityService.GetUserAtlasId(), postOpClosedPolicy, docId, docTypeId, CommonRules.BaseCurrency, fxRates.FxRateInvoiceCurrency, accountingSetup, null, null, null, null, null, null, null, null, fxSettlementDocument);

                accountingDocument.AccountingPeriod = CommonRules.CalculateAccountPeriod(accountingSetup, fxSettlementDocument.DocumentDate, postOpClosedPolicy);
                accountingDocument.AccrualNumber    = CommonRules.IsLastMonthForOperationOpen(accountingSetup.LastMonthClosedForOperation, fxSettlementDocument.DocumentDate) ?
                                                      fxSettlementDocument.AccrualNumber :
                                                      null;
                accountingDocument.AccountingDate = accountingDocument.DocumentDate.Year == accountingDocument.AccountingPeriod.Year &&
                                                    accountingDocument.DocumentDate.Month == accountingDocument.AccountingPeriod.Month ?
                                                    accountingDocument.DocumentDate :
                                                    new DateTime(accountingDocument.AccountingPeriod.Year, accountingDocument.AccountingPeriod.Month, 1);

                if (accountingDocument != null)
                {
                    accountingDocument.AccountingDocumentLines = await CreateAccountingDocumentLines(docTypeId, company, accountingSetup, fxRates, null, null, null, null, null, null, null, fxSettlementDocument);

                    accountingDocument.StatusId = await CommonRules.GetAccountingDocumentStatus(accountingSetup, _accountingQueries, accountingDocument, company.CompanyId, companyDate, null, null);
                }
            }

            return(accountingDocument);
        }
示例#3
0
        private async Task <AccountingDocument> GetInformationForManualJournal(bool postOpClosedPolicy, long docId, int docTypeId, AccountingSetupDto accountingSetup, Company company, DateTime companyDate)
        {
            AccountingDocument accountingDocument = null;

            ManualJournalDocumentDto manualJournal = null;

            manualJournal = await _accountingQueries.GetManualJournalbyTransactionDocumentId(docId, company.CompanyId);

            var fxRates = CommonRules.GetFxRateInformation(manualJournal.DocumentDate, manualJournal.CurrencyCode, company);

            if (manualJournal != null && fxRates.AreAllFilled())
            {
                accountingDocument = await CommonRules.CreateAccountingDocument(_masterDataService, _identityService.GetUserAtlasId(), postOpClosedPolicy, docId, docTypeId, CommonRules.BaseCurrency, fxRates.FxRateInvoiceCurrency, accountingSetup, null, null, null, manualJournal);

                if (accountingDocument != null)
                {
                    accountingDocument.AccountingDocumentLines = await CreateAccountingDocumentLines(docTypeId, company, accountingSetup, fxRates, null, null, null, null, manualJournal);

                    accountingDocument.StatusId = await CommonRules.GetAccountingDocumentStatus(accountingSetup, _accountingQueries, accountingDocument, company.CompanyId, companyDate, null, null);
                }
            }

            return(accountingDocument);
        }
        private async Task <List <AccountingDocument> > GetInformationForCash(bool postOpClosedPrivilege, long docId, int docTypeId, AccountingSetupDto accountingSetup, Company company, DateTime companyDate)
        {
            List <AccountingDocument> accountingDocuments = new List <AccountingDocument>();
            CashInformationDto        cashInformation     = await _accountingQueries.GetCashInformationForAccountingDocument(docId, company.CompanyId);

            if (accountingSetup == null)
            {
                throw new Exception("No accounting setup found.");
            }

            var fxRates = CommonRules.GetFxRateInformation(cashInformation.DocumentDate, cashInformation.Currency, company);

            if (cashInformation.CashTypeId == (int)CashSelectionType.SimpleCashPayment || cashInformation.CashTypeId == (int)CashSelectionType.SimpleCashReceipt)
            {
                /* Simple cash */

                var accountingDocument = await CommonRules.CreateAccountingDocument(_masterDataService, _identityService.GetUserAtlasId(), postOpClosedPrivilege, docId, docTypeId, CommonRules.BaseCurrency, fxRates.FxRateInvoiceCurrency, accountingSetup, null, cashInformation);

                if (accountingDocument != null)
                {
                    accountingDocument.AccountingDocumentLines = await CreateAccountingDocumentLines(docTypeId, company, accountingSetup, fxRates, null, null, null, cashInformation);

                    accountingDocuments.Add(accountingDocument);
                    accountingDocument.StatusId = await CommonRules.GetAccountingDocumentStatus(accountingSetup, _accountingQueries, accountingDocument, company.CompanyId, companyDate, null, cashInformation);
                }

                // the cashLines list is supposed to contain one unique cash line information  ; we initialize the "C" acc line with the ID of the cash line
                if (cashInformation.CashLines != null && cashInformation.CashLines.Any())
                {
                    var cashLineRecord = cashInformation.CashLines.FirstOrDefault();
                    foreach (var accountingLine in accountingDocument.AccountingDocumentLines)
                    {
                        if (accountingLine.AccountingCategoryId == (int)AccountingCategory.C)
                        {
                            accountingLine.SourceCashLineId = cashLineRecord.CashLineId;
                        }
                    }
                }
            }
            else
            {
                /* Cash by picking */
                var accountingDocument = await CommonRules.CreateAccountingDocument(_masterDataService, _identityService.GetUserAtlasId(), postOpClosedPrivilege, docId, docTypeId, CommonRules.BaseCurrency, fxRates.FxRateInvoiceCurrency, accountingSetup, null, cashInformation);

                accountingDocument.AccountingDocumentLines = await CreateAccountingDocumentLinesForCashPickingTransaction(docTypeId, company, fxRates, accountingSetup, cashInformation);

                accountingDocument.StatusId = await CommonRules.GetAccountingDocumentStatus(accountingSetup, _accountingQueries, accountingDocument, company.CompanyId, companyDate, null, cashInformation);

                accountingDocuments.Add(accountingDocument);

                // If diff ccy, then process the paid cash (the one with the same currency than the invoices)
                if (cashInformation.CashTypeId == (int)CashSelectionType.PaymentDifferentCurrency || cashInformation.CashTypeId == (int)CashSelectionType.ReceiptDifferentCurrency)
                {
                    // Get information for the paid cash
                    CashInformationDto paidCashInformation = await _accountingQueries.GetCashInformationForAccountingDocument(cashInformation.PaymentTransactionDocumentId.Value, company.CompanyId);

                    if (paidCashInformation == null)
                    {
                        throw new AtlasBusinessException("Cannot retrieve information for the associated cash.");
                    }

                    fxRates = CommonRules.GetFxRateInformation(paidCashInformation.DocumentDate, paidCashInformation.Currency, company);
                    var accountingDocumentForPaidCash = await CommonRules.CreateAccountingDocument(_masterDataService, _identityService.GetUserAtlasId(), postOpClosedPrivilege, cashInformation.PaymentTransactionDocumentId.Value, docTypeId, CommonRules.BaseCurrency, fxRates.FxRateInvoiceCurrency, accountingSetup, null, paidCashInformation);

                    // Create the lines for the accounting document in the cash currency (in case of diff ccy)
                    accountingDocumentForPaidCash.AccountingDocumentLines = await CreateAccountingDocumentLineForCashPaidCashInAnotherCcy(docTypeId, company, fxRates, accountingSetup, cashInformation, paidCashInformation);

                    // We don't want this accounting document to be individually posted ; the posting will be done
                    // automatically when posting the matched cash. Puttin the status id to the value "Incomplete" prevent to send this document to the message queue
                    // later in the code
                    accountingDocumentForPaidCash.StatusId = PostingStatus.Incomplete;

                    // Overriding the Roe + type with the information entered by the end user within the screen
                    // (we don't want to use the "current" roe)
                    // This is done the cash which is NOT in USD ; as a reminder, in cash by picking diff ccy, we have the assumption that
                    // one of the currency is USD, and the second is not!
                    if (accountingDocument.CurrencyCode != "USD")
                    {
                        accountingDocument.Roe = paidCashInformation.MatchingRate;
                    }
                    else
                    {
                        accountingDocumentForPaidCash.Roe = paidCashInformation.MatchingRate;
                    }

                    accountingDocuments.Add(accountingDocumentForPaidCash);
                }
            }

            return(accountingDocuments);
        }
示例#5
0
        private async Task <AccountingDocument> GetInformationForInvoice(bool postOpClosedPrivilege, long docId, int docTypeId, AccountingSetupDto accountingSetup, Company company, string companyId, DateTime companyDate)
        {
            AccountingDocument    accountingDocument;
            InvoiceInformationDto invoiceInformation;
            BusinessSectorDto     businessSectorInfo;
            IEnumerable <SectionsInformationDto> sectionsInformation;

            IEnumerable <Vat> vat = null;

            invoiceInformation = await _accountingQueries.GetInvoiceInformationForAccountingDocument(docId, company.CompanyId);

            if (invoiceInformation != null)
            {
                if (invoiceInformation.BusinessSectorNominalPostingPurpose == true)
                {
                    var businessSectorCode = invoiceInformation.InvoiceLines.FirstOrDefault().BusinessSectorCode;
                    if (businessSectorCode != null)
                    {
                        businessSectorInfo = await _accountingQueries.GetAccountNumberbyBusinessSectorId(company.CompanyId, businessSectorCode);

                        if (businessSectorInfo != null)
                        {
                            invoiceInformation.CostTypeCode     = businessSectorInfo.CostTypeCode;
                            invoiceInformation.AccountReference = businessSectorInfo.AccountNumber;
                        }
                    }
                }

                sectionsInformation = await _accountingQueries.GetSectionsInformationForAccountingDocument(companyId, invoiceInformation.InvoiceId);

                var vatCodes = invoiceInformation.InvoiceLines.Select(x => x.VATCode).Distinct();

                if (sectionsInformation != null && sectionsInformation.Any())
                {
                    vat = await _masterDataService.GetVat(vatCodes, companyId);

                    var blDateList = sectionsInformation.Where(section => section.BLDate != null).ToList();

                    DateTime?blDate = null;

                    if (blDateList.Count > 0)
                    {
                        blDate = blDateList.OrderByDescending(x => x.BLDate).FirstOrDefault().BLDate.Value;

                        if (blDate == null)
                        {
                            blDate = invoiceInformation.InvoiceDate;
                        }
                    }
                    else
                    {
                        blDate = invoiceInformation.InvoiceDate;
                    }

                    var fxRates = CommonRules.GetFxRateInformation((DateTime)blDate, invoiceInformation.Currency, company);

                    if (accountingSetup != null && fxRates.AreAllFilled() && company != null && vat != null)
                    {
                        accountingDocument = await CommonRules.CreateAccountingDocument(_masterDataService, _identityService.GetUserAtlasId(), postOpClosedPrivilege, docId, docTypeId, CommonRules.BaseCurrency, fxRates.FxRateInvoiceCurrency, accountingSetup, invoiceInformation, null, blDate);

                        if (accountingDocument != null)
                        {
                            accountingDocument.AccountingDocumentLines = await CreateAccountingDocumentLines(docTypeId, company, accountingSetup, fxRates, vat, invoiceInformation, sectionsInformation);

                            CommonRules.PostingLineIdOrder(accountingDocument.AccountingDocumentLines);

                            accountingDocument.StatusId = await CommonRules.GetAccountingDocumentStatus(accountingSetup, _accountingQueries, accountingDocument, company.CompanyId, companyDate, invoiceInformation);

                            _logger.LogInformation("Doc with id {Atlas_DocId}.", docId);
                        }
                        else
                        {
                            throw new Exception("Unable to create document header and lines");
                        }
                    }
                    else
                    {
                        throw new Exception("Unable to create document header and lines. Insufficient Information");
                    }
                }
                else
                {
                    throw new Exception("Unable to create document header and lines. There is no section information available.");
                }
            }
            else
            {
                throw new Exception("Unable to create document header and lines. There is no invoice information available.");
            }

            return(accountingDocument);
        }