Пример #1
0
        /// <summary>
        /// Returns the current service status for the specified company. If there are no submissions
        /// against this company it will always return ssIdle.
        /// </summary>
        /// <param name="ForCompany"></param>
        /// <returns>ServiceStatus</returns>
        public ServiceStatus Status(string ForCompany)
        {
            // Return idle if no record found.
            ServiceStatus status = ServiceStatus.ssIdle;

            VAT100Record Entry = null;

            // PKR. 15/09/2015. ABSEXCH-16855. Status of a submission in one company is affecting other companies.
            // Get the record that is submitted or pending for this company.
            // If there isn't one, we get null back.
            Entry = FDatabase.GetPendingVAT100Entry(ForCompany);
            if (Entry != null)
            {
                status = (ServiceStatus)Entry.status;
            }

            /*
             *    // We don't need this.  We are looking only for the submission status for the specified company -
             *    // the one passed in - NOT for any company.
             *
             *    Enterprise04.ICompanyDetail CompanyDetail;
             *    // Cycle through all the companies
             *    int CompanyCount = FDatabase.tToolkit.Company.cmCount;
             *    for (int i = 1; i <= CompanyCount; i++)
             *      {
             *      // Point the Toolkit at the company path (getPendingVAT100Entry will
             *      // open and close the Toolkit using this path)
             *      CompanyDetail = FDatabase.tToolkit.Company.get_cmCompany(i);
             *
             *      // Find any pending VAT Submission for this company and add it to the list
             *      Entry = FDatabase.GetPendingVAT100Entry(CompanyDetail.coCode);
             *      if (Entry != null)
             *        {
             *        status = (ServiceStatus)Entry.status;
             *        }
             *      }
             */
            return(status);
        }
Пример #2
0
        //---------------------------------------------------------------------------------------------
        /// <summary>
        /// Scans the VAT100 tables in all companies to find the next VAT
        /// submission that is waiting for a response from HMRC, and returns
        /// a DocumentRecord containing the details.
        /// </summary>
        /// <returns></returns>
        private DocumentRecord SelectNextDocument()
        {
            Enterprise04.ICompanyDetail CompanyDetail;

            DocumentRecord document = null;

            // Cycle through all the companies
            int CompanyCount = FDatabase.tToolkit.Company.cmCount;

            for (int i = 1; i <= CompanyCount; i++)
            {
                // Point the Toolkit at the company path (getPendingVAT100Entry will
                // open and close the Toolkit using this path)
                CompanyDetail = FDatabase.tToolkit.Company.get_cmCompany(i);

                // Find any pending VAT Submission for this company and add it to the list
                VAT100Record Entry = FDatabase.GetPendingVAT100Entry(CompanyDetail.coCode);
                if (Entry != null)
                {
                    document             = new DocumentRecord();
                    document.theDocument = Entry;
                    document.companyCode = CompanyDetail.coCode;
                    document.companyPath = CompanyDetail.coPath;
                    document.status      = ServiceStatus.ssPolling;
                    break;
                }
            }

            if (document == null)
            {
                // No more pending documents, so revert back to the
                // slow polling interval.
                pollingTimer.Interval = DEFAULT_POLLING_INTERVAL;
            }

            return(document);
        }
