Skip to content

Commit

Permalink
Merge pull request #41 from gustavodebiasi/master
Browse files Browse the repository at this point in the history
Ajustes realizados no MDF-e para funcionar.
  • Loading branch information
samuelbasso authored Mar 1, 2017
2 parents f870fad + 1da1812 commit 27d7274
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 31 deletions.
44 changes: 40 additions & 4 deletions schemes/PL_MDFe_300/consSitMDFeTiposBasico_v3.00.xsd
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.portalfiscal.inf.br/mdfe" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" targetNamespace="http://www.portalfiscal.inf.br/mdfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="tiposGeralMDFe_v3.00.xsd"/>
<xs:include schemaLocation="consReciMDFeTiposBasico_v3.00.xsd"/>
<xs:include schemaLocation="eventoMDFeTiposBasico_v3.00.xsd"/>
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema_v1.01.xsd"/>
<xs:complexType name="TConsSitMDFe">
<xs:annotation>
Expand Down Expand Up @@ -65,8 +63,46 @@
<xs:documentation>código da UF de atendimento</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="protMDFe" type="TProtMDFe" minOccurs="0"/>
<xs:element name="procEventoMDFe" type="TProcEvento" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="protMDFe" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip">
<xs:annotation>
<xs:documentation>Retornar protMDFe da versão correspondente do MDF-e autorizado</xs:documentation>
</xs:annotation>
</xs:any>
</xs:sequence>
<xs:attribute name="versao" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:enumeration value="1.00"/>
<xs:enumeration value="3.00"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="procEventoMDFe" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip">
<xs:annotation>
<xs:documentation>Retornar procEventoMDFe da versão correspondente do evento MDF-e autorizado</xs:documentation>
</xs:annotation>
</xs:any>
</xs:sequence>
<xs:attribute name="versao" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:enumeration value="1.00"/>
<xs:enumeration value="3.00"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="versao" type="TVerConsSitMDFe" use="required"/>
</xs:complexType>
Expand Down
9 changes: 1 addition & 8 deletions schemes/PL_MDFe_300/eventoMDFeTiposBasico_v3.00.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,7 @@ Insira neste local o XML específico do tipo de evento (cancelamento, encerramen
</xs:annotation>
</xs:any>
</xs:sequence>
<xs:attribute name="versaoEvento" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:whiteSpace value="preserve"/>
<xs:pattern value="1\.[0-9]{2}"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="versaoEvento" type="TVerEvento" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down
1 change: 1 addition & 0 deletions schemes/PL_MDFe_300/leiauteDistMDFe_v3.00.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<xs:documentation>número sequencial único do Ambiente Autorizador</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ipTransmissor" type="TIPv4" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
Expand Down
9 changes: 9 additions & 0 deletions schemes/PL_MDFe_300/retConsMDFeNaoEnc_v1.00.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns="http://www.portalfiscal.inf.br/mdfe" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.portalfiscal.inf.br/mdfe" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="consMDFeNaoEncTiposBasico_v1.00.xsd"/>
<xs:element name="retConsMDFeNaoEnc" type="TRetConsMDFeNaoEnc">
<xs:annotation>
<xs:documentation>Schema XML de validação do retorno da consulta MDF-e não encerrados</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
5 changes: 2 additions & 3 deletions schemes/PL_MDFe_300/tiposGeralMDFe_v3.00.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,7 @@
<xs:whiteSpace value="preserve"/>
<xs:enumeration value="1"/>
<xs:enumeration value="2"/>
<xs:enumeration value="3"/>
<xs:enumeration value="4"/>
<xs:enumeration value="3"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TVerAplic">
Expand Down Expand Up @@ -623,7 +622,7 @@
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{15}"/>
</xs:restriction>
</xs:simpleType>
</xs:simpleType>
<xs:simpleType name="TIPv4">
<xs:annotation>
<xs:documentation>Tipo IP versão 4</xs:documentation>
Expand Down
2 changes: 1 addition & 1 deletion src/Auxiliar/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function readReturnSefaz($method, $xmlResp)
case 'MDFeRetRecepcao':
return self::zReadRetRecepcao($dom);
break;
case 'MDFeConsultaSituacao':
case 'MDFeConsulta':
return self::zReadConsultaMDF($dom);
break;
case 'MDFeStatusServico':
Expand Down
29 changes: 22 additions & 7 deletions src/Make.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public function taginfMDFe($chave = '', $versao = '')
$this->infMDFe = $this->dom->createElement("infMDFe");
$this->infMDFe->setAttribute("Id", 'MDFe'.$chave);
$this->infMDFe->setAttribute("versao", $versao);
$this->versao = $versao;
$this->chMDFe = $chave;
$this->versao = $versao;
return $this->infMDFe;
}

