Beispiel #1
0
 private static SADDocumentType GetSADDocument(CustomsDocument document, Entities edc, SADDocumentLib lookup)
 {
     try
     {
         SADDocumentType newRow = new SADDocumentType()
         {
             SADDocumenLibrarytIndex = lookup,
             Title           = String.Format("{0}: {1} / {2}", document.MessageRootName(), document.GetDocumentNumber(), document.GetReferenceNumber()),
             Currency        = document.GetCurrency(),
             CustomsDebtDate = document.GetCustomsDebtDate(),
             DocumentNumber  = document.GetDocumentNumber(),
             ExchangeRate    = document.GetExchangeRate(),
             GrossMass       = document.GetGrossMass(),
             NetMass         = 0, //TODO remove column is useless
             ReferenceNumber = document.GetReferenceNumber()
         };
         edc.SADDocument.InsertOnSubmit(newRow);
         GetSADGood(document.GetSADGood(), edc, newRow);
         return(newRow);
     }
     catch (IPRDataConsistencyException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new IPRDataConsistencyException("SADDocumentType", ex.Message, ex, "SAD main part analysis problem");
     }
 }
        /// <summary>
        /// Creates the IPR account.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <param name="clearance">The clearance.</param>
        /// <param name="messageType">Type of the _message.</param>
        /// <param name="comments">The _comments.</param>
        /// <param name="warnings">The list of warnings.</param>
        /// <param name="trace">The trace action.</param>
        private static void CreateIPRAccount(Entities entities, Clearence clearance, CustomsDocument.DocumentType messageType, out string comments, List <Warnning> warnings, NamedTraceLogger.TraceAction trace)
        {
            trace("Entering ClearenceHelpers.CreateIPRAccount", 169, TraceSeverity.Verbose);
            comments = "IPR account creation error";
            string          _referenceNumber = String.Empty;
            SADDocumentType declaration      = clearance.Clearence2SadGoodID.SADDocumentIndex;

            _referenceNumber = declaration.ReferenceNumber;
            if (WebsiteModel.Linq.IPR.RecordExist(entities, clearance.DocumentNo))
            {
                string _msg = "IPR record with the same SAD document number: {0} exist";
                _msg = String.Format(_msg, clearance.DocumentNo);
                trace("Exception at ClearenceHelpers.CreateIPRAccount: " + _msg, 199, TraceSeverity.Verbose);
                throw GenericStateMachineEngine.ActionResult.NotValidated(_msg);
            }
            comments = "Inconsistent or incomplete data to create IPR account";
            IPRAccountData _iprdata = new IPRAccountData(clearance.Id.Value);

            _iprdata.GetAccountData(entities, clearance, ImportXMLCommon.Convert2MessageType(messageType), warnings, trace);
            comments = "Consent lookup filed";
            IPRClass _ipr = new IPRClass(entities, _iprdata, clearance, declaration);

            entities.IPR.InsertOnSubmit(_ipr);
            clearance.SPStatus = true;
            trace("ClearenceHelpers.CreateIPRAccount at SubmitChanges", 209, TraceSeverity.Verbose);
            entities.SubmitChanges();
            _ipr.UpdateTitle();
            comments = "IPR account created";
            trace("ClearenceHelpers.Create - IPRAccount comments", 213, TraceSeverity.Verbose);
        }
        private static void CLNEProcessing(string webUrl, int sadDocumentTypeId, ref string comments, List <Warnning> warnings, NamedTraceLogger.TraceAction trace)
        {
            trace("Entering ClearenceHelpers.CLNEProcessing", 71, TraceSeverity.Verbose);
            List <CWAccountData> _tasksList = new List <CWAccountData>();

            using (Entities _entities = new Entities(webUrl))
            {
                SADDocumentType        _sad    = Element.GetAtIndex <SADDocumentType>(_entities.SADDocument, sadDocumentTypeId);
                IQueryable <Clearence> _clrncs = Clearence.GetClearence(_entities, _sad.ReferenceNumber);
                if ((from _cx in _clrncs where _cx.Clearence2SadGoodID == null select _cx).Any <Clearence>())
                {
                    string _error = String.Format("SAD with reference number: {0} must be imported first", _sad.ReferenceNumber);
                    throw new InputDataValidationException("CLNE message cannot be processed before SAD", "DeclarationProcessing", _error, true);
                }
                foreach (Clearence _cx in _clrncs)
                {
                    _cx.DocumentNo = _sad.DocumentNumber;
                    switch (_cx.ClearenceProcedure.Value.RequestedProcedure())
                    {
                    case CustomsProcedureCodes.FreeCirculation:
                        _cx.FinishClearingThroughCustoms(_entities, trace);
                        break;

                    case CustomsProcedureCodes.InwardProcessing:
                        CreateIPRAccount(_entities, _cx, CustomsDocument.DocumentType.SAD, out comments, warnings, trace);
                        break;

                    case CustomsProcedureCodes.CustomsWarehousingProcedure:
                        throw new NotImplementedException("CLNEProcessing - CustomsWarehousingProcedure"); //TODO http://casas:11227/sites/awt/Lists/RequirementsList/_cts/Requirements/displayifs.aspx?List=e1cf335a

                    //comments = "CW account creation error";
                    //CWAccountData _accountData = new CWAccountData(_cx.Id.Value);
                    //_accountData.GetAccountData(_entities, _cx, ImportXMLCommon.Convert2MessageType(CustomsDocument.DocumentType.SAD), progressChange);
                    //CreateCWAccount(_accountData, webUrl, out comments);
                    //break;
                    case CustomsProcedureCodes.ReExport:
                    case CustomsProcedureCodes.NoProcedure:
                    default:
                        throw new IPRDataConsistencyException("CLNEProcessing", "Unexpected procedure code for CLNE message", null, c_wrongProcedure);
                    }
                }
                _entities.SubmitChanges();
            }
            trace("ClearenceHelpers.CLNEProcessing at CreateCWAccount", 109, TraceSeverity.Verbose);
            foreach (CWAccountData _accountData in _tasksList)
            {
                CreateCWAccount(_accountData, webUrl, out comments);
            }
        }
