Ejemplo n.º 1
0
    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        Button      btnGenerate = (Button)sender;
        GridViewRow gvRow       = (GridViewRow)btnGenerate.Parent.Parent;
        Guid        newUID      = new Guid();
        var         xmldoc      = new XmlDocument();
        XmlNode     messageSpec = xmldoc.CreateNode(XmlNodeType.Element, "MessageSpec", null);
        var         countryCode = gvRow.Cells[0].Text.Split('-')[1].Trim();
        var         country     = gvRow.Cells[0].Text.Split('-')[0].Trim();
        var         year        = int.Parse(gvRow.Cells[1].Text);

        if (ValidateRequiredFields(year))
        {
            decimal id      = 0;
            var     package = Common.GenerateNewPackage(countryCode, dpReportingPeriod.Text, ref messageSpec, id);
            if (!string.IsNullOrEmpty(package.ToString()))
            {
                var outgoingCBC = new OutGoingCBCDeclarations()
                {
                    Id              = id,
                    Country         = countryCode,
                    CBCData         = package.ToString(),
                    NSCBCData       = null,
                    StatusId        = 2,
                    Year            = year,
                    ReportingPeriod = DateTime.Parse(dpReportingPeriod.Text),
                    CreatedBy       = Sars.Systems.Security.ADUser.CurrentSID
                };

                id = DatabaseWriter.SaveOutgoingCBC(outgoingCBC, ref newUID);
                if (id > 0)
                {
                    var newPackage     = Common.GenerateNewPackage(countryCode, dpReportingPeriod.Text, ref messageSpec, id);
                    var newMessageSpec = messageSpec;
                    var nmPackage      = Common.GenerateNMPackage(countryCode, dpReportingPeriod.Text, newMessageSpec);
                    var newPackagedCBC = new OutGoingCBCDeclarations()
                    {
                        Id        = id,
                        Country   = countryCode,
                        CBCData   = newPackage.ToString(),
                        NSCBCData = nmPackage,
                        StatusId  = 2,
                        Year      = year,
                        CreatedBy = Sars.Systems.Security.ADUser.CurrentSID
                    };
                    var saved = DatabaseWriter.SaveOutgoingCBC(newPackagedCBC, ref newUID);
                }

                DBWriteManager.Insert_OutgoingPackageAuditTrail(newUID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Package for {0} generated", country));

                LoadCBC();
                MessageBox.Show(string.Format("Package for {0} was successfully generated", country));
            }
        }
    }