Expand Down Expand Up @@ -1147,6 +1147,7 @@ public function tagVeicTracao(
$cInt,
$placa,
$tara,
$this->aCondutor,
$capKG,
$capM3,
$tpRod,
Expand Down Expand Up @@ -1270,6 +1271,7 @@ protected function zTagVeiculo(
$cInt = '',
$placa = '',
$tara = '',
$condutores = array(),
$capKG = '',
$capM3 = '',
$tpRod = '',
Expand Down Expand Up @@ -1299,6 +1301,10 @@ protected function zTagVeiculo(
true,
"Tara em KG"
);
$this->dom->addArrayChild(
$node,
$condutores
);
$this->dom->addChild(
$node,
"capKG",
Expand Down Expand Up @@ -1396,24 +1402,33 @@ protected function zTagInfDoc()
$this->aCountDoc = array('CTe'=>0, 'NFe'=>0, 'MDFe'=>0);
if (! empty($this->aInfMunDescarga)) {
$infDoc = $this->dom->createElement("infDoc");
$this->aCountDoc['CTe'] = 0;
$this->aCountDoc['NFe'] = 0;
$this->aCountDoc['MDFe'] = 0;
foreach ($this->aInfMunDescarga as $nItem => $node) {
if (isset($this->aInfCTe[$nItem])) {
$this->aCountDoc['CTe'] = $this->dom->addArrayChild($node, $this->aInfCTe[$nItem]);
$this->aCountDoc['CTe'] += $this->dom->addArrayChild($node, $this->aInfCTe[$nItem]);
}
if (isset($this->aInfNFe[$nItem])) {
$this->aCountDoc['NFe'] = $this->dom->addArrayChild($node, $this->aInfNFe[$nItem]);
$this->aCountDoc['NFe'] += $this->dom->addArrayChild($node, $this->aInfNFe[$nItem]);
}
if (isset($this->aInfMDFe[$nItem])) {
$this->aCountDoc['MDFe'] = $this->dom->addArrayChild($node, $this->aInfMDFe[$nItem]);
$this->aCountDoc['MDFe'] += $this->dom->addArrayChild($node, $this->aInfMDFe[$nItem]);
}
$this->dom->appChild($infDoc, $node, '');
}
$this->dom->appChild($this->infMDFe, $infDoc, 'Falta tag "infMDFe"');
}
//ajusta quantidades em tot
$this->tot->getElementsByTagName('qCTe')->item(0)->nodeValue = $this->aCountDoc['CTe'];
$this->tot->getElementsByTagName('qNFe')->item(0)->nodeValue = $this->aCountDoc['NFe'];
$this->tot->getElementsByTagName('qMDFe')->item(0)->nodeValue = $this->aCountDoc['MDFe'];
if ($this->aCountDoc['CTe'] > 0) {
$this->tot->getElementsByTagName('qCTe')->item(0)->nodeValue = $this->aCountDoc['CTe'];
}
if ($this->aCountDoc['NFe'] > 0) {
$this->tot->getElementsByTagName('qNFe')->item(0)->nodeValue = $this->aCountDoc['NFe'];
}
if ($this->aCountDoc['MDFe'] > 0) {
$this->tot->getElementsByTagName('qMDFe')->item(0)->nodeValue = $this->aCountDoc['MDFe'];
}
}

/**
Expand Down
42 changes: 34 additions & 8 deletions src/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ public function addProtocolo($pathMDFefile = '', $pathProtfile = '', $saveFile =
{
//carrega a MDFe
$docmdfe = new Dom();
$docmdfe->loadXMLFile($pathMDFefile);
if (file_exists($pathMDFefile)) {
//carrega o XML pelo caminho do arquivo informado
$docmdfe->loadXMLFile($pathMDFefile);
} else {
//carrega o XML pelo conteúdo
$docmdfe->loadXMLString($pathMDFefile);
}
$nodemdfe = $docmdfe->getNode('MDFe', 0);
if ($nodemdfe == '') {
$msg = "O arquivo indicado como MDFe não é um xml de MDFe!";
Expand All @@ -119,7 +125,13 @@ public function addProtocolo($pathMDFefile = '', $pathProtfile = '', $saveFile =
}
//carrega o protocolo
$docprot = new Dom();
$docprot->loadXMLFile($pathProtfile);
if (file_exists($pathMDFefile)) {
//carrega o XML pelo caminho do arquivo informado
$docprot->loadXMLFile($pathProtfile);
} else {
//carrega o XML pelo conteúdo
$docprot->loadXMLString($pathProtfile);
}
$nodeprots = $docprot->getElementsByTagName('protMDFe');
if ($nodeprots->length == 0) {
$msg = "O arquivo indicado não contêm um protocolo de autorização!";
Expand Down Expand Up @@ -157,7 +169,7 @@ public function addProtocolo($pathMDFefile = '', $pathProtfile = '', $saveFile =
throw new Exception\RuntimeException($msg);
}
//cria a MDFe processada com a tag do protocolo
$procmdfe = new \DOMDocument('1.0', 'utf-8');
$procmdfe = new \DOMDocument('1.0', 'UTF-8');
$procmdfe->formatOutput = false;
$procmdfe->preserveWhiteSpace = false;
//cria a tag mdfeProc
Expand Down Expand Up @@ -215,7 +227,13 @@ public function addCancelamento($pathMDFefile = '', $pathCancfile = '', $saveFil
$procXML = '';
//carrega a MDFe
$docmdfe = new Dom();
$docmdfe->loadXMLFile($pathMDFefile);
if (file_exists($pathMDFefile)) {
//carrega o XML pelo caminho do arquivo informado
$docmdfe->loadXMLFile($pathMDFefile);
} else {
//carrega o XML pelo conteúdo
$docmdfe->loadXMLString($pathMDFefile);
}
$nodemdfe = $docmdfe->getNode('MDFe', 0);
if ($nodemdfe == '') {
$msg = "O arquivo indicado como MDFe não é um xml de MDFe!";
Expand All @@ -236,8 +254,15 @@ public function addCancelamento($pathMDFefile = '', $pathCancfile = '', $saveFil
//carrega o cancelamento
//pode ser um evento ou resultado de uma consulta com multiplos eventos
$doccanc = new Dom();
$doccanc->loadXMLFile($pathCancfile);
$eventos = $doccanc->getElementsByTagName('infEvento');
if (file_exists($pathCancfile)) {
//carrega o XML pelo caminho do arquivo informado
$doccanc->loadXMLFile($pathCancfile);
} else {
//carrega o XML pelo conteúdo
$doccanc->loadXMLString($pathCancfile);
}
$retEvento = $doccanc->getElementsByTagName('retEventoMDFe')->item(0);
$eventos = $retEvento->getElementsByTagName('infEvento');
foreach ($eventos as $evento) {
//evento
$cStat = $evento->getElementsByTagName('cStat')->item(0)->nodeValue;
Expand All @@ -254,8 +279,8 @@ public function addCancelamento($pathMDFefile = '', $pathCancfile = '', $saveFil
&& $tpEvento == '110111'
&& $chaveEvento == $chaveMDFe
) {
$proMDFe->getElementsByTagName('cStat')->item(0)->nodeValue = '101';
$proMDFe->getElementsByTagName('xMotivo')->item(0)->nodeValue = 'Cancelamento de MDF-e homologado';
$docmdfe->getElementsByTagName('cStat')->item(0)->nodeValue = '101';
$docmdfe->getElementsByTagName('xMotivo')->item(0)->nodeValue = 'Cancelamento de MDF-e homologado';
$procXML = $docmdfe->saveXML();
//remove as informações indesejadas
$procXML = Strings::clearProt($procXML);
Expand Down Expand Up @@ -516,6 +541,7 @@ public function sefazConsultaChave($chave = '', $tpAmb = '2', &$aRetorno = array
$this->zGravaFile('mdfe', $tpAmb, $filename, $retorno);
//tratar dados de retorno
$aRetorno = Response::readReturnSefaz($servico, $retorno);

return (string) $retorno;
}

Expand Down

0 comments on commit 27d7274

Please sign in to comment.