Пример #3
0
        //---------------------------------------------------------------------------------------------
        /// <summary>
        /// Adds a VAT100 record to the database
        /// </summary>
        /// <param name="aVATRecord"></param>
        /// <returns></returns>
        public int AddVAT100Entry(VAT100Record aVATRecord, string ForCompanyCode)
        {
            IVAT100 oVAT100 = null;
            int     Res     = -1;

#if DEBUG
            Log.Add(string.Format("Adding record for [{0}] :", ForCompanyCode));
            Log.Add(string.Format(" Correlation ID : [{0}]", aVATRecord.correlationID));
            Log.Add(string.Format(" HMRC Narrative : [{0}]", aVATRecord.hmrcNarrative));
#endif
            string path = GetCompanyPath(ForCompanyCode);
            if (path == "")
            {
                return(12); // File not found
            }
            // PKR. 15/09/2015. ABSEXCH-16839. Close toolkit before changing path.
            if (tToolkit.Status == TToolkitStatus.tkOpen)
            {
                tToolkit.CloseToolkit();
            }
            tToolkit.Configuration.DataDirectory = path;
            Res = tToolkit.OpenToolkit();

            if (Res == 0)
            {
                try
                {
                    try
                    {
                        oVAT100 = (tToolkit as ICSNFToolkit).VAT100.Add();

                        oVAT100.vatCorrelationId       = aVATRecord.correlationID;
                        oVAT100.vatIRMark              = aVATRecord.IRMark;
                        oVAT100.vatDateSubmitted       = aVATRecord.dateSubmitted;
                        oVAT100.vatDocumentType        = aVATRecord.documentType;
                        oVAT100.vatPeriod              = aVATRecord.VATPeriod;
                        oVAT100.vatUserName            = aVATRecord.username;
                        oVAT100.vatStatus              = aVATRecord.status;
                        oVAT100.vatPollingInterval     = aVATRecord.pollingInterval;
                        oVAT100.vatDueOnOutputs        = aVATRecord.VATDueOnOutputs;
                        oVAT100.vatDueOnECAcquisitions = aVATRecord.VATDueOnECAcquisitions;
                        oVAT100.vatTotal             = aVATRecord.VATTotal;
                        oVAT100.vatReclaimedOnInputs = aVATRecord.VATReclaimedOnInputs;
                        oVAT100.vatNet = aVATRecord.VATNet;
                        oVAT100.vatNetSalesAndOutputs    = aVATRecord.netSalesAndOutputs;
                        oVAT100.vatNetPurchasesAndInputs = aVATRecord.netPurchasesAndInputs;
                        oVAT100.vatNetECSupplies         = aVATRecord.netECSupplies;
                        oVAT100.vatNetECAcquisition      = aVATRecord.netECAcquisitions;
                        oVAT100.vatNotifyEmail           = aVATRecord.notifyEmail;
                        oVAT100.vatPollingURL            = aVATRecord.PollingURL;
                        oVAT100.vatHMRCNarrative         = aVATRecord.hmrcNarrative;

                        Res = oVAT100.Save();

                        if (Res != 0)
                        {
                            LogText("An error occurred adding a record to the VAT 100 database.\r\n" + tToolkit.LastErrorString);
                        }
                    }
                    catch (Exception ex)
                    {
                        lastErrorString = ex.Message;
                        LogText("AddVAT100Entry : " + ex.Message);
                    }
                }
                finally
                {
                    Res = tToolkit.CloseToolkit();
                }
            }
            else
            {
                LogText("Failed to open COM toolkit");
                lastErrorString = "AddVAT100Entry : Failed to open COM toolkit";
            }

            return(Res);
        }
Пример #4
0
        //---------------------------------------------------------------------------------------------
        /// <summary>
        /// Updates the record in the VAT100 table
        /// </summary>
        /// <param name="aVATRecord"></param>
        /// <returns></returns>
        public int UpdateVAT100Entry(VAT100Record aVATRecord, string ForCompanyCode)
        {
            IVAT100 oVAT100 = null;

            int Res = 0;

            LogText("Updating DB record for CorrelationID " + aVATRecord.correlationID);

            // Find the record, based on Correlation ID
            string path = GetCompanyPath(ForCompanyCode);

            if (path == "")
            {
                return(12); // File not found
            }
            // PKR. 15/09/2015. ABSEXCH-16839. Close toolkit before changing path.
            if (tToolkit.Status == TToolkitStatus.tkOpen)
            {
                tToolkit.CloseToolkit();
            }
            tToolkit.Configuration.DataDirectory = path;
            Res = tToolkit.OpenToolkit();

            if (Res == 0)
            {
                try
                {
                    try
                    {
                        // Look for the entry to update
                        oVAT100 = (tToolkit as ICSNFToolkit).VAT100;
                        Res     = oVAT100.GetFirst();
                        while (Res == 0)
                        {
                            // See if it's the required record
                            if (oVAT100.vatCorrelationId == aVATRecord.correlationID)
                            {
                                // Matched
                                // Update the values
                                IVAT100 uRec = oVAT100.Update();

                                if (uRec != null)
                                {
                                    uRec.vatIRMark              = aVATRecord.IRMark;
                                    uRec.vatDateSubmitted       = aVATRecord.dateSubmitted;
                                    uRec.vatDocumentType        = aVATRecord.documentType;
                                    uRec.vatPeriod              = aVATRecord.VATPeriod;
                                    uRec.vatUserName            = aVATRecord.username;
                                    uRec.vatStatus              = aVATRecord.status;
                                    uRec.vatPollingInterval     = aVATRecord.pollingInterval;
                                    uRec.vatDueOnOutputs        = aVATRecord.VATDueOnOutputs;
                                    uRec.vatDueOnECAcquisitions = aVATRecord.VATDueOnECAcquisitions;
                                    uRec.vatTotal             = aVATRecord.VATTotal;
                                    uRec.vatReclaimedOnInputs = aVATRecord.VATReclaimedOnInputs;
                                    uRec.vatNet = aVATRecord.VATNet;
                                    uRec.vatNetSalesAndOutputs    = aVATRecord.netSalesAndOutputs;
                                    uRec.vatNetPurchasesAndInputs = aVATRecord.netPurchasesAndInputs;
                                    uRec.vatNetECSupplies         = aVATRecord.netECSupplies;
                                    uRec.vatNetECAcquisition      = aVATRecord.netECAcquisitions;
                                    uRec.vatHMRCNarrative         = aVATRecord.hmrcNarrative;
                                    uRec.vatNotifyEmail           = aVATRecord.notifyEmail;
                                    uRec.vatPollingURL            = aVATRecord.PollingURL;

                                    Res = uRec.Save();

                                    if (Res != 0)
                                    {
                                        LogText("Could not update VAT 100 database entry for Correlation ID " + aVATRecord.correlationID +
                                                ".\r\n" + tToolkit.LastErrorString);
                                    }
                                }
                                else
                                {
                                    LogText("Failed to create Update object.");
                                    // PKR. TODO: This needs updating to whatever value means that we couldn't get an Update object.
                                    Res             = -1;
                                    lastErrorString = "Could not update VAT 100 database entry for Correlation ID " + aVATRecord.correlationID;
                                }
                                // We found the record, so we don't need to look further
                                break;
                            } // if correct record

                            Res = oVAT100.GetNext();
                        } // while we have a record
                    }
                    catch (Exception ex)
                    {
                        lastErrorString = ex.Message;
                        LogText("Could not update VAT 100 database entry for Correlation ID " + aVATRecord.correlationID + ".\r\n" + ex.Message);
                    }
                }
                finally
                {
                    Res = tToolkit.CloseToolkit();
                }
            }
            else
            {
                LogText("UpdateVAT100Entry : Failed to open COM toolkit");
                lastErrorString = "UpdateVAT100Entry : Failed to open COM toolkit";
            }

            return(Res);
        }