Beispiel #4
0
        internal void FinishClearThroughCustoms(Entities entities, NamedTraceLogger.TraceAction traceEvent)
        {
            traceEvent("Starting Clearence.FinishClearThroughCustoms", 74, TraceSeverity.Verbose);
            SADDocumentType _sadDocument = Clearence2SadGoodID.SADDocumentIndex;

            DocumentNo      = _sadDocument.DocumentNumber;
            ReferenceNumber = _sadDocument.ReferenceNumber;
            SPStatus        = true;
            foreach (CustomsWarehouseDisposal _cwdx in this.CustomsWarehouseDisposal(entities, false))
            {
                _cwdx.FinishClearThroughCustoms(entities, Clearence2SadGoodID, traceEvent);
            }
            UpdateTitle(entities, traceEvent);
            traceEvent("Finished Clearence.FinishClearThroughCustoms", 82, TraceSeverity.Verbose);
        }
 private static void IE529Processing(string webUrl, int sadDocumentTypeId, ref string comments, NamedTraceLogger.TraceAction trace)
 {
     comments = "Reexport of goods failed";
     trace("Entering ClearenceHelpers.IE529Processing", 61, TraceSeverity.Verbose);
     using (Entities _entities = new Entities(webUrl))
     {
         SADDocumentType _sad = Element.GetAtIndex <SADDocumentType>(_entities.SADDocument, sadDocumentTypeId);
         foreach (SADGood _gdx in _sad.SADGood(_entities))
         {
             IPRClearThroughCustoms(_entities, _gdx, trace);
         }
         comments = "Reexport of goods";
         trace("ClearenceHelpers.IE529Processing SubmitChanges", 61, TraceSeverity.Verbose);
         _entities.SubmitChanges();
     }
 }
Beispiel #6
0
        /// <summary>
        /// Analyzes the good.
        /// </summary>
        /// <param name="edc">The <see cref="Entities"/> instance.</param>
        /// <param name="good">The good.</param>
        /// <param name="messageType">Type of the _message.</param>
        protected internal virtual void AnalizeGood(Entities edc, SADGood good, MessageType messageType)
        {
            SADDocumentType _document = good.SADDocumentIndex;

            switch (messageType)
            {
            case MessageType.PZC:
                GrossMass = _document.GrossMass.HasValue ? _document.GrossMass.Value : good.GrossMass.Value;
                break;

            case MessageType.SAD:
                GrossMass = good.GrossMass.HasValue ? good.GrossMass.Value : _document.GrossMass.Value;
                break;
            }
            GetNetMass(edc, good);
        }