Ejemplo n.º 2
0
    protected void btnApprove_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(1000);
        decimal id           = decimal.Parse(Request.QueryString["idx"].ToString());
        int     statusId     = int.Parse(Request.QueryString["statusIdx"].ToString());
        string  incominLocal = Request.QueryString["incLocal"].ToString();
        var     country      = gvCBC.Rows[0].Cells[4].Text.Split('-')[0].Trim() + "_" + gvCBC.Rows[0].Cells[5].Text;

        if (fp.IsUserInRole("Reviewer") || fp.IsUserInRole("Approver"))
        {
            try
            {
                int      status        = fp.IsUserInRole("Reviewer") ? 3 : 5;
                bool     blnIsReviewer = fp.IsUserInRole("Reviewer") ? true : false;
                var      email         = string.IsNullOrEmpty(ADUser.CurrentUser.Mail) ? "*****@*****.**" : ADUser.CurrentUser.Mail;
                string[] senderEmail   = { email };
                string   Subject       = "";
                DBWriteManager.ApproveForeignPackage(status, id, ADUser.CurrentSID);
                var    mspec   = DBReadManager.GetMessageSpecById(id);
                string message = string.Format("Incoming Package for {0} has been approved successfully", country);
                if (blnIsReviewer)
                {
                    DBWriteManager.Insert_OutgoingPackageAuditTrail(mspec.UID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Incoming Package for {0} from {1} verified", gvCBC.Rows[0].Cells[4].Text.Split('-')[0].Trim()));
                    Subject = string.Format("Incoming Package for {0} from {1} has been verified ", gvCBC.Rows[0].Cells[4].Text.Split('-')[0].Trim(),
                                            gvCBC.Rows[0].Cells[3].Text.Split('-')[0].Trim());
                    Common.SendEmailToRole("Approver", gvCBC.Rows[0].Cells[4].Text.Split('-')[0].Trim(), Subject, FDRPage.Statuses.Verified, senderEmail);
                }
                else
                {
                    DBWriteManager.Insert_OutgoingPackageAuditTrail(mspec.UID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Incoming Package for {0} from {1} approved",
                                                                                                                                      gvCBC.Rows[0].Cells[4].Text.Split('-')[0].Trim(), gvCBC.Rows[0].Cells[3].Text.Split('-')[0].Trim()));
                    Subject = string.Format("Incoming Package for {0}  from {1} has been approved", gvCBC.Rows[0].Cells[4].Text.Split('-')[0].Trim(),
                                            gvCBC.Rows[0].Cells[3].Text.Split('-')[0].Trim());
                    Common.SendEmailToRole("Reviewer", gvCBC.Rows[0].Cells[4].Text.Split('-')[0].Trim(), Subject, FDRPage.Statuses.Approved, senderEmail);
                }
                btnApprove.Enabled = false;
                btnReject.Enabled  = false;
                MessageBox.Show(message);
                //LoadCBCHsitory(countryCode, reportingPeriod);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
Ejemplo n.º 3
0
    protected void btnVoid_Click(object sender, EventArgs e)
    {
        Guid        newUid  = new Guid();
        Button      btnVoid = (Button)sender;
        GridViewRow gvRow   = (GridViewRow)btnVoid.Parent.Parent;
        var         email   = ADUser.CurrentUser.Mail;

        string[] senderEmail = { email };
        var      countryCode = gvRow.Cells[0].Text.Split('-')[1].Trim();
        var      reportingPeriod = gvRow.Cells[1].Text; var outCBC = DBReadManager.OutGoingCBCDeclarationsDetails(countryCode, reportingPeriod);
        var      id = string.IsNullOrEmpty(outCBC.Id.ToString()) ? 0 : outCBC.Id;
        var      reportP = DateTime.Parse(reportingPeriod).ToString("yyyy-MM-ddTHH:mm:ss");
        Guid     uid     = new Guid();

        if (outCBC != null)
        {
            var prepareVoidPackage = PrepareNMVoidPackage(id, countryCode, outCBC.NMCBC, reportingPeriod);
            var nmPackage          = prepareVoidPackage;
            uid = outCBC.UID;
            var voidedCBC = new OutGoingCBCDeclarations()
            {
                Id              = id,
                Country         = countryCode,
                CBCData         = prepareVoidPackage,
                StatusId        = 8,
                Year            = int.Parse(reportingPeriod.Substring(0, 4)),
                UID             = uid,
                ActionId        = 3,
                NSCBCData       = nmPackage,
                ReportingPeriod = DateTime.Parse(reportP),
                CreatedBy       = Sars.Systems.Security.ADUser.CurrentSID
            };
            decimal saved = DatabaseWriter.SaveOutgoingCBC(voidedCBC, ref uid);
            DBWriteManager.ApproveOutgoingPackage(id, countryCode, reportingPeriod, 8, ADUser.CurrentSID);
            DBWriteManager.Insert_OutgoingPackageAuditTrail(outCBC.UID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Outgoing Package for {0} Pending Void Review", gvRow.Cells[0].Text.Split('-')[0].Trim()));
            var Subject = "Outgoing Package pending void review ";
            Common.SendEmailToRole("Reviewer", outCBC.CountryName, Subject, FDRPage.Statuses.Voided, senderEmail);
            MessageBox.Show("Package pending void review");
            LoadCBC();
        }
    }
Ejemplo n.º 4
0
    protected void btnCorrect_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["ccode"] != null && Request.QueryString["period"] != null)
        {
            FDRPage  fPage           = new FDRPage();
            Guid     newUid          = new Guid();
            var      country         = Request.QueryString["ccode"].ToString();
            var      reportingPeriod = Request.QueryString["period"].ToString();
            var      outCBC          = DBReadManager.OutGoingCBCDeclarationsDetails(country, reportingPeriod);
            decimal  id          = string.IsNullOrEmpty(outCBC.Id.ToString()) ? 0 : outCBC.Id;
            var      package     = Common.GenerateCorrectionPackage(country, reportingPeriod);
            var      email       = ADUser.CurrentUser.Mail;
            string[] senderEmail = { email };
            if (!string.IsNullOrEmpty(package.ToString()))
            {
                var outgoingCBC = new OutGoingCBCDeclarations()
                {
                    Id        = id,
                    Country   = country,
                    CBCData   = package.ToString(),
                    StatusId  = 7,
                    Year      = int.Parse(reportingPeriod.Substring(0, 4)),
                    CreatedBy = Sars.Systems.Security.ADUser.CurrentSID
                };
                decimal saved = DatabaseWriter.SaveOutgoingCBC(outgoingCBC, ref newUid);
                DBWriteManager.ApproveOutgoingPackage(id, country, reportingPeriod, 7, ADUser.CurrentSID);
                DBWriteManager.Insert_OutgoingPackageAuditTrail(outCBC.UID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Outgoing Package for {0} corrected", gvCBC.Rows[0].Cells[0].Text.Split('-')[0].Trim()));

                var Subject = "Outgoing CBC Report has been corrected ";
                Common.SendEmailToRole("Reviewer", outCBC.CountryName, Subject, FDRPage.Statuses.Corrected, senderEmail);
                LoadCBC(country, reportingPeriod);
                MessageBox.Show("Package has been corrected successfully");
            }
            else
            {
                MessageBox.Show("No package was corrected");
            }
        }
    }
Ejemplo n.º 5
0
    protected void btnAddComments_Click(object sender, EventArgs e)
    {
        var hiddenValue = Parent.FindControl("hdnDone") as HiddenField;
        var mpeMe       = Parent.FindControl("ModalPopupExtender1") as AjaxControlToolkit.ModalPopupExtender;

        hiddenValue.Value = txtComments.Text;
        var gvCBC = Parent.FindControl("gvCBC") as GridView;

        if (!string.IsNullOrEmpty(txtComments.Text))
        {
            var      email       = ADUser.CurrentUser.Mail;
            string[] senderEmail = { email };
            string   Subject     = "";
            if (Request.QueryString["idx"] == null)
            {
                return;
            }

            if (Request.QueryString["idx"] == "0")
            {
                var countryCode = Request.QueryString["xCountry"].ToString();

                if (gvCBC != null)
                {
                    string ReportingPeriod = gvCBC.Rows[0].Cells[4].Text;
                    var    outCBC          = DBReadManager.OutGoingCBCDeclarationsDetails(countryCode, ReportingPeriod);
                    var    comments        = new Comments()
                    {
                        OutGoingCBCDeclarationsID = outCBC.Id,
                        Notes   = txtComments.Text,
                        AddedBy = ADUser.CurrentSID
                    };
                    if (SaveComments(comments, 2) > 0)
                    {
                        DBWriteManager.ApproveOutgoingPackage(outCBC.Id, countryCode, ReportingPeriod, 4, ADUser.CurrentSID);
                        Subject = "Outgoing CBC Package has been rejected";
                        FDR.DataLayer.DBWriteManager.Insert_OutgoingPackageAuditTrail(outCBC.UID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Outgoing Package for {0} has been rejected", outCBC.CountryName));
                        Common.SendEmailToRole("Reviewer", outCBC.CountryName, Subject, FDRPage.Statuses.Rejected, senderEmail);
                        MessageBox.Show(string.Format("Outgoing Package for {0} has been successfully rejected", outCBC.CountryName));
                    }
                }
            }
            else
            {
                if (Request.QueryString["idx"] != null)
                {
                    string  ReportingPeriod = gvCBC.Rows[0].Cells[6].Text;
                    decimal msgSpecId       = decimal.Parse(Request.QueryString["idx"].ToString());
                    var     comments        = new Comments()
                    {
                        OutGoingCBCDeclarationsID = msgSpecId,
                        Notes   = txtComments.Text,
                        AddedBy = ADUser.CurrentSID
                    };
                    if (SaveComments(comments, 1) > 0)
                    {
                        DBWriteManager.ApproveForeignPackage(4, msgSpecId, ADUser.CurrentSID);
                        var mspec = DBReadManager.GetMessageSpecById(msgSpecId);
                        DBWriteManager.Insert_OutgoingPackageAuditTrail(mspec.UID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Incoming Package for {0} from {1} rejected",
                                                                                                                                          gvCBC.Rows[0].Cells[4].Text.Split('-')[0].Trim(), gvCBC.Rows[0].Cells[3].Text.Split('-')[0].Trim()));
                        Subject = string.Format("Incoming Package for {0} has been rejected", gvCBC.Rows[0].Cells[4].Text.Split('-')[0].Trim());
                        Common.SendEmailToRole("Reviewer", gvCBC.Rows[0].Cells[4].Text.Split('-')[0].Trim(), Subject, FDRPage.Statuses.Approved, senderEmail);
                        MessageBox.Show(string.Format("Incoming Foreign Package for {0} has been rejected successfully", gvCBC.Rows[0].Cells[3].Text.Split('-')[0]));
                    }
                }
            }
            txtComments.Text = "";
            var btnApprove = Parent.FindControl("btnApprove") as Button;
            var btnReject  = Parent.FindControl("btnReject") as Button;
            btnReject.Enabled  = false;
            btnApprove.Enabled = false;
        }

        else
        {
            MessageBox.Show("Please Enter comments");
            if (mpeMe != null)
            {
                mpeMe.Show();
            }
        }
    }
    protected void btnGenerateSingle_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(1000);
        try
        {
            Button      btnGenerate = (Button)sender;
            GridViewRow gvRow       = (GridViewRow)btnGenerate.Parent.Parent;
            Guid        newUID      = new Guid();
            var         xmldoc      = new XmlDocument();
            XmlNode     messageSpec = xmldoc.CreateNode(XmlNodeType.Element, "MessageSpec", xmldoc.NamespaceURI);
            var         countryCode = gvRow.Cells[0].Text.Split('-')[1].Trim();
            var         country     = gvRow.Cells[0].Text.Split('-')[0].Trim();
            var         period      = ddlReportingPeriod.SelectedIndex == 0? gvRow.Cells[1].Text: ddlReportingPeriod.SelectedValue;
            var         year        = int.Parse(gvRow.Cells[2].Text);
            if (ValidateRequiredFields(period))
            {
                decimal id         = 0;
                var     outgoinCBC = DBReadManager.OutGoingCBCDeclarationsDetails(countryCode, period);
                if (outgoinCBC != null)
                {
                    id = outgoinCBC.Id;
                    var newPackage     = Common.GenerateNewPackage(countryCode, period, ref messageSpec, id);
                    var newMessageSpec = messageSpec;
                    var nmPackage      = newPackage;
                    var newPackagedCBC = Utils.GetOutgoingCBCR(newPackage, countryCode, year,
                                                               DateTime.Parse(period), Sars.Systems.Security.ADUser.CurrentSID,
                                                               nmPackage, id);
                    var saved = DatabaseWriter.SaveOutgoingCBC(newPackagedCBC, ref newUID);
                    if (saved > 0)
                    {
                        DBWriteManager.Insert_OutgoingPackageAuditTrail(newUID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Outgoing Package for {0} generated", country));
                    }
                    else
                    {
                        DBWriteManager.Insert_OutgoingPackageAuditTrail(outgoinCBC.UID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Outgoing Package for {0} generated", country));
                    }
                    LoadCBC();
                    MessageBox.Show(string.Format("Package for {0} was successfully generated", country));
                    return;
                }

                var package = Common.GenerateNewPackage(countryCode, period, ref messageSpec, id);
                if (!string.IsNullOrEmpty(package.ToString()))
                {
                    var outgoingCBC = Utils.GetOutgoingCBCR(package.ToString(), countryCode, year,
                                                            DateTime.Parse(period), Sars.Systems.Security.ADUser.CurrentSID,
                                                            null, id);
                    id = DatabaseWriter.SaveOutgoingCBC(outgoingCBC, ref newUID);
                    if (id > 0)
                    {
                        var newPackage     = Common.GenerateNewPackage(countryCode, period, ref messageSpec, id);
                        var newMessageSpec = messageSpec;
                        var nmPackage      = newPackage;
                        var newPackagedCBC = Utils.GetOutgoingCBCR(newPackage, countryCode, year,
                                                                   DateTime.Parse(period), Sars.Systems.Security.ADUser.CurrentSID,
                                                                   nmPackage, id);
                        var saved = DatabaseWriter.SaveOutgoingCBC(newPackagedCBC, ref newUID);
                    }

                    DBWriteManager.Insert_OutgoingPackageAuditTrail(newUID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Outgoing Package for {0} generated", country));

                    LoadCBC();
                    MessageBox.Show(string.Format("Outgoing Package for {0} was successfully generated", country));
                }
                else
                {
                    MessageBox.Show("No package was generated");
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
Ejemplo n.º 7
0
    protected void btnApprove_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(1000);
        var countryCode = Request.QueryString["xCountry"].ToString();
        var period      = Request.QueryString["Period"].ToString();

        if (string.IsNullOrEmpty(countryCode) && string.IsNullOrEmpty(period))
        {
            return;
        }
        if (fp.IsUserInRole("Reviewer") || fp.IsUserInRole("Approver"))
        {
            try
            {
                string reportingPeriod = period;
                var    outCBC          = DBReadManager.OutGoingCBCDeclarationsDetails(countryCode, reportingPeriod);
                int    statusId        = fp.IsUserInRole("Reviewer") ? 3 : 5;

                string Subject = "";
                var    email   = string.IsNullOrEmpty(ADUser.CurrentUser.Mail) ? "*****@*****.**" : ADUser.CurrentUser.Mail;
                // DBWriteManager.ApproveOutgoingPackage(outCBC.Id, countryCode, reportingPeriod, statusId, ADUser.CurrentSID);
                string[] senderEmail = { email };
                if (fp.IsUserInRole("Reviewer"))
                {
                    try
                    {
                        DBWriteManager.Insert_OutgoingPackageAuditTrail(outCBC.UID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Outgoing Package for {0} verified", outCBC.CountryName));
                        Subject = string.Format("Outgoing Package for {0} has been verified ", outCBC.CountryName);
                        Common.SendEmailToRole("Approver", outCBC.CountryName, Subject, FDRPage.Statuses.Verified, senderEmail);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    try
                    {
                        DBWriteManager.Insert_OutgoingPackageAuditTrail(outCBC.UID, Sars.Systems.Security.ADUser.CurrentSID, string.Format("Outgoing Package for {0} approved", outCBC.CountryName));
                        Subject = string.Format("Outgoing Package for {0} has been approved", outCBC.CountryName);
                        Common.SendEmailToRole("Reviewer", outCBC.CountryName, Subject, FDRPage.Statuses.Approved, senderEmail);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                LoadCBCHsitory(countryCode, reportingPeriod);
                MessageBox.Show(Subject + " successfully");
                if (fp.IsUserInRole("Reviewer"))
                {
                    if (statusId > 2)
                    {
                        btnApprove.Enabled = false;
                    }
                }
                else
                {
                    if (statusId > 3)
                    {
                        btnApprove.Enabled = false;
                        btnReject.Enabled  = true;
                    }
                }
                btnApprove.Enabled = false;
                btnReject.Enabled  = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            var message = File.ReadAllText(@"D:\SARS\INCOMING\USA.xml");

            var applicationInformationStructure = new Sars.ESBSchema.ApplicationInformation.v31.
                                                  ApplicationInformationStructure
            {
                ApplicationInformationResult =
                    new Sars.ESBSchema.ApplicationInformation.v31.
                    ApplicationInformationStructureApplicationInformationResult[1]
            };


            var incomingMessage = new IncomingMessage(HttpContext.Current);
            //var message = incomingMessage.Message;
            if (string.IsNullOrEmpty(message))
            {
                return;
            }
            message = message.Replace("ns0:", "esb:");



            var dataset = new RecordSet();
            dataset.ReadXml(new StringReader(message));

            if (dataset.HasRows)
            {
                if (dataset.Tables.Contains("MessageIdentification") &&
                    dataset.Tables.Contains("CountryByCountryReportManagementRequest"))
                {
                    //var messageIdentification = dataset.Tables["MessageIdentification"];
                    var countryByCountryReportManagementRequest =
                        dataset.Tables["CountryByCountryReportManagementRequest"];

                    //var fileName = countryByCountryReportManagementRequest.Rows[0]["Filename"].ToString();
                    var destination = countryByCountryReportManagementRequest.Rows[0]["Destination"].ToString();
                    //var requestOperation = countryByCountryReportManagementRequest.Rows[0]["RequestOperation"].ToString();
                    var fileContent = countryByCountryReportManagementRequest.Rows[0]["FileContent"].ToString();

                    var fileBuffer = fileContent.Base64StringToByteArray();
                    if (Request.PhysicalApplicationPath != null)
                    {
                        var zipFolder = Path.Combine(Request.PhysicalApplicationPath,
                                                     SARSDataSettings.Settings.TempFolder,
                                                     DateTime.Now.ToFileTime().ToString());
                        if (!Directory.Exists(zipFolder))
                        {
                            Directory.CreateDirectory(zipFolder);
                        }
                        var zipFile = Path.Combine(zipFolder, string.Format("{0}.ZIP", DateTime.Now.ToFileTime()));
                        File.WriteAllBytes(zipFile, fileBuffer);

                        Sars.Systems.Compression.ZipExtraction.ExtractZipFile(zipFile, zipFolder);
                        var files = new DirectoryInfo(zipFolder).GetFiles("*.*").ToList();

                        var payLoadFiles  = files.Where(f => f.Name.Contains("Payload")).ToList();
                        var metaDataFiles = files.Where(f => f.Name.Contains("Metadata")).ToList();
                        if (!payLoadFiles.Any())
                        {
                            return;
                        }
                        if (!metaDataFiles.Any())
                        {
                            return;
                        }
                        var payloadData = File.ReadAllText(payLoadFiles[0].FullName);

                        if (string.IsNullOrEmpty(payloadData))
                        {
                            return;
                        }
                        var doc = new XmlDocument();
                        var originalMessageDocument = new XmlDocument();
                        doc.LoadXml(payloadData);
                        originalMessageDocument.LoadXml(message);

                        var cbCXmlNodeList = doc.GetElementsByTagName("CbCStatusMessage_OECD", "*");
                        var headerNodeList = originalMessageDocument.GetElementsByTagName("Header", "*");
                        var countryByCountryReportManagementRequestNodeList =
                            originalMessageDocument.GetElementsByTagName("CountryByCountryReportManagementRequest", "*");
                        if (cbCXmlNodeList.Count == 0 || headerNodeList.Count == 0 ||
                            countryByCountryReportManagementRequestNodeList.Count == 0)
                        {
                            //Common.LogEvent("XmlNodeList CbCXml = xmlDoc.GetElementsByTagName(\"CBC_OECD\", \" * \"); yielded zero elements");
                            return;
                        }
                        var statusXml = cbCXmlNodeList[0].OuterXml;
                        var headerXml = headerNodeList[0].OuterXml;
                        var countryByCountryReportManagementRequestXml = countryByCountryReportManagementRequestNodeList[0].OuterXml;


                        var schenaVal = _client.ValidateSchema(Configurations.CbCStatusValidationServiceID, statusXml);
                        if (!schenaVal.IsValid)
                        {
                            applicationInformationStructure.ApplicationInformationResult[0] =
                                new
                                ApplicationInformationStructureApplicationInformationResult
                            {
                                Code        = "9999",
                                Description = schenaVal.ErrorXml,
                                MessageType = MessageTypeEnum.ERROR
                            };
                            var messageToSend = CreateXml(headerXml, applicationInformationStructure, countryByCountryReportManagementRequestXml);
                            SendMessage(messageToSend, incomingMessage, _client);
                            return;
                        }

                        if (!destination.Equals("ZA", StringComparison.CurrentCultureIgnoreCase))
                        {
                            var code          = "9999";
                            var returnMessage = "MESSAGE DESTINATION NOT ZA";
                            RespondToB2Bi(
                                applicationInformationStructure
                                , code
                                , returnMessage
                                , true
                                , headerXml
                                , countryByCountryReportManagementRequestXml
                                , incomingMessage);
                            return;
                        }
                        if (string.IsNullOrEmpty(fileContent))
                        {
                            var code          = "9999";
                            var returnMessage = "FILE CONTENT EMPTY";
                            RespondToB2Bi(
                                applicationInformationStructure
                                , code
                                , returnMessage
                                , true
                                , headerXml
                                , countryByCountryReportManagementRequestXml
                                , incomingMessage);
                            return;
                        }

                        var statusMessage =
                            Sars.Systems.Serialization.XmlObjectSerializer.ConvertXmlToObject <CbCStatusMessage_OECD>(
                                statusXml);
                        if (statusMessage == null)
                        {
                            var code          = "9999";
                            var returnMessage = "XML COULD NOT BE DESERIALISED";
                            RespondToB2Bi(
                                applicationInformationStructure
                                , code
                                , returnMessage
                                , true
                                , headerXml
                                , countryByCountryReportManagementRequestXml
                                , incomingMessage);
                            return;
                        }

                        try
                        {
                            SaveMessageToDisc(statusMessage, message);
                        }
                        catch (Exception ex)
                        {
                            LogError(ex);
                        }
                        var originalMessageRefId = statusMessage.CbCStatusMessage.OriginalMessage.OriginalMessageRefID;
                        if (!string.IsNullOrEmpty(originalMessageRefId))
                        {
                            var indexOfDesh = originalMessageRefId.IndexOf("-", StringComparison.Ordinal);
                            if (indexOfDesh == -1)
                            {
                                var code          = "9999";
                                var returnMessage = "MessageRefId not correct";
                                RespondToB2Bi(
                                    applicationInformationStructure
                                    , code
                                    , returnMessage
                                    , true
                                    , headerXml
                                    , countryByCountryReportManagementRequestXml
                                    , incomingMessage);
                                return;
                            }
                            var origionalUid = originalMessageRefId.Substring(indexOfDesh + 3, 36);

                            Guid uidGuid;
                            if (!Guid.TryParse(origionalUid, out uidGuid))
                            {
                                var code          = "9999";
                                var returnMessage = "originalMessageRefId is not correct";
                                RespondToB2Bi(
                                    applicationInformationStructure
                                    , code
                                    , returnMessage
                                    , true
                                    , headerXml
                                    , countryByCountryReportManagementRequestXml
                                    , incomingMessage);
                                return;
                            }
                            //uidGuid = Guid.Parse("EF663F3E-E9DF-4FE3-8EAD-8BECCECF42AC");

                            DBWriteManager.Insert_OutgoingPackageAuditTrail
                            (
                                uidGuid,
                                null,
                                string.Format("Status Message received from {0} - {1}",
                                              statusMessage.MessageSpec.TransmittingCountry,
                                              statusMessage.MessageSpec.MessageRefId)
                            );

                            DBWriteManager.Insert_OutgoingPackageAuditTrail
                            (
                                uidGuid,
                                null,
                                "Incoming status update validation successful."
                            );
                            DBWriteManager.UpdatePackageWithStatusFromeOtherCountries
                            (
                                uidGuid
                                , statusXml
                                , statusMessage.CbCStatusMessage.ValidationResult.Status.ToString()
                            );

                            var validationErrors = statusMessage.CbCStatusMessage.ValidationErrors;
                            if (validationErrors.FileError != null && validationErrors.FileError.Any())
                            {
                                var numErrors = 0;
                                foreach (var fileErrorType in validationErrors.FileError)
                                {
                                    var code             = fileErrorType.Code;
                                    var errorDescription = fileErrorType.Details.Value;
                                    numErrors += DBWriteManager.Insert_OutgoingPackage_File_ReturnErrors(
                                        uidGuid,
                                        code,
                                        errorDescription
                                        );
                                }
                                DBWriteManager.Insert_OutgoingPackageAuditTrail
                                (
                                    uidGuid,
                                    null,
                                    string.Format("{0} File Validation Error(s) Found", numErrors)
                                );
                            }
                            DBWriteManager.Insert_OutgoingPackageAuditTrail
                            (
                                uidGuid,
                                null,
                                string.Format("File Status is : {0}", statusMessage.CbCStatusMessage.ValidationResult.Status)
                            );
                            if (validationErrors.RecordError != null && validationErrors.RecordError.Any())
                            {
                                var numErrors = 0;
                                foreach (var recordError in validationErrors.RecordError)
                                {
                                    var code             = recordError.Code;
                                    var errorDescription = recordError.Details.Value;
                                    var docRef           = string.Join(" | ", recordError.DocRefIDInError);
                                    numErrors += DBWriteManager.Insert_OutgoingPackage_Record_ReturnErrors(
                                        uidGuid,
                                        code,
                                        errorDescription,
                                        docRef
                                        );
                                }
                                DBWriteManager.Insert_OutgoingPackageAuditTrail
                                (
                                    uidGuid,
                                    null,
                                    string.Format("{0} Record Validation Error(s) Found", numErrors)
                                );
                            }
                            applicationInformationStructure.ApplicationInformationResult[0] = new ApplicationInformationStructureApplicationInformationResult
                            {
                                Code        = "0000",
                                Description = "Successful",
                                MessageType = MessageTypeEnum.INFORMATION
                            };
                            var successMessageToSend = CreateXml(headerXml, applicationInformationStructure,
                                                                 countryByCountryReportManagementRequestXml);
                            SendMessage(successMessageToSend, incomingMessage, _client);
                        }
                        Directory.Delete(zipFolder, true);
                    }
                }
            }
        }
        catch (Exception exception)
        {
            LogError(exception);
        }
        finally
        {
            _client.Close();
        }
    }