Пример #5
0
        //---------------------------------------------------------------------------------------------
        /// <summary>
        /// Returns the most recent pending VAT entry (there should only be 1)
        /// Returns null if no pending submissions
        /// </summary>
        /// <returns></returns>
        public VAT100Record GetPendingVAT100Entry(string ForCompanyCode)
        {
            int Res;

            // Create the return record
            VAT100Record theEntry = null;

            // Switch to the data path for the selected company
            string path = GetCompanyPath(ForCompanyCode);

            if (path == "")
            {
                return(null);
            }

            // If the toolkit is open, close it so we can change the directory
            if (tToolkit.Status == TToolkitStatus.tkOpen)
            {
                tToolkit.CloseToolkit();
            }
            // Change the directory
            tToolkit.Configuration.DataDirectory = path;
            // Reopen the toolkit
            Res = tToolkit.OpenToolkit();

            // Database record
            IVAT100 oVAT100 = (tToolkit as ICSNFToolkit).VAT100;

            try
            {
                try
                {
                    Res = oVAT100.GetFirst();
                    while (Res == 0)
                    {
                        // See if it's the required record (submitted or pending status)
                        if ((oVAT100.vatStatus == 1) || (oVAT100.vatStatus == 2))
                        {
                            // Found the record, so create a return object
                            theEntry = new VAT100Record();

                            theEntry.correlationID          = oVAT100.vatCorrelationId;
                            theEntry.IRMark                 = oVAT100.vatIRMark;
                            theEntry.dateSubmitted          = oVAT100.vatDateSubmitted;
                            theEntry.documentType           = oVAT100.vatDocumentType;
                            theEntry.VATPeriod              = oVAT100.vatPeriod;
                            theEntry.username               = oVAT100.vatUserName;
                            theEntry.status                 = oVAT100.vatStatus;
                            theEntry.pollingInterval        = oVAT100.vatPollingInterval;
                            theEntry.VATDueOnOutputs        = oVAT100.vatDueOnOutputs;
                            theEntry.VATDueOnECAcquisitions = oVAT100.vatDueOnECAcquisitions;
                            theEntry.VATTotal               = oVAT100.vatTotal;
                            theEntry.VATReclaimedOnInputs   = oVAT100.vatReclaimedOnInputs;
                            theEntry.VATNet                 = oVAT100.vatNet;
                            theEntry.netSalesAndOutputs     = oVAT100.vatNetSalesAndOutputs;
                            theEntry.netPurchasesAndInputs  = oVAT100.vatNetPurchasesAndInputs;
                            theEntry.netECSupplies          = oVAT100.vatNetECSupplies;
                            theEntry.netECAcquisitions      = oVAT100.vatNetECAcquisition;
                            theEntry.hmrcNarrative          = oVAT100.vatHMRCNarrative;
                            theEntry.notifyEmail            = oVAT100.vatNotifyEmail;
                            theEntry.PollingURL             = oVAT100.vatPollingURL;

                            break;
                        }
                        Res = oVAT100.GetNext();
                    }
                }
                catch (Exception ex)
                {
                    lastErrorString = ex.Message;
                }
            }
            finally
            {
                tToolkit.CloseToolkit();
            }

            return(theEntry);
        }