NFePHP\NFe\MakeNFe::zTagdet PHP Метод

zTagdet() приватный Метод

Insere dentro da tag det os produtos tag NFe/infNFe/det[]
private zTagdet ( )
    private function zTagdet()
    {
        if (empty($this->aProd)) {
            return '';
        }
        //insere NVE
        if (!empty($this->aNVE)) {
            foreach ($this->aNVE as $nItem => $nve) {
                $prod = $this->aProd[$nItem];
                foreach ($nve as $child) {
                    $node = $prod->getElementsByTagName("EXTIPI")->item(0);
                    if (empty($node)) {
                        $node = $prod->getElementsByTagName("CFOP")->item(0);
                    }
                    $prod->insertBefore($child, $node);
                }
            }
        }
        //insere CEST
        if (!empty($this->aCest)) {
            foreach ($this->aCest as $nItem => $cest) {
                $prod = $this->aProd[$nItem];
                foreach ($cest as $child) {
                    $node = $prod->getElementsByTagName("EXTIPI")->item(0);
                    if (empty($node)) {
                        $node = $prod->getElementsByTagName("CFOP")->item(0);
                    }
                    $prod->insertBefore($child, $node);
                }
            }
        }
        //insere DI
        if (!empty($this->aDI)) {
            foreach ($this->aDI as $nItem => $aDI) {
                $prod = $this->aProd[$nItem];
                foreach ($aDI as $child) {
                    $node = $prod->getElementsByTagName("xPed")->item(0);
                    if (!empty($node)) {
                        $prod->insertBefore($child, $node);
                    } else {
                        $this->dom->appChild($prod, $child, "Inclusão do node DI");
                    }
                }
                $this->aProd[$nItem] = $prod;
            }
        }
        //insere detExport
        if (!empty($this->aDetExport)) {
            foreach ($this->aDetExport as $nItem => $child) {
                $prod = $this->aProd[$nItem];
                $node = $prod->getElementsByTagName("xPed")->item(0);
                if (!empty($node)) {
                    $prod->insertBefore($child, $node);
                } else {
                    $this->dom->appChild($prod, $child, "Inclusão do node detExport");
                }
                $this->aProd[$nItem] = $prod;
            }
        }
        //insere veiculo
        if (!empty($this->aVeicProd)) {
            foreach ($this->aVeicProd as $nItem => $child) {
                $prod = $this->aProd[$nItem];
                $this->dom->appChild($prod, $child, "Inclusão do node veiculo");
                $this->aProd[$nItem] = $prod;
            }
        }
        //insere medicamentos
        if (!empty($this->aMed)) {
            foreach ($this->aMed as $nItem => $child) {
                $prod = $this->aProd[$nItem];
                $this->dom->appChild($prod, $child, "Inclusão do node medicamento");
                $this->aProd[$nItem] = $prod;
            }
        }
        //insere armas
        if (!empty($this->aArma)) {
            foreach ($this->aArma as $nItem => $child) {
                $prod = $this->aProd[$nItem];
                $this->dom->appChild($prod, $child, "Inclusão do node arma");
                $this->aProd[$nItem] = $prod;
            }
        }
        //insere combustivel
        if (!empty($this->aComb)) {
            foreach ($this->aComb as $nItem => $child) {
                $prod = $this->aProd[$nItem];
                if (!empty($this->aEncerrante)) {
                    $encerrante = $this->aEncerrante[$nItem];
                    if (!empty($encerrante)) {
                        $this->dom->appChild($child, $encerrante, "inclusão do node encerrante na tag comb");
                    }
                }
                $this->dom->appChild($prod, $child, "Inclusão do node combustivel");
                $this->aProd[$nItem] = $prod;
            }
        }
        //insere RECOPI
        if (!empty($this->aRECOPI)) {
            foreach ($this->aRECOPI as $nItem => $child) {
                $prod = $this->aProd[$nItem];
                $this->dom->appChild($prod, $child, "Inclusão do node RECOPI");
                $this->aProd[$nItem] = $prod;
            }
        }
        //montagem da tag imposto[]
        $this->zTagImp();
        //montagem da tag det[]
        foreach ($this->aProd as $nItem => $prod) {
            $det = $this->dom->createElement("det");
            $det->setAttribute("nItem", $nItem);
            $det->appendChild($prod);
            //insere imposto
            if (!empty($this->aImposto[$nItem])) {
                $child = $this->aImposto[$nItem];
                $this->dom->appChild($det, $child, "Inclusão do node imposto");
            }
            //insere impostoDevol
            if (!empty($this->aImpostoDevol)) {
                $child = $this->aImpostoDevol[$nItem];
                $this->dom->appChild($det, $child, "Inclusão do node impostoDevol");
            }
            //insere infAdProd
            if (!empty($this->aInfAdProd[$nItem])) {
                $child = $this->aInfAdProd[$nItem];
                $this->dom->appChild($det, $child, "Inclusão do node infAdProd");
            }
            $this->aDet[] = $det;
            $det = null;
        }
    }