Ejemplo n.º 1
0
        private string GenerateXmlStringDC()
        {
            _log.Debug($"string ServiceAT.GenerateXmlStringDC() :: {_documentMaster.DocumentNumber}");

            /* IN009150 (IN009075) */
            string entityFiscalNumber = "";

            if (!string.IsNullOrEmpty(_documentMaster.EntityFiscalNumber))
            {
                entityFiscalNumber = GlobalFramework.PluginSoftwareVendor.Decrypt(_documentMaster.EntityFiscalNumber);
            }
            /* IN009150 - end */

            //Init Local Vars
            string customerTaxID                   = FiscalNumber.ExtractFiscalNumber(entityFiscalNumber);
            string sbContentCustomerTax            = string.Empty;
            string sbContentLinesAndDocumentTotals = string.Empty;

            //Test mode, increase DocumentNumber only when Develop
            if (_increaseDocumentNumber)
            {
                Utils.IncreaseDocumentNumber(_documentMaster);
            }

            //Diferent sbContentCustomerTax if OutSide Portugal
            if (_documentMaster.EntityCountryOid.Equals(SettingsApp.XpoOidConfigurationCountryPortugal))
            {
                sbContentCustomerTax = string.Format("    <CustomerTaxID>{0}</CustomerTaxID>", customerTaxID);
            }
            else
            {
                sbContentCustomerTax = string.Format(@"    <ns2:InternationalCustomerTaxID>
              <TaxIDNumber>{0}</TaxIDNumber>
              <TaxIDCountry>{1}</TaxIDCountry>
            </ns2:InternationalCustomerTaxID>"
                                                     , customerTaxID
                                                     , _documentMaster.EntityCountry
                                                     );
            }

            //Get Lines Content
            sbContentLinesAndDocumentTotals = Utils.GetDocumentContentLinesAndDocumentTotals(_documentMaster);

            //Init StringBuilder
            StringBuilder sb = new StringBuilder();

            //Soap Header
            sb.Append("<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">");
            sb.Append("  <S:Header>");
            sb.Append("    <wss:Security xmlns:wss=\"http://schemas.xmlsoap.org/ws/2002/12/secext/\">");
            sb.Append("    <wss:UsernameToken>");
            sb.Append("      <wss:Username>" + _atAccountFiscalNumber + "</wss:Username>");
            sb.Append("      <wss:Password>" + _accountPasswordEncrypted + "</wss:Password>");
            sb.Append("      <wss:Nonce>" + _symetricKeyEncrypted + "</wss:Nonce>");
            sb.Append("      <wss:Created>" + _dateOfCriationEncrypted + "</wss:Created>");
            sb.Append("    </wss:UsernameToken>");
            sb.Append("  </wss:Security>");
            sb.Append("</S:Header>");
            //Soap Body
            sb.Append("  <S:Body>");
            sb.Append("    <ns2:RegisterInvoiceElem xmlns:ns2=\"http://servicos.portaldasfinancas.gov.pt/faturas/\">");
            sb.Append("    <TaxRegistrationNumber>" + _atTaxRegistrationNumber + "</TaxRegistrationNumber>");
            sb.Append("    <ns2:InvoiceNo>" + _documentMaster.DocumentNumber + "</ns2:InvoiceNo>");
            sb.Append("    <ns2:InvoiceDate>" + _documentMaster.DocumentDate + "</ns2:InvoiceDate>");
            sb.Append("    <ns2:InvoiceType>" + _documentMaster.DocumentType.Acronym + "</ns2:InvoiceType>");
            sb.Append("    <ns2:InvoiceStatus>N</ns2:InvoiceStatus>");
            //Generated Content
            sb.Append(sbContentCustomerTax);
            sb.Append(sbContentLinesAndDocumentTotals);
            sb.Append("    </ns2:RegisterInvoiceElem>");
            sb.Append("  </S:Body>");
            sb.Append("</S:Envelope>");

            TextReader textReader  = new StringReader(sb.ToString());
            XDocument  xmlDocument = XDocument.Load(textReader);

            //Save Soap
            xmlDocument.Save(_pathSaveSoap);

            return(xmlDocument.ToString());
        }
Ejemplo n.º 2
0
        private string GenerateXmlStringWB()
        {
            /* IN007016 - escaping the following list of chars using "System.Security.SecurityElement.Escape()" method:
             *
             *      "   &quot;
             *      '   &apos;
             *      <   &lt;
             *      >   &gt;
             *      &   &amp;
             */
            _log.Debug($"string ServicesAT.GenerateXmlStringWB() :: {_documentMaster.DocumentNumber}");
            //IN009347 Documentos PT - Alteração do Layout dos dados do Cliente #Lindote 2020
            /* IN009150 (IN009075) - Decrypt phase */
            string entityName     = "";
            string entityAddress  = "";
            string entityZipCode  = "";
            string entityCity     = "";
            string entityLocality = "";
            // string entityCountry        = "";
            string entityFiscalNumber = "";

            if (!string.IsNullOrEmpty(_documentMaster.EntityName))
            {
                entityName = GlobalFramework.PluginSoftwareVendor.Decrypt(_documentMaster.EntityName);
            }
            if (!string.IsNullOrEmpty(_documentMaster.EntityAddress))
            {
                entityAddress = GlobalFramework.PluginSoftwareVendor.Decrypt(_documentMaster.EntityAddress);
            }
            if (!string.IsNullOrEmpty(_documentMaster.EntityZipCode))
            {
                entityZipCode = GlobalFramework.PluginSoftwareVendor.Decrypt(_documentMaster.EntityZipCode);
            }
            if (!string.IsNullOrEmpty(_documentMaster.EntityCity))
            {
                entityCity = GlobalFramework.PluginSoftwareVendor.Decrypt(_documentMaster.EntityCity);
            }
            if (!string.IsNullOrEmpty(_documentMaster.EntityLocality))
            {
                entityCity = GlobalFramework.PluginSoftwareVendor.Decrypt(_documentMaster.EntityLocality);
            }
            // if (!string.IsNullOrEmpty(_documentMaster.EntityCountry))       { entityCountry = GlobalFramework.PluginSoftwareVendor.Decrypt(_documentMaster.EntityCountry); }
            if (!string.IsNullOrEmpty(_documentMaster.EntityFiscalNumber))
            {
                entityFiscalNumber = GlobalFramework.PluginSoftwareVendor.Decrypt(_documentMaster.EntityFiscalNumber);
            }
            /* IN009150 - end */

            //Init Local Vars
            string customerTaxID  = FiscalNumber.ExtractFiscalNumber(entityFiscalNumber);
            string sbContentLines = string.Empty;

            //MovementStartTime equal/greater system DateTime to prevent -100 error (Override _documentMaster.MovementStartTime)
            _movementStartTime = DateTime.Now;

            //Test mode, increase DocumentNumber only when Develop
            if (_increaseDocumentNumber)
            {
                Utils.IncreaseDocumentNumber(_documentMaster);
            }

            //Get Lines Content
            sbContentLines = Utils.GetDocumentWayBillContentLines(_documentMaster);

            StringBuilder sb = new StringBuilder();

            //Soap Envelope
            sb.Append("<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">");
            //Soap Header
            sb.Append("  <S:Header>");
            sb.Append("    <wss:Security xmlns:wss=\"http://schemas.xmlsoap.org/ws/2002/12/secext/\">");
            sb.Append("      <wss:UsernameToken>");
            sb.Append("      <wss:Username>" + _atAccountFiscalNumber + "</wss:Username>");
            sb.Append("      <wss:Password>" + _accountPasswordEncrypted + "</wss:Password>");
            sb.Append("      <wss:Nonce>" + _symetricKeyEncrypted + "</wss:Nonce>");
            sb.Append("      <wss:Created>" + _dateOfCriationEncrypted + "</wss:Created>");
            sb.Append("      </wss:UsernameToken>");
            sb.Append("    </wss:Security>");
            sb.Append("  </S:Header>");
            //Soap Body
            sb.Append("  <S:Body>");
            sb.Append("		<ns2:envioDocumentoTransporteRequestElem xmlns:ns2=\"https://servicos.portaldasfinancas.gov.pt/sgdtws/documentosTransporte/\">");
            sb.Append("       <TaxRegistrationNumber>" + _atTaxRegistrationNumber + "</TaxRegistrationNumber>");
            sb.Append("       <CompanyName>" + SecurityElement.Escape(entityName) + "</CompanyName>");
            sb.Append("       <CompanyAddress>");
            //Change "AddressDetail" to "Addressdetail" else error: complex-type 2.4: in element CompanyAddress of type
            //Only sent is not empty Addressdetail,City,PostalCode,Country
            sb.Append("         <Addressdetail>" + SecurityElement.Escape(entityAddress) + "</Addressdetail>");
            sb.Append("         <City>" + entityCity + "</City>");
            sb.Append("         <PostalCode>" + entityZipCode + "</PostalCode>");
            sb.Append("         <Country>" + _documentMaster.EntityCountry + "</Country>");
            sb.Append("       </CompanyAddress>");
            sb.Append("       <DocumentNumber>" + _documentMaster.DocumentNumber + "</DocumentNumber>");
            //WIP: CancellWayBills : Find "//WIP: CancellWayBills : " to continue in Uncomment in PosDocumentFinanceSelectRecordDialog.cs
            //Used to Cancel Documents, ex After we have it in DB, resulted from a Sent WB
            //Currently disabled Problems :"Não pode ser alterado um Documento de Transporte quando a Data de Início já decorreu."
            if (!string.IsNullOrEmpty(_documentMaster.ATDocCodeID))
            {
                /* IN009083 - only Transportation Documents  have "ATDocCodeID" when successfully sent to AT */
                sb.Append("       <ATDocCodeID>" + _documentMaster.ATDocCodeID + "</ATDocCodeID>");
            }
            sb.Append("       <MovementStatus>" + _documentMaster.DocumentStatusStatus + "</MovementStatus>");
            sb.Append("       <MovementDate>" + _documentMaster.DocumentDate + "</MovementDate>");
            sb.Append("       <MovementType>" + _documentMaster.DocumentType.Acronym + "</MovementType>");
            sb.Append("       <CustomerTaxID>" + customerTaxID + "</CustomerTaxID>");
            sb.Append("       <CustomerAddress>");
            //Only sent is not empty Addressdetail,City,PostalCode,Country
            sb.Append("         <Addressdetail>" + SecurityElement.Escape(entityAddress) + "</Addressdetail>");
            sb.Append("         <City>" + entityCity + "</City>");
            sb.Append("         <PostalCode>" + entityZipCode + "</PostalCode>");
            sb.Append("         <Country>" + _documentMaster.EntityCountry + "</Country>");
            sb.Append("       </CustomerAddress>");
            //Required to be after <CustomerAddress>
            sb.Append("       <CustomerName>" + SecurityElement.Escape(entityName) + "</CustomerName>");
            sb.Append("       <AddressTo>");
            sb.Append("         <Addressdetail>" + SecurityElement.Escape(_documentMaster.ShipToAddressDetail) + "</Addressdetail>");
            sb.Append("         <City>" + _documentMaster.ShipToCity + "</City>");
            sb.Append("         <PostalCode>" + _documentMaster.ShipToPostalCode + "</PostalCode>");
            sb.Append("         <Country>" + _documentMaster.ShipToCountry + "</Country>");
            sb.Append("       </AddressTo>");
            sb.Append("       <AddressFrom>");
            sb.Append("         <Addressdetail>" + SecurityElement.Escape(_documentMaster.ShipFromAddressDetail) + "</Addressdetail>");
            sb.Append("         <City>" + _documentMaster.ShipFromCity + "</City>");
            sb.Append("         <PostalCode>" + _documentMaster.ShipFromPostalCode + "</PostalCode>");
            sb.Append("         <Country>" + _documentMaster.ShipFromCountry + "</Country>");
            sb.Append("       </AddressFrom>");
            //Dont Sent MovementEndTime, not required
            //sb.Append("       <MovementEndTime>" + _documentMaster.MovementEndTime.ToString(SettingsApp.DateTimeFormatCombinedDateTime) + "</MovementEndTime>");
            sb.Append("       <MovementStartTime>" + _movementStartTime.ToString(SettingsApp.DateTimeFormatCombinedDateTime) + "</MovementStartTime>");
            //VehicleID
            if (!string.IsNullOrEmpty(_documentMaster.ShipFromDeliveryID))
            {
                sb.Append("       <VehicleID>" + _documentMaster.ShipFromDeliveryID + "</VehicleID>");
            }
            //Line
            //Generated Content
            sb.Append(sbContentLines);
            sb.Append("		</ns2:envioDocumentoTransporteRequestElem>");
            sb.Append("  </S:Body>");
            sb.Append("</S:Envelope>");

            TextReader textReader  = new StringReader(sb.ToString());
            XDocument  xmlDocument = XDocument.Load(textReader);

            //Save Soap
            xmlDocument.Save(_pathSaveSoap);

            return(xmlDocument.ToString());
        }
Ejemplo n.º 3
0
        private string GenerateXmlStringWB()
        {
            //Init Local Vars
            string customerTaxID  = FiscalNumber.ExtractFiscalNumber(_documentMaster.EntityFiscalNumber);
            string sbContentLines = string.Empty;

            //MovementStartTime equal/greater system DateTime to prevent -100 error (Override _documentMaster.MovementStartTime)
            _movementStartTime = DateTime.Now;

            //Test mode, increase DocumentNumber only when Develop
            if (_increaseDocumentNumber)
            {
                Utils.IncreaseDocumentNumber(_documentMaster);
            }

            //Get Lines Content
            sbContentLines = Utils.GetDocumentWayBillContentLines(_documentMaster);

            StringBuilder sb = new StringBuilder();

            //Soap Envelope
            sb.Append("<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">");
            //Soap Header
            sb.Append("  <S:Header>");
            sb.Append("    <wss:Security xmlns:wss=\"http://schemas.xmlsoap.org/ws/2002/12/secext/\">");
            sb.Append("      <wss:UsernameToken>");
            sb.Append("      <wss:Username>" + _atAccountFiscalNumber + "</wss:Username>");
            sb.Append("      <wss:Password>" + _accountPasswordEncrypted + "</wss:Password>");
            sb.Append("      <wss:Nonce>" + _symetricKeyEncrypted + "</wss:Nonce>");
            sb.Append("      <wss:Created>" + _dateOfCriationEncrypted + "</wss:Created>");
            sb.Append("      </wss:UsernameToken>");
            sb.Append("    </wss:Security>");
            sb.Append("  </S:Header>");
            //Soap Body
            sb.Append("  <S:Body>");
            sb.Append("		<ns2:envioDocumentoTransporteRequestElem xmlns:ns2=\"https://servicos.portaldasfinancas.gov.pt/sgdtws/documentosTransporte/\">");
            sb.Append("       <TaxRegistrationNumber>" + _atTaxRegistrationNumber + "</TaxRegistrationNumber>");
            sb.Append("       <CompanyName>" + _documentMaster.EntityName + "</CompanyName>");
            sb.Append("       <CompanyAddress>");
            //Change "AddressDetail" to "Addressdetail" else error: complex-type 2.4: in element CompanyAddress of type
            //Only sent is not empty Addressdetail,City,PostalCode,Country
            sb.Append("         <Addressdetail>" + _documentMaster.EntityAddress + "</Addressdetail>");
            sb.Append("         <City>" + _documentMaster.EntityCity + "</City>");
            sb.Append("         <PostalCode>" + _documentMaster.EntityZipCode + "</PostalCode>");
            sb.Append("         <Country>" + _documentMaster.EntityCountry + "</Country>");
            sb.Append("       </CompanyAddress>");
            sb.Append("       <DocumentNumber>" + _documentMaster.DocumentNumber + "</DocumentNumber>");
            //WIP: CancellWayBills : Find "//WIP: CancellWayBills : " to continue in Uncomment in PosDocumentFinanceSelectRecordDialog.cs
            //Used to Cancel Documents, ex After we have it in DB, resulted from a Sent WB
            //Currently disabled Problems :"Não pode ser alterado um Documento de Transporte quando a Data de Início já decorreu."
            //if (! string.IsNullOrEmpty(_documentMaster.ATDocCodeID)) sb.Append("       <ATDocCodeID>" + _documentMaster.ATDocCodeID + "</ATDocCodeID>");
            sb.Append("       <MovementStatus>" + _documentMaster.DocumentStatusStatus + "</MovementStatus>");
            sb.Append("       <MovementDate>" + _documentMaster.DocumentDate + "</MovementDate>");
            sb.Append("       <MovementType>" + _documentMaster.DocumentType.Acronym + "</MovementType>");
            sb.Append("       <CustomerTaxID>" + customerTaxID + "</CustomerTaxID>");
            sb.Append("       <CustomerAddress>");
            //Only sent is not empty Addressdetail,City,PostalCode,Country
            sb.Append("         <Addressdetail>" + _documentMaster.EntityAddress + "</Addressdetail>");
            sb.Append("         <City>" + _documentMaster.EntityCity + "</City>");
            sb.Append("         <PostalCode>" + _documentMaster.EntityZipCode + "</PostalCode>");
            sb.Append("         <Country>" + _documentMaster.EntityCountry + "</Country>");
            sb.Append("       </CustomerAddress>");
            //Required to be after <CustomerAddress>
            sb.Append("       <CustomerName>" + _documentMaster.EntityName + "</CustomerName>");
            sb.Append("       <AddressTo>");
            sb.Append("         <Addressdetail>" + _documentMaster.ShipToAddressDetail + "</Addressdetail>");
            sb.Append("         <City>" + _documentMaster.ShipToCity + "</City>");
            sb.Append("         <PostalCode>" + _documentMaster.ShipToPostalCode + "</PostalCode>");
            sb.Append("         <Country>" + _documentMaster.ShipToCountry + "</Country>");
            sb.Append("       </AddressTo>");
            sb.Append("       <AddressFrom>");
            sb.Append("         <Addressdetail>" + _documentMaster.ShipFromAddressDetail + "</Addressdetail>");
            sb.Append("         <City>" + _documentMaster.ShipFromCity + "</City>");
            sb.Append("         <PostalCode>" + _documentMaster.ShipFromPostalCode + "</PostalCode>");
            sb.Append("         <Country>" + _documentMaster.ShipFromCountry + "</Country>");
            sb.Append("       </AddressFrom>");
            //Dont Sent MovementEndTime, not required
            //sb.Append("       <MovementEndTime>" + _documentMaster.MovementEndTime.ToString(SettingsApp.DateTimeFormatCombinedDateTime) + "</MovementEndTime>");
            sb.Append("       <MovementStartTime>" + _movementStartTime.ToString(SettingsApp.DateTimeFormatCombinedDateTime) + "</MovementStartTime>");
            //VehicleID
            if (!string.IsNullOrEmpty(_documentMaster.ShipFromDeliveryID))
            {
                sb.Append("       <VehicleID>" + _documentMaster.ShipFromDeliveryID + "</VehicleID>");
            }
            //Line
            //Generated Content
            sb.Append(sbContentLines);
            sb.Append("		</ns2:envioDocumentoTransporteRequestElem>");
            sb.Append("  </S:Body>");
            sb.Append("</S:Envelope>");

            XmlDocument xc          = new XmlDocument();
            TextReader  textReader  = new StringReader(sb.ToString());
            XDocument   xmlDocument = XDocument.Load(textReader);

            //Save Soap
            xmlDocument.Save(_pathSaveSoap);

            return(xmlDocument.ToString());
        }