Beispiel #7
0
 private static void GetSADGood(GoodDescription[] document, Entities edc, SADDocumentType lookup)
 {
     if (document.NullOrEmpty <GoodDescription>())
     {
         return;
     }
     try
     {
         foreach (GoodDescription _doc in document)
         {
             string  _description = _doc.GetDescription().SPValidSubstring();
             SADGood newRow       = new SADGood()
             {
                 SADDocumentIndex    = lookup,
                 Title               = String.Format("{0}: {1}", _doc.GetDescription().SPValidSubstring(), _doc.GetPCNTariffCode()),
                 GoodsDescription    = _description,
                 PCNTariffCode       = _doc.GetPCNTariffCode(),
                 GrossMass           = _doc.GetGrossMass(),
                 NetMass             = _doc.GetNetMass(),
                 SPProcedure         = _doc.GetProcedure(),
                 TotalAmountInvoiced = _doc.GetTotalAmountInvoiced(),
                 ItemNo              = _doc.GetItemNo()
             };
             edc.SADGood.InsertOnSubmit(newRow);
             edc.SubmitChanges();
             GetSADDuties(_doc.GetSADDuties(), edc, newRow);
             GetSADPackage(_doc.GetSADPackage(), edc, newRow);
             GetSADQuantity(_doc.GetSADQuantity(), edc, newRow);
             GetSADRequiredDocuments(_doc.GetSADRequiredDocuments(), edc, newRow);
         }
     }
     catch (IPRDataConsistencyException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new IPRDataConsistencyException("GetSADGood", ex.Message, ex, "Goods analysis problem");
     }
 }
        private static void SADPZCProcessing(string webUrl, CustomsDocument.DocumentType messageType, int sadDocumentTypeId, ref string comments, List <Warnning> warnings, NamedTraceLogger.TraceAction trace)
        {
            trace("Entering ClearenceHelpers.SADPZCProcessing", 71, TraceSeverity.Verbose);
            List <CommonClearanceData> _tasksList = new List <CommonClearanceData>();

            using (Entities entities = new Entities(webUrl))
            {
                SADDocumentType sad = Element.GetAtIndex <SADDocumentType>(entities.SADDocument, sadDocumentTypeId);
                foreach (SADGood _sgx in sad.SADGood(entities))
                {
                    switch (_sgx.SPProcedure.RequestedProcedure())
                    {
                    case CustomsProcedureCodes.FreeCirculation:
                        if (messageType == CustomsDocument.DocumentType.SAD)
                        {
                            comments = "Document added";
                            continue;
                        }
                        if (_sgx.SPProcedure.PreviousProcedure() == CustomsProcedureCodes.CustomsWarehousingProcedure)
                        {
                            _tasksList.Add(CWPrepareClearance(entities, _sgx)); //Procedure 4071
                        }
                        else if (_sgx.SPProcedure.PreviousProcedure() == CustomsProcedureCodes.InwardProcessing)
                        {
                            IPRClearThroughCustoms(entities, _sgx, trace); //Procedure 4051
                        }
                        else
                        {
                            string _msg = string.Format("Unexpected previous procedure code {1} for the {0} message", messageType, _sgx.SPProcedure.PreviousProcedure());
                            trace("IPRDataConsistencyException at ClearenceHelpers.SADPZCProcessing: ", 140, TraceSeverity.Verbose);
                            throw new IPRDataConsistencyException("SADPZCProcessing.FreeCirculation", _msg, null, c_wrongProcedure);
                        }
                        break;

                    case CustomsProcedureCodes.InwardProcessing:
                    {
                        if (messageType == CustomsDocument.DocumentType.SAD)
                        {
                            comments = "Document added";
                            continue;
                        }
                        if (_sgx.SPProcedure.PreviousProcedure() == CustomsProcedureCodes.CustomsWarehousingProcedure)
                        {
                            _tasksList.Add(CWPrepareClearance(entities, _sgx)); //Procedure 5171
                        }
                        // Procedure 5100 or 5171
                        Clearence _newClearance = Clearence.CreataClearance(entities, "InwardProcessing", ClearenceProcedure._5171, _sgx);
                        CreateIPRAccount(entities, _newClearance, CustomsDocument.DocumentType.PZC, out comments, warnings, trace);
                        break;
                    }

                    case CustomsProcedureCodes.CustomsWarehousingProcedure:
                        Clearence _newWarehousinClearance = Clearence.CreataClearance(entities, "CustomsWarehousingProcedure", ClearenceProcedure._7100, _sgx);
                        if (messageType == CustomsDocument.DocumentType.PZC)
                        {
                            comments = "CW account creation error";
                            CWAccountData _accountData = new CWAccountData(_newWarehousinClearance.Id.Value);
                            _accountData.GetAccountData(entities, _newWarehousinClearance, ImportXMLCommon.Convert2MessageType(CustomsDocument.DocumentType.SAD), warnings, trace);
                            _tasksList.Add(_accountData);
                        }
                        else
                        {
                            comments = "Document added";
                        }
                        break;

                    case CustomsProcedureCodes.NoProcedure:
                    case CustomsProcedureCodes.ReExport:
                    default:
                        throw new IPRDataConsistencyException("SADPZCProcessing.RequestedProcedure", string.Format("Unexpected procedure code for the {0} message", messageType), null, c_wrongProcedure);
                    } //switch ( _sgx.Procedure.RequestedProcedure() )
                }     //foreach ( SADGood _sgx in sad.SADGood )
                entities.SubmitChanges();
            }         //using ( Entities entities
            foreach (CommonClearanceData _accountData in _tasksList)
            {
                if (_accountData is CWAccountData)
                {
                    CreateCWAccount((CWAccountData)_accountData, webUrl, out comments);
                }
                else if (_accountData is CWClearanceData)
                {
                    CWClearThroughCustoms((CWClearanceData)_accountData, webUrl, out comments);
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// An item was added
        /// </summary>
        /// <param name="properties"> Contains properties for asynchronous list item event handlers, and serves as a base class for
        /// event handlers.
        /// </param>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            TraceEvent("Entering SADImportXML ItemAdded", 46, TraceSeverity.Monitorable);
            ErrorsList m_Warnings = new ErrorsList();
            string     _at        = "beginning";

            if (!properties.ListTitle.Contains(CommonDefinition.SADDocumentLibrary))
            {
                //TODO  [pr4-3435] Item add event - selective handling mechanism. http://itrserver/Bugs/BugDetail.aspx?bid=3435
                TraceEvent(String.Format("Exiting SADImportXML.ItemAdded - event called for wrong lis list name {0}.", properties.ListTitle), 52, TraceSeverity.Monitorable);
                base.ItemAdded(properties);
                return;
            }
            bool   _entrySADDocumentLibraryOK       = false;
            string _entrySADDocumentLibraryComments = "Item adding error";

            try
            {
                this.EventFiringEnabled = false;
                if (properties.ListItem.File == null)
                {
                    TraceEvent("Exiting SADImportXML.ItemAdded - file is empty", 63, TraceSeverity.High);
                    base.ItemAdded(properties);
                    return;
                    //TODO  [pr4-3435] Item add event - selective handling mechanism. http://itrserver/Bugs/BugDetail.aspx?bid=3435
                    //throw new IPRDataConsistencyException("ItemAdded", "Import of a SAD declaration message failed because the file is empty.", null, "There is no file");
                }
                try
                {
                    ActivityLogCT.WriteEntry(m_Title, String.Format("Import of the SAD declaration {0} starting.", properties.ListItem.File.Name), properties.WebUrl);
                    CustomsDocument _message = null;
                    using (Stream _str = properties.ListItem.File.OpenBinaryStream())
                        _message = CustomsDocument.ImportDocument(_str);
                    int _sadIDValue;
                    using (Entities edc = new Entities(properties.WebUrl))
                    {
                        _at = "GetAtIndex<SADDocumentLib>";
                        SADDocumentLib _SADLibEntry = Element.GetAtIndex <SADDocumentLib>(edc.SADDocumentLibrary, properties.ListItem.ID);
                        _at = "GetSADDocument";
                        SADDocumentType _SADEntity = GetSADDocument(_message, edc, _SADLibEntry);
                        _at = "SubmitChanges";
                        edc.SubmitChanges();
                        _sadIDValue = _SADEntity.Id.Value;
                    }
                    _at = "DeclarationProcessing";
                    _entrySADDocumentLibraryComments = "OK";
                    ClearenceHelpers.DeclarationProcessing(properties.WebUrl, _sadIDValue, _message.MessageRootName(), ref _entrySADDocumentLibraryComments, m_Warnings, TraceEvent);
                }
                catch (InputDataValidationException _ie)
                {
                    TraceEvent(String.Format("Exception {0} at SADImportXML.ItemAdded file={1}", _ie.GetType().Name, properties.ListItem.File.Name), 92, TraceSeverity.High);
                    _ie.ReportActionResult(properties.WebUrl, properties.ListItem.File.Name);
                }
                catch (Exception _ex)
                {
                    string _pattern = "XML import error at {0}.";
                    if (_ex is CustomsDataException)
                    {
                        _pattern = "XML import error at {0}.";
                        _at      = ((CustomsDataException)_ex).Source;
                    }
                    else if (_ex is IPRDataConsistencyException)
                    {
                        IPRDataConsistencyException _iprex = _ex as IPRDataConsistencyException;
                        _pattern = "SAD analyses error at {0}.";
                        _at      = _iprex.Source;
                    }
                    else if (_ex is GenericStateMachineEngine.ActionResult)
                    {
                        GenericStateMachineEngine.ActionResult _ar = _ex as GenericStateMachineEngine.ActionResult;
                        if (_ar.LastActionResult == GenericStateMachineEngine.ActionResult.Result.NotValidated)
                        {
                            _pattern = "SAD content validation error at {0}.";
                        }
                        else
                        {
                            _pattern = "SAD analyses internal error at {0}.";
                        }
                        _at = _ar.Source;
                    }
                    else
                    {
                        _pattern = "ItemAdded error at {0}.";
                    }
                    string _innerMsg = String.Empty;
                    if (_ex.InnerException != null)
                    {
                        _innerMsg = String.Format(" as the result of {0}.", _ex.InnerException.Message);
                    }
                    string _msg   = String.Format("Message= {0}; Inner: {1}", _ex.Message, _innerMsg);
                    string _where = String.Format(_pattern, _at);
                    ActivityLogCT.WriteEntry(_where, _msg, properties.WebUrl);
                    TraceEvent(String.Format("Exception {0} at SADImportXML.ItemAdded/{1}, Stack: {2}", _ex.GetType().Name, _where, _ex.StackTrace), 126, TraceSeverity.High);
                }
                try
                {
                    using (Entities edc = new Entities(properties.WebUrl))
                    {
                        SADDocumentLib _entry = Element.GetAtIndex <SADDocumentLib>(edc.SADDocumentLibrary, properties.ListItem.ID);
                        _entry.SADDocumentLibraryOK       = _entrySADDocumentLibraryOK;
                        _entry.SADDocumentLibraryComments = _entrySADDocumentLibraryComments;
                        _entrySADDocumentLibraryOK        = true;
                        _at = "m_Warnings";
                        foreach (Warnning _wrnngx in m_Warnings)
                        {
                            ActivityLogCT.WriteEntry(edc, m_Title, String.Format("Import of the SAD declaration wanning: {0}", _wrnngx.Message));
                        }
                        if (m_Warnings.Count == 0)
                        {
                            ActivityLogCT.WriteEntry(edc, m_Title, String.Format("Import of the SAD declaration {0} finished.", properties.ListItem.File.Name));
                        }
                        else
                        {
                            ActivityLogCT.WriteEntry(edc, m_Title, String.Format("Import of the SAD declaration {0} finished. {1} warnings have been reported.", properties.ListItem.File.Name, m_Warnings.Count));
                        }
                        _at = "SubmitChanges";
                        TraceEvent("SADImportXMLItemAdded SubmitChanges", 144, TraceSeverity.Verbose);
                        edc.SubmitChanges();
                    }
                }
                catch (Exception _ex)
                {
                    string _pattern = "Unexpected SADDocumentLib SubmitChanges error: {0}.";
                    ActivityLogCT.WriteEntry(m_Title, String.Format(_pattern, _ex.Message), properties.WebUrl);
                    TraceEvent(String.Format("Exception {0} at SADImportXML.ItemAdded/{1}, Stack: {2}", _ex.GetType().Name, _at, _ex.StackTrace), 152, TraceSeverity.High);
                }
            }
            finally
            {
                this.EventFiringEnabled = true;
            }
            base.ItemAdded(properties);
            TraceEvent("Finished SADImportXML ItemAdded", 160, TraceSeverity.Verbose);
        }