/// <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);
        }
Exemple #2
0
        internal static CAS.SmartFactory.Customs.Account.CommonAccountData.MessageType Convert2MessageType(CustomsDocument.DocumentType type)
        {
            AccountData.MessageType _ret = default(AccountData.MessageType);
            switch (type)
            {
            case CustomsDocument.DocumentType.SAD:
                _ret = AccountData.MessageType.SAD;
                break;

            case CustomsDocument.DocumentType.PZC:
                _ret = AccountData.MessageType.SAD;
                break;

            case CustomsDocument.DocumentType.IE529:
            case CustomsDocument.DocumentType.CLNE:
            default:
                throw new ArgumentException("Out of range value for CustomsDocument.DocumentType argument in Convert2MessageType ", "type");
            }
            return(_ret);
        }
        internal static void DeclarationProcessing(string webUrl, int sadDocumentTypeId, CustomsDocument.DocumentType documentType, ref string comments, List <Warnning> warnings, NamedTraceLogger.TraceAction trace)
        {
            trace("Entering ClearenceHelpers.DeclarationProcessing", 40, TraceSeverity.Verbose);
            comments = "Clearance association error";
            switch (documentType)
            {
            case CustomsDocument.DocumentType.SAD:
            case CustomsDocument.DocumentType.PZC:
                SADPZCProcessing(webUrl, documentType, sadDocumentTypeId, ref comments, warnings, trace);
                break;

            case CustomsDocument.DocumentType.IE529:
                IE529Processing(webUrl, sadDocumentTypeId, ref comments, trace);
                break;

            case CustomsDocument.DocumentType.CLNE:
                CLNEProcessing(webUrl, sadDocumentTypeId, ref comments, warnings, trace);
                break;
            }//switch (_documentType
        }
        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);
                }
            }
        }