Example #1
0
 /**
  * itensDANFE
  * Monta o campo de itens da DANFE (retrato e paisagem)
  * @name itensDANFE
  * @param float $x Posição horizontal canto esquerdo
  * @param float $y Posição vertical canto superior
  * @param float $nInicio Número do item inicial
  * @param float $max Número do item final
  * @param float $hmax Altura máxima do campo de itens em mm
  * @return float Posição vertical final
  */
 protected function pItensDANFE($x, $y, &$nInicio, $hmax, $pag = 0, $totpag = 0)
 {
     $oldX = $x;
     $oldY = $y;
     $totItens = $this->det->length;
     //#####################################################################
     //DADOS DOS PRODUTOS / SERVIÇOS
     $texto = "DADOS DOS PRODUTOS / SERVIÇOS ";
     if ($this->orientacao == 'P') {
         $w = $this->wPrint;
     } else {
         if ($nInicio < 2) {
             // primeira página
             $w = $this->wPrint - $this->wCanhoto;
         } else {
             // páginas seguintes
             $w = $this->wPrint;
         }
     }
     $h = 4;
     $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => 'B');
     $this->pTextBox($x, $y, $w, $h, $texto, $aFont, 'T', 'L', 0, '');
     $y += 3;
     //desenha a caixa dos dados dos itens da NF
     $hmax += 1;
     $texto = '';
     $this->pTextBox($x, $y, $w, $hmax);
     //##################################################################################
     // cabecalho LOOP COM OS DADOS DOS PRODUTOS
     //CÓDIGO PRODUTO
     $texto = "CÓDIGO PRODUTO";
     $w1 = round($w * 0.09, 0);
     $h = 4;
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w1, $y, $x + $w1, $y + $hmax);
     //DESCRIÇÃO DO PRODUTO / SERVIÇO
     $x += $w1;
     $w2 = round($w * 0.31, 0);
     $texto = 'DESCRIÇÃO DO PRODUTO / SERVIÇO';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w2, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w2, $y, $x + $w2, $y + $hmax);
     //NCM/SH
     $x += $w2;
     $w3 = round($w * 0.06, 0);
     $texto = 'NCM/SH';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w3, $y, $x + $w3, $y + $hmax);
     //O/CST
     $x += $w3;
     $w4 = round($w * 0.04, 0);
     $texto = 'O/CST';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w4, $y, $x + $w4, $y + $hmax);
     //CFOP
     $x += $w4;
     $w5 = round($w * 0.04, 0);
     $texto = 'CFOP';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w5, $y, $x + $w5, $y + $hmax);
     //UN
     $x += $w5;
     $w6 = round($w * 0.03, 0);
     $texto = 'UN';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w6, $y, $x + $w6, $y + $hmax);
     //QUANT
     $x += $w6;
     $w7 = round($w * 0.07000000000000001, 0);
     $texto = 'QUANT';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w7, $y, $x + $w7, $y + $hmax);
     //VALOR UNIT
     $x += $w7;
     $w8 = round($w * 0.06, 0);
     $texto = 'VALOR UNIT';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w8, $y, $x + $w8, $y + $hmax);
     //VALOR TOTAL
     $x += $w8;
     $w9 = round($w * 0.06, 0);
     $texto = 'VALOR TOTAL';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w9, $y, $x + $w9, $y + $hmax);
     //B.CÁLC ICMS
     $x += $w9;
     $w10 = round($w * 0.06, 0);
     $texto = 'B.CÁLC ICMS';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w10, $y, $x + $w10, $y + $hmax);
     //VALOR ICMS
     $x += $w10;
     $w11 = round($w * 0.06, 0);
     $texto = 'VALOR ICMS';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w11, $y, $x + $w11, $y + $hmax);
     //VALOR IPI
     $x += $w11;
     $w12 = round($w * 0.05, 0);
     $texto = 'VALOR IPI';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w12, $y, $x + $w12, $y + $hmax);
     //ALÍQ. ICMS
     $x += $w12;
     $w13 = round($w * 0.035, 0);
     $texto = 'ALÍQ. ICMS';
     $aFont = array('font' => $this->fontePadrao, 'size' => 6, 'style' => '');
     $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($x + $w13, $y, $x + $w13, $y + $hmax);
     //ALÍQ. IPI
     $x += $w13;
     $w14 = $w - ($w1 + $w2 + $w3 + $w4 + $w5 + $w6 + $w7 + $w8 + $w9 + $w10 + $w11 + $w12 + $w13);
     $texto = 'ALÍQ. IPI';
     $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'C', 'C', 0, '', false);
     $this->pdf->Line($oldX, $y + $h + 1, $oldX + $w, $y + $h + 1);
     $y += 5;
     //##################################################################################
     // LOOP COM OS DADOS DOS PRODUTOS
     $i = 0;
     $hUsado = 4;
     $aFont = array('font' => $this->fontePadrao, 'size' => 7, 'style' => '');
     foreach ($this->det as $d) {
         if ($i >= $nInicio) {
             $thisItem = $this->det->item($i);
             //carrega as tags do item
             $prod = $thisItem->getElementsByTagName("prod")->item(0);
             $imposto = $this->det->item($i)->getElementsByTagName("imposto")->item(0);
             $ICMS = $imposto->getElementsByTagName("ICMS")->item(0);
             $IPI = $imposto->getElementsByTagName("IPI")->item(0);
             $textoProduto = $this->pDescricaoProduto($thisItem);
             $linhaDescr = $this->pGetNumLines($textoProduto, $w2, $aFont);
             $h = round($linhaDescr * $this->pdf->FontSize + $linhaDescr * 0.5, 2);
             $hUsado += $h;
             if ($pag != $totpag) {
                 if ($hUsado >= $hmax && $i < $totItens) {
                     //ultrapassa a capacidade para uma única página
                     //o restante dos dados serão usados nas proximas paginas
                     $nInicio = $i;
                     break;
                 }
             }
             $y_linha = $y + $h;
             // linha entre itens
             $this->pdf->DashedHLine($oldX, $y_linha, $w, 0.1, 120);
             //corrige o x
             $x = $oldX;
             //codigo do produto
             $texto = $prod->getElementsByTagName("cProd")->item(0)->nodeValue;
             $this->pTextBox($x, $y, $w1, $h, $texto, $aFont, 'T', 'C', 0, '');
             $x += $w1;
             //DESCRIÇÃO
             if ($this->orientacao == 'P') {
                 $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
             } else {
                 $this->pTextBox($x, $y, $w2, $h, $textoProduto, $aFont, 'T', 'L', 0, '', false);
             }
             $x += $w2;
             //NCM
             $texto = !empty($prod->getElementsByTagName("NCM")->item(0)->nodeValue) ? $prod->getElementsByTagName("NCM")->item(0)->nodeValue : '';
             $this->pTextBox($x, $y, $w3, $h, $texto, $aFont, 'T', 'C', 0, '');
             $x += $w3;
             //CST
             if (isset($ICMS)) {
                 $origem = $this->pSimpleGetValue($ICMS, "orig");
                 $cst = $this->pSimpleGetValue($ICMS, "CST");
                 $csosn = $this->pSimpleGetValue($ICMS, "CSOSN");
                 $texto = $origem . $cst . $csosn;
                 $this->pTextBox($x, $y, $w4, $h, $texto, $aFont, 'T', 'C', 0, '');
             }
             //CFOP
             $x += $w4;
             $texto = $prod->getElementsByTagName("CFOP")->item(0)->nodeValue;
             $this->pTextBox($x, $y, $w5, $h, $texto, $aFont, 'T', 'C', 0, '');
             //Unidade
             $x += $w5;
             $texto = $prod->getElementsByTagName("uCom")->item(0)->nodeValue;
             $this->pTextBox($x, $y, $w6, $h, $texto, $aFont, 'T', 'C', 0, '');
             $x += $w6;
             if ($this->orientacao == 'P') {
                 $alinhamento = 'R';
             } else {
                 $alinhamento = 'R';
             }
             // QTDADE
             $texto = number_format($prod->getElementsByTagName("qCom")->item(0)->nodeValue, 4, ",", ".");
             $this->pTextBox($x, $y, $w7, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
             $x += $w7;
             // Valor Unitário
             $texto = number_format($prod->getElementsByTagName("vUnCom")->item(0)->nodeValue, 4, ",", ".");
             $this->pTextBox($x, $y, $w8, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
             $x += $w8;
             // Valor do Produto
             $texto = number_format($prod->getElementsByTagName("vProd")->item(0)->nodeValue, 2, ",", ".");
             $this->pTextBox($x, $y, $w9, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
             //Valor da Base de calculo
             $x += $w9;
             if (isset($ICMS)) {
                 $texto = !empty($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue) ? number_format($ICMS->getElementsByTagName("vBC")->item(0)->nodeValue, 2, ",", ".") : '0, 00';
                 $this->pTextBox($x, $y, $w10, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
             }
             //Valor do ICMS
             $x += $w10;
             if (isset($ICMS)) {
                 $texto = !empty($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue) ? number_format($ICMS->getElementsByTagName("vICMS")->item(0)->nodeValue, 2, ",", ".") : '0, 00';
                 $this->pTextBox($x, $y, $w11, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
             }
             //Valor do IPI
             $x += $w11;
             if (isset($IPI)) {
                 $texto = !empty($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue) ? number_format($IPI->getElementsByTagName("vIPI")->item(0)->nodeValue, 2, ",", ".") : '';
             } else {
                 $texto = '';
             }
             $this->pTextBox($x, $y, $w12, $h, $texto, $aFont, 'T', $alinhamento, 0, '');
             // %ICMS
             $x += $w12;
             if (isset($ICMS)) {
                 $texto = !empty($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue) ? number_format($ICMS->getElementsByTagName("pICMS")->item(0)->nodeValue, 2, ",", ".") : '0, 00';
                 $this->pTextBox($x, $y, $w13, $h, $texto, $aFont, 'T', 'C', 0, '');
             }
             //%IPI
             $x += $w13;
             if (isset($IPI)) {
                 $texto = !empty($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue) ? number_format($IPI->getElementsByTagName("pIPI")->item(0)->nodeValue, 2, ",", ".") : '';
             } else {
                 $texto = '';
             }
             $this->pTextBox($x, $y, $w14, $h, $texto, $aFont, 'T', 'C', 0, '');
             $y += $h;
             $i++;
             //incrementa o controle dos itens processados.
             $this->qtdeItensProc++;
         } else {
             $i++;
         }
     }
     return $oldY + $hmax;
 }