//--------------------------------------------------------------------------------------------- /// <summary> /// Gets the VAT100 record for the specified VAT Period /// </summary> /// <param name="aCorrelationID"></param> /// <returns></returns> public IVAT100 GetRecordByVATPeriod(string aVATPeriod, string ForCompanyCode) { int Res; IVAT100 Result = null; string path = GetCompanyPath(ForCompanyCode); if (path == "") { return(null); } // PKR. 15/09/2015. Close toolkit before changing path. if (tToolkit.Status == TToolkitStatus.tkOpen) { tToolkit.CloseToolkit(); } tToolkit.Configuration.DataDirectory = path; tToolkit.OpenToolkit(); IVAT100 oVAT100 = (tToolkit as ICSNFToolkit).VAT100; try { try { Res = oVAT100.GetFirst(); while (Res == 0) { // See if it's the required record if (oVAT100.vatPeriod == aVATPeriod) { Result = oVAT100; break; } Res = oVAT100.GetNext(); } } catch (Exception ex) { lastErrorString = ex.Message; Log.Add(lastErrorString); } } finally { tToolkit.CloseToolkit(); } return(Result); }
//--------------------------------------------------------------------------------------------- /// <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); }
//--------------------------------------------------------------------------------------------- /// <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); }