Esempio n. 1
0
        private CompanyRecord CreateCompanyRecord(GAFPeriod gafPeriod, GSTAuditFile gstAuditFile, DateTime creationDate)
        {
            var companyRecord = new CompanyRecord();

            var branch      = _gafRepository.GetBranchByID(gafPeriod.BranchID);
            var baccount    = _gafRepository.GetBAccountByID(branch.BAccountID);
            var mainContact = _gafRepository.GetContact(baccount.DefContactID);

            companyRecord.CompanyName      = mainContact.FullName;
            companyRecord.CompanyBRN       = baccount.AcctReferenceNbr;
            companyRecord.CompanyGSTNumber = baccount.TaxRegistrationID;

            var taxPeriod = _gafRepository.GetTaxPeriodByKey(gafPeriod.BranchID, gafPeriod.TaxAgencyID, gafPeriod.TaxPeriodID);

            companyRecord.PeriodStartDate = taxPeriod.StartDate.Value;
            companyRecord.PeriodEndDate   = taxPeriod.EndDateUI.Value;

            companyRecord.FileCreationDate = creationDate;

            var acumaticaVersion = _gafRepository.GetAcumaticaVersion();

            companyRecord.ProductVersion = String.Concat("Acumatica", acumaticaVersion.CurrentVersion);
            companyRecord.GAFVersion     = String.Format(GafVersionTemplate, gstAuditFile.MajorVersion, GafVersionDelimiter,
                                                         gstAuditFile.MinorVersion);

            return(companyRecord);
        }
Esempio n. 2
0
        private void SetGAFVersion(GSTAuditFile gstAuditFile, GAFPeriod gafPeriod)
        {
            if (gafPeriod.GAFMajorVersion == null)
            {
                var maxGAFMajorVersion = _gafRepository.GetMaxGAFMajorVersion(gafPeriod);

                if (maxGAFMajorVersion != null)
                {
                    gstAuditFile.MajorVersion = maxGAFMajorVersion.Value + 1;
                }
                else
                {
                    gstAuditFile.MajorVersion = 1;
                }

                gstAuditFile.MinorVersion = 0;
            }
            else
            {
                gstAuditFile.MajorVersion = gafPeriod.GAFMajorVersion.Value;
                gstAuditFile.MinorVersion = gafPeriod.GAFMinorLastVersion.Value + 1;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates GST File data.
        /// </summary>
        public GSTAuditFile Create(GAFPeriod gafPeriod, DateTime creationDate)
        {
            if (gafPeriod == null)
            {
                throw new ArgumentNullException(nameof(gafPeriod));
            }

            var validationResult = _gafValidator.ValidateTaxYearStructure(_gafRepository.GetTaxPeriodByKey(gafPeriod.BranchID, gafPeriod.TaxAgencyID, gafPeriod.TaxPeriodID));

            validationResult.RaiseIfHasError();

            var documentIds = _gafRepository.GetReportedDocuments(gafPeriod.BranchID, gafPeriod.TaxAgencyID, gafPeriod.TaxPeriodID)
                              .ToArray();

            if (!documentIds.Any())
            {
                return(null);
            }


            #region Initialization

            var glDocumentIds = documentIds.Where(documentId => _glTaxDocumentTypes.Contains(documentId.DocType))
                                .ToArray();

            var documentGroups = SplitToDocumentGroups(documentIds.Except(glDocumentIds));

            if (glDocumentIds.Any())
            {
                var glDocumentGroup = BuildGLDocumentGroup(glDocumentIds);

                documentGroups.Add(glDocumentGroup);
            }

            var documentProcessingQueue = new GAFDocumentProcessingQueue(documentGroups);

            var gafDataStringBuilder = new StringBuilder();

            _purchaseGAFDataStringBuilder = new StringBuilder();
            _supplyGAFDataStringBuilder   = new StringBuilder();

            var footerRecord = new FooterRecord();
            var gstAuditFile = new GSTAuditFile();

            #endregion


            #region Processing

            SetGAFVersion(gstAuditFile, gafPeriod);

            var companyRecord = CreateCompanyRecord(gafPeriod, gstAuditFile, creationDate);
            _gafRecordWriter.WriteCompanyRecord(companyRecord, gafDataStringBuilder);

            #region Documents

            var documentGroup = documentProcessingQueue.GetNextDocumentGroup();

            while (documentGroup != null)
            {
                CreateGAFDataByDocumentGroup(documentGroup, gafPeriod, footerRecord);

                _gafRepository.ClearCaches();

                documentGroup = documentProcessingQueue.GetNextDocumentGroup();
            }

            gafDataStringBuilder.Append(_purchaseGAFDataStringBuilder);
            gafDataStringBuilder.Append(_supplyGAFDataStringBuilder);

            #endregion


            #region Ledger

            var ledgerRecords = _glgafLedgerRecordsCreator.CreateLedgerRecords(gafPeriod);

            AddAmountsAndCountToFooterRecord(footerRecord, ledgerRecords);

            foreach (var ledgerRecord in ledgerRecords)
            {
                _gafRecordWriter.WriteLedgerRecord(ledgerRecord, gafDataStringBuilder);
            }

            #endregion


            _gafRecordWriter.WriteFooterRecord(footerRecord, gafDataStringBuilder);

            #endregion


            gstAuditFile.Data = gafDataStringBuilder.ToString();

            var branch = _gafRepository.GetBranchByID(gafPeriod.BranchID);

            gstAuditFile.FileName = string.Concat(branch.BranchCD.Trim(), "_",
                                                  string.Format(GafVersionTemplate, gstAuditFile.MajorVersion, GafVersionDelimiterForFileName,
                                                                gstAuditFile.MinorVersion), ".txt");

            return(gstAuditFile);